@inspecto-dev/core 0.3.4 → 0.3.6

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.
@@ -966,7 +966,9 @@ var overlayMenuStyles = `
966
966
  border: 1px solid var(--inspecto-border-subtle);
967
967
  border-radius: var(--inspecto-radius-lg);
968
968
  padding: 10px;
969
- min-width: 304px;
969
+ width: 304px;
970
+ max-width: calc(100vw - 16px);
971
+ box-sizing: border-box;
970
972
  box-shadow: var(--inspecto-shadow-floating);
971
973
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
972
974
  color: var(--inspecto-text-primary);
@@ -2926,7 +2928,7 @@ function createBadge(ctx) {
2926
2928
  const state = asLauncherContext(ctx);
2927
2929
  const btn = document.createElement("div");
2928
2930
  btn.className = badgeClass;
2929
- btn.style.display = "flex";
2931
+ btn.style.visibility = "hidden";
2930
2932
  const indicator = document.createElement("span");
2931
2933
  indicator.className = `${badgeClass}-indicator`;
2932
2934
  indicator.dataset.inspectoLauncherIndicator = "true";
@@ -3011,14 +3013,85 @@ function createBadge(ctx) {
3011
3013
  titleBlock.append(titleSpan, stateSpan);
3012
3014
  content.append(indicator, titleBlock);
3013
3015
  btn.append(content, eyes, panel);
3016
+ let isDragging = false;
3017
+ let dragStartX = 0;
3018
+ let dragStartY = 0;
3019
+ let initialBadgeX = 0;
3020
+ let initialBadgeY = 0;
3021
+ const handleDragStart = (e) => {
3022
+ const target = e.target;
3023
+ if (target.closest(`.${badgeClass}-panel`) || target.closest(`[data-inspecto-launcher-action]`)) {
3024
+ return;
3025
+ }
3026
+ if (e.type === "mousedown" && e.button !== 0) return;
3027
+ const clientX = e.type === "touchstart" ? e.touches[0].clientX : e.clientX;
3028
+ const clientY = e.type === "touchstart" ? e.touches[0].clientY : e.clientY;
3029
+ dragStartX = clientX;
3030
+ dragStartY = clientY;
3031
+ const rect = btn.getBoundingClientRect();
3032
+ initialBadgeX = rect.left;
3033
+ initialBadgeY = rect.top;
3034
+ isDragging = false;
3035
+ document.addEventListener("mousemove", handleDragMove, { passive: false });
3036
+ document.addEventListener("mouseup", handleDragEnd);
3037
+ document.addEventListener("touchmove", handleDragMove, { passive: false });
3038
+ document.addEventListener("touchend", handleDragEnd);
3039
+ };
3040
+ const handleDragMove = (e) => {
3041
+ const clientX = e.type === "touchmove" ? e.touches[0].clientX : e.clientX;
3042
+ const clientY = e.type === "touchmove" ? e.touches[0].clientY : e.clientY;
3043
+ const dx = clientX - dragStartX;
3044
+ const dy = clientY - dragStartY;
3045
+ if (!isDragging && Math.hypot(dx, dy) > 5) {
3046
+ isDragging = true;
3047
+ btn.style.transition = "none";
3048
+ }
3049
+ if (isDragging) {
3050
+ e.preventDefault();
3051
+ const maxX = window.innerWidth - btn.offsetWidth;
3052
+ const maxY = window.innerHeight - btn.offsetHeight;
3053
+ let newX = initialBadgeX + dx;
3054
+ let newY = initialBadgeY + dy;
3055
+ newX = Math.max(0, Math.min(newX, maxX));
3056
+ newY = Math.max(0, Math.min(newY, maxY));
3057
+ btn.style.bottom = "auto";
3058
+ btn.style.right = "auto";
3059
+ btn.style.left = `${newX}px`;
3060
+ btn.style.top = `${newY}px`;
3061
+ }
3062
+ };
3063
+ const handleDragEnd = () => {
3064
+ document.removeEventListener("mousemove", handleDragMove);
3065
+ document.removeEventListener("mouseup", handleDragEnd);
3066
+ document.removeEventListener("touchmove", handleDragMove);
3067
+ document.removeEventListener("touchend", handleDragEnd);
3068
+ if (isDragging) {
3069
+ btn.style.transition = "";
3070
+ setTimeout(() => {
3071
+ isDragging = false;
3072
+ }, 0);
3073
+ }
3074
+ };
3075
+ btn.addEventListener("mousedown", handleDragStart);
3076
+ btn.addEventListener("touchstart", handleDragStart, { passive: false });
3014
3077
  btn.addEventListener("click", (event) => {
3015
3078
  var _a2, _b;
3079
+ if (isDragging) {
3080
+ event.preventDefault();
3081
+ event.stopPropagation();
3082
+ return;
3083
+ }
3016
3084
  if ((_b = (_a2 = event.target).closest) == null ? void 0 : _b.call(_a2, `[data-inspecto-launcher-action]`)) return;
3017
3085
  state.launcherPanelOpen = !state.launcherPanelOpen;
3018
3086
  state.updateBadgeContent();
3019
3087
  });
3020
3088
  state.shadowRootEl.appendChild(btn);
3021
3089
  updateLauncherEye(state);
3090
+ requestAnimationFrame(() => {
3091
+ requestAnimationFrame(() => {
3092
+ btn.style.visibility = "";
3093
+ });
3094
+ });
3022
3095
  return btn;
3023
3096
  }
3024
3097
  function setPaused(ctx, value) {
@@ -3571,7 +3644,11 @@ function buildCustomInspectPrompt(input) {
3571
3644
  const prompt = appendCssContextToPrompt(
3572
3645
  appendScreenshotContextToPrompt(
3573
3646
  appendRuntimeContextToPrompt(
3574
- buildPrompt(CUSTOM_PROMPT_TEMPLATE(input.ask.trim()), input.location, snippetResult),
3647
+ buildPrompt(
3648
+ buildCustomInspectPromptTemplate(input.ask.trim(), input.location, input.targetLabel),
3649
+ input.location,
3650
+ snippetResult
3651
+ ),
3575
3652
  (_b = (_a2 = input.runtimeContext) == null ? void 0 : _a2.records) != null ? _b : []
3576
3653
  ),
3577
3654
  (_c = input.screenshotContext) != null ? _c : null
@@ -3584,6 +3661,19 @@ function buildCustomInspectPrompt(input) {
3584
3661
  };
3585
3662
  });
3586
3663
  }
3664
+ function buildCustomInspectPromptTemplate(ask, location, targetLabel) {
3665
+ const sections = [CUSTOM_PROMPT_TEMPLATE(ask)];
3666
+ if (targetLabel == null ? void 0 : targetLabel.trim()) {
3667
+ sections.push(`Selected component:
3668
+ - ${targetLabel.trim()}`);
3669
+ }
3670
+ sections.push(
3671
+ `Source location:
3672
+ - file: ${location.file}
3673
+ - location: ${location.line}:${location.column}`
3674
+ );
3675
+ return sections.join("\n\n");
3676
+ }
3587
3677
 
3588
3678
  // src/menu-header.ts
3589
3679
  function createMenuHeaderDom(input) {
@@ -3594,7 +3684,14 @@ function createMenuHeaderDom(input) {
3594
3684
  headerCopy.style.display = "flex";
3595
3685
  headerCopy.style.flexDirection = "column";
3596
3686
  headerCopy.style.gap = "2px";
3687
+ headerCopy.style.minWidth = "0";
3688
+ headerCopy.style.flex = "1 1 auto";
3597
3689
  const title = document.createElement("strong");
3690
+ title.style.display = "block";
3691
+ title.style.minWidth = "0";
3692
+ title.style.whiteSpace = "nowrap";
3693
+ title.style.overflow = "hidden";
3694
+ title.style.textOverflow = "ellipsis";
3598
3695
  title.textContent = ((_a2 = input.targetLabel) == null ? void 0 : _a2.trim()) || input.location.file.split("/").pop() || input.location.file;
3599
3696
  const meta = document.createElement("div");
3600
3697
  meta.className = menuMetaClass;
@@ -3690,8 +3787,21 @@ function applyIconToggleButtonState(button, enabled, enabledTitle, disabledTitle
3690
3787
  button.style.boxShadow = "none";
3691
3788
  }
3692
3789
 
3790
+ // src/menu-position.ts
3791
+ var DEFAULT_EDGE_MARGIN = 8;
3792
+ function resolveMenuPosition(input) {
3793
+ var _a2;
3794
+ const edgeMargin = (_a2 = input.edgeMargin) != null ? _a2 : DEFAULT_EDGE_MARGIN;
3795
+ const safeWidth = input.viewport.width > 0 ? input.viewport.width : input.menuRect.width + edgeMargin * 2;
3796
+ const safeHeight = input.viewport.height > 0 ? input.viewport.height : input.menuRect.height + edgeMargin * 2;
3797
+ const maxLeft = Math.max(safeWidth - input.menuRect.width - edgeMargin, edgeMargin);
3798
+ const left = Math.max(edgeMargin, Math.min(input.clickX, maxLeft));
3799
+ const maxTop = Math.max(safeHeight - input.menuRect.height - edgeMargin, edgeMargin);
3800
+ const top = Math.max(edgeMargin, Math.min(input.clickY + edgeMargin, maxTop));
3801
+ return { left, top };
3802
+ }
3803
+
3693
3804
  // src/menu.ts
3694
- var MENU_WIDTH = 280;
3695
3805
  function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose, deps = {}) {
3696
3806
  var _a2, _b, _c;
3697
3807
  const maxSnippetLines = (_a2 = options.maxSnippetLines) != null ? _a2 : 100;
@@ -3705,6 +3815,10 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
3705
3815
  const canAttachCssContext2 = typeof deps.captureCssContextPrompt === "function";
3706
3816
  const menu = document.createElement("div");
3707
3817
  menu.className = menuClass;
3818
+ menu.style.width = "304px";
3819
+ menu.style.maxWidth = "calc(100vw - 16px)";
3820
+ menu.style.boxSizing = "border-box";
3821
+ menu.style.pointerEvents = "auto";
3708
3822
  const {
3709
3823
  header,
3710
3824
  headerActions,
@@ -3791,25 +3905,36 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
3791
3905
  menu.appendChild(askAiSection);
3792
3906
  const actionsSection = createMenuSection();
3793
3907
  menu.appendChild(actionsSection);
3794
- const viewportWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
3795
- const safeWidth = viewportWidth > 0 ? viewportWidth : MENU_WIDTH;
3796
- menu.style.left = `${Math.min(clickX, Math.max(safeWidth - MENU_WIDTH, 0))}px`;
3908
+ menu.style.left = `${clickX}px`;
3797
3909
  menu.style.visibility = "hidden";
3798
3910
  menu.style.display = "block";
3799
3911
  shadowRoot.appendChild(menu);
3800
3912
  const updatePosition = () => {
3801
3913
  const rect = menu.getBoundingClientRect();
3802
- const viewportHeight = Math.max(
3803
- document.documentElement.clientHeight || 0,
3804
- window.innerHeight || 0
3805
- );
3806
- const safeHeight = viewportHeight > 0 ? viewportHeight : rect.height + 16;
3807
- menu.style.top = `${Math.min(clickY + 8, Math.max(safeHeight - rect.height - 8, 0))}px`;
3914
+ const { left: nextLeft, top: nextTop } = resolveMenuPosition({
3915
+ clickX,
3916
+ clickY,
3917
+ menuRect: { width: rect.width, height: rect.height },
3918
+ viewport: {
3919
+ width: document.documentElement.clientWidth || window.innerWidth || 0,
3920
+ height: document.documentElement.clientHeight || window.innerHeight || 0
3921
+ }
3922
+ });
3923
+ menu.style.left = `${nextLeft}px`;
3924
+ menu.style.top = `${nextTop}px`;
3808
3925
  };
3809
3926
  updatePosition();
3810
3927
  menu.style.visibility = "visible";
3811
3928
  setTimeout(() => input.focus(), 0);
3812
3929
  const onDocClick = (e) => {
3930
+ const eventTarget = e.target;
3931
+ if (eventTarget) {
3932
+ if (eventTarget.closest(
3933
+ '[role="dialog"], [role="menu"], [role="tooltip"], [role="presentation"], [role="listbox"], [data-radix-popper-content-wrapper], [data-radix-focus-guard]'
3934
+ )) {
3935
+ return;
3936
+ }
3937
+ }
3813
3938
  const path = e.composedPath();
3814
3939
  if (path.includes(menu)) return;
3815
3940
  cleanup();
@@ -3925,15 +4050,16 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
3925
4050
  const requestRuntimeContext = resolveRuntimeContext();
3926
4051
  const requestScreenshotContext = yield resolveScreenshotContext();
3927
4052
  const requestCssContextPrompt = resolveCssContextPrompt();
3928
- const built = yield buildCustomInspectPrompt({
4053
+ const built = yield buildCustomInspectPrompt(__spreadProps(__spreadValues({
3929
4054
  location,
3930
- ask: input.value.trim(),
4055
+ ask: input.value.trim()
4056
+ }, deps.targetLabel ? { targetLabel: deps.targetLabel } : {}), {
3931
4057
  includeSnippet,
3932
4058
  maxSnippetLines,
3933
4059
  runtimeContext: requestRuntimeContext,
3934
4060
  screenshotContext: requestScreenshotContext,
3935
4061
  cssContextPrompt: requestCssContextPrompt
3936
- });
4062
+ }));
3937
4063
  yield openAndSendInspectPrompt({
3938
4064
  location,
3939
4065
  promptText: built.prompt,
@@ -4624,6 +4750,18 @@ function handleMouseMove(ctx, event) {
4624
4750
  state.lastPointerX = event.clientX;
4625
4751
  state.lastPointerY = event.clientY;
4626
4752
  state.updateLauncherEye();
4753
+ if (state.cleanupMenu !== null) {
4754
+ const eventTarget = event.target;
4755
+ if (eventTarget) {
4756
+ if (eventTarget.closest(
4757
+ '[role="dialog"], [role="menu"], [role="tooltip"], [role="presentation"], [role="listbox"], [data-radix-popper-content-wrapper], [data-radix-focus-guard]'
4758
+ )) {
4759
+ return;
4760
+ }
4761
+ }
4762
+ state.overlay.hide();
4763
+ return;
4764
+ }
4627
4765
  const isActive = state.isInspectorActive(event);
4628
4766
  if (!isActive) {
4629
4767
  state.overlay.hide();
@@ -4645,8 +4783,18 @@ function handleMouseMove(ctx, event) {
4645
4783
  event.stopPropagation();
4646
4784
  }
4647
4785
  function handleTrigger(ctx, event) {
4648
- var _a2;
4649
4786
  const state = asInteractionContext(ctx);
4787
+ if (state.cleanupMenu !== null) {
4788
+ const eventTarget = event.target;
4789
+ if (eventTarget) {
4790
+ if (eventTarget.closest(
4791
+ '[role="dialog"], [role="menu"], [role="tooltip"], [role="presentation"], [role="listbox"], [data-radix-popper-content-wrapper], [data-radix-focus-guard]'
4792
+ )) {
4793
+ return;
4794
+ }
4795
+ }
4796
+ return;
4797
+ }
4650
4798
  if (!state.isInspectorActive(event)) return;
4651
4799
  const target = findInspectable(event.target);
4652
4800
  if (!target) return;
@@ -4665,11 +4813,12 @@ function handleTrigger(ctx, event) {
4665
4813
  return;
4666
4814
  }
4667
4815
  if (state.shouldQuickJumpOnTrigger(event)) {
4668
- (_a2 = state.cleanupMenu) == null ? void 0 : _a2.call(state);
4816
+ state.overlay.hide();
4669
4817
  state.cleanupMenu = null;
4670
4818
  void openFile(loc);
4671
4819
  return;
4672
4820
  }
4821
+ state.overlay.hide();
4673
4822
  state.openInspectMenu(loc, event.clientX, event.clientY, target);
4674
4823
  }
4675
4824
  function handleKeyDown(ctx, event) {
@@ -4697,6 +4846,7 @@ function openInspectMenu(ctx, loc, clientX, clientY, targetElement) {
4697
4846
  var _a2, _b;
4698
4847
  const state = asInteractionContext(ctx);
4699
4848
  (_a2 = state.cleanupMenu) == null ? void 0 : _a2.call(state);
4849
+ state.style.pointerEvents = "auto";
4700
4850
  state.cleanupMenu = showIntentMenu(
4701
4851
  state.shadowRootEl,
4702
4852
  loc,
@@ -4704,6 +4854,7 @@ function openInspectMenu(ctx, loc, clientX, clientY, targetElement) {
4704
4854
  clientY,
4705
4855
  state.options,
4706
4856
  () => {
4857
+ state.style.pointerEvents = "none";
4707
4858
  state.cleanupMenu = null;
4708
4859
  },
4709
4860
  {
@@ -5204,11 +5355,14 @@ function createAnnotateSidebarRenderers({
5204
5355
  titleEl.style.letterSpacing = "0.04em";
5205
5356
  titleEl.textContent = title;
5206
5357
  const contentEl = document.createElement("div");
5358
+ contentEl.style.minWidth = "0";
5359
+ contentEl.style.whiteSpace = "normal";
5360
+ contentEl.style.overflowWrap = "anywhere";
5361
+ contentEl.style.wordBreak = "break-word";
5207
5362
  if (typeof content === "string") {
5208
5363
  contentEl.style.fontSize = "13px";
5209
5364
  contentEl.style.color = "rgba(255, 255, 255, 0.9)";
5210
5365
  contentEl.style.lineHeight = "1.4";
5211
- contentEl.style.wordBreak = "break-word";
5212
5366
  if (title === "NOTE" && !chip.note.trim()) {
5213
5367
  contentEl.style.fontStyle = "italic";
5214
5368
  contentEl.style.color = "rgba(255, 255, 255, 0.4)";
@@ -5221,9 +5375,13 @@ function createAnnotateSidebarRenderers({
5221
5375
  return section;
5222
5376
  };
5223
5377
  const elementValue = document.createElement("div");
5378
+ elementValue.style.minWidth = "0";
5224
5379
  elementValue.style.fontFamily = "monospace";
5225
5380
  elementValue.style.fontSize = "13px";
5226
5381
  elementValue.style.color = "#9cdcfe";
5382
+ elementValue.style.whiteSpace = "normal";
5383
+ elementValue.style.overflowWrap = "anywhere";
5384
+ elementValue.style.wordBreak = "break-word";
5227
5385
  elementValue.textContent = chip.label;
5228
5386
  activeTooltip.appendChild(createSection("ELEMENT", elementValue));
5229
5387
  activeTooltip.appendChild(createSection("NOTE", chip.note.trim() || "No note provided"));
@@ -5258,9 +5416,12 @@ function createAnnotateSidebarRenderers({
5258
5416
  chipElement.className = annotateSidebarChipClass;
5259
5417
  chipElement.contentEditable = "false";
5260
5418
  chipElement.style.margin = "0 4px";
5419
+ chipElement.style.boxSizing = "border-box";
5261
5420
  chipElement.style.display = "inline-flex";
5262
5421
  chipElement.style.alignItems = "center";
5263
5422
  chipElement.style.gap = "5px";
5423
+ chipElement.style.minWidth = "0";
5424
+ chipElement.style.maxWidth = "calc(100% - 8px)";
5264
5425
  chipElement.style.verticalAlign = "middle";
5265
5426
  chipElement.tabIndex = 0;
5266
5427
  chipElement.setAttribute("role", "button");
@@ -5268,6 +5429,11 @@ function createAnnotateSidebarRenderers({
5268
5429
  chipElement.dataset.state = chip.state;
5269
5430
  const label = document.createElement("span");
5270
5431
  label.dataset.annotateChipLabel = "true";
5432
+ label.style.flex = "1 1 auto";
5433
+ label.style.minWidth = "0";
5434
+ label.style.overflow = "hidden";
5435
+ label.style.textOverflow = "ellipsis";
5436
+ label.style.whiteSpace = "nowrap";
5271
5437
  label.textContent = chip.label;
5272
5438
  const actionSlot = document.createElement("span");
5273
5439
  actionSlot.style.position = "relative";
@@ -5702,12 +5868,14 @@ function teardownListeners(_ctx, handlers) {
5702
5868
  // src/overlay.ts
5703
5869
  var GAP = 8;
5704
5870
  var EDGE_MARGIN = 4;
5871
+ var MAX_CLASS_SUMMARY_LENGTH = 96;
5705
5872
  function createOverlay(shadowRoot) {
5706
5873
  const overlay = document.createElement("div");
5707
5874
  overlay.className = overlayClass;
5708
5875
  overlay.style.display = "none";
5709
5876
  const tooltip = document.createElement("div");
5710
5877
  tooltip.className = tooltipClass;
5878
+ tooltip.style.display = "none";
5711
5879
  const tagSpan = document.createElement("span");
5712
5880
  tagSpan.className = tagClass;
5713
5881
  const idSpan = document.createElement("span");
@@ -5740,7 +5908,7 @@ function createOverlay(shadowRoot) {
5740
5908
  tagSpan.textContent = tagName;
5741
5909
  idSpan.textContent = el.id ? `#${el.id}` : "";
5742
5910
  const classes = Array.from(el.classList).map((c) => `.${c}`).join("");
5743
- classSpan.textContent = classes;
5911
+ classSpan.textContent = summarizeClasses(classes);
5744
5912
  dimSpan.textContent = `${Math.round(rect.width)} \xD7 ${Math.round(rect.height)}`;
5745
5913
  sourceSpan.textContent = sourceLabel;
5746
5914
  tooltip.style.visibility = "hidden";
@@ -5780,6 +5948,10 @@ function createOverlay(shadowRoot) {
5780
5948
  }
5781
5949
  return { show, hide };
5782
5950
  }
5951
+ function summarizeClasses(classes) {
5952
+ if (classes.length <= MAX_CLASS_SUMMARY_LENGTH) return classes;
5953
+ return `${classes.slice(0, MAX_CLASS_SUMMARY_LENGTH - 3)}...`;
5954
+ }
5783
5955
 
5784
5956
  // src/component-lifecycle.ts
5785
5957
  function asLifecycleContext(ctx) {
@@ -5805,6 +5977,11 @@ function resetAnnotateState(state) {
5805
5977
  }
5806
5978
  function connect(ctx, createAnnotateOverlay2) {
5807
5979
  const state = asLifecycleContext(ctx);
5980
+ const host = state;
5981
+ host.style.position = "fixed";
5982
+ host.style.inset = "0";
5983
+ host.style.pointerEvents = "none";
5984
+ host.style.zIndex = "2147483646";
5808
5985
  state.shadowRootEl = state.attachShadow({ mode: "open" });
5809
5986
  const style = document.createElement("style");
5810
5987
  style.textContent = inspectorStyles;
@@ -6316,10 +6493,10 @@ var InspectoElement = class extends BaseElement {
6316
6493
  });
6317
6494
  }
6318
6495
  };
6319
- if (typeof customElements !== "undefined") {
6496
+ if (typeof customElements !== "undefined" && !customElements.get("inspecto-overlay")) {
6320
6497
  customElements.define("inspecto-overlay", InspectoElement);
6321
6498
  }
6322
6499
  export {
6323
6500
  InspectoElement
6324
6501
  };
6325
- //# sourceMappingURL=component-M23S536R.js.map
6502
+ //# sourceMappingURL=component-YOUXVPMF.js.map