unknown

andy

var AndyCircuitLab=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}var n={},r={},i={},a;function o(){if(a)return i;a=1;function e(e){return e==null}function t(e){return typeof e==`object`&&!!e}function n(t){return Array.isArray(t)?t:e(t)?[]:[t]}function r(e,t){if(t){let n=Object.keys(t);for(let r=0,i=n.length;rs&&(a=` ... `,t=r-s+a.length),n-r>s&&(o=` ...`,n=r+s-o.length),{str:a+e.slice(t,n).replace(/\t/g,`→`)+o,pos:r-t+a.length}}function n(t,n){return e.repeat(` `,n-t.length)+t}function r(r,i){if(i=Object.create(i||null),!r.buffer)return null;i.maxLength||=79,typeof i.indent!=`number`&&(i.indent=1),typeof i.linesBefore!=`number`&&(i.linesBefore=3),typeof i.linesAfter!=`number`&&(i.linesAfter=2);let a=/\r?\n|\r|\0/g,o=[0],s=[],c,l=-1;for(;c=a.exec(r.buffer);)s.push(c.index),o.push(c.index+c[0].length),r.position<=c.index&&l<0&&(l=o.length-2);l<0&&(l=o.length-1);let u=``,d=Math.min(r.line+i.linesAfter,s.length).toString().length,f=i.maxLength-(i.indent+d+3);for(let a=1;a<=i.linesBefore&&!(l-a<0);a++){let c=t(r.buffer,o[l-a],s[l-a],r.position-(o[l]-o[l-a]),f);u=e.repeat(` `,i.indent)+n((r.line-a+1).toString(),d)+` | `+c.str+` `+u}let p=t(r.buffer,o[l],s[l],r.position,f);u+=e.repeat(` `,i.indent)+n((r.line+1).toString(),d)+` | `+p.str+` `,u+=e.repeat(`-`,i.indent+d+3+p.pos)+`^ `;for(let a=1;a<=i.linesAfter&&!(l+a>=s.length);a++){let c=t(r.buffer,o[l+a],s[l+a],r.position-(o[l]-o[l+a]),f);u+=e.repeat(` `,i.indent)+n((r.line+a+1).toString(),d)+` | `+c.str+` `}return u.replace(/\n$/,``)}return u=r,u}var p,m;function h(){if(m)return p;m=1;let e=l(),t=[`kind`,`multi`,`resolve`,`construct`,`instanceOf`,`predicate`,`represent`,`representName`,`defaultStyle`,`styleAliases`],n=[`scalar`,`sequence`,`mapping`];function r(e){let t={};return e!==null&&Object.keys(e).forEach(function(n){e[n].forEach(function(e){t[String(e)]=n})}),t}function i(i,a){if(a||={},Object.keys(a).forEach(function(n){if(t.indexOf(n)===-1)throw new e(`Unknown option "`+n+`" is met in definition of "`+i+`" YAML type.`)}),this.options=a,this.tag=i,this.kind=a.kind||null,this.resolve=a.resolve||function(){return!0},this.construct=a.construct||function(e){return e},this.instanceOf=a.instanceOf||null,this.predicate=a.predicate||null,this.represent=a.represent||null,this.representName=a.representName||null,this.defaultStyle=a.defaultStyle||null,this.multi=a.multi||!1,this.styleAliases=r(a.styleAliases||null),n.indexOf(this.kind)===-1)throw new e(`Unknown kind "`+this.kind+`" is specified for "`+i+`" YAML type.`)}return p=i,p}var g,_;function v(){if(_)return g;_=1;let e=l(),t=h();function n(e,t){let n=[];return e[t].forEach(function(e){let t=n.length;n.forEach(function(n,r){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=r)}),n[t]=e}),n}function r(){let e={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function t(t){t.multi?(e.multi[t.kind].push(t),e.multi.fallback.push(t)):e[t.kind][t.tag]=e.fallback[t.tag]=t}for(let e=0,n=arguments.length;e=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function r(e){return e>=48&&e<=55}function i(e){return e>=48&&e<=57}function a(e){if(e===null)return!1;let t=e.length,a=0,o=!1;if(!t)return!1;let c=e[a];if((c===`-`||c===`+`)&&(c=e[++a]),c===`0`){if(a+1===t)return!0;if(c=e[++a],c===`b`){for(a++;a=0?`0b`+e.toString(2):`-0b`+e.toString(2).slice(1)},octal:function(e){return e>=0?`0o`+e.toString(8):`-0o`+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?`0x`+e.toString(16).toUpperCase():`-0x`+e.toString(16).toUpperCase().slice(1)}},defaultStyle:`decimal`,styleAliases:{binary:[2,`bin`],octal:[8,`oct`],decimal:[10,`dec`],hexadecimal:[16,`hex`]}}),P}var ae,oe;function F(){if(oe)return ae;oe=1;let e=o(),t=h(),n=RegExp(`^(?:[-+]?(?:[0-9]+)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$`),r=RegExp(`^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$`);function i(e){return e===null||!n.test(e)?!1:isFinite(parseFloat(e,10))?!0:r.test(e)}function a(e){let t=e.toLowerCase(),n=t[0]===`-`?-1:1;return`+-`.indexOf(t[0])>=0&&(t=t.slice(1)),t===`.inf`?n===1?1/0:-1/0:t===`.nan`?NaN:n*parseFloat(t,10)}let s=/^[-+]?[0-9]+e/;function c(t,n){if(isNaN(t))switch(n){case`lowercase`:return`.nan`;case`uppercase`:return`.NAN`;case`camelcase`:return`.NaN`}else if(t===1/0)switch(n){case`lowercase`:return`.inf`;case`uppercase`:return`.INF`;case`camelcase`:return`.Inf`}else if(t===-1/0)switch(n){case`lowercase`:return`-.inf`;case`uppercase`:return`-.INF`;case`camelcase`:return`-.Inf`}else if(e.isNegativeZero(t))return`-0.0`;let r=t.toString(10);return s.test(r)?r.replace(`e`,`.e`):r}function l(t){return Object.prototype.toString.call(t)===`[object Number]`&&(t%1!=0||e.isNegativeZero(t))}return ae=new t(`tag:yaml.org,2002:float`,{kind:`scalar`,resolve:i,construct:a,predicate:l,represent:c,defaultStyle:`lowercase`}),ae}var se,ce;function le(){return ce?se:(ce=1,se=O().extend({implicit:[ne(),N(),ie(),F()]}),se)}var ue,de;function fe(){return de?ue:(de=1,ue=le(),ue)}var pe,me;function he(){if(me)return pe;me=1;let e=h(),t=RegExp(`^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$`),n=RegExp(`^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$`);function r(e){return e===null?!1:t.exec(e)!==null||n.exec(e)!==null}function i(e){let r=0,i=null,a=t.exec(e);if(a===null&&(a=n.exec(e)),a===null)throw Error(`Date resolve error`);let o=+a[1],s=a[2]-1,c=+a[3];if(!a[4])return new Date(Date.UTC(o,s,c));let l=+a[4],u=+a[5],d=+a[6];if(a[7]){for(r=a[7].slice(0,3);r.length<3;)r+=`0`;r=+r}if(a[9]){let e=+a[10],t=+(a[11]||0);i=(e*60+t)*6e4,a[9]===`-`&&(i=-i)}let f=new Date(Date.UTC(o,s,c,l,u,d,r));return i&&f.setTime(f.getTime()-i),f}function a(e){return e.toISOString()}return pe=new e(`tag:yaml.org,2002:timestamp`,{kind:`scalar`,resolve:r,construct:i,instanceOf:Date,represent:a}),pe}var I,L;function ge(){if(L)return I;L=1;let e=h();function t(e){return e===`<<`||e===null}return I=new e(`tag:yaml.org,2002:merge`,{kind:`scalar`,resolve:t}),I}var _e,ve;function ye(){if(ve)return _e;ve=1;let e=h();function t(e){if(e===null)return!1;let t=0,n=e.length;for(let r=0;r64)){if(n<0)return!1;t+=6}}return t%8==0}function n(e){let t=e.replace(/[\r\n=]/g,``),n=t.length,r=0,i=[];for(let e=0;e>16&255),i.push(r>>8&255),i.push(r&255)),r=r<<6|`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/= \r`.indexOf(t.charAt(e));let a=n%4*6;return a===0?(i.push(r>>16&255),i.push(r>>8&255),i.push(r&255)):a===18?(i.push(r>>10&255),i.push(r>>2&255)):a===12&&i.push(r>>4&255),new Uint8Array(i)}function r(e){let t=``,n=0,r=e.length,i=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/= \r`;for(let a=0;a>18&63],t+=i[n>>12&63],t+=i[n>>6&63],t+=i[n&63]),n=(n<<8)+e[a];let a=r%3;return a===0?(t+=i[n>>18&63],t+=i[n>>12&63],t+=i[n>>6&63],t+=i[n&63]):a===2?(t+=i[n>>10&63],t+=i[n>>4&63],t+=i[n<<2&63],t+=i[64]):a===1&&(t+=i[n>>2&63],t+=i[n<<4&63],t+=i[64],t+=i[64]),t}function i(e){return Object.prototype.toString.call(e)===`[object Uint8Array]`}return _e=new e(`tag:yaml.org,2002:binary`,{kind:`scalar`,resolve:t,construct:n,predicate:i,represent:r}),_e}var be,xe;function Se(){if(xe)return be;xe=1;let e=h(),t=Object.prototype.hasOwnProperty,n=Object.prototype.toString;function r(e){if(e===null)return!0;let r=[],i=e;for(let e=0,a=i.length;e=48&&e<=57)return e-48;let t=e|32;return t>=97&&t<=102?t-97+10:-1}function b(e){return e===120?2:e===117?4:e===85?8:0}function x(e){return e>=48&&e<=57?e-48:-1}function S(e){switch(e){case 48:return`\0`;case 97:return`\x07`;case 98:return`\b`;case 116:return` `;case 9:return` `;case 110:return` `;case 118:return`\v`;case 102:return`\f`;case 114:return`\r`;case 101:return`\x1B`;case 32:return` `;case 34:return`"`;case 47:return`/`;case 92:return`\\`;case 78:return`…`;case 95:return`\xA0`;case 76:return`\u2028`;case 80:return`\u2029`;default:return``}}function C(e){return e<=65535?String.fromCharCode(e):String.fromCharCode((e-65536>>10)+55296,(e-65536&1023)+56320)}function w(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{configurable:!0,enumerable:!0,writable:!0,value:n}):e[t]=n}let ee=Array(256),T=Array(256);for(let e=0;e<256;e++)ee[e]=+!!S(e),T[e]=S(e);function te(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||i,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.maxDepth=typeof t.maxDepth==`number`?t.maxDepth:100,this.maxTotalMergeKeys=typeof t.maxTotalMergeKeys==`number`?t.maxTotalMergeKeys:1e4,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.depth=0,this.totalMergeKeys=0,this.firstTabInLine=-1,this.documents=[],this.anchorMapTransactions=[]}function E(e,r){let i={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return i.snippet=n(i),new t(r,i)}function D(e,t){throw E(e,t)}function O(e,t){e.onWarning&&e.onWarning.call(null,E(e,t))}function k(e,t,n){let r=e.anchorMapTransactions;if(r.length!==0){let n=r[r.length-1];a.call(n,t)||(n[t]={existed:a.call(e.anchorMap,t),value:e.anchorMap[t]})}e.anchorMap[t]=n}function A(e){e.anchorMapTransactions.push(Object.create(null))}function ne(e){let t=e.anchorMapTransactions.pop(),n=e.anchorMapTransactions;if(n.length===0)return;let r=n[n.length-1],i=Object.keys(t);for(let e=0,n=i.length;e=0;--r){let i=t[n[r]];i.existed?e.anchorMap[n[r]]=i.value:delete e.anchorMap[n[r]]}}function M(e){return{position:e.position,line:e.line,lineStart:e.lineStart,lineIndent:e.lineIndent,firstTabInLine:e.firstTabInLine,tag:e.tag,anchor:e.anchor,kind:e.kind,result:e.result}}function N(e,t){e.position=t.position,e.line=t.line,e.lineStart=t.lineStart,e.lineIndent=t.lineIndent,e.firstTabInLine=t.firstTabInLine,e.tag=t.tag,e.anchor=t.anchor,e.kind=t.kind,e.result=t.result}let P={YAML:function(e,t,n){e.version!==null&&D(e,`duplication of %YAML directive`),n.length!==1&&D(e,`YAML directive accepts exactly one argument`);let r=/^([0-9]+)\.([0-9]+)$/.exec(n[0]);r===null&&D(e,`ill-formed argument of the YAML directive`);let i=parseInt(r[1],10),a=parseInt(r[2],10);i!==1&&D(e,`unacceptable YAML version of the document`),e.version=n[0],e.checkLineBreaks=a<2,a!==1&&a!==2&&O(e,`unsupported YAML version of the document`)},TAG:function(e,t,n){let r;n.length!==2&&D(e,`TAG directive accepts exactly two arguments`);let i=n[0];r=n[1],d.test(i)||D(e,`ill-formed tag handle (first argument) of the TAG directive`),a.call(e.tagMap,i)&&D(e,`there is a previously declared suffix for "`+i+`" tag handle`),p.test(r)||D(e,`ill-formed tag prefix (second argument) of the TAG directive`);try{r=decodeURIComponent(r)}catch{D(e,`tag prefix is malformed: `+r)}e.tagMap[i]=r}};function re(e,t,n,r){if(t=32&&n<=1114111||D(e,`expected valid JSON character`)}else s.test(i)&&D(e,`the stream contains non-printable characters`);e.result+=i}}function ie(t,n,r,i){e.isObject(r)||D(t,`cannot merge mappings; the provided source object is unacceptable`);let o=Object.keys(r);for(let e=0,s=o.length;et.maxTotalMergeKeys&&D(t,`merge keys exceeded maxTotalMergeKeys (`+t.maxTotalMergeKeys+`)`),a.call(n,s)||(w(n,s,r[s]),i[s]=!0)}}function ae(e,t,n,r,i,o,s,c,l){if(Array.isArray(i)){i=Array.prototype.slice.call(i);for(let t=0,n=i.length;t1&&(t.result+=e.repeat(` `,n-1))}function le(e,t,n){let r,i,a,o,s,c,l=e.kind,u=e.result,d=e.input.charCodeAt(e.position);if(_(d)||v(d)||d===35||d===38||d===42||d===33||d===124||d===62||d===39||d===34||d===37||d===64||d===96)return!1;if(d===63||d===45){let t=e.input.charCodeAt(e.position+1);if(_(t)||n&&v(t))return!1}for(e.kind=`scalar`,e.result=``,r=i=e.position,a=!1;d!==0;){if(d===58){let t=e.input.charCodeAt(e.position+1);if(_(t)||n&&v(t))break}else if(d===35){if(_(e.input.charCodeAt(e.position-1)))break}else if(e.position===e.lineStart&&se(e)||n&&v(d))break;else if(h(d))if(o=e.line,s=e.lineStart,c=e.lineIndent,F(e,!1,-1),e.lineIndent>=t){a=!0,d=e.input.charCodeAt(e.position);continue}else{e.position=i,e.line=o,e.lineStart=s,e.lineIndent=c;break}a&&=(re(e,r,i,!1),ce(e,e.line-o),r=i=e.position,!1),g(d)||(i=e.position+1),d=e.input.charCodeAt(++e.position)}return re(e,r,i,!1),e.result?!0:(e.kind=l,e.result=u,!1)}function ue(e,t){let n,r,i=e.input.charCodeAt(e.position);if(i!==39)return!1;for(e.kind=`scalar`,e.result=``,e.position++,n=r=e.position;(i=e.input.charCodeAt(e.position))!==0;)if(i===39)if(re(e,n,e.position,!0),i=e.input.charCodeAt(++e.position),i===39)n=e.position,e.position++,r=e.position;else return!0;else h(i)?(re(e,n,r,!0),ce(e,F(e,!1,t)),n=r=e.position):e.position===e.lineStart&&se(e)?D(e,`unexpected end of the document within a single quoted scalar`):(e.position++,g(i)||(r=e.position));D(e,`unexpected end of the stream within a single quoted scalar`)}function de(e,t){let n,r,i,a=e.input.charCodeAt(e.position);if(a!==34)return!1;for(e.kind=`scalar`,e.result=``,e.position++,n=r=e.position;(a=e.input.charCodeAt(e.position))!==0;)if(a===34)return re(e,n,e.position,!0),e.position++,!0;else if(a===92){if(re(e,n,e.position,!0),a=e.input.charCodeAt(++e.position),h(a))F(e,!1,t);else if(a<256&&ee[a])e.result+=T[a],e.position++;else if((i=b(a))>0){let t=i,n=0;for(;t>0;t--)a=e.input.charCodeAt(++e.position),(i=y(a))>=0?n=(n<<4)+i:D(e,`expected hexadecimal character`);e.result+=C(n),e.position++}else D(e,`unknown escape sequence`);n=r=e.position}else h(a)?(re(e,n,r,!0),ce(e,F(e,!1,t)),n=r=e.position):e.position===e.lineStart&&se(e)?D(e,`unexpected end of the document within a double quoted scalar`):(e.position++,g(a)||(r=e.position));D(e,`unexpected end of the stream within a double quoted scalar`)}function fe(e,t){let n=!0,r,i,a,o=e.tag,s,c=e.anchor,l,u,d,f,p=Object.create(null),m,h,g,v=e.input.charCodeAt(e.position);if(v===91)l=93,f=!1,s=[];else if(v===123)l=125,f=!0,s={};else return!1;for(e.anchor!==null&&k(e,e.anchor,s),v=e.input.charCodeAt(++e.position);v!==0;){if(F(e,!0,t),v=e.input.charCodeAt(e.position),v===l)return e.position++,e.tag=o,e.anchor=c,e.kind=f?`mapping`:`sequence`,e.result=s,!0;n?v===44&&D(e,`expected the node content, but found ','`):D(e,`missed comma between flow collection entries`),h=m=g=null,u=d=!1,v===63&&_(e.input.charCodeAt(e.position+1))&&(u=d=!0,e.position++,F(e,!0,t)),r=e.line,i=e.lineStart,a=e.position,ve(e,t,1,!1,!0),h=e.tag,m=e.result,F(e,!0,t),v=e.input.charCodeAt(e.position),(d||e.line===r)&&v===58&&(u=!0,v=e.input.charCodeAt(++e.position),F(e,!0,t),ve(e,t,1,!1,!0),g=e.result),f?ae(e,s,p,h,m,g,r,i,a):u?s.push(ae(e,null,p,h,m,g,r,i,a)):s.push(m),F(e,!0,t),v=e.input.charCodeAt(e.position),v===44?(n=!0,v=e.input.charCodeAt(++e.position)):n=!1}D(e,`unexpected end of the stream within a flow collection`)}function pe(t,n){let r,i=1,a=!1,o=!1,s=n,c=0,l=!1,u,d=t.input.charCodeAt(t.position);if(d===124)r=!1;else if(d===62)r=!0;else return!1;for(t.kind=`scalar`,t.result=``;d!==0;)if(d=t.input.charCodeAt(++t.position),d===43||d===45)i===1?i=d===43?3:2:D(t,`repeat of a chomping mode identifier`);else if((u=x(d))>=0)u===0?D(t,`bad explicit indentation width of a block scalar; it cannot be less than one`):o?D(t,`repeat of an indentation width identifier`):(s=n+u-1,o=!0);else break;if(g(d)){do d=t.input.charCodeAt(++t.position);while(g(d));if(d===35)do d=t.input.charCodeAt(++t.position);while(!h(d)&&d!==0)}for(;d!==0;){for(oe(t),t.lineIndent=0,d=t.input.charCodeAt(t.position);(!o||t.lineIndents&&(s=t.lineIndent),h(d)){c++;continue}if(!o&&s===0&&D(t,`missing indentation for block scalar`),t.lineIndentt)&&o!==0)D(e,`bad indentation of a sequence entry`);else if(e.lineIndentt)&&(m&&(i=e.line,a=e.lineStart,o=e.position),ve(e,t,4,!0,r)&&(m?f=e.result:p=e.result),m||(ae(e,l,u,d,f,p,i,a,o),d=f=p=null),F(e,!0,-1),v=e.input.charCodeAt(e.position)),(e.line===b||e.lineIndent>t)&&v!==0)D(e,`bad indentation of a mapping entry`);else if(e.lineIndent=e.maxDepth&&D(e,`nesting exceeded maxDepth (`+e.maxDepth+`)`),e.depth+=1,e.listener!==null&&e.listener(`open`,e),e.tag=null,e.anchor=null,e.kind=null,e.result=null;let h=o=s=n===4||n===3;if(r&&F(e,!0,-1)&&(l=!0,e.lineIndent>t?c=1:e.lineIndent===t?c=0:e.lineIndentt?c=1:e.lineIndent===t?c=0:e.lineIndent tag; it should be "scalar", not "`+e.kind+`"`);for(let t=0,n=e.implicitTypes.length;t`),e.result!==null&&f.kind!==e.kind&&D(e,`unacceptable node kind for !<`+e.tag+`> tag; it should be "`+f.kind+`", not "`+e.kind+`"`),f.resolve(e.result,e.tag)?(e.result=f.construct(e.result,e.tag),e.anchor!==null&&k(e,e.anchor,e.result)):D(e,`cannot resolve a node with !<`+e.tag+`> explicit tag`)}return e.listener!==null&&e.listener(`close`,e),--e.depth,e.tag!==null||e.anchor!==null||u}function ye(e){let t=e.position,n=!1,r;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);(r=e.input.charCodeAt(e.position))!==0&&(F(e,!0,-1),r=e.input.charCodeAt(e.position),!(e.lineIndent>0||r!==37));){n=!0,r=e.input.charCodeAt(++e.position);let t=e.position;for(;r!==0&&!_(r);)r=e.input.charCodeAt(++e.position);let i=e.input.slice(t,e.position),o=[];for(i.length<1&&D(e,`directive name must not be less than one character in length`);r!==0;){for(;g(r);)r=e.input.charCodeAt(++e.position);if(r===35){do r=e.input.charCodeAt(++e.position);while(r!==0&&!h(r));break}if(h(r))break;for(t=e.position;r!==0&&!_(r);)r=e.input.charCodeAt(++e.position);o.push(e.input.slice(t,e.position))}r!==0&&oe(e),a.call(P,i)?P[i](e,i,o):O(e,`unknown document directive "`+i+`"`)}if(F(e,!0,-1),e.lineIndent===0&&e.input.charCodeAt(e.position)===45&&e.input.charCodeAt(e.position+1)===45&&e.input.charCodeAt(e.position+2)===45?(e.position+=3,F(e,!0,-1)):n&&D(e,`directives end mark is expected`),ve(e,e.lineIndent-1,4,!1,!0),F(e,!0,-1),e.checkLineBreaks&&c.test(e.input.slice(t,e.position))&&O(e,`non-ASCII line breaks are interpreted as content`),e.documents.push(e.result),e.position===e.lineStart&&se(e)){e.input.charCodeAt(e.position)===46&&(e.position+=3,F(e,!0,-1));return}e.position=32&&e<=126||e>=161&&e<=55295&&e!==8232&&e!==8233||e>=57344&&e<=65533&&e!==a||e>=65536&&e<=1114111}function y(e){return v(e)&&e!==a&&e!==13&&e!==10}function b(e,t,n){let r=y(e),i=r&&!_(e);return(n?r:r&&e!==44&&e!==91&&e!==93&&e!==123&&e!==125)&&e!==35&&!(t===58&&!i)||y(t)&&!_(t)&&e===35||t===58&&i}function x(e){return v(e)&&e!==a&&!_(e)&&e!==45&&e!==63&&e!==58&&e!==44&&e!==91&&e!==93&&e!==123&&e!==125&&e!==35&&e!==38&&e!==42&&e!==33&&e!==124&&e!==61&&e!==62&&e!==39&&e!==34&&e!==37&&e!==64&&e!==96}function S(e){return!_(e)&&e!==58}function C(e,t){let n=e.charCodeAt(t),r;return n>=55296&&n<=56319&&t+1=56320&&r<=57343)?(n-55296)*1024+r-56320+65536:n}function w(e){return/^\n* /.test(e)}function ee(e,t,n,r,i,a,o,s){let c,l=0,u=null,d=!1,f=!1,p=r!==-1,m=-1,h=x(C(e,0))&&S(C(e,e.length-1));if(t||o)for(c=0;c=65536?c+=2:c++){if(l=C(e,c),!v(l))return 5;h&&=b(l,u,s),u=l}else{for(c=0;c=65536?c+=2:c++){if(l=C(e,c),l===10)d=!0,p&&(f||=c-m-1>r&&e[m+1]!==` `,m=c);else if(!v(l))return 5;h&&=b(l,u,s),u=l}f||=p&&c-m-1>r&&e[m+1]!==` `}return!d&&!f?h&&!o&&!i(e)?1:a===2?5:2:n>9&&w(e)?5:o?a===2?5:2:f?4:3}function T(e,n,r,i,a){e.dump=(function(){if(n.length===0)return e.quotingType===2?`""`:`''`;if(!e.noCompatMode&&(c.indexOf(n)!==-1||u.test(n)))return e.quotingType===2?`"`+n+`"`:`'`+n+`'`;let o=e.indent*Math.max(1,r),s=e.lineWidth===-1?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-o),l=i||e.flowLevel>-1&&r>=e.flowLevel;function d(t){return g(e,t)}switch(ee(n,l,e.indent,s,d,e.quotingType,e.forceQuotes&&!i,a)){case 1:return n;case 2:return`'`+n.replace(/'/g,`''`)+`'`;case 3:return`|`+te(n,e.indent)+E(m(n,o));case 4:return`>`+te(n,e.indent)+E(m(D(n,s),o));case 5:return`"`+k(n)+`"`;default:throw new t(`impossible error: invalid scalar style`)}})()}function te(e,t){let n=w(e)?String(t):``,r=e[e.length-1]===` `;return n+(r&&(e[e.length-2]===` `||e===` `)?`+`:r?``:`-`)+` `}function E(e){return e[e.length-1]===` `?e.slice(0,-1):e}function D(e,t){let n=/(\n+)([^\n]*)/g,r=(function(){let r=e.indexOf(` `);return r=r===-1?e.length:r,n.lastIndex=r,O(e.slice(0,r),t)})(),i=e[0]===` `||e[0]===` `,a,o;for(;o=n.exec(e);){let e=o[1],n=o[2];a=n[0]===` `,r+=e+(!i&&!a&&n!==``?` `:``)+O(n,t),i=a}return r}function O(e,t){if(e===``||e[0]===` `)return e;let n=/ [^ ]/g,r,i=0,a,o=0,s=0,c=``;for(;r=n.exec(e);)s=r.index,s-i>t&&(a=o>i?o:s,c+=` `+e.slice(i,a),i=a+1),o=s;return c+=` `,e.length-i>t&&o>i?c+=e.slice(i,o)+` `+e.slice(o+1):c+=e.slice(i),c.slice(1)}function k(e){let t=``,n=0;for(let r=0;r=65536?r+=2:r++){n=C(e,r);let i=s[n];!i&&v(n)?(t+=e[r],n>=65536&&(t+=e[r+1])):t+=i||f(n)}return t}function A(e,t,n){let r=``,i=e.tag;for(let i=0,a=n.length;i1024&&(o+=`? `),o+=e.dump+(e.condenseFlow?`"`:``)+`:`+(e.condenseFlow?``:` `),P(e,t,c,!1,!1)&&(o+=e.dump,r+=o))}e.tag=i,e.dump=`{`+r+`}`}function M(e,n,r,i){let a=``,o=e.tag,s=Object.keys(r);if(e.sortKeys===!0)s.sort();else if(typeof e.sortKeys==`function`)s.sort(e.sortKeys);else if(e.sortKeys)throw new t(`sortKeys must be a boolean or a function`);for(let t=0,o=s.length;t1024;u&&(e.dump&&e.dump.charCodeAt(0)===10?o+=`?`:o+=`? `),o+=e.dump,u&&(o+=h(e,n)),P(e,n+1,l,!0,u)&&(e.dump&&e.dump.charCodeAt(0)===10?o+=`:`:o+=`: `,o+=e.dump,a+=o)}e.tag=o,e.dump=a||`{}`}function N(e,n,a){let o=a?e.explicitTypes:e.implicitTypes;for(let s=0,c=o.length;s tag resolver accepts not "`+a+`" style`);e.dump=o}return!0}}return!1}function P(e,n,i,a,o,s,c){e.tag=null,e.dump=i,N(e,i,!1)||N(e,i,!0);let l=r.call(e.dump),u=a;a&&=e.flowLevel<0||e.flowLevel>n;let d=l===`[object Object]`||l===`[object Array]`,f,p;if(d&&(f=e.duplicates.indexOf(i),p=f!==-1),(e.tag!==null&&e.tag!==`?`||p||e.indent!==2&&n>0)&&(o=!1),p&&e.usedDuplicates[f])e.dump=`*ref_`+f;else{if(d&&p&&!e.usedDuplicates[f]&&(e.usedDuplicates[f]=!0),l===`[object Object]`)a&&Object.keys(e.dump).length!==0?(M(e,n,e.dump,o),p&&(e.dump=`&ref_`+f+e.dump)):(j(e,n,e.dump),p&&(e.dump=`&ref_`+f+` `+e.dump));else if(l===`[object Array]`)a&&e.dump.length!==0?(e.noArrayIndent&&!c&&n>0?ne(e,n-1,e.dump,o):ne(e,n,e.dump,o),p&&(e.dump=`&ref_`+f+e.dump)):(A(e,n,e.dump),p&&(e.dump=`&ref_`+f+` `+e.dump));else if(l===`[object String]`)e.tag!==`?`&&T(e,e.dump,n,s,u);else if(l===`[object Undefined]`)return!1;else{if(e.skipInvalid)return!1;throw new t(`unacceptable kind of an object to dump `+l)}if(e.tag!==null&&e.tag!==`?`){let t=encodeURI(e.tag[0]===`!`?e.tag.slice(1):e.tag).replace(/!/g,`%21`);t=e.tag[0]===`!`?`!`+t:t.slice(0,18)===`tag:yaml.org,2002:`?`!!`+t.slice(18):`!<`+t+`>`,e.dump=t+` `+e.dump}}return!0}function re(e,t){let n=[],r=[];ie(e,n,r);let i=r.length;for(let e=0;e4)throw B(`Component "`+t+`" legs must be an integer from 1 to 4 (got `+String(e)+`).`);return n}function pt(e,t){if(e==null||e===``)return`ac`;let n=String(e).toLowerCase();if(n!==`ac`&&n!==`dc`)throw B(`Component "`+t+`" kind must be "ac" or "dc" (got `+String(e)+`).`);return n}function mt(e){let t={};for(let n=0;n or closed: [] (use closed: [] for all open/default).`);if(!Array.isArray(e.energize))throw B(i+` needs energize: an array of load ids (e.g. [front] or []).`);let o=e.energize.map(function(e,t){let n=String(e);if(r&&!r[n]){let e=Object.keys(r).join(`, `)||`(none)`;throw B(i+`.energize[`+t+`] references unknown load "`+n+`". simulation.loads ids: `+e+`.`)}return n}),s={closed:a,energize:o};return e.switch==null?a.length===1&&(s.switch=a[0]):s.switch=String(e.switch),s}function St(e,t,n){if(e==null)return null;if(typeof e!=`object`||Array.isArray(e))throw B(`grading must be an object with required, continuity, polarity, and/or whenClosed.`);let r=(Array.isArray(e.required)?e.required:[]).map(function(e,n){let r=String(e);return st(r,t,`grading.required[`+n+`]`),r}),i=Array.isArray(e.continuity)?e.continuity.map(function(e,n){return yt(e,n,t)}):[],a=Array.isArray(e.polarity)?e.polarity.map(function(e,r){return bt(e,r,t,n)}):[],o=Array.isArray(e.whenClosed)?e.whenClosed.map(function(e,r){return xt(e,r,t,n)}):[];if((o.length>0||a.length>0)&&!n)throw B(`grading.whenClosed and grading.polarity require a simulation block with loads.`);return{required:r,continuity:i,polarity:a,whenClosed:o}}function Ct(e){let t=typeof e.margin==`number`?e.margin:40,n=(Array.isArray(e.components)?e.components:[]).map(dt),r=mt(n),i=e.demo&&typeof e.demo==`object`?e.demo:{},a=e.hints&&typeof e.hints==`object`?e.hints:{},o=Array.isArray(i.wires)?i.wires.map(function(e,t){return ut(e,t,r)}):[],s=vt(e.simulation,r),c=null;if(s){c={};for(let e=0;e element.`);return Ct(it(t,`yaml`))}var Et=Math.PI/180;function Dt(){return typeof window<`u`&&({}.toString.call(window)===`[object Window]`||{}.toString.call(window)===`[object global]`)}var Ot=typeof global<`u`?global:typeof window<`u`?window:typeof WorkerGlobalScope<`u`?self:{},V={_global:Ot,version:`10.3.0`,isBrowser:Dt(),isUnminified:/param/.test(function(e){}.toString()),dblClickWindow:400,getAngle(e){return V.angleDeg?e*Et:e},enableTrace:!1,pointerEventsEnabled:!0,autoDrawEnabled:!0,hitOnDragEnabled:!1,capturePointerEventsEnabled:!1,_mouseListenClick:!1,_touchListenClick:!1,_pointerListenClick:!1,_mouseInDblClickWindow:!1,_touchInDblClickWindow:!1,_pointerInDblClickWindow:!1,_mouseDblClickPointerId:null,_touchDblClickPointerId:null,_pointerDblClickPointerId:null,_renderBackend:`web`,legacyTextRendering:!1,pixelRatio:typeof window<`u`&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging(){return V.DD.isDragging},isTransforming(){return V.Transformer?.isTransforming()??!1},isDragReady(){return!!V.DD.node},releaseCanvasOnDestroy:!0,document:Ot.document,_injectGlobal(e){Ot.Konva!==void 0&&console.error(`Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment.`),Ot.Konva=e}},H=e=>{V[e.prototype.getClassName()]=e};V._injectGlobal(V);var kt=`Konva.js unsupported environment. Looks like you are trying to use Konva.js in Node.js environment. because "document" object is undefined. To use Konva.js in Node.js environment, you need to use the "canvas-backend" or "skia-backend" module. bash: npm install canvas js: import "konva/canvas-backend"; or bash: npm install skia-canvas js: import "konva/skia-backend"; `,At=()=>{if(typeof document>`u`)throw Error(kt)},jt=class e{constructor(e=[1,0,0,1,0,0]){this.dirty=!1,this.m=e&&e.slice()||[1,0,0,1,0,0]}reset(){this.m[0]=1,this.m[1]=0,this.m[2]=0,this.m[3]=1,this.m[4]=0,this.m[5]=0}copy(){return new e(this.m)}copyInto(e){e.m[0]=this.m[0],e.m[1]=this.m[1],e.m[2]=this.m[2],e.m[3]=this.m[3],e.m[4]=this.m[4],e.m[5]=this.m[5]}point(e){let t=this.m;return{x:t[0]*e.x+t[2]*e.y+t[4],y:t[1]*e.x+t[3]*e.y+t[5]}}translate(e,t){return this.m[4]+=this.m[0]*e+this.m[2]*t,this.m[5]+=this.m[1]*e+this.m[3]*t,this}scale(e,t){return this.m[0]*=e,this.m[1]*=e,this.m[2]*=t,this.m[3]*=t,this}rotate(e){let t=Math.cos(e),n=Math.sin(e),r=this.m[0]*t+this.m[2]*n,i=this.m[1]*t+this.m[3]*n,a=this.m[0]*-n+this.m[2]*t,o=this.m[1]*-n+this.m[3]*t;return this.m[0]=r,this.m[1]=i,this.m[2]=a,this.m[3]=o,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(e,t){let n=this.m[0]+this.m[2]*t,r=this.m[1]+this.m[3]*t,i=this.m[2]+this.m[0]*e,a=this.m[3]+this.m[1]*e;return this.m[0]=n,this.m[1]=r,this.m[2]=i,this.m[3]=a,this}multiply(e){let t=this.m[0]*e.m[0]+this.m[2]*e.m[1],n=this.m[1]*e.m[0]+this.m[3]*e.m[1],r=this.m[0]*e.m[2]+this.m[2]*e.m[3],i=this.m[1]*e.m[2]+this.m[3]*e.m[3],a=this.m[0]*e.m[4]+this.m[2]*e.m[5]+this.m[4],o=this.m[1]*e.m[4]+this.m[3]*e.m[5]+this.m[5];return this.m[0]=t,this.m[1]=n,this.m[2]=r,this.m[3]=i,this.m[4]=a,this.m[5]=o,this}invert(){let e=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),t=this.m[3]*e,n=-this.m[1]*e,r=-this.m[2]*e,i=this.m[0]*e,a=e*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),o=e*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=t,this.m[1]=n,this.m[2]=r,this.m[3]=i,this.m[4]=a,this.m[5]=o,this}getMatrix(){return this.m}decompose(){let e=this.m[0],t=this.m[1],n=this.m[2],r=this.m[3],i=this.m[4],a=this.m[5],o=e*r-t*n,s={x:i,y:a,rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(e!=0||t!=0){let i=Math.sqrt(e*e+t*t);s.rotation=t>0?Math.acos(e/i):-Math.acos(e/i),s.scaleX=i,s.scaleY=o/i,s.skewX=(e*n+t*r)/o,s.skewY=0}else if(n!=0||r!=0){let i=Math.sqrt(n*n+r*r);s.rotation=Math.PI/2-(r>0?Math.acos(-n/i):-Math.acos(n/i)),s.scaleX=o/i,s.scaleY=i,s.skewX=0,s.skewY=(e*n+t*r)/o}return s.rotation=U._getRotation(s.rotation),s}},Mt=`[object Array]`,Nt=`[object Number]`,Pt=`[object String]`,Ft=`[object Boolean]`,It=Math.PI/180,Lt=180/Math.PI,Rt=`#`,zt=``,Bt=`0`,Vt=`Konva warning: `,Ht=`Konva error: `,Ut=`rgb(`,Wt={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,132,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,255,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,203],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[119,128,144],slategrey:[119,128,144],snow:[255,255,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],transparent:[255,255,255,0],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,5]},Gt=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,Kt=[],qt=null,Jt=typeof requestAnimationFrame<`u`&&requestAnimationFrame||function(e){setTimeout(e,16)},U={_isElement(e){return!!(e&&e.nodeType==1)},_isFunction(e){return!!(e&&e.constructor&&e.call&&e.apply)},_isPlainObject(e){return!!e&&e.constructor===Object},_isArray(e){return Object.prototype.toString.call(e)===Mt},_isNumber(e){return Object.prototype.toString.call(e)===Nt&&!isNaN(e)&&isFinite(e)},_isString(e){return Object.prototype.toString.call(e)===Pt},_isBoolean(e){return Object.prototype.toString.call(e)===Ft},isObject(e){return e instanceof Object},isValidSelector(e){if(typeof e!=`string`)return!1;let t=e[0];return t===`#`||t===`.`||t===t.toUpperCase()},_sign(e){return e===0||e>0?1:-1},requestAnimFrame(e){Kt.push(e),Kt.length===1&&Jt(function(){let e=Kt;Kt=[],e.forEach(function(e){e()})})},createCanvasElement(){At();let e=document.createElement(`canvas`);try{e.style=e.style||{}}catch{}return e},createImageElement(){return At(),document.createElement(`img`)},_isInDocument(e){for(;e=e.parentNode;)if(e==document)return!0;return!1},_urlToImage(e,t){let n=U.createImageElement();n.onload=function(){t(n)},n.src=e},_rgbToHex(e,t,n){return((1<<24)+(e<<16)+(t<<8)+n).toString(16).slice(1)},_hexToRgb(e){e=e.replace(Rt,zt);let t=parseInt(e,16);return{r:t>>16&255,g:t>>8&255,b:t&255}},getRandomColor(){let e=(Math.random()*16777215<<0).toString(16);for(;e.length<6;)e=Bt+e;return Rt+e},isCanvasFarblingActive(){if(qt!==null)return qt;if(typeof document>`u`)return qt=!1,!1;let e=this.createCanvasElement();e.width=10,e.height=10;let t=e.getContext(`2d`,{willReadFrequently:!0});t.clearRect(0,0,10,10),t.fillStyle=`#282828`,t.fillRect(0,0,10,10);let n=t.getImageData(0,0,10,10).data,r=!1;for(let e=0;e<100;e++)if(n[e*4]!==40||n[e*4+1]!==40||n[e*4+2]!==40||n[e*4+3]!==255){r=!0;break}return qt=r,this.releaseCanvas(e),qt},getHitColor(){let e=this.getRandomColor();return this.isCanvasFarblingActive()?this.getSnappedHexColor(e):e},getHitColorKey(e,t,n){return this.isCanvasFarblingActive()&&(e=Math.round(e/5)*5,t=Math.round(t/5)*5,n=Math.round(n/5)*5),Rt+this._rgbToHex(e,t,n)},getSnappedHexColor(e){let t=this._hexToRgb(e);return Rt+this._rgbToHex(Math.round(t.r/5)*5,Math.round(t.g/5)*5,Math.round(t.b/5)*5)},getRGB(e){let t;return e in Wt?(t=Wt[e],{r:t[0],g:t[1],b:t[2]}):e[0]===Rt?this._hexToRgb(e.substring(1)):e.substr(0,4)===Ut?(t=Gt.exec(e.replace(/ /g,``)),{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10)}):{r:0,g:0,b:0}},colorToRGBA(e){return e||=`black`,U._namedColorToRBA(e)||U._hex3ColorToRGBA(e)||U._hex4ColorToRGBA(e)||U._hex6ColorToRGBA(e)||U._hex8ColorToRGBA(e)||U._rgbColorToRGBA(e)||U._rgbaColorToRGBA(e)||U._hslColorToRGBA(e)},_namedColorToRBA(e){let t=Wt[e.toLowerCase()];return t?{r:t[0],g:t[1],b:t[2],a:1}:null},_rgbColorToRGBA(e){if(e.indexOf(`rgb(`)===0){e=e.match(/rgb\(([^)]+)\)/)[1];let t=e.split(/ *, */).map(Number);return{r:t[0],g:t[1],b:t[2],a:1}}},_rgbaColorToRGBA(e){if(e.indexOf(`rgba(`)===0){e=e.match(/rgba\(([^)]+)\)/)[1];let t=e.split(/ *, */).map((e,t)=>e.slice(-1)===`%`?t===3?parseInt(e)/100:parseInt(e)/100*255:Number(e));return{r:t[0],g:t[1],b:t[2],a:t[3]}}},_hex8ColorToRGBA(e){if(e[0]===`#`&&e.length===9)return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16),a:parseInt(e.slice(7,9),16)/255}},_hex6ColorToRGBA(e){if(e[0]===`#`&&e.length===7)return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16),a:1}},_hex4ColorToRGBA(e){if(e[0]===`#`&&e.length===5)return{r:parseInt(e[1]+e[1],16),g:parseInt(e[2]+e[2],16),b:parseInt(e[3]+e[3],16),a:parseInt(e[4]+e[4],16)/255}},_hex3ColorToRGBA(e){if(e[0]===`#`&&e.length===4)return{r:parseInt(e[1]+e[1],16),g:parseInt(e[2]+e[2],16),b:parseInt(e[3]+e[3],16),a:1}},_hslColorToRGBA(e){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(e)){let[t,...n]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(e),r=Number(n[0])/360,i=Number(n[1])/100,a=Number(n[2])/100,o,s,c;if(i===0)return c=a*255,{r:Math.round(c),g:Math.round(c),b:Math.round(c),a:1};o=a<.5?a*(1+i):a+i-a*i;let l=2*a-o,u=[0,0,0];for(let e=0;e<3;e++)s=r+1/3*-(e-1),s<0&&s++,s>1&&s--,c=6*s<1?l+(o-l)*6*s:2*s<1?o:3*s<2?l+(o-l)*(2/3-s)*6:l,u[e]=c*255;return{r:Math.round(u[0]),g:Math.round(u[1]),b:Math.round(u[2]),a:1}}},haveIntersection(e,t){return!(t.x>e.x+e.width||t.x+t.widthe.y+e.height||t.y+t.height1?(o=n,s=r,c=(n-i)*(n-i)+(r-a)*(r-a)):(o=e+u*(n-e),s=t+u*(r-t),c=(o-i)*(o-i)+(s-a)*(s-a))}return[o,s,c]},_getProjectionToLine(e,t,n){let r=U.cloneObject(e),i=Number.MAX_VALUE;return t.forEach(function(a,o){if(!n&&o===t.length-1)return;let s=t[(o+1)%t.length],c=U._getProjectionToSegment(a.x,a.y,s.x,s.y,e.x,e.y),l=c[0],u=c[1],d=c[2];dt.length){let n=t;t=e,e=n}for(let t=0;t{e.width=0,e.height=0})},drawRoundedRectPath(e,t,n,r){let i=t<0?t:0,a=n<0?n:0;t=Math.abs(t),n=Math.abs(n);let o=0,s=0,c=0,l=0;typeof r==`number`?o=s=c=l=Math.min(r,t/2,n/2):(o=Math.min(r[0]||0,t/2,n/2),s=Math.min(r[1]||0,t/2,n/2),l=Math.min(r[2]||0,t/2,n/2),c=Math.min(r[3]||0,t/2,n/2)),e.moveTo(i+o,a),e.lineTo(i+t-s,a),e.arc(i+t-s,a+s,s,Math.PI*3/2,0,!1),e.lineTo(i+t,a+n-l),e.arc(i+t-l,a+n-l,l,0,Math.PI/2,!1),e.lineTo(i+c,a+n),e.arc(i+c,a+n-c,c,Math.PI/2,Math.PI,!1),e.lineTo(i,a+o),e.arc(i+o,a+o,o,Math.PI,Math.PI*3/2,!1)},drawRoundedPolygonPath(e,t,n,r,i){r=Math.abs(r);for(let a=0;atypeof e==`number`?Math.floor(e):e)),i+=Zt+c.join(Xt)+Qt)):(i+=o.property,e||(i+=rn+o.val)),i+=tn;return i}clearTrace(){this.traceArr=[]}_trace(e){let t=this.traceArr,n;t.push(e),n=t.length,n>=sn&&t.shift()}reset(){let e=this.getCanvas().getPixelRatio();this.setTransform(1*e,0,0,1*e,0,0)}getCanvas(){return this.canvas}clear(e){let t=this.getCanvas();e?this.clearRect(e.x||0,e.y||0,e.width||0,e.height||0):this.clearRect(0,0,t.getWidth()/t.pixelRatio,t.getHeight()/t.pixelRatio)}_applyLineCap(e){let t=e.attrs.lineCap;t&&this.setAttr(`lineCap`,t)}_applyOpacity(e){let t=e.getAbsoluteOpacity();t!==1&&this.setAttr(`globalAlpha`,t)}_applyLineJoin(e){let t=e.attrs.lineJoin;t&&this.setAttr(`lineJoin`,t)}_applyMiterLimit(e){let t=e.attrs.miterLimit;t!=null&&this.setAttr(`miterLimit`,t)}setAttr(e,t){this._context[e]=t}arc(e,t,n,r,i,a){this._context.arc(e,t,n,r,i,a)}arcTo(e,t,n,r,i){this._context.arcTo(e,t,n,r,i)}beginPath(){this._context.beginPath()}bezierCurveTo(e,t,n,r,i,a){this._context.bezierCurveTo(e,t,n,r,i,a)}clearRect(e,t,n,r){this._context.clearRect(e,t,n,r)}clip(...e){this._context.clip.apply(this._context,e)}closePath(){this._context.closePath()}createImageData(e,t){let n=arguments;if(n.length===2)return this._context.createImageData(e,t);if(n.length===1)return this._context.createImageData(e)}createLinearGradient(e,t,n,r){return this._context.createLinearGradient(e,t,n,r)}createPattern(e,t){return this._context.createPattern(e,t)}createRadialGradient(e,t,n,r,i,a){return this._context.createRadialGradient(e,t,n,r,i,a)}drawImage(e,t,n,r,i,a,o,s,c){let l=arguments,u=this._context;l.length===3?u.drawImage(e,t,n):l.length===5?u.drawImage(e,t,n,r,i):l.length===9&&u.drawImage(e,t,n,r,i,a,o,s,c)}ellipse(e,t,n,r,i,a,o,s){this._context.ellipse(e,t,n,r,i,a,o,s)}isPointInPath(e,t,n,r){return n?this._context.isPointInPath(n,e,t,r):this._context.isPointInPath(e,t,r)}fill(...e){this._context.fill.apply(this._context,e)}fillRect(e,t,n,r){this._context.fillRect(e,t,n,r)}strokeRect(e,t,n,r){this._context.strokeRect(e,t,n,r)}fillText(e,t,n,r){r?this._context.fillText(e,t,n,r):this._context.fillText(e,t,n)}measureText(e){return this._context.measureText(e)}getImageData(e,t,n,r){return this._context.getImageData(e,t,n,r)}lineTo(e,t){this._context.lineTo(e,t)}moveTo(e,t){this._context.moveTo(e,t)}rect(e,t,n,r){this._context.rect(e,t,n,r)}roundRect(e,t,n,r,i){this._context.roundRect(e,t,n,r,i)}putImageData(e,t,n){this._context.putImageData(e,t,n)}quadraticCurveTo(e,t,n,r){this._context.quadraticCurveTo(e,t,n,r)}restore(){this._context.restore()}rotate(e){this._context.rotate(e)}save(){this._context.save()}scale(e,t){this._context.scale(e,t)}setLineDash(e){this._context.setLineDash?this._context.setLineDash(e):`mozDash`in this._context?this._context.mozDash=e:`webkitLineDash`in this._context&&(this._context.webkitLineDash=e)}getLineDash(){return this._context.getLineDash()}setTransform(e,t,n,r,i,a){this._context.setTransform(e,t,n,r,i,a)}stroke(e){e?this._context.stroke(e):this._context.stroke()}strokeText(e,t,n,r){this._context.strokeText(e,t,n,r)}transform(e,t,n,r,i,a){this._context.transform(e,t,n,r,i,a)}translate(e,t){this._context.translate(e,t)}_enableTrace(){let e=this,t=an.length,n=this.setAttr,r,i,a=function(t){let n=e[t],r;e[t]=function(){return i=Yt(Array.prototype.slice.call(arguments,0)),r=n.apply(e,arguments),e._trace({method:t,args:i}),r}};for(r=0;r{t.dragStatus===`dragging`&&(e=!0)}),e},justDragged:!1,get node(){let e;return W._dragElements.forEach(t=>{e=t.node}),e},_dragElements:new Map,_drag(e){let t=[];W._dragElements.forEach((n,r)=>{let{node:i}=n,a=i.getStage();a.setPointersPositions(e),n.pointerId===void 0&&(n.pointerId=U._getFirstPointerId(e));let o=a._changedPointerPositions.find(e=>e.id===n.pointerId);if(o){if(n.dragStatus!==`dragging`){let t=i.dragDistance();if(Math.max(Math.abs(o.x-n.startPointerPos.x),Math.abs(o.y-n.startPointerPos.y)){t.getStage()&&t.fire(`dragmove`,{type:`dragmove`,target:t,evt:e},!0)})},_endDragBefore(e){let t=[];W._dragElements.forEach(n=>{let{node:r}=n,i=r.getStage();if(e&&i.setPointersPositions(e),!i._changedPointerPositions.find(e=>e.id===n.pointerId))return;(n.dragStatus===`dragging`||n.dragStatus===`stopped`)&&(W.justDragged=!0,V._mouseListenClick=!1,V._touchListenClick=!1,V._pointerListenClick=!1,n.dragStatus=`stopped`);let a=n.node.getLayer()||n.node instanceof V.Stage&&n.node;a&&t.indexOf(a)===-1&&t.push(a)}),t.forEach(e=>{e.draw()})},_endDragAfter(e){W._dragElements.forEach((t,n)=>{t.dragStatus===`stopped`&&t.node.fire(`dragend`,{type:`dragend`,target:t.node,evt:e},!0),t.dragStatus!==`dragging`&&W._dragElements.delete(n)})}};V.isBrowser&&(window.addEventListener(`mouseup`,W._endDragBefore,!0),window.addEventListener(`touchend`,W._endDragBefore,!0),window.addEventListener(`touchcancel`,W._endDragBefore,!0),window.addEventListener(`mousemove`,W._drag),window.addEventListener(`touchmove`,W._drag),window.addEventListener(`mouseup`,W._endDragAfter,!1),window.addEventListener(`touchend`,W._endDragAfter,!1),window.addEventListener(`touchcancel`,W._endDragAfter,!1));function vn(e){return U._isString(e)?`"`+e+`"`:Object.prototype.toString.call(e)===`[object Number]`||U._isBoolean(e)?e:Object.prototype.toString.call(e)}function yn(e){return e>255?255:e<0?0:Math.round(e)}function G(){if(V.isUnminified)return function(e,t){return U._isNumber(e)||U.warn(vn(e)+` is a not valid value for "`+t+`" attribute. The value should be a number.`),e}}function bn(e){if(V.isUnminified)return function(t,n){let r=U._isNumber(t),i=U._isArray(t)&&t.length==e;return!r&&!i&&U.warn(vn(t)+` is a not valid value for "`+n+`" attribute. The value should be a number or Array(`+e+`)`),t}}function xn(){if(V.isUnminified)return function(e,t){return U._isNumber(e)||e===`auto`||U.warn(vn(e)+` is a not valid value for "`+t+`" attribute. The value should be a number or "auto".`),e}}function Sn(){if(V.isUnminified)return function(e,t){return U._isString(e)||U.warn(vn(e)+` is a not valid value for "`+t+`" attribute. The value should be a string.`),e}}function Cn(){if(V.isUnminified)return function(e,t){let n=U._isString(e),r=Object.prototype.toString.call(e)===`[object CanvasGradient]`||e&&e.addColorStop;return n||r||U.warn(vn(e)+` is a not valid value for "`+t+`" attribute. The value should be a string or a native gradient.`),e}}function wn(){if(V.isUnminified)return function(e,t){let n=Int8Array?Object.getPrototypeOf(Int8Array):null;return n&&e instanceof n||(U._isArray(e)?e.forEach(function(e){U._isNumber(e)||U.warn(`"`+t+`" attribute has non numeric element `+e+`. Make sure that all elements are numbers.`)}):U.warn(vn(e)+` is a not valid value for "`+t+`" attribute. The value should be a array of numbers.`)),e}}function Tn(){if(V.isUnminified)return function(e,t){return e===!0||e===!1||U.warn(vn(e)+` is a not valid value for "`+t+`" attribute. The value should be a boolean.`),e}}function En(e){if(V.isUnminified)return function(t,n){return t==null||U.isObject(t)||U.warn(vn(t)+` is a not valid value for "`+n+`" attribute. The value should be an object with properties `+e),t}}var Dn=`get`,On=`set`,K={addGetterSetter(e,t,n,r,i){K.addGetter(e,t,n),K.addSetter(e,t,r,i),K.addOverloadedGetterSetter(e,t)},addGetter(e,t,n){let r=Dn+U._capitalize(t);e.prototype[r]=e.prototype[r]||function(){let e=this.attrs[t];return e===void 0?n:e}},addSetter(e,t,n,r){let i=On+U._capitalize(t);e.prototype[i]||K.overWriteSetter(e,t,n,r)},overWriteSetter(e,t,n,r){let i=On+U._capitalize(t);e.prototype[i]=function(e){return n&&e!=null&&(e=n.call(this,e,t)),this._setAttr(t,e),r&&r.call(this),this}},addComponentsGetterSetter(e,t,n,r,i){let a=n.length,o=U._capitalize,s=Dn+o(t),c=On+o(t);e.prototype[s]=function(){let e={};for(let r=0;r{this._setAttr(t+o(e),void 0)}),this._fireChangeEvent(t,a,e),i&&i.call(this),this},K.addOverloadedGetterSetter(e,t)},addOverloadedGetterSetter(e,t){let n=U._capitalize(t),r=On+n,i=Dn+n;e.prototype[t]=function(){return arguments.length?(this[r](arguments[0]),this):this[i]()}},addDeprecatedGetterSetter(e,t,n,r){U.error(`Adding deprecated `+t);let i=Dn+U._capitalize(t),a=t+` property is deprecated and will be removed soon. Look at Konva change log for more information.`;e.prototype[i]=function(){U.error(a);let e=this.attrs[t];return e===void 0?n:e},K.addSetter(e,t,r,function(){U.error(a)}),K.addOverloadedGetterSetter(e,t)},backCompat(e,t){U.each(t,function(t,n){let r=e.prototype[n],i=Dn+U._capitalize(t),a=On+U._capitalize(t);function o(){r.apply(this,arguments),U.error(`"`+t+`" method is deprecated and will be removed soon. Use ""`+n+`" instead.`)}e.prototype[t]=o,e.prototype[i]=o,e.prototype[a]=o})},afterSetFilter(){this._filterUpToDate=!1}};function kn(e){let t=/(\w+)\(([^)]+)\)/g,n;for(;(n=t.exec(e))!==null;){let[,e,t]=n;switch(e){case`blur`:{let e=parseFloat(t.replace(`px`,``));return function(t){this.blurRadius(e*.5);let n=V.Filters;n&&n.Blur&&n.Blur.call(this,t)}}case`brightness`:{let e=t.includes(`%`)?parseFloat(t)/100:parseFloat(t);return function(t){this.brightness(e);let n=V.Filters;n&&n.Brightness&&n.Brightness.call(this,t)}}case`contrast`:{let e=parseFloat(t);return function(t){let n=100*(Math.sqrt(e)-1);this.contrast(n);let r=V.Filters;r&&r.Contrast&&r.Contrast.call(this,t)}}case`grayscale`:return function(e){let t=V.Filters;t&&t.Grayscale&&t.Grayscale.call(this,e)};case`sepia`:return function(e){let t=V.Filters;t&&t.Sepia&&t.Sepia.call(this,e)};case`invert`:return function(e){let t=V.Filters;t&&t.Invert&&t.Invert.call(this,e)};default:U.warn(`CSS filter "${e}" is not supported in fallback mode. Consider using function filters for better compatibility.`);break}}return()=>{}}var An=`absoluteOpacity`,jn=`allEventListeners`,Mn=`absoluteTransform`,Nn=`absoluteScale`,Pn=`canvas`,Fn=`Change`,In=`children`,Ln=`konva`,Rn=`listening`,zn=`mouseenter`,Bn=`mouseleave`,Vn=`pointerenter`,Hn=`pointerleave`,Un=`touchenter`,Wn=`touchleave`,Gn=`set`,Kn=`Shape`,qn=` `,Jn=`stage`,Yn=`transform`,Xn=`Stage`,Zn=`visible`,Qn=[`xChange.konva`,`yChange.konva`,`scaleXChange.konva`,`scaleYChange.konva`,`skewXChange.konva`,`skewYChange.konva`,`rotationChange.konva`,`offsetXChange.konva`,`offsetYChange.konva`,`transformsEnabledChange.konva`].join(qn),$n=1,q=class e{constructor(e){this._id=$n++,this.eventListeners={},this.attrs={},this.index=0,this._allEventListeners=null,this.parent=null,this._cache=new Map,this._attachedDepsListeners=new Map,this._lastPos=null,this._batchingTransformChange=!1,this._needClearTransformCache=!1,this._filterUpToDate=!1,this._isUnderCache=!1,this._dragEventId=null,this._shouldFireChangeEvents=!1,this.setAttrs(e),this._shouldFireChangeEvents=!0}hasChildren(){return!1}_clearCache(e){(e===Yn||e===Mn)&&this._cache.get(e)?this._cache.get(e).dirty=!0:e?this._cache.delete(e):this._cache.clear()}_getCache(e,t){let n=this._cache.get(e);return(n===void 0||(e===Yn||e===Mn)&&n.dirty===!0)&&(n=t.call(this),this._cache.set(e,n)),n}_calculate(e,t,n){if(!this._attachedDepsListeners.get(e)){let n=t.map(e=>e+`Change.konva`).join(qn);this.on(n,()=>{this._clearCache(e)}),this._attachedDepsListeners.set(e,!0)}return this._getCache(e,n)}_getCanvasCache(){return this._cache.get(Pn)}_clearSelfAndDescendantCache(e){this._clearCache(e),e===Mn&&this.fire(`absoluteTransformChange`)}clearCache(){if(this._cache.has(Pn)){let{scene:e,filter:t,hit:n}=this._cache.get(Pn);U.releaseCanvas(e._canvas,t._canvas,n._canvas),this._cache.delete(Pn)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(e){let t=e||{},n={};(t.x===void 0||t.y===void 0||t.width===void 0||t.height===void 0)&&(n=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let r=Math.ceil(t.width||n.width),i=Math.ceil(t.height||n.height),a=t.pixelRatio,o=t.x===void 0?Math.floor(n.x):t.x,s=t.y===void 0?Math.floor(n.y):t.y,c=t.offset||0,l=t.drawBorder||!1,u=t.hitCanvasPixelRatio||1;if(!r||!i){U.error(`Can not cache the node. Width or height of the node equals 0. Caching is skipped.`);return}let d=+(Math.abs(Math.round(n.x)-o)>.5),f=+(Math.abs(Math.round(n.y)-s)>.5);r+=c*2+d,i+=c*2+f,o-=c,s-=c;let p=new gn({pixelRatio:a,width:r,height:i}),m=new gn({pixelRatio:a,width:0,height:0,willReadFrequently:!0}),h=new _n({pixelRatio:u,width:r,height:i}),g=p.getContext(),_=h.getContext(),v=new gn({width:p.width/p.pixelRatio+Math.abs(o),height:p.height/p.pixelRatio+Math.abs(s),pixelRatio:p.pixelRatio}),y=v.getContext();return h.isCache=!0,p.isCache=!0,this._cache.delete(Pn),this._filterUpToDate=!1,t.imageSmoothingEnabled===!1&&(p.getContext()._context.imageSmoothingEnabled=!1,m.getContext()._context.imageSmoothingEnabled=!1),g.save(),_.save(),y.save(),g.translate(-o,-s),_.translate(-o,-s),y.translate(-o,-s),v.x=o,v.y=s,this._isUnderCache=!0,this._clearSelfAndDescendantCache(An),this._clearSelfAndDescendantCache(Nn),this.drawScene(p,this,v),this.drawHit(h,this),this._isUnderCache=!1,g.restore(),_.restore(),l&&(g.save(),g.beginPath(),g.rect(0,0,r,i),g.closePath(),g.setAttr(`strokeStyle`,`red`),g.setAttr(`lineWidth`,5),g.stroke(),g.restore()),U.releaseCanvas(v._canvas),this._cache.set(Pn,{scene:p,filter:m,hit:h,x:o,y:s}),this._requestDraw(),this}isCached(){return this._cache.has(Pn)}getClientRect(e){throw Error(`abstract "getClientRect" method call`)}_transformedRect(e,t){let n=[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y},{x:e.x+e.width,y:e.y+e.height},{x:e.x,y:e.y+e.height}],r=1/0,i=1/0,a=-1/0,o=-1/0,s=this.getAbsoluteTransform(t);return n.forEach(function(e){let t=s.point(e);r===void 0&&(r=a=t.x,i=o=t.y),r=Math.min(r,t.x),i=Math.min(i,t.y),a=Math.max(a,t.x),o=Math.max(o,t.y)}),{x:r,y:i,width:a-r,height:o-i}}_drawCachedSceneCanvas(e){e.save(),e._applyOpacity(this),e._applyGlobalCompositeOperation(this);let t=this._getCanvasCache();e.translate(t.x,t.y);let n=this._getCachedSceneCanvas(),r=n.pixelRatio;e.drawImage(n._canvas,0,0,n.width/r,n.height/r),e.restore()}_drawCachedHitCanvas(e){let t=this._getCanvasCache(),n=t.hit;e.save(),e.translate(t.x,t.y),e.drawImage(n._canvas,0,0,n.width/n.pixelRatio,n.height/n.pixelRatio),e.restore()}_getCachedSceneCanvas(){let e=this.filters(),t=this._getCanvasCache(),n=t.scene,r=t.filter,i=r.getContext(),a,o,s,c;if(!e||e.length===0)return n;if(this._filterUpToDate)return r;let l=!0;for(let t=0;t{this.isAncestorOf(e.node)&&W._dragElements.delete(t)}),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(Mn),this._clearSelfAndDescendantCache(An),this._clearSelfAndDescendantCache(Nn),this._clearSelfAndDescendantCache(Jn),this._clearSelfAndDescendantCache(Zn),this._clearSelfAndDescendantCache(Rn)}_remove(){this._clearCaches();let e=this.getParent();e&&e.children&&(e.children.splice(this.index,1),e._setChildrenIndices(),this.parent=null)}destroy(){return this.remove(),this.clearCache(),this}getAttr(e){let t=`get`+U._capitalize(e);return U._isFunction(this[t])?this[t]():this.attrs[e]}getAncestors(){let e=this.getParent(),t=[];for(;e;)t.push(e),e=e.getParent();return t}getAttrs(){return this.attrs||{}}setAttrs(e){return this._batchTransformChanges(()=>{let t,n;if(!e)return this;for(t in e)t!==In&&(n=Gn+U._capitalize(t),U._isFunction(this[n])?this[n](e[t]):this._setAttr(t,e[t]))}),this}isListening(){return this._getCache(Rn,this._isListening)}_isListening(e){if(!this.listening())return!1;let t=this.getParent();return t&&t!==e&&this!==e?t._isListening(e):!0}isVisible(){return this._getCache(Zn,this._isVisible)}_isVisible(e){if(!this.visible())return!1;let t=this.getParent();return t&&t!==e&&this!==e?t._isVisible(e):!0}shouldDrawHit(e,t=!1){if(e)return this._isVisible(e)&&this._isListening(e);let n=this.getLayer(),r=!1;W._dragElements.forEach(e=>{e.dragStatus===`dragging`&&(e.node.nodeType===`Stage`||e.node.getLayer()===n)&&(r=!0)});let i=!t&&!V.hitOnDragEnabled&&(r||V.isTransforming());return this.isListening()&&this.isVisible()&&!i}show(){return this.visible(!0),this}hide(){return this.visible(!1),this}getZIndex(){return this.index||0}getAbsoluteZIndex(){let e=this.getDepth(),t=this,n=0,r,i,a,o;function s(c){for(r=[],i=c.length,a=0;a0&&r[0].getDepth()<=e&&s(r)}let c=this.getStage();return t.nodeType!==Xn&&c&&s(c.getChildren()),n}getDepth(){let e=0,t=this.parent;for(;t;)e++,t=t.parent;return e}_batchTransformChanges(e){this._batchingTransformChange=!0,e(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(Yn),this._clearSelfAndDescendantCache(Mn)),this._needClearTransformCache=!1}setPosition(e){return this._batchTransformChanges(()=>{this.x(e.x),this.y(e.y)}),this}getPosition(){return{x:this.x(),y:this.y()}}getRelativePointerPosition(){let e=this.getStage();if(!e)return null;let t=e.getPointerPosition();if(!t)return null;let n=this.getAbsoluteTransform().copy();return n.invert(),n.point(t)}getAbsolutePosition(e){let t=!1,n=this.parent;for(;n;){if(n.isCached()){t=!0;break}n=n.parent}t&&!e&&(e=!0);let r=this.getAbsoluteTransform(e).getMatrix(),i=new jt,a=this.offset();return i.m=r.slice(),i.translate(a.x,a.y),i.getTranslation()}setAbsolutePosition(e){let{x:t,y:n,...r}=this._clearTransform();this.attrs.x=t,this.attrs.y=n,this._clearCache(Yn);let i=this._getAbsoluteTransform().copy();return i.invert(),i.translate(e.x,e.y),e={x:this.attrs.x+i.getTranslation().x,y:this.attrs.y+i.getTranslation().y},this._setTransform(r),this.setPosition({x:e.x,y:e.y}),this._clearCache(Yn),this._clearSelfAndDescendantCache(Mn),this}_setTransform(e){let t;for(t in e)this.attrs[t]=e[t]}_clearTransform(){let e={x:this.x(),y:this.y(),rotation:this.rotation(),scaleX:this.scaleX(),scaleY:this.scaleY(),offsetX:this.offsetX(),offsetY:this.offsetY(),skewX:this.skewX(),skewY:this.skewY()};return this.attrs.x=0,this.attrs.y=0,this.attrs.rotation=0,this.attrs.scaleX=1,this.attrs.scaleY=1,this.attrs.offsetX=0,this.attrs.offsetY=0,this.attrs.skewX=0,this.attrs.skewY=0,e}move(e){let t=e.x,n=e.y,r=this.x(),i=this.y();return t!==void 0&&(r+=t),n!==void 0&&(i+=n),this.setPosition({x:r,y:i}),this}_eachAncestorReverse(e,t){let n=[],r=this.getParent(),i,a;if(!(t&&t._id===this._id)){for(n.unshift(this);r&&(!t||r._id!==t._id);)n.unshift(r),r=r.parent;for(i=n.length,a=0;a0?(this.parent.children.splice(e,1),this.parent.children.splice(e-1,0,this),this.parent._setChildrenIndices(),!0):!1}moveToBottom(){if(!this.parent)return U.warn(`Node has no parent. moveToBottom function is ignored.`),!1;let e=this.index;return e>0?(this.parent.children.splice(e,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0):!1}setZIndex(e){if(!this.parent)return U.warn(`Node has no parent. zIndex parameter is ignored.`),this;(e<0||e>=this.parent.children.length)&&U.warn(`Unexpected value `+e+` for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to `+(this.parent.children.length-1)+`.`);let t=this.index;return this.parent.children.splice(t,1),this.parent.children.splice(e,0,this),this.parent._setChildrenIndices(),this}getAbsoluteOpacity(){return this._getCache(An,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){let e=this.opacity(),t=this.getParent();return t&&!t._isUnderCache&&(e*=t.getAbsoluteOpacity()),e}moveTo(e){return this.getParent()!==e&&(this._remove(),e.add(this)),this}toObject(){let e=this.getAttrs(),t,n,r,i,a,o={attrs:{},className:this.getClassName()};for(t in e)n=e[t],a=U.isObject(n)&&!U._isPlainObject(n)&&!U._isArray(n),!a&&(r=typeof this[t]==`function`&&this[t],delete e[t],i=r?r.call(this):null,e[t]=n,i!==n&&(o.attrs[t]=n));return U._prepareToStringify(o)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(e,t,n){let r=[];t&&this._isMatch(e)&&r.push(this);let i=this.parent;for(;i;){if(i===n)return r;i._isMatch(e)&&r.push(i),i=i.parent}return r}isAncestorOf(e){return!1}findAncestor(e,t,n){return this.findAncestors(e,t,n)[0]}_isMatch(e){if(!e)return!1;if(typeof e==`function`)return e(this);let t=e.replace(/ /g,``).split(`,`),n=t.length,r,i;for(r=0;r{try{let n=e?.callback;n&&delete e.callback,U._urlToImage(this.toDataURL(e),function(e){t(e),n?.(e)})}catch(e){n(e)}})}toBlob(e){return new Promise((t,n)=>{try{let n=e?.callback;n&&delete e.callback,this.toCanvas(e).toBlob(e=>{t(e),n?.(e)},e?.mimeType,e?.quality)}catch(e){n(e)}})}setSize(e){return this.width(e.width),this.height(e.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return this.attrs.dragDistance===void 0?this.parent?this.parent.getDragDistance():V.dragDistance:this.attrs.dragDistance}_off(e,t,n){let r=this.eventListeners[e],i,a,o;for(i=0;i=0)||this.isDragging())return;let t=!1;W._dragElements.forEach(e=>{this.isAncestorOf(e.node)&&(t=!0)}),t||this._createDragElement(e)})}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{if(this._dragCleanup(),!this.getStage())return;let e=W._dragElements.get(this._id),t=e&&e.dragStatus===`dragging`,n=e&&e.dragStatus===`ready`;t?this.stopDrag():n&&W._dragElements.delete(this._id)}}_dragCleanup(){this.off(`mousedown.konva`),this.off(`touchstart.konva`)}isClientRectOnScreen(e={x:0,y:0}){let t=this.getStage();if(!t)return!1;let n={x:-e.x,y:-e.y,width:t.width()+2*e.x,height:t.height()+2*e.y};return U.haveIntersection(n,this.getClientRect())}static create(e,t){return U._isString(e)&&(e=JSON.parse(e)),this._createNode(e,t)}static _createNode(t,n){let r=e.prototype.getClassName.call(t),i=t.children,a,o,s;n&&(t.attrs.container=n),V[r]||(U.warn(`Can not find a node with class name "`+r+`". Fallback to "Shape".`),r=`Shape`);let c=V[r];if(a=new c(t.attrs),i)for(o=i.length,s=0;s0}removeChildren(){return this.getChildren().forEach(e=>{e.parent=null,e.index=0,e.remove()}),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach(e=>{e.parent=null,e.index=0,e.destroy()}),this.children=[],this._requestDraw(),this}add(...e){if(e.length===0)return this;if(e.length>1){for(let t=0;t0?t[0]:void 0}_generalFind(e,t){let n=[];return this._descendants(r=>{let i=r._isMatch(e);return i&&n.push(r),!!(i&&t)}),n}_descendants(e){let t=!1,n=this.getChildren();for(let r of n)if(t=e(r),t||r.hasChildren()&&(t=r._descendants(e),t))return!0;return!1}toObject(){let e=q.prototype.toObject.call(this);return e.children=[],this.getChildren().forEach(t=>{e.children.push(t.toObject())}),e}isAncestorOf(e){let t=e.getParent();for(;t;){if(t._id===this._id)return!0;t=t.getParent()}return!1}clone(e){let t=q.prototype.clone.call(this,e);return this.getChildren().forEach(function(e){t.add(e.clone())}),t}getAllIntersections(e){let t=[];return this.find(`Shape`).forEach(n=>{n.isVisible()&&n.intersects(e)&&t.push(n)}),t}_clearSelfAndDescendantCache(e){var t;super._clearSelfAndDescendantCache(e),!this.isCached()&&((t=this.children)==null||t.forEach(function(t){t._clearSelfAndDescendantCache(e)}))}_setChildrenIndices(){var e;(e=this.children)==null||e.forEach(function(e,t){e.index=t}),this._requestDraw()}drawScene(e,t,n){let r=this.getLayer(),i=e||r&&r.getCanvas(),a=i&&i.getContext(),o=this._getCanvasCache(),s=o&&o.scene,c=i&&i.isCache;if(!this.isVisible()&&!c)return this;if(s){a.save();let e=this.getAbsoluteTransform(t).getMatrix();a.transform(e[0],e[1],e[2],e[3],e[4],e[5]),this._drawCachedSceneCanvas(a),a.restore()}else this._drawChildren(`drawScene`,i,t,n);return this}drawHit(e,t){if(!this.shouldDrawHit(t))return this;let n=this.getLayer(),r=e||n&&n.hitCanvas,i=r&&r.getContext(),a=this._getCanvasCache();if(a&&a.hit){i.save();let e=this.getAbsoluteTransform(t).getMatrix();i.transform(e[0],e[1],e[2],e[3],e[4],e[5]),this._drawCachedHitCanvas(i),i.restore()}else this._drawChildren(`drawHit`,r,t);return this}_drawChildren(e,t,n,r){var i;let a=t&&t.getContext(),o=this.clipWidth(),s=this.clipHeight(),c=this.clipFunc(),l=typeof o==`number`&&typeof s==`number`||c,u=n===this;if(l){a.save();let e=this.getAbsoluteTransform(n),t=e.getMatrix();a.transform(t[0],t[1],t[2],t[3],t[4],t[5]),a.beginPath();let r;if(c)r=c.call(this,a,this);else{let e=this.clipX(),t=this.clipY();a.rect(e||0,t||0,o,s)}a.clip.apply(a,r),t=e.copy().invert().getMatrix(),a.transform(t[0],t[1],t[2],t[3],t[4],t[5])}let d=!u&&this.globalCompositeOperation()!==`source-over`&&e===`drawScene`;d&&(a.save(),a._applyGlobalCompositeOperation(this)),(i=this.children)==null||i.forEach(function(i){i[e](t,n,r)}),d&&a.restore(),l&&a.restore()}getClientRect(e={}){var t;let n=e.skipTransform,r=e.relativeTo,i,a,o,s,c={x:1/0,y:1/0,width:0,height:0},l=this;(t=this.children)==null||t.forEach(function(t){if(!t.visible())return;let n=t.getClientRect({relativeTo:l,skipShadow:e.skipShadow,skipStroke:e.skipStroke});n.width===0&&n.height===0||(i===void 0?(i=n.x,a=n.y,o=n.x+n.width,s=n.y+n.height):(i=Math.min(i,n.x),a=Math.min(a,n.y),o=Math.max(o,n.x+n.width),s=Math.max(s,n.y+n.height)))});let u=this.find(`Shape`),d=!1;for(let e=0;ee.indexOf(`pointer`)>=0?`pointer`:e.indexOf(`touch`)>=0?`touch`:`mouse`,Lr=e=>{let t=Ir(e);if(t===`pointer`)return V.pointerEventsEnabled&&Fr.pointer;if(t===`touch`)return Fr.touch;if(t===`mouse`)return Fr.mouse};function Rr(e={}){return(e.clipFunc||e.clipWidth||e.clipHeight)&&U.warn(`Stage does not support clipping. Please use clip for Layers or Groups.`),e}var zr=`Pointer position is missing and not registered by the stage. Looks like it is outside of the stage container. You can set it manually from event: stage.setPointersPositions(event);`,Br=[],Vr=class extends er{constructor(e){super(Rr(e)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),Br.push(this),this.on(`widthChange.konva heightChange.konva`,this._resizeDOM),this.on(`visibleChange.konva`,this._checkVisibility),this.on(`clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva`,()=>{Rr(this.attrs)}),this._checkVisibility()}_validateAdd(e){let t=e.getType()===`Layer`,n=e.getType()===`FastLayer`;t||n||U.throw(`You may only add layers to the stage.`)}_checkVisibility(){if(!this.content)return;let e=this.visible()?``:`none`;this.content.style.display=e}setContainer(e){if(typeof e===lr){let t;if(e.charAt(0)===`.`){let t=e.slice(1);e=document.getElementsByClassName(t)[0]}else t=e.charAt(0)===`#`?e.slice(1):e,e=document.getElementById(t);if(!e)throw`Can not find container in document with id `+t}return this._setAttr(`container`,e),this.content&&(this.content.parentElement&&this.content.parentElement.removeChild(this.content),e.appendChild(this.content)),this}shouldDrawHit(){return!0}clear(){let e=this.children,t=e.length;for(let n=0;n-1&&Br.splice(t,1),U.releaseCanvas(this.bufferCanvas._canvas,this.bufferHitCanvas._canvas),this}getPointerPosition(){let e=this._pointerPositions[0]||this._changedPointerPositions[0];return e?{x:e.x,y:e.y}:(U.warn(zr),null)}_getPointerById(e){return this._pointerPositions.find(t=>t.id===e)}getPointersPositions(){return this._pointerPositions}getStage(){return this}getContent(){return this.content}_toKonvaCanvas(e){e={...e},e.x=e.x||0,e.y=e.y||0,e.width=e.width||this.width(),e.height=e.height||this.height();let t=new gn({width:e.width,height:e.height,pixelRatio:e.pixelRatio||1}),n=t.getContext()._context,r=this.children;return(e.x||e.y)&&n.translate(-1*e.x,-1*e.y),r.forEach(function(t){if(!t.isVisible())return;let r=t._toKonvaCanvas(e);n.drawImage(r._canvas,e.x,e.y,r.getWidth()/r.getPixelRatio(),r.getHeight()/r.getPixelRatio())}),t}getIntersection(e){if(!e)return null;let t=this.children,n=t.length-1;for(let r=n;r>=0;r--){let n=t[r].getIntersection(e);if(n)return n}return null}_resizeDOM(){let e=this.width(),t=this.height();this.content&&(this.content.style.width=e+ur,this.content.style.height=t+ur),this.bufferCanvas.setSize(e,t),this.bufferHitCanvas.setSize(e,t),this.children.forEach(n=>{n.setSize({width:e,height:t}),n.draw()})}add(e,...t){if(arguments.length>1){for(let e=0;eNr&&U.warn(`The stage has `+n+` layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group.`),e.setSize({width:this.width(),height:this.height()}),e.draw(),V.isBrowser&&this.content.appendChild(e.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(e){return ar(e,this)}setPointerCapture(e){or(e,this)}releaseCapture(e){sr(e,this)}getLayers(){return this.children}_bindContentEvents(){V.isBrowser&&Pr.forEach(([e,t])=>{this.content.addEventListener(e,e=>{this[t](e)},{passive:!1})})}_pointerenter(e){this.setPointersPositions(e);let t=Lr(e.type);t&&this._fire(t.pointerenter,{evt:e,target:this,currentTarget:this})}_pointerover(e){this.setPointersPositions(e);let t=Lr(e.type);t&&this._fire(t.pointerover,{evt:e,target:this,currentTarget:this})}_getTargetShape(e){let t=this[e+`targetShape`];return t&&!t.getStage()&&(t=null),t}_pointerleave(e){let t=Lr(e.type),n=Ir(e.type);if(!t)return;this.setPointersPositions(e);let r=this._getTargetShape(n),i=!(V.isDragging()||V.isTransforming())||V.hitOnDragEnabled;r&&i?(r._fireAndBubble(t.pointerout,{evt:e}),r._fireAndBubble(t.pointerleave,{evt:e}),this._fire(t.pointerleave,{evt:e,target:this,currentTarget:this}),this[n+`targetShape`]=null):i&&(this._fire(t.pointerleave,{evt:e,target:this,currentTarget:this}),this._fire(t.pointerout,{evt:e,target:this,currentTarget:this})),this.pointerPos=null,this._pointerPositions=[]}_pointerdown(e){let t=Lr(e.type),n=Ir(e.type);if(!t)return;this.setPointersPositions(e);let r=!1;this._changedPointerPositions.forEach(i=>{let a=this.getIntersection(i);if(W.justDragged=!1,V[`_`+n+`ListenClick`]=!0,!a||!a.isListening()){this[n+`ClickStartShape`]=void 0;return}V.capturePointerEventsEnabled&&a.setPointerCapture(i.id),this[n+`ClickStartShape`]=a,a._fireAndBubble(t.pointerdown,{evt:e,pointerId:i.id}),r=!0;let o=e.type.indexOf(`touch`)>=0;a.preventDefault()&&e.cancelable&&o&&e.preventDefault()}),r||this._fire(t.pointerdown,{evt:e,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(e){let t=Lr(e.type),n=Ir(e.type);if(!t)return;let r=e.type.indexOf(`touch`)>=0||e.pointerType===`touch`;if(V.isDragging()&&W.node.preventDefault()&&e.cancelable&&r&&e.preventDefault(),this.setPointersPositions(e),!(!(V.isDragging()||V.isTransforming())||V.hitOnDragEnabled))return;let i={},a=!1,o=this._getTargetShape(n);this._changedPointerPositions.forEach(r=>{let s=rr(r.id)||this.getIntersection(r),c=r.id,l={evt:e,pointerId:c},u=o!==s;if(u&&o&&(o._fireAndBubble(t.pointerout,{...l},s),o._fireAndBubble(t.pointerleave,{...l},s)),s){if(i[s._id])return;i[s._id]=!0}s&&s.isListening()?(a=!0,u&&(s._fireAndBubble(t.pointerover,{...l},o),s._fireAndBubble(t.pointerenter,{...l},o),this[n+`targetShape`]=s),s._fireAndBubble(t.pointermove,{...l})):o&&(this._fire(t.pointerover,{evt:e,target:this,currentTarget:this,pointerId:c}),this[n+`targetShape`]=null)}),a||this._fire(t.pointermove,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(e){let t=Lr(e.type),n=Ir(e.type);if(!t)return;this.setPointersPositions(e);let r=this[n+`ClickStartShape`],i=this[n+`ClickEndShape`],a={},o=!1;this._changedPointerPositions.forEach(s=>{let c=rr(s.id)||this.getIntersection(s);if(c){if(c.releaseCapture(s.id),a[c._id])return;a[c._id]=!0}let l=s.id,u={evt:e,pointerId:l},d=!1;V[`_`+n+`InDblClickWindow`]?(d=!0,clearTimeout(this[n+`DblTimeout`])):W.justDragged||(V[`_`+n+`InDblClickWindow`]=!0,clearTimeout(this[n+`DblTimeout`])),this[n+`DblTimeout`]=setTimeout(function(){V[`_`+n+`InDblClickWindow`]=!1},V.dblClickWindow),c&&c.isListening()?(o=!0,this[n+`ClickEndShape`]=c,c._fireAndBubble(t.pointerup,{...u}),V[`_`+n+`ListenClick`]&&r&&r===c&&(c._fireAndBubble(t.pointerclick,{...u}),d&&i&&i===c&&c._fireAndBubble(t.pointerdblclick,{...u}))):(this[n+`ClickEndShape`]=null,o||=(this._fire(t.pointerup,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),!0),V[`_`+n+`ListenClick`]&&this._fire(t.pointerclick,{evt:e,target:this,currentTarget:this,pointerId:l}),d&&this._fire(t.pointerdblclick,{evt:e,target:this,currentTarget:this,pointerId:l}))}),o||this._fire(t.pointerup,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),V[`_`+n+`ListenClick`]=!1,e.cancelable&&n!==`touch`&&n!==`pointer`&&e.preventDefault()}_contextmenu(e){this.setPointersPositions(e);let t=this.getIntersection(this.getPointerPosition());t&&t.isListening()?t._fireAndBubble(Dr,{evt:e}):this._fire(Dr,{evt:e,target:this,currentTarget:this})}_wheel(e){this.setPointersPositions(e);let t=this.getIntersection(this.getPointerPosition());t&&t.isListening()?t._fireAndBubble(Mr,{evt:e}):this._fire(Mr,{evt:e,target:this,currentTarget:this})}_pointercancel(e){this.setPointersPositions(e);let t=rr(e.pointerId)||this.getIntersection(this.getPointerPosition());t&&t._fireAndBubble(br,ir(e)),sr(e.pointerId)}_lostpointercapture(e){sr(e.pointerId)}setPointersPositions(e){let t=this._getContentPosition(),n=null,r=null;e||=window.event,e.touches===void 0?(n=(e.clientX-t.left)/t.scaleX,r=(e.clientY-t.top)/t.scaleY,this.pointerPos={x:n,y:r},this._pointerPositions=[{x:n,y:r,id:U._getFirstPointerId(e)}],this._changedPointerPositions=[{x:n,y:r,id:U._getFirstPointerId(e)}]):(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(e.touches,e=>{this._pointerPositions.push({id:e.identifier,x:(e.clientX-t.left)/t.scaleX,y:(e.clientY-t.top)/t.scaleY})}),Array.prototype.forEach.call(e.changedTouches||e.touches,e=>{this._changedPointerPositions.push({id:e.identifier,x:(e.clientX-t.left)/t.scaleX,y:(e.clientY-t.top)/t.scaleY})}))}_setPointerPosition(e){U.warn(`Method _setPointerPosition is deprecated. Use "stage.setPointersPositions(event)" instead.`),this.setPointersPositions(e)}_getContentPosition(){if(!this.content||!this.content.getBoundingClientRect)return{top:0,left:0,scaleX:1,scaleY:1};let e=this.content.getBoundingClientRect();return{top:e.top,left:e.left,scaleX:e.width/this.content.clientWidth||1,scaleY:e.height/this.content.clientHeight||1}}_buildDOM(){if(this.bufferCanvas=new gn({width:this.width(),height:this.height()}),this.bufferHitCanvas=new _n({pixelRatio:1,width:this.width(),height:this.height()}),!V.isBrowser)return;let e=this.container();if(!e)throw`Stage has no container. A container is required.`;e.innerHTML=``,this.content=document.createElement(`div`),this.content.style.position=`relative`,this.content.style.userSelect=`none`,this.content.className=`konvajs-content`,this.content.setAttribute(`role`,`presentation`),e.appendChild(this.content),this._resizeDOM()}cache(){return U.warn(`Cache function is not allowed for stage. You may use cache only for layers, groups and shapes.`),this}clearCache(){return this}batchDraw(){return this.getChildren().forEach(function(e){e.batchDraw()}),this}};Vr.prototype.nodeType=cr,H(Vr),K.addGetterSetter(Vr,`container`),V.isBrowser&&document.addEventListener(`visibilitychange`,()=>{Br.forEach(e=>{e.batchDraw()})});var Hr=`hasShadow`,Ur=`shadowRGBA`,Wr=`patternImage`,Gr=`linearGradient`,Kr=`radialGradient`,qr;function Jr(){return qr||(qr=U.createCanvasElement().getContext(`2d`),qr)}var Yr={};function Xr(e){let t=this.attrs.fillRule;t?e.fill(t):e.fill()}function Zr(e){e.stroke()}function Qr(e){let t=this.attrs.fillRule;t?e.fill(t):e.fill()}function $r(e){e.stroke()}function ei(){this._clearCache(Hr)}function ti(){this._clearCache(Ur)}function ni(){this._clearCache(Wr)}function ri(){this._clearCache(Gr)}function ii(){this._clearCache(Kr)}var Y=class extends q{constructor(e){super(e);let t,n=0;for(;t=U.getHitColor(),!(t&&!(t in Yr));)if(n++,n>=1e4){U.warn(`Failed to find a unique color key for a shape. Konva may work incorrectly. Most likely your browser is using canvas farbling. Consider disabling it.`),t=U.getRandomColor();break}this.colorKey=t,Yr[t]=this}getContext(){return U.warn(`shape.getContext() method is deprecated. Please do not use it.`),this.getLayer().getContext()}getCanvas(){return U.warn(`shape.getCanvas() method is deprecated. Please do not use it.`),this.getLayer().getCanvas()}getSceneFunc(){return this.attrs.sceneFunc||this._sceneFunc}getHitFunc(){return this.attrs.hitFunc||this._hitFunc}hasShadow(){return this._getCache(Hr,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&this.shadowOpacity()!==0&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(Wr,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){let e=Jr().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||`repeat`);if(e&&e.setTransform){let t=new jt;t.translate(this.fillPatternX(),this.fillPatternY()),t.rotate(V.getAngle(this.fillPatternRotation())),t.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),t.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());let n=t.getMatrix(),r=typeof DOMMatrix>`u`?{a:n[0],b:n[1],c:n[2],d:n[3],e:n[4],f:n[5]}:new DOMMatrix(n);e.setTransform(r)}return e}}_getLinearGradient(){return this._getCache(Gr,this.__getLinearGradient)}__getLinearGradient(){let e=this.fillLinearGradientColorStops();if(e){let t=Jr(),n=this.fillLinearGradientStartPoint(),r=this.fillLinearGradientEndPoint(),i=t.createLinearGradient(n.x,n.y,r.x,r.y);for(let t=0;tthis.fillEnabled()&&!!(this.fill()||this.fillPatternImage()||this.fillLinearGradientColorStops()||this.fillRadialGradientColorStops()))}hasStroke(){return this._calculate(`hasStroke`,[`strokeEnabled`,`strokeWidth`,`stroke`,`strokeLinearGradientColorStops`],()=>this.strokeEnabled()&&this.strokeWidth()&&!!(this.stroke()||this.strokeLinearGradientColorStops()))}hasHitStroke(){let e=this.hitStrokeWidth();return e===`auto`?this.hasStroke():this.strokeEnabled()&&!!e}intersects(e){let t=this.getStage();if(!t)return!1;let n=t.bufferHitCanvas;return n.getContext().clear(),this.drawHit(n,void 0,!0),n.context.getImageData(Math.round(e.x),Math.round(e.y),1,1).data[3]>0}destroy(){return q.prototype.destroy.call(this),delete Yr[this.colorKey],delete this.colorKey,this}_useBufferCanvas(e){if(!(this.attrs.perfectDrawEnabled??!0))return!1;let t=e||this.hasFill(),n=this.hasStroke(),r=this.getAbsoluteOpacity()!==1;if(t&&n&&r)return!0;let i=this.hasShadow(),a=this.shadowForStrokeEnabled();return!!(t&&n&&i&&a)}setStrokeHitEnabled(e){U.warn(`strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead.`),e?this.hitStrokeWidth(`auto`):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return this.hitStrokeWidth()!==0}getSelfRect(){let e=this.size();return{x:this._centroid?-e.width/2:0,y:this._centroid?-e.height/2:0,width:e.width,height:e.height}}getClientRect(e={}){let t=!1,n=this.getParent();for(;n;){if(n.isCached()){t=!0;break}n=n.getParent()}let r=e.skipTransform,i=e.relativeTo||t&&this.getStage()||void 0,a=this.getSelfRect(),o=!e.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,s=a.width+o,c=a.height+o,l=!e.skipShadow&&this.hasShadow(),u=l?this.shadowOffsetX():0,d=l?this.shadowOffsetY():0,f=s+Math.abs(u),p=c+Math.abs(d),m=l&&this.shadowBlur()||0,h={width:f+m*2,height:p+m*2,x:-(o/2+m)+Math.min(u,0)+a.x,y:-(o/2+m)+Math.min(d,0)+a.y};return r?h:this._transformedRect(h,i)}drawScene(e,t,n){let r=this.getLayer(),i=(e||r.getCanvas()).getContext(),a=this._getCanvasCache(),o=this.getSceneFunc(),s=this.hasShadow(),c,l=t===this;if(!this.isVisible()&&!l)return this;if(a){i.save();let e=this.getAbsoluteTransform(t).getMatrix();return i.transform(e[0],e[1],e[2],e[3],e[4],e[5]),this._drawCachedSceneCanvas(i),i.restore(),this}if(!o)return this;if(i.save(),this._useBufferCanvas()){c=this.getStage();let e=n||c.bufferCanvas,r=e.getContext();n?(r.save(),r.setTransform(1,0,0,1,0,0),r.clearRect(0,0,e.width,e.height),r.restore()):r.clear(),r.save(),r._applyLineJoin(this),r._applyMiterLimit(this);let a=this.getAbsoluteTransform(t).getMatrix();r.transform(a[0],a[1],a[2],a[3],a[4],a[5]),o.call(this,r,this),r.restore();let u=e.pixelRatio;s&&i._applyShadow(this),l||(i._applyOpacity(this),i._applyGlobalCompositeOperation(this)),i.drawImage(e._canvas,e.x||0,e.y||0,e.width/u,e.height/u)}else{if(i._applyLineJoin(this),i._applyMiterLimit(this),!l){let e=this.getAbsoluteTransform(t).getMatrix();i.transform(e[0],e[1],e[2],e[3],e[4],e[5]),i._applyOpacity(this),i._applyGlobalCompositeOperation(this)}s&&i._applyShadow(this),o.call(this,i,this)}return i.restore(),this}drawHit(e,t,n=!1){if(!this.shouldDrawHit(t,n))return this;let r=this.getLayer(),i=e||r.hitCanvas,a=i&&i.getContext(),o=this.hitFunc()||this.sceneFunc(),s=this._getCanvasCache(),c=s&&s.hit;if(this.colorKey||U.warn(`Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()`),c){a.save();let e=this.getAbsoluteTransform(t).getMatrix();return a.transform(e[0],e[1],e[2],e[3],e[4],e[5]),this._drawCachedHitCanvas(a),a.restore(),this}if(!o)return this;if(a.save(),a._applyLineJoin(this),a._applyMiterLimit(this),this!==t){let e=this.getAbsoluteTransform(t).getMatrix();a.transform(e[0],e[1],e[2],e[3],e[4],e[5])}return o.call(this,a,this),a.restore(),this}drawHitFromCache(e=0){let t=this._getCanvasCache(),n=this._getCachedSceneCanvas(),r=t.hit,i=r.getContext(),a=r.getWidth(),o=r.getHeight();i.clear(),i.drawImage(n._canvas,0,0,a,o);try{let t=i.getImageData(0,0,a,o),n=t.data,r=n.length,s=U._hexToRgb(this.colorKey);for(let t=0;te?(n[t]=s.r,n[t+1]=s.g,n[t+2]=s.b,n[t+3]=255):n[t+3]=0;i.putImageData(t,0,0)}catch(e){U.error(`Unable to draw hit graph from cached scene canvas. `+e.message)}return this}hasPointerCapture(e){return ar(e,this)}setPointerCapture(e){or(e,this)}releaseCapture(e){sr(e,this)}};Y.prototype._fillFunc=Xr,Y.prototype._strokeFunc=Zr,Y.prototype._fillFuncHit=Qr,Y.prototype._strokeFuncHit=$r,Y.prototype._centroid=!1,Y.prototype.nodeType=`Shape`,H(Y),Y.prototype.eventListeners={},Y.prototype.on(`shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva`,ei),Y.prototype.on(`shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva`,ti),Y.prototype.on(`fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva`,ni),Y.prototype.on(`fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva`,ri),Y.prototype.on(`fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva`,ii),K.addGetterSetter(Y,`stroke`,void 0,Cn()),K.addGetterSetter(Y,`strokeWidth`,2,G()),K.addGetterSetter(Y,`fillAfterStrokeEnabled`,!1),K.addGetterSetter(Y,`hitStrokeWidth`,`auto`,xn()),K.addGetterSetter(Y,`strokeHitEnabled`,!0,Tn()),K.addGetterSetter(Y,`perfectDrawEnabled`,!0,Tn()),K.addGetterSetter(Y,`shadowForStrokeEnabled`,!0,Tn()),K.addGetterSetter(Y,`lineJoin`),K.addGetterSetter(Y,`lineCap`),K.addGetterSetter(Y,`miterLimit`),K.addGetterSetter(Y,`sceneFunc`),K.addGetterSetter(Y,`hitFunc`),K.addGetterSetter(Y,`dash`),K.addGetterSetter(Y,`dashOffset`,0,G()),K.addGetterSetter(Y,`shadowColor`,void 0,Sn()),K.addGetterSetter(Y,`shadowBlur`,0,G()),K.addGetterSetter(Y,`shadowOpacity`,1,G()),K.addComponentsGetterSetter(Y,`shadowOffset`,[`x`,`y`]),K.addGetterSetter(Y,`shadowOffsetX`,0,G()),K.addGetterSetter(Y,`shadowOffsetY`,0,G()),K.addGetterSetter(Y,`fillPatternImage`),K.addGetterSetter(Y,`fill`,void 0,Cn()),K.addGetterSetter(Y,`fillPatternX`,0,G()),K.addGetterSetter(Y,`fillPatternY`,0,G()),K.addGetterSetter(Y,`fillLinearGradientColorStops`),K.addGetterSetter(Y,`strokeLinearGradientColorStops`),K.addGetterSetter(Y,`fillRadialGradientStartRadius`,0),K.addGetterSetter(Y,`fillRadialGradientEndRadius`,0),K.addGetterSetter(Y,`fillRadialGradientColorStops`),K.addGetterSetter(Y,`fillPatternRepeat`,`repeat`),K.addGetterSetter(Y,`fillEnabled`,!0),K.addGetterSetter(Y,`strokeEnabled`,!0),K.addGetterSetter(Y,`shadowEnabled`,!0),K.addGetterSetter(Y,`dashEnabled`,!0),K.addGetterSetter(Y,`strokeScaleEnabled`,!0),K.addGetterSetter(Y,`fillPriority`,`color`),K.addComponentsGetterSetter(Y,`fillPatternOffset`,[`x`,`y`]),K.addGetterSetter(Y,`fillPatternOffsetX`,0,G()),K.addGetterSetter(Y,`fillPatternOffsetY`,0,G()),K.addComponentsGetterSetter(Y,`fillPatternScale`,[`x`,`y`]),K.addGetterSetter(Y,`fillPatternScaleX`,1,G()),K.addGetterSetter(Y,`fillPatternScaleY`,1,G()),K.addComponentsGetterSetter(Y,`fillLinearGradientStartPoint`,[`x`,`y`]),K.addComponentsGetterSetter(Y,`strokeLinearGradientStartPoint`,[`x`,`y`]),K.addGetterSetter(Y,`fillLinearGradientStartPointX`,0),K.addGetterSetter(Y,`strokeLinearGradientStartPointX`,0),K.addGetterSetter(Y,`fillLinearGradientStartPointY`,0),K.addGetterSetter(Y,`strokeLinearGradientStartPointY`,0),K.addComponentsGetterSetter(Y,`fillLinearGradientEndPoint`,[`x`,`y`]),K.addComponentsGetterSetter(Y,`strokeLinearGradientEndPoint`,[`x`,`y`]),K.addGetterSetter(Y,`fillLinearGradientEndPointX`,0),K.addGetterSetter(Y,`strokeLinearGradientEndPointX`,0),K.addGetterSetter(Y,`fillLinearGradientEndPointY`,0),K.addGetterSetter(Y,`strokeLinearGradientEndPointY`,0),K.addComponentsGetterSetter(Y,`fillRadialGradientStartPoint`,[`x`,`y`]),K.addGetterSetter(Y,`fillRadialGradientStartPointX`,0),K.addGetterSetter(Y,`fillRadialGradientStartPointY`,0),K.addComponentsGetterSetter(Y,`fillRadialGradientEndPoint`,[`x`,`y`]),K.addGetterSetter(Y,`fillRadialGradientEndPointX`,0),K.addGetterSetter(Y,`fillRadialGradientEndPointY`,0),K.addGetterSetter(Y,`fillPatternRotation`,0),K.addGetterSetter(Y,`fillRule`,void 0,Sn()),K.backCompat(Y,{dashArray:`dash`,getDashArray:`getDash`,setDashArray:`getDash`,drawFunc:`sceneFunc`,getDrawFunc:`getSceneFunc`,setDrawFunc:`setSceneFunc`,drawHitFunc:`hitFunc`,getDrawHitFunc:`getHitFunc`,setDrawHitFunc:`setHitFunc`});var ai=`beforeDraw`,oi=`draw`,si=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],ci=si.length,li=class extends er{constructor(e){super(e),this.canvas=new gn,this.hitCanvas=new _n({pixelRatio:1}),this._waitingForDraw=!1,this.on(`visibleChange.konva`,this._checkVisibility),this._checkVisibility(),this.on(`imageSmoothingEnabledChange.konva`,this._setSmoothEnabled),this._setSmoothEnabled()}createPNGStream(){return this.canvas._canvas.createPNGStream()}getCanvas(){return this.canvas}getNativeCanvasElement(){return this.canvas._canvas}getHitCanvas(){return this.hitCanvas}getContext(){return this.getCanvas().getContext()}clear(e){return this.getContext().clear(e),this.getHitCanvas().getContext().clear(e),this}setZIndex(e){super.setZIndex(e);let t=this.getStage();return t&&t.content&&(t.content.removeChild(this.getNativeCanvasElement()),e{this.draw(),this._waitingForDraw=!1})),this}getIntersection(e){if(!this.isListening()||!this.isVisible())return null;let t=1,n=!1;for(;;){for(let r=0;r0)return{antialiased:!0};return{}}drawScene(e,t,n){let r=this.getLayer(),i=e||r&&r.getCanvas();return this._fire(ai,{node:this}),this.clearBeforeDraw()&&i.getContext().clear(),er.prototype.drawScene.call(this,i,t,n),this._fire(oi,{node:this}),this}drawHit(e,t){let n=this.getLayer(),r=e||n&&n.hitCanvas;return n&&n.clearBeforeDraw()&&n.getHitCanvas().getContext().clear(),er.prototype.drawHit.call(this,r,t),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(e){U.warn(`hitGraphEnabled method is deprecated. Please use layer.listening() instead.`),this.listening(e)}getHitGraphEnabled(e){return U.warn(`hitGraphEnabled method is deprecated. Please use layer.listening() instead.`),this.listening()}toggleHitCanvas(){if(!this.parent||!this.parent.content)return;let e=this.parent;this.hitCanvas._canvas.parentNode?e.content.removeChild(this.hitCanvas._canvas):e.content.appendChild(this.hitCanvas._canvas)}destroy(){return U.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}};li.prototype.nodeType=`Layer`,H(li),K.addGetterSetter(li,`imageSmoothingEnabled`,!0),K.addGetterSetter(li,`clearBeforeDraw`,!0),K.addGetterSetter(li,`hitGraphEnabled`,!0,Tn());var ui=class extends li{constructor(e){super(e),this.listening(!1),U.warn(`Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.`)}};ui.prototype.nodeType=`FastLayer`,H(ui);var di=class extends er{_validateAdd(e){let t=e.getType();t!==`Group`&&t!==`Shape`&&U.throw(`You may only add groups and shapes to groups.`)}};di.prototype.nodeType=`Group`,H(di);var fi=(function(){return Ot.performance&&Ot.performance.now?function(){return Ot.performance.now()}:function(){return new Date().getTime()}})(),pi=class e{constructor(t,n){this.id=e.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:fi(),frameRate:0},this.func=t,this.setLayers(n)}setLayers(e){let t=[];return e&&(t=Array.isArray(e)?e:[e]),this.layers=t,this}getLayers(){return this.layers}addLayer(e){let t=this.layers,n=t.length;for(let r=0;rthis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():e<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=e,this.update())}getTime(){return this._time}setPosition(e){this.prevPos=this._pos,this.propFunc(e),this._pos=e}getPosition(e){return e===void 0&&(e=this._time),this.func(e,this.begin,this._change,this.duration)}play(){this.state=gi,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire(`onPlay`)}reverse(){this.state=_i,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire(`onReverse`)}seek(e){this.pause(),this._time=e,this.update(),this.fire(`onSeek`)}reset(){this.pause(),this._time=0,this.update(),this.fire(`onReset`)}finish(){this.pause(),this._time=this.duration,this.update(),this.fire(`onFinish`)}update(){this.setPosition(this.getPosition(this._time)),this.fire(`onUpdate`)}onEnterFrame(){let e=this.getTimer()-this._startTime;this.state===gi?this.setTime(e):this.state===_i&&this.setTime(this.duration-e)}pause(){this.state=hi,this.fire(`onPause`)}getTimer(){return new Date().getTime()}},xi=class e{constructor(t){let n=this,r=t.node,i=r._id,a=t.easing||Si.Linear,o=!!t.yoyo,s,c;s=t.duration===void 0?.3:t.duration===0?.001:t.duration,this.node=r,this._id=yi++;let l=r.getLayer()||(r instanceof V.Stage?r.getLayers():null);for(c in l||U.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new pi(function(){n.tween.onEnterFrame()},l),this.tween=new bi(c,function(e){n._tweenFunc(e)},a,0,1,s*1e3,o),this._addListeners(),e.attrs[i]||(e.attrs[i]={}),e.attrs[i][this._id]||(e.attrs[i][this._id]={}),e.tweens[i]||(e.tweens[i]={}),t)mi[c]===void 0&&this._addAttr(c,t[c]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset,this.onUpdate=t.onUpdate}_addAttr(t,n){let r=this.node,i=r._id,a,o,s,c,l,u=e.tweens[i][t];u&&delete e.attrs[i][u][t];let d=r.getAttr(t);if(U._isArray(n))if(a=[],o=Math.max(n.length,d.length),t===`points`&&n.length!==d.length&&(n.length>d.length?(c=d,d=U._prepareArrayForTween(d,n,r.closed())):(s=n,n=U._prepareArrayForTween(n,d,r.closed()))),t.indexOf(`fill`)===0)for(let e=0;e{this.anim.start()},this.tween.onReverse=()=>{this.anim.start()},this.tween.onPause=()=>{this.anim.stop()},this.tween.onFinish=()=>{let t=this.node,n=e.attrs[t._id][this._id];n.points&&n.points.trueEnd&&t.setAttr(`points`,n.points.trueEnd),this.onFinish&&this.onFinish.call(this)},this.tween.onReset=()=>{let t=this.node,n=e.attrs[t._id][this._id];n.points&&n.points.trueStart&&t.points(n.points.trueStart),this.onReset&&this.onReset()},this.tween.onUpdate=()=>{this.onUpdate&&this.onUpdate.call(this)}}play(){return this.tween.play(),this}reverse(){return this.tween.reverse(),this}reset(){return this.tween.reset(),this}seek(e){return this.tween.seek(e*1e3),this}pause(){return this.tween.pause(),this}finish(){return this.tween.finish(),this}destroy(){let t=this.node._id,n=this._id,r=e.tweens[t];this.pause(),this.anim&&this.anim.stop();for(let n in r)delete e.tweens[t][n];delete e.attrs[t][n],e.tweens[t]&&(Object.keys(e.tweens[t]).length===0&&delete e.tweens[t],Object.keys(e.attrs[t]).length===0&&delete e.attrs[t])}};xi.attrs={},xi.tweens={},q.prototype.to=function(e){let t=e.onFinish;e.node=this,e.onFinish=function(){this.destroy(),t&&t()},new xi(e).play()};var Si={BackEaseIn(e,t,n,r){return n*(e/=r)*e*(2.70158*e-1.70158)+t},BackEaseOut(e,t,n,r){return n*((e=e/r-1)*e*(2.70158*e+1.70158)+1)+t},BackEaseInOut(e,t,n,r){let i=1.70158;return(e/=r/2)<1?n/2*(e*e*(((i*=1.525)+1)*e-i))+t:n/2*((e-=2)*e*(((i*=1.525)+1)*e+i)+2)+t},ElasticEaseIn(e,t,n,r,i,a){let o=0;return e===0?t:(e/=r)===1?t+n:(a||=r*.3,!i||i0?e:t),c=1*t,l=a*(a>0?e:t),u=o*(o>0?t:e);return{x:s,y:n?-1*u:l,width:c-s,height:u-l}}};wi.prototype._centroid=!0,wi.prototype.className=`Arc`,wi.prototype._attrsAffectingSize=[`innerRadius`,`outerRadius`,`angle`,`clockwise`],H(wi),K.addGetterSetter(wi,`innerRadius`,0,G()),K.addGetterSetter(wi,`outerRadius`,0,G()),K.addGetterSetter(wi,`angle`,0,G()),K.addGetterSetter(wi,`clockwise`,!1,Tn());function Ti(e,t,n,r,i,a,o){let s=Math.sqrt((n-e)**2+(r-t)**2),c=Math.sqrt((i-n)**2+(a-r)**2),l=o*s/(s+c),u=o*c/(s+c);return[n-l*(i-e),r-l*(a-t),n+u*(i-e),r+u*(a-t)]}function Ei(e,t){let n=e.length,r=[];for(let i=2;i=0){let e=Math.sqrt(a);n.push((-r+e)/(2*t)),n.push((-r-e)/(2*t))}}}return n.filter(e=>e>0&&e<1).flatMap(e=>t.map(t=>{let n=1-e;return n*n*n*t[0]+3*n*n*e*t[1]+3*n*e*e*t[2]+e*e*e*t[3]}))}var Oi=class extends Y{constructor(e){super(e),this.on(`pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva`,function(){this._clearCache(`tensionPoints`)})}_sceneFunc(e){let t=this.points(),n=t.length,r=this.tension(),i=this.closed(),a=this.bezier();if(!n)return;let o=0;if(e.beginPath(),e.moveTo(t[0],t[1]),r!==0&&n>4){let r=this.getTensionPoints(),a=r.length;for(o=i?0:4,i||e.quadraticCurveTo(r[0],r[1],r[2],r[3]);o{let r,i,a=n/2;r=0;for(let n=0;n<20;n++)i=a*ki[20][n]+a,r+=Ai[20][n]*Pi(e,t,i);return a*r},Ni=(e,t,n)=>{n===void 0&&(n=1);let r=e[0]-2*e[1]+e[2],i=t[0]-2*t[1]+t[2],a=2*e[1]-2*e[0],o=2*t[1]-2*t[0],s=4*(r*r+i*i),c=4*(r*a+i*o),l=a*a+o*o;if(s===0)return n*Math.sqrt((e[2]-e[0])**2+(t[2]-t[0])**2);let u=c/(2*s),d=l/s,f=n+u,p=d-u*u,m=f*f+p>0?Math.sqrt(f*f+p):0,h=u*u+p>0?Math.sqrt(u*u+p):0,g=u+Math.sqrt(u*u+p)===0?0:p*Math.log(Math.abs((f+m)/(u+h)));return Math.sqrt(s)/2*(f*m-u*h+g)};function Pi(e,t,n){let r=Fi(1,n,e),i=Fi(1,n,t),a=r*r+i*i;return Math.sqrt(a)}var Fi=(e,t,n)=>{let r=n.length-1,i,a;if(r===0)return 0;if(e===0){a=0;for(let e=0;e<=r;e++)a+=ji[r][e]*(1-t)**(r-e)*t**+e*n[e];return a}else{i=Array(r);for(let e=0;e{let r=1,i=e/t,a=(e-n(i))/t,o=0;for(;r>.001;){let s=n(i+a),c=Math.abs(e-s)/t;if(c500)break}return i},Li=class e extends Y{constructor(e){super(e),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on(`dataChange.konva`,function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=e.parsePathData(this.data()),this.pathLength=e.getPathLength(this.dataArray)}_sceneFunc(e){let t=this.dataArray;e.beginPath();let n=!1;for(let r=0;ro?i:o,f=i>o?1:i/o,p=i>o?o/i:1;e.translate(t,r),e.rotate(l),e.scale(f,p),e.arc(0,0,d,s,s+c,1-u),e.scale(1/f,1/p),e.rotate(-l),e.translate(-t,-r);break;case`z`:n=!0,e.closePath();break}}!n&&!this.hasFill()?e.strokeShape(this):e.fillStrokeShape(this)}getSelfRect(){let t=[];this.dataArray.forEach(function(n){if(n.command===`A`){let r=n.points[4],i=n.points[5],a=n.points[4]+i,o=Math.PI/180;if(Math.abs(r-a)a;i-=o){let r=e.getPointOnEllipticalArc(n.points[0],n.points[1],n.points[2],n.points[3],i,0);t.push(r.x,r.y)}else for(let i=r+o;in[i].pathLength;)t-=n[i].pathLength,++i;if(i===a)return r=n[i-1].points.slice(-2),{x:r[0],y:r[1]};if(t<.01)return n[i].command===`M`?(r=n[i].points.slice(0,2),{x:r[0],y:r[1]}):{x:n[i].start.x,y:n[i].start.y};let o=n[i],s=o.points;switch(o.command){case`L`:return e.getPointOnLine(t,o.start.x,o.start.y,s[0],s[1]);case`C`:return e.getPointOnCubicBezier(Ii(t,e.getPathLength(n),e=>Mi([o.start.x,s[0],s[2],s[4]],[o.start.y,s[1],s[3],s[5]],e)),o.start.x,o.start.y,s[0],s[1],s[2],s[3],s[4],s[5]);case`Q`:return e.getPointOnQuadraticBezier(Ii(t,e.getPathLength(n),e=>Ni([o.start.x,s[0],s[2]],[o.start.y,s[1],s[3]],e)),o.start.x,o.start.y,s[0],s[1],s[2],s[3]);case`A`:let r=s[0],i=s[1],a=s[2],c=s[3],l=s[5],u=s[6],d=s[4];return d+=l*t/o.pathLength,e.getPointOnEllipticalArc(r,i,a,c,d,u)}return null}static getPointOnLine(e,t,n,r,i,a,o){a??=t,o??=n;let s=this.getLineLength(t,n,r,i);if(s<1e-10)return{x:t,y:n};if(r===t)return{x:a,y:o+(i>n?e:-e)};let c=(i-n)/(r-t),l=Math.sqrt(e*e/(1+c*c))*(r=0&&(d+=2,d>=7&&(d-=7));continue}if(d>=0){if(d===3){if(/^[01]{2}\d+(?:\.\d+)?$/.test(t)){u.push(parseInt(t[0],10)),u.push(parseInt(t[1],10)),u.push(parseFloat(t.slice(2))),d+=3,d>=7&&(d-=7);continue}if(t===`11`||t===`10`||t===`01`){u.push(parseInt(t[0],10)),u.push(parseInt(t[1],10)),d+=2,d>=7&&(d-=7);continue}if(t===`0`||t===`1`){u.push(parseInt(t,10)),d+=1,d>=7&&(d-=7);continue}}else if(d===4){if(/^[01]\d+(?:\.\d+)?$/.test(t)){u.push(parseInt(t[0],10)),u.push(parseFloat(t.slice(1))),d+=2,d>=7&&(d-=7);continue}if(t===`0`||t===`1`){u.push(parseInt(t,10)),d+=1,d>=7&&(d-=7);continue}}let e=parseFloat(t);isNaN(e)?u.push(0):u.push(e),d+=1,d>=7&&(d-=7)}else{let e=parseFloat(t);isNaN(e)?u.push(0):u.push(e)}}for(;u.length>0&&!isNaN(u[0]);){let e=``,t=[],r=o,a=s,c,l,d,f,p,m,h,g,_,v;switch(n){case`l`:o+=u.shift(),s+=u.shift(),e=`L`,t.push(o,s);break;case`L`:o=u.shift(),s=u.shift(),t.push(o,s);break;case`m`:let r=u.shift(),a=u.shift();if(o+=r,s+=a,e=`M`,i.length>2&&i[i.length-1].command===`z`){for(let e=i.length-2;e>=0;e--)if(i[e].command===`M`){o=i[e].points[0]+r,s=i[e].points[1]+a;break}}t.push(o,s),n=`l`;break;case`M`:o=u.shift(),s=u.shift(),e=`M`,t.push(o,s),n=`L`;break;case`h`:o+=u.shift(),e=`L`,t.push(o,s);break;case`H`:o=u.shift(),e=`L`,t.push(o,s);break;case`v`:s+=u.shift(),e=`L`,t.push(o,s);break;case`V`:s=u.shift(),e=`L`,t.push(o,s);break;case`C`:t.push(u.shift(),u.shift(),u.shift(),u.shift()),o=u.shift(),s=u.shift(),t.push(o,s);break;case`c`:t.push(o+u.shift(),s+u.shift(),o+u.shift(),s+u.shift()),o+=u.shift(),s+=u.shift(),e=`C`,t.push(o,s);break;case`S`:l=o,d=s,c=i[i.length-1],c.command===`C`&&(l=o+(o-c.points[2]),d=s+(s-c.points[3])),t.push(l,d,u.shift(),u.shift()),o=u.shift(),s=u.shift(),e=`C`,t.push(o,s);break;case`s`:l=o,d=s,c=i[i.length-1],c.command===`C`&&(l=o+(o-c.points[2]),d=s+(s-c.points[3])),t.push(l,d,o+u.shift(),s+u.shift()),o+=u.shift(),s+=u.shift(),e=`C`,t.push(o,s);break;case`Q`:t.push(u.shift(),u.shift()),o=u.shift(),s=u.shift(),t.push(o,s);break;case`q`:t.push(o+u.shift(),s+u.shift()),o+=u.shift(),s+=u.shift(),e=`Q`,t.push(o,s);break;case`T`:l=o,d=s,c=i[i.length-1],c.command===`Q`&&(l=o+(o-c.points[0]),d=s+(s-c.points[1])),o=u.shift(),s=u.shift(),e=`Q`,t.push(l,d,o,s);break;case`t`:l=o,d=s,c=i[i.length-1],c.command===`Q`&&(l=o+(o-c.points[0]),d=s+(s-c.points[1])),o+=u.shift(),s+=u.shift(),e=`Q`,t.push(l,d,o,s);break;case`A`:f=u.shift(),p=u.shift(),m=u.shift(),h=u.shift(),g=u.shift(),_=o,v=s,o=u.shift(),s=u.shift(),e=`A`,t=this.convertEndpointToCenterParameterization(_,v,o,s,h,g,f,p,m);break;case`a`:f=u.shift(),p=u.shift(),m=u.shift(),h=u.shift(),g=u.shift(),_=o,v=s,o+=u.shift(),s+=u.shift(),e=`A`,t=this.convertEndpointToCenterParameterization(_,v,o,s,h,g,f,p,m);break}i.push({command:e||n,points:t,start:{x:r,y:a},pathLength:this.calcLength(r,a,e||n,t)})}(n===`z`||n===`Z`)&&i.push({command:`z`,points:[],start:void 0,pathLength:0})}return i}static calcLength(t,n,r,i){let a,o,s,c,l=e;switch(r){case`L`:return l.getLineLength(t,n,i[0],i[1]);case`C`:return Mi([t,i[0],i[2],i[4]],[n,i[1],i[3],i[5]],1);case`Q`:return Ni([t,i[0],i[2]],[n,i[1],i[3]],1);case`A`:a=0;let e=i[4],r=i[5],u=i[4]+r,d=Math.PI/180;if(Math.abs(e-u)u;c-=d)s=l.getPointOnEllipticalArc(i[0],i[1],i[2],i[3],c,0),a+=l.getLineLength(o.x,o.y,s.x,s.y),o=s;else for(c=e+d;c1&&(o*=Math.sqrt(f),s*=Math.sqrt(f));let p=Math.sqrt((o*o*(s*s)-o*o*(d*d)-s*s*(u*u))/(o*o*(d*d)+s*s*(u*u)));i===a&&(p*=-1),isNaN(p)&&(p=0);let m=p*o*d/s,h=p*-s*u/o,g=(e+n)/2+Math.cos(l)*m-Math.sin(l)*h,_=(t+r)/2+Math.sin(l)*m+Math.cos(l)*h,v=function(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1])},y=function(e,t){return(e[0]*t[0]+e[1]*t[1])/(v(e)*v(t))},b=function(e,t){return(e[0]*t[1]=1&&(w=0),a===0&&w>0&&(w-=2*Math.PI),a===1&&w<0&&(w+=2*Math.PI),[g,_,o,s,x,w,l,a]}};Li.prototype.className=`Path`,Li.prototype._attrsAffectingSize=[`data`],H(Li),K.addGetterSetter(Li,`data`);var Ri=class extends Oi{_sceneFunc(e){super._sceneFunc(e);let t=Math.PI*2,n=this.points(),r=n,i=this.tension()!==0&&n.length>4;i&&(r=this.getTensionPoints());let a=this.pointerLength(),o=n.length,s,c;if(i){let e=[r[r.length-4],r[r.length-3],r[r.length-2],r[r.length-1],n[o-2],n[o-1]],t=Li.calcLength(r[r.length-4],r[r.length-3],`C`,e),i=Li.getPointOnQuadraticBezier(Math.min(1,1-a/t),e[0],e[1],e[2],e[3],e[4],e[5]);s=n[o-2]-i.x,c=n[o-1]-i.y}else s=n[o-2]-n[o-4],c=n[o-1]-n[o-3];let l=(Math.atan2(c,s)+t)%t,u=this.pointerWidth();this.pointerAtEnding()&&(e.save(),e.beginPath(),e.translate(n[o-2],n[o-1]),e.rotate(l),e.moveTo(0,0),e.lineTo(-a,u/2),e.lineTo(-a,-u/2),e.closePath(),e.restore(),this.__fillStroke(e)),this.pointerAtBeginning()&&(e.save(),e.beginPath(),e.translate(n[0],n[1]),i?(s=(r[0]+r[2])/2-n[0],c=(r[1]+r[3])/2-n[1]):(s=n[2]-n[0],c=n[3]-n[1]),e.rotate((Math.atan2(-c,-s)+t)%t),e.moveTo(0,0),e.lineTo(-a,u/2),e.lineTo(-a,-u/2),e.closePath(),e.restore(),this.__fillStroke(e))}__fillStroke(e){let t=this.dashEnabled();t&&(this.attrs.dashEnabled=!1,e.setLineDash([])),e.fillStrokeShape(this),t&&(this.attrs.dashEnabled=!0)}getSelfRect(){let e=super.getSelfRect(),t=this.pointerWidth()/2;return{x:e.x,y:e.y-t,width:e.width,height:e.height+t*2}}};Ri.prototype.className=`Arrow`,H(Ri),K.addGetterSetter(Ri,`pointerLength`,10,G()),K.addGetterSetter(Ri,`pointerWidth`,10,G()),K.addGetterSetter(Ri,`pointerAtBeginning`,!1),K.addGetterSetter(Ri,`pointerAtEnding`,!0);var zi=class extends Y{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.attrs.radius||0,0,Math.PI*2,!1),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(e){this.radius()!==e/2&&this.radius(e/2)}setHeight(e){this.radius()!==e/2&&this.radius(e/2)}};zi.prototype._centroid=!0,zi.prototype.className=`Circle`,zi.prototype._attrsAffectingSize=[`radius`],H(zi),K.addGetterSetter(zi,`radius`,0,G());var Bi=class extends Y{_sceneFunc(e){let t=this.radiusX(),n=this.radiusY();e.beginPath(),e.save(),t!==n&&e.scale(1,n/t),e.arc(0,0,t,0,Math.PI*2,!1),e.restore(),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.radiusX()*2}getHeight(){return this.radiusY()*2}setWidth(e){this.radiusX(e/2)}setHeight(e){this.radiusY(e/2)}};Bi.prototype.className=`Ellipse`,Bi.prototype._centroid=!0,Bi.prototype._attrsAffectingSize=[`radiusX`,`radiusY`],H(Bi),K.addComponentsGetterSetter(Bi,`radius`,[`x`,`y`]),K.addGetterSetter(Bi,`radiusX`,0,G()),K.addGetterSetter(Bi,`radiusY`,0,G());var Vi=class e extends Y{constructor(e){super(e),this._loadListener=()=>{this._requestDraw()},this.on(`imageChange.konva`,e=>{this._removeImageLoad(e.oldVal),this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){let e=this.image();e&&e.complete||e&&e.readyState===4||e&&e.addEventListener&&e.addEventListener(`load`,this._loadListener)}_removeImageLoad(e){e&&e.removeEventListener&&e.removeEventListener(`load`,this._loadListener)}destroy(){return this._removeImageLoad(this.image()),super.destroy(),this}_useBufferCanvas(){let e=!!this.cornerRadius(),t=this.hasShadow();return e&&t?!0:super._useBufferCanvas(!0)}_sceneFunc(e){let t=this.getWidth(),n=this.getHeight(),r=this.cornerRadius(),i=this.attrs.image,a;if(i){let e=this.attrs.cropWidth,r=this.attrs.cropHeight;a=e&&r?[i,this.cropX(),this.cropY(),e,r,0,0,t,n]:[i,0,0,t,n]}(this.hasFill()||this.hasStroke()||r)&&(e.beginPath(),r?U.drawRoundedRectPath(e,t,n,r):e.rect(0,0,t,n),e.closePath(),e.fillStrokeShape(this)),i&&(r&&e.clip(),e.drawImage.apply(e,a))}_hitFunc(e){let t=this.width(),n=this.height(),r=this.cornerRadius();e.beginPath(),r?U.drawRoundedRectPath(e,t,n,r):e.rect(0,0,t,n),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.attrs.width??this.image()?.width??0}getHeight(){return this.attrs.height??this.image()?.height??0}static fromURL(t,n,r=null){let i=U.createImageElement();i.onload=function(){n(new e({image:i}))},i.onerror=r,i.crossOrigin=`Anonymous`,i.src=t}};Vi.prototype.className=`Image`,Vi.prototype._attrsAffectingSize=[`image`],H(Vi),K.addGetterSetter(Vi,`cornerRadius`,0,bn(4)),K.addGetterSetter(Vi,`image`),K.addComponentsGetterSetter(Vi,`crop`,[`x`,`y`,`width`,`height`]),K.addGetterSetter(Vi,`cropX`,0,G()),K.addGetterSetter(Vi,`cropY`,0,G()),K.addGetterSetter(Vi,`cropWidth`,0,G()),K.addGetterSetter(Vi,`cropHeight`,0,G());var Hi=[`fontFamily`,`fontSize`,`fontStyle`,`padding`,`lineHeight`,`text`,`width`,`height`,`pointerDirection`,`pointerWidth`,`pointerHeight`],Ui=`Change.konva`,Wi=`none`,Gi=`up`,Ki=`right`,qi=`down`,Ji=`left`,Yi=Hi.length,Xi=class extends di{constructor(e){super(e),this.on(`add.konva`,function(e){this._addListeners(e.child),this._sync()})}getText(){return this.find(`Text`)[0]}getTag(){return this.find(`Tag`)[0]}_addListeners(e){let t=this,n,r=function(){t._sync()};for(n=0;n{t=Math.min(t,e.x),n=Math.max(n,e.x),r=Math.min(r,e.y),i=Math.max(i,e.y)}),{x:t,y:r,width:n-t,height:i-r}}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(e){this.radius(e/2)}setHeight(e){this.radius(e/2)}};$i.prototype.className=`RegularPolygon`,$i.prototype._centroid=!0,$i.prototype._attrsAffectingSize=[`radius`],H($i),K.addGetterSetter($i,`radius`,0,G()),K.addGetterSetter($i,`sides`,0,G()),K.addGetterSetter($i,`cornerRadius`,0,bn(4));var ea=Math.PI*2,ta=class extends Y{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.innerRadius(),0,ea,!1),e.moveTo(this.outerRadius(),0),e.arc(0,0,this.outerRadius(),ea,0,!0),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(e){this.outerRadius(e/2)}setHeight(e){this.outerRadius(e/2)}};ta.prototype.className=`Ring`,ta.prototype._centroid=!0,ta.prototype._attrsAffectingSize=[`innerRadius`,`outerRadius`],H(ta),K.addGetterSetter(ta,`innerRadius`,0,G()),K.addGetterSetter(ta,`outerRadius`,0,G());var na=class extends Y{constructor(e){super(e),this._updated=!0,this.anim=new pi(()=>{let e=this._updated;return this._updated=!1,e}),this.on(`animationChange.konva`,function(){this.frameIndex(0)}),this.on(`frameIndexChange.konva`,function(){this._updated=!0}),this.on(`frameRateChange.konva`,function(){this.anim.isRunning()&&(clearInterval(this.interval),this._setInterval())})}_sceneFunc(e){let t=this.animation(),n=this.frameIndex(),r=n*4,i=this.animations()[t],a=this.frameOffsets(),o=i[r+0],s=i[r+1],c=i[r+2],l=i[r+3],u=this.image();if((this.hasFill()||this.hasStroke())&&(e.beginPath(),e.rect(0,0,c,l),e.closePath(),e.fillStrokeShape(this)),u)if(a){let r=a[t],i=n*2;e.drawImage(u,o,s,c,l,r[i+0],r[i+1],c,l)}else e.drawImage(u,o,s,c,l,0,0,c,l)}_hitFunc(e){let t=this.animation(),n=this.frameIndex(),r=n*4,i=this.animations()[t],a=this.frameOffsets(),o=i[r+2],s=i[r+3];if(e.beginPath(),a){let r=a[t],i=n*2;e.rect(r[i+0],r[i+1],o,s)}else e.rect(0,0,o,s);e.closePath(),e.fillShape(this)}_useBufferCanvas(){return super._useBufferCanvas(!0)}_setInterval(){let e=this;this.interval=setInterval(function(){e._updateIndex()},1e3/this.frameRate())}start(){if(this.isRunning())return;let e=this.getLayer();this.anim.setLayers(e),this._setInterval(),this.anim.start()}stop(){this.anim.stop(),clearInterval(this.interval)}isRunning(){return this.anim.isRunning()}_updateIndex(){let e=this.frameIndex(),t=this.animation();e{if(/\p{Emoji}/u.test(t)){let i=r[n+1];i&&/\p{Emoji_Modifier}|\u200D/u.test(i)?(e.push(t+i),r[n+1]=``):e.push(t)}else/\p{Regional_Indicator}{2}/u.test(t+(r[n+1]||``))?e.push(t+r[n+1]):n>0&&/\p{Mn}|\p{Me}|\p{Mc}/u.test(t)?e[e.length-1]+=t:t&&e.push(t);return e},[])}var aa=`auto`,oa=`center`,sa=`inherit`,ca=`justify`,la=`Change.konva`,ua=`2d`,da=`-`,fa=`left`,pa=`text`,ma=`Text`,ha=`top`,ga=`bottom`,_a=`middle`,va=`normal`,ya=`px `,ba=` `,xa=`right`,Sa=`rtl`,Ca=`word`,wa=`char`,Ta=`none`,Ea=`…`,Da=[`direction`,`fontFamily`,`fontSize`,`fontStyle`,`fontVariant`,`padding`,`align`,`verticalAlign`,`lineHeight`,`text`,`width`,`height`,`wrap`,`ellipsis`,`letterSpacing`],Oa=Da.length,ka=null;function Aa(){if(ka!==null)return ka;ka=!1;try{let e=document.createElement(`canvas`);e.width=10,e.height=10;let t=e.getContext(ua);if(t){t.globalAlpha=0,t.shadowColor=`black`,t.shadowBlur=5,t.shadowOffsetX=5,t.shadowOffsetY=5,t.fillStyle=`black`,t.font=`10px Arial`,t.fillText(`X`,0,10);let e=t.getImageData(0,0,10,10).data;for(let t=3;t0){ka=!0;break}}}catch{}return ka}function ja(e){return e.split(`,`).map(e=>{e=e.trim();let t=e.indexOf(` `)>=0,n=e.indexOf(`"`)>=0||e.indexOf(`'`)>=0;return t&&!n&&(e=`"${e}"`),e}).join(`, `)}var Ma;function Na(){return Ma||(Ma=U.createCanvasElement().getContext(ua),Ma)}function Pa(e){e.fillText(this._partialText,this._partialTextX,this._partialTextY)}function Fa(e){e.setAttr(`miterLimit`,2),e.strokeText(this._partialText,this._partialTextX,this._partialTextY)}function Ia(e){return e||={},!e.fillLinearGradientColorStops&&!e.fillRadialGradientColorStops&&!e.fillPatternImage&&(e.fill=e.fill||`black`),e}var X=class extends Y{constructor(e){super(Ia(e)),this._partialTextX=0,this._partialTextY=0;for(let e=0;ee+ia(t.text).length,0);f({char:s,index:a+n,x:o,y:y+0,lineIndex:v,column:a,isLastInLine:x,width:this.measureSize(s).width,context:e})}e.fillStrokeShape(this),f&&e.restore(),o+=this.measureSize(s).width+d}}else d!==0&&e.setAttr(`letterSpacing`,`${d}px`),this._partialTextX=o,this._partialTextY=y+0,this._partialText=m,e.fillStrokeShape(this);if(_){e.save(),e.beginPath();let t=V.legacyTextRendering?0:-Math.round(i/4),n=S;e.moveTo(n,y+0+t);let a=l===ca&&!x?u-r*2:b;e.lineTo(n+Math.round(a),y+0+t),e.lineWidth=i/15,e.strokeStyle=this._getLinearGradient()||p,e.stroke(),e.restore()}e.restore(),n>1&&(y+=a)}}_hitFunc(e){let t=this.getWidth(),n=this.getHeight();e.beginPath(),e.rect(0,0,t,n),e.closePath(),e.fillStrokeShape(this)}setText(e){let t=U._isString(e)?e:e==null?``:e+``;return this._setAttr(pa,t),this}getWidth(){return this.attrs.width===aa||this.attrs.width===void 0?this.getTextWidth()+this.padding()*2:this.attrs.width}getHeight(){return this.attrs.height===aa||this.attrs.height===void 0?this.fontSize()*this.textArr.length*this.lineHeight()+this.padding()*2:this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return U.warn(`text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.`),this.textHeight}measureSize(e){let t=Na(),n=this.fontSize(),r;t.save(),t.font=this._getContextFont(),r=t.measureText(e),t.restore();let i=n/100;return{actualBoundingBoxAscent:r.actualBoundingBoxAscent??71.58203125*i,actualBoundingBoxDescent:r.actualBoundingBoxDescent??0,actualBoundingBoxLeft:r.actualBoundingBoxLeft??-7.421875*i,actualBoundingBoxRight:r.actualBoundingBoxRight??75.732421875*i,alphabeticBaseline:r.alphabeticBaseline??0,emHeightAscent:r.emHeightAscent??100*i,emHeightDescent:r.emHeightDescent??-20*i,fontBoundingBoxAscent:r.fontBoundingBoxAscent??91*i,fontBoundingBoxDescent:r.fontBoundingBoxDescent??21*i,hangingBaseline:r.hangingBaseline??72.80000305175781*i,ideographicBaseline:r.ideographicBaseline??-21*i,width:r.width,height:n}}_getContextFont(){return this.fontStyle()+ba+this.fontVariant()+ba+(this.fontSize()+ya)+ja(this.fontFamily())}_addTextLine(e){this.align()===ca&&(e=e.trim());let t=this._getTextWidth(e);return this.textArr.push({text:e,width:t,lastInParagraph:!1})}_getTextWidth(e){let t=this.letterSpacing(),n=e.length;return Na().measureText(e).width+t*n}_setTextData(){let e=this.text().split(` `),t=+this.fontSize(),n=0,r=this.lineHeight()*t,i=this.attrs.width,a=this.attrs.height,o=i!==aa&&i!==void 0,s=a!==aa&&a!==void 0,c=this.padding(),l=i-c*2,u=a-c*2,d=0,f=this.wrap(),p=f!==wa&&f!==Ta,m=this.ellipsis();this.textArr=[],Na().font=this._getContextFont();let h=m?this._getTextWidth(Ea):0;for(let t=0,i=e.length;tl)for(;a.length>0;){let e=0,t=ia(a).length,i=``,o=0;for(;e>>1,c=ia(a).slice(0,n+1).join(``),f=this._getTextWidth(c);(m&&s&&d+r>u?f+h:f)<=l?(e=n+1,i=c,o=f):t=n}if(i){if(p){let t=ia(a),n=ia(i),r=t[n.length],s=r===ba||r===da,c;if(s&&o<=l)c=n.length;else{let e=n.lastIndexOf(ba),t=n.lastIndexOf(da);c=Math.max(e,t)+1}c>0&&(e=c,i=t.slice(0,e).join(``),o=this._getTextWidth(i))}if(i=i.trimRight(),this._addTextLine(i),n=Math.max(n,o),d+=r,this._shouldHandleEllipsis(d)){this._tryToAddEllipsisToLastLine();break}if(a=ia(a).slice(e).join(``).trimLeft(),a.length>0&&(c=this._getTextWidth(a),c<=l)){this._addTextLine(a),d+=r,n=Math.max(n,c);break}}else break}else this._addTextLine(a),d+=r,n=Math.max(n,c),this._shouldHandleEllipsis(d)&&tu)break}this.textHeight=t,this.textWidth=n}_shouldHandleEllipsis(e){let t=+this.fontSize(),n=this.lineHeight()*t,r=this.attrs.height,i=r!==aa&&r!==void 0,a=r-this.padding()*2;return this.wrap()===Ta||i&&e+n>a}_tryToAddEllipsisToLastLine(){let e=this.attrs.width,t=e!==aa&&e!==void 0,n=e-this.padding()*2,r=this.ellipsis(),i=this.textArr[this.textArr.length-1];!i||!r||(t&&(this._getTextWidth(i.text+Ea)this.pathLength?null:Li.getPointAtLengthOfDataArray(e,this.dataArray)}_readDataAttribute(){this.dataArray=Li.parsePathData(this.attrs.data),this.pathLength=this._getTextPathLength()}_sceneFunc(e){e.setAttr(`font`,this._getContextFont()),e.setAttr(`textBaseline`,this.textBaseline()),e.setAttr(`textAlign`,`left`),e.save();let t=this.textDecoration(),n=this.fill(),r=this.fontSize(),i=this.glyphInfo,a=t.indexOf(`underline`)!==-1,o=t.indexOf(`line-through`)!==-1;a&&e.beginPath();for(let t=0;t=1){let n=t[0].p0;e.moveTo(n.x,n.y)}for(let n=0;nthis.pathLength&&f-this.pathLength<=c?this.pathLength:f);if(!p)return;let m=Li.getLineLength(r.x,r.y,p.x,p.y),h=0;if(s)try{h=s(t[n-1].char,i)*this.fontSize()}catch{h=0}r.x+=h,p.x+=h,this.textWidth+=h;let g=Li.getPointOnLine(h+m/2,r.x,r.y,p.x,p.y),_=Math.atan2(p.y-r.y,p.x-r.x);this.glyphInfo.push({transposeX:g.x,transposeY:g.y,text:e[n],rotation:_,p0:r,p1:p,width:m}),d+=u}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};let e=[];this.glyphInfo.forEach(function(t){e.push(t.p0.x),e.push(t.p0.y),e.push(t.p1.x),e.push(t.p1.y)});let t=e[0]||0,n=e[0]||0,r=e[1]||0,i=e[1]||0,a,o;for(let s=0;se+`.${Ha}`).join(` `),Wa=`nodesRect`,Ga=[`widthChange`,`heightChange`,`scaleXChange`,`scaleYChange`,`skewXChange`,`skewYChange`,`rotationChange`,`offsetXChange`,`offsetYChange`,`transformsEnabledChange`,`strokeWidthChange`,`draggableChange`],Ka={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},qa=`ontouchstart`in V._global;function Ja(e,t,n){if(e===`rotater`)return n;t+=U.degToRad(Ka[e]||0);let r=(U.radToDeg(t)%360+360)%360;return U._inRange(r,337.5,360)||U._inRange(r,0,22.5)?`ns-resize`:U._inRange(r,22.5,67.5)?`nesw-resize`:U._inRange(r,67.5,112.5)?`ew-resize`:U._inRange(r,112.5,157.5)?`nwse-resize`:U._inRange(r,157.5,202.5)?`ns-resize`:U._inRange(r,202.5,247.5)?`nesw-resize`:U._inRange(r,247.5,292.5)?`ew-resize`:U._inRange(r,292.5,337.5)?`nwse-resize`:(U.error(`Transformer has unknown angle for cursor detection: `+r),`pointer`)}var Ya=[`top-left`,`top-center`,`top-right`,`middle-right`,`middle-left`,`bottom-left`,`bottom-center`,`bottom-right`];function Xa(e){return{x:e.x+e.width/2*Math.cos(e.rotation)+e.height/2*Math.sin(-e.rotation),y:e.y+e.height/2*Math.cos(e.rotation)+e.width/2*Math.sin(e.rotation)}}function Za(e,t,n){let r=n.x+(e.x-n.x)*Math.cos(t)-(e.y-n.y)*Math.sin(t),i=n.y+(e.x-n.x)*Math.sin(t)+(e.y-n.y)*Math.cos(t);return{...e,rotation:e.rotation+t,x:r,y:i}}function Qa(e,t){return Za(e,t,Xa(e))}function $a(e,t,n){let r=t;for(let i=0;ie.isAncestorOf(this)?(U.error(`Konva.Transformer cannot be an a child of the node you are trying to attach`),!1):!0);return this._nodes=e=t,e.length===1&&this.useSingleNodeRotation()?this.rotation(e[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach(e=>{let t=()=>{this.nodes().length===1&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),!this._transforming&&!this.isDragging()&&this.update()};if(e._attrsAffectingSize.length){let n=e._attrsAffectingSize.map(e=>e+`Change.`+this._getEventNamespace()).join(` `);e.on(n,t)}e.on(Ga.map(e=>e+`.${this._getEventNamespace()}`).join(` `),t),e.on(`absoluteTransformChange.${this._getEventNamespace()}`,t),this._proxyDrag(e)}),this._resetTransformCache(),this.findOne(`.top-left`)&&this.update(),this}_proxyDrag(e){let t;e.on(`dragstart.${this._getEventNamespace()}`,n=>{t=e.getAbsolutePosition(),!this.isDragging()&&e!==this.findOne(`.back`)&&this.startDrag(n,!1)}),e.on(`dragmove.${this._getEventNamespace()}`,n=>{if(!t)return;let r=e.getAbsolutePosition(),i=r.x-t.x,a=r.y-t.y;this.nodes().forEach(t=>{if(t===e||t.isDragging())return;let r=t.getAbsolutePosition();t.setAbsolutePosition({x:r.x+i,y:r.y+a}),t.startDrag(n)}),t=null})}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){this._nodes&&this._nodes.forEach(e=>{e.off(`.`+this._getEventNamespace())}),this._nodes=[],this._resetTransformCache()}_resetTransformCache(){this._clearCache(Wa),this._clearCache(`transform`),this._clearSelfAndDescendantCache(`absoluteTransform`)}_getNodeRect(){return this._getCache(Wa,this.__getNodeRect)}__getNodeShape(e,t=this.rotation(),n){let r=e.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),i=e.getAbsoluteScale(n),a=e.getAbsolutePosition(n),o=r.x*i.x-e.offsetX()*i.x,s=r.y*i.y-e.offsetY()*i.y,c=(V.getAngle(e.getAbsoluteRotation())+Math.PI*2)%(Math.PI*2);return Za({x:a.x+o*Math.cos(c)+s*Math.sin(-c),y:a.y+s*Math.cos(c)+o*Math.sin(c),width:r.width*i.x,height:r.height*i.y,rotation:c},-V.getAngle(t),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};let e=[];this.nodes().map(t=>{let n=t.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),r=[{x:n.x,y:n.y},{x:n.x+n.width,y:n.y},{x:n.x+n.width,y:n.y+n.height},{x:n.x,y:n.y+n.height}],i=t.getAbsoluteTransform();r.forEach(function(t){let n=i.point(t);e.push(n)})});let t=new jt;t.rotate(-V.getAngle(this.rotation()));let n=1/0,r=1/0,i=-1/0,a=-1/0;e.forEach(function(e){let o=t.point(e);n===void 0&&(n=i=o.x,r=a=o.y),n=Math.min(n,o.x),r=Math.min(r,o.y),i=Math.max(i,o.x),a=Math.max(a,o.y)}),t.invert();let o=t.point({x:n,y:r});return{x:o.x,y:o.y,width:i-n,height:a-r,rotation:V.getAngle(this.rotation())}}getX(){return this._getNodeRect().x}getY(){return this._getNodeRect().y}getWidth(){return this._getNodeRect().width}getHeight(){return this._getNodeRect().height}_createElements(){this._createBack(),Ya.forEach(e=>{this._createAnchor(e)}),this._createAnchor(`rotater`),this._elementsCreated=!0}_createAnchor(e){let t=new Qi({stroke:`rgb(0, 161, 255)`,fill:`white`,strokeWidth:1,name:e+` _anchor`,dragDistance:0,draggable:!0,hitStrokeWidth:qa?10:`auto`}),n=this;t.on(`mousedown touchstart`,function(e){n._handleMouseDown(e)}),t.on(`dragstart`,e=>{t.stopDrag(),e.cancelBubble=!0}),t.on(`dragend`,e=>{e.cancelBubble=!0}),t.on(`mouseenter`,()=>{let n=Ja(e,V.getAngle(this.rotation()),this.rotateAnchorCursor());t.getStage().content&&(t.getStage().content.style.cursor=n),this._cursorChange=!0}),t.on(`mouseout`,()=>{t.getStage().content&&(t.getStage().content.style.cursor=``),this._cursorChange=!1}),this.add(t)}_createBack(){let e=new Y({name:`back`,width:0,height:0,sceneFunc(e,t){let n=t.getParent(),r=n.padding(),i=t.width(),a=t.height();if(e.beginPath(),e.rect(-r,-r,i+r*2,a+r*2),n.rotateEnabled()&&n.rotateLineVisible()){let t=n.rotateAnchorAngle(),r=n.rotateAnchorOffset(),o=U.degToRad(t),s=Math.sin(o),c=-Math.cos(o),l=i/2,u=a/2,d=1/0;c<0?d=Math.min(d,-u/c):c>0&&(d=Math.min(d,(a-u)/c)),s<0?d=Math.min(d,-l/s):s>0&&(d=Math.min(d,(i-l)/s));let f=l+s*d,p=u+c*d,m=U._sign(a),h=f+s*r*m,g=p+c*r*m;e.moveTo(f,p),e.lineTo(h,g)}e.fillStrokeShape(t)},hitFunc:(e,t)=>{if(!this.shouldOverdrawWholeArea())return;let n=this.padding();e.beginPath(),e.rect(-n,-n,t.width()+n*2,t.height()+n*2),e.fillStrokeShape(t)}});this.add(e),this._proxyDrag(e),e.on(`dragstart`,e=>{e.cancelBubble=!0}),e.on(`dragmove`,e=>{e.cancelBubble=!0}),e.on(`dragend`,e=>{e.cancelBubble=!0}),this.on(`dragmove`,e=>{this.update()})}_handleMouseDown(e){if(this._transforming)return;this._movingAnchorName=e.target.name().split(` `)[0];let t=this._getNodeRect(),n=t.width,r=t.height,i=Math.sqrt(n**2+r**2);this.sin=Math.abs(r/i),this.cos=Math.abs(n/i),typeof window<`u`&&(window.addEventListener(`mousemove`,this._handleMouseMove),window.addEventListener(`touchmove`,this._handleMouseMove),window.addEventListener(`mouseup`,this._handleMouseUp,!0),window.addEventListener(`touchend`,this._handleMouseUp,!0)),this._transforming=!0;let a=e.target.getAbsolutePosition(),o=e.target.getStage().getPointerPosition();this._anchorDragOffset={x:o.x-a.x,y:o.y-a.y},eo++,this._fire(`transformstart`,{evt:e.evt,target:this.getNode()}),this._nodes.forEach(t=>{t._fire(`transformstart`,{evt:e.evt,target:t})})}_handleMouseMove(e){let t,n,r,i=this.findOne(`.`+this._movingAnchorName),a=i.getStage();a.setPointersPositions(e);let o=a.getPointerPosition(),s={x:o.x-this._anchorDragOffset.x,y:o.y-this._anchorDragOffset.y},c=i.getAbsolutePosition();this.anchorDragBoundFunc()&&(s=this.anchorDragBoundFunc()(c,s,e)),i.setAbsolutePosition(s);let l=i.getAbsolutePosition();if(c.x===l.x&&c.y===l.y)return;if(this._movingAnchorName===`rotater`){let r=this._getNodeRect();t=i.x()-r.width/2,n=-i.y()+r.height/2;let a=V.getAngle(this.rotateAnchorAngle()),o=Math.atan2(-n,t)+Math.PI/2-a;r.height<0&&(o-=Math.PI);let s=V.getAngle(this.rotation())+o,c=V.getAngle(this.rotationSnapTolerance()),l=Qa(r,$a(this.rotationSnaps(),s,c)-r.rotation);this._fitNodesInto(l,e);return}let u=this.shiftBehavior(),d;d=u===`inverted`?this.keepRatio()&&!e.shiftKey:u===`none`?this.keepRatio():this.keepRatio()||e.shiftKey;let f=this.centeredScaling()||e.altKey;if(this._movingAnchorName===`top-left`){if(d){let e=f?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(`.bottom-right`).x(),y:this.findOne(`.bottom-right`).y()};r=Math.sqrt((e.x-i.x())**2+(e.y-i.y())**2);let a=this.findOne(`.top-left`).x()>e.x?-1:1,o=this.findOne(`.top-left`).y()>e.y?-1:1;t=r*this.cos*a,n=r*this.sin*o,this.findOne(`.top-left`).x(e.x-t),this.findOne(`.top-left`).y(e.y-n)}}else if(this._movingAnchorName===`top-center`)this.findOne(`.top-left`).y(i.y());else if(this._movingAnchorName===`top-right`){if(d){let e=f?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(`.bottom-left`).x(),y:this.findOne(`.bottom-left`).y()};r=Math.sqrt((i.x()-e.x)**2+(e.y-i.y())**2);let a=this.findOne(`.top-right`).x()e.y?-1:1;t=r*this.cos*a,n=r*this.sin*o,this.findOne(`.top-right`).x(e.x+t),this.findOne(`.top-right`).y(e.y-n)}var p=i.position();this.findOne(`.top-left`).y(p.y),this.findOne(`.bottom-right`).x(p.x)}else if(this._movingAnchorName===`middle-left`)this.findOne(`.top-left`).x(i.x());else if(this._movingAnchorName===`middle-right`)this.findOne(`.bottom-right`).x(i.x());else if(this._movingAnchorName===`bottom-left`){if(d){let e=f?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(`.top-right`).x(),y:this.findOne(`.top-right`).y()};r=Math.sqrt((e.x-i.x())**2+(i.y()-e.y)**2);let a=e.x{var n;t._fire(`transformend`,{evt:e,target:t}),(n=t.getLayer())==null||n.batchDraw()}),this._movingAnchorName=null}}_fitNodesInto(e,t){let n=this._getNodeRect();if(U._inRange(e.width,-this.padding()*2-1,1)){this.update();return}if(U._inRange(e.height,-this.padding()*2-1,1)){this.update();return}let r=new jt;if(r.rotate(V.getAngle(this.rotation())),this._movingAnchorName&&e.width<0&&this._movingAnchorName.indexOf(`left`)>=0){let t=r.point({x:-this.padding()*2,y:0});e.x+=t.x,e.y+=t.y,e.width+=this.padding()*2,this._movingAnchorName=this._movingAnchorName.replace(`left`,`right`),this._anchorDragOffset.x-=t.x,this._anchorDragOffset.y-=t.y}else if(this._movingAnchorName&&e.width<0&&this._movingAnchorName.indexOf(`right`)>=0){let t=r.point({x:this.padding()*2,y:0});this._movingAnchorName=this._movingAnchorName.replace(`right`,`left`),this._anchorDragOffset.x-=t.x,this._anchorDragOffset.y-=t.y,e.width+=this.padding()*2}if(this._movingAnchorName&&e.height<0&&this._movingAnchorName.indexOf(`top`)>=0){let t=r.point({x:0,y:-this.padding()*2});e.x+=t.x,e.y+=t.y,this._movingAnchorName=this._movingAnchorName.replace(`top`,`bottom`),this._anchorDragOffset.x-=t.x,this._anchorDragOffset.y-=t.y,e.height+=this.padding()*2}else if(this._movingAnchorName&&e.height<0&&this._movingAnchorName.indexOf(`bottom`)>=0){let t=r.point({x:0,y:this.padding()*2});this._movingAnchorName=this._movingAnchorName.replace(`bottom`,`top`),this._anchorDragOffset.x-=t.x,this._anchorDragOffset.y-=t.y,e.height+=this.padding()*2}if(this.boundBoxFunc()){let t=this.boundBoxFunc()(n,e);t?e=t:U.warn(`boundBoxFunc returned falsy. You should return new bound rect from it!`)}let i=1e7,a=new jt;a.translate(n.x,n.y),a.rotate(n.rotation),a.scale(n.width/i,n.height/i);let o=new jt,s=e.width/i,c=e.height/i;this.flipEnabled()===!1?(o.translate(e.x,e.y),o.rotate(e.rotation),o.translate(e.width<0?e.width:0,e.height<0?e.height:0),o.scale(Math.abs(s),Math.abs(c))):(o.translate(e.x,e.y),o.rotate(e.rotation),o.scale(s,c));let l=o.multiply(a.invert());this._nodes.forEach(e=>{var t;if(!e.getStage())return;let n=e.getParent().getAbsoluteTransform(),r=e.getTransform().copy();r.translate(e.offsetX(),e.offsetY());let i=new jt;i.multiply(n.copy().invert()).multiply(l).multiply(n).multiply(r);let a=i.decompose();e.setAttrs(a),(t=e.getLayer())==null||t.batchDraw()}),this.rotation(U._getRotation(e.rotation)),this._nodes.forEach(e=>{this._fire(`transform`,{evt:t,target:e}),e._fire(`transform`,{evt:t,target:e})}),this._resetTransformCache(),this.update(),this.getLayer().batchDraw()}forceUpdate(){this._resetTransformCache(),this.update()}_batchChangeChild(e,t){this.findOne(e).setAttrs(t)}update(){var e;let t=this._getNodeRect();this.rotation(U._getRotation(t.rotation));let n=t.width,r=t.height,i=this.enabledAnchors(),a=this.resizeEnabled(),o=this.padding(),s=this.anchorSize(),c=this.find(`._anchor`);c.forEach(e=>{e.setAttrs({width:s,height:s,offsetX:s/2,offsetY:s/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})}),this._batchChangeChild(`.top-left`,{x:0,y:0,offsetX:s/2+o,offsetY:s/2+o,visible:a&&i.indexOf(`top-left`)>=0}),this._batchChangeChild(`.top-center`,{x:n/2,y:0,offsetY:s/2+o,visible:a&&i.indexOf(`top-center`)>=0}),this._batchChangeChild(`.top-right`,{x:n,y:0,offsetX:s/2-o,offsetY:s/2+o,visible:a&&i.indexOf(`top-right`)>=0}),this._batchChangeChild(`.middle-left`,{x:0,y:r/2,offsetX:s/2+o,visible:a&&i.indexOf(`middle-left`)>=0}),this._batchChangeChild(`.middle-right`,{x:n,y:r/2,offsetX:s/2-o,visible:a&&i.indexOf(`middle-right`)>=0}),this._batchChangeChild(`.bottom-left`,{x:0,y:r,offsetX:s/2+o,offsetY:s/2-o,visible:a&&i.indexOf(`bottom-left`)>=0}),this._batchChangeChild(`.bottom-center`,{x:n/2,y:r,offsetY:s/2-o,visible:a&&i.indexOf(`bottom-center`)>=0}),this._batchChangeChild(`.bottom-right`,{x:n,y:r,offsetX:s/2-o,offsetY:s/2-o,visible:a&&i.indexOf(`bottom-right`)>=0});let l=this.rotateAnchorAngle(),u=this.rotateAnchorOffset(),d=U.degToRad(l),f=Math.sin(d),p=-Math.cos(d),m=n/2,h=r/2,g=1/0;p<0?g=Math.min(g,-h/p):p>0&&(g=Math.min(g,(r-h)/p)),f<0?g=Math.min(g,-m/f):f>0&&(g=Math.min(g,(n-m)/f));let _=m+f*g,v=h+p*g,y=U._sign(r);this._batchChangeChild(`.rotater`,{x:_+f*u*y,y:v+p*u*y-o*p,visible:this.rotateEnabled()}),this._batchChangeChild(`.back`,{width:n,height:r,visible:this.borderEnabled(),stroke:this.borderStroke(),strokeWidth:this.borderStrokeWidth(),dash:this.borderDash(),draggable:this.nodes().some(e=>e.draggable()),x:0,y:0});let b=this.anchorStyleFunc();b&&c.forEach(e=>{b(e)}),(e=this.getLayer())==null||e.batchDraw()}isTransforming(){return this._transforming}stopTransform(){if(this._transforming){this._removeEvents();let e=this.findOne(`.`+this._movingAnchorName);e&&e.stopDrag()}}destroy(){return this.getStage()&&this._cursorChange&&this.getStage().content&&(this.getStage().content.style.cursor=``),di.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}add(...e){return this._elementsCreated?(U.error(`You cannot add external nodes to the Transformer. Use tr.nodes([node]) instead.`),this):super.add(...e)}toObject(){return q.prototype.toObject.call(this)}clone(e){return q.prototype.clone.call(this,e)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}};Z.isTransforming=()=>eo>0;function to(e){return e instanceof Array||U.warn(`enabledAnchors value should be an array`),e instanceof Array&&e.forEach(function(e){Ya.indexOf(e)===-1&&U.warn(`Unknown anchor name: `+e+`. Available names are: `+Ya.join(`, `))}),e||[]}Z.prototype.className=`Transformer`,H(Z),K.addGetterSetter(Z,`enabledAnchors`,Ya,to),K.addGetterSetter(Z,`flipEnabled`,!0,Tn()),K.addGetterSetter(Z,`resizeEnabled`,!0),K.addGetterSetter(Z,`anchorSize`,10,G()),K.addGetterSetter(Z,`rotateEnabled`,!0),K.addGetterSetter(Z,`rotateLineVisible`,!0),K.addGetterSetter(Z,`rotationSnaps`,[]),K.addGetterSetter(Z,`rotateAnchorOffset`,50,G()),K.addGetterSetter(Z,`rotateAnchorAngle`,0,G()),K.addGetterSetter(Z,`rotateAnchorCursor`,`crosshair`),K.addGetterSetter(Z,`rotationSnapTolerance`,5,G()),K.addGetterSetter(Z,`borderEnabled`,!0),K.addGetterSetter(Z,`anchorStroke`,`rgb(0, 161, 255)`),K.addGetterSetter(Z,`anchorStrokeWidth`,1,G()),K.addGetterSetter(Z,`anchorFill`,`white`),K.addGetterSetter(Z,`anchorCornerRadius`,0,G()),K.addGetterSetter(Z,`borderStroke`,`rgb(0, 161, 255)`),K.addGetterSetter(Z,`borderStrokeWidth`,1,G()),K.addGetterSetter(Z,`borderDash`),K.addGetterSetter(Z,`keepRatio`,!0),K.addGetterSetter(Z,`shiftBehavior`,`default`),K.addGetterSetter(Z,`centeredScaling`,!1),K.addGetterSetter(Z,`ignoreStroke`,!1),K.addGetterSetter(Z,`padding`,0,G()),K.addGetterSetter(Z,`nodes`),K.addGetterSetter(Z,`node`),K.addGetterSetter(Z,`boundBoxFunc`),K.addGetterSetter(Z,`anchorDragBoundFunc`),K.addGetterSetter(Z,`anchorStyleFunc`),K.addGetterSetter(Z,`shouldOverdrawWholeArea`,!1),K.addGetterSetter(Z,`useSingleNodeRotation`,!0),K.backCompat(Z,{lineEnabled:`borderEnabled`,rotateHandlerOffset:`rotateAnchorOffset`,enabledHandlers:`enabledAnchors`});var no=class extends Y{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.radius(),0,V.getAngle(this.angle()),this.clockwise()),e.lineTo(0,0),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(e){this.radius(e/2)}setHeight(e){this.radius(e/2)}};no.prototype.className=`Wedge`,no.prototype._centroid=!0,no.prototype._attrsAffectingSize=[`radius`],H(no),K.addGetterSetter(no,`radius`,0,G()),K.addGetterSetter(no,`angle`,0,G()),K.addGetterSetter(no,`clockwise`,!1),K.backCompat(no,{angleDeg:`angle`,getAngleDeg:`getAngle`,setAngleDeg:`setAngle`});function ro(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}var io=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],ao=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function oo(e,t){let n=e.data,r=e.width,i=e.height,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,ee=t+t+1,T=r-1,te=i-1,E=t+1,D=E*(E+1)/2,O=new ro,k=io[t],A=ao[t],ne=null,j=O,M=null,N=null;for(let e=1;e>A,C===0?n[o]=n[o+1]=n[o+2]=0:(C=255/C,n[o]=(c*k>>A)*C,n[o+1]=(l*k>>A)*C,n[o+2]=(u*k>>A)*C),c-=f,l-=p,u-=m,d-=h,f-=M.r,p-=M.g,m-=M.b,h-=M.a,a=s+((a=e+t+1)>A,C>0?(C=255/C,n[a]=(c*k>>A)*C,n[a+1]=(l*k>>A)*C,n[a+2]=(u*k>>A)*C):n[a]=n[a+1]=n[a+2]=0,c-=f,l-=p,u-=m,d-=h,f-=M.r,p-=M.g,m-=M.b,h-=M.a,a=e+((a=t+E)0&&oo(e,t)};K.addGetterSetter(q,`blurRadius`,0,G(),K.afterSetFilter);var co=function(e){let t=this.brightness()*255,n=e.data,r=n.length;for(let e=0;e255?255:i,a=a<0?0:a>255?255:a,o=o<0?0:o>255?255:o,n[e]=i,n[e+1]=a,n[e+2]=o};K.addGetterSetter(q,`contrast`,0,G(),K.afterSetFilter);var fo=function(e){let t=e.data,n=e.width,r=e.height,i=Math.min(1,Math.max(0,this.embossStrength?.call(this)??.5)),a=Math.min(1,Math.max(0,this.embossWhiteLevel?.call(this)??.5)),o={"top-left":315,top:270,"top-right":225,right:180,"bottom-right":135,bottom:90,"bottom-left":45,left:0}[this.embossDirection?.call(this)??`top-left`]??315,s=!!(this.embossBlend?.call(this)??!1),c=i*10,l=a*255,u=o*Math.PI/180,d=Math.cos(u),f=Math.sin(u),p=128/1020*c,m=new Uint8ClampedArray(t),h=new Float32Array(n*r);for(let e=0,n=0;ne<0?0:e>255?255:e;for(let e=1;ei&&(i=a),c=t[e+1],cs&&(s=c),d=t[e+2],du&&(u=d);i===r&&(i=255,r=0),s===o&&(s=255,o=0),u===l&&(u=255,l=0);let p,m,h,g,_,v;if(f>0)p=i+f*(255-i),m=r-f*(r-0),h=s+f*(255-s),g=o-f*(o-0),_=u+f*(255-u),v=l-f*(l-0);else{let e=(i+r)*.5;p=i+f*(i-e),m=r+f*(r-e);let t=(s+o)*.5;h=s+f*(s-t),g=o+f*(o-t);let n=(u+l)*.5;_=u+f*(u-n),v=l+f*(l-n)}for(let e=0;el?f:l;let p=o,m=a,h=360/m*Math.PI/180;for(let e=0;el?f:l;let p=o,m=a,h=n.polarRotation||0,g,_;for(u=0;ut&&(b=y,x=0,S=-1),i=0;i=0&&d=0&&f=0&&d=0&&f=1020?255:0}return o}function ko(e,t,n){let r=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],i=Math.round(Math.sqrt(r.length)),a=Math.floor(i/2),o=[];for(let s=0;s=0&&d=0&&f=n))for(let t=f;t=r)continue;let i=(n*t+e)*4;a+=o[i+0],s+=o[i+1],c+=o[i+2],l+=o[i+3],m+=1}a/=m,s/=m,c/=m,l/=m;for(let e=u;e=n))for(let t=f;t=r)continue;let i=(n*t+e)*4;o[i+0]=a,o[i+1]=s,o[i+2]=c,o[i+3]=l}}};K.addGetterSetter(q,`pixelSize`,8,G(),K.afterSetFilter);var No=function(e){let t=Math.round(this.levels()*254)+1,n=e.data,r=n.length,i=255/t;for(let e=0;e255?255:e<0?0:Math.round(e)}),K.addGetterSetter(q,`green`,0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),K.addGetterSetter(q,`blue`,0,yn,K.afterSetFilter);var Fo=function(e){let t=e.data,n=t.length,r=this.red(),i=this.green(),a=this.blue(),o=this.alpha();for(let e=0;e255?255:e<0?0:Math.round(e)}),K.addGetterSetter(q,`green`,0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),K.addGetterSetter(q,`blue`,0,yn,K.afterSetFilter),K.addGetterSetter(q,`alpha`,1,function(e){return this._filterUpToDate=!1,e>1?1:e<0?0:e});var Io=function(e){let t=e.data,n=t.length;for(let e=0;e=128&&(t[e]=255-n,t[e+1]=255-r,t[e+2]=255-i)}return e},Ro=function(e){let t=this.threshold()*255,n=e.data,r=n.length;for(let e=0;e=2?`120/240V`:`120V`,fontSize:11,fontFamily:`system-ui, Arial, sans-serif`,fill:`#71717a`,listening:!1}));let c=s.width/(o+1),l={side:`top`,shellWidth:s.width,shellHeight:s.height},u=[`blue`,`red`,`blue`,`red`],d=[];for(let e=1;e<=r;e+=1){let t=`l`+e,n=e===1?R.L1:e===2?R.L2:t;d.push($(a,c*e,-16,t,`L`+e,{role:n,wireColor:u[(e-1)%u.length],labelPlacement:`above`,...l}))}return d.push($(a,c*(r+1),-16,`n`,`N`,{role:R.NEUTRAL,wireColor:`gray`,labelPlacement:`above`,...l})),d.push($(a,c*(r+2),-16,`g`,`G`,{role:R.GROUND,wireColor:`green`,labelPlacement:`above`,...l})),a.powerLegs=r,a.powerKind=i,Wo(a,et.POWER,Bo(`power`),d),a}function Ts(e,t,n){let r=new Q.Group({x:t,y:n}),i=Yo(r,120,100,e||`Receptacle`),a=i.width/2;r.add(new Q.Rect({x:a-18,y:28,width:36,height:48,fill:`#fafafa`,stroke:`#a1a1aa`,strokeWidth:2,cornerRadius:4,listening:!1})),r.add(new Q.Rect({x:a-10,y:36,width:6,height:14,fill:`#52525b`,listening:!1})),r.add(new Q.Rect({x:a+4,y:36,width:6,height:14,fill:`#52525b`,listening:!1})),r.add(new Q.Circle({x:a,y:62,radius:3,fill:`#52525b`,listening:!1}));let o=i.height+16,s=i.width/4,c={side:`bottom`,shellWidth:i.width,shellHeight:i.height},l=[$(r,s,o,`hot`,`Hot`,{role:R.LOAD_HOT,wireColor:`red`,labelPlacement:`below`,...c}),$(r,s*2,o,`n`,`N`,{role:R.LOAD_NEUTRAL,wireColor:`gray`,labelPlacement:`below`,...c}),$(r,s*3,o,`g`,`G`,{role:R.GROUND,wireColor:`green`,labelPlacement:`below`,...c})];return Wo(r,et.RECEPTACLE,Bo(`receptacle`),l),r}function Es(e,t,n){let r=new Q.Group({x:t,y:n}),i=us(r,110,88,e||`Switch`);ds(r,1),fs(r,i.width,`Open`),ps(r,i.width);let a=i.width/3,o=i.width/3*2,s={side:`top`,shellWidth:i.width,shellHeight:i.height},c=[$(r,a,-16,`com`,`COM`,{role:R.SWITCH_COM,wireColor:`gray`,labelPlacement:`above`,...s}),$(r,o,-16,`no`,`NO`,{role:R.SWITCH_NO,wireColor:`red`,labelPlacement:`above`,...s})];return r.isSwitch=!0,r.isToggle=!0,r.switchKind=`spst`,r.isClosed=!1,r.isPressed=!1,Wo(r,et.SWITCH,Bo(`switch`),c),bs(r),xs(r,{closed:!1}),r}function Ds(e,t){let n=new Q.Group({x:e,y:t}),r=Yo(n,280,78,`Terminal Block`),i=r.height+16,a=r.width/4,o=r.width/5,s={side:`top`,shellWidth:r.width,shellHeight:r.height},c={side:`bottom`,shellWidth:r.width,shellHeight:r.height},l=[$(n,a,-16,`l1`,`L1`,{role:R.L1,wireColor:`blue`,labelPlacement:`above`,...s}),$(n,a*2,-16,`n`,`N`,{role:R.NEUTRAL,wireColor:`gray`,labelPlacement:`above`,...s}),$(n,a*3,-16,`g`,`G`,{role:R.GROUND,wireColor:`green`,labelPlacement:`above`,...s}),$(n,o,i,`com`,`COM`,{role:R.COM_24V,wireColor:`gray`,labelPlacement:`below`,...c}),$(n,o*2,i,`sig-f`,`F`,{role:R.JUNCTION,wireColor:`red`,labelPlacement:`below`,...c}),$(n,o*3,i,`sig-r`,`R`,{role:R.JUNCTION,wireColor:`red`,labelPlacement:`below`,...c}),$(n,o*4,i,`sig-s`,`S`,{role:R.JUNCTION,wireColor:`red`,labelPlacement:`below`,...c})];return Wo(n,et.TERMINAL_BLOCK,Bo(`terminal-block`),l),n}function Os(e,t,n){let r=new Q.Group({x:t,y:n}),i=us(r,130,88,e||`3-Way`);ds(r,1),fs(r,i.width,`T1`),ms(r,i.width);let a=i.width/4,o={side:`top`,shellWidth:i.width,shellHeight:i.height},s=[$(r,a,-16,`t1`,`T1`,{role:R.TRAVELER_1,wireColor:`red`,labelPlacement:`above`,...o}),$(r,a*2,-16,`com`,`COM`,{role:R.SWITCH_COM,wireColor:`blue`,labelPlacement:`above`,...o}),$(r,a*3,-16,`t2`,`T2`,{role:R.TRAVELER_2,wireColor:`red`,labelPlacement:`above`,...o})];return r.isSwitch=!0,r.isToggle=!0,r.switchKind=`three-way`,r.isClosed=!1,r.isPressed=!1,Wo(r,et.THREE_WAY,Bo(`three-way`),s),bs(r),xs(r,{closed:!1}),r}function ks(e,t){let n=new Q.Group({x:e,y:t}),r=Yo(n,150,110,`Transformer`);n.add(new Q.Line({points:[16,55,r.width-16,55],stroke:`#e4e4e7`,strokeWidth:1,dash:[4,4],listening:!1})),n.add(new Q.Text({x:14,y:62,text:`120V`,fontSize:11,fontFamily:`system-ui, Arial, sans-serif`,fill:`#71717a`,listening:!1})),n.add(new Q.Text({x:100,y:28,text:`24V`,fontSize:11,fontFamily:`system-ui, Arial, sans-serif`,fill:`#71717a`,listening:!1})),Zo(n,28,78);let i=r.height+16,a={side:`top`,shellWidth:r.width,shellHeight:r.height},o={side:`bottom`,shellWidth:r.width,shellHeight:r.height},s=[$(n,104,-16,`sec-hot`,`24V`,{role:R.HOT_24V,wireColor:`red`,labelPlacement:`above`,...a}),$(n,130,-16,`sec-com`,`COM`,{role:R.COM_24V,wireColor:`gray`,labelPlacement:`above`,...a}),$(n,24,i,`pri-l1`,`L1`,{role:R.L1,wireColor:`blue`,labelPlacement:`below`,...o}),$(n,50,i,`pri-n`,`N`,{role:R.NEUTRAL,wireColor:`gray`,labelPlacement:`below`,...o}),$(n,76,i,`pri-g`,`G`,{role:R.GROUND,wireColor:`green`,labelPlacement:`below`,...o})];return Wo(n,et.TRANSFORMER,Bo(`transformer`),s),n}var As={power:function(e){return ws(e.x,e.y,{legs:e.legs,kind:e.kind})},transformer:function(e){return ks(e.x,e.y)},chime:function(e){return as(e.x,e.y)},"terminal-block":function(e){return Ds(e.x,e.y)},terminalBlock:function(e){return Ds(e.x,e.y)},button:function(e){return ns(e.label||e.id,e.x,e.y)},switch:function(e){return Es(e.label||e.id,e.x,e.y)},"three-way":function(e){return Os(e.label||e.id,e.x,e.y)},threeWay:function(e){return Os(e.label||e.id,e.x,e.y)},"four-way":function(e){return Ss(e.label||e.id,e.x,e.y)},fourWay:function(e){return Ss(e.label||e.id,e.x,e.y)},lamp:function(e){return is(e.label||e.id,e.x,e.y)},receptacle:function(e){return Ts(e.label||e.id,e.x,e.y)},gfci:function(e){return Cs(e.label||e.id,e.x,e.y)}};function js(e){let t=e.type,n=As[t];if(!n)throw Error(`Unknown component type "`+t+`" for id "`+e.id+`".`);return n(e)}function Ms(e,t,n,r){let i={width:t,height:n,margin:e.margin},a={};for(let t=0;tn?(t+n)/2:Math.min(n,Math.max(t,e))}function zs(e){return Math.min(3,Math.max(Ns,e))}function Bs(e,t,n){if(t.width<=0||t.height<=0)return e;let r=e.scale,i=72-n.maxX*r,a=t.width-72-n.minX*r,o=72-n.maxY*r,s=t.height-72-n.minY*r;return{scale:r,x:Rs(e.x,i,a),y:Rs(e.y,o,s)}}function Vs(e){return{minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height}}function Hs(e,t,n,r,i){let a=zs(n),o={x:(t.x-e.x)/e.scale,y:(t.y-e.y)/e.scale};return Bs({scale:a,x:t.x-o.x*a,y:t.y-o.y*a},r,i)}function Us(e,t){return{x:(e.x-t.x)/t.scale,y:(e.y-t.y)/t.scale}}function Ws(e,t){return{x:e.x*t.scale+t.x,y:e.y*t.scale+t.y}}function Gs(e,t){let n=e.deltaX,r=e.deltaY;return e.deltaMode===1?(n*=16,r*=16):e.deltaMode===2&&(n*=t.width,r*=t.height),{deltaX:n,deltaY:r}}function Ks(e,t){e.scale({x:t.scale,y:t.scale}),e.position({x:t.x,y:t.y})}function qs(e,t){let n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)}function Js(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function Ys(e,t){let n=[];for(let r=0;r0)||!(i>0))return e;let s=Hs(e,r,e.scale*(i/n),a,o);return Bs({scale:s.scale,x:s.x+(r.x-t.x),y:s.y+(r.y-t.y)},a,o)}var Zs=.4;function Qs(e,t,n,r){let i=Math.hypot(t.x-e.x,t.y-e.y),a=Math.hypot(n.x-t.x,n.y-t.y),o=i+a;if(o===0)return[t,t];let s=r*i/o,c=r*a/o;return[{x:t.x-s*(n.x-e.x),y:t.y-s*(n.y-e.y)},{x:t.x+c*(n.x-e.x),y:t.y+c*(n.y-e.y)}]}function $s(e,t,n,r){let i=1-r;return{x:i*i*e.x+2*i*r*t.x+r*r*n.x,y:i*i*e.y+2*i*r*t.y+r*r*n.y}}function ec(e,t,n,r,i){let a=1-i,o=a*a,s=i*i;return{x:o*a*e.x+3*o*i*t.x+3*a*s*n.x+s*i*r.x,y:o*a*e.y+3*o*i*t.y+3*a*s*n.y+s*i*r.y}}function tc(e,t){if(e.length<2)return[];if(t===0||e.length===2){let t=[];for(let n=0;n0)}function g(e,t){typeof a==`function`&&a(e,t||null)}function _(e){let t=Uo(e);return(t&&t.componentId?t.componentId:`unknown`)+`:`+e.id}function v(e,t){let n=_(e),r=_(t);for(let e=0;e50&&l.shift(),h())}function x(){l.length=0,h()}function S(){let e=[];for(let t=0;t0}function E(){d&&d.node&&(d.node.stroke(`#000000`),d.node.strokeWidth(2)),d=null,j()}function D(e){E(),d=e,e.node.stroke(`#2563eb`),e.node.strokeWidth(3)}function O(t){let n=Ho(t.from,e),r=Ho(t.to,e);return[n].concat(t.bends,[r])}function k(e){let t=O(e),n=[];for(let e=0;e=t.bends.length||(t.bends[c].x=r.x,t.bends[c].y=r.y,A(t),t.handles&&t.handles[c]&&t.handles[c].position(t.bends[c]),e.batchDraw())}}function u(){i.off(`.wireMidpoint`),s&&(ae(t),m()),e.batchDraw()}i.on(`mousemove.wireMidpoint touchmove.wireMidpoint`,l),i.on(`mouseup.wireMidpoint touchend.wireMidpoint`,u)}function ae(t){N(t),t.handles=[],t.midHandles=[],re(t);for(let n=0;n=t.bends.length||(b(),t.bends.splice(n,1),A(t),u===t&&(ae(t),g(t,null)),m(),e.batchDraw())}function le(){for(let e=0;e0;){let e=c.pop();N(e),e.understroke&&e.understroke.destroy(),e.line.destroy()}m(),e.batchDraw()}function I(t){if(typeof o==`function`){f=!0,he();for(let e=0;e`+(o?``:``)+`
`;if(i){t+=`
`;for(let e=0;e`}t+=`
`}n.innerHTML=t}function p(e,t){c={x:e.x,y:e.y},l={width:t.width,height:t.height},n.hidden=!1;let r=n.offsetWidth,i=n.offsetHeight;if(r<=0||i<=0){n.style.left=e.x+`px`,n.style.top=e.y+`px`;return}let a=e.y-i-dc;at.height-fc&&(a=Math.max(fc,t.height-fc-i));let o=e.x-r/2;o=Math.min(Math.max(o,fc),Math.max(fc,t.width-fc-r)),n.style.left=o+`px`,n.style.top=a+`px`}function m(e){a=e.colorKey,o=e.canDelete!==!1,s={x:e.world.x,y:e.world.y},i=!1,f(),p(e.screen,e.viewport)}function h(e,t){n.hidden||!s||p(e(s),t)}function g(e,t,r){a=e,f(),!n.hidden&&s&&t&&r&&p(t(s),r)}function _(){n.hidden||(n.hidden=!0,i=!1,s=null,u=!0,window.setTimeout(function(){u=!1},0))}function v(){return!n.hidden}function y(){return u||!n.hidden}n.addEventListener(`click`,function(e){let n=e.target;if(!(n instanceof Element))return;let r=n.closest(`[data-wire-menu], [data-wire-menu-color]`);if(!(r instanceof HTMLElement))return;e.stopPropagation();let o=r.getAttribute(`data-wire-menu`);if(o===`delete`){t.onDelete();return}if(o===`close`){t.onDismiss();return}if(o===`toggle-color`){i=!i,f(),c&&l&&p(c,l);return}let s=r.getAttribute(`data-wire-menu-color`);s&&(i=!1,a=s,f(),c&&l&&p(c,l),t.onPickColor(s))});function b(e){let t=typeof e.composedPath==`function`?e.composedPath():[];for(let e=0;e0){let n=[];for(let r=0;r0;){let t=e[a.shift()]||[];for(let e=0;e0?t.closed.slice():t.switch?[t.switch]:[],a=r(e.simulate(n).energized),o=(t.energize||[]).slice().sort();return{ok:i(a,o),lit:a,expected:o,switchId:t.switch||(n.length?n.join(`+`):`(none)`),closedIds:n}}function l(e){let t=e.closedIds&&e.closedIds.length>1?`Closing [`+e.closedIds.join(`, `)+`]`:e.closedIds&&e.closedIds.length===0?`With all switches open/default`:`Closing `+e.switchId;return e.lit.length===0?e.expected.length===0?t+` should leave all loads off, but the check failed unexpectedly.`:t+` does not energize [`+e.expected.join(`, `)+`].`:t+` energized [`+e.lit.join(`, `)+`] — expected [`+e.expected.join(`, `)+`].`}function u(){let e=[];if(!n)return e.push(`This lab has no grading rules configured.`),{pass:!1,failures:e};let t=a();if(t.length>0)return e.push(`Missing components: `+t.join(`, `)),{pass:!1,failures:e};let r=o();for(let t=0;t=e.length){o=!1,m.disabled=!1,ee(n===`demo`?t.hints.demo:t.hints.lab),Le();return}let r=e[i];if(i+=1,r.isToggle){let e=!!r.isClosed;Re(r),window.setTimeout(function(){if(!s()){o=!1,m.disabled=!1;return}r.isClosed!==e&&Re(r),window.setTimeout(c,280)},550);return}Fe(r,!0),Ie(r),window.setTimeout(function(){if(!s()){o=!1,m.disabled=!1;return}Fe(r,!1),Le(),window.setTimeout(c,280)},550)}c()}function Ke(){if(n!==`lab`)return;let e=ye.grade();e.pass?ee(t.passMessage,`pass`):ee(`Fail — `+e.failures.join(` `),`fail`)}function qe(){L.canUndo()&&L.undo()}f.addEventListener(`click`,function(){Ae(`demo`)}),p.addEventListener(`click`,function(){Ae(`lab`)}),m.addEventListener(`click`,Ge),h.addEventListener(`click`,Ke),g.addEventListener(`click`,qe),b&&b.addEventListener(`click`,function(){ie(1/Ps)}),x&&x.addEventListener(`click`,function(){ie(Ps)}),S&&S.addEventListener(`click`,ae);function Je(e){e.evt.preventDefault();let t=M(),n=Gs(e.evt,t);if(e.evt.ctrlKey||e.evt.metaKey){let e=T.getPointerPosition();if(!e)return;P(Hs(D,e,D.scale*Math.exp(-n.deltaY*Fs),t,O));return}P({scale:D.scale,x:D.x-n.deltaX,y:D.y-n.deltaY})}function Ye(e){if(e.target!==T)return;e.evt.preventDefault();let t=T.getPointerPosition();if(!t)return;let n={x:t.x,y:t.y},r={scale:D.scale,x:D.x,y:D.y},i=!1;function a(e){if(e.evt.touches&&e.evt.touches.length>=2){j();return}e.evt.preventDefault();let t=T.getPointerPosition();if(!t)return;let a=t.x-n.x,o=t.y-n.y;if(!i){if(a*a+o*o<16)return;i=!0,k=!0,_&&_.classList.add(`lab-stage-wrap--panning`),T.container().style.cursor=`grabbing`}P({scale:r.scale,x:r.x+a,y:r.y+o})}function o(){j()}T.on(`mousemove.stagePan touchmove.stagePan`,a),T.on(`mouseup.stagePan touchend.stagePan`,o)}function Xe(e){let t=e.evt.touches;if(!t||t.length<2)return;e.evt.preventDefault(),j(),k=!0;let n=Ys(t,T.container().getBoundingClientRect()),r=Js(n[0],n[1]),i=qs(n[0],n[1]);if(!A||!(ne>0)){let t=e.target;for(;t&&t!==T;)t.isDragging&&t.isDragging()&&t.stopDrag(),t=t.getParent();A=r,ne=i;return}P(Xs(D,A,ne,r,i,M(),O)),A=r,ne=i}function Ze(e){let t=e.evt.touches;(!t||t.length<2)&&(A=null,ne=0)}T.on(`wheel`,Je),T.on(`mousedown touchstart`,Ye),T.on(`touchmove`,Xe),T.on(`touchend touchcancel`,Ze),T.on(`click tap`,function(e){if(e.target===T){if(k){k=!1;return}L.clearWireSelection(),L.clearPendingHighlight(),te.batchDraw(),E.batchDraw()}}),window.addEventListener(`keydown`,function(e){if((e.metaKey||e.ctrlKey)&&(e.key===`z`||e.key===`Z`)){e.shiftKey||(e.preventDefault(),qe());return}n===`lab`&&((e.key===`Delete`||e.key===`Backspace`)&&L.removeSelectedWire()&&e.preventDefault(),e.key===`Escape`&&(L.clearPendingHighlight(),L.clearWireSelection(),te.batchDraw(),E.batchDraw()))});function Qe(){w();let t=u?u.offsetHeight:52;T.width(e.clientWidth||window.innerWidth),T.height(Math.max(200,(e.clientHeight||window.innerHeight)-t)),re(),P(D),L.updateWirePositions(),T.batchDraw()}window.addEventListener(`resize`,Qe),Ue(),We(t.defaultWireColor),N(),we(),De()}var vc=`data-circuit-lab-styles`,yc=`circuit-lab-styles`,bc=`:host { display: block; box-sizing: border-box; width: 100%; height: 100%; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; font-size: 14px; line-height: 1.4; color: #1a1a1a; background: #fafafa; } *, *::before, *::after { box-sizing: border-box; } .circuit-lab-ui { display: flex; flex-direction: column; width: 100%; height: 100%; font: inherit; color: inherit; } .lab-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; padding: 10px 16px; background: #fff; border-bottom: 1px solid #d4d4d8; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06); } .lab-toolbar h1 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; color: inherit; } .toolbar-group { display: flex; align-items: center; gap: 6px; } .toolbar-label { font-size: 12px; font-weight: 600; color: #71717a; text-transform: uppercase; letter-spacing: 0.04em; } .toolbar-divider { width: 1px; height: 24px; background: #e4e4e7; flex-shrink: 0; } .toolbar-btn { padding: 6px 12px; border: 1px solid #d4d4d8; border-radius: 6px; background: #fff; color: #1a1a1a; font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; transition: background 0.12s, border-color 0.12s, color 0.12s; } .toolbar-btn:hover { background: #f4f4f5; border-color: #a1a1aa; } .toolbar-btn.active { background: #2563eb; border-color: #2563eb; color: #fff; } .toolbar-btn.active:hover { background: #1d4ed8; border-color: #1d4ed8; } .toolbar-btn:disabled { opacity: 0.45; cursor: not-allowed; } .lab-btn-test { background: #16a34a; border-color: #16a34a; color: #fff; font-weight: 600; } .lab-btn-test:hover:not(:disabled) { background: #15803d; border-color: #15803d; } .lab-btn-check { background: #7c3aed; border-color: #7c3aed; color: #fff; font-weight: 600; } .lab-btn-check:hover:not(:disabled) { background: #6d28d9; border-color: #6d28d9; } .lab-hint { flex: 1 1 220px; margin: 0; font-size: 12px; color: #71717a; line-height: 1.4; min-width: 0; } .lab-hint.pass { color: #15803d; font-weight: 600; } .lab-hint.fail { color: #b91c1c; font-weight: 600; } .toolbar-zoom-label { min-width: 3.25rem; text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; color: #52525b; } .lab-stage-wrap { position: relative; flex: 1 1 auto; width: 100%; min-height: 0; overflow: hidden; cursor: grab; /* Let Konva own touch pans/zooms instead of the browser scrolling the page. */ touch-action: none; overscroll-behavior: none; /* FigJam-style soft canvas with a subtle dotted grid. */ background-color: #e8e8e8; background-image: radial-gradient( circle, rgba(0, 0, 0, 0.14) 1px, transparent 1px ); background-size: 24px 24px; } .lab-stage-wrap--panning { cursor: grabbing; } .lab-stage { width: 100%; height: 100%; } .lab-stage canvas { touch-action: none; } .wire-menu { position: absolute; z-index: 5; display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 4px; border: 1px solid #d4d4d8; border-radius: 8px; background: #ffffff; box-shadow: 0 4px 14px rgba(24, 24, 27, 0.14), 0 1px 3px rgba(24, 24, 27, 0.08); pointer-events: auto; } .wire-menu[hidden] { display: none; } .wire-menu-row { display: flex; flex-direction: row; align-items: center; gap: 2px; } .wire-menu-item { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 6px; padding: 0; background: transparent; color: #3f3f46; cursor: pointer; } .wire-menu-item:hover { background: #f4f4f5; } .wire-menu-item--danger { color: #dc2626; } .wire-menu-item--danger:hover { background: #fef2f2; color: #b91c1c; } .wire-menu-color-trigger { display: flex; align-items: center; justify-content: center; gap: 4px; height: 32px; border: 0; border-radius: 6px; padding: 0 6px; background: transparent; color: #71717a; cursor: pointer; } .wire-menu-color-trigger:hover { background: #f4f4f5; } .wire-menu-color-trigger[aria-expanded="true"] { background: #f4f4f5; } .wire-menu-color-trigger[aria-expanded="true"] svg { transform: rotate(180deg); } .wire-menu-colors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 2px; } .wire-menu-swatch { display: inline-block; width: 22px; height: 22px; border: 1px solid rgba(24, 24, 27, 0.2); border-radius: 999px; padding: 0; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35); } button.wire-menu-swatch:hover { outline: 2px solid #a1a1aa; outline-offset: 1px; } .wire-menu-swatch--selected { outline: 2px solid #18181b; outline-offset: 1px; } .circuit-lab-error { margin: 0; padding: 16px; font: inherit; color: #b91c1c; }`;function xc(e){if(typeof document>`u`)return;let t=e||document;if(t instanceof ShadowRoot){if(t.querySelector(`style[data-circuit-lab-styles]`))return;let e=document.createElement(`style`);e.setAttribute(vc,``),e.textContent=bc,t.appendChild(e);return}if(document.getElementById(yc))return;let n=document.createElement(`style`);n.id=yc,n.setAttribute(vc,``),n.textContent=bc,document.head.appendChild(n)}function Sc(e){if(e==null)return null;let t=String(e).trim();return t?/^\d+(\.\d+)?$/.test(t)?t+`px`:t:null}function Cc(e){let t=Sc(e.getAttribute(`width`)),n=Sc(e.getAttribute(`height`));t?e.style.width=t:e.style.removeProperty(`width`),n?e.style.height=n:e.style.removeProperty(`height`)}var wc=`data-circuit-lab-mounted`;function Tc(){let e=document.createElement(`div`);return e.className=`circuit-lab-ui`,e.innerHTML=`

Mode
100%

`,e}function Ec(e){let t=document.createElement(`div`);t.className=`circuit-lab`,t.setAttribute(wc,``);let n=e.getAttribute(`width`),r=e.getAttribute(`height`);return n!=null&&t.setAttribute(`width`,n),r!=null&&t.setAttribute(`height`,r),Cc(t),t}function Dc(e,t){e.replaceChildren(),xc(e);let n=document.createElement(`p`);n.className=`circuit-lab-error`,n.textContent=`circuit-lab config error: `+(t&&t.message?t.message:t),e.appendChild(n)}function Oc(e){if(!(e instanceof HTMLElement)||e.getAttribute(wc)!=null)return null;let t;try{t=Tt(e)}catch(t){let n=Ec(e);return e.replaceWith(n),Dc(n.attachShadow({mode:`open`}),t),n}let n=Ec(e);e.replaceWith(n);let r=n.attachShadow({mode:`open`});return xc(r),r.appendChild(Tc()),_c(n,t),n}function kc(e){let t=e||document;if(!t||!t.querySelectorAll)return[];let n=t.querySelectorAll(`pre.circuit-lab`),r=[];for(let e=0;e