This repository has been archived by the owner on Aug 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
330 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules/ | ||
npm-debug.log | ||
*.actual.css | ||
*.sublime-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,56 @@ | ||
const R_FUNC = /url\((\s*)((['"]?).*?\3.*?)(\s*)\)/gi; | ||
const R_PARAMS = /^(['"]?)(.+?)\1(?:\s+(.+))?$/; | ||
|
||
module.exports = function mapFunctions(cssValue, callback) { | ||
return cssValue.replace(R_FUNC, function (matches, before, params, quote, after) { | ||
params = params.match(R_PARAMS); | ||
var assetStr = params[2]; | ||
var modifier = params[3]; | ||
var result = callback(before, quote, assetStr, modifier, after); | ||
return result || matches; | ||
}); | ||
var gonzales = require('gonzales'); | ||
var list = require('postcss/lib/list'); | ||
|
||
function CSSString (str) { | ||
this.quotes = str[0]; | ||
|
||
if (this.quotes === "'" || this.quotes === '"') { | ||
this.value = str.slice(1, -1); | ||
} else { | ||
this.value = str; | ||
this.quotes = ''; | ||
} | ||
} | ||
|
||
CSSString.prototype.toString = function () { | ||
return this.quotes + this.value + this.quotes; | ||
}; | ||
|
||
module.exports = function mapFunctions(cssValue, map) { | ||
var ast = gonzales.srcToCSSP(cssValue, 'value'); | ||
|
||
var traverse = function (node) { | ||
var type = node[0]; | ||
var children = node.slice(1); | ||
|
||
if (type === 'uri') { | ||
node = gonzales.srcToCSSP(gonzales.csspToSrc(node), 'funktion'); | ||
return traverse(node); | ||
} | ||
|
||
if (type === 'funktion') { | ||
var name = children[0][1]; | ||
var body = children[1].slice(1).map(function (x) { | ||
return gonzales.csspToSrc(traverse(x));; | ||
}).join(''); | ||
|
||
var process = map[name]; | ||
|
||
if (typeof process === 'function') { | ||
return ['raw', process.apply(this, list.comma(body).map(function (param) { | ||
return new CSSString(param); | ||
}))]; | ||
} | ||
} | ||
|
||
return [type].concat(children.map(function (child) { | ||
if (Array.isArray(child)) { | ||
return traverse(child); | ||
} | ||
|
||
return child; | ||
})); | ||
}; | ||
|
||
return gonzales.csspToSrc(traverse(ast)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
{ | ||
"name": "postcss-assets", | ||
"version": "0.9.1", | ||
"version": "1.0.0", | ||
"description": "PostCSS plugin to manage assets", | ||
"author": "Vadim Borodean <[email protected]>", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/borodean/postcss-assets" | ||
"url": "https://github.com/borodean/postcss-assets" | ||
}, | ||
"dependencies": { | ||
"cssesc": "^0.1.0", | ||
"image-size": "^0.3.3", | ||
"gonzales": "^1.0.7", | ||
"image-size": "^0.3.5", | ||
"js-base64": "^2.1.5", | ||
"mime": "^1.2.11", | ||
"postcss": "^2.2.5" | ||
"postcss": "^3.0.7" | ||
}, | ||
"devDependencies": { | ||
"tape": "^3.0.0" | ||
"tape": "^3.0.3" | ||
}, | ||
"scripts": { | ||
"test": "tape test" | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.