@vite-plugin-opencode-assistant/components 1.0.33 → 1.0.34

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.
@@ -1225,6 +1225,17 @@ function useWidget(options) {
1225
1225
  }
1226
1226
  //#endregion
1227
1227
  //#region es/open-code-widget/composables/use-inspector.js
1228
+ var IGNORE_SELECTORS = [
1229
+ "#vue-inspector-container",
1230
+ ".opencode-widget",
1231
+ ".opencode-element-highlight",
1232
+ ".opencode-element-tooltip",
1233
+ ".opencode-select-mode-hint",
1234
+ ".floating-bubble"
1235
+ ];
1236
+ var IGNORE_ATTRIBUTE = "data-v-inspector-ignore";
1237
+ var KEY_PROPS_DATA = "__v_inspector";
1238
+ var KEY_DATA = "data-v-inspector";
1228
1239
  function throttle(fn, delay) {
1229
1240
  let lastCall = 0;
1230
1241
  let rafId = null;
@@ -1271,67 +1282,26 @@ function isStateClass(className) {
1271
1282
  if (/^(?:router-link|nuxt-link)/.test(className)) return true;
1272
1283
  return false;
1273
1284
  }
1274
- function filterStateClasses(classes) {
1275
- return classes.filter((cls) => !isStateClass(cls));
1276
- }
1277
1285
  function getElementDescription(element) {
1278
- try {
1279
- return (0, css_selector_generator.default)(element, {
1280
- selectors: [
1281
- "id",
1282
- "class",
1283
- "tag",
1284
- "nthchild"
1285
- ],
1286
- combineWithinSelector: true,
1287
- combineBetweenSelectors: true,
1288
- maxCombinations: 100,
1289
- maxCandidates: 100,
1290
- blacklist: [(selectorValue) => {
1291
- const idMatch = selectorValue.match(/^#(.+)$/);
1292
- if (idMatch) return isDynamicId(idMatch[1]);
1293
- const classMatch = selectorValue.match(/^\.([a-zA-Z_-][\w-]*)$/);
1294
- if (classMatch) return isStateClass(classMatch[1]);
1295
- return false;
1296
- }]
1297
- });
1298
- } catch (e) {
1299
- const parts = [element.tagName.toLowerCase()];
1300
- const id = element.id;
1301
- if (id && !isDynamicId(id)) parts.push(`#${id}`);
1302
- const className = element.className;
1303
- if (typeof className === "string") {
1304
- const classes = filterStateClasses(className.trim().split(/\s+/).filter(Boolean)).slice(0, 2);
1305
- if (classes.length > 0) parts.push(`.${classes.join(".")}`);
1306
- } else {
1307
- const svgClass = className.baseVal;
1308
- if (svgClass) {
1309
- const classes = filterStateClasses(svgClass.trim().split(/\s+/).filter(Boolean)).slice(0, 2);
1310
- if (classes.length > 0) parts.push(`.${classes.join(".")}`);
1311
- }
1312
- }
1313
- const name = element.getAttribute("name");
1314
- if (name) parts.push(`[name="${name}"]`);
1315
- const placeholder = element.getAttribute("placeholder");
1316
- if (placeholder) parts.push(`[placeholder="${placeholder.substring(0, 20)}"]`);
1317
- if (element.getAttribute("src")) parts.push(`[src]`);
1318
- const href = element.getAttribute("href");
1319
- if (href && href !== "#") parts.push(`[href]`);
1320
- return parts.join("");
1321
- }
1322
- }
1323
- function getFileInfoFromAttributes(element) {
1324
- const file = element.getAttribute("data-v-inspector-file");
1325
- if (file) {
1326
- const line = element.getAttribute("data-v-inspector-line");
1327
- const column = element.getAttribute("data-v-inspector-column");
1328
- return {
1329
- file,
1330
- line: line ? parseInt(line, 10) : null,
1331
- column: column ? parseInt(column, 10) : null
1332
- };
1333
- }
1334
- return null;
1286
+ return (0, css_selector_generator.default)(element, {
1287
+ selectors: [
1288
+ "id",
1289
+ "class",
1290
+ "tag",
1291
+ "nthchild"
1292
+ ],
1293
+ combineWithinSelector: true,
1294
+ combineBetweenSelectors: true,
1295
+ maxCombinations: 100,
1296
+ maxCandidates: 100,
1297
+ blacklist: [(selectorValue) => {
1298
+ const idMatch = selectorValue.match(/^#(.+)$/);
1299
+ if (idMatch) return isDynamicId(idMatch[1]);
1300
+ const classMatch = selectorValue.match(/^\.([a-zA-Z_-][\w-]*)$/);
1301
+ if (classMatch) return isStateClass(classMatch[1]);
1302
+ return false;
1303
+ }]
1304
+ });
1335
1305
  }
1336
1306
  function getFileInfoFromVueInstance(element) {
1337
1307
  var _a, _b, _c, _d;
@@ -1363,51 +1333,68 @@ function getFileInfoFromVueInstance(element) {
1363
1333
  }
1364
1334
  return null;
1365
1335
  }
1366
- function findFileInfo(element, inspector) {
1336
+ function shouldIgnoreElement(el) {
1337
+ if (el.hasAttribute(IGNORE_ATTRIBUTE)) return true;
1338
+ for (const selector of IGNORE_SELECTORS) if (el.closest(selector)) return true;
1339
+ return false;
1340
+ }
1341
+ function getDataFromElement(el) {
1367
1342
  var _a, _b;
1343
+ const vnodeData = (_b = (_a = el.__vnode) == null ? void 0 : _a.props) == null ? void 0 : _b[KEY_PROPS_DATA];
1344
+ if (vnodeData) return vnodeData;
1345
+ const attr = el.getAttribute(KEY_DATA);
1346
+ return attr != null ? attr : void 0;
1347
+ }
1348
+ function findInspectorFileInfo(element) {
1368
1349
  let current = element;
1369
- let fallbackFileInfo = null;
1370
1350
  while (current) {
1371
- const attrInfo = getFileInfoFromAttributes(current);
1372
- if (attrInfo && attrInfo.line !== null) return attrInfo;
1373
- if (attrInfo && !fallbackFileInfo) fallbackFileInfo = attrInfo;
1374
- const fakeEvent = {
1375
- clientX: 0,
1376
- clientY: 0,
1377
- target: current,
1378
- currentTarget: current
1379
- };
1380
- const { params } = inspector.getTargetNode(fakeEvent);
1381
- if (params && params.file) {
1382
- const info = {
1383
- file: params.file,
1384
- line: (_a = params.line) != null ? _a : null,
1385
- column: (_b = params.column) != null ? _b : null
1351
+ const data = getDataFromElement(current);
1352
+ if (data) {
1353
+ const match = data.match(/(.+):([\d]+):([\d]+)$/);
1354
+ if (match) return {
1355
+ file: match[1],
1356
+ line: parseInt(match[2], 10),
1357
+ column: parseInt(match[3], 10)
1386
1358
  };
1387
- if (info.line !== null) return info;
1388
- if (!fallbackFileInfo) fallbackFileInfo = info;
1389
1359
  }
1390
- const vueInfo = getFileInfoFromVueInstance(current);
1391
- if (vueInfo && !fallbackFileInfo) fallbackFileInfo = vueInfo;
1392
1360
  current = current.parentElement;
1393
1361
  }
1394
- return fallbackFileInfo || {
1362
+ return null;
1363
+ }
1364
+ function mergeFileInfo(inspectorFileInfo, vueFileInfo) {
1365
+ if (!(inspectorFileInfo == null ? void 0 : inspectorFileInfo.file) && !(vueFileInfo == null ? void 0 : vueFileInfo.file)) return {
1395
1366
  file: null,
1396
1367
  line: null,
1397
1368
  column: null
1398
1369
  };
1370
+ const isNodeModules = (path) => path.includes("node_modules");
1371
+ if ((inspectorFileInfo == null ? void 0 : inspectorFileInfo.file) && (vueFileInfo == null ? void 0 : vueFileInfo.file)) if (!isNodeModules(inspectorFileInfo.file)) return inspectorFileInfo;
1372
+ else if (!isNodeModules(vueFileInfo.file)) return vueFileInfo;
1373
+ else return inspectorFileInfo;
1374
+ else if (inspectorFileInfo == null ? void 0 : inspectorFileInfo.file) return inspectorFileInfo;
1375
+ else return vueFileInfo;
1399
1376
  }
1400
- function getPreciseElementAtPoint(x, y, boundary) {
1401
- const elements = document.elementsFromPoint(x, y);
1402
- for (const el of elements) {
1403
- if (el.closest("#vue-inspector-container")) continue;
1404
- if (el.closest(".opencode-widget")) continue;
1405
- if (el.hasAttribute("data-v-inspector-ignore")) continue;
1406
- if (boundary) {
1407
- if (boundary.contains(el) || el === boundary) return el;
1408
- } else return el;
1377
+ function getTargetElement(e) {
1378
+ if (!e.target || !(e.target instanceof Element)) return null;
1379
+ const el = e.target;
1380
+ if (shouldIgnoreElement(el)) return null;
1381
+ return el;
1382
+ }
1383
+ function getFileInfo(e, element) {
1384
+ var _a, _b;
1385
+ const inspector = window.__VUE_INSPECTOR__;
1386
+ let inspectorFileInfo = null;
1387
+ if (inspector) {
1388
+ const { targetNode, params } = inspector.getTargetNode(e);
1389
+ if (targetNode && params && params.file) inspectorFileInfo = {
1390
+ file: params.file,
1391
+ line: (_a = params.line) != null ? _a : null,
1392
+ column: (_b = params.column) != null ? _b : null
1393
+ };
1409
1394
  }
1410
- return null;
1395
+ if (element && !inspectorFileInfo) inspectorFileInfo = findInspectorFileInfo(element);
1396
+ const vueFileInfo = element ? getFileInfoFromVueInstance(element) : null;
1397
+ return mergeFileInfo(inspectorFileInfo, vueFileInfo);
1411
1398
  }
1412
1399
  function useInspector(options) {
1413
1400
  const highlightVisible = (0, vue.ref)(false);
@@ -1428,79 +1415,48 @@ function useInspector(options) {
1428
1415
  });
1429
1416
  const INSPECTOR_CHECK_INTERVAL = 500;
1430
1417
  let inspectorCheckTimer = null;
1431
- let currentHighlightElement = null;
1432
- let currentFileInfo = {
1433
- file: null,
1434
- line: null,
1435
- column: null
1436
- };
1437
1418
  let currentPrimary = "#3b82f6";
1438
1419
  let currentPrimaryBg = "rgba(59, 130, 246, 0.1)";
1439
- let currentDescription = "";
1440
- let currentFileInfoText = "";
1420
+ function setPointerEventsNone(elements) {
1421
+ elements.forEach((el) => {
1422
+ if (el) el.style.pointerEvents = "none";
1423
+ });
1424
+ }
1425
+ function setPointerEventsAuto(elements) {
1426
+ elements.forEach((el) => {
1427
+ if (el) el.style.pointerEvents = "";
1428
+ });
1429
+ }
1441
1430
  function handleMouseMoveCore(e) {
1442
- var _a, _b;
1443
1431
  if (!options.selectMode.value) return;
1444
- const inspector = window.__VUE_INSPECTOR__;
1445
- const highlight = document.querySelector(".opencode-element-highlight");
1446
- const tooltip = document.querySelector(".opencode-element-tooltip");
1447
- if (highlight) highlight.style.pointerEvents = "none";
1448
- if (tooltip) tooltip.style.pointerEvents = "none";
1449
- let elementToHighlight = null;
1450
- let targetNode;
1451
- let fileInfo = {
1452
- file: null,
1453
- line: null,
1454
- column: null
1455
- };
1456
- try {
1457
- if (inspector) {
1458
- const result = inspector.getTargetNode(e);
1459
- targetNode = result.targetNode;
1460
- const params = result.params;
1461
- if (targetNode) {
1462
- elementToHighlight = getPreciseElementAtPoint(e.clientX, e.clientY, targetNode) || targetNode;
1463
- if (params && params.file) fileInfo = {
1464
- file: params.file,
1465
- line: (_a = params.line) != null ? _a : null,
1466
- column: (_b = params.column) != null ? _b : null
1467
- };
1468
- else fileInfo = findFileInfo(targetNode, inspector);
1469
- }
1470
- }
1471
- if (!elementToHighlight) elementToHighlight = getPreciseElementAtPoint(e.clientX, e.clientY, null);
1472
- if (elementToHighlight && !fileInfo.file) fileInfo = getFileInfoFromVueInstance(elementToHighlight) || fileInfo;
1473
- } finally {
1474
- if (highlight) highlight.style.pointerEvents = "";
1475
- if (tooltip) tooltip.style.pointerEvents = "";
1476
- }
1432
+ const uiElements = [
1433
+ document.querySelector(".opencode-element-highlight"),
1434
+ document.querySelector(".opencode-element-tooltip"),
1435
+ document.querySelector(".opencode-select-mode-hint"),
1436
+ document.querySelector(".floating-bubble")
1437
+ ];
1438
+ setPointerEventsNone(uiElements);
1439
+ const elementToHighlight = getTargetElement(e);
1440
+ const fileInfo = getFileInfo(e, elementToHighlight);
1441
+ setPointerEventsAuto(uiElements);
1477
1442
  if (elementToHighlight) {
1478
- const elementChanged = currentHighlightElement !== elementToHighlight;
1479
- if (elementChanged) {
1480
- currentHighlightElement = elementToHighlight;
1481
- currentFileInfo = fileInfo;
1482
- const widget = document.querySelector(".opencode-widget");
1483
- if (widget) {
1484
- const style = getComputedStyle(widget);
1485
- currentPrimary = style.getPropertyValue("--oc-primary").trim() || currentPrimary;
1486
- currentPrimaryBg = style.getPropertyValue("--oc-primary-bg").trim() || currentPrimaryBg;
1487
- }
1488
- currentDescription = getElementDescription(elementToHighlight);
1489
- } else if (!currentFileInfo.file && fileInfo.file) currentFileInfo = fileInfo;
1490
- const fileName = currentFileInfo.file ? currentFileInfo.file.split("/").pop() : "";
1491
- let lineInfo = "";
1492
- if (currentFileInfo.line) {
1493
- lineInfo = `:${currentFileInfo.line}`;
1494
- if (currentFileInfo.column) lineInfo += `:${currentFileInfo.column}`;
1443
+ const widget = document.querySelector(".opencode-widget");
1444
+ if (widget) {
1445
+ const style = getComputedStyle(widget);
1446
+ currentPrimary = style.getPropertyValue("--oc-primary").trim() || currentPrimary;
1447
+ currentPrimaryBg = style.getPropertyValue("--oc-primary-bg").trim() || currentPrimaryBg;
1495
1448
  }
1496
- const newFileInfoText = fileName ? `${fileName}${lineInfo}` : "";
1497
- if (elementChanged || currentFileInfoText !== newFileInfoText) {
1498
- currentFileInfoText = newFileInfoText;
1499
- tooltipContent.value = {
1500
- description: currentDescription,
1501
- fileInfo: currentFileInfoText
1502
- };
1449
+ const description = getElementDescription(elementToHighlight);
1450
+ const fileName = fileInfo.file ? fileInfo.file.split("/").pop() : "";
1451
+ let lineInfo = "";
1452
+ if (fileInfo.line) {
1453
+ lineInfo = `:${fileInfo.line}`;
1454
+ if (fileInfo.column) lineInfo += `:${fileInfo.column}`;
1503
1455
  }
1456
+ tooltipContent.value = {
1457
+ description,
1458
+ fileInfo: fileName ? `${fileName}${lineInfo}` : ""
1459
+ };
1504
1460
  const rect = elementToHighlight.getBoundingClientRect();
1505
1461
  const newTop = `${rect.top}px`;
1506
1462
  const newLeft = `${rect.left}px`;
@@ -1516,29 +1472,24 @@ function useInspector(options) {
1516
1472
  };
1517
1473
  const tooltipHeight = 50;
1518
1474
  const tooltipWidth = 200;
1475
+ const margin = 10;
1519
1476
  let tooltipTop = rect.top - tooltipHeight - 8;
1520
1477
  let tooltipLeft = rect.left;
1521
- if (tooltipTop < 10) tooltipTop = rect.bottom + 8;
1522
- if (tooltipLeft + tooltipWidth > window.innerWidth - 10) tooltipLeft = window.innerWidth - tooltipWidth - 10;
1478
+ if (tooltipTop < margin) tooltipTop = rect.bottom + 8;
1479
+ if (tooltipTop + tooltipHeight > window.innerHeight - margin) tooltipTop = Math.max(margin, rect.top - tooltipHeight - 8);
1480
+ if (tooltipLeft < margin) tooltipLeft = margin;
1481
+ if (tooltipLeft + tooltipWidth > window.innerWidth - margin) tooltipLeft = window.innerWidth - tooltipWidth - margin;
1523
1482
  const newTooltipTop = `${tooltipTop}px`;
1524
1483
  const newTooltipLeft = `${tooltipLeft}px`;
1525
1484
  if (tooltipStyle.value.top !== newTooltipTop || tooltipStyle.value.left !== newTooltipLeft) tooltipStyle.value = {
1526
1485
  top: newTooltipTop,
1527
1486
  left: newTooltipLeft
1528
1487
  };
1529
- if (!highlightVisible.value) highlightVisible.value = true;
1530
- if (!tooltipVisible.value) tooltipVisible.value = true;
1488
+ highlightVisible.value = true;
1489
+ tooltipVisible.value = true;
1531
1490
  } else {
1532
- currentHighlightElement = null;
1533
- currentDescription = "";
1534
- currentFileInfoText = "";
1535
- currentFileInfo = {
1536
- file: null,
1537
- line: null,
1538
- column: null
1539
- };
1540
- if (highlightVisible.value) highlightVisible.value = false;
1541
- if (tooltipVisible.value) tooltipVisible.value = false;
1491
+ highlightVisible.value = false;
1492
+ tooltipVisible.value = false;
1542
1493
  }
1543
1494
  }
1544
1495
  const handleMouseMove = throttle(handleMouseMoveCore, 16);
@@ -1547,28 +1498,11 @@ function useInspector(options) {
1547
1498
  if (!inspector || inspector.__opencode_hooked) return;
1548
1499
  const originalHandleClick = inspector.handleClick.bind(inspector);
1549
1500
  inspector.handleClick = function(e) {
1550
- var _a, _b;
1551
1501
  if (options.selectMode.value) {
1552
1502
  e.preventDefault();
1553
1503
  e.stopPropagation();
1554
- let elementToSelect = null;
1555
- let fileInfo = {
1556
- file: null,
1557
- line: null,
1558
- column: null
1559
- };
1560
- const { targetNode, params } = inspector.getTargetNode(e);
1561
- if (targetNode) {
1562
- elementToSelect = getPreciseElementAtPoint(e.clientX, e.clientY, targetNode) || targetNode;
1563
- if (params && params.file) fileInfo = {
1564
- file: params.file,
1565
- line: (_a = params.line) != null ? _a : null,
1566
- column: (_b = params.column) != null ? _b : null
1567
- };
1568
- else if (elementToSelect) fileInfo = findFileInfo(elementToSelect, inspector);
1569
- }
1570
- if (!elementToSelect) elementToSelect = getPreciseElementAtPoint(e.clientX, e.clientY, null);
1571
- if (elementToSelect && !fileInfo.file) fileInfo = getFileInfoFromVueInstance(elementToSelect) || fileInfo;
1504
+ const elementToSelect = getTargetElement(e);
1505
+ const fileInfo = getFileInfo(e, elementToSelect);
1572
1506
  if (elementToSelect) {
1573
1507
  const innerText = getDirectText(elementToSelect);
1574
1508
  const description = getElementDescription(elementToSelect);
@@ -1604,14 +1538,6 @@ function useInspector(options) {
1604
1538
  if (inspector) inspector.disable();
1605
1539
  document.removeEventListener("mousemove", handleMouseMove);
1606
1540
  document.removeEventListener("keydown", handleKeydown, true);
1607
- currentHighlightElement = null;
1608
- currentDescription = "";
1609
- currentFileInfoText = "";
1610
- currentFileInfo = {
1611
- file: null,
1612
- line: null,
1613
- column: null
1614
- };
1615
1541
  highlightVisible.value = false;
1616
1542
  tooltipVisible.value = false;
1617
1543
  }
@@ -2417,7 +2343,7 @@ __vue_sfc__.render = __vue_render__;
2417
2343
  var open_code_widget_default = __vue_sfc__;
2418
2344
  //#endregion
2419
2345
  //#region es/index.js
2420
- var version = "1.0.33";
2346
+ var version = "1.0.34";
2421
2347
  function install(app, options) {
2422
2348
  [open_code_widget_default].forEach((item) => {
2423
2349
  if (item.install) app.use(item, options);