flutter_html_css_units 0.3.0
flutter_html_css_units: ^0.3.0 copied to clipboard
A flutter_html extension that renders the CSS absolute and viewport length units flutter_html 3.0.0 reads as pixels or as zero: pt, pc, in, cm, mm, Q, vw, vh, vmin and vmax.
0.3.0 #
- Renamed from
flutter_html_css_units_extensionon pub.flutter-io.cn. The old package stays published and is marked discontinued with this one as its replacement. Class names are unchanged.
0.2.0 #
- Five more properties are rewritten, every one of them a length a sibling renders and
flutter_htmldrops:text-decoration-thickness,transform,transform-origin,flexandgrid-template-columns. Each was measured against the package that reads it, with this extension registered and without. text-decoration-thicknessis the one that started this.flutter_html_css_text_metrics0.2.0 resolves that property inpx,em,remand%and in nothing else, so30ptstayed unusable while10pxworked. It now arrives as40px. Measured on a red underline atfont-size: 40px:30ptpainted 79 red pixels, one row tall, in 0.1.0, and paints 720 red pixels, nine rows tall, now, which is pixel for pixel what40pxpaints on its own.1cmlands on 639 pixels and eight rows, and5vwon the same 720 and nine as40px, because5vwof an 800 pixel viewport is 40. text-metrics 0.2.0 is not on pub.flutter-io.cn yet, so that half is measured against its working tree and there is no dev dependency on it here.transformandtransform-origin.flutter_html_css_transform0.1.0 readspx,em,remandpt, and returns null for every other unit, which drops the whole declaration. Measured ontransform: translate(1in, 0): a translation of 0 before, 96 now.translate(10vw, 5vh)goes from (0, 0) to (80, 30).72ptalready gave 96 and still does.flexandgrid-template-columns.flutter_html_css_flex0.2.0 readspx,em,remand a bare0. Measured onflex: 0 0 2inin adisplay: flexcontainer: the item is 14.25 wide before and 192 now, which is what192pxgives.grid-template-columns: 2in 1frgoes from 584 and 584 to 192 and 392.flex-basis,gap,row-gapandcolumn-gapwere in the list already; 0.1.0 filed them under "nothing renders these yet", and flex 0.2.0 renders all four, so the dartdoc moves them up a group.- No new ordering rule, and the existing ones are unchanged. All three siblings read the
inline style after the
preStylingstep, so this extension always writes first. Both orders are measured for transform and flex. - Rejected, because nothing reads the length:
background-positionandbackground-size(flutter_html_css_backgroundkeeps the colour of abackgroundshorthand and drops the image),object-position(flutter_html_css_object_fittakes keywords and percentages),vertical-align(flutter_htmlmaps keywords to aVerticalAlignenum),text-underline-offset,perspective,filter,border-spacing,scroll-marginandscroll-padding.doc/units.mdhas the list and the reason for each.
0.1.0 #
- Initial release.
flutter_html3.0.0 has a_unitMapwith exactly one arm,default: return Unit.px, so every absolute unit keeps its number and loses its meaning:12ptrenders 12 pixels,1inrenders 1,2cmrenders 2,3pcrenders 3. The viewport units are worse, becausecsslibhands them over as aViewportTermthat nothing influtter_htmlhas a case for, so50vwis 0 andfont-size: 5vwis dropped outright.dvhand friends are not even lexed as a unit;10dvhcomes through as the number 10 and a stray identifier. All of it is silent.doc/units.mdhas the table, and every row is pinned by a test. - The fix is one rewrite of the inline
styleattribute at thepreStylingstep: eachpt,pc,in,cm,mmorQtoken becomespxby the CSS ratios, and eachvw,vh,vminorvmaxtoken (plus thes,landdvariants) becomespxagainst the viewport. That lands beforeflutter_html's parser and reacheswidth,height,font-size,line-height,margin,padding,borderandtext-shadowthrough its own cascade. The tokenizer walks the value by hand rather than with a regex, so a quoted string, aurl()argument, a hex colour and an identifier such astranslate3dare never touched. - The viewport comes from
MediaQuery.maybeSizeOfonExtensionContext.buildContext. Its dartdoc says that field is only guaranteed at thebuildingstep, but the parser passes its own context at all four steps and the parse runs fromdidChangeDependencies, so the lookup works. I measured that rather than trusting either the comment or my reading. There is aviewportSizeargument for when the basis should be something other than the window. One honest limitation: the rewrite replaces50vwin the DOM, so a resize does not re-resolve it; give the widget a new key. - Order rules, all measured against the real siblings: list this after
CssStylesheetHtmlExtensionand after Bootstrap or Vuetify, because they write into the same attribute at the same step and a declaration written after this ran keeps its unit. List it beforeCssBorderHtmlExtension, which reads3ptas 3 and writes3pxback. Colour, size-constraints, font-size and percent-size are order-free, and the tests run each in both orders. ex,chandfrare left alone. They need font metrics no step exposes, and guessing at anemfallback would have made the render wrong in a different way.