Giter Club home page Giter Club logo

scoper's Introduction

Scoper

A polyfill for scoped HTML style elements.

Quick Start

Just include scoper.js on your page to start using scoped HTML style elements.

Install via npm: npm install css-scoper

How It Works

Each <style scoped> element's parent is wrapped with a span that is given a unique ID. Its rules are moved to head and all selectors prepended with their respective ID.

Scoper is only active when the page contains scoped styles and the browser doesn't support them.

Tests

Tests can be run with the command mocha test/test.js.

scoper's People

Contributors

fcamblor avatar ldipasquale avatar thomaspark avatar

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

Watchers

 avatar  avatar  avatar  avatar

scoper's Issues

Scoper is ignoring closing </style> tag

I've been using scoper and it has been working well. But today I got a strange behavior that breaks the code. I have:

<a href="'+pagelink+'" target="_blank"> <img src="'+imgpath+'" class="extLinkImg"> <style scoped> .extLinkImg { width: 35px; height: 35px; margin:10px; } <\style> </a>

And I see in the console that what is being put in the head <style> is:

#scoper-2 .extLinkImg { width: 35px; height: 35px; margin:10px; } <style> </a>

It seems that scoper is not seeing the ending / in the closing tag...
I tried the same code inside a wrapping div and is the same. Do you have any clue why this is happening?

using :root/html selectors has no effect

Again, in Chrome/Vivaldi, using ":root" selector doesn't seem to have any effect
It is important, because you'd want to use ":root" or "html" to specify font-size and use "rem" size units

ReferenceError: document is not defined

The error ReferenceError: document is not defined shows when I tried to use it in the node environment.

Maybe we can add a null check before calling document.createElement?

Disable wrapping body elements

scoper.js attempts to wrap elements where the scoped style element is a direct descendant, which effectively eliminates the applicability of the style content. I think it's fairly safe to just leave these style elements as is since they apply to the whole body.

I know this is an unusual case with an obvious manual workaround, but I'm auto generating the html and I don't always know where the scoped styles are going to be placed in the document.

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.