@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.
@@ -1198,6 +1198,17 @@ function useWidget(options) {
1198
1198
  }
1199
1199
  //#endregion
1200
1200
  //#region es/open-code-widget/composables/use-inspector.js
1201
+ var IGNORE_SELECTORS = [
1202
+ "#vue-inspector-container",
1203
+ ".opencode-widget",
1204
+ ".opencode-element-highlight",
1205
+ ".opencode-element-tooltip",
1206
+ ".opencode-select-mode-hint",
1207
+ ".floating-bubble"
1208
+ ];
1209
+ var IGNORE_ATTRIBUTE = "data-v-inspector-ignore";
1210
+ var KEY_PROPS_DATA = "__v_inspector";
1211
+ var KEY_DATA = "data-v-inspector";
1201
1212
  function throttle(fn, delay) {
1202
1213
  let lastCall = 0;
1203
1214
  let rafId = null;
@@ -1244,67 +1255,26 @@ function isStateClass(className) {
1244
1255
  if (/^(?:router-link|nuxt-link)/.test(className)) return true;
1245
1256
  return false;
1246
1257
  }
1247
- function filterStateClasses(classes) {
1248
- return classes.filter((cls) => !isStateClass(cls));
1249
- }
1250
1258
  function getElementDescription(element) {
1251
- try {
1252
- return getCssSelector(element, {
1253
- selectors: [
1254
- "id",
1255
- "class",
1256
- "tag",
1257
- "nthchild"
1258
- ],
1259
- combineWithinSelector: true,
1260
- combineBetweenSelectors: true,
1261
- maxCombinations: 100,
1262
- maxCandidates: 100,
1263
- blacklist: [(selectorValue) => {
1264
- const idMatch = selectorValue.match(/^#(.+)$/);
1265
- if (idMatch) return isDynamicId(idMatch[1]);
1266
- const classMatch = selectorValue.match(/^\.([a-zA-Z_-][\w-]*)$/);
1267
- if (classMatch) return isStateClass(classMatch[1]);
1268
- return false;
1269
- }]
1270
- });
1271
- } catch (e) {
1272
- const parts = [element.tagName.toLowerCase()];
1273
- const id = element.id;
1274
- if (id && !isDynamicId(id)) parts.push(`#${id}`);
1275
- const className = element.className;
1276
- if (typeof className === "string") {
1277
- const classes = filterStateClasses(className.trim().split(/\s+/).filter(Boolean)).slice(0, 2);
1278
- if (classes.length > 0) parts.push(`.${classes.join(".")}`);
1279
- } else {
1280
- const svgClass = className.baseVal;
1281
- if (svgClass) {
1282
- const classes = filterStateClasses(svgClass.trim().split(/\s+/).filter(Boolean)).slice(0, 2);
1283
- if (classes.length > 0) parts.push(`.${classes.join(".")}`);
1284
- }
1285
- }
1286
- const name = element.getAttribute("name");
1287
- if (name) parts.push(`[name="${name}"]`);
1288
- const placeholder = element.getAttribute("placeholder");
1289
- if (placeholder) parts.push(`[placeholder="${placeholder.substring(0, 20)}"]`);
1290
- if (element.getAttribute("src")) parts.push(`[src]`);
1291
- const href = element.getAttribute("href");
1292
- if (href && href !== "#") parts.push(`[href]`);
1293
- return parts.join("");
1294
- }
1295
- }
1296
- function getFileInfoFromAttributes(element) {
1297
- const file = element.getAttribute("data-v-inspector-file");
1298
- if (file) {
1299
- const line = element.getAttribute("data-v-inspector-line");
1300
- const column = element.getAttribute("data-v-inspector-column");
1301
- return {
1302
- file,
1303
- line: line ? parseInt(line, 10) : null,
1304
- column: column ? parseInt(column, 10) : null
1305
- };
1306
- }
1307
- return null;
1259
+ return getCssSelector(element, {
1260
+ selectors: [
1261
+ "id",
1262
+ "class",
1263
+ "tag",
1264
+ "nthchild"
1265
+ ],
1266
+ combineWithinSelector: true,
1267
+ combineBetweenSelectors: true,
1268
+ maxCombinations: 100,
1269
+ maxCandidates: 100,
1270
+ blacklist: [(selectorValue) => {
1271
+ const idMatch = selectorValue.match(/^#(.+)$/);
1272
+ if (idMatch) return isDynamicId(idMatch[1]);
1273
+ const classMatch = selectorValue.match(/^\.([a-zA-Z_-][\w-]*)$/);
1274
+ if (classMatch) return isStateClass(classMatch[1]);
1275
+ return false;
1276
+ }]
1277
+ });
1308
1278
  }
1309
1279
  function getFileInfoFromVueInstance(element) {
1310
1280
  var _a, _b, _c, _d;
@@ -1336,51 +1306,68 @@ function getFileInfoFromVueInstance(element) {
1336
1306
  }
1337
1307
  return null;
1338
1308
  }
1339
- function findFileInfo(element, inspector) {
1309
+ function shouldIgnoreElement(el) {
1310
+ if (el.hasAttribute(IGNORE_ATTRIBUTE)) return true;
1311
+ for (const selector of IGNORE_SELECTORS) if (el.closest(selector)) return true;
1312
+ return false;
1313
+ }
1314
+ function getDataFromElement(el) {
1340
1315
  var _a, _b;
1316
+ const vnodeData = (_b = (_a = el.__vnode) == null ? void 0 : _a.props) == null ? void 0 : _b[KEY_PROPS_DATA];
1317
+ if (vnodeData) return vnodeData;
1318
+ const attr = el.getAttribute(KEY_DATA);
1319
+ return attr != null ? attr : void 0;
1320
+ }
1321
+ function findInspectorFileInfo(element) {
1341
1322
  let current = element;
1342
- let fallbackFileInfo = null;
1343
1323
  while (current) {
1344
- const attrInfo = getFileInfoFromAttributes(current);
1345
- if (attrInfo && attrInfo.line !== null) return attrInfo;
1346
- if (attrInfo && !fallbackFileInfo) fallbackFileInfo = attrInfo;
1347
- const fakeEvent = {
1348
- clientX: 0,
1349
- clientY: 0,
1350
- target: current,
1351
- currentTarget: current
1352
- };
1353
- const { params } = inspector.getTargetNode(fakeEvent);
1354
- if (params && params.file) {
1355
- const info = {
1356
- file: params.file,
1357
- line: (_a = params.line) != null ? _a : null,
1358
- column: (_b = params.column) != null ? _b : null
1324
+ const data = getDataFromElement(current);
1325
+ if (data) {
1326
+ const match = data.match(/(.+):([\d]+):([\d]+)$/);
1327
+ if (match) return {
1328
+ file: match[1],
1329
+ line: parseInt(match[2], 10),
1330
+ column: parseInt(match[3], 10)
1359
1331
  };
1360
- if (info.line !== null) return info;
1361
- if (!fallbackFileInfo) fallbackFileInfo = info;
1362
1332
  }
1363
- const vueInfo = getFileInfoFromVueInstance(current);
1364
- if (vueInfo && !fallbackFileInfo) fallbackFileInfo = vueInfo;
1365
1333
  current = current.parentElement;
1366
1334
  }
1367
- return fallbackFileInfo || {
1335
+ return null;
1336
+ }
1337
+ function mergeFileInfo(inspectorFileInfo, vueFileInfo) {
1338
+ if (!(inspectorFileInfo == null ? void 0 : inspectorFileInfo.file) && !(vueFileInfo == null ? void 0 : vueFileInfo.file)) return {
1368
1339
  file: null,
1369
1340
  line: null,
1370
1341
  column: null
1371
1342
  };
1343
+ const isNodeModules = (path) => path.includes("node_modules");
1344
+ if ((inspectorFileInfo == null ? void 0 : inspectorFileInfo.file) && (vueFileInfo == null ? void 0 : vueFileInfo.file)) if (!isNodeModules(inspectorFileInfo.file)) return inspectorFileInfo;
1345
+ else if (!isNodeModules(vueFileInfo.file)) return vueFileInfo;
1346
+ else return inspectorFileInfo;
1347
+ else if (inspectorFileInfo == null ? void 0 : inspectorFileInfo.file) return inspectorFileInfo;
1348
+ else return vueFileInfo;
1372
1349
  }
1373
- function getPreciseElementAtPoint(x, y, boundary) {
1374
- const elements = document.elementsFromPoint(x, y);
1375
- for (const el of elements) {
1376
- if (el.closest("#vue-inspector-container")) continue;
1377
- if (el.closest(".opencode-widget")) continue;
1378
- if (el.hasAttribute("data-v-inspector-ignore")) continue;
1379
- if (boundary) {
1380
- if (boundary.contains(el) || el === boundary) return el;
1381
- } else return el;
1350
+ function getTargetElement(e) {
1351
+ if (!e.target || !(e.target instanceof Element)) return null;
1352
+ const el = e.target;
1353
+ if (shouldIgnoreElement(el)) return null;
1354
+ return el;
1355
+ }
1356
+ function getFileInfo(e, element) {
1357
+ var _a, _b;
1358
+ const inspector = window.__VUE_INSPECTOR__;
1359
+ let inspectorFileInfo = null;
1360
+ if (inspector) {
1361
+ const { targetNode, params } = inspector.getTargetNode(e);
1362
+ if (targetNode && params && params.file) inspectorFileInfo = {
1363
+ file: params.file,
1364
+ line: (_a = params.line) != null ? _a : null,
1365
+ column: (_b = params.column) != null ? _b : null
1366
+ };
1382
1367
  }
1383
- return null;
1368
+ if (element && !inspectorFileInfo) inspectorFileInfo = findInspectorFileInfo(element);
1369
+ const vueFileInfo = element ? getFileInfoFromVueInstance(element) : null;
1370
+ return mergeFileInfo(inspectorFileInfo, vueFileInfo);
1384
1371
  }
1385
1372
  function useInspector(options) {
1386
1373
  const highlightVisible = ref(false);
@@ -1401,79 +1388,48 @@ function useInspector(options) {
1401
1388
  });
1402
1389
  const INSPECTOR_CHECK_INTERVAL = 500;
1403
1390
  let inspectorCheckTimer = null;
1404
- let currentHighlightElement = null;
1405
- let currentFileInfo = {
1406
- file: null,
1407
- line: null,
1408
- column: null
1409
- };
1410
1391
  let currentPrimary = "#3b82f6";
1411
1392
  let currentPrimaryBg = "rgba(59, 130, 246, 0.1)";
1412
- let currentDescription = "";
1413
- let currentFileInfoText = "";
1393
+ function setPointerEventsNone(elements) {
1394
+ elements.forEach((el) => {
1395
+ if (el) el.style.pointerEvents = "none";
1396
+ });
1397
+ }
1398
+ function setPointerEventsAuto(elements) {
1399
+ elements.forEach((el) => {
1400
+ if (el) el.style.pointerEvents = "";
1401
+ });
1402
+ }
1414
1403
  function handleMouseMoveCore(e) {
1415
- var _a, _b;
1416
1404
  if (!options.selectMode.value) return;
1417
- const inspector = window.__VUE_INSPECTOR__;
1418
- const highlight = document.querySelector(".opencode-element-highlight");
1419
- const tooltip = document.querySelector(".opencode-element-tooltip");
1420
- if (highlight) highlight.style.pointerEvents = "none";
1421
- if (tooltip) tooltip.style.pointerEvents = "none";
1422
- let elementToHighlight = null;
1423
- let targetNode;
1424
- let fileInfo = {
1425
- file: null,
1426
- line: null,
1427
- column: null
1428
- };
1429
- try {
1430
- if (inspector) {
1431
- const result = inspector.getTargetNode(e);
1432
- targetNode = result.targetNode;
1433
- const params = result.params;
1434
- if (targetNode) {
1435
- elementToHighlight = getPreciseElementAtPoint(e.clientX, e.clientY, targetNode) || targetNode;
1436
- if (params && params.file) fileInfo = {
1437
- file: params.file,
1438
- line: (_a = params.line) != null ? _a : null,
1439
- column: (_b = params.column) != null ? _b : null
1440
- };
1441
- else fileInfo = findFileInfo(targetNode, inspector);
1442
- }
1443
- }
1444
- if (!elementToHighlight) elementToHighlight = getPreciseElementAtPoint(e.clientX, e.clientY, null);
1445
- if (elementToHighlight && !fileInfo.file) fileInfo = getFileInfoFromVueInstance(elementToHighlight) || fileInfo;
1446
- } finally {
1447
- if (highlight) highlight.style.pointerEvents = "";
1448
- if (tooltip) tooltip.style.pointerEvents = "";
1449
- }
1405
+ const uiElements = [
1406
+ document.querySelector(".opencode-element-highlight"),
1407
+ document.querySelector(".opencode-element-tooltip"),
1408
+ document.querySelector(".opencode-select-mode-hint"),
1409
+ document.querySelector(".floating-bubble")
1410
+ ];
1411
+ setPointerEventsNone(uiElements);
1412
+ const elementToHighlight = getTargetElement(e);
1413
+ const fileInfo = getFileInfo(e, elementToHighlight);
1414
+ setPointerEventsAuto(uiElements);
1450
1415
  if (elementToHighlight) {
1451
- const elementChanged = currentHighlightElement !== elementToHighlight;
1452
- if (elementChanged) {
1453
- currentHighlightElement = elementToHighlight;
1454
- currentFileInfo = fileInfo;
1455
- const widget = document.querySelector(".opencode-widget");
1456
- if (widget) {
1457
- const style = getComputedStyle(widget);
1458
- currentPrimary = style.getPropertyValue("--oc-primary").trim() || currentPrimary;
1459
- currentPrimaryBg = style.getPropertyValue("--oc-primary-bg").trim() || currentPrimaryBg;
1460
- }
1461
- currentDescription = getElementDescription(elementToHighlight);
1462
- } else if (!currentFileInfo.file && fileInfo.file) currentFileInfo = fileInfo;
1463
- const fileName = currentFileInfo.file ? currentFileInfo.file.split("/").pop() : "";
1464
- let lineInfo = "";
1465
- if (currentFileInfo.line) {
1466
- lineInfo = `:${currentFileInfo.line}`;
1467
- if (currentFileInfo.column) lineInfo += `:${currentFileInfo.column}`;
1416
+ const widget = document.querySelector(".opencode-widget");
1417
+ if (widget) {
1418
+ const style = getComputedStyle(widget);
1419
+ currentPrimary = style.getPropertyValue("--oc-primary").trim() || currentPrimary;
1420
+ currentPrimaryBg = style.getPropertyValue("--oc-primary-bg").trim() || currentPrimaryBg;
1468
1421
  }
1469
- const newFileInfoText = fileName ? `${fileName}${lineInfo}` : "";
1470
- if (elementChanged || currentFileInfoText !== newFileInfoText) {
1471
- currentFileInfoText = newFileInfoText;
1472
- tooltipContent.value = {
1473
- description: currentDescription,
1474
- fileInfo: currentFileInfoText
1475
- };
1422
+ const description = getElementDescription(elementToHighlight);
1423
+ const fileName = fileInfo.file ? fileInfo.file.split("/").pop() : "";
1424
+ let lineInfo = "";
1425
+ if (fileInfo.line) {
1426
+ lineInfo = `:${fileInfo.line}`;
1427
+ if (fileInfo.column) lineInfo += `:${fileInfo.column}`;
1476
1428
  }
1429
+ tooltipContent.value = {
1430
+ description,
1431
+ fileInfo: fileName ? `${fileName}${lineInfo}` : ""
1432
+ };
1477
1433
  const rect = elementToHighlight.getBoundingClientRect();
1478
1434
  const newTop = `${rect.top}px`;
1479
1435
  const newLeft = `${rect.left}px`;
@@ -1489,29 +1445,24 @@ function useInspector(options) {
1489
1445
  };
1490
1446
  const tooltipHeight = 50;
1491
1447
  const tooltipWidth = 200;
1448
+ const margin = 10;
1492
1449
  let tooltipTop = rect.top - tooltipHeight - 8;
1493
1450
  let tooltipLeft = rect.left;
1494
- if (tooltipTop < 10) tooltipTop = rect.bottom + 8;
1495
- if (tooltipLeft + tooltipWidth > window.innerWidth - 10) tooltipLeft = window.innerWidth - tooltipWidth - 10;
1451
+ if (tooltipTop < margin) tooltipTop = rect.bottom + 8;
1452
+ if (tooltipTop + tooltipHeight > window.innerHeight - margin) tooltipTop = Math.max(margin, rect.top - tooltipHeight - 8);
1453
+ if (tooltipLeft < margin) tooltipLeft = margin;
1454
+ if (tooltipLeft + tooltipWidth > window.innerWidth - margin) tooltipLeft = window.innerWidth - tooltipWidth - margin;
1496
1455
  const newTooltipTop = `${tooltipTop}px`;
1497
1456
  const newTooltipLeft = `${tooltipLeft}px`;
1498
1457
  if (tooltipStyle.value.top !== newTooltipTop || tooltipStyle.value.left !== newTooltipLeft) tooltipStyle.value = {
1499
1458
  top: newTooltipTop,
1500
1459
  left: newTooltipLeft
1501
1460
  };
1502
- if (!highlightVisible.value) highlightVisible.value = true;
1503
- if (!tooltipVisible.value) tooltipVisible.value = true;
1461
+ highlightVisible.value = true;
1462
+ tooltipVisible.value = true;
1504
1463
  } else {
1505
- currentHighlightElement = null;
1506
- currentDescription = "";
1507
- currentFileInfoText = "";
1508
- currentFileInfo = {
1509
- file: null,
1510
- line: null,
1511
- column: null
1512
- };
1513
- if (highlightVisible.value) highlightVisible.value = false;
1514
- if (tooltipVisible.value) tooltipVisible.value = false;
1464
+ highlightVisible.value = false;
1465
+ tooltipVisible.value = false;
1515
1466
  }
1516
1467
  }
1517
1468
  const handleMouseMove = throttle(handleMouseMoveCore, 16);
@@ -1520,28 +1471,11 @@ function useInspector(options) {
1520
1471
  if (!inspector || inspector.__opencode_hooked) return;
1521
1472
  const originalHandleClick = inspector.handleClick.bind(inspector);
1522
1473
  inspector.handleClick = function(e) {
1523
- var _a, _b;
1524
1474
  if (options.selectMode.value) {
1525
1475
  e.preventDefault();
1526
1476
  e.stopPropagation();
1527
- let elementToSelect = null;
1528
- let fileInfo = {
1529
- file: null,
1530
- line: null,
1531
- column: null
1532
- };
1533
- const { targetNode, params } = inspector.getTargetNode(e);
1534
- if (targetNode) {
1535
- elementToSelect = getPreciseElementAtPoint(e.clientX, e.clientY, targetNode) || targetNode;
1536
- if (params && params.file) fileInfo = {
1537
- file: params.file,
1538
- line: (_a = params.line) != null ? _a : null,
1539
- column: (_b = params.column) != null ? _b : null
1540
- };
1541
- else if (elementToSelect) fileInfo = findFileInfo(elementToSelect, inspector);
1542
- }
1543
- if (!elementToSelect) elementToSelect = getPreciseElementAtPoint(e.clientX, e.clientY, null);
1544
- if (elementToSelect && !fileInfo.file) fileInfo = getFileInfoFromVueInstance(elementToSelect) || fileInfo;
1477
+ const elementToSelect = getTargetElement(e);
1478
+ const fileInfo = getFileInfo(e, elementToSelect);
1545
1479
  if (elementToSelect) {
1546
1480
  const innerText = getDirectText(elementToSelect);
1547
1481
  const description = getElementDescription(elementToSelect);
@@ -1577,14 +1511,6 @@ function useInspector(options) {
1577
1511
  if (inspector) inspector.disable();
1578
1512
  document.removeEventListener("mousemove", handleMouseMove);
1579
1513
  document.removeEventListener("keydown", handleKeydown, true);
1580
- currentHighlightElement = null;
1581
- currentDescription = "";
1582
- currentFileInfoText = "";
1583
- currentFileInfo = {
1584
- file: null,
1585
- line: null,
1586
- column: null
1587
- };
1588
1514
  highlightVisible.value = false;
1589
1515
  tooltipVisible.value = false;
1590
1516
  }
@@ -2390,7 +2316,7 @@ __vue_sfc__.render = __vue_render__;
2390
2316
  var open_code_widget_default = __vue_sfc__;
2391
2317
  //#endregion
2392
2318
  //#region es/index.js
2393
- var version = "1.0.33";
2319
+ var version = "1.0.34";
2394
2320
  function install(app, options) {
2395
2321
  [open_code_widget_default].forEach((item) => {
2396
2322
  if (item.install) app.use(item, options);
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import OpenCodeWidget from './open-code-widget';
2
2
  import type { App } from 'vue';
3
- declare const version = "1.0.33";
3
+ declare const version = "1.0.34";
4
4
  declare function install(app: App<any>, options?: any): void;
5
5
  export { install, version, OpenCodeWidget };
6
6
  export default install;
package/lib/index.js CHANGED
@@ -34,7 +34,7 @@ __export(lib_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(lib_exports);
36
36
  var import_open_code_widget = __toESM(require("./open-code-widget"));
37
- const version = "1.0.33";
37
+ const version = "1.0.34";
38
38
  function install(app, options) {
39
39
  const components = [
40
40
  import_open_code_widget.default