Code Monkey home page Code Monkey logo

stylis's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stylis's Issues

Minor styling issue

I'm using stylis through styled-components and you already fixed an issue I had a few months ago (styled-components/styled-components#530) but I found another one when I wrote this

.item {
  .wrapper button& {
    /* styles */
  }
}

It should out put .wrapper button.item {} but it wasn't working for me. It works as expected on styled-components 1.X.

Syntax errors

Would be great if we could get some syntax errors for invalid CSS. Is this possible with stylis?

PrinceXML specific nested css selectors broken in the last week or so

Hello,

I'm using styled-components, which has a dependency on stylis. In their update 2.0.1 they upgraded stylis, and now my PrinceXML specific css stopped rendering correctly.

(PrinceXML generates PDF's from CSS/HTML/JS)

So previously I could do:

@page {
    @top-left {
        font-size: 11px;
        content: "this is an example string shown in the header";
    }
}

which is plain css, not pre-processed syntax or anything.

As of late, it completely ignores these selectors and prints out the cssRules outside of these selectors.

Any way to fix this?

align-self not prefixed in iOS8

On an iPhone 6 (running iOS 8), stylis is outputting:
align-self: center

It needs to be:
-webkit-align-self: center

Thanks!

Lighthouse complains about old flexbox spec

When I run Lighthouse on my website it complains about old flex box spec being used. It doesn't like for example display: webkit-box.

Is this something that could be configurable if you don't need to support really old browsers?

Most of the rules with universal selector has stopped to work

At some point, I think stylis has stopped supporting universal selectors :(.

When I do this (on the playground):

.MyComponent > * {
  color: blue;
}

it outputs:

.MyComponent > {
  color: blue;
}

And well, in every position I try to use a universal selector. It's this intended?

I just updated styled-jsx from 0.5.7 to 1.0.0. Previously, this same rules were working and, with this update, all got broken >_<.

Feature - execute plugin on empty block

I need a way to enable plugins to execute on empty blocks.

I see two use cases for this:

  1. transform and preserve any selector that was in my source (lossless).
  2. when used as linter be able to warn on empty selector.

The issue:

.selector {}

This will not trigger my plugin.


I did fixed it in my project by modifying the source.

I added config called lossless

stylis.use({lossless: true})

and changed this code block

// execute plugins, block context
if ((lossless && current[0] !== '') || (length > 0 && plugged > 0)) {
    result = proxy(BLCKS, out, current, parent, line, column, length, id)

    if (result !== void 0) {
        length = (out = result).length
    }
}

I can submit a pull request but I wanted to create an issue first.

10x in advance.

Invalid hidden characters inserted after commas

This is really weirding me out to debug, but I think this is an issue that has arisen in a recent version of Stylis.

With this input:

html {
  font-family: 'Proxima Nova', 'Helvetica Neue', sans-serif;
}

Strange invisible characters get inserted just after the commas, that invalidates the whole rule in browsers. All my fonts are Times New Roman now :'(

Attribute selectors with no value cause TypeError

Using attribute selectors without a value [data-attribute] causes an error in stylis:

stylis.js:89 Uncaught TypeError: Cannot read property 'charCodeAt' of undefined

// [ attr selector
case 91: {
  // `[data-id=namespace]` -> ['data-id', 'namespace']
  attr = selector.substring(1, selector.length - 1).split('=');
  char = (namespace = attr[1]).charCodeAt(0); // Error occurs here

sample code:

const style = document.createElement('style');
style.textContent = stylis('[data-attribute]', 'color: red');
document.head.appendChild(style);

This happens with using [email protected].

This can be resolved when using [data-attribute="anything here"] however that enforces the element to have that value for the attribute, instead of matching every data-attribute instance no matter the value.

Might be possible to add a check to make sure there is an =, and if there is then split on it, else grab the value between index 1 and index: length - 1 which would correspond to the [ and ] wrapping the data-attribute without a namespace.

Precompute calc when possible

When possible calc can be precomputed:

calc(10px * 2) => 20px
calc(100% / 3) => 33.3333%

This is done in many transpilers like stylus, less, postcss etc.

Not possible when dealing with relative values like:
calc(100vh - 5px)
calc(50% - 20px)

Use stylis.js from command line

Is there a cli I can use to compile my styled-components css?

Something like this:

npm install stylis -g
stylis -w style.stylis -o style.css

Prefix `:read-only` psuedo class

Input:

/* @scope .foo */

input:read-only {
	color: red;
}

Expected result:

.foo input:-moz-read-only {
	color: red;
}

.foo input:read-only {
	color: red;
}

Actual result:

.foo input:read-only {
	color: red;
}

Class attached to other class in sub section doesn't work

This is correct:

stylis(`.abc`, `&.foo {color: yesplease}`)
".abc.foo {color: yesplease}"

This is not:

stylis(`.abc`, `&.foo { &.bar {color: yesplease}}`)
".abc .foo.bar {color: yesplease}"

(should be .abc.foo.bar without space)

This is also not:

stylis(`.abc`, `&.foo { &.bar { &.barbar {color: yesplease}}}`)
".abc .foo.bar .barbar {color: yesplease}"

(should be .abc.foo.bar.barbar)

grid-template-areas after first string is not being passed to the browser

ide:
screen shot 2017-07-23 at 2 58 01 pm

browser:
screen shot 2017-07-23 at 2 57 51 pm

as you can see, the second line for the grid-template-areas is not being passed to the browser.

Is there a way to fix this?

edit
Making it inline seems to work but it should work both ways

.mainContainer {
  width: 80vw;
  margin: auto;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto;
  grid-template-areas:
    "header header header" ". main .";
}

Stilynt - linter plugin

v1.2.0 landed with what was needed to successfully created a linter, WIP at plugins/linter The bulk of the effort will be in scrapping css syntax data and converting that to regex's or create them by hand to validate known css properties.

Autoprefixing configuration

Different browsers require different sets of prefixes - see http://caniuse.com/. There does not currently seem to be any support for configuring which browsers should be supported with prefixing. Is it intended to be a manual setting - flagging every single prefix you need on your own - or to match e.g. postCSS functionality where you can set which browsers to support?

Position fixed with wrong prefixing

There are useless prefixing of position: fixed when I update from 3.2.9 to 3.2.10:

// compare 3.2.9 with 3.2.10

+ position: -webkit-box;
+ position: -webkit-fixed;
+ position: -ms-fixedbox;
  position: fixed;

Online demo:

2017-08-24 11 00 59

Prefix column-count css property

I'm using column-count css property in my css but the property doesn't get prefixed. I'm not quite sure what properties the library should prefix and what not to. Are you using browserslist or some predefined list of properties to prefix?

Nested at-rule

Was working on some styled-components stuff, and I think I've found a bug.

Here's the code I'm running (just to get a sense of how the plugins work atm) using v3.2.8:

import Stylis from 'stylis'

const stylis = new Stylis({
  global: false,
  cascade: true,
  keyframe: false,
  prefix: true,
  compress: false,
  semicolon: true,
})

const plugin_calls = []
stylis.use((context, content, selectors, parent, line, column, length) => {
  plugin_calls.push({ context, content, selectors, parent, line, column, length })
})
stylis('.foo', `
  bar: baz;
  @media screen and (min-width: 600px) { 
    yeah: nah;
    @supports (lol) {
      too: right;
    }
  }
`)
console.log(JSON.stringify(plugin_calls, null, 2))
[
  {
    "context": -1,
    "content": "\n  bar: baz;\n  @media screen and (min-width: 600px) { \n    yeah: nah;\n    @supports (lol) {\n      too: right;\n    }\n  }\n",
    "selectors": [
      ".foo"
    ],
    "parent": [
      ".foo"
    ],
    "line": 1,
    "column": 1,
    "length": 0
  },
  {
    "context": 1,
    "content": "bar:baz",
    "selectors": [
      ".foo"
    ],
    "parent": [],
    "line": 2,
    "column": 11,
    "length": 0
  },
  {
    "context": 1,
    "content": "yeah:nah",
    "selectors": [
      ".foo"
    ],
    "parent": [
      ".foo"
    ],
    "line": 4,
    "column": 14,
    "length": 0
  },
  {
    "context": 1,
    "content": "too:right",
    "selectors": [
      ".foo"
    ],
    "parent": [
      ".foo"
    ],
    "line": 6,
    "column": 17,
    "length": 0
  },
  {
    "context": 2,
    "content": "too:right;",
    "selectors": [
      ".foo"
    ],
    "parent": [
      ".foo"
    ],
    "line": 7,
    "column": 5,
    "length": 10
  },
  {
    "context": 3,
    "content": ".foo{too:right;}",
    "selectors": [
      "@supports (lol)"
    ],
    "parent": [
      ".foo"
    ],
    "line": 7,
    "column": 5,
    "length": 16
  },
  {
    "context": 2,
    "content": "yeah:nah;",
    "selectors": [
      ".foo"
    ],
    "parent": [
      ".foo"
    ],
    "line": 8,
    "column": 3,
    "length": 9
  },
  {
    "context": 3,
    "content": ".foo{yeah:nah;}@supports (lol){.foo{too:right;}}",
    "selectors": [
      "@media screen and (min-width:600px)"
    ],
    "parent": [
      ".foo"
    ],
    "line": 8,
    "column": 3,
    "length": 48
  },
  {
    "context": 2,
    "content": "bar:baz;",
    "selectors": [
      ".foo"
    ],
    "parent": [],
    "line": 9,
    "column": 1,
    "length": 8
  },
  {
    "context": -2,
    "content": ".foo{bar:baz;}@media screen and (min-width:600px){.foo{yeah:nah;}@supports (lol){.foo{too:right;}}}",
    "selectors": [
      ".foo"
    ],
    "parent": [
      ".foo"
    ],
    "line": 9,
    "column": 1,
    "length": 99
  }
]

To my mind, the first "context": 3, callback (for "content": ".foo{too:right;}",) should have a parent of [".foo", "@media screen and (min-width:600px)"], not just .foo. I'm guessing somewhere there's an expectation that at-rules can only be one level deep, which isn't the case (@media and @supports work just fine nested, at least).

I'm trying to build a simple plugin that can do the sort of thing described here: threepointone/glam#5 to make stylis' output insertRule-able.

Would there be a better way to approach this?

No semicolons support

I'm working on a big app with lots of CSS, and tried to use styled-components v2 but everything broke. After some debugging I realised that almost all of the breakage was because we're not very... consistent with semicolons, and stylis treats semicolon-less lines differently from PostCSS.

Is there any chance we could align that behaviour? Otherwise few people can upgrade to v2 as it'll break their entire app with basically no automated way of fixing it. 😕

option to disable minification

It would be nice to be able to disable minification completely. This is useful for development mostly. Would it be hard to do so?

Remove 2009 flex box spec

The spec is ancient and the prefixes are hurting performance for any browser that is ie11 and above.

New syntax support is: Chrome 21+, Safari 6.1+, Firefox 22+, Opera (& Opera Mobile) 12.1+, IE 11+, and Blackberry 10+.

(https://css-tricks.com/old-flexbox-and-new-flexbox/)

Summary: Old is 2.3x slower than new.

https://developers.google.com/web/updates/2013/10/Flexbox-layout-isn-t-slow
https://developers.google.com/web/tools/lighthouse/audits/old-flexbox

Regardless of how modern browsers are using the older properties, we are sending down unnecessary properties when using SSR.

pasted_image_at_2017_10_10_05_57_pm_360

I think we should remove this for the benefit of all end users. I'm willing to help with the removal if you are open to the idea of removing the old spec.

Print styles

Input

injectGlobal`
  @page {
    size: A4 landscape;
  }
  @page :left {
    margin-left: 3cm;
  }
  @media (max-width: 700px) {
    html {
      background: palevioletred;
    }
  }
`

Expected Behavior

style tag in server side rendered head with

@page{size: A4 landscape;}
@page :left{margin-left: 3cm;}
@media (max-width: 700px){html{background: palevioletred;}}

Actual Behavior

style tag in server side rendered head with

@page{{size: A4 landscape;}}
@page :left{{margin-left: 3cm;}}
@media (max-width: 700px){html{background: palevioletred;}}

Copied from styled-components/styled-components#957

Prefix inside `@supports` declaration

Input:

/* @scope .foo */

input {
	@supports (appearance: none) {
		appearance: none;
	}
}

Expected result:

@supports ((-webkit-appearance: none) or (-moz-appearance: none) or (appearance: none)) {
	.foo input {
		-webkit-appearance: none;
		-moz-appearance: none;
		appearance: none;
	}
}

Actual result:

@supports (appearance: none) {
	.foo input {
		-webkit-appearance: none;
		-moz-appearance: none;
		appearance: none;
	}
}

objectify plugin

I saw that you started ast and objectify plugins. cool!

I took the idea and started my own.

here is the gist for it I want to get you feedback.

gist

`nth-child` not working with `cascade: false`

I found this bug via using styled-jsx and pinpointed the error.

I tried running this test:

'nth-child with cascade false': {
	options: {
		cascade: false
	},
	sample: `b > a:nth-child(2n) { color: blue }`,
	expected: `b.user>a:nth-child(2n){color: blue;}`
}

It fails ❌ and the result is this:

46 'failed: ' 'test' '\n\n' 'b.user>a.user:nth-child(2n.user){color: blue;}'
36 'expected: ' '\n\n' 'b.user>a:nth-child(2n){color: blue;}' '\n\n---------------\n\n'

Somehow the 2n value got namespaced and became 2n.user 😢

Prefixing SVG fill unnecessarily

It looks like the fill SVG property gets a webkit prefix it doesn't need, as it has the same first three letters as filter. The MDN page doesn't mention this ever needing a prefix.

Happy to make a PR with a fix 😄

Parsing error with version 2

What happened

I'm trying to use stylis with this input but it's not working with stylis 2.x 😕

stylis(`.${hash}`, style)

In

  @media (max-width: 600px) {
    & { color: red }
  }

  &:hover {
    color: orange
  }

Out - 1.2.8

@media (max-width: 600px) {.OTIfQo {color: red}}.OTIfQo:hover {color: orange} 

Out - 2.0.5 (fail)

.OTIfQo:hover {@media (max-width: 600px) {.OTIfQo {color: red}}color: orange} 

--dynamic css

This is an idea i've been thinking about... since stylis can identify css variables / a css-variables-like syntax for free it could potentially also mark them for faster re compiling of just the dynamic parts that a CSS in JS library can use to plugin into. For example: with s-c.

const Button = styled.button`
color:red;
width: ${value};
`

The s-c library could then pass this to stylis as

// first tell stylis to enable this option
stylis.set({dynamic: true})

// then pass as a string once
stylis('#id', `
color:red;
// prefixed the dynamic value with a hash
width: --hash1203 30px; 
`)

stylis would compile this to the following but also record that --hash1203 is a dynamic value that i can quickly recompile later when requested.

#id {
color:red;
width: 30px;
}

s-c could then call stylis to re-compile only the dynamic parts if it has any in cache into a function when needed.

stylis.pipe(hash, fn)

The fn function would receive only the parts that have changed

const fn = (selector, property, value, index) => {
style.insertRule(`${selector} { ${property}: ${value} }`, index)
}

This is an idea that could go into V3 of the stylis rewrite i'm working on while still maintaining the small 3kb bundle size.

cc @geelen, @philpl, @mxstbr, @giuseppeg in case this is something they might see using.

Prefix both transition & transform for iOS Safari 8 and older

I'm using stylis via styled-components and I noticed a bug in iOS 8 and older.

When using a style like this transition: transform 600ms ease;, iOS Safari 8 and older requires both properties to be -webkit- prefixed.

Current stylis output:

-webkit-transition: transform 600ms ease;
transition: transform 600ms ease;

Needs to also include a double prefixed rule like this:

-webkit-transition: transform 600ms ease;
-webkit-transition: -webkit-transform 600ms ease;
transition: transform 600ms ease;

More info on this behavior: http://stackoverflow.com/questions/20669190/browser-specific-prefixes-with-a-css-transition-on-transform

Thanks!

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.