From 06011065d2afbd09480356728687a0d3b4d5512d Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 21 Nov 2017 17:37:38 +0100 Subject: [PATCH] Add a debug app --- customize.dist/src/less2/include/toolbar.less | 1 + customize.dist/src/less2/main.less | 1 + www/common/sframe-common-history.js | 9 + www/debug/app-debug.less | 30 +++ www/debug/colors.js | 52 +++++ www/debug/index.html | 38 ++++ www/debug/inner.html | 19 ++ www/debug/inner.js | 178 ++++++++++++++++++ www/debug/main.js | 58 ++++++ 9 files changed, 386 insertions(+) create mode 100644 www/debug/app-debug.less create mode 100644 www/debug/colors.js create mode 100644 www/debug/index.html create mode 100644 www/debug/inner.html create mode 100644 www/debug/inner.js create mode 100644 www/debug/main.js diff --git a/customize.dist/src/less2/include/toolbar.less b/customize.dist/src/less2/include/toolbar.less index 99c0cdf15..e4499d67e 100644 --- a/customize.dist/src/less2/include/toolbar.less +++ b/customize.dist/src/less2/include/toolbar.less @@ -24,6 +24,7 @@ } .cp-toolbar-userlist-drawer { + background-color: @colortheme_default-bg; font: @colortheme_app-font-size @colortheme_font; min-width: 175px; width: 175px; diff --git a/customize.dist/src/less2/main.less b/customize.dist/src/less2/main.less index c7b425f8c..ca1c3503e 100644 --- a/customize.dist/src/less2/main.less +++ b/customize.dist/src/less2/main.less @@ -36,4 +36,5 @@ body.cp-app-whiteboard { @import "../../../whiteboard/app-whiteboard.less"; } body.cp-app-todo { @import "../../../todo/app-todo.less"; } body.cp-app-profile { @import "../../../profile/app-profile.less"; } body.cp-app-settings { @import "../../../settings/app-settings.less"; } +body.cp-app-debug { @import "../../../debug/app-debug.less"; } diff --git a/www/common/sframe-common-history.js b/www/common/sframe-common-history.js index 30d389816..49f4233c9 100644 --- a/www/common/sframe-common-history.js +++ b/www/common/sframe-common-history.js @@ -124,6 +124,15 @@ define([ $hist.find('.cp-toolbar-history-next, .cp-toolbar-history-previous').css('visibility', ''); if (c === states.length - 1) { $hist.find('.cp-toolbar-history-next').css('visibility', 'hidden'); } if (c === 0) { $hist.find('.cp-toolbar-history-previous').css('visibility', 'hidden'); } + + if (config.debug) { + console.log(states[i]); + var ops = states[i] && states[i].getPatch() && states[i].getPatch().operations; + if (Array.isArray(ops)) { + ops.forEach(function (op) { console.log(op); }); + } + } + return val || ''; }; diff --git a/www/debug/app-debug.less b/www/debug/app-debug.less new file mode 100644 index 000000000..b7c6b009e --- /dev/null +++ b/www/debug/app-debug.less @@ -0,0 +1,30 @@ +@import (once) "../../customize/src/less2/include/browser.less"; +@import (once) "../../customize/src/less2/include/toolbar.less"; +@import (once) "../../customize/src/less2/include/markdown.less"; +@import (once) '../../customize/src/less2/include/fileupload.less'; +@import (once) '../../customize/src/less2/include/alertify.less'; +@import (once) '../../customize/src/less2/include/tools.less'; +@import (once) '../../customize/src/less2/include/tokenfield.less'; + +.toolbar_main(); +.fileupload_main(); +.alertify_main(); +.tokenfield_main(); + +// body +&.cp-app-debug { + display: flex; + flex-flow: column; + height: 100%; + + #cp-app-debug { + flex: 1; + display: flex; + } + #cp-app-debug-content { + flex: 1; + overflow: auto; + white-space: pre-wrap; + } +} + diff --git a/www/debug/colors.js b/www/debug/colors.js new file mode 100644 index 000000000..d812f4d34 --- /dev/null +++ b/www/debug/colors.js @@ -0,0 +1,52 @@ +define(function () { + var padZero = function (str, len) { + len = len || 2; + var zeros = new Array(len).join('0'); + return (zeros + str).slice(-len); + }; + var invertColor = function (hex) { + if (hex.indexOf('#') === 0) { + hex = hex.slice(1); + } + // convert 3-digit hex to 6-digits. + if (hex.length === 3) { + hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; + } + if (hex.length !== 6) { + console.error(hex); + throw new Error('Invalid HEX color.'); + } + // invert color components + var r = (255 - parseInt(hex.slice(0, 2), 16)).toString(16), + g = (255 - parseInt(hex.slice(2, 4), 16)).toString(16), + b = (255 - parseInt(hex.slice(4, 6), 16)).toString(16); + // pad each with zeros and return + return '#' + padZero(r) + padZero(g) + padZero(b); + }; + var rgb2hex = function (rgb) { + if (rgb.indexOf('#') === 0) { return rgb; } + rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); + var hex = function (x) { + return ("0" + parseInt(x).toString(16)).slice(-2); + }; + return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); + }; + var hex2rgba = function (hex, opacity) { + if (hex.indexOf('#') === 0) { + hex = hex.slice(1); + } + if (hex.length === 3) { + hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; + } + if (!opacity) { opacity = 1; } + var r = parseInt(hex.slice(0,2), 16); + var g = parseInt(hex.slice(2,4), 16); + var b = parseInt(hex.slice(4,6), 16); + return 'rgba('+r+', '+g+', '+b+', '+opacity+')'; + }; + return { + invert: invertColor, + rgb2hex: rgb2hex, + hex2rgba: hex2rgba + }; +}); diff --git a/www/debug/index.html b/www/debug/index.html new file mode 100644 index 000000000..e3f7eacc4 --- /dev/null +++ b/www/debug/index.html @@ -0,0 +1,38 @@ + + + + CryptPad + + + + + + + +