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.cjs CHANGED
@@ -1239,6 +1239,44 @@ var Toolbar = class {
1239
1239
  }
1240
1240
  };
1241
1241
 
1242
+ // src/ui/transform.ts
1243
+ function getElementToViewportMatrix(el) {
1244
+ const w = el.offsetWidth;
1245
+ const h = el.offsetHeight;
1246
+ if (w === 0 && h === 0) return new DOMMatrix();
1247
+ const rect = el.getBoundingClientRect();
1248
+ if (Math.abs(rect.width - w) < 1 && Math.abs(rect.height - h) < 1) {
1249
+ return new DOMMatrix([1, 0, 0, 1, rect.left, rect.top]);
1250
+ }
1251
+ const savedPosition = el.style.position;
1252
+ const cs = getComputedStyle(el);
1253
+ if (cs.position === "static") {
1254
+ el.style.position = "relative";
1255
+ }
1256
+ const probe = document.createElement("div");
1257
+ probe.style.cssText = "position:absolute;width:0;height:0;margin:0;padding:0;border:0;pointer-events:none;";
1258
+ el.appendChild(probe);
1259
+ probe.style.left = "0px";
1260
+ probe.style.top = "0px";
1261
+ let r = probe.getBoundingClientRect();
1262
+ const tlx = r.left, tly = r.top;
1263
+ probe.style.left = `${w}px`;
1264
+ probe.style.top = "0px";
1265
+ r = probe.getBoundingClientRect();
1266
+ const trx = r.left, try_ = r.top;
1267
+ probe.style.left = "0px";
1268
+ probe.style.top = `${h}px`;
1269
+ r = probe.getBoundingClientRect();
1270
+ const blx = r.left, bly = r.top;
1271
+ probe.remove();
1272
+ el.style.position = savedPosition;
1273
+ const a = (trx - tlx) / w;
1274
+ const b = (try_ - tly) / w;
1275
+ const c = (blx - tlx) / h;
1276
+ const d = (bly - tly) / h;
1277
+ return new DOMMatrix([a, b, c, d, tlx, tly]);
1278
+ }
1279
+
1242
1280
  // src/ui/overlay.ts
1243
1281
  var Overlay = class {
1244
1282
  constructor(container) {
@@ -1255,40 +1293,16 @@ var Overlay = class {
1255
1293
  show(target) {
1256
1294
  try {
1257
1295
  const rect = target.getBoundingClientRect();
1258
- const cs = window.getComputedStyle(target);
1259
- const transform = cs.transform;
1260
- const hasTransform = transform && transform !== "none";
1296
+ const w = target.offsetWidth;
1297
+ const h = target.offsetHeight;
1298
+ const matrix = getElementToViewportMatrix(target);
1261
1299
  this.overlayEl.style.display = "block";
1262
- if (hasTransform) {
1263
- const w = target.offsetWidth;
1264
- const h = target.offsetHeight;
1265
- const origin = cs.transformOrigin;
1266
- const [ox, oy] = origin.split(" ").map(parseFloat);
1267
- const matrix = new DOMMatrix(transform);
1268
- const corners = [
1269
- matrix.transformPoint(new DOMPoint(-ox, -oy)),
1270
- matrix.transformPoint(new DOMPoint(w - ox, -oy)),
1271
- matrix.transformPoint(new DOMPoint(-ox, h - oy)),
1272
- matrix.transformPoint(new DOMPoint(w - ox, h - oy))
1273
- ];
1274
- const minX = Math.min(corners[0].x, corners[1].x, corners[2].x, corners[3].x);
1275
- const minY = Math.min(corners[0].y, corners[1].y, corners[2].y, corners[3].y);
1276
- const overlayX = rect.left - minX - ox;
1277
- const overlayY = rect.top - minY - oy;
1278
- this.overlayEl.style.left = `${overlayX}px`;
1279
- this.overlayEl.style.top = `${overlayY}px`;
1280
- this.overlayEl.style.width = `${w}px`;
1281
- this.overlayEl.style.height = `${h}px`;
1282
- this.overlayEl.style.transform = transform;
1283
- this.overlayEl.style.transformOrigin = origin;
1284
- } else {
1285
- this.overlayEl.style.left = `${rect.left}px`;
1286
- this.overlayEl.style.top = `${rect.top}px`;
1287
- this.overlayEl.style.width = `${rect.width}px`;
1288
- this.overlayEl.style.height = `${rect.height}px`;
1289
- this.overlayEl.style.transform = "";
1290
- this.overlayEl.style.transformOrigin = "";
1291
- }
1300
+ this.overlayEl.style.left = "0px";
1301
+ this.overlayEl.style.top = "0px";
1302
+ this.overlayEl.style.width = `${w}px`;
1303
+ this.overlayEl.style.height = `${h}px`;
1304
+ this.overlayEl.style.transform = matrix.toString();
1305
+ this.overlayEl.style.transformOrigin = "0 0";
1292
1306
  this.tooltipEl.textContent = describeElement(target);
1293
1307
  this.tooltipEl.style.display = "block";
1294
1308
  this.positionTooltip(rect.left, rect.top - 28);
@@ -1334,7 +1348,9 @@ function describeElement(el) {
1334
1348
  if (el.id) {
1335
1349
  parts.push(`#${el.id}`);
1336
1350
  }
1337
- 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);
1351
+ const classes = Array.from(el.classList).filter(
1352
+ (c) => !c.match(/^(sc-|css-)/) && !c.match(/^[a-zA-Z0-9]{8,}$/) && !c.match(/__[a-zA-Z0-9]{3,}$/)
1353
+ ).slice(0, 2);
1338
1354
  if (classes.length) {
1339
1355
  parts.push(`.${classes.join(".")}`);
1340
1356
  }
@@ -1363,25 +1379,6 @@ function getDirectText(el) {
1363
1379
  function parsePx(value) {
1364
1380
  return parseFloat(value) || 0;
1365
1381
  }
1366
- function computeUntransformedOrigin(rect, offsetW, offsetH, transform, transformOrigin) {
1367
- if (!transform || transform === "none") {
1368
- return { x: rect.left, y: rect.top };
1369
- }
1370
- const [ox, oy] = transformOrigin.split(" ").map(parseFloat);
1371
- const matrix = new DOMMatrix(transform);
1372
- const corners = [
1373
- matrix.transformPoint(new DOMPoint(-ox, -oy)),
1374
- matrix.transformPoint(new DOMPoint(offsetW - ox, -oy)),
1375
- matrix.transformPoint(new DOMPoint(-ox, offsetH - oy)),
1376
- matrix.transformPoint(new DOMPoint(offsetW - ox, offsetH - oy))
1377
- ];
1378
- const minX = Math.min(corners[0].x, corners[1].x, corners[2].x, corners[3].x);
1379
- const minY = Math.min(corners[0].y, corners[1].y, corners[2].y, corners[3].y);
1380
- return {
1381
- x: rect.left - minX - ox,
1382
- y: rect.top - minY - oy
1383
- };
1384
- }
1385
1382
  var SpacingOverlay = class {
1386
1383
  constructor(parent) {
1387
1384
  this.parent = parent;
@@ -1414,28 +1411,19 @@ var SpacingOverlay = class {
1414
1411
  if (target === this.lastTarget) return;
1415
1412
  this.lastTarget = target;
1416
1413
  try {
1417
- const rect = target.getBoundingClientRect();
1418
1414
  const cs = window.getComputedStyle(target);
1419
1415
  const margin = this.readSides(cs, "margin");
1420
1416
  const padding = this.readSides(cs, "padding");
1421
1417
  const border = this.readBorderSides(cs);
1422
- const transform = cs.transform;
1423
- const transformOrigin = cs.transformOrigin;
1424
- const hasTransform = transform && transform !== "none";
1425
1418
  const w = target.offsetWidth;
1426
1419
  const h = target.offsetHeight;
1427
- const origin = computeUntransformedOrigin(rect, w, h, transform, transformOrigin);
1428
- this.containerEl.style.left = `${origin.x}px`;
1429
- this.containerEl.style.top = `${origin.y}px`;
1420
+ const matrix = getElementToViewportMatrix(target);
1421
+ this.containerEl.style.left = "0px";
1422
+ this.containerEl.style.top = "0px";
1430
1423
  this.containerEl.style.width = `${w}px`;
1431
1424
  this.containerEl.style.height = `${h}px`;
1432
- if (hasTransform) {
1433
- this.containerEl.style.transform = transform;
1434
- this.containerEl.style.transformOrigin = transformOrigin;
1435
- } else {
1436
- this.containerEl.style.transform = "";
1437
- this.containerEl.style.transformOrigin = "";
1438
- }
1425
+ this.containerEl.style.transform = matrix.toString();
1426
+ this.containerEl.style.transformOrigin = "0 0";
1439
1427
  this.positionEl(
1440
1428
  this.marginEl,
1441
1429
  -margin.left,
@@ -1448,7 +1436,13 @@ var SpacingOverlay = class {
1448
1436
  const contentTop = border.top + padding.top;
1449
1437
  const contentW = w - border.left - border.right - padding.left - padding.right;
1450
1438
  const contentH = h - border.top - border.bottom - padding.top - padding.bottom;
1451
- this.positionEl(this.contentEl, contentLeft, contentTop, contentW, contentH);
1439
+ this.positionEl(
1440
+ this.contentEl,
1441
+ contentLeft,
1442
+ contentTop,
1443
+ contentW,
1444
+ contentH
1445
+ );
1452
1446
  this.clearLabels();
1453
1447
  this.clearGaps();
1454
1448
  this.addMarginPaddingLabels(
@@ -1505,7 +1499,9 @@ var SpacingOverlay = class {
1505
1499
  return {
1506
1500
  top: parsePx(cs[`${prop}Top`]),
1507
1501
  right: parsePx(cs[`${prop}Right`]),
1508
- bottom: parsePx(cs[`${prop}Bottom`]),
1502
+ bottom: parsePx(
1503
+ cs[`${prop}Bottom`]
1504
+ ),
1509
1505
  left: parsePx(cs[`${prop}Left`])
1510
1506
  };
1511
1507
  }
@@ -1601,18 +1597,40 @@ var SpacingOverlay = class {
1601
1597
  this.renderGap(children[i], children[i + 1], gap, isRow);
1602
1598
  }
1603
1599
  }
1600
+ /**
1601
+ * Compute the parent's content box (border-box minus padding and border)
1602
+ * to constrain gap dimensions to the actual content area.
1603
+ */
1604
+ getParentContentBox(parent) {
1605
+ const rect = parent.getBoundingClientRect();
1606
+ const cs = window.getComputedStyle(parent);
1607
+ const pl = parsePx(cs.paddingLeft);
1608
+ const pr = parsePx(cs.paddingRight);
1609
+ const pt = parsePx(cs.paddingTop);
1610
+ const pb = parsePx(cs.paddingBottom);
1611
+ const bl = parsePx(cs.borderLeftWidth);
1612
+ const br = parsePx(cs.borderRightWidth);
1613
+ const bt = parsePx(cs.borderTopWidth);
1614
+ const bb = parsePx(cs.borderBottomWidth);
1615
+ return {
1616
+ left: rect.left + bl + pl,
1617
+ top: rect.top + bt + pt,
1618
+ width: rect.width - bl - br - pl - pr,
1619
+ height: rect.height - bt - bb - pt - pb
1620
+ };
1621
+ }
1604
1622
  renderGap(before, after, gap, isRow) {
1605
1623
  const rectBefore = before.getBoundingClientRect();
1606
1624
  const rectAfter = after.getBoundingClientRect();
1607
1625
  const parent = before.parentElement;
1608
- const parentRect = parent ? parent.getBoundingClientRect() : null;
1626
+ const contentBox = parent ? this.getParentContentBox(parent) : null;
1609
1627
  const gapEl = document.createElement("div");
1610
1628
  gapEl.className = "remarq-spacing-gap";
1611
1629
  if (isRow) {
1612
1630
  const left = Math.min(rectBefore.right, rectAfter.right);
1613
1631
  const right = Math.max(rectBefore.left, rectAfter.left);
1614
- const top = parentRect ? parentRect.top : Math.min(rectBefore.top, rectAfter.top);
1615
- const height = parentRect ? parentRect.height : Math.max(rectBefore.height, rectAfter.height);
1632
+ const top = contentBox ? contentBox.top : Math.min(rectBefore.top, rectAfter.top);
1633
+ const height = contentBox ? contentBox.height : Math.max(rectBefore.height, rectAfter.height);
1616
1634
  gapEl.style.top = `${top}px`;
1617
1635
  gapEl.style.left = `${left}px`;
1618
1636
  gapEl.style.width = `${Math.abs(right - left)}px`;
@@ -1620,8 +1638,8 @@ var SpacingOverlay = class {
1620
1638
  } else {
1621
1639
  const top = Math.min(rectBefore.bottom, rectAfter.bottom);
1622
1640
  const bottom = Math.max(rectBefore.top, rectAfter.top);
1623
- const left = parentRect ? parentRect.left : Math.min(rectBefore.left, rectAfter.left);
1624
- const width = parentRect ? parentRect.width : Math.max(rectBefore.width, rectAfter.width);
1641
+ const left = contentBox ? contentBox.left : Math.min(rectBefore.left, rectAfter.left);
1642
+ const width = contentBox ? contentBox.width : Math.max(rectBefore.width, rectAfter.width);
1625
1643
  gapEl.style.top = `${top}px`;
1626
1644
  gapEl.style.left = `${left}px`;
1627
1645
  gapEl.style.width = `${width}px`;
@@ -2104,6 +2122,7 @@ var SHORTCUTS = [
2104
2122
  { key: `${modKey2}+I`, description: "Toggle inspect mode" },
2105
2123
  { key: "S", description: "Toggle spacing overlay", context: "inspect" },
2106
2124
  { key: `${modKey2}+C`, description: "Copy all annotations to clipboard" },
2125
+ { key: `${modKey2}+D`, description: "Delete all annotations" },
2107
2126
  { key: "Esc", description: "Exit inspect mode / close popup" },
2108
2127
  { key: "?", description: "Show this help" },
2109
2128
  { key: "Enter", description: "Submit annotation", context: "popup" },
@@ -2397,6 +2416,13 @@ function handleInspectKeydown(e) {
2397
2416
  e.preventDefault();
2398
2417
  copyToClipboard();
2399
2418
  }
2419
+ if (e.altKey && e.code === "KeyD") {
2420
+ e.preventDefault();
2421
+ elementCache.clear();
2422
+ storage.clearAll();
2423
+ refreshMarkers();
2424
+ showToast(themeManager.container, "All annotations cleared");
2425
+ }
2400
2426
  if (e.key === "?") {
2401
2427
  showShortcutsModal(themeManager.container);
2402
2428
  }