Comparing version 4.2.2 to 4.3.0
@@ -5,2 +5,4 @@ /*global window*/ | ||
var duplicateText = require('./duplicateText'); | ||
var rgbRegexp = require('./rgbRegexp'); | ||
var cssStyles = require('./cssStyles'); | ||
@@ -460,10 +462,10 @@ function MagicPen(options) { | ||
formats.forEach(function (format) { | ||
that._themes[format] = extend({}, that._themes[format] || {}, theme); | ||
}); | ||
Object.keys(theme).forEach(function (themeKey) { | ||
if (rgbRegexp.test(themeKey) || cssStyles[themeKey]) { | ||
throw new Error("Invalid theme key: '" + themeKey + "' you can't map build styles."); | ||
} | ||
Object.keys(theme).forEach(function (themeEntry) { | ||
if (!that[themeEntry]) { | ||
that.addStyle(themeEntry, function (content) { | ||
this.text(content, themeEntry); | ||
if (!that[themeKey]) { | ||
that.addStyle(themeKey, function (content) { | ||
this.text(content, themeKey); | ||
}); | ||
@@ -473,2 +475,7 @@ } | ||
formats.forEach(function (format) { | ||
that._themes[format] = extend({}, that._themes[format] || {}, theme); | ||
}); | ||
return this; | ||
@@ -475,0 +482,0 @@ }; |
@@ -1,11 +0,19 @@ | ||
var rgbRegexp = require('./rgbRegexp'); | ||
var cssStyles = require('./cssStyles'); | ||
module.exports = function (theme, args) { | ||
var themeKey = args[1]; | ||
if (args.length === 2 && typeof themeKey === 'string') { | ||
var themeMapping = theme[themeKey]; | ||
if (themeMapping && !rgbRegexp.test(themeKey) && !cssStyles[themeKey]) { | ||
return [args[0]].concat(themeMapping); | ||
if (args.length === 2) { | ||
var count = 0; | ||
var stack = []; | ||
var themeMapping = args[1]; | ||
while(typeof themeMapping === 'string' && theme[themeMapping]) { | ||
themeMapping = theme[themeMapping]; | ||
count += 1; | ||
if (100 < count) { | ||
var index = stack.indexOf(themeMapping); | ||
stack.push(themeMapping); | ||
if (index !== -1) { | ||
throw new Error('Your theme contains a loop: ' + stack.slice(index).join(' -> ')); | ||
} | ||
} | ||
} | ||
return [args[0]].concat(themeMapping); | ||
} | ||
@@ -12,0 +20,0 @@ |
130
magicpen.js
@@ -311,2 +311,4 @@ /*! | ||
var duplicateText = require(7); | ||
var rgbRegexp = require(9); | ||
var cssStyles = require(6); | ||
@@ -766,10 +768,10 @@ function MagicPen(options) { | ||
formats.forEach(function (format) { | ||
that._themes[format] = extend({}, that._themes[format] || {}, theme); | ||
}); | ||
Object.keys(theme).forEach(function (themeKey) { | ||
if (rgbRegexp.test(themeKey) || cssStyles[themeKey]) { | ||
throw new Error("Invalid theme key: '" + themeKey + "' you can't map build styles."); | ||
} | ||
Object.keys(theme).forEach(function (themeEntry) { | ||
if (!that[themeEntry]) { | ||
that.addStyle(themeEntry, function (content) { | ||
this.text(content, themeEntry); | ||
if (!that[themeKey]) { | ||
that.addStyle(themeKey, function (content) { | ||
this.text(content, themeKey); | ||
}); | ||
@@ -779,2 +781,7 @@ } | ||
formats.forEach(function (format) { | ||
that._themes[format] = extend({}, that._themes[format] || {}, theme); | ||
}); | ||
return this; | ||
@@ -973,12 +980,20 @@ }; | ||
},{}],10:[function(require,module,exports){ | ||
var rgbRegexp = require(9); | ||
var cssStyles = require(6); | ||
module.exports = function (theme, args) { | ||
var themeKey = args[1]; | ||
if (args.length === 2 && typeof themeKey === 'string') { | ||
var themeMapping = theme[themeKey]; | ||
if (themeMapping && !rgbRegexp.test(themeKey) && !cssStyles[themeKey]) { | ||
return [args[0]].concat(themeMapping); | ||
if (args.length === 2) { | ||
var count = 0; | ||
var stack = []; | ||
var themeMapping = args[1]; | ||
while(typeof themeMapping === 'string' && theme[themeMapping]) { | ||
themeMapping = theme[themeMapping]; | ||
count += 1; | ||
if (100 < count) { | ||
var index = stack.indexOf(themeMapping); | ||
stack.push(themeMapping); | ||
if (index !== -1) { | ||
throw new Error('Your theme contains a loop: ' + stack.slice(index).join(' -> ')); | ||
} | ||
} | ||
} | ||
return [args[0]].concat(themeMapping); | ||
} | ||
@@ -1119,30 +1134,38 @@ | ||
var process = module.exports = {}; | ||
var queue = []; | ||
var draining = false; | ||
function drainQueue() { | ||
if (draining) { | ||
return; | ||
process.nextTick = (function () { | ||
var canSetImmediate = typeof window !== 'undefined' | ||
&& window.setImmediate; | ||
var canPost = typeof window !== 'undefined' | ||
&& window.postMessage && window.addEventListener | ||
; | ||
if (canSetImmediate) { | ||
return function (f) { return window.setImmediate(f) }; | ||
} | ||
draining = true; | ||
var currentQueue; | ||
var len = queue.length; | ||
while(len) { | ||
currentQueue = queue; | ||
queue = []; | ||
var i = -1; | ||
while (++i < len) { | ||
currentQueue[i](); | ||
} | ||
len = queue.length; | ||
if (canPost) { | ||
var queue = []; | ||
window.addEventListener('message', function (ev) { | ||
var source = ev.source; | ||
if ((source === window || source === null) && ev.data === 'process-tick') { | ||
ev.stopPropagation(); | ||
if (queue.length > 0) { | ||
var fn = queue.shift(); | ||
fn(); | ||
} | ||
} | ||
}, true); | ||
return function nextTick(fn) { | ||
queue.push(fn); | ||
window.postMessage('process-tick', '*'); | ||
}; | ||
} | ||
draining = false; | ||
} | ||
process.nextTick = function (fun) { | ||
queue.push(fun); | ||
if (!draining) { | ||
setTimeout(drainQueue, 0); | ||
} | ||
}; | ||
return function nextTick(fn) { | ||
setTimeout(fn, 0); | ||
}; | ||
})(); | ||
process.title = 'browser'; | ||
@@ -1152,3 +1175,2 @@ process.browser = true; | ||
process.argv = []; | ||
process.version = ''; // empty string to avoid regexp issues | ||
@@ -1167,3 +1189,3 @@ function noop() {} | ||
throw new Error('process.binding is not supported'); | ||
}; | ||
} | ||
@@ -1175,3 +1197,2 @@ // TODO(shtylman) | ||
}; | ||
process.umask = function() { return 0; }; | ||
@@ -1476,6 +1497,15 @@ },{}],14:[function(require,module,exports){ | ||
var result = color.map_palette([target], relative); | ||
var result = color.map_palette([target], relative, 'closest'); | ||
return result[key]; | ||
}; | ||
color.furthest = function(target, relative) { | ||
var key = color.palette_map_key(target); | ||
var result = color.map_palette([target], relative, 'furthest'); | ||
return result[key]; | ||
}; | ||
},{}],17:[function(require,module,exports){ | ||
@@ -1540,7 +1570,9 @@ /** | ||
* @param [{rgbcolor}] b each element should have fields R,G,B | ||
* @param 'type' should have field closest or furthest | ||
* @return {palettemap} | ||
*/ | ||
function map_palette(a, b) | ||
function map_palette(a, b, type) | ||
{ | ||
var c = {}; | ||
type = type || 'closest'; | ||
for (var idx1 in a){ | ||
@@ -1554,7 +1586,15 @@ var color1 = a[idx1]; | ||
var current_color_diff = diff(color1,color2); | ||
if((best_color == undefined) || (current_color_diff < best_color_diff)) | ||
if((best_color == undefined) || ((type === 'closest') && (current_color_diff < best_color_diff))) | ||
{ | ||
best_color = color2; | ||
best_color_diff = current_color_diff; | ||
continue; | ||
} | ||
if((type === 'furthest') && (current_color_diff > best_color_diff)) | ||
{ | ||
best_color = color2; | ||
best_color_diff = current_color_diff; | ||
continue; | ||
} | ||
} | ||
@@ -1561,0 +1601,0 @@ c[palette_map_key(color1)] = best_color; |
{ | ||
"name": "magicpen", | ||
"version": "4.2.2", | ||
"version": "4.3.0", | ||
"description": "Styled output in both consoles and browsers", | ||
@@ -5,0 +5,0 @@ "main": "./lib/MagicPen.js", |
@@ -429,4 +429,5 @@ # MagicPen | ||
MagicPen have support for theming text styles differently for each | ||
format. A theme is just a hash of aliases to build in text styles. You | ||
install the theme for one or more formats. | ||
format. A theme is just a hash of aliases to build in text styles or | ||
aliases to other theme entries. You install the theme for one or more | ||
formats. | ||
@@ -437,3 +438,4 @@ ```js | ||
functionName: ['green', 'italic'], | ||
number: '#FF8DFE' | ||
primitive: '#FF8DFE', | ||
number: 'primitive' | ||
}); | ||
@@ -481,3 +483,3 @@ ``` | ||
functionName: ['#403298', 'italic', 'bold'], | ||
number: '#80417F' | ||
primitive: '#80417F' | ||
}); | ||
@@ -484,0 +486,0 @@ ``` |
@@ -1101,3 +1101,4 @@ /*global describe, it, beforeEach*/ | ||
comment: ['#969896', 'italic'], | ||
keyword: '#bf41ea' | ||
keyword: '#bf41ea', | ||
string: 'keyword' | ||
}); | ||
@@ -1108,3 +1109,3 @@ | ||
pen.indentLines(); | ||
pen.i().text('console.').text('log', 'method').text('("wat");').nl(); | ||
pen.i().text('console.').text('log', 'method').text('(').string('"wat"').text(');').nl(); | ||
pen.outdentLines(); | ||
@@ -1132,3 +1133,3 @@ pen.text('}'); | ||
' <div><span style="color: #bf41ea">function</span> wat() {</div>\n' + | ||
' <div> console.log("wat");</div>\n' + | ||
' <div> console.log(<span style="color: #bf41ea">"wat"</span>);</div>\n' + | ||
' <div>}</div>\n' + | ||
@@ -1170,3 +1171,3 @@ '</div>'); | ||
' <div><span style="color: #bf41ea">function</span> <span style="color: #55ab40">wat</span>() {</div>\n' + | ||
' <div> console.<span style="color: #55ab40; font-weight: bold">log</span>("wat");</div>\n' + | ||
' <div> console.<span style="color: #55ab40; font-weight: bold">log</span>(<span style="color: #bf41ea">"wat"</span>);</div>\n' + | ||
' <div>}</div>\n' + | ||
@@ -1184,3 +1185,21 @@ '</div>'); | ||
}); | ||
describe('when the theme has a loop', function () { | ||
beforeEach(function () { | ||
pen.installTheme({ | ||
comment: 'foo', | ||
foo: 'bar', | ||
bar: 'baz', | ||
baz: 'qux', | ||
qux: 'bar' | ||
}); | ||
}); | ||
it('throw when the theme is applied', function () { | ||
expect(function () { | ||
pen.toString('ansi'); | ||
}, 'to throw', 'Your theme contains a loop: bar -> baz -> qux -> bar'); | ||
}); | ||
}); | ||
}); | ||
}); |
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
531139
3337
581