UNPKG

zan-poster

Version:

通过json在canvas上绘制图像, 基于cax画图框架开发, 本画图组件是json2canvas库的改造、优化版本 (详情查看README.md文档末说明)。

1,398 lines (1,397 loc) 71.3 kB
import { r as registerInstance, c as createEvent, h, g as getElement } from './index-86f0f68f.js'; function dt(s) { return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s; } var ut = /* @__PURE__ */ function() { function s(t, i) { var r = i.length, h, a; return r >= 2 ? (h = i.slice(0, r / 2), a = i.slice(r / 2, r), e(t, s(t, h), s(t, a))) : i.slice(); } function e(t, i, r) { for (var h = [], a = i.length, o = r.length; a > 0 && o > 0; ) t(i[0], r[0]) <= 0 ? (h.push(i.shift()), a--) : (h.push(r.shift()), o--); return a > 0 ? h.push.apply(h, i) : h.push.apply(h, r), h; } return s; }(), ft = /* @__PURE__ */ function() { function s(e, t, i) { var r, h; for (r = 0, h = t.length; r < h && !(e(t[r], i) > 0); r++) ; return r; } return s; }(), tt, et; tt = ut; et = ft; var gt = function() { var s; s = {}; function e(n) { return function() { return n; }; } function t(n) { n = n || {}, this.config = n, this.config.childrenPropertyName = n.childrenPropertyName || "children", this.config.modelComparatorFn = n.modelComparatorFn; } function i(n, l) { return l.parent = n, n.children.push(l), l; } function r(n, l) { this.config = n, this.model = l, this.children = []; } t.prototype.parse = function(n) { var l, c, d; if (!(n instanceof Object)) throw new TypeError("Model must be of type object."); if (d = new r(this.config, n), n[this.config.childrenPropertyName] instanceof Array) for (this.config.modelComparatorFn && (n[this.config.childrenPropertyName] = tt( this.config.modelComparatorFn, n[this.config.childrenPropertyName] )), l = 0, c = n[this.config.childrenPropertyName].length; l < c; l++) i(d, this.parse(n[this.config.childrenPropertyName][l])); return d; }; function h(n) { return typeof n.config.modelComparatorFn == "function"; } r.prototype.isRoot = function() { return this.parent === void 0; }, r.prototype.hasChildren = function() { return this.children.length > 0; }; function a(n, l, c) { var d; if (!(l instanceof r)) throw new TypeError("Child must be of type Node."); if (l.parent = n, n.model[n.config.childrenPropertyName] instanceof Array || (n.model[n.config.childrenPropertyName] = []), h(n)) d = et( n.config.modelComparatorFn, n.model[n.config.childrenPropertyName], l.model ), n.model[n.config.childrenPropertyName].splice(d, 0, l.model), n.children.splice(d, 0, l); else if (c === void 0) n.model[n.config.childrenPropertyName].push(l.model), n.children.push(l); else { if (c < 0 || c > n.children.length) throw new Error("Invalid index."); n.model[n.config.childrenPropertyName].splice(c, 0, l.model), n.children.splice(c, 0, l); } return l; } r.prototype.addChild = function(n) { return a(this, n); }, r.prototype.addChildAtIndex = function(n, l) { if (h(this)) throw new Error("Cannot add child at index when using a comparator function."); return a(this, n, l); }, r.prototype.setIndex = function(n) { if (h(this)) throw new Error("Cannot set node index when using a comparator function."); if (this.isRoot()) { if (n === 0) return this; throw new Error("Invalid index."); } if (n < 0 || n >= this.parent.children.length) throw new Error("Invalid index."); var l = this.parent.children.indexOf(this); return this.parent.children.splice(n, 0, this.parent.children.splice(l, 1)[0]), this.parent.model[this.parent.config.childrenPropertyName].splice(n, 0, this.parent.model[this.parent.config.childrenPropertyName].splice(l, 1)[0]), this; }, r.prototype.getPath = function() { var n = []; return function l(c) { n.unshift(c), c.isRoot() || l(c.parent); }(this), n; }, r.prototype.getIndex = function() { return this.isRoot() ? 0 : this.parent.children.indexOf(this); }; function o() { var n = {}; if (arguments.length === 1 ? typeof arguments[0] == "function" ? n.fn = arguments[0] : n.options = arguments[0] : arguments.length === 2 ? typeof arguments[0] == "function" ? (n.fn = arguments[0], n.ctx = arguments[1]) : (n.options = arguments[0], n.fn = arguments[1]) : (n.options = arguments[0], n.fn = arguments[1], n.ctx = arguments[2]), n.options = n.options || {}, n.options.strategy || (n.options.strategy = "pre"), !s[n.options.strategy]) throw new Error("Unknown tree walk strategy. Valid strategies are 'pre' [default], 'post' and 'breadth'."); return n; } return r.prototype.walk = function() { var n; n = o.apply(this, arguments), s[n.options.strategy].call(this, n.fn, n.ctx); }, s.pre = function n(l, c) { var d, u, f; for (f = l.call(c, this), d = 0, u = this.children.length; d < u; d++) { if (f === !1) return !1; f = n.call(this.children[d], l, c); } return f; }, s.post = function n(l, c) { var d, u, f; for (d = 0, u = this.children.length; d < u; d++) if (f = n.call(this.children[d], l, c), f === !1) return !1; return f = l.call(c, this), f; }, s.breadth = function(l, c) { var d = [this]; (function u() { var f, p, m; if (d.length !== 0) { for (m = d.shift(), f = 0, p = m.children.length; f < p; f++) d.push(m.children[f]); l.call(c, m) !== !1 && u(); } })(); }, r.prototype.all = function() { var n, l = []; return n = o.apply(this, arguments), n.fn = n.fn || e(!0), s[n.options.strategy].call(this, function(c) { n.fn.call(n.ctx, c) && l.push(c); }, n.ctx), l; }, r.prototype.first = function() { var n, l; return n = o.apply(this, arguments), n.fn = n.fn || e(!0), s[n.options.strategy].call(this, function(c) { if (n.fn.call(n.ctx, c)) return l = c, !1; }, n.ctx), l; }, r.prototype.drop = function() { var n; return this.isRoot() || (n = this.parent.children.indexOf(this), this.parent.children.splice(n, 1), this.parent.model[this.config.childrenPropertyName].splice(n, 1), this.parent = void 0, delete this.parent), this; }, t; }(); const pt = /* @__PURE__ */ dt(gt); let H = null; typeof wx < "u" && (wx.getSharedCanvas ? H = wx.getSharedCanvas() : wx.createCanvas && (H = wx.createCanvas())); const mt = H, D = 0.017453292519943295, xt = Math.PI * 2; class F { constructor(e, t, i, r, h, a) { return this.a = e != null ? e : 1, this.b = t || 0, this.c = i || 0, this.d = r != null ? r : 1, this.tx = h || 0, this.ty = a || 0, this; } identity() { return this.a = this.d = 1, this.b = this.c = this.tx = this.ty = 0, this; } appendTransform(e, t, i, r, h, a, o, n, l) { if (h % 360) var c = h * D, d = Math.cos(c), u = Math.sin(c); else d = 1, u = 0; return a || o ? (a *= D, o *= D, this.append(Math.cos(o), Math.sin(o), -Math.sin(a), Math.cos(a), e, t), this.append(d * i, u * i, -u * r, d * r, 0, 0)) : this.append(d * i, u * i, -u * r, d * r, e, t), (n || l) && (this.tx -= n * this.a + l * this.c, this.ty -= n * this.b + l * this.d), this; } append(e, t, i, r, h, a) { var o = this.a, n = this.b, l = this.c, c = this.d; return this.a = e * o + t * l, this.b = e * n + t * c, this.c = i * o + r * l, this.d = i * n + r * c, this.tx = h * o + a * l + this.tx, this.ty = h * n + a * c + this.ty, this; } initialize(e, t, i, r, h, a) { return this.a = e, this.b = t, this.c = i, this.d = r, this.tx = h, this.ty = a, this; } setValues(e, t, i, r, h, a) { return this.a = e != null ? e : 1, this.b = t || 0, this.c = i || 0, this.d = r != null ? r : 1, this.tx = h || 0, this.ty = a || 0, this; } invert() { let e = this.a, t = this.b, i = this.c, r = this.d, h = this.tx, a = e * r - t * i; return this.a = r / a, this.b = -t / a, this.c = -i / a, this.d = e / a, this.tx = (i * this.ty - r * h) / a, this.ty = -(e * this.ty - t * h) / a, this; } copy(e) { return this.setValues(e.a, e.b, e.c, e.d, e.tx, e.ty); } } F.decompose = function(s, e, t, i, r, h, a) { const o = -Math.atan2(-t, i), n = Math.atan2(e, s), l = Math.abs(o + n); l < 1e-5 || Math.abs(xt - l) < 1e-5 ? (a.rotation = n, s < 0 && i >= 0 && (a.rotation += a.rotation <= 0 ? Math.PI : -Math.PI), a.skewX = a.skewY = 0) : (a.rotation = 0, a.skewX = o, a.skewY = n), a.scaleX = Math.sqrt(s * s + e * e), a.scaleY = Math.sqrt(t * t + i * i), a.x = r, a.y = h; }; const wt = { stagePropagationStopped: {} }; class yt { constructor() { this._listeners = null, this._captureListeners = null; } addEventListener(e, t, i) { var r; i ? r = this._captureListeners = this._captureListeners || {} : r = this._listeners = this._listeners || {}; var h = r[e]; return h && this.removeEventListener(e, t, i), h = r[e], h ? h.push(t) : r[e] = [t], t; } removeEventListener(e, t, i) { var r = i ? this._captureListeners : this._listeners; if (r) { var h = r[e]; h && h.every((a, o) => a === t ? (h.splice(o, 1), !1) : !0); } } on(e, t, i) { this.addEventListener(e, t, i); } off(e, t, i) { this.removeEventListener(e, t, i); } dispatchEvent(e) { wt.stagePropagationStopped[e.type] = !1; for (var t = this, i = [t]; t.parent; ) i.push(t = t.parent); var r, h = i.length; for (r = h - 1; r >= 0 && !e.propagationStopped; r--) i[r]._dispatchEvent(e, 0); for (r = 0; r < h && !e.propagationStopped; r++) i[r]._dispatchEvent(e, 1); } _dispatchEvent(e, t) { if (e.target = this, this._captureListeners && t === 0) { let i = this._captureListeners[e.type]; i && i.forEach((r) => { r.call(this, e); }); } if (this._listeners && t === 1) { let i = this._listeners[e.type]; i && i.forEach((r) => { r.call(this, e); }); } } } var L = {}; L._nextID = 0; L.get = function() { return L._nextID++; }; class G extends yt { constructor() { super(), this.alpha = this.complexAlpha = this.scaleX = this.scaleY = 1, this.x = this.y = this.rotation = this.skewX = this.skewY = this.originX = this.originY = 0, this.cursor = null, this.visible = !0, this._matrix = new F(), this._hitMatrix = new F(), this.id = L.get(), this.clipGraphics = null, this.clipRuleNonzero = !0, this.fixed = !1, this.shadow = null, this.compositeOperation = null, this.absClipGraphics = null, this.absClipRuleNonzero = !0, this.cacheUpdating = !1; try { Object.defineProperties(this, { stage: { get: this._getStage }, scale: { get: function() { return this.scaleX; }, set: function(e) { this.scaleX = this.scaleY = e; } } }); } catch { } this.hitBox = null; } isVisible() { return this.visible && this.alpha > 0 && this.scaleX !== 0 && this.scaleY !== 0; } initAABB() { if ((this.width === void 0 || this.height === void 0) && !this.hitBox) return; let e, t, i = this.width, r = this.height, h = this._matrix, a = h.tx, o = h.ty; this.hitBox && (i = this.hitBox[2], r = this.hitBox[3], a = this.hitBox[0] * h.a + this.hitBox[1] * h.c + a, o = this.hitBox[0] * h.b + this.hitBox[1] * h.d + o); let n = i * h.a, l = i * h.b, c = r * h.c, d = r * h.d, u = a, f = a, p = o, m = o; (e = n + a) < u ? u = e : e > f && (f = e), (e = n + c + a) < u ? u = e : e > f && (f = e), (e = c + a) < u ? u = e : e > f && (f = e), (t = l + o) < p ? p = t : t > m && (m = t), (t = l + d + o) < p ? p = t : t > m && (m = t), (t = d + o) < p ? p = t : t > m && (m = t), this.AABB = [u, p, f - u, m - p], this.rectPoints = [ { x: a, y: o }, { x: n + a, y: l + o }, { x: n + c + a, y: l + d + o }, { x: c + a, y: d + o } ]; } destroy() { this.parent.remove(this); } hover(e, t, i) { this.on("mouseover", e), this.on("mouseout", t), i && this.on("mousemove", i); } // https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/clip clip(e, t) { this.clipGraphics = e, this.clipRuleNonzero = !t; } unclip() { this.clipGraphics = null; } absClip(e, t) { this.absClipGraphics = e, this.absClipRuleNonzero = !t; } unAbsClip() { this.absClipGraphics = null; } cache(e, t, i, r, h, a) { this._cacheData = { x: e || 0, y: t || 0, width: i || this.width, height: r || this.height, scale: h || 1 }, this.cacheUpdating = a, this.cacheCanvas || (typeof wx < "u" && wx.createCanvas ? this.cacheCanvas = wx.createCanvas() : this.cacheCanvas = document.createElement("canvas"), this.cacheCtx = this.cacheCanvas.getContext("2d")), this.cacheCanvas.width = this._cacheData.width * this._cacheData.scale, this.cacheCanvas.height = this._cacheData.height * this._cacheData.scale, this._readyToCache = !0; } uncache() { this.cacheCanvas = null; } filter(e, t) { t = Object.assign( {}, { x: 0, y: 0, width: this.width, height: this.height }, t ), this.cache(t.x, t.y, t.width, t.height), this._readyToFilter = !0, this._filterName = e; } setTransform(e, t, i, r, h, a, o, n, l) { this.x = e || 0, this.y = t || 0, this.scaleX = i != null ? i : 1, this.scaleY = r != null ? r : 1, this.rotation = h || 0, this.skewX = a || 0, this.skewY = o || 0, this.originX = n || 0, this.originY = l || 0; } setMatrix(e, t, i, r, h, a) { F.decompose(e, t, i, r, h, a, this); } unfilter() { this.uncache(); } _getStage() { for (var e = this; e.parent; ) e = e.parent; return e.___instanceof === "Stage" ? e : null; } } class O extends G { constructor(e) { super(e), this.children = []; } add(e) { const t = arguments.length; for (let i = 0; i < t; i++) { const r = arguments[i], h = r.parent; h && h.removeChildAt(h.children.indexOf(r)), this.children.push(r), r.parent = this; } } addChildAt(e, t) { const i = e.parent; i && i.removeChildAt(i.children.indexOf(e)), e.parent = this, this.children.splice(t, 0, e); } removeChildAt(e) { const t = this.children[e]; t && (t.parent = null), this.children.splice(e, 1); } replace(e, t) { const i = t.parent.children.indexOf(t); this.removeChildAt(i), this.addChildAt(e, i); } remove(e) { const t = arguments.length; let i = this.children.length; for (let r = 0; r < t; r++) for (let h = 0; h < i; h++) e.id === this.children[h].id && (e.parent = null, this.children.splice(h, 1), h--, i--); } empty() { this.children.forEach((e) => { e.parent = null; }), this.children.length = 0; } destroy() { this.empty(), this.parent && super.destroy(); } } const bt = { globalAlpha: !0, filter: !0, fillStyle: !0, strokeStyle: !0, lineWidth: !0, lineCap: !0, lineDashOffset: !0, lineJoin: !0, miterLimit: !0 }; class V extends G { constructor() { super(), this.cmds = [], this.currentGradient = null; } /** * ȫ��͸���� */ globalAlpha() { return this.cmds.push(["globalAlpha", arguments]), this; } /** * �˾�-͸���ȣ�С������bug * @returns */ filter() { return this.cmds.push(["filter", arguments]), this; } filter(...e) { return this.cmds.push(["filter", e]), this; } clearRect(...e) { return this.cmds.push(["clearRect", e]), this; } rect(...e) { return this.cmds.push(["rect", e]), this; } clear() { return this.cmds.length = 0, this; } setLineDash(...e) { return this.cmds.push(["setLineDash", e]), this; } strokeRect(...e) { return this.cmds.push(["strokeRect", e]), this; } fillRect(...e) { return this.cmds.push(["fillRect", e]), this; } beginPath(...e) { return this.cmds.push(["beginPath", e]), this; } arc(...e) { return this.cmds.push(["arc", e]), this; } closePath(...e) { return this.cmds.push(["closePath", e]), this; } fillStyle(...e) { return this.cmds.push(["fillStyle", e]), this; } fill(...e) { return this.cmds.push(["fill", e]), this; } strokeStyle(...e) { return this.cmds.push(["strokeStyle", e]), this; } lineWidth(...e) { return this.cmds.push(["lineWidth", e]), this; } lineCap(...e) { return this.cmds.push(["lineCap", e]), this; } lineDashOffset(...e) { return this.cmds.push(["lineDashOffset", e]), this; } lineJoin(...e) { return this.cmds.push(["lineJoin", e]), this; } miterLimit(...e) { return this.cmds.push(["miterLimit", e]), this; } stroke(...e) { return this.cmds.push(["stroke", e]), this; } moveTo(...e) { return this.cmds.push(["moveTo", e]), this; } lineTo(...e) { return this.cmds.push(["lineTo", e]), this; } bezierCurveTo(...e) { return this.cmds.push(["bezierCurveTo", e]), this; } quadraticCurveTo(...e) { return this.cmds.push(["quadraticCurveTo", e]), this; } createRadialGradient(...e) { return this.cmds.push(["createRadialGradient", e]), this; } createLinearGradient(...e) { return this.cmds.push(["createLinearGradient", e]), this; } addColorStop(...e) { return this.cmds.push(["addColorStop", e]), this; } fillGradient() { return this.cmds.push(["fillGradient"]), this; } arcTo(...e) { return this.cmds.push(["arcTo", e]), this; } render(e) { this.cmds.forEach((t) => { const i = t[0]; if (bt[i]) e[i] = t[1][0]; else if (i === "addColorStop") this.currentGradient && this.currentGradient.addColorStop(t[1][0], t[1][1]); else if (i === "fillGradient") e.fillStyle = this.currentGradient; else { const r = e[i](...t[1]); (i === "createRadialGradient" || i === "createLinearGradient") && (this.currentGradient = r); } }); } } function vt(s, e) { !s.includes("https://") && !s.includes("http://") || /^https?:\/\/tmp\//.test(s) ? wx.getImageInfo({ src: s, success: (t) => { e({ img: s, width: t.width, height: t.height }); } }) : wx.downloadFile({ url: s, success: (t) => { t.statusCode === 200 && wx.getImageInfo({ src: t.tempFilePath, success: (i) => { e({ img: t.tempFilePath, width: i.width, height: i.height }); } }); } }); } function Ct() { return typeof global != "object" || !global || global.Math !== Math || global.Array !== Array ? typeof self < "u" ? self : typeof window < "u" ? window : typeof global < "u" ? global : /* @__PURE__ */ function() { return this; }() : global; } const _t = Ct(), W = { getImageInWx: vt, root: _t, isWeapp: typeof wx < "u" && wx.getSystemInfo && typeof Page < "u", isWegame: typeof wx < "u" && wx.getSystemInfo && typeof Page > "u" }; class x extends G { constructor(e, t) { super(), typeof e == "string" ? x.cache[e] ? (W.isWeapp ? (this.img = x.cache[e].img, this.rect = [0, 0, x.cache[e].width, x.cache[e].height], this.width = this.rect[2], this.height = this.rect[3]) : (this.img = x.cache[e], this.rect = [0, 0, this.img.width, this.img.height], this.width = this.img.width, this.height = this.img.height), t && t.call(this)) : (this.img = W.isWegame ? wx.createImage() : new window.Image(), this.img.onload = () => { this.rect || (this.rect = [0, 0, this.img.width, this.img.height]), this.width = this.img.width, this.height = this.img.height, t && t.call(this), x.cache[e] = this.img; }, this.img.src = e) : (this.img = e, this.rect = [0, 0, e.width, e.height], this.width = e.width, this.height = e.height, x.cache[e.src] = e, t && t.call(this)); } clone(e) { const t = new x(e); return t.x = this.x, t.y = this.y, t.scaleX = this.scaleX, t.scaleY = this.scaleY, t.rotation = this.rotation, t.skewX = this.skewX, t.skewY = this.skewY, t.originX = this.originX, t.originY = this.originY, t.width = this.width, t.height = this.height, t.cursor = this.cursor, t; } } x.cache = {}; let M; W.isWeapp ? M = wx.createCanvasContext("measure0") : typeof document < "u" && (M = document.createElement("canvas").getContext("2d")); class it extends G { constructor(e, t) { super(null), this.text = e, t = t || {}, this.font = t.font || "10px sans-serif", this.fontSize = t.fontSize || 10, this.textAlign = t.textAlign || "left", this.baseline = t.baseline || "top", this.fillStyle = t.fillStyle || t.color, this.lineWidth = t.lineWidth || 1, this.strokeStyle = t.strokeStyle; } getWidth() { return M || W.isWegame && (M = wx.createCanvas().getContext("2d")), this.font && (M.font = this.font), M.measureText(this.text).width; } } function At(s, e) { const t = s.data; e = e === void 0 ? 1 : e; for (var i = 0; i < t.length; i += 4) t[i] = t[i] + e * (255 - 2 * t[i]), t[i + 1] = t[i + 1] + e * (255 - 2 * t[i + 1]), t[i + 2] = t[i + 2] + e * (255 - 2 * t[i + 2]); return s; } let j = null; typeof document < "u" ? j = document.createElement("canvas").getContext("2d") : typeof wx < "u" && wx.createCanvas && (j = wx.createCanvas().getContext("2d")); function st(s, e) { return j.createImageData(s, e); } function St(s, e) { if (e = Math.abs(e), e <= 1) return s; for (var t = e / 2, i = Math.ceil(e) + (1 - Math.ceil(e) % 2), r = new Float32Array(i), h = (t + 0.5) / 3, a = h * h, o = 1 / Math.sqrt(2 * Math.PI * a), n = -1 / (2 * h * h), l = 0, c = Math.floor(i / 2), d = 0; d < i; d++) { var u = d - c, f = o * Math.exp(u * u * n); r[d] = f, l += f; } for (var d = 0; d < r.length; d++) r[d] /= l; return kt(s, r, r); } function kt(s, e, t, i) { return Tt( Mt(s, t), e ); } function Tt(s, e, t) { for (var i = e.length, r = Math.floor(i / 2), h = s.data, a = s.width, o = s.height, n = a, l = o, c = st(n, l), d = c.data, u = 0, f = 0; f < l; f++) for (var p = 0; p < n; p++) { for (var m = f, _ = p, y = (f * n + p) * 4, P = 0, I = 0, B = 0, A = 0, b = 0; b < i; b++) { var N = m, R = Math.min(a - 1, Math.max(0, _ + b - r)), v = (N * a + R) * 4, C = e[b]; P += h[v] * C, I += h[v + 1] * C, B += h[v + 2] * C, A += h[v + 3] * C; } d[y] = P, d[y + 1] = I, d[y + 2] = B, d[y + 3] = A + u * (255 - A); } return c; } function Mt(s, e, t) { for (var i = e.length, r = Math.floor(i / 2), h = s.data, a = s.width, o = s.height, n = a, l = o, c = st(n, l), d = c.data, u = 0, f = 0; f < l; f++) for (var p = 0; p < n; p++) { for (var m = f, _ = p, y = (f * n + p) * 4, P = 0, I = 0, B = 0, A = 0, b = 0; b < i; b++) { var N = Math.min(o - 1, Math.max(0, m + b - r)), R = _, v = (N * a + R) * 4, C = e[b]; P += h[v] * C, I += h[v + 1] * C, B += h[v + 2] * C, A += h[v + 3] * C; } d[y] = P, d[y + 1] = I, d[y + 2] = B, d[y + 3] = A + u * (255 - A); } return c; } function Pt(s, e) { const t = s.data, i = t.length; for (let r = 0; r < i; r += 4) t[r] += e, t[r + 1] += e, t[r + 2] += e; return s; } function It(s, e) { const t = s.data, i = t.length, r = 259 * (e + 255) / (255 * (259 - e)); for (let h = 0; h < i; h += 4) t[h] = r * (t[h] - 128) + 128, t[h + 1] = r * (t[h + 1] - 128) + 128, t[h + 2] = r * (t[h + 2] - 128) + 128; return s; } function Bt(s, e) { const t = s.data, i = t.length; for (let r = 0; r < i; r += 4) { let h = t[r], a = t[r + 1], o = t[r + 2], n = 0.2126 * h + 0.7152 * a + 0.0722 * o; t[r] = h + (n - h) * e, t[r + 1] = a + (n - a) * e, t[r + 2] = o + (n - o) * e; } return s; } function Ot(s, e) { const t = s.data, i = t.length; for (let r = 0; r < i; r += 4) { const h = t[r], a = t[r + 1], o = t[r + 2], n = h * 0.393 + a * 0.769 + o * 0.189, l = h * 0.349 + a * 0.686 + o * 0.168, c = h * 0.272 + a * 0.534 + o * 0.131; t[r] = h + (n - h) * e, t[r + 1] = a + (l - a) * e, t[r + 2] = o + (c - o) * e; } return s; } function Et(s, e) { const t = s.data, i = t.length; for (let r = 0; r < i; r += 4) { const h = t[r], a = t[r + 1], o = t[r + 2], n = 0.2126 * h + 0.7152 * a + 0.0722 * o >= e ? 255 : 0; t[r] = t[r + 1] = t[r + 2] = n; } return s; } function Ft(s, e) { const t = s.data, i = t.length; for (let r = 0; r < i; r += 4) t[r] = Math.pow(t[r] / 255, e) * 255, t[r + 1] = Math.pow(t[r + 1] / 255, e) * 255, t[r + 2] = Math.pow(t[r + 2] / 255, e) * 255; return s; } function Lt(s, e) { const t = s.data, i = t.length, r = e.color.charAt(0) === "#" ? e.color.substr(1) : e.color, h = { r: parseInt(r.substr(0, 2), 16), g: parseInt(r.substr(2, 2), 16), b: parseInt(r.substr(4, 2), 16) }; for (let a = 0; a < i; a += 4) t[a] -= (t[a] - h.r) * e.amount, t[a + 1] -= (t[a + 1] - h.g) * e.amount, t[a + 2] -= (t[a + 2] - h.b) * e.amount; return s; } function Wt(s, e) { if (typeof e == "string") { let t = e.split("(")[0], i = Gt(e); switch (t) { case "invert": return At(s, i); case "brightness": return Pt(s, -255 + i * 255); case "blur": return St(s, i); case "contrast": return It(s, -255 + i * 255); case "grayscale": return Bt(s, i); case "sepia": return Ot(s, i); case "threshold": return Et(s, i); case "gamma": return Ft(s, i); } } else switch (e.type) { case "colorize": return Lt(s, e); } } function Gt(s) { return s = s.replace(/(invert)|(brightness)|(blur)|(contrast)|(grayscale)|(sepia)|(threshold)|(gamma)?\(/g, "").replace(")", ""), s.indexOf("%") !== -1 ? Number(s.replace("%", "")) / 100 : s.indexOf("px") !== -1 ? Number(s.replace("px", "")) : Number(s); } class Xt { render() { } renderGraphics() { } clear() { } } class Q extends Xt { constructor(e, t, i, r) { super(), arguments.length === 3 ? this.ctx = e : this.ctx = e.getContext("2d", r), this.width = t, this.height = i; } clear(e, t, i) { e.clearRect(0, 0, t, i); } render(e, t, i) { const r = t._matrix; if (t.children) { const h = t.children.slice(0), a = h.length; for (let o = 0; o < a; o++) { const n = h[o]; r.initialize(1, 0, 0, 1, 0, 0), r.appendTransform( t.x, t.y, t.scaleX, t.scaleY, t.rotation, t.skewX, t.skewY, t.originX, t.originY ), e.save(), this._render(e, n, i ? null : r, i, !0), e.restore(); } } else this._render(e, t, i ? null : r, i); } _render(e, t, i, r, h) { if (!t.isVisible()) return; i && !t.fixed ? t._matrix.initialize(i.a, i.b, i.c, i.d, i.tx, i.ty) : r && !t.fixed ? t._matrix.initialize( r.scale, 0, 0, r.scale, r.x * -1, r.y * -1 ) : t._matrix.initialize(1, 0, 0, 1, 0, 0), i = t._matrix, (h || !r) && i.appendTransform( t.x, t.y, t.scaleX, t.scaleY, t.rotation, t.skewX, t.skewY, t.originX, t.originY ); const a = t.clipGraphics; a && (e.beginPath(), a._matrix.copy(i), a._matrix.appendTransform( a.x, a.y, a.scaleX, a.scaleY, a.rotation, a.skewX, a.skewY, a.originX, a.originY ), e.setTransform( a._matrix.a, a._matrix.b, a._matrix.c, a._matrix.d, a._matrix.tx, a._matrix.ty ), a.render(e), e.clip(t.clipRuleNonzero ? "nonzero" : "evenodd")); const o = t.absClipGraphics; if (o && (e.beginPath(), o._matrix.initialize(1, 0, 0, 1, 0, 0), o._matrix.appendTransform( o.x, o.y, o.scaleX, o.scaleY, o.rotation, o.skewX, o.skewY, o.originX, o.originY ), e.setTransform( o._matrix.a, o._matrix.b, o._matrix.c, o._matrix.d, o._matrix.tx, o._matrix.ty ), o.render(e), e.clip(t.absClipRuleNonzero ? "nonzero" : "evenodd")), e.setTransform(i.a, i.b, i.c, i.d, i.tx, i.ty), t._readyToCache || t.cacheUpdating) this.setComplexProps(e, t), t._readyToCache = !1, t.cacheCtx.clearRect(0, 0, t.cacheCanvas.width, t.cacheCanvas.height), t.cacheCtx.save(), this.render(t.cacheCtx, t, t._cacheData), t.cacheCtx.restore(), t._readyToFilter && (t.cacheCtx.putImageData( Wt( t.cacheCtx.getImageData( 0, 0, t.cacheCanvas.width, t.cacheCanvas.height ), t._filterName ), 0, 0 ), this._readyToFilter = !1), t.filterStyle && (e.filter = t.filterStyle), this.drawImage(e, t.cacheCanvas, t._cacheData.x, t._cacheData.y); else if (t.cacheCanvas && !r) this.setComplexProps(e, t), t.filterStyle && (e.filter = t.filterStyle), this.drawImage(e, t.cacheCanvas, t._cacheData.x, t._cacheData.y); else if (t instanceof O) { const n = t.children.slice(0), l = n.length; for (let c = 0; c < l; c++) e.save(), this._render(e, n[c], i), e.restore(); } else if (t instanceof V) this.setComplexProps(e, t), t.render(e); else if (t instanceof x && t.rect) { this.setComplexProps(e, t); const n = t.rect; t.filterStyle && (e.filter = t.filterStyle), this.drawImage( e, t.img, n[0], n[1], n[2], n[3], 0, 0, n[2], n[3] ); } else t instanceof it && (this.setComplexProps(e, t), e.font = t.font, e.textAlign = t.textAlign, e.textBaseline = t.baseline, t.fillStyle ? (e.fillStyle = t.fillStyle, e.fillText(t.text, 0, 0, t.maxWidth)) : t.strokeStyle ? (e.strokeStyle = t.strokeStyle, e.lineWidth = t.lineWidth, e.strokeText(t.text, 0, 0)) : console.warn("The Text element needs to have 【fillStyle】 or 【strokeStyle】 set in order to be rendered.")); } // 小程序新接口和web画图适配 drawImage(e, ...t) { e.drawImage(...t); } setComplexProps(e, t) { t.complexCompositeOperation = e.globalCompositeOperation = this.getCompositeOperation( t ), t.complexAlpha = e.globalAlpha = this.getAlpha(t, 1), t.complexShadow = this.getShadow(t), t.complexShadow && (e.shadowColor = t.complexShadow.color, e.shadowOffsetX = t.complexShadow.offsetX, e.shadowOffsetY = t.complexShadow.offsetY, e.shadowBlur = t.complexShadow.blur); } getCompositeOperation(e) { if (e.compositeOperation) return e.compositeOperation; if (e.parent) return this.getCompositeOperation(e.parent); } getAlpha(e, t) { const i = e.alpha * t; return e.parent ? this.getAlpha(e.parent, i) : i; } getShadow(e) { if (e.shadow) return e.shadow; if (e.parent) return this.getShadow(e.parent); } } class rt { constructor(e, t, i) { this.renderList = [], arguments.length === 3 ? (this.renderer = new Q(e, t, i), this.width = t, this.height = i) : (this.renderer = new Q(e), this.width = e.width, this.height = e.height), this.ctx = this.renderer.ctx; } update(e) { this.renderer.clear(this.ctx, this.width, this.height), this.ctx.draw && this.ctx.draw(), this.renderer.render(this.ctx, e); } getHitRenderList(e) { const t = this.renderList; return t.length = 0, this.computeMatrix(e), t; } computeMatrix(e) { for (let t = 0, i = e.children.length; t < i; t++) this._computeMatrix(e.children[t]); } initComplex(e) { e.complexCompositeOperation = this._getCompositeOperation(e), e.complexAlpha = this._getAlpha(e, 1); } _computeMatrix(e, t) { if (e.isVisible()) if (t && !e.fixed ? e._matrix.initialize(t.a, t.b, t.c, t.d, t.tx, t.ty) : e._matrix.initialize(1, 0, 0, 1, 0, 0), e._matrix.appendTransform(e.x, e.y, e.scaleX, e.scaleY, e.rotation, e.skewX, e.skewY, e.originX, e.originY), e instanceof O) { const i = e.children, r = i.length; let h = 0; for (; h < r; h++) this._computeMatrix(i[h], e._matrix); } else e.initAABB(), this.renderList.push(e), this.initComplex(e); } _getCompositeOperation(e) { if (e.compositeOperation) return e.compositeOperation; if (e.parent) return this._getCompositeOperation(e.parent); } _getAlpha(e, t) { const i = e.alpha * t; return e.parent ? this._getAlpha(e.parent, i) : i; } isInStage(e) { return this.collisionBetweenAABB(e.AABB, this.stage.AABB); } collisionBetweenAABB(e, t) { return !(e[0] + e[2] < t[0] || e[0] > t[0] + t[2] || e[1] + e[3] < t[1] || e[1] > t[1] + t[3]); } } class ht extends O { constructor(e, t, i, r) { if (super(), i) this.canvas = i, this.ctx = this.canvas.getContext("2d"); else throw new Error("无效canvas元素"); this.renderer = new rt(this.ctx, e, t), this._overObject = null, this.hitAABB = !0, this.width = e, this.height = t; } // touchStartHandler (evt) { // const p1 = evt.changedTouches[0] // evt.stageX = Math.round(p1.x * this.scaleX) // evt.stageY = Math.round(p1.y * this.scaleY) // this._getObjectUnderPoint(evt, (obj) => { // this.willDragObject = obj // this._mouseDownX = evt.stageX // this._mouseDownY = evt.stageY // this.preStageX = evt.stageX // this.preStageY = evt.stageY // }) // } // touchMoveHandler (evt) { // const p1 = evt.changedTouches[0] // evt.stageX = Math.round(p1.x * this.scaleX) // evt.stageY = Math.round(p1.y * this.scaleY) // this._getObjectUnderPoint(evt, (obj) => { // let mockEvt = new Event() // mockEvt.stageX = evt.stageX // mockEvt.stageY = evt.stageY // mockEvt.pureEvent = evt // if (this.willDragObject) { // mockEvt.type = 'drag' // mockEvt.dx = mockEvt.stageX - this.preStageX // mockEvt.dy = mockEvt.stageY - this.preStageY // this.preStageX = mockEvt.stageX // this.preStageY = mockEvt.stageY // this.willDragObject.dispatchEvent(mockEvt) // } // if (obj) { // if (this._overObject === null) { // this._overObject = obj // } else { // if (obj.id !== this._overObject.id) { // this._overObject = obj // } else { // mockEvt.type = 'touchmove' // obj.dispatchEvent(mockEvt) // } // } // } else if (this._overObject) { // this._overObject = null // } // }) // } // touchEndHandler (evt) { // const p1 = evt.changedTouches[0] // evt.stageX = Math.round(p1.x * this.scaleX) // evt.stageY = Math.round(p1.y * this.scaleY) // let mockEvt = new Event() // mockEvt.stageX = evt.stageX // mockEvt.stageY = evt.stageY // mockEvt.pureEvent = evt // this._getObjectUnderPoint(evt, (obj) => { // this._mouseUpX = evt.stageX // this._mouseUpY = evt.stageY // this.willDragObject = null // this.preStageX = null // this.preStageY = null // if (obj && Math.abs(this._mouseDownX - this._mouseUpX) < 30 && Math.abs(this._mouseDownY - this._mouseUpY) < 30) { // mockEvt.type = 'tap' // obj.dispatchEvent(mockEvt) // } // }) // } // _handleMouseOut (evt) { // this.dispatchEvent({ // pureEvent: evt, // type: 'mouseout', // stageX: evt.stageX, // stageY: evt.stageY // }) // } // _getObjectUnderPoint (evt, cb) { // const list = this.renderer.getHitRenderList(this) // if (this.hitAABB) { // return this._hitRender.hitAABB(list, evt, cb) // } else { // this._hitRender.clear() // this._hitRender.hit(list, evt, cb, list.length - 1) // } // } // on (type, cb) { // switch (type) { // case 'touchstart': // this.touchStart = cb // break // case 'touchmove': // this.touchMove = cb // break // case 'touchend': // this.touchEnd = cb // break // } // } update() { this.renderer.update(this); } } class Yt extends O { constructor(e, t, i, r) { super(); const h = arguments.length; if (this.isWegame = typeof wx < "u" && typeof Page > "u", this.moveDetectionInterval = 0, h === 0) this.canvas = mt, this.disableMoveDetection = !0, this.moveDetectionInterval = 500; else { if (h === 4) return new ht(arguments[0], arguments[1], arguments[2], arguments[3]); h === 1 ? this.canvas = typeof e == "string" ? document.querySelector(e) : e : (this.renderTo = typeof i == "string" ? document.querySelector(i) : i, this.renderTo.tagName === "CANVAS" ? (this.canvas = this.renderTo, this.canvas.width = e, this.canvas.height = t) : (this.canvas = document.createElement("canvas"), this.canvas.width = e, this.canvas.height = t, this.renderTo.appendChild(this.canvas))), this._boundingClientRect = this.canvas.getBoundingClientRect(), this.offset = this._getOffset(this.canvas); } this.renderer = new rt(this.canvas, this.canvas.width, this.canvas.height, r), this.borderTopWidth = 0, this.borderLeftWidth = 0, this.hitAABB = !1, this._overObject = null, this._scaleX = 1, this._scaleY = 1, this._mouseDownX = 0, this._mouseDownY = 0, this._mouseUpX = 0, this._mouseUpY = 0, this.willDragObject = null, this.preStageX = null, this.preStageY = null, this.width = this.canvas.width, this.height = this.canvas.height, this.___instanceof = "Stage", this._moveDetectionTime = Date.now(); } // _handleContextmenu (evt) { // this._getObjectUnderPoint(evt) // } // _handleDblClick (evt) { // this._getObjectUnderPoint(evt) // } // _handleClick (evt) { // if (Math.abs(this._mouseDownX - this._mouseUpX) < 20 && Math.abs(this._mouseDownY - this._mouseUpY) < 20) { // this._getObjectUnderPoint(evt) // } // } // _handleMouseDown (evt) { // if (this.isWegame) { // evt.type = 'touchstart' // } // this.offset = this._getOffset(this.canvas) // let obj = this._getObjectUnderPoint(evt) // this.willDragObject = obj // this._mouseDownX = evt.stageX // this._mouseDownY = evt.stageY // this.preStageX = evt.stageX // this.preStageY = evt.stageY // } // scaleEventPoint (x, y) { // this._scaleX = x // this._scaleY = y // } // _handleMouseUp (evt) { // if (this.isWegame) { // evt.type = 'touchend' // } // const obj = this._getObjectUnderPoint(evt) // this._mouseUpX = evt.stageX // this._mouseUpY = evt.stageY // let mockEvt = new Event() // mockEvt.stageX = evt.stageX // mockEvt.stageY = evt.stageY // mockEvt.pureEvent = evt // this.willDragObject = null // this.preStageX = null // this.preStageY = null // if (obj && evt.type === 'touchend' && Math.abs(this._mouseDownX - this._mouseUpX) < 30 && Math.abs(this._mouseDownY - this._mouseUpY) < 30) { // mockEvt.type = 'tap' // obj.dispatchEvent(mockEvt) // } // } // _handleMouseOut (evt) { // this._computeStageXY(evt) // this.dispatchEvent({ // pureEvent: evt, // type: 'mouseout', // stageX: evt.stageX, // stageY: evt.stageY // }) // } // _handleMouseMove (evt) { // if (Date.now() - this._moveDetectionTime < this.moveDetectionInterval) { // return // } // this._moveDetectionTime = Date.now() // if (this.isWegame) { // evt.type = 'touchmove' // } // if (this.disableMoveDetection) return // let obj = this._getObjectUnderPoint(evt) // let mockEvt = new Event() // mockEvt.stageX = evt.stageX // mockEvt.stageY = evt.stageY // mockEvt.pureEvent = evt // if (this.willDragObject) { // mockEvt.type = 'drag' // mockEvt.dx = mockEvt.stageX - this.preStageX // mockEvt.dy = mockEvt.stageY - this.preStageY // this.preStageX = mockEvt.stageX // this.preStageY = mockEvt.stageY // this.willDragObject.dispatchEvent(mockEvt) // } // if (obj) { // if (this._overObject === null) { // mockEvt.type = 'mouseover' // obj.dispatchEvent(mockEvt) // this._overObject = obj // this._setCursor(obj) // } else { // if (obj.id !== this._overObject.id) { // this._overObject.dispatchEvent({ // pureEvent: evt, // type: 'mouseout', // stageX: evt.stageX, // stageY: evt.stageY // }) // mockEvt.type = 'mouseover' // obj.dispatchEvent(mockEvt) // this._setCursor(obj) // this._overObject = obj // } else { // mockEvt.type = 'mousemove' // obj.dispatchEvent(mockEvt) // mockEvt.type = 'touchmove' // obj.dispatchEvent(mockEvt) // } // } // } else if (this._overObject) { // mockEvt.type = 'mouseout' // this._overObject.dispatchEvent(mockEvt) // this._overObject = null // this._setCursor({ cursor: 'default' }) // } // } // _setCursor (obj) { // if (!this.canvas.style) { // return // } // if (obj.cursor) { // this.canvas.style.cursor = obj.cursor // } else if (obj.parent) { // this._setCursor(obj.parent) // } else { // this._setCursor({ cursor: 'default' }) // } // } // _getObjectUnderPoint (evt) { // this._computeStageXY(evt) // if (this.hitAABB) { // return this._hitRender.hitAABB(this, evt) // } else { // return this._hitRender.hitPixel(this, evt) // } // } // _computeStageXY (evt) { // this._boundingClientRect = this.isWegame ? {left: 0, top: 0} : this.canvas.getBoundingClientRect() // if (evt.touches || evt.changedTouches) { // const firstTouch = evt.touches[0] || evt.changedTouches[0] // if (firstTouch) { // evt.stageX = (firstTouch.pageX - this.offset[0]) / this._scaleX // evt.stageY = (firstTouch.pageY - this.offset[1]) / this._scaleY // } // } else { // evt.stageX = (evt.clientX - this._boundingClientRect.left - this.borderLeftWidth) / this._scaleX // evt.stageY = (evt.clientY - this._boundingClientRect.top - this.borderTopWidth) / this._scaleY // } // } _getOffset(e) { if (this.isWegame) return [0, 0]; let t = 0, i = 0; if (document.documentElement.getBoundingClientRect && e.getBoundingClientRect) { let r = e.getBoundingClientRect(); i = r.left, t = r.top; } else { for (; e.offsetParent; ) t += e.offsetTop, i += e.offsetLeft, e = e.offsetParent; return [i, t]; } return [i + Math.max(document.documentElement.scrollLeft, document.body.scrollLeft), t + Math.max(document.documentElement.scrollTop, document.body.scrollTop)]; } update() { this.renderer.update(this); } // on (type, fn) { // const handler = (evt) => { // if (!option.stagePropagationStopped[type]) { // this._computeStageXY(evt) // fn(evt) // } // option.stagePropagationStopped[type] = false // } // fn.__handler__ = handler // this.canvas.addEventListener(type, handler) // } // off (type, fn) { // this.canvas.removeEventListener(type, fn.__handler__ || fn) // } } class Nt extends V { // constructor() { // super() // } draw() { } render(e) { this.clear(), this.draw(), super.render(e); } } const T = { util: { randomInt: (s, e) => s + Math.floor(Math.random() * (e - s + 1)) }, Stage: Yt, WeStage: ht, Graphics: V, Bitmap: x, Text: it, Group: O, Shape: Nt, caxCanvasId: 0 }, k = typeof wx != "undefined" && wx.getSystemInfo && !wx.createCanvas && wx.createCanvasContext; typeof wx != "undefined" && wx.getSystemInfo && wx.createCanvas; function nt({ option: s }, e) { let t = null; if (s.linearGradient && s.colors) { const i = s.linearGradient.length > 4 ? "createRadialGradient" : "createLinearGradient"; t = e[i](...s.linearGradient); for (let r = 0; r < s.colors.length; r++) t.addColorStop(...s.colors[r]); } return t || s.fillStyle; } function $(s) { return JSON.parse(JSON.stringify(s)); } const g = { /** * 形状(组合图案) */ shape: "shape", rect: "rect", circle: "circle", line: "line", image: "image", text: "text", group: "group", container: "container" }; class U extends T.Graphics { constructor(e, t) { if (super(), e = Object.assign( { font: "10px sans-serif", color: "black", textAlign: "left", baseline: "top", orientation: "horizontal", lineHeight: 0 }, e ), !e.lineHeight) { const i = /\d+px/i.exec(e.font); i && (e.lineHeight = Number.parseFloat(i[0])); } this.option = e || {}, this.text = e.text, this.ctx = t ? t.getContext("2d") : document.createElement("canvas").getContext("2d"); } getWidth(e) { var i; this.option.font && (this.ctx.font = this.option.font); const { width: t } = (i = this.ctx) == null ? void 0 : i.measureText(`${e || this.text}`); return t || 0; } getHeight() { return this.renderBreakLine({ ctx: this.ctx, isMeasure: !0 }); } render(e) { e.save(), e.fillStyle = nt({ option: this.option }, this.ctx) || this.option.color, e.font = this.option.font, e.textAlign = this.option.textAlign, e.textBaseline = this.option.baseline, this.option.filter && (e.filter = this.option.filter), this.option.orientation === "vertical" ? this.renderVertical({ ctx: e }) : this.option.maxWidth && this.getWidth() > this.option.maxWidth ? this.renderBreakLine({ ctx: e, symbol: this.option.symbol }) : this.fill(e, this.text), e.restore(); } /** * 文字划线 * @param {[CanvasHTML]} ctx [ctx context 2d] * @param {[string]} text [text 文字] * @param {[number]} x [x 坐标] * @param {[number]} y [y 坐标] * @param {[boolean]} line [line 是否显示划线] * * @return {[void]} */ fill(e, t = "", i = 0, r = 0) { const { actualBoundingBoxDescent: h, width: a } = e.measureText(`${t}`), o = Math.ceil(h); if (this.option.lineDecoration) { const { lineSize: n, lineColor: l, lineOffset: c = 0, lineOffsetTop: d = 0, lineOffsetLeft: u = 0, color: f, lineDecoration: p, lineLevel: m } = this.option; m !== "bottom" && e.fillText(t, i, r); let _ = 0; switch (p) { case "middle": _ = o / 2; break; case "bottom": _ = o; break; } e.strokeStyle = l || f || "#222", e.lineWidth = n || 2, e.beginPath(), e.moveTo(i + u, _ + r + (c || d)), e.lineTo(i + a + u, _ + r + (c || d)), e.stroke(), m === "bottom" && e.fillText(t, i, r); } else e.fillText(t, i, r); } /** * 竖排代码来自 张鑫旭大神 http://www.zhangxinxu.com/wordpress/?p=7362 * isMeasure 如果为测量模式,只返回计算的文本高度 */ renderVertical({ ctx: e }) { const t = this.text.split(""), i = t.map((l) => this.getWidth(l)), r = e.textAlign, h = e.textBaseline; let a = 0, o = 0; const n = this.text; return r === "left" ? a = a + Math.max.apply(null, i) / 2 : r === "right" && (a = a - Math.max.apply(null, i) / 2), h === "bottom" || h === "alphabetic" || h === "ideographic" ? o = o - i[0] / 2 : (h === "top" || h === "hanging") && (o = o + i[0] / 2), e.textAlign = "center", e.textBaseline = "middle", t.forEach((l, c) => { const d = l.charCodeAt(0); d <= 256 ? (e.translate(a, o), e.rotate(90 * Math.PI / 180), e.translate(-a, -o)) : c > 0 && n.charCodeAt(c - 1) < 256 && (o = o + i[c - 1] / 2), this.fill(e, l, a, o), d <= 256 && (e.translate(a, o), e.rotate(-90 * Math.PI / 180), e.translate(-a, -o)); const u = i[c]; o = o + u; }), e.textAlign = r, e.textBaseline = h, o; } /** * isMeasure 如果为测量模式,只返回计算的文本高度 */ renderBreakLine({ ctx: e, isMeasure: t = !1, symbol: i = "..." }) { const r = /\b(?![\u0020-\u002F\u003A-\u003F\u2000-\u206F\u2E00-\u2E7F\u3000-\u303F\uFF00-\uFF1F])|(?=[\u2E80-\u2FFF\u3040-\u9FFF])/g; let h = "", a = 0, o = 1; const n = []; this.option.text.replace(r, function() { n.push(arguments[arguments.length - 2] - 1); }); let l = 0; for (let c = 0; c < this.option.text.length; c++) if (n.includes(c) && (l = c), h += [this.option.text[c]], this.getWidth(h) > this.option.maxWidth || this.option.text[c].charCodeAt(0) === 10) { let d = ""; if (o === this.option.maxLine && c !== this.option.text.length ? (d = `${h.substring(0, h.length - 1)}${i || ""}`, h = "") : l === c || this.option.text[c].charCodeAt(0) === 10 ? (d = h, h = "") : (d = h.substring( 0, h.length - (c - l) ), h = h.substring( h.length - (c - l), h.length )), this.option.text[c].charCodeAt(0) === 10 && (d = d.substring(0, d.length - 1)), !t && this.fill(e, d, 0, a, !1), o === this.option.maxLine && c !== this.option.text.length) break; a += this.option.lineHeight || 0, o++; } return h && !t && this.fill(e, h, 0, a, !1), a + this.option.lineHeight - 2; } } class at extends T.Graphics { constructor(e, t) { if (super(), e = Object.assign( { lineWidth: 1, lt: !0, rt: !0, lb: !0, rb: !0 }, e ), this.option = e, this.ctx = t ? t.getContext("2d") : document.createElement("canvas").getContext("2d"), this.beginPath(), e.type === g.shape) { this.setShape(); return; } switch (e.type) { case g.rect: e.r > 0 ? this.setRoundedRect(e) : this.rect(0, 0, e.width, e.height); break; case g.circle: { let r = 1, h = 0; e.angle && (r = e.angle / 360), e.sAngle && (h = e.sAngle / 360), this.arc( 0, 0, e.r, h * Math.PI * 2, r * Math.PI * 2, !1 ); break; } case g.line: this.moveTo(0, 0), this.lineTo(