Giter Club home page Giter Club logo

postcss-src's Introduction

Open source PostCSS polyfill for the new src() function

CSS Values and Units Level 4 defines a src() function. This function works just like the old-school url() function, but without url()'s legacy parsing behavior that prevents the use of additional CSS functions like var() inside it.

This plugin polyfills the src() function by compiling it to an equivalent url(), getting rid of the quotes around the string if possible. For example:

body {
  background: src("http://www.example.com/pinkish.gif");
}

is transformed into:

body {
  background: url(http://www.example.com/pinkish.gif);
}

Although this plugin doesn't natively polyfill CSS variables, it can be used with other polyfills like postcss-custom-properties to make it possible to include build-time variable values in url()s. But make sure you run postcss-src last in your plugin chain!

For example:

/* With both postcss-custom-properties and postcss-src: */

:root {
  --pinkish: "http://www.example.com/pinkish.gif";
}

body {
  background: src(var(--pinkish));
}

is transformed into:

body {
  background: url(http://www.example.com/pinkish.gif);
}

Usage

Add postcss-src to your project:

npm install postcss-custom-properties --save-dev

Use postcss-src as a PostCSS plugin:

const postcss = require('postcss');
const postcssSrc = require('postcss-src);

postcss([
  postcssSrc(/* plugin options */)
]).process(css /*, PostCSS options */);

Options

allowNativeSrc

By default, if postcss-src encounters a src() that it can't safely convert to a url() (such as src(var(--foo))), it will throw an error.

If this is true, it will emit the src() unchanged instead.

postcssSrc({
  allowNativeSrc: true,
});

For example, this throws an error by default but with allowNativeSrc: true it will be left unchanged.

/* Without postcss-custom-properties */

body {
  background: src(var(--foo));
}

postcss-src's People

Contributors

digvan avatar nex3 avatar pamelalozano16 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

postcss-src's Issues

Security Policy violation Outside Collaborators

Allstar has detected that this repository’s Outside Collaborators security policy is out of compliance. Status:
Did not find any owners of this repository
This policy requires all repositories to have an organization member or team assigned as an administrator. Either there are no administrators, or all administrators are outside collaborators. A responsible party is required by organization policy to respond to security events and organization requests.

To add an administrator From the main page of the repository, go to Settings -> Manage Access.
(For more information, see https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories)

Alternately, if this repository does not have any maintainers, archive or delete it.

This issue will auto resolve when the policy is in compliance.

Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.

Include in `postcss-preset-env` ?

Should this polyfill be included in postcss-preset-env?

From what I can tell it seems relatively safe for users because it throws when something unsafe is encountered.

Security Policy violation Branch Protection

Allstar has detected that this repository’s Branch Protection security policy is out of compliance. Status:
Branch Protection enforcement is configured in Allstar, however Branch Protection is not available on this repository. Upgrade to GitHub Pro or make this repository public to enable this feature.
See: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/about-protected-branches for more information.
If this is not feasible, then disable Branch Protection policy enforcement for this repository in Allstar configuration.

This issue will auto resolve when the policy is in compliance.

Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.

Security Policy violation SECURITY.md

Allstar has detected that this repository’s SECURITY.md security policy is out of compliance. Status:
Security policy not enabled.
A SECURITY.md file can give users information about what constitutes a vulnerability and how to report one securely so that information about a bug is not publicly visible. Examples of secure reporting methods include using an issue tracker with private issue support, or encrypted email with a published key.

To fix this, add a SECURITY.md file that explains how to handle vulnerabilities found in your repository. Go to https://github.com/googlestaging/postcss-src/security/policy to enable.

For more information, see https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository.

This issue will auto resolve when the policy is in compliance.

Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.