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.
@@ -3806,11 +3806,8 @@ var InputOverlay = (props) => {
3806
3806
  const handleInput = (event) => {
3807
3807
  const target = event.target;
3808
3808
  props.onInput(target.value);
3809
- autoResizeTextarea(target);
3810
- };
3811
- const autoResizeTextarea = (textarea) => {
3812
- textarea.style.height = "auto";
3813
- textarea.style.height = `${textarea.scrollHeight}px`;
3809
+ target.style.height = "auto";
3810
+ target.style.height = `${target.scrollHeight}px`;
3814
3811
  };
3815
3812
  createEffect(() => {
3816
3813
  if (props.visible && inputRef) {
@@ -4948,6 +4945,14 @@ var formatStack = (stack) => {
4948
4945
  return framePart;
4949
4946
  }).join("\n");
4950
4947
  };
4948
+ var getFileName = (stack) => {
4949
+ for (const frame of stack) {
4950
+ if (frame.source && je2(frame.source.fileName)) {
4951
+ return Q(frame.source.fileName);
4952
+ }
4953
+ }
4954
+ return null;
4955
+ };
4951
4956
  var getHTMLPreview = (element) => {
4952
4957
  const tagName = element.tagName.toLowerCase();
4953
4958
  if (!(element instanceof HTMLElement)) {
@@ -5240,6 +5245,59 @@ var createElementBounds = (element) => {
5240
5245
  };
5241
5246
  };
5242
5247
 
5248
+ // src/utils/is-c-like-key.ts
5249
+ var C_LIKE_CHARACTERS = /* @__PURE__ */ new Set([
5250
+ "c",
5251
+ "C",
5252
+ "\u0441",
5253
+ // Cyrillic small es
5254
+ "\u0421",
5255
+ // Cyrillic capital es
5256
+ "\u023C",
5257
+ // c with stroke
5258
+ "\u023B",
5259
+ // C with stroke
5260
+ "\u2184",
5261
+ // reversed c
5262
+ "\u2183",
5263
+ // reversed C
5264
+ "\u1D04",
5265
+ // modifier small c
5266
+ "\u1D9C",
5267
+ // modifier small c turned
5268
+ "\u2C7C",
5269
+ // latin small c with palatal hook
5270
+ "\u217D",
5271
+ // small roman numeral 100
5272
+ "\u216D",
5273
+ // capital roman numeral 100
5274
+ "\xE7",
5275
+ // c with cedilla
5276
+ "\xC7",
5277
+ // C with cedilla
5278
+ "\u0107",
5279
+ // c with acute
5280
+ "\u0106",
5281
+ // C with acute
5282
+ "\u010D",
5283
+ // c with caron
5284
+ "\u010C",
5285
+ // C with caron
5286
+ "\u0109",
5287
+ // c with circumflex
5288
+ "\u0108",
5289
+ // C with circumflex
5290
+ "\u010B",
5291
+ // c with dot above
5292
+ "\u010A"
5293
+ // C with dot above
5294
+ ]);
5295
+ var isCLikeKey = (key, code) => {
5296
+ if (code === "KeyC") return true;
5297
+ if (!key || key.length !== 1) return false;
5298
+ return C_LIKE_CHARACTERS.has(key);
5299
+ };
5300
+
5243
5301
  // src/theme.ts
5244
5302
  var DEFAULT_THEME = {
5245
5303
  enabled: true,
@@ -5357,11 +5415,23 @@ var _tmpl$9 = /* @__PURE__ */ template(`<span class="font-mono tabular-nums alig
5357
5415
  var _tmpl$23 = /* @__PURE__ */ template(`<span class="font-mono tabular-nums align-middle">&lt;<!>>`);
5358
5416
  var _tmpl$33 = /* @__PURE__ */ template(`<span class="tabular-nums text-[10px] ml-1 align-middle"> in `);
5359
5417
  var hasInited = false;
5418
+ var getScriptOptions = () => {
5419
+ if (typeof window === "undefined") return null;
5420
+ try {
5421
+ const dataOptions = document.currentScript?.getAttribute("data-options");
5422
+ if (!dataOptions) return null;
5423
+ return JSON.parse(dataOptions);
5424
+ } catch {
5425
+ return null;
5426
+ }
5427
+ };
5360
5428
  var init = (rawOptions) => {
5429
+ const scriptOptions = getScriptOptions();
5361
5430
  const options = {
5362
5431
  enabled: true,
5363
5432
  keyHoldDuration: 200,
5364
5433
  allowActivationInsideInput: true,
5434
+ ...scriptOptions,
5365
5435
  ...rawOptions
5366
5436
  };
5367
5437
  const initialTheme = mergeTheme(options.theme);
@@ -5381,6 +5451,7 @@ var init = (rawOptions) => {
5381
5451
  isActive: false,
5382
5452
  isDragging: false,
5383
5453
  isCopying: false,
5454
+ isInputMode: false,
5384
5455
  targetElement: null,
5385
5456
  dragBounds: null
5386
5457
  }),
@@ -5392,7 +5463,7 @@ var init = (rawOptions) => {
5392
5463
  hasInited = true;
5393
5464
  const logIntro = () => {
5394
5465
  try {
5395
- const version = "0.0.52";
5466
+ const version = "0.0.54";
5396
5467
  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>`;
5397
5468
  const logoDataUri = `data:image/svg+xml;base64,${btoa(logoSvg)}`;
5398
5469
  console.log(`%cReact Grab${version ? ` v${version}` : ""}%c
@@ -5412,7 +5483,9 @@ https://react-grab.com`, `background: #330039; color: #ffffff; border: 1px solid
5412
5483
  } catch {
5413
5484
  }
5414
5485
  };
5415
- logIntro();
5486
+ if (options.log !== false) {
5487
+ logIntro();
5488
+ }
5416
5489
  return createRoot((dispose2) => {
5417
5490
  const [theme, setTheme] = createSignal(initialTheme);
5418
5491
  const [isHoldingKeys, setIsHoldingKeys] = createSignal(false);
@@ -5437,18 +5510,17 @@ https://react-grab.com`, `background: #330039; color: #ffffff; border: 1px solid
5437
5510
  const [viewportVersion, setViewportVersion] = createSignal(0);
5438
5511
  const [isInputMode, setIsInputMode] = createSignal(false);
5439
5512
  const [inputText, setInputText] = createSignal("");
5513
+ const [isTouchMode, setIsTouchMode] = createSignal(false);
5440
5514
  let holdTimerId = null;
5441
5515
  let progressAnimationId = null;
5442
5516
  let progressDelayTimerId = null;
5443
5517
  let keydownSpamTimerId = null;
5444
5518
  let mouseSettleTimerId = null;
5445
5519
  let autoScrollAnimationId = null;
5520
+ let previouslyFocusedElement = null;
5446
5521
  const isRendererActive = createMemo(() => isActivated() && !isCopying());
5447
5522
  const hasValidMousePosition = createMemo(() => mouseX() > OFFSCREEN_POSITION && mouseY() > OFFSCREEN_POSITION);
5448
- const isTargetKeyCombination = (event) => (
5449
- // NOTE: we use event.code instead of event.key for keyboard layout compatibility (e.g., AZERTY, QWERTZ)
5450
- (event.metaKey || event.ctrlKey) && event.code === "KeyC"
5451
- );
5523
+ const isTargetKeyCombination = (event) => (event.metaKey || event.ctrlKey) && isCLikeKey(event.key, event.code);
5452
5524
  const getAutoScrollDirection = (clientX, clientY) => {
5453
5525
  return {
5454
5526
  top: clientY < AUTO_SCROLL_EDGE_THRESHOLD_PX,
@@ -5468,16 +5540,21 @@ https://react-grab.com`, `background: #330039; color: #ffffff; border: 1px solid
5468
5540
  };
5469
5541
  const currentBoxes = grabbedBoxes();
5470
5542
  setGrabbedBoxes([...currentBoxes, newBox]);
5543
+ options.onGrabbedBox?.(bounds, element);
5471
5544
  setTimeout(() => {
5472
5545
  setGrabbedBoxes((previousBoxes) => previousBoxes.filter((box) => box.id !== boxId));
5473
5546
  }, SUCCESS_LABEL_DURATION_MS);
5474
5547
  };
5475
- const showTemporarySuccessLabel = (text) => {
5548
+ const showTemporarySuccessLabel = (text, type) => {
5476
5549
  const labelId = `success-${Date.now()}-${Math.random()}`;
5477
5550
  setSuccessLabels((previousLabels) => [...previousLabels, {
5478
5551
  id: labelId,
5479
5552
  text
5480
5553
  }]);
5554
+ options.onSuccessLabel?.(text, type, {
5555
+ x: mouseX(),
5556
+ y: mouseY()
5557
+ });
5481
5558
  setTimeout(() => {
5482
5559
  setSuccessLabels((previousLabels) => previousLabels.filter((label) => label.id !== labelId));
5483
5560
  }, SUCCESS_LABEL_DURATION_MS);
@@ -5491,17 +5568,14 @@ ${context}
5491
5568
  return tagName ? `<${tagName}>` : "1 element";
5492
5569
  };
5493
5570
  const notifyElementsSelected = (elements) => {
5494
- try {
5495
- const elementsPayload = elements.map((element) => ({
5496
- tagName: extractElementTagName(element)
5497
- }));
5498
- window.dispatchEvent(new CustomEvent("react-grab:element-selected", {
5499
- detail: {
5500
- elements: elementsPayload
5501
- }
5502
- }));
5503
- } catch {
5504
- }
5571
+ const elementsPayload = elements.map((element) => ({
5572
+ tagName: extractElementTagName(element)
5573
+ }));
5574
+ window.dispatchEvent(new CustomEvent("react-grab:element-selected", {
5575
+ detail: {
5576
+ elements: elementsPayload
5577
+ }
5578
+ }));
5505
5579
  };
5506
5580
  const executeCopyOperation = async (positionX, positionY, operation) => {
5507
5581
  setCopyStartX(positionX);
@@ -5528,9 +5602,26 @@ ${context}
5528
5602
  let didCopy = false;
5529
5603
  let copiedContent = "";
5530
5604
  const isReactProject = Ee();
5531
- try {
5532
- await options.onBeforeCopy?.(elements);
5533
- } catch {
5605
+ await options.onBeforeCopy?.(elements);
5606
+ if (options.copyFileOnly && isReactProject) {
5607
+ try {
5608
+ const firstElement = elements[0];
5609
+ if (firstElement) {
5610
+ const stack = await getStack(firstElement);
5611
+ const fileName = getFileName(stack);
5612
+ if (fileName) {
5613
+ copiedContent = `@${fileName}`;
5614
+ didCopy = await copyContent(copiedContent);
5615
+ if (didCopy) {
5616
+ options.onCopySuccess?.(elements, copiedContent);
5617
+ }
5618
+ }
5619
+ }
5620
+ } catch (error) {
5621
+ options.onCopyError?.(error);
5622
+ }
5623
+ options.onAfterCopy?.(elements, didCopy);
5624
+ return didCopy;
5534
5625
  }
5535
5626
  try {
5536
5627
  const elementSnippetResults = await Promise.allSettled(elements.map(async (element) => {
@@ -5571,16 +5662,10 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5571
5662
  }
5572
5663
  }
5573
5664
  if (didCopy) {
5574
- try {
5575
- options.onCopySuccess?.(elements, copiedContent);
5576
- } catch {
5577
- }
5665
+ options.onCopySuccess?.(elements, copiedContent);
5578
5666
  }
5579
5667
  } catch (error) {
5580
- try {
5581
- options.onCopyError?.(error);
5582
- } catch {
5583
- }
5668
+ options.onCopyError?.(error);
5584
5669
  const plainTextContentOnly = createCombinedTextContent(elements);
5585
5670
  if (plainTextContentOnly.length > 0) {
5586
5671
  const contentWithPrompt = extraPrompt ? `${extraPrompt}
@@ -5590,34 +5675,26 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5590
5675
  didCopy = await copyContent(contentWithPrompt);
5591
5676
  }
5592
5677
  }
5593
- try {
5594
- options.onAfterCopy?.(elements, didCopy);
5595
- } catch {
5596
- }
5678
+ options.onAfterCopy?.(elements, didCopy);
5597
5679
  return didCopy;
5598
5680
  };
5599
5681
  const copySingleElementToClipboard = async (targetElement2, extraPrompt) => {
5600
- try {
5601
- options.onElementSelect?.(targetElement2);
5602
- } catch {
5603
- }
5682
+ const successLabelType = extraPrompt ? "input-submit" : "copy";
5683
+ options.onElementSelect?.(targetElement2);
5604
5684
  if (theme().grabbedBoxes.enabled) {
5605
5685
  showTemporaryGrabbedBox(createElementBounds(targetElement2), targetElement2);
5606
5686
  }
5607
5687
  await new Promise((resolve) => requestAnimationFrame(resolve));
5608
5688
  const didCopy = await tryCopyWithFallback([targetElement2], extraPrompt);
5609
5689
  if (didCopy && theme().successLabels.enabled) {
5610
- showTemporarySuccessLabel(extractElementTagNameForSuccess(targetElement2));
5690
+ showTemporarySuccessLabel(extractElementTagNameForSuccess(targetElement2), successLabelType);
5611
5691
  }
5612
5692
  notifyElementsSelected([targetElement2]);
5613
5693
  };
5614
5694
  const copyMultipleElementsToClipboard = async (targetElements) => {
5615
5695
  if (targetElements.length === 0) return;
5616
5696
  for (const element of targetElements) {
5617
- try {
5618
- options.onElementSelect?.(element);
5619
- } catch {
5620
- }
5697
+ options.onElementSelect?.(element);
5621
5698
  }
5622
5699
  if (theme().grabbedBoxes.enabled) {
5623
5700
  for (const element of targetElements) {
@@ -5627,7 +5704,7 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5627
5704
  await new Promise((resolve) => requestAnimationFrame(resolve));
5628
5705
  const didCopy = await tryCopyWithFallback(targetElements);
5629
5706
  if (didCopy && theme().successLabels.enabled) {
5630
- showTemporarySuccessLabel(`${targetElements.length} elements`);
5707
+ showTemporarySuccessLabel(`${targetElements.length} elements`, "copy");
5631
5708
  }
5632
5709
  notifyElementsSelected(targetElements);
5633
5710
  };
@@ -5733,10 +5810,7 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5733
5810
  setLastGrabbedElement(null);
5734
5811
  }
5735
5812
  if (currentElement) {
5736
- try {
5737
- options.onElementHover?.(currentElement);
5738
- } catch {
5739
- }
5813
+ options.onElementHover?.(currentElement);
5740
5814
  }
5741
5815
  }));
5742
5816
  createEffect(on(() => viewportVersion(), () => {
@@ -5748,22 +5822,47 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5748
5822
  }));
5749
5823
  setGrabbedBoxes(updatedBoxes);
5750
5824
  }));
5751
- createEffect(on(() => [isActivated(), isDragging(), isCopying(), targetElement(), dragBounds()], ([active, dragging, copying, target, drag]) => {
5752
- try {
5753
- options.onStateChange?.({
5754
- isActive: active,
5755
- isDragging: dragging,
5756
- isCopying: copying,
5757
- targetElement: target,
5758
- dragBounds: drag ? {
5759
- x: drag.x,
5760
- y: drag.y,
5761
- width: drag.width,
5762
- height: drag.height
5763
- } : null
5764
- });
5765
- } catch {
5766
- }
5825
+ createEffect(on(() => [isActivated(), isDragging(), isCopying(), isInputMode(), targetElement(), dragBounds()], ([active, dragging, copying, inputMode, target, drag]) => {
5826
+ options.onStateChange?.({
5827
+ isActive: active,
5828
+ isDragging: dragging,
5829
+ isCopying: copying,
5830
+ isInputMode: inputMode,
5831
+ targetElement: target,
5832
+ dragBounds: drag ? {
5833
+ x: drag.x,
5834
+ y: drag.y,
5835
+ width: drag.width,
5836
+ height: drag.height
5837
+ } : null
5838
+ });
5839
+ }));
5840
+ createEffect(on(() => [isInputMode(), mouseX(), mouseY(), targetElement()], ([inputMode, x3, y2, target]) => {
5841
+ options.onInputModeChange?.(inputMode, {
5842
+ x: x3,
5843
+ y: y2,
5844
+ targetElement: target
5845
+ });
5846
+ }));
5847
+ createEffect(on(() => [selectionVisible(), selectionBounds(), targetElement()], ([visible, bounds, element]) => {
5848
+ options.onSelectionBox?.(Boolean(visible), bounds ?? null, element);
5849
+ }));
5850
+ createEffect(on(() => [dragVisible(), dragBounds()], ([visible, bounds]) => {
5851
+ options.onDragBox?.(Boolean(visible), bounds ?? null);
5852
+ }));
5853
+ createEffect(on(() => [crosshairVisible(), mouseX(), mouseY()], ([visible, x3, y2]) => {
5854
+ options.onCrosshair?.(Boolean(visible), {
5855
+ x: x3,
5856
+ y: y2
5857
+ });
5858
+ }));
5859
+ createEffect(on(() => [labelVisible(), labelVariant(), labelContent(), labelPosition()], ([visible, variant, content, position]) => {
5860
+ const contentString = typeof content === "string" ? content : "";
5861
+ options.onElementLabel?.(Boolean(visible), variant, {
5862
+ x: position.x,
5863
+ y: position.y,
5864
+ content: contentString
5865
+ });
5767
5866
  }));
5768
5867
  const startProgressAnimation = () => {
5769
5868
  const startTime = Date.now();
@@ -5828,6 +5927,7 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5828
5927
  };
5829
5928
  const activateRenderer = () => {
5830
5929
  stopProgressAnimation();
5930
+ previouslyFocusedElement = document.activeElement;
5831
5931
  setIsActivated(true);
5832
5932
  document.body.style.cursor = "crosshair";
5833
5933
  options.onActivate?.();
@@ -5852,6 +5952,10 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5852
5952
  setMouseHasSettled(false);
5853
5953
  stopAutoScroll();
5854
5954
  stopProgressAnimation();
5955
+ if (previouslyFocusedElement instanceof HTMLElement && document.contains(previouslyFocusedElement)) {
5956
+ previouslyFocusedElement.focus();
5957
+ }
5958
+ previouslyFocusedElement = null;
5855
5959
  options.onDeactivate?.();
5856
5960
  };
5857
5961
  const handleInputChange = (value) => {
@@ -5877,17 +5981,78 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5877
5981
  if (!isInputMode()) return;
5878
5982
  deactivateRenderer();
5879
5983
  };
5984
+ const handlePointerMove = (clientX, clientY) => {
5985
+ if (isInputMode()) return;
5986
+ setMouseX(clientX);
5987
+ setMouseY(clientY);
5988
+ if (mouseSettleTimerId !== null) {
5989
+ window.clearTimeout(mouseSettleTimerId);
5990
+ }
5991
+ setMouseHasSettled(false);
5992
+ mouseSettleTimerId = window.setTimeout(() => {
5993
+ setMouseHasSettled(true);
5994
+ mouseSettleTimerId = null;
5995
+ }, 300);
5996
+ if (isDragging()) {
5997
+ const direction = getAutoScrollDirection(clientX, clientY);
5998
+ const isNearEdge = direction.top || direction.bottom || direction.left || direction.right;
5999
+ if (isNearEdge && autoScrollAnimationId === null) {
6000
+ startAutoScroll();
6001
+ } else if (!isNearEdge && autoScrollAnimationId !== null) {
6002
+ stopAutoScroll();
6003
+ }
6004
+ }
6005
+ };
6006
+ const handlePointerDown = (clientX, clientY) => {
6007
+ if (!isRendererActive() || isCopying()) return false;
6008
+ setIsDragging(true);
6009
+ const startX = clientX + window.scrollX;
6010
+ const startY = clientY + window.scrollY;
6011
+ setDragStartX(startX);
6012
+ setDragStartY(startY);
6013
+ document.body.style.userSelect = "none";
6014
+ options.onDragStart?.(startX, startY);
6015
+ return true;
6016
+ };
6017
+ const handlePointerUp = (clientX, clientY) => {
6018
+ if (!isDragging()) return;
6019
+ const dragDistance = calculateDragDistance(clientX, clientY);
6020
+ const wasDragGesture = dragDistance.x > DRAG_THRESHOLD_PX || dragDistance.y > DRAG_THRESHOLD_PX;
6021
+ setIsDragging(false);
6022
+ stopAutoScroll();
6023
+ document.body.style.userSelect = "";
6024
+ if (wasDragGesture) {
6025
+ setDidJustDrag(true);
6026
+ const dragRect = calculateDragRectangle(clientX, clientY);
6027
+ const elements = getElementsInDrag(dragRect, isValidGrabbableElement);
6028
+ if (elements.length > 0) {
6029
+ options.onDragEnd?.(elements, dragRect);
6030
+ void executeCopyOperation(clientX, clientY, () => copyMultipleElementsToClipboard(elements));
6031
+ } else {
6032
+ const fallbackElements = getElementsInDragLoose(dragRect, isValidGrabbableElement);
6033
+ if (fallbackElements.length > 0) {
6034
+ options.onDragEnd?.(fallbackElements, dragRect);
6035
+ void executeCopyOperation(clientX, clientY, () => copyMultipleElementsToClipboard(fallbackElements));
6036
+ }
6037
+ }
6038
+ } else {
6039
+ const element = getElementAtPosition(clientX, clientY);
6040
+ if (!element) return;
6041
+ setLastGrabbedElement(element);
6042
+ void executeCopyOperation(clientX, clientY, () => copySingleElementToClipboard(element));
6043
+ }
6044
+ };
5880
6045
  const abortController = new AbortController();
5881
6046
  const eventListenerSignal = abortController.signal;
5882
6047
  window.addEventListener("keydown", (event) => {
5883
- if (event.code === "Escape" && isHoldingKeys()) {
6048
+ if (event.key === "Escape" && isHoldingKeys()) {
5884
6049
  if (isInputMode()) {
5885
6050
  return;
5886
6051
  }
5887
6052
  deactivateRenderer();
5888
6053
  return;
5889
6054
  }
5890
- if (event.code === "Enter" && isHoldingKeys() && !isInputMode()) {
6055
+ if (event.key === "Enter" && isHoldingKeys() && !isInputMode()) {
5891
6056
  event.preventDefault();
5892
6057
  event.stopPropagation();
5893
6058
  setIsToggleMode(true);
@@ -5936,7 +6101,7 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5936
6101
  window.addEventListener("keyup", (event) => {
5937
6102
  if (!isHoldingKeys() && !isActivated()) return;
5938
6103
  const isReleasingModifier = !event.metaKey && !event.ctrlKey;
5939
- const isReleasingC = event.code === "KeyC";
6104
+ const isReleasingC = isCLikeKey(event.key, event.code);
5940
6105
  if (isReleasingC || isReleasingModifier) {
5941
6106
  if (isToggleMode()) return;
5942
6107
  deactivateRenderer();
@@ -5946,26 +6111,8 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5946
6111
  capture: true
5947
6112
  });
5948
6113
  window.addEventListener("mousemove", (event) => {
5949
- if (isInputMode()) return;
5950
- setMouseX(event.clientX);
5951
- setMouseY(event.clientY);
5952
- if (mouseSettleTimerId !== null) {
5953
- window.clearTimeout(mouseSettleTimerId);
5954
- }
5955
- setMouseHasSettled(false);
5956
- mouseSettleTimerId = window.setTimeout(() => {
5957
- setMouseHasSettled(true);
5958
- mouseSettleTimerId = null;
5959
- }, 300);
5960
- if (isDragging()) {
5961
- const direction = getAutoScrollDirection(event.clientX, event.clientY);
5962
- const isNearEdge = direction.top || direction.bottom || direction.left || direction.right;
5963
- if (isNearEdge && autoScrollAnimationId === null) {
5964
- startAutoScroll();
5965
- } else if (!isNearEdge && autoScrollAnimationId !== null) {
5966
- stopAutoScroll();
5967
- }
5968
- }
6114
+ setIsTouchMode(false);
6115
+ handlePointerMove(event.clientX, event.clientY);
5969
6116
  }, {
5970
6117
  signal: eventListenerSignal
5971
6118
  });
@@ -5978,54 +6125,56 @@ ${plainTextContentOnly}` : plainTextContentOnly;
5978
6125
  }
5979
6126
  return;
5980
6127
  }
5981
- if (!isRendererActive() || isCopying()) return;
5982
- event.preventDefault();
5983
- setIsDragging(true);
5984
- const startX = event.clientX + window.scrollX;
5985
- const startY = event.clientY + window.scrollY;
5986
- setDragStartX(startX);
5987
- setDragStartY(startY);
5988
- document.body.style.userSelect = "none";
5989
- try {
5990
- options.onDragStart?.(startX, startY);
5991
- } catch {
6128
+ const didHandle = handlePointerDown(event.clientX, event.clientY);
6129
+ if (didHandle) {
6130
+ event.preventDefault();
5992
6131
  }
5993
6132
  }, {
5994
- signal: eventListenerSignal
6133
+ signal: eventListenerSignal,
6134
+ capture: true
6135
+ });
6136
+ window.addEventListener("pointerdown", (event) => {
6137
+ if (!isRendererActive() || isCopying() || isInputMode()) return;
6138
+ event.stopPropagation();
6139
+ }, {
6140
+ signal: eventListenerSignal,
6141
+ capture: true
5995
6142
  });
5996
6143
  window.addEventListener("mouseup", (event) => {
5997
- if (!isDragging()) return;
5998
- const dragDistance = calculateDragDistance(event.clientX, event.clientY);
5999
- const wasDragGesture = dragDistance.x > DRAG_THRESHOLD_PX || dragDistance.y > DRAG_THRESHOLD_PX;
6000
- setIsDragging(false);
6001
- stopAutoScroll();
6002
- document.body.style.userSelect = "";
6003
- if (wasDragGesture) {
6004
- setDidJustDrag(true);
6005
- const dragRect = calculateDragRectangle(event.clientX, event.clientY);
6006
- const elements = getElementsInDrag(dragRect, isValidGrabbableElement);
6007
- if (elements.length > 0) {
6008
- try {
6009
- options.onDragEnd?.(elements, dragRect);
6010
- } catch {
6011
- }
6012
- void executeCopyOperation(event.clientX, event.clientY, () => copyMultipleElementsToClipboard(elements));
6013
- } else {
6014
- const fallbackElements = getElementsInDragLoose(dragRect, isValidGrabbableElement);
6015
- if (fallbackElements.length > 0) {
6016
- try {
6017
- options.onDragEnd?.(fallbackElements, dragRect);
6018
- } catch {
6019
- }
6020
- void executeCopyOperation(event.clientX, event.clientY, () => copyMultipleElementsToClipboard(fallbackElements));
6021
- }
6144
+ handlePointerUp(event.clientX, event.clientY);
6145
+ }, {
6146
+ signal: eventListenerSignal
6147
+ });
6148
+ window.addEventListener("touchmove", (event) => {
6149
+ if (event.touches.length === 0) return;
6150
+ setIsTouchMode(true);
6151
+ handlePointerMove(event.touches[0].clientX, event.touches[0].clientY);
6152
+ }, {
6153
+ signal: eventListenerSignal,
6154
+ passive: true
6155
+ });
6156
+ window.addEventListener("touchstart", (event) => {
6157
+ if (event.touches.length === 0) return;
6158
+ setIsTouchMode(true);
6159
+ if (isInputMode()) {
6160
+ const target = event.target;
6161
+ const isClickingInput = target.closest("[data-react-grab-input]");
6162
+ if (!isClickingInput) {
6163
+ handleInputCancel();
6022
6164
  }
6023
- } else {
6024
- const element = getElementAtPosition(event.clientX, event.clientY);
6025
- if (!element) return;
6026
- setLastGrabbedElement(element);
6027
- void executeCopyOperation(event.clientX, event.clientY, () => copySingleElementToClipboard(element));
6165
+ return;
6028
6166
  }
6167
+ const didHandle = handlePointerDown(event.touches[0].clientX, event.touches[0].clientY);
6168
+ if (didHandle) {
6169
+ event.preventDefault();
6170
+ }
6171
+ }, {
6172
+ signal: eventListenerSignal,
6173
+ passive: false
6174
+ });
6175
+ window.addEventListener("touchend", (event) => {
6176
+ if (event.changedTouches.length === 0) return;
6177
+ handlePointerUp(event.changedTouches[0].clientX, event.changedTouches[0].clientY);
6029
6178
  }, {
6030
6179
  signal: eventListenerSignal
6031
6180
  });
@@ -6097,7 +6246,7 @@ ${plainTextContentOnly}` : plainTextContentOnly;
6097
6246
  return isRendererActive() && !isDragging() && Boolean(targetElement());
6098
6247
  });
6099
6248
  const progressVisible = createMemo(() => isCopying() && showProgressIndicator() && hasValidMousePosition());
6100
- const crosshairVisible = createMemo(() => theme().crosshair.enabled && isRendererActive() && !isDragging());
6249
+ const crosshairVisible = createMemo(() => theme().crosshair.enabled && isRendererActive() && !isDragging() && !isTouchMode());
6101
6250
  const inputVisible = createMemo(() => theme().inputOverlay.enabled && isInputMode());
6102
6251
  const shouldShowGrabbedBoxes = createMemo(() => theme().grabbedBoxes.enabled);
6103
6252
  const shouldShowSuccessLabels = createMemo(() => theme().successLabels.enabled);
@@ -6185,21 +6334,16 @@ ${plainTextContentOnly}` : plainTextContentOnly;
6185
6334
  const copyElementAPI = async (elements) => {
6186
6335
  const elementsArray = Array.isArray(elements) ? elements : [elements];
6187
6336
  if (elementsArray.length === 0) return false;
6188
- try {
6189
- await options.onBeforeCopy?.(elementsArray);
6190
- } catch {
6191
- }
6337
+ await options.onBeforeCopy?.(elementsArray);
6192
6338
  const didCopy = await tryCopyWithFallback(elementsArray);
6193
- try {
6194
- options.onAfterCopy?.(elementsArray, didCopy);
6195
- } catch {
6196
- }
6339
+ options.onAfterCopy?.(elementsArray, didCopy);
6197
6340
  return didCopy;
6198
6341
  };
6199
6342
  const getStateAPI = () => ({
6200
6343
  isActive: isActivated(),
6201
6344
  isDragging: isDragging(),
6202
6345
  isCopying: isCopying(),
6346
+ isInputMode: isInputMode(),
6203
6347
  targetElement: targetElement(),
6204
6348
  dragBounds: dragBounds() ? {
6205
6349
  x: dragBounds().x,
@@ -6305,6 +6449,7 @@ bippy/dist/source.js:
6305
6449
  exports.DEFAULT_THEME = DEFAULT_THEME;
6306
6450
  exports.Ee = Ee;
6307
6451
  exports.formatStack = formatStack;
6452
+ exports.getFileName = getFileName;
6308
6453
  exports.getHTMLPreview = getHTMLPreview;
6309
6454
  exports.getNearestComponentName = getNearestComponentName;
6310
6455
  exports.getStack = getStack;