Comparing version 2.0.5 to 2.0.6
@@ -1,5 +0,4 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var AnsiPainter, styles, tags, tools, | ||
hasProp = {}.hasOwnProperty, | ||
slice = [].slice; | ||
hasProp = {}.hasOwnProperty; | ||
@@ -15,110 +14,107 @@ tools = require('./tools'); | ||
function AnsiPainter() {} | ||
class AnsiPainter { | ||
paint(s) { | ||
return this._replaceSpecialStrings(this._renderDom(this._parse(s))); | ||
} | ||
AnsiPainter.tags = tags; | ||
_replaceSpecialStrings(str) { | ||
return str.replace(/&sp;/g, ' ').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/&/g, '&'); | ||
} | ||
AnsiPainter.prototype.paint = function(s) { | ||
return this._replaceSpecialStrings(this._renderDom(this._parse(s))); | ||
}; | ||
_parse(string, injectFakeRoot = true) { | ||
if (injectFakeRoot) { | ||
string = '<none>' + string + '</none>'; | ||
} | ||
return tools.toDom(string); | ||
} | ||
AnsiPainter.prototype._replaceSpecialStrings = function(str) { | ||
return str.replace(/&sp;/g, ' ').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/&/g, '&'); | ||
}; | ||
_renderDom(dom) { | ||
var parentStyles; | ||
parentStyles = { | ||
bg: 'none', | ||
color: 'none' | ||
}; | ||
return this._renderChildren(dom, parentStyles); | ||
} | ||
AnsiPainter.prototype._parse = function(string, injectFakeRoot) { | ||
if (injectFakeRoot == null) { | ||
injectFakeRoot = true; | ||
_renderChildren(children, parentStyles) { | ||
var child, n, ret; | ||
ret = ''; | ||
for (n in children) { | ||
if (!hasProp.call(children, n)) continue; | ||
child = children[n]; | ||
ret += this._renderNode(child, parentStyles); | ||
} | ||
return ret; | ||
} | ||
if (injectFakeRoot) { | ||
string = '<none>' + string + '</none>'; | ||
_renderNode(node, parentStyles) { | ||
if (node.type === 'text') { | ||
return this._renderTextNode(node, parentStyles); | ||
} else { | ||
return this._renderTag(node, parentStyles); | ||
} | ||
} | ||
return tools.toDom(string); | ||
}; | ||
AnsiPainter.prototype._renderDom = function(dom) { | ||
var parentStyles; | ||
parentStyles = { | ||
bg: 'none', | ||
color: 'none' | ||
}; | ||
return this._renderChildren(dom, parentStyles); | ||
}; | ||
_renderTextNode(node, parentStyles) { | ||
return this._wrapInStyle(node.data, parentStyles); | ||
} | ||
AnsiPainter.prototype._renderChildren = function(children, parentStyles) { | ||
var child, n, ret; | ||
ret = ''; | ||
for (n in children) { | ||
if (!hasProp.call(children, n)) continue; | ||
child = children[n]; | ||
ret += this._renderNode(child, parentStyles); | ||
_wrapInStyle(str, style) { | ||
return styles.color(style.color) + styles.bg(style.bg) + str + styles.none(); | ||
} | ||
return ret; | ||
}; | ||
AnsiPainter.prototype._renderNode = function(node, parentStyles) { | ||
if (node.type === 'text') { | ||
return this._renderTextNode(node, parentStyles); | ||
} else { | ||
return this._renderTag(node, parentStyles); | ||
_renderTag(node, parentStyles) { | ||
var currentStyles, tagStyles; | ||
tagStyles = this._getStylesForTagName(node.name); | ||
currentStyles = this._mixStyles(parentStyles, tagStyles); | ||
return this._renderChildren(node.children, currentStyles); | ||
} | ||
}; | ||
AnsiPainter.prototype._renderTextNode = function(node, parentStyles) { | ||
return this._wrapInStyle(node.data, parentStyles); | ||
}; | ||
AnsiPainter.prototype._wrapInStyle = function(str, style) { | ||
return styles.color(style.color) + styles.bg(style.bg) + str + styles.none(); | ||
}; | ||
AnsiPainter.prototype._renderTag = function(node, parentStyles) { | ||
var currentStyles, tagStyles; | ||
tagStyles = this._getStylesForTagName(node.name); | ||
currentStyles = this._mixStyles(parentStyles, tagStyles); | ||
return this._renderChildren(node.children, currentStyles); | ||
}; | ||
AnsiPainter.prototype._mixStyles = function() { | ||
var final, i, key, len, style, styles, val; | ||
styles = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
final = {}; | ||
for (i = 0, len = styles.length; i < len; i++) { | ||
style = styles[i]; | ||
for (key in style) { | ||
if (!hasProp.call(style, key)) continue; | ||
val = style[key]; | ||
if ((final[key] == null) || val !== 'inherit') { | ||
final[key] = val; | ||
_mixStyles(...styles) { | ||
var final, i, key, len, style, val; | ||
final = {}; | ||
for (i = 0, len = styles.length; i < len; i++) { | ||
style = styles[i]; | ||
for (key in style) { | ||
if (!hasProp.call(style, key)) continue; | ||
val = style[key]; | ||
if ((final[key] == null) || val !== 'inherit') { | ||
final[key] = val; | ||
} | ||
} | ||
} | ||
return final; | ||
} | ||
return final; | ||
}; | ||
AnsiPainter.prototype._getStylesForTagName = function(name) { | ||
if (tags[name] == null) { | ||
throw Error("Unknown tag name `" + name + "`"); | ||
_getStylesForTagName(name) { | ||
if (tags[name] == null) { | ||
throw Error(`Unknown tag name \`${name}\``); | ||
} | ||
return tags[name]; | ||
} | ||
return tags[name]; | ||
}; | ||
self = AnsiPainter; | ||
static getInstance() { | ||
if (self._instance == null) { | ||
self._instance = new self(); | ||
} | ||
return self._instance; | ||
} | ||
AnsiPainter.getInstance = function() { | ||
if (self._instance == null) { | ||
self._instance = new self; | ||
static paint(str) { | ||
return self.getInstance().paint(str); | ||
} | ||
return self._instance; | ||
}; | ||
AnsiPainter.paint = function(str) { | ||
return self.getInstance().paint(str); | ||
}; | ||
static strip(s) { | ||
return s.replace(/\x1b\[[0-9]+m/g, ''); | ||
} | ||
AnsiPainter.strip = function(s) { | ||
return s.replace(/\x1b\[[0-9]+m/g, ''); | ||
}; | ||
AnsiPainter.tags = tags; | ||
self = AnsiPainter; | ||
return AnsiPainter; | ||
})(); | ||
}).call(this); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var codes, styles; | ||
@@ -49,3 +49,3 @@ | ||
if (code == null) { | ||
throw Error("Unknown color `" + str + "`"); | ||
throw Error(`Unknown color \`${str}\``); | ||
} | ||
@@ -62,3 +62,3 @@ return "\x1b[" + code + "m"; | ||
if (code == null) { | ||
throw Error("Unknown bg color `" + str + "`"); | ||
throw Error(`Unknown bg color \`${str}\``); | ||
} | ||
@@ -65,0 +65,0 @@ return "\x1B[" + code + "m"; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var color, colors, i, len, tags; | ||
@@ -27,7 +27,7 @@ | ||
}; | ||
tags["color-" + color] = { | ||
tags[`color-${color}`] = { | ||
color: color, | ||
bg: 'inherit' | ||
}; | ||
tags["bg-" + color] = { | ||
tags[`bg-${color}`] = { | ||
color: 'inherit', | ||
@@ -34,0 +34,0 @@ bg: color |
@@ -1,7 +0,7 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var Block, Layout, SpecialString, cloneAndMergeDeep, fn, i, len, prop, ref, terminalWidth; | ||
// Generated by CoffeeScript 2.5.1 | ||
var Block, Layout, SpecialString, cloneAndMergeDeep, i, len, prop, ref, terminalWidth; | ||
Block = require('./layout/Block'); | ||
cloneAndMergeDeep = require('./tools').cloneAndMergeDeep; | ||
({cloneAndMergeDeep} = require('./tools')); | ||
@@ -15,2 +15,51 @@ SpecialString = require('./layout/SpecialString'); | ||
class Layout { | ||
constructor(config = {}, rootBlockConfig = {}) { | ||
var rootConfig; | ||
this._written = []; | ||
this._activeBlock = null; | ||
this._config = cloneAndMergeDeep(self._defaultConfig, config); | ||
// Every layout has a root block | ||
rootConfig = cloneAndMergeDeep(self._rootBlockDefaultConfig, rootBlockConfig); | ||
this._root = new Block(this, null, rootConfig, '__root'); | ||
this._root._open(); | ||
} | ||
getRootBlock() { | ||
return this._root; | ||
} | ||
_append(text) { | ||
return this._written.push(text); | ||
} | ||
_appendLine(text) { | ||
var s; | ||
this._append(text); | ||
s = new SpecialString(text); | ||
if (s.length < this._config.terminalWidth) { | ||
this._append('<none>\n</none>'); | ||
} | ||
return this; | ||
} | ||
get() { | ||
this._ensureClosed(); | ||
if (this._written[this._written.length - 1] === '<none>\n</none>') { | ||
this._written.pop(); | ||
} | ||
return this._written.join(""); | ||
} | ||
_ensureClosed() { | ||
if (this._activeBlock !== this._root) { | ||
throw Error("Not all the blocks have been closed. Please call block.close() on all open blocks."); | ||
} | ||
if (this._root.isOpen()) { | ||
this._root.close(); | ||
} | ||
} | ||
}; | ||
self = Layout; | ||
@@ -45,68 +94,16 @@ | ||
function Layout(config, rootBlockConfig) { | ||
var rootConfig; | ||
if (config == null) { | ||
config = {}; | ||
} | ||
if (rootBlockConfig == null) { | ||
rootBlockConfig = {}; | ||
} | ||
this._written = []; | ||
this._activeBlock = null; | ||
this._config = cloneAndMergeDeep(self._defaultConfig, config); | ||
rootConfig = cloneAndMergeDeep(self._rootBlockDefaultConfig, rootBlockConfig); | ||
this._root = new Block(this, null, rootConfig, '__root'); | ||
this._root._open(); | ||
} | ||
Layout.prototype.getRootBlock = function() { | ||
return this._root; | ||
}; | ||
Layout.prototype._append = function(text) { | ||
return this._written.push(text); | ||
}; | ||
Layout.prototype._appendLine = function(text) { | ||
var s; | ||
this._append(text); | ||
s = SpecialString(text); | ||
if (s.length < this._config.terminalWidth) { | ||
this._append('<none>\n</none>'); | ||
} | ||
return this; | ||
}; | ||
Layout.prototype.get = function() { | ||
this._ensureClosed(); | ||
if (this._written[this._written.length - 1] === '<none>\n</none>') { | ||
this._written.pop(); | ||
} | ||
return this._written.join(""); | ||
}; | ||
Layout.prototype._ensureClosed = function() { | ||
if (this._activeBlock !== this._root) { | ||
throw Error("Not all the blocks have been closed. Please call block.close() on all open blocks."); | ||
} | ||
if (this._root.isOpen()) { | ||
this._root.close(); | ||
} | ||
}; | ||
return Layout; | ||
})(); | ||
}).call(this); | ||
ref = ['openBlock', 'write']; | ||
fn = function() { | ||
var method; | ||
method = prop; | ||
return Layout.prototype[method] = function() { | ||
return this._root[method].apply(this._root, arguments); | ||
}; | ||
}; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
prop = ref[i]; | ||
fn(); | ||
(function() { | ||
var method; | ||
method = prop; | ||
return Layout.prototype[method] = function() { | ||
return this._root[method].apply(this._root, arguments); | ||
}; | ||
})(); | ||
} |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var Block, SpecialString, cloneAndMergeDeep, terminalWidth; | ||
@@ -8,3 +8,3 @@ | ||
cloneAndMergeDeep = require('../tools').cloneAndMergeDeep; | ||
({cloneAndMergeDeep} = require('../tools')); | ||
@@ -14,209 +14,157 @@ module.exports = Block = (function() { | ||
self = Block; | ||
class Block { | ||
constructor(_layout, _parent, config = {}, _name = '') { | ||
this._layout = _layout; | ||
this._parent = _parent; | ||
this._name = _name; | ||
this._config = cloneAndMergeDeep(self.defaultConfig, config); | ||
this._closed = false; | ||
this._wasOpenOnce = false; | ||
this._active = false; | ||
this._buffer = ''; | ||
this._didSeparateBlock = false; | ||
this._linePrependor = new this._config.linePrependor.fn(this._config.linePrependor.options); | ||
this._lineAppendor = new this._config.lineAppendor.fn(this._config.lineAppendor.options); | ||
this._blockPrependor = new this._config.blockPrependor.fn(this._config.blockPrependor.options); | ||
this._blockAppendor = new this._config.blockAppendor.fn(this._config.blockAppendor.options); | ||
} | ||
Block.defaultConfig = { | ||
blockPrependor: { | ||
fn: require('./block/blockPrependor/Default'), | ||
options: { | ||
amount: 0 | ||
_activate(deactivateParent = true) { | ||
if (this._active) { | ||
throw Error("This block is already active. This is probably a bug in RenderKid itself"); | ||
} | ||
}, | ||
blockAppendor: { | ||
fn: require('./block/blockAppendor/Default'), | ||
options: { | ||
amount: 0 | ||
if (this._closed) { | ||
throw Error("This block is closed and cannot be activated. This is probably a bug in RenderKid itself"); | ||
} | ||
}, | ||
linePrependor: { | ||
fn: require('./block/linePrependor/Default'), | ||
options: { | ||
amount: 0 | ||
this._active = true; | ||
this._layout._activeBlock = this; | ||
if (deactivateParent) { | ||
if (this._parent != null) { | ||
this._parent._deactivate(false); | ||
} | ||
} | ||
}, | ||
lineAppendor: { | ||
fn: require('./block/lineAppendor/Default'), | ||
options: { | ||
amount: 0 | ||
return this; | ||
} | ||
_deactivate(activateParent = true) { | ||
this._ensureActive(); | ||
this._flushBuffer(); | ||
if (activateParent) { | ||
if (this._parent != null) { | ||
this._parent._activate(false); | ||
} | ||
} | ||
}, | ||
lineWrapper: { | ||
fn: require('./block/lineWrapper/Default'), | ||
options: { | ||
lineWidth: null | ||
this._active = false; | ||
return this; | ||
} | ||
_ensureActive() { | ||
if (!this._wasOpenOnce) { | ||
throw Error("This block has never been open before. This is probably a bug in RenderKid itself."); | ||
} | ||
}, | ||
width: terminalWidth, | ||
prefixRaw: '', | ||
suffixRaw: '' | ||
}; | ||
function Block(_layout, _parent, config, _name) { | ||
this._layout = _layout; | ||
this._parent = _parent; | ||
if (config == null) { | ||
config = {}; | ||
if (!this._active) { | ||
throw Error("This block is not active. This is probably a bug in RenderKid itself."); | ||
} | ||
if (this._closed) { | ||
throw Error("This block is already closed. This is probably a bug in RenderKid itself."); | ||
} | ||
} | ||
this._name = _name != null ? _name : ''; | ||
this._config = cloneAndMergeDeep(self.defaultConfig, config); | ||
this._closed = false; | ||
this._wasOpenOnce = false; | ||
this._active = false; | ||
this._buffer = ''; | ||
this._didSeparateBlock = false; | ||
this._linePrependor = new this._config.linePrependor.fn(this._config.linePrependor.options); | ||
this._lineAppendor = new this._config.lineAppendor.fn(this._config.lineAppendor.options); | ||
this._blockPrependor = new this._config.blockPrependor.fn(this._config.blockPrependor.options); | ||
this._blockAppendor = new this._config.blockAppendor.fn(this._config.blockAppendor.options); | ||
} | ||
Block.prototype._activate = function(deactivateParent) { | ||
if (deactivateParent == null) { | ||
deactivateParent = true; | ||
} | ||
if (this._active) { | ||
throw Error("This block is already active. This is probably a bug in RenderKid itself"); | ||
} | ||
if (this._closed) { | ||
throw Error("This block is closed and cannot be activated. This is probably a bug in RenderKid itself"); | ||
} | ||
this._active = true; | ||
this._layout._activeBlock = this; | ||
if (deactivateParent) { | ||
_open() { | ||
if (this._wasOpenOnce) { | ||
throw Error("Block._open() has been called twice. This is probably a RenderKid bug."); | ||
} | ||
this._wasOpenOnce = true; | ||
if (this._parent != null) { | ||
this._parent._deactivate(false); | ||
this._parent.write(this._whatToPrependToBlock()); | ||
} | ||
this._activate(); | ||
return this; | ||
} | ||
return this; | ||
}; | ||
Block.prototype._deactivate = function(activateParent) { | ||
if (activateParent == null) { | ||
activateParent = true; | ||
} | ||
this._ensureActive(); | ||
this._flushBuffer(); | ||
if (activateParent) { | ||
close() { | ||
this._deactivate(); | ||
this._closed = true; | ||
if (this._parent != null) { | ||
this._parent._activate(false); | ||
this._parent.write(this._whatToAppendToBlock()); | ||
} | ||
return this; | ||
} | ||
this._active = false; | ||
return this; | ||
}; | ||
Block.prototype._ensureActive = function() { | ||
if (!this._wasOpenOnce) { | ||
throw Error("This block has never been open before. This is probably a bug in RenderKid itself."); | ||
isOpen() { | ||
return this._wasOpenOnce && !this._closed; | ||
} | ||
if (!this._active) { | ||
throw Error("This block is not active. This is probably a bug in RenderKid itself."); | ||
write(str) { | ||
this._ensureActive(); | ||
if (str === '') { | ||
return; | ||
} | ||
str = String(str); | ||
this._buffer += str; | ||
return this; | ||
} | ||
if (this._closed) { | ||
throw Error("This block is already closed. This is probably a bug in RenderKid itself."); | ||
} | ||
}; | ||
Block.prototype._open = function() { | ||
if (this._wasOpenOnce) { | ||
throw Error("Block._open() has been called twice. This is probably a RenderKid bug."); | ||
openBlock(config, name) { | ||
var block; | ||
this._ensureActive(); | ||
block = new Block(this._layout, this, config, name); | ||
block._open(); | ||
return block; | ||
} | ||
this._wasOpenOnce = true; | ||
if (this._parent != null) { | ||
this._parent.write(this._whatToPrependToBlock()); | ||
} | ||
this._activate(); | ||
return this; | ||
}; | ||
Block.prototype.close = function() { | ||
this._deactivate(); | ||
this._closed = true; | ||
if (this._parent != null) { | ||
this._parent.write(this._whatToAppendToBlock()); | ||
_flushBuffer() { | ||
var str; | ||
if (this._buffer === '') { | ||
return; | ||
} | ||
str = this._buffer; | ||
this._buffer = ''; | ||
this._writeInline(str); | ||
} | ||
return this; | ||
}; | ||
Block.prototype.isOpen = function() { | ||
return this._wasOpenOnce && !this._closed; | ||
}; | ||
Block.prototype.write = function(str) { | ||
this._ensureActive(); | ||
if (str === '') { | ||
return; | ||
_toPrependToLine() { | ||
var fromParent; | ||
fromParent = ''; | ||
if (this._parent != null) { | ||
fromParent = this._parent._toPrependToLine(); | ||
} | ||
return this._linePrependor.render(fromParent); | ||
} | ||
str = String(str); | ||
this._buffer += str; | ||
return this; | ||
}; | ||
Block.prototype.openBlock = function(config, name) { | ||
var block; | ||
this._ensureActive(); | ||
block = new Block(this._layout, this, config, name); | ||
block._open(); | ||
return block; | ||
}; | ||
Block.prototype._flushBuffer = function() { | ||
var str; | ||
if (this._buffer === '') { | ||
return; | ||
_toAppendToLine() { | ||
var fromParent; | ||
fromParent = ''; | ||
if (this._parent != null) { | ||
fromParent = this._parent._toAppendToLine(); | ||
} | ||
return this._lineAppendor.render(fromParent); | ||
} | ||
str = this._buffer; | ||
this._buffer = ''; | ||
this._writeInline(str); | ||
}; | ||
Block.prototype._toPrependToLine = function() { | ||
var fromParent; | ||
fromParent = ''; | ||
if (this._parent != null) { | ||
fromParent = this._parent._toPrependToLine(); | ||
_whatToPrependToBlock() { | ||
return this._blockPrependor.render(); | ||
} | ||
return this._linePrependor.render(fromParent); | ||
}; | ||
Block.prototype._toAppendToLine = function() { | ||
var fromParent; | ||
fromParent = ''; | ||
if (this._parent != null) { | ||
fromParent = this._parent._toAppendToLine(); | ||
_whatToAppendToBlock() { | ||
return this._blockAppendor.render(); | ||
} | ||
return this._lineAppendor.render(fromParent); | ||
}; | ||
Block.prototype._whatToPrependToBlock = function() { | ||
return this._blockPrependor.render(); | ||
}; | ||
Block.prototype._whatToAppendToBlock = function() { | ||
return this._blockAppendor.render(); | ||
}; | ||
Block.prototype._writeInline = function(str) { | ||
var i, j, k, l, lineBreaksToAppend, m, ref, ref1, ref2, remaining; | ||
if (SpecialString(str).isOnlySpecialChars()) { | ||
this._layout._append(str); | ||
return; | ||
} | ||
remaining = str; | ||
lineBreaksToAppend = 0; | ||
if (m = remaining.match(/^\n+/)) { | ||
for (i = j = 1, ref = m[0].length; 1 <= ref ? j <= ref : j >= ref; i = 1 <= ref ? ++j : --j) { | ||
this._writeLine(''); | ||
_writeInline(str) { | ||
var i, j, k, l, lineBreaksToAppend, m, ref, ref1, ref2, remaining; | ||
// special characters (such as <bg-white>) don't require | ||
// any wrapping... | ||
if (new SpecialString(str).isOnlySpecialChars()) { | ||
// ... and directly get appended to the layout. | ||
this._layout._append(str); | ||
return; | ||
} | ||
remaining = remaining.substr(m[0].length, remaining.length); | ||
} | ||
if (m = remaining.match(/\n+$/)) { | ||
lineBreaksToAppend = m[0].length; | ||
remaining = remaining.substr(0, remaining.length - m[0].length); | ||
} | ||
while (remaining.length > 0) { | ||
if (m = remaining.match(/^[^\n]+/)) { | ||
this._writeLine(m[0]); | ||
remaining = remaining.substr(m[0].length, remaining.length); | ||
} else if (m = remaining.match(/^\n+/)) { | ||
for (i = k = 1, ref1 = m[0].length; 1 <= ref1 ? k < ref1 : k > ref1; i = 1 <= ref1 ? ++k : --k) { | ||
// we'll be removing from the original string till it's empty | ||
remaining = str; | ||
// we might need to add a few line breaks at the end of the text. | ||
lineBreaksToAppend = 0; | ||
// if text starts with line breaks... | ||
if (m = remaining.match(/^\n+/)) { | ||
// ... we want to write the exact same number of line breaks | ||
// to the layout. | ||
for (i = j = 1, ref = m[0].length; (1 <= ref ? j <= ref : j >= ref); i = 1 <= ref ? ++j : --j) { | ||
this._writeLine(''); | ||
@@ -226,27 +174,104 @@ } | ||
} | ||
// and if the text ends with line breaks... | ||
if (m = remaining.match(/\n+$/)) { | ||
// we want to write the exact same number of line breaks | ||
// to the end of the layout. | ||
lineBreaksToAppend = m[0].length; | ||
remaining = remaining.substr(0, remaining.length - m[0].length); | ||
} | ||
// now let's parse the body of the text: | ||
while (remaining.length > 0) { | ||
// anything other than a break line... | ||
if (m = remaining.match(/^[^\n]+/)) { | ||
// ... should be wrapped as a block of text. | ||
this._writeLine(m[0]); | ||
remaining = remaining.substr(m[0].length, remaining.length); | ||
// for any number of line breaks we find inside the text... | ||
} else if (m = remaining.match(/^\n+/)) { | ||
// ... we write one less break line to the layout. | ||
for (i = k = 1, ref1 = m[0].length; (1 <= ref1 ? k < ref1 : k > ref1); i = 1 <= ref1 ? ++k : --k) { | ||
this._writeLine(''); | ||
} | ||
remaining = remaining.substr(m[0].length, remaining.length); | ||
} | ||
} | ||
// if we had line breaks to append to the layout... | ||
if (lineBreaksToAppend > 0) { | ||
// ... we append the exact same number of line breaks to the layout. | ||
for (i = l = 1, ref2 = lineBreaksToAppend; (1 <= ref2 ? l <= ref2 : l >= ref2); i = 1 <= ref2 ? ++l : --l) { | ||
this._writeLine(''); | ||
} | ||
} | ||
} | ||
if (lineBreaksToAppend > 0) { | ||
for (i = l = 1, ref2 = lineBreaksToAppend; 1 <= ref2 ? l <= ref2 : l >= ref2; i = 1 <= ref2 ? ++l : --l) { | ||
this._writeLine(''); | ||
// wraps a line into multiple lines if necessary, adds horizontal margins, | ||
// etc, and appends it to the layout. | ||
_writeLine(str) { | ||
var line, lineContent, lineContentLength, remaining, roomLeft, toAppend, toAppendLength, toPrepend, toPrependLength; | ||
// we'll be cutting from our string as we go | ||
remaining = new SpecialString(str); | ||
while (true) { | ||
// left margin... | ||
// this will continue until nothing is left of our block. | ||
toPrepend = this._toPrependToLine(); | ||
// ... and its length | ||
toPrependLength = new SpecialString(toPrepend).length; | ||
// right margin... | ||
toAppend = this._toAppendToLine(); | ||
// ... and its length | ||
toAppendLength = new SpecialString(toAppend).length; | ||
// how much room is left for content | ||
roomLeft = this._layout._config.terminalWidth - (toPrependLength + toAppendLength); | ||
// how much room each line of content will have | ||
lineContentLength = Math.min(this._config.width, roomLeft); | ||
// cut line content, only for the amount needed | ||
lineContent = remaining.cut(0, lineContentLength, true); | ||
// line will consist of both margins and the content | ||
line = toPrepend + lineContent.str + toAppend; | ||
// send it off to layout | ||
this._layout._appendLine(line); | ||
if (remaining.isEmpty()) { | ||
break; | ||
} | ||
} | ||
} | ||
}; | ||
Block.prototype._writeLine = function(str) { | ||
var line, lineContent, lineContentLength, remaining, roomLeft, toAppend, toAppendLength, toPrepend, toPrependLength; | ||
remaining = SpecialString(str); | ||
while (true) { | ||
toPrepend = this._toPrependToLine(); | ||
toPrependLength = SpecialString(toPrepend).length; | ||
toAppend = this._toAppendToLine(); | ||
toAppendLength = SpecialString(toAppend).length; | ||
roomLeft = this._layout._config.terminalWidth - (toPrependLength + toAppendLength); | ||
lineContentLength = Math.min(this._config.width, roomLeft); | ||
lineContent = remaining.cut(0, lineContentLength, true); | ||
line = toPrepend + lineContent.str + toAppend; | ||
this._layout._appendLine(line); | ||
if (remaining.isEmpty()) { | ||
break; | ||
self = Block; | ||
Block.defaultConfig = { | ||
blockPrependor: { | ||
fn: require('./block/blockPrependor/Default'), | ||
options: { | ||
amount: 0 | ||
} | ||
} | ||
}, | ||
blockAppendor: { | ||
fn: require('./block/blockAppendor/Default'), | ||
options: { | ||
amount: 0 | ||
} | ||
}, | ||
linePrependor: { | ||
fn: require('./block/linePrependor/Default'), | ||
options: { | ||
amount: 0 | ||
} | ||
}, | ||
lineAppendor: { | ||
fn: require('./block/lineAppendor/Default'), | ||
options: { | ||
amount: 0 | ||
} | ||
}, | ||
lineWrapper: { | ||
fn: require('./block/lineWrapper/Default'), | ||
options: { | ||
lineWidth: null | ||
} | ||
}, | ||
width: terminalWidth, | ||
prefixRaw: '', | ||
suffixRaw: '' | ||
}; | ||
@@ -256,2 +281,2 @@ | ||
})(); | ||
}).call(this); |
@@ -1,15 +0,13 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var _BlockAppendor; | ||
module.exports = _BlockAppendor = (function() { | ||
function _BlockAppendor(_config) { | ||
module.exports = _BlockAppendor = class _BlockAppendor { | ||
constructor(_config) { | ||
this._config = _config; | ||
} | ||
_BlockAppendor.prototype.render = function(options) { | ||
render(options) { | ||
return this._render(options); | ||
}; | ||
} | ||
return _BlockAppendor; | ||
})(); | ||
}; |
@@ -1,21 +0,11 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var DefaultBlockAppendor, tools, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var DefaultBlockAppendor, tools; | ||
tools = require('../../../tools'); | ||
module.exports = DefaultBlockAppendor = (function(superClass) { | ||
extend(DefaultBlockAppendor, superClass); | ||
function DefaultBlockAppendor() { | ||
return DefaultBlockAppendor.__super__.constructor.apply(this, arguments); | ||
module.exports = DefaultBlockAppendor = class DefaultBlockAppendor extends require('./_BlockAppendor') { | ||
_render(options) { | ||
return tools.repeatString("\n", this._config.amount); | ||
} | ||
DefaultBlockAppendor.prototype._render = function(options) { | ||
return tools.repeatString("\n", this._config.amount); | ||
}; | ||
return DefaultBlockAppendor; | ||
})(require('./_BlockAppendor')); | ||
}; |
@@ -1,15 +0,13 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var _BlockPrependor; | ||
module.exports = _BlockPrependor = (function() { | ||
function _BlockPrependor(_config) { | ||
module.exports = _BlockPrependor = class _BlockPrependor { | ||
constructor(_config) { | ||
this._config = _config; | ||
} | ||
_BlockPrependor.prototype.render = function(options) { | ||
render(options) { | ||
return this._render(options); | ||
}; | ||
} | ||
return _BlockPrependor; | ||
})(); | ||
}; |
@@ -1,21 +0,11 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var DefaultBlockPrependor, tools, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var DefaultBlockPrependor, tools; | ||
tools = require('../../../tools'); | ||
module.exports = DefaultBlockPrependor = (function(superClass) { | ||
extend(DefaultBlockPrependor, superClass); | ||
function DefaultBlockPrependor() { | ||
return DefaultBlockPrependor.__super__.constructor.apply(this, arguments); | ||
module.exports = DefaultBlockPrependor = class DefaultBlockPrependor extends require('./_BlockPrependor') { | ||
_render(options) { | ||
return tools.repeatString("\n", this._config.amount); | ||
} | ||
DefaultBlockPrependor.prototype._render = function(options) { | ||
return tools.repeatString("\n", this._config.amount); | ||
}; | ||
return DefaultBlockPrependor; | ||
})(require('./_BlockPrependor')); | ||
}; |
@@ -1,6 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var _LineAppendor; | ||
module.exports = _LineAppendor = (function() { | ||
function _LineAppendor(_config) { | ||
module.exports = _LineAppendor = class _LineAppendor { | ||
constructor(_config) { | ||
this._config = _config; | ||
@@ -10,9 +10,7 @@ this._lineNo = 0; | ||
_LineAppendor.prototype.render = function(inherited, options) { | ||
render(inherited, options) { | ||
this._lineNo++; | ||
return '<none>' + this._render(inherited, options) + '</none>'; | ||
}; | ||
} | ||
return _LineAppendor; | ||
})(); | ||
}; |
@@ -1,21 +0,11 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var DefaultLineAppendor, tools, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var DefaultLineAppendor, tools; | ||
tools = require('../../../tools'); | ||
module.exports = DefaultLineAppendor = (function(superClass) { | ||
extend(DefaultLineAppendor, superClass); | ||
function DefaultLineAppendor() { | ||
return DefaultLineAppendor.__super__.constructor.apply(this, arguments); | ||
module.exports = DefaultLineAppendor = class DefaultLineAppendor extends require('./_LineAppendor') { | ||
_render(inherited, options) { | ||
return inherited + tools.repeatString(" ", this._config.amount); | ||
} | ||
DefaultLineAppendor.prototype._render = function(inherited, options) { | ||
return inherited + tools.repeatString(" ", this._config.amount); | ||
}; | ||
return DefaultLineAppendor; | ||
})(require('./_LineAppendor')); | ||
}; |
@@ -1,6 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var _LinePrependor; | ||
module.exports = _LinePrependor = (function() { | ||
function _LinePrependor(_config) { | ||
module.exports = _LinePrependor = class _LinePrependor { | ||
constructor(_config) { | ||
this._config = _config; | ||
@@ -10,9 +10,7 @@ this._lineNo = -1; | ||
_LinePrependor.prototype.render = function(inherited, options) { | ||
render(inherited, options) { | ||
this._lineNo++; | ||
return '<none>' + this._render(inherited, options) + '</none>'; | ||
}; | ||
} | ||
return _LinePrependor; | ||
})(); | ||
}; |
@@ -1,5 +0,3 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var DefaultLinePrependor, SpecialString, tools, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var DefaultLinePrependor, SpecialString, tools; | ||
@@ -10,50 +8,47 @@ tools = require('../../../tools'); | ||
module.exports = DefaultLinePrependor = (function(superClass) { | ||
module.exports = DefaultLinePrependor = (function() { | ||
var self; | ||
extend(DefaultLinePrependor, superClass); | ||
class DefaultLinePrependor extends require('./_LinePrependor') { | ||
static pad(howMuch) { | ||
return tools.repeatString(" ", howMuch); | ||
} | ||
function DefaultLinePrependor() { | ||
return DefaultLinePrependor.__super__.constructor.apply(this, arguments); | ||
} | ||
self = DefaultLinePrependor; | ||
DefaultLinePrependor.pad = function(howMuch) { | ||
return tools.repeatString(" ", howMuch); | ||
}; | ||
DefaultLinePrependor.prototype._render = function(inherited, options) { | ||
var addToLeft, addToRight, alignment, bullet, char, charLen, diff, left, output, space, toWrite; | ||
if (this._lineNo === 0 && (bullet = this._config.bullet)) { | ||
char = bullet.char; | ||
charLen = SpecialString(char).length; | ||
alignment = bullet.alignment; | ||
space = this._config.amount; | ||
toWrite = char; | ||
addToLeft = ''; | ||
addToRight = ''; | ||
if (space > charLen) { | ||
diff = space - charLen; | ||
if (alignment === 'right') { | ||
addToLeft = self.pad(diff); | ||
} else if (alignment === 'left') { | ||
addToRight = self.pad(diff); | ||
} else if (alignment === 'center') { | ||
left = Math.round(diff / 2); | ||
addToLeft = self.pad(left); | ||
addToRight = self.pad(diff - left); | ||
} else { | ||
throw Error("Unknown alignment `" + alignment + "`"); | ||
_render(inherited, options) { | ||
var addToLeft, addToRight, alignment, bullet, char, charLen, diff, left, output, space, toWrite; | ||
if (this._lineNo === 0 && (bullet = this._config.bullet)) { | ||
char = bullet.char; | ||
charLen = new SpecialString(char).length; | ||
alignment = bullet.alignment; | ||
space = this._config.amount; | ||
toWrite = char; | ||
addToLeft = ''; | ||
addToRight = ''; | ||
if (space > charLen) { | ||
diff = space - charLen; | ||
if (alignment === 'right') { | ||
addToLeft = self.pad(diff); | ||
} else if (alignment === 'left') { | ||
addToRight = self.pad(diff); | ||
} else if (alignment === 'center') { | ||
left = Math.round(diff / 2); | ||
addToLeft = self.pad(left); | ||
addToRight = self.pad(diff - left); | ||
} else { | ||
throw Error(`Unknown alignment \`${alignment}\``); | ||
} | ||
} | ||
output = addToLeft + char + addToRight; | ||
} else { | ||
output = self.pad(this._config.amount); | ||
} | ||
output = addToLeft + char + addToRight; | ||
} else { | ||
output = self.pad(this._config.amount); | ||
return inherited + output; | ||
} | ||
return inherited + output; | ||
}; | ||
self = DefaultLinePrependor; | ||
return DefaultLinePrependor; | ||
})(require('./_LinePrependor')); | ||
}).call(this); |
@@ -1,13 +0,11 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var _LineWrapper; | ||
module.exports = _LineWrapper = (function() { | ||
function _LineWrapper() {} | ||
module.exports = _LineWrapper = class _LineWrapper { | ||
constructor() {} | ||
_LineWrapper.prototype.render = function(str, options) { | ||
render(str, options) { | ||
return this._render(str, options); | ||
}; | ||
} | ||
return _LineWrapper; | ||
})(); | ||
}; |
@@ -1,17 +0,7 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var DefaultLineWrapper, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var DefaultLineWrapper; | ||
module.exports = DefaultLineWrapper = (function(superClass) { | ||
extend(DefaultLineWrapper, superClass); | ||
module.exports = DefaultLineWrapper = class DefaultLineWrapper extends require('./_LineWrapper') { | ||
_render() {} | ||
function DefaultLineWrapper() { | ||
return DefaultLineWrapper.__super__.constructor.apply(this, arguments); | ||
} | ||
DefaultLineWrapper.prototype._render = function() {}; | ||
return DefaultLineWrapper; | ||
})(require('./_LineWrapper')); | ||
}; |
@@ -1,3 +0,3 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var SpecialString, fn, i, len, prop, ref; | ||
// Generated by CoffeeScript 2.5.1 | ||
var SpecialString, i, len, prop, ref; | ||
@@ -7,112 +7,98 @@ module.exports = SpecialString = (function() { | ||
self = SpecialString; | ||
class SpecialString { | ||
constructor(str) { | ||
if (!(this instanceof self)) { | ||
return new self(str); | ||
} | ||
this._str = String(str); | ||
this._len = 0; | ||
} | ||
SpecialString._tabRx = /^\t/; | ||
_getStr() { | ||
return this._str; | ||
} | ||
SpecialString._tagRx = /^<[^>]+>/; | ||
set(str) { | ||
this._str = String(str); | ||
return this; | ||
} | ||
SpecialString._quotedHtmlRx = /^&(gt|lt|quot|amp|apos|sp);/; | ||
clone() { | ||
return new SpecialString(this._str); | ||
} | ||
function SpecialString(str) { | ||
if (!(this instanceof self)) { | ||
return new self(str); | ||
isEmpty() { | ||
return this._str === ''; | ||
} | ||
this._str = String(str); | ||
this._len = 0; | ||
} | ||
SpecialString.prototype._getStr = function() { | ||
return this._str; | ||
}; | ||
isOnlySpecialChars() { | ||
return !this.isEmpty() && this.length === 0; | ||
} | ||
SpecialString.prototype.set = function(str) { | ||
this._str = String(str); | ||
return this; | ||
}; | ||
_reset() { | ||
return this._len = 0; | ||
} | ||
SpecialString.prototype.clone = function() { | ||
return new SpecialString(this._str); | ||
}; | ||
SpecialString.prototype.isEmpty = function() { | ||
return this._str === ''; | ||
}; | ||
SpecialString.prototype.isOnlySpecialChars = function() { | ||
return !this.isEmpty() && this.length === 0; | ||
}; | ||
SpecialString.prototype._reset = function() { | ||
return this._len = 0; | ||
}; | ||
SpecialString.prototype.splitIn = function(limit, trimLeftEachLine) { | ||
var buffer, bufferLength, justSkippedSkipChar, lines; | ||
if (trimLeftEachLine == null) { | ||
trimLeftEachLine = false; | ||
} | ||
buffer = ''; | ||
bufferLength = 0; | ||
lines = []; | ||
justSkippedSkipChar = false; | ||
self._countChars(this._str, function(char, charLength) { | ||
if (bufferLength > limit || bufferLength + charLength > limit) { | ||
splitIn(limit, trimLeftEachLine = false) { | ||
var buffer, bufferLength, justSkippedSkipChar, lines; | ||
buffer = ''; | ||
bufferLength = 0; | ||
lines = []; | ||
justSkippedSkipChar = false; | ||
self._countChars(this._str, function(char, charLength) { | ||
if (bufferLength > limit || bufferLength + charLength > limit) { | ||
lines.push(buffer); | ||
buffer = ''; | ||
bufferLength = 0; | ||
} | ||
if (bufferLength === 0 && char === ' ' && !justSkippedSkipChar && trimLeftEachLine) { | ||
return justSkippedSkipChar = true; | ||
} else { | ||
buffer += char; | ||
bufferLength += charLength; | ||
return justSkippedSkipChar = false; | ||
} | ||
}); | ||
if (buffer.length > 0) { | ||
lines.push(buffer); | ||
buffer = ''; | ||
bufferLength = 0; | ||
} | ||
if (bufferLength === 0 && char === ' ' && !justSkippedSkipChar && trimLeftEachLine) { | ||
return justSkippedSkipChar = true; | ||
} else { | ||
buffer += char; | ||
bufferLength += charLength; | ||
return justSkippedSkipChar = false; | ||
} | ||
}); | ||
if (buffer.length > 0) { | ||
lines.push(buffer); | ||
return lines; | ||
} | ||
return lines; | ||
}; | ||
SpecialString.prototype.trim = function() { | ||
return new SpecialString(this.str.trim()); | ||
}; | ||
trim() { | ||
return new SpecialString(this.str.trim()); | ||
} | ||
SpecialString.prototype.trimLeft = function() { | ||
return new SpecialString(this.str.replace(/^\s+/, '')); | ||
}; | ||
trimLeft() { | ||
return new SpecialString(this.str.replace(/^\s+/, '')); | ||
} | ||
SpecialString.prototype.trimRight = function() { | ||
return new SpecialString(this.str.replace(/\s+$/, '')); | ||
}; | ||
trimRight() { | ||
return new SpecialString(this.str.replace(/\s+$/, '')); | ||
} | ||
SpecialString.prototype._getLength = function() { | ||
var sum; | ||
sum = 0; | ||
self._countChars(this._str, function(char, charLength) { | ||
sum += charLength; | ||
}); | ||
return sum; | ||
}; | ||
_getLength() { | ||
var sum; | ||
sum = 0; | ||
self._countChars(this._str, function(char, charLength) { | ||
sum += charLength; | ||
}); | ||
return sum; | ||
} | ||
SpecialString.prototype.cut = function(from, to, trimLeft) { | ||
var after, before, cur, cut; | ||
if (trimLeft == null) { | ||
trimLeft = false; | ||
} | ||
if (to == null) { | ||
to = this.length; | ||
} | ||
from = parseInt(from); | ||
if (from >= to) { | ||
throw Error("`from` shouldn't be larger than `to`"); | ||
} | ||
before = ''; | ||
after = ''; | ||
cut = ''; | ||
cur = 0; | ||
self._countChars(this._str, (function(_this) { | ||
return function(char, charLength) { | ||
if (_this.str === 'ab<tag>') { | ||
cut(from, to, trimLeft = false) { | ||
var after, before, cur, cut; | ||
if (to == null) { | ||
to = this.length; | ||
} | ||
from = parseInt(from); | ||
if (from >= to) { | ||
throw Error("`from` shouldn't be larger than `to`"); | ||
} | ||
before = ''; | ||
after = ''; | ||
cut = ''; | ||
cur = 0; | ||
self._countChars(this._str, (char, charLength) => { | ||
if (this.str === 'ab<tag>') { | ||
console.log(charLength, char); | ||
@@ -125,2 +111,3 @@ } | ||
before += char; | ||
// let's be greedy | ||
} else if (cur < to || cur + charLength <= to) { | ||
@@ -132,48 +119,56 @@ cut += char; | ||
cur += charLength; | ||
}; | ||
})(this)); | ||
this._str = before + after; | ||
this._reset(); | ||
return SpecialString(cut); | ||
}; | ||
}); | ||
this._str = before + after; | ||
this._reset(); | ||
return new SpecialString(cut); | ||
} | ||
SpecialString._countChars = function(text, cb) { | ||
var char, charLength, m; | ||
while (text.length !== 0) { | ||
if (m = text.match(self._tagRx)) { | ||
char = m[0]; | ||
charLength = 0; | ||
text = text.substr(char.length, text.length); | ||
} else if (m = text.match(self._quotedHtmlRx)) { | ||
char = m[0]; | ||
charLength = 1; | ||
text = text.substr(char.length, text.length); | ||
} else if (text.match(self._tabRx)) { | ||
char = "\t"; | ||
charLength = 8; | ||
text = text.substr(1, text.length); | ||
} else { | ||
char = text[0]; | ||
charLength = 1; | ||
text = text.substr(1, text.length); | ||
static _countChars(text, cb) { | ||
var char, charLength, m; | ||
while (text.length !== 0) { | ||
if (m = text.match(self._tagRx)) { | ||
char = m[0]; | ||
charLength = 0; | ||
text = text.substr(char.length, text.length); | ||
} else if (m = text.match(self._quotedHtmlRx)) { | ||
char = m[0]; | ||
charLength = 1; | ||
text = text.substr(char.length, text.length); | ||
} else if (text.match(self._tabRx)) { | ||
char = "\t"; | ||
charLength = 8; | ||
text = text.substr(1, text.length); | ||
} else { | ||
char = text[0]; | ||
charLength = 1; | ||
text = text.substr(1, text.length); | ||
} | ||
cb.call(null, char, charLength); | ||
} | ||
cb.call(null, char, charLength); | ||
} | ||
}; | ||
self = SpecialString; | ||
SpecialString._tabRx = /^\t/; | ||
SpecialString._tagRx = /^<[^>]+>/; | ||
SpecialString._quotedHtmlRx = /^&(gt|lt|quot|amp|apos|sp);/; | ||
return SpecialString; | ||
})(); | ||
}).call(this); | ||
ref = ['str', 'length']; | ||
fn = function() { | ||
var methodName; | ||
methodName = '_get' + prop[0].toUpperCase() + prop.substr(1, prop.length); | ||
return SpecialString.prototype.__defineGetter__(prop, function() { | ||
return this[methodName](); | ||
}); | ||
}; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
prop = ref[i]; | ||
fn(); | ||
(function() { | ||
var methodName; | ||
methodName = '_get' + prop[0].toUpperCase() + prop.substr(1, prop.length); | ||
return SpecialString.prototype.__defineGetter__(prop, function() { | ||
return this[methodName](); | ||
}); | ||
})(); | ||
} |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var AnsiPainter, Layout, RenderKid, Styles, blockStyleApplier, cloneAndMergeDeep, inlineStyleApplier, isPlainObject, stripAnsi, terminalWidth, tools; | ||
@@ -10,3 +10,3 @@ | ||
cloneAndMergeDeep = require('./tools').cloneAndMergeDeep; | ||
({cloneAndMergeDeep} = require('./tools')); | ||
@@ -28,170 +28,162 @@ AnsiPainter = require('./AnsiPainter'); | ||
self = RenderKid; | ||
class RenderKid { | ||
constructor(config = {}) { | ||
this.tools = self.tools; | ||
this._config = cloneAndMergeDeep(self._defaultConfig, config); | ||
this._initStyles(); | ||
} | ||
RenderKid.AnsiPainter = AnsiPainter; | ||
_initStyles() { | ||
return this._styles = new Styles(); | ||
} | ||
RenderKid.Layout = Layout; | ||
style() { | ||
return this._styles.setRule.apply(this._styles, arguments); | ||
} | ||
RenderKid.quote = tools.quote; | ||
_getStyleFor(el) { | ||
return this._styles.getStyleFor(el); | ||
} | ||
RenderKid.tools = tools; | ||
render(input, withColors = true) { | ||
return this._paint(this._renderDom(this._toDom(input)), withColors); | ||
} | ||
RenderKid._defaultConfig = { | ||
layout: { | ||
terminalWidth: terminalWidth | ||
_toDom(input) { | ||
if (typeof input === 'string') { | ||
return this._parse(input); | ||
} else if (isPlainObject(input) || Array.isArray(input)) { | ||
return this._objToDom(input); | ||
} else { | ||
throw Error("Invalid input type. Only strings, arrays and objects are accepted"); | ||
} | ||
} | ||
}; | ||
function RenderKid(config) { | ||
if (config == null) { | ||
config = {}; | ||
_objToDom(o, injectFakeRoot = true) { | ||
if (injectFakeRoot) { | ||
o = { | ||
body: o | ||
}; | ||
} | ||
return tools.objectToDom(o); | ||
} | ||
this.tools = self.tools; | ||
this._config = cloneAndMergeDeep(self._defaultConfig, config); | ||
this._initStyles(); | ||
} | ||
RenderKid.prototype._initStyles = function() { | ||
return this._styles = new Styles; | ||
}; | ||
_paint(text, withColors) { | ||
var painted; | ||
painted = AnsiPainter.paint(text); | ||
if (withColors) { | ||
return painted; | ||
} else { | ||
return stripAnsi(painted); | ||
} | ||
} | ||
RenderKid.prototype.style = function() { | ||
return this._styles.setRule.apply(this._styles, arguments); | ||
}; | ||
RenderKid.prototype._getStyleFor = function(el) { | ||
return this._styles.getStyleFor(el); | ||
}; | ||
RenderKid.prototype.render = function(input, withColors) { | ||
if (withColors == null) { | ||
withColors = true; | ||
_parse(string, injectFakeRoot = true) { | ||
if (injectFakeRoot) { | ||
string = '<body>' + string + '</body>'; | ||
} | ||
return tools.stringToDom(string); | ||
} | ||
return this._paint(this._renderDom(this._toDom(input)), withColors); | ||
}; | ||
RenderKid.prototype._toDom = function(input) { | ||
if (typeof input === 'string') { | ||
return this._parse(input); | ||
} else if (isPlainObject(input) || Array.isArray(input)) { | ||
return this._objToDom(input); | ||
} else { | ||
throw Error("Invalid input type. Only strings, arrays and objects are accepted"); | ||
_renderDom(dom) { | ||
var bodyTag, layout, rootBlock; | ||
bodyTag = dom[0]; | ||
layout = new Layout(this._config.layout); | ||
rootBlock = layout.getRootBlock(); | ||
this._renderBlockNode(bodyTag, null, rootBlock); | ||
return layout.get(); | ||
} | ||
}; | ||
RenderKid.prototype._objToDom = function(o, injectFakeRoot) { | ||
if (injectFakeRoot == null) { | ||
injectFakeRoot = true; | ||
_renderChildrenOf(parentNode, parentBlock) { | ||
var i, len, node, nodes; | ||
nodes = parentNode.children; | ||
for (i = 0, len = nodes.length; i < len; i++) { | ||
node = nodes[i]; | ||
this._renderNode(node, parentNode, parentBlock); | ||
} | ||
} | ||
if (injectFakeRoot) { | ||
o = { | ||
body: o | ||
}; | ||
} | ||
return tools.objectToDom(o); | ||
}; | ||
RenderKid.prototype._paint = function(text, withColors) { | ||
var painted; | ||
painted = AnsiPainter.paint(text); | ||
if (withColors) { | ||
return painted; | ||
} else { | ||
return stripAnsi(painted); | ||
_renderNode(node, parentNode, parentBlock) { | ||
if (node.type === 'text') { | ||
this._renderText(node, parentNode, parentBlock); | ||
} else if (node.name === 'br') { | ||
this._renderBr(node, parentNode, parentBlock); | ||
} else if (this._isBlock(node)) { | ||
this._renderBlockNode(node, parentNode, parentBlock); | ||
} else if (this._isNone(node)) { | ||
return; | ||
} else { | ||
this._renderInlineNode(node, parentNode, parentBlock); | ||
} | ||
} | ||
}; | ||
RenderKid.prototype._parse = function(string, injectFakeRoot) { | ||
if (injectFakeRoot == null) { | ||
injectFakeRoot = true; | ||
_renderText(node, parentNode, parentBlock) { | ||
var ref, text; | ||
text = node.data; | ||
text = text.replace(/\s+/g, ' '); | ||
// let's only trim if the parent is an inline element | ||
if ((parentNode != null ? (ref = parentNode.styles) != null ? ref.display : void 0 : void 0) !== 'inline') { | ||
text = text.trim(); | ||
} | ||
if (text.length === 0) { | ||
return; | ||
} | ||
text = text.replace(/&nl;/g, "\n"); | ||
return parentBlock.write(text); | ||
} | ||
if (injectFakeRoot) { | ||
string = '<body>' + string + '</body>'; | ||
} | ||
return tools.stringToDom(string); | ||
}; | ||
RenderKid.prototype._renderDom = function(dom) { | ||
var bodyTag, layout, rootBlock; | ||
bodyTag = dom[0]; | ||
layout = new Layout(this._config.layout); | ||
rootBlock = layout.getRootBlock(); | ||
this._renderBlockNode(bodyTag, null, rootBlock); | ||
return layout.get(); | ||
}; | ||
RenderKid.prototype._renderChildrenOf = function(parentNode, parentBlock) { | ||
var i, len, node, nodes; | ||
nodes = parentNode.children; | ||
for (i = 0, len = nodes.length; i < len; i++) { | ||
node = nodes[i]; | ||
this._renderNode(node, parentNode, parentBlock); | ||
_renderBlockNode(node, parentNode, parentBlock) { | ||
var after, before, block, blockConfig; | ||
({before, after, blockConfig} = blockStyleApplier.applyTo(node, this._getStyleFor(node))); | ||
block = parentBlock.openBlock(blockConfig); | ||
if (before !== '') { | ||
block.write(before); | ||
} | ||
this._renderChildrenOf(node, block); | ||
if (after !== '') { | ||
block.write(after); | ||
} | ||
return block.close(); | ||
} | ||
}; | ||
RenderKid.prototype._renderNode = function(node, parentNode, parentBlock) { | ||
if (node.type === 'text') { | ||
this._renderText(node, parentNode, parentBlock); | ||
} else if (node.name === 'br') { | ||
this._renderBr(node, parentNode, parentBlock); | ||
} else if (this._isBlock(node)) { | ||
this._renderBlockNode(node, parentNode, parentBlock); | ||
} else if (this._isNone(node)) { | ||
return; | ||
} else { | ||
this._renderInlineNode(node, parentNode, parentBlock); | ||
_renderInlineNode(node, parentNode, parentBlock) { | ||
var after, before; | ||
({before, after} = inlineStyleApplier.applyTo(node, this._getStyleFor(node))); | ||
if (before !== '') { | ||
parentBlock.write(before); | ||
} | ||
this._renderChildrenOf(node, parentBlock); | ||
if (after !== '') { | ||
return parentBlock.write(after); | ||
} | ||
} | ||
}; | ||
RenderKid.prototype._renderText = function(node, parentNode, parentBlock) { | ||
var ref, text; | ||
text = node.data; | ||
text = text.replace(/\s+/g, ' '); | ||
if ((parentNode != null ? (ref = parentNode.styles) != null ? ref.display : void 0 : void 0) !== 'inline') { | ||
text = text.trim(); | ||
_renderBr(node, parentNode, parentBlock) { | ||
return parentBlock.write("\n"); | ||
} | ||
if (text.length === 0) { | ||
return; | ||
} | ||
text = text.replace(/&nl;/g, "\n"); | ||
return parentBlock.write(text); | ||
}; | ||
RenderKid.prototype._renderBlockNode = function(node, parentNode, parentBlock) { | ||
var after, before, block, blockConfig, ref; | ||
ref = blockStyleApplier.applyTo(node, this._getStyleFor(node)), before = ref.before, after = ref.after, blockConfig = ref.blockConfig; | ||
block = parentBlock.openBlock(blockConfig); | ||
if (before !== '') { | ||
block.write(before); | ||
_isBlock(node) { | ||
return !(node.type === 'text' || node.name === 'br' || this._getStyleFor(node).display !== 'block'); | ||
} | ||
this._renderChildrenOf(node, block); | ||
if (after !== '') { | ||
block.write(after); | ||
} | ||
return block.close(); | ||
}; | ||
RenderKid.prototype._renderInlineNode = function(node, parentNode, parentBlock) { | ||
var after, before, ref; | ||
ref = inlineStyleApplier.applyTo(node, this._getStyleFor(node)), before = ref.before, after = ref.after; | ||
if (before !== '') { | ||
parentBlock.write(before); | ||
_isNone(node) { | ||
return !(node.type === 'text' || node.name === 'br' || this._getStyleFor(node).display !== 'none'); | ||
} | ||
this._renderChildrenOf(node, parentBlock); | ||
if (after !== '') { | ||
return parentBlock.write(after); | ||
} | ||
}; | ||
RenderKid.prototype._renderBr = function(node, parentNode, parentBlock) { | ||
return parentBlock.write("\n"); | ||
}; | ||
RenderKid.prototype._isBlock = function(node) { | ||
return !(node.type === 'text' || node.name === 'br' || this._getStyleFor(node).display !== 'block'); | ||
}; | ||
self = RenderKid; | ||
RenderKid.prototype._isNone = function(node) { | ||
return !(node.type === 'text' || node.name === 'br' || this._getStyleFor(node).display !== 'none'); | ||
RenderKid.AnsiPainter = AnsiPainter; | ||
RenderKid.Layout = Layout; | ||
RenderKid.quote = tools.quote; | ||
RenderKid.tools = tools; | ||
RenderKid._defaultConfig = { | ||
layout: { | ||
terminalWidth: terminalWidth | ||
} | ||
}; | ||
@@ -201,2 +193,2 @@ | ||
})(); | ||
}).call(this); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var AnsiPainter, _common; | ||
@@ -13,3 +13,3 @@ | ||
if (AnsiPainter.tags[tagName] == null) { | ||
throw Error("Unknown color `" + style.color + "`"); | ||
throw Error(`Unknown color \`${style.color}\``); | ||
} | ||
@@ -21,3 +21,3 @@ tagsToAdd.push(tagName); | ||
if (AnsiPainter.tags[tagName] == null) { | ||
throw Error("Unknown background `" + style.background + "`"); | ||
throw Error(`Unknown background \`${style.background}\``); | ||
} | ||
@@ -32,4 +32,4 @@ tagsToAdd.push(tagName); | ||
tag = tagsToAdd[i]; | ||
ret.before = ("<" + tag + ">") + ret.before; | ||
ret.after = ret.after + ("</" + tag + ">"); | ||
ret.before = `<${tag}>` + ret.before; | ||
ret.after = ret.after + `</${tag}>`; | ||
} | ||
@@ -36,0 +36,0 @@ return ret; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var _common, blockStyleApplier, merge, self; | ||
@@ -57,3 +57,3 @@ | ||
_bullet: function(style, config) { | ||
var after, before, bullet, conf, ref; | ||
var after, before, bullet, conf; | ||
if ((style.bullet != null) && style.bullet.enabled) { | ||
@@ -63,6 +63,6 @@ bullet = style.bullet; | ||
conf.alignment = style.bullet.alignment; | ||
ref = _common.getStyleTagsFor({ | ||
({before, after} = _common.getStyleTagsFor({ | ||
color: bullet.color, | ||
background: bullet.background | ||
}), before = ref.before, after = ref.after; | ||
})); | ||
conf.char = before + bullet.char + after; | ||
@@ -69,0 +69,0 @@ merge(config, { |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var _common, inlineStyleApplier, self, tools; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var MixedDeclarationSet, StyleSheet, Styles, terminalWidth; | ||
@@ -13,2 +13,52 @@ | ||
class Styles { | ||
constructor() { | ||
this._defaultStyles = new StyleSheet(); | ||
this._userStyles = new StyleSheet(); | ||
this._setDefaultStyles(); | ||
} | ||
_setDefaultStyles() { | ||
this._defaultStyles.setRule(self.defaultRules); | ||
} | ||
setRule(selector, rules) { | ||
this._userStyles.setRule.apply(this._userStyles, arguments); | ||
return this; | ||
} | ||
getStyleFor(el) { | ||
var styles; | ||
styles = el.styles; | ||
if (styles == null) { | ||
el.styles = styles = this._getComputedStyleFor(el); | ||
} | ||
return styles; | ||
} | ||
_getRawStyleFor(el) { | ||
var def, user; | ||
def = this._defaultStyles.getRulesFor(el); | ||
user = this._userStyles.getRulesFor(el); | ||
return MixedDeclarationSet.mix(def, user).toObject(); | ||
} | ||
_getComputedStyleFor(el) { | ||
var decs, parent, prop, ref, val; | ||
decs = {}; | ||
parent = el.parent; | ||
ref = this._getRawStyleFor(el); | ||
for (prop in ref) { | ||
val = ref[prop]; | ||
if (val !== 'inherit') { | ||
decs[prop] = val; | ||
} else { | ||
throw Error("Inherited styles are not supported yet."); | ||
} | ||
} | ||
return decs; | ||
} | ||
}; | ||
self = Styles; | ||
@@ -28,51 +78,4 @@ | ||
function Styles() { | ||
this._defaultStyles = new StyleSheet; | ||
this._userStyles = new StyleSheet; | ||
this._setDefaultStyles(); | ||
} | ||
Styles.prototype._setDefaultStyles = function() { | ||
this._defaultStyles.setRule(self.defaultRules); | ||
}; | ||
Styles.prototype.setRule = function(selector, rules) { | ||
this._userStyles.setRule.apply(this._userStyles, arguments); | ||
return this; | ||
}; | ||
Styles.prototype.getStyleFor = function(el) { | ||
var styles; | ||
styles = el.styles; | ||
if (styles == null) { | ||
el.styles = styles = this._getComputedStyleFor(el); | ||
} | ||
return styles; | ||
}; | ||
Styles.prototype._getRawStyleFor = function(el) { | ||
var def, user; | ||
def = this._defaultStyles.getRulesFor(el); | ||
user = this._userStyles.getRulesFor(el); | ||
return MixedDeclarationSet.mix(def, user).toObject(); | ||
}; | ||
Styles.prototype._getComputedStyleFor = function(el) { | ||
var decs, parent, prop, ref, val; | ||
decs = {}; | ||
parent = el.parent; | ||
ref = this._getRawStyleFor(el); | ||
for (prop in ref) { | ||
val = ref[prop]; | ||
if (val !== 'inherit') { | ||
decs[prop] = val; | ||
} else { | ||
throw Error("Inherited styles are not supported yet."); | ||
} | ||
} | ||
return decs; | ||
}; | ||
return Styles; | ||
})(); | ||
}).call(this); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var DeclarationBlock, Rule, Selector; | ||
@@ -8,15 +8,13 @@ | ||
module.exports = Rule = (function() { | ||
function Rule(selector) { | ||
module.exports = Rule = class Rule { | ||
constructor(selector) { | ||
this.selector = new Selector(selector); | ||
this.styles = new DeclarationBlock; | ||
this.styles = new DeclarationBlock(); | ||
} | ||
Rule.prototype.setStyles = function(styles) { | ||
setStyles(styles) { | ||
this.styles.set(styles); | ||
return this; | ||
}; | ||
} | ||
return Rule; | ||
})(); | ||
}; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var Arbitrary, DeclarationBlock, declarationClasses; | ||
@@ -7,40 +7,43 @@ | ||
self = DeclarationBlock; | ||
class DeclarationBlock { | ||
constructor() { | ||
this._declarations = {}; | ||
} | ||
function DeclarationBlock() { | ||
this._declarations = {}; | ||
} | ||
DeclarationBlock.prototype.set = function(prop, value) { | ||
var key, val; | ||
if (typeof prop === 'object') { | ||
for (key in prop) { | ||
val = prop[key]; | ||
this.set(key, val); | ||
set(prop, value) { | ||
var key, val; | ||
if (typeof prop === 'object') { | ||
for (key in prop) { | ||
val = prop[key]; | ||
this.set(key, val); | ||
} | ||
return this; | ||
} | ||
prop = self.sanitizeProp(prop); | ||
this._getDeclarationClass(prop).setOnto(this._declarations, prop, value); | ||
return this; | ||
} | ||
prop = self.sanitizeProp(prop); | ||
this._getDeclarationClass(prop).setOnto(this._declarations, prop, value); | ||
return this; | ||
}; | ||
DeclarationBlock.prototype._getDeclarationClass = function(prop) { | ||
var cls; | ||
if (prop[0] === '_') { | ||
return Arbitrary; | ||
_getDeclarationClass(prop) { | ||
var cls; | ||
if (prop[0] === '_') { | ||
return Arbitrary; | ||
} | ||
if (!(cls = declarationClasses[prop])) { | ||
throw Error(`Unknown property \`${prop}\`. Write it as \`_${prop}\` if you're defining a custom property`); | ||
} | ||
return cls; | ||
} | ||
if (!(cls = declarationClasses[prop])) { | ||
throw Error("Unknown property `" + prop + "`. Write it as `_" + prop + "` if you're defining a custom property"); | ||
static sanitizeProp(prop) { | ||
return String(prop).trim(); | ||
} | ||
return cls; | ||
}; | ||
DeclarationBlock.sanitizeProp = function(prop) { | ||
return String(prop).trim(); | ||
}; | ||
self = DeclarationBlock; | ||
return DeclarationBlock; | ||
})(); | ||
}).call(this); | ||
@@ -47,0 +50,0 @@ Arbitrary = require('./declarationBlock/Arbitrary'); |
@@ -1,2 +0,3 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
// Abstract Style Declaration | ||
var _Declaration; | ||
@@ -7,79 +8,82 @@ | ||
self = _Declaration; | ||
class _Declaration { | ||
static setOnto(declarations, prop, val) { | ||
var dec; | ||
if (!(dec = declarations[prop])) { | ||
return declarations[prop] = new this(prop, val); | ||
} else { | ||
return dec.set(val); | ||
} | ||
} | ||
_Declaration.importantClauseRx = /(\s\!important)$/; | ||
static sanitizeValue(val) { | ||
return String(val).trim().replace(/[\s]+/g, ' '); | ||
} | ||
_Declaration.setOnto = function(declarations, prop, val) { | ||
var dec; | ||
if (!(dec = declarations[prop])) { | ||
return declarations[prop] = new this(prop, val); | ||
} else { | ||
return dec.set(val); | ||
constructor(prop1, val) { | ||
this.prop = prop1; | ||
this.important = false; | ||
this.set(val); | ||
} | ||
}; | ||
_Declaration.sanitizeValue = function(val) { | ||
return String(val).trim().replace(/[\s]+/g, ' '); | ||
}; | ||
get() { | ||
return this._get(); | ||
} | ||
_Declaration.inheritAllowed = false; | ||
_get() { | ||
return this.val; | ||
} | ||
function _Declaration(prop1, val) { | ||
this.prop = prop1; | ||
this.important = false; | ||
this.set(val); | ||
} | ||
_Declaration.prototype.get = function() { | ||
return this._get(); | ||
}; | ||
_Declaration.prototype._get = function() { | ||
return this.val; | ||
}; | ||
_Declaration.prototype._pickImportantClause = function(val) { | ||
if (self.importantClauseRx.test(String(val))) { | ||
this.important = true; | ||
return val.replace(self.importantClauseRx, ''); | ||
} else { | ||
this.important = false; | ||
return val; | ||
_pickImportantClause(val) { | ||
if (self.importantClauseRx.test(String(val))) { | ||
this.important = true; | ||
return val.replace(self.importantClauseRx, ''); | ||
} else { | ||
this.important = false; | ||
return val; | ||
} | ||
} | ||
}; | ||
_Declaration.prototype.set = function(val) { | ||
val = self.sanitizeValue(val); | ||
val = this._pickImportantClause(val); | ||
val = val.trim(); | ||
if (this._handleNullOrInherit(val)) { | ||
set(val) { | ||
val = self.sanitizeValue(val); | ||
val = this._pickImportantClause(val); | ||
val = val.trim(); | ||
if (this._handleNullOrInherit(val)) { | ||
return this; | ||
} | ||
this._set(val); | ||
return this; | ||
} | ||
this._set(val); | ||
return this; | ||
}; | ||
_Declaration.prototype._set = function(val) { | ||
return this.val = val; | ||
}; | ||
_set(val) { | ||
return this.val = val; | ||
} | ||
_Declaration.prototype._handleNullOrInherit = function(val) { | ||
if (val === '') { | ||
this.val = ''; | ||
return true; | ||
} | ||
if (val === 'inherit') { | ||
if (this.constructor.inheritAllowed) { | ||
this.val = 'inherit'; | ||
_handleNullOrInherit(val) { | ||
if (val === '') { | ||
this.val = ''; | ||
return true; | ||
} | ||
if (val === 'inherit') { | ||
if (this.constructor.inheritAllowed) { | ||
this.val = 'inherit'; | ||
} else { | ||
throw Error(`Inherit is not allowed for \`${this.prop}\``); | ||
} | ||
return true; | ||
} else { | ||
throw Error("Inherit is not allowed for `" + this.prop + "`"); | ||
return false; | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
self = _Declaration; | ||
_Declaration.importantClauseRx = /(\s\!important)$/; | ||
_Declaration.inheritAllowed = false; | ||
return _Declaration; | ||
})(); | ||
}).call(this); |
@@ -1,24 +0,14 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var _Declaration, _Length, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var _Declaration, _Length; | ||
_Declaration = require('./_Declaration'); | ||
module.exports = _Length = (function(superClass) { | ||
extend(_Length, superClass); | ||
function _Length() { | ||
return _Length.__super__.constructor.apply(this, arguments); | ||
} | ||
_Length.prototype._set = function(val) { | ||
module.exports = _Length = class _Length extends _Declaration { | ||
_set(val) { | ||
if (!/^[0-9]+$/.test(String(val))) { | ||
throw Error("`" + this.prop + "` only takes an integer for value"); | ||
throw Error(`\`${this.prop}\` only takes an integer for value`); | ||
} | ||
return this.val = parseInt(val); | ||
}; | ||
} | ||
return _Length; | ||
})(_Declaration); | ||
}; |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var Arbitrary, _Declaration, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var Arbitrary, _Declaration; | ||
_Declaration = require('./_Declaration'); | ||
module.exports = Arbitrary = (function(superClass) { | ||
extend(Arbitrary, superClass); | ||
function Arbitrary() { | ||
return Arbitrary.__super__.constructor.apply(this, arguments); | ||
} | ||
return Arbitrary; | ||
})(_Declaration); | ||
module.exports = Arbitrary = class Arbitrary extends _Declaration {}; |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var Background, _Declaration, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var Background, _Declaration; | ||
_Declaration = require('./_Declaration'); | ||
module.exports = Background = (function(superClass) { | ||
extend(Background, superClass); | ||
function Background() { | ||
return Background.__super__.constructor.apply(this, arguments); | ||
} | ||
return Background; | ||
})(_Declaration); | ||
module.exports = Background = class Background extends _Declaration {}; |
@@ -1,63 +0,58 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var Bullet, _Declaration, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var Bullet, _Declaration; | ||
_Declaration = require('./_Declaration'); | ||
module.exports = Bullet = (function(superClass) { | ||
module.exports = Bullet = (function() { | ||
var self; | ||
extend(Bullet, superClass); | ||
class Bullet extends _Declaration { | ||
_set(val) { | ||
var alignment, bg, char, color, enabled, m, original; | ||
val = String(val); | ||
original = val; | ||
char = null; | ||
enabled = false; | ||
color = 'none'; | ||
bg = 'none'; | ||
if (m = val.match(/\"([^"]+)\"/) || (m = val.match(/\'([^']+)\'/))) { | ||
char = m[1]; | ||
val = val.replace(m[0], ''); | ||
enabled = true; | ||
} | ||
if (m = val.match(/(none|left|right|center)/)) { | ||
alignment = m[1]; | ||
val = val.replace(m[0], ''); | ||
} else { | ||
alignment = 'left'; | ||
} | ||
if (alignment === 'none') { | ||
enabled = false; | ||
} | ||
if (m = val.match(/color\:([\w\-]+)/)) { | ||
color = m[1]; | ||
val = val.replace(m[0], ''); | ||
} | ||
if (m = val.match(/bg\:([\w\-]+)/)) { | ||
bg = m[1]; | ||
val = val.replace(m[0], ''); | ||
} | ||
if (val.trim() !== '') { | ||
throw Error(`Unrecognizable value \`${original}\` for \`${this.prop}\``); | ||
} | ||
return this.val = { | ||
enabled: enabled, | ||
char: char, | ||
alignment: alignment, | ||
background: bg, | ||
color: color | ||
}; | ||
} | ||
function Bullet() { | ||
return Bullet.__super__.constructor.apply(this, arguments); | ||
} | ||
}; | ||
self = Bullet; | ||
Bullet.prototype._set = function(val) { | ||
var alignment, bg, char, color, enabled, m, original; | ||
val = String(val); | ||
original = val; | ||
char = null; | ||
enabled = false; | ||
color = 'none'; | ||
bg = 'none'; | ||
if (m = val.match(/\"([^"]+)\"/) || (m = val.match(/\'([^']+)\'/))) { | ||
char = m[1]; | ||
val = val.replace(m[0], ''); | ||
enabled = true; | ||
} | ||
if (m = val.match(/(none|left|right|center)/)) { | ||
alignment = m[1]; | ||
val = val.replace(m[0], ''); | ||
} else { | ||
alignment = 'left'; | ||
} | ||
if (alignment === 'none') { | ||
enabled = false; | ||
} | ||
if (m = val.match(/color\:([\w\-]+)/)) { | ||
color = m[1]; | ||
val = val.replace(m[0], ''); | ||
} | ||
if (m = val.match(/bg\:([\w\-]+)/)) { | ||
bg = m[1]; | ||
val = val.replace(m[0], ''); | ||
} | ||
if (val.trim() !== '') { | ||
throw Error("Unrecognizable value `" + original + "` for `" + this.prop + "`"); | ||
} | ||
return this.val = { | ||
enabled: enabled, | ||
char: char, | ||
alignment: alignment, | ||
background: bg, | ||
color: color | ||
}; | ||
}; | ||
return Bullet; | ||
})(_Declaration); | ||
}).call(this); |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var Color, _Declaration, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var Color, _Declaration; | ||
_Declaration = require('./_Declaration'); | ||
module.exports = Color = (function(superClass) { | ||
extend(Color, superClass); | ||
function Color() { | ||
return Color.__super__.constructor.apply(this, arguments); | ||
} | ||
return Color; | ||
})(_Declaration); | ||
module.exports = Color = class Color extends _Declaration {}; |
@@ -1,17 +0,20 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var Display, _Declaration, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty, | ||
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
indexOf = [].indexOf; | ||
_Declaration = require('./_Declaration'); | ||
module.exports = Display = (function(superClass) { | ||
module.exports = Display = (function() { | ||
var self; | ||
extend(Display, superClass); | ||
class Display extends _Declaration { | ||
_set(val) { | ||
val = String(val).toLowerCase(); | ||
if (indexOf.call(self._allowed, val) < 0) { | ||
throw Error(`Unrecognizable value \`${val}\` for \`${this.prop}\``); | ||
} | ||
return this.val = val; | ||
} | ||
function Display() { | ||
return Display.__super__.constructor.apply(this, arguments); | ||
} | ||
}; | ||
@@ -22,12 +25,4 @@ self = Display; | ||
Display.prototype._set = function(val) { | ||
val = String(val).toLowerCase(); | ||
if (indexOf.call(self._allowed, val) < 0) { | ||
throw Error("Unrecognizable value `" + val + "` for `" + this.prop + "`"); | ||
} | ||
return this.val = val; | ||
}; | ||
return Display; | ||
})(_Declaration); | ||
}).call(this); |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var Height, _Length, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var Height, _Length; | ||
_Length = require('./_Length'); | ||
module.exports = Height = (function(superClass) { | ||
extend(Height, superClass); | ||
function Height() { | ||
return Height.__super__.constructor.apply(this, arguments); | ||
} | ||
return Height; | ||
})(_Length); | ||
module.exports = Height = class Height extends _Length {}; |
@@ -1,5 +0,3 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var Margin, MarginBottom, MarginLeft, MarginRight, MarginTop, _Declaration, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var Margin, MarginBottom, MarginLeft, MarginRight, MarginTop, _Declaration; | ||
@@ -16,50 +14,47 @@ _Declaration = require('./_Declaration'); | ||
module.exports = Margin = (function(superClass) { | ||
module.exports = Margin = (function() { | ||
var self; | ||
extend(Margin, superClass); | ||
class Margin extends _Declaration { | ||
static setOnto(declarations, prop, originalValue) { | ||
var append, val, vals; | ||
append = ''; | ||
val = _Declaration.sanitizeValue(originalValue); | ||
if (_Declaration.importantClauseRx.test(String(val))) { | ||
append = ' !important'; | ||
val = val.replace(_Declaration.importantClauseRx, ''); | ||
} | ||
val = val.trim(); | ||
if (val.length === 0) { | ||
return self._setAllDirections(declarations, append, append, append, append); | ||
} | ||
vals = val.split(" ").map(function(val) { | ||
return val + append; | ||
}); | ||
if (vals.length === 1) { | ||
return self._setAllDirections(declarations, vals[0], vals[0], vals[0], vals[0]); | ||
} else if (vals.length === 2) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[0], vals[1]); | ||
} else if (vals.length === 3) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[1]); | ||
} else if (vals.length === 4) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[3]); | ||
} else { | ||
throw Error(`Can't understand value for margin: \`${originalValue}\``); | ||
} | ||
} | ||
function Margin() { | ||
return Margin.__super__.constructor.apply(this, arguments); | ||
} | ||
self = Margin; | ||
Margin.setOnto = function(declarations, prop, originalValue) { | ||
var append, val, vals; | ||
append = ''; | ||
val = _Declaration.sanitizeValue(originalValue); | ||
if (_Declaration.importantClauseRx.test(String(val))) { | ||
append = ' !important'; | ||
val = val.replace(_Declaration.importantClauseRx, ''); | ||
static _setAllDirections(declarations, top, right, bottom, left) { | ||
MarginTop.setOnto(declarations, 'marginTop', top); | ||
MarginTop.setOnto(declarations, 'marginRight', right); | ||
MarginTop.setOnto(declarations, 'marginBottom', bottom); | ||
MarginTop.setOnto(declarations, 'marginLeft', left); | ||
} | ||
val = val.trim(); | ||
if (val.length === 0) { | ||
return self._setAllDirections(declarations, append, append, append, append); | ||
} | ||
vals = val.split(" ").map(function(val) { | ||
return val + append; | ||
}); | ||
if (vals.length === 1) { | ||
return self._setAllDirections(declarations, vals[0], vals[0], vals[0], vals[0]); | ||
} else if (vals.length === 2) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[0], vals[1]); | ||
} else if (vals.length === 3) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[1]); | ||
} else if (vals.length === 4) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[3]); | ||
} else { | ||
throw Error("Can't understand value for margin: `" + originalValue + "`"); | ||
} | ||
}; | ||
Margin._setAllDirections = function(declarations, top, right, bottom, left) { | ||
MarginTop.setOnto(declarations, 'marginTop', top); | ||
MarginTop.setOnto(declarations, 'marginRight', right); | ||
MarginTop.setOnto(declarations, 'marginBottom', bottom); | ||
MarginTop.setOnto(declarations, 'marginLeft', left); | ||
}; | ||
self = Margin; | ||
return Margin; | ||
})(_Declaration); | ||
}).call(this); |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var MarginBottom, _Length, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var MarginBottom, _Length; | ||
_Length = require('./_Length'); | ||
module.exports = MarginBottom = (function(superClass) { | ||
extend(MarginBottom, superClass); | ||
function MarginBottom() { | ||
return MarginBottom.__super__.constructor.apply(this, arguments); | ||
} | ||
return MarginBottom; | ||
})(_Length); | ||
module.exports = MarginBottom = class MarginBottom extends _Length {}; |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var MarginLeft, _Length, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var MarginLeft, _Length; | ||
_Length = require('./_Length'); | ||
module.exports = MarginLeft = (function(superClass) { | ||
extend(MarginLeft, superClass); | ||
function MarginLeft() { | ||
return MarginLeft.__super__.constructor.apply(this, arguments); | ||
} | ||
return MarginLeft; | ||
})(_Length); | ||
module.exports = MarginLeft = class MarginLeft extends _Length {}; |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var MarginRight, _Length, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var MarginRight, _Length; | ||
_Length = require('./_Length'); | ||
module.exports = MarginRight = (function(superClass) { | ||
extend(MarginRight, superClass); | ||
function MarginRight() { | ||
return MarginRight.__super__.constructor.apply(this, arguments); | ||
} | ||
return MarginRight; | ||
})(_Length); | ||
module.exports = MarginRight = class MarginRight extends _Length {}; |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var MarginTop, _Length, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var MarginTop, _Length; | ||
_Length = require('./_Length'); | ||
module.exports = MarginTop = (function(superClass) { | ||
extend(MarginTop, superClass); | ||
function MarginTop() { | ||
return MarginTop.__super__.constructor.apply(this, arguments); | ||
} | ||
return MarginTop; | ||
})(_Length); | ||
module.exports = MarginTop = class MarginTop extends _Length {}; |
@@ -1,5 +0,3 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var Padding, PaddingBottom, PaddingLeft, PaddingRight, PaddingTop, _Declaration, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var Padding, PaddingBottom, PaddingLeft, PaddingRight, PaddingTop, _Declaration; | ||
@@ -16,50 +14,47 @@ _Declaration = require('./_Declaration'); | ||
module.exports = Padding = (function(superClass) { | ||
module.exports = Padding = (function() { | ||
var self; | ||
extend(Padding, superClass); | ||
class Padding extends _Declaration { | ||
static setOnto(declarations, prop, originalValue) { | ||
var append, val, vals; | ||
append = ''; | ||
val = _Declaration.sanitizeValue(originalValue); | ||
if (_Declaration.importantClauseRx.test(String(val))) { | ||
append = ' !important'; | ||
val = val.replace(_Declaration.importantClauseRx, ''); | ||
} | ||
val = val.trim(); | ||
if (val.length === 0) { | ||
return self._setAllDirections(declarations, append, append, append, append); | ||
} | ||
vals = val.split(" ").map(function(val) { | ||
return val + append; | ||
}); | ||
if (vals.length === 1) { | ||
return self._setAllDirections(declarations, vals[0], vals[0], vals[0], vals[0]); | ||
} else if (vals.length === 2) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[0], vals[1]); | ||
} else if (vals.length === 3) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[1]); | ||
} else if (vals.length === 4) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[3]); | ||
} else { | ||
throw Error(`Can't understand value for padding: \`${originalValue}\``); | ||
} | ||
} | ||
function Padding() { | ||
return Padding.__super__.constructor.apply(this, arguments); | ||
} | ||
self = Padding; | ||
Padding.setOnto = function(declarations, prop, originalValue) { | ||
var append, val, vals; | ||
append = ''; | ||
val = _Declaration.sanitizeValue(originalValue); | ||
if (_Declaration.importantClauseRx.test(String(val))) { | ||
append = ' !important'; | ||
val = val.replace(_Declaration.importantClauseRx, ''); | ||
static _setAllDirections(declarations, top, right, bottom, left) { | ||
PaddingTop.setOnto(declarations, 'paddingTop', top); | ||
PaddingTop.setOnto(declarations, 'paddingRight', right); | ||
PaddingTop.setOnto(declarations, 'paddingBottom', bottom); | ||
PaddingTop.setOnto(declarations, 'paddingLeft', left); | ||
} | ||
val = val.trim(); | ||
if (val.length === 0) { | ||
return self._setAllDirections(declarations, append, append, append, append); | ||
} | ||
vals = val.split(" ").map(function(val) { | ||
return val + append; | ||
}); | ||
if (vals.length === 1) { | ||
return self._setAllDirections(declarations, vals[0], vals[0], vals[0], vals[0]); | ||
} else if (vals.length === 2) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[0], vals[1]); | ||
} else if (vals.length === 3) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[1]); | ||
} else if (vals.length === 4) { | ||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[3]); | ||
} else { | ||
throw Error("Can't understand value for padding: `" + originalValue + "`"); | ||
} | ||
}; | ||
Padding._setAllDirections = function(declarations, top, right, bottom, left) { | ||
PaddingTop.setOnto(declarations, 'paddingTop', top); | ||
PaddingTop.setOnto(declarations, 'paddingRight', right); | ||
PaddingTop.setOnto(declarations, 'paddingBottom', bottom); | ||
PaddingTop.setOnto(declarations, 'paddingLeft', left); | ||
}; | ||
self = Padding; | ||
return Padding; | ||
})(_Declaration); | ||
}).call(this); |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var PaddingBottom, _Length, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var PaddingBottom, _Length; | ||
_Length = require('./_Length'); | ||
module.exports = PaddingBottom = (function(superClass) { | ||
extend(PaddingBottom, superClass); | ||
function PaddingBottom() { | ||
return PaddingBottom.__super__.constructor.apply(this, arguments); | ||
} | ||
return PaddingBottom; | ||
})(_Length); | ||
module.exports = PaddingBottom = class PaddingBottom extends _Length {}; |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var PaddingLeft, _Length, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var PaddingLeft, _Length; | ||
_Length = require('./_Length'); | ||
module.exports = PaddingLeft = (function(superClass) { | ||
extend(PaddingLeft, superClass); | ||
function PaddingLeft() { | ||
return PaddingLeft.__super__.constructor.apply(this, arguments); | ||
} | ||
return PaddingLeft; | ||
})(_Length); | ||
module.exports = PaddingLeft = class PaddingLeft extends _Length {}; |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var PaddingRight, _Length, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var PaddingRight, _Length; | ||
_Length = require('./_Length'); | ||
module.exports = PaddingRight = (function(superClass) { | ||
extend(PaddingRight, superClass); | ||
function PaddingRight() { | ||
return PaddingRight.__super__.constructor.apply(this, arguments); | ||
} | ||
return PaddingRight; | ||
})(_Length); | ||
module.exports = PaddingRight = class PaddingRight extends _Length {}; |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var PaddingTop, _Length, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var PaddingTop, _Length; | ||
_Length = require('./_Length'); | ||
module.exports = PaddingTop = (function(superClass) { | ||
extend(PaddingTop, superClass); | ||
function PaddingTop() { | ||
return PaddingTop.__super__.constructor.apply(this, arguments); | ||
} | ||
return PaddingTop; | ||
})(_Length); | ||
module.exports = PaddingTop = class PaddingTop extends _Length {}; |
@@ -1,17 +0,6 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var Width, _Length, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 2.5.1 | ||
var Width, _Length; | ||
_Length = require('./_Length'); | ||
module.exports = Width = (function(superClass) { | ||
extend(Width, superClass); | ||
function Width() { | ||
return Width.__super__.constructor.apply(this, arguments); | ||
} | ||
return Width; | ||
})(_Length); | ||
module.exports = Width = class Width extends _Length {}; |
@@ -1,4 +0,3 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
var MixedDeclarationSet, | ||
slice = [].slice; | ||
// Generated by CoffeeScript 2.5.1 | ||
var MixedDeclarationSet; | ||
@@ -8,72 +7,74 @@ module.exports = MixedDeclarationSet = (function() { | ||
self = MixedDeclarationSet; | ||
class MixedDeclarationSet { | ||
static mix(...ruleSets) { | ||
var i, len, mixed, rules; | ||
mixed = new self(); | ||
for (i = 0, len = ruleSets.length; i < len; i++) { | ||
rules = ruleSets[i]; | ||
mixed.mixWithList(rules); | ||
} | ||
return mixed; | ||
} | ||
MixedDeclarationSet.mix = function() { | ||
var i, len, mixed, ruleSets, rules; | ||
ruleSets = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
mixed = new self; | ||
for (i = 0, len = ruleSets.length; i < len; i++) { | ||
rules = ruleSets[i]; | ||
mixed.mixWithList(rules); | ||
constructor() { | ||
this._declarations = {}; | ||
} | ||
return mixed; | ||
}; | ||
function MixedDeclarationSet() { | ||
this._declarations = {}; | ||
} | ||
mixWithList(rules) { | ||
var i, len, rule; | ||
rules.sort(function(a, b) { | ||
return a.selector.priority > b.selector.priority; | ||
}); | ||
for (i = 0, len = rules.length; i < len; i++) { | ||
rule = rules[i]; | ||
this._mixWithRule(rule); | ||
} | ||
return this; | ||
} | ||
MixedDeclarationSet.prototype.mixWithList = function(rules) { | ||
var i, len, rule; | ||
rules.sort(function(a, b) { | ||
return a.selector.priority > b.selector.priority; | ||
}); | ||
for (i = 0, len = rules.length; i < len; i++) { | ||
rule = rules[i]; | ||
this._mixWithRule(rule); | ||
_mixWithRule(rule) { | ||
var dec, prop, ref; | ||
ref = rule.styles._declarations; | ||
for (prop in ref) { | ||
dec = ref[prop]; | ||
this._mixWithDeclaration(dec); | ||
} | ||
} | ||
return this; | ||
}; | ||
MixedDeclarationSet.prototype._mixWithRule = function(rule) { | ||
var dec, prop, ref; | ||
ref = rule.styles._declarations; | ||
for (prop in ref) { | ||
dec = ref[prop]; | ||
this._mixWithDeclaration(dec); | ||
_mixWithDeclaration(dec) { | ||
var cur; | ||
cur = this._declarations[dec.prop]; | ||
if ((cur != null) && cur.important && !dec.important) { | ||
return; | ||
} | ||
this._declarations[dec.prop] = dec; | ||
} | ||
}; | ||
MixedDeclarationSet.prototype._mixWithDeclaration = function(dec) { | ||
var cur; | ||
cur = this._declarations[dec.prop]; | ||
if ((cur != null) && cur.important && !dec.important) { | ||
return; | ||
get(prop) { | ||
if (prop == null) { | ||
return this._declarations; | ||
} | ||
if (this._declarations[prop] == null) { | ||
return null; | ||
} | ||
return this._declarations[prop].val; | ||
} | ||
this._declarations[dec.prop] = dec; | ||
}; | ||
MixedDeclarationSet.prototype.get = function(prop) { | ||
if (prop == null) { | ||
return this._declarations; | ||
toObject() { | ||
var dec, obj, prop, ref; | ||
obj = {}; | ||
ref = this._declarations; | ||
for (prop in ref) { | ||
dec = ref[prop]; | ||
obj[prop] = dec.val; | ||
} | ||
return obj; | ||
} | ||
if (this._declarations[prop] == null) { | ||
return null; | ||
} | ||
return this._declarations[prop].val; | ||
}; | ||
MixedDeclarationSet.prototype.toObject = function() { | ||
var dec, obj, prop, ref; | ||
obj = {}; | ||
ref = this._declarations; | ||
for (prop in ref) { | ||
dec = ref[prop]; | ||
obj[prop] = dec.val; | ||
} | ||
return obj; | ||
}; | ||
self = MixedDeclarationSet; | ||
return MixedDeclarationSet; | ||
})(); | ||
}).call(this); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var CSSSelect, Selector; | ||
@@ -9,31 +9,37 @@ | ||
self = Selector; | ||
class Selector { | ||
constructor(text1) { | ||
this.text = text1; | ||
this._fn = CSSSelect.compile(this.text); | ||
this.priority = self.calculatePriority(this.text); | ||
} | ||
function Selector(text1) { | ||
this.text = text1; | ||
this._fn = CSSSelect.compile(this.text); | ||
this.priority = self.calculatePriority(this.text); | ||
} | ||
matches(elem) { | ||
return CSSSelect.is(elem, this._fn); | ||
} | ||
Selector.prototype.matches = function(elem) { | ||
return CSSSelect.is(elem, this._fn); | ||
}; | ||
// This stupid piece of code is supposed to calculate | ||
// selector priority, somehow according to | ||
// http://www.w3.org/wiki/CSS/Training/Priority_level_of_selector | ||
static calculatePriority(text) { | ||
var n, priotrity; | ||
priotrity = 0; | ||
if (n = text.match(/[\#]{1}/g)) { | ||
priotrity += 100 * n.length; | ||
} | ||
if (n = text.match(/[a-zA-Z]+/g)) { | ||
priotrity += 2 * n.length; | ||
} | ||
if (n = text.match(/\*/g)) { | ||
priotrity += 1 * n.length; | ||
} | ||
return priotrity; | ||
} | ||
Selector.calculatePriority = function(text) { | ||
var n, priotrity; | ||
priotrity = 0; | ||
if (n = text.match(/[\#]{1}/g)) { | ||
priotrity += 100 * n.length; | ||
} | ||
if (n = text.match(/[a-zA-Z]+/g)) { | ||
priotrity += 2 * n.length; | ||
} | ||
if (n = text.match(/\*/g)) { | ||
priotrity += 1 * n.length; | ||
} | ||
return priotrity; | ||
}; | ||
self = Selector; | ||
return Selector; | ||
})(); | ||
}).call(this); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var Rule, StyleSheet; | ||
@@ -9,65 +9,68 @@ | ||
self = StyleSheet; | ||
class StyleSheet { | ||
constructor() { | ||
this._rulesBySelector = {}; | ||
} | ||
function StyleSheet() { | ||
this._rulesBySelector = {}; | ||
} | ||
StyleSheet.prototype.setRule = function(selector, styles) { | ||
var key, val; | ||
if (typeof selector === 'string') { | ||
this._setRule(selector, styles); | ||
} else if (typeof selector === 'object') { | ||
for (key in selector) { | ||
val = selector[key]; | ||
this._setRule(key, val); | ||
setRule(selector, styles) { | ||
var key, val; | ||
if (typeof selector === 'string') { | ||
this._setRule(selector, styles); | ||
} else if (typeof selector === 'object') { | ||
for (key in selector) { | ||
val = selector[key]; | ||
this._setRule(key, val); | ||
} | ||
} | ||
return this; | ||
} | ||
return this; | ||
}; | ||
StyleSheet.prototype._setRule = function(s, styles) { | ||
var i, len, ref, selector; | ||
ref = self.splitSelectors(s); | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
selector = ref[i]; | ||
this._setSingleRule(selector, styles); | ||
_setRule(s, styles) { | ||
var i, len, ref, selector; | ||
ref = self.splitSelectors(s); | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
selector = ref[i]; | ||
this._setSingleRule(selector, styles); | ||
} | ||
return this; | ||
} | ||
return this; | ||
}; | ||
StyleSheet.prototype._setSingleRule = function(s, styles) { | ||
var rule, selector; | ||
selector = self.normalizeSelector(s); | ||
if (!(rule = this._rulesBySelector[selector])) { | ||
rule = new Rule(selector); | ||
this._rulesBySelector[selector] = rule; | ||
_setSingleRule(s, styles) { | ||
var rule, selector; | ||
selector = self.normalizeSelector(s); | ||
if (!(rule = this._rulesBySelector[selector])) { | ||
rule = new Rule(selector); | ||
this._rulesBySelector[selector] = rule; | ||
} | ||
rule.setStyles(styles); | ||
return this; | ||
} | ||
rule.setStyles(styles); | ||
return this; | ||
}; | ||
StyleSheet.prototype.getRulesFor = function(el) { | ||
var ref, rule, rules, selector; | ||
rules = []; | ||
ref = this._rulesBySelector; | ||
for (selector in ref) { | ||
rule = ref[selector]; | ||
if (rule.selector.matches(el)) { | ||
rules.push(rule); | ||
getRulesFor(el) { | ||
var ref, rule, rules, selector; | ||
rules = []; | ||
ref = this._rulesBySelector; | ||
for (selector in ref) { | ||
rule = ref[selector]; | ||
if (rule.selector.matches(el)) { | ||
rules.push(rule); | ||
} | ||
} | ||
return rules; | ||
} | ||
return rules; | ||
}; | ||
StyleSheet.normalizeSelector = function(selector) { | ||
return selector.replace(/[\s]+/g, ' ').replace(/[\s]*([>\,\+]{1})[\s]*/g, '$1').trim(); | ||
}; | ||
static normalizeSelector(selector) { | ||
return selector.replace(/[\s]+/g, ' ').replace(/[\s]*([>\,\+]{1})[\s]*/g, '$1').trim(); | ||
} | ||
StyleSheet.splitSelectors = function(s) { | ||
return s.trim().split(','); | ||
static splitSelectors(s) { | ||
return s.trim().split(','); | ||
} | ||
}; | ||
self = StyleSheet; | ||
return StyleSheet; | ||
})(); | ||
}).call(this); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 2.5.1 | ||
var cloneDeep, htmlparser, isPlainObject, merge, objectToDom, self; | ||
@@ -6,3 +6,3 @@ | ||
objectToDom = require('dom-converter').objectToDom; | ||
({objectToDom} = require('dom-converter')); | ||
@@ -19,3 +19,3 @@ merge = require('lodash/merge'); | ||
output = ''; | ||
for (i = j = 0, ref = times; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) { | ||
for (i = j = 0, ref = times; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) { | ||
output += str; | ||
@@ -39,3 +39,3 @@ } | ||
var handler, parser; | ||
handler = new htmlparser.DomHandler; | ||
handler = new htmlparser.DomHandler(); | ||
parser = new htmlparser.Parser(handler); | ||
@@ -78,2 +78,3 @@ parser.write(string); | ||
var cols, tty; | ||
// Based on https://github.com/jonschlinkert/window-size | ||
tty = require('tty'); | ||
@@ -91,3 +92,3 @@ cols = (function() { | ||
} | ||
} catch (_error) {} | ||
} catch (error) {} | ||
})(); | ||
@@ -94,0 +95,0 @@ if (typeof cols === 'number' && cols > 30) { |
{ | ||
"name": "renderkid", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "Stylish console.log for node", | ||
"main": "lib/RenderKid.js", | ||
"dependencies": { | ||
"css-select": "^2.0.2", | ||
"dom-converter": "^0.2", | ||
"htmlparser2": "^3.10.1", | ||
"lodash": "^4.17.20", | ||
"strip-ansi": "^3.0.0" | ||
"css-select": "^4.1.3", | ||
"dom-converter": "^0.2.0", | ||
"htmlparser2": "^6.1.0", | ||
"lodash": "^4.17.21", | ||
"strip-ansi": "^6.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"chai-changes": "^1.3.4", | ||
"chai-fuzzy": "^1.5.0", | ||
"coffee-script": "^1.9.1", | ||
"jitter": "^1.3.0", | ||
"mocha": "^5.2.0", | ||
"mocha-pretty-spec-reporter": "0.1.0-beta.2", | ||
"sinon": "^1.14.1", | ||
"sinon-chai": "^2.7.0", | ||
"underscore": "^1.8.3" | ||
"chai": "^4.3.4", | ||
"chai-changes": "^1.3.6", | ||
"chai-fuzzy": "^1.6.1", | ||
"coffeescript": "^2.5.1", | ||
"mocha": "^9.0.0", | ||
"sinon": "^11.1.1", | ||
"sinon-chai": "^3.7.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha \"test/**/*.coffee\"", | ||
"test:watch": "mocha \"test/**/*.coffee\" --watch", | ||
"test:watch": "npm run test -- --watch", | ||
"compile": "coffee --bare --compile --output ./lib ./src", | ||
"compile:watch": "jitter src lib -b", | ||
"compile:watch": "coffee --watch --bare --compile --output ./lib ./src", | ||
"watch": "npm run compile:watch & npm run test:watch", | ||
@@ -31,0 +28,0 @@ "winwatch": "start/b npm run compile:watch & npm run test:watch", |
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
7
55
80358
1863
+ Addedansi-regex@5.0.1(transitive)
+ Addedcss-select@4.3.0(transitive)
+ Addedcss-what@6.1.0(transitive)
+ Addeddom-serializer@1.4.1(transitive)
+ Addeddomhandler@4.3.1(transitive)
+ Addeddomutils@2.8.0(transitive)
+ Addedhtmlparser2@6.1.0(transitive)
+ Addednth-check@2.1.1(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedcss-select@2.1.0(transitive)
- Removedcss-what@3.4.2(transitive)
- Removeddom-serializer@0.2.2(transitive)
- Removeddomelementtype@1.3.1(transitive)
- Removeddomhandler@2.4.2(transitive)
- Removeddomutils@1.7.0(transitive)
- Removedentities@1.1.2(transitive)
- Removedhtmlparser2@3.10.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removednth-check@1.0.2(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updatedcss-select@^4.1.3
Updateddom-converter@^0.2.0
Updatedhtmlparser2@^6.1.0
Updatedlodash@^4.17.21
Updatedstrip-ansi@^6.0.0