@inspecto-dev/core 0.3.5 → 0.3.7

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/dist/index.cjs CHANGED
@@ -3119,7 +3119,7 @@ function createBadge(ctx) {
3119
3119
  const state = asLauncherContext(ctx);
3120
3120
  const btn = document.createElement("div");
3121
3121
  btn.className = badgeClass;
3122
- btn.style.display = "flex";
3122
+ btn.style.visibility = "hidden";
3123
3123
  const indicator = document.createElement("span");
3124
3124
  indicator.className = `${badgeClass}-indicator`;
3125
3125
  indicator.dataset.inspectoLauncherIndicator = "true";
@@ -3204,14 +3204,85 @@ function createBadge(ctx) {
3204
3204
  titleBlock.append(titleSpan, stateSpan);
3205
3205
  content.append(indicator, titleBlock);
3206
3206
  btn.append(content, eyes, panel);
3207
+ let isDragging = false;
3208
+ let dragStartX = 0;
3209
+ let dragStartY = 0;
3210
+ let initialBadgeX = 0;
3211
+ let initialBadgeY = 0;
3212
+ const handleDragStart = (e) => {
3213
+ const target = e.target;
3214
+ if (target.closest(`.${badgeClass}-panel`) || target.closest(`[data-inspecto-launcher-action]`)) {
3215
+ return;
3216
+ }
3217
+ if (e.type === "mousedown" && e.button !== 0) return;
3218
+ const clientX = e.type === "touchstart" ? e.touches[0].clientX : e.clientX;
3219
+ const clientY = e.type === "touchstart" ? e.touches[0].clientY : e.clientY;
3220
+ dragStartX = clientX;
3221
+ dragStartY = clientY;
3222
+ const rect = btn.getBoundingClientRect();
3223
+ initialBadgeX = rect.left;
3224
+ initialBadgeY = rect.top;
3225
+ isDragging = false;
3226
+ document.addEventListener("mousemove", handleDragMove, { passive: false });
3227
+ document.addEventListener("mouseup", handleDragEnd);
3228
+ document.addEventListener("touchmove", handleDragMove, { passive: false });
3229
+ document.addEventListener("touchend", handleDragEnd);
3230
+ };
3231
+ const handleDragMove = (e) => {
3232
+ const clientX = e.type === "touchmove" ? e.touches[0].clientX : e.clientX;
3233
+ const clientY = e.type === "touchmove" ? e.touches[0].clientY : e.clientY;
3234
+ const dx = clientX - dragStartX;
3235
+ const dy = clientY - dragStartY;
3236
+ if (!isDragging && Math.hypot(dx, dy) > 5) {
3237
+ isDragging = true;
3238
+ btn.style.transition = "none";
3239
+ }
3240
+ if (isDragging) {
3241
+ e.preventDefault();
3242
+ const maxX = window.innerWidth - btn.offsetWidth;
3243
+ const maxY = window.innerHeight - btn.offsetHeight;
3244
+ let newX = initialBadgeX + dx;
3245
+ let newY = initialBadgeY + dy;
3246
+ newX = Math.max(0, Math.min(newX, maxX));
3247
+ newY = Math.max(0, Math.min(newY, maxY));
3248
+ btn.style.bottom = "auto";
3249
+ btn.style.right = "auto";
3250
+ btn.style.left = `${newX}px`;
3251
+ btn.style.top = `${newY}px`;
3252
+ }
3253
+ };
3254
+ const handleDragEnd = () => {
3255
+ document.removeEventListener("mousemove", handleDragMove);
3256
+ document.removeEventListener("mouseup", handleDragEnd);
3257
+ document.removeEventListener("touchmove", handleDragMove);
3258
+ document.removeEventListener("touchend", handleDragEnd);
3259
+ if (isDragging) {
3260
+ btn.style.transition = "";
3261
+ setTimeout(() => {
3262
+ isDragging = false;
3263
+ }, 0);
3264
+ }
3265
+ };
3266
+ btn.addEventListener("mousedown", handleDragStart);
3267
+ btn.addEventListener("touchstart", handleDragStart, { passive: false });
3207
3268
  btn.addEventListener("click", (event) => {
3208
3269
  var _a2, _b;
3270
+ if (isDragging) {
3271
+ event.preventDefault();
3272
+ event.stopPropagation();
3273
+ return;
3274
+ }
3209
3275
  if ((_b = (_a2 = event.target).closest) == null ? void 0 : _b.call(_a2, `[data-inspecto-launcher-action]`)) return;
3210
3276
  state.launcherPanelOpen = !state.launcherPanelOpen;
3211
3277
  state.updateBadgeContent();
3212
3278
  });
3213
3279
  state.shadowRootEl.appendChild(btn);
3214
3280
  updateLauncherEye(state);
3281
+ requestAnimationFrame(() => {
3282
+ requestAnimationFrame(() => {
3283
+ btn.style.visibility = "";
3284
+ });
3285
+ });
3215
3286
  return btn;
3216
3287
  }
3217
3288
  function setPaused(ctx, value) {
@@ -4103,8 +4174,70 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
4103
4174
  };
4104
4175
  updatePosition();
4105
4176
  menu.style.visibility = "visible";
4106
- setTimeout(() => input.focus(), 0);
4177
+ const teardownDocFocusGuards = () => {
4178
+ document.removeEventListener("focusin", onDocFocusIn, true);
4179
+ document.removeEventListener("focusout", onDocFocusOut, true);
4180
+ };
4181
+ const onDocFocusIn = (e) => {
4182
+ var _a3, _b2;
4183
+ if (!menu.isConnected) {
4184
+ teardownDocFocusGuards();
4185
+ return;
4186
+ }
4187
+ const path = (_b2 = (_a3 = e.composedPath) == null ? void 0 : _a3.call(e)) != null ? _b2 : [];
4188
+ if (path.includes(menu)) {
4189
+ e.stopImmediatePropagation();
4190
+ }
4191
+ };
4192
+ const onDocFocusOut = (e) => {
4193
+ if (!menu.isConnected) {
4194
+ teardownDocFocusGuards();
4195
+ return;
4196
+ }
4197
+ const related = e.relatedTarget;
4198
+ if (!related) return;
4199
+ if (related === shadowRoot.host) {
4200
+ e.stopImmediatePropagation();
4201
+ return;
4202
+ }
4203
+ if (related instanceof Node && menu.contains(related)) {
4204
+ e.stopImmediatePropagation();
4205
+ }
4206
+ };
4207
+ document.addEventListener("focusin", onDocFocusIn, true);
4208
+ document.addEventListener("focusout", onDocFocusOut, true);
4209
+ const focusAskInput = () => {
4210
+ try {
4211
+ input.focus({ preventScroll: true });
4212
+ } catch (e) {
4213
+ input.focus();
4214
+ }
4215
+ };
4216
+ const isAskInputFocused = () => {
4217
+ try {
4218
+ return shadowRoot.activeElement === input;
4219
+ } catch (e) {
4220
+ return false;
4221
+ }
4222
+ };
4223
+ focusAskInput();
4224
+ const rafId = requestAnimationFrame(() => {
4225
+ if (!menu.isConnected) return;
4226
+ if (!isAskInputFocused()) focusAskInput();
4227
+ });
4228
+ const focusTimeoutId = setTimeout(() => {
4229
+ if (!menu.isConnected) return;
4230
+ if (!isAskInputFocused()) focusAskInput();
4231
+ }, 50);
4107
4232
  const onDocClick = (e) => {
4233
+ const eventTarget = e.target;
4234
+ if (eventTarget) {
4235
+ if (eventTarget.closest(
4236
+ '[role="dialog"], [role="menu"], [role="tooltip"], [role="presentation"], [role="listbox"], [data-radix-popper-content-wrapper], [data-radix-focus-guard]'
4237
+ )) {
4238
+ return;
4239
+ }
4240
+ }
4108
4241
  const path = e.composedPath();
4109
4242
  if (path.includes(menu)) return;
4110
4243
  cleanup();
@@ -4112,6 +4245,9 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
4112
4245
  setTimeout(() => document.addEventListener("click", onDocClick, { capture: true }), 0);
4113
4246
  function cleanup() {
4114
4247
  document.removeEventListener("click", onDocClick, { capture: true });
4248
+ teardownDocFocusGuards();
4249
+ cancelAnimationFrame(rafId);
4250
+ clearTimeout(focusTimeoutId);
4115
4251
  menu.remove();
4116
4252
  onClose();
4117
4253
  }
@@ -4967,6 +5103,14 @@ function handleMouseMove(ctx, event) {
4967
5103
  state.lastPointerY = event.clientY;
4968
5104
  state.updateLauncherEye();
4969
5105
  if (state.cleanupMenu !== null) {
5106
+ const eventTarget = event.target;
5107
+ if (eventTarget) {
5108
+ if (eventTarget.closest(
5109
+ '[role="dialog"], [role="menu"], [role="tooltip"], [role="presentation"], [role="listbox"], [data-radix-popper-content-wrapper], [data-radix-focus-guard]'
5110
+ )) {
5111
+ return;
5112
+ }
5113
+ }
4970
5114
  state.overlay.hide();
4971
5115
  return;
4972
5116
  }
@@ -4992,7 +5136,17 @@ function handleMouseMove(ctx, event) {
4992
5136
  }
4993
5137
  function handleTrigger(ctx, event) {
4994
5138
  const state = asInteractionContext(ctx);
4995
- if (state.cleanupMenu !== null) return;
5139
+ if (state.cleanupMenu !== null) {
5140
+ const eventTarget = event.target;
5141
+ if (eventTarget) {
5142
+ if (eventTarget.closest(
5143
+ '[role="dialog"], [role="menu"], [role="tooltip"], [role="presentation"], [role="listbox"], [data-radix-popper-content-wrapper], [data-radix-focus-guard]'
5144
+ )) {
5145
+ return;
5146
+ }
5147
+ }
5148
+ return;
5149
+ }
4996
5150
  if (!state.isInspectorActive(event)) return;
4997
5151
  const target = findInspectable(event.target);
4998
5152
  if (!target) return;
@@ -6116,6 +6270,7 @@ function createOverlay(shadowRoot) {
6116
6270
  overlay.style.display = "none";
6117
6271
  const tooltip = document.createElement("div");
6118
6272
  tooltip.className = tooltipClass;
6273
+ tooltip.style.display = "none";
6119
6274
  const tagSpan = document.createElement("span");
6120
6275
  tagSpan.className = tagClass;
6121
6276
  const idSpan = document.createElement("span");