All Projects → kripod → style-vendorizer

kripod / style-vendorizer

Licence: MIT license
Tiny CSS vendor prefixer and property alias mapper for runtime styling solutions

Programming Languages

typescript
32286 projects
shell
77523 projects

Projects that are alternatives of or similar to style-vendorizer

Sbt S3 Resolver
☁️Amazon S3-based resolver for sbt
Stars: ✭ 112 (+100%)
Mutual labels:  resolver
Outlaw
JSON mapper for macOS, iOS, tvOS, and watchOS
Stars: ✭ 24 (-57.14%)
Mutual labels:  mapper
rescached-go
Resolver (DNS) cache daemon.
Stars: ✭ 30 (-46.43%)
Mutual labels:  resolver
Sofie Tv Automation
This is the documentation for the state-based studio automation system Sofie, used in live TV news production by the Norwegian public service broadcaster NRK since September 2018.
Stars: ✭ 155 (+176.79%)
Mutual labels:  resolver
es-mvc
ESMVC 旨在方便 ElasticSearch 的使用,就行访问数据库一样访问ES,提供了方便的 service, mapper 层。底层支持 TransportClient, RestHighLevelClient 。
Stars: ✭ 20 (-64.29%)
Mutual labels:  mapper
graphql-dependency
Cross service dependencies for GraphQL API with underlying @imqueue services
Stars: ✭ 17 (-69.64%)
Mutual labels:  resolver
C Ares
A C library for asynchronous DNS requests
Stars: ✭ 1,193 (+2030.36%)
Mutual labels:  resolver
Farseer.Net
Provides consistent standard use of common components of the .Net Core language
Stars: ✭ 42 (-25%)
Mutual labels:  mapper
jurl
Fast and simple URL parsing for Java, with UTF-8 and path resolving support
Stars: ✭ 84 (+50%)
Mutual labels:  resolver
reach-schema
Functional schema-driven JavaScript object validation library.
Stars: ✭ 34 (-39.29%)
Mutual labels:  resolver
Hotchocolate
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
Stars: ✭ 3,009 (+5273.21%)
Mutual labels:  resolver
Kuberesolver
Grpc Load Balancer with Kubernetes resolver
Stars: ✭ 241 (+330.36%)
Mutual labels:  resolver
restql
RESTful API Resolver for Nested-Linked Resources | 🕸 🕷
Stars: ✭ 16 (-71.43%)
Mutual labels:  resolver
Prance
Resolving Swagger/OpenAPI 2.0 and 3.0 Parser
Stars: ✭ 133 (+137.5%)
Mutual labels:  resolver
devtoolbox
A PowerShell module that enables software developers to speed up their CLI workflow.
Stars: ✭ 28 (-50%)
Mutual labels:  alias
Graphql Mongoose Loader
GraphQL Mongoose Loader helpers
Stars: ✭ 98 (+75%)
Mutual labels:  resolver
Swift-Viper-Weather-App
iOS app with Clean Architecture
Stars: ✭ 20 (-64.29%)
Mutual labels:  mapper
ngx upstream jdomain
An asynchronous domain name resolution module for nginx upstream.
Stars: ✭ 71 (+26.79%)
Mutual labels:  resolver
derivejs
DeriveJS is a reactive ODM - Object Document Mapper - framework, a "wrapper" around a database, that removes all the hassle of data-persistence by handling it transparently in the background, in a DRY manner.
Stars: ✭ 54 (-3.57%)
Mutual labels:  mapper
polymorphia
A very fast POJO codec for MongoDB (used in conjunction with the Mongo Java Driver) that handles generic types as well as polymorphic class hierarchies
Stars: ✭ 21 (-62.5%)
Mutual labels:  mapper

style-vendorizer

Tiny CSS vendor prefixer and property alias mapper for runtime styling solutions.

npm npm bundle size GitHub Workflow Status (branch) Contributor Covenant

Usage

Install the library with a package manager, e.g. npm:

npm install style-vendorizer

After that, import transformer functions on demand. A recommended starting point is shown below:

import {
  cssPropertyAlias,
  cssPropertyPrefixFlags,
  cssValuePrefixFlags,
} from "style-vendorizer";

function styleDeclaration(property, value) {
  let cssText = "";

  /* Resolve aliases, e.g. `gap` -> `grid-gap` */
  const propertyAlias = cssPropertyAlias(property);
  if (propertyAlias) cssText += `${propertyAlias}:${value};`;

  /* Prefix properties, e.g. `backdrop-filter` -> `-webkit-backdrop-filter` */
  const propertyFlags = cssPropertyPrefixFlags(property);
  if (propertyFlags & 0b001) cssText += `-webkit-${property}:${value};`;
  if (propertyFlags & 0b010) cssText += `-moz-${property}:${value};`;
  if (propertyFlags & 0b100) cssText += `-ms-${property}:${value};`;

  /* Prefix values, e.g. `position: "sticky"` -> `position: "-webkit-sticky"` */
  /* Notice that flags don't overlap and property prefixing isn't needed here */
  const valueFlags = cssValuePrefixFlags(property, value);
  if (valueFlags & 0b001) cssText += `${property}:-webkit-${value};`;
  else if (valueFlags & 0b010) cssText += `${property}:-moz-${value};`;
  else if (valueFlags & 0b100) cssText += `${property}:-ms-${value};`;

  /* Include the standardized declaration last */
  /* https://css-tricks.com/ordering-css3-properties/ */
  cssText += `${property}:${value};`;

  return cssText;
}

Prefix flags may be defined in TypeScript without any overhead as follows:

const enum CSSPrefixFlags {
  "-webkit-" = 1 << 0, // 0b001
     "-moz-" = 1 << 1, // 0b010
      "-ms-" = 1 << 2, // 0b100
}

/* Magic numbers from the previous snippet should be replaced like below: */
if (flags & CSSPrefixFlags["-webkit-"]) cssText += "...";
if (flags & CSSPrefixFlags["-moz-"]) cssText += "...";
if (flags & CSSPrefixFlags["-ms-"]) cssText += "...";

Browser Support

Every browser in the default Browserslist configuration is supported and tested against:

  • Baidu Browser for Android 7.12+
  • Chrome 57+
  • Edge 16+
  • Firefox 48+
  • Internet Explorer 11
  • KaiOS Browser 2.5+
  • Opera 46+
  • Safari 12.2+
  • Samsung Internet Browser 11.1+
  • QQ Browser for Android 10.4+
  • UC Browser for Android 12.12+

Quirks

  • Function values are only prefixed for longhand properties. This guarantees that only the start of each value is compared, for efficiency:

    // Prints "1 0"
    console.log(
      cssPropertyPrefixFlags(
        "background-image", // Longhand
        "image-set('example.png' 1x, 'example-2x.png' 2x)", // Prefixed
      ),
      cssPropertyPrefixFlags(
        "background", // Shorthand
        "image-set('example.png' 1x, 'example-2x.png' 2x)", // Not prefixed
      ),
    );
  • CSS Grid works in IE 11 only when using the following longhand properties:

    • grid-template-rows, grid-template-columns
    • grid-row-start, grid-column-start
    • -ms-grid-row-span and -ms-grid-column-span (along with grid-row-end and grid-column-end for cross-browser compatibility)
    • align-self, justify-self
  • cross-fade() and element() functions are not prefixed, due to the lack of standard implementations.

  • Selectors are not yet supported.

Acknowledgements

This project was heavily inspired by tiny-css-prefixer. Test vectors are obtained from @mdn/browser-compat-data.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].