mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-26 09:08:13 +08:00
Migrate build system from Webpack to Parcel (#1102)
* Migrate webpack to parcel * Always colour shell output * Fix typos * Fix updateImage function having undefined editorInstance * Readd webpack for deployment builds (licence checker) * Only use webpack for license generation * Re add typscript support * Fix cloudlare deploy * Bump wasm-pack version * Update ci script * Print versions in ci script * Use optional-dependencies for wasm-pack * Execute wget after rust install * Finding wasm-opt version * Print wasm-opt version * Revert test? * Try to revert * Deploy cloudflare via github actions * Fix indentation in ci script * Change project to graphite-dev * Trigger ci * Parcel ci (#1152) * CI Test * Add write permissions for pr * Manually add cloudflare ci comment to prs * Unskip cargo about * Make compile on new versions of npm * Add deployment script to rebuild editor.graphite.rs on tag creation * Remove deploy script * Comment out unused Svelte props causing warnings * Many small fixes, including fixing @ imports --------- Co-authored-by: hypercube <0hypercube@gmail.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
hypercube
Keavon Chambers
parent
b0a3632868
commit
1180b19284
@@ -1,15 +1,15 @@
|
||||
import type WasmBindgenPackage from "@graphite/../wasm/pkg";
|
||||
import type WasmBindgenPackage from "@graphite-frontend/wasm/pkg";
|
||||
import init, { setRandomSeed, wasmMemory, JsEditorHandle } from "@graphite-frontend/wasm/pkg/graphite_wasm.js";
|
||||
import { panicProxy } from "@graphite/utility-functions/panic-proxy";
|
||||
import { type JsMessageType } from "@graphite/wasm-communication/messages";
|
||||
import { createSubscriptionRouter, type SubscriptionRouter } from "@graphite/wasm-communication/subscription-router";
|
||||
|
||||
export type WasmRawInstance = typeof WasmBindgenPackage;
|
||||
export type WasmEditorInstance = InstanceType<WasmRawInstance["JsEditorHandle"]>;
|
||||
export type WasmRawInstance = WebAssembly.Memory;
|
||||
export type WasmEditorInstance = JsEditorHandle;
|
||||
export type Editor = Readonly<ReturnType<typeof createEditor>>;
|
||||
|
||||
// `wasmImport` starts uninitialized because its initialization needs to occur asynchronously, and thus needs to occur by manually calling and awaiting `initWasm()`
|
||||
let wasmImport: WasmRawInstance | undefined;
|
||||
let editorInstance: WasmEditorInstance | undefined;
|
||||
let wasmImport: WebAssembly.Memory | undefined;
|
||||
|
||||
export async function updateImage(path: BigUint64Array, mime: string, imageData: Uint8Array, transform: Float64Array, documentId: bigint): Promise<void> {
|
||||
const blob = new Blob([imageData], { type: mime });
|
||||
@@ -21,7 +21,7 @@ export async function updateImage(path: BigUint64Array, mime: string, imageData:
|
||||
image.src = blobURL;
|
||||
await image.decode();
|
||||
|
||||
editorInstance?.setImageBlobURL(documentId, path, blobURL, image.naturalWidth, image.naturalHeight,transform);
|
||||
window["editorInstance"]?.setImageBlobURL(documentId, path, blobURL, image.naturalWidth, image.naturalHeight, transform);
|
||||
}
|
||||
|
||||
export async function fetchImage(path: BigUint64Array, mime: string, documentId: bigint, url: string): Promise<void> {
|
||||
@@ -35,7 +35,7 @@ export async function fetchImage(path: BigUint64Array, mime: string, documentId:
|
||||
image.src = blobURL;
|
||||
await image.decode();
|
||||
|
||||
editorInstance?.setImageBlobURL(documentId, path, blobURL, image.naturalWidth, image.naturalHeight, undefined);
|
||||
window["editorInstance"]?.setImageBlobURL(documentId, path, blobURL, image.naturalWidth, image.naturalHeight, undefined);
|
||||
}
|
||||
|
||||
const tauri = "__TAURI_METADATA__" in window && import("@tauri-apps/api");
|
||||
@@ -44,7 +44,7 @@ export async function dispatchTauri(message: unknown): Promise<void> {
|
||||
|
||||
try {
|
||||
const response = await (await tauri).invoke("handle_message", { message });
|
||||
editorInstance?.tauriResponse(response);
|
||||
window["editorInstance"]?.tauriResponse(response);
|
||||
} catch {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error("Failed to dispatch Tauri message");
|
||||
@@ -58,18 +58,16 @@ export async function initWasm(): Promise<void> {
|
||||
|
||||
// Import the WASM module JS bindings and wrap them in the panic proxy
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
wasmImport = await import("@graphite/../wasm/pkg");
|
||||
await init();
|
||||
wasmImport = await wasmMemory();
|
||||
|
||||
|
||||
// Provide a random starter seed which must occur after initializing the WASM module, since WASM can't generate its own random numbers
|
||||
const randomSeedFloat = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
|
||||
const randomSeed = BigInt(randomSeedFloat);
|
||||
wasmImport?.setRandomSeed(randomSeed);
|
||||
// TODO: Tauri: reenable this
|
||||
// try {
|
||||
// await invoke("set_random_seed", { seed: randomSeedFloat });
|
||||
// } catch {
|
||||
// // Ignore errors
|
||||
// }
|
||||
setRandomSeed(randomSeed);
|
||||
if (!tauri) return;
|
||||
await (await tauri).invoke("set_random_seed", { seed: randomSeedFloat });
|
||||
}
|
||||
|
||||
// Should be called after running `initWasm()` and its promise resolving
|
||||
@@ -80,12 +78,12 @@ export function createEditor() {
|
||||
const raw: WasmRawInstance = wasmImport;
|
||||
|
||||
// Instance: Object containing many functions from `editor_api.rs` that are part of the editor instance (generated by wasm-bindgen)
|
||||
const instance: WasmEditorInstance = new raw.JsEditorHandle((messageType: JsMessageType, messageData: Record<string, unknown>): void => {
|
||||
const instance: WasmEditorInstance = new JsEditorHandle((messageType: JsMessageType, messageData: Record<string, unknown>): void => {
|
||||
// This callback is called by WASM when a FrontendMessage is received from the WASM wrapper editor instance
|
||||
// We pass along the first two arguments then add our own `raw` and `instance` context for the last two arguments
|
||||
subscriptions.handleJsMessage(messageType, messageData, raw, instance);
|
||||
});
|
||||
editorInstance = instance;
|
||||
window["editorInstance"] = instance;
|
||||
|
||||
// Subscriptions: Allows subscribing to messages in JS that are sent from the WASM backend
|
||||
const subscriptions: SubscriptionRouter = createSubscriptionRouter();
|
||||
|
||||
Reference in New Issue
Block a user