Compare commits

...
15 Commits
Author SHA1 Message Date
xiaoqidun 385d7aa531 feat(编辑能力): 支持拖拽时画布自动跟随
build.yaml / build (push) Successful in 43s
2026-10-29 17:26:46 +08:00
xiaoqidun 94157b10c3 fix(编辑能力): 修复页外文字框拖拽
build.yaml / build (push) Successful in 45s
2026-10-29 16:59:05 +08:00
xiaoqidun aebcda51a3 fix(编辑能力): 修复旋转后纵向滚动回弹
build.yaml / build (push) Successful in 44s
2026-10-29 16:44:01 +08:00
xiaoqidun 19084bb40b fix(编辑能力): 修复横向滚动回弹 2026-10-29 16:37:35 +08:00
xiaoqidun 545b697310 fix(编辑能力): 修复文字编辑查找快捷键
build.yaml / build (push) Successful in 47s
2026-10-29 16:25:24 +08:00
xiaoqidun 1a25472b43 fix(编辑能力): 修复搜索焦点抢占问题 2026-10-29 16:17:41 +08:00
xiaoqidun af80fcc9ba fix(编辑能力): 修复全选及全局快捷键 2026-10-29 16:09:14 +08:00
xiaoqidun 838a769c5b fix(编辑能力): 修复输入状态下标签快捷键
build.yaml / build (push) Successful in 47s
2026-10-29 15:01:52 +08:00
xiaoqidun 5b4f2472f7 fix(编辑能力): 修复快捷键遗漏及跨文档干扰
build.yaml / build (push) Successful in 45s
2026-10-29 14:52:40 +08:00
xiaoqidun fb51fd3b07 fix(编辑能力): 修复工具栏复制剪切粘贴失效
build.yaml / build (push) Successful in 45s
2026-10-29 14:30:58 +08:00
xiaoqidun 80e548f93e fix(编辑能力): 修复工具栏撤销快捷键失效
build.yaml / build (push) Successful in 48s
2026-10-29 14:16:31 +08:00
xiaoqidun 9c3a04b7eb feat(编辑能力): 优化分布操作,提前禁用无效方向
build.yaml / build (push) Successful in 46s
2026-10-29 13:54:58 +08:00
xiaoqidun 9bb6c9141a feat(基础镜像): 升级到alpine:3.24.3
build.yaml / build (push) Successful in 44s
2026-10-29 08:46:31 +08:00
xiaoqidun 4320b53d4a fix(字体处理): 修复字体补全误配与共享释放
build.yaml / build (push) Successful in 49s
2026-10-28 22:07:10 +08:00
xiaoqidun e5d7f577c7 fix(字体处理): 修复字体续建、替换与复制异常 2026-10-28 21:59:44 +08:00
7 changed files with 168 additions and 34 deletions

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
# 基础镜像
FROM alpine:3.24.2
FROM alpine:3.24.3
# 作者信息
LABEL authors="肖其顿 (XIAO QI DUN)"
+86 -27
View File
@@ -110,6 +110,7 @@ function createDocumentState() {
styleOriginal: null,
objectClipboardToken: null,
styleClipboard: null,
objectDistribution: null,
outlineExpanded: new Map(),
textFonts: [],
textFontID: null,
@@ -683,9 +684,12 @@ function createPrintDialog(tab) {
});
}
function openPrintPanel() {
const tab = documentTab();
async function openPrintPanel() {
const tab = documentTab(), content = documentContentKey(state);
if (!tab.state.doc || !tab.state.ready || document.body.hasAttribute("data-busy") || formDialogOpen()) return;
const current = () => isForegroundDocument(tab) && content === documentContentKey(state);
if (!await canvasEditor.commitNudge() || !current() || !await canvasEditor.commitText() || !current()
|| !await canvasEditor.commitCrop() || !current() || document.body.hasAttribute("data-busy") || formDialogOpen()) return;
tab.print ||= createPrintDialog(tab);
tab.print.open({tab, document:documentEntryKey(tab.state.doc.documents?.[tab.state.doc.documentIndex || 0]), call:(name, ...args) => callTabWASM(tab, name, ...args), page:tab.state.pageIndex,
selection:tab.state.pageSelection.size ? selectedPageIndexes() : [], annotations:tab.state.renderAnnotations,
@@ -1260,7 +1264,7 @@ el.objectAlign.addEventListener("change", () => {
el.objectDistribute.addEventListener("change", () => {
const axis = el.objectDistribute.value;
el.objectDistribute.value = "";
if (axis && canvasEditor.items().length >= 3) {
if (axis && !el.objectDistribute.disabled && state.objectDistribution?.axes?.includes(axis)) {
return changeDocument("ofdgoDistributeObjects", canvasEditor.selected, axis);
}
});
@@ -1307,7 +1311,10 @@ for (const [button, tool] of [[el.drawLineButton, "line"], [el.drawRectangleButt
}
editorClick(el.eraseButton, () => toggleDrawingTool(el.eraseMode.value));
el.eraseMode.addEventListener("change", () => {
if (canvasEditor.tool.startsWith("erase-")) canvasEditor.setTool(el.eraseMode.value);
if (canvasEditor.tool.startsWith("erase-")) {
canvasEditor.setTool(el.eraseMode.value);
canvasEditor.focus();
}
});
for (const input of [el.shapeFill, el.shapeStroke]) {
input.addEventListener("change", changeShapeStyle);
@@ -1407,9 +1414,11 @@ for (const [button, ungroup] of [[el.groupObjectsButton, false], [el.ungroupObje
});
}
el.arrowTool.addEventListener("change", async () => {
const tab = documentTab(), content = documentContentKey(state);
const current = () => isForegroundDocument(tab) && state.editing && content === documentContentKey(state);
const tool = el.arrowTool.value;
el.arrowTool.value = "";
if (await canvasEditor.commitText() && await canvasEditor.commitCrop()) {
if (await canvasEditor.commitText() && current() && await canvasEditor.commitCrop() && current()) {
const item = canvasEditor.selected;
if (lineShape(item?.shape)) {
const box = item.geometry;
@@ -1420,6 +1429,7 @@ el.arrowTool.addEventListener("change", async () => {
state.selectObjects = true;
canvasEditor.setTool(tool);
updateControls();
canvasEditor.focus();
}
});
el.copyStyleButton.addEventListener("click", async () => {
@@ -1807,6 +1817,7 @@ el.annotationButton.addEventListener("click", toggleAnnotations);
document.addEventListener("copy", copySelection);
document.addEventListener("cut", copySelection);
el.viewerPanel.addEventListener("paste", pasteEditorContent);
el.editorTools.addEventListener("paste", pasteEditorContent);
document.addEventListener("selectionchange", syncSelection);
el.exportFormat.addEventListener("change", () => updateDPIControl());
el.outputCompression.addEventListener("change", () => {
@@ -1933,6 +1944,11 @@ el.documentNewTab.addEventListener("click", openEmptyDocumentTab);
updateSidebarState();
boot();
function editorShortcutTarget(target) {
const field = target.closest?.("input, textarea, select, [contenteditable]");
return !field || el.editorTools.contains(field) && field.matches('select, input[type="checkbox"], input[type="radio"], input[type="color"], input[type="range"]');
}
function handleKeyDown(event) {
if (sealPreview) {
if (event.key === "Escape") { event.preventDefault(); finishSealPosition(); }
@@ -1965,10 +1981,11 @@ function handleKeyDown(event) {
return;
}
if ((event.ctrlKey || event.metaKey) && !event.shiftKey && key.toLowerCase() === "a" && state.doc
&& el.viewerPanel.contains(target) && !target.closest("input, textarea, select, [contenteditable]")) {
&& (el.viewerPanel.contains(target) || state.editing && el.editorTools.contains(target)) && editorShortcutTarget(target)) {
event.preventDefault();
if (!document.body.hasAttribute("data-busy") && !formDialogOpen()) {
selectDocumentText();
if (state.editing) canvasEditor.selectAll(state.pageIndex);
else selectDocumentText();
}
return;
}
@@ -1994,7 +2011,7 @@ function handleKeyDown(event) {
}
}
if (event.ctrlKey || event.metaKey) {
if (state.editing && !target.closest("input, textarea, select, [contenteditable]")
if (state.editing && editorShortcutTarget(target)
&& (key.toLowerCase() === "z" || (!event.shiftKey && key.toLowerCase() === "y"))) {
event.preventDefault();
(key.toLowerCase() === "y" || event.shiftKey ? el.redoButton : el.undoButton).click();
@@ -2010,6 +2027,11 @@ function handleKeyDown(event) {
if (!state.doc) {
return;
}
if (state.editing && !event.shiftKey && el.editorTools.contains(target) && editorShortcutTarget(target)
&& (key === "Delete" || key === "F2")) {
canvasEditor.keyDown(event, true);
return;
}
if (key === "Escape" && !event.shiftKey && state.documentSelection && el.viewerPanel.contains(target)
&& !target.closest("input, textarea, select, [contenteditable]")) {
event.preventDefault();
@@ -2019,11 +2041,7 @@ function handleKeyDown(event) {
}
if (key === "F3") {
event.preventDefault();
if (state.searchMatches.length) {
selectSearchMatch(event.shiftKey ? Math.max(0, state.searchIndex) - 1 : state.searchIndex + 1);
} else {
focusSearch();
}
focusSearch(event.shiftKey ? -1 : 1);
return;
}
if (key === "Escape" && !event.shiftKey && !el.searchPanel.hidden && (el.pageListPanel.contains(target) || el.viewerPanel.contains(target))) {
@@ -4353,15 +4371,15 @@ async function validateRichText(item, model, width, fonts = []) {
attempted.add(id);
const original = (await callWASM("ofdgoEditorFont", id)).bytes;
const [source] = await callWASM("ofdgoFontFaces", original);
if (!source?.postscriptName) throw error;
if (!source?.postscriptName || !source.familyKey) throw error;
await fontManager.loadFaces(data => callWASM("ofdgoFontFaces", data));
const candidates = fontManager.editorFonts().filter(font => !font.disabled && font.postscriptName === source.postscriptName);
const candidates = fontManager.editorFonts().filter(font => !font.disabled && font.postscriptName === source.postscriptName && font.familyKey === source.familyKey);
let recovered;
for (const choice of candidates) {
try {
const data = await readTextFont(choice, tab);
const [face] = await callWASM("ofdgoFontFaces", data);
if (face?.postscriptName !== source.postscriptName) continue;
if (face?.postscriptName !== source.postscriptName || face.familyKey !== source.familyKey) continue;
await callWASM("ofdgoCheckTextFont", data, model.runs.filter(run => run.format.font === id).map(run => run.text).join(""));
recovered = { key: id, data, choice };
break;
@@ -4376,8 +4394,9 @@ async function validateRichText(item, model, width, fonts = []) {
rich.imports.set(id, recovered.data);
rich.choices.set(id, recovered.choice);
const previous = rich.faces.get(id);
if (previous) document.fonts.delete(previous);
rich.faces.set(id, face); document.fonts.add(face);
rich.faces.set(id, face);
if (previous && ![...rich.faces.values()].includes(previous)) document.fonts.delete(previous);
document.fonts.add(face);
if (!editing.composing && !editing.saving) { rich.selection(); rich.render(); updateObjectControls(canvasEditor.selected); }
}
}
@@ -4443,9 +4462,10 @@ async function beginCanvasText(index, box, surface, page) {
const item = { ...state.textDefaults, ...box, wrap: Boolean(box.wrap),
index, page, surface, node, text: "", draft: true, fontData: data };
const model = { ...richTextModel(item), autoWidth: !box.wrap };
const key = `temp-font-${crypto.randomUUID()}`;
const key = font.embedded ? font.id.slice(9) : `temp-font-${crypto.randomUUID()}`;
const embedded = font.embedded && state.doc?.fonts?.some(font => font.id === key && font.embedded);
model.runs[0].format.font = key;
canvasEditor.editText(item, face, null, { model, faces: new Map([[key, face]]), fonts: [{ key, data }] });
canvasEditor.editText(item, face, null, { model, faces: new Map([[key, face]]), fonts: embedded ? [] : [{ key, data }], resources: new Map([[key, data]]) });
} catch (err) {
if (isForegroundDocument(tab) && openSeq === state.openSeq) showError(err, false);
} finally {
@@ -4608,8 +4628,12 @@ async function prepareTextFaces(tab, runs, font, key, value, rich) {
const candidates = [...choices.values()];
for (const choice of candidates) {
if (choice.menuFamily || ![...originals.values()].some(font => textFontIdentity(font || {}) === textFontIdentity(choice)) && (!font || textFontIdentity(choice) !== textFontIdentity(font))) continue;
try {
const [metadata] = await callWASM("ofdgoFontFaces", await read(choice));
if (metadata) Object.assign(choice, metadata, { index: choice.index });
} catch (error) {
if (!current() || !font || textFontIdentity(choice) === textFontIdentity(font)) throw error;
}
}
const groups = await groupTextFonts(candidates, tab), changes = new Map(), prepared = new Map();
for (const run of runs) {
@@ -4675,7 +4699,9 @@ async function changeTextFace(font, key, value) {
tab.editTask = busy;
setBusy(true, "", 0, "", tab);
try {
const fonts = fontManager.editorFonts().filter(font => font.familyKey === source.familyKey && textFontSource(font) === textFontSource(source)), groups = await groupTextFonts(fonts, tab);
const available = source.embedded ? (state.doc?.fonts || []).filter(font => font.embedded || font.status === "matched").map(font => documentFontChoice(font.id)) : fontManager.editorFonts();
const fonts = [source, ...available.filter(font => textFontIdentity(font) !== textFontIdentity(source))].filter(font => font.familyKey === source.familyKey && textFontSource(font) === textFontSource(source));
const groups = await groupTextFonts(fonts, tab);
if (!current()) return;
const index = fonts.findIndex(choice => textFontIdentity(choice) === textFontIdentity(source));
const faces = (groups.find(group => group.includes(index)) || []).map(index => fonts[index]);
@@ -4726,6 +4752,7 @@ async function changeTextFace(font, key, value) {
rich.faces.set(entry.key, entry.face);
if (previous && ![...rich.faces.values()].includes(previous)) document.fonts.delete(previous);
if (!entry.choice.embedded) rich.imports.set(entry.key, entry.data);
else rich.resources.set(entry.key, entry.data);
rich.choices.set(entry.key, entry.choice);
document.fonts.add(entry.face);
}
@@ -10842,8 +10869,9 @@ async function selectDocumentText() {
function copyEditorSelection(event) {
const tab = documentTab(), state = tab.state;
if (!state.editing || !canvasEditor.enabled || !canvasEditor.selected || !el.viewerPanel.contains(event.target)
|| canvasEditor.input || canvasEditor.crop || canvasEditor.drag || document.body.hasAttribute("data-busy")) return false;
if (!state.editing || !canvasEditor.enabled || !canvasEditor.selected || !editorShortcutTarget(event.target)
|| !el.viewerPanel.contains(event.target) && !el.editorTools.contains(event.target)
|| canvasEditor.input || canvasEditor.crop || canvasEditor.drag || document.body.hasAttribute("data-busy") || formDialogOpen()) return false;
const items = canvasEditor.items().slice().sort((a, b) => a.order - b.order);
const cut = event.type === "cut";
if (!canEditObject(canvasEditor.selected, "copy") || cut && !canEditObject(canvasEditor.selected, "delete")) {
@@ -10919,7 +10947,7 @@ function visiblePageBounds(index) {
async function pasteEditorContent(event) {
const tab = documentTab(), state = tab.state;
if (!state.editing || event.target.closest?.("input, textarea, select, [contenteditable]") || formDialogOpen()) return;
if (!state.editing || !editorShortcutTarget(event.target) || formDialogOpen()) return;
event.preventDefault();
const token = event.clipboardData.getData(OBJECT_CLIPBOARD_TYPE);
const files = Array.from(event.clipboardData.files);
@@ -10988,7 +11016,7 @@ async function pasteEditorContent(event) {
function copySelection(event) {
if (sealPreview) return;
if (event.target.closest?.("input, textarea, [contenteditable]")) {
if (!editorShortcutTarget(event.target)) {
return;
}
const selection = document.getSelection();
@@ -11033,7 +11061,14 @@ function copySelection(event) {
event.preventDefault();
}
function focusSearch() {
async function focusSearch(direction = 0) {
if (canvasEditor.input || canvasEditor.crop || canvasEditor.nudge || canvasEditor.nudgeCommit) {
const tab = documentTab(), content = documentContentKey(state);
const current = () => isForegroundDocument(tab) && content === documentContentKey(state);
if (!await canvasEditor.commitNudge() || !current() || !await canvasEditor.commitText() || !current()
|| !await canvasEditor.commitCrop() || !current() || document.body.hasAttribute("data-busy") || formDialogOpen()) return;
}
if (direction && state.searchMatches.length) return selectSearchMatch((direction < 0 ? Math.max(0, state.searchIndex) : state.searchIndex) + direction);
if (!state.showPages) {
toggleSidebar("pages");
}
@@ -12737,6 +12772,30 @@ function updateEditorTools() {
updateObjectControls(canvasEditor.selected);
}
function updateObjectDistribution(item, disabled) {
const tab = documentTab(), state = tab.state;
const ids = item?.items?.slice().sort((a, b) => a.order - b.order).map(member => member.id) || [];
if (disabled || ids.length < 3) state.objectDistribution = null;
else {
const { openSeq, wasmSeq } = state, revision = state.editorInfo?.revision;
const key = JSON.stringify([openSeq, wasmSeq, revision, item.index, ids]);
if (state.objectDistribution?.key !== key) {
const request = state.objectDistribution = { key, axes: [] };
const current = () => !tab.closed && state.objectDistribution === request && state.openSeq === openSeq && state.wasmSeq === wasmSeq && state.editorInfo?.revision === revision;
callTabWASM(tab, "ofdgoDistributionAxes", item.index, ids).then(axes => {
if (!current()) return;
request.axes = axes;
if (isForegroundDocument(tab)) updateObjectControls(canvasEditor.selected);
}).catch(error => {
if (current() && isForegroundDocument(tab)) showError(error, false);
});
}
}
const axes = state.objectDistribution?.axes || [];
el.objectDistribute.disabled = disabled || !axes.length;
for (const option of el.objectDistribute.options) if (option.value) option.disabled = !axes.includes(option.value);
}
function updateObjectControls(item, reset = false) {
const members = item?.items || (item ? [item] : []);
const disabled = !item || Boolean(item.draft) || !state.ready || state.exporting;
@@ -12754,7 +12813,7 @@ function updateObjectControls(item, reset = false) {
el.cropImageButton.setAttribute("data-pressed", String(cropping));
el.resetCropButton.textContent = cropping ? "取消" : "还原";
el.resetCropButton.disabled = canEditObject(item, "resetCrop") ? disabled : el.cropImageButton.disabled || !cropping && (item.scoped ? !item.cropped : !item.imageBounds || ["x", "y", "width", "height"].every(key => Math.abs(item[key] - item.imageBounds[key]) < 1e-9));
el.objectDistribute.disabled = el.objectAlign.disabled || !item.items || item.items.length < 3;
updateObjectDistribution(item, el.objectAlign.disabled);
el.editObjectButton.disabled = disabled || (item.items ? !item.items.every(member => member.type === "TextObject" && !member.richText)
: !canEditObject(item, "children") && (item.type === "PathObject"
|| !(item.type === "TextObject" && canEditObject(item, "rewriteText")) && !canEditObject(item, item.type === "TextObject" ? "textContent" : item.type === "ImageObject" ? "replaceImage" : "update")));
+22 -5
View File
@@ -1122,6 +1122,14 @@ export class CanvasEditor {
return true;
}
selectAll(index) {
if (!this.enabled || this.input || this.crop || this.drag || this.nudge || this.nudgeCommit || this.options.busy()) return;
this.setTool("");
document.getSelection()?.removeAllRanges();
this.setSelection(this.pageItems(index));
this.focus();
}
clear() {
this.closeText();
this.closeCrop();
@@ -1204,6 +1212,10 @@ export class CanvasEditor {
rect: item.surface.getBoundingClientRect(), rotation: this.options.rotation(),
clientX: event.clientX, clientY: event.clientY,
};
const extent = this.drag.extent = document.createElement("div");
Object.assign(extent.style, { position: "absolute", left: "0", top: "0", pointerEvents: "none",
width: `${this.viewer.scrollWidth}px`, height: `${this.viewer.scrollHeight}px` });
this.viewer.append(extent);
if (!this.drag.corner) {
const selected = this.items();
const targets = [...item.surface.querySelectorAll(".edit-object")]
@@ -1310,6 +1322,7 @@ export class CanvasEditor {
}
const from = drag.origin ||= pagePoint(drag.clientX, drag.clientY, drag.rect, drag.item.page, drag.rotation);
const to = pagePoint(event.clientX, event.clientY, drag.rect, drag.item.page, drag.rotation);
this.autoScroll(drag);
if (drag.item.type === "TextObject" && (drag.corner === "w" || drag.corner === "e")) {
if (drag.item.textFrame) {
const frame = drag.item.textFrame, [a, b, c, d] = frame.matrix;
@@ -1355,14 +1368,13 @@ export class CanvasEditor {
drag.axis = event.shiftKey ? Math.abs(drag.change.x) >= Math.abs(drag.change.y) ? "x" : "y" : "";
if (drag.axis) drag.change[drag.axis === "x" ? "y" : "x"] = 0;
this.snap(drag, event.altKey);
this.autoScroll(drag);
}
this.place(drag.item, drag.change);
}
scroll() {
const drag = this.drag;
if (!drag || !drag.item && !drag.marquee || drag.corner || !drag.pointer) {
if (!drag || !drag.item && !drag.marquee || !drag.pointer) {
this.cancel();
return;
}
@@ -1477,6 +1489,7 @@ export class CanvasEditor {
}
if (drag.corner && drag.box) {
this.drag = null;
drag.extent?.remove();
this.viewer.releasePointerCapture(drag.pointerID);
const frame = drag.item.textFrame;
const geometry = drag.item.oriented?.box || drag.item.geometry || (frame ? { x: drag.item.x, width: textFrameBox(drag.item).width } : drag.item);
@@ -1490,6 +1503,7 @@ export class CanvasEditor {
}
if (drag.change && (drag.change.x || drag.change.y || drag.change.scale !== 1)) {
this.drag = null;
drag.extent?.remove();
drag.guides?.preview.remove();
this.viewer.releasePointerCapture(drag.pointerID);
Promise.resolve(this.options.onTransform(drag.item, drag.change)).finally(() => this.place(drag.item));
@@ -1500,6 +1514,7 @@ export class CanvasEditor {
const drag = this.drag;
this.drag = null;
if (drag) {
drag.extent?.remove();
for (const item of drag.erased || []) item.node.classList.remove("erasing");
if (drag.crop) {
this.crop.box = drag.box;
@@ -1741,8 +1756,8 @@ export class CanvasEditor {
return this.nudgeCommit;
}
keyDown(event) {
if (event.defaultPrevented || event.target?.closest("input, textarea, select, [contenteditable]")) return;
keyDown(event, toolbar = false) {
if (event.defaultPrevented || !toolbar && event.target?.closest("input, textarea, select, [contenteditable]")) return;
if (this.crop && !this.options.busy()) {
if (event.key === "Escape" || event.key === "Enter") {
event.preventDefault();
@@ -1952,7 +1967,9 @@ export class CanvasEditor {
}
});
input.addEventListener("keydown", (event) => {
if ((event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey && event.key.toLowerCase() === "s") return;
if (event.key === "F3" && !event.ctrlKey && !event.metaKey && !event.altKey) return;
if ((event.ctrlKey || event.metaKey) && !event.altKey && (["s", "w", "tab"].includes(event.key.toLowerCase())
|| !event.shiftKey && ["f", "o", "p"].includes(event.key.toLowerCase()))) return;
event.stopPropagation();
if (event.isComposing || editing.composing || editing.saving) {
return;
+1 -1
View File
@@ -183,7 +183,7 @@ export class FontPicker {
}
keyDown(event) {
if (event.isComposing) return;
if (event.isComposing || event.key === "Tab" && (event.ctrlKey || event.metaKey || event.altKey)) return;
if (!["Escape", "Enter", "ArrowDown", "ArrowUp", "Tab"].includes(event.key)) return;
event.stopPropagation();
if (event.key === "Escape") {
+9
View File
@@ -292,6 +292,15 @@ export function createPageView(context) {
unmountPage(index) {
const shell = pageView.pageShell(index);
if (!shell) return;
if (context.state.editing && shell.classList.contains("rendered")) {
const bounds = shell.getBoundingClientRect(), viewport = context.el.viewerPanel.getBoundingClientRect();
const margin = context.state.pageWindow?.overscan ?? 600;
const bottom = Math.max(bounds.bottom, bounds.top + shell.scrollHeight);
if (bottom >= viewport.top - margin && bounds.top <= viewport.bottom + margin) {
context.state.selectedPages.add(index);
return;
}
}
const selection = document.getSelection();
const range = !selection.isCollapsed && selection.rangeCount ? selection.getRangeAt(0) : null;
if (context.canvasEditor.input?.item.index === index || context.canvasEditor.crop?.item.index === index
+15
View File
@@ -5703,6 +5703,20 @@ func (e *businessEngine) orderObjects(args []platformValue) (any, error) {
})
}
// distributionAxes 获取画布选区可用的等间距分布方向
// 入参: args 页面索引和画布对象标识数组
// 返回: any 可用方向, error 路径或度量错误
func (e *businessEngine) distributionAxes(args []platformValue) (any, error) {
if e.currentEditor == nil {
return nil, fmt.Errorf("no document is being edited")
}
paths, err := e.editorTargetPaths(e.stringsFromJS(args[1]))
if err != nil {
return nil, err
}
return e.currentEditor.DistributionAxes(args[0].Int(), paths)
}
// distributeObjects 按指定轴等距分布选区
// 入参: args 页面索引、对象标识数组和分布轴
// 返回: any 文档信息, error 错误信息
@@ -8159,6 +8173,7 @@ func (e *businessEngine) businessCommands() map[string]func([]platformValue) (an
"ofdgoImportObjects": e.importObjects,
"ofdgoOrderObjects": e.orderObjects,
"ofdgoDistributeObjects": e.distributeObjects,
"ofdgoDistributionAxes": e.distributionAxes,
"ofdgoRotateObjects": e.rotateObjects,
"ofdgoFlipObjects": e.flipObjects,
"ofdgoCropImage": e.cropImage,
+34
View File
@@ -808,6 +808,40 @@ func (e *Editor) ResizeTargets(page int, paths []ObjectPath, box Box) error {
return e.TransformTargets(page, paths, Matrix{a: sx, d: sy, e: box.X - bounds.X*sx, f: box.Y - bounds.Y*sy})
}
// DistributionAxes 获取选区可保持位置顺序的等间距分布方向,不修改文档或历史
// 入参: page 页面索引, paths 按绘制顺序排列的完整路径
// 返回: []string 可用的horizontal和vertical方向, error 路径或度量错误
func (e *Editor) DistributionAxes(page int, paths []ObjectPath) ([]string, error) {
objects, annotations, groups, err := editorTargetGroups(paths)
if err != nil {
return nil, err
}
var boxes []Box
var positions []editorObjectPosition
if len(groups) == 0 {
boxes, positions, _, err = e.selectionGeometry(page, objects, annotations)
} else {
boxes, _, _, err = e.targetGeometry(page, paths)
positions = make([]editorObjectPosition, len(paths))
for i := range positions {
positions[i].index = i
}
}
if err != nil {
return nil, err
}
axes := []string{}
if len(boxes) < 3 {
return axes, nil
}
for _, axis := range []string{"horizontal", "vertical"} {
if _, err := editorDistribution(boxes, positions, axis); err == nil {
axes = append(axes, axis)
}
}
return axes, nil
}
// ArrangeTargets 对齐或等距分布跨容器选区,单选对齐页面
// 入参: page 页面索引, paths 按绘制顺序排列的完整路径, distribute 是否分布, direction 对齐方向或分布轴
// 返回: error 路径、方向或编辑错误