refactor(html): keep the frontend css and js as files, embedded at build time - #864
Conversation
2af5585 to
102de6a
Compare
|
Rebased onto main (#863 and #865 have landed) and force-pushed. The asset files carry the current scripts. They were snapshots of the literals as of #862, so the four the sheet editor changed — Checks:
Rebase decisions worth a look: Review: two comments carried facts that this PR dates — the char-array rationale said the longest script "sits a few hundred under" the cap (it is over it now), and the Note for whoever advances the reference-output pins next: |
…ild time `frontend.cpp` was 92 KB, 78 KB of it css and javascript inside raw string literals. Nothing that reads either language could see it: no highlighting, no formatter, no linter, and the three `test/browser` harnesses each parsed the C++ by string index to recover a script and wrote a gitignored copy beside their pages. msvc caps a string literal at 16380 bytes, so `pdf_annotation_js` was already split over two literals reassembled through an `Asset::content_tail`, guarded by a `consteval fits_a_literal`, and `spreadsheet.js` has since been split the same way. The 21 assets now live as files under `src/odr/internal/html/frontend/`, and `cmake/frontend_assets.cmake` embeds them into a generated header of `inline constexpr std::string_view`s. The bytes back them as a `char` array of `'\xNN'` character literals: an array has no length cap, and the literal form survives both a signed and an unsigned `char` — a `0xNN` integer narrows on one and a negative one on the other. This is not the `data/` directory #648 removed. Nothing is shipped beside the library, no consumer gains a path to point at, and android, apple, wasm, python and the jni all build the same target as before. `frontend.cpp` keeps the asset table, which now reads as the documented index of what each view writes, and loses `content_tail` and `fits_a_literal`. The emitted html is byte-identical: `HtmlOutputTests` reproduces every reference output, `resources/*.css` and `*.js` included. The newline that used to open each literal — and that a shipped resource file still carries — is written once now, in `written()`, so the two forms stay the same bytes. `pdf-annotation.js` keeps the blank line at the seam of the two old literals for the same reason. `test/browser/*/serve` no longer extract anything: a shared `serve.py` falls back to the asset directory, so a page links the file the library embeds. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DChmZKEn3WdXWKu9KRbJMz
102de6a to
7485f7f
Compare
frontend.cppwas 92 KB, 78 KB of it css and javascript inside raw string literals. Nothing that reads either language could see it — no highlighting, no formatter, no linter — and the threetest/browserharnesses each parsed the C++ by string index to recover a script and wrote a gitignored copy beside their pages. msvc caps a string literal at 16380 bytes, sopdf_annotation_jswas already split over two literals reassembled through anAsset::content_tail, guarded by aconsteval fits_a_literal;spreadsheet.jsis within a few hundred bytes of the same surgery.What changes
The 21 assets now live as files under
src/odr/internal/html/frontend/, andcmake/frontend_assets.cmakeembeds them into a generated header ofinline constexpr std::string_views.frontend.cppdrops from 2744 to 295 lines and keeps only the asset table — which now reads as the documented index of what each view writes — plus the locating and writing.The bytes back each view as a
chararray of'\xNN'character literals: an array has no length cap, and the literal form survives both a signed and an unsignedchar, where a0xNNinteger narrows on one and a negative decimal on the other. Verified against the ndk'saarch64-linux-android24, whosecharis unsigned.test/browser/*/serveno longer extract anything. A sharedserve.pyfalls back to the asset directory, so a page links the file the library embeds rather than a copy of it, and the three.gitignores go away.What does not change
This is not the
data/directory #648 removed. That was a runtime split — a directory every consumer had to ship and point at. This is a build-time one: nothing is shipped beside the library, no consumer gains a path, and android, apple, wasm, python and the jni all build the same target as before. No public API, no install rule, no conan option.Byte-identical output
HtmlOutputTestsreproduces every reference output exactly —diff -rqagainsttest/data/reference-outputis empty,resources/*.cssand*.jsincluded. Two details serve that:written(), so the embedded and the linked form stay the same bytes.pdf-annotation.jskeeps the blank line at the seam of the two old literals.Checks
HtmlOutputTests+diff -rqagainst the reference output: no differences.-Wall -Wextra -Werror -fsyntax-onlywith Homebrew g++-15 and with the ndk clang (--target=aarch64-linux-android24), both clean.frontend.cpp: only the pre-existingbugprone-derived-method-shadowing-base-methodfindings in untouchedfile.hpp.🤖 Generated with Claude Code