rhwp WASM Engine
Relevant source files
The following files were used as context for generating this wiki page:
The rhwp WASM Engine is the core document processing component of the OpenHWP project. Developed by Edward Kim, it is written in Rust and compiled to WebAssembly (WASM) to provide cross-platform document parsing and rendering capabilities. In the OpenHWP architecture, the rhwp engine functions as the primary "document engine," while the Deno-based desktop application serves as a thin "platform shell" around it.
The engine is responsible for handling the internal complexities of the Korean HWP and HWPX document formats. By utilizing WASM, the engine can be loaded through npm packages rather than being statically compiled into the desktop shell, allowing for a clean separation of concerns between document logic and the user interface.
Sources: README.en.md:3-8, README.en.md:12-16, README.md:11-15
Architecture and Integration
The rhwp engine is integrated into OpenHWP via standard web technologies. Because OpenHWP utilizes a Chromium (CEF) backend through Deno, it can execute the WASM engine with high performance and identical behavior across macOS, Windows, and Linux.
Component Breakdown
The engine is distributed through two primary npm packages, each serving a distinct purpose in the application lifecycle:
| Package | Purpose | Primary Functions |
|---|---|---|
@rhwp/core | Document Parsing & Viewing | Parsing bytes, rendering pages to SVG, PDF export. |
@rhwp/editor | Interactive Editing | Full editor UI provided as an embeddable iframe. |
Sources: README.en.md:20-30, README.md:18-28, README.en.md:65-68
System Data Flow
The following diagram illustrates how the rhwp engine interacts with the Deno desktop shell and the local file system using the File System Access API.
The desktop shell retrieves document bytes from the disk and passes them to the rhwp engine. The engine then returns rendered content (like SVG) back to the shell for display in the webview.
Sources: README.en.md:11-20, README.en.md:33-51
Implementation Details
Core Viewing Logic
The @rhwp/core package provides the HwpDocument class. Developers must first initialize the WASM module before instantiating the document object with raw byte data.
import init, { HwpDocument } from "@rhwp/core";
// Initialize the WASM engine
await init();
// Load document from Uint8Array bytes
const doc = new HwpDocument(bytes);
// Render specific page (index 0) to SVG for the viewer
document.querySelector("#viewer").innerHTML = doc.renderPageSvg(0);
Sources: README.en.md:22-28, README.md:20-26
Editor Integration
The editor is designed to be a "full editor UI" that is embedded as an iframe. This encapsulates the entire editing experience, including complex state management, within the rhwp engine's scope.
import { createEditor } from "@rhwp/editor";
// Embed the editor into a DOM element
const editor = await createEditor("#editor");
Sources: README.en.md:30-34, README.md:28-32
Roadmap and Capabilities
The rhwp engine is central to the project's phased roadmap, supporting both current viewing capabilities and future editing and export features.
- Parsing: Supports both
.hwpand.hwpxformats. - Rendering: Currently supports rendering document pages to SVG for browser-based viewing.
- Editing: Future implementation will wire
@rhwp/editorto theFileSystemFileHandlefor native-like save functionality. - Exporting: PDF export is planned to be handled directly by the rhwp engine.
Sources: README.en.md:63-71, README.md:60-68
Development Environment
Since the engine is delivered via npm and utilized in a Deno environment, the project maintains a specific toolchain to ensure compatibility.
- Runtime: Deno ≥ 2.9.0 is required for
deno desktopfeatures. - Package Management: Deno's built-in package management or
bun(for specific scripts) is used to handle the@rhwpdependencies. - Testing: Linting and testing are performed through the Deno CLI.
Sources: CONTRIBUTING.md:12-16, CONTRIBUTING.md:25-28, orca.yaml:13-17
The rhwp WASM Engine provides the critical heavy-lifting for document manipulation, allowing OpenHWP to remain a lightweight, cross-platform desktop application without the need for the original Hancom Office suite.