react-grab 0.0.52 → 0.0.54

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.
@@ -3804,11 +3804,8 @@ var InputOverlay = (props) => {
3804
3804
  const handleInput = (event) => {
3805
3805
  const target = event.target;
3806
3806
  props.onInput(target.value);
3807
- autoResizeTextarea(target);
3808
- };
3809
- const autoResizeTextarea = (textarea) => {
3810
- textarea.style.height = "auto";
3811
- textarea.style.height = `${textarea.scrollHeight}px`;
3807
+ target.style.height = "auto";
3808
+ target.style.height = `${target.scrollHeight}px`;
3812
3809
  };
3813
3810
  createEffect(() => {
3814
3811
  if (props.visible && inputRef) {
@@ -4946,6 +4943,14 @@ var formatStack = (stack) => {
4946
4943
  return framePart;
4947
4944
  }).join("\n");
4948
4945
  };
4946
+ var getFileName = (stack) => {
4947
+ for (const frame of stack) {
4948
+ if (frame.source && je2(frame.source.fileName)) {
4949
+ return Q(frame.source.fileName);
4950
+ }
4951
+ }
4952
+ return null;
4953
+ };
4949
4954
  var getHTMLPreview = (element) => {
4950
4955
  const tagName = element.tagName.toLowerCase();
4951
4956
  if (!(element instanceof HTMLElement)) {
@@ -5238,6 +5243,59 @@ var createElementBounds = (element) => {
5238
5243
  };
5239
5244
  };
5240
5245
 
5246
+ // src/utils/is-c-like-key.ts
5247
+ var C_LIKE_CHARACTERS = /* @__PURE__ */ new Set([
5248
+ "c",
5249
+ "C",
5250
+ "\u0441",
5251
+ // Cyrillic small es
5252
+ "\u0421",
5253
+ // Cyrillic capital es
5254
+ "\u023C",
5255
+ // c with stroke
5256
+ "\u023B",
5257
+ // C with stroke
5258
+ "\u2184",
5259
+ // reversed c
5260
+ "\u2183",
5261
+ // reversed C
5262
+ "\u1D04",
5263
+ // modifier small c
5264
+ "\u1D9C",
5265
+ // modifier small c turned
5266
+ "\u2C7C",
5267
+ // latin small c with palatal hook
5268
+ "\u217D",
5269
+ // small roman numeral 100
5270
+ "\u216D",
5271
+ // capital roman numeral 100
5272
+ "\xE7",
5273
+ // c with cedilla
5274
+ "\xC7",
5275
+ // C with cedilla
5276
+ "\u0107",
5277
+ // c with acute
5278
+ "\u0106",
5279
+ // C with acute
5280
+ "\u010D",
5281
+ // c with caron
5282
+ "\u010C",
5283
+ // C with caron
5284
+ "\u0109",
5285
+ // c with circumflex
5286
+ "\u0108",
5287
+ // C with circumflex
5288
+ "\u010B",
5289
+ // c with dot above
5290
+ "\u010A"
5291
+ // C with dot above
5292
+ ]);
5293
+ var isCLikeKey = (key, code) => {
5294
+ if (code === "KeyC") return true;
5295
+ if (!key || key.length !== 1) return false;
5296
+ return C_LIKE_CHARACTERS.has(key);
5297
+ };
5298
+
5241
5299
  // src/theme.ts
5242
5300
  var DEFAULT_THEME = {
5243
5301
  enabled: true,
@@ -5355,11 +5413,23 @@ var _tmpl$9 = /* @__PURE__ */ template(`<span class="font-mono tabular-nums alig
5355
5413
  var _tmpl$23 = /* @__PURE__ */ template(`<span class="font-mono tabular-nums align-middle">&lt;<!>>`);
5356
5414
  var _tmpl$33 = /* @__PURE__ */ template(`<span class="tabular-nums text-[10px] ml-1 align-middle"> in `);
5357
5415
  var hasInited = false;
5416
+ var getScriptOptions = () => {
5417
+ if (typeof window === "undefined") return null;
5418
+ try {
5419
+ const dataOptions = document.currentScript?.getAttribute("data-options");
5420
+ if (!dataOptions) return null;
5421
+ return JSON.parse(dataOptions);
5422
+ } catch {
5423
+ return null;
5424
+ }
5425
+ };
5358
5426
  var init = (rawOptions) => {
5427
+ const scriptOptions = getScriptOptions();
5359
5428
  const options = {
5360
5429
  enabled: true,
5361
5430
  keyHoldDuration: 200,
5362
5431
  allowActivationInsideInput: true,
5432
+ ...scriptOptions,
5363
5433
  ...rawOptions
5364
5434
  };
5365
5435
  const initialTheme = mergeTheme(options.theme);
@@ -5379,6 +5449,7 @@ var init = (rawOptions) => {
5379
5449
  isActive: false,
5380
5450
  isDragging: false,
5381
5451
  isCopying: false,
5452
+ isInputMode: false,
5382
5453
  targetElement: null,
5383
5454
  dragBounds: null
5384
5455
  }),
@@ -5390,7 +5461,7 @@ var init = (rawOptions) => {
5390
5461
  hasInited = true;
5391
5462
  const logIntro = () => {
5392
5463
  try {
5393
- const version = "0.0.52";
5464
+ const version = "0.0.54";
5394
5465
  const logoSvg = `<svg width="294" height="294" viewBox="0 0 294 294" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_0_3)"><mask id="mask0_0_3" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="294" height="294"><path d="M294 0H0V294H294V0Z" fill="white"/></mask><g mask="url(#mask0_0_3)"><path d="M144.599 47.4924C169.712 27.3959 194.548 20.0265 212.132 30.1797C227.847 39.2555 234.881 60.3243 231.926 89.516C231.677 92.0069 231.328 94.5423 230.94 97.1058L228.526 110.14C228.517 110.136 228.505 110.132 228.495 110.127C228.486 110.165 228.479 110.203 228.468 110.24L216.255 105.741C216.256 105.736 216.248 105.728 216.248 105.723C207.915 103.125 199.421 101.075 190.82 99.5888L190.696 99.5588L173.526 97.2648L173.511 97.2631C173.492 97.236 173.467 97.2176 173.447 97.1905C163.862 96.2064 154.233 95.7166 144.599 95.7223C134.943 95.7162 125.295 96.219 115.693 97.2286C110.075 105.033 104.859 113.118 100.063 121.453C95.2426 129.798 90.8624 138.391 86.939 147.193C90.8624 155.996 95.2426 164.588 100.063 172.933C104.866 181.302 110.099 189.417 115.741 197.245C115.749 197.245 115.758 197.246 115.766 197.247L115.752 197.27L115.745 197.283L115.754 197.296L126.501 211.013L126.574 211.089C132.136 217.767 138.126 224.075 144.507 229.974L144.609 230.082L154.572 238.287C154.539 238.319 154.506 238.35 154.472 238.38C154.485 238.392 154.499 238.402 154.513 238.412L143.846 247.482L143.827 247.497C126.56 261.128 109.472 268.745 94.8019 268.745C88.5916 268.837 82.4687 267.272 77.0657 264.208C61.3496 255.132 54.3164 234.062 57.2707 204.871C57.528 202.307 57.8806 199.694 58.2904 197.054C28.3363 185.327 9.52301 167.51 9.52301 147.193C9.52301 129.042 24.2476 112.396 50.9901 100.375C53.3443 99.3163 55.7938 98.3058 58.2904 97.3526C57.8806 94.7023 57.528 92.0803 57.2707 89.516C54.3164 60.3243 61.3496 39.2555 77.0657 30.1797C94.6494 20.0265 119.486 27.3959 144.599 47.4924ZM70.6423 201.315C70.423 202.955 70.2229 204.566 70.0704 206.168C67.6686 229.567 72.5478 246.628 83.3615 252.988L83.5176 253.062C95.0399 259.717 114.015 254.426 134.782 238.38C125.298 229.45 116.594 219.725 108.764 209.314C95.8516 207.742 83.0977 205.066 70.6423 201.315ZM80.3534 163.438C77.34 171.677 74.8666 180.104 72.9484 188.664C81.1787 191.224 89.5657 193.247 98.0572 194.724L98.4618 194.813C95.2115 189.865 92.0191 184.66 88.9311 179.378C85.8433 174.097 83.003 168.768 80.3534 163.438ZM60.759 110.203C59.234 110.839 57.7378 111.475 56.27 112.11C34.7788 121.806 22.3891 134.591 22.3891 147.193C22.3891 160.493 36.4657 174.297 60.7494 184.26C63.7439 171.581 67.8124 159.182 72.9104 147.193C67.822 135.23 63.7566 122.855 60.759 110.203ZM98.4137 99.6404C89.8078 101.145 81.3075 103.206 72.9676 105.809C74.854 114.203 77.2741 122.468 80.2132 130.554L80.3059 130.939C82.9938 125.6 85.8049 120.338 88.8834 115.008C91.9618 109.679 95.1544 104.569 98.4137 99.6404ZM94.9258 38.5215C90.9331 38.4284 86.9866 39.3955 83.4891 41.3243C72.6291 47.6015 67.6975 64.5954 70.0424 87.9446L70.0416 88.2194C70.194 89.8208 70.3941 91.4325 70.6134 93.0624C83.0737 89.3364 95.8263 86.6703 108.736 85.0924C116.57 74.6779 125.28 64.9532 134.773 56.0249C119.877 44.5087 105.895 38.5215 94.9258 38.5215ZM205.737 41.3148C202.268 39.398 198.355 38.4308 194.394 38.5099L194.29 38.512C183.321 38.512 169.34 44.4991 154.444 56.0153C163.93 64.9374 172.634 74.6557 180.462 85.064C193.375 86.6345 206.128 89.3102 218.584 93.0624C218.812 91.4325 219.003 89.8118 219.165 88.2098C221.548 64.7099 216.65 47.6164 205.737 41.3148ZM144.552 64.3097C138.104 70.2614 132.054 76.6306 126.443 83.3765C132.39 82.995 138.426 82.8046 144.552 82.8046C150.727 82.8046 156.778 83.0143 162.707 83.3765C157.08 76.6293 151.015 70.2596 144.552 64.3097Z" fill="white"/><path d="M144.598 47.4924C169.712 27.3959 194.547 20.0265 212.131 30.1797C227.847 39.2555 234.88 60.3243 231.926 89.516C231.677 92.0069 231.327 94.5423 230.941 97.1058L228.526 110.14L228.496 110.127C228.487 110.165 228.478 110.203 228.469 110.24L216.255 105.741L216.249 105.723C207.916 103.125 199.42 101.075 190.82 99.5888L190.696 99.5588L173.525 97.2648L173.511 97.263C173.492 97.236 173.468 97.2176 173.447 97.1905C163.863 96.2064 154.234 95.7166 144.598 95.7223C134.943 95.7162 125.295 96.219 115.693 97.2286C110.075 105.033 104.859 113.118 100.063 121.453C95.2426 129.798 90.8622 138.391 86.939 147.193C90.8622 155.996 95.2426 164.588 100.063 172.933C104.866 181.302 110.099 189.417 115.741 197.245L115.766 197.247L115.752 197.27L115.745 197.283L115.754 197.296L126.501 211.013L126.574 211.089C132.136 217.767 138.126 224.075 144.506 229.974L144.61 230.082L154.572 238.287C154.539 238.319 154.506 238.35 154.473 238.38L154.512 238.412L143.847 247.482L143.827 247.497C126.56 261.13 109.472 268.745 94.8018 268.745C88.5915 268.837 82.4687 267.272 77.0657 264.208C61.3496 255.132 54.3162 234.062 57.2707 204.871C57.528 202.307 57.8806 199.694 58.2904 197.054C28.3362 185.327 9.52298 167.51 9.52298 147.193C9.52298 129.042 24.2476 112.396 50.9901 100.375C53.3443 99.3163 55.7938 98.3058 58.2904 97.3526C57.8806 94.7023 57.528 92.0803 57.2707 89.516C54.3162 60.3243 61.3496 39.2555 77.0657 30.1797C94.6493 20.0265 119.486 27.3959 144.598 47.4924ZM70.6422 201.315C70.423 202.955 70.2229 204.566 70.0704 206.168C67.6686 229.567 72.5478 246.628 83.3615 252.988L83.5175 253.062C95.0399 259.717 114.015 254.426 134.782 238.38C125.298 229.45 116.594 219.725 108.764 209.314C95.8515 207.742 83.0977 205.066 70.6422 201.315ZM80.3534 163.438C77.34 171.677 74.8666 180.104 72.9484 188.664C81.1786 191.224 89.5657 193.247 98.0572 194.724L98.4618 194.813C95.2115 189.865 92.0191 184.66 88.931 179.378C85.8433 174.097 83.003 168.768 80.3534 163.438ZM60.7589 110.203C59.234 110.839 57.7378 111.475 56.2699 112.11C34.7788 121.806 22.3891 134.591 22.3891 147.193C22.3891 160.493 36.4657 174.297 60.7494 184.26C63.7439 171.581 67.8124 159.182 72.9103 147.193C67.822 135.23 63.7566 122.855 60.7589 110.203ZM98.4137 99.6404C89.8078 101.145 81.3075 103.206 72.9676 105.809C74.8539 114.203 77.2741 122.468 80.2132 130.554L80.3059 130.939C82.9938 125.6 85.8049 120.338 88.8834 115.008C91.9618 109.679 95.1544 104.569 98.4137 99.6404ZM94.9258 38.5215C90.9331 38.4284 86.9866 39.3955 83.4891 41.3243C72.629 47.6015 67.6975 64.5954 70.0424 87.9446L70.0415 88.2194C70.194 89.8208 70.3941 91.4325 70.6134 93.0624C83.0737 89.3364 95.8262 86.6703 108.736 85.0924C116.57 74.6779 125.28 64.9532 134.772 56.0249C119.877 44.5087 105.895 38.5215 94.9258 38.5215ZM205.737 41.3148C202.268 39.398 198.355 38.4308 194.394 38.5099L194.291 38.512C183.321 38.512 169.34 44.4991 154.443 56.0153C163.929 64.9374 172.634 74.6557 180.462 85.064C193.374 86.6345 206.129 89.3102 218.584 93.0624C218.813 91.4325 219.003 89.8118 219.166 88.2098C221.548 64.7099 216.65 47.6164 205.737 41.3148ZM144.551 64.3097C138.103 70.2614 132.055 76.6306 126.443 83.3765C132.389 82.995 138.427 82.8046 144.551 82.8046C150.727 82.8046 156.779 83.0143 162.707 83.3765C157.079 76.6293 151.015 70.2596 144.551 64.3097Z" fill="#FF40E0"/></g><mask id="mask1_0_3" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="102" y="84" width="161" height="162"><path d="M235.282 84.827L102.261 112.259L129.693 245.28L262.714 217.848L235.282 84.827Z" fill="white"/></mask><g mask="url(#mask1_0_3)"><path d="M136.863 129.916L213.258 141.224C220.669 142.322 222.495 152.179 215.967 155.856L187.592 171.843L184.135 204.227C183.339 211.678 173.564 213.901 169.624 207.526L129.021 141.831C125.503 136.14 130.245 128.936 136.863 129.916Z" fill="#FF40E0" stroke="#FF40E0" stroke-width="0.817337" stroke-linecap="round" stroke-linejoin="round"/></g></g><defs><clipPath id="clip0_0_3"><rect width="294" height="294" fill="white"/></clipPath></defs></svg>`;
5395
5466
  const logoDataUri = `data:image/svg+xml;base64,${btoa(logoSvg)}`;
5396
5467
  console.log(`%cReact Grab${version ? ` v${version}` : ""}%c
@@ -5410,7 +5481,9 @@ https://react-grab.com`, `background: #330039; color: #ffffff; border: 1px solid
5410
5481
  } catch {
5411
5482
  }
5412
5483
  };
5413
- logIntro();
5484
+ if (options.log !== false) {
5485
+ logIntro();
5486
+ }
5414
5487
  return createRoot((dispose2) => {
5415
5488
  const [theme, setTheme] = createSignal(initialTheme);
5416
5489
  const [isHoldingKeys, setIsHoldingKeys] = createSignal(false);
@@ -5435,18 +5508,17 @@ https://react-grab.com`, `background: #330039; color: #ffffff; border: 1px solid
5435
5508
  const [viewportVersion, setViewportVersion] = createSignal(0);
5436
5509
  const [isInputMode, setIsInputMode] = createSignal(false);
5437
5510
  const [inputText, setInputText] = createSignal("");
5511
+ const [isTouchMode, setIsTouchMode] = createSignal(false);
5438
5512
  let holdTimerId = null;
5439
5513
  let progressAnimationId = null;
5440
5514
  let progressDelayTimerId = null;
5441
5515
  let keydownSpamTimerId = null;
5442
5516
  let mouseSettleTimerId = null;
5443
5517
  let autoScrollAnimationId = null;
5518
+ let previouslyFocusedElement = null;
5444
5519
  const isRendererActive = createMemo(() => isActivated() && !isCopying());
5445
5520
  const hasValidMousePosition = createMemo(() => mouseX() > OFFSCREEN_POSITION && mouseY() > OFFSCREEN_POSITION);
5446
- const isTargetKeyCombination = (event) => (
5447
- // NOTE: we use event.code instead of event.key for keyboard layout compatibility (e.g., AZERTY, QWERTZ)
5448
- (event.metaKey || event.ctrlKey) && event.code === "KeyC"
5449
- );
5521
+ const isTargetKeyCombination = (event) => (event.metaKey || event.ctrlKey) && isCLikeKey(event.key, event.code);
5450
5522
  const getAutoScrollDirection = (clientX, clientY) => {
5451
5523
  return {
5452
5524
  top: clientY < AUTO_SCROLL_EDGE_THRESHOLD_PX,
@@ -5466,16 +5538,21 @@ https://react-grab.com`, `background: #330039; color: #ffffff; border: 1px solid
5466
5538
  };
5467
5539
  const currentBoxes = grabbedBoxes();
5468
5540
  setGrabbedBoxes([...currentBoxes, newBox]);
5541
+ options.onGrabbedBox?.(bounds, element);
5469
5542
  setTimeout(() => {
5470
5543
  setGrabbedBoxes((previousBoxes) => previousBoxes.filter((box) => box.id !== boxId));
5471
5544
  }, SUCCESS_LABEL_DURATION_MS);
5472
5545
  };
5473
- const showTemporarySuccessLabel = (text) => {
5546
+ const showTemporarySuccessLabel = (text, type) => {
5474
5547
  const labelId = `success-${Date.now()}-${Math.random()}`;
5475
5548
  setSuccessLabels((previousLabels) => [...previousLabels, {
5476
5549
  id: labelId,
5477
5550
  text
5478
5551
  }]);
5552
+ options.onSuccessLabel?.(text, type, {
5553
+ x: mouseX(),
5554
+ y: mouseY()
5555
+ });
5479
5556
  setTimeout(() => {
5480
5557
  setSuccessLabels((previousLabels) => previousLabels.filter((label) => label.id !== labelId));
5481
5558
  }, SUCCESS_LABEL_DURATION_MS);
@@ -5489,17 +5566,14 @@ ${context}
5489
5566
  return tagName ? `<${tagName}>` : "1 element";
5490
5567
  };
5491
5568
  const notifyElementsSelected = (elements) => {
5492
- try {
5493
- const elementsPayload = elements.map((element) => ({
5494
- tagName: extractElementTagName(element)
5495
- }));
5496
- window.dispatchEvent(new CustomEvent("react-grab:element-selected", {
5497
- detail: {
5498
- elements: elementsPayload
5499
- }
5500
- }));
5501
- } catch {
5502
- }
5569
+ const elementsPayload = elements.map((element) => ({
5570
+ tagName: extractElementTagName(element)
5571
+ }));
5572
+ window.dispatchEvent(new CustomEvent("react-grab:element-selected", {
5573
+ detail: {
5574
+ elements: elementsPayload
5575
+ }
5576
+ }));
5503
5577
  };
5504
5578
  const executeCopyOperation = async (positionX, positionY, operation) => {
5505
5579
  setCopyStartX(positionX);
@@ -5526,9 +5600,26 @@ ${context}
5526
5600
  let didCopy = false;
5527
5601
  let copiedContent = "";
5528
5602
  const isReactProject = Ee();
5529
- try {
5530
- await options.onBeforeCopy?.(elements);
5531
- } catch {
5603
+ await options.onBeforeCopy?.(elements);
5604
+ if (options.copyFileOnly && isReactProject) {
5605
+ try {
5606
+ const firstElement = elements[0];
5607
+ if (firstElement) {
5608
+ const stack = await getStack(firstElement);
5609
+ const fileName = getFileName(stack);
5610
+ if (fileName) {
5611
+ copiedContent = `@${fileName}`;
5612
+ didCopy = await copyContent(copiedContent);
5613
+ if (didCopy) {
5614
+ options.onCopySuccess?.(elements, copiedContent);
5615
+ }
5616
+ }
5617
+ }
5618
+ } catch (error) {
5619
+ options.onCopyError?.(error);
5620
+ }
5621
+ options.onAfterCopy?.(elements, didCopy);
5622
+ return didCopy;
5532
5623
  }
5533
5624
  try {
5534
5625
  const elementSnippetResults = await Promise.allSettled(elements.map(async (element) => {
@@ -5569,16 +5660,10 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5569
5660
  }
5570
5661
  }
5571
5662
  if (didCopy) {
5572
- try {
5573
- options.onCopySuccess?.(elements, copiedContent);
5574
- } catch {
5575
- }
5663
+ options.onCopySuccess?.(elements, copiedContent);
5576
5664
  }
5577
5665
  } catch (error) {
5578
- try {
5579
- options.onCopyError?.(error);
5580
- } catch {
5581
- }
5666
+ options.onCopyError?.(error);
5582
5667
  const plainTextContentOnly = createCombinedTextContent(elements);
5583
5668
  if (plainTextContentOnly.length > 0) {
5584
5669
  const contentWithPrompt = extraPrompt ? `${extraPrompt}
@@ -5588,34 +5673,26 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5588
5673
  didCopy = await copyContent(contentWithPrompt);
5589
5674
  }
5590
5675
  }
5591
- try {
5592
- options.onAfterCopy?.(elements, didCopy);
5593
- } catch {
5594
- }
5676
+ options.onAfterCopy?.(elements, didCopy);
5595
5677
  return didCopy;
5596
5678
  };
5597
5679
  const copySingleElementToClipboard = async (targetElement2, extraPrompt) => {
5598
- try {
5599
- options.onElementSelect?.(targetElement2);
5600
- } catch {
5601
- }
5680
+ const successLabelType = extraPrompt ? "input-submit" : "copy";
5681
+ options.onElementSelect?.(targetElement2);
5602
5682
  if (theme().grabbedBoxes.enabled) {
5603
5683
  showTemporaryGrabbedBox(createElementBounds(targetElement2), targetElement2);
5604
5684
  }
5605
5685
  await new Promise((resolve) => requestAnimationFrame(resolve));
5606
5686
  const didCopy = await tryCopyWithFallback([targetElement2], extraPrompt);
5607
5687
  if (didCopy && theme().successLabels.enabled) {
5608
- showTemporarySuccessLabel(extractElementTagNameForSuccess(targetElement2));
5688
+ showTemporarySuccessLabel(extractElementTagNameForSuccess(targetElement2), successLabelType);
5609
5689
  }
5610
5690
  notifyElementsSelected([targetElement2]);
5611
5691
  };
5612
5692
  const copyMultipleElementsToClipboard = async (targetElements) => {
5613
5693
  if (targetElements.length === 0) return;
5614
5694
  for (const element of targetElements) {
5615
- try {
5616
- options.onElementSelect?.(element);
5617
- } catch {
5618
- }
5695
+ options.onElementSelect?.(element);
5619
5696
  }
5620
5697
  if (theme().grabbedBoxes.enabled) {
5621
5698
  for (const element of targetElements) {
@@ -5625,7 +5702,7 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5625
5702
  await new Promise((resolve) => requestAnimationFrame(resolve));
5626
5703
  const didCopy = await tryCopyWithFallback(targetElements);
5627
5704
  if (didCopy && theme().successLabels.enabled) {
5628
- showTemporarySuccessLabel(`${targetElements.length} elements`);
5705
+ showTemporarySuccessLabel(`${targetElements.length} elements`, "copy");
5629
5706
  }
5630
5707
  notifyElementsSelected(targetElements);
5631
5708
  };
@@ -5731,10 +5808,7 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5731
5808
  setLastGrabbedElement(null);
5732
5809
  }
5733
5810
  if (currentElement) {
5734
- try {
5735
- options.onElementHover?.(currentElement);
5736
- } catch {
5737
- }
5811
+ options.onElementHover?.(currentElement);
5738
5812
  }
5739
5813
  }));
5740
5814
  createEffect(on(() => viewportVersion(), () => {
@@ -5746,22 +5820,47 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5746
5820
  }));
5747
5821
  setGrabbedBoxes(updatedBoxes);
5748
5822
  }));
5749
- createEffect(on(() => [isActivated(), isDragging(), isCopying(), targetElement(), dragBounds()], ([active, dragging, copying, target, drag]) => {
5750
- try {
5751
- options.onStateChange?.({
5752
- isActive: active,
5753
- isDragging: dragging,
5754
- isCopying: copying,
5755
- targetElement: target,
5756
- dragBounds: drag ? {
5757
- x: drag.x,
5758
- y: drag.y,
5759
- width: drag.width,
5760
- height: drag.height
5761
- } : null
5762
- });
5763
- } catch {
5764
- }
5823
+ createEffect(on(() => [isActivated(), isDragging(), isCopying(), isInputMode(), targetElement(), dragBounds()], ([active, dragging, copying, inputMode, target, drag]) => {
5824
+ options.onStateChange?.({
5825
+ isActive: active,
5826
+ isDragging: dragging,
5827
+ isCopying: copying,
5828
+ isInputMode: inputMode,
5829
+ targetElement: target,
5830
+ dragBounds: drag ? {
5831
+ x: drag.x,
5832
+ y: drag.y,
5833
+ width: drag.width,
5834
+ height: drag.height
5835
+ } : null
5836
+ });
5837
+ }));
5838
+ createEffect(on(() => [isInputMode(), mouseX(), mouseY(), targetElement()], ([inputMode, x3, y2, target]) => {
5839
+ options.onInputModeChange?.(inputMode, {
5840
+ x: x3,
5841
+ y: y2,
5842
+ targetElement: target
5843
+ });
5844
+ }));
5845
+ createEffect(on(() => [selectionVisible(), selectionBounds(), targetElement()], ([visible, bounds, element]) => {
5846
+ options.onSelectionBox?.(Boolean(visible), bounds ?? null, element);
5847
+ }));
5848
+ createEffect(on(() => [dragVisible(), dragBounds()], ([visible, bounds]) => {
5849
+ options.onDragBox?.(Boolean(visible), bounds ?? null);
5850
+ }));
5851
+ createEffect(on(() => [crosshairVisible(), mouseX(), mouseY()], ([visible, x3, y2]) => {
5852
+ options.onCrosshair?.(Boolean(visible), {
5853
+ x: x3,
5854
+ y: y2
5855
+ });
5856
+ }));
5857
+ createEffect(on(() => [labelVisible(), labelVariant(), labelContent(), labelPosition()], ([visible, variant, content, position]) => {
5858
+ const contentString = typeof content === "string" ? content : "";
5859
+ options.onElementLabel?.(Boolean(visible), variant, {
5860
+ x: position.x,
5861
+ y: position.y,
5862
+ content: contentString
5863
+ });
5765
5864
  }));
5766
5865
  const startProgressAnimation = () => {
5767
5866
  const startTime = Date.now();
@@ -5826,6 +5925,7 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5826
5925
  };
5827
5926
  const activateRenderer = () => {
5828
5927
  stopProgressAnimation();
5928
+ previouslyFocusedElement = document.activeElement;
5829
5929
  setIsActivated(true);
5830
5930
  document.body.style.cursor = "crosshair";
5831
5931
  options.onActivate?.();
@@ -5850,6 +5950,10 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5850
5950
  setMouseHasSettled(false);
5851
5951
  stopAutoScroll();
5852
5952
  stopProgressAnimation();
5953
+ if (previouslyFocusedElement instanceof HTMLElement && document.contains(previouslyFocusedElement)) {
5954
+ previouslyFocusedElement.focus();
5955
+ }
5956
+ previouslyFocusedElement = null;
5853
5957
  options.onDeactivate?.();
5854
5958
  };
5855
5959
  const handleInputChange = (value) => {
@@ -5875,17 +5979,78 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5875
5979
  if (!isInputMode()) return;
5876
5980
  deactivateRenderer();
5877
5981
  };
5982
+ const handlePointerMove = (clientX, clientY) => {
5983
+ if (isInputMode()) return;
5984
+ setMouseX(clientX);
5985
+ setMouseY(clientY);
5986
+ if (mouseSettleTimerId !== null) {
5987
+ window.clearTimeout(mouseSettleTimerId);
5988
+ }
5989
+ setMouseHasSettled(false);
5990
+ mouseSettleTimerId = window.setTimeout(() => {
5991
+ setMouseHasSettled(true);
5992
+ mouseSettleTimerId = null;
5993
+ }, 300);
5994
+ if (isDragging()) {
5995
+ const direction = getAutoScrollDirection(clientX, clientY);
5996
+ const isNearEdge = direction.top || direction.bottom || direction.left || direction.right;
5997
+ if (isNearEdge && autoScrollAnimationId === null) {
5998
+ startAutoScroll();
5999
+ } else if (!isNearEdge && autoScrollAnimationId !== null) {
6000
+ stopAutoScroll();
6001
+ }
6002
+ }
6003
+ };
6004
+ const handlePointerDown = (clientX, clientY) => {
6005
+ if (!isRendererActive() || isCopying()) return false;
6006
+ setIsDragging(true);
6007
+ const startX = clientX + window.scrollX;
6008
+ const startY = clientY + window.scrollY;
6009
+ setDragStartX(startX);
6010
+ setDragStartY(startY);
6011
+ document.body.style.userSelect = "none";
6012
+ options.onDragStart?.(startX, startY);
6013
+ return true;
6014
+ };
6015
+ const handlePointerUp = (clientX, clientY) => {
6016
+ if (!isDragging()) return;
6017
+ const dragDistance = calculateDragDistance(clientX, clientY);
6018
+ const wasDragGesture = dragDistance.x > DRAG_THRESHOLD_PX || dragDistance.y > DRAG_THRESHOLD_PX;
6019
+ setIsDragging(false);
6020
+ stopAutoScroll();
6021
+ document.body.style.userSelect = "";
6022
+ if (wasDragGesture) {
6023
+ setDidJustDrag(true);
6024
+ const dragRect = calculateDragRectangle(clientX, clientY);
6025
+ const elements = getElementsInDrag(dragRect, isValidGrabbableElement);
6026
+ if (elements.length > 0) {
6027
+ options.onDragEnd?.(elements, dragRect);
6028
+ void executeCopyOperation(clientX, clientY, () => copyMultipleElementsToClipboard(elements));
6029
+ } else {
6030
+ const fallbackElements = getElementsInDragLoose(dragRect, isValidGrabbableElement);
6031
+ if (fallbackElements.length > 0) {
6032
+ options.onDragEnd?.(fallbackElements, dragRect);
6033
+ void executeCopyOperation(clientX, clientY, () => copyMultipleElementsToClipboard(fallbackElements));
6034
+ }
6035
+ }
6036
+ } else {
6037
+ const element = getElementAtPosition(clientX, clientY);
6038
+ if (!element) return;
6039
+ setLastGrabbedElement(element);
6040
+ void executeCopyOperation(clientX, clientY, () => copySingleElementToClipboard(element));
6041
+ }
6042
+ };
5878
6043
  const abortController = new AbortController();
5879
6044
  const eventListenerSignal = abortController.signal;
5880
6045
  window.addEventListener("keydown", (event) => {
5881
- if (event.code === "Escape" && isHoldingKeys()) {
6046
+ if (event.key === "Escape" && isHoldingKeys()) {
5882
6047
  if (isInputMode()) {
5883
6048
  return;
5884
6049
  }
5885
6050
  deactivateRenderer();
5886
6051
  return;
5887
6052
  }
5888
- if (event.code === "Enter" && isHoldingKeys() && !isInputMode()) {
6053
+ if (event.key === "Enter" && isHoldingKeys() && !isInputMode()) {
5889
6054
  event.preventDefault();
5890
6055
  event.stopPropagation();
5891
6056
  setIsToggleMode(true);
@@ -5934,7 +6099,7 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5934
6099
  window.addEventListener("keyup", (event) => {
5935
6100
  if (!isHoldingKeys() && !isActivated()) return;
5936
6101
  const isReleasingModifier = !event.metaKey && !event.ctrlKey;
5937
- const isReleasingC = event.code === "KeyC";
6102
+ const isReleasingC = isCLikeKey(event.key, event.code);
5938
6103
  if (isReleasingC || isReleasingModifier) {
5939
6104
  if (isToggleMode()) return;
5940
6105
  deactivateRenderer();
@@ -5944,26 +6109,8 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5944
6109
  capture: true
5945
6110
  });
5946
6111
  window.addEventListener("mousemove", (event) => {
5947
- if (isInputMode()) return;
5948
- setMouseX(event.clientX);
5949
- setMouseY(event.clientY);
5950
- if (mouseSettleTimerId !== null) {
5951
- window.clearTimeout(mouseSettleTimerId);
5952
- }
5953
- setMouseHasSettled(false);
5954
- mouseSettleTimerId = window.setTimeout(() => {
5955
- setMouseHasSettled(true);
5956
- mouseSettleTimerId = null;
5957
- }, 300);
5958
- if (isDragging()) {
5959
- const direction = getAutoScrollDirection(event.clientX, event.clientY);
5960
- const isNearEdge = direction.top || direction.bottom || direction.left || direction.right;
5961
- if (isNearEdge && autoScrollAnimationId === null) {
5962
- startAutoScroll();
5963
- } else if (!isNearEdge && autoScrollAnimationId !== null) {
5964
- stopAutoScroll();
5965
- }
5966
- }
6112
+ setIsTouchMode(false);
6113
+ handlePointerMove(event.clientX, event.clientY);
5967
6114
  }, {
5968
6115
  signal: eventListenerSignal
5969
6116
  });
@@ -5976,54 +6123,56 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5976
6123
  }
5977
6124
  return;
5978
6125
  }
5979
- if (!isRendererActive() || isCopying()) return;
5980
- event.preventDefault();
5981
- setIsDragging(true);
5982
- const startX = event.clientX + window.scrollX;
5983
- const startY = event.clientY + window.scrollY;
5984
- setDragStartX(startX);
5985
- setDragStartY(startY);
5986
- document.body.style.userSelect = "none";
5987
- try {
5988
- options.onDragStart?.(startX, startY);
5989
- } catch {
6126
+ const didHandle = handlePointerDown(event.clientX, event.clientY);
6127
+ if (didHandle) {
6128
+ event.preventDefault();
5990
6129
  }
5991
6130
  }, {
5992
- signal: eventListenerSignal
6131
+ signal: eventListenerSignal,
6132
+ capture: true
6133
+ });
6134
+ window.addEventListener("pointerdown", (event) => {
6135
+ if (!isRendererActive() || isCopying() || isInputMode()) return;
6136
+ event.stopPropagation();
6137
+ }, {
6138
+ signal: eventListenerSignal,
6139
+ capture: true
5993
6140
  });
5994
6141
  window.addEventListener("mouseup", (event) => {
5995
- if (!isDragging()) return;
5996
- const dragDistance = calculateDragDistance(event.clientX, event.clientY);
5997
- const wasDragGesture = dragDistance.x > DRAG_THRESHOLD_PX || dragDistance.y > DRAG_THRESHOLD_PX;
5998
- setIsDragging(false);
5999
- stopAutoScroll();
6000
- document.body.style.userSelect = "";
6001
- if (wasDragGesture) {
6002
- setDidJustDrag(true);
6003
- const dragRect = calculateDragRectangle(event.clientX, event.clientY);
6004
- const elements = getElementsInDrag(dragRect, isValidGrabbableElement);
6005
- if (elements.length > 0) {
6006
- try {
6007
- options.onDragEnd?.(elements, dragRect);
6008
- } catch {
6009
- }
6010
- void executeCopyOperation(event.clientX, event.clientY, () => copyMultipleElementsToClipboard(elements));
6011
- } else {
6012
- const fallbackElements = getElementsInDragLoose(dragRect, isValidGrabbableElement);
6013
- if (fallbackElements.length > 0) {
6014
- try {
6015
- options.onDragEnd?.(fallbackElements, dragRect);
6016
- } catch {
6017
- }
6018
- void executeCopyOperation(event.clientX, event.clientY, () => copyMultipleElementsToClipboard(fallbackElements));
6019
- }
6142
+ handlePointerUp(event.clientX, event.clientY);
6143
+ }, {
6144
+ signal: eventListenerSignal
6145
+ });
6146
+ window.addEventListener("touchmove", (event) => {
6147
+ if (event.touches.length === 0) return;
6148
+ setIsTouchMode(true);
6149
+ handlePointerMove(event.touches[0].clientX, event.touches[0].clientY);
6150
+ }, {
6151
+ signal: eventListenerSignal,
6152
+ passive: true
6153
+ });
6154
+ window.addEventListener("touchstart", (event) => {
6155
+ if (event.touches.length === 0) return;
6156
+ setIsTouchMode(true);
6157
+ if (isInputMode()) {
6158
+ const target = event.target;
6159
+ const isClickingInput = target.closest("[data-react-grab-input]");
6160
+ if (!isClickingInput) {
6161
+ handleInputCancel();
6020
6162
  }
6021
- } else {
6022
- const element = getElementAtPosition(event.clientX, event.clientY);
6023
- if (!element) return;
6024
- setLastGrabbedElement(element);
6025
- void executeCopyOperation(event.clientX, event.clientY, () => copySingleElementToClipboard(element));
6163
+ return;
6026
6164
  }
6165
+ const didHandle = handlePointerDown(event.touches[0].clientX, event.touches[0].clientY);
6166
+ if (didHandle) {
6167
+ event.preventDefault();
6168
+ }
6169
+ }, {
6170
+ signal: eventListenerSignal,
6171
+ passive: false
6172
+ });
6173
+ window.addEventListener("touchend", (event) => {
6174
+ if (event.changedTouches.length === 0) return;
6175
+ handlePointerUp(event.changedTouches[0].clientX, event.changedTouches[0].clientY);
6027
6176
  }, {
6028
6177
  signal: eventListenerSignal
6029
6178
  });
@@ -6095,7 +6244,7 @@ ${plainTextContentOnly}` : plainTextContentOnly;
6095
6244
  return isRendererActive() && !isDragging() && Boolean(targetElement());
6096
6245
  });
6097
6246
  const progressVisible = createMemo(() => isCopying() && showProgressIndicator() && hasValidMousePosition());
6098
- const crosshairVisible = createMemo(() => theme().crosshair.enabled && isRendererActive() && !isDragging());
6247
+ const crosshairVisible = createMemo(() => theme().crosshair.enabled && isRendererActive() && !isDragging() && !isTouchMode());
6099
6248
  const inputVisible = createMemo(() => theme().inputOverlay.enabled && isInputMode());
6100
6249
  const shouldShowGrabbedBoxes = createMemo(() => theme().grabbedBoxes.enabled);
6101
6250
  const shouldShowSuccessLabels = createMemo(() => theme().successLabels.enabled);
@@ -6183,21 +6332,16 @@ ${plainTextContentOnly}` : plainTextContentOnly;
6183
6332
  const copyElementAPI = async (elements) => {
6184
6333
  const elementsArray = Array.isArray(elements) ? elements : [elements];
6185
6334
  if (elementsArray.length === 0) return false;
6186
- try {
6187
- await options.onBeforeCopy?.(elementsArray);
6188
- } catch {
6189
- }
6335
+ await options.onBeforeCopy?.(elementsArray);
6190
6336
  const didCopy = await tryCopyWithFallback(elementsArray);
6191
- try {
6192
- options.onAfterCopy?.(elementsArray, didCopy);
6193
- } catch {
6194
- }
6337
+ options.onAfterCopy?.(elementsArray, didCopy);
6195
6338
  return didCopy;
6196
6339
  };
6197
6340
  const getStateAPI = () => ({
6198
6341
  isActive: isActivated(),
6199
6342
  isDragging: isDragging(),
6200
6343
  isCopying: isCopying(),
6344
+ isInputMode: isInputMode(),
6201
6345
  targetElement: targetElement(),
6202
6346
  dragBounds: dragBounds() ? {
6203
6347
  x: dragBounds().x,
@@ -6300,4 +6444,4 @@ bippy/dist/source.js:
6300
6444
  *)
6301
6445
  */
6302
6446
 
6303
- export { DEFAULT_THEME, Ee, formatStack, getHTMLPreview, getNearestComponentName, getStack, init };
6447
+ export { DEFAULT_THEME, Ee, formatStack, getFileName, getHTMLPreview, getNearestComponentName, getStack, init };