Comparing version 7.0.0 to 8.0.0
@@ -1,5 +0,10 @@ | ||
# 7.0.0 / 2019-11-27 | ||
# 8.0.0 / 2021-22-21 | ||
* pseudo Update | ||
* !important table attribute update | ||
# 7.0.0 / 2020-07-10 | ||
* Breaking: requires node 10+ | ||
* Please see changes in web-resource-inliner@6 for other details | ||
* Please see changes in web-resource-inliner@5 for other details | ||
@@ -6,0 +11,0 @@ # 6.0.0 / 2019-11-27 |
'use strict'; | ||
var program = require('commander'); | ||
var { program } = require('commander'); | ||
var pkg = require('../package'); | ||
@@ -5,0 +5,0 @@ |
'use strict'; | ||
var utils = require('./utils'); | ||
var numbers = require('./numbers'); | ||
@@ -29,2 +30,3 @@ module.exports = function makeJuiceClient(juiceClient) { | ||
var styleAttributeName = 'style'; | ||
var counters = {}; | ||
@@ -133,2 +135,3 @@ if (options.styleAttributeName) { | ||
pseudoEl.pseudoElementParent = el; | ||
pseudoEl.counterProps = el.counterProps; | ||
el[pseudoElPropName] = pseudoEl; | ||
@@ -152,2 +155,39 @@ } | ||
if (!el.counterProps) { | ||
el.counterProps = el.parent && el.parent.counterProps | ||
? Object.create(el.parent.counterProps) | ||
: {}; | ||
} | ||
function resetCounter(el, value) { | ||
var tokens = value.split(/\s+/); | ||
for (var j = 0; j < tokens.length; j++) { | ||
var counter = tokens[j]; | ||
var resetval = parseInt(tokens[j+1], 10); | ||
isNaN(resetval) | ||
? el.counterProps[counter] = counters[counter] = 0 | ||
: el.counterProps[counter] = counters[tokens[j++]] = resetval; | ||
} | ||
} | ||
function incrementCounter(el, value) { | ||
var tokens = value.split(/\s+/); | ||
for (var j = 0; j < tokens.length; j++) { | ||
var counter = tokens[j]; | ||
if (el.counterProps[counter] === undefined) { | ||
continue; | ||
} | ||
var incrval = parseInt(tokens[j+1], 10); | ||
isNaN(incrval) | ||
? el.counterProps[counter] = counters[counter] += 1 | ||
: el.counterProps[counter] = counters[tokens[j++]] += incrval; | ||
} | ||
} | ||
// go through the properties | ||
@@ -159,4 +199,13 @@ function addProps(style, selector) { | ||
var value = style[i].value; | ||
var important = style[i].value.match(/!important$/) !== null; | ||
if (important && !options.preserveImportant) value = value.replace(/\s*!important$/, ''); | ||
if (name === 'counter-reset') { | ||
resetCounter(el, value); | ||
} | ||
if (name === 'counter-increment') { | ||
incrementCounter(el, value); | ||
} | ||
var important = value.match(/!important$/) !== null; | ||
if (important && !options.preserveImportant) value = removeImportant(value); | ||
// adds line number and column number for the properties as "additionalPriority" to the | ||
@@ -225,3 +274,3 @@ // properties because in CSS the position directly affect the priority. | ||
if (el.pseudoElementType && el.styleProps.content) { | ||
var parsed = parseContent(el.styleProps.content.value); | ||
var parsed = parseContent(el); | ||
if (parsed.img) { | ||
@@ -248,9 +297,13 @@ el.name = 'img'; | ||
if (el.styleProps[i].prop === dimension) { | ||
if (el.styleProps[i].value.match(/px/)) { | ||
var pxSize = el.styleProps[i].value.replace('px', ''); | ||
var value = el.styleProps[i].value; | ||
if (options.preserveImportant) { | ||
value = removeImportant(value); | ||
} | ||
if (value.match(/px/)) { | ||
var pxSize = value.replace('px', ''); | ||
$(el).attr(dimension, pxSize); | ||
return; | ||
} | ||
if (juiceClient.tableElements.indexOf(elName) > -1 && el.styleProps[i].value.match(/\%/)) { | ||
$(el).attr(dimension, el.styleProps[i].value); | ||
if (juiceClient.tableElements.indexOf(elName) > -1 && value.match(/\%/)) { | ||
$(el).attr(dimension, value); | ||
return; | ||
@@ -279,2 +332,5 @@ } | ||
var value = el.styleProps[i].value; | ||
if (options.preserveImportant) { | ||
value = removeImportant(value); | ||
} | ||
if (prop === 'background') { | ||
@@ -293,3 +349,37 @@ value = extractBackgroundUrl(value); | ||
function parseContent(content) { | ||
function removeImportant(value) { | ||
return value.replace(/\s*!important$/, '') | ||
} | ||
function findVariableValue(el, variable) { | ||
while (el) { | ||
if (variable in el.styleProps) { | ||
return el.styleProps[variable].value; | ||
} | ||
var el = el.parent || el.pseudoElementParent; | ||
} | ||
} | ||
function applyCounterStyle(counter, style) { | ||
switch (style) { | ||
case 'lower-roman': | ||
return numbers.romanize(counter).toLowerCase(); | ||
case 'upper-roman': | ||
return numbers.romanize(counter); | ||
case 'lower-latin': | ||
case 'lower-alpha': | ||
return numbers.alphanumeric(counter).toLowerCase(); | ||
case 'upper-latin': | ||
case 'upper-alpha': | ||
return numbers.alphanumeric(counter); | ||
// TODO support more counter styles | ||
default: | ||
return counter.toString(); | ||
} | ||
} | ||
function parseContent(el) { | ||
var content = el.styleProps.content.value; | ||
if (content === 'none' || content === 'normal') { | ||
@@ -305,4 +395,36 @@ return ''; | ||
// Naive parsing, assume well-formed value | ||
content = content.slice(1, content.length - 1); | ||
var parsed = []; | ||
var tokens = content.split(/['"]/); | ||
for (var i = 0; i < tokens.length; i++) { | ||
if (tokens[i] === '') continue; | ||
var varMatch = tokens[i].match(/var\s*\(\s*(.*?)\s*(,\s*(.*?)\s*)?\s*\)/i); | ||
if (varMatch) { | ||
var variable = findVariableValue(el, varMatch[1]) || varMatch[2]; | ||
parsed.push(variable.replace(/^['"]|['"]$/g, '')); | ||
continue; | ||
} | ||
var counterMatch = tokens[i].match(/counter\s*\(\s*(.*?)\s*(,\s*(.*?)\s*)?\s*\)/i); | ||
if (counterMatch && counterMatch[1] in el.counterProps) { | ||
var counter = el.counterProps[counterMatch[1]]; | ||
parsed.push(applyCounterStyle(counter, counterMatch[3])); | ||
continue; | ||
} | ||
var attrMatch = tokens[i].match(/attr\s*\(\s*(.*?)\s*\)/i); | ||
if (attrMatch) { | ||
var attr = attrMatch[1]; | ||
parsed.push(el.pseudoElementParent | ||
? el.pseudoElementParent.attribs[attr] | ||
: el.attribs[attr] | ||
); | ||
continue; | ||
} | ||
parsed.push(tokens[i]); | ||
} | ||
content = parsed.join(''); | ||
// Naive unescape, assume no unicode char codes | ||
@@ -309,0 +431,0 @@ content = content.replace(/\\/g, ''); |
{ | ||
"name": "juice", | ||
"version": "7.0.0", | ||
"version": "8.0.0", | ||
"description": "Inlines css into html source", | ||
@@ -39,3 +39,3 @@ "bin": "bin/juice", | ||
"cheerio": "^1.0.0-rc.3", | ||
"commander": "^5.1.0", | ||
"commander": "^6.1.0", | ||
"mensch": "^0.3.4", | ||
@@ -42,0 +42,0 @@ "slick": "^1.12.2", |
[![Build Status](https://travis-ci.org/Automattic/juice.svg?branch=master)](https://travis-ci.org/Automattic/juice) | ||
[![Dependency Status](https://david-dm.org/Automattic/juice.svg)](https://david-dm.org/Automattic/juice) | ||
# Juice ![](http://i.imgur.com/jN8Ht.gif) | ||
# Juice ![](https://i.imgur.com/jN8Ht.gif) | ||
@@ -26,3 +26,3 @@ Given HTML, juice will inline your CSS properties into the `style` attribute. | ||
[Try out the web client version](http://automattic.github.io/juice/) | ||
[Try out the web client version](https://automattic.github.io/juice/) | ||
@@ -192,25 +192,4 @@ ## What is this useful for ? | ||
(The MIT License) | ||
MIT Licensed, see License.md | ||
Copyright (c) 2015 Guillermo Rauch <guillermo@learnboost.com> | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
### 3rd-party | ||
@@ -217,0 +196,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57090
15
1078
200
+ Addedcommander@6.2.1(transitive)
- Removedcommander@5.1.0(transitive)
Updatedcommander@^6.1.0