zan-poster
Version:
通过json在canvas上绘制图像, 基于cax画图框架开发, 本画图组件是json2canvas库的改造、优化版本 (详情查看README.md文档末说明)。
1,401 lines (1,400 loc) • 71 kB
JavaScript
import { r as registerInstance, c as createEvent, h, g as getElement } from './index-86f0f68f.js';
function dt(r) {
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
}
var ut = /* @__PURE__ */ function() {
function r(t, i) {
var s = i.length, h, n;
return s >= 2 ? (h = i.slice(0, s / 2), n = i.slice(s / 2, s), e(t, r(t, h), r(t, n))) : i.slice();
}
function e(t, i, s) {
for (var h = [], n = i.length, a = s.length; n > 0 && a > 0; )
t(i[0], s[0]) <= 0 ? (h.push(i.shift()), n--) : (h.push(s.shift()), a--);
return n > 0 ? h.push.apply(h, i) : h.push.apply(h, s), h;
}
return r;
}(), ft = /* @__PURE__ */ function() {
function r(e, t, i) {
var s, h;
for (s = 0, h = t.length; s < h && !(e(t[s], i) > 0); s++)
;
return s;
}
return r;
}(), tt, et;
tt = ut;
et = ft;
var pt = function() {
var r;
r = {};
function e(o) {
return function() {
return o;
};
}
function t(o) {
o = o || {}, this.config = o, this.config.childrenPropertyName = o.childrenPropertyName || "children", this.config.modelComparatorFn = o.modelComparatorFn;
}
function i(o, l) {
return l.parent = o, o.children.push(l), l;
}
function s(o, l) {
this.config = o, this.model = l, this.children = [];
}
t.prototype.parse = function(o) {
var l, c, d;
if (!(o instanceof Object))
throw new TypeError("Model must be of type object.");
if (d = new s(this.config, o), o[this.config.childrenPropertyName] instanceof Array)
for (this.config.modelComparatorFn && (o[this.config.childrenPropertyName] = tt(
this.config.modelComparatorFn,
o[this.config.childrenPropertyName]
)), l = 0, c = o[this.config.childrenPropertyName].length; l < c; l++)
i(d, this.parse(o[this.config.childrenPropertyName][l]));
return d;
};
function h(o) {
return typeof o.config.modelComparatorFn == "function";
}
s.prototype.isRoot = function() {
return this.parent === void 0;
}, s.prototype.hasChildren = function() {
return this.children.length > 0;
};
function n(o, l, c) {
var d;
if (!(l instanceof s))
throw new TypeError("Child must be of type Node.");
if (l.parent = o, o.model[o.config.childrenPropertyName] instanceof Array || (o.model[o.config.childrenPropertyName] = []), h(o))
d = et(
o.config.modelComparatorFn,
o.model[o.config.childrenPropertyName],
l.model
), o.model[o.config.childrenPropertyName].splice(d, 0, l.model), o.children.splice(d, 0, l);
else if (c === void 0)
o.model[o.config.childrenPropertyName].push(l.model), o.children.push(l);
else {
if (c < 0 || c > o.children.length)
throw new Error("Invalid index.");
o.model[o.config.childrenPropertyName].splice(c, 0, l.model), o.children.splice(c, 0, l);
}
return l;
}
s.prototype.addChild = function(o) {
return n(this, o);
}, s.prototype.addChildAtIndex = function(o, l) {
if (h(this))
throw new Error("Cannot add child at index when using a comparator function.");
return n(this, o, l);
}, s.prototype.setIndex = function(o) {
if (h(this))
throw new Error("Cannot set node index when using a comparator function.");
if (this.isRoot()) {
if (o === 0)
return this;
throw new Error("Invalid index.");
}
if (o < 0 || o >= this.parent.children.length)
throw new Error("Invalid index.");
var l = this.parent.children.indexOf(this);
return this.parent.children.splice(o, 0, this.parent.children.splice(l, 1)[0]), this.parent.model[this.parent.config.childrenPropertyName].splice(o, 0, this.parent.model[this.parent.config.childrenPropertyName].splice(l, 1)[0]), this;
}, s.prototype.getPath = function() {
var o = [];
return function l(c) {
o.unshift(c), c.isRoot() || l(c.parent);
}(this), o;
}, s.prototype.getIndex = function() {
return this.isRoot() ? 0 : this.parent.children.indexOf(this);
};
function a() {
var o = {};
if (arguments.length === 1 ? typeof arguments[0] == "function" ? o.fn = arguments[0] : o.options = arguments[0] : arguments.length === 2 ? typeof arguments[0] == "function" ? (o.fn = arguments[0], o.ctx = arguments[1]) : (o.options = arguments[0], o.fn = arguments[1]) : (o.options = arguments[0], o.fn = arguments[1], o.ctx = arguments[2]), o.options = o.options || {}, o.options.strategy || (o.options.strategy = "pre"), !r[o.options.strategy])
throw new Error("Unknown tree walk strategy. Valid strategies are 'pre' [default], 'post' and 'breadth'.");
return o;
}
return s.prototype.walk = function() {
var o;
o = a.apply(this, arguments), r[o.options.strategy].call(this, o.fn, o.ctx);
}, r.pre = function o(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 = o.call(this.children[d], l, c);
}
return f;
}, r.post = function o(l, c) {
var d, u, f;
for (d = 0, u = this.children.length; d < u; d++)
if (f = o.call(this.children[d], l, c), f === !1)
return !1;
return f = l.call(c, this), f;
}, r.breadth = function(l, c) {
var d = [this];
(function u() {
var f, g, m;
if (d.length !== 0) {
for (m = d.shift(), f = 0, g = m.children.length; f < g; f++)
d.push(m.children[f]);
l.call(c, m) !== !1 && u();
}
})();
}, s.prototype.all = function() {
var o, l = [];
return o = a.apply(this, arguments), o.fn = o.fn || e(!0), r[o.options.strategy].call(this, function(c) {
o.fn.call(o.ctx, c) && l.push(c);
}, o.ctx), l;
}, s.prototype.first = function() {
var o, l;
return o = a.apply(this, arguments), o.fn = o.fn || e(!0), r[o.options.strategy].call(this, function(c) {
if (o.fn.call(o.ctx, c))
return l = c, !1;
}, o.ctx), l;
}, s.prototype.drop = function() {
var o;
return this.isRoot() || (o = this.parent.children.indexOf(this), this.parent.children.splice(o, 1), this.parent.model[this.config.childrenPropertyName].splice(o, 1), this.parent = void 0, delete this.parent), this;
}, t;
}();
const gt = /* @__PURE__ */ dt(pt);
let z = null;
typeof wx < "u" && (wx.getSharedCanvas ? z = wx.getSharedCanvas() : wx.createCanvas && (z = wx.createCanvas()));
const mt = z, R = 0.017453292519943295, xt = Math.PI * 2;
class W {
constructor(e, t, i, s, h, n) {
return this.a = e ?? 1, this.b = t || 0, this.c = i || 0, this.d = s ?? 1, this.tx = h || 0, this.ty = n || 0, this;
}
identity() {
return this.a = this.d = 1, this.b = this.c = this.tx = this.ty = 0, this;
}
appendTransform(e, t, i, s, h, n, a, o, l) {
if (h % 360)
var c = h * R, d = Math.cos(c), u = Math.sin(c);
else
d = 1, u = 0;
return n || a ? (n *= R, a *= R, this.append(Math.cos(a), Math.sin(a), -Math.sin(n), Math.cos(n), e, t), this.append(d * i, u * i, -u * s, d * s, 0, 0)) : this.append(d * i, u * i, -u * s, d * s, e, t), (o || l) && (this.tx -= o * this.a + l * this.c, this.ty -= o * this.b + l * this.d), this;
}
append(e, t, i, s, h, n) {
var a = this.a, o = this.b, l = this.c, c = this.d;
return this.a = e * a + t * l, this.b = e * o + t * c, this.c = i * a + s * l, this.d = i * o + s * c, this.tx = h * a + n * l + this.tx, this.ty = h * o + n * c + this.ty, this;
}
initialize(e, t, i, s, h, n) {
return this.a = e, this.b = t, this.c = i, this.d = s, this.tx = h, this.ty = n, this;
}
setValues(e, t, i, s, h, n) {
return this.a = e ?? 1, this.b = t || 0, this.c = i || 0, this.d = s ?? 1, this.tx = h || 0, this.ty = n || 0, this;
}
invert() {
let e = this.a, t = this.b, i = this.c, s = this.d, h = this.tx, n = e * s - t * i;
return this.a = s / n, this.b = -t / n, this.c = -i / n, this.d = e / n, this.tx = (i * this.ty - s * h) / n, this.ty = -(e * this.ty - t * h) / n, this;
}
copy(e) {
return this.setValues(e.a, e.b, e.c, e.d, e.tx, e.ty);
}
}
W.decompose = function(r, e, t, i, s, h, n) {
const a = -Math.atan2(-t, i), o = Math.atan2(e, r), l = Math.abs(a + o);
l < 1e-5 || Math.abs(xt - l) < 1e-5 ? (n.rotation = o, r < 0 && i >= 0 && (n.rotation += n.rotation <= 0 ? Math.PI : -Math.PI), n.skewX = n.skewY = 0) : (n.rotation = 0, n.skewX = a, n.skewY = o), n.scaleX = Math.sqrt(r * r + e * e), n.scaleY = Math.sqrt(t * t + i * i), n.x = s, n.y = h;
};
const wt = {
stagePropagationStopped: {}
};
class yt {
constructor() {
this._listeners = null, this._captureListeners = null;
}
addEventListener(e, t, i) {
var s;
i ? s = this._captureListeners = this._captureListeners || {} : s = this._listeners = this._listeners || {};
var h = s[e];
return h && this.removeEventListener(e, t, i), h = s[e], h ? h.push(t) : s[e] = [t], t;
}
removeEventListener(e, t, i) {
var s = i ? this._captureListeners : this._listeners;
if (s) {
var h = s[e];
h && h.every((n, a) => n === t ? (h.splice(a, 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 s, h = i.length;
for (s = h - 1; s >= 0 && !e.propagationStopped; s--)
i[s]._dispatchEvent(e, 0);
for (s = 0; s < h && !e.propagationStopped; s++)
i[s]._dispatchEvent(e, 1);
}
_dispatchEvent(e, t) {
if (e.target = this, this._captureListeners && t === 0) {
let i = this._captureListeners[e.type];
i && i.forEach((s) => {
s.call(this, e);
});
}
if (this._listeners && t === 1) {
let i = this._listeners[e.type];
i && i.forEach((s) => {
s.call(this, e);
});
}
}
}
var E = {};
E._nextID = 0;
E.get = function() {
return E._nextID++;
};
class L 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 W(), this._hitMatrix = new W(), this.id = E.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, s = this.height, h = this._matrix, n = h.tx, a = h.ty;
this.hitBox && (i = this.hitBox[2], s = this.hitBox[3], n = this.hitBox[0] * h.a + this.hitBox[1] * h.c + n, a = this.hitBox[0] * h.b + this.hitBox[1] * h.d + a);
let o = i * h.a, l = i * h.b, c = s * h.c, d = s * h.d, u = n, f = n, g = a, m = a;
(e = o + n) < u ? u = e : e > f && (f = e), (e = o + c + n) < u ? u = e : e > f && (f = e), (e = c + n) < u ? u = e : e > f && (f = e), (t = l + a) < g ? g = t : t > m && (m = t), (t = l + d + a) < g ? g = t : t > m && (m = t), (t = d + a) < g ? g = t : t > m && (m = t), this.AABB = [u, g, f - u, m - g], this.rectPoints = [
{
x: n,
y: a
},
{
x: o + n,
y: l + a
},
{
x: o + c + n,
y: l + d + a
},
{
x: c + n,
y: d + a
}
];
}
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, s, h, n) {
this._cacheData = {
x: e || 0,
y: t || 0,
width: i || this.width,
height: s || this.height,
scale: h || 1
}, this.cacheUpdating = n, 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, s, h, n, a, o, l) {
this.x = e || 0, this.y = t || 0, this.scaleX = i ?? 1, this.scaleY = s ?? 1, this.rotation = h || 0, this.skewX = n || 0, this.skewY = a || 0, this.originX = o || 0, this.originY = l || 0;
}
setMatrix(e, t, i, s, h, n) {
W.decompose(e, t, i, s, h, n, this);
}
unfilter() {
this.uncache();
}
_getStage() {
for (var e = this; e.parent; )
e = e.parent;
return e.___instanceof === "Stage" ? e : null;
}
}
class B extends L {
constructor(e) {
super(e), this.children = [];
}
add(e) {
const t = arguments.length;
for (let i = 0; i < t; i++) {
const s = arguments[i], h = s.parent;
h && h.removeChildAt(h.children.indexOf(s)), this.children.push(s), s.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 s = 0; s < t; s++)
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 L {
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 s = e[i](...t[1]);
(i === "createRadialGradient" || i === "createLinearGradient") && (this.currentGradient = s);
}
});
}
}
function vt(r, e) {
!r.includes("https://") && !r.includes("http://") || /^https?:\/\/tmp\//.test(r) ? wx.getImageInfo({
src: r,
success: (t) => {
e({
img: r,
width: t.width,
height: t.height
});
}
}) : wx.downloadFile({
url: r,
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(), F = {
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 L {
constructor(e, t) {
super(), typeof e == "string" ? x.cache[e] ? (F.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 = F.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 T;
F.isWeapp ? T = wx.createCanvasContext("measure0") : typeof document < "u" && (T = document.createElement("canvas").getContext("2d"));
class it extends L {
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 T || F.isWegame && (T = wx.createCanvas().getContext("2d")), this.font && (T.font = this.font), T.measureText(this.text).width;
}
}
function St(r, e) {
const t = r.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 r;
}
let H = null;
typeof document < "u" ? H = document.createElement("canvas").getContext("2d") : typeof wx < "u" && wx.createCanvas && (H = wx.createCanvas().getContext("2d"));
function st(r, e) {
return H.createImageData(r, e);
}
function At(r, e) {
if (e = Math.abs(e), e <= 1) return r;
for (var t = e / 2, i = Math.ceil(e) + (1 - Math.ceil(e) % 2), s = new Float32Array(i), h = (t + 0.5) / 3, n = h * h, a = 1 / Math.sqrt(2 * Math.PI * n), o = -1 / (2 * h * h), l = 0, c = Math.floor(i / 2), d = 0; d < i; d++) {
var u = d - c, f = a * Math.exp(u * u * o);
s[d] = f, l += f;
}
for (var d = 0; d < s.length; d++)
s[d] /= l;
return kt(r, s, s);
}
function kt(r, e, t, i) {
return Tt(
Mt(r, t),
e
);
}
function Tt(r, e, t) {
for (var i = e.length, s = Math.floor(i / 2), h = r.data, n = r.width, a = r.height, o = n, l = a, c = st(o, l), d = c.data, u = 0, f = 0; f < l; f++)
for (var g = 0; g < o; g++) {
for (var m = f, _ = g, y = (f * o + g) * 4, M = 0, P = 0, I = 0, S = 0, b = 0; b < i; b++) {
var Y = m, N = Math.min(n - 1, Math.max(0, _ + b - s)), v = (Y * n + N) * 4, C = e[b];
M += h[v] * C, P += h[v + 1] * C, I += h[v + 2] * C, S += h[v + 3] * C;
}
d[y] = M, d[y + 1] = P, d[y + 2] = I, d[y + 3] = S + u * (255 - S);
}
return c;
}
function Mt(r, e, t) {
for (var i = e.length, s = Math.floor(i / 2), h = r.data, n = r.width, a = r.height, o = n, l = a, c = st(o, l), d = c.data, u = 0, f = 0; f < l; f++)
for (var g = 0; g < o; g++) {
for (var m = f, _ = g, y = (f * o + g) * 4, M = 0, P = 0, I = 0, S = 0, b = 0; b < i; b++) {
var Y = Math.min(a - 1, Math.max(0, m + b - s)), N = _, v = (Y * n + N) * 4, C = e[b];
M += h[v] * C, P += h[v + 1] * C, I += h[v + 2] * C, S += h[v + 3] * C;
}
d[y] = M, d[y + 1] = P, d[y + 2] = I, d[y + 3] = S + u * (255 - S);
}
return c;
}
function Pt(r, e) {
const t = r.data, i = t.length;
for (let s = 0; s < i; s += 4)
t[s] += e, t[s + 1] += e, t[s + 2] += e;
return r;
}
function It(r, e) {
const t = r.data, i = t.length, s = 259 * (e + 255) / (255 * (259 - e));
for (let h = 0; h < i; h += 4)
t[h] = s * (t[h] - 128) + 128, t[h + 1] = s * (t[h + 1] - 128) + 128, t[h + 2] = s * (t[h + 2] - 128) + 128;
return r;
}
function Bt(r, e) {
const t = r.data, i = t.length;
for (let s = 0; s < i; s += 4) {
let h = t[s], n = t[s + 1], a = t[s + 2], o = 0.2126 * h + 0.7152 * n + 0.0722 * a;
t[s] = h + (o - h) * e, t[s + 1] = n + (o - n) * e, t[s + 2] = a + (o - a) * e;
}
return r;
}
function Ot(r, e) {
const t = r.data, i = t.length;
for (let s = 0; s < i; s += 4) {
const h = t[s], n = t[s + 1], a = t[s + 2], o = h * 0.393 + n * 0.769 + a * 0.189, l = h * 0.349 + n * 0.686 + a * 0.168, c = h * 0.272 + n * 0.534 + a * 0.131;
t[s] = h + (o - h) * e, t[s + 1] = n + (l - n) * e, t[s + 2] = a + (c - a) * e;
}
return r;
}
function Wt(r, e) {
const t = r.data, i = t.length;
for (let s = 0; s < i; s += 4) {
const h = t[s], n = t[s + 1], a = t[s + 2], o = 0.2126 * h + 0.7152 * n + 0.0722 * a >= e ? 255 : 0;
t[s] = t[s + 1] = t[s + 2] = o;
}
return r;
}
function Et(r, e) {
const t = r.data, i = t.length;
for (let s = 0; s < i; s += 4)
t[s] = Math.pow(t[s] / 255, e) * 255, t[s + 1] = Math.pow(t[s + 1] / 255, e) * 255, t[s + 2] = Math.pow(t[s + 2] / 255, e) * 255;
return r;
}
function Ft(r, e) {
const t = r.data, i = t.length, s = e.color.charAt(0) === "#" ? e.color.substr(1) : e.color, h = {
r: parseInt(s.substr(0, 2), 16),
g: parseInt(s.substr(2, 2), 16),
b: parseInt(s.substr(4, 2), 16)
};
for (let n = 0; n < i; n += 4)
t[n] -= (t[n] - h.r) * e.amount, t[n + 1] -= (t[n + 1] - h.g) * e.amount, t[n + 2] -= (t[n + 2] - h.b) * e.amount;
return r;
}
function Lt(r, e) {
if (typeof e == "string") {
let t = e.split("(")[0], i = Gt(e);
switch (t) {
case "invert":
return St(r, i);
case "brightness":
return Pt(r, -255 + i * 255);
case "blur":
return At(r, i);
case "contrast":
return It(r, -255 + i * 255);
case "grayscale":
return Bt(r, i);
case "sepia":
return Ot(r, i);
case "threshold":
return Wt(r, i);
case "gamma":
return Et(r, i);
}
} else
switch (e.type) {
case "colorize":
return Ft(r, e);
}
}
function Gt(r) {
return r = r.replace(/(invert)|(brightness)|(blur)|(contrast)|(grayscale)|(sepia)|(threshold)|(gamma)?\(/g, "").replace(")", ""), r.indexOf("%") !== -1 ? Number(r.replace("%", "")) / 100 : r.indexOf("px") !== -1 ? Number(r.replace("px", "")) : Number(r);
}
class Xt {
render() {
}
renderGraphics() {
}
clear() {
}
}
class Q extends Xt {
constructor(e, t, i, s) {
super(), arguments.length === 3 ? this.ctx = e : this.ctx = e.getContext("2d", s), this.width = t, this.height = i;
}
clear(e, t, i) {
e.clearRect(0, 0, t, i);
}
render(e, t, i) {
const s = t._matrix;
if (t.children) {
const h = t.children.slice(0), n = h.length;
for (let a = 0; a < n; a++) {
const o = h[a];
s.initialize(1, 0, 0, 1, 0, 0), s.appendTransform(
t.x,
t.y,
t.scaleX,
t.scaleY,
t.rotation,
t.skewX,
t.skewY,
t.originX,
t.originY
), e.save(), this._render(e, o, i ? null : s, i, !0), e.restore();
}
} else
this._render(e, t, i ? null : s, i);
}
_render(e, t, i, s, h) {
if (!t.isVisible())
return;
i && !t.fixed ? t._matrix.initialize(i.a, i.b, i.c, i.d, i.tx, i.ty) : s && !t.fixed ? t._matrix.initialize(
s.scale,
0,
0,
s.scale,
s.x * -1,
s.y * -1
) : t._matrix.initialize(1, 0, 0, 1, 0, 0), i = t._matrix, (h || !s) && i.appendTransform(
t.x,
t.y,
t.scaleX,
t.scaleY,
t.rotation,
t.skewX,
t.skewY,
t.originX,
t.originY
);
const n = t.clipGraphics;
n && (e.beginPath(), n._matrix.copy(i), n._matrix.appendTransform(
n.x,
n.y,
n.scaleX,
n.scaleY,
n.rotation,
n.skewX,
n.skewY,
n.originX,
n.originY
), e.setTransform(
n._matrix.a,
n._matrix.b,
n._matrix.c,
n._matrix.d,
n._matrix.tx,
n._matrix.ty
), n.render(e), e.clip(t.clipRuleNonzero ? "nonzero" : "evenodd"));
const a = t.absClipGraphics;
if (a && (e.beginPath(), a._matrix.initialize(1, 0, 0, 1, 0, 0), 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.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(
Lt(
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 && !s)
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 B) {
const o = t.children.slice(0), l = o.length;
for (let c = 0; c < l; c++)
e.save(), this._render(e, o[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 o = t.rect;
t.filterStyle && (e.filter = t.filterStyle), this.drawImage(
e,
t.img,
o[0],
o[1],
o[2],
o[3],
0,
0,
o[2],
o[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 B) {
const i = e.children, s = i.length;
let h = 0;
for (; h < s; 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 B {
constructor(e, t, i, s) {
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 B {
constructor(e, t, i, s) {
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, s), 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 s = e.getBoundingClientRect();
i = s.left, t = s.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 k = {
util: {
randomInt: (r, e) => r + Math.floor(Math.random() * (e - r + 1))
},
Stage: Yt,
WeStage: ht,
Graphics: V,
Bitmap: x,
Text: it,
Group: B,
Shape: Nt,
caxCanvasId: 0
}, A = typeof wx < "u" && wx.getSystemInfo && !wx.createCanvas && wx.createCanvasContext;
typeof wx < "u" && wx.getSystemInfo && wx.createCanvas;
function nt({ option: r }, e) {
let t = null;
if (r.linearGradient && r.colors) {
const i = r.linearGradient.length > 4 ? "createRadialGradient" : "createLinearGradient";
t = e[i](...r.linearGradient);
for (let s = 0; s < r.colors.length; s++)
t.addColorStop(...r.colors[s]);
}
return t || r.fillStyle;
}
function j(r) {
return JSON.parse(JSON.stringify(r));
}
const p = {
/**
* 形状(组合图案)
*/
shape: "shape",
rect: "rect",
circle: "circle",
line: "line",
image: "image",
text: "text",
group: "group",
container: "container"
};
class U extends k.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) {
this.option.font && (this.ctx.font = this.option.font);
const { width: t } = this.ctx?.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, s = 0) {
const { actualBoundingBoxDescent: h, width: n } = e.measureText(`${t}`), a = Math.ceil(h);
if (this.option.lineDecoration) {
const { lineSize: o, lineColor: l, lineOffset: c = 0, lineOffsetTop: d = 0, lineOffsetLeft: u = 0, color: f, lineDecoration: g, lineLevel: m } = this.option;
m !== "bottom" && e.fillText(t, i, s);
let _ = 0;
switch (g) {
case "middle":
_ = a / 2;
break;
case "bottom":
_ = a;
break;
}
e.strokeStyle = l || f || "#222", e.lineWidth = o || 2, e.beginPath(), e.moveTo(i + u, _ + s + (c || d)), e.lineTo(i + n + u, _ + s + (c || d)), e.stroke(), m === "bottom" && e.fillText(t, i, s);
} else
e.fillText(t, i, s);
}
/**
* 竖排代码来自 张鑫旭大神 http://www.zhangxinxu.com/wordpress/?p=7362
* isMeasure 如果为测量模式,只返回计算的文本高度
*/
renderVertical({ ctx: e }) {
const t = this.text.split(""), i = t.map((l) => this.getWidth(l)), s = e.textAlign, h = e.textBaseline;
let n = 0, a = 0;
const o = this.text;
return s === "left" ? n = n + Math.max.apply(null, i) / 2 : s === "right" && (n = n - Math.max.apply(null, i) / 2), h === "bottom" || h === "alphabetic" || h === "ideographic" ? a = a - i[0] / 2 : (h === "top" || h === "hanging") && (a = a + i[0] / 2), e.textAlign = "center", e.textBaseline = "middle", t.forEach((l, c) => {
const d = l.charCodeAt(0);
d <= 256 ? (e.translate(n, a), e.rotate(90 * Math.PI / 180), e.translate(-n, -a)) : c > 0 && o.charCodeAt(c - 1) < 256 && (a = a + i[c - 1] / 2), this.fill(e, l, n, a), d <= 256 && (e.translate(n, a), e.rotate(-90 * Math.PI / 180), e.translate(-n, -a));
const u = i[c];
a = a + u;
}), e.textAlign = s, e.textBaseline = h, a;
}
/**
* isMeasure 如果为测量模式,只返回计算的文本高度
*/
renderBreakLine({ ctx: e, isMeasure: t = !1, symbol: i = "..." }) {
const s = /\b(?![\u0020-\u002F\u003A-\u003F\u2000-\u206F\u2E00-\u2E7F\u3000-\u303F\uFF00-\uFF1F])|(?=[\u2E80-\u2FFF\u3040-\u9FFF])/g;
let h = "", n = 0, a = 1;
const o = [];
this.option.text.replace(s, function() {
o.push(arguments[arguments.length - 2] - 1);
});
let l = 0;
for (let c = 0; c < this.option.text.length; c++)
if (o.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 (a === 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, n, !1), a === this.option.maxLine && c !== this.option.text.length)
break;
n += this.option.lineHeight || 0, a++;
}
return h && !t && this.fill(e, h, 0, n, !1), n + this.option.lineHeight - 2;
}
}
class at extends k.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 === p.shape) {
this.setShape();
return;
}
switch (e.type) {
case p.rect:
e.r > 0 ? this.setRoundedRect(e) : this.rect(0, 0, e.width, e.height);
break;
case p.circle: {
let s = 1, h = 0;
e.angle && (s = e.angle / 360), e.sAngle && (h = e.sAngle / 360), this.arc(
0,
0,
e.r,
h * Math.PI * 2,
s * Math.PI * 2,
!1
);
break;
}
case p.line:
this.moveTo(0, 0), this.lineTo(e.long, 0);
break;
}
const i = nt({ option: e }, this.ctx);
!("fillStyle" in e) && !e.strokeStyle &&