Files
vectorcraft/packaging/web
dotCooCoo 82e3d6dac3 Plug-ins: the web build checks plug-ins and runs filters in a Web Worker
On the web, a plug-in being installed ran its start function and
vc_manifest on the page, and a filter ran on the page for its whole
budget, so a slow or looping module froze the tab for up to a minute
(five for a heavy filter), and Cancel could not stop it.

- A second wasm, apps/vectorcraft-plugin-worker, is built by Trunk as a
  worker (data-type="worker" with data-loader-shim in index.html). The
  page starts one worker for each check and each run, and terminates it
  on Cancel, when the document or the plug-in changes, and 5 s past the
  run's time budget, also while a dialog is open. Each worker's inbox
  holds its latest progress report and at most 8 other messages.
- crates/plugins/src/worker.rs holds the messages and the worker's
  side. Runs can pause at each vc_call (Plugin::begin_run and
  resume_run), which the desktop's synchronous calls now use too.
- Install Plug-in... and File > Open check a module in a worker first;
  the page then loads it with Plugin::load_checked, which runs none of
  its code.
- A filter that calls commands sends each call to the page. The session
  holds the run's undo step open and refuses other edits with "a
  plug-in is running: cancel it or wait for it to finish" until the run
  ends; the progress window shows at once with Cancel only.
- On the web every filter and plug-in command started from the menus
  or their dialogs runs in a worker, and the dialogs have no Preview.
  A plug-in command applies as itself, one undo step named after it.
  Commands that automation runs directly still run where they are
  called and return their result.
- packaging/web: the worker files carry no hash, so the sample cache
  rules make only the hashed app files immutable.
2026-11-22 10:15:28 -08:00
..

Hosting VectorCraft for the web

vectorcraft-web-<version>.zip (from the GitHub release, or packaging/web/package.sh) holds a static site in vectorcraft-web-<version>/:

File What it is
index.html The page. It loads everything through relative URLs.
vectorcraft-web-<hash>.js wasm-bindgen glue (generated, ES module)
vectorcraft-web-<hash>_bg.wasm The app, about 13 MB, or 5 MB with compression
vectorcraft-plugin-worker_loader.js, vectorcraft-plugin-worker.js, vectorcraft-plugin-worker_bg.wasm The plug-in worker, which checks plug-ins and runs filters off the page. These names carry no hash.
_headers, .htaccess Sample header rules for Netlify/Cloudflare Pages and Apache

There is no server-side code. Upload the folder's contents anywhere that serves static files.

Any path works

All URLs in index.html are relative (public_url = "./" in apps/vectorcraft-web/Trunk.toml), so the site works at a domain root (https://example.com/), under a prefix (https://example.com/tools/vectorcraft/) and from a CDN bucket. The app's asset names carry a content hash, so they can be cached forever. index.html and the three vectorcraft-plugin-worker files need revalidation.

Required server settings

  • MIME type: serve .wasm as application/wasm. Browsers refuse to stream-compile it under any other type, and the app then loads slowly or not at all. Serve .js as text/javascript. Most hosts already do both. For nginx, check that mime.types has application/wasm wasm;.
  • Compression: turn on gzip or Brotli for .wasm, .js and .html. That takes the download from about 13 MB to about 5 MB. You can also precompress (brotli -k *.wasm) and let the server send Content-Encoding: br.
  • Caching: Cache-Control: public, max-age=31536000, immutable on the hashed vectorcraft-web-<hash> .wasm and .js files, and no-cache on index.html and the vectorcraft-plugin-worker files. The page refuses a cached worker whose messages differ from its own, and plug-ins then fail to install and run until the browser fetches the new worker.
  • Content Security Policy: a site that sends one needs worker-src 'self' (or a script-src that allows the site's own scripts) for the plug-in worker. Without it the app runs, and plug-ins fail to install and run.
  • HTTPS: WebGPU (and the clipboard) only work in a secure context, which means https:// or http://localhost. Over plain HTTP elsewhere, the app falls back to WebGL2.
  • No special isolation headers: VectorCraft doesn't use SharedArrayBuffer, so it doesn't need Cross-Origin-Opener-Policy or Cross-Origin-Embedder-Policy. If your site already sends COEP require-corp, also send Cross-Origin-Resource-Policy: same-origin (or cross-origin when the files live on a CDN) on the app's files.

nginx example:

location /vectorcraft/ {
    types { application/wasm wasm; text/javascript js; text/html html; }
    gzip on;
    gzip_types application/wasm text/javascript text/html;
    location ~* /vectorcraft-web-[^/]*\.(wasm|js)$ { add_header Cache-Control "public, max-age=31536000, immutable"; }
    location ~* (index\.html|/vectorcraft-plugin-worker[^/]*)$ { add_header Cache-Control "no-cache"; }
}

Local test: python3 -m http.server 8765 inside the folder, then open http://localhost:8765/.

Browser requirements

The wasm is built with WebAssembly SIMD (-C target-feature=+simd128, .cargo/config.toml, #2786), so it needs a browser that has it:

Browser First version
Chrome, Edge 91
Firefox 89
Safari (macOS and iOS/iPadOS) 16.4

Source: caniuse wasm-simd and the WebAssembly feature table (webassembly.org/features). An older browser can't compile the module. There is no fallback build and no message: the page stays on "Loading VectorCraft..." and the console shows a WebAssembly compile error. The app also needs WebGPU or WebGL2 (see "Renderer selection" below). If you must serve older browsers, put a version check in front of the app on your own page.

Fonts folder

Builds made with craft-fonts (CRAFT_FONTS_DIR, all releases) have a fonts/ folder beside the wasm: the Arabic fonts the app fetches instead of embedding (about 8 MB, each next to its OFL licence). Serve it with the rest of the site. Noto Sans Arabic is fetched before the app starts; the other families load in the background and appear in the font menus as they arrive.

  • Serve .ttf as font/ttf (the browser checks each file's SHA-256, so a wrong type or a rewritten file makes the app skip that font and log web font … in the console).
  • The folder names are the files' SHA-256 prefixes, so fonts/* can be cached forever (Cache-Control: public, max-age=31536000, immutable); _headers and .htaccess do this.
  • Without the folder the app still runs, but Arabic text shows as boxes.

Embedding in a page (iframe)

<iframe
  src="https://example.com/vectorcraft/"
  title="VectorCraft vector illustration app"
  style="width: 100%; height: 720px; border: 0;"
  allow="fullscreen; clipboard-read; clipboard-write"
  allowfullscreen>
</iframe>
  • The app fills the iframe and follows its size, so size the iframe and not the app.
  • Keyboard shortcuts go to the iframe after the user clicks into it, as with any embedded app.
  • Cross-origin embeds work. Preferences are kept in the iframe's localStorage. Browsers that partition or block third-party storage may forget them between visits, and the app then starts with defaults.
  • Sandboxed iframes need at least sandbox="allow-scripts allow-same-origin allow-downloads allow-popups". Without allow-same-origin there's no storage. Without allow-downloads, Save and Export (browser downloads) are blocked.
  • Don't send X-Frame-Options: DENY or a frame-ancestors CSP that excludes the embedding page.

Renderer selection and fallback flags

VectorCraft renders with wgpu. It uses WebGPU when the browser has it and falls back to WebGL2 on its own. URL query flags override this, and they work on the iframe src too:

Flag Effect
(none) WebGPU if available, otherwise WebGL2
?webgl Force the WebGL2 backend (useful when a WebGPU driver misbehaves)
?cpu Force the CPU canvas path (slowest, most compatible)

For example: <iframe src="https://example.com/vectorcraft/?webgl" ...>.

A browser with neither WebGPU nor WebGL2 gets a message in place of the app.