PandaText for Electron
The web view in an Electron renderer, with the app’s menus and clipboard.
Supported platforms
Get started
Install the package, then load your fonts, create a view and set the text. Package sources come with early access.
Electron
Requires: The web requirements of @pandatext/core.
1 Install
Install the web packages in the renderer’s project:
npm install @pandatext/core @pandatext/textviewServe the renderer from a custom scheme (protocol.handle) or a bundler, not file:, since the engine fetches its .wasm by URL. Add 'wasm-unsafe-eval' to the Content Security Policy.
In the main process, let the renderer use the clipboard:
const allowed = new Set(["clipboard-read", "clipboard-sanitized-write"]);
session.defaultSession.setPermissionRequestHandler((_contents, permission, callback) =>
callback(allowed.has(permission)),
);
session.defaultSession.setPermissionCheckHandler((_contents, permission) => allowed.has(permission));2 Create the view
In the renderer, create the view as on the web. Edit menu items call the view.
import { createPandaText } from "@pandatext/core";
import { PandaTextView } from "@pandatext/textview";
import "@pandatext/textview/PandaTextView.css";
const textEngine = await createPandaText();
const font = textEngine.createFontFromBytes(fontBytes);
const fontCollection = textEngine.createCollectionFromFonts([font]);
const textView = new PandaTextView({ textEngine, fontCollection, text: "Hello PandaText" });
textView.mount(document.querySelector("#editor"));
// Edit menu items (Undo, Redo, Select All) go through the view:
textView.performEditAction("undo");API
After setup, every call does the same job on every platform. Open the Editor API for Electron.