UNPKG

@realsee/dnalogel

Version:
1,285 lines (1,272 loc) 1.39 MB
var Rf = Object.defineProperty, Vf = Object.defineProperties; var Qf = Object.getOwnPropertyDescriptors; var ul = Object.getOwnPropertySymbols; var Gf = Object.prototype.hasOwnProperty, Nf = Object.prototype.propertyIsEnumerable; var Pr = (n, t, e) => t in n ? Rf(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, R = (n, t) => { for (var e in t || (t = {})) Gf.call(t, e) && Pr(n, e, t[e]); if (ul) for (var e of ul(t)) Nf.call(t, e) && Pr(n, e, t[e]); return n; }, fe = (n, t) => Vf(n, Qf(t)); var u = (n, t, e) => (Pr(n, typeof t != "symbol" ? t + "" : t, e), e); var _ = (n, t, e) => new Promise((i, s) => { var o = (l) => { try { a(e.next(l)); } catch (c) { s(c); } }, r = (l) => { try { a(e.throw(l)); } catch (c) { s(c); } }, a = (l) => l.done ? i(l.value) : Promise.resolve(l.value).then(o, r); a((e = e.apply(n, t)).next()); }); import { Camera as Hf, Subscribe as gt, Five as et } from "@realsee/five"; import * as P from "three"; import { Vector3 as ne, LineSegments as Ff, Group as gn, Raycaster as vi, MeshBasicMaterial as ps, CanvasTexture as _f, AnimationMixer as Wf, Color as Sn, TextureLoader as Lh, Vector2 as it, Object3D as jh, Face3 as Uf, PlaneGeometry as Yf, sRGBEncoding as Xf, LinearFilter as Kr, Mesh as ds, CurvePath as Zf, LineCurve3 as Jf, TubeGeometry as qf, ShaderMaterial as zh, SphereGeometry as Kf, DoubleSide as Oh, RingGeometry as $f, Quaternion as Pa, Euler as fl, Matrix4 as rs, VideoTexture as em, Vector4 as tm, SphereBufferGeometry as im } from "three"; import { CSS3DRenderer as nm, CSS3DObject as $r } from "three/examples/jsm/renderers/CSS3DRenderer"; import Is from "hammerjs"; import { Line as Bh } from "@realsee/five/line"; import { FBXLoader as Rh } from "three/examples/jsm/loaders/FBXLoader"; import sm from "earcut"; import ea from "animejs"; import { GLTFLoader as om } from "@realsee/five/gltf-loader"; function rm() { console.debug( "%c %c@realsee/dnalogel %cv3.12.7", [ "background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAMCAMAAACHgmeRAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAABLFBMVEUAAAAapPoap/oaqvkbrfkbr/gZnfwZoPsaqfnD4v/E4/8Ylv0clPm93/+/4P/B4f8Yj/683/8Wif+33P8Uhv+x2f8ShP+s1v8Pgf+n0/8Nf/+h0f8Lff8Lff8Nf/9dl/+czv8KfP8KfP+Lxf+Uyv+Xy/+Hwv+Jw/+Mxf+Oxv+RyP8aovsapfoap/oZmfwZm/wZnvsYnPsYkf4YlP0NePsDYfgYcfi43f+63v8Xiv8Xjf4EWfwCV/sWZ/qz2v+02/8Vh/8WiP8EUf8CTf4WXv2u1/+v2P8Thf8Thv8ETf8CR/8VV/+o1f+q1f8Qgv8Rg/8DSv8BRf8UVP+j0v+k0v8OgP8Pgf8DR/8DQv9Nhf+dzv+fz/+Kv/+Vyv+Xy/+azf+Oxv+Qx/+SyP////8MUhLdAAAAK3RSTlMACEWQ2bd98uQECPXxqO7c+Pb49vj2+Pb49vj23Oul8fMHA+TwerXXjEIG2P+bHgAAAAFiS0dEY1y+LaoAAAB+SURBVAjXY2BgZGJmYWVgYGBgY9fW0eVg4ORi4NbTNzDk4eXjZxAwMjYxNTO3EGQQsrSytrG1sxdmEHFwdHJ2cXUTZRBz9/D08vbxFWeQ8PMPCAwKDpFkkAoNC4+IjIqWZpCRlZOPiY2LV2BQVGJQTkhMUlEFWaOmrqGpxQAAyg0S9Dq+VPYAAAAASUVORK5CYII=')", "background-repeat: no-repeat", "background-position: 0 center", "padding-left: 8px" ].join(";"), "", "background-color: #12ce9b;color:black;padding:0 6px;border-radius: 3px" ); } function am() { const n = typeof OffscreenCanvas != "undefined", t = n && new OffscreenCanvas(1, 1).getContext("webgl") !== null; n && !t && Object.assign(window, { OffscreenCanvas: function(e, i) { const s = document.createElement("canvas"); return s.width = e, s.height = i, s; } }); } function Vh() { } const ml = () => Promise.resolve(), gl = { __queue: Promise.resolve() }; function lm(n = ml) { gl.__queue = gl.__queue.then(n).catch(ml); } function Qs(n, t, e) { const i = n.x, s = n.y, o = Math.floor(i / t * 1e4) / 1e4, r = Math.floor(s / e * 1e4) / 1e4; return { x: o, y: r }; } function Er(n, t, e) { const { x: i, y: s } = n, o = i * t, r = s * e; return { x: o, y: r }; } function Gs(n) { if (n.length < 2) return {}; const t = n.slice(-2), e = t[0], i = { x: (t[0].x + t[1].x) / 2, y: (t[0].y + t[1].y) / 2 }; return { control: e, end: i }; } function cm(n, t, e = Vh) { new Promise((i) => { setTimeout(() => { e(), i(!0); }, t * n); }); } const dm = window, pl = window.requestAnimationFrame || dm.webkitRequestAnimationFrame || ((n) => setTimeout(n, 16)); function so(n, t = 0) { t <= 0 ? pl(n) : pl(() => so(n, t - 1)); } var zt = Object.freeze({ Linear: Object.freeze({ None: function(n) { return n; }, In: function(n) { return this.None(n); }, Out: function(n) { return this.None(n); }, InOut: function(n) { return this.None(n); } }), Quadratic: Object.freeze({ In: function(n) { return n * n; }, Out: function(n) { return n * (2 - n); }, InOut: function(n) { return (n *= 2) < 1 ? 0.5 * n * n : -0.5 * (--n * (n - 2) - 1); } }), Cubic: Object.freeze({ In: function(n) { return n * n * n; }, Out: function(n) { return --n * n * n + 1; }, InOut: function(n) { return (n *= 2) < 1 ? 0.5 * n * n * n : 0.5 * ((n -= 2) * n * n + 2); } }), Quartic: Object.freeze({ In: function(n) { return n * n * n * n; }, Out: function(n) { return 1 - --n * n * n * n; }, InOut: function(n) { return (n *= 2) < 1 ? 0.5 * n * n * n * n : -0.5 * ((n -= 2) * n * n * n - 2); } }), Quintic: Object.freeze({ In: function(n) { return n * n * n * n * n; }, Out: function(n) { return --n * n * n * n * n + 1; }, InOut: function(n) { return (n *= 2) < 1 ? 0.5 * n * n * n * n * n : 0.5 * ((n -= 2) * n * n * n * n + 2); } }), Sinusoidal: Object.freeze({ In: function(n) { return 1 - Math.sin((1 - n) * Math.PI / 2); }, Out: function(n) { return Math.sin(n * Math.PI / 2); }, InOut: function(n) { return 0.5 * (1 - Math.sin(Math.PI * (0.5 - n))); } }), Exponential: Object.freeze({ In: function(n) { return n === 0 ? 0 : Math.pow(1024, n - 1); }, Out: function(n) { return n === 1 ? 1 : 1 - Math.pow(2, -10 * n); }, InOut: function(n) { return n === 0 ? 0 : n === 1 ? 1 : (n *= 2) < 1 ? 0.5 * Math.pow(1024, n - 1) : 0.5 * (-Math.pow(2, -10 * (n - 1)) + 2); } }), Circular: Object.freeze({ In: function(n) { return 1 - Math.sqrt(1 - n * n); }, Out: function(n) { return Math.sqrt(1 - --n * n); }, InOut: function(n) { return (n *= 2) < 1 ? -0.5 * (Math.sqrt(1 - n * n) - 1) : 0.5 * (Math.sqrt(1 - (n -= 2) * n) + 1); } }), Elastic: Object.freeze({ In: function(n) { return n === 0 ? 0 : n === 1 ? 1 : -Math.pow(2, 10 * (n - 1)) * Math.sin((n - 1.1) * 5 * Math.PI); }, Out: function(n) { return n === 0 ? 0 : n === 1 ? 1 : Math.pow(2, -10 * n) * Math.sin((n - 0.1) * 5 * Math.PI) + 1; }, InOut: function(n) { return n === 0 ? 0 : n === 1 ? 1 : (n *= 2, n < 1 ? -0.5 * Math.pow(2, 10 * (n - 1)) * Math.sin((n - 1.1) * 5 * Math.PI) : 0.5 * Math.pow(2, -10 * (n - 1)) * Math.sin((n - 1.1) * 5 * Math.PI) + 1); } }), Back: Object.freeze({ In: function(n) { var t = 1.70158; return n === 1 ? 1 : n * n * ((t + 1) * n - t); }, Out: function(n) { var t = 1.70158; return n === 0 ? 0 : --n * n * ((t + 1) * n + t) + 1; }, InOut: function(n) { var t = 2.5949095; return (n *= 2) < 1 ? 0.5 * (n * n * ((t + 1) * n - t)) : 0.5 * ((n -= 2) * n * ((t + 1) * n + t) + 2); } }), Bounce: Object.freeze({ In: function(n) { return 1 - zt.Bounce.Out(1 - n); }, Out: function(n) { return n < 1 / 2.75 ? 7.5625 * n * n : n < 2 / 2.75 ? 7.5625 * (n -= 1.5 / 2.75) * n + 0.75 : n < 2.5 / 2.75 ? 7.5625 * (n -= 2.25 / 2.75) * n + 0.9375 : 7.5625 * (n -= 2.625 / 2.75) * n + 0.984375; }, InOut: function(n) { return n < 0.5 ? zt.Bounce.In(n * 2) * 0.5 : zt.Bounce.Out(n * 2 - 1) * 0.5 + 0.5; } }), generatePow: function(n) { return n === void 0 && (n = 4), n = n < Number.EPSILON ? Number.EPSILON : n, n = n > 1e4 ? 1e4 : n, { In: function(t) { return Math.pow(t, n); }, Out: function(t) { return 1 - Math.pow(1 - t, n); }, InOut: function(t) { return t < 0.5 ? Math.pow(t * 2, n) / 2 : (1 - Math.pow(2 - t * 2, n)) / 2 + 0.5; } }; } }), dn = function() { return performance.now(); }, Qh = ( /** @class */ function() { function n() { this._tweens = {}, this._tweensAddedDuringUpdate = {}; } return n.prototype.getAll = function() { var t = this; return Object.keys(this._tweens).map(function(e) { return t._tweens[e]; }); }, n.prototype.removeAll = function() { this._tweens = {}; }, n.prototype.add = function(t) { this._tweens[t.getId()] = t, this._tweensAddedDuringUpdate[t.getId()] = t; }, n.prototype.remove = function(t) { delete this._tweens[t.getId()], delete this._tweensAddedDuringUpdate[t.getId()]; }, n.prototype.update = function(t, e) { t === void 0 && (t = dn()), e === void 0 && (e = !1); var i = Object.keys(this._tweens); if (i.length === 0) return !1; for (; i.length > 0; ) { this._tweensAddedDuringUpdate = {}; for (var s = 0; s < i.length; s++) { var o = this._tweens[i[s]], r = !e; o && o.update(t, r) === !1 && !e && delete this._tweens[i[s]]; } i = Object.keys(this._tweensAddedDuringUpdate); } return !0; }, n; }() ), Ti = { Linear: function(n, t) { var e = n.length - 1, i = e * t, s = Math.floor(i), o = Ti.Utils.Linear; return t < 0 ? o(n[0], n[1], i) : t > 1 ? o(n[e], n[e - 1], e - i) : o(n[s], n[s + 1 > e ? e : s + 1], i - s); }, Bezier: function(n, t) { for (var e = 0, i = n.length - 1, s = Math.pow, o = Ti.Utils.Bernstein, r = 0; r <= i; r++) e += s(1 - t, i - r) * s(t, r) * n[r] * o(i, r); return e; }, CatmullRom: function(n, t) { var e = n.length - 1, i = e * t, s = Math.floor(i), o = Ti.Utils.CatmullRom; return n[0] === n[e] ? (t < 0 && (s = Math.floor(i = e * (1 + t))), o(n[(s - 1 + e) % e], n[s], n[(s + 1) % e], n[(s + 2) % e], i - s)) : t < 0 ? n[0] - (o(n[0], n[0], n[1], n[1], -i) - n[0]) : t > 1 ? n[e] - (o(n[e], n[e], n[e - 1], n[e - 1], i - e) - n[e]) : o(n[s ? s - 1 : 0], n[s], n[e < s + 1 ? e : s + 1], n[e < s + 2 ? e : s + 2], i - s); }, Utils: { Linear: function(n, t, e) { return (t - n) * e + n; }, Bernstein: function(n, t) { var e = Ti.Utils.Factorial; return e(n) / e(t) / e(n - t); }, Factorial: function() { var n = [1]; return function(t) { var e = 1; if (n[t]) return n[t]; for (var i = t; i > 1; i--) e *= i; return n[t] = e, e; }; }(), CatmullRom: function(n, t, e, i, s) { var o = (e - n) * 0.5, r = (i - t) * 0.5, a = s * s, l = s * a; return (2 * t - 2 * e + o + r) * l + (-3 * t + 3 * e - 2 * o - r) * a + o * s + t; } } }, Ea = ( /** @class */ function() { function n() { } return n.nextId = function() { return n._nextId++; }, n._nextId = 0, n; }() ), ta = new Qh(), Mo = ( /** @class */ function() { function n(t, e) { e === void 0 && (e = ta), this._object = t, this._group = e, this._isPaused = !1, this._pauseStart = 0, this._valuesStart = {}, this._valuesEnd = {}, this._valuesStartRepeat = {}, this._duration = 1e3, this._isDynamic = !1, this._initialRepeat = 0, this._repeat = 0, this._yoyo = !1, this._isPlaying = !1, this._reversed = !1, this._delayTime = 0, this._startTime = 0, this._easingFunction = zt.Linear.None, this._interpolationFunction = Ti.Linear, this._chainedTweens = [], this._onStartCallbackFired = !1, this._onEveryStartCallbackFired = !1, this._id = Ea.nextId(), this._isChainStopped = !1, this._propertiesAreSetUp = !1, this._goToEnd = !1; } return n.prototype.getId = function() { return this._id; }, n.prototype.isPlaying = function() { return this._isPlaying; }, n.prototype.isPaused = function() { return this._isPaused; }, n.prototype.to = function(t, e) { if (e === void 0 && (e = 1e3), this._isPlaying) throw new Error("Can not call Tween.to() while Tween is already started or paused. Stop the Tween first."); return this._valuesEnd = t, this._propertiesAreSetUp = !1, this._duration = e, this; }, n.prototype.duration = function(t) { return t === void 0 && (t = 1e3), this._duration = t, this; }, n.prototype.dynamic = function(t) { return t === void 0 && (t = !1), this._isDynamic = t, this; }, n.prototype.start = function(t, e) { if (t === void 0 && (t = dn()), e === void 0 && (e = !1), this._isPlaying) return this; if (this._group && this._group.add(this), this._repeat = this._initialRepeat, this._reversed) { this._reversed = !1; for (var i in this._valuesStartRepeat) this._swapEndStartRepeatValues(i), this._valuesStart[i] = this._valuesStartRepeat[i]; } if (this._isPlaying = !0, this._isPaused = !1, this._onStartCallbackFired = !1, this._onEveryStartCallbackFired = !1, this._isChainStopped = !1, this._startTime = t, this._startTime += this._delayTime, !this._propertiesAreSetUp || e) { if (this._propertiesAreSetUp = !0, !this._isDynamic) { var s = {}; for (var o in this._valuesEnd) s[o] = this._valuesEnd[o]; this._valuesEnd = s; } this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, e); } return this; }, n.prototype.startFromCurrentValues = function(t) { return this.start(t, !0); }, n.prototype._setupProperties = function(t, e, i, s, o) { for (var r in i) { var a = t[r], l = Array.isArray(a), c = l ? "array" : typeof a, d = !l && Array.isArray(i[r]); if (!(c === "undefined" || c === "function")) { if (d) { var h = i[r]; if (h.length === 0) continue; for (var f = [a], m = 0, A = h.length; m < A; m += 1) { var p = this._handleRelativeValue(a, h[m]); if (isNaN(p)) { d = !1, console.warn("Found invalid interpolation list. Skipping."); break; } f.push(p); } d && (i[r] = f); } if ((c === "object" || l) && a && !d) { e[r] = l ? [] : {}; var g = a; for (var b in g) e[r][b] = g[b]; s[r] = l ? [] : {}; var h = i[r]; if (!this._isDynamic) { var y = {}; for (var b in h) y[b] = h[b]; i[r] = h = y; } this._setupProperties(g, e[r], h, s[r], o); } else (typeof e[r] == "undefined" || o) && (e[r] = a), l || (e[r] *= 1), d ? s[r] = i[r].slice().reverse() : s[r] = e[r] || 0; } } }, n.prototype.stop = function() { return this._isChainStopped || (this._isChainStopped = !0, this.stopChainedTweens()), this._isPlaying ? (this._group && this._group.remove(this), this._isPlaying = !1, this._isPaused = !1, this._onStopCallback && this._onStopCallback(this._object), this) : this; }, n.prototype.end = function() { return this._goToEnd = !0, this.update(1 / 0), this; }, n.prototype.pause = function(t) { return t === void 0 && (t = dn()), this._isPaused || !this._isPlaying ? this : (this._isPaused = !0, this._pauseStart = t, this._group && this._group.remove(this), this); }, n.prototype.resume = function(t) { return t === void 0 && (t = dn()), !this._isPaused || !this._isPlaying ? this : (this._isPaused = !1, this._startTime += t - this._pauseStart, this._pauseStart = 0, this._group && this._group.add(this), this); }, n.prototype.stopChainedTweens = function() { for (var t = 0, e = this._chainedTweens.length; t < e; t++) this._chainedTweens[t].stop(); return this; }, n.prototype.group = function(t) { return t === void 0 && (t = ta), this._group = t, this; }, n.prototype.delay = function(t) { return t === void 0 && (t = 0), this._delayTime = t, this; }, n.prototype.repeat = function(t) { return t === void 0 && (t = 0), this._initialRepeat = t, this._repeat = t, this; }, n.prototype.repeatDelay = function(t) { return this._repeatDelayTime = t, this; }, n.prototype.yoyo = function(t) { return t === void 0 && (t = !1), this._yoyo = t, this; }, n.prototype.easing = function(t) { return t === void 0 && (t = zt.Linear.None), this._easingFunction = t, this; }, n.prototype.interpolation = function(t) { return t === void 0 && (t = Ti.Linear), this._interpolationFunction = t, this; }, n.prototype.chain = function() { for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e]; return this._chainedTweens = t, this; }, n.prototype.onStart = function(t) { return this._onStartCallback = t, this; }, n.prototype.onEveryStart = function(t) { return this._onEveryStartCallback = t, this; }, n.prototype.onUpdate = function(t) { return this._onUpdateCallback = t, this; }, n.prototype.onRepeat = function(t) { return this._onRepeatCallback = t, this; }, n.prototype.onComplete = function(t) { return this._onCompleteCallback = t, this; }, n.prototype.onStop = function(t) { return this._onStopCallback = t, this; }, n.prototype.update = function(t, e) { if (t === void 0 && (t = dn()), e === void 0 && (e = !0), this._isPaused) return !0; var i, s, o = this._startTime + this._duration; if (!this._goToEnd && !this._isPlaying) { if (t > o) return !1; e && this.start(t, !0); } if (this._goToEnd = !1, t < this._startTime) return !0; this._onStartCallbackFired === !1 && (this._onStartCallback && this._onStartCallback(this._object), this._onStartCallbackFired = !0), this._onEveryStartCallbackFired === !1 && (this._onEveryStartCallback && this._onEveryStartCallback(this._object), this._onEveryStartCallbackFired = !0), s = (t - this._startTime) / this._duration, s = this._duration === 0 || s > 1 ? 1 : s; var r = this._easingFunction(s); if (this._updateProperties(this._object, this._valuesStart, this._valuesEnd, r), this._onUpdateCallback && this._onUpdateCallback(this._object, s), s === 1) if (this._repeat > 0) { isFinite(this._repeat) && this._repeat--; for (i in this._valuesStartRepeat) !this._yoyo && typeof this._valuesEnd[i] == "string" && (this._valuesStartRepeat[i] = // eslint-disable-next-line // @ts-ignore FIXME? this._valuesStartRepeat[i] + parseFloat(this._valuesEnd[i])), this._yoyo && this._swapEndStartRepeatValues(i), this._valuesStart[i] = this._valuesStartRepeat[i]; return this._yoyo && (this._reversed = !this._reversed), this._repeatDelayTime !== void 0 ? this._startTime = t + this._repeatDelayTime : this._startTime = t + this._delayTime, this._onRepeatCallback && this._onRepeatCallback(this._object), this._onEveryStartCallbackFired = !1, !0; } else { this._onCompleteCallback && this._onCompleteCallback(this._object); for (var a = 0, l = this._chainedTweens.length; a < l; a++) this._chainedTweens[a].start(this._startTime + this._duration, !1); return this._isPlaying = !1, !1; } return !0; }, n.prototype._updateProperties = function(t, e, i, s) { for (var o in i) if (e[o] !== void 0) { var r = e[o] || 0, a = i[o], l = Array.isArray(t[o]), c = Array.isArray(a), d = !l && c; d ? t[o] = this._interpolationFunction(a, s) : typeof a == "object" && a ? this._updateProperties(t[o], r, a, s) : (a = this._handleRelativeValue(r, a), typeof a == "number" && (t[o] = r + (a - r) * s)); } }, n.prototype._handleRelativeValue = function(t, e) { return typeof e != "string" ? e : e.charAt(0) === "+" || e.charAt(0) === "-" ? t + parseFloat(e) : parseFloat(e); }, n.prototype._swapEndStartRepeatValues = function(t) { var e = this._valuesStartRepeat[t], i = this._valuesEnd[t]; typeof i == "string" ? this._valuesStartRepeat[t] = this._valuesStartRepeat[t] + parseFloat(i) : this._valuesStartRepeat[t] = this._valuesEnd[t], this._valuesEnd[t] = e; }, n; }() ), hm = "20.0.3", um = Ea.nextId, Ut = ta, fm = Ut.getAll.bind(Ut), mm = Ut.removeAll.bind(Ut), gm = Ut.add.bind(Ut), Gh = Ut.remove.bind(Ut), pm = Ut.update.bind(Ut), Al = { Easing: zt, Group: Qh, Interpolation: Ti, now: dn, Sequence: Ea, nextId: um, Tween: Mo, VERSION: hm, getAll: fm, removeAll: mm, add: gm, remove: Gh, update: pm }; function Am(n, t, e, i = zt.Linear.None) { const s = new Mo(n).to(t, e).easing(i).start(); function o(r) { s.update(r) && requestAnimationFrame(o); } return requestAnimationFrame(o), s; } var hi = /* @__PURE__ */ ((n) => (n.Drawline = "Drawline", n.Undo = "Undo", n.Exit = "Exit", n))(hi || {}); const hs = Symbol("$$PAINT_BRUSH_EVENT$$"); function Ns(n) { return n[hs] || (n[hs] = {}), n[hs]; } function vm(n) { n[hs] || delete n[hs]; } let bm = class { /** * 判断是否注册了事件 * @param name 事件类型 */ hasListener(t) { const e = Ns(this); return e && e[t] && e[t].length > 0; } /** * 注册事件 * @param name 事件类型 * @param callback 事件回调函数 * @param once 是否只执行一次 * @returns 解除事件 * @template K 预设的监听事件名称 * @template C 回调函数函数上下文 */ on(t, e, i) { const s = Ns(this); return s[t] || (s[t] = []), s[t].push([e, i || !1]), () => this.off(t, e); } /** * 注册事件(是否只执行一次) * @param name 事件类型 * @param callback 事件回调函数 * @returns 解除事件 * @template K 预设的监听事件名称 * @template C 回调函数函数上下文 */ once(t, e) { return this.on(t, e, !0); } /** * 解除事件 * * 如果 name 不传的话解除对应所有事件 * 如果 name, callback 不传的话解除所有name的所有事件 * @param name 事件类型 * @param callback 事件回调函数 * @template K 预设的监听事件名称 */ off(t, e) { if (t === void 0) { vm(this); return; } const i = Ns(this); if (i[t] || (i[t] = []), e === void 0) { i[t].length = 0; return; } let s = 0; for (; s < i[t].length && i[t][s][0] !== e; s++) ; s < i[t].length && i[t].splice(s, 1); } /** * 触发事件 * @param name 事件类型 * @param data 触发事件的数据 * @returns canceled 是否被触发取消 * @template K 预设的监听事件名称 */ emit(t, ...e) { let i = !1; const o = Ns(this)[t] || []; for (let r of o.slice()) { const [a, l = !1] = r, c = a(...e); l && this.off(t, a), c === !1 && (i = !0); } return i; } }; function ci() { return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1); } function tt() { return (ci() + ci() + "-" + ci() + "-4" + ci().substr(0, 3) + "-" + ci() + "-" + ci() + ci() + ci()).toLowerCase(); } const ym = ` <style type="text/css"> #_gl_paintBrush { position: fixed; top: 0; bottom: 0; left: 0; right: 0; transform: translateZ(0); z-index: 1997; pointer-events: none; opacity: 0; transition: all 500ms; } #_gl_paintBrush.brushing { opacity: 1; } #_gl_paintBrush ._paintBrush-canvas { position: absolute; width: 100%; height: 100%; left: 0; top: 0; } #_gl_paintBrush ._paintBrush-canvas--sync { pointer-events: none; z-index: 0; position: absolute; width: 100%; height: 100%; left: 0; top: 0; } #_gl_paintBrush ._paintBrush-canvas { pointer-events: none; z-index: 1; } #_gl_paintBrush.brushing ._paintBrush-canvas { pointer-events: auto; } #_gl_paintBrush ._paintBrush-ctrl { width: 140px; height: 52px; position: absolute; bottom: 28px; right: 50%; transform: translateX(50%); font-size: 10px; color: white; z-index: 2; } #_gl_paintBrush.brushing ._paintBrush-ctrl { pointer-events: auto; } #_gl_paintBrush ._paintBrush-ctrl ._paintBrush-ctrlinner { display: flex; justify-content: space-between; align-items: center; width: 100%; height: 100%; border-radius: 26px; padding: 8px 16px; box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.2); background-image: linear-gradient(180deg, hsl(0deg 0% 0% / 57%), hsl(0deg 0% 0% / 70%) 117%); } ._paintBrush-ctrlitem { display: flex; flex-direction: column; justify-content: center; align-items: center; width: 38px; height: 38px; cursor: pointer; } ._paintBrush-ctrlitem--undo >.brush-icon{ background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iMjJweCIgaGVpZ2h0PSIyMnB4IiB2aWV3Qm94PSIwIDAgMjIgMjIiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8ZGVmcz4KICAgICAgICA8bGluZWFyR3JhZGllbnQgeDE9IjUwJSIgeTE9IjQ1LjY3NTI0OCUiIHgyPSItMTYuOTYxMDIzJSIgeTI9Ijg0LjIzODQxOTglIiBpZD0ibGluZWFyR3JhZGllbnQtMSI+CiAgICAgICAgICAgIDxzdG9wIHN0b3AtY29sb3I9IiNGRkZGRkYiIG9mZnNldD0iMCUiPjwvc3RvcD4KICAgICAgICAgICAgPHN0b3Agc3RvcC1jb2xvcj0iI0ZGRkZGRiIgc3RvcC1vcGFjaXR5PSIwLjMwMzY3Njc5MiIgb2Zmc2V0PSIxMDAlIj48L3N0b3A+CiAgICAgICAgPC9saW5lYXJHcmFkaWVudD4KICAgIDwvZGVmcz4KICAgIDxnIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxnIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0xNDAuMDAwMDAwLCAtNzQwLjAwMDAwMCkiPgogICAgICAgICAgICA8ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgxNDAuMDAwMDAwLCA3NDAuMDAwMDAwKSI+CiAgICAgICAgICAgICAgICA8cmVjdCBmaWxsPSIjRDhEOEQ4IiBvcGFjaXR5PSIwIiB4PSIwIiB5PSIwIiB3aWR0aD0iMjIiIGhlaWdodD0iMjIiPjwvcmVjdD4KICAgICAgICAgICAgICAgIDxnIHRyYW5zZm9ybT0idHJhbnNsYXRlKDQuMDAwMDAwLCAyLjk5MDY1OSkiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIyIj4KICAgICAgICAgICAgICAgICAgICA8cGF0aCBkPSJNMCwzLjc1ODc1NzA5IEw5Ljg0Mzc1LDMuNzU4NzU3MDkgQzEyLjY5MTQ2ODIsMy43NTg3NTcwOSAxNSw2LjA2NzI4ODg1IDE1LDguOTE1MDA3MDkgQzE1LDExLjc2MjcyNTMgMTIuNjkxNDY4MiwxNC4wNzEyNTcxIDkuODQzNzUsMTQuMDcxMjU3MSBMMSwxNC4wNzEyNTcxIiBzdHJva2U9InVybCgjbGluZWFyR3JhZGllbnQtMSkiPjwvcGF0aD4KICAgICAgICAgICAgICAgICAgICA8cG9seWxpbmUgc3Ryb2tlPSIjRkZGRkZGIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBwb2ludHM9IjMuNzkwMjI3MDcgNy41Mzk2NjA2NCAwIDMuNzU4NzU3MDkgMy43OTAyMjcwNyAwIj48L3BvbHlsaW5lPgogICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICA8L2c+CiAgICAgICAgPC9nPgogICAgPC9nPgo8L3N2Zz4=); background-size: 100%; width: 22px; height: 22px; } ._paintBrush-ctrlitem--close >.brush-icon { background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iMjJweCIgaGVpZ2h0PSIyMnB4IiB2aWV3Qm94PSIwIDAgMjIgMjIiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8ZGVmcz4KICAgICAgICA8bGluZWFyR3JhZGllbnQgeDE9IjUwLjAyMDY5MyUiIHkxPSItMTMuNzMzMzc1MSUiIHgyPSI1MCUiIHkyPSIxMTQuMTEwOTk0JSIgaWQ9ImxpbmVhckdyYWRpZW50LTEiPgogICAgICAgICAgICA8c3RvcCBzdG9wLWNvbG9yPSIjRkZGRkZGIiBvZmZzZXQ9IjAlIj48L3N0b3A+CiAgICAgICAgICAgIDxzdG9wIHN0b3AtY29sb3I9IiNGRkZGRkYiIHN0b3Atb3BhY2l0eT0iMC42MDEwNDM0ODgiIG9mZnNldD0iNDkuMzA4NDg4MiUiPjwvc3RvcD4KICAgICAgICAgICAgPHN0b3Agc3RvcC1jb2xvcj0iI0ZGRkZGRiIgb2Zmc2V0PSIxMDAlIj48L3N0b3A+CiAgICAgICAgPC9saW5lYXJHcmFkaWVudD4KICAgICAgICA8bGluZWFyR3JhZGllbnQgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSIgaWQ9ImxpbmVhckdyYWRpZW50LTIiPgogICAgICAgICAgICA8c3RvcCBzdG9wLWNvbG9yPSIjRkZGRkZGIiBvZmZzZXQ9IjAlIj48L3N0b3A+CiAgICAgICAgICAgIDxzdG9wIHN0b3AtY29sb3I9IiNGRkZGRkYiIG9mZnNldD0iNTUuOTY4MTUzNSUiPjwvc3RvcD4KICAgICAgICAgICAgPHN0b3Agc3RvcC1jb2xvcj0iI0ZGRkZGRiIgb2Zmc2V0PSIxMDAlIj48L3N0b3A+CiAgICAgICAgPC9saW5lYXJHcmFkaWVudD4KICAgIDwvZGVmcz4KICAgIDxnIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxnPgogICAgICAgICAgICA8cmVjdCBmaWxsPSIjRDhEOEQ4IiBvcGFjaXR5PSIwIiB4PSIwIiB5PSIwIiB3aWR0aD0iMjIiIGhlaWdodD0iMjIiPjwvcmVjdD4KICAgICAgICAgICAgPGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoNC4wMDAwMDAsIDUuMDAwMDAwKSIgZmlsbC1ydWxlPSJub256ZXJvIj4KICAgICAgICAgICAgICAgIDxnPgogICAgICAgICAgICAgICAgICAgIDxwYXRoIGQ9Ik03LC0yLjk4ODE2NTY4IEM3LjUxMjgzNTg0LC0yLjk4ODE2NTY4IDcuOTM1NTA3MTYsLTIuNjAyMTI1NDkgNy45OTMyNzIyNywtMi4xMDQ3ODY4MSBMOCwtMS45ODgxNjU2OCBMOCwxMy45OTgxMTQ2IEM4LDE0LjU1MDM5OTMgNy41NTIyODQ3NSwxNC45OTgxMTQ2IDcsMTQuOTk4MTE0NiBDNi40ODcxNjQxNiwxNC45OTgxMTQ2IDYuMDY0NDkyODQsMTQuNjEyMDc0NCA2LjAwNjcyNzczLDE0LjExNDczNTcgTDYsMTMuOTk4MTE0NiBMNiwtMS45ODgxNjU2OCBDNiwtMi41NDA0NTA0MyA2LjQ0NzcxNTI1LC0yLjk4ODE2NTY4IDcsLTIuOTg4MTY1NjggWiIgZmlsbD0idXJsKCNsaW5lYXJHcmFkaWVudC0xKSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoNy4wMDAwMDAsIDYuMDA0OTc0KSByb3RhdGUoLTQ1LjAwMDAwMCkgdHJhbnNsYXRlKC03LjAwMDAwMCwgLTYuMDA0OTc0KSAiPjwvcGF0aD4KICAgICAgICAgICAgICAgICAgICA8cGF0aCBkPSJNNywtMi45ODgxNjU2OCBDNy41MTI4MzU4NCwtMi45ODgxNjU2OCA3LjkzNTUwNzE2LC0yLjYwMjEyNTQ5IDcuOTkzMjcyMjcsLTIuMTA0Nzg2ODEgTDgsLTEuOTg4MTY1NjggTDgsMTMuOTk4MTE0NiBDOCwxNC41NTAzOTkzIDcuNTUyMjg0NzUsMTQuOTk4MTE0NiA3LDE0Ljk5ODExNDYgQzYuNDg3MTY0MTYsMTQuOTk4MTE0NiA2LjA2NDQ5Mjg0LDE0LjYxMjA3NDQgNi4wMDY3Mjc3MywxNC4xMTQ3MzU3IEw2LDEzLjk5ODExNDYgTDYsLTEuOTg4MTY1NjggQzYsLTIuNTQwNDUwNDMgNi40NDc3MTUyNSwtMi45ODgxNjU2OCA3LC0yLjk4ODE2NTY4IFoiIGZpbGw9InVybCgjbGluZWFyR3JhZGllbnQtMikiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDcuMDAwMDAwLCA2LjAwNDk3NCkgcm90YXRlKC0xMzUuMDAwMDAwKSB0cmFuc2xhdGUoLTcuMDAwMDAwLCAtNi4wMDQ5NzQpICI+PC9wYXRoPgogICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICA8L2c+CiAgICAgICAgPC9nPgogICAgPC9nPgo8L3N2Zz4=); background-size: 100%; width: 22px; height: 22px; } </style> `; let wm = class extends bm { constructor(e) { super(); u(this, "configs"); u(this, "clientWidth"); u(this, "clientHeight"); u(this, "ready", !1); u(this, "uuid", tt()); u(this, "tween"); u(this, "tweening", !1); u(this, "container"); u(this, "canvas"); u(this, "data", {}); u(this, "tempLine", {}); this.configs = e, this.clientWidth = document.body.clientWidth, this.clientHeight = document.body.clientHeight, this.container = this.ifInsertToDOM(), this.canvas = {}, this.initCtrl(); } get color() { return this.configs.currentColor; } get state() { return this.data; } get dpr() { return this.configs.DPR || 1; } ifInsertToDOM() { if (this.container) return this.container; if (this.configs.container) this.configs.container.id = "_gl_paintBrush", this.container = this.configs.container; else if (document.getElementById("_gl_paintBrush")) this.container = document.getElementById("_gl_paintBrush"); else { const e = document.createElement("div"); e.id = "_gl_paintBrush", document.body.appendChild(e), this.container = e; } return this.container.innerHTML = ym, this.container; } /** * * @param className 初始化画板 * @returns */ initCanvas(e) { const i = document.createElement("canvas"); i.className = e, i.width = this.clientWidth, i.height = this.clientHeight; const s = i.getContext("2d"); if (s) return s.lineWidth = 5 * this.dpr, s.lineCap = "round", s.lineJoin = "round", this.container.appendChild(i), i; } /** * 初始化操作面板 * @returns */ initCtrl() { const e = document.createElement("div"); e.className = "_paintBrush-ctrl"; const i = document.createElement("div"); i.className = "_paintBrush-ctrlinner"; const s = document.createElement("a"); s.className = "_paintBrush-ctrlitem _paintBrush-ctrlitem--undo", s.addEventListener("click", (a) => { var f; if (a.stopPropagation(), this.configs.onClickUndo && this.configs.onClickUndo(), !this.canvas[this.uuid] || !this.data[this.uuid] || this.data[this.uuid].length === 0) return; const l = this.data[this.uuid].pop(); l && this.emitStateChange({ type: hi.Undo, color: this.color, ready: this.ready, state: l, uuid: this.uuid }); const c = (f = this.canvas[this.uuid]) == null ? void 0 : f.getContext("2d"); if (!this.canvas[this.uuid]) return; const { width: d, height: h } = this.canvas[this.uuid]; c && c.clearRect(0, 0, d, h), this.data[this.uuid].forEach((m) => this.handleDrawLine(this.uuid, m, { withUndo: !0 })); }); const o = document.createElement("a"); return o.className = "_paintBrush-ctrlitem _paintBrush-ctrlitem--close", o.addEventListener("click", (a) => { a.stopPropagation(), this.closeBrush(), this.configs.onClickClose && this.configs.onClickClose(); }), [s, o].forEach((a) => { const l = document.createElement("i"); l.className = "brush-icon"; const c = document.createElement("span"); c.className = "brush-txt", c.innerText = a.className.endsWith("undo") ? this.configs.onUndoText : this.configs.onExitText, a.appendChild(l), a.appendChild(c); }), i.appendChild(s), i.appendChild(o), e.appendChild(i), this.container.appendChild(e), e; } openBrush() { if (this.ready) return; this.canvas[this.uuid] || (this.canvas[this.uuid] = this.initCanvas("_paintBrush-canvas")), this.container.className = "brushing"; const e = this.canvas[this.uuid]; e.getContext("2d").clearRect(0, 0, e.width, e.height), this.openBrushHandle(), this.ready = !0, this.emit("readyChange", !0); } closeBrush() { this.ready && (this.container.className = "", this.data = {}, this.tempLine = {}, Object.keys(this.canvas).forEach((e) => { this.canvas[e].ontouchstart = () => !1, this.canvas[e].ontouchmove = () => !1, this.canvas[e].ontouchend = () => !1, this.canvas[e].ontouchcancel = () => !1; const i = this.canvas[e].getContext("2d"); i && i.clearRect(0, 0, this.canvas[e].width, this.canvas[e].height); }), this.ready = !1, this.emit("readyChange", !1), this.emitStateChange({ type: hi.Exit, color: this.color, ready: !1, uuid: this.uuid })); } updateCurrentColor(e) { const i = this.canvas[this.uuid]; if (!i) return; const s = i.getContext("2d"); s && (this.configs.currentColor = e, s.strokeStyle = e); } openBrushHandle() { const e = this.canvas[this.uuid]; if (!e) return; const i = e.getContext("2d"); if (!i) return; const s = this.color || "#6D92FF"; i.strokeStyle = s; let o = null, r = [], a, l = [], c = 0; const d = (h, f, m) => { const A = this.color || "#ff0000"; i.strokeStyle = A, i.beginPath(), i.moveTo(h.x, h.y), i.quadraticCurveTo(f.x, f.y, m.x, m.y), i.stroke(); }; e.onmousedown = (h) => { h.preventDefault(), c = Date.now(); const f = h.clientX, m = h.clientY; r = [], r.push({ x: f, y: m }), o = { x: f, y: m }, a = Qs({ x: f, y: m }, this.clientWidth, this.clientHeight), l = []; }, e.onmousemove = (h) => { if (h.preventDefault(), !o) return; const f = Number(h.clientX), m = Number(h.clientY); if (Math.abs(f - o.x) < 5 && Math.abs(m - o.y) < 5 || (r.push({ x: f, y: m }), l.push(Qs({ x: f, y: m }, this.clientWidth, this.clientHeight)), r.length < 3)) return; const { control: A, end: p } = Gs(r); !A || !p || (d(o, A, p), o = p); }, e.onmouseup = (h) => { if (h.preventDefault(), o = null, r.length < 3) return; this.data[this.uuid] || (this.data[this.uuid] = []); const f = Date.now() - c, m = { move: Object.assign({}, a), uuid: this.uuid, line: [...l], color: this.color, duration: f < 1280 ? f : f < 2e3 ? 1280 : 0 // 单次笔迹时长超过2000ms不加动画 }; this.data[this.uuid].push(m), so(() => { this.emitStateChange({ type: hi.Drawline, color: this.color, ready: this.ready, state: m, uuid: this.uuid }); }); }, e.ontouchstart = (h) => { h.preventDefault(), c = Date.now(); const f = h.touches[0].clientX, m = h.touches[0].clientY; r = [], r.push({ x: f, y: m }), o = { x: f, y: m }, a = Qs({ x: f, y: m }, this.clientWidth, this.clientHeight), l = []; }, e.ontouchmove = (h) => { if (h.preventDefault(), !o) return; const f = Number(h.touches[0].clientX), m = Number(h.touches[0].clientY); if (Math.abs(f - o.x) < 5 && Math.abs(m - o.y) < 5 || (r.push({ x: f, y: m }), l.push(Qs({ x: f, y: m }, this.clientWidth, this.clientHeight)), r.length < 3)) return; const { control: A, end: p } = Gs(r); !A || !p || (d(o, A, p), o = p); }, e.ontouchend = e.ontouchcancel = (h) => { if (h.preventDefault(), o = null, r.length < 3) return; this.data[this.uuid] || (this.data[this.uuid] = []); const f = Date.now() - c, m = { move: Object.assign({}, a), line: [...l], uuid: this.uuid, color: this.color, duration: f < 1280 ? f : f < 2e3 ? 1280 : 0 // 单次笔迹时长超过2000ms不加动画 }; this.data[this.uuid].push(m), so(() => { this.emitStateChange({ type: hi.Drawline, color: this.color, ready: this.ready, state: m, uuid: this.uuid }); }); }; } emitStateChange(e, i = !0) { if (e.type !== hi.Drawline) { this.emit("stateChange", e, i); return; } const s = Date.now(), o = e.state; if (!o || !o.line) return; const r = Math.ceil(o.line.length / 100); for (let a = 0; a < r; a++) { const l = { uuid: this.uuid, color: this.color, ready: this.ready, type: e.type, state: { uuid: this.uuid, move: o.move, duration: o.duration, color: this.color, line: o.line.slice(a * 100, (a + 1) * 100) }, timestamp: s, end: a === r - 1 }; cm(a, 20, () => { this.emit("stateChange", l, i); }); } } action(e) { const { ready: i, type: s, uuid: o } = e; if (!i && this.ready) { this.closeBrush(); return; } if (i && !this.ready) { this.openBrush(); return; } if (this.ready) switch (s) { case hi.Drawline: const { state: r, timestamp: a, end: l } = e; if (!a || !r) return; this.tempLine[a] = [].concat(this.tempLine[a] || [], r.line), l && (Object.assign(r, { line: this.tempLine[a] }), this.handleDrawLine(o, r, {}, () => delete this.tempLine[a])); break; case hi.Undo: this.handleUndo(o); break; } } handleDrawLine(e, i, { withUndo: s = !1 }, o = Vh) { !i || Object.prototype.toString.call(i) != "[object Object]" || Object.keys(i).length === 0 || lm(() => new Promise((r) => { if (s || (this.canvas[e] || (this.canvas[e] = this.initCanvas("_paintBrush-canvas--sync")), this.data[e] || (this.data[e] = []), this.data[e].push(i)), !this.canvas[e]) return; const a = this.canvas[e].getContext("2d"); if (!a) return; const { line: l = [], color: c = "black", duration: d = 0, uuid: h } = i, f = Er(i.move || {}, this.clientWidth, this.clientHeight); let m = [f]; if (a.strokeStyle = c, a.beginPath(), a.moveTo(f.x, f.y), d && !s) { let A = []; const p = this; p.tween = Am({ step: 0 }, { step: l.length - 1 }, d).onUpdate(({ step: g }) => { var y; if (p.tweening = !0, !p.ready) return a.clearRect(0, 0, p.canvas[h].width, p.canvas[h].height), (y = p.tween) == null ? void 0 : y.stop(); const b = Math.floor(g); if (!A.find((E) => E === b)) { if (A.push(b), m.push(Er(l[b], p.clientWidth, p.clientHeight)), m.length < 3) return; const { control: E, end: I } = Gs(m); if (!E || !I) return; a.quadraticCurveTo(E.x, E.y, I.x, I.y), a.stroke(); } }).onComplete((g) => { p.tween = void 0, p.tweening = !1, A = [], m = [], o && o(), r(); }); } else { for (let A = 0; A < l.length; A++) { if (m.push(Er(l[A], this.clientWidth, this.clientHeight)), m.length < 3) continue; const { control: p, end: g } = Gs(m); !p || !g || a.quadraticCurveTo(p.x, p.y, g.x, g.y); } a.stroke(), m = [], o && o(), r(); } })); } handleUndo(e) { if (!this.canvas[e] || !this.data[e] || this.data[e].length === 0) return; this.data[e].pop(); const i = () => { var o; const s = (o = this.canvas[e]) == null ? void 0 : o.getContext("2d"); s && s.clearRect(0, 0, this.canvas[e].width, this.canvas[e].height), this.data[e].forEach((r) => this.handleDrawLine(e, r, { withUndo: !0 })); }; if (this.tween && this.tweening) { this.tween.stop(), so(i, 60); return; } i(); } destroyBrush() { this.closeBrush(), this.ready = !1, this.emit("readyChange", !0); } }; class nk { constructor(t = {}) { u(this, "controller"); const e = Object.assign({ currentColor: "#f44336", onUndoText: "回退", onExitText: "关闭" }, t); this.controller = new wm(e); } on(t, e) { this.controller.on(t, e); } off(t, e) { this.controller.off(t, e); } once(t, e) { this.controller.once(t, e); } /** * 显示画笔。 */ show() { this.controller.openBrush(); } action(t) { this.controller.action(t); } /** * 获取画笔状态。 */ get state() { return this.controller.state; } get configs() { return this.controller.configs; } /** * 销毁。 * * @deprecated * * @description 画笔应该维护一个 **全局单例**,重复利用。 */ dispose() { return this.controller.destroyBrush(); } setCurrentColor(t) { this.controller.updateCurrentColor(t); } } const sk = (n, t) => { var H, F; let e = (F = (H = t == null ? void 0 : t.initialState) == null ? void 0 : H.enabled) != null ? F : !0, i = !1, s = !0, o = null; const a = R(R({}, { lookAtCurrentCamera: !1, lockedPanoIndex: null, lockedLatitude: null, lockedLongitude: null }), t == null ? void 0 : t.config), l = new P.Scene(), c = new Hf(60); let d = new P.Object3D(), h, f; { const N = new P.DirectionalLight(16777215, 0.5); N.position.copy(new P.Vector3(1, 1, 1)), l.add(N); } { const N = new P.DirectionalLight(16777215, 0.3); l.add(N); } { const N = new P.AmbientLight(16777215, 0.3); l.add(N); } l.add(d); const m = () => { if (i) return; h = x(n.model, c.fov, c.aspect), f = n.model.bounding.getCenter(new P.Vector3()), l.remove(d), d = U(n.model), l.add(d), i = !0, L(); function N(X) { const Z = X.clone(); return Z.uniforms.modelAlpha.value = 1, Z.uniforms.map.value && (Z.uniforms.map.value.needsUpdate = !0), Z; } function U(X) { if (X instanceof P.Mesh) { const Z = X.geometry, $ = Array.isArray(X.material) ? X.material.map(N) : N(X.material); return new P.Mesh(Z, $); } else if (X instanceof P.Group) { const Z = new P.Group(); return X.children.forEach(($) => Z.add(U($))), Z; } else { const Z = new P.Object3D(); return X.children.forEach(($) => Z.add(U($))), Z; } } }, A = () => { if (n.renderer) return o || (o = new P.WebGLRenderer({ antialias: !1, alpha: !0 }), o.setPixelRatio(n.renderer.getPixelRatio()), o.outputEncoding = P.sRGBEncoding, o.setClearColor(1579548, 0), o.autoClear = !0), o; }, p = () => { d.traverse((N) => { N instanceof P.Mesh && [].concat(N.material).forEach((X) => X.dispose()); }), l.remove(d), d = new P.Object3D(), l.add(d), i = !1, L(); }, g = () => { e && (i || m()); }, b = () => { e || (e = !0, l.add(d), !i && n.model.loaded && m(), L()); }, y = () => { e && (l.remove(d), s = !0, Q(), e = !1); }, E = (N, U = {}) => { const X = A(); if (!X) return; N.appendChild(X.domElement), I(U); const Z = window.getComputedStyle(N).position; Z !== "relative" && Z !== "absolute" && Z !== "fixed" && Z !== "sticky" && (N.style.position = "relative"); }, I = (N = {}) => { if (!o) return; const X = o.domElement.parentNode; if (X != null && X.nodeName) { const { width: Z = X.offsetWidth, height: $ = X.offsetHeight } = N; o.setSize(Z, $), c.aspect = Z / $, c.updateProjectionMatrix(); } L(); }; function x(N, U, X) { const Z = N.bounding, $ = Math.pow( Math.pow(Z.max.x - Z.min.x + 1, 2) + Math.pow(Z.max.y - Z.min.y + 1, 2) + Math.pow(Z.max.z - Z.min.z + 1, 2), 1 / 2 ); let he = $ / 2 / Math.tan(Math.PI * U / 360); return X < 1 && (he = he / X), isNaN(he) ? $ : he; } function C(N) { return n.work.observers[N].standingPosition.clone(); } const L = () => { if (!e || !h || !f) return; const N = n.getPose(); N.fov = c.fov, N.offset = f, N.distance = h, typeof a.lockedLatitude == "number" && (N.latitude = a.lockedLatitude), typeof a.lockedLongitude == "number" && (N.longitude = a.lockedLongitude), typeof a.lockedPanoIndex == "number" && (N.offset = C(a.lockedPanoIndex)), a.lookAtCurrentCamera && (N.offset = n.camera.position.clone().setY(n.camera.position.y + 1)), c.setFromPose(N), s = !0; }, Q = () => { !e || s !== !0 || !o || !o.domElement.parentNode || o.domElement.parentNode.offsetWidth === 0 || (o.render(l, c), s = !1); }, G = () => { o && o.dispose(), o = null; }, W = (N) => { Object.assign(a, N), L(); }, V = () => ({ enabled: e }); return Object.assign(window, { camera: c }), n.on("modelLoaded", g), n.on("modelWillLoad", p), n.on("cameraDirectionUpdate", L), n.on("dispose", G), n.on("renderFrame", Q), n.on("cameraPositionUpdate", L), { appendTo: E, refresh: I, changeConfigs: W, enable: b, disable: y, getCurrentState: V }; }, Cm = ({ x: n, y: t, z: e }) => new ne(n, t, e), ii = (n) => new ne().fromArray(n), kt = (n) => n instanceof ne ? n : Array.isArray(n) ? ii(n) : Cm(n); function Im(n) { if (n) return Array.isArray(n) ? typeof n[0] == "number" ? kt(n) : n.map(kt) : kt(n); } function Nh(n) { return arguments.length === 0 ? [] : Array.isArray(n) ? n : [n]; } function Ri(n) { const t = []; return Nh(n).forEach((i) => { i.traverse((s) => { s.isCSS3DObjectPlus && t.push(s); }); }), t; } function ho(n, t) { const e = Math.round(n); return e % 2 === 0 ? e : e + (t != null && t.floor ? -1 : 1); } function Pm(n, t, e = !0) { if (!n) return console.error("createResizeObserver: element is undefined"), { observe: () => { }, unobserve: () => { } }; const i = () => { const o = ho(n.clientWidth, { floor: !0 }), r = ho(n.clientHeight, { floor: !0 }); t(o, r); }; if (typeof ResizeObserver == "undefined" || !ResizeObserver) return console.warn("createResizeObserver: ResizeObserver is undefined"), { observe: () => i(), unobserve: () => { } }; const s = new ResizeObserver(i); return e && i(), { observe: () => s.observe(n), unobserve: () => s.unobserve(n) }; } class vl extends nm { constructor() { super(); u(this, "wrapper"); u(this, "requestAnimationFrameId"); u(this, "resizeDisoper"); this.domElement.style.position = "absolute", this.domElement.style.top = "0", this.domElement.style.left = "0", this.domElement.style.userSelect = "none", this.domElement.style.pointerEvents = "none"; } setWrapper(e) { if (!e) throw new Error("CSS3DRenderer: wrapper is required"); if (e.contains(this.domElement)) return; const i = this.wrapper; return i && i.contains(this.domElement) && this.domElement.remove(), this.appendToElement(e), this.wrapper = e, this; } appendToElement(e) { e.appendChild(this.domElement); const i = (r, a) => this.setSize(r, a), { observe: s, unobserve: o } = Pm(e, i, !0); s(), this.resizeDisoper = o, this.wrapper = e; } renderEveryFrame(e, i) { if (this.wrapper || console.warn("wrapper is not find, creating a html element and call setWrapper(wrapper)", this, e), this.requestAnimationFrameId) return; const s = () => { this.requestAnimationFrameId = requestAnimationFrame(s), e.visible && Ri(e).length !== 0 && this.render(e, i); }; s(); } stopRender() { this.requestAnimationFrameId && cancelAnimationFrame(this.requestAnimationFrameId); } dispose() { var e; this.stopRender(), (e = this.resizeDisoper) == null || e.call(this), this.domElement.remove(); } } function Em(n) { return typeof Symbol == "undefined" ? `$Symbol<${n}>$` : Symbol(n); } const us = Em("$$EVENT$$"); function Hs(n) { return n[us] || (n[us] = {}), n[us]; } function km(n) { n[us] || delete n[us]; } class Tn { /** * 判断是否注册了事件 * @param name - 事件类型 */ hasListener(t) { const e = Hs(this); return !!(e != null && e[t] && e[t].length > 0); } /** * 注册事件 * @param name - 事件类型 * @param callback - 事件回调函数 * @param once - 是否只执行一次 * @returns 解除事件 * @template K - 预设的监听事件名称 * @template C - 回调函数函数上下文 */ on(t, e, i) { const s = Hs(this); return s[t] || (s[t] = []), s[t].push([e, i || !1]), () => this.off(t, e); } /** * 注册事件(是否只执行一次) * @param name - 事件类型 * @param callback - 事件回调函数 * @returns 解除事件 * @template K - 预设的监听事件名称 * @template C - 回调函数函数上下文 */ once(t, e) { return this.on(t, e, !0); } /** * 解除事件 * * 如果 name 不传的话解除对应所有事件 * 如果 name, callback 不传的话解除所有name的所有事件 * @param name - 事件类型 * @param callback - 事件回调函数 * @template K - 预设的监听事件名称 */ off(t, e) { if (t === void 0) { km(this); return; } const i = Hs(this); if (i[t] || (i[t] = []), e === void 0) { i[t].length = 0; return; } let s = 0