web-remarq 0.4.7 → 0.4.9

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.
package/dist/index.js CHANGED
@@ -1216,6 +1216,44 @@ var Toolbar = class {
1216
1216
  }
1217
1217
  };
1218
1218
 
1219
+ // src/ui/transform.ts
1220
+ function getElementToViewportMatrix(el) {
1221
+ const w = el.offsetWidth;
1222
+ const h = el.offsetHeight;
1223
+ if (w === 0 && h === 0) return new DOMMatrix();
1224
+ const rect = el.getBoundingClientRect();
1225
+ if (Math.abs(rect.width - w) < 1 && Math.abs(rect.height - h) < 1) {
1226
+ return new DOMMatrix([1, 0, 0, 1, rect.left, rect.top]);
1227
+ }
1228
+ const savedPosition = el.style.position;
1229
+ const cs = getComputedStyle(el);
1230
+ if (cs.position === "static") {
1231
+ el.style.position = "relative";
1232
+ }
1233
+ const probe = document.createElement("div");
1234
+ probe.style.cssText = "position:absolute;width:0;height:0;margin:0;padding:0;border:0;pointer-events:none;";
1235
+ el.appendChild(probe);
1236
+ probe.style.left = "0px";
1237
+ probe.style.top = "0px";
1238
+ let r = probe.getBoundingClientRect();
1239
+ const tlx = r.left, tly = r.top;
1240
+ probe.style.left = `${w}px`;
1241
+ probe.style.top = "0px";
1242
+ r = probe.getBoundingClientRect();
1243
+ const trx = r.left, try_ = r.top;
1244
+ probe.style.left = "0px";
1245
+ probe.style.top = `${h}px`;
1246
+ r = probe.getBoundingClientRect();
1247
+ const blx = r.left, bly = r.top;
1248
+ probe.remove();
1249
+ el.style.position = savedPosition;
1250
+ const a = (trx - tlx) / w;
1251
+ const b = (try_ - tly) / w;
1252
+ const c = (blx - tlx) / h;
1253
+ const d = (bly - tly) / h;
1254
+ return new DOMMatrix([a, b, c, d, tlx, tly]);
1255
+ }
1256
+
1219
1257
  // src/ui/overlay.ts
1220
1258
  var Overlay = class {
1221
1259
  constructor(container) {
@@ -1232,40 +1270,16 @@ var Overlay = class {
1232
1270
  show(target) {
1233
1271
  try {
1234
1272
  const rect = target.getBoundingClientRect();
1235
- const cs = window.getComputedStyle(target);
1236
- const transform = cs.transform;
1237
- const hasTransform = transform && transform !== "none";
1273
+ const w = target.offsetWidth;
1274
+ const h = target.offsetHeight;
1275
+ const matrix = getElementToViewportMatrix(target);
1238
1276
  this.overlayEl.style.display = "block";
1239
- if (hasTransform) {
1240
- const w = target.offsetWidth;
1241
- const h = target.offsetHeight;
1242
- const origin = cs.transformOrigin;
1243
- const [ox, oy] = origin.split(" ").map(parseFloat);
1244
- const matrix = new DOMMatrix(transform);
1245
- const corners = [
1246
- matrix.transformPoint(new DOMPoint(-ox, -oy)),
1247
- matrix.transformPoint(new DOMPoint(w - ox, -oy)),
1248
- matrix.transformPoint(new DOMPoint(-ox, h - oy)),
1249
- matrix.transformPoint(new DOMPoint(w - ox, h - oy))
1250
- ];
1251
- const minX = Math.min(corners[0].x, corners[1].x, corners[2].x, corners[3].x);
1252
- const minY = Math.min(corners[0].y, corners[1].y, corners[2].y, corners[3].y);
1253
- const overlayX = rect.left - minX - ox;
1254
- const overlayY = rect.top - minY - oy;
1255
- this.overlayEl.style.left = `${overlayX}px`;
1256
- this.overlayEl.style.top = `${overlayY}px`;
1257
- this.overlayEl.style.width = `${w}px`;
1258
- this.overlayEl.style.height = `${h}px`;
1259
- this.overlayEl.style.transform = transform;
1260
- this.overlayEl.style.transformOrigin = origin;
1261
- } else {
1262
- this.overlayEl.style.left = `${rect.left}px`;
1263
- this.overlayEl.style.top = `${rect.top}px`;
1264
- this.overlayEl.style.width = `${rect.width}px`;
1265
- this.overlayEl.style.height = `${rect.height}px`;
1266
- this.overlayEl.style.transform = "";
1267
- this.overlayEl.style.transformOrigin = "";
1268
- }
1277
+ this.overlayEl.style.left = "0px";
1278
+ this.overlayEl.style.top = "0px";
1279
+ this.overlayEl.style.width = `${w}px`;
1280
+ this.overlayEl.style.height = `${h}px`;
1281
+ this.overlayEl.style.transform = matrix.toString();
1282
+ this.overlayEl.style.transformOrigin = "0 0";
1269
1283
  this.tooltipEl.textContent = describeElement(target);
1270
1284
  this.tooltipEl.style.display = "block";
1271
1285
  this.positionTooltip(rect.left, rect.top - 28);
@@ -1311,7 +1325,9 @@ function describeElement(el) {
1311
1325
  if (el.id) {
1312
1326
  parts.push(`#${el.id}`);
1313
1327
  }
1314
- const classes = Array.from(el.classList).filter((c) => !c.match(/^(sc-|css-)/) && !c.match(/^[a-zA-Z0-9]{8,}$/) && !c.match(/__[a-zA-Z0-9]{3,}$/)).slice(0, 2);
1328
+ const classes = Array.from(el.classList).filter(
1329
+ (c) => !c.match(/^(sc-|css-)/) && !c.match(/^[a-zA-Z0-9]{8,}$/) && !c.match(/__[a-zA-Z0-9]{3,}$/)
1330
+ ).slice(0, 2);
1315
1331
  if (classes.length) {
1316
1332
  parts.push(`.${classes.join(".")}`);
1317
1333
  }
@@ -1340,25 +1356,6 @@ function getDirectText(el) {
1340
1356
  function parsePx(value) {
1341
1357
  return parseFloat(value) || 0;
1342
1358
  }
1343
- function computeUntransformedOrigin(rect, offsetW, offsetH, transform, transformOrigin) {
1344
- if (!transform || transform === "none") {
1345
- return { x: rect.left, y: rect.top };
1346
- }
1347
- const [ox, oy] = transformOrigin.split(" ").map(parseFloat);
1348
- const matrix = new DOMMatrix(transform);
1349
- const corners = [
1350
- matrix.transformPoint(new DOMPoint(-ox, -oy)),
1351
- matrix.transformPoint(new DOMPoint(offsetW - ox, -oy)),
1352
- matrix.transformPoint(new DOMPoint(-ox, offsetH - oy)),
1353
- matrix.transformPoint(new DOMPoint(offsetW - ox, offsetH - oy))
1354
- ];
1355
- const minX = Math.min(corners[0].x, corners[1].x, corners[2].x, corners[3].x);
1356
- const minY = Math.min(corners[0].y, corners[1].y, corners[2].y, corners[3].y);
1357
- return {
1358
- x: rect.left - minX - ox,
1359
- y: rect.top - minY - oy
1360
- };
1361
- }
1362
1359
  var SpacingOverlay = class {
1363
1360
  constructor(parent) {
1364
1361
  this.parent = parent;
@@ -1391,28 +1388,19 @@ var SpacingOverlay = class {
1391
1388
  if (target === this.lastTarget) return;
1392
1389
  this.lastTarget = target;
1393
1390
  try {
1394
- const rect = target.getBoundingClientRect();
1395
1391
  const cs = window.getComputedStyle(target);
1396
1392
  const margin = this.readSides(cs, "margin");
1397
1393
  const padding = this.readSides(cs, "padding");
1398
1394
  const border = this.readBorderSides(cs);
1399
- const transform = cs.transform;
1400
- const transformOrigin = cs.transformOrigin;
1401
- const hasTransform = transform && transform !== "none";
1402
1395
  const w = target.offsetWidth;
1403
1396
  const h = target.offsetHeight;
1404
- const origin = computeUntransformedOrigin(rect, w, h, transform, transformOrigin);
1405
- this.containerEl.style.left = `${origin.x}px`;
1406
- this.containerEl.style.top = `${origin.y}px`;
1397
+ const matrix = getElementToViewportMatrix(target);
1398
+ this.containerEl.style.left = "0px";
1399
+ this.containerEl.style.top = "0px";
1407
1400
  this.containerEl.style.width = `${w}px`;
1408
1401
  this.containerEl.style.height = `${h}px`;
1409
- if (hasTransform) {
1410
- this.containerEl.style.transform = transform;
1411
- this.containerEl.style.transformOrigin = transformOrigin;
1412
- } else {
1413
- this.containerEl.style.transform = "";
1414
- this.containerEl.style.transformOrigin = "";
1415
- }
1402
+ this.containerEl.style.transform = matrix.toString();
1403
+ this.containerEl.style.transformOrigin = "0 0";
1416
1404
  this.positionEl(
1417
1405
  this.marginEl,
1418
1406
  -margin.left,
@@ -1425,7 +1413,13 @@ var SpacingOverlay = class {
1425
1413
  const contentTop = border.top + padding.top;
1426
1414
  const contentW = w - border.left - border.right - padding.left - padding.right;
1427
1415
  const contentH = h - border.top - border.bottom - padding.top - padding.bottom;
1428
- this.positionEl(this.contentEl, contentLeft, contentTop, contentW, contentH);
1416
+ this.positionEl(
1417
+ this.contentEl,
1418
+ contentLeft,
1419
+ contentTop,
1420
+ contentW,
1421
+ contentH
1422
+ );
1429
1423
  this.clearLabels();
1430
1424
  this.clearGaps();
1431
1425
  this.addMarginPaddingLabels(
@@ -1482,7 +1476,9 @@ var SpacingOverlay = class {
1482
1476
  return {
1483
1477
  top: parsePx(cs[`${prop}Top`]),
1484
1478
  right: parsePx(cs[`${prop}Right`]),
1485
- bottom: parsePx(cs[`${prop}Bottom`]),
1479
+ bottom: parsePx(
1480
+ cs[`${prop}Bottom`]
1481
+ ),
1486
1482
  left: parsePx(cs[`${prop}Left`])
1487
1483
  };
1488
1484
  }
@@ -1578,18 +1574,40 @@ var SpacingOverlay = class {
1578
1574
  this.renderGap(children[i], children[i + 1], gap, isRow);
1579
1575
  }
1580
1576
  }
1577
+ /**
1578
+ * Compute the parent's content box (border-box minus padding and border)
1579
+ * to constrain gap dimensions to the actual content area.
1580
+ */
1581
+ getParentContentBox(parent) {
1582
+ const rect = parent.getBoundingClientRect();
1583
+ const cs = window.getComputedStyle(parent);
1584
+ const pl = parsePx(cs.paddingLeft);
1585
+ const pr = parsePx(cs.paddingRight);
1586
+ const pt = parsePx(cs.paddingTop);
1587
+ const pb = parsePx(cs.paddingBottom);
1588
+ const bl = parsePx(cs.borderLeftWidth);
1589
+ const br = parsePx(cs.borderRightWidth);
1590
+ const bt = parsePx(cs.borderTopWidth);
1591
+ const bb = parsePx(cs.borderBottomWidth);
1592
+ return {
1593
+ left: rect.left + bl + pl,
1594
+ top: rect.top + bt + pt,
1595
+ width: rect.width - bl - br - pl - pr,
1596
+ height: rect.height - bt - bb - pt - pb
1597
+ };
1598
+ }
1581
1599
  renderGap(before, after, gap, isRow) {
1582
1600
  const rectBefore = before.getBoundingClientRect();
1583
1601
  const rectAfter = after.getBoundingClientRect();
1584
1602
  const parent = before.parentElement;
1585
- const parentRect = parent ? parent.getBoundingClientRect() : null;
1603
+ const contentBox = parent ? this.getParentContentBox(parent) : null;
1586
1604
  const gapEl = document.createElement("div");
1587
1605
  gapEl.className = "remarq-spacing-gap";
1588
1606
  if (isRow) {
1589
1607
  const left = Math.min(rectBefore.right, rectAfter.right);
1590
1608
  const right = Math.max(rectBefore.left, rectAfter.left);
1591
- const top = parentRect ? parentRect.top : Math.min(rectBefore.top, rectAfter.top);
1592
- const height = parentRect ? parentRect.height : Math.max(rectBefore.height, rectAfter.height);
1609
+ const top = contentBox ? contentBox.top : Math.min(rectBefore.top, rectAfter.top);
1610
+ const height = contentBox ? contentBox.height : Math.max(rectBefore.height, rectAfter.height);
1593
1611
  gapEl.style.top = `${top}px`;
1594
1612
  gapEl.style.left = `${left}px`;
1595
1613
  gapEl.style.width = `${Math.abs(right - left)}px`;
@@ -1597,8 +1615,8 @@ var SpacingOverlay = class {
1597
1615
  } else {
1598
1616
  const top = Math.min(rectBefore.bottom, rectAfter.bottom);
1599
1617
  const bottom = Math.max(rectBefore.top, rectAfter.top);
1600
- const left = parentRect ? parentRect.left : Math.min(rectBefore.left, rectAfter.left);
1601
- const width = parentRect ? parentRect.width : Math.max(rectBefore.width, rectAfter.width);
1618
+ const left = contentBox ? contentBox.left : Math.min(rectBefore.left, rectAfter.left);
1619
+ const width = contentBox ? contentBox.width : Math.max(rectBefore.width, rectAfter.width);
1602
1620
  gapEl.style.top = `${top}px`;
1603
1621
  gapEl.style.left = `${left}px`;
1604
1622
  gapEl.style.width = `${width}px`;
@@ -2081,6 +2099,7 @@ var SHORTCUTS = [
2081
2099
  { key: `${modKey2}+I`, description: "Toggle inspect mode" },
2082
2100
  { key: "S", description: "Toggle spacing overlay", context: "inspect" },
2083
2101
  { key: `${modKey2}+C`, description: "Copy all annotations to clipboard" },
2102
+ { key: `${modKey2}+D`, description: "Delete all annotations" },
2084
2103
  { key: "Esc", description: "Exit inspect mode / close popup" },
2085
2104
  { key: "?", description: "Show this help" },
2086
2105
  { key: "Enter", description: "Submit annotation", context: "popup" },
@@ -2374,6 +2393,13 @@ function handleInspectKeydown(e) {
2374
2393
  e.preventDefault();
2375
2394
  copyToClipboard();
2376
2395
  }
2396
+ if (e.altKey && e.code === "KeyD") {
2397
+ e.preventDefault();
2398
+ elementCache.clear();
2399
+ storage.clearAll();
2400
+ refreshMarkers();
2401
+ showToast(themeManager.container, "All annotations cleared");
2402
+ }
2377
2403
  if (e.key === "?") {
2378
2404
  showShortcutsModal(themeManager.container);
2379
2405
  }