@canvas-components/print-design 0.1.3 → 0.1.4
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 +104 -18
- package/dist/index.js +104 -18
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7762,6 +7762,26 @@ function hitTableColumnBoundary(element, point, scale, _document) {
|
|
|
7762
7762
|
-(element.rotation ?? 0) * Math.PI / 180
|
|
7763
7763
|
);
|
|
7764
7764
|
if (local.y < element.y || local.y > element.y + element.height) return;
|
|
7765
|
+
const { widths, regions } = tableColumnResizeLayout(element, scale);
|
|
7766
|
+
let nearest;
|
|
7767
|
+
let distance2 = 5;
|
|
7768
|
+
for (const region of regions) {
|
|
7769
|
+
if (local.y < region.y || local.y >= region.y + region.height) continue;
|
|
7770
|
+
const edgeDistance = Math.abs(local.x - region.edge) * scale;
|
|
7771
|
+
if (edgeDistance <= distance2) {
|
|
7772
|
+
distance2 = edgeDistance;
|
|
7773
|
+
nearest = {
|
|
7774
|
+
elementId: element.id,
|
|
7775
|
+
boundary: region.boundary,
|
|
7776
|
+
widths,
|
|
7777
|
+
columns: element.columns,
|
|
7778
|
+
rotation: element.rotation ?? 0
|
|
7779
|
+
};
|
|
7780
|
+
}
|
|
7781
|
+
}
|
|
7782
|
+
return nearest;
|
|
7783
|
+
}
|
|
7784
|
+
function tableColumnResizeLayout(element, scale) {
|
|
7765
7785
|
const columns = tableLeafColumns(
|
|
7766
7786
|
element.columns.filter((column) => !column.hidden)
|
|
7767
7787
|
).filter((column) => !column.hidden);
|
|
@@ -7770,19 +7790,39 @@ function hitTableColumnBoundary(element, point, scale, _document) {
|
|
|
7770
7790
|
const widths = weights.map(
|
|
7771
7791
|
(value) => element.width * 96 / 25.4 * value / total
|
|
7772
7792
|
);
|
|
7793
|
+
const regions = [];
|
|
7794
|
+
if (element.locked || element.visible === false || element.groupPath?.length)
|
|
7795
|
+
return { widths, regions };
|
|
7796
|
+
const rowHeight = element.headerRowHeight ?? 9;
|
|
7797
|
+
const depth = element.showHeader === false ? 0 : tableHeaderDepth(element.columns);
|
|
7798
|
+
const headers = tableHeaderCells(element);
|
|
7773
7799
|
let offset = 0;
|
|
7774
|
-
for (let
|
|
7775
|
-
offset += widths[
|
|
7776
|
-
const edge =
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7800
|
+
for (let boundary = 0; boundary < widths.length - 1; boundary++) {
|
|
7801
|
+
offset += widths[boundary] * 25.4 / 96;
|
|
7802
|
+
const edge = element.x + offset;
|
|
7803
|
+
const add = (top, bottom, header) => {
|
|
7804
|
+
bottom = Math.min(bottom, element.height);
|
|
7805
|
+
if (bottom <= top) return;
|
|
7806
|
+
regions.push({
|
|
7807
|
+
boundary,
|
|
7808
|
+
edge,
|
|
7809
|
+
x: edge - 5 / scale,
|
|
7810
|
+
y: element.y + top,
|
|
7811
|
+
width: 10 / scale,
|
|
7812
|
+
height: bottom - top,
|
|
7813
|
+
header
|
|
7814
|
+
});
|
|
7815
|
+
};
|
|
7816
|
+
for (let row = 0; row < depth; row++) {
|
|
7817
|
+
if (headers.some(
|
|
7818
|
+
(cell) => row >= cell.rowIndex && row < cell.rowIndex + cell.rowSpan && (cell.columnIndex === boundary + 1 || cell.columnIndex + cell.colSpan === boundary + 1)
|
|
7819
|
+
)) {
|
|
7820
|
+
add(row * rowHeight, (row + 1) * rowHeight, true);
|
|
7821
|
+
}
|
|
7822
|
+
}
|
|
7823
|
+
add(depth * rowHeight, element.height, false);
|
|
7785
7824
|
}
|
|
7825
|
+
return { widths, regions };
|
|
7786
7826
|
}
|
|
7787
7827
|
function resizeTableColumns(session, dx, dy) {
|
|
7788
7828
|
const angle = session.rotation * Math.PI / 180;
|
|
@@ -9002,7 +9042,8 @@ function drawPrintDesignDebugOverlay(params) {
|
|
|
9002
9042
|
table,
|
|
9003
9043
|
params.scale,
|
|
9004
9044
|
params.data,
|
|
9005
|
-
element.type === "table" && params.showTableSelectors !== false && params.selectedIds.length === 1 && params.selectedIds[0] === element.id
|
|
9045
|
+
element.type === "table" && params.showTableSelectors !== false && params.selectedIds.length === 1 && params.selectedIds[0] === element.id,
|
|
9046
|
+
options.showHitTarget ? pointer : null
|
|
9006
9047
|
);
|
|
9007
9048
|
}
|
|
9008
9049
|
});
|
|
@@ -9032,7 +9073,7 @@ function drawPrintDesignDebugOverlay(params) {
|
|
|
9032
9073
|
}
|
|
9033
9074
|
context.restore();
|
|
9034
9075
|
}
|
|
9035
|
-
function drawTableDebugBounds(context, table, scale, data = {}, showSelectors = false) {
|
|
9076
|
+
function drawTableDebugBounds(context, table, scale, data = {}, showSelectors = false, pointer = null) {
|
|
9036
9077
|
const bounds = getSelectionRect(table, scale, data);
|
|
9037
9078
|
const centerX = (bounds.x + bounds.width / 2) * scale;
|
|
9038
9079
|
const centerY = (bounds.y + bounds.height / 2) * scale;
|
|
@@ -9060,6 +9101,41 @@ function drawTableDebugBounds(context, table, scale, data = {}, showSelectors =
|
|
|
9060
9101
|
selector.height * scale
|
|
9061
9102
|
);
|
|
9062
9103
|
}
|
|
9104
|
+
const hit = pointer ? hitTableColumnBoundary(table, pointer, scale) : void 0;
|
|
9105
|
+
context.setLineDash([]);
|
|
9106
|
+
for (const region of tableColumnResizeLayout(table, scale).regions) {
|
|
9107
|
+
if (!region.header) continue;
|
|
9108
|
+
const active = hit?.boundary === region.boundary;
|
|
9109
|
+
context.fillStyle = active ? "rgba(34,197,94,0.35)" : "rgba(236,72,153,0.18)";
|
|
9110
|
+
context.fillRect(
|
|
9111
|
+
region.x * scale,
|
|
9112
|
+
region.y * scale,
|
|
9113
|
+
region.width * scale,
|
|
9114
|
+
region.height * scale
|
|
9115
|
+
);
|
|
9116
|
+
context.strokeStyle = active ? "#16a34a" : "#ec4899";
|
|
9117
|
+
context.strokeRect(
|
|
9118
|
+
region.x * scale,
|
|
9119
|
+
region.y * scale,
|
|
9120
|
+
region.width * scale,
|
|
9121
|
+
region.height * scale
|
|
9122
|
+
);
|
|
9123
|
+
context.fillStyle = active ? "#16a34a" : "#db2777";
|
|
9124
|
+
context.fillRect(
|
|
9125
|
+
region.edge * scale - 0.5,
|
|
9126
|
+
region.y * scale,
|
|
9127
|
+
1,
|
|
9128
|
+
region.height * scale
|
|
9129
|
+
);
|
|
9130
|
+
context.font = "10px sans-serif";
|
|
9131
|
+
context.textAlign = "left";
|
|
9132
|
+
context.textBaseline = "bottom";
|
|
9133
|
+
context.fillText(
|
|
9134
|
+
`\u5217 ${region.boundary + 1}/${region.boundary + 2} \xB15px${active ? " \u547D\u4E2D" : ""}`,
|
|
9135
|
+
region.edge * scale + 6,
|
|
9136
|
+
region.y * scale
|
|
9137
|
+
);
|
|
9138
|
+
}
|
|
9063
9139
|
context.restore();
|
|
9064
9140
|
}
|
|
9065
9141
|
function drawElementBounds(context, element, scale, color2, data = {}) {
|
|
@@ -9484,7 +9560,7 @@ var PrintDesignRenderer = class extends PrintDesignTextEditing {
|
|
|
9484
9560
|
}
|
|
9485
9561
|
}
|
|
9486
9562
|
const debugOptions = resolvePrintDesignDebugOptions(this.options.debug);
|
|
9487
|
-
if (
|
|
9563
|
+
if (debugOptions.enabled) {
|
|
9488
9564
|
ctx.save();
|
|
9489
9565
|
ctx.beginPath();
|
|
9490
9566
|
ctx.rect(0, 0, pageWidth, pageHeight);
|
|
@@ -9492,7 +9568,7 @@ var PrintDesignRenderer = class extends PrintDesignTextEditing {
|
|
|
9492
9568
|
drawPrintDesignDebugOverlay({
|
|
9493
9569
|
context: ctx,
|
|
9494
9570
|
page,
|
|
9495
|
-
data: this.options.data,
|
|
9571
|
+
data: preview?.data ?? this.options.data,
|
|
9496
9572
|
scale,
|
|
9497
9573
|
options: debugOptions,
|
|
9498
9574
|
pointer: this.debugPointer,
|
|
@@ -11065,8 +11141,11 @@ var PrintDesignInteraction = class extends PrintDesignRenderer {
|
|
|
11065
11141
|
return;
|
|
11066
11142
|
}
|
|
11067
11143
|
if (this.options.preview && !session) {
|
|
11068
|
-
|
|
11069
|
-
|
|
11144
|
+
this.updateCursor(event, point);
|
|
11145
|
+
if (resolvePrintDesignDebugOptions(this.options.debug).enabled) {
|
|
11146
|
+
this.debugPointer = point;
|
|
11147
|
+
this.render();
|
|
11148
|
+
}
|
|
11070
11149
|
return;
|
|
11071
11150
|
}
|
|
11072
11151
|
if (!session) {
|
|
@@ -12191,7 +12270,14 @@ var PrintDesignInteraction = class extends PrintDesignRenderer {
|
|
|
12191
12270
|
y: (event.clientY - rect2.top - origin2.y) / origin2.scale
|
|
12192
12271
|
};
|
|
12193
12272
|
const source = this.previewSourceAt(cursorPoint2, origin2.scale);
|
|
12194
|
-
|
|
12273
|
+
const editable = source && !source.element.locked && !this.options.readonly;
|
|
12274
|
+
const boundary = editable && source.previewElement?.type === "table" && !event.shiftKey && !event.metaKey && !event.ctrlKey && hitTableColumnBoundary(
|
|
12275
|
+
source.previewElement,
|
|
12276
|
+
cursorPoint2,
|
|
12277
|
+
origin2.scale,
|
|
12278
|
+
this.container.ownerDocument
|
|
12279
|
+
);
|
|
12280
|
+
this.canvas.style.cursor = boundary ? "col-resize" : editable ? "move" : "grab";
|
|
12195
12281
|
return;
|
|
12196
12282
|
}
|
|
12197
12283
|
const rect = this.canvas.getBoundingClientRect();
|
package/dist/index.js
CHANGED
|
@@ -7760,6 +7760,26 @@ function hitTableColumnBoundary(element, point, scale, _document) {
|
|
|
7760
7760
|
-(element.rotation ?? 0) * Math.PI / 180
|
|
7761
7761
|
);
|
|
7762
7762
|
if (local.y < element.y || local.y > element.y + element.height) return;
|
|
7763
|
+
const { widths, regions } = tableColumnResizeLayout(element, scale);
|
|
7764
|
+
let nearest;
|
|
7765
|
+
let distance2 = 5;
|
|
7766
|
+
for (const region of regions) {
|
|
7767
|
+
if (local.y < region.y || local.y >= region.y + region.height) continue;
|
|
7768
|
+
const edgeDistance = Math.abs(local.x - region.edge) * scale;
|
|
7769
|
+
if (edgeDistance <= distance2) {
|
|
7770
|
+
distance2 = edgeDistance;
|
|
7771
|
+
nearest = {
|
|
7772
|
+
elementId: element.id,
|
|
7773
|
+
boundary: region.boundary,
|
|
7774
|
+
widths,
|
|
7775
|
+
columns: element.columns,
|
|
7776
|
+
rotation: element.rotation ?? 0
|
|
7777
|
+
};
|
|
7778
|
+
}
|
|
7779
|
+
}
|
|
7780
|
+
return nearest;
|
|
7781
|
+
}
|
|
7782
|
+
function tableColumnResizeLayout(element, scale) {
|
|
7763
7783
|
const columns = tableLeafColumns(
|
|
7764
7784
|
element.columns.filter((column) => !column.hidden)
|
|
7765
7785
|
).filter((column) => !column.hidden);
|
|
@@ -7768,19 +7788,39 @@ function hitTableColumnBoundary(element, point, scale, _document) {
|
|
|
7768
7788
|
const widths = weights.map(
|
|
7769
7789
|
(value) => element.width * 96 / 25.4 * value / total
|
|
7770
7790
|
);
|
|
7791
|
+
const regions = [];
|
|
7792
|
+
if (element.locked || element.visible === false || element.groupPath?.length)
|
|
7793
|
+
return { widths, regions };
|
|
7794
|
+
const rowHeight = element.headerRowHeight ?? 9;
|
|
7795
|
+
const depth = element.showHeader === false ? 0 : tableHeaderDepth(element.columns);
|
|
7796
|
+
const headers = tableHeaderCells(element);
|
|
7771
7797
|
let offset = 0;
|
|
7772
|
-
for (let
|
|
7773
|
-
offset += widths[
|
|
7774
|
-
const edge =
|
|
7775
|
-
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7798
|
+
for (let boundary = 0; boundary < widths.length - 1; boundary++) {
|
|
7799
|
+
offset += widths[boundary] * 25.4 / 96;
|
|
7800
|
+
const edge = element.x + offset;
|
|
7801
|
+
const add = (top, bottom, header) => {
|
|
7802
|
+
bottom = Math.min(bottom, element.height);
|
|
7803
|
+
if (bottom <= top) return;
|
|
7804
|
+
regions.push({
|
|
7805
|
+
boundary,
|
|
7806
|
+
edge,
|
|
7807
|
+
x: edge - 5 / scale,
|
|
7808
|
+
y: element.y + top,
|
|
7809
|
+
width: 10 / scale,
|
|
7810
|
+
height: bottom - top,
|
|
7811
|
+
header
|
|
7812
|
+
});
|
|
7813
|
+
};
|
|
7814
|
+
for (let row = 0; row < depth; row++) {
|
|
7815
|
+
if (headers.some(
|
|
7816
|
+
(cell) => row >= cell.rowIndex && row < cell.rowIndex + cell.rowSpan && (cell.columnIndex === boundary + 1 || cell.columnIndex + cell.colSpan === boundary + 1)
|
|
7817
|
+
)) {
|
|
7818
|
+
add(row * rowHeight, (row + 1) * rowHeight, true);
|
|
7819
|
+
}
|
|
7820
|
+
}
|
|
7821
|
+
add(depth * rowHeight, element.height, false);
|
|
7783
7822
|
}
|
|
7823
|
+
return { widths, regions };
|
|
7784
7824
|
}
|
|
7785
7825
|
function resizeTableColumns(session, dx, dy) {
|
|
7786
7826
|
const angle = session.rotation * Math.PI / 180;
|
|
@@ -9000,7 +9040,8 @@ function drawPrintDesignDebugOverlay(params) {
|
|
|
9000
9040
|
table,
|
|
9001
9041
|
params.scale,
|
|
9002
9042
|
params.data,
|
|
9003
|
-
element.type === "table" && params.showTableSelectors !== false && params.selectedIds.length === 1 && params.selectedIds[0] === element.id
|
|
9043
|
+
element.type === "table" && params.showTableSelectors !== false && params.selectedIds.length === 1 && params.selectedIds[0] === element.id,
|
|
9044
|
+
options.showHitTarget ? pointer : null
|
|
9004
9045
|
);
|
|
9005
9046
|
}
|
|
9006
9047
|
});
|
|
@@ -9030,7 +9071,7 @@ function drawPrintDesignDebugOverlay(params) {
|
|
|
9030
9071
|
}
|
|
9031
9072
|
context.restore();
|
|
9032
9073
|
}
|
|
9033
|
-
function drawTableDebugBounds(context, table, scale, data = {}, showSelectors = false) {
|
|
9074
|
+
function drawTableDebugBounds(context, table, scale, data = {}, showSelectors = false, pointer = null) {
|
|
9034
9075
|
const bounds = getSelectionRect(table, scale, data);
|
|
9035
9076
|
const centerX = (bounds.x + bounds.width / 2) * scale;
|
|
9036
9077
|
const centerY = (bounds.y + bounds.height / 2) * scale;
|
|
@@ -9058,6 +9099,41 @@ function drawTableDebugBounds(context, table, scale, data = {}, showSelectors =
|
|
|
9058
9099
|
selector.height * scale
|
|
9059
9100
|
);
|
|
9060
9101
|
}
|
|
9102
|
+
const hit = pointer ? hitTableColumnBoundary(table, pointer, scale) : void 0;
|
|
9103
|
+
context.setLineDash([]);
|
|
9104
|
+
for (const region of tableColumnResizeLayout(table, scale).regions) {
|
|
9105
|
+
if (!region.header) continue;
|
|
9106
|
+
const active = hit?.boundary === region.boundary;
|
|
9107
|
+
context.fillStyle = active ? "rgba(34,197,94,0.35)" : "rgba(236,72,153,0.18)";
|
|
9108
|
+
context.fillRect(
|
|
9109
|
+
region.x * scale,
|
|
9110
|
+
region.y * scale,
|
|
9111
|
+
region.width * scale,
|
|
9112
|
+
region.height * scale
|
|
9113
|
+
);
|
|
9114
|
+
context.strokeStyle = active ? "#16a34a" : "#ec4899";
|
|
9115
|
+
context.strokeRect(
|
|
9116
|
+
region.x * scale,
|
|
9117
|
+
region.y * scale,
|
|
9118
|
+
region.width * scale,
|
|
9119
|
+
region.height * scale
|
|
9120
|
+
);
|
|
9121
|
+
context.fillStyle = active ? "#16a34a" : "#db2777";
|
|
9122
|
+
context.fillRect(
|
|
9123
|
+
region.edge * scale - 0.5,
|
|
9124
|
+
region.y * scale,
|
|
9125
|
+
1,
|
|
9126
|
+
region.height * scale
|
|
9127
|
+
);
|
|
9128
|
+
context.font = "10px sans-serif";
|
|
9129
|
+
context.textAlign = "left";
|
|
9130
|
+
context.textBaseline = "bottom";
|
|
9131
|
+
context.fillText(
|
|
9132
|
+
`\u5217 ${region.boundary + 1}/${region.boundary + 2} \xB15px${active ? " \u547D\u4E2D" : ""}`,
|
|
9133
|
+
region.edge * scale + 6,
|
|
9134
|
+
region.y * scale
|
|
9135
|
+
);
|
|
9136
|
+
}
|
|
9061
9137
|
context.restore();
|
|
9062
9138
|
}
|
|
9063
9139
|
function drawElementBounds(context, element, scale, color2, data = {}) {
|
|
@@ -9482,7 +9558,7 @@ var PrintDesignRenderer = class extends PrintDesignTextEditing {
|
|
|
9482
9558
|
}
|
|
9483
9559
|
}
|
|
9484
9560
|
const debugOptions = resolvePrintDesignDebugOptions(this.options.debug);
|
|
9485
|
-
if (
|
|
9561
|
+
if (debugOptions.enabled) {
|
|
9486
9562
|
ctx.save();
|
|
9487
9563
|
ctx.beginPath();
|
|
9488
9564
|
ctx.rect(0, 0, pageWidth, pageHeight);
|
|
@@ -9490,7 +9566,7 @@ var PrintDesignRenderer = class extends PrintDesignTextEditing {
|
|
|
9490
9566
|
drawPrintDesignDebugOverlay({
|
|
9491
9567
|
context: ctx,
|
|
9492
9568
|
page,
|
|
9493
|
-
data: this.options.data,
|
|
9569
|
+
data: preview?.data ?? this.options.data,
|
|
9494
9570
|
scale,
|
|
9495
9571
|
options: debugOptions,
|
|
9496
9572
|
pointer: this.debugPointer,
|
|
@@ -11063,8 +11139,11 @@ var PrintDesignInteraction = class extends PrintDesignRenderer {
|
|
|
11063
11139
|
return;
|
|
11064
11140
|
}
|
|
11065
11141
|
if (this.options.preview && !session) {
|
|
11066
|
-
|
|
11067
|
-
|
|
11142
|
+
this.updateCursor(event, point);
|
|
11143
|
+
if (resolvePrintDesignDebugOptions(this.options.debug).enabled) {
|
|
11144
|
+
this.debugPointer = point;
|
|
11145
|
+
this.render();
|
|
11146
|
+
}
|
|
11068
11147
|
return;
|
|
11069
11148
|
}
|
|
11070
11149
|
if (!session) {
|
|
@@ -12189,7 +12268,14 @@ var PrintDesignInteraction = class extends PrintDesignRenderer {
|
|
|
12189
12268
|
y: (event.clientY - rect2.top - origin2.y) / origin2.scale
|
|
12190
12269
|
};
|
|
12191
12270
|
const source = this.previewSourceAt(cursorPoint2, origin2.scale);
|
|
12192
|
-
|
|
12271
|
+
const editable = source && !source.element.locked && !this.options.readonly;
|
|
12272
|
+
const boundary = editable && source.previewElement?.type === "table" && !event.shiftKey && !event.metaKey && !event.ctrlKey && hitTableColumnBoundary(
|
|
12273
|
+
source.previewElement,
|
|
12274
|
+
cursorPoint2,
|
|
12275
|
+
origin2.scale,
|
|
12276
|
+
this.container.ownerDocument
|
|
12277
|
+
);
|
|
12278
|
+
this.canvas.style.cursor = boundary ? "col-resize" : editable ? "move" : "grab";
|
|
12193
12279
|
return;
|
|
12194
12280
|
}
|
|
12195
12281
|
const rect = this.canvas.getBoundingClientRect();
|