Integrate graphics, RAW, audio and CAD Craft tools with protected saves

This commit is contained in:
SantaSpeen committed 2026-10-22 19:48:16 +03:00
1 parent 6e36b6c4b7
commit 852140c3a7
24 files changed
+600 -74

No files matched your search

+10 -6
View File
@@ -1,18 +1,20 @@
// Adapter for official office builds without a native parent-host protocol.
// Adapter for official editor builds without a native parent-host protocol.
// Loaded before WASM starts; vendor files on disk remain checksum-verifiable.
(() => {
"use strict";
const segments = location.pathname.split("/");
const id = segments[segments.lastIndexOf("addons") + 1];
if (!["wordcraft", "deckcraft"].includes(id) || parent === window || new URLSearchParams(location.search).get("host") !== "parent") return;
const extension = id === "wordcraft" ? ".docx" : ".pptx";
const legacy = { wordcraft: ".docx", deckcraft: ".pptx" };
const config = window.__filebrowserCraft || (legacy[id] ? { id, extension: legacy[id], extensions: [legacy[id]], exports: [legacy[id], ".pdf"] } : null);
if (!config || config.id !== id || parent === window || new URLSearchParams(location.search).get("host") !== "parent") return;
const accepts = (name, list) => typeof name === "string" && list.some(extension => name.toLowerCase().endsWith(extension));
const origin = location.origin;
const limit = 64 * 1024 * 1024;
const jobs = new Map();
const blobs = new Map();
let opened = false, dirty = false, revision = 0, sequence = 0;
const send = (type, data = {}, transfer = []) => parent.postMessage({ type: id + ":" + type, ...data }, origin, transfer);
const managed = name => typeof name === "string" && (name.toLowerCase().endsWith(extension) || name.toLowerCase().endsWith(".pdf"));
const managed = name => accepts(name, config.exports);
const markDirty = () => { dirty = true; revision++; send("dirty", { dirty: true }); };
const createURL = URL.createObjectURL.bind(URL), revokeURL = URL.revokeObjectURL.bind(URL);
URL.createObjectURL = blob => { const url = createURL(blob); blobs.set(url, blob); return url; };
@@ -67,13 +69,15 @@
window.addEventListener("message", event => {
if (event.source !== parent || event.origin !== origin || !event.data) return;
const message = event.data;
if (message.type === id + ":open" && !opened && message.bytes instanceof ArrayBuffer && message.bytes.byteLength <= limit && typeof message.name === "string" && message.name.toLowerCase().endsWith(extension)) {
if (message.type === id + ":open" && !opened && message.bytes instanceof ArrayBuffer && message.bytes.byteLength <= limit && typeof message.name === "string" && accepts(message.name, config.extensions)) {
const canvas = document.getElementById(id + "_canvas");
if (!canvas) { send("failed", { error: "Editor canvas unavailable" }); return; }
opened = true;
const transfer = new DataTransfer();
transfer.items.add(new File([message.bytes], message.name));
canvas.dispatchEvent(new DragEvent("drop", { bubbles: true, cancelable: true, dataTransfer: transfer }));
if (id === "vectorcraft" && window.vectorcraft?.openFile) {
Promise.resolve(window.vectorcraft.openFile(message.name, new Uint8Array(message.bytes))).catch(error => send("failed", { error: String(error) }));
} else canvas.dispatchEvent(new DragEvent("drop", { bubbles: true, cancelable: true, clientX: 0, clientY: 0, dataTransfer: transfer }));
canvas.focus();
} else if (message.type === id + ":saved" || message.type === id + ":save-error") {
const job = jobs.get(message.requestId);