add lisp packages

This commit is contained in:
2020-12-05 21:29:49 +01:00
parent 85e20365ae
commit a6e2395755
7272 changed files with 1363243 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
sudo: false
language: node_js
node_js:
- 'node'
- '6'
- '5'
- '4'

View File

@@ -0,0 +1,74 @@
'use strict'
var slugify = require('slugify')
var escaper = require('escaper')
var stripComments = require('strip-css-comments')
module.exports = scope
scope.replace = replace
function scope (css, parent, o) {
if (!css) return css
if (!parent) return css
if (typeof o === 'string') o = {keyframes: o}
if (!o) o = {keyframes: false}
css = replace(css, parent + ' $1$2')
//regexp.escape
var parentRe = parent.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
//replace self-selectors
css = css.replace(new RegExp('(' + parentRe + ')\\s*\\1(?=[\\s\\r\\n,{])', 'g'), '$1')
//replace `:host` with parent
css = css.replace(new RegExp('(' + parentRe + ')\\s*:host', 'g'), '$1')
//revoke wrongly replaced @ statements, like @supports, @import, @media etc.
css = css.replace(new RegExp('(' + parentRe + ')\\s*@', 'g'), '@')
//revoke wrongly replaced :root blocks
css = css.replace(new RegExp('(' + parentRe + ')\\s*:root', 'g'), ':root')
//animations: prefix animation anmes
var animations = [],
animationNameRe = /@keyframes\s+([a-zA-Z0-9_-]+)\s*{/g,
match
while ((match = animationNameRe.exec(css)) !== null) {
if (animations.indexOf(match[1]) < 0)
animations.push(match[1])
}
var slug = slugify(parent)
animations.forEach(function (name) {
var newName = (o.keyframes === true ? slug + '-' : typeof o.keyframes === 'string' ? o.keyframes : '') + name
css = css.replace(new RegExp('(@keyframes\\s+)' + name + '(\\s*{)', 'g'),
'$1' + newName + '$2')
css = css.replace(new RegExp('(animation(?:-name)?\\s*:[^;]*\\s*)' + name + '([\\s;}])', 'g'),
'$1' + newName + '$2')
})
//animation: revoke wrongly replaced keyframes
css = css.replace(new RegExp('(' + parentRe + ' )(\\s*(?:to|from|[+-]?(?:(?:\\.\\d+)|(?:\\d+(?:\\.\\d*)?))%))(?=[\\s\\r\\n,{])', 'g'), '$2')
return css
}
function replace (css, replacer) {
var arr = []
css = stripComments(css)
// escape strings etc.
css = escaper.replace(css, true, arr)
css = css.replace(/([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)/g, replacer)
// insert comments, strings etc. back
css = escaper.paste(css, arr)
return css
}

View File

@@ -0,0 +1,39 @@
{
"name": "scope-css",
"version": "1.2.1",
"description": "Scope each css rule with a selector, ie. nest into parent",
"main": "index.js",
"scripts": {
"test": "node test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dy/scope-css.git"
},
"keywords": [
"css",
"style",
"insert-css",
"nesting",
"scope",
"nest",
"parent",
"selector",
"sheetify"
],
"author": "ΔY <df.creative@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/dy/scope-css/issues"
},
"homepage": "https://github.com/dy/scope-css#readme",
"devDependencies": {
"cln": "^1.1.0",
"tape": "^4.9.1"
},
"dependencies": {
"escaper": "^2.5.3",
"slugify": "^1.3.1",
"strip-css-comments": "^3.0.0"
}
}

View File

@@ -0,0 +1,92 @@
# scope-css [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges) [![Build Status](https://img.shields.io/travis/dy/scope-css.svg)](https://travis-ci.org/dy/scope-css)
Prefix or nest each style selector in a css string. Useful to create namespaced css for components, themes, applications, modular css etc. Also it is tiny.
## Usage
[![npm install scope-css](https://nodei.co/npm/scope-css.png?mini=true)](https://npmjs.org/package/scope-css/)
```js
const scope = require('scope-css');
scope(`
.my-component {}
.my-component-element {}
`, '.parent');
/*
`
.parent .my-component {}
.parent .my-component-element {}
`
*/
```
## API
## css = scope(css, parent, options?)
Return css string with each rule prefixed with the parent selector. Note that `parent` selector itself will be ignored. Also each `:host` keyword will be replaced with `parent` value. Example:
```js
scope(`
.panel {}
:host {}
:host .my-element {}
.panel .my-element {}
.my-element {}
`, '.panel');
/*
`
.panel {}
.panel {}
.panel .my-element {}
.panel .my-element {}
.panel .my-element {}
`
*/
```
Options can scope keyframes via `{ keyframes: bool|prefixStr }` option, eg.
```js
scope(`
.panel {
animation: infinite loading 4s;
}
@keyframes loading {
from { top: 0; }
to { top: 100px; }
}
`, '.panel', { keyframes: true })
/*
`
.panel {
animation: infinite panel-loading 4s;
}
@keyframes panel-loading {
from { top: 0; }
to { top: 100px; }
`)
*/
```
## css = scope.replace(css, 'replacement $1$2')
Apply replace to css, where `$1` is matched selectors and `$2` is rules for the selectors. It does not do any self/host detection, so use it for more flexible replacements.
```js
scope.replace(`
.my-component, .my-other-component {
padding: 0;
}
`, '$1');
// `.my-component, my-other-component`
```
## Credits
Based on [this question](http://stackoverflow.com/questions/12575845/what-is-the-regex-of-a-css-selector).