!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.colorcode=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o cp437 function by sheetjs // edited from https://github.com/SheetJS/js-codepage/blob/master/bits/437.js var cp437 = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ", D = [], e = {}; for(var i=0;i!=d.length;++i) { if(d.charCodeAt(i) !== 0xFFFD) e[d[i]] = i; D[i] = d.charAt(i); } return {"enc": e, "dec": D }; })(); var render_char = function(font, char_value, ctx, ctx_x, ctx_y){ char_value = cp437.enc[String.fromCharCode(char_value)] | 0; var sheet_x = (char_value % font.sheet_w_in_chars) * font.char_w var sheet_y = ((char_value / font.sheet_w_in_chars) |0) * font.char_h ctx.drawImage(font.sheet, sheet_x|0, sheet_y|0, font.char_w, font.char_h, ctx_x|0, ctx_y|0, font.char_w, font.char_h) } for (var i=0, wh; wh=cp437s[i]; i++){ var font = {}; font.is_char_blank = require('../fontutil').is_char_blank; font.render_char = render_char; font.name = 'cp437_' + wh[0] + 'x' + wh[1]; font.sheet_url = './img/' + font.name + '.png' font.sheet_w_in_chars = 16; font.char_w = wh[0] font.char_h = wh[1] fonts[font.name] = font; } // window.cp437 = cp437; },{"../fontutil":7}],6:[function(require,module,exports){ var fsexps = [[8,16,0],[8,15,1],[8,8,5]] var fonts = {}; module.exports = fonts; var render_char = function(font, char_value, ctx, ctx_x, ctx_y, char){ var sheet_x = 0, sheet_y = 3; if (char_value >= 0x20 && char_value <= 0x7e){ // ascii sheet_x = (char_value - 0x20) * font.char_w_sheet if (char.i){ // italic sheet_y = 1 * font.char_h_sheet + 3 } } else if (char_value >= 0x80 && char_value <= 0xff){ // latin-1 sheet_x = (char_value - 0x80) * font.char_w_sheet; sheet_y = 2 * font.char_h_sheet + 3 } else if (char_value >= 0x0100 && char_value <= 0x017f){ // latin a sheet_x = (char_value - 0x0100) * font.char_w_sheet; sheet_y = 3 * font.char_h_sheet + 3 } else if (char_value >= 0x0180 && char_value <= 0x024f){ // latin b sheet_x = (char_value - 0x0180) * font.char_w_sheet; sheet_y = 4 * font.char_h_sheet + 3 } else if (char_value >= 0x2500 && char_value <= 0x25ff){ // geom sheet_x = (char_value - 0x2500) * font.char_w_sheet; sheet_y = 5 * font.char_h_sheet + 3 } else if (char_value >= 0x2600 && char_value <= 0x26ff){ // emoji sheet_x = (char_value - 0x2600) * font.char_w_sheet; sheet_y = 6 * font.char_h_sheet + 3 } // var sheet_x = (char_value % font.sheet_w_in_chars) * font.char_w // var sheet_y = ((char_value / font.sheet_w_in_chars) |0) * font.char_h + 3 ctx.drawImage(font.sheet, sheet_x|0, (sheet_y|0) + font.y_adj, font.char_w, font.char_h, ctx_x|0, ctx_y|0, font.char_w, font.char_h) } for (var i=0, wh; wh=fsexps[i]; i++){ var font = { name: 'fixedsys_' + wh[0] + 'x' + wh[1], sheet_url: './img/fsex-simple.png', sheet_w_in_chars: 128, char_w_sheet: 8, char_h_sheet: 16, char_w: wh[0], char_h: wh[1], y_adj: wh[2], is_char_blank: require('../fontutil').is_char_blank, render_char: render_char } fonts[font.name] = font } },{"../fontutil":7}],7:[function(require,module,exports){ var util = {}; module.exports = util; util.is_char_blank = function(char_value){ if (char_value === 32) return true; } util.render_char = function(font, char_value, ctx, ctx_x, ctx_y){ var sheet_x = (char_value % font.sheet_w_in_chars) * font.char_w var sheet_y = ((char_value / font.sheet_w_in_chars) |0) * font.char_h ctx.drawImage(font.sheet, sheet_x|0, sheet_y|0, font.char_w, font.char_h, ctx_x|0, ctx_y|0, font.char_w, font.char_h) } },{}],8:[function(require,module,exports){ var char_color = '\x03'; var make_colorcode_fgbg = function(fg, bg){ // pad numbers: this prevents irc parsing confusion // when the character after the colorcode is a number if (fg < 10) fg = "0" + fg; if (bg < 10) bg = "0" + bg; return char_color + fg + "," + bg } var colorcode_from_json = function(json, opts){ var out = ""; for (var li=0, line; line=json.lines[li]; li++){ for (var ci=0, char; char=line[ci]; ci++){ out += make_colorcode_fgbg(char.fg, char.bg) out += String.fromCharCode(char.value) } out += "\n"; } return out; } module.exports = colorcode_from_json; },{}],9:[function(require,module,exports){ // default settings for fonts, colors, etc var style = {}; module.exports = style; },{}],10:[function(require,module,exports){ var char_color = '\x03'; var regexp_color = /(^[\d]{1,2})?(?:,([\d]{1,2}))?/; var style_chars = { '\x02': 'bold', '\x1d': 'italic', '\x1f': 'underline', '\x0f': 'reset', '\x16': 'inverse' }; var Style = function(style){ this.b = style.b; this.i = style.i; this.u = style.u; this.fg = style.fg; this.bg = style.bg; }; var style_fns = {}; style_fns.bold = function(style){ style.b = !style.b }; style_fns.italic = function(style){ style.i = !style.i }; style_fns.underline = function(style){ style.u = !style.u }; style_fns.inverse = function(style){ var tmp = style.fg; style.fg = style.bg; style.bg = tmp; }; style_fns.reset = function(style, base_style){ style.b = base_style.b; style.i = base_style.i; style.u = base_style.u; style.fg = base_style.fg; style.bg = base_style.bg; }; var colorcode_to_json = function(string, opts){ // looks like its already converted if (typeof string === 'object' && 'lines' in string && 'w' in string && 'h' in string) return string; opts = opts || {}; var d = colorcode_to_json.defaults; var base_style = { b: "b" in opts ? opts.b : d.b, i: "i" in opts ? opts.i : d.i, u: "u" in opts ? opts.u : d.u, fg: "fg" in opts ? opts.fg : d.fg, bg: "bg" in opts ? opts.bg : d.bg }; var lines_in = string.split(/\r?\n/); var lines_out = []; var w = 0, h = 0; for (var i=0; i