EDITORCLASSBLOGLOGINOpkleOpkle, the Editor for CreatorsInfiniteExpression,In New Forms.New ContentOpkle makes an editor so anyone can build for the web without code, and share it anywhere.Blending text and screen, we build tools that make the web about imagination, not code.Building Opkle Editor: The Valkey Queue Server Basicsdev7Building Opkle Editor: The Worker Loop and AI Validationdev8Building Opkle Editor: The Preview, Straight to Codedev9Building Opkle Editor: Building Our Own Graphics Editordev10Building Opkle Editor: Turning Rust into a Graphics Enginedev111011121314...10 Building Opkle Editor: Building Our Own Graphics Editor

Once edits in the preview flowed into real EPUB code, and even the AI was working with HTML and CSS inside that flow, the next gap became quite clear. EPUB is not a format that ends with text. Images, tables, layouts, icons, shapes, backgrounds and decorative elements keep coming in. With media queries, CSS animation and image-sequence video already covered, my thinking naturally leaned toward one conclusion: I needed a dedicated editor for the graphics inside a book.

At first I could have simply bolted on an existing graphics tool. But the graphics tool Opkle Editor needed had a slightly different purpose from an ordinary design tool. It was not for making images to post on the web; it had to create and edit graphics that could be used directly inside an EPUB. Vector images, raster images, SVG, JPEG, PNG, WebP, fonts, compressed project files, the preview and the export pipeline all had to move in one flow. Opening and closing an external tool would never keep that workflow smooth.

So I decided I would have to build a graphics editor like Figma myself after all. More precisely, a graphics editor that lives inside Opkle Editor. Within an EPUB document, you should be able to create an image, draw vectors, apply image filters, convert to SVG when needed, and save it back as an EPUB asset. When someone making a book suddenly needs an image, they should be able to make the graphic in the same workflow, without leaving for another app.

Penpot's Clojure

After deciding to build a graphics editor, the first thing I looked into was Penpot. Penpot is a browser-based graphics editor with a structure in the same spirit as Figma. I downloaded the source code and started digging into the ClojureScript side. The goal was not to take the code as it was. I wanted to see what kind of state structure and rendering sense this sort of vector graphics editor has.

A vector graphics editor feels quite different from an ordinary document editor. A text editor centers on blocks, inlines, selection and undo history, while a graphics editor centers on the object tree, transforms, bounding boxes, path data, fills, strokes, layer order, groups, frames, canvas coordinates and hit testing. Even at the moment a user selects a single shape, the coordinate system, transform matrix, screen scale, selection box, resize handles, snapping and z-index all move together.

This was also what I wanted to confirm while reading the ClojureScript code. A graphics editor is not a tool you finish by building pretty UI components. The object model has to come first. I needed to see in what unit a shape is stored, how a group holds its child objects, how frames and pages are separated, which id a selection points to, and what kind of patches pile up on the undo stack.

Seeing that made my own direction clearer. A graphics editor should have an independent document model, but at the boundary where it meets the publishing document it must not lose the meaning of the result. Flowing the internal layers straight into the body text is wrong, and so is leaving only finished pixels and erasing the editability of the original. Separating the editing source from the publishing asset, and keeping only the relationship between the two stable, was the boundary an authoring tool in general needs.

A New Graphics Vector Editor

The first thing to pin down in a vector graphics editor was the object model. Rectangles, circles, paths, text, images, groups and frames all have to move inside the same canvas. Each object needs an id, and needs position, size, rotation, opacity, fill, stroke and transform information. With that state in place, selecting, moving, resizing, aligning, duplicating, deleting, undo and redo follow naturally.

I could not carry over the feel of handling blocks in a document editor as it was. Paragraphs flow from top to bottom, but graphics objects overlap on a 2D plane. Several objects can sit at the same coordinates, and the user may select the topmost one, or step into a group and select a nested object. Hit testing and layer order become the center of the editor UX.

Another thing that kept nagging me was the relationship with SVG. For using vector graphics inside EPUB, SVG is a very natural format. But if the editor's internal state is carried around as a single SVG string, editing becomes hard. It was right to manage things as an object tree internally and serialize to SVG at export or preview time. In the other direction, when an external SVG is imported, it has to be convertible into an object tree or a raster result.

I organized the interaction layer on the same principle. If buttons, shortcuts, menus and automation tools each start modifying objects directly, the undo and validation rules soon diverge. Regardless of the input method, selection, transforms, styling and asset replacement should be normalized into explicit commands, and the actual state changes should pass through the same execution boundary. Inputs may take many forms, but the operations a document accepts must be finite and verifiable. It was a textbook application of the command pattern.

Where WebAssembly Becomes Necessary

To build a graphics editor properly, I could not put every operation in the same execution layer. Work close to the DOM, such as selection and panel updates, is handled well by the browser's own language, but traversing millions of pixels or parsing compressed binaries has a different computational load and memory access pattern. If an interaction that must finish within one frame and a computation that can take tens of milliseconds or more sit on the same event loop, input lag and frozen screens show up immediately.

So WebAssembly became not just a choice of a fast language but a way to isolate the computation domain. What mattered was the size of the boundary, not the name of the language. If every small function crosses the runtime boundary, the call cost and memory copying can outweigh the actual computation. Hand over a large enough block of pixels or one complete file operation, though, and the fixed boundary cost is spread over a long stretch of computation. Just as in Amdahl's law the non-parallelizable portion sets the upper limit of the overall speedup, the serialization stretch between the browser and the computation module sets the upper limit of perceived performance.

Rust suited this layer well for making memory ownership and failure boundaries explicit. Pixels and files are ultimately contiguous bytes, so length, alignment, lifetime and maximum size have to be settled first. A safe type system reduces invalid references and lifetime problems, but it does not automatically guarantee that bytes coming in from outside are a valid image. So I treated language safety and data validation as separate responsibilities.

A computation module delivered to the browser is not done just because it runs fast. The size of the downloaded binary, the initial compile time, the first-call latency and the memory growth are all part of the user experience. I arranged things so that rarely used features are not all included in the initial boot, the common computation path stays small, and large jobs are prepared at the moment they become necessary. At this stage, I came to judge performance not by a single function's benchmark but by the total latency of transfer, initialization, computation and copying combined.

The Rust Core Factory

I began to see this Rust core as a kind of factory. The front end manages editing intent and document state, and hands the computation layer complete units of work. The results also come back not as exposed internal objects but as data with clear boundaries, such as images, vectors and fonts. Once the lifecycle of the UI and the lifecycle of numerical computation were separated, a structural change on one side no longer shook the whole of the other.

The first thing I sorted out was what format conversion really means. A raster image is a set of samples on a finite grid, and a vector image is a set of commands describing shapes and curves. Converting between them is not a mere change of file extension. Turning a vector into a raster means integrating continuous shapes according to the resolution and sample positions, and turning a raster into a vector means estimating boundaries and curvature from discrete pixels. The former is sampling of information, and the latter is model estimation that presupposes loss.

The alpha channel was also an important difference in meaning between formats. When sending semi-transparent pixels to an output that does not support transparency, you first have to decide which background to composite them against. If you simply average channel values while ignoring color space and gamma, edge brightness can change, so where possible it is more accurate to composite in linear-light space and then return to the display space. A file opening and producing a visually identical result were different verification problems.

In the filter layer, I treated the pixel array as the domain of a function. Per-point color transforms can compute each pixel independently, but blur and sharpen read neighboring pixels, and geometric transforms fetch samples from other positions. Depending on the kind of operation, the memory traversal direction, the number of temporary buffers and the boundary conditions differ. Classifying this difference first became the foundation for keeping a consistent performance model as more tools were added later.

The Image Processing Pipeline

When building the image pipeline, “it doesn't break” mattered more than simply “it converts.” When receiving an RGBA buffer, width, height and length must always be validated. Computing width × height × 4 in u32 risks overflow, so I compute it in u64 first and then check it against the usize range. If the pixel buffer is shorter than expected, an error is returned right away. Binary data coming from the browser always has to be checked again.

I handled blur the same way. Running a 2D kernel as it is gets expensive for a Gaussian blur. So I split it into separable convolution: a horizontal 1D pass and a vertical 1D pass. The complexity drops considerably, and direct access to the raw buffer cuts the cost of get_pixel/put_pixel. Edges are clamped so that no black borders or folding artifacts appear.

I put an upper bound on sigma, too. Blur strength is a value the user can adjust, but if an arbitrarily large value comes in, the kernel size explodes and overflow or DoS problems can occur. So there is a sigma max, and NaN, Infinity and values of zero or less are handled defensively. Even if the graphics editor's UI slider only sends normal values, the core has to block bad ones again. The Rust core is the last line of defense.

Noise follows the same logic. Textures like film grain are often needed in image work, but just adding uniformly distributed random numbers to the channels does not produce a natural result. The texture changes depending on whether you add the same amplitude along the luminance axis or jitter the color channels independently, and spatially correlated noise has a different frequency distribution from white noise. When a reproducible result is needed, the initial state of the stochastic process is fixed, but the concrete generation method had to be chosen by the statistical properties of the effect and its computational cost.

Asset factory

A graphics editor is not a tool that handles just one image. A single project holds vectors and rasters, fonts, the document state and previews all together. So the save format could not be just a compressed file; it had to be a container from which the object graph can be rebuilt. Compression is the problem of shrinking repeated bytes, while a container is the problem of preserving file names, kinds, versions and relationships. Thinking of the two as separate responsibilities is what keeps the document's meaning steady even when the format changes.

What a binary container needs first is self-description and boundary validation. The header tells you by which rules to read, the version determines how to interpret what follows, and the length of each section sets where the next data begins. If you trust a length and allocate memory from it, a single corrupted input can lead to excessive memory use. The total size, the number of entries, each entry's size and the cumulative offset all have to be validated separately, and after reading finishes you also have to check whether any unexplained bytes remain.

I did not judge storage methods by compression ratio alone, either. You have to look at dictionary size and seekability, how much must be rewritten for a small change, where a corrupted block is detected, and the maximum memory needed for decompression. A project with a lot of duplication across assets and a project made mostly of already compressed images give completely different results under the same strategy. The right move was to look at the data's entropy and access pattern first, and then choose the container and compression layers.

A font, too, is not simply a file but closer to a binary database in which many tables reference one another. Glyph outlines, character mapping, advance widths, kerning and name information all move together. Reducing the size does not end with stripping out unused glyphs; the components referenced by composite glyphs and their relationship to the layout tables must also stay closed. After conversion, it is not enough to check that the font reopens; you have to confirm that glyph selection and metrics are preserved for the same string.

Only with this kind of asset engineering does a graphics editor become a real publishing tool. A single image visible on screen has a recoverable relationship to the source document, the fonts used, the color space and the output specification. By including saving and exporting not as extras but as the final stage of the editing model, graphics work became able to withstand the whole lifetime of a project.

The First Rust Core

The key point of Part 10 is not yet a finished graphics editor. It is that I laid the computational foundation for building one properly. I looked at the object model and canvas architecture of an existing vector editor, and in the actual implementation I separated the responsibilities: interaction versus numerical computation, editing source versus publishing assets, and container versus compression. From this point on, Opkle Editor was preparing to expand from an EPUB document editor into a graphics production environment as well.

The front end handles the UI, document state, commands and user feedback, while the computation layer handles work where contiguous memory and numerical stability matter, such as pixels, curves, files and fonts. It is not because one language is superior, but because each layer has different time constraints and data structures. Dividing roles this way lets the event loop stay responsive and the computed results stay reproducible, even as features grow.

This stage also settled in a stable way. Everything at the bottom of a graphics system was engineered and fixed: the cost of the execution boundary, memory ownership, the sampling relationship between raster and vector, alpha compositing, pixel buffer validation, container integrity and the reference relationships between font tables. In repeated testing, images of various sizes, corrupted input, transparent edges, long-running computation and the save and restore paths all passed stably.

The next step was to connect this Rust factory to the actual tools of the graphics editor. You have to be able to draw shapes, place images, apply filters, move between SVG and raster, and have AI commands call that work. Part 10 was the starting point. It was the stage where I decided to build the graphics editor myself, and successfully stood up the Rust/WASM-based core that would support that decision.

PreviousListNext
CopyrightAll design outputs and videos on this website are copyrighted by Abstract Cloud and protected under copyright law and related regulations. All content, including web, video, text, cover, and interior designs, is the property of the copyright holder. Unauthorized reproduction, distribution, creation of derivative works, or online sharing without prior consent is strictly prohibited. Violations may result in civil and criminal liability under copyright law. Legitimate purchases and copyright protection preserve creators' rights and fuel better works in return.Copyright: Abstract Cloud | CEO: Bae Changkyu
© Abstract Cloud. All Rights Reserved.
HOMEFAQTerms of ServicePrivacy PolicyRefund PolicySeller Informationhelp@opkle.app
+82 10-2747-3403
Business Name :Abstract Cloud  |  CEO :Bae ChangkyuBusiness Registration Number :249-74-00533E-commerce Registration Number :2025-Uijeongbu Songsan-0634Address :402, 108-dong, 49 Buyong-ro, Uijeongbu-si, Gyeonggi-do, Republic of KoreaAll content, designs, and source code on this website
are copyrighted by Opkle.
Opkle