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 +80 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +80 -72
- package/dist/index.js.map +1 -1
- package/dist/web-remarq.global.global.js +80 -72
- package/dist/web-remarq.global.global.js.map +1 -1
- package/package.json +1 -1
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
|
|
1236
|
-
const
|
|
1237
|
-
const
|
|
1273
|
+
const w = target.offsetWidth;
|
|
1274
|
+
const h = target.offsetHeight;
|
|
1275
|
+
const matrix = getElementToViewportMatrix(target);
|
|
1238
1276
|
this.overlayEl.style.display = "block";
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
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);
|
|
@@ -1340,25 +1354,6 @@ function getDirectText(el) {
|
|
|
1340
1354
|
function parsePx(value) {
|
|
1341
1355
|
return parseFloat(value) || 0;
|
|
1342
1356
|
}
|
|
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
1357
|
var SpacingOverlay = class {
|
|
1363
1358
|
constructor(parent) {
|
|
1364
1359
|
this.parent = parent;
|
|
@@ -1391,28 +1386,19 @@ var SpacingOverlay = class {
|
|
|
1391
1386
|
if (target === this.lastTarget) return;
|
|
1392
1387
|
this.lastTarget = target;
|
|
1393
1388
|
try {
|
|
1394
|
-
const rect = target.getBoundingClientRect();
|
|
1395
1389
|
const cs = window.getComputedStyle(target);
|
|
1396
1390
|
const margin = this.readSides(cs, "margin");
|
|
1397
1391
|
const padding = this.readSides(cs, "padding");
|
|
1398
1392
|
const border = this.readBorderSides(cs);
|
|
1399
|
-
const transform = cs.transform;
|
|
1400
|
-
const transformOrigin = cs.transformOrigin;
|
|
1401
|
-
const hasTransform = transform && transform !== "none";
|
|
1402
1393
|
const w = target.offsetWidth;
|
|
1403
1394
|
const h = target.offsetHeight;
|
|
1404
|
-
const
|
|
1405
|
-
this.containerEl.style.left =
|
|
1406
|
-
this.containerEl.style.top =
|
|
1395
|
+
const matrix = getElementToViewportMatrix(target);
|
|
1396
|
+
this.containerEl.style.left = "0px";
|
|
1397
|
+
this.containerEl.style.top = "0px";
|
|
1407
1398
|
this.containerEl.style.width = `${w}px`;
|
|
1408
1399
|
this.containerEl.style.height = `${h}px`;
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
this.containerEl.style.transformOrigin = transformOrigin;
|
|
1412
|
-
} else {
|
|
1413
|
-
this.containerEl.style.transform = "";
|
|
1414
|
-
this.containerEl.style.transformOrigin = "";
|
|
1415
|
-
}
|
|
1400
|
+
this.containerEl.style.transform = matrix.toString();
|
|
1401
|
+
this.containerEl.style.transformOrigin = "0 0";
|
|
1416
1402
|
this.positionEl(
|
|
1417
1403
|
this.marginEl,
|
|
1418
1404
|
-margin.left,
|
|
@@ -1578,18 +1564,40 @@ var SpacingOverlay = class {
|
|
|
1578
1564
|
this.renderGap(children[i], children[i + 1], gap, isRow);
|
|
1579
1565
|
}
|
|
1580
1566
|
}
|
|
1567
|
+
/**
|
|
1568
|
+
* Compute the parent's content box (border-box minus padding and border)
|
|
1569
|
+
* to constrain gap dimensions to the actual content area.
|
|
1570
|
+
*/
|
|
1571
|
+
getParentContentBox(parent) {
|
|
1572
|
+
const rect = parent.getBoundingClientRect();
|
|
1573
|
+
const cs = window.getComputedStyle(parent);
|
|
1574
|
+
const pl = parsePx(cs.paddingLeft);
|
|
1575
|
+
const pr = parsePx(cs.paddingRight);
|
|
1576
|
+
const pt = parsePx(cs.paddingTop);
|
|
1577
|
+
const pb = parsePx(cs.paddingBottom);
|
|
1578
|
+
const bl = parsePx(cs.borderLeftWidth);
|
|
1579
|
+
const br = parsePx(cs.borderRightWidth);
|
|
1580
|
+
const bt = parsePx(cs.borderTopWidth);
|
|
1581
|
+
const bb = parsePx(cs.borderBottomWidth);
|
|
1582
|
+
return {
|
|
1583
|
+
left: rect.left + bl + pl,
|
|
1584
|
+
top: rect.top + bt + pt,
|
|
1585
|
+
width: rect.width - bl - br - pl - pr,
|
|
1586
|
+
height: rect.height - bt - bb - pt - pb
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1581
1589
|
renderGap(before, after, gap, isRow) {
|
|
1582
1590
|
const rectBefore = before.getBoundingClientRect();
|
|
1583
1591
|
const rectAfter = after.getBoundingClientRect();
|
|
1584
1592
|
const parent = before.parentElement;
|
|
1585
|
-
const
|
|
1593
|
+
const contentBox = parent ? this.getParentContentBox(parent) : null;
|
|
1586
1594
|
const gapEl = document.createElement("div");
|
|
1587
1595
|
gapEl.className = "remarq-spacing-gap";
|
|
1588
1596
|
if (isRow) {
|
|
1589
1597
|
const left = Math.min(rectBefore.right, rectAfter.right);
|
|
1590
1598
|
const right = Math.max(rectBefore.left, rectAfter.left);
|
|
1591
|
-
const top =
|
|
1592
|
-
const height =
|
|
1599
|
+
const top = contentBox ? contentBox.top : Math.min(rectBefore.top, rectAfter.top);
|
|
1600
|
+
const height = contentBox ? contentBox.height : Math.max(rectBefore.height, rectAfter.height);
|
|
1593
1601
|
gapEl.style.top = `${top}px`;
|
|
1594
1602
|
gapEl.style.left = `${left}px`;
|
|
1595
1603
|
gapEl.style.width = `${Math.abs(right - left)}px`;
|
|
@@ -1597,8 +1605,8 @@ var SpacingOverlay = class {
|
|
|
1597
1605
|
} else {
|
|
1598
1606
|
const top = Math.min(rectBefore.bottom, rectAfter.bottom);
|
|
1599
1607
|
const bottom = Math.max(rectBefore.top, rectAfter.top);
|
|
1600
|
-
const left =
|
|
1601
|
-
const width =
|
|
1608
|
+
const left = contentBox ? contentBox.left : Math.min(rectBefore.left, rectAfter.left);
|
|
1609
|
+
const width = contentBox ? contentBox.width : Math.max(rectBefore.width, rectAfter.width);
|
|
1602
1610
|
gapEl.style.top = `${top}px`;
|
|
1603
1611
|
gapEl.style.left = `${left}px`;
|
|
1604
1612
|
gapEl.style.width = `${width}px`;
|
|
@@ -2370,7 +2378,7 @@ function handleInspectKeydown(e) {
|
|
|
2370
2378
|
spacingOverlay.hide();
|
|
2371
2379
|
}
|
|
2372
2380
|
}
|
|
2373
|
-
if (e.altKey && e.
|
|
2381
|
+
if (e.altKey && e.code === "KeyC") {
|
|
2374
2382
|
e.preventDefault();
|
|
2375
2383
|
copyToClipboard();
|
|
2376
2384
|
}
|