PandaText / Docs / Web

PandaText for Web

The same engine as WebAssembly, for any page in Chrome, Safari and Firefox.

Supported platforms

Chrome
Tested.
Safari
Tested.
Firefox
Tested.
Safari on iOS
Tested.
Chrome on Android
Supported.
Edge
Supported, with other Chromium-based browsers.

Get started

Install the package, then load your fonts, create a view and set the text. Package sources come with early access.

Web

Requires: A bundler or any server that serves files over HTTP.

1 Install

Install the two packages:

npm install @pandatext/core @pandatext/textview

With Vite, keep them out of dependency pre-bundling, so the engine finds its .wasm file:

// vite.config.ts
export default defineConfig({
  optimizeDeps: { exclude: ["@pandatext/core", "@pandatext/textview"] },
});

The engine loads pandatext_core.wasm, and word dictionaries for Chinese, Japanese and Thai only when such text appears. A Content Security Policy needs 'wasm-unsafe-eval' in script-src.

2 Create the view

The view for any page in Chrome, Safari and Firefox. It fills its container, so give #editor a height. It paints no background: set one in CSS on the container if you need it.

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"));

API

After setup, every call does the same job on every platform. Open the Editor API for Web.

Uses the same API column as React, Electron, tldraw.