alexdunphy / units Goto Github PK
View Code? Open in Web Editor NEWGot units? Convert them! Parse length, angle and resolution CSS values and convert between units.
License: MIT License
Got units? Convert them! Parse length, angle and resolution CSS values and convert between units.
License: MIT License
This library was required from a Node Canvas dependency in our app and was failing because our code was initialised in the head rather than the body, so document.body didn't exist. This was the error for anyone googling
utilities.js: Uncaught TypeError: Cannot read property 'appendChild' of null
For vertical-align, the two numeric values it can take are percentage and length.
getCreatedElementHeight(document.body, {
lineHeight: el_styles.lineHeight,
fontFamily: el_styles.fontFamily,
fontSize: el_styles.fontSize
});
Though that may not be entirely reliable
When you try to convert from PX to % on an element, which is a child of body and has fixed position, it will throw an error on utilities.getRelativeElementDimension, when trying to get element.offsetParent, which is null in that case.
The solution I propose is to add document.documentElement fallback to offsetParent:
reference = positioned ? element.offsetParent || document.documentElement : element.parentNode;
The problem with server side rendering is that window doesnt exist. Neiter can it look what px the body has. Would be nice if the prop element also could be a numeric value in px.
units.convert('rem', '16px', 16);
I recently discovered the SVG DOM API provides some builtin unit conversion functionality. It would not be applicable to all cases, but I suspect it could possibly be more reliable and faster for the cases it can be used for.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.