@vue-office/excel
Version:
支持多种文件(**docx、excel、pdf、pptx**)预览的vue组件库,支持vue2/3。也支持非Vue框架的预览。
1,817 lines • 3.54 MB
JavaScript
import { defineComponent, ref, onMounted, nextTick, onBeforeUnmount, watch } from "vue-demi";
import { openBlock, createElementBlock, createElementVNode } from "vue";
function _typeof$2(o) {
"@babel/helpers - typeof";
return _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
return typeof o2;
} : function(o2) {
return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
}, _typeof$2(o);
}
function toPrimitive(t2, r) {
if ("object" != _typeof$2(t2) || !t2)
return t2;
var e = t2[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t2, r || "default");
if ("object" != _typeof$2(i))
return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t2);
}
function toPropertyKey(t2) {
var i = toPrimitive(t2, "string");
return "symbol" == _typeof$2(i) ? i : i + "";
}
function _defineProperty(e, r, t2) {
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t2,
enumerable: true,
configurable: true,
writable: true
}) : e[r] = t2, e;
}
function _arrayWithHoles(r) {
if (Array.isArray(r))
return r;
}
function _iterableToArrayLimit(r, l) {
var t2 = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t2) {
var e, n, i, u, a = [], f = true, o = false;
try {
if (i = (t2 = t2.call(r)).next, 0 === l) {
if (Object(t2) !== t2)
return;
f = false;
} else
for (; !(f = (e = i.call(t2)).done) && (a.push(e.value), a.length !== l); f = true)
;
} catch (r2) {
o = true, n = r2;
} finally {
try {
if (!f && null != t2["return"] && (u = t2["return"](), Object(u) !== u))
return;
} finally {
if (o)
throw n;
}
}
return a;
}
}
function _arrayLikeToArray$3(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++)
n[e] = r[e];
return n;
}
function _unsupportedIterableToArray$3(r, a) {
if (r) {
if ("string" == typeof r)
return _arrayLikeToArray$3(r, a);
var t2 = {}.toString.call(r).slice(8, -1);
return "Object" === t2 && r.constructor && (t2 = r.constructor.name), "Map" === t2 || "Set" === t2 ? Array.from(r) : "Arguments" === t2 || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t2) ? _arrayLikeToArray$3(r, a) : void 0;
}
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray$3(r, e) || _nonIterableRest();
}
function _classCallCheck(a, n) {
if (!(a instanceof n))
throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(e, r) {
for (var t2 = 0; t2 < r.length; t2++) {
var o = r[t2];
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t2) {
return r && _defineProperties(e.prototype, r), t2 && _defineProperties(e, t2), Object.defineProperty(e, "prototype", {
writable: false
}), e;
}
function _iterableToArray(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"])
return Array.from(r);
}
function _toArray(r) {
return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray$3(r) || _nonIterableRest();
}
var Element = /* @__PURE__ */ function() {
function Element2(tag) {
var className = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
_classCallCheck(this, Element2);
if (typeof tag === "string") {
this.el = document.createElement(tag);
this.el.className = className;
} else {
this.el = tag;
}
this.data = {};
}
return _createClass(Element2, [{
key: "data",
value: function data(key, value) {
if (value !== void 0) {
this.data[key] = value;
return this;
}
return this.data[key];
}
}, {
key: "on",
value: function on(eventNames, handler) {
var _eventNames$split = eventNames.split("."), _eventNames$split2 = _toArray(_eventNames$split), fen = _eventNames$split2[0], oen = _eventNames$split2.slice(1);
var eventName = fen;
if (eventName === "mousewheel" && /Firefox/i.test(window.navigator.userAgent)) {
eventName = "DOMMouseScroll";
}
this.el.addEventListener(eventName, function(evt) {
handler(evt);
for (var i = 0; i < oen.length; i += 1) {
var k = oen[i];
if (k === "left" && evt.button !== 0) {
return;
}
if (k === "right" && evt.button !== 2) {
return;
}
if (k === "stop") {
evt.stopPropagation();
}
}
});
return this;
}
}, {
key: "offset",
value: function offset(value) {
var _this = this;
if (value !== void 0) {
Object.keys(value).forEach(function(k) {
_this.css(k, "".concat(value[k], "px"));
});
return this;
}
var _this$el = this.el, offsetTop = _this$el.offsetTop, offsetLeft = _this$el.offsetLeft, offsetHeight = _this$el.offsetHeight, offsetWidth = _this$el.offsetWidth;
return {
top: offsetTop,
left: offsetLeft,
height: offsetHeight,
width: offsetWidth
};
}
}, {
key: "scroll",
value: function scroll(v) {
var el = this.el;
if (v !== void 0) {
if (v.left !== void 0) {
el.scrollLeft = v.left;
}
if (v.top !== void 0) {
el.scrollTop = v.top;
}
}
return {
left: el.scrollLeft,
top: el.scrollTop
};
}
}, {
key: "box",
value: function box() {
return this.el.getBoundingClientRect();
}
}, {
key: "parent",
value: function parent() {
return new Element2(this.el.parentNode);
}
}, {
key: "children",
value: function children() {
var _this2 = this;
for (var _len = arguments.length, eles = new Array(_len), _key = 0; _key < _len; _key++) {
eles[_key] = arguments[_key];
}
if (arguments.length === 0) {
return this.el.childNodes;
}
eles.forEach(function(ele) {
return _this2.child(ele);
});
return this;
}
}, {
key: "removeChild",
value: function removeChild(el) {
this.el.removeChild(el);
}
/*
first() {
return this.el.firstChild;
}
last() {
return this.el.lastChild;
}
remove(ele) {
return this.el.removeChild(ele);
}
prepend(ele) {
const { el } = this;
if (el.children.length > 0) {
el.insertBefore(ele, el.firstChild);
} else {
el.appendChild(ele);
}
return this;
}
prev() {
return this.el.previousSibling;
}
next() {
return this.el.nextSibling;
}
*/
}, {
key: "child",
value: function child(arg) {
var ele = arg;
if (typeof arg === "string") {
ele = document.createTextNode(arg);
} else if (arg instanceof Element2) {
ele = arg.el;
}
this.el.appendChild(ele);
return this;
}
}, {
key: "contains",
value: function contains(ele) {
return this.el.contains(ele);
}
}, {
key: "className",
value: function className(v) {
if (v !== void 0) {
this.el.className = v;
return this;
}
return this.el.className;
}
}, {
key: "addClass",
value: function addClass(name) {
this.el.classList.add(name);
return this;
}
}, {
key: "hasClass",
value: function hasClass(name) {
return this.el.classList.contains(name);
}
}, {
key: "removeClass",
value: function removeClass(name) {
this.el.classList.remove(name);
return this;
}
}, {
key: "toggle",
value: function toggle() {
var cls = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "active";
return this.toggleClass(cls);
}
}, {
key: "toggleClass",
value: function toggleClass(name) {
return this.el.classList.toggle(name);
}
}, {
key: "active",
value: function active() {
var flag = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
var cls = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "active";
if (flag)
this.addClass(cls);
else
this.removeClass(cls);
return this;
}
}, {
key: "checked",
value: function checked() {
var flag = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
this.active(flag, "checked");
return this;
}
}, {
key: "disabled",
value: function disabled() {
var flag = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
if (flag)
this.addClass("disabled");
else
this.removeClass("disabled");
return this;
}
// key, value
// key
// {k, v}...
}, {
key: "attr",
value: function attr(key, value) {
var _this3 = this;
if (value !== void 0) {
this.el.setAttribute(key, value);
} else {
if (typeof key === "string") {
return this.el.getAttribute(key);
}
Object.keys(key).forEach(function(k) {
_this3.el.setAttribute(k, key[k]);
});
}
return this;
}
}, {
key: "removeAttr",
value: function removeAttr(key) {
this.el.removeAttribute(key);
return this;
}
}, {
key: "html",
value: function html(content) {
if (content !== void 0) {
this.el.innerHTML = content;
return this;
}
return this.el.innerHTML;
}
}, {
key: "val",
value: function val(v) {
if (v !== void 0) {
this.el.value = v;
return this;
}
return this.el.value;
}
}, {
key: "focus",
value: function focus() {
this.el.focus();
}
}, {
key: "cssRemoveKeys",
value: function cssRemoveKeys() {
var _this4 = this;
for (var _len2 = arguments.length, keys2 = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
keys2[_key2] = arguments[_key2];
}
keys2.forEach(function(k) {
return _this4.el.style.removeProperty(k);
});
return this;
}
// css( propertyName )
// css( propertyName, value )
// css( properties )
}, {
key: "css",
value: function css(name, value) {
var _this5 = this;
if (value === void 0 && typeof name !== "string") {
Object.keys(name).forEach(function(k) {
_this5.el.style[k] = name[k];
});
return this;
}
if (value !== void 0) {
this.el.style[name] = value;
return this;
}
return this.el.style[name];
}
}, {
key: "computedStyle",
value: function computedStyle() {
return window.getComputedStyle(this.el, null);
}
}, {
key: "show",
value: function show() {
this.css("display", "block");
return this;
}
}, {
key: "hide",
value: function hide() {
this.css("display", "none");
return this;
}
}]);
}();
var h = function h2(tag) {
var className = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
return new Element(tag, className);
};
function _arrayWithoutHoles(r) {
if (Array.isArray(r))
return _arrayLikeToArray$3(r);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(r) {
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray$3(r) || _nonIterableSpread();
}
var alphabets = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
function stringAt(index2) {
var str = "";
var cindex = index2;
while (cindex >= alphabets.length) {
cindex /= alphabets.length;
cindex -= 1;
str += alphabets[parseInt(cindex, 10) % alphabets.length];
}
var last = index2 % alphabets.length;
str += alphabets[last];
return str;
}
function indexAt(str) {
var ret = 0;
for (var i = 0; i !== str.length; ++i)
ret = 26 * ret + str.charCodeAt(i) - 64;
return ret - 1;
}
function expr2xy(src) {
var x = "";
var y = "";
for (var i = 0; i < src.length; i += 1) {
if (src.charAt(i) >= "0" && src.charAt(i) <= "9") {
y += src.charAt(i);
} else {
x += src.charAt(i);
}
}
return [indexAt(x), parseInt(y, 10) - 1];
}
function xy2expr(x, y) {
return "".concat(stringAt(x)).concat(y + 1);
}
function expr2expr(src, xn, yn) {
var condition = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : function() {
return true;
};
if (xn === 0 && yn === 0)
return src;
var _expr2xy = expr2xy(src), _expr2xy2 = _slicedToArray(_expr2xy, 2), x = _expr2xy2[0], y = _expr2xy2[1];
if (!condition(x, y))
return src;
return xy2expr(x + xn, y + yn);
}
var CellRange = /* @__PURE__ */ function() {
function CellRange2(sri, sci, eri, eci) {
var w = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : 0;
var h3 = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : 0;
_classCallCheck(this, CellRange2);
this.sri = sri;
this.sci = sci;
this.eri = eri;
this.eci = eci;
this.w = w;
this.h = h3;
}
return _createClass(CellRange2, [{
key: "set",
value: function set(sri, sci, eri, eci) {
this.sri = sri;
this.sci = sci;
this.eri = eri;
this.eci = eci;
}
}, {
key: "multiple",
value: function multiple() {
return this.eri - this.sri > 0 || this.eci - this.sci > 0;
}
// cell-index: ri, ci
// cell-ref: A10
}, {
key: "includes",
value: function includes() {
var ri = 0, ci = 0;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (args.length === 1) {
var _expr2xy = expr2xy(args[0]);
var _expr2xy2 = _slicedToArray(_expr2xy, 2);
ci = _expr2xy2[0];
ri = _expr2xy2[1];
} else if (args.length === 2) {
ri = args[0];
ci = args[1];
}
var sri = this.sri, sci = this.sci, eri = this.eri, eci = this.eci;
return sri <= ri && ri <= eri && sci <= ci && ci <= eci;
}
}, {
key: "each",
value: function each(cb) {
var rowFilter = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : function() {
return true;
};
var sri = this.sri, sci = this.sci, eri = this.eri, eci = this.eci;
for (var i = sri; i <= eri; i += 1) {
if (rowFilter(i)) {
for (var j = sci; j <= eci; j += 1) {
cb(i, j);
}
}
}
}
}, {
key: "contains",
value: function contains(other) {
return this.sri <= other.sri && this.sci <= other.sci && this.eri >= other.eri && this.eci >= other.eci;
}
// within
}, {
key: "within",
value: function within(other) {
return this.sri >= other.sri && this.sci >= other.sci && this.eri <= other.eri && this.eci <= other.eci;
}
// disjoint
}, {
key: "disjoint",
value: function disjoint(other) {
return this.sri > other.eri || this.sci > other.eci || other.sri > this.eri || other.sci > this.eci;
}
// intersects
}, {
key: "intersects",
value: function intersects(other) {
return this.sri <= other.eri && this.sci <= other.eci && other.sri <= this.eri && other.sci <= this.eci;
}
// union
}, {
key: "union",
value: function union(other) {
var sri = this.sri, sci = this.sci, eri = this.eri, eci = this.eci;
return new CellRange2(other.sri < sri ? other.sri : sri, other.sci < sci ? other.sci : sci, other.eri > eri ? other.eri : eri, other.eci > eci ? other.eci : eci);
}
// intersection
// intersection(other) {}
// Returns Array<CellRange> that represents that part of this that does not intersect with other
// difference
}, {
key: "difference",
value: function difference(other) {
var ret = [];
var addRet = function addRet2(sri2, sci2, eri2, eci2) {
ret.push(new CellRange2(sri2, sci2, eri2, eci2));
};
var sri = this.sri, sci = this.sci, eri = this.eri, eci = this.eci;
var dsr = other.sri - sri;
var dsc = other.sci - sci;
var der = eri - other.eri;
var dec2 = eci - other.eci;
if (dsr > 0) {
addRet(sri, sci, other.sri - 1, eci);
if (der > 0) {
addRet(other.eri + 1, sci, eri, eci);
if (dsc > 0) {
addRet(other.sri, sci, other.eri, other.sci - 1);
}
if (dec2 > 0) {
addRet(other.sri, other.eci + 1, other.eri, eci);
}
} else {
if (dsc > 0) {
addRet(other.sri, sci, eri, other.sci - 1);
}
if (dec2 > 0) {
addRet(other.sri, other.eci + 1, eri, eci);
}
}
} else if (der > 0) {
addRet(other.eri + 1, sci, eri, eci);
if (dsc > 0) {
addRet(sri, sci, other.eri, other.sci - 1);
}
if (dec2 > 0) {
addRet(sri, other.eci + 1, other.eri, eci);
}
}
if (dsc > 0) {
addRet(sri, sci, eri, other.sci - 1);
if (dec2 > 0) {
addRet(sri, other.eri + 1, eri, eci);
if (dsr > 0) {
addRet(sri, other.sci, other.sri - 1, other.eci);
}
if (der > 0) {
addRet(other.sri + 1, other.sci, eri, other.eci);
}
} else {
if (dsr > 0) {
addRet(sri, other.sci, other.sri - 1, eci);
}
if (der > 0) {
addRet(other.sri + 1, other.sci, eri, eci);
}
}
} else if (dec2 > 0) {
addRet(eri, other.eci + 1, eri, eci);
if (dsr > 0) {
addRet(sri, sci, other.sri - 1, other.eci);
}
if (der > 0) {
addRet(other.eri + 1, sci, eri, other.eci);
}
}
return ret;
}
}, {
key: "size",
value: function size() {
return [this.eri - this.sri + 1, this.eci - this.sci + 1];
}
}, {
key: "toString",
value: function toString2() {
var sri = this.sri, sci = this.sci, eri = this.eri, eci = this.eci;
var ref2 = xy2expr(sci, sri);
if (this.multiple()) {
ref2 = "".concat(ref2, ":").concat(xy2expr(eci, eri));
}
return ref2;
}
}, {
key: "clone",
value: function clone2() {
var sri = this.sri, sci = this.sci, eri = this.eri, eci = this.eci, w = this.w, h3 = this.h;
return new CellRange2(sri, sci, eri, eci, w, h3);
}
/*
toJSON() {
return this.toString();
}
*/
}, {
key: "equals",
value: function equals2(other) {
return this.eri === other.eri && this.eci === other.eci && this.sri === other.sri && this.sci === other.sci;
}
}], [{
key: "valueOf",
value: function valueOf(ref2) {
var refs = ref2.split(":");
var _expr2xy3 = expr2xy(refs[0]), _expr2xy4 = _slicedToArray(_expr2xy3, 2), sci = _expr2xy4[0], sri = _expr2xy4[1];
var eri = sri, eci = sci;
if (refs.length > 1) {
var _expr2xy5 = expr2xy(refs[1]);
var _expr2xy6 = _slicedToArray(_expr2xy5, 2);
eci = _expr2xy6[0];
eri = _expr2xy6[1];
}
return new CellRange2(sri, sci, eri, eci);
}
}]);
}();
var Selector$1 = /* @__PURE__ */ function() {
function Selector2() {
_classCallCheck(this, Selector2);
this.range = new CellRange(0, 0, 0, 0);
this.ri = 0;
this.ci = 0;
}
return _createClass(Selector2, [{
key: "multiple",
value: function multiple() {
return this.range.multiple();
}
}, {
key: "setIndexes",
value: function setIndexes(ri, ci) {
this.ri = ri;
this.ci = ci;
}
}, {
key: "size",
value: function size() {
return this.range.size();
}
}]);
}();
var Scroll = /* @__PURE__ */ _createClass(function Scroll2() {
_classCallCheck(this, Scroll2);
this.x = 0;
this.y = 0;
this.ri = 0;
this.ci = 0;
});
var History = /* @__PURE__ */ function() {
function History2() {
_classCallCheck(this, History2);
this.undoItems = [];
this.redoItems = [];
}
return _createClass(History2, [{
key: "add",
value: function add(data) {
this.undoItems.push(JSON.stringify(data));
this.redoItems = [];
}
}, {
key: "canUndo",
value: function canUndo() {
return this.undoItems.length > 0;
}
}, {
key: "canRedo",
value: function canRedo() {
return this.redoItems.length > 0;
}
}, {
key: "undo",
value: function undo(currentd, cb) {
var undoItems = this.undoItems, redoItems = this.redoItems;
if (this.canUndo()) {
redoItems.push(JSON.stringify(currentd));
cb(JSON.parse(undoItems.pop()));
}
}
}, {
key: "redo",
value: function redo(currentd, cb) {
var undoItems = this.undoItems, redoItems = this.redoItems;
if (this.canRedo()) {
undoItems.push(JSON.stringify(currentd));
cb(JSON.parse(redoItems.pop()));
}
}
}]);
}();
var Clipboard = /* @__PURE__ */ function() {
function Clipboard2() {
_classCallCheck(this, Clipboard2);
this.range = null;
this.state = "clear";
}
return _createClass(Clipboard2, [{
key: "copy",
value: function copy2(cellRange) {
this.range = cellRange;
this.state = "copy";
return this;
}
}, {
key: "cut",
value: function cut2(cellRange) {
this.range = cellRange;
this.state = "cut";
return this;
}
}, {
key: "isCopy",
value: function isCopy() {
return this.state === "copy";
}
}, {
key: "isCut",
value: function isCut() {
return this.state === "cut";
}
}, {
key: "isClear",
value: function isClear() {
return this.state === "clear";
}
}, {
key: "clear",
value: function clear() {
this.range = null;
this.state = "clear";
}
}]);
}();
var Filter = /* @__PURE__ */ function() {
function Filter2(ci, operator, value) {
_classCallCheck(this, Filter2);
this.ci = ci;
this.operator = operator;
this.value = value;
}
return _createClass(Filter2, [{
key: "set",
value: function set(operator, value) {
this.operator = operator;
this.value = value;
}
}, {
key: "includes",
value: function includes(v) {
var operator = this.operator, value = this.value;
if (operator === "all") {
return true;
}
if (operator === "in") {
return value.includes(v);
}
return false;
}
}, {
key: "vlength",
value: function vlength() {
var operator = this.operator, value = this.value;
if (operator === "in") {
return value.length;
}
return 0;
}
}, {
key: "getData",
value: function getData2() {
var ci = this.ci, operator = this.operator, value = this.value;
return {
ci,
operator,
value
};
}
}]);
}();
var Sort = /* @__PURE__ */ function() {
function Sort2(ci, order) {
_classCallCheck(this, Sort2);
this.ci = ci;
this.order = order;
}
return _createClass(Sort2, [{
key: "asc",
value: function asc() {
return this.order === "asc";
}
}, {
key: "desc",
value: function desc() {
return this.order === "desc";
}
}]);
}();
var AutoFilter = /* @__PURE__ */ function() {
function AutoFilter2() {
_classCallCheck(this, AutoFilter2);
this.ref = null;
this.filters = [];
this.sort = null;
}
return _createClass(AutoFilter2, [{
key: "setData",
value: function setData(_ref) {
var ref2 = _ref.ref, filters = _ref.filters, sort = _ref.sort;
if (ref2 != null) {
this.ref = ref2;
this.filters = filters.map(function(it) {
return new Filter(it.ci, it.operator, it.value);
});
if (sort) {
this.sort = new Sort(sort.ci, sort.order);
}
}
}
}, {
key: "getData",
value: function getData2() {
if (this.active()) {
var ref2 = this.ref, filters = this.filters, sort = this.sort;
return {
ref: ref2,
filters: filters.map(function(it) {
return it.getData();
}),
sort
};
}
return {};
}
}, {
key: "addFilter",
value: function addFilter(ci, operator, value) {
var filter = this.getFilter(ci);
if (filter == null) {
this.filters.push(new Filter(ci, operator, value));
} else {
filter.set(operator, value);
}
}
}, {
key: "setSort",
value: function setSort(ci, order) {
this.sort = order ? new Sort(ci, order) : null;
}
}, {
key: "includes",
value: function includes(ri, ci) {
if (this.active()) {
return this.hrange().includes(ri, ci);
}
return false;
}
}, {
key: "getSort",
value: function getSort(ci) {
var sort = this.sort;
if (sort && sort.ci === ci) {
return sort;
}
return null;
}
}, {
key: "getFilter",
value: function getFilter(ci) {
var filters = this.filters;
for (var i = 0; i < filters.length; i += 1) {
if (filters[i].ci === ci) {
return filters[i];
}
}
return null;
}
}, {
key: "filteredRows",
value: function filteredRows(getCell) {
var rset = /* @__PURE__ */ new Set();
var fset = /* @__PURE__ */ new Set();
if (this.active()) {
var _this$range = this.range(), sri = _this$range.sri, eri = _this$range.eri;
var filters = this.filters;
for (var ri = sri + 1; ri <= eri; ri += 1) {
for (var i = 0; i < filters.length; i += 1) {
var filter = filters[i];
var cell = getCell(ri, filter.ci);
var ctext = cell ? cell.text : "";
if (!filter.includes(ctext)) {
rset.add(ri);
break;
} else {
fset.add(ri);
}
}
}
}
return {
rset,
fset
};
}
}, {
key: "items",
value: function items(ci, getCell) {
var m = {};
if (this.active()) {
var _this$range2 = this.range(), sri = _this$range2.sri, eri = _this$range2.eri;
for (var ri = sri + 1; ri <= eri; ri += 1) {
var cell = getCell(ri, ci);
if (cell !== null && !/^\s*$/.test(cell.text)) {
var key = cell.text;
var cnt = (m[key] || 0) + 1;
m[key] = cnt;
} else {
m[""] = (m[""] || 0) + 1;
}
}
}
return m;
}
}, {
key: "range",
value: function range() {
return CellRange.valueOf(this.ref);
}
}, {
key: "hrange",
value: function hrange() {
var r = this.range();
r.eri = r.sri;
return r;
}
}, {
key: "clear",
value: function clear() {
this.ref = null;
this.filters = [];
this.sort = null;
}
}, {
key: "active",
value: function active() {
return this.ref !== null;
}
}]);
}();
var Merges = /* @__PURE__ */ function() {
function Merges2() {
var d = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
_classCallCheck(this, Merges2);
this._ = d;
}
return _createClass(Merges2, [{
key: "forEach",
value: function forEach(cb) {
this._.forEach(cb);
}
}, {
key: "deleteWithin",
value: function deleteWithin(cr) {
this._ = this._.filter(function(it) {
return !it.within(cr);
});
}
}, {
key: "getFirstIncludes",
value: function getFirstIncludes(ri, ci) {
for (var i = 0; i < this._.length; i += 1) {
var it = this._[i];
if (it.includes(ri, ci)) {
return it;
}
}
return null;
}
}, {
key: "filterIntersects",
value: function filterIntersects(cellRange) {
return new Merges2(this._.filter(function(it) {
return it.intersects(cellRange);
}));
}
}, {
key: "intersects",
value: function intersects(cellRange) {
for (var i = 0; i < this._.length; i += 1) {
var it = this._[i];
if (it.intersects(cellRange)) {
return true;
}
}
return false;
}
}, {
key: "union",
value: function union(cellRange) {
var cr = cellRange;
this._.forEach(function(it) {
if (it.intersects(cr)) {
cr = it.union(cr);
}
});
return cr;
}
}, {
key: "add",
value: function add(cr) {
this.deleteWithin(cr);
this._.push(cr);
}
// type: row | column
}, {
key: "shift",
value: function shift(type, index2, n, cbWithin) {
this._.forEach(function(cellRange) {
var sri = cellRange.sri, sci = cellRange.sci, eri = cellRange.eri, eci = cellRange.eci;
var range = cellRange;
if (type === "row") {
if (sri >= index2) {
range.sri += n;
range.eri += n;
} else if (sri < index2 && index2 <= eri) {
range.eri += n;
cbWithin(sri, sci, n, 0);
}
} else if (type === "column") {
if (sci >= index2) {
range.sci += n;
range.eci += n;
} else if (sci < index2 && index2 <= eci) {
range.eci += n;
cbWithin(sri, sci, 0, n);
}
}
});
}
}, {
key: "move",
value: function move(cellRange, rn, cn) {
this._.forEach(function(it1) {
var it = it1;
if (it.within(cellRange)) {
it.eri += rn;
it.sri += rn;
it.sci += cn;
it.eci += cn;
}
});
}
}, {
key: "setData",
value: function setData(merges) {
this._ = merges.map(function(merge2) {
return CellRange.valueOf(merge2);
});
return this;
}
}, {
key: "getData",
value: function getData2() {
return this._.map(function(merge2) {
return merge2.toString();
});
}
}]);
}();
function cloneDeep(obj) {
return JSON.parse(JSON.stringify(obj));
}
var _mergeDeep = function mergeDeep() {
var object = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
sources[_key - 1] = arguments[_key];
}
sources.forEach(function(source) {
Object.keys(source).forEach(function(key) {
var v = source[key];
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
object[key] = v;
} else if (typeof v !== "function" && !Array.isArray(v) && v instanceof Object) {
object[key] = object[key] || {};
_mergeDeep(object[key], v);
} else {
object[key] = v;
}
});
});
return object;
};
function equals(obj1, obj2) {
var keys2 = Object.keys(obj1);
if (keys2.length !== Object.keys(obj2).length)
return false;
for (var i = 0; i < keys2.length; i += 1) {
var k = keys2[i];
var v1 = obj1[k];
var v2 = obj2[k];
if (v2 === void 0)
return false;
if (typeof v1 === "string" || typeof v1 === "number" || typeof v1 === "boolean") {
if (v1 !== v2)
return false;
} else if (Array.isArray(v1)) {
if (v1.length !== v2.length)
return false;
for (var ai = 0; ai < v1.length; ai += 1) {
if (!equals(v1[ai], v2[ai]))
return false;
}
} else if (typeof v1 !== "function" && !Array.isArray(v1) && v1 instanceof Object) {
if (!equals(v1, v2))
return false;
}
}
return true;
}
var sum = function sum2(objOrAry) {
var cb = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : function(value) {
return value;
};
var total = 0;
var size = 0;
Object.keys(objOrAry).forEach(function(key) {
total += cb(objOrAry[key], key);
size += 1;
});
return [total, size];
};
function deleteProperty(obj, property) {
var oldv = obj["".concat(property)];
delete obj["".concat(property)];
return oldv;
}
function rangeReduceIf(min, max, inits, initv, ifv, getv) {
var s = inits;
var v = initv;
var i = min;
for (; i < max; i += 1) {
if (s > ifv)
break;
v = getv(i);
s += v;
}
return [i, s - v, v];
}
function rangeSum(min, max, getv) {
var s = 0;
for (var i = min; i < max; i += 1) {
s += getv(i);
}
return s;
}
function rangeEach(min, max, cb) {
for (var i = min; i < max; i += 1) {
cb(i);
}
}
function arrayEquals(a1, a2) {
if (a1.length === a2.length) {
for (var i = 0; i < a1.length; i += 1) {
if (a1[i] !== a2[i])
return false;
}
} else
return false;
return true;
}
function digits(a) {
var v = "".concat(a);
var ret = 0;
var flag = false;
for (var i = 0; i < v.length; i += 1) {
if (flag === true)
ret += 1;
if (v.charAt(i) === ".")
flag = true;
}
return ret;
}
function numberCalc(type, a1, a2) {
if (Number.isNaN(a1) || Number.isNaN(a2)) {
return a1 + type + a2;
}
var al1 = digits(a1);
var al2 = digits(a2);
var num1 = Number(a1);
var num2 = Number(a2);
var ret = 0;
if (type === "-") {
ret = num1 - num2;
} else if (type === "+") {
ret = num1 + num2;
} else if (type === "*") {
ret = num1 * num2;
} else if (type === "/") {
ret = num1 / num2;
if (digits(ret) > 5)
return ret.toFixed(2);
return ret;
}
return ret.toFixed(Math.max(al1, al2));
}
const helper = {
cloneDeep,
merge: function merge() {
for (var _len2 = arguments.length, sources = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
sources[_key2] = arguments[_key2];
}
return _mergeDeep.apply(void 0, [{}].concat(sources));
},
equals,
arrayEquals,
sum,
rangeEach,
rangeSum,
rangeReduceIf,
deleteProperty,
numberCalc
};
var Rows = /* @__PURE__ */ function() {
function Rows2(_ref) {
var len = _ref.len, height2 = _ref.height;
_classCallCheck(this, Rows2);
this._ = {};
this.len = len;
this.height = height2;
}
return _createClass(Rows2, [{
key: "getHeight",
value: function getHeight(ri) {
if (this.isHide(ri))
return 0;
var row = this.get(ri);
if (row && row.height) {
return row.height;
}
return this.height;
}
}, {
key: "setHeight",
value: function setHeight(ri, v) {
var row = this.getOrNew(ri);
row.height = v;
}
}, {
key: "unhide",
value: function unhide(idx) {
var index2 = idx;
while (index2 > 0) {
index2 -= 1;
if (this.isHide(index2)) {
this.setHide(index2, false);
} else
break;
}
}
}, {
key: "isHide",
value: function isHide(ri) {
var row = this.get(ri);
return row && row.hide;
}
}, {
key: "setHide",
value: function setHide(ri, v) {
var row = this.getOrNew(ri);
if (v === true)
row.hide = true;
else
delete row.hide;
}
}, {
key: "setStyle",
value: function setStyle(ri, style) {
var row = this.getOrNew(ri);
row.style = style;
}
}, {
key: "sumHeight",
value: function sumHeight(min, max, exceptSet) {
var _this = this;
return helper.rangeSum(min, max, function(i) {
if (exceptSet && exceptSet.has(i))
return 0;
return _this.getHeight(i);
});
}
}, {
key: "totalHeight",
value: function totalHeight() {
return this.sumHeight(0, this.len);
}
}, {
key: "get",
value: function get(ri) {
return this._[ri];
}
}, {
key: "getOrNew",
value: function getOrNew(ri) {
this._[ri] = this._[ri] || {
cells: {}
};
return this._[ri];
}
}, {
key: "getCell",
value: function getCell(ri, ci) {
var row = this.get(ri);
if (row !== void 0 && row.cells !== void 0 && row.cells[ci] !== void 0) {
return row.cells[ci];
}
return null;
}
}, {
key: "getCellMerge",
value: function getCellMerge(ri, ci) {
var cell = this.getCell(ri, ci);
if (cell && cell.merge)
return cell.merge;
return [0, 0];
}
}, {
key: "getCellOrNew",
value: function getCellOrNew(ri, ci) {
var row = this.getOrNew(ri);
row.cells[ci] = row.cells[ci] || {};
return row.cells[ci];
}
// what: all | text | format
}, {
key: "setCell",
value: function setCell(ri, ci, cell) {
var what = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "all";
var row = this.getOrNew(ri);
if (what === "all") {
row.cells[ci] = cell;
} else if (what === "text") {
row.cells[ci] = row.cells[ci] || {};
row.cells[ci].text = cell.text;
} else if (what === "format") {
row.cells[ci] = row.cells[ci] || {};
row.cells[ci].style = cell.style;
if (cell.merge)
row.cells[ci].merge = cell.merge;
}
}
}, {
key: "setCellText",
value: function setCellText(ri, ci, text) {
var cell = this.getCellOrNew(ri, ci);
if (cell.editable !== false)
cell.text = text;
}
// what: all | format | text
}, {
key: "copyPaste",
value: function copyPaste2(srcCellRange, dstCellRange, what) {
var _this2 = this;
var autofill = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
var cb = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : function() {
};
var sri = srcCellRange.sri, sci = srcCellRange.sci, eri = srcCellRange.eri, eci = srcCellRange.eci;
var dsri = dstCellRange.sri;
var dsci = dstCellRange.sci;
var deri = dstCellRange.eri;
var deci = dstCellRange.eci;
var _srcCellRange$size = srcCellRange.size(), _srcCellRange$size2 = _slicedToArray(_srcCellRange$size, 2), rn = _srcCellRange$size2[0], cn = _srcCellRange$size2[1];
var _dstCellRange$size = dstCellRange.size(), _dstCellRange$size2 = _slicedToArray(_dstCellRange$size, 2), drn = _dstCellRange$size2[0], dcn = _dstCellRange$size2[1];
var isAdd = true;
var dn = 0;
if (deri < sri || deci < sci) {
isAdd = false;
if (deri < sri)
dn = drn;
else
dn = dcn;
}
for (var i = sri; i <= eri; i += 1) {
if (this._[i]) {
for (var j = sci; j <= eci; j += 1) {
if (this._[i].cells && this._[i].cells[j]) {
for (var ii = dsri; ii <= deri; ii += rn) {
var _loop = function _loop2() {
var nri = ii + (i - sri);
var nci = jj + (j - sci);
var ncell = helper.cloneDeep(_this2._[i].cells[j]);
if (autofill && ncell && ncell.text && ncell.text.length > 0) {
var text = ncell.text;
var n = jj - dsci + (ii - dsri) + 2;
if (!isAdd) {
n -= dn + 1;
}
if (text[0] === "=") {
ncell.text = text.replace(/[a-zA-Z]{1,3}\d+/g, function(word) {
var xn = 0, yn = 0;
if (sri === dsri) {
xn = n - 1;
} else {
yn = n - 1;
}
if (/^\d+$/.test(word))
return word;
return expr2expr(word, xn, yn);
});
} else if (rn <= 1 && cn > 1 && (dsri > eri || deri < sri) || cn <= 1 && rn > 1 && (dsci > eci || deci < sci) || rn <= 1 && cn <= 1) {
var result = /[\\.\d]+$/.exec(text);
if (result !== null) {
var index2 = Number(result[0]) + n - 1;
ncell.text = text.substring(0, result.index) + index2;
}
}
}
_this2.setCell(nri, nci, ncell, what);
cb(nri, nci, ncell);
};
for (var jj = dsci; jj <= deci; jj += cn) {
_loop();
}
}
}
}
}
}
}
}, {
key: "cutPaste",
value: function cutPaste2(srcCellRange, dstCellRange) {
var _this3 = this;
var ncellmm = {};
this.each(function(ri) {
_this3.eachCells(ri, function(ci) {
var nri = parseInt(ri, 10);
var nci = parseInt(ci, 10);
if (srcCellRange.includes(ri, ci)) {
nri = dstCellRange.sri + (nri - srcCellRange.sri);
nci = dstCellRange.sci + (nci - srcCellRange.sci);
}
ncellmm[nri] = ncellmm[nri] || {
cells: {}
};
ncellmm[nri].cells[nci] = _this3._[ri].cells[ci];
});
});
this._ = ncellmm;
}
// src: Array<Array<String>>
}, {
key: "paste",
value: function paste2(src, dstCellRange) {
var _this4 = this;
if (src.length <= 0)
return;
var sri = dstCellRange.sri, sci = dstCellRange.sci;
src.forEach(function(row, i) {
var ri = sri + i;
row.forEach(function(cell, j) {
var ci = sci + j;
_this4.setCellText(ri, ci, cell);
});
});
}
}, {
key: "insert",
value: function insert(sri) {
var _this5 = this;
var n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
var ndata = {};
this.each(function(ri, row) {
var nri = parseInt(ri, 10);
if (nri >= sri) {
nri += n;
_this5.eachCells(ri, function(ci, cell) {
if (cell.text && cell.text[0] === "=") {
cell.text = cell.text.replace(/[a-zA-Z]{1,3}\d+/g, function(word) {
return expr2expr(word, 0, n, function(x, y) {
return y >= sri;
});
});
}
});
}
ndata[nri] = row;
});
this._ = ndata;
this.len += n;
}
}, {
key: "delete",
value: function _delete(sri, eri) {
var _this6 = this;
var n = eri - sri + 1;
var ndata = {};
this.each(function(ri, row) {
var nri = parseInt(ri, 10);
if (nri < sri) {
ndata[nri] = row;
} else if (ri > eri) {
ndata[nri - n] = row;
_this6.eachCells(ri, function(ci, cell) {
if (cell.text && cell.text[0] === "=") {
cell.text = cell.text.replace(/[a-zA-Z]{1,3}\d+/g, function(word) {
return expr2expr(word, 0, -n, function(x, y) {
return y > eri;
});
});
}
});
}
});
this._ = ndata;
this.len -= n;
}
}, {
key: "insertColumn",
value: function insertColumn(sci) {
var _this7 = this;
var n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
this.each(function(ri, row) {
var rndata = {};
_this7.eachCells(ri, function(ci, cell) {
var nci = parseInt(ci, 10);
if (nci >= sci) {
nci += n;
if (cell.text && cell.text[0] === "=") {
cell.text = cell.text.replace(/[a-zA-Z]{1,3}\d+/g, function(word) {
return expr2expr(word, n, 0, function(x) {
return x >= sci;
});
});
}
}
rndata[nci] = cell;
});
row.cells = rndata;
});
}
}, {
key: "deleteColumn",
value: function deleteColumn(sci, eci) {
var _this8 = this;
var n = eci - sci + 1;
this.each(function(ri, row) {
var rndata = {};
_this8.eachCells(ri, function(ci, cell) {
var nci = parseInt(ci, 10);
if (nci < sci) {
rndata[nci] = cell;
} else if (nci > eci) {
rndata[nci - n] = cell;
if (cell.text && cell.text[0] === "=") {
cell.text = cell.text.replace(/[a-zA-Z]{1,3}\d+/g, function(word) {
return expr2expr(word, -n, 0, function(x) {
return x > eci;
});
});
}
}
});
row.cells = rndata;
});
}
// what: all | text | format | merge
}, {
key: "deleteCells",
value: function deleteCells(cellRange) {
var _this9 = this;
var what = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all";
cellRange.each(function(i, j) {
_this9.deleteCell(i, j, what);
});
}
// what: all | text | format | merge
}, {
key: "deleteCell",
value: function deleteCell(ri, ci) {
var what = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "all";
var row = this.get(ri);
if (row !== null) {
var cell = this.getCell(ri, ci);
if (cell !== null && cell.editable !== false) {
if (what === "all") {
delete row.cells[ci];
} else if (what === "text") {
if (cell.text)
delete cell.text;
if (cell.value)
delete cell.value;
} else if (what === "format") {
if (cell.style !== void 0)
delete cell.style;
if (cell.merge)
delete cell.merge;
} else if (what === "merge") {
if (cell.merge)
delete cell.merge;
}
}
}
}
}, {
key: "maxCell",
value: function maxCell() {
var keys2 = Object.keys(this._);
var ri = keys2[keys2.length - 1];
var col = this._[ri];
if (col) {
var cells = col.cells;
var ks = Object.keys(cells);
var ci = ks[ks.length - 1];
return [parseInt(ri, 10), parseInt(ci, 10)];
}
return [0, 0];
}
}, {
key: "each",
value: function each(cb) {
Object.entries(this._).forEach(function(_ref2) {
var _ref3 = _slicedToArray(_ref2, 2), ri = _ref3[0], row = _ref3[1];
cb(ri, row);
});
}
}, {
key: "eachCells",
value: function eachCells(ri, cb) {
if (this._[ri] && this._[ri].cells) {
Object.entries(this._[ri].cells).forEach(function(_ref4) {
var _ref5 = _slicedToArray(_ref4, 2), ci = _ref5[0], cell = _ref5[1];
cb(ci, cell);
});
}
}
}, {
key: "setData",
value: function setData(d) {
if (d.len) {
this.len = d.len;
delete d.len;
}
this._ = d;
}
}, {
key: "getData",
value: function getData2() {
var len = this.len;
return Object.assign({
len
}, this._);
}
}]);
}();
var Cols = /* @__PURE__ */ function() {
function Cols2(_ref) {
var len = _ref.len, width2 = _ref.width, indexWidth = _ref.indexWidth, minWidth = _ref.minWidth;
_classCallCheck(this, Cols2);
this._ = {};
this.len = len;
this.width = width2;
this.indexWidth = indexWidth;
this.minWidth = minWidth;
}
return _createClass(Cols2, [{
key: "setData",
value: function setData(d) {
if (d.len) {
this.len = d.len;
delete d.len;
}
this._ = d;
}
}, {
key: "getData",
value: function getData2() {
var len = this.len;
return Object.assign({
len
}, this._);
}
}, {
key: "getWidth",
value: function getWidth(i) {
if (this.isHide(i))
return 0;
var col = this._[i];
if (col && col.width) {
return col.width;
}
return this.width;
}
}, {
key: "getOrNew",
value: function getOrNew(ci) {
this._[ci] = this._[ci] || {};
return this._[ci];
}
}, {
key: "setWidth",
value: function setWidth(ci, width2) {
var col = this.getOrNew(ci);
col.width = width2;
}
}, {
key: "unhide",
value: function unhide(idx) {
var index2 = idx;
while (index2 > 0) {
index2 -= 1;
if (this.isHide(index2)) {
this.setHide(index2, false);
} else
break;
}
}
}, {
key: "isHide",
value: function isHide(ci) {
var col = this._[ci];
return col && col.hide;
}
}, {
key: "setHide",
value: function setHide(ci, v) {
var col = this.getOrNew(ci);
if (v === true)
col.hide = true;
else
delete col.hide;
}
}, {
key: "setStyle",
value: function setStyle(ci, style) {
var col = this.getOrNew(ci);
col.style = style;
}
}, {
key: "sumWidth",
value: function sumWidth(min, max) {
var _this = this;
return helper.rangeSum(min, max, f