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: Linear Algebra in the Enginedev12Building Opkle Editor: An InDesign-Style Layout Editordev13Building Opkle Editor: Text That Flows Across Pagesdev14Building Opkle Editor: EPUB and IDML as Editable Pagesdev15Building Opkle Editor: One Layout, EPUB and Printdev161112131415...15 Building Opkle Editor: EPUB and IDML as Editable Pages

With the layout and typesetting engines finished, there was no reason to leave this editor as a tool that only starts from a blank document. Real publishing work keeps bringing in finished manuscripts, existing EPUBs and pages made in other typesetting programs. Displaying a file and recovering an editable semantic structure were different problems. Importing was closer to translation than to rendering.

Each format describes a document in a different language. EPUB builds meaning around flow and the cascade, while fixed-layout documents describe a scene through pages, transforms and reference graphs. For a plain manuscript, the order and role of paragraphs matter more than pages. Turning all of these into one flat string simplifies the grammar, but the types and relationships the source language carried disappear.

So I viewed the import process as a compiler pipeline. You parse each format's surface syntax, resolve names and references, lower to a common intermediate representation, and finally materialize into an editable scene graph. If the parser reads the file, semantic analysis decides what that file means. An importer stopped being a feature that opens a file extension and became a meaning-preserving translation between different document languages.

Document compiler

The compiler's first step was not trusting the input but determining which grammar it can be read with. The file extension is only a hint; the structure of the actual bytes, the required headers and the internal relationships decide the grammar. If the structure does not hold at lexical validation, it is not passed on to the later semantic phase. A document importer, like any compiler, had to reject bad input at as early a stage as possible.

Even when parsing finished, I did not build editing objects right away. A syntax tree preserves the source file's representation well, but it is too format-dependent for an editor. Conversely, if you lower it directly to on-screen objects, you easily lose the names, style origins and reading order that were in the source. So I put in an intermediate representation that expresses paragraphs, assets, pages, transforms and references, and normalized the differences between formats on top of it.

The intermediate representation needed source provenance as well. Even for the same text, the meaning of later conversion differs depending on whether it was a heading in the source or simply large type. By not treating information interpreted with certainty and information inferred heuristically as the same value, and distinguishing confidence and origin, only the uncertain structure can be flattened conservatively. The converter had to preserve the meaning it knew rather than invent what it did not know.

The final materialization is the step that turns the intermediate representation into objects of the current editing model. By then, coordinate units, style inheritance and asset references must all be resolved. So that the whole manuscript is not lost even if some nodes fail along the way, I set up fallbacks at each semantic layer. I applied the compiler's error-recovery principle so that even for input whose structure could not be perfectly restored, the most important information, the text and its reading order, remains.

Package graph

A package like EPUB is closer to a reference graph than to a set of files. Assets are vertices, and links inside documents, stylesheets and the reading order are edges. The physical order of entries inside the archive has nothing to do with the semantic order of the graph. What the importer had to recover was not a directory listing but the document graph reachable from the root and the linear reading order the author defined.

Resolving relative paths was a graph normalization problem. If `a/../b`, `./b` and `b` point to the same target, different strings must be sent to the same canonical vertex. Otherwise you cannot tell asset duplication from references that do not exist. Canonicalization is not simple string cleanup but also a security boundary, so paths that escape the root and ambiguous forms must be restricted together.

Documents with namespaces must be read by expanded name rather than by prefix string. A prefix can differ from document to document, but the pair of namespace URI and local name carries the same meaning. It is like how, in a programming language, the result of symbol resolution matters more than a variable's surface name. This is why XML is handled as a namespace-aware tree rather than read by string search.

I checked referential integrity the way a compiler's link stage does. I separate out whether the target of every required edge exists, whether the media type is compatible with the actual asset's role, and which orphan assets are unreachable from the root. Rather than inventing missing targets, I judged the severity of the error and distinguished references essential to the body from auxiliary metadata. “Linking the document graph” was a more accurate phrase than “unpacking the package.”

Cascade algebra

The CSS cascade was not string merging but an algebra with priorities. When several declarations reach one property, the winner is decided by comparing a tuple made of origin, importance, layer, specificity and source order. This comparison is nearly a lexicographic order, and can be seen as an operation that selects the maximum element among the candidates arriving at the same element and property.

Inheritance is a separate stage from the cascade. Only when a value is not settled in the element's own candidate set is the parent's computed value passed down, and some properties return to their initial value. Once `inherit`, `initial`, `unset` and relative units come in, you have to distinguish the specified value, the computed value and the used value. That is why storing only the last number that appeared on screen loses which rule it came from.

Selector matching is predicate evaluation over a tree. A simple selector looks only at one vertex's attributes, but descendant and sibling combinators also look at surrounding relationships. If you cut the source tree into fragments, the domain of the predicate changes, and a selector that was true before can become false. Preserving styles was less about copying declarations than about how to keep the context in which the selectors were evaluated.

A media query can be seen as a boolean function over an environment vector. If you take viewport, orientation and color preference as variables, each query defines a subset of the environment space. Where several queries overlap, the cascade applies again. To reproduce a particular environment, the importer had to state one environment vector explicitly and evaluate every condition with the same logical expression, rather than using an arbitrary screen width.

Fragmentation geometry

Dividing a flow document into pages was the problem of mapping a continuous block flow onto finite fragmentation containers. Each block has splittable intervals and unsplittable atomic regions, and margin collapse, floats and keep constraints change the possibilities for the next break. A single bounding box cannot express the actual pieces of an element spanning several pages.

Typesetting geometry has meaning only after the font metrics are settled. Even the same string gets different advances depending on glyph substitution, kerning and fallback, and line breaks shift in a chain. So the font set is not an external extra of the layout function but an input variable. When the input fonts differ, even the same DOM has gone into a different function, so the previous geometry cannot be reused.

Looking at fragmentation as an interval algebra, one logical box turns into an ordered sequence of rectangular pieces, one per page. Each piece maps a source content interval `[a_i, b_i)` to a physical region `R_i`, and the intervals must not overlap and must add up to the original range. With this provenance, even when you select a piece on screen you can explain which part of the source document it is.

I separated measurement space from display space as well. Typesetting is computed in canonical coordinates with no zoom or pan, and the screen applies an observation transform to the result. If the display magnification got mixed into the layout input, you would get the contradiction of line breaks changing when you zoom. The foundation of page import was not DOM techniques but a stable mapping between logical intervals and physical pieces.

Provenance tree

When the source tree is divided into physical pieces, the ancestor context can vanish. Descendant selectors, relative units and inherited values depend not on the current node alone but on the path leading up to the root. So a fragment had to be not an independent document copying only the leaves needed on screen but a view looking at a particular interval of the source tree. Provenance explains which logical node and path a piece came from.

This relationship can be thought of like a path in a persistent tree. The source tree remains the authoritative structure, and each fragment describes itself through the source revision, the node path and the content interval. Since you can compute new pieces from the source at any time rather than guessing the source by joining pieces, information is not lost cumulatively even when the trim size changes.

Preserving styles needs two representations. The source rule explains why a value was applied, and the computed value explains what it actually became in the current environment. If you keep only the former, selectors can change in a fragment cut off from context, and if you keep only the latter, the user cannot edit the original style. Preserving cause and effect together was similar to handling a compiler's source map together with the optimized code.

I distinguished a glyph's ink bounds from the line box as well. The line box is the typesetting region built from advance, ascent and descent, and the actual outline can extend past it because of italic overhang or decorative marks. Clipping cannot be decided from the logical box alone, and you must choose between the visual boundary and the typesetting boundary depending on the purpose. This difference is not a quirk of a particular browser but a general property of digital typography.

When promoting an imported structure into the editing model, too, I judged by the amount of information lost. Headings and paragraphs with clear meaning can be normalized into simpler native structures, but if you hastily flatten regions with complex selectors and mixed content, the original representation cannot be restored. Convertibility was decided not by node type but by whether information is preserved between meaning and representation.

Durable IR

A rendering tree cannot be a persistent document format. Anonymous boxes, caches and session addresses computed by the browser mean something only in the current execution environment and do not guarantee the same identity in the next run. What has to be stored is not the objects on screen but a declarative intermediate representation from which the same screen can be computed again. The durable IR had to include the semantic structure, the causes of styles and asset references.

Serializability does not simply mean it can be turned into JSON. Every reference in the tree has to be resolved within a namespace, cycles and sharing relationships have to be explicit, and the meaning of each field has to be interpretable even across versions. Only when ephemeral caches, selection and layout boxes are excluded, leaving just the source document and the editing intent, can the screen be materialized again from the same input.

Asset references, too, must be logical identities rather than location addresses. If you store a URL or pointer valid only in the current process, the file may exist but the connection cannot be restored. A durable reference uses values independent of the environment, such as a name inside the package or a content identity, and is turned into a handle the current runtime understands at the load stage. The separation of names from actual memory addresses is like the relationship between a linker and a loader.

Restoration should be the inverse of saving, but it need not be a complete byte-level inverse function. It is enough if `decode(encode(x))` is semantically equivalent to the original x. Here, equivalence means the same paragraph order, styles and asset relationships, and transient node addresses need not be the same. By defining the round-trip property as a semantic invariant, the lifecycle of the screen and the lifecycle of the document were separated.

Reference graph

Fixed-layout documents start from the opposite direction to flow documents. They are closer to an object graph in which pages, stories, styles and assets reference one another than to a single tree. File boundaries are only a partition for storage convenience and do not coincide with semantic boundaries. Only after the importer reads several pieces, builds a symbol table and links the references can it describe a single page.

In the link stage, I checked vertex kinds and edge types together. An edge where a text frame references a story and an edge where a page references a template look like the same identifier link but mean different things. If a reference of the wrong type is connected as if it were simply an existing target, the graph looks complete but the document is wrong. Typed graph validation was needed.

Where cycles are allowed in a reference graph also differs from place to place. An inheritance cycle of colors or styles cannot settle a value, but fan-in, where several nodes point to a shared asset, is normal. A story's reading path must have an order, and in the group ownership tree one object must not have two parents at once. Instead of applying a single rule to the whole graph, I defined invariants for each edge meaning.

Importing was not a process of baking the graph into one background image. It is a process of moving the relationships among manuscripts, frames, templates and assets into a common intermediate representation so that they can be selected and edited again. By lowering to a typed scene graph and style graph without exposing the surface XML names as they were, a stable compiler boundary formed between the format's details and the editing model.

Affine decomposition

Coordinate conversion between fixed-layout formats does not end with unit conversion. An object's transform is an affine map `p' = Ap + t`, and an object inside a group has to multiply the matrices from the root down to itself in order to get its world position. Matrix multiplication is not commutative, so the coordinate convention and the direction of composition have to be fixed first.

Decomposing the matrix A into the rotation, scale and shear familiar to users is not unique either. Using the polar decomposition `A = RS`, R is an orthogonal rotation or reflection and S is a symmetric stretch. The eigenvectors of S describe the principal axes of stretching and the eigenvalues describe the scale on each axis. This decomposition preserves the actual geometry of a skewed transform better than simply back-computing an angle.

Numerically, the determinant and condition number matter. When the determinant is near 0, the area almost vanishes and the inverse becomes unstable. But the determinant alone cannot fully describe an ill-conditioned matrix with one axis stretched a lot and the other shrunk. Only by looking at the ratio of the singular values as well can you judge how much a small error in the input coordinates gets amplified in the output.

I also could not simplify every transform into a rotated rectangle. An affine map with shear or reflection does not preserve right angles, and free curves have to pass through the same map including their control points and tangents. If you discard degrees of freedom the representation model cannot handle, the geometry changes at the moment of import. When simplifying a transform, it was right to measure the approximation error and, if it fell outside the tolerance, keep a more general path representation.

Style lattice

A text style was the composition of partial functions from several scopes rather than a single object. Document defaults, paragraph styles, character styles and direct overrides offer candidates for the same property. Each layer does not define every property, so a style can be seen as a partial map from a set of properties to values. The final value is obtained by composing, in order, operations in which definitions from the nearer scope override those from the farther one.

This structure resembles a lattice in some ways. `undefined` is the bottom value not yet decided, and an explicit override is a more specific value. However, when incomparable candidates arise, like two different direct overrides, source order or an explicit priority is needed. If you think of style merging not as an object spread but as a selection among values that have origins, it becomes easier to preserve causes in editing and round trips.

The units of typography values also differ by meaning. Font size and baseline shift are lengths, but line-height can be a length or a dimensionless ratio, and tracking is sometimes interpreted as a value relative to the font size. If you multiply every number by the same scale, the units break. Only by distinguishing quantities that have dimensions from ratios, and normalizing to a base unit, does the typographic feel survive between different document languages.

Color is a coordinate transform too. Device-dependent CMYK and screen RGB are not a simple reduction from four numbers to three, and depend on the profile and rendering intent. A gradient is an interpolation function over a color space, defined together with alpha and stop positions. In importing, I had to distinguish values for the screen preview from the original color definitions, keeping both the result of the representation and the publishing meaning.

Constraint migration

Changing the trim size of an imported document was not a transform that multiplies every coordinate by the same scale. Text flow has to be re-optimized at the new width, and objects whose physical position matters, like logos and photos, have to keep their relative coordinates or anchors. Backgrounds and margin guides must be regenerated from the new page constraints, not by enlarging the old geometry. Each object had a different invariant to preserve.

I saw this as constraint migration. The old solution `x_old` satisfies the old constraints `C_old` but does not fit the new constraints `C_new`. The goal is to find, among the solutions satisfying `C_new`, the `x_new` semantically closest to `x_old`. The distance function can weight position change, size change, reading-order violation and style loss differently.

For free-placement objects, normalized coordinates are useful. If you turn a position inside the old content box into relative coordinates in `[0,1]²`, you can restore the proportional position in the new box as well. But this does not suit text and repeated elements. Text must be re-typeset from its source and style at the new width, and repeated elements must be evaluated in the new template context. A constraint that fits the object's meaning mattered more than a single conversion formula.

You also have to consider cases where no solution exists. Objects with minimum sizes may not all fit on the new page, or keep constraints may conflict with each other. In that case you have to relax the constraints by priority and record which conditions were broken. Without distinguishing hard constraints from soft constraints, a solver can silently produce a wrong layout.

A transformation of the whole document had to be treated as a transaction. An intermediate state in which only some pages have the new specification is not a valid document. Only after the new solution passes all invariants is the old solution replaced, and if it fails, the complete previous revision is kept. A trim size change came to be organized not as a coordinate edit but as solving the whole constraint system anew.

The Import Engine Is Done

At this stage the layout editor became able to absorb different documents into one editing model. Input became a syntax tree in each format's parser, and passed through symbol resolution and graph linking down to a common IR with provenance. The cascade and fragmentation of flow documents, and the typed reference graph and affine geometry of fixed layout, each kept their own meaning within the same compiler pipeline.

The imported result was not a one-time screen. I preserved a durable IR instead of the rendering tree, and separated the causes of styles from computed results, and the logical source text from the physical fragments. For trim size changes too, I arranged things to recompute the closest solution under the new constraints rather than forcibly enlarging the old geometry.

I repeatedly checked it with combinations of various document structures and CSS, different fonts and color spaces, long manuscripts and mixed content, nested transforms and incomplete references. I confirmed that after saving, restoring and changing trim size, the meaning of reading order, style provenance, asset relationships and page geometry was maintained. An import engine that translates different publishing languages into editable pages was fully implemented and stabilized.

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