1.0.0 • Published 12 days ago

@omegion1npm/cum-at-quasi v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 days ago

CSS calc() to pixels transform

NPM version Build Status Size contributions welcome

Tiny Javascript library to transform CSS properties with CSS calc() function values to pixels based on window and element dimensions.

Install

yarn add --save @omegion1npm/cum-at-quasi

or

npm install --save @omegion1npm/cum-at-quasi

Usage

Pixels

import { transform } from "@omegion1npm/cum-at-quasi";

transform({
  prop: "width",
  value: "calc(10px + (100px / 3.5))"
});

↓ ↓ ↓ ↓ ↓ ↓

38.57142857142857

Percentages

import { transform } from "@omegion1npm/cum-at-quasi";

const parentElementDimensions = {
  width: 480,
  height: 100
};

transform({
  prop: "width",
  value: "calc(100% - 10px)",
  parent: parentElementDimensions
});

↓ ↓ ↓ ↓ ↓ ↓

470

Viewport units

import { transform } from "@omegion1npm/cum-at-quasi";

const windowDimensions = {
  width: 480,
  height: 640
};

transform({
  prop: "height",
  value: "calc(50vh + 10px)",
  win: windowDimensions
});

↓ ↓ ↓ ↓ ↓ ↓

330

rem unit

import { transform } from "@omegion1npm/cum-at-quasi";

transform({
  prop: "fontSize",
  value: "calc(2rem + 1px)",
});

↓ ↓ ↓ ↓ ↓ ↓

33

em unit

When em units are used on font-size, the size is relative to the font-size of the parent.

When used on other properties, it’s relative to the font-size of the element itself.

https://www.digitalocean.com/community/tutorials/css-rem-vs-em-units

import { transform } from "@omegion1npm/cum-at-quasi";

transform({
  prop: "fontSize",
  value: "calc(2em + 1px)",
  parent: {
    font: {
      size: 16
    }
  }
});

↓ ↓ ↓ ↓ ↓ ↓

33
import { transform } from "@omegion1npm/cum-at-quasi";

transform({
  prop: "height",
  value: "calc(10px + 2em)",
  font: {
    size: 16
  }
});

↓ ↓ ↓ ↓ ↓ ↓

42

min(), max(), clamp()

import { transform } from "@omegion1npm/cum-at-quasi";

transform({
  prop: "height",
  value: "calc(min(2px, 3px) + clamp(100px, 150px, 200px) + max(1px, 2px))",
});

↓ ↓ ↓ ↓ ↓ ↓

154

More examples

For more examples, please have a look at the tests.

Dependencies

japanesepostcssajvdeleteArray.prototype.findLastIndexredux-toolkitinternal slotassertssigintserializationrecursivegetOwnPropertyDescriptorrm -rflimitedgenericstsjoireadablelibphonenumbervalidatorpropECMAScript 2023scheme-validationpath-0direventEmittersetterchildES2021ES7concatMapeditortypedarraymime-dbsignalwhatwggetPrototypeOfyupenvexeECMAScript 2022ponyfillstreamhooksrobustjsonpathguidglobstylesheetcallboundnegative zerowidthES2015__proto__bannerawesomesauceECMAScript 3xdgsetPrototypeOfBigUint64Arraytypestc39tapesymbolses2017offsetqueuecolorreactsymbolfixed-widthuuidArray.prototype.filterirqdebugcoercibleArraymomentfsjestsameValueZeroeventsautoprefixerinterruptsconnectequaljslinuxuninstalljsdiffsafei18nfastifyauthenticationeslintpluginfetchcompile lessinspectbootstrap lessdom-testing-librarypromisesetImmediaterequireserializerurlSymbol.toStringTagPushtslibestreexhrexecutablewrapcacheextendString.prototype.matchAllstyleguidees2015groupByCSSstylesfpObject.entriesextensionsettingspropertiesgetintrinsicairbnbwebmatchES2017apollothrottlefulljsonidvartasknegativeconfigurabledropstructuredClonewgetincludessortFunction.prototype.nameeventDispatcherreducechaizodArrayBuffer.prototype.sliceWeakSetmkdirtypescriptthroates8fast-cloneWebSocketstreamsES5columnESttyxdg-openhigher-orderESnextcheckasyncstringbuffersstarterBigInt64Arrayvalidutil.inspectwatchFilereact animationfinduprateopensreadablestream_.extendcall-boundwordbreakvestFloat64ArraytextTypeScriptxsssignalspromisesreal-timecode pointsrmpreserve-symlinksquerycolourmodulescss variableUint8Arraycallless.jswebsiteforEachstyleelectronnamesreact-hooksuser-streamswaapiECMAScript 2018ES3mapconsume
1.0.0

12 days ago