boring_avatars 0.2.0
boring_avatars: ^0.2.0 copied to clipboard
A bit-exact Dart port of boring-avatars. Same name in, same avatar out — with every upstream version selectable.
0.2.0 #
Adds upstream boring-avatars 1.7.0, 1.8.0, 1.9.0 and 1.10.0 as
BoringAvatarsVersion.v1_7_0. Purely additive — v1_6_1 renders the same
bytes it did in 0.1.0, so nothing you have already shipped changes.
<title>is optional from 1.7.0, and defaults to off — upstream's own default. That is the entire difference between the two selectors: measured against the reference tree, the 1.6.3 → 1.7.0 source diff is 7 files and 14 lines, of which 6 are the title and 6 are whitespace inside a JSX expression that reaches no output. Withtitle: true,v1_7_0andv1_6_1render byte-identical documents for every variant.boringAvatarSvgtakes a newtitleargument. It isbool?rather thanboolbecause the two selectors disagree about the default, and either literal would be silently wrong for one of them.title: falsewithv1_6_1throws anArgumentErrornaming the argument — 1.6.x has no such prop and cannot switch the element off, and upstream would ignore the request rather than tell you.BoringAvatarsVersion.latesthas moved fromv1_6_1tov1_7_0. If you passedlatestin0.1.0and relied on<title>, you lose it here — which is what passinglatestmeans. Name a selector to pin an avatar.BoringAvatar, the widget, is unchanged and takes notitleargument:<title>is not drawn, so accepting the choice would be accepting a value nothing reads. UseSemanticsto announce an avatar in Flutter.- Four upstream releases share one selector, and each is measured rather than
assumed. 1.10.0 is rendered and compared to 1.7.0 across 1,200 documents —
zero differ. 1.8.0 and 1.9.0 shipped npm tarballs with no JavaScript in
them at all, so nothing can render those; their evidence is that their
src/libgit tree is 1.10.0's, byte for byte. Both records live in the committed fixture, not in prose. - The one difference inside the group is the mask
id— a literal at 1.7.0, React'suseId()from 1.8.0. It names nothing a reader sees and depends on the component's position in the render tree, so this package emits the literal. The fixture records both, unnormalised, rather than leaving the exclusion implicit.
0.1.0 #
First release. Reproduces upstream boring-avatars 1.6.1, 1.6.2 and 1.6.3
— the three releases that share one output — as BoringAvatarsVersion.v1_6_1.
-
boringAvatarSvg(...)returns upstream's SVG document as a string, byte for byte, for all six variants:marble,beam,pixel,sunset,ringandbauhaus. Upstream's two deprecated names,geometricandabstractStyle, resolve exactly as upstream resolves them. -
versionandsizeare required. A defaultversionwould make the avatars in your app change on a dependency upgrade, which is the one thing a frozen selector exists to prevent. -
Verified against the real npm package rendered through
react-dom/server: 600 documents (6 variants × 20 names × 5 palettes), plus square and size variations. Names include empty strings, Hangul, CJK, emoji ZWJ sequences, newlines and 200-character inputs. -
Two inputs deliberately do not reproduce upstream, both documented in the README:
sunsetwith a name containing',",(,)or\(upstream paints a blank avatar; this package renders it), and asizethat is neither anumnor aString(upstream drops the attributes; this package throws). -
BoringAvatardraws the same avatar as a widget, rasterised in software at the display's physical pixel size. Not throughflutter_svg— measured, it does not clamprxper SVG 1.1 §9.4, so the circular mask comes out square, and it has no<filter>, somarbleloses its blur. Not throughCanvaseither, which would make the pixels depend on Skia-vs-Impeller, GPU, platform and Flutter version. -
The rasterizer reads the whole practical CSS
<color>grammar: hex (#RGB,#RGBA,#RRGGBB,#RRGGBBAA), the 148 CSS named colours,transparent,currentColor,rgb()/rgba()/hsl()/hsla()(either separator, percentages or 0–255, alpha as a number or a percentage, hue indeg/grad/rad/turn), the Color 4 families —hwb(),lab()/lch(),oklab()/oklch(),color()with every predefined space — and the 42 system colours, frozen at Chrome's macOS light-mode values. Out-of-gamut colours clip per channel, as Chrome was measured doing. Keywords are ASCII case-insensitive and tolerate surrounding whitespace. Not read, deliberately:nonecomponents, relative colour syntax, andcalc(). Anything outside that grammar draws what a browser draws for an invalid declaration — the shape is not painted, and a gradient stop falls back to black; measured against Chrome. The widget still rejects such a palette up front, naming the argument, so a typo fails loudly. -
A palette colour may carry its own transparency, and its alpha multiplies the shape's coverage, as a browser does with the same document.
-
The named-colour table is generated from the CSS Color 4 specification and cross-checked against a real Chrome render — 148 of 148 agree.
-
The drawing happens off the frame. A background isolate on native; on the web, where Flutter has no isolate to offer, the rasterizer yields the thread between bands instead. Your app stays responsive while an avatar draws, and the box is its final size from the first frame, so nothing reflows when the picture arrives — but it arrives a beat later rather than immediately. Web is about four times slower than native for the same drawing; the README carries the measured numbers.
-
One physical size per variant is markedly cheaper than its neighbours. Each variant has a design size — 80 for
marble,pixel,sunsetandbauhaus, 90 forring, 36 forbeam— and asking for exactly that many physical pixels is the one case where an axis-aligned rectangle keeps an exact closed-form coverage instead of going through the polygon integrator. Same picture; measured,pixelis 6.5x cheaper at 80 than at 81. Worth knowing if you draw many avatars and can choosesize × devicePixelRatio. -
Only one raster runs at a time per widget. A burst of changing sizes draws once, at the size that survived, rather than once per frame.
-
Changing
name,colors,variant,versionorsquareclears the avatar while the new one draws, because the old pixels are a picture of somebody else. Changingsizealone keeps the current one on screen until the sharper version is ready. -
sizemust be finite and positive, and must survive the device pixel ratio. Each failure throws anArgumentErrornamingsizeand saying which of the two it was. -
A raster that fails reports through Flutter's error machinery instead of vanishing, and the widget clears rather than leaving a stale avatar up.