@inspecto-dev/core 0.3.6 → 0.3.8

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.
@@ -2061,6 +2061,8 @@ function createAnnotateOverlay(shadowRoot) {
2061
2061
 
2062
2062
  // src/component-utils.ts
2063
2063
  var ATTR_NAME = "data-inspecto";
2064
+ var ASTRO_FILE_ATTR_NAME = "data-astro-source-file";
2065
+ var ASTRO_LOC_ATTR_NAME = "data-astro-source-loc";
2064
2066
  function parseAttrValue(value) {
2065
2067
  const parts = value.split(":");
2066
2068
  if (parts.length < 3) return null;
@@ -2070,9 +2072,29 @@ function parseAttrValue(value) {
2070
2072
  if (isNaN(line) || isNaN(col) || !file) return null;
2071
2073
  return { file, line, column: col };
2072
2074
  }
2075
+ function parseAstroAttrValue(file, loc) {
2076
+ const parts = loc.split(":");
2077
+ if (parts.length !== 2) return null;
2078
+ const line = parseInt(parts[0], 10);
2079
+ const column = parseInt(parts[1], 10);
2080
+ if (isNaN(line) || isNaN(column) || !file) return null;
2081
+ return { file, line, column };
2082
+ }
2083
+ function getInspectableLocation(el) {
2084
+ const attrValue = el.getAttribute(ATTR_NAME);
2085
+ if (attrValue) {
2086
+ return parseAttrValue(attrValue);
2087
+ }
2088
+ const astroFile = el.getAttribute(ASTRO_FILE_ATTR_NAME);
2089
+ const astroLoc = el.getAttribute(ASTRO_LOC_ATTR_NAME);
2090
+ if (astroFile && astroLoc) {
2091
+ return parseAstroAttrValue(astroFile, astroLoc);
2092
+ }
2093
+ return null;
2094
+ }
2073
2095
  function findInspectable(el) {
2074
2096
  while (el) {
2075
- if (el.hasAttribute(ATTR_NAME)) return el;
2097
+ if (getInspectableLocation(el)) return el;
2076
2098
  el = el.parentElement;
2077
2099
  }
2078
2100
  return null;
@@ -2276,7 +2298,16 @@ function findElementForLocation(_ctx, location, selector) {
2276
2298
  const byLocation = Array.from(document.querySelectorAll(`[${ATTR_NAME}]`)).find(
2277
2299
  (candidate) => candidate.getAttribute(ATTR_NAME) === locationAttr
2278
2300
  );
2279
- return byLocation instanceof Element ? byLocation : null;
2301
+ if (byLocation instanceof Element) {
2302
+ return byLocation;
2303
+ }
2304
+ const byAstroLocation = Array.from(
2305
+ document.querySelectorAll("[data-astro-source-file][data-astro-source-loc]")
2306
+ ).find((candidate) => {
2307
+ const candidateLocation = getInspectableLocation(candidate);
2308
+ return (candidateLocation == null ? void 0 : candidateLocation.file) === location.file && candidateLocation.line === location.line && candidateLocation.column === location.column;
2309
+ });
2310
+ return byAstroLocation instanceof Element ? byAstroLocation : null;
2280
2311
  }
2281
2312
  function rebindCurrentAnnotationElements(ctx) {
2282
2313
  const state = asAnnotateContext(ctx);
@@ -3925,7 +3956,61 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
3925
3956
  };
3926
3957
  updatePosition();
3927
3958
  menu.style.visibility = "visible";
3928
- setTimeout(() => input.focus(), 0);
3959
+ const teardownDocFocusGuards = () => {
3960
+ document.removeEventListener("focusin", onDocFocusIn, true);
3961
+ document.removeEventListener("focusout", onDocFocusOut, true);
3962
+ };
3963
+ const onDocFocusIn = (e) => {
3964
+ var _a3, _b2;
3965
+ if (!menu.isConnected) {
3966
+ teardownDocFocusGuards();
3967
+ return;
3968
+ }
3969
+ const path = (_b2 = (_a3 = e.composedPath) == null ? void 0 : _a3.call(e)) != null ? _b2 : [];
3970
+ if (path.includes(menu)) {
3971
+ e.stopImmediatePropagation();
3972
+ }
3973
+ };
3974
+ const onDocFocusOut = (e) => {
3975
+ if (!menu.isConnected) {
3976
+ teardownDocFocusGuards();
3977
+ return;
3978
+ }
3979
+ const related = e.relatedTarget;
3980
+ if (!related) return;
3981
+ if (related === shadowRoot.host) {
3982
+ e.stopImmediatePropagation();
3983
+ return;
3984
+ }
3985
+ if (related instanceof Node && menu.contains(related)) {
3986
+ e.stopImmediatePropagation();
3987
+ }
3988
+ };
3989
+ document.addEventListener("focusin", onDocFocusIn, true);
3990
+ document.addEventListener("focusout", onDocFocusOut, true);
3991
+ const focusAskInput = () => {
3992
+ try {
3993
+ input.focus({ preventScroll: true });
3994
+ } catch (e) {
3995
+ input.focus();
3996
+ }
3997
+ };
3998
+ const isAskInputFocused = () => {
3999
+ try {
4000
+ return shadowRoot.activeElement === input;
4001
+ } catch (e) {
4002
+ return false;
4003
+ }
4004
+ };
4005
+ focusAskInput();
4006
+ const rafId = requestAnimationFrame(() => {
4007
+ if (!menu.isConnected) return;
4008
+ if (!isAskInputFocused()) focusAskInput();
4009
+ });
4010
+ const focusTimeoutId = setTimeout(() => {
4011
+ if (!menu.isConnected) return;
4012
+ if (!isAskInputFocused()) focusAskInput();
4013
+ }, 50);
3929
4014
  const onDocClick = (e) => {
3930
4015
  const eventTarget = e.target;
3931
4016
  if (eventTarget) {
@@ -3942,6 +4027,9 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
3942
4027
  setTimeout(() => document.addEventListener("click", onDocClick, { capture: true }), 0);
3943
4028
  function cleanup() {
3944
4029
  document.removeEventListener("click", onDocClick, { capture: true });
4030
+ teardownDocFocusGuards();
4031
+ cancelAnimationFrame(rafId);
4032
+ clearTimeout(focusTimeoutId);
3945
4033
  menu.remove();
3946
4034
  onClose();
3947
4035
  }
@@ -4772,9 +4860,8 @@ function handleMouseMove(ctx, event) {
4772
4860
  state.overlay.hide();
4773
4861
  return;
4774
4862
  }
4775
- const attrValue = target.getAttribute(ATTR_NAME);
4776
- const loc = parseAttrValue(attrValue);
4777
- const label = loc ? `${(_a2 = loc.file.split("/").pop()) != null ? _a2 : ""}:${loc.line}` : attrValue;
4863
+ const loc = getInspectableLocation(target);
4864
+ const label = loc ? `${(_a2 = loc.file.split("/").pop()) != null ? _a2 : ""}:${loc.line}` : "";
4778
4865
  if (state.mode === "annotate" && state.annotateCapturePaused) {
4779
4866
  state.overlay.hide();
4780
4867
  return;
@@ -4801,8 +4888,7 @@ function handleTrigger(ctx, event) {
4801
4888
  if (state.mode === "annotate" && state.annotateCapturePaused) return;
4802
4889
  event.preventDefault();
4803
4890
  event.stopPropagation();
4804
- const attrValue = target.getAttribute(ATTR_NAME);
4805
- const loc = parseAttrValue(attrValue);
4891
+ const loc = getInspectableLocation(target);
4806
4892
  if (!loc) return;
4807
4893
  if (state.mode === "annotate") {
4808
4894
  if (state.annotateQuickCaptureEnabled) {
@@ -4822,10 +4908,13 @@ function handleTrigger(ctx, event) {
4822
4908
  state.openInspectMenu(loc, event.clientX, event.clientY, target);
4823
4909
  }
4824
4910
  function handleKeyDown(ctx, event) {
4825
- var _a2;
4826
4911
  const state = asInteractionContext(ctx);
4827
4912
  if (event.key === "Escape") {
4828
- (_a2 = state.cleanupMenu) == null ? void 0 : _a2.call(state);
4913
+ if (state.cleanupMenu !== null) {
4914
+ state.cleanupMenu();
4915
+ } else if (!state.disabled) {
4916
+ state.pause();
4917
+ }
4829
4918
  state.overlay.hide();
4830
4919
  }
4831
4920
  state.updateLauncherEye();
@@ -6339,6 +6428,9 @@ var InspectoElement = class extends BaseElement {
6339
6428
  updateLauncherEye() {
6340
6429
  updateLauncherEye(this);
6341
6430
  }
6431
+ pause() {
6432
+ this.setPaused(true);
6433
+ }
6342
6434
  openInspectMenu(loc, clientX, clientY, targetElement) {
6343
6435
  openInspectMenu(this, loc, clientX, clientY, targetElement);
6344
6436
  }
@@ -6499,4 +6591,4 @@ if (typeof customElements !== "undefined" && !customElements.get("inspecto-overl
6499
6591
  export {
6500
6592
  InspectoElement
6501
6593
  };
6502
- //# sourceMappingURL=component-YOUXVPMF.js.map
6594
+ //# sourceMappingURL=component-BLZBHHON.js.map