UNPKG

vue-files-preview-inno

Version:

A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.

217 lines (216 loc) 7.84 kB
import { __exports as h } from "../../../_virtual/marks.mjs"; import "./svg.mjs"; import "./events.mjs"; import { __exports as k } from "../../../_virtual/svg.mjs"; import { __exports as w } from "../../../_virtual/events.mjs"; var p, m; Object.defineProperty(h, "__esModule", { value: !0 }); var C = h.Underline = m = h.Highlight = h.Mark = p = h.Pane = void 0, O = function n(t, e, i) { t === null && (t = Function.prototype); var r = Object.getOwnPropertyDescriptor(t, e); if (r === void 0) { var a = Object.getPrototypeOf(t); return a === null ? void 0 : n(a, e, i); } else { if ("value" in r) return r.value; var o = r.get; return o === void 0 ? void 0 : o.call(i); } }, v = /* @__PURE__ */ function() { function n(t, e) { for (var i = 0; i < e.length; i++) { var r = e[i]; r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(t, r.key, r); } } return function(t, e, i) { return e && n(t.prototype, e), i && n(t, i), t; }; }(), R = k, c = y(R), A = w, P = y(A); function y(n) { return n && n.__esModule ? n : { default: n }; } function b(n, t) { if (!n) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return t && (typeof t == "object" || typeof t == "function") ? t : n; } function _(n, t) { if (typeof t != "function" && t !== null) throw new TypeError("Super expression must either be null or a function, not " + typeof t); n.prototype = Object.create(t && t.prototype, { constructor: { value: n, enumerable: !1, writable: !0, configurable: !0 } }), t && (Object.setPrototypeOf ? Object.setPrototypeOf(n, t) : n.__proto__ = t); } function g(n, t) { if (!(n instanceof t)) throw new TypeError("Cannot call a class as a function"); } p = h.Pane = function() { function n(t) { var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : document.body; g(this, n), this.target = t, this.element = c.default.createElement("svg"), this.marks = [], this.element.style.position = "absolute", this.element.setAttribute("pointer-events", "none"), P.default.proxyMouse(this.target, this.marks), this.container = e, this.container.appendChild(this.element), this.render(); } return v(n, [{ key: "addMark", value: function(e) { var i = c.default.createElement("g"); return this.element.appendChild(i), e.bind(i, this.container), this.marks.push(e), e.render(), e; } }, { key: "removeMark", value: function(e) { var i = this.marks.indexOf(e); if (i !== -1) { var r = e.unbind(); this.element.removeChild(r), this.marks.splice(i, 1); } } }, { key: "render", value: function() { B(this.element, M(this.target, this.container)); var e = !0, i = !1, r = void 0; try { for (var a = this.marks[Symbol.iterator](), o; !(e = (o = a.next()).done); e = !0) { var s = o.value; s.render(); } } catch (d) { i = !0, r = d; } finally { try { !e && a.return && a.return(); } finally { if (i) throw r; } } } }]), n; }(); var x = h.Mark = function() { function n() { g(this, n), this.element = null; } return v(n, [{ key: "bind", value: function(e, i) { this.element = e, this.container = i; } }, { key: "unbind", value: function() { var e = this.element; return this.element = null, e; } }, { key: "render", value: function() { } }, { key: "dispatchEvent", value: function(e) { this.element && this.element.dispatchEvent(e); } }, { key: "getBoundingClientRect", value: function() { return this.element.getBoundingClientRect(); } }, { key: "getClientRects", value: function() { for (var e = [], i = this.element.firstChild; i; ) e.push(i.getBoundingClientRect()), i = i.nextSibling; return e; } }, { key: "filteredRanges", value: function() { var e = Array.from(this.range.getClientRects()); return e.filter(function(i) { for (var r = 0; r < e.length; r++) { if (e[r] === i) return !0; var a = H(e[r], i); if (a) return !1; } return !0; }); } }]), n; }(), E = m = h.Highlight = function(n) { _(t, n); function t(e, i, r, a) { g(this, t); var o = b(this, (t.__proto__ || Object.getPrototypeOf(t)).call(this)); return o.range = e, o.className = i, o.data = r || {}, o.attributes = a || {}, o; } return v(t, [{ key: "bind", value: function(i, r) { O(t.prototype.__proto__ || Object.getPrototypeOf(t.prototype), "bind", this).call(this, i, r); for (var a in this.data) this.data.hasOwnProperty(a) && (this.element.dataset[a] = this.data[a]); for (var a in this.attributes) this.attributes.hasOwnProperty(a) && this.element.setAttribute(a, this.attributes[a]); this.className && this.element.classList.add(this.className); } }, { key: "render", value: function() { for (; this.element.firstChild; ) this.element.removeChild(this.element.firstChild); for (var i = this.element.ownerDocument.createDocumentFragment(), r = this.filteredRanges(), a = this.element.getBoundingClientRect(), o = this.container.getBoundingClientRect(), s = 0, d = r.length; s < d; s++) { var l = r[s], u = c.default.createElement("rect"); u.setAttribute("x", l.left - a.left + o.left), u.setAttribute("y", l.top - a.top + o.top), u.setAttribute("height", l.height), u.setAttribute("width", l.width), i.appendChild(u); } this.element.appendChild(i); } }]), t; }(x); C = h.Underline = function(n) { _(t, n); function t(e, i, r, a) { return g(this, t), b(this, (t.__proto__ || Object.getPrototypeOf(t)).call(this, e, i, r, a)); } return v(t, [{ key: "render", value: function() { for (; this.element.firstChild; ) this.element.removeChild(this.element.firstChild); for (var i = this.element.ownerDocument.createDocumentFragment(), r = this.filteredRanges(), a = this.element.getBoundingClientRect(), o = this.container.getBoundingClientRect(), s = 0, d = r.length; s < d; s++) { var l = r[s], u = c.default.createElement("rect"); u.setAttribute("x", l.left - a.left + o.left), u.setAttribute("y", l.top - a.top + o.top), u.setAttribute("height", l.height), u.setAttribute("width", l.width), u.setAttribute("fill", "none"); var f = c.default.createElement("line"); f.setAttribute("x1", l.left - a.left + o.left), f.setAttribute("x2", l.left - a.left + o.left + l.width), f.setAttribute("y1", l.top - a.top + o.top + l.height - 1), f.setAttribute("y2", l.top - a.top + o.top + l.height - 1), f.setAttribute("stroke-width", 1), f.setAttribute("stroke", "black"), f.setAttribute("stroke-linecap", "square"), i.appendChild(u), i.appendChild(f); } this.element.appendChild(i); } }]), t; }(E); function M(n, t) { var e = t.getBoundingClientRect(), i = n.getBoundingClientRect(); return { top: i.top - e.top, left: i.left - e.left, height: n.scrollHeight, width: n.scrollWidth }; } function B(n, t) { n.style.setProperty("top", t.top + "px", "important"), n.style.setProperty("left", t.left + "px", "important"), n.style.setProperty("height", t.height + "px", "important"), n.style.setProperty("width", t.width + "px", "important"); } function H(n, t) { return t.right <= n.right && t.left >= n.left && t.top >= n.top && t.bottom <= n.bottom; } export { m as Highlight, p as Pane, C as Underline, h as default }; //# sourceMappingURL=marks.mjs.map