@gemx-dev/clarity-visualize 0.8.63 → 0.8.64

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.
@@ -106,8 +106,9 @@ var selectorMap = {};
106
106
  function reset$8() {
107
107
  selectorMap = {};
108
108
  }
109
- function configure(classNames) {
109
+ function config$2(classNames) {
110
110
  extraExcludeClassNames = classNames || [];
111
+ console.log("[Selector] config called \u2014 extraExcludeClassNames set to: [".concat(extraExcludeClassNames.join(', '), "]"));
111
112
  }
112
113
  function get$1(input, type) {
113
114
  var a = input.attributes;
@@ -131,7 +132,13 @@ function get$1(input, type) {
131
132
  input.tag = input.tag.indexOf("svg:" /* Constant.SvgPrefix */) === 0 ? input.tag.substr("svg:" /* Constant.SvgPrefix */.length) : input.tag;
132
133
  var selector = "".concat(prefix).concat(input.tag).concat(suffix);
133
134
  var id = "id" /* Constant.Id */ in a && a["id" /* Constant.Id */].length > 0 ? a["id" /* Constant.Id */] : null;
134
- var classes = input.tag !== "BODY" /* Constant.BodyTag */ && "class" /* Constant.Class */ in a && a["class" /* Constant.Class */].length > 0 ? a["class" /* Constant.Class */].trim().split(/\s+/).filter(function (c) { return filter(c); }).join("." /* Constant.Period */) : null;
135
+ var rawClasses = "class" /* Constant.Class */ in a ? a["class" /* Constant.Class */].trim().split(/\s+/) : [];
136
+ var filteredClasses = rawClasses.filter(function (c) { return filter(c); });
137
+ var removedClasses = rawClasses.filter(function (c) { return !filter(c); });
138
+ if (removedClasses.length > 0) {
139
+ console.log("[Selector] tag=\"".concat(input.tag, "\" id=\"").concat(input.id, "\" \u2014 removed classes: [").concat(removedClasses.join(', '), "] | kept: [").concat(filteredClasses.join(', '), "] | extraExclude: [").concat(extraExcludeClassNames.join(', '), "]"));
140
+ }
141
+ var classes = input.tag !== "BODY" /* Constant.BodyTag */ && filteredClasses.length > 0 ? filteredClasses.join("." /* Constant.Period */) : null;
135
142
  if (classes && classes.length > 0) {
136
143
  if (type === 0 /* Selector.Alpha */) {
137
144
  // In Alpha mode, update selector to use class names, with relative positioning within the parent id container.
@@ -144,16 +151,19 @@ function get$1(input, type) {
144
151
  selectorMap[key].push(input.id);
145
152
  }
146
153
  selector = "".concat(key).concat("~" /* Constant.Tilde */).concat(selectorMap[key].indexOf(input.id));
154
+ console.log("\uD83D\uDE80 \uD83D\uDC25 ~ get ~ selector:", selector);
147
155
  }
148
156
  else {
149
157
  // In Beta mode, we continue to look at query selectors in context of the full page
150
158
  selector = "".concat(prefix).concat(input.tag, ".").concat(classes).concat(suffix);
159
+ console.log("\uD83D\uDE80 \uD83D\uDC25 ~ get ~ selector:", selector);
151
160
  }
152
161
  }
153
162
  // Update selector to use "id" field when available. There are two exceptions:
154
163
  // (1) if "id" appears to be an auto generated string token, e.g. guid or a random id containing digits
155
164
  // (2) if "id" appears inside a shadow DOM, in which case we continue to prefix up to shadow DOM to prevent conflicts
156
165
  selector = id && filter(id) ? "".concat(getDomPrefix(prefix)).concat("#" /* Constant.Hash */).concat(id) : selector;
166
+ console.log("\uD83D\uDE80 \uD83D\uDC25 ~ get ~ selector:", selector);
157
167
  return selector;
158
168
  }
159
169
  }
@@ -180,7 +190,9 @@ function filter(value) {
180
190
  if (!value) {
181
191
  return false;
182
192
  } // Do not process empty strings
183
- if (getExcludeClassNames().some(function (x) { return value.toLowerCase().indexOf(x) >= 0; })) {
193
+ var excludeClassNames = getExcludeClassNames();
194
+ console.log("\uD83D\uDE80 \uD83D\uDC25 ~ filter ~ excludeClassNames:", excludeClassNames);
195
+ if (excludeClassNames.some(function (x) { return value.toLowerCase().indexOf(x) >= 0; })) {
184
196
  return false;
185
197
  }
186
198
  for (var i = 0; i < value.length; i++) {
@@ -192,12 +204,14 @@ function filter(value) {
192
204
  return true;
193
205
  }
194
206
  function getExcludeClassNames() {
207
+ console.log("\uD83D\uDE80 \uD83D\uDC25 ~ getExcludeClassNames ~ extraExcludeClassNames:", extraExcludeClassNames);
208
+ console.log("\uD83D\uDE80 \uD83D\uDC25 ~ getExcludeClassNames ~ excludeClassNames:", excludeClassNames);
195
209
  return __spreadArray(__spreadArray([], excludeClassNames, true), extraExcludeClassNames, true);
196
210
  }
197
211
 
198
212
  var selector = /*#__PURE__*/Object.freeze({
199
213
  __proto__: null,
200
- configure: configure,
214
+ config: config$2,
201
215
  get: get$1,
202
216
  reset: reset$8
203
217
  });
@@ -376,6 +390,10 @@ var EnrichHelper = /** @class */ (function () {
376
390
  var selectorBeta = helper.selector.get(input, 1 /* Layout.Selector.Beta */);
377
391
  d.selectorBeta = selectorBeta.length > 0 ? selectorBeta : null;
378
392
  d.hashBeta = selectorBeta.length > 0 ? helper.hash(d.selectorBeta) : null;
393
+ var rawClass = (d.attributes || {})['class'] || '';
394
+ if (rawClass.includes('gp_ls-is-cached')) {
395
+ console.log("[Enrich] id=".concat(d.id, " tag=").concat(d.tag, " | class=\"").concat(rawClass, "\" | selectorBeta=\"").concat(selectorBeta, "\" | hashBeta=").concat(d.hashBeta));
396
+ }
379
397
  /* Track state for future reference */
380
398
  node.alpha = selectorAlpha;
381
399
  node.beta = selectorBeta;
@@ -916,7 +934,8 @@ var HeatmapHelper = /** @class */ (function () {
916
934
  continue;
917
935
  }
918
936
  var r = el.getBoundingClientRect();
919
- var v = _this.visible(el, r, height);
937
+ var isDebugHash = element.hash === "270qs0pw7";
938
+ var v = _this.visible(el, r, height, isDebugHash ? element.hash : undefined);
920
939
  if (!v && _this.max !== null) {
921
940
  console.warn("[Heatmap] SKIP hash=\"".concat(element.hash, "\" \u2014 not visible on re-render"), { rect: { top: r.top, left: r.left, width: r.width, height: r.height }, maxIsSet: _this.max !== null });
922
941
  continue;
@@ -955,13 +974,28 @@ var HeatmapHelper = /** @class */ (function () {
955
974
  console.groupEnd();
956
975
  return output;
957
976
  };
958
- this.visible = function (el, r, height) {
977
+ this.visible = function (el, r, height, debugHash) {
959
978
  var doc = _this.state.window.document;
960
979
  var visibility = r.height > height ? true : false;
980
+ if (debugHash) {
981
+ console.group("[Heatmap visible] hash=".concat(debugHash, " tag=").concat(el === null || el === void 0 ? void 0 : el.tagName));
982
+ console.log(" rect: top=".concat(r.top.toFixed(1), " bottom=").concat(r.bottom.toFixed(1), " left=").concat(r.left.toFixed(1), " width=").concat(r.width.toFixed(1), " height=").concat(r.height.toFixed(1)));
983
+ console.log(" viewport height=".concat(height, " | r.height > height? ").concat(r.height > height));
984
+ }
961
985
  if (visibility === false && r.width > 0 && r.height > 0) {
986
+ var checkX = r.left + (r.width / 2);
987
+ var checkY = r.top + (r.height / 2);
988
+ if (debugHash) {
989
+ console.log(" elementsFromPoint(".concat(checkX.toFixed(1), ", ").concat(checkY.toFixed(1), ")"));
990
+ }
962
991
  while (!visibility && doc) {
963
992
  var shadowElement = null;
964
- var elements = doc.elementsFromPoint(r.left + (r.width / 2), r.top + (r.height / 2));
993
+ var elements = doc.elementsFromPoint(checkX, checkY);
994
+ if (debugHash) {
995
+ var topElements = elements.slice(0, 5).map(function (e) { return "".concat(e.tagName).concat(e.id ? '#' + e.id : '').concat(e.className ? '.' + String(e.className).trim().split(/\s+/).slice(0, 2).join('.') : ''); });
996
+ console.log(" top elements at center: [".concat(topElements.join(', '), "]"));
997
+ console.log(" is el in top elements? ".concat(elements.includes(el), " | el matches first non-canvas? ").concat(elements.find(function (e) { return !(e.tagName === "CANVAS" /* Constant.Canvas */ || (e.id && e.id.indexOf("clarity-" /* Constant.ClarityPrefix */) === 0)); }) === el));
998
+ }
965
999
  for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
966
1000
  var e = elements_1[_i];
967
1001
  // Ignore if top element ends up being the canvas element we added for heatmap visualization
@@ -975,7 +1009,18 @@ var HeatmapHelper = /** @class */ (function () {
975
1009
  doc = shadowElement;
976
1010
  }
977
1011
  }
978
- return visibility && r.bottom >= 0 && r.top <= height;
1012
+ else if (debugHash) {
1013
+ if (r.width === 0 || r.height === 0) {
1014
+ console.log(" SKIP elementsFromPoint \u2014 zero dimension: width=".concat(r.width, " height=").concat(r.height));
1015
+ }
1016
+ }
1017
+ var result = visibility && r.bottom >= 0 && r.top <= height;
1018
+ if (debugHash) {
1019
+ console.log(" visibility=".concat(visibility, " | r.bottom(").concat(r.bottom.toFixed(1), ") >= 0? ").concat(r.bottom >= 0, " | r.top(").concat(r.top.toFixed(1), ") <= height(").concat(height, ")? ").concat(r.top <= height));
1020
+ console.log(" => final result: ".concat(result));
1021
+ console.groupEnd();
1022
+ }
1023
+ return result;
979
1024
  };
980
1025
  this.waitForDialogs = function () { return __awaiter(_this, void 0, void 0, function () {
981
1026
  var isPortalCanvas;
@@ -1724,6 +1769,9 @@ var LayoutHelper = /** @class */ (function () {
1724
1769
  // In case of selector collision, prefer the first inserted node
1725
1770
  _this.hashMapAlpha[data.hashAlpha] = _this.get(data.hashAlpha) || parent;
1726
1771
  _this.hashMapBeta[data.hashBeta] = _this.get(data.hashBeta) || parent;
1772
+ if (data.hashBeta === '2e36mrf7c' || data.hashBeta === '19lq10ve5') {
1773
+ console.log("[Layout] addToHashMap hashBeta=".concat(data.hashBeta, " | hashAlpha=").concat(data.hashAlpha, " | tag=").concat(parent === null || parent === void 0 ? void 0 : parent.tagName));
1774
+ }
1727
1775
  };
1728
1776
  this.resize = function (el, width, height) {
1729
1777
  if (el && el.nodeType === 1 /* NodeType.ELEMENT_NODE */ && width && height) {
@@ -2393,25 +2441,33 @@ var Visualizer = /** @class */ (function () {
2393
2441
  return false;
2394
2442
  }
2395
2443
  };
2396
- this.html = function (decoded, target, portalCanvasId, hash, useproxy, logerror, shortCircuitStrategy) {
2444
+ this.html = function (decoded, target, portalCanvasId, hash, useproxy, logerror, shortCircuitStrategy, signal) {
2397
2445
  if (hash === void 0) { hash = null; }
2398
2446
  if (shortCircuitStrategy === void 0) { shortCircuitStrategy = 0 /* ShortCircuitStrategy.None */; }
2399
2447
  return __awaiter(_this, void 0, void 0, function () {
2400
- var merged, entry, _a, domEvent, e_1;
2448
+ var merged, CHUNK_BUDGET_MS, chunkStart, entry, _a, domEvent, e_1;
2401
2449
  return __generator(this, function (_b) {
2402
2450
  switch (_b.label) {
2403
2451
  case 0:
2404
- if (!(decoded && decoded.length > 0 && target)) return [3 /*break*/, 11];
2452
+ if (!(decoded && decoded.length > 0 && target)) return [3 /*break*/, 13];
2405
2453
  _b.label = 1;
2406
2454
  case 1:
2407
- _b.trys.push([1, 10, , 11]);
2455
+ _b.trys.push([1, 12, , 13]);
2408
2456
  merged = this.merge(decoded);
2457
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
2458
+ return [2 /*return*/, this];
2409
2459
  return [4 /*yield*/, this.setup(target, { version: decoded[0].envelope.version, dom: merged.dom, useproxy: useproxy, portalCanvasId: portalCanvasId })];
2410
2460
  case 2:
2411
2461
  _b.sent();
2462
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
2463
+ return [2 /*return*/, this];
2464
+ CHUNK_BUDGET_MS = 8;
2465
+ chunkStart = performance.now();
2412
2466
  _b.label = 3;
2413
2467
  case 3:
2414
- if (!(merged.events.length > 0)) return [3 /*break*/, 9];
2468
+ if (!(merged.events.length > 0)) return [3 /*break*/, 11];
2469
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
2470
+ return [2 /*return*/, this];
2415
2471
  entry = merged.events.shift();
2416
2472
  _a = entry.event;
2417
2473
  switch (_a) {
@@ -2437,15 +2493,22 @@ var Visualizer = /** @class */ (function () {
2437
2493
  case 7:
2438
2494
  _b.sent();
2439
2495
  return [3 /*break*/, 8];
2440
- case 8: return [3 /*break*/, 3];
2441
- case 9: return [3 /*break*/, 11];
2442
- case 10:
2496
+ case 8:
2497
+ if (!(performance.now() - chunkStart >= CHUNK_BUDGET_MS)) return [3 /*break*/, 10];
2498
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 0); })];
2499
+ case 9:
2500
+ _b.sent();
2501
+ chunkStart = performance.now();
2502
+ _b.label = 10;
2503
+ case 10: return [3 /*break*/, 3];
2504
+ case 11: return [3 /*break*/, 13];
2505
+ case 12:
2443
2506
  e_1 = _b.sent();
2444
2507
  if (logerror) {
2445
2508
  logerror(e_1);
2446
2509
  }
2447
- return [3 /*break*/, 11];
2448
- case 11: return [2 /*return*/, this];
2510
+ return [3 /*break*/, 13];
2511
+ case 13: return [2 /*return*/, this];
2449
2512
  }
2450
2513
  });
2451
2514
  });