web-remarq 0.4.6 → 0.4.8

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);
@@ -1363,25 +1377,6 @@ function getDirectText(el) {
1363
1377
  function parsePx(value) {
1364
1378
  return parseFloat(value) || 0;
1365
1379
  }
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
1380
  var SpacingOverlay = class {
1386
1381
  constructor(parent) {
1387
1382
  this.parent = parent;
@@ -1414,28 +1409,19 @@ var SpacingOverlay = class {
1414
1409
  if (target === this.lastTarget) return;
1415
1410
  this.lastTarget = target;
1416
1411
  try {
1417
- const rect = target.getBoundingClientRect();
1418
1412
  const cs = window.getComputedStyle(target);
1419
1413
  const margin = this.readSides(cs, "margin");
1420
1414
  const padding = this.readSides(cs, "padding");
1421
1415
  const border = this.readBorderSides(cs);
1422
- const transform = cs.transform;
1423
- const transformOrigin = cs.transformOrigin;
1424
- const hasTransform = transform && transform !== "none";
1425
1416
  const w = target.offsetWidth;
1426
1417
  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`;
1418
+ const matrix = getElementToViewportMatrix(target);
1419
+ this.containerEl.style.left = "0px";
1420
+ this.containerEl.style.top = "0px";
1430
1421
  this.containerEl.style.width = `${w}px`;
1431
1422
  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
- }
1423
+ this.containerEl.style.transform = matrix.toString();
1424
+ this.containerEl.style.transformOrigin = "0 0";
1439
1425
  this.positionEl(
1440
1426
  this.marginEl,
1441
1427
  -margin.left,
@@ -1601,18 +1587,40 @@ var SpacingOverlay = class {
1601
1587
  this.renderGap(children[i], children[i + 1], gap, isRow);
1602
1588
  }
1603
1589
  }
1590
+ /**
1591
+ * Compute the parent's content box (border-box minus padding and border)
1592
+ * to constrain gap dimensions to the actual content area.
1593
+ */
1594
+ getParentContentBox(parent) {
1595
+ const rect = parent.getBoundingClientRect();
1596
+ const cs = window.getComputedStyle(parent);
1597
+ const pl = parsePx(cs.paddingLeft);
1598
+ const pr = parsePx(cs.paddingRight);
1599
+ const pt = parsePx(cs.paddingTop);
1600
+ const pb = parsePx(cs.paddingBottom);
1601
+ const bl = parsePx(cs.borderLeftWidth);
1602
+ const br = parsePx(cs.borderRightWidth);
1603
+ const bt = parsePx(cs.borderTopWidth);
1604
+ const bb = parsePx(cs.borderBottomWidth);
1605
+ return {
1606
+ left: rect.left + bl + pl,
1607
+ top: rect.top + bt + pt,
1608
+ width: rect.width - bl - br - pl - pr,
1609
+ height: rect.height - bt - bb - pt - pb
1610
+ };
1611
+ }
1604
1612
  renderGap(before, after, gap, isRow) {
1605
1613
  const rectBefore = before.getBoundingClientRect();
1606
1614
  const rectAfter = after.getBoundingClientRect();
1607
1615
  const parent = before.parentElement;
1608
- const parentRect = parent ? parent.getBoundingClientRect() : null;
1616
+ const contentBox = parent ? this.getParentContentBox(parent) : null;
1609
1617
  const gapEl = document.createElement("div");
1610
1618
  gapEl.className = "remarq-spacing-gap";
1611
1619
  if (isRow) {
1612
1620
  const left = Math.min(rectBefore.right, rectAfter.right);
1613
1621
  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);
1622
+ const top = contentBox ? contentBox.top : Math.min(rectBefore.top, rectAfter.top);
1623
+ const height = contentBox ? contentBox.height : Math.max(rectBefore.height, rectAfter.height);
1616
1624
  gapEl.style.top = `${top}px`;
1617
1625
  gapEl.style.left = `${left}px`;
1618
1626
  gapEl.style.width = `${Math.abs(right - left)}px`;
@@ -1620,8 +1628,8 @@ var SpacingOverlay = class {
1620
1628
  } else {
1621
1629
  const top = Math.min(rectBefore.bottom, rectAfter.bottom);
1622
1630
  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);
1631
+ const left = contentBox ? contentBox.left : Math.min(rectBefore.left, rectAfter.left);
1632
+ const width = contentBox ? contentBox.width : Math.max(rectBefore.width, rectAfter.width);
1625
1633
  gapEl.style.top = `${top}px`;
1626
1634
  gapEl.style.left = `${left}px`;
1627
1635
  gapEl.style.width = `${width}px`;
@@ -2393,7 +2401,7 @@ function handleInspectKeydown(e) {
2393
2401
  spacingOverlay.hide();
2394
2402
  }
2395
2403
  }
2396
- if (e.altKey && e.key === "c") {
2404
+ if (e.altKey && e.code === "KeyC") {
2397
2405
  e.preventDefault();
2398
2406
  copyToClipboard();
2399
2407
  }