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

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,21 +1225,17 @@ function useWidget(options) {
1225
1225
  }
1226
1226
  //#endregion
1227
1227
  //#region es/open-code-widget/composables/use-inspector.js
1228
- function throttle(fn, delay) {
1229
- let lastCall = 0;
1230
- let rafId = null;
1231
- return ((...args) => {
1232
- const now = performance.now();
1233
- if (now - lastCall >= delay) {
1234
- lastCall = now;
1235
- fn(...args);
1236
- } else if (!rafId) rafId = requestAnimationFrame(() => {
1237
- rafId = null;
1238
- lastCall = performance.now();
1239
- fn(...args);
1240
- });
1241
- });
1242
- }
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";
1243
1239
  function getDirectText(element) {
1244
1240
  let text = "";
1245
1241
  for (let i = 0; i < element.childNodes.length; i++) {
@@ -1271,67 +1267,26 @@ function isStateClass(className) {
1271
1267
  if (/^(?:router-link|nuxt-link)/.test(className)) return true;
1272
1268
  return false;
1273
1269
  }
1274
- function filterStateClasses(classes) {
1275
- return classes.filter((cls) => !isStateClass(cls));
1276
- }
1277
1270
  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;
1271
+ return (0, css_selector_generator.default)(element, {
1272
+ selectors: [
1273
+ "id",
1274
+ "class",
1275
+ "tag",
1276
+ "nthchild"
1277
+ ],
1278
+ combineWithinSelector: true,
1279
+ combineBetweenSelectors: true,
1280
+ maxCombinations: 100,
1281
+ maxCandidates: 100,
1282
+ blacklist: [(selectorValue) => {
1283
+ const idMatch = selectorValue.match(/^#(.+)$/);
1284
+ if (idMatch) return isDynamicId(idMatch[1]);
1285
+ const classMatch = selectorValue.match(/^\.([a-zA-Z_-][\w-]*)$/);
1286
+ if (classMatch) return isStateClass(classMatch[1]);
1287
+ return false;
1288
+ }]
1289
+ });
1335
1290
  }
1336
1291
  function getFileInfoFromVueInstance(element) {
1337
1292
  var _a, _b, _c, _d;
@@ -1363,51 +1318,68 @@ function getFileInfoFromVueInstance(element) {
1363
1318
  }
1364
1319
  return null;
1365
1320
  }
1366
- function findFileInfo(element, inspector) {
1321
+ function shouldIgnoreElement(el) {
1322
+ if (el.hasAttribute(IGNORE_ATTRIBUTE)) return true;
1323
+ for (const selector of IGNORE_SELECTORS) if (el.closest(selector)) return true;
1324
+ return false;
1325
+ }
1326
+ function getDataFromElement(el) {
1367
1327
  var _a, _b;
1328
+ const vnodeData = (_b = (_a = el.__vnode) == null ? void 0 : _a.props) == null ? void 0 : _b[KEY_PROPS_DATA];
1329
+ if (vnodeData) return vnodeData;
1330
+ const attr = el.getAttribute(KEY_DATA);
1331
+ return attr != null ? attr : void 0;
1332
+ }
1333
+ function findInspectorFileInfo(element) {
1368
1334
  let current = element;
1369
- let fallbackFileInfo = null;
1370
1335
  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
1336
+ const data = getDataFromElement(current);
1337
+ if (data) {
1338
+ const match = data.match(/(.+):([\d]+):([\d]+)$/);
1339
+ if (match) return {
1340
+ file: match[1],
1341
+ line: parseInt(match[2], 10),
1342
+ column: parseInt(match[3], 10)
1386
1343
  };
1387
- if (info.line !== null) return info;
1388
- if (!fallbackFileInfo) fallbackFileInfo = info;
1389
1344
  }
1390
- const vueInfo = getFileInfoFromVueInstance(current);
1391
- if (vueInfo && !fallbackFileInfo) fallbackFileInfo = vueInfo;
1392
1345
  current = current.parentElement;
1393
1346
  }
1394
- return fallbackFileInfo || {
1347
+ return null;
1348
+ }
1349
+ function mergeFileInfo(inspectorFileInfo, vueFileInfo) {
1350
+ if (!(inspectorFileInfo == null ? void 0 : inspectorFileInfo.file) && !(vueFileInfo == null ? void 0 : vueFileInfo.file)) return {
1395
1351
  file: null,
1396
1352
  line: null,
1397
1353
  column: null
1398
1354
  };
1355
+ const isNodeModules = (path) => path.includes("node_modules");
1356
+ if ((inspectorFileInfo == null ? void 0 : inspectorFileInfo.file) && (vueFileInfo == null ? void 0 : vueFileInfo.file)) if (!isNodeModules(inspectorFileInfo.file)) return inspectorFileInfo;
1357
+ else if (!isNodeModules(vueFileInfo.file)) return vueFileInfo;
1358
+ else return inspectorFileInfo;
1359
+ else if (inspectorFileInfo == null ? void 0 : inspectorFileInfo.file) return inspectorFileInfo;
1360
+ else return vueFileInfo;
1399
1361
  }
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;
1362
+ function getTargetElement(e) {
1363
+ if (!e.target || !(e.target instanceof Element)) return null;
1364
+ const el = e.target;
1365
+ if (shouldIgnoreElement(el)) return null;
1366
+ return el;
1367
+ }
1368
+ function getFileInfo(e, element) {
1369
+ var _a, _b;
1370
+ const inspector = window.__VUE_INSPECTOR__;
1371
+ let inspectorFileInfo = null;
1372
+ if (inspector) {
1373
+ const { targetNode, params } = inspector.getTargetNode(e);
1374
+ if (targetNode && params && params.file) inspectorFileInfo = {
1375
+ file: params.file,
1376
+ line: (_a = params.line) != null ? _a : null,
1377
+ column: (_b = params.column) != null ? _b : null
1378
+ };
1409
1379
  }
1410
- return null;
1380
+ if (element && !inspectorFileInfo) inspectorFileInfo = findInspectorFileInfo(element);
1381
+ const vueFileInfo = element ? getFileInfoFromVueInstance(element) : null;
1382
+ return mergeFileInfo(inspectorFileInfo, vueFileInfo);
1411
1383
  }
1412
1384
  function useInspector(options) {
1413
1385
  const highlightVisible = (0, vue.ref)(false);
@@ -1428,79 +1400,48 @@ function useInspector(options) {
1428
1400
  });
1429
1401
  const INSPECTOR_CHECK_INTERVAL = 500;
1430
1402
  let inspectorCheckTimer = null;
1431
- let currentHighlightElement = null;
1432
- let currentFileInfo = {
1433
- file: null,
1434
- line: null,
1435
- column: null
1436
- };
1437
1403
  let currentPrimary = "#3b82f6";
1438
1404
  let currentPrimaryBg = "rgba(59, 130, 246, 0.1)";
1439
- let currentDescription = "";
1440
- let currentFileInfoText = "";
1405
+ function setPointerEventsNone(elements) {
1406
+ elements.forEach((el) => {
1407
+ if (el) el.style.pointerEvents = "none";
1408
+ });
1409
+ }
1410
+ function setPointerEventsAuto(elements) {
1411
+ elements.forEach((el) => {
1412
+ if (el) el.style.pointerEvents = "";
1413
+ });
1414
+ }
1441
1415
  function handleMouseMoveCore(e) {
1442
- var _a, _b;
1443
1416
  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
- }
1417
+ const uiElements = [
1418
+ document.querySelector(".opencode-element-highlight"),
1419
+ document.querySelector(".opencode-element-tooltip"),
1420
+ document.querySelector(".opencode-select-mode-hint"),
1421
+ document.querySelector(".floating-bubble")
1422
+ ];
1423
+ setPointerEventsNone(uiElements);
1424
+ const elementToHighlight = getTargetElement(e);
1425
+ const fileInfo = getFileInfo(e, elementToHighlight);
1426
+ setPointerEventsAuto(uiElements);
1477
1427
  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}`;
1428
+ const widget = document.querySelector(".opencode-widget");
1429
+ if (widget) {
1430
+ const style = getComputedStyle(widget);
1431
+ currentPrimary = style.getPropertyValue("--oc-primary").trim() || currentPrimary;
1432
+ currentPrimaryBg = style.getPropertyValue("--oc-primary-bg").trim() || currentPrimaryBg;
1495
1433
  }
1496
- const newFileInfoText = fileName ? `${fileName}${lineInfo}` : "";
1497
- if (elementChanged || currentFileInfoText !== newFileInfoText) {
1498
- currentFileInfoText = newFileInfoText;
1499
- tooltipContent.value = {
1500
- description: currentDescription,
1501
- fileInfo: currentFileInfoText
1502
- };
1434
+ const description = getElementDescription(elementToHighlight);
1435
+ const fileName = fileInfo.file ? fileInfo.file.split("/").pop() : "";
1436
+ let lineInfo = "";
1437
+ if (fileInfo.line) {
1438
+ lineInfo = `:${fileInfo.line}`;
1439
+ if (fileInfo.column) lineInfo += `:${fileInfo.column}`;
1503
1440
  }
1441
+ tooltipContent.value = {
1442
+ description,
1443
+ fileInfo: fileName ? `${fileName}${lineInfo}` : ""
1444
+ };
1504
1445
  const rect = elementToHighlight.getBoundingClientRect();
1505
1446
  const newTop = `${rect.top}px`;
1506
1447
  const newLeft = `${rect.left}px`;
@@ -1516,59 +1457,37 @@ function useInspector(options) {
1516
1457
  };
1517
1458
  const tooltipHeight = 50;
1518
1459
  const tooltipWidth = 200;
1460
+ const margin = 10;
1519
1461
  let tooltipTop = rect.top - tooltipHeight - 8;
1520
1462
  let tooltipLeft = rect.left;
1521
- if (tooltipTop < 10) tooltipTop = rect.bottom + 8;
1522
- if (tooltipLeft + tooltipWidth > window.innerWidth - 10) tooltipLeft = window.innerWidth - tooltipWidth - 10;
1463
+ if (tooltipTop < margin) tooltipTop = rect.bottom + 8;
1464
+ if (tooltipTop + tooltipHeight > window.innerHeight - margin) tooltipTop = Math.max(margin, rect.top - tooltipHeight - 8);
1465
+ if (tooltipLeft < margin) tooltipLeft = margin;
1466
+ if (tooltipLeft + tooltipWidth > window.innerWidth - margin) tooltipLeft = window.innerWidth - tooltipWidth - margin;
1523
1467
  const newTooltipTop = `${tooltipTop}px`;
1524
1468
  const newTooltipLeft = `${tooltipLeft}px`;
1525
1469
  if (tooltipStyle.value.top !== newTooltipTop || tooltipStyle.value.left !== newTooltipLeft) tooltipStyle.value = {
1526
1470
  top: newTooltipTop,
1527
1471
  left: newTooltipLeft
1528
1472
  };
1529
- if (!highlightVisible.value) highlightVisible.value = true;
1530
- if (!tooltipVisible.value) tooltipVisible.value = true;
1473
+ highlightVisible.value = true;
1474
+ tooltipVisible.value = true;
1531
1475
  } 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;
1476
+ highlightVisible.value = false;
1477
+ tooltipVisible.value = false;
1542
1478
  }
1543
1479
  }
1544
- const handleMouseMove = throttle(handleMouseMoveCore, 16);
1480
+ const handleMouseMove = handleMouseMoveCore;
1545
1481
  function setupInspectorHook() {
1546
1482
  const inspector = window.__VUE_INSPECTOR__;
1547
1483
  if (!inspector || inspector.__opencode_hooked) return;
1548
1484
  const originalHandleClick = inspector.handleClick.bind(inspector);
1549
1485
  inspector.handleClick = function(e) {
1550
- var _a, _b;
1551
1486
  if (options.selectMode.value) {
1552
1487
  e.preventDefault();
1553
1488
  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;
1489
+ const elementToSelect = getTargetElement(e);
1490
+ const fileInfo = getFileInfo(e, elementToSelect);
1572
1491
  if (elementToSelect) {
1573
1492
  const innerText = getDirectText(elementToSelect);
1574
1493
  const description = getElementDescription(elementToSelect);
@@ -1604,14 +1523,6 @@ function useInspector(options) {
1604
1523
  if (inspector) inspector.disable();
1605
1524
  document.removeEventListener("mousemove", handleMouseMove);
1606
1525
  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
1526
  highlightVisible.value = false;
1616
1527
  tooltipVisible.value = false;
1617
1528
  }
@@ -2417,7 +2328,7 @@ __vue_sfc__.render = __vue_render__;
2417
2328
  var open_code_widget_default = __vue_sfc__;
2418
2329
  //#endregion
2419
2330
  //#region es/index.js
2420
- var version = "1.0.33";
2331
+ var version = "1.0.35";
2421
2332
  function install(app, options) {
2422
2333
  [open_code_widget_default].forEach((item) => {
2423
2334
  if (item.install) app.use(item, options);