Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/development/ci-failures.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ The OpenCode hang tracked as #162 is unrelated and was not verified here.

The toolbar top-bar test timed out on both main and PR #689 at 50% zoom. The center of the fixture node was behind the left rail, so the drag pressed Add Text. Use an exposed point on the node and check its hit target before sending pointer input. [Main run](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/47344640055/job/145081431931) · [PR run](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/47378835105/job/145201585744)

## Python shard inventory after adding a test module

The core shard failed on both main and PR #698 because the Ark availability test was missing from the shard manifest. Register each new test module in one shard and run the existing inventory test. [Main run](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/47460479983/job/145484772476) · [PR run](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/47484854000/job/145564214390)

## Packaged runtime dependency resolution

A Windows installer rerun and the independent Linux wheel check resolved FastAPI 0.165.1 with OpenTelemetry API 1.46.0. FastAPI passed positional arguments that the newer logging API accepts only as keywords, so HTTP requests returned 500. The wheel declares the compatible OpenTelemetry range until FastAPI supports the new API. Desktop packaging also constrains wheel dependencies to the repository lock. Verify fresh wheel installation and both desktop builds when changing these constraints. [Windows run](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/47382086691/job/145228863573) · [Linux run](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/47389658023/job/145239847848)
Expand Down
7 changes: 7 additions & 0 deletions docs/development/lessons.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ When work exposes a consequential risk or a recurring problem, add a lesson or u
- **Evidence:** [PR #380](https://github.com/ThinkFlowLab/OpenDirector/pull/380) reproduced delayed assistant reads closing the project picker and ending new-project renaming. Project creation and opening succeeded; the chat's readiness effect moved focus and triggered the other controls' dismissal handlers.
- **Check:** Hold the assistant read until the project picker or name editor is active, then release it and verify that both the control and its focus remain. Preserve focus requested by explicitly opening chat or changing conversations, while respecting a later user focus change. Distinguish a controlled reproduction from proof of the original CI event order.
- In a narrow chat, dismissing the pending canvas references on pointer-down moved a result button before pointer-up. The click landed on the card and never reached the button. Exercise a real pointer click after returning from a selected canvas node and verify that the node becomes visible again. / 窄屏聊天曾在按下鼠标时收起待引用面板,使结果按钮在松开鼠标前移位。回归应从已有选区的画布返回对话,实际点击结果按钮,并检查对应节点是否重新进入视口。
- **Clipboard follow-up:** Chromium can target a prior DOM selection when the canvas already owns focus. A toast, project title, or file picker input can receive the clipboard event even though the canvas is the active element. Check both the active element and selection. Use real copy, cut, and paste keystrokes after moving focus between the canvas and a text field. [Browser regression](../../tests/browser/canvas_system_clipboard.mjs)

## Clipboard HTML parsing stays outside the browser document

- **Trigger:** Reading HTML from the system clipboard before deciding what to paste.
- **Evidence:** [CodeQL on PR #698](https://github.com/ThinkFlowLab/OpenDirector/runs/145564305656) flagged assignment of clipboard HTML to a template element.
- **Check:** Parse the clipboard string into a data tree without a browser document. Verify known markers, mixed text and images, and inline image paste with the [parser tests](../../tests/canvasSystemClipboard.test.ts) and the real browser clipboard.

## Pointer capture does not transfer keyboard focus

Expand Down
3 changes: 2 additions & 1 deletion docs/guides/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ The first launch creates an untitled canvas. Later launches can restore the most
- To explore a complete project, select **Browse example canvases** on an empty canvas or **Example canvases** in the project menu. The list shows sample sizes and download progress, and offers manual download links where available. Importing a sample opens a new project. A ZIP containing one `.canvas` file is unpacked automatically. If a download returns a webpage, the picker reports the error.
- To connect a generation model, open **Settings → Model connections**.
- Right-click empty canvas space to create a node, paste, undo, or redo.
- To copy nodes between tabs in the same browser profile, select them and press `Ctrl+C` (`⌘C` on Mac). Wait for the copy confirmation, then focus the destination canvas and press `Ctrl+V` (`⌘V` on Mac). If the shortcut is unavailable, right-click the destination canvas and choose **Paste**.
- To copy nodes between tabs in the same browser profile, select them and press `Ctrl+C` (`⌘C` on Mac). Wait for the copy confirmation, then focus the destination canvas and press `Ctrl+V` (`⌘V` on Mac). You can also right-click the canvas and choose **Paste** if your browser allows clipboard access.
- Focus the canvas and paste text, a screenshot, or media files from your clipboard to add them as nodes. Copy a text node to paste its text into another app.
- Click **Upload** on the left or drag files onto the canvas to add assets. Click **Asset library** to choose existing material.
- Single-image HEIC and HEIF photos are supported; multi-image files and sequences are rejected. OpenDirector retains the original file and creates an oriented, full-resolution PNG for browser display. Downloads, canvas archives and timeline media packages retain the original. Files must decode successfully and contain at most 25 million pixels. If an original is unavailable, exporting reports an error instead of substituting the display preview.
- Double-click a node's name to rename it. Double-click its content to open the appropriate editor or preview.
Expand Down
3 changes: 2 additions & 1 deletion docs/guides/user-guide.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ vLLM-Omni 视频连接支持直接输入小数秒,例如 `6.583333`。CLI 可
- 想看看完整项目时,点击空画布上的“浏览示例画布”,或从项目菜单打开“示例画布”。列表会显示示例大小和下载进度,部分示例也提供手动下载链接。导入后会打开一个新项目。下载包中若只有一个 `.canvas` 文件,会自动解包。若下载返回网页,列表会提示错误。
- 要连接生成模型,打开“设置 → 模型接入”。
- 右键空白画布可新建节点、粘贴、撤销或重做。
- 在同一浏览器配置文件的两个标签页间复制节点时,先选中节点,按 `Ctrl+C`(Mac 上为 `⌘C`)。看到复制提示后,点击目标画布并按 `Ctrl+V`(Mac 上为 `⌘V`)。如果快捷键不可用,可右键点击目标画布并选择“粘贴”。
- 在同一浏览器配置文件的两个标签页间复制节点时,先选中节点,按 `Ctrl+C`(Mac 上为 `⌘C`)。看到复制提示后,点击目标画布并按 `Ctrl+V`(Mac 上为 `⌘V`)。如果浏览器允许读取剪贴板,也可以右键点击画布并选择“粘贴”。
- 将焦点移到画布后,粘贴剪贴板中的文本、截图或媒体文件,即可添加节点。复制文本节点后,可以把正文粘贴到其他应用。
- 点击左侧“上传”或将文件拖入画布添加素材;“资产库”可选择已有素材。
- 支持单图 HEIC 和 HEIF 照片,不接受多图文件和图像序列。OpenDirector 保留原文件,并生成方向正确、完整分辨率的 PNG 供浏览器显示;下载、画布归档和时间线媒体包均保留原件。文件须能完整解码,且像素总数不超过 2500 万。原件不可用时,导出会报错,不会改用显示预览图。
- 双击节点名称重命名;双击节点内容进入相应编辑或预览界面。
Expand Down
25 changes: 25 additions & 0 deletions feature-assets/canvas-system-clipboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# System clipboard evidence

These captures use an isolated creation server and synthetic project content.
The baseline is `93bd25b08a53633c08a9d904b1043e8cf6c2de65`. The recording and
corrected screenshots use the build from `cd82ad1ae2294decdd3162806228922b2117bd86`.

1. Copy an image node. Copy `External clipboard en-US` from a separate
text field, then paste it onto the canvas.
2. On the baseline, the canvas pastes another image. The system
clipboard still contains the external text. [Baseline screenshot](before.png)
3. The candidate creates a text node containing `External clipboard en-US`.
[Corrected screenshot](after.png)

The [video](clipboard.mp4) shows the same reproduction, cut and paste, menu
paste, screenshot and HTML image paste, and the project after reopening.
It also shows a large UTF-8 paste rejected before the canvas changes.
The model service is a fixture. The recording does not call a real provider.

The [browser regression](../../tests/browser/canvas_system_clipboard.mjs)
checks the same workflow in English and Chinese.

The [cross-tab screenshot](cross-tab-after.png) shows the destination project
after the source tab closed and the destination reopened. The
[cross-canvas browser test](../../tests/browser/cross_canvas_paste.mjs) verifies
the registered assets by fingerprint.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"mdast-util-from-markdown": "2.1.0",
"mediabunny": "1.62.1",
"opencode-ai": "1.19.5",
"parse5": "7.3.0",
"react": "19.3.1",
"react-dom": "19.3.1",
"streamdown": "2.5.0",
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/python_shards.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"core": [
"tests/test_a2_repros.py",
"tests/test_app_settings.py",
"tests/test_ark_availability.py",
"tests/test_ark_plan_models.py",
"tests/test_asset_names.py",
"tests/test_atlascloud.py",
Expand Down
1 change: 1 addition & 0 deletions scripts/run-browser-suite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const workflows = [
{ name: "canvas composer placement", script: "tests/browser/canvas_composer_placement.mjs" },
{ name: "created node focus", script: "tests/browser/created_node_focus.mjs" },
{ name: "cross canvas paste", script: "tests/browser/cross_canvas_paste.mjs" },
{ name: "system clipboard", script: "tests/browser/canvas_system_clipboard.mjs" },
{ name: "reference reconnect", script: "tests/browser/reference_reconnect.mjs" },
{
name: "context menu dismissal",
Expand Down
189 changes: 189 additions & 0 deletions src/canvas/canvasSystemClipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import { defaultTreeAdapter, html as htmlTree, parseFragment, type DefaultTreeAdapterTypes } from "parse5";
import { downloadFilename } from "./assets.ts";

const MARKER = "data-opendirector-clipboard";
const HTML_WRAPPERS = new Set(["html", "body", "div", "p", "span"]);
const COPY_ID = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;
const IMAGE_BYTES = 32 * 1024 * 1024;
const RASTER_IMAGE = /^image\/(?:png|jpe?g|webp|gif|avif|bmp|tiff?|heic|heif)$/i;

export interface CanvasClipboardSnapshot {
html: string;
text: string;
files: File[];
}

export function snapshotClipboard(data: DataTransfer): CanvasClipboardSnapshot {
const files = Array.from(data.files);
return {
html: data.getData("text/html"),
text: data.getData("text/plain"),
files: files.length ? files : Array.from(data.items).flatMap((item) => {
const file = item.kind === "file" ? item.getAsFile() : null;
return file ? [file] : [];
}),
};
}

export async function readSystemClipboard(imageName: string): Promise<CanvasClipboardSnapshot> {
const entries = await navigator.clipboard.read();
const readText = async (mime: string) => {
const entry = entries.find((item) => item.types.includes(mime));
return entry ? (await entry.getType(mime)).text() : "";
};
const [html, text, files] = await Promise.all([
readText("text/html"),
readText("text/plain"),
Promise.all(entries.flatMap((entry) => {
const type = entry.types.find((mime) => RASTER_IMAGE.test(mime));
return type ? [entry.getType(type).then((blob) => clipboardImageFile(blob, imageName))] : [];
})),
]);
return { html, text, files };
}

export function canvasClipboardFormats(id: string, text: string) {
const marker = document.createElement("span");
marker.setAttribute(MARKER, id);
marker.textContent = text || "\u200b";
return { html: marker.outerHTML, text };
}

export function writeClipboardEvent(
event: ClipboardEvent,
{ html, text }: ReturnType<typeof canvasClipboardFormats>,
) {
if (event.defaultPrevented || !event.cancelable || !event.clipboardData) return false;
event.clipboardData.setData("text/html", html);
event.clipboardData.setData("text/plain", text);
event.preventDefault();
return true;
}

export function writeClipboardFromMenu(formats: ReturnType<typeof canvasClipboardFormats>) {
let written = false;
const copy = (event: ClipboardEvent) => {
written = writeClipboardEvent(event, formats);
};
document.addEventListener("copy", copy, { capture: true, once: true });
try {
return document.execCommand("copy") && written;
} finally {
document.removeEventListener("copy", copy, true);
}
}

function clipboardHtml(html: string) {
if (!html || html.length > IMAGE_BYTES * 2) return;
return parseFragment(html);
}

function isIgnorableClipboardNode(node: DefaultTreeAdapterTypes.ChildNode) {
return defaultTreeAdapter.isCommentNode(node) ||
(defaultTreeAdapter.isTextNode(node) && !node.value.trim()) ||
(defaultTreeAdapter.isElementNode(node) && node.tagName === "meta");
}

export function canvasClipboardId(html: string) {
if (!html.includes(MARKER)) return;
let content: DefaultTreeAdapterTypes.ParentNode | undefined = clipboardHtml(html);
while (content) {
const nodes: DefaultTreeAdapterTypes.ChildNode[] = content.childNodes.filter(
(node) => !isIgnorableClipboardNode(node),
);
const node = nodes[0];
if (nodes.length !== 1 || !node || !defaultTreeAdapter.isElementNode(node) ||
node.namespaceURI !== htmlTree.NS.HTML)
return;
const id = node.attrs.find((attr) => attr.name === MARKER)?.value;
if (node.tagName === "span" && id) {
if (node.childNodes.some(defaultTreeAdapter.isElementNode)) return;
return COPY_ID.test(id) ? id : undefined;
}
if (!HTML_WRAPPERS.has(node.tagName)) return;
content = node;
}
}

type ClipboardImage =
| { kind: "inline"; mime: string; base64: string }
| { kind: "url"; url: string };

export function clipboardHtmlImage(html: string): ClipboardImage | undefined {
const content = clipboardHtml(html);
if (!content) return;
const pending = [...content.childNodes];
let image: DefaultTreeAdapterTypes.Element | undefined;
for (let node = pending.pop(); node; node = pending.pop()) {
if (defaultTreeAdapter.isTextNode(node) && node.value.trim()) return;
if (!defaultTreeAdapter.isElementNode(node)) continue;
if (node.tagName === "img" && node.namespaceURI === htmlTree.NS.HTML) {
if (image) return;
image = node;
}
for (const child of node.childNodes) pending.push(child);
}
const src = image?.attrs.find((attr) => attr.name === "src")?.value;
if (!src) return;
const inline = /^data:([^;,]+);base64,/i.exec(src);
const mime = inline?.[1];
if (inline && mime && RASTER_IMAGE.test(mime))
return { kind: "inline", mime, base64: src.slice(inline[0].length) };
try {
const url = new URL(src);
if (url.protocol === "https:" && url.origin !== location.origin && !url.username && !url.password)
return { kind: "url", url: url.href };
} catch {
return undefined;
}
}

async function rasterBlob(response: Response): Promise<Blob> {
const type = response.headers.get("Content-Type")?.split(";")[0] ?? "";
if (!response.ok || !RASTER_IMAGE.test(type) ||
Number(response.headers.get("Content-Length")) > IMAGE_BYTES || !response.body) {
await response.body?.cancel();
throw new Error("Invalid clipboard image");
}
const reader = response.body.getReader();
const chunks: Uint8Array<ArrayBuffer>[] = [];
let size = 0;
try {
while (true) {
const result = await reader.read();
if (result.done) break;
size += result.value.byteLength;
if (size > IMAGE_BYTES) {
await reader.cancel();
throw new Error("Clipboard image exceeds size limit");
}
chunks.push(Uint8Array.from(result.value));
}
} finally {
reader.releaseLock();
}
return new Blob(chunks, { type });
}

function clipboardImageFile(blob: Blob, name: string) {
return new File([blob], downloadFilename(name, blob.type), { type: blob.type });
}

export async function loadClipboardImage(image: ClipboardImage, imageName: string) {
if (image.kind === "inline") {
if (image.base64.length > Math.ceil(IMAGE_BYTES / 3) * 4)
throw new Error("Clipboard image exceeds size limit");
const decoded = atob(image.base64);
if (decoded.length > IMAGE_BYTES) throw new Error("Clipboard image exceeds size limit");
const bytes = new Uint8Array(decoded.length);
for (let index = 0; index < bytes.length; index++) bytes[index] = decoded.charCodeAt(index);
return clipboardImageFile(new Blob([bytes], { type: image.mime }), imageName);
}
const response = await fetch(image.url, {
credentials: "omit",
redirect: "error",
referrerPolicy: "no-referrer",
signal: AbortSignal.timeout(10_000),
});
return clipboardImageFile(await rasterBlob(response), imageName);
}
Loading
Loading