1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/renderkid/lib/Layout.js

134 lines
3.6 KiB
JavaScript
Raw Normal View History

2024-01-16 21:26:16 +08:00
"use strict";
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
// Generated by CoffeeScript 2.5.1
var Block, Layout, SpecialString, cloneAndMergeDeep, i, len, prop, ref, terminalWidth;
2023-12-18 13:12:25 +08:00
Block = require('./layout/Block');
2024-01-16 21:26:16 +08:00
var _require = require('./tools');
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
cloneAndMergeDeep = _require.cloneAndMergeDeep;
2023-12-18 13:12:25 +08:00
SpecialString = require('./layout/SpecialString');
terminalWidth = require('./tools').getCols();
2024-01-16 21:26:16 +08:00
module.exports = Layout = function () {
2023-12-18 13:12:25 +08:00
var self;
2024-01-16 21:26:16 +08:00
var Layout = /*#__PURE__*/function () {
function Layout() {
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var rootBlockConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, Layout);
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();
}
_createClass(Layout, [{
key: "getRootBlock",
value: function getRootBlock() {
return this._root;
}
}, {
key: "_append",
value: function _append(text) {
return this._written.push(text);
}
}, {
key: "_appendLine",
value: function _appendLine(text) {
var s;
this._append(text);
s = new SpecialString(text);
if (s.length < this._config.terminalWidth) {
this._append('<none>\n</none>');
}
return this;
}
}, {
key: "get",
value: function get() {
this._ensureClosed();
if (this._written[this._written.length - 1] === '<none>\n</none>') {
this._written.pop();
}
return this._written.join("");
}
}, {
key: "_ensureClosed",
value: function _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();
}
}
}]);
return Layout;
}();
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
;
self = Layout;
2023-12-18 13:12:25 +08:00
Layout._rootBlockDefaultConfig = {
linePrependor: {
options: {
amount: 0
}
},
lineAppendor: {
options: {
amount: 0
}
},
blockPrependor: {
options: {
amount: 0
}
},
blockAppendor: {
options: {
amount: 0
}
}
};
Layout._defaultConfig = {
terminalWidth: terminalWidth
};
return Layout;
2024-01-16 21:26:16 +08:00
}.call(void 0);
2023-12-18 13:12:25 +08:00
ref = ['openBlock', 'write'];
2024-01-16 21:26:16 +08:00
2023-12-18 13:12:25 +08:00
for (i = 0, len = ref.length; i < len; i++) {
prop = ref[i];
2024-01-16 21:26:16 +08:00
(function () {
var method;
method = prop;
return Layout.prototype[method] = function () {
return this._root[method].apply(this._root, arguments);
};
})();
}