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 First Build Was a Code Editordev2Building Opkle Editor: The Preview Became a Second Editordev3Building Opkle Editor: Editing Media Queries Toodev4Building Opkle Editor: Absorbing Video with CSS Animationdev5Building Opkle Editor: Designing an LLM for Making Booksdev6910111213...5 Building Opkle Editor: Absorbing Video with CSS Animation

After confirming that the media query support rendered reliably even in retailer e-readers, my confidence in EPUB3 grew clearer. EPUB is not just a file that reflows text; it is a format that can bring the expressive power of HTML and CSS into a book. Watching mobile, tablet and desktop together with light and dark modes, and seeing images and tables change naturally to fit each condition, I knew exactly which area to try next: CSS animation.

CSS can do far more than media queries. Combine features like `transition`, `animation`, `transform`, `opacity`, `filter` and `@keyframes`, and you can make everything from simple entrance effects to layer-by-layer motion, repeated playback and scene transitions. On the ordinary web these are very familiar, but letting creators handle them directly inside an EPUB had a completely different meaning. If you can create motion inside an ebook and it plays back unchanged in retailer e-readers, EPUB can become a much broader expressive medium.

So the next implementation was a GUI animation generator. The idea was that users, without writing any CSS, pick a layer and adjust values such as time, delay, repeat, opacity, position, size and rotation, and the editor generates the CSS animation and keyframes. The preview target and document state structure I had built for media query support carried over here unchanged. An animation is an effect you see on screen, but inside the EPUB it still had to be serialized reliably into CSS strings, resources and XHTML structure.

Blocks, Layers and Animation

From the start I had no intention of making animation a CSS code input feature. If users had to write `@keyframes` themselves and hand-tune `animation-duration` or `animation-delay`, we'd be back to a code editor. What I wanted was for users to select a layer on screen and decide through a GUI when and how it moves, with the editor generating the CSS.

So I took the block and the layer as the basic unit of animation. There are elements such as image blocks, text blocks, group blocks and overlay blocks, and each element can have an animation state. The animation state holds properties such as duration, delay, easing, iteration count, fill mode, transform values, opacity values and start/end positions. Users change values in a panel, but internally that state is serialized into CSS keyframes and animation rules.

This fit well with the document state structure I had already built. The XHTML keeps the semantic structure of elements, while CSS handles presentation and motion. The Shadow DOM preview renders the current state, and the CSS string in CodeMirror 6 preserves the generated animation rules. IndexedDB saves the block state and CSS state together. When a user adjusts the timing in the GUI, the motion in the preview changes right away and the CSS string is updated at the same time.

What mattered in building per-layer animation was independence and composition. To make a scene where one image fades in slowly, another piece of text rises up 0.3 seconds later, and the background layer gently zooms, each layer needs its own animation state. At the same time, the whole scene has to move like a single timeline. So I managed individual layer state and scene-level timing separately.

A CSS Animation GUI

The most important principle in building the animation GUI was not to hide the CSS but to generate accurate CSS. Creators adjust motion with a timeline, sliders, toggles and easing choices, but the result is, in the end, the CSS that goes into the EPUB. So any value made in the GUI had to be reproducible at any time as `@keyframes` and class rules.

For example, when a user sets a fade-in and translateY on an image layer, the internal state isn't stored as a mere string saying “fade in.” It is preserved as values like `opacity: 0` and `transform: translateY(...)` in the start frame and `opacity: 1` and `transform: translateY(0)` in the end frame. The CSS serializer then builds a keyframes name from those values and gives that block an animation class.

Keyframes names also had to be managed. An EPUB contains many chapters and many blocks, and keyframes with the same name must not collide. So I generated unique keyframes names based on the block id or animation id and created the CSS rules from those. When a layer is deleted or an animation changes, the unused rules have to be cleaned up too. Otherwise the CSS keeps growing, and dead keyframes are left inside the exported EPUB.

With this structure in place, the distance between the GUI and the CSS disappeared. Users adjust animation visually, while the editor is internally building precise CSS animation rules. Because the motion seen in the preview and the motion inside the exported EPUB come from the same rules, the gap between the editor and the output also shrank.

Getting Past the Limits of the video Tag in EPUB

Making animations naturally led to the problem of video. EPUB3 supports the video tag. By the spec, it is possible to put video in an ebook and play it. But in real retailer e-readers and reading systems, video playback is often unreliable. Some readers show different playback controls, in some environments it doesn't play at all, and file size and codec conditions can cause trouble.

So I didn't go the route of simply trusting the video tag. What EPUB still guaranteed reliably was images and CSS. Image resources are handled reliably by most reading systems, and CSS animation, even with its limits, was often more predictable than video. So the thought came naturally: what if I turned the video into an image sequence and played those images back with CSS animation?

Conceptually this is simple. When the user adds an mp4, the server extracts frames with ffmpeg. The extracted frames become a JPEG image sequence. The editor bundles those frames into a single animation component and shows them in order using CSS keyframes or a step animation. As a result, the EPUB contains not a video tag but many images and a CSS animation rule.

The key was to make the playback feel smooth enough. If you include every frame no matter what, the file size balloons. If you cut frames too much, the motion looks choppy. So I had to tune together the original video's length, the target fps, the number of images a reader can handle, the JPEG compression quality and the image size per viewport. This was a video-processing problem and an EPUB packaging problem at once.

Turning an MP4 into a Frame Sequence

On the server side I used ffmpeg. When a user uploads or drops an mp4, the server receives the file and breaks it down frame by frame. The output can be made into an image sequence like `frame_0001.jpg` and `frame_0002.jpg`, with resolution and quality adjusted as needed. Since these are resources that go into an EPUB, rather than keeping the original resolution, it mattered to shrink them to a size suited to the actual preview targets and reading environments.

Once the frame sequence is made, the editor doesn't treat it as an ordinary bundle of images but registers it as the resource set of an animation component. Each frame has to go into the OPF manifest, with the media-type set to image/jpeg. The resource store keeps metadata such as the frame list and order, duration, fps and target size. This component state also has to be saved in IndexedDB so the same animation can be restored when the project is reopened later.

There are several possible ways to play it back in CSS. One is to switch the background-image step by step in keyframes, and another is to lay the frame images out like a sprite and move the background-position. In an EPUB environment you have to account for differences in CSS support among reading systems, so I had to go with the approach that renders most reliably. What mattered was that the result wouldn't depend on video decoding and would move through image loading and CSS animation alone.

With this structure, video was no longer tied to the video tag. The user adds an mp4, but inside the editor it is converted into an EPUB-friendly image animation. Even if video is unstable in retailer e-readers, an animation made of images and CSS could play back far more reliably.

Image-Sequence Video

The advantage of the image-sequence approach was that it fit the image component structure I had already built. Since in Part 4 I was already handling image variants as components, the frame sequence could go into the same resource management scheme. The difference was that it wasn't a single image variant but a bundle of images with a time order.

The animation component holds a frame list, and the CSS state decides at what time interval that frame list is shown. The preview target renders the frame size and presentation that match the current viewport and theme conditions. On export, all the frame images go into the EPUB package and are registered in the OPF manifest without omission. The body XHTML gets a structure representing the animation component, and the CSS gets the playback rules.

This approach could also be combined with media queries. On mobile it can use a smaller frame sequence, and on desktop a larger one. Using frames with a different color feel in dark mode is also structurally possible. In the end even video could be handled as an extension of the image variant component. It suited the actual reading environment of EPUB better than putting in a single mp4 as is.

Of course, as the number of resources grows, you have to manage package size and loading timing. So I managed frame count, compression rate, preload behavior, animation duration and repeat behavior together inside the component state. In the editor preview you can check the feel of real playback, and in the pre-export review you can check for missing manifest entries, path errors, missing CSS rules and frame order errors.

CSS Animation as a Core Feature of EPUB Expression

After this implementation, CSS animation was no longer a mere decorative feature. It became the key technology for expressing motion safely inside an EPUB. Scenes where text appears slowly, where images move layer by layer, and where a short video plays as an image sequence all came in through the CSS animation structure.

Inside the editor, users adjust layers and timing directly. Internally, the animation state changes, the CSS serializer generates keyframes and class rules, and the Shadow DOM preview shows the result immediately. The generated CSS string is reflected in CodeMirror 6, and IndexedDB saves the state and resources. This flow ran naturally on top of the synchronization, media query and resource management structures built in Parts 3 and 4.

Converting an mp4 into a frame sequence in particular made the direction of Opkle Editor clearer. Users add a video, but what goes into the EPUB is images and CSS that retailer e-readers can handle reliably. It looks like video on the outside, but internally it is an EPUB-friendly animation package. This approach let expression survive even in environments where video tag support is patchy.

The result was a clear success. The GUI animation generator produced per-layer CSS animation reliably, and the generated keyframes and animation rules behaved consistently across the preview and the exported result. The flow of converting an mp4 into a JPEG frame sequence with ffmpeg and playing it as a CSS animation also passed retailer e-reader review without a hitch. At this stage Opkle Editor evolved beyond images and tables into an editor that can absorb motion and video into EPUB3.

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