hyperlens 0.2.4
hyperlens: ^0.2.4 copied to clipboard
Source-linked preview for Markdown and HTML: rendering, outline and reading position share one address (source line or DOM path), so editors can jump either way.
0.2.4 #
Documentation only — no code changed in this release.
- The README still said "0.1.0 in progress, nothing has been published yet" and told
callers to depend on
^0.1.0. Both had been stale for five releases: the status line now tracks the current version, and the install snippet points at the 0.2 line. Copying the old snippet resolved an old package. - The capability list was missing two things the package has had for a while: code-block syntax highlighting (78 languages, including the 41 extra grammars from 0.2.3) and KaTeX / Mermaid, which switch on from the document's own source.
0.2.3 #
Code blocks in both previews now cover the languages people actually write in, not just highlight.js's "common" build.
- 41 more grammars ship with the package (
assets/web/hljs/, the official 11.9.0 per-language files, ~110 KB raw / ~50 KB deflated): PowerShell, CMake, Protocol Buffers, Groovy, Gradle, LaTeX, Haskell, Scala, Elixir, Erlang, Clojure, OCaml, GLSL, Verilog, VHDL, Nginx, Handlebars, Twig, ERB, batch files, VBScript, PostgreSQL and more.highlight.min.jsis the official common build and carries none of them, so the same code was colored in an editor and plain in the preview. HyperlensAssets.hljsExtraLanguageslists them andallnow includes them; drop entries from that list to slim the bundle.- Vue has no highlight.js grammar (it never had one). A fence written as
vuefalls back toxml, whose rules hand<script>/<style>to the JavaScript and CSS grammars — so template, script and style all get color; only<script lang="ts">is parsed as JavaScript.
0.2.2 #
Receipts now have a single entry point, so a host no longer decides whether a given receipt is worth moving off the main isolate — and HTML can re-send its syntax tree on demand.
- New
PreviewReceiptDispatcher: hand every channel message todispatch()and the package takes it from there. Small receipts are parsed inline, big ones (the syntax tree can reach 2MB) are decoded in a background isolate, and the threshold stays internal — callers no longer carry a "how long counts as big" constant. The same document posts twice (the skeleton at render time, the full tree when the syntax panel asks), so a late skeleton is dropped as stale when another tree has already landed or a newer request returned first. The panel never falls back from the full tree to the skeleton. Platforms without isolates degrade to inline parsing. - The constructor takes an optional
onLog: one line for the off-thread duration of a big receipt, one for each dropped stale receipt. Silent by default. - The injected HTML script now exposes
window.hyperlensSyntaxAst()(the same name Markdown uses). HTML still sends its whole tree at once, but that first receipt can be lost (page reload, blank-page retry) — a caller opening the syntax panel can ask withHyperlensCommands.requestSyntaxAst()for another one. - The library docs, the example and both READMEs now use this entry point; the example's syntax sheet shows Markdown (skeleton → full tree) and HTML (re-send) taking the same command.
0.2.1 #
No change to the library itself — this release makes the artifact's third-party notices match what is actually inside it.
assets/web/mermaid.min.jsis rebuilt. Besides mermaid and KaTeX it carries 53 further dependencies (the d3 family, the cytoscape family, dagre-d3-es, dompurify, marked, lodash-es, …), distributed under MIT / ISC / BSD-3-Clause / (MPL-2.0 OR Apache-2.0). The complete list — every package with its copyright line, plus the verbatim text of all four licenses — is inlined as a comment at the end of the artifact, so the notices travel with every copy of the file.- New
assets/licenses/mermaid-bundle.txt: the same list as plain text, for a host's license page to read directly.mermaid.txtonly ever held the two MIT texts of the primary works (mermaid, KaTeX) — it could not tell a reader that the file also contains 53 other packages. THIRD_PARTY_NOTICES.md/.cn.md: the claim that there is no fourth-party code inside the artifact is gone. The two texts are now explained as a pair, and one note flags the second dompurify (3.4.18, brought along by mermaid) that rides inside the file alongside the separately shippedpurify.min.js(3.2.6) — same license, different code.
0.2.0 #
Link clicks now have one protocol, owned by the package: the criteria for when a click is intercepted, the receipt envelope, and the list of schemes that count as "leave the document". A caller injects and receives — it no longer copies either table.
- New
PreviewLinkSpace(repo/book) pluslinkReceipt()/parseLinkReceipt()/isExternalPreviewLink()/kPreviewExternalSchemesinlib/src/protocol/link_intent.dart. The private scheme list inlinks.dartis gone; both sides now read the exported one. - The link receipt carries the address space:
link <space> <context> <encoded href>(e.g.link repo docs%2Fchap2.html chap2.html%23sec2).contextis what lets a caller drop a late receipt from the page it has just left — the old envelope left that tohrefalone, and a late tap could be applied to the new page. The plainlink <encoded href>form is still understood, so existing templates keep working. PreviewLinkTappedgainsspaceandcontext.HtmlPreviewView-style callers can compare them with the page they configured and ignore everything else.HyperlensPage.fromText/htmlAnchorScriptacceptlinkSpace/linkContext: the injected HTML script posts the enriched envelope itself, so a page no longer needs a second, hand-written click script (two scripts meant two receipts for one click, and the second was only caught by a "same place" guard downstream).- The injected HTML script reports the reading position before the link, in the same JS turn (one capture-phase listener registered earlier than the link one), so a back stack gets the position the reader left from rather than the last settled one.
- A receipt the package cannot make sense of — wrong segment count, unknown address
space, broken escaping — is reported as unknown instead of being handed to the caller
as a link (
%FF-style escapes used to throw out of the parser). OpenRepoFilekeeps the#fragmentof a cross-file link (fragment, decoded):README.md#getting-startedno longer loses the section. A bare#anchorinside one document is still left to the page's own scrolling.- The example now shows the link path end to end: the HTML document gets
linkSpace/linkContext, the status bar prints the address space that came back, and ademo.html#receiptslink lands throughPreviewDomAddress('#receipts')(the Markdown document keeps posting the plain envelope, so both forms are on screen).
0.1.1 #
No change to the library itself — this release only tidies what the package ships with.
- The example is split by responsibility:
lib/main.dartkeeps the render pipeline (commit, receipt routing, reading-position semantics), while the sample documents, toolbar, outline drawer, status bar, syntax sheet and platform fallback moved tolib/src/. - The
descriptioninpubspec.yamlwas tightened to the length the pub specification asks for.
0.1.0 #
First extraction from the preview implementation of an editor app.
- Markdown rendering payload with line/block markers, safe HTML (DOMPurify), and KaTeX / mhchem math.
- HTML rendering payload with a DOM-path address for restoring the reading position.
- The HTML outline also picks up ARIA headings (
role="heading"witharia-level, defaulting to 2 and capped at 6) next to<h1>~<h6>; one entry per heading, so a heading nested inside another keeps only the outer one. - The HTML outline watches the document height (
ResizeObserver) and re-scans after a disclosure panel opens or closes, or an image grows — no page reload needed. - New syntax-tree skeleton receipt (
ast): Markdown reuses the same lexer as the render pass, HTML walks the browser's owndocument; the payload is clipped by node count, depth and byte gates. Dart side exposesPreviewSyntaxTree/PreviewSyntaxNode. - The full tree (nested blocks plus inline tokens) is fetched on demand through
HyperlensCommands.requestSyntaxAst(), sharing the same tokens and line numbers as the skeleton. - Syntax issue list (
issuesin theastreceipt): the page reports unclosed code fences, table rows whose cell count differs from the header, and reference-style links with no definition; the Dart side addsscanHtmlTagIssues(), a tag-stack scan over the source text that finds unclosed and stray end tags the browser's fixed-updocumentno longer shows. When both sources are merged the page's entries come first, and a duplicate (same kind, same place) is dropped. - Receipt protocol: render ready, link tapped, position reported, outline reported, focus applied, anchor scrolled, unknown message.
- Source-linked outline and syntax tree built from the same parse.
- Web assets (marked, DOMPurify, KaTeX, mhchem, highlight.js, Mermaid) declared by the package; the caller stops declaring them.
- Public surface:
HyperlensPage.fromTextis the single render entry (Markdown and HTML alike);HyperlensAssets,HyperlensBridge,HyperlensTheme,HyperlensLoggerandHyperlensAssetLoader(HyperlensRootBundleAssetLoaderfor Flutter) are the rest of it. - The WebView channel name is injected instead of being hard-coded: the Markdown
template takes it through a placeholder,
htmlAnchorScript(channelName:)for the HTML side, so the caller can register its own name. Either has to matchaddJavaScriptChannel, and a name that is not a valid identifier is rejected while the script is assembled. - Missing enhanced assets (KaTeX, mhchem, Mermaid) degrade to plain text and report
through
HyperlensLoggerinstead of failing the whole page. HyperlensThemetreats dark and ink as independent axes: ink is a monochrome overlay shipped in both polarities (*-ink.cssfor the default light e-ink look,*-ink-dark.cssfor its inverse).- Mermaid stays fully visible on dark backdrops: Sankey link bands were lost because
Mermaid hard-codes
mix-blend-mode: multiplyon them, which only works over a light page; the blend mode is now set back tonormalfor the dark themes only, so the light and light-ink looks are unchanged. - Reading positions are one address type (breaking):
PreviewSourceAddressfor a Markdown source line,PreviewDomAddressfor an HTML DOM path such asbody>div#main>p:nth(3), plusPreviewViewportcarrying the per-frame viewport lines that drive outline highlighting.PreviewAnchor(block/offset/scrollY) is gone, pages are only told to scroll throughHyperlensCommands(mdScrollToLine/hyperLensScrollToPath), and a position that cannot be resolved puts the reader back at the top instead of guessing. Saved positions still parse: a storedlineis reused, a pixel-only record falls back to top. - Documented that
HyperlensThemeis the sole definition of "how this page looks" for a host that has to decide whether to reload: the rendered page is a snapshot (background, text colour and overlay layers are baked into the HTML at load time), so a new knob has to be added together with==/hashCode. The case that bit us: ink and light share the same#ffffffbackground, so a host comparing only the background skipped the reload on "ink → light" and kept the ink monochrome overlay — coloured headings turned black (see theHyperlensThemeclass docs).