Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-epub

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-epub - npm Package Compare versions

Comparing version 2.2.5 to 2.2.6

106

index.js

@@ -7,2 +7,3 @@ "use strict";

var postcss = require("postcss"),
list = require("postcss/lib/list"),
props = [

@@ -30,26 +31,87 @@ // text

"voice-family"
];
],
types = [
"opentype",
"woff"
],
rxTypes = new RegExp("format\\(['\"]?(" + types.join("|") + ")['\"]?\\)");
/**
* PostCSS plugin to prefix ePub3 properties.
* @param {Object} style
*/
function plugin(style) {
style.eachDecl(function(decl) {
if (decl.value) {
if (props.indexOf(decl.prop) >= 0) {
decl.parent.insertBefore(decl, decl.clone({prop: "-epub-" + decl.prop}));
module.exports = postcss.plugin("postcss-epub", function(opts) {
opts = opts || {};
var
/**
* Sets all other options to true.
* @type {boolean}
*/
isStrict = opts.strict,
/**
* Set if we are to do strict font format checking and strip any non-epub prefixes.
* @type {boolean}
*/
isStrip = isStrict || opts.strip,
/**
* Set if we are to only check that the font defaults are correct.
* @type {boolean}
*/
isFonts = isStrict || opts.fonts;
/**
* PostCSS plugin to prefix ePub3 properties.
* @param {Object} css
*/
return function(css) {
css.eachDecl(function(decl) {
if (decl.value) {
if (props.indexOf(decl.prop) >= 0) {
decl.parent.insertBefore(decl, decl.clone({
prop: "-epub-" + decl.prop
}));
} else if (isStrip && decl.prop[0] === "-" && !/^-epub-/.test(decl.prop)) {
decl.parent.remove(decl);
}
}
});
if (isFonts) {
css.eachAtRule(function(rule) {
if (rule.name === "font-face") {
var hasWeight = false,
hasStyle = false;
rule.eachDecl(function(decl) {
switch (decl.prop) {
case "src":
var i,
fonts = list.comma(decl.value),
usable = [];
for (i = 0; i < fonts.length; i++) {
if (!/url\(/.test(fonts[i]) || rxTypes.test(fonts[i])) {
usable.push(fonts[i]);
}
}
if (usable.length) {
decl.value = usable.join(",");
} else {
throw decl.error("No valid font format, must have one of: " + types.join(", "), {plugin: "postcss-epub"});
}
break;
case "font-weight":
hasWeight = true;
break;
case "font-style":
hasStyle = true;
break;
}
});
if (!hasWeight) {
rule.append({prop: "font-weight", value: "normal"});
}
if (!hasStyle) {
rule.append({prop: "font-style", value: "normal"});
}
}
});
}
});
}
/*
* ...and export for use...
*/
module.exports = {
postcss: plugin,
process: function(css, opts) {
return postcss(plugin).process(css, opts).css;
}
};
};
});
{
"name": "postcss-epub",
"version": "2.2.5",
"version": "2.2.6",
"description": "PostCSS plugin to prefix ePub3 properties",

@@ -8,3 +8,3 @@ "keywords": [

"postcss",
"postcss-plugins",
"postcss-plugin",
"epub",

@@ -25,3 +25,3 @@ "epub3"

"devDependencies": {
"postcss": "^2.2.5",
"postcss": "^4.1.11",
"test": "^0.6.0"

@@ -28,0 +28,0 @@ },

# postcss-epub [![Build Status](https://travis-ci.org/Rycochet/postcss-epub.png)](https://travis-ci.org/Rycochet/postcss-epub)
> [PostCSS](https://github.com/postcss/postcss) plugin to prefix ePub3 properties.
> [PostCSS](https://github.com/postcss/postcss) plugin to give correct ePub3 css output.
See the [EPUB 3 CSS Profile](http://www.idpf.org/epub/30/spec/epub30-contentdocs.html#sec-css-text) for more information.
**Note:** This will leave the unprefixed property, there are other plugins to remove them if creating ePub3-only files.
## Installation

@@ -13,22 +11,73 @@

## Options
* ```fonts:true``` - This will ensure fonts have the correct font-weight and font-style defaults. This will also throw an error if any there is not a valid font source format (opentype or woff).
* ```strip:true``` - This will strip any non ```-epub-``` prefixes.
* ```strict:true``` - Implies all other options are set.
## Usage
```js
// dependencies
var fs = require("fs")
var postcss = require("postcss")
var epub = require("postcss-epub")
postcss([ require("postcss-epub") ])
// or
postcss([ require("postcss-epub")({strict:true}) ])
```
// css to be processed
var css = fs.readFileSync("input.css", "utf8")
See [PostCSS] docs for examples for your environment.
// process css
var output = postcss()
.use(epub())
.process(css)
.css
## Example
```css
@font-face {
font-family: 'Fake Font';
src: local('Fake Font'),
url('path/to/font.woff') format('woff'),
url('path/to/font.ttf') format('truetype'),
url('path/to/font.otf') format('opentype');
}
stuff {
dont: care;
hyphens: all;
line-break: normal;
text-align-last: center;
text-emphasis: red triangle;
text-emphasis-color: red;
text-emphasis-style: triangle;
word-break: break-all;
-webkit-prefix: something;
}
```
```css
@font-face {
font-family: 'Fake Font';
src: local('Fake Font'),url('path/to/font.woff') format('woff'),url('path/to/font.otf') format('opentype');
font-weight: normal;
font-style: normal;
}
stuff {
dont: care;
-epub-hyphens: all;
hyphens: all;
-epub-line-break: normal;
line-break: normal;
-epub-text-align-last: center;
text-align-last: center;
-epub-text-emphasis: red triangle;
text-emphasis: red triangle;
-epub-text-emphasis-color: red;
text-emphasis-color: red;
-epub-text-emphasis-style: triangle;
text-emphasis-style: triangle;
-epub-word-break: break-all;
word-break: break-all;
}
```
---
## [License](LICENSE)
[PostCSS]: https://github.com/postcss/postcss
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc