| This supersedes the litehtml column of |
| 6 | `docs/widget-profile-draft.md` only in what it lists below; the probes have not |
| 7 | been re-run on the fork. |
| 8 |
| 9 | The renderer has since moved to twidget as TwidgetCore (`Sources/TwidgetCore`, |
| 10 | `docs/TWIDGET_CORE.md` there), which reads this repository as its protocol. |
| 11 | `apps/renderer-litehtml` here is a copy kept until this repository drops it. |
| 12 |
| 13 | ## What was ported from twidget |
| 14 |
| 15 | twidget's Swift layer did these things on Apple only. They are now shared C++ in |
| 16 | the litehtml core or shared TypeScript in the sandbox, so every host gets them. |
| 17 |
| 18 | | Piece | Where | From | |
| 19 | |---|---|---| |
| 20 | | Fork support: documents patched in place (`update_from_string`, `update_styles`), the fork's SVG, group and box-shadow paint hooks | `apps/renderer-litehtml/src/renderer.cpp`, `display_list.h`, behind `TW_LITEHTML_TWIDGET` | `LHContainer.mm` | |
| 21 | | CSS animations and transitions: `@keyframes`, timing functions incl. `steps()`, `linear()` and `calc()` times, interpolation of numbers, colours and transform lists, animation and transition events | `src/animations.*` | `WidgetAnimations.swift` | |
| 22 | | Web Animations: the renderer samples the validated `anim` records of the sandbox's `webAnimations` feature (`packages/core/src/sandbox/waapi.ts`, `Validator.validateAnim`), and answers the `anims` query | `src/animations.*` | `WidgetWebAnimations.swift` | |
| 23 | | Events: hover enter/leave/over/out over the whole ancestor chain, `dblclick`, `wheel`, `keydown`/`keyup`, moves coalesced per frame, click on the common ancestor | `src/renderer.cpp` (`hover`, `wheel`, `key`, `tick`) | `LiteHTMLWidgetRenderer.swift` | |
| 24 | | Canvas 2D: the interpreter (state stack, transforms, paths and `Path2D`, SVG `d` incl. arcs, gradients, clip, text, `drawImage`, `putImageData`, hit tests) emits `CanvasOp`s a `Backend` runs | `src/canvas.*`, `src/canvas_ops.h`, `Backend::canvas_run/read/release` | `WidgetCanvas.swift` | |
| 25 | | `light-dark()` resolved in the renderer; tag, attribute and property names checked before they are written into the generated HTML | `src/css.*`, `src/renderer.cpp` | `WidgetDOM.swift` | |
| 26 |
| 27 | The `anim` message and the `anims` query are the `webAnimations` feature of |
| 28 | `docs/protocol.md`: a host lists it in `config.features` to turn it on. |
| 29 |
| 30 | How it fits together: |
| 31 |
| 32 | - **An animation frame patches style holes.** Overrides are written after the |
| 33 | fork's `-lh-anim` marker and applied with `update_styles`, so a frame neither |
| 34 | serialises nor re-parses the document. A renderer asks for frames only while |
| 35 | `wants_tick()` holds. |
| 36 | - **A canvas is laid out as an image.** The fork makes `<canvas>` an image |
| 37 | element whose source is `tw-canvas:<id>/<w>x<h>`; the backend draws its |
| 38 | bitmap there. Canvas ops run when they arrive, not at paint time. |
| 39 |
| 40 | ### Compositor layers |
| 41 |
| 42 | An element whose animations write only `transform`, `opacity`, `translate`, `rotate` or `scale` |
| 43 | can be handed to the platform's compositor instead of being painted every frame |
| 44 | (`src/compositor.h`, ported from twidget's `WidgetCompositor.swift`): |
| 45 |
| 46 | - **The core decides and bakes.** `Renderer::composition()` lists the layers after each |
| 47 | `paint()`. Each layer carries: |
| 48 | - the element's subtree as its own display list, without the element's own transform and |
| 49 | opacity; |
| 50 | - its bounds; |
| 51 | - an optional clip from one clipping ancestor; |
| 52 | - a raster scale; |
| 53 | - a track of linear keys, each a full 2D matrix plus an opacity. |
| 54 |
| 55 | Easing, `steps()`, direction, iterations and Web Animations timing are all baked into those |
| 56 | keys, by halving spans until the box's corners are within 0.05 px. A platform therefore only |
| 57 | needs linear keyframes, and a loop repeats. |
| 58 | - **The document leaves layers out.** Promoted elements are skipped in the main paint (the fork's |
| 59 | `skip_paint`), and their sampled transform and opacity no longer reach the document. The core |
| 60 | stops asking for frames for them, and wakes only when an iteration or end event is due |
| 61 | (`next_tick_in()`). |
| 62 | - **Promotion rules:** |
| 63 | - nothing animates inside or around the element; |
| 64 | - it has no filter, and no ancestor groups its paint; |
| 65 | - at most one ancestor clips it; |
| 66 | - nothing painted after it meets the area it sweeps over; |
| 67 | - at most 64 layers, and no track shorter than 0.1 s. |
| 68 | - **Off by default.** `set_compositing(true)` turns it on; a platform without a compositor keeps |
| 69 | painting every frame. |
| 70 | - **`resume_track()`** helps a compositor that cannot start an animation part way through: it |
| 71 | turns a loop to its current phase and cuts a one-shot to what is left. |
| 72 |
| 73 | The Windows spike plays layers with `Windows.UI.Composition`: |
| 74 | - each layer is a sprite drawn once by Direct2D; |
| 75 | - its transform is an expression over a property set whose `Vector4`/`Vector2` keyframes |
| 76 | interpolate component by component, as the core baked them; |
| 77 | - opacity is a scalar keyframe animation; |
| 78 | - the clip is a rounded-rectangle geometric clip, which cannot round uneven corners. |
| 79 |
| 80 | ### State per platform |
| 81 |
| 82 | The shared parts build everywhere, but each host still has work to do: |
| 83 |
| 84 | | | Windows (UWP spike, Direct2D) | Apple (CoreGraphics) | Android | Web (wasm) | |
| 85 | |---|---|---|---|---| |
| 86 | | `canvas_run` / `canvas_read` | done (spike, outside this repo) | — | — | — | |
| 87 | | calls `tick()` (animations) | done | — | — | — | |
| 88 | | forwards `hover`, `wheel`, `key` | done | — | — | — | |
| 89 | | fork paint hooks (path, group, shadow) | done | — | — | — | |
| 90 | | compositor layers (`set_compositing`) | done | — | — | — | |
| 91 |
| 92 | Without `tick()` a host renders the state at each rebuild, as before. Without |
| 93 | `canvas_run` a canvas stays empty, as before. |
| 94 |
| 95 | ### Checks |
| 96 |
| 97 | - The core was compiled with MSVC against both the fork and the vendored |
| 98 | upstream litehtml (without `TW_LITEHTML_TWIDGET`). It was not built here |
| 99 | with clang for Apple, Android or wasm; `CMakeLists.txt` and |
| 100 | `scripts/build-litehtml-web.ts` list the new sources. |
| 101 | - A headless harness (events, animations, Web Animations, canvas, compositor |
| 102 | layers, `light-dark()`, names) runs the core with a stub backend: twidget's |
| 103 | `Tests/TwidgetCoreTests`. `tests/test_main.cpp` here needs the CoreGraphics |
| 104 | backend and was not run. |
| 105 | - In the Windows spike, `corpus/common` (32) and `corpus/htmlbubbles-ported` |
| 106 | (116) load with no errors. |
| 107 |
| 108 | ## The profile: one subset, decided on purpose |
| 109 |
| 110 | What ships is user-generated content, not the widgets in `corpus/`. Those are |
| 111 | demos written to a profile, so how often they use a feature says little about |
| 112 | what users will write. The profile therefore has to be decided, not measured. |
| 113 |
| 114 | It also cannot be "everything": choosing litehtml is choosing a subset. Per |
| 115 | `docs/decisions.md` ("one profile for the promise"), whatever the subset is, it |
| 116 | is the same on every client: |
| 117 |
| 118 | - **The validator enforces it on every platform, the web included.** Anything |
| 119 | outside is dropped and reported, so a widget never draws more in one client |
| 120 | than another. The web renderer cannot be the iframe in that case, or it must |
| 121 | be held to the same cut. |
| 122 | - **`docs/widget-runtime-profile.md` becomes that subset.** Today it describes the |
| 123 | WebView, and it is what bots are told: `@container`, `@layer`, SVG masks and |
| 124 | filters, canvas patterns. A bot that follows it today produces widgets |
| 125 | litehtml does not draw. |
| 126 | - **A feature is in only if every backend draws it on the GPU natively.** Each |
| 127 | backend draws in its own API; the core owns what a command means (state, |
| 128 | transforms, paths, clip stack, compositing order). A feature one target lacks |
| 129 | is left out rather than emulated on that target. |
| 130 |
| 131 | ### What the fork changes against the draft's litehtml column |
| 132 |
| 133 | `docs/widget-profile-draft.md` found that litehtml switched off what LLM widgets |
| 134 | are made of: `gap`, grid, `box-shadow`, `opacity`, `transform`, inline SVG. The |
| 135 | fork has grid (`render_grid.cpp`), parses `gap`, `box-shadow`, `opacity` and 2D |
| 136 | transforms, has an SVG element and paint hooks for it, and the ports above |
| 137 | add canvas, `@keyframes` and transitions. That should move most of those rows, |
| 138 | but **it has not been probed**: re-running `scripts/profile/probes.ts` on the |
| 139 | fork is the first thing to do before settling the profile. |
| 140 |
| 141 | ### Canvas |
| 142 |
| 143 | Canvas is in the profile for speed, so it is drawn on the GPU everywhere, not |
| 144 | rasterised in the core. That makes what each graphics API can do the limit. As |
| 145 | far as known, without checking each platform's documentation: |
| 146 |
| 147 | | Feature | Proposal | |
| 148 | |---|---| |
| 149 | | paths, fill and stroke with solid, linear and radial paints, text and `measureText`, transforms, `clip`, dashes, `globalAlpha`, shadows, `drawImage`, `getImageData` / `putImageData` | in | |
| 150 | | the Porter-Duff modes and `lighter` | in: every target has them | |
| 151 | | `strokeText`, `toDataURL` | in: glyph outlines and PNG encoding exist everywhere | |
| 152 | | `multiply`, `screen`, `overlay`, `darken`, `lighten` | in, if Android's minimum API has them through `PorterDuff.Mode` | |
| 153 | | the other separable blend modes | out, unless Android's minimum API is 29 or more (`BlendMode`) | |
| 154 | | `hue`, `saturation`, `color`, `luminosity` | out: QPainter has none | |
| 155 | | `createConicGradient` | decide: Direct2D has no conic brush; CoreGraphics only on recent systems | |
| 156 | | `ctx.filter` | decide | |
| 157 |
| 158 | The demo corpora use only rectangles, text, `save`/`restore`, |
| 159 | `translate`/`rotate`, `globalAlpha` and one linear gradient directly, plus |
| 160 | Chart.js. Running Chart.js 4 through the interpreter would show what it needs. |
| 161 |
| 162 | ### What the demo corpora use (indicative only) |
| 163 |
| 164 | A regex scan of `common`, `htmlbubbles-ported`, `showcase`, `compat` and |
| 165 | `generated` (230 files) gave the following. It counts what the demos' |
| 166 | authors chose, not what users will. |
| 167 |
| 168 | - In `generated` (40 LLM widgets, the nearest to user content): grid 17, |
| 169 | `<input>` 14, transitions 14, `box-shadow` 12, `<select>` 6, Chart.js 5. |
| 170 | - At-rules: `@keyframes` and `@media (prefers-color-scheme)` only; nothing uses |
| 171 | `@container`, `@supports` or `@layer`. |
| 172 | - `filter`: 8 widgets, only `blur()`, `brightness()` and `drop-shadow()`. |
| 173 | `backdrop-filter`: 1. `mix-blend-mode`: 0. `conic-gradient()`: 10. |
| 174 | - 3D transforms: 4 widgets (card flips). |
| 175 | - Properties the fork does not parse: `font-variant-numeric: tabular-nums` |
| 176 | (28), `pointer-events` (16), `user-select` (16), `touch-action` (6), |
| 177 | `text-overflow: ellipsis` (4). |
| 178 | - Inline SVG: 56 widgets, nearly all plain shapes, text and linear gradients. |
| 179 | - `element.animate()`: 1 widget. |
| 180 |
| 181 | ## Open questions |
| 182 |
| 183 | 1. **Form controls.** litehtml draws neither `<input>` values nor `<select>`. |
| 184 | Does the core draw them itself, the same on every platform, or are they out |
| 185 | of the profile? |
| 186 | 2. **3D transforms.** In, or 2D only? |
| 187 | 3. **`filter` and `backdrop-filter`.** Only `blur()`, `brightness()` and |
| 188 | `drop-shadow()`? If `backdrop-filter` is in, it must sample only the |
| 189 | widget's own content: what is behind the bubble differs per app. |
| 190 | 4. **Canvas.** The "decide" rows above, and Android's minimum API level. |
| 191 | 5. **Text.** Platform fonts and shaping make the same widget wrap differently |
| 192 | on each platform. Is that accepted, or does the core bundle fonts and a |
| 193 | shaper (HarfBuzz)? |
| 194 | 6. **Web.** Does the web client run the litehtml core (wasm) so it cannot draw |
| 195 | more than the native clients, or the iframe with the validator's cut? |
| 196 | 7. **Unparsed properties.** `font-variant-numeric`, `pointer-events`, |
| 197 | `touch-action`, `text-overflow`: in? |
| 198 | 8. **Hover.** `:hover` and the hover events have no meaning under a finger. |
| 199 | Keep them for desktop only, or out? |
| 200 | 9. **Not ported from twidget yet.** Magic move, layers for elements with |
| 201 | effects or overlapping content (twidget also promotes what covers a layer), `filter` painting |
| 202 | (the fork's `draw_filtered` / `draw_backdrop`), scrolling inside a widget. |
| 203 | Which of them belong in the profile? |
| 204 |
| 205 | ## Next |
| 206 |
| 207 | - Re-run `scripts/profile/probes.ts` on the fork and redo the litehtml column. |
| 208 | - Answer the questions above, then rewrite `docs/widget-runtime-profile.md` and |
| 209 | make the validator enforce it. |
| 210 | - Fill the platform table: `canvas_run`, `tick()` and the event calls on |
| 211 | CoreGraphics, Android and wasm. |
| 212 |