UNPKG

pencil.js

Version:

Nice modular interactive 2D drawing library.

1 lines 76 kB
(()=>{var t={505:t=>{"use strict";function e(t,e,n){t instanceof RegExp&&(t=s(t,n)),e instanceof RegExp&&(e=s(e,n));var r=i(t,e,n);return r&&{start:r[0],end:r[1],pre:n.slice(0,r[0]),body:n.slice(r[0]+t.length,r[1]),post:n.slice(r[1]+e.length)}}function s(t,e){var s=e.match(t);return s?s[0]:null}function i(t,e,s){var i,n,r,o,a,h=s.indexOf(t),l=s.indexOf(e,h+1),c=h;if(h>=0&&l>0){if(t===e)return[h,l];for(i=[],r=s.length;c>=0&&!a;)c==h?(i.push(c),h=s.indexOf(t,c+1)):1==i.length?a=[i.pop(),l]:((n=i.pop())<r&&(r=n,o=l),l=s.indexOf(e,c+1)),c=h<l&&h>=0?h:l;i.length&&(a=[r,o])}return a}t.exports=e,e.range=i},928:(t,e,s)=>{var i=s(505);t.exports=function(t){return t?("{}"===t.substr(0,2)&&(t="\\{\\}"+t.substr(2)),m(function(t){return t.split("\\\\").join(n).split("\\{").join(r).split("\\}").join(o).split("\\,").join(a).split("\\.").join(h)}(t),!0).map(c)):[]};var n="\0SLASH"+Math.random()+"\0",r="\0OPEN"+Math.random()+"\0",o="\0CLOSE"+Math.random()+"\0",a="\0COMMA"+Math.random()+"\0",h="\0PERIOD"+Math.random()+"\0";function l(t){return parseInt(t,10)==t?parseInt(t,10):t.charCodeAt(0)}function c(t){return t.split(n).join("\\").split(r).join("{").split(o).join("}").split(a).join(",").split(h).join(".")}function u(t){if(!t)return[""];var e=[],s=i("{","}",t);if(!s)return t.split(",");var n=s.pre,r=s.body,o=s.post,a=n.split(",");a[a.length-1]+="{"+r+"}";var h=u(o);return o.length&&(a[a.length-1]+=h.shift(),a.push.apply(a,h)),e.push.apply(e,a),e}function d(t){return"{"+t+"}"}function p(t){return/^-?0\d/.test(t)}function f(t,e){return t<=e}function g(t,e){return t>=e}function m(t,e){var s=[],n=i("{","}",t);if(!n)return[t];var r=n.pre,a=n.post.length?m(n.post,!1):[""];if(/\$$/.test(n.pre))for(var h=0;h<a.length;h++){var c=r+"{"+n.body+"}"+a[h];s.push(c)}else{var w,b,v=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(n.body),y=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(n.body),x=v||y,O=n.body.indexOf(",")>=0;if(!x&&!O)return n.post.match(/,.*\}/)?m(t=n.pre+"{"+n.body+o+n.post):[t];if(x)w=n.body.split(/\.\./);else if(1===(w=u(n.body)).length&&1===(w=m(w[0],!1).map(d)).length)return a.map((function(t){return n.pre+w[0]+t}));if(x){var S=l(w[0]),k=l(w[1]),R=Math.max(w[0].length,w[1].length),z=3==w.length?Math.abs(l(w[2])):1,E=f;k<S&&(z*=-1,E=g);var M=w.some(p);b=[];for(var C=S;E(C,k);C+=z){var A;if(y)"\\"===(A=String.fromCharCode(C))&&(A="");else if(A=String(C),M){var N=R-A.length;if(N>0){var T=new Array(N+1).join("0");A=C<0?"-"+T+A.slice(1):T+A}}b.push(A)}}else{b=[];for(var P=0;P<w.length;P++)b.push.apply(b,m(w[P],!1))}for(P=0;P<b.length;P++)for(h=0;h<a.length;h++)c=r+b[P]+a[h],(!e||x||c)&&s.push(c)}return s}},112:t=>{const e="object"==typeof process&&process&&"win32"===process.platform;t.exports=e?{sep:"\\"}:{sep:"/"}},27:(t,e,s)=>{const i=t.exports=(t,e,s={})=>(m(e),!(!s.nocomment&&"#"===e.charAt(0))&&new b(e,s).match(t));t.exports=i;const n=s(112);i.sep=n.sep;const r=Symbol("globstar **");i.GLOBSTAR=r;const o=s(928),a={"!":{open:"(?:(?!(?:",close:"))[^/]*?)"},"?":{open:"(?:",close:")?"},"+":{open:"(?:",close:")+"},"*":{open:"(?:",close:")*"},"@":{open:"(?:",close:")"}},h="[^/]",l=h+"*?",c=t=>t.split("").reduce(((t,e)=>(t[e]=!0,t)),{}),u=c("().*{}+?[]^$\\!"),d=c("[.("),p=/\/+/;i.filter=(t,e={})=>(s,n,r)=>i(s,t,e);const f=(t,e={})=>{const s={};return Object.keys(t).forEach((e=>s[e]=t[e])),Object.keys(e).forEach((t=>s[t]=e[t])),s};i.defaults=t=>{if(!t||"object"!=typeof t||!Object.keys(t).length)return i;const e=i,s=(s,i,n)=>e(s,i,f(t,n));return(s.Minimatch=class extends e.Minimatch{constructor(e,s){super(e,f(t,s))}}).defaults=s=>e.defaults(f(t,s)).Minimatch,s.filter=(s,i)=>e.filter(s,f(t,i)),s.defaults=s=>e.defaults(f(t,s)),s.makeRe=(s,i)=>e.makeRe(s,f(t,i)),s.braceExpand=(s,i)=>e.braceExpand(s,f(t,i)),s.match=(s,i,n)=>e.match(s,i,f(t,n)),s},i.braceExpand=(t,e)=>g(t,e);const g=(t,e={})=>(m(t),e.nobrace||!/\{(?:(?!\{).)*\}/.test(t)?[t]:o(t)),m=t=>{if("string"!=typeof t)throw new TypeError("invalid pattern");if(t.length>65536)throw new TypeError("pattern is too long")},w=Symbol("subparse");i.makeRe=(t,e)=>new b(t,e||{}).makeRe(),i.match=(t,e,s={})=>{const i=new b(e,s);return t=t.filter((t=>i.match(t))),i.options.nonull&&!t.length&&t.push(e),t};class b{constructor(t,e){m(t),e||(e={}),this.options=e,this.set=[],this.pattern=t,this.windowsPathsNoEscape=!!e.windowsPathsNoEscape||!1===e.allowWindowsEscape,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.regexp=null,this.negate=!1,this.comment=!1,this.empty=!1,this.partial=!!e.partial,this.make()}debug(){}make(){const t=this.pattern,e=this.options;if(!e.nocomment&&"#"===t.charAt(0))return void(this.comment=!0);if(!t)return void(this.empty=!0);this.parseNegate();let s=this.globSet=this.braceExpand();e.debug&&(this.debug=(...t)=>console.error(...t)),this.debug(this.pattern,s),s=this.globParts=s.map((t=>t.split(p))),this.debug(this.pattern,s),s=s.map(((t,e,s)=>t.map(this.parse,this))),this.debug(this.pattern,s),s=s.filter((t=>-1===t.indexOf(!1))),this.debug(this.pattern,s),this.set=s}parseNegate(){if(this.options.nonegate)return;const t=this.pattern;let e=!1,s=0;for(let i=0;i<t.length&&"!"===t.charAt(i);i++)e=!e,s++;s&&(this.pattern=t.slice(s)),this.negate=e}matchOne(t,e,s){var i=this.options;this.debug("matchOne",{this:this,file:t,pattern:e}),this.debug("matchOne",t.length,e.length);for(var n=0,o=0,a=t.length,h=e.length;n<a&&o<h;n++,o++){this.debug("matchOne loop");var l,c=e[o],u=t[n];if(this.debug(e,c,u),!1===c)return!1;if(c===r){this.debug("GLOBSTAR",[e,c,u]);var d=n,p=o+1;if(p===h){for(this.debug("** at the end");n<a;n++)if("."===t[n]||".."===t[n]||!i.dot&&"."===t[n].charAt(0))return!1;return!0}for(;d<a;){var f=t[d];if(this.debug("\nglobstar while",t,d,e,p,f),this.matchOne(t.slice(d),e.slice(p),s))return this.debug("globstar found match!",d,a,f),!0;if("."===f||".."===f||!i.dot&&"."===f.charAt(0)){this.debug("dot detected!",t,d,e,p);break}this.debug("globstar swallow a segment, and continue"),d++}return!(!s||(this.debug("\n>>> no match, partial?",t,d,e,p),d!==a))}if("string"==typeof c?(l=u===c,this.debug("string match",c,u,l)):(l=u.match(c),this.debug("pattern match",c,u,l)),!l)return!1}if(n===a&&o===h)return!0;if(n===a)return s;if(o===h)return n===a-1&&""===t[n];throw new Error("wtf?")}braceExpand(){return g(this.pattern,this.options)}parse(t,e){m(t);const s=this.options;if("**"===t){if(!s.noglobstar)return r;t="*"}if(""===t)return"";let i="",n=!1,o=!1;const c=[],p=[];let f,g,b,v,y=!1,x=-1,O=-1,S="."===t.charAt(0),k=s.dot||S;const R=t=>"."===t.charAt(0)?"":s.dot?"(?!(?:^|\\/)\\.{1,2}(?:$|\\/))":"(?!\\.)",z=()=>{if(f){switch(f){case"*":i+=l,n=!0;break;case"?":i+=h,n=!0;break;default:i+="\\"+f}this.debug("clearStateChar %j %j",f,i),f=!1}};for(let e,r=0;r<t.length&&(e=t.charAt(r));r++)if(this.debug("%s\t%s %s %j",t,r,i,e),o){if("/"===e)return!1;u[e]&&(i+="\\"),i+=e,o=!1}else switch(e){case"/":return!1;case"\\":if(y&&"-"===t.charAt(r+1)){i+=e;continue}z(),o=!0;continue;case"?":case"*":case"+":case"@":case"!":if(this.debug("%s\t%s %s %j <-- stateChar",t,r,i,e),y){this.debug(" in class"),"!"===e&&r===O+1&&(e="^"),i+=e;continue}this.debug("call clearStateChar %j",f),z(),f=e,s.noext&&z();continue;case"(":{if(y){i+="(";continue}if(!f){i+="\\(";continue}const e={type:f,start:r-1,reStart:i.length,open:a[f].open,close:a[f].close};this.debug(this.pattern,"\t",e),c.push(e),i+=e.open,0===e.start&&"!"!==e.type&&(S=!0,i+=R(t.slice(r+1))),this.debug("plType %j %j",f,i),f=!1;continue}case")":{const t=c[c.length-1];if(y||!t){i+="\\)";continue}c.pop(),z(),n=!0,b=t,i+=b.close,"!"===b.type&&p.push(Object.assign(b,{reEnd:i.length}));continue}case"|":{const e=c[c.length-1];if(y||!e){i+="\\|";continue}z(),i+="|",0===e.start&&"!"!==e.type&&(S=!0,i+=R(t.slice(r+1)));continue}case"[":if(z(),y){i+="\\"+e;continue}y=!0,O=r,x=i.length,i+=e;continue;case"]":if(r===O+1||!y){i+="\\"+e;continue}g=t.substring(O+1,r);try{RegExp("["+(g.replace(/\\([^-\]])/g,"$1").replace(/[[\]\\]/g,"\\$&")+"]")),i+=e}catch(t){i=i.substring(0,x)+"(?:$.)"}n=!0,y=!1;continue;default:z(),!u[e]||"^"===e&&y||(i+="\\"),i+=e}for(y&&(g=t.slice(O+1),v=this.parse(g,w),i=i.substring(0,x)+"\\["+v[0],n=n||v[1]),b=c.pop();b;b=c.pop()){let t;t=i.slice(b.reStart+b.open.length),this.debug("setting tail",i,b),t=t.replace(/((?:\\{2}){0,64})(\\?)\|/g,((t,e,s)=>(s||(s="\\"),e+e+s+"|"))),this.debug("tail=%j\n %s",t,t,b,i);const e="*"===b.type?l:"?"===b.type?h:"\\"+b.type;n=!0,i=i.slice(0,b.reStart)+e+"\\("+t}z(),o&&(i+="\\\\");const E=d[i.charAt(0)];for(let t=p.length-1;t>-1;t--){const s=p[t],n=i.slice(0,s.reStart),r=i.slice(s.reStart,s.reEnd-8);let o=i.slice(s.reEnd);const a=i.slice(s.reEnd-8,s.reEnd)+o,h=n.split(")").length,l=n.split("(").length-h;let c=o;for(let t=0;t<l;t++)c=c.replace(/\)[+*?]?/,"");o=c,i=n+r+o+(""===o&&e!==w?"(?:$|\\/)":"")+a}if(""!==i&&n&&(i="(?=.)"+i),E&&(i=(S?"":k?"(?!(?:^|\\/)\\.{1,2}(?:$|\\/))":"(?!\\.)")+i),e===w)return[i,n];if(s.nocase&&!n&&(n=t.toUpperCase()!==t.toLowerCase()),!n)return(t=>t.replace(/\\(.)/g,"$1"))(t);const M=s.nocase?"i":"";try{return Object.assign(new RegExp("^"+i+"$",M),{_glob:t,_src:i})}catch(t){return new RegExp("$.")}}makeRe(){if(this.regexp||!1===this.regexp)return this.regexp;const t=this.set;if(!t.length)return this.regexp=!1,this.regexp;const e=this.options,s=e.noglobstar?l:e.dot?"(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?":"(?:(?!(?:\\/|^)\\.).)*?",i=e.nocase?"i":"";let n=t.map((t=>(t=t.map((t=>"string"==typeof t?t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"):t===r?r:t._src)).reduce(((t,e)=>(t[t.length-1]===r&&e===r||t.push(e),t)),[]),t.forEach(((e,i)=>{e===r&&t[i-1]!==r&&(0===i?t.length>1?t[i+1]="(?:\\/|"+s+"\\/)?"+t[i+1]:t[i]=s:i===t.length-1?t[i-1]+="(?:\\/|"+s+")?":(t[i-1]+="(?:\\/|\\/"+s+"\\/)"+t[i+1],t[i+1]=r))})),t.filter((t=>t!==r)).join("/")))).join("|");n="^(?:"+n+")$",this.negate&&(n="^(?!"+n+").*$");try{this.regexp=new RegExp(n,i)}catch(t){this.regexp=!1}return this.regexp}match(t,e=this.partial){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return""===t;if("/"===t&&e)return!0;const s=this.options;"/"!==n.sep&&(t=t.split(n.sep).join("/")),t=t.split(p),this.debug(this.pattern,"split",t);const i=this.set;let r;this.debug(this.pattern,"set",i);for(let e=t.length-1;e>=0&&(r=t[e],!r);e--);for(let n=0;n<i.length;n++){const o=i[n];let a=t;if(s.matchBase&&1===o.length&&(a=[r]),this.matchOne(a,o,e))return!!s.flipNegate||!this.negate}return!s.flipNegate&&this.negate}static defaults(t){return i.defaults(t).Minimatch}}i.Minimatch=b}},e={};function s(i){var n=e[i];if(void 0!==n)return n.exports;var r=e[i]={exports:{}};return t[i](r,r.exports,s),r.exports}s.d=(t,e)=>{for(var i in e)s.o(e,i)&&!s.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};(()=>{"use strict";s.d(i,{default:()=>ve});var t={};s.r(t),s.d(t,{average:()=>f,constrain:()=>n,degreeCircle:()=>l,distribute:()=>d,equals:()=>r,lerp:()=>m,map:()=>g,modulo:()=>u,phi:()=>c,radianCircle:()=>h,random:()=>o,sum:()=>p,truncate:()=>a});var e={};s.r(e),s.d(e,{back:()=>Rt,displayScene:()=>kt,getCurrentScene:()=>St,prepareScenes:()=>zt});const n=(t,e,s)=>Math.min(Math.max(t,e),s),r=(t,e,s=Number.EPSILON)=>Math.abs(t-e)<s,o=(t=1,e)=>{let s=t,i=e;return void 0===e&&(s=0,i=t),Math.random()*(i-s)+s},a=t=>0|t,h=2*Math.PI,l=360,c=(Math.sqrt(5)+1)/2,u=(t,e)=>{const s=t%e;return t&&Math.sign(t)!==Math.sign(e)?s+e:s},d=(t,e=0,s=1)=>{const i=o(e,s),n=s-e;return[...new Array(t)].map(((t,s)=>e+u(i+s*c*n,n)))},p=(...t)=>t.reduce(((t,e)=>t+e),0),f=(...t)=>p(...t)/t.length,g=(t,e,s,i=0,n=1)=>(t-e)/(s-e)*(n-i)+i,m=(t,e,s)=>t+(e-t)*s;class w{constructor(t=0,e=0){this.x=+t,this.y=+e}set(t,e){let s,i;if("number"==typeof t)s=t,i=void 0===e?t:e;else{const e=w.from(t);({x:s,y:i}=e)}return this.x=s,this.y=i,this}clone(){return new w(this.x,this.y)}equals(t){const e=w.from(t);return r(this.x,e.x)&&r(this.y,e.y)}calc(t,e,s){let i=0,n=0;if("number"==typeof e)i=t(this.x,e),n=t(this.y,void 0===s?e:s);else{const s=w.from(e);i=t(this.x,s.x),n=t(this.y,s.y)}return this.set(i,n)}add(t,e){return this.calc(((t,e)=>t+e),t,e)}subtract(t,e){return this.calc(((t,e)=>t-e),t,e)}multiply(t,e){return this.calc(((t,e)=>t*e),t,e)}divide(t,e){return this.calc(((t,e)=>t/e),t,e)}modulo(t,e){return this.calc(((t,e)=>u(t,e)),t,e)}power(t,e){return this.calc(((t,e)=>t**e),t,e)}rotate(t=0,e){const{cos:s,sin:i}=Math,n=t*h,r=w.from(e),o=this.clone().subtract(r),a=o.x*s(n)-o.y*i(n),l=o.y*s(n)+o.x*i(n);return this.set(a,l).add(r)}constrain(t,e){const s=w.from(t),i=w.from(e),r=n(this.x,Math.min(s.x,i.x),Math.max(s.x,i.x)),o=n(this.y,Math.min(s.y,i.y),Math.max(s.y,i.y));return this.set(r,o)}lerp(t,e){const s=w.from(t).clone().subtract(this).multiply(e);return this.add(s)}distance(t){const e=w.from(t);return Math.hypot(e.x-this.x,e.y-this.y)}dotProduct(t){const e=w.from(t);return this.x*e.x+this.y*e.y}crossProduct(t){const e=w.from(t);return this.x*e.y-this.y*e.x}isOnSameSide(t,e){const s=w.from(t),i=this.clone().subtract(e.start),n=s.clone().subtract(e.start),r=e.getDelta(),{sign:o}=Math;return o(i.crossProduct(r))===o(n.crossProduct(r))}get length(){return this.distance()}get angle(){return 0===this.x&&0===this.y?0:Math.atan(this.y/this.x)/h+(this.x<0?.75:.25)}toJSON(){const{x:t,y:e}=this;return[t,e]}static from(t=new w){if(t instanceof w)return t;if(Array.isArray(t))return new w(...t);try{return new w(t.x,t.y)}catch{throw TypeError(`Unexpected type for position: ${JSON.stringify(t)}.`)}}static average(...t){let e=new w;t.forEach((t=>e=e.add(w.from(t))));const s=t.length;return e.divide(s)}}const b=(...t)=>t.slice(1).every((e=>e===t[0]));function v(t){return"number"==typeof t||t instanceof w?t:"function"==typeof t.getDelta?t.getDelta():"number"==typeof t[0]&&"number"==typeof t[1]?w.from(t):y.from(t).getDelta()}class y{constructor(t,e){this.start=w.from(t),this.end=w.from(e)}get width(){return Math.abs(this.start.x-this.end.x)}get height(){return Math.abs(this.start.y-this.end.y)}get length(){return this.start.distance(this.end)}clone(){return new y(this.start.clone(),this.end.clone())}equals(t){const e=y.from(t);return this.start.equals(e.start)&&this.end.equals(e.end)}getDelta(){return this.end.clone().subtract(this.start)}add(t){const e=v(t);return this.end.add(e),this}translate(t){const e=v(t);return this.start.add(e),this.end.add(e),this}multiply(t){if("number"==typeof t)return this.add(this.getDelta().multiply(t-1)),this;const e=v(t);return this.end.multiply(e),this}intersect(t){const e=y.from(t);if(!this.start.isOnSameSide(this.end,e)&&!e.start.isOnSameSide(e.end,this))return!0;const s=this.getDelta(),i=e.start.clone().subtract(this.start);return!(0!==s.crossProduct(i)||0!==s.crossProduct(e.getDelta())||b(this.start.x<e.start.x,this.start.x<e.end.x,this.end.x<e.start.x,this.end.x<e.end.x)&&b(this.start.y<e.start.y,this.start.y<e.end.y,this.end.y<e.start.y,this.end.y<e.end.y))}getIntersectionPoint(t){const e=y.from(t);if(!this.intersect(e))return null;const s=e.getDelta(),i=this.getDelta().crossProduct(s);if(0===i)return this.start.clone().constrain(e.start,e.end).lerp(this.end.clone().constrain(e.start,e.end),.5);const n=this.start.clone().subtract(e.start);return this.start.clone().lerp(this.end,s.crossProduct(n)/i)}getClosestToPoint(t){const e=w.from(t),s=new y(this.start,e).getDelta(),i=this.getDelta(),n=s.dotProduct(i)/this.length**2;return this.start.clone().add(i.multiply(n)).constrain(this.start,this.end)}toJSON(){const{start:t,end:e}=this;return[t,e]}static from(t=new y){if(t instanceof y)return t;if(Array.isArray(t)&&2===t.length)return new y(...t);try{return new y(t.start,t.end)}catch{throw new TypeError(`Unexpected type for vector: ${JSON.stringify(t)}.`)}}}class x{constructor(){this.eventListeners={}}on(t,e,s=!1){const i={callback:e,element:this,isTargeted:s};return(Array.isArray(t)?t:[t]).forEach((t=>{const[e,s]=t.split(".");this.eventListeners[e]||(this.eventListeners[e]=[]),this.eventListeners[e].push({...i,modifier:s})})),this}fire(t){const e=this.eventListeners[t.name];return e&&e.forEach((e=>{if(!e.isTargeted||e.element===t.target){const s=t.getModifier&&t.getModifier();e.modifier&&e.modifier!==s||e.callback.call(this,t)}})),this}removeListener(t,e){return(Array.isArray(t)?t:[t]).forEach((t=>{const[s,i]=t.split(".");e||i?this.eventListeners[s]=this.eventListeners[s].filter((t=>e&&t.callback!==e||i&&t.modifier!==i)):delete this.eventListeners[s]})),this}removeAllListener(){return this.eventListeners={},this}static get events(){return{}}}class O{constructor(t,e,s){this.name=t,this.target=e,this.event=s,this.bubble=!0}stop(){return this.bubble=!1,this}getModifier(){return null}prevent(){return this.event.preventDefault(),this}}const S=Symbol("_scenePromise");class k extends x{constructor(t=new w,e){super(),this.position=w.from(t),this.options={},this.setOptions(e),this.children=[],this.parent=null,this.frameCount=0,this[S]=new Promise((t=>{this.on(k.events.attach,(()=>{const e=this.getRoot();e.isScene?t(e):e.getScene().then((e=>t(e)))}),!0)}))}setOptions(t={}){return this.options={...this.constructor.defaultOptions,...this.options,...t},this.options.rotationCenter=w.from(this.options.rotationCenter),"number"!=typeof this.options.scale&&(this.options.scale=w.from(this.options.scale)),this}isHover(){return!1}add(...t){return t.forEach((t=>{if(t===this)throw new RangeError("A container can't contain itself.");if(t.isScene)throw new RangeError("A scene can't be contained in another container.");t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t),t.fire(new O(k.events.attach,t))})),this}remove(...t){return t.forEach((t=>{if(this.children.includes(t)){const e=this.children.splice(this.children.indexOf(t),1)[0];e.parent=null,e.fire(new O(k.events.detach,e))}})),this}empty(){return this.remove(...this.children)}delete(){return this.parent&&this.parent.remove(this),this}getScene(){return this[S]}getRoot(){return this.parent?this.parent.getRoot():this}getAbsolutePosition(){const t=new w;return this.climbAncestry((e=>{t.rotate(e.options.rotation,e.options.rotationCenter).add(e.position)})),t}fire(t){return super.fire(t),this.parent&&t.bubble&&this.parent.fire(t),this}getTarget(t,e){if(!this.options.shown)return null;e.save(),e.translate(this.position.x,this.position.y),this.setContext(e);let s=null,i=this.children.length-1;for(;!s&&i>=0;)s=this.children[i].getTarget(t,e),--i;let n=s;return(!s||s.options.zIndex<0&&s.parent===this)&&this.isHover(t,e)&&(n=this),e.restore(),n}setContext(t){if(this.options.clip){const e=new window.Path2D,{clip:s}=this.options,{x:i,y:n}=s.position;t.translate(i,n),s.trace&&s.trace(e),t.clip(e),t.translate(-i,-n)}if(this.options.rotation){const e=w.from(this.options.rotationCenter);t.translate(e.x,e.y),t.rotate(this.options.rotation*h),t.translate(-e.x,-e.y)}if("number"==typeof this.options.scale)1!==this.options.scale&&t.scale(this.options.scale,this.options.scale);else{const e=w.from(this.options.scale);1===e.x&&1===e.y||t.scale(e.x,e.y)}return this}render(t){if(!this.options.shown)return this;this.frameCount++,this.fire(new O(k.events.draw,this)),t.save(),t.translate(this.position.x,this.position.y),this.setContext(t),this.children.sort(((t,e)=>t.options.zIndex-e.options.zIndex)),k.setOpacity(t,this.options.opacity);const e=this.children.findIndex((t=>t.options.zIndex>=0)),s=-1===e?this.children.length:e;for(let e=0,i=s;e<i;++e)this.children[e].render(t);this.makePath(t);for(let e=s,i=this.children.length;e<i;++e)this.children[e].render(t);return t.restore(),this}makePath(){return this}show(){return this.options.shown=!0,this.fire(new O(k.events.show,this)),this}hide(){return this.options.shown=!1,this.fire(new O(k.events.hide,this)),this}isAncestorOf(t){return!(!t||!t.parent)&&(t.parent===this||this.isAncestorOf(t.parent))}climbAncestry(t,e){t(this),this.parent&&this.parent!==e&&this.parent.climbAncestry(t)}toJSON(){const{defaultOptions:t}=this.constructor,e={};Object.keys(this.options).forEach((s=>{const i=this.options[s];(i&&i.equals?i.equals(t[s]):Object.is(i,t[s]))||(e[s]=i)}));const s={constructor:this.constructor.name,position:this.position};return this.children.length&&(s.children=this.children.map((t=>t.toJSON()))),Object.keys(e).length&&(s.options=e),s}clone(){return this.constructor.from(this.toJSON())}static setOpacity(t,e){null!==e&&t.globalAlpha!==e&&(t.globalAlpha=e)}static from(t){return new k(t.position,t.options)}static get defaultOptions(){return{shown:!0,opacity:null,rotation:0,rotationCenter:new w,scale:1,zIndex:1,clip:null}}static get events(){return{...super.events,attach:"attach",detach:"detach",draw:"draw",hide:"hide",show:"show"}}}class R extends k{constructor(t=1,e=1,s){super(void 0,s),this.ctx=this.constructor.getDrawingContext(t,e)}setImageSmoothing(t){return this.ctx.imageSmoothingEnabled=t,this}clear(){if(this.ctx.clearRect(0,0,this.width,this.height),this.options.fill){R.setOpacity(this.ctx,this.options.opacity);const{width:t,height:e}=this;this.ctx.fillStyle=this.options.fill.toString(this.ctx),this.ctx.fillRect(0,0,t,e)}return this}render(){return this.clear(),super.render(this.ctx),this}get width(){return this.ctx.canvas.width}set width(t){this.ctx.canvas.width=+t}get height(){return this.ctx.canvas.height}set height(t){this.ctx.canvas.height=+t}get size(){return new w(this.width,this.height)}get center(){return this.size.divide(2)}getRandomPosition(){return new w(o(this.width),o(this.height))}getImageData(t){let e;return e=t?y.from(t):new y(void 0,this.size),this.render(),this.ctx.getImageData(e.start.x,e.start.y,e.end.x,e.end.y)}setImageData(t,e){const s=w.from(e);this.ctx.putImageData(t,s.x,s.y)}toImage(t,e="image/png"){let s;s=t?y.from(t):new y(void 0,[this.width,this.height]);const i=window.document.createElement("img"),{width:n,height:r}=this,o=s.getDelta();return this.width=o.x,this.height=o.y,i.width=this.width,i.height=this.height,this.ctx.translate(-s.start.x,-s.start.y),this.render(),i.src=this.ctx.canvas.toDataURL(e),this.width=n,this.height=r,i}static getDrawingContext(t=1,e=1){const s=window.document.createElement("canvas");return s.width=t,s.height=e,s.getContext("2d")}static get defaultOptions(){return{...super.defaultOptions,fill:null,opacity:1}}}var z={grad:.9,turn:360,rad:360/(2*Math.PI)},E=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},M=function(t,e,s){return void 0===e&&(e=0),void 0===s&&(s=Math.pow(10,e)),Math.round(s*t)/s+0},C=function(t,e,s){return void 0===e&&(e=0),void 0===s&&(s=1),t>s?s:t>e?t:e},A=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},N=function(t){return{r:C(t.r,0,255),g:C(t.g,0,255),b:C(t.b,0,255),a:C(t.a)}},T=function(t){return{r:M(t.r),g:M(t.g),b:M(t.b),a:M(t.a,3)}},P=/^#([0-9a-f]{3,8})$/i,L=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},H=function(t){var e=t.r,s=t.g,i=t.b,n=t.a,r=Math.max(e,s,i),o=r-Math.min(e,s,i),a=o?r===e?(s-i)/o:r===s?2+(i-e)/o:4+(e-s)/o:0;return{h:60*(a<0?a+6:a),s:r?o/r*100:0,v:r/255*100,a:n}},I=function(t){var e=t.h,s=t.s,i=t.v,n=t.a;e=e/360*6,s/=100,i/=100;var r=Math.floor(e),o=i*(1-s),a=i*(1-(e-r)*s),h=i*(1-(1-e+r)*s),l=r%6;return{r:255*[i,a,o,o,h,i][l],g:255*[h,i,i,a,o,o][l],b:255*[o,o,h,i,i,a][l],a:n}},j=function(t){return{h:A(t.h),s:C(t.s,0,100),l:C(t.l,0,100),a:C(t.a)}},D=function(t){return{h:M(t.h),s:M(t.s),l:M(t.l),a:M(t.a,3)}},J=function(t){return I((s=(e=t).s,{h:e.h,s:(s*=((i=e.l)<50?i:100-i)/100)>0?2*s/(i+s)*100:0,v:i+s,a:e.a}));var e,s,i},$=function(t){return{h:(e=H(t)).h,s:(n=(200-(s=e.s))*(i=e.v)/100)>0&&n<200?s*i/100/(n<=100?n:200-n)*100:0,l:n/2,a:e.a};var e,s,i,n},G=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,q=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,F=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,B=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,_={string:[[function(t){var e=P.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:4===t.length?M(parseInt(t[3]+t[3],16)/255,2):1}:6===t.length||8===t.length?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:8===t.length?M(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=F.exec(t)||B.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:N({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:void 0===e[7]?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=G.exec(t)||q.exec(t);if(!e)return null;var s,i,n=j({h:(s=e[1],i=e[2],void 0===i&&(i="deg"),Number(s)*(z[i]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return J(n)},"hsl"]],object:[[function(t){var e=t.r,s=t.g,i=t.b,n=t.a,r=void 0===n?1:n;return E(e)&&E(s)&&E(i)?N({r:Number(e),g:Number(s),b:Number(i),a:Number(r)}):null},"rgb"],[function(t){var e=t.h,s=t.s,i=t.l,n=t.a,r=void 0===n?1:n;if(!E(e)||!E(s)||!E(i))return null;var o=j({h:Number(e),s:Number(s),l:Number(i),a:Number(r)});return J(o)},"hsl"],[function(t){var e=t.h,s=t.s,i=t.v,n=t.a,r=void 0===n?1:n;if(!E(e)||!E(s)||!E(i))return null;var o=function(t){return{h:A(t.h),s:C(t.s,0,100),v:C(t.v,0,100),a:C(t.a)}}({h:Number(e),s:Number(s),v:Number(i),a:Number(r)});return I(o)},"hsv"]]},U=function(t,e){for(var s=0;s<e.length;s++){var i=e[s][0](t);if(i)return[i,e[s][1]]}return[null,void 0]},W=function(t,e){var s=$(t);return{h:s.h,s:C(s.s+100*e,0,100),l:s.l,a:s.a}},Y=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},X=function(t,e){var s=$(t);return{h:s.h,s:s.s,l:C(s.l+100*e,0,100),a:s.a}},Z=function(){function t(t){this.parsed=function(t){return"string"==typeof t?U(t.trim(),_.string):"object"==typeof t&&null!==t?U(t,_.object):[null,void 0]}(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return null!==this.parsed},t.prototype.brightness=function(){return M(Y(this.rgba),2)},t.prototype.isDark=function(){return Y(this.rgba)<.5},t.prototype.isLight=function(){return Y(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=T(this.rgba)).r,s=t.g,i=t.b,r=(n=t.a)<1?L(M(255*n)):"","#"+L(e)+L(s)+L(i)+r;var t,e,s,i,n,r},t.prototype.toRgb=function(){return T(this.rgba)},t.prototype.toRgbString=function(){return e=(t=T(this.rgba)).r,s=t.g,i=t.b,(n=t.a)<1?"rgba("+e+", "+s+", "+i+", "+n+")":"rgb("+e+", "+s+", "+i+")";var t,e,s,i,n},t.prototype.toHsl=function(){return D($(this.rgba))},t.prototype.toHslString=function(){return e=(t=D($(this.rgba))).h,s=t.s,i=t.l,(n=t.a)<1?"hsla("+e+", "+s+"%, "+i+"%, "+n+")":"hsl("+e+", "+s+"%, "+i+"%)";var t,e,s,i,n},t.prototype.toHsv=function(){return t=H(this.rgba),{h:M(t.h),s:M(t.s),v:M(t.v),a:M(t.a,3)};var t},t.prototype.invert=function(){return V({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},t.prototype.saturate=function(t){return void 0===t&&(t=.1),V(W(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),V(W(this.rgba,-t))},t.prototype.grayscale=function(){return V(W(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),V(X(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),V(X(this.rgba,-t))},t.prototype.rotate=function(t){return void 0===t&&(t=15),this.hue(this.hue()+t)},t.prototype.alpha=function(t){return"number"==typeof t?V({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):M(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=$(this.rgba);return"number"==typeof t?V({h:t,s:e.s,l:e.l,a:e.a}):M(e.h)},t.prototype.isEqual=function(t){return this.toHex()===V(t).toHex()},t}(),V=function(t){return t instanceof Z?t:new Z(t)},K=[],Q=function(t,e,s){return void 0===e&&(e=0),void 0===s&&(s=1),t>s?s:t>e?t:e},tt=function(t){var e=t/255;return e<.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)},et=function(t){return 255*(t>.0031308?1.055*Math.pow(t,1/2.4)-.055:12.92*t)},st=96.422,it=82.521,nt=216/24389,rt=24389/27,ot=function(t){var e=function(t){var e=tt(t.r),s=tt(t.g),i=tt(t.b);return function(t){return{x:Q(t.x,0,st),y:Q(t.y,0,100),z:Q(t.z,0,it),a:Q(t.a)}}(function(t){return{x:1.0478112*t.x+.0228866*t.y+-.050127*t.z,y:.0295424*t.x+.9904844*t.y+-.0170491*t.z,z:-.0092345*t.x+.0150436*t.y+.7521316*t.z,a:t.a}}({x:100*(.4124564*e+.3575761*s+.1804375*i),y:100*(.2126729*e+.7151522*s+.072175*i),z:100*(.0193339*e+.119192*s+.9503041*i),a:t.a}))}(t),s=e.x/st,i=e.y/100,n=e.z/it;return s=s>nt?Math.cbrt(s):(rt*s+16)/116,{l:116*(i=i>nt?Math.cbrt(i):(rt*i+16)/116)-16,a:500*(s-i),b:200*(i-(n=n>nt?Math.cbrt(n):(rt*n+16)/116)),alpha:e.a}};!function(t){t.forEach((function(t){K.indexOf(t)<0&&(t(Z,_),K.push(t))}))}([function(t,e){var s={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},i={};for(var n in s)i[s[n]]=n;var r={};t.prototype.toName=function(e){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var n,o,a=i[this.toHex()];if(a)return a;if(null==e?void 0:e.closest){var h=this.toRgb(),l=1/0,c="black";if(!r.length)for(var u in s)r[u]=new t(s[u]).toRgb();for(var d in s){var p=(n=h,o=r[d],Math.pow(n.r-o.r,2)+Math.pow(n.g-o.g,2)+Math.pow(n.b-o.b,2));p<l&&(l=p,c=d)}return c}},e.string.push([function(e){var i=e.toLowerCase(),n="transparent"===i?"#0000":s[i];return n?new t(n).toRgb():null},"name"])},function(t){function e(t,e,s){void 0===s&&(s=5);for(var i=[],n=1/(s-1),r=0;r<=s-1;r++)i.push(t.mix(e,n*r));return i}t.prototype.mix=function(e,s){void 0===s&&(s=.5);var i=e instanceof t?e:new t(e),n=function(t,e,s){var i,n=ot(t),r=ot(e);return function(t){var e=(t.l+16)/116,s=t.a/500+e,i=e-t.b/200;return function(t){var e,s,i=.9555766*(e=t).x+-.0230393*e.y+.0631636*e.z,n=-.0282895*e.x+1.0099416*e.y+.0210077*e.z,r=.0122982*e.x+-.020483*e.y+1.3299098*e.z;return s={r:et(.032404542*i-.015371385*n-.004985314*r),g:et(-.00969266*i+.018760108*n+41556e-8*r),b:et(556434e-9*i-.002040259*n+.010572252*r),a:t.a},{r:Q(s.r,0,255),g:Q(s.g,0,255),b:Q(s.b,0,255),a:Q(s.a)}}({x:(Math.pow(s,3)>nt?Math.pow(s,3):(116*s-16)/rt)*st,y:100*(t.l>8?Math.pow((t.l+16)/116,3):t.l/rt),z:(Math.pow(i,3)>nt?Math.pow(i,3):(116*i-16)/rt)*it,a:t.alpha})}({l:Q((i={l:n.l*(1-s)+r.l*s,a:n.a*(1-s)+r.a*s,b:n.b*(1-s)+r.b*s,alpha:n.alpha*(1-s)+r.alpha*s}).l,0,400),a:i.a,b:i.b,alpha:Q(i.alpha)})}(this.toRgb(),i.toRgb(),s);return new t(n)},t.prototype.tints=function(t){return e(this,"#fff",t)},t.prototype.shades=function(t){return e(this,"#000",t)},t.prototype.tones=function(t){return e(this,"#808080",t)}}]);const at=Symbol("_parsed");class ht{constructor(...t){this[at]=null,this.set(...t)}clone(){return new ht(this)}get red(){return this[at].rgba.r/255}set red(t){this[at].rgba.r=n(255*t,0,255)}get green(){return this[at].rgba.g/255}set green(t){this[at].rgba.g=n(255*t,0,255)}get blue(){return this[at].rgba.b/255}set blue(t){this[at].rgba.b=n(255*t,0,255)}get alpha(){return this[at].rgba.a}set alpha(t){this[at].rgba.a=n(t,0,1)}get array(){return[this.red,this.green,this.blue]}get hex(){return this[at].toHex()}get rgb(){return this.hex}get name(){return this[at].toName({closest:!0})}set(...t){const[e]=t;let s,i;if(e instanceof ht)s=e[at].rgba,[,i=s.a]=t;else if("string"==typeof e)s=e,[,i=1]=t;else if(null==e)s="#000",i=1;else if(t.length<3)s=`#${a(t[0]).toString(16)}`,[,i=1]=t;else{const[e,n,r]=t.slice(0,3).map((t=>255*t));[,,,i=1]=t,s={r:e,g:n,b:r}}return this[at]=V(s).alpha(i),this}grey(){return this[at]=this[at].grayscale(),this}hue(t){return this[at]=this[at].hue(t*l),this}saturation(t){const e=this[at].toHsl();return e.s=100*t,this[at]=V(e),this}lightness(t){const e=this[at].toHsl();return e.l=100*t,this[at]=V(e),this}reverse(){return this[at]=this[at].invert(),this}level(t){const{r:e,g:s,b:i}=this[at].rgba,n=255/t;return this[at].rgba.r=a(e/n)*n+n/2,this[at].rgba.g=a(s/n)*n+n/2,this[at].rgba.b=a(i/n)*n+n/2,this}lerp(t,e){const s=ht.from(t);return this[at]=this[at].mix(s[at],e),this}toString(){return this.hex}toJSON(){return[...this.array,this.alpha]}static from(...t){const e=t[0];return e instanceof ht?e:new ht(...t)}}ht.prototype.gray=ht.prototype.grey,ht.prototype.mix=ht.prototype.lerp;class lt extends k{constructor(t,e={}){super(t,e),this.path=null,this.isClicked=!1,this.isHovered=!1}getOrigin(){return w.from(this.options.origin)}setOptions(t={}){const{shadow:e}=this.options;return super.setOptions(t),"string"!=typeof this.options.origin&&(this.options.origin=w.from(this.options.origin)),this.options.shadow={...lt.defaultOptions.shadow,...e,...t.shadow},this.options.shadow.position=w.from(this.options.shadow.position),this}get willFill(){return Boolean(this.options.fill)}get willStroke(){return Boolean(this.options.stroke)&&this.options.strokeWidth>0}setContext(t){if(super.setContext(t),this.options.shadow.color){const e=w.from(this.options.shadow.position);t.shadowColor=this.options.shadow.color.toString(),t.shadowBlur=this.options.shadow.blur,t.shadowOffsetX=e.x,t.shadowOffsetY=e.y}else t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0;if(this.willFill&&(t.fillStyle=this.options.fill.toString(t)),this.willStroke)if(t.lineJoin=this.options.join,t.lineCap=this.options.cap,t.strokeStyle=this.options.stroke.toString(t),t.lineWidth=this.options.strokeWidth,this.options.dashed){const{dashed:e,strokeWidth:s}=this.options,i=Array.isArray(e)?e:lt.dashes.default;t.setLineDash(i.map((t=>t*s)))}else t.setLineDash([]);return this}makePath(t){if(this.willFill||this.willStroke){const e=this.getOrigin();t.translate(e.x,e.y),this.path=new window.Path2D,this.trace(this.path),this.willFill&&t.fill(this.path),this.willStroke&&t.stroke(this.path),t.translate(-e.x,-e.y)}return this}trace(){throw new ReferenceError(`Unimplemented [trace] function in ${this.constructor.name}.`)}isHover(t,e=R.getDrawingContext()){if(!this.options.shown)return!1;e.save();const s=w.from(t),i=this.getOrigin();if(e.translate(i.x,i.y),!this.willFill&&!this.willStroke)return e.restore(),!1;this.path||(this.path=new window.Path2D,this.trace(this.path));let n=this.willFill&&e.isPointInPath(this.path,s.x,s.y)||this.willStroke&&e.isPointInStroke(this.path,s.x,s.y);return this.options.clip&&(n=n&&this.options.clip.isHover(s,e)),e.restore(),n}static get defaultOptions(){return{...super.defaultOptions,fill:"#000",stroke:null,strokeWidth:2,dashed:!1,cursor:lt.cursors.default,join:lt.joins.miter,origin:new w,shadow:{blur:0,position:new w,color:null}}}static get cursors(){const t={default:"default",none:"none",contextMenu:"context-menu",help:"help",pointer:"pointer",progress:"progress",wait:"wait",cell:"cell",crosshair:"crosshair",text:"text",textVertical:"vertical-text",alias:"alias",copy:"copy",move:"move",noDrop:"no-drop",notAllowed:"not-allowed",grab:"grab",grabbing:"grabbing",allScroll:"all-scroll",colResize:"col-resize",rowResize:"row-resize",nResize:"n-resize",eResize:"e-resize",sResize:"s-resize",wResize:"w-resize",neResize:"ne-resize",seResize:"se-resize",swResize:"sw-resize",nwResize:"nw-resize",ewResize:"ew-resize",nsResize:"ns-resize",neswResize:"nesw-resize",nwseResize:"nwse-resize",zoomIn:"zoom-in",zoomOut:"zoom-out"};return t.link=t.alias,t.verticalResize=t.rowResize,t.horizontalResize=t.colResize,t.topResize=t.nResize,t.rightResize=t.eResize,t.bottomResize=t.sResize,t.leftResize=t.wResize,t}static get joins(){return{miter:"miter",round:"round",bevel:"bevel"}}static get dashes(){const t={default:[4,4],dots:[1,4],long:[9,4]};return t.sewing=[...t.default,...t.dots],t}}class ct extends lt{constructor(t,e=0,s=0,i){super(t,i),this.width=e,this.height=s}trace(t){const{rounded:e}=this.options;return e?t.roundRect(0,0,this.width,this.height,...Array.isArray(e)?e:[e]):t.rect(0,0,this.width,this.height),this}getOrigin(){const{origin:t}=this.options;if("string"==typeof t){const{origins:e}=ct,s=new w;return[e.topRight,e.centerRight,e.bottomRight].includes(t)?s.x=-this.width:[e.topCenter,e.center,e.bottomCenter].includes(t)&&(s.x=-this.width/2),[e.bottomLeft,e.bottomCenter,e.bottomRight].includes(t)?s.y=-this.height:[e.centerLeft,e.center,e.centerRight].includes(t)&&(s.y=-this.height/2),s}return super.getOrigin()}toJSON(){const{width:t,height:e}=this;return{...super.toJSON(),width:t,height:e}}static from(t){return new ct(t.position,t.width,t.height,t.options)}static get defaultOptions(){return{...super.defaultOptions,rounded:0}}static get origins(){return{topLeft:"topLeft",topRight:"topRight",topCenter:"topCenter",center:"center",centerLeft:"centerLeft",centerRight:"centerRight",bottomLeft:"bottomLeft",bottomRight:"bottomRight",bottomCenter:"bottomCenter"}}}class ut extends O{static get events(){return{ready:"ready",error:"error"}}}const dt=Symbol("_url"),pt=Symbol("_offscreen");class ft extends ct{constructor(t,e,s){super(t,void 0,void 0,s),this.file=null,this.isLoaded=!1,this[dt]=null,this[pt]={},this.url=e}set url(t){if(this.url!==t&&(this.file=null,this.isLoaded=!1,this[dt]=t,t)){const e=t=>{this[dt]=t.src,this.file=t,this.isLoaded=!0,this.width=t.width,this.height=t.height,this.fire(new ut(ut.events.ready,this))};t instanceof window.HTMLImageElement?e(t):t instanceof ft?t.isLoaded?e(t.file):t.on(ut.events.ready,(()=>e(t.file))):ft.load(t).then(e).catch((()=>{this.fire(new ut(ut.events.error,this))}))}}get url(){return this[dt]}makePath(t){if(this.isLoaded){t.save();const e=this.getOrigin();t.translate(e.x,e.y);const s=new window.Path2D;this.trace(s),this.path=s,this.willFill&&(t.fill(s),t.shadowBlur=0),this.willStroke&&t.stroke(s),this.draw(t),t.restore()}return this}draw(t){if(this.options.tint){this[pt].cache||(this[pt].cache=R.getDrawingContext(this.width,this.height));const{cache:e}=this[pt],s=this.options.tint.toString();s!==this[pt].tint&&(e.clearRect(0,0,e.canvas.width,e.canvas.height),e.drawImage(this.file,0,0),e.globalCompositeOperation="source-atop",e.fillStyle=s,e.fillRect(0,0,e.canvas.width,e.canvas.height),this[pt].tint=s),t.drawImage(this[pt].cache.canvas,0,0,this.width,this.height)}else t.drawImage(this.file,0,0,this.width,this.height);return this}isHover(...t){if(!this.isLoaded)return!1;const e=this.options.fill;this.options.fill=!0;const s=super.isHover(...t);return this.options.fill=e,s}toJSON(){const t=super.toJSON();delete t.width,delete t.height;const{url:e}=this;return{...t,url:e}}static from(t){return new ft(t.position,t.url,t.options)}static load(t){return Array.isArray(t)?Promise.all(t.map((t=>ft.load(t)))):new Promise(((e,s)=>{const i=window.document.createElement("img");i.crossOrigin="Anonymous",i.src=t,i.addEventListener("load",(()=>e(i))),i.addEventListener("error",(()=>s(new URIError(`Fail to load ${t}.`))))}))}static get defaultOptions(){return{...super.defaultOptions,fill:null,tint:null,description:""}}}const gt=Symbol("_source");class mt{constructor(t,e){this.options={...mt.defaultOptions,...e},this.source=t}get source(){const t=this[gt];return t instanceof R?(t.isLooped||t.render(),t.ctx.canvas):t}set source(t){t instanceof window.HTMLImageElement||t instanceof window.HTMLCanvasElement||t instanceof R?this[gt]=t:t instanceof ft?t.isLoaded?this[gt]=t.file:t.on(ut.events.ready,(()=>{this[gt]=t.file})):t instanceof mt&&(this[gt]=t.source)}get width(){return this[gt].width}get height(){return this[gt].height}toString(t){const{repeat:e,scale:s}=this.options,i=t.createPattern(this.source,e),n=new window.DOMMatrix;if("number"==typeof s)n.a=s,n.d=s;else{const t=w.from(s);n.a=t.x,n.d=t.y}const r=ct.prototype.getOrigin.call(this);return n.e=r.x*n.a,n.f=r.y*n.d,i.setTransform(n),i}static get defaultOptions(){return{repeat:this.repetition.repeat,origin:new w,scale:1}}static get repetition(){return{repeat:"repeat",x:"repeat-x",y:"repeat-y",none:"no-repeat"}}}class wt extends O{constructor(t,e,s){super(t,e,s),this.key=s.key}getModifier(){return this.key}static get events(){return{down:"keydown",up:"keyup"}}static get keys(){return{backspace:"Backspace",enter:"Enter",delete:"Delete",escape:"Escape",control:"Control",shift:"Shift",fn:"Fn",arrows:{up:"ArrowUp",right:"ArrowRight",down:"ArrowDown",left:"ArrowLeft"},tab:"Tab",alt:"Alt",altGr:"AltGraph",pageUp:"PageUp",pageDown:"PageDown",start:"Home",end:"End",insert:"Insert"}}}class bt extends O{constructor(t,e,s,i){super(t,e,i),this.position=w.from(s),this.button=i?i.button:null}getModifier(){return this.button}static get buttons(){return{left:"0",main:"0",wheel:"1",middle:"1",right:"2",secondary:"2",backward:"3",aux1:"3",forward:"4",aux2:"4"}}static get events(){return{down:"mousedown",up:"mouseup",click:"click",contextMenu:"contextmenu",move:"mousemove",hover:"hover",leave:"leave",wheel:"mousewheel",scrollDown:"scrolldown",scrollUp:"scrollup",zoomOut:"zoomout",zoomIn:"zoomin",grab:"grab",drag:"drag",drop:"drop",resize:"resize",rotate:"rotate",doubleClick:"dblclick"}}}const vt=Symbol("_listenForEvents");class yt extends R{constructor(t=window.document.body,e){t===window.document.body&&(t.style.margin=0,t.style.height=`${window.innerHeight}px`);const s=t.getBoundingClientRect();t instanceof window.HTMLCanvasElement?(super(null,0,e),this.ctx=t.getContext("2d")):(super(t,0,e),t.appendChild(this.ctx.canvas)),this.cursorPosition=new w,this.containerPosition=new w(s.left+window.scrollX,s.top+window.scrollY),this.isScene=!0,this.isLooped=!1,this.isClicked=!1,this.fps=0,this.lastTick=null,this[vt](t)}setCursor(t=lt.cursors.default){return this.ctx.canvas.style.cursor=t,this}render(){const t=this.isLooped?window.requestAnimationFrame(this.render.bind(this,void 0)):null;try{super.render(this.ctx)}catch(e){throw window.cancelAnimationFrame(t),this.stopLoop(),e}const e=window.performance.now();return this.isLooped&&this.lastTick&&(this.fps=1e3/(e-this.lastTick)),this.lastTick=e,this}isHover(){return this.options.shown}startLoop(){return this.isLooped=!0,this.render(),this}stopLoop(){return this.isLooped=!1,this.fps=0,this}hide(){return this.ctx.canvas.style.visibility="hidden",super.hide()}show(){return this.ctx.canvas.style.visibility="",super.show()}static from(t){return new yt(void 0,t.options)}static getDrawingContext(t=window.document.body){if(t){const{scrollWidth:e,scrollHeight:s}=t,i=super.getDrawingContext(e,s);return i.canvas.style.display="block",i.canvas.style.position="absolute",i}return null}static get defaultOptions(){return{...super.defaultOptions,cursor:lt.cursors.default}}static get events(){return{...super.events,change:"change-scene"}}}yt.prototype[vt]=function(t){if(this.isReady)throw new EvalError("Can't rebind event a second time.");let e=null,s=null;const i={[bt.events.down]:(t,e)=>{t.isClicked=!0,s=e},[bt.events.move]:(t,i)=>{s&&(t.isClicked=t.isClicked&&i.distance(s)<10),t!==e&&(e&&(e.isHovered=!1,e.isAncestorOf(t)||e.fire(new bt(bt.events.leave,e,i))),e=t),t.isHovered||(t.isHovered=!0,t.fire(new bt(bt.events.hover,t,i))),this.setCursor(t.options.cursor),this.cursorPosition.set(i)},[bt.events.up]:(t,e,i)=>{s=null,t.isClicked&&(t.fire(new bt(bt.events.click,t,e,i)),t.isClicked=!1)},[bt.events.wheel]:(t,e,s)=>{const i=bt.events,n=s.deltaY>0?[i.scrollDown,i.zoomOut]:[i.scrollUp,i.zoomIn];t.fire(new bt(n[0],t,e,s)).fire(new bt(n[1],t,e,s))},mouseout:(t,e,s)=>{t.fire(new bt(bt.events.leave,t,e,s))},mouseenter:(t,e,s)=>{t.fire(new bt(bt.events.hover,t,e,s))},[bt.events.contextMenu]:null,[bt.events.doubleClick]:null};Object.keys(i).forEach((e=>{t.addEventListener(e,(t=>{if(this.options.shown){const s=new w(t.clientX,t.clientY).subtract(this.containerPosition).add(window.scrollX,window.scrollY),n=this.getTarget(s,this.ctx);n&&(n.fire(new bt(e,n,s,t)),i[e]instanceof Function&&i[e](n,s,t))}}),{passive:!1})}));const n={[wt.events.down]:null,[wt.events.up]:null};Object.keys(n).forEach((t=>{window.document.addEventListener(t,(e=>{this.options.shown&&(this.fire(new wt(t,this,e)),n[t]instanceof Function&&n[t](e))}))}))};let xt=null;const Ot=[],St=()=>xt,kt=(t,e=!0)=>(xt&&xt.hide().stopLoop(),e&&Ot.push(xt),t.show().startLoop(),xt=t,t),Rt=()=>kt(Ot.pop(),!1),zt=(t,e=window.document.body)=>{let s=e;s instanceof window.HTMLCanvasElement||(({canvas:s}=yt.getDrawingContext(e)),e.appendChild(s));const i=Object.keys(t),n={};return i.forEach((e=>{const i=new yt(s);t[e](i),n[e]=i,i.hide(),i.on(yt.events.change,(t=>kt(n[t.target])))})),kt(n[i[0]]),n};class Et extends lt{constructor(t,e,s,i,n){super(t,{...e.options,...n}),this.base=e,this.generator=s,this.updater=i,this.data=[]}generate(t,...e){return this.data=this.data.concat([...new Array(t)].map(((t,s)=>{const i={...Et.defaultData,...this.generator?this.generator(s,...e):{}};return i.position=w.from(i.position),i}))),this}trace(t){const e=new window.Path2D;this.base.trace(e);const s=new window.DOMMatrix,{cos:i,sin:n}=Math;if(this.data=this.data.filter(((r,o)=>{this.updater&&this.updater(r,o);const{position:a,scale:l=1,rotation:c=0,ttl:u}=r,d="number"==typeof l?[l,l]:w.from(l).toJSON(),p=c*h;return s.a=i(p)*d[0],s.b=n(p)*d[0],s.c=-n(p)*d[1],s.d=i(p)*d[1],s.e=a.x,s.f=a.y,t.addPath(e,s),!u||--r.ttl>0})),this.options.emit&&o()<this.options.frequency){const t=Array.isArray(this.options.emit)?o(...this.options.emit):this.options.emit;this.generate(Math.floor(t),...this.options.args)}return this}isHover(){return!1}toJSON(){const{base:t,data:e}=this;return{...super.toJSON(),base:t,data:e}}static from(t){const e=from(t.base),s=new Et(t.position,e,0);return s.data=t.data,s}static get defaultOptions(){return{...super.defaultOptions,frequency:1,emit:null,args:[]}}static get defaultData(){return{position:new w}}}class Mt extends lt{constructor(t,e,s){super(t,s),this.points=e.map(w.from)}trace(t){t.moveTo(0,0);const{x:e=0,y:s=0}=this.options.absolute?this.position:{};return this.points.forEach((i=>t.lineTo(i.x-e,i.y-s))),this}toJSON(){const{points:t}=this;return{...super.toJSON(),points:t}}static from(t){return new Mt(t.position,t.points,t.options)}static get defaultOptions(){return{...super.defaultOptions,cap:Mt.caps.round,join:Mt.joins.round,fill:null,stroke:super.defaultOptions.fill,absolute:!1}}static get caps(){return{butt:"butt",round:"round",square:"square"}}}class Ct extends lt{constructor(t,e=0,s=0,i=0,n=.5,r){super(t,r),this.width=e,this.height=s,this.startAngle=i,this.endAngle=n}trace(t){const e=(this.startAngle+-.25)*h,s=(this.endAngle+-.25)*h;return t.ellipse(0,0,this.width,this.height,0,e,s),this}toJSON(){const{width:t,height:e,startAngle:s,endAngle:i}=this;return{...super.toJSON(),width:t,height:e,startAngle:s,endAngle:i}}static from(t){return new Ct(t.position,t.width,t.height,t.startAngle,t.endAngle,t.options)}static get defaultOptions(){return Mt.defaultOptions}static get caps(){return Mt.caps}}class At extends Ct{constructor(t,e,s,i,n){super(t,e,e,s,i,n)}trace(t){return t.moveTo(0,0),super.trace(t)}get radius(){return this.width}set radius(t){this.width=t,this.height=t}toJSON(){const{radius:t}=this,e={...super.toJSON(),radius:t};return delete e.width,delete e.height,e}static get defaultOptions(){return lt.defaultOptions}}class Nt extends Ct{constructor(t,e,s,i){super(t,e,s,0,1,i)}toJSO