diff --git a/konva.js b/konva.js index 08deff43..0ea0fce8 100644 --- a/konva.js +++ b/konva.js @@ -8,7 +8,7 @@ * Konva JavaScript Framework v8.4.3 * http://konvajs.org/ * Licensed under the MIT - * Date: Thu Mar 23 2023 + * Date: Wed Apr 05 2023 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) @@ -10295,6 +10295,806 @@ * line.points(line.points().concat([70, 80])); */ + // Credits: rveciana/svg-path-properties + // Legendre-Gauss abscissae (xi values, defined at i=n as the roots of the nth order Legendre polynomial Pn(x)) + const tValues = [ + [], + [], + [ + -0.5773502691896257645091487805019574556476, + 0.5773502691896257645091487805019574556476, + ], + [ + 0, -0.7745966692414833770358530799564799221665, + 0.7745966692414833770358530799564799221665, + ], + [ + -0.3399810435848562648026657591032446872005, + 0.3399810435848562648026657591032446872005, + -0.8611363115940525752239464888928095050957, + 0.8611363115940525752239464888928095050957, + ], + [ + 0, -0.5384693101056830910363144207002088049672, + 0.5384693101056830910363144207002088049672, + -0.9061798459386639927976268782993929651256, + 0.9061798459386639927976268782993929651256, + ], + [ + 0.6612093864662645136613995950199053470064, + -0.6612093864662645136613995950199053470064, + -0.2386191860831969086305017216807119354186, + 0.2386191860831969086305017216807119354186, + -0.9324695142031520278123015544939946091347, + 0.9324695142031520278123015544939946091347, + ], + [ + 0, 0.4058451513773971669066064120769614633473, + -0.4058451513773971669066064120769614633473, + -0.7415311855993944398638647732807884070741, + 0.7415311855993944398638647732807884070741, + -0.9491079123427585245261896840478512624007, + 0.9491079123427585245261896840478512624007, + ], + [ + -0.1834346424956498049394761423601839806667, + 0.1834346424956498049394761423601839806667, + -0.5255324099163289858177390491892463490419, + 0.5255324099163289858177390491892463490419, + -0.7966664774136267395915539364758304368371, + 0.7966664774136267395915539364758304368371, + -0.9602898564975362316835608685694729904282, + 0.9602898564975362316835608685694729904282, + ], + [ + 0, -0.8360311073266357942994297880697348765441, + 0.8360311073266357942994297880697348765441, + -0.9681602395076260898355762029036728700494, + 0.9681602395076260898355762029036728700494, + -0.3242534234038089290385380146433366085719, + 0.3242534234038089290385380146433366085719, + -0.6133714327005903973087020393414741847857, + 0.6133714327005903973087020393414741847857, + ], + [ + -0.1488743389816312108848260011297199846175, + 0.1488743389816312108848260011297199846175, + -0.4333953941292471907992659431657841622, + 0.4333953941292471907992659431657841622, + -0.6794095682990244062343273651148735757692, + 0.6794095682990244062343273651148735757692, + -0.8650633666889845107320966884234930485275, + 0.8650633666889845107320966884234930485275, + -0.9739065285171717200779640120844520534282, + 0.9739065285171717200779640120844520534282, + ], + [ + 0, -0.2695431559523449723315319854008615246796, + 0.2695431559523449723315319854008615246796, + -0.5190961292068118159257256694586095544802, + 0.5190961292068118159257256694586095544802, + -0.7301520055740493240934162520311534580496, + 0.7301520055740493240934162520311534580496, + -0.8870625997680952990751577693039272666316, + 0.8870625997680952990751577693039272666316, + -0.9782286581460569928039380011228573907714, + 0.9782286581460569928039380011228573907714, + ], + [ + -0.1252334085114689154724413694638531299833, + 0.1252334085114689154724413694638531299833, + -0.3678314989981801937526915366437175612563, + 0.3678314989981801937526915366437175612563, + -0.587317954286617447296702418940534280369, + 0.587317954286617447296702418940534280369, + -0.7699026741943046870368938332128180759849, + 0.7699026741943046870368938332128180759849, + -0.9041172563704748566784658661190961925375, + 0.9041172563704748566784658661190961925375, + -0.9815606342467192506905490901492808229601, + 0.9815606342467192506905490901492808229601, + ], + [ + 0, -0.2304583159551347940655281210979888352115, + 0.2304583159551347940655281210979888352115, + -0.4484927510364468528779128521276398678019, + 0.4484927510364468528779128521276398678019, + -0.6423493394403402206439846069955156500716, + 0.6423493394403402206439846069955156500716, + -0.8015780907333099127942064895828598903056, + 0.8015780907333099127942064895828598903056, + -0.9175983992229779652065478365007195123904, + 0.9175983992229779652065478365007195123904, + -0.9841830547185881494728294488071096110649, + 0.9841830547185881494728294488071096110649, + ], + [ + -0.1080549487073436620662446502198347476119, + 0.1080549487073436620662446502198347476119, + -0.3191123689278897604356718241684754668342, + 0.3191123689278897604356718241684754668342, + -0.5152486363581540919652907185511886623088, + 0.5152486363581540919652907185511886623088, + -0.6872929048116854701480198030193341375384, + 0.6872929048116854701480198030193341375384, + -0.8272013150697649931897947426503949610397, + 0.8272013150697649931897947426503949610397, + -0.928434883663573517336391139377874264477, + 0.928434883663573517336391139377874264477, + -0.986283808696812338841597266704052801676, + 0.986283808696812338841597266704052801676, + ], + [ + 0, -0.2011940939974345223006283033945962078128, + 0.2011940939974345223006283033945962078128, + -0.3941513470775633698972073709810454683627, + 0.3941513470775633698972073709810454683627, + -0.5709721726085388475372267372539106412383, + 0.5709721726085388475372267372539106412383, + -0.7244177313601700474161860546139380096308, + 0.7244177313601700474161860546139380096308, + -0.8482065834104272162006483207742168513662, + 0.8482065834104272162006483207742168513662, + -0.9372733924007059043077589477102094712439, + 0.9372733924007059043077589477102094712439, + -0.9879925180204854284895657185866125811469, + 0.9879925180204854284895657185866125811469, + ], + [ + -0.0950125098376374401853193354249580631303, + 0.0950125098376374401853193354249580631303, + -0.281603550779258913230460501460496106486, + 0.281603550779258913230460501460496106486, + -0.45801677765722738634241944298357757354, + 0.45801677765722738634241944298357757354, + -0.6178762444026437484466717640487910189918, + 0.6178762444026437484466717640487910189918, + -0.7554044083550030338951011948474422683538, + 0.7554044083550030338951011948474422683538, + -0.8656312023878317438804678977123931323873, + 0.8656312023878317438804678977123931323873, + -0.9445750230732325760779884155346083450911, + 0.9445750230732325760779884155346083450911, + -0.9894009349916499325961541734503326274262, + 0.9894009349916499325961541734503326274262, + ], + [ + 0, -0.1784841814958478558506774936540655574754, + 0.1784841814958478558506774936540655574754, + -0.3512317634538763152971855170953460050405, + 0.3512317634538763152971855170953460050405, + -0.5126905370864769678862465686295518745829, + 0.5126905370864769678862465686295518745829, + -0.6576711592166907658503022166430023351478, + 0.6576711592166907658503022166430023351478, + -0.7815140038968014069252300555204760502239, + 0.7815140038968014069252300555204760502239, + -0.8802391537269859021229556944881556926234, + 0.8802391537269859021229556944881556926234, + -0.9506755217687677612227169578958030214433, + 0.9506755217687677612227169578958030214433, + -0.9905754753144173356754340199406652765077, + 0.9905754753144173356754340199406652765077, + ], + [ + -0.0847750130417353012422618529357838117333, + 0.0847750130417353012422618529357838117333, + -0.2518862256915055095889728548779112301628, + 0.2518862256915055095889728548779112301628, + -0.4117511614628426460359317938330516370789, + 0.4117511614628426460359317938330516370789, + -0.5597708310739475346078715485253291369276, + 0.5597708310739475346078715485253291369276, + -0.6916870430603532078748910812888483894522, + 0.6916870430603532078748910812888483894522, + -0.8037049589725231156824174550145907971032, + 0.8037049589725231156824174550145907971032, + -0.8926024664975557392060605911271455154078, + 0.8926024664975557392060605911271455154078, + -0.9558239495713977551811958929297763099728, + 0.9558239495713977551811958929297763099728, + -0.9915651684209309467300160047061507702525, + 0.9915651684209309467300160047061507702525, + ], + [ + 0, -0.1603586456402253758680961157407435495048, + 0.1603586456402253758680961157407435495048, + -0.3165640999636298319901173288498449178922, + 0.3165640999636298319901173288498449178922, + -0.4645707413759609457172671481041023679762, + 0.4645707413759609457172671481041023679762, + -0.6005453046616810234696381649462392798683, + 0.6005453046616810234696381649462392798683, + -0.7209661773352293786170958608237816296571, + 0.7209661773352293786170958608237816296571, + -0.8227146565371428249789224867127139017745, + 0.8227146565371428249789224867127139017745, + -0.9031559036148179016426609285323124878093, + 0.9031559036148179016426609285323124878093, + -0.960208152134830030852778840687651526615, + 0.960208152134830030852778840687651526615, + -0.9924068438435844031890176702532604935893, + 0.9924068438435844031890176702532604935893, + ], + [ + -0.0765265211334973337546404093988382110047, + 0.0765265211334973337546404093988382110047, + -0.227785851141645078080496195368574624743, + 0.227785851141645078080496195368574624743, + -0.3737060887154195606725481770249272373957, + 0.3737060887154195606725481770249272373957, + -0.5108670019508270980043640509552509984254, + 0.5108670019508270980043640509552509984254, + -0.6360536807265150254528366962262859367433, + 0.6360536807265150254528366962262859367433, + -0.7463319064601507926143050703556415903107, + 0.7463319064601507926143050703556415903107, + -0.8391169718222188233945290617015206853296, + 0.8391169718222188233945290617015206853296, + -0.9122344282513259058677524412032981130491, + 0.9122344282513259058677524412032981130491, + -0.963971927277913791267666131197277221912, + 0.963971927277913791267666131197277221912, + -0.9931285991850949247861223884713202782226, + 0.9931285991850949247861223884713202782226, + ], + [ + 0, -0.1455618541608950909370309823386863301163, + 0.1455618541608950909370309823386863301163, + -0.288021316802401096600792516064600319909, + 0.288021316802401096600792516064600319909, + -0.4243421202074387835736688885437880520964, + 0.4243421202074387835736688885437880520964, + -0.551618835887219807059018796724313286622, + 0.551618835887219807059018796724313286622, + -0.667138804197412319305966669990339162597, + 0.667138804197412319305966669990339162597, + -0.7684399634756779086158778513062280348209, + 0.7684399634756779086158778513062280348209, + -0.8533633645833172836472506385875676702761, + 0.8533633645833172836472506385875676702761, + -0.9200993341504008287901871337149688941591, + 0.9200993341504008287901871337149688941591, + -0.9672268385663062943166222149076951614246, + 0.9672268385663062943166222149076951614246, + -0.9937521706203895002602420359379409291933, + 0.9937521706203895002602420359379409291933, + ], + [ + -0.0697392733197222212138417961186280818222, + 0.0697392733197222212138417961186280818222, + -0.2078604266882212854788465339195457342156, + 0.2078604266882212854788465339195457342156, + -0.3419358208920842251581474204273796195591, + 0.3419358208920842251581474204273796195591, + -0.4693558379867570264063307109664063460953, + 0.4693558379867570264063307109664063460953, + -0.5876404035069115929588769276386473488776, + 0.5876404035069115929588769276386473488776, + -0.6944872631866827800506898357622567712673, + 0.6944872631866827800506898357622567712673, + -0.7878168059792081620042779554083515213881, + 0.7878168059792081620042779554083515213881, + -0.8658125777203001365364256370193787290847, + 0.8658125777203001365364256370193787290847, + -0.9269567721871740005206929392590531966353, + 0.9269567721871740005206929392590531966353, + -0.9700604978354287271239509867652687108059, + 0.9700604978354287271239509867652687108059, + -0.994294585482399292073031421161298980393, + 0.994294585482399292073031421161298980393, + ], + [ + 0, -0.1332568242984661109317426822417661370104, + 0.1332568242984661109317426822417661370104, + -0.264135680970344930533869538283309602979, + 0.264135680970344930533869538283309602979, + -0.390301038030290831421488872880605458578, + 0.390301038030290831421488872880605458578, + -0.5095014778460075496897930478668464305448, + 0.5095014778460075496897930478668464305448, + -0.6196098757636461563850973116495956533871, + 0.6196098757636461563850973116495956533871, + -0.7186613631319501944616244837486188483299, + 0.7186613631319501944616244837486188483299, + -0.8048884016188398921511184069967785579414, + 0.8048884016188398921511184069967785579414, + -0.8767523582704416673781568859341456716389, + 0.8767523582704416673781568859341456716389, + -0.9329710868260161023491969890384229782357, + 0.9329710868260161023491969890384229782357, + -0.9725424712181152319560240768207773751816, + 0.9725424712181152319560240768207773751816, + -0.9947693349975521235239257154455743605736, + 0.9947693349975521235239257154455743605736, + ], + [ + -0.0640568928626056260850430826247450385909, + 0.0640568928626056260850430826247450385909, + -0.1911188674736163091586398207570696318404, + 0.1911188674736163091586398207570696318404, + -0.3150426796961633743867932913198102407864, + 0.3150426796961633743867932913198102407864, + -0.4337935076260451384870842319133497124524, + 0.4337935076260451384870842319133497124524, + -0.5454214713888395356583756172183723700107, + 0.5454214713888395356583756172183723700107, + -0.6480936519369755692524957869107476266696, + 0.6480936519369755692524957869107476266696, + -0.7401241915785543642438281030999784255232, + 0.7401241915785543642438281030999784255232, + -0.8200019859739029219539498726697452080761, + 0.8200019859739029219539498726697452080761, + -0.8864155270044010342131543419821967550873, + 0.8864155270044010342131543419821967550873, + -0.9382745520027327585236490017087214496548, + 0.9382745520027327585236490017087214496548, + -0.9747285559713094981983919930081690617411, + 0.9747285559713094981983919930081690617411, + -0.9951872199970213601799974097007368118745, + 0.9951872199970213601799974097007368118745, + ], + ]; + // Legendre-Gauss weights (wi values, defined by a function linked to in the Bezier primer article) + const cValues = [ + [], + [], + [1.0, 1.0], + [ + 0.8888888888888888888888888888888888888888, + 0.5555555555555555555555555555555555555555, + 0.5555555555555555555555555555555555555555, + ], + [ + 0.6521451548625461426269360507780005927646, + 0.6521451548625461426269360507780005927646, + 0.3478548451374538573730639492219994072353, + 0.3478548451374538573730639492219994072353, + ], + [ + 0.5688888888888888888888888888888888888888, + 0.4786286704993664680412915148356381929122, + 0.4786286704993664680412915148356381929122, + 0.2369268850561890875142640407199173626432, + 0.2369268850561890875142640407199173626432, + ], + [ + 0.3607615730481386075698335138377161116615, + 0.3607615730481386075698335138377161116615, + 0.4679139345726910473898703439895509948116, + 0.4679139345726910473898703439895509948116, + 0.1713244923791703450402961421727328935268, + 0.1713244923791703450402961421727328935268, + ], + [ + 0.4179591836734693877551020408163265306122, + 0.3818300505051189449503697754889751338783, + 0.3818300505051189449503697754889751338783, + 0.2797053914892766679014677714237795824869, + 0.2797053914892766679014677714237795824869, + 0.1294849661688696932706114326790820183285, + 0.1294849661688696932706114326790820183285, + ], + [ + 0.3626837833783619829651504492771956121941, + 0.3626837833783619829651504492771956121941, + 0.3137066458778872873379622019866013132603, + 0.3137066458778872873379622019866013132603, + 0.2223810344533744705443559944262408844301, + 0.2223810344533744705443559944262408844301, + 0.1012285362903762591525313543099621901153, + 0.1012285362903762591525313543099621901153, + ], + [ + 0.3302393550012597631645250692869740488788, + 0.1806481606948574040584720312429128095143, + 0.1806481606948574040584720312429128095143, + 0.0812743883615744119718921581105236506756, + 0.0812743883615744119718921581105236506756, + 0.3123470770400028400686304065844436655987, + 0.3123470770400028400686304065844436655987, + 0.2606106964029354623187428694186328497718, + 0.2606106964029354623187428694186328497718, + ], + [ + 0.295524224714752870173892994651338329421, + 0.295524224714752870173892994651338329421, + 0.2692667193099963550912269215694693528597, + 0.2692667193099963550912269215694693528597, + 0.2190863625159820439955349342281631924587, + 0.2190863625159820439955349342281631924587, + 0.1494513491505805931457763396576973324025, + 0.1494513491505805931457763396576973324025, + 0.0666713443086881375935688098933317928578, + 0.0666713443086881375935688098933317928578, + ], + [ + 0.272925086777900630714483528336342189156, + 0.2628045445102466621806888698905091953727, + 0.2628045445102466621806888698905091953727, + 0.2331937645919904799185237048431751394317, + 0.2331937645919904799185237048431751394317, + 0.1862902109277342514260976414316558916912, + 0.1862902109277342514260976414316558916912, + 0.1255803694649046246346942992239401001976, + 0.1255803694649046246346942992239401001976, + 0.0556685671161736664827537204425485787285, + 0.0556685671161736664827537204425485787285, + ], + [ + 0.2491470458134027850005624360429512108304, + 0.2491470458134027850005624360429512108304, + 0.2334925365383548087608498989248780562594, + 0.2334925365383548087608498989248780562594, + 0.2031674267230659217490644558097983765065, + 0.2031674267230659217490644558097983765065, + 0.160078328543346226334652529543359071872, + 0.160078328543346226334652529543359071872, + 0.1069393259953184309602547181939962242145, + 0.1069393259953184309602547181939962242145, + 0.047175336386511827194615961485017060317, + 0.047175336386511827194615961485017060317, + ], + [ + 0.2325515532308739101945895152688359481566, + 0.2262831802628972384120901860397766184347, + 0.2262831802628972384120901860397766184347, + 0.2078160475368885023125232193060527633865, + 0.2078160475368885023125232193060527633865, + 0.1781459807619457382800466919960979955128, + 0.1781459807619457382800466919960979955128, + 0.1388735102197872384636017768688714676218, + 0.1388735102197872384636017768688714676218, + 0.0921214998377284479144217759537971209236, + 0.0921214998377284479144217759537971209236, + 0.0404840047653158795200215922009860600419, + 0.0404840047653158795200215922009860600419, + ], + [ + 0.2152638534631577901958764433162600352749, + 0.2152638534631577901958764433162600352749, + 0.2051984637212956039659240656612180557103, + 0.2051984637212956039659240656612180557103, + 0.1855383974779378137417165901251570362489, + 0.1855383974779378137417165901251570362489, + 0.1572031671581935345696019386238421566056, + 0.1572031671581935345696019386238421566056, + 0.1215185706879031846894148090724766259566, + 0.1215185706879031846894148090724766259566, + 0.0801580871597602098056332770628543095836, + 0.0801580871597602098056332770628543095836, + 0.0351194603317518630318328761381917806197, + 0.0351194603317518630318328761381917806197, + ], + [ + 0.2025782419255612728806201999675193148386, + 0.1984314853271115764561183264438393248186, + 0.1984314853271115764561183264438393248186, + 0.1861610000155622110268005618664228245062, + 0.1861610000155622110268005618664228245062, + 0.1662692058169939335532008604812088111309, + 0.1662692058169939335532008604812088111309, + 0.1395706779261543144478047945110283225208, + 0.1395706779261543144478047945110283225208, + 0.1071592204671719350118695466858693034155, + 0.1071592204671719350118695466858693034155, + 0.0703660474881081247092674164506673384667, + 0.0703660474881081247092674164506673384667, + 0.0307532419961172683546283935772044177217, + 0.0307532419961172683546283935772044177217, + ], + [ + 0.1894506104550684962853967232082831051469, + 0.1894506104550684962853967232082831051469, + 0.1826034150449235888667636679692199393835, + 0.1826034150449235888667636679692199393835, + 0.1691565193950025381893120790303599622116, + 0.1691565193950025381893120790303599622116, + 0.1495959888165767320815017305474785489704, + 0.1495959888165767320815017305474785489704, + 0.1246289712555338720524762821920164201448, + 0.1246289712555338720524762821920164201448, + 0.0951585116824927848099251076022462263552, + 0.0951585116824927848099251076022462263552, + 0.0622535239386478928628438369943776942749, + 0.0622535239386478928628438369943776942749, + 0.0271524594117540948517805724560181035122, + 0.0271524594117540948517805724560181035122, + ], + [ + 0.1794464703562065254582656442618856214487, + 0.1765627053669926463252709901131972391509, + 0.1765627053669926463252709901131972391509, + 0.1680041021564500445099706637883231550211, + 0.1680041021564500445099706637883231550211, + 0.1540457610768102880814315948019586119404, + 0.1540457610768102880814315948019586119404, + 0.1351363684685254732863199817023501973721, + 0.1351363684685254732863199817023501973721, + 0.1118838471934039710947883856263559267358, + 0.1118838471934039710947883856263559267358, + 0.0850361483171791808835353701910620738504, + 0.0850361483171791808835353701910620738504, + 0.0554595293739872011294401653582446605128, + 0.0554595293739872011294401653582446605128, + 0.0241483028685479319601100262875653246916, + 0.0241483028685479319601100262875653246916, + ], + [ + 0.1691423829631435918406564701349866103341, + 0.1691423829631435918406564701349866103341, + 0.1642764837458327229860537764659275904123, + 0.1642764837458327229860537764659275904123, + 0.1546846751262652449254180038363747721932, + 0.1546846751262652449254180038363747721932, + 0.1406429146706506512047313037519472280955, + 0.1406429146706506512047313037519472280955, + 0.1225552067114784601845191268002015552281, + 0.1225552067114784601845191268002015552281, + 0.1009420441062871655628139849248346070628, + 0.1009420441062871655628139849248346070628, + 0.0764257302548890565291296776166365256053, + 0.0764257302548890565291296776166365256053, + 0.0497145488949697964533349462026386416808, + 0.0497145488949697964533349462026386416808, + 0.0216160135264833103133427102664524693876, + 0.0216160135264833103133427102664524693876, + ], + [ + 0.1610544498487836959791636253209167350399, + 0.1589688433939543476499564394650472016787, + 0.1589688433939543476499564394650472016787, + 0.152766042065859666778855400897662998461, + 0.152766042065859666778855400897662998461, + 0.1426067021736066117757461094419029724756, + 0.1426067021736066117757461094419029724756, + 0.1287539625393362276755157848568771170558, + 0.1287539625393362276755157848568771170558, + 0.1115666455473339947160239016817659974813, + 0.1115666455473339947160239016817659974813, + 0.0914900216224499994644620941238396526609, + 0.0914900216224499994644620941238396526609, + 0.0690445427376412265807082580060130449618, + 0.0690445427376412265807082580060130449618, + 0.0448142267656996003328381574019942119517, + 0.0448142267656996003328381574019942119517, + 0.0194617882297264770363120414644384357529, + 0.0194617882297264770363120414644384357529, + ], + [ + 0.1527533871307258506980843319550975934919, + 0.1527533871307258506980843319550975934919, + 0.1491729864726037467878287370019694366926, + 0.1491729864726037467878287370019694366926, + 0.1420961093183820513292983250671649330345, + 0.1420961093183820513292983250671649330345, + 0.1316886384491766268984944997481631349161, + 0.1316886384491766268984944997481631349161, + 0.118194531961518417312377377711382287005, + 0.118194531961518417312377377711382287005, + 0.1019301198172404350367501354803498761666, + 0.1019301198172404350367501354803498761666, + 0.0832767415767047487247581432220462061001, + 0.0832767415767047487247581432220462061001, + 0.0626720483341090635695065351870416063516, + 0.0626720483341090635695065351870416063516, + 0.040601429800386941331039952274932109879, + 0.040601429800386941331039952274932109879, + 0.0176140071391521183118619623518528163621, + 0.0176140071391521183118619623518528163621, + ], + [ + 0.1460811336496904271919851476833711882448, + 0.1445244039899700590638271665537525436099, + 0.1445244039899700590638271665537525436099, + 0.1398873947910731547221334238675831108927, + 0.1398873947910731547221334238675831108927, + 0.132268938633337461781052574496775604329, + 0.132268938633337461781052574496775604329, + 0.1218314160537285341953671771257335983563, + 0.1218314160537285341953671771257335983563, + 0.1087972991671483776634745780701056420336, + 0.1087972991671483776634745780701056420336, + 0.0934444234560338615532897411139320884835, + 0.0934444234560338615532897411139320884835, + 0.0761001136283793020170516533001831792261, + 0.0761001136283793020170516533001831792261, + 0.0571344254268572082836358264724479574912, + 0.0571344254268572082836358264724479574912, + 0.0369537897708524937999506682993296661889, + 0.0369537897708524937999506682993296661889, + 0.0160172282577743333242246168584710152658, + 0.0160172282577743333242246168584710152658, + ], + [ + 0.1392518728556319933754102483418099578739, + 0.1392518728556319933754102483418099578739, + 0.1365414983460151713525738312315173965863, + 0.1365414983460151713525738312315173965863, + 0.1311735047870623707329649925303074458757, + 0.1311735047870623707329649925303074458757, + 0.1232523768105124242855609861548144719594, + 0.1232523768105124242855609861548144719594, + 0.1129322960805392183934006074217843191142, + 0.1129322960805392183934006074217843191142, + 0.1004141444428809649320788378305362823508, + 0.1004141444428809649320788378305362823508, + 0.0859416062170677274144436813727028661891, + 0.0859416062170677274144436813727028661891, + 0.0697964684245204880949614189302176573987, + 0.0697964684245204880949614189302176573987, + 0.0522933351526832859403120512732112561121, + 0.0522933351526832859403120512732112561121, + 0.0337749015848141547933022468659129013491, + 0.0337749015848141547933022468659129013491, + 0.0146279952982722006849910980471854451902, + 0.0146279952982722006849910980471854451902, + ], + [ + 0.1336545721861061753514571105458443385831, + 0.132462039404696617371642464703316925805, + 0.132462039404696617371642464703316925805, + 0.1289057221880821499785953393997936532597, + 0.1289057221880821499785953393997936532597, + 0.1230490843067295304675784006720096548158, + 0.1230490843067295304675784006720096548158, + 0.1149966402224113649416435129339613014914, + 0.1149966402224113649416435129339613014914, + 0.1048920914645414100740861850147438548584, + 0.1048920914645414100740861850147438548584, + 0.0929157660600351474770186173697646486034, + 0.0929157660600351474770186173697646486034, + 0.0792814117767189549228925247420432269137, + 0.0792814117767189549228925247420432269137, + 0.0642324214085258521271696151589109980391, + 0.0642324214085258521271696151589109980391, + 0.0480376717310846685716410716320339965612, + 0.0480376717310846685716410716320339965612, + 0.0309880058569794443106942196418845053837, + 0.0309880058569794443106942196418845053837, + 0.0134118594871417720813094934586150649766, + 0.0134118594871417720813094934586150649766, + ], + [ + 0.1279381953467521569740561652246953718517, + 0.1279381953467521569740561652246953718517, + 0.1258374563468282961213753825111836887264, + 0.1258374563468282961213753825111836887264, + 0.121670472927803391204463153476262425607, + 0.121670472927803391204463153476262425607, + 0.1155056680537256013533444839067835598622, + 0.1155056680537256013533444839067835598622, + 0.1074442701159656347825773424466062227946, + 0.1074442701159656347825773424466062227946, + 0.0976186521041138882698806644642471544279, + 0.0976186521041138882698806644642471544279, + 0.086190161531953275917185202983742667185, + 0.086190161531953275917185202983742667185, + 0.0733464814110803057340336152531165181193, + 0.0733464814110803057340336152531165181193, + 0.0592985849154367807463677585001085845412, + 0.0592985849154367807463677585001085845412, + 0.0442774388174198061686027482113382288593, + 0.0442774388174198061686027482113382288593, + 0.0285313886289336631813078159518782864491, + 0.0285313886289336631813078159518782864491, + 0.0123412297999871995468056670700372915759, + 0.0123412297999871995468056670700372915759, + ], + ]; + // LUT for binomial coefficient arrays per curve order 'n' + const binomialCoefficients = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]; + const getCubicArcLength = (xs, ys, t) => { + let z; + let sum; + let correctedT; + /*if (xs.length >= tValues.length) { + throw new Error('too high n bezier'); + }*/ + const n = 20; + z = t / 2; + sum = 0; + for (let i = 0; i < n; i++) { + correctedT = z * tValues[n][i] + z; + sum += cValues[n][i] * BFunc(xs, ys, correctedT); + } + return z * sum; + }; + const getQuadraticArcLength = (xs, ys, t) => { + if (t === undefined) { + t = 1; + } + const ax = xs[0] - 2 * xs[1] + xs[2]; + const ay = ys[0] - 2 * ys[1] + ys[2]; + const bx = 2 * xs[1] - 2 * xs[0]; + const by = 2 * ys[1] - 2 * ys[0]; + const A = 4 * (ax * ax + ay * ay); + const B = 4 * (ax * bx + ay * by); + const C = bx * bx + by * by; + if (A === 0) { + return (t * Math.sqrt(Math.pow(xs[2] - xs[0], 2) + Math.pow(ys[2] - ys[0], 2))); + } + const b = B / (2 * A); + const c = C / A; + const u = t + b; + const k = c - b * b; + const uuk = u * u + k > 0 ? Math.sqrt(u * u + k) : 0; + const bbk = b * b + k > 0 ? Math.sqrt(b * b + k) : 0; + const term = b + Math.sqrt(b * b + k) !== 0 + ? k * Math.log(Math.abs((u + uuk) / (b + bbk))) + : 0; + return (Math.sqrt(A) / 2) * (u * uuk - b * bbk + term); + }; + function BFunc(xs, ys, t) { + const xbase = getDerivative(1, t, xs); + const ybase = getDerivative(1, t, ys); + const combined = xbase * xbase + ybase * ybase; + return Math.sqrt(combined); + } + /** + * Compute the curve derivative (hodograph) at t. + */ + const getDerivative = (derivative, t, vs) => { + // the derivative of any 't'-less function is zero. + const n = vs.length - 1; + let _vs; + let value; + if (n === 0) { + return 0; + } + // direct values? compute! + if (derivative === 0) { + value = 0; + for (let k = 0; k <= n; k++) { + value += + binomialCoefficients[n][k] * + Math.pow(1 - t, n - k) * + Math.pow(t, k) * + vs[k]; + } + return value; + } + else { + // Still some derivative? go down one order, then try + // for the lower order curve's. + _vs = new Array(n); + for (let k = 0; k < n; k++) { + _vs[k] = n * (vs[k + 1] - vs[k]); + } + return getDerivative(derivative - 1, t, _vs); + } + }; + const t2length = (length, totalLength, func) => { + let error = 1; + let t = length / totalLength; + let step = (length - func(t)) / totalLength; + let numIterations = 0; + while (error > 0.001) { + const increasedTLength = func(t + step); + const increasedTError = Math.abs(length - increasedTLength) / totalLength; + if (increasedTError < error) { + error = increasedTError; + t += step; + } + else { + const decreasedTLength = func(t - step); + const decreasedTError = Math.abs(length - decreasedTLength) / totalLength; + if (decreasedTError < error) { + error = decreasedTError; + t -= step; + } + else { + step /= 2; + } + } + numIterations++; + if (numIterations > 500) { + break; + } + } + return t; + }; + /** * Path constructor. * @author Jason Follas @@ -10392,19 +11192,15 @@ super(config); this.dataArray = []; this.pathLength = 0; - this.dataArray = Path.parsePathData(this.data()); - this.pathLength = 0; - for (var i = 0; i < this.dataArray.length; ++i) { - this.pathLength += this.dataArray[i].pathLength; - } + this._readDataAttribute(); this.on('dataChange.konva', function () { - this.dataArray = Path.parsePathData(this.data()); - this.pathLength = 0; - for (var i = 0; i < this.dataArray.length; ++i) { - this.pathLength += this.dataArray[i].pathLength; - } + this._readDataAttribute(); }); } + _readDataAttribute() { + this.dataArray = Path.parsePathData(this.data()); + this.pathLength = Path.getPathLength(this.dataArray); + } _sceneFunc(context) { var ca = this.dataArray; // context position @@ -10540,37 +11336,54 @@ * var point = path.getPointAtLength(10); */ getPointAtLength(length) { - var point, i = 0, ii = this.dataArray.length; + return Path.getPointAtLengthOfDataArray(length, this.dataArray); + } + static getLineLength(x1, y1, x2, y2) { + return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); + } + static getPathLength(dataArray) { + let pathLength = 0; + for (var i = 0; i < dataArray.length; ++i) { + pathLength += dataArray[i].pathLength; + } + return pathLength; + } + static getPointAtLengthOfDataArray(length, dataArray) { + var point, i = 0, ii = dataArray.length; if (!ii) { return null; } - while (i < ii && length > this.dataArray[i].pathLength) { - length -= this.dataArray[i].pathLength; + while (i < ii && length > dataArray[i].pathLength) { + length -= dataArray[i].pathLength; ++i; } if (i === ii) { - point = this.dataArray[i - 1].points.slice(-2); + point = dataArray[i - 1].points.slice(-2); return { x: point[0], y: point[1], }; } if (length < 0.01) { - point = this.dataArray[i].points.slice(0, 2); + point = dataArray[i].points.slice(0, 2); return { x: point[0], y: point[1], }; } - var cp = this.dataArray[i]; + var cp = dataArray[i]; var p = cp.points; switch (cp.command) { case 'L': return Path.getPointOnLine(length, cp.start.x, cp.start.y, p[0], p[1]); case 'C': - return Path.getPointOnCubicBezier(length / cp.pathLength, cp.start.x, cp.start.y, p[0], p[1], p[2], p[3], p[4], p[5]); + return Path.getPointOnCubicBezier(t2length(length, Path.getPathLength(dataArray), (i) => { + return getCubicArcLength([cp.start.x, p[0], p[2], p[4]], [cp.start.y, p[1], p[3], p[5]], i); + }), cp.start.x, cp.start.y, p[0], p[1], p[2], p[3], p[4], p[5]); case 'Q': - return Path.getPointOnQuadraticBezier(length / cp.pathLength, cp.start.x, cp.start.y, p[0], p[1], p[2], p[3]); + return Path.getPointOnQuadraticBezier(t2length(length, Path.getPathLength(dataArray), (i) => { + return getQuadraticArcLength([cp.start.x, p[0], p[2]], [cp.start.y, p[1], p[3]], i); + }), cp.start.x, cp.start.y, p[0], p[1], p[2], p[3]); case 'A': var cx = p[0], cy = p[1], rx = p[2], ry = p[3], theta = p[4], dTheta = p[5], psi = p[6]; theta += (dTheta * length) / cp.pathLength; @@ -10578,9 +11391,6 @@ } return null; } - static getLineLength(x1, y1, x2, y2) { - return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); - } static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX, fromY) { if (fromX === undefined) { fromX = P1x; @@ -10991,25 +11801,9 @@ case 'L': return path.getLineLength(x, y, points[0], points[1]); case 'C': - // Approximates by breaking curve into 100 line segments - len = 0.0; - p1 = path.getPointOnCubicBezier(0, x, y, points[0], points[1], points[2], points[3], points[4], points[5]); - for (t = 0.01; t <= 1; t += 0.01) { - p2 = path.getPointOnCubicBezier(t, x, y, points[0], points[1], points[2], points[3], points[4], points[5]); - len += path.getLineLength(p1.x, p1.y, p2.x, p2.y); - p1 = p2; - } - return len; + return getCubicArcLength([x, points[0], points[2], points[4]], [y, points[1], points[3], points[5]], 1); case 'Q': - // Approximates by breaking curve into 100 line segments - len = 0.0; - p1 = path.getPointOnQuadraticBezier(0, x, y, points[0], points[1], points[2], points[3]); - for (t = 0.01; t <= 1; t += 0.01) { - p2 = path.getPointOnQuadraticBezier(t, x, y, points[0], points[1], points[2], points[3]); - len += path.getLineLength(p1.x, p1.y, p2.x, p2.y); - p1 = p2; - } - return len; + return getQuadraticArcLength([x, points[0], points[2]], [y, points[1], points[3]], 1); case 'A': // Approximates by breaking curve into line segments len = 0.0; @@ -14166,15 +14960,34 @@ super(config); this.dummyCanvas = Util.createCanvasElement(); this.dataArray = []; - this.dataArray = Path.parsePathData(this.attrs.data); + this._readDataAttribute(); this.on('dataChange.konva', function () { - this.dataArray = Path.parsePathData(this.attrs.data); + this._readDataAttribute(); this._setTextData(); }); // update text data for certain attr changes this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva', this._setTextData); this._setTextData(); } + _getTextPathLength() { + return Path.getPathLength(this.dataArray); + } + _getPointAtLength(length) { + // if path is not defined yet, do nothing + if (!this.attrs.data) { + return null; + } + const totalLength = this.pathLength; + // -1px for rounding of the last symbol + if (length - 1 > totalLength) { + return null; + } + return Path.getPointAtLengthOfDataArray(length, this.dataArray); + } + _readDataAttribute() { + this.dataArray = Path.parsePathData(this.attrs.data); + this.pathLength = this._getTextPathLength(); + } _sceneFunc(context) { context.setAttr('font', this._getContextFont()); context.setAttr('textBaseline', this.textBaseline()); @@ -14259,188 +15072,50 @@ _context.restore(); return { width: metrics.width, - height: parseInt(this.attrs.fontSize, 10), + height: parseInt(`${this.fontSize()}`, 10), }; } _setTextData() { - var that = this; - var size = this._getTextSize(this.attrs.text); - var letterSpacing = this.letterSpacing(); - var align = this.align(); - var kerningFunc = this.kerningFunc(); - this.textWidth = size.width; - this.textHeight = size.height; - var textFullWidth = Math.max(this.textWidth + ((this.attrs.text || '').length - 1) * letterSpacing, 0); + const { width, height } = this._getTextSize(this.attrs.text); + this.textWidth = width; + this.textHeight = height; this.glyphInfo = []; - var fullPathWidth = 0; - for (var l = 0; l < that.dataArray.length; l++) { - if (that.dataArray[l].pathLength > 0) { - fullPathWidth += that.dataArray[l].pathLength; - } + if (!this.attrs.data) { + return null; } - var offset = 0; + const letterSpacing = this.letterSpacing(); + const align = this.align(); + const kerningFunc = this.kerningFunc(); + // defines the width of the text on a straight line + const textWidth = Math.max(this.textWidth + ((this.attrs.text || '').length - 1) * letterSpacing, 0); + let offset = 0; if (align === 'center') { - offset = Math.max(0, fullPathWidth / 2 - textFullWidth / 2); + offset = Math.max(0, this.pathLength / 2 - textWidth / 2); } if (align === 'right') { - offset = Math.max(0, fullPathWidth - textFullWidth); - } - var charArr = stringToArray(this.text()); - var spacesNumber = this.text().split(' ').length - 1; - var p0, p1, pathCmd; - var pIndex = -1; - var currentT = 0; - // var sumLength = 0; - // for(var j = 0; j < that.dataArray.length; j++) { - // if(that.dataArray[j].pathLength > 0) { - // - // if (sumLength + that.dataArray[j].pathLength > offset) {} - // fullPathWidth += that.dataArray[j].pathLength; - // } - // } - var getNextPathSegment = function () { - currentT = 0; - var pathData = that.dataArray; - for (var j = pIndex + 1; j < pathData.length; j++) { - if (pathData[j].pathLength > 0) { - pIndex = j; - return pathData[j]; - } - else if (pathData[j].command === 'M') { - p0 = { - x: pathData[j].points[0], - y: pathData[j].points[1], - }; - } - } - return {}; - }; - var findSegmentToFitCharacter = function (c) { - var glyphWidth = that._getTextSize(c).width + letterSpacing; - if (c === ' ' && align === 'justify') { - glyphWidth += (fullPathWidth - textFullWidth) / spacesNumber; - } - var currLen = 0; - var attempts = 0; - p1 = undefined; - while (Math.abs(glyphWidth - currLen) / glyphWidth > 0.01 && - attempts < 20) { - attempts++; - var cumulativePathLength = currLen; - while (pathCmd === undefined) { - pathCmd = getNextPathSegment(); - if (pathCmd && - cumulativePathLength + pathCmd.pathLength < glyphWidth) { - cumulativePathLength += pathCmd.pathLength; - pathCmd = undefined; - } - } - if (Object.keys(pathCmd).length === 0 || p0 === undefined) { - return undefined; - } - var needNewSegment = false; - switch (pathCmd.command) { - case 'L': - if (Path.getLineLength(p0.x, p0.y, pathCmd.points[0], pathCmd.points[1]) > glyphWidth) { - p1 = Path.getPointOnLine(glyphWidth, p0.x, p0.y, pathCmd.points[0], pathCmd.points[1], p0.x, p0.y); - } - else { - pathCmd = undefined; - } - break; - case 'A': - var start = pathCmd.points[4]; - // 4 = theta - var dTheta = pathCmd.points[5]; - // 5 = dTheta - var end = pathCmd.points[4] + dTheta; - if (currentT === 0) { - currentT = start + 0.00000001; - } - else if (glyphWidth > currLen) { - // Just in case start is 0 - currentT += ((Math.PI / 180.0) * dTheta) / Math.abs(dTheta); - } - else { - currentT -= ((Math.PI / 360.0) * dTheta) / Math.abs(dTheta); - } - // Credit for bug fix: @therth https://github.com/ericdrowell/KonvaJS/issues/249 - // Old code failed to render text along arc of this path: "M 50 50 a 150 50 0 0 1 250 50 l 50 0" - if ((dTheta < 0 && currentT < end) || - (dTheta >= 0 && currentT > end)) { - currentT = end; - needNewSegment = true; - } - p1 = Path.getPointOnEllipticalArc(pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3], currentT, pathCmd.points[6]); - break; - case 'C': - if (currentT === 0) { - if (glyphWidth > pathCmd.pathLength) { - currentT = 0.00000001; - } - else { - currentT = glyphWidth / pathCmd.pathLength; - } - } - else if (glyphWidth > currLen) { - currentT += (glyphWidth - currLen) / pathCmd.pathLength / 2; - } - else { - currentT = Math.max(currentT - (currLen - glyphWidth) / pathCmd.pathLength / 2, 0); - } - if (currentT > 1.0) { - currentT = 1.0; - needNewSegment = true; - } - p1 = Path.getPointOnCubicBezier(currentT, pathCmd.start.x, pathCmd.start.y, pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3], pathCmd.points[4], pathCmd.points[5]); - break; - case 'Q': - if (currentT === 0) { - currentT = glyphWidth / pathCmd.pathLength; - } - else if (glyphWidth > currLen) { - currentT += (glyphWidth - currLen) / pathCmd.pathLength; - } - else { - currentT -= (currLen - glyphWidth) / pathCmd.pathLength; - } - if (currentT > 1.0) { - currentT = 1.0; - needNewSegment = true; - } - p1 = Path.getPointOnQuadraticBezier(currentT, pathCmd.start.x, pathCmd.start.y, pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3]); - break; - } - if (p1 !== undefined) { - currLen = Path.getLineLength(p0.x, p0.y, p1.x, p1.y); - } - if (needNewSegment) { - needNewSegment = false; - pathCmd = undefined; - } - } - }; - // fake search for offset, this is the best approach - var testChar = 'C'; - var glyphWidth = that._getTextSize(testChar).width + letterSpacing; - var lettersInOffset = offset / glyphWidth - 1; - // the idea is simple - // try to draw testChar until we fill offset - for (var k = 0; k < lettersInOffset; k++) { - findSegmentToFitCharacter(testChar); - if (p0 === undefined || p1 === undefined) { - break; - } - p0 = p1; + offset = Math.max(0, this.pathLength - textWidth); } + const charArr = stringToArray(this.text()); + // Algorithm for calculating glyph positions: + // 1. Get the begging point of the glyph on the path using the offsetToGlyph, + // 2. Get the ending point of the glyph on the path using the offsetToGlyph plus glyph width, + // 3. Calculate the rotation, width, and midpoint of the glyph using the start and end points, + // 4. Add glyph width to the offsetToGlyph and repeat + let offsetToGlyph = offset; for (var i = 0; i < charArr.length; i++) { - // Find p1 such that line segment between p0 and p1 is approx. width of glyph - findSegmentToFitCharacter(charArr[i]); - if (p0 === undefined || p1 === undefined) { - break; + const charStartPoint = this._getPointAtLength(offsetToGlyph); + if (!charStartPoint) + return; + let glyphWidth = this._getTextSize(charArr[i]).width + letterSpacing; + if (charArr[i] === ' ' && align === 'justify') { + const numberOfSpaces = this.text().split(' ').length - 1; + glyphWidth += (this.pathLength - textWidth) / numberOfSpaces; } - var width = Path.getLineLength(p0.x, p0.y, p1.x, p1.y); - var kern = 0; + const charEndPoint = this._getPointAtLength(offsetToGlyph + glyphWidth); + if (!charEndPoint) + return; + const width = Path.getLineLength(charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y); + let kern = 0; if (kerningFunc) { try { // getKerning is a user provided getter. Make sure it never breaks our logic @@ -14450,20 +15125,20 @@ kern = 0; } } - p0.x += kern; - p1.x += kern; + charStartPoint.x += kern; + charEndPoint.x += kern; this.textWidth += kern; - var midpoint = Path.getPointOnLine(kern + width / 2.0, p0.x, p0.y, p1.x, p1.y); - var rotation = Math.atan2(p1.y - p0.y, p1.x - p0.x); + const midpoint = Path.getPointOnLine(kern + width / 2.0, charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y); + const rotation = Math.atan2(charEndPoint.y - charStartPoint.y, charEndPoint.x - charStartPoint.x); this.glyphInfo.push({ transposeX: midpoint.x, transposeY: midpoint.y, text: charArr[i], rotation: rotation, - p0: p0, - p1: p1, + p0: charStartPoint, + p1: charEndPoint, }); - p0 = p1; + offsetToGlyph += glyphWidth; } } getSelfRect() { diff --git a/konva.min.js b/konva.min.js index b7322696..f58f205a 100644 --- a/konva.min.js +++ b/konva.min.js @@ -3,10 +3,10 @@ * Konva JavaScript Framework v8.4.3 * http://konvajs.org/ * Licensed under the MIT - * Date: Thu Mar 23 2023 + * Date: Wed Apr 05 2023 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * * @license - */var t=Math.PI/180;const e="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{},i={_global:e,version:"8.4.3",isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),isUnminified:/param/.test(function(t){}.toString()),dblClickWindow:400,getAngle:e=>i.angleDeg?e*t: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,pixelRatio:"undefined"!=typeof window&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging:()=>i.DD.isDragging,isDragReady:()=>!!i.DD.node,releaseCanvasOnDestroy:!0,document:e.document,_injectGlobal(t){e.Konva=t}},r=t=>{i[t.prototype.getClassName()]=t};i._injectGlobal(i);class a{constructor(t=[1,0,0,1,0,0]){this.dirty=!1,this.m=t&&t.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 a(this.m)}copyInto(t){t.m[0]=this.m[0],t.m[1]=this.m[1],t.m[2]=this.m[2],t.m[3]=this.m[3],t.m[4]=this.m[4],t.m[5]=this.m[5]}point(t){var e=this.m;return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}translate(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this}scale(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this}rotate(t){var e=Math.cos(t),i=Math.sin(t),r=this.m[0]*e+this.m[2]*i,a=this.m[1]*e+this.m[3]*i,n=this.m[0]*-i+this.m[2]*e,s=this.m[1]*-i+this.m[3]*e;return this.m[0]=r,this.m[1]=a,this.m[2]=n,this.m[3]=s,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,e){var i=this.m[0]+this.m[2]*e,r=this.m[1]+this.m[3]*e,a=this.m[2]+this.m[0]*t,n=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=r,this.m[2]=a,this.m[3]=n,this}multiply(t){var e=this.m[0]*t.m[0]+this.m[2]*t.m[1],i=this.m[1]*t.m[0]+this.m[3]*t.m[1],r=this.m[0]*t.m[2]+this.m[2]*t.m[3],a=this.m[1]*t.m[2]+this.m[3]*t.m[3],n=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],s=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=e,this.m[1]=i,this.m[2]=r,this.m[3]=a,this.m[4]=n,this.m[5]=s,this}invert(){var t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,i=-this.m[1]*t,r=-this.m[2]*t,a=this.m[0]*t,n=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),s=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=e,this.m[1]=i,this.m[2]=r,this.m[3]=a,this.m[4]=n,this.m[5]=s,this}getMatrix(){return this.m}decompose(){var t=this.m[0],e=this.m[1],i=this.m[2],r=this.m[3],a=t*r-e*i;let n={x:this.m[4],y:this.m[5],rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!=t||0!=e){var s=Math.sqrt(t*t+e*e);n.rotation=e>0?Math.acos(t/s):-Math.acos(t/s),n.scaleX=s,n.scaleY=a/s,n.skewX=(t*i+e*r)/a,n.skewY=0}else if(0!=i||0!=r){var o=Math.sqrt(i*i+r*r);n.rotation=Math.PI/2-(r>0?Math.acos(-i/o):-Math.acos(i/o)),n.scaleX=a/o,n.scaleY=o,n.skewX=0,n.skewY=(t*i+e*r)/a}return n.rotation=g._getRotation(n.rotation),n}}var n=Math.PI/180,s=180/Math.PI,o="Konva error: ",h={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]},l=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,d=[];const c="undefined"!=typeof requestAnimationFrame&&requestAnimationFrame||function(t){setTimeout(t,60)},g={_isElement:t=>!(!t||1!=t.nodeType),_isFunction:t=>!!(t&&t.constructor&&t.call&&t.apply),_isPlainObject:t=>!!t&&t.constructor===Object,_isArray:t=>"[object Array]"===Object.prototype.toString.call(t),_isNumber:t=>"[object Number]"===Object.prototype.toString.call(t)&&!isNaN(t)&&isFinite(t),_isString:t=>"[object String]"===Object.prototype.toString.call(t),_isBoolean:t=>"[object Boolean]"===Object.prototype.toString.call(t),isObject:t=>t instanceof Object,isValidSelector(t){if("string"!=typeof t)return!1;var e=t[0];return"#"===e||"."===e||e===e.toUpperCase()},_sign:t=>0===t||t>0?1:-1,requestAnimFrame(t){d.push(t),1===d.length&&c((function(){const t=d;d=[],t.forEach((function(t){t()}))}))},createCanvasElement(){var t=document.createElement("canvas");try{t.style=t.style||{}}catch(t){}return t},createImageElement:()=>document.createElement("img"),_isInDocument(t){for(;t=t.parentNode;)if(t==document)return!0;return!1},_urlToImage(t,e){var i=g.createImageElement();i.onload=function(){e(i)},i.src=t},_rgbToHex:(t,e,i)=>((1<<24)+(t<<16)+(e<<8)+i).toString(16).slice(1),_hexToRgb(t){t=t.replace("#","");var e=parseInt(t,16);return{r:e>>16&255,g:e>>8&255,b:255&e}},getRandomColor(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},getRGB(t){var e;return t in h?{r:(e=h[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=l.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:t=>(t=t||"black",g._namedColorToRBA(t)||g._hex3ColorToRGBA(t)||g._hex4ColorToRGBA(t)||g._hex6ColorToRGBA(t)||g._hex8ColorToRGBA(t)||g._rgbColorToRGBA(t)||g._rgbaColorToRGBA(t)||g._hslColorToRGBA(t)),_namedColorToRBA(t){var e=h[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map(((t,e)=>"%"===t.slice(-1)?3===e?parseInt(t)/100:parseInt(t)/100*255:Number(t)));return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex8ColorToRGBA(t){if("#"===t[0]&&9===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:parseInt(t.slice(7,9),16)/255}},_hex6ColorToRGBA(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex4ColorToRGBA(t){if("#"===t[0]&&5===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:parseInt(t[4]+t[4],16)/255}},_hex3ColorToRGBA(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_hslColorToRGBA(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){const[e,...i]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),r=Number(i[0])/360,a=Number(i[1])/100,n=Number(i[2])/100;let s,o,h;if(0===a)return h=255*n,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};s=n<.5?n*(1+a):n+a-n*a;const l=2*n-s,d=[0,0,0];for(let t=0;t<3;t++)o=r+1/3*-(t-1),o<0&&o++,o>1&&o--,h=6*o<1?l+6*(s-l)*o:2*o<1?s:3*o<2?l+(s-l)*(2/3-o)*6:l,d[t]=255*h;return{r:Math.round(d[0]),g:Math.round(d[1]),b:Math.round(d[2]),a:1}}},haveIntersection:(t,e)=>!(e.x>t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heightt.slice(0),degToRad:t=>t*n,radToDeg:t=>t*s,_degToRad:t=>(g.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),g.degToRad(t)),_radToDeg:t=>(g.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),g.radToDeg(t)),_getRotation:t=>i.angleDeg?g.radToDeg(t):t,_capitalize:t=>t.charAt(0).toUpperCase()+t.slice(1),throw(t){throw new Error(o+t)},error(t){console.error(o+t)},warn(t){i.showWarnings&&console.warn("Konva warning: "+t)},each(t,e){for(var i in t)e(i,t[i])},_inRange:(t,e,i)=>e<=t&&t1?(s=i,o=r,h=(i-a)*(i-a)+(r-n)*(r-n)):h=((s=t+d*(i-t))-a)*(s-a)+((o=e+d*(r-e))-n)*(o-n)}return[s,o,h]},_getProjectionToLine(t,e,i){var r=g.cloneObject(t),a=Number.MAX_VALUE;return e.forEach((function(n,s){if(i||s!==e.length-1){var o=e[(s+1)%e.length],h=g._getProjectionToSegment(n.x,n.y,o.x,o.y,t.x,t.y),l=h[0],d=h[1],c=h[2];ce.length){var s=e;e=t,t=s}for(r=0;rt.touches?t.changedTouches[0].identifier:t.pointerId||999,releaseCanvas(...t){i.releaseCanvasOnDestroy&&t.forEach((t=>{t.width=0,t.height=0}))},drawRoundedRectPath(t,e,i,r){let a=0,n=0,s=0,o=0;"number"==typeof r?a=n=s=o=Math.min(r,e/2,i/2):(a=Math.min(r[0]||0,e/2,i/2),n=Math.min(r[1]||0,e/2,i/2),o=Math.min(r[2]||0,e/2,i/2),s=Math.min(r[3]||0,e/2,i/2)),t.moveTo(a,0),t.lineTo(e-n,0),t.arc(e-n,n,n,3*Math.PI/2,0,!1),t.lineTo(e,i-o),t.arc(e-o,i-o,o,0,Math.PI/2,!1),t.lineTo(s,i),t.arc(s,i-s,s,Math.PI/2,Math.PI,!1),t.lineTo(0,a),t.arc(a,a,a,Math.PI,3*Math.PI/2,!1)}};function u(t){return g._isString(t)?'"'+t+'"':"[object Number]"===Object.prototype.toString.call(t)||g._isBoolean(t)?t:Object.prototype.toString.call(t)}function f(t){return t>255?255:t<0?0:Math.round(t)}function p(){if(i.isUnminified)return function(t,e){return g._isNumber(t)||g.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),t}}function v(t){if(i.isUnminified)return function(e,i){let r=g._isNumber(e),a=g._isArray(e)&&e.length==t;return r||a||g.warn(u(e)+' is a not valid value for "'+i+'" attribute. The value should be a number or Array('+t+")"),e}}function m(){if(i.isUnminified)return function(t,e){return g._isNumber(t)||"auto"===t||g.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),t}}function _(){if(i.isUnminified)return function(t,e){return g._isString(t)||g.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a string.'),t}}function y(){if(i.isUnminified)return function(t,e){const i=g._isString(t),r="[object CanvasGradient]"===Object.prototype.toString.call(t)||t&&t.addColorStop;return i||r||g.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a string or a native gradient.'),t}}function x(){if(i.isUnminified)return function(t,e){return!0===t||!1===t||g.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),t}}var b="get",S="set";const w={addGetterSetter(t,e,i,r,a){w.addGetter(t,e,i),w.addSetter(t,e,r,a),w.addOverloadedGetterSetter(t,e)},addGetter(t,e,i){var r=b+g._capitalize(e);t.prototype[r]=t.prototype[r]||function(){var t=this.attrs[e];return void 0===t?i:t}},addSetter(t,e,i,r){var a=S+g._capitalize(e);t.prototype[a]||w.overWriteSetter(t,e,i,r)},overWriteSetter(t,e,i,r){var a=S+g._capitalize(e);t.prototype[a]=function(t){return i&&null!=t&&(t=i.call(this,t,e)),this._setAttr(e,t),r&&r.call(this),this}},addComponentsGetterSetter(t,e,r,a,n){var s,o,h=r.length,l=g._capitalize,d=b+l(e),c=S+l(e);t.prototype[d]=function(){var t={};for(s=0;s{this._setAttr(e+l(t),void 0)})),this._fireChangeEvent(e,s,t),n&&n.call(this),this},w.addOverloadedGetterSetter(t,e)},addOverloadedGetterSetter(t,e){var i=g._capitalize(e),r=S+i,a=b+i;t.prototype[e]=function(){return arguments.length?(this[r](arguments[0]),this):this[a]()}},addDeprecatedGetterSetter(t,e,i,r){g.error("Adding deprecated "+e);var a=b+g._capitalize(e),n=e+" property is deprecated and will be removed soon. Look at Konva change log for more information.";t.prototype[a]=function(){g.error(n);var t=this.attrs[e];return void 0===t?i:t},w.addSetter(t,e,r,(function(){g.error(n)})),w.addOverloadedGetterSetter(t,e)},backCompat(t,e){g.each(e,(function(e,i){var r=t.prototype[i],a=b+g._capitalize(e),n=S+g._capitalize(e);function s(){r.apply(this,arguments),g.error('"'+e+'" method is deprecated and will be removed soon. Use ""'+i+'" instead.')}t.prototype[e]=s,t.prototype[a]=s,t.prototype[n]=s}))},afterSetFilter(){this._filterUpToDate=!1}};var C=["arc","arcTo","beginPath","bezierCurveTo","clearRect","clip","closePath","createLinearGradient","createPattern","createRadialGradient","drawImage","ellipse","fill","fillText","getImageData","createImageData","lineTo","moveTo","putImageData","quadraticCurveTo","rect","restore","rotate","save","scale","setLineDash","setTransform","stroke","strokeText","transform","translate"];class P{constructor(t){this.canvas=t,i.enableTrace&&(this.traceArr=[],this._enableTrace())}fillShape(t){t.fillEnabled()&&this._fill(t)}_fill(t){}strokeShape(t){t.hasStroke()&&this._stroke(t)}_stroke(t){}fillStrokeShape(t){t.attrs.fillAfterStrokeEnabled?(this.strokeShape(t),this.fillShape(t)):(this.fillShape(t),this.strokeShape(t))}getTrace(t,e){var i,r,a,n,s=this.traceArr,o=s.length,h="";for(i=0;i"number"==typeof t?Math.floor(t):t))),h+="("+n.join(",")+")")):(h+=r.property,t||(h+="="+r.val)),h+=";";return h}clearTrace(){this.traceArr=[]}_trace(t){var e=this.traceArr;e.push(t),e.length>=100&&e.shift()}reset(){var t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)}getCanvas(){return this.canvas}clear(t){var e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)}_applyLineCap(t){const e=t.attrs.lineCap;e&&this.setAttr("lineCap",e)}_applyOpacity(t){var e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)}_applyLineJoin(t){const e=t.attrs.lineJoin;e&&this.setAttr("lineJoin",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,r,a,n){this._context.arc(t,e,i,r,a,n)}arcTo(t,e,i,r,a){this._context.arcTo(t,e,i,r,a)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,r,a,n){this._context.bezierCurveTo(t,e,i,r,a,n)}clearRect(t,e,i,r){this._context.clearRect(t,e,i,r)}clip(){this._context.clip()}closePath(){this._context.closePath()}createImageData(t,e){var i=arguments;return 2===i.length?this._context.createImageData(t,e):1===i.length?this._context.createImageData(t):void 0}createLinearGradient(t,e,i,r){return this._context.createLinearGradient(t,e,i,r)}createPattern(t,e){return this._context.createPattern(t,e)}createRadialGradient(t,e,i,r,a,n){return this._context.createRadialGradient(t,e,i,r,a,n)}drawImage(t,e,i,r,a,n,s,o,h){var l=arguments,d=this._context;3===l.length?d.drawImage(t,e,i):5===l.length?d.drawImage(t,e,i,r,a):9===l.length&&d.drawImage(t,e,i,r,a,n,s,o,h)}ellipse(t,e,i,r,a,n,s,o){this._context.ellipse(t,e,i,r,a,n,s,o)}isPointInPath(t,e,i,r){return i?this._context.isPointInPath(i,t,e,r):this._context.isPointInPath(t,e,r)}fill(t){t?this._context.fill(t):this._context.fill()}fillRect(t,e,i,r){this._context.fillRect(t,e,i,r)}strokeRect(t,e,i,r){this._context.strokeRect(t,e,i,r)}fillText(t,e,i,r){r?this._context.fillText(t,e,i,r):this._context.fillText(t,e,i)}measureText(t){return this._context.measureText(t)}getImageData(t,e,i,r){return this._context.getImageData(t,e,i,r)}lineTo(t,e){this._context.lineTo(t,e)}moveTo(t,e){this._context.moveTo(t,e)}rect(t,e,i,r){this._context.rect(t,e,i,r)}putImageData(t,e,i){this._context.putImageData(t,e,i)}quadraticCurveTo(t,e,i,r){this._context.quadraticCurveTo(t,e,i,r)}restore(){this._context.restore()}rotate(t){this._context.rotate(t)}save(){this._context.save()}scale(t,e){this._context.scale(t,e)}setLineDash(t){this._context.setLineDash?this._context.setLineDash(t):"mozDash"in this._context?this._context.mozDash=t:"webkitLineDash"in this._context&&(this._context.webkitLineDash=t)}getLineDash(){return this._context.getLineDash()}setTransform(t,e,i,r,a,n){this._context.setTransform(t,e,i,r,a,n)}stroke(t){t?this._context.stroke(t):this._context.stroke()}strokeText(t,e,i,r){this._context.strokeText(t,e,i,r)}transform(t,e,i,r,a,n){this._context.transform(t,e,i,r,a,n)}translate(t,e){this._context.translate(t,e)}_enableTrace(){var t,e,i=this,r=C.length,a=this.setAttr,n=function(t){var r,a=i[t];i[t]=function(){return e=function(t){var e,i,r=[],a=t.length,n=g;for(e=0;e{"dragging"===e.dragStatus&&(t=!0)})),t},justDragged:!1,get node(){var t;return E._dragElements.forEach((e=>{t=e.node})),t},_dragElements:new Map,_drag(t){const e=[];E._dragElements.forEach(((i,r)=>{const{node:a}=i,n=a.getStage();n.setPointersPositions(t),void 0===i.pointerId&&(i.pointerId=g._getFirstPointerId(t));const s=n._changedPointerPositions.find((t=>t.id===i.pointerId));if(s){if("dragging"!==i.dragStatus){var o=a.dragDistance();if(Math.max(Math.abs(s.x-i.startPointerPos.x),Math.abs(s.y-i.startPointerPos.y)){e.fire("dragmove",{type:"dragmove",target:e,evt:t},!0)}))},_endDragBefore(t){const e=[];E._dragElements.forEach((r=>{const{node:a}=r,n=a.getStage();t&&n.setPointersPositions(t);if(!n._changedPointerPositions.find((t=>t.id===r.pointerId)))return;"dragging"!==r.dragStatus&&"stopped"!==r.dragStatus||(E.justDragged=!0,i._mouseListenClick=!1,i._touchListenClick=!1,i._pointerListenClick=!1,r.dragStatus="stopped");const s=r.node.getLayer()||r.node instanceof i.Stage&&r.node;s&&-1===e.indexOf(s)&&e.push(s)})),e.forEach((t=>{t.draw()}))},_endDragAfter(t){E._dragElements.forEach(((e,i)=>{"stopped"===e.dragStatus&&e.node.fire("dragend",{type:"dragend",target:e.node,evt:t},!0),"dragging"!==e.dragStatus&&E._dragElements.delete(i)}))}};i.isBrowser&&(window.addEventListener("mouseup",E._endDragBefore,!0),window.addEventListener("touchend",E._endDragBefore,!0),window.addEventListener("mousemove",E._drag),window.addEventListener("touchmove",E._drag),window.addEventListener("mouseup",E._endDragAfter,!1),window.addEventListener("touchend",E._endDragAfter,!1));var L="absoluteOpacity",D="allEventListeners",O="absoluteTransform",I="absoluteScale",F="canvas",N="listening",B="mouseenter",z="mouseleave",H="Shape",W=" ",Y="stage",X="transform",j="visible",U=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(W);let q=1;class V{constructor(t){this._id=q++,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(t),this._shouldFireChangeEvents=!0}hasChildren(){return!1}_clearCache(t){t!==X&&t!==O||!this._cache.get(t)?t?this._cache.delete(t):this._cache.clear():this._cache.get(t).dirty=!0}_getCache(t,e){var i=this._cache.get(t);return(void 0===i||(t===X||t===O)&&!0===i.dirty)&&(i=e.call(this),this._cache.set(t,i)),i}_calculate(t,e,i){if(!this._attachedDepsListeners.get(t)){const i=e.map((t=>t+"Change.konva")).join(W);this.on(i,(()=>{this._clearCache(t)})),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(F)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===O&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(F)){const{scene:t,filter:e,hit:i}=this._cache.get(F);g.releaseCanvas(t,e,i),this._cache.delete(F)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){var e=t||{},i={};void 0!==e.x&&void 0!==e.y&&void 0!==e.width&&void 0!==e.height||(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()}));var r=Math.ceil(e.width||i.width),a=Math.ceil(e.height||i.height),n=e.pixelRatio,s=void 0===e.x?Math.floor(i.x):e.x,o=void 0===e.y?Math.floor(i.y):e.y,h=e.offset||0,l=e.drawBorder||!1,d=e.hitCanvasPixelRatio||1;if(r&&a){s-=h,o-=h;var c=new G({pixelRatio:n,width:r+=2*h+1,height:a+=2*h+1}),u=new G({pixelRatio:n,width:0,height:0}),f=new R({pixelRatio:d,width:r,height:a}),p=c.getContext(),v=f.getContext();return f.isCache=!0,c.isCache=!0,this._cache.delete(F),this._filterUpToDate=!1,!1===e.imageSmoothingEnabled&&(c.getContext()._context.imageSmoothingEnabled=!1,u.getContext()._context.imageSmoothingEnabled=!1),p.save(),v.save(),p.translate(-s,-o),v.translate(-s,-o),this._isUnderCache=!0,this._clearSelfAndDescendantCache(L),this._clearSelfAndDescendantCache(I),this.drawScene(c,this),this.drawHit(f,this),this._isUnderCache=!1,p.restore(),v.restore(),l&&(p.save(),p.beginPath(),p.rect(0,0,r,a),p.closePath(),p.setAttr("strokeStyle","red"),p.setAttr("lineWidth",5),p.stroke(),p.restore()),this._cache.set(F,{scene:c,filter:u,hit:f,x:s,y:o}),this._requestDraw(),this}g.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.")}isCached(){return this._cache.has(F)}getClientRect(t){throw new Error('abstract "getClientRect" method call')}_transformedRect(t,e){var i,r,a,n,s=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],o=this.getAbsoluteTransform(e);return s.forEach((function(t){var e=o.point(t);void 0===i&&(i=a=e.x,r=n=e.y),i=Math.min(i,e.x),r=Math.min(r,e.y),a=Math.max(a,e.x),n=Math.max(n,e.y)})),{x:i,y:r,width:a-i,height:n-r}}_drawCachedSceneCanvas(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);const e=this._getCanvasCache();t.translate(e.x,e.y);var i=this._getCachedSceneCanvas(),r=i.pixelRatio;t.drawImage(i._canvas,0,0,i.width/r,i.height/r),t.restore()}_drawCachedHitCanvas(t){var e=this._getCanvasCache(),i=e.hit;t.save(),t.translate(e.x,e.y),t.drawImage(i._canvas,0,0,i.width/i.pixelRatio,i.height/i.pixelRatio),t.restore()}_getCachedSceneCanvas(){var t,e,i,r,a=this.filters(),n=this._getCanvasCache(),s=n.scene,o=n.filter,h=o.getContext();if(a){if(!this._filterUpToDate){var l=s.pixelRatio;o.setSize(s.width/s.pixelRatio,s.height/s.pixelRatio);try{for(t=a.length,h.clear(),h.drawImage(s._canvas,0,0,s.getWidth()/l,s.getHeight()/l),e=h.getImageData(0,0,o.getWidth(),o.getHeight()),i=0;i{var e,i;if(!t)return this;for(e in t)"children"!==e&&(i="set"+g._capitalize(e),g._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))})),this}isListening(){return this._getCache(N,this._isListening)}_isListening(t){if(!this.listening())return!1;const e=this.getParent();return!e||e===t||this===t||e._isListening(t)}isVisible(){return this._getCache(j,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const e=this.getParent();return!e||e===t||this===t||e._isVisible(t)}shouldDrawHit(t,e=!1){if(t)return this._isVisible(t)&&this._isListening(t);var r=this.getLayer(),a=!1;E._dragElements.forEach((t=>{"dragging"===t.dragStatus&&("Stage"===t.node.nodeType||t.node.getLayer()===r)&&(a=!0)}));var n=!e&&!i.hitOnDragEnabled&&a;return this.isListening()&&this.isVisible()&&!n}show(){return this.visible(!0),this}hide(){return this.visible(!1),this}getZIndex(){return this.index||0}getAbsoluteZIndex(){var t,e,i,r,a=this.getDepth(),n=this,s=0;return"Stage"!==n.nodeType&&function o(h){for(t=[],e=h.length,i=0;i0&&t[0].getDepth()<=a&&o(t)}(n.getStage().getChildren()),s}getDepth(){for(var t=0,e=this.parent;e;)t++,e=e.parent;return t}_batchTransformChanges(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(X),this._clearSelfAndDescendantCache(O)),this._needClearTransformCache=!1}setPosition(t){return this._batchTransformChanges((()=>{this.x(t.x),this.y(t.y)})),this}getPosition(){return{x:this.x(),y:this.y()}}getRelativePointerPosition(){if(!this.getStage())return null;var t=this.getStage().getPointerPosition();if(!t)return null;var e=this.getAbsoluteTransform().copy();return e.invert(),e.point(t)}getAbsolutePosition(t){let e=!1,i=this.parent;for(;i;){if(i.isCached()){e=!0;break}i=i.parent}e&&!t&&(t=!0);var r=this.getAbsoluteTransform(t).getMatrix(),n=new a,s=this.offset();return n.m=r.slice(),n.translate(s.x,s.y),n.getTranslation()}setAbsolutePosition(t){var e=this._clearTransform();this.attrs.x=e.x,this.attrs.y=e.y,delete e.x,delete e.y,this._clearCache(X);var i=this._getAbsoluteTransform().copy();return i.invert(),i.translate(t.x,t.y),t={x:this.attrs.x+i.getTranslation().x,y:this.attrs.y+i.getTranslation().y},this._setTransform(e),this.setPosition({x:t.x,y:t.y}),this._clearCache(X),this._clearSelfAndDescendantCache(O),this}_setTransform(t){var e;for(e in t)this.attrs[e]=t[e]}_clearTransform(){var t={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,t}move(t){var e=t.x,i=t.y,r=this.x(),a=this.y();return void 0!==e&&(r+=e),void 0!==i&&(a+=i),this.setPosition({x:r,y:a}),this}_eachAncestorReverse(t,e){var i,r,a=[],n=this.getParent();if(!e||e._id!==this._id){for(a.unshift(this);n&&(!e||n._id!==e._id);)a.unshift(n),n=n.parent;for(i=a.length,r=0;r0&&(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0)}moveToBottom(){if(!this.parent)return g.warn("Node has no parent. moveToBottom function is ignored."),!1;var t=this.index;return t>0&&(this.parent.children.splice(t,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0)}setZIndex(t){if(!this.parent)return g.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&g.warn("Unexpected value "+t+" 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)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this}getAbsoluteOpacity(){return this._getCache(L,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t}moveTo(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this}toObject(){var t,e,i,r,a={},n=this.getAttrs();for(t in a.attrs={},n)e=n[t],g.isObject(e)&&!g._isPlainObject(e)&&!g._isArray(e)||(i="function"==typeof this[t]&&this[t],delete n[t],r=i?i.call(this):null,n[t]=e,r!==e&&(a.attrs[t]=e));return a.className=this.getClassName(),g._prepareToStringify(a)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(t,e,i){var r=[];e&&this._isMatch(t)&&r.push(this);for(var a=this.parent;a;){if(a===i)return r;a._isMatch(t)&&r.push(a),a=a.parent}return r}isAncestorOf(t){return!1}findAncestor(t,e,i){return this.findAncestors(t,e,i)[0]}_isMatch(t){if(!t)return!1;if("function"==typeof t)return t(this);var e,i,r=t.replace(/ /g,"").split(","),a=r.length;for(e=0;e{try{const i=null==t?void 0:t.callback;i&&delete t.callback,g._urlToImage(this.toDataURL(t),(function(t){e(t),null==i||i(t)}))}catch(t){i(t)}}))}toBlob(t){return new Promise(((e,i)=>{try{const i=null==t?void 0:t.callback;i&&delete t.callback,this.toCanvas(t).toBlob((t=>{e(t),null==i||i(t)}))}catch(t){i(t)}}))}setSize(t){return this.width(t.width),this.height(t.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return void 0!==this.attrs.dragDistance?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():i.dragDistance}_off(t,e,i){var r,a,n,s=this.eventListeners[t];for(r=0;r=0)&&!this.isDragging()){var e=!1;E._dragElements.forEach((t=>{this.isAncestorOf(t.node)&&(e=!0)})),e||this._createDragElement(t)}}))}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{if(this._dragCleanup(),!this.getStage())return;const t=E._dragElements.get(this._id),e=t&&"dragging"===t.dragStatus,i=t&&"ready"===t.dragStatus;e?this.stopDrag():i&&E._dragElements.delete(this._id)}}_dragCleanup(){this.off("mousedown.konva"),this.off("touchstart.konva")}isClientRectOnScreen(t={x:0,y:0}){const e=this.getStage();if(!e)return!1;const i={x:-t.x,y:-t.y,width:e.width()+2*t.x,height:e.height()+2*t.y};return g.haveIntersection(i,this.getClientRect())}static create(t,e){return g._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)}static _createNode(t,e){var r,a,n,s=V.prototype.getClassName.call(t),o=t.children;e&&(t.attrs.container=e),i[s]||(g.warn('Can not find a node with class name "'+s+'". Fallback to "Shape".'),s="Shape");if(r=new(0,i[s])(t.attrs),o)for(a=o.length,n=0;n0}removeChildren(){return this.getChildren().forEach((t=>{t.parent=null,t.index=0,t.remove()})),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach((t=>{t.parent=null,t.index=0,t.destroy()})),this.children=[],this._requestDraw(),this}add(...t){if(0===t.length)return this;if(t.length>1){for(var e=0;e0?e[0]:void 0}_generalFind(t,e){var i=[];return this._descendants((r=>{const a=r._isMatch(t);return a&&i.push(r),!(!a||!e)})),i}_descendants(t){let e=!1;const i=this.getChildren();for(const r of i){if(e=t(r),e)return!0;if(r.hasChildren()&&(e=r._descendants(t),e))return!0}return!1}toObject(){var t=V.prototype.toObject.call(this);return t.children=[],this.getChildren().forEach((e=>{t.children.push(e.toObject())})),t}isAncestorOf(t){for(var e=t.getParent();e;){if(e._id===this._id)return!0;e=e.getParent()}return!1}clone(t){var e=V.prototype.clone.call(this,t);return this.getChildren().forEach((function(t){e.add(t.clone())})),e}getAllIntersections(t){var e=[];return this.find("Shape").forEach((function(i){i.isVisible()&&i.intersects(t)&&e.push(i)})),e}_clearSelfAndDescendantCache(t){var e;super._clearSelfAndDescendantCache(t),this.isCached()||null===(e=this.children)||void 0===e||e.forEach((function(e){e._clearSelfAndDescendantCache(t)}))}_setChildrenIndices(){var t;null===(t=this.children)||void 0===t||t.forEach((function(t,e){t.index=e})),this._requestDraw()}drawScene(t,e){var i=this.getLayer(),r=t||i&&i.getCanvas(),a=r&&r.getContext(),n=this._getCanvasCache(),s=n&&n.scene,o=r&&r.isCache;if(!this.isVisible()&&!o)return this;if(s){a.save();var h=this.getAbsoluteTransform(e).getMatrix();a.transform(h[0],h[1],h[2],h[3],h[4],h[5]),this._drawCachedSceneCanvas(a),a.restore()}else this._drawChildren("drawScene",r,e);return this}drawHit(t,e){if(!this.shouldDrawHit(e))return this;var i=this.getLayer(),r=t||i&&i.hitCanvas,a=r&&r.getContext(),n=this._getCanvasCache();if(n&&n.hit){a.save();var s=this.getAbsoluteTransform(e).getMatrix();a.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._drawCachedHitCanvas(a),a.restore()}else this._drawChildren("drawHit",r,e);return this}_drawChildren(t,e,i){var r,a=e&&e.getContext(),n=this.clipWidth(),s=this.clipHeight(),o=this.clipFunc(),h=n&&s||o;const l=i===this;if(h){a.save();var d=this.getAbsoluteTransform(i),c=d.getMatrix();if(a.transform(c[0],c[1],c[2],c[3],c[4],c[5]),a.beginPath(),o)o.call(this,a,this);else{var g=this.clipX(),u=this.clipY();a.rect(g,u,n,s)}a.clip(),c=d.copy().invert().getMatrix(),a.transform(c[0],c[1],c[2],c[3],c[4],c[5])}var f=!l&&"source-over"!==this.globalCompositeOperation()&&"drawScene"===t;f&&(a.save(),a._applyGlobalCompositeOperation(this)),null===(r=this.children)||void 0===r||r.forEach((function(r){r[t](e,i)})),f&&a.restore(),h&&a.restore()}getClientRect(t){var e,i,r,a,n,s=(t=t||{}).skipTransform,o=t.relativeTo,h={x:1/0,y:1/0,width:0,height:0},l=this;null===(e=this.children)||void 0===e||e.forEach((function(e){if(e.visible()){var s=e.getClientRect({relativeTo:l,skipShadow:t.skipShadow,skipStroke:t.skipStroke});0===s.width&&0===s.height||(void 0===i?(i=s.x,r=s.y,a=s.x+s.width,n=s.y+s.height):(i=Math.min(i,s.x),r=Math.min(r,s.y),a=Math.max(a,s.x+s.width),n=Math.max(n,s.y+s.height)))}}));for(var d=this.find("Shape"),c=!1,g=0;gt.indexOf("pointer")>=0?"pointer":t.indexOf("touch")>=0?"touch":"mouse",Tt=t=>{const e=kt(t);return"pointer"===e?i.pointerEventsEnabled&&Pt.pointer:"touch"===e?Pt.touch:"mouse"===e?Pt.mouse:void 0};function At(t={}){return(t.clipFunc||t.clipWidth||t.clipHeight)&&g.warn("Stage does not support clipping. Please use clip for Layers or Groups."),t}const Mt=[];class Gt extends Q{constructor(t){super(At(t)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),Mt.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",(()=>{At(this.attrs)})),this._checkVisibility()}_validateAdd(t){const e="Layer"===t.getType(),i="FastLayer"===t.getType();e||i||g.throw("You may only add layers to the stage.")}_checkVisibility(){if(!this.content)return;const t=this.visible()?"":"none";this.content.style.display=t}setContainer(t){if("string"==typeof t){if("."===t.charAt(0)){var e=t.slice(1);t=document.getElementsByClassName(e)[0]}else{var i;i="#"!==t.charAt(0)?t:t.slice(1),t=document.getElementById(i)}if(!t)throw"Can not find container in document with id "+i}return this._setAttr("container",t),this.content&&(this.content.parentElement&&this.content.parentElement.removeChild(this.content),t.appendChild(this.content)),this}shouldDrawHit(){return!0}clear(){var t,e=this.children,i=e.length;for(t=0;t-1&&Mt.splice(e,1),g.releaseCanvas(this.bufferCanvas._canvas,this.bufferHitCanvas._canvas),this}getPointerPosition(){const t=this._pointerPositions[0]||this._changedPointerPositions[0];return t?{x:t.x,y:t.y}:(g.warn("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);"),null)}_getPointerById(t){return this._pointerPositions.find((e=>e.id===t))}getPointersPositions(){return this._pointerPositions}getStage(){return this}getContent(){return this.content}_toKonvaCanvas(t){(t=t||{}).x=t.x||0,t.y=t.y||0,t.width=t.width||this.width(),t.height=t.height||this.height();var e=new G({width:t.width,height:t.height,pixelRatio:t.pixelRatio||1}),i=e.getContext()._context,r=this.children;return(t.x||t.y)&&i.translate(-1*t.x,-1*t.y),r.forEach((function(e){if(e.isVisible()){var r=e._toKonvaCanvas(t);i.drawImage(r._canvas,t.x,t.y,r.getWidth()/r.getPixelRatio(),r.getHeight()/r.getPixelRatio())}})),e}getIntersection(t){if(!t)return null;var e,i=this.children;for(e=i.length-1;e>=0;e--){const r=i[e].getIntersection(t);if(r)return r}return null}_resizeDOM(){var t=this.width(),e=this.height();this.content&&(this.content.style.width=t+"px",this.content.style.height=e+"px"),this.bufferCanvas.setSize(t,e),this.bufferHitCanvas.setSize(t,e),this.children.forEach((i=>{i.setSize({width:t,height:e}),i.draw()}))}add(t,...e){if(arguments.length>1){for(var r=0;r5&&g.warn("The stage has "+a+" 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."),t.setSize({width:this.width(),height:this.height()}),t.draw(),i.isBrowser&&this.content.appendChild(t.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(t){return et(t,this)}setPointerCapture(t){it(t,this)}releaseCapture(t){rt(t)}getLayers(){return this.children}_bindContentEvents(){i.isBrowser&&Ct.forEach((([t,e])=>{this.content.addEventListener(t,(t=>{this[e](t)}),{passive:!1})}))}_pointerenter(t){this.setPointersPositions(t);const e=Tt(t.type);this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);const e=Tt(t.type);this._fire(e.pointerover,{evt:t,target:this,currentTarget:this})}_getTargetShape(t){let e=this[t+"targetShape"];return e&&!e.getStage()&&(e=null),e}_pointerleave(t){const e=Tt(t.type),r=kt(t.type);if(e){this.setPointersPositions(t);var a=this._getTargetShape(r),n=!E.isDragging||i.hitOnDragEnabled;a&&n?(a._fireAndBubble(e.pointerout,{evt:t}),a._fireAndBubble(e.pointerleave,{evt:t}),this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this[r+"targetShape"]=null):n&&(this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this._fire(e.pointerout,{evt:t,target:this,currentTarget:this})),this.pointerPos=void 0,this._pointerPositions=[]}}_pointerdown(t){const e=Tt(t.type),r=kt(t.type);if(e){this.setPointersPositions(t);var a=!1;this._changedPointerPositions.forEach((n=>{var s=this.getIntersection(n);E.justDragged=!1,i["_"+r+"ListenClick"]=!0;if(!(s&&s.isListening()))return;i.capturePointerEventsEnabled&&s.setPointerCapture(n.id),this[r+"ClickStartShape"]=s,s._fireAndBubble(e.pointerdown,{evt:t,pointerId:n.id}),a=!0;const o=t.type.indexOf("touch")>=0;s.preventDefault()&&t.cancelable&&o&&t.preventDefault()})),a||this._fire(e.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}}_pointermove(t){const e=Tt(t.type),r=kt(t.type);if(!e)return;if(E.isDragging&&E.node.preventDefault()&&t.cancelable&&t.preventDefault(),this.setPointersPositions(t),!(!E.isDragging||i.hitOnDragEnabled))return;var a={};let n=!1;var s=this._getTargetShape(r);this._changedPointerPositions.forEach((i=>{const o=$(i.id)||this.getIntersection(i),h=i.id,l={evt:t,pointerId:h};var d=s!==o;if(d&&s&&(s._fireAndBubble(e.pointerout,Object.assign({},l),o),s._fireAndBubble(e.pointerleave,Object.assign({},l),o)),o){if(a[o._id])return;a[o._id]=!0}o&&o.isListening()?(n=!0,d&&(o._fireAndBubble(e.pointerover,Object.assign({},l),s),o._fireAndBubble(e.pointerenter,Object.assign({},l),s),this[r+"targetShape"]=o),o._fireAndBubble(e.pointermove,Object.assign({},l))):s&&(this._fire(e.pointerover,{evt:t,target:this,currentTarget:this,pointerId:h}),this[r+"targetShape"]=null)})),n||this._fire(e.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(t){const e=Tt(t.type),r=kt(t.type);if(!e)return;this.setPointersPositions(t);const a=this[r+"ClickStartShape"],n=this[r+"ClickEndShape"];var s={};let o=!1;this._changedPointerPositions.forEach((h=>{const l=$(h.id)||this.getIntersection(h);if(l){if(l.releaseCapture(h.id),s[l._id])return;s[l._id]=!0}const d=h.id,c={evt:t,pointerId:d};let g=!1;i["_"+r+"InDblClickWindow"]?(g=!0,clearTimeout(this[r+"DblTimeout"])):E.justDragged||(i["_"+r+"InDblClickWindow"]=!0,clearTimeout(this[r+"DblTimeout"])),this[r+"DblTimeout"]=setTimeout((function(){i["_"+r+"InDblClickWindow"]=!1}),i.dblClickWindow),l&&l.isListening()?(o=!0,this[r+"ClickEndShape"]=l,l._fireAndBubble(e.pointerup,Object.assign({},c)),i["_"+r+"ListenClick"]&&a&&a===l&&(l._fireAndBubble(e.pointerclick,Object.assign({},c)),g&&n&&n===l&&l._fireAndBubble(e.pointerdblclick,Object.assign({},c)))):(this[r+"ClickEndShape"]=null,i["_"+r+"ListenClick"]&&this._fire(e.pointerclick,{evt:t,target:this,currentTarget:this,pointerId:d}),g&&this._fire(e.pointerdblclick,{evt:t,target:this,currentTarget:this,pointerId:d}))})),o||this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),i["_"+r+"ListenClick"]=!1,t.cancelable&&"touch"!==r&&t.preventDefault()}_contextmenu(t){this.setPointersPositions(t);var e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(_t,{evt:t}):this._fire(_t,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);var e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(wt,{evt:t}):this._fire(wt,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);const e=$(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(gt,tt(t)),rt(t.pointerId)}_lostpointercapture(t){rt(t.pointerId)}setPointersPositions(t){var e=this._getContentPosition(),i=null,r=null;void 0!==(t=t||window.event).touches?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(t.touches,(t=>{this._pointerPositions.push({id:t.identifier,x:(t.clientX-e.left)/e.scaleX,y:(t.clientY-e.top)/e.scaleY})})),Array.prototype.forEach.call(t.changedTouches||t.touches,(t=>{this._changedPointerPositions.push({id:t.identifier,x:(t.clientX-e.left)/e.scaleX,y:(t.clientY-e.top)/e.scaleY})}))):(i=(t.clientX-e.left)/e.scaleX,r=(t.clientY-e.top)/e.scaleY,this.pointerPos={x:i,y:r},this._pointerPositions=[{x:i,y:r,id:g._getFirstPointerId(t)}],this._changedPointerPositions=[{x:i,y:r,id:g._getFirstPointerId(t)}])}_setPointerPosition(t){g.warn('Method _setPointerPosition is deprecated. Use "stage.setPointersPositions(event)" instead.'),this.setPointersPositions(t)}_getContentPosition(){if(!this.content||!this.content.getBoundingClientRect)return{top:0,left:0,scaleX:1,scaleY:1};var t=this.content.getBoundingClientRect();return{top:t.top,left:t.left,scaleX:t.width/this.content.clientWidth||1,scaleY:t.height/this.content.clientHeight||1}}_buildDOM(){if(this.bufferCanvas=new G({width:this.width(),height:this.height()}),this.bufferHitCanvas=new R({pixelRatio:1,width:this.width(),height:this.height()}),i.isBrowser){var t=this.container();if(!t)throw"Stage has no container. A container is required.";t.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"),t.appendChild(this.content),this._resizeDOM()}}cache(){return g.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(t){t.batchDraw()})),this}}Gt.prototype.nodeType="Stage",r(Gt),w.addGetterSetter(Gt,"container");var Rt="hasShadow",Et="shadowRGBA",Lt="patternImage",Dt="linearGradient",Ot="radialGradient";let It;function Ft(){return It||(It=g.createCanvasElement().getContext("2d"),It)}const Nt={};class Bt extends V{constructor(t){let e;for(super(t);e=g.getRandomColor(),!e||e in Nt;);this.colorKey=e,Nt[e]=this}getContext(){return g.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return g.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(Rt,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&0!==this.shadowOpacity()&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(Lt,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const t=Ft().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(t&&t.setTransform){const e=new a;e.translate(this.fillPatternX(),this.fillPatternY()),e.rotate(i.getAngle(this.fillPatternRotation())),e.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),e.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());const r=e.getMatrix(),n="undefined"==typeof DOMMatrix?{a:r[0],b:r[1],c:r[2],d:r[3],e:r[4],f:r[5]}:new DOMMatrix(r);t.setTransform(n)}return t}}_getLinearGradient(){return this._getCache(Dt,this.__getLinearGradient)}__getLinearGradient(){var t=this.fillLinearGradientColorStops();if(t){for(var e=Ft(),i=this.fillLinearGradientStartPoint(),r=this.fillLinearGradientEndPoint(),a=e.createLinearGradient(i.x,i.y,r.x,r.y),n=0;nthis.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(){const t=this.hitStrokeWidth();return"auto"===t?this.hasStroke():this.strokeEnabled()&&!!t}intersects(t){var e=this.getStage().bufferHitCanvas;return e.getContext().clear(),this.drawHit(e,null,!0),e.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data[3]>0}destroy(){return V.prototype.destroy.call(this),delete Nt[this.colorKey],delete this.colorKey,this}_useBufferCanvas(t){var e;if(!this.getStage())return!1;if(!(null===(e=this.attrs.perfectDrawEnabled)||void 0===e||e))return!1;const i=t||this.hasFill(),r=this.hasStroke(),a=1!==this.getAbsoluteOpacity();if(i&&r&&a)return!0;const n=this.hasShadow(),s=this.shadowForStrokeEnabled();return!!(i&&r&&n&&s)}setStrokeHitEnabled(t){g.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return 0!==this.hitStrokeWidth()}getSelfRect(){var t=this.size();return{x:this._centroid?-t.width/2:0,y:this._centroid?-t.height/2:0,width:t.width,height:t.height}}getClientRect(t={}){const e=t.skipTransform,i=t.relativeTo,r=this.getSelfRect(),a=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,n=r.width+a,s=r.height+a,o=!t.skipShadow&&this.hasShadow(),h=o?this.shadowOffsetX():0,l=o?this.shadowOffsetY():0,d=n+Math.abs(h),c=s+Math.abs(l),g=o&&this.shadowBlur()||0,u={width:d+2*g,height:c+2*g,x:-(a/2+g)+Math.min(h,0)+r.x,y:-(a/2+g)+Math.min(l,0)+r.y};return e?u:this._transformedRect(u,i)}drawScene(t,e){var i,r,a=this.getLayer(),n=t||a.getCanvas(),s=n.getContext(),o=this._getCanvasCache(),h=this.getSceneFunc(),l=this.hasShadow(),d=n.isCache,c=e===this;if(!this.isVisible()&&!c)return this;if(o){s.save();var g=this.getAbsoluteTransform(e).getMatrix();return s.transform(g[0],g[1],g[2],g[3],g[4],g[5]),this._drawCachedSceneCanvas(s),s.restore(),this}if(!h)return this;if(s.save(),this._useBufferCanvas()&&!d){(r=(i=this.getStage().bufferCanvas).getContext()).clear(),r.save(),r._applyLineJoin(this);var u=this.getAbsoluteTransform(e).getMatrix();r.transform(u[0],u[1],u[2],u[3],u[4],u[5]),h.call(this,r,this),r.restore();var f=i.pixelRatio;l&&s._applyShadow(this),s._applyOpacity(this),s._applyGlobalCompositeOperation(this),s.drawImage(i._canvas,0,0,i.width/f,i.height/f)}else{if(s._applyLineJoin(this),!c){u=this.getAbsoluteTransform(e).getMatrix();s.transform(u[0],u[1],u[2],u[3],u[4],u[5]),s._applyOpacity(this),s._applyGlobalCompositeOperation(this)}l&&s._applyShadow(this),h.call(this,s,this)}return s.restore(),this}drawHit(t,e,i=!1){if(!this.shouldDrawHit(e,i))return this;var r=this.getLayer(),a=t||r.hitCanvas,n=a&&a.getContext(),s=this.hitFunc()||this.sceneFunc(),o=this._getCanvasCache(),h=o&&o.hit;if(this.colorKey||g.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()"),h){n.save();var l=this.getAbsoluteTransform(e).getMatrix();return n.transform(l[0],l[1],l[2],l[3],l[4],l[5]),this._drawCachedHitCanvas(n),n.restore(),this}if(!s)return this;n.save(),n._applyLineJoin(this);if(!(this===e)){var d=this.getAbsoluteTransform(e).getMatrix();n.transform(d[0],d[1],d[2],d[3],d[4],d[5])}return s.call(this,n,this),n.restore(),this}drawHitFromCache(t=0){var e,i,r,a,n,s=this._getCanvasCache(),o=this._getCachedSceneCanvas(),h=s.hit,l=h.getContext(),d=h.getWidth(),c=h.getHeight();l.clear(),l.drawImage(o._canvas,0,0,d,c);try{for(r=(i=(e=l.getImageData(0,0,d,c)).data).length,a=g._hexToRgb(this.colorKey),n=0;nt?(i[n]=a.r,i[n+1]=a.g,i[n+2]=a.b,i[n+3]=255):i[n+3]=0;l.putImageData(e,0,0)}catch(t){g.error("Unable to draw hit graph from cached scene canvas. "+t.message)}return this}hasPointerCapture(t){return et(t,this)}setPointerCapture(t){it(t,this)}releaseCapture(t){rt(t)}}Bt.prototype._fillFunc=function(t){t.fill()},Bt.prototype._strokeFunc=function(t){t.stroke()},Bt.prototype._fillFuncHit=function(t){t.fill()},Bt.prototype._strokeFuncHit=function(t){t.stroke()},Bt.prototype._centroid=!1,Bt.prototype.nodeType="Shape",r(Bt),Bt.prototype.eventListeners={},Bt.prototype.on.call(Bt.prototype,"shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",(function(){this._clearCache(Rt)})),Bt.prototype.on.call(Bt.prototype,"shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",(function(){this._clearCache(Et)})),Bt.prototype.on.call(Bt.prototype,"fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",(function(){this._clearCache(Lt)})),Bt.prototype.on.call(Bt.prototype,"fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",(function(){this._clearCache(Dt)})),Bt.prototype.on.call(Bt.prototype,"fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",(function(){this._clearCache(Ot)})),w.addGetterSetter(Bt,"stroke",void 0,y()),w.addGetterSetter(Bt,"strokeWidth",2,p()),w.addGetterSetter(Bt,"fillAfterStrokeEnabled",!1),w.addGetterSetter(Bt,"hitStrokeWidth","auto",m()),w.addGetterSetter(Bt,"strokeHitEnabled",!0,x()),w.addGetterSetter(Bt,"perfectDrawEnabled",!0,x()),w.addGetterSetter(Bt,"shadowForStrokeEnabled",!0,x()),w.addGetterSetter(Bt,"lineJoin"),w.addGetterSetter(Bt,"lineCap"),w.addGetterSetter(Bt,"sceneFunc"),w.addGetterSetter(Bt,"hitFunc"),w.addGetterSetter(Bt,"dash"),w.addGetterSetter(Bt,"dashOffset",0,p()),w.addGetterSetter(Bt,"shadowColor",void 0,_()),w.addGetterSetter(Bt,"shadowBlur",0,p()),w.addGetterSetter(Bt,"shadowOpacity",1,p()),w.addComponentsGetterSetter(Bt,"shadowOffset",["x","y"]),w.addGetterSetter(Bt,"shadowOffsetX",0,p()),w.addGetterSetter(Bt,"shadowOffsetY",0,p()),w.addGetterSetter(Bt,"fillPatternImage"),w.addGetterSetter(Bt,"fill",void 0,y()),w.addGetterSetter(Bt,"fillPatternX",0,p()),w.addGetterSetter(Bt,"fillPatternY",0,p()),w.addGetterSetter(Bt,"fillLinearGradientColorStops"),w.addGetterSetter(Bt,"strokeLinearGradientColorStops"),w.addGetterSetter(Bt,"fillRadialGradientStartRadius",0),w.addGetterSetter(Bt,"fillRadialGradientEndRadius",0),w.addGetterSetter(Bt,"fillRadialGradientColorStops"),w.addGetterSetter(Bt,"fillPatternRepeat","repeat"),w.addGetterSetter(Bt,"fillEnabled",!0),w.addGetterSetter(Bt,"strokeEnabled",!0),w.addGetterSetter(Bt,"shadowEnabled",!0),w.addGetterSetter(Bt,"dashEnabled",!0),w.addGetterSetter(Bt,"strokeScaleEnabled",!0),w.addGetterSetter(Bt,"fillPriority","color"),w.addComponentsGetterSetter(Bt,"fillPatternOffset",["x","y"]),w.addGetterSetter(Bt,"fillPatternOffsetX",0,p()),w.addGetterSetter(Bt,"fillPatternOffsetY",0,p()),w.addComponentsGetterSetter(Bt,"fillPatternScale",["x","y"]),w.addGetterSetter(Bt,"fillPatternScaleX",1,p()),w.addGetterSetter(Bt,"fillPatternScaleY",1,p()),w.addComponentsGetterSetter(Bt,"fillLinearGradientStartPoint",["x","y"]),w.addComponentsGetterSetter(Bt,"strokeLinearGradientStartPoint",["x","y"]),w.addGetterSetter(Bt,"fillLinearGradientStartPointX",0),w.addGetterSetter(Bt,"strokeLinearGradientStartPointX",0),w.addGetterSetter(Bt,"fillLinearGradientStartPointY",0),w.addGetterSetter(Bt,"strokeLinearGradientStartPointY",0),w.addComponentsGetterSetter(Bt,"fillLinearGradientEndPoint",["x","y"]),w.addComponentsGetterSetter(Bt,"strokeLinearGradientEndPoint",["x","y"]),w.addGetterSetter(Bt,"fillLinearGradientEndPointX",0),w.addGetterSetter(Bt,"strokeLinearGradientEndPointX",0),w.addGetterSetter(Bt,"fillLinearGradientEndPointY",0),w.addGetterSetter(Bt,"strokeLinearGradientEndPointY",0),w.addComponentsGetterSetter(Bt,"fillRadialGradientStartPoint",["x","y"]),w.addGetterSetter(Bt,"fillRadialGradientStartPointX",0),w.addGetterSetter(Bt,"fillRadialGradientStartPointY",0),w.addComponentsGetterSetter(Bt,"fillRadialGradientEndPoint",["x","y"]),w.addGetterSetter(Bt,"fillRadialGradientEndPointX",0),w.addGetterSetter(Bt,"fillRadialGradientEndPointY",0),w.addGetterSetter(Bt,"fillPatternRotation",0),w.backCompat(Bt,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});var zt=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],Ht=zt.length;class Wt extends Q{constructor(t){super(t),this.canvas=new G,this.hitCanvas=new R({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(t){return this.getContext().clear(t),this.getHitCanvas().getContext().clear(t),this}setZIndex(t){super.setZIndex(t);var e=this.getStage();return e&&e.content&&(e.content.removeChild(this.getNativeCanvasElement()),t{this.draw(),this._waitingForDraw=!1}))),this}getIntersection(t){if(!this.isListening()||!this.isVisible())return null;for(var e=1,i=!1;;){for(let r=0;r0?{antialiased:!0}:{}}drawScene(t,e){var i=this.getLayer(),r=t||i&&i.getCanvas();return this._fire("beforeDraw",{node:this}),this.clearBeforeDraw()&&r.getContext().clear(),Q.prototype.drawScene.call(this,r,e),this._fire("draw",{node:this}),this}drawHit(t,e){var i=this.getLayer(),r=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),Q.prototype.drawHit.call(this,r,e),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(t){g.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}getHitGraphEnabled(t){return g.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening()}toggleHitCanvas(){if(this.parent&&this.parent.content){var t=this.parent;!!this.hitCanvas._canvas.parentNode?t.content.removeChild(this.hitCanvas._canvas):t.content.appendChild(this.hitCanvas._canvas)}}destroy(){return g.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}}Wt.prototype.nodeType="Layer",r(Wt),w.addGetterSetter(Wt,"imageSmoothingEnabled",!0),w.addGetterSetter(Wt,"clearBeforeDraw",!0),w.addGetterSetter(Wt,"hitGraphEnabled",!0,x());class Yt extends Wt{constructor(t){super(t),this.listening(!1),g.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}}Yt.prototype.nodeType="FastLayer",r(Yt);class Xt extends Q{_validateAdd(t){var e=t.getType();"Group"!==e&&"Shape"!==e&&g.throw("You may only add groups and shapes to groups.")}}Xt.prototype.nodeType="Group",r(Xt);var jt=e.performance&&e.performance.now?function(){return e.performance.now()}:function(){return(new Date).getTime()};class Ut{constructor(t,e){this.id=Ut.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:jt(),frameRate:0},this.func=t,this.setLayers(e)}setLayers(t){var e=[];return e=t?t.length>0?t:[t]:[],this.layers=e,this}getLayers(){return this.layers}addLayer(t){var e,i=this.layers,r=i.length;for(e=0;ethis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())}getTime(){return this._time}setPosition(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t}getPosition(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)}play(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")}seek(t){this.pause(),this._time=t,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(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)}pause(){this.state=1,this.fire("onPause")}getTimer(){return(new Date).getTime()}}class Jt{constructor(t){var e,r,a=this,n=t.node,s=n._id,o=t.easing||Zt.Linear,h=!!t.yoyo;e=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=n,this._id=Vt++;var l=n.getLayer()||(n instanceof i.Stage?n.getLayers():null);for(r in l||g.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Ut((function(){a.tween.onEnterFrame()}),l),this.tween=new Qt(r,(function(t){a._tweenFunc(t)}),o,0,1,1e3*e,h),this._addListeners(),Jt.attrs[s]||(Jt.attrs[s]={}),Jt.attrs[s][this._id]||(Jt.attrs[s][this._id]={}),Jt.tweens[s]||(Jt.tweens[s]={}),t)void 0===qt[r]&&this._addAttr(r,t[r]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset,this.onUpdate=t.onUpdate}_addAttr(t,e){var i,r,a,n,s,o,h,l,d=this.node,c=d._id;if((a=Jt.tweens[c][t])&&delete Jt.attrs[c][a][t],i=d.getAttr(t),g._isArray(e))if(r=[],s=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(h=i,i=g._prepareArrayForTween(i,e,d.closed())):(o=e,e=g._prepareArrayForTween(e,i,d.closed()))),0===t.indexOf("fill"))for(n=0;n{this.anim.start()},this.tween.onReverse=()=>{this.anim.start()},this.tween.onPause=()=>{this.anim.stop()},this.tween.onFinish=()=>{var t=this.node,e=Jt.attrs[t._id][this._id];e.points&&e.points.trueEnd&&t.setAttr("points",e.points.trueEnd),this.onFinish&&this.onFinish.call(this)},this.tween.onReset=()=>{var t=this.node,e=Jt.attrs[t._id][this._id];e.points&&e.points.trueStart&&t.points(e.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(t){return this.tween.seek(1e3*t),this}pause(){return this.tween.pause(),this}finish(){return this.tween.finish(),this}destroy(){var t,e=this.node._id,i=this._id,r=Jt.tweens[e];for(t in this.pause(),r)delete Jt.tweens[e][t];delete Jt.attrs[e][i]}}Jt.attrs={},Jt.tweens={},V.prototype.to=function(t){var e=t.onFinish;t.node=this,t.onFinish=function(){this.destroy(),e&&e()},new Jt(t).play()};const Zt={BackEaseIn(t,e,i,r){var a=1.70158;return i*(t/=r)*t*((a+1)*t-a)+e},BackEaseOut(t,e,i,r){var a=1.70158;return i*((t=t/r-1)*t*((a+1)*t+a)+1)+e},BackEaseInOut(t,e,i,r){var a=1.70158;return(t/=r/2)<1?i/2*(t*t*((1+(a*=1.525))*t-a))+e:i/2*((t-=2)*t*((1+(a*=1.525))*t+a)+2)+e},ElasticEaseIn(t,e,i,r,a,n){var s=0;return 0===t?e:1==(t/=r)?e+i:(n||(n=.3*r),!a||a(t/=r)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e,BounceEaseIn:(t,e,i,r)=>i-Zt.BounceEaseOut(r-t,0,i,r)+e,BounceEaseInOut:(t,e,i,r)=>ti*(t/=r)*t+e,EaseOut:(t,e,i,r)=>-i*(t/=r)*(t-2)+e,EaseInOut:(t,e,i,r)=>(t/=r/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e,StrongEaseIn:(t,e,i,r)=>i*(t/=r)*t*t*t*t+e,StrongEaseOut:(t,e,i,r)=>i*((t=t/r-1)*t*t*t*t+1)+e,StrongEaseInOut:(t,e,i,r)=>(t/=r/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e,Linear:(t,e,i,r)=>i*t/r+e},$t=g._assign(i,{Util:g,Transform:a,Node:V,Container:Q,Stage:Gt,stages:Mt,Layer:Wt,FastLayer:Yt,Group:Xt,DD:E,Shape:Bt,shapes:Nt,Animation:Ut,Tween:Jt,Easings:Zt,Context:P,Canvas:M});class te extends Bt{_sceneFunc(t){var e=i.getAngle(this.angle()),r=this.clockwise();t.beginPath(),t.arc(0,0,this.outerRadius(),0,e,r),t.arc(0,0,this.innerRadius(),e,0,!r),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}getSelfRect(){const t=this.innerRadius(),e=this.outerRadius(),r=this.clockwise(),a=i.getAngle(r?360-this.angle():this.angle()),n=Math.cos(Math.min(a,Math.PI)),s=Math.sin(Math.min(Math.max(Math.PI,a),3*Math.PI/2)),o=Math.sin(Math.min(a,Math.PI/2)),h=n*(n>0?t:e),l=s*(s>0?t:e),d=o*(o>0?e:t);return{x:h,y:r?-1*d:l,width:1*e-h,height:d-l}}}function ee(t,e,i,r,a,n,s){var o=Math.sqrt(Math.pow(i-t,2)+Math.pow(r-e,2)),h=Math.sqrt(Math.pow(a-i,2)+Math.pow(n-r,2)),l=s*o/(o+h),d=s*h/(o+h);return[i-l*(a-t),r-l*(n-e),i+d*(a-t),r+d*(n-e)]}function ie(t,e){var i,r,a=t.length,n=[];for(i=2;i4){for(i=(e=this.getTensionPoints()).length,r=o?0:4,o||t.quadraticCurveTo(e[0],e[1],e[2],e[3]);rl?h:l,p=h>l?1:h/l,v=h>l?l/h:1;t.translate(s,o),t.rotate(g),t.scale(p,v),t.arc(0,0,f,d,d+c,1-u),t.scale(1/p,1/v),t.rotate(-g),t.translate(-s,-o);break;case"z":i=!0,t.closePath()}}i||this.hasFill()?t.fillStrokeShape(this):t.strokeShape(this)}getSelfRect(){var t=[];this.dataArray.forEach((function(e){if("A"===e.command){var i=e.points[4],r=e.points[5],a=e.points[4]+r,n=Math.PI/180;if(Math.abs(i-a)a;r-=n){const i=ae.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],r,0);t.push(i.x,i.y)}else for(let r=i+n;rthis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===r)return{x:(e=this.dataArray[i-1].points.slice(-2))[0],y:e[1]};if(t<.01)return{x:(e=this.dataArray[i].points.slice(0,2))[0],y:e[1]};var a=this.dataArray[i],n=a.points;switch(a.command){case"L":return ae.getPointOnLine(t,a.start.x,a.start.y,n[0],n[1]);case"C":return ae.getPointOnCubicBezier(t/a.pathLength,a.start.x,a.start.y,n[0],n[1],n[2],n[3],n[4],n[5]);case"Q":return ae.getPointOnQuadraticBezier(t/a.pathLength,a.start.x,a.start.y,n[0],n[1],n[2],n[3]);case"A":var s=n[0],o=n[1],h=n[2],l=n[3],d=n[4],c=n[5],g=n[6];return d+=c*t/a.pathLength,ae.getPointOnEllipticalArc(s,o,h,l,d,g)}return null}static getLineLength(t,e,i,r){return Math.sqrt((i-t)*(i-t)+(r-e)*(r-e))}static getPointOnLine(t,e,i,r,a,n,s){void 0===n&&(n=e),void 0===s&&(s=i);var o=(a-i)/(r-e+1e-8),h=Math.sqrt(t*t/(1+o*o));r0&&!isNaN(u[0]);){var m,_,y,x,b,S,w,C,P,k,T=null,A=[],M=h,G=l;switch(g){case"l":h+=u.shift(),l+=u.shift(),T="L",A.push(h,l);break;case"L":h=u.shift(),l=u.shift(),A.push(h,l);break;case"m":var R=u.shift(),E=u.shift();if(h+=R,l+=E,T="M",s.length>2&&"z"===s[s.length-1].command)for(var L=s.length-2;L>=0;L--)if("M"===s[L].command){h=s[L].points[0]+R,l=s[L].points[1]+E;break}A.push(h,l),g="l";break;case"M":h=u.shift(),l=u.shift(),T="M",A.push(h,l),g="L";break;case"h":h+=u.shift(),T="L",A.push(h,l);break;case"H":h=u.shift(),T="L",A.push(h,l);break;case"v":l+=u.shift(),T="L",A.push(h,l);break;case"V":l=u.shift(),T="L",A.push(h,l);break;case"C":A.push(u.shift(),u.shift(),u.shift(),u.shift()),h=u.shift(),l=u.shift(),A.push(h,l);break;case"c":A.push(h+u.shift(),l+u.shift(),h+u.shift(),l+u.shift()),h+=u.shift(),l+=u.shift(),T="C",A.push(h,l);break;case"S":_=h,y=l,"C"===(m=s[s.length-1]).command&&(_=h+(h-m.points[2]),y=l+(l-m.points[3])),A.push(_,y,u.shift(),u.shift()),h=u.shift(),l=u.shift(),T="C",A.push(h,l);break;case"s":_=h,y=l,"C"===(m=s[s.length-1]).command&&(_=h+(h-m.points[2]),y=l+(l-m.points[3])),A.push(_,y,h+u.shift(),l+u.shift()),h+=u.shift(),l+=u.shift(),T="C",A.push(h,l);break;case"Q":A.push(u.shift(),u.shift()),h=u.shift(),l=u.shift(),A.push(h,l);break;case"q":A.push(h+u.shift(),l+u.shift()),h+=u.shift(),l+=u.shift(),T="Q",A.push(h,l);break;case"T":_=h,y=l,"Q"===(m=s[s.length-1]).command&&(_=h+(h-m.points[0]),y=l+(l-m.points[1])),h=u.shift(),l=u.shift(),T="Q",A.push(_,y,h,l);break;case"t":_=h,y=l,"Q"===(m=s[s.length-1]).command&&(_=h+(h-m.points[0]),y=l+(l-m.points[1])),h+=u.shift(),l+=u.shift(),T="Q",A.push(_,y,h,l);break;case"A":x=u.shift(),b=u.shift(),S=u.shift(),w=u.shift(),C=u.shift(),P=h,k=l,h=u.shift(),l=u.shift(),T="A",A=this.convertEndpointToCenterParameterization(P,k,h,l,w,C,x,b,S);break;case"a":x=u.shift(),b=u.shift(),S=u.shift(),w=u.shift(),C=u.shift(),P=h,k=l,h+=u.shift(),l+=u.shift(),T="A",A=this.convertEndpointToCenterParameterization(P,k,h,l,w,C,x,b,S)}s.push({command:T||g,points:A,start:{x:M,y:G},pathLength:this.calcLength(M,G,T||g,A)})}"z"!==g&&"Z"!==g||s.push({command:"z",points:[],start:void 0,pathLength:0})}return s}static calcLength(t,e,i,r){var a,n,s,o,h=ae;switch(i){case"L":return h.getLineLength(t,e,r[0],r[1]);case"C":for(a=0,n=h.getPointOnCubicBezier(0,t,e,r[0],r[1],r[2],r[3],r[4],r[5]),o=.01;o<=1;o+=.01)s=h.getPointOnCubicBezier(o,t,e,r[0],r[1],r[2],r[3],r[4],r[5]),a+=h.getLineLength(n.x,n.y,s.x,s.y),n=s;return a;case"Q":for(a=0,n=h.getPointOnQuadraticBezier(0,t,e,r[0],r[1],r[2],r[3]),o=.01;o<=1;o+=.01)s=h.getPointOnQuadraticBezier(o,t,e,r[0],r[1],r[2],r[3]),a+=h.getLineLength(n.x,n.y,s.x,s.y),n=s;return a;case"A":a=0;var l=r[4],d=r[5],c=r[4]+d,g=Math.PI/180;if(Math.abs(l-c)c;o-=g)s=h.getPointOnEllipticalArc(r[0],r[1],r[2],r[3],o,0),a+=h.getLineLength(n.x,n.y,s.x,s.y),n=s;else for(o=l+g;o1&&(s*=Math.sqrt(g),o*=Math.sqrt(g));var u=Math.sqrt((s*s*(o*o)-s*s*(c*c)-o*o*(d*d))/(s*s*(c*c)+o*o*(d*d)));a===n&&(u*=-1),isNaN(u)&&(u=0);var f=u*s*c/o,p=u*-o*d/s,v=(t+i)/2+Math.cos(l)*f-Math.sin(l)*p,m=(e+r)/2+Math.sin(l)*f+Math.cos(l)*p,_=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},y=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(_(t)*_(e))},x=function(t,e){return(t[0]*e[1]=1&&(C=0),0===n&&C>0&&(C-=2*Math.PI),1===n&&C<0&&(C+=2*Math.PI),[v,m,s,o,b,C,l,n]}}ae.prototype.className="Path",ae.prototype._attrsAffectingSize=["data"],r(ae),w.addGetterSetter(ae,"data");class ne extends re{_sceneFunc(t){super._sceneFunc(t);var e=2*Math.PI,i=this.points(),r=i,a=0!==this.tension()&&i.length>4;a&&(r=this.getTensionPoints());var n,s,o=this.pointerLength(),h=i.length;if(a){const t=[r[r.length-4],r[r.length-3],r[r.length-2],r[r.length-1],i[h-2],i[h-1]],e=ae.calcLength(r[r.length-4],r[r.length-3],"C",t),a=ae.getPointOnQuadraticBezier(Math.min(1,1-o/e),t[0],t[1],t[2],t[3],t[4],t[5]);n=i[h-2]-a.x,s=i[h-1]-a.y}else n=i[h-2]-i[h-4],s=i[h-1]-i[h-3];var l=(Math.atan2(s,n)+e)%e,d=this.pointerWidth();this.pointerAtEnding()&&(t.save(),t.beginPath(),t.translate(i[h-2],i[h-1]),t.rotate(l),t.moveTo(0,0),t.lineTo(-o,d/2),t.lineTo(-o,-d/2),t.closePath(),t.restore(),this.__fillStroke(t)),this.pointerAtBeginning()&&(t.save(),t.beginPath(),t.translate(i[0],i[1]),a?(n=(r[0]+r[2])/2-i[0],s=(r[1]+r[3])/2-i[1]):(n=i[2]-i[0],s=i[3]-i[1]),t.rotate((Math.atan2(-s,-n)+e)%e),t.moveTo(0,0),t.lineTo(-o,d/2),t.lineTo(-o,-d/2),t.closePath(),t.restore(),this.__fillStroke(t))}__fillStroke(t){var e=this.dashEnabled();e&&(this.attrs.dashEnabled=!1,t.setLineDash([])),t.fillStrokeShape(this),e&&(this.attrs.dashEnabled=!0)}getSelfRect(){const t=super.getSelfRect(),e=this.pointerWidth()/2;return{x:t.x-e,y:t.y-e,width:t.width+2*e,height:t.height+2*e}}}ne.prototype.className="Arrow",r(ne),w.addGetterSetter(ne,"pointerLength",10,p()),w.addGetterSetter(ne,"pointerWidth",10,p()),w.addGetterSetter(ne,"pointerAtBeginning",!1),w.addGetterSetter(ne,"pointerAtEnding",!0);class se extends Bt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.attrs.radius||0,0,2*Math.PI,!1),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius()!==t/2&&this.radius(t/2)}setHeight(t){this.radius()!==t/2&&this.radius(t/2)}}se.prototype._centroid=!0,se.prototype.className="Circle",se.prototype._attrsAffectingSize=["radius"],r(se),w.addGetterSetter(se,"radius",0,p());class oe extends Bt{_sceneFunc(t){var e=this.radiusX(),i=this.radiusY();t.beginPath(),t.save(),e!==i&&t.scale(1,i/e),t.arc(0,0,e,0,2*Math.PI,!1),t.restore(),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radiusX()}getHeight(){return 2*this.radiusY()}setWidth(t){this.radiusX(t/2)}setHeight(t){this.radiusY(t/2)}}oe.prototype.className="Ellipse",oe.prototype._centroid=!0,oe.prototype._attrsAffectingSize=["radiusX","radiusY"],r(oe),w.addComponentsGetterSetter(oe,"radius",["x","y"]),w.addGetterSetter(oe,"radiusX",0,p()),w.addGetterSetter(oe,"radiusY",0,p());class he extends Bt{constructor(t){super(t),this.on("imageChange.konva",(()=>{this._setImageLoad()})),this._setImageLoad()}_setImageLoad(){const t=this.image();t&&t.complete||t&&4===t.readyState||t&&t.addEventListener&&t.addEventListener("load",(()=>{this._requestDraw()}))}_useBufferCanvas(){return super._useBufferCanvas(!0)}_sceneFunc(t){const e=this.getWidth(),i=this.getHeight(),r=this.cornerRadius(),a=this.attrs.image;let n;if(a){const t=this.attrs.cropWidth,r=this.attrs.cropHeight;n=t&&r?[a,this.cropX(),this.cropY(),t,r,0,0,e,i]:[a,0,0,e,i]}(this.hasFill()||this.hasStroke()||r)&&(t.beginPath(),r?g.drawRoundedRectPath(t,e,i,r):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)),a&&(r&&t.clip(),t.drawImage.apply(t,n))}_hitFunc(t){var e=this.width(),i=this.height(),r=this.cornerRadius();t.beginPath(),r?g.drawRoundedRectPath(t,e,i,r):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}getWidth(){var t,e;return null!==(t=this.attrs.width)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.width}getHeight(){var t,e;return null!==(t=this.attrs.height)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.height}static fromURL(t,e,i=null){var r=g.createImageElement();r.onload=function(){var t=new he({image:r});e(t)},r.onerror=i,r.crossOrigin="Anonymous",r.src=t}}he.prototype.className="Image",r(he),w.addGetterSetter(he,"cornerRadius",0,v(4)),w.addGetterSetter(he,"image"),w.addComponentsGetterSetter(he,"crop",["x","y","width","height"]),w.addGetterSetter(he,"cropX",0,p()),w.addGetterSetter(he,"cropY",0,p()),w.addGetterSetter(he,"cropWidth",0,p()),w.addGetterSetter(he,"cropHeight",0,p());var le=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],de="up",ce="right",ge="down",ue="left",fe=le.length;class pe extends Xt{constructor(t){super(t),this.on("add.konva",(function(t){this._addListeners(t.child),this._sync()}))}getText(){return this.find("Text")[0]}getTag(){return this.find("Tag")[0]}_addListeners(t){var e,i=this,r=function(){i._sync()};for(e=0;e{e=Math.min(e,t.x),i=Math.max(i,t.x),r=Math.min(r,t.y),a=Math.max(a,t.y)})),{x:e,y:r,width:i-e,height:a-r}}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}_e.prototype.className="RegularPolygon",_e.prototype._centroid=!0,_e.prototype._attrsAffectingSize=["radius"],r(_e),w.addGetterSetter(_e,"radius",0,p()),w.addGetterSetter(_e,"sides",0,p());var ye=2*Math.PI;class xe extends Bt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.innerRadius(),0,ye,!1),t.moveTo(this.outerRadius(),0),t.arc(0,0,this.outerRadius(),ye,0,!0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}xe.prototype.className="Ring",xe.prototype._centroid=!0,xe.prototype._attrsAffectingSize=["innerRadius","outerRadius"],r(xe),w.addGetterSetter(xe,"innerRadius",0,p()),w.addGetterSetter(xe,"outerRadius",0,p());class be extends Bt{constructor(t){super(t),this._updated=!0,this.anim=new Ut((()=>{var t=this._updated;return this._updated=!1,t})),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(t){var e=this.animation(),i=this.frameIndex(),r=4*i,a=this.animations()[e],n=this.frameOffsets(),s=a[r+0],o=a[r+1],h=a[r+2],l=a[r+3],d=this.image();if((this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,h,l),t.closePath(),t.fillStrokeShape(this)),d)if(n){var c=n[e],g=2*i;t.drawImage(d,s,o,h,l,c[g+0],c[g+1],h,l)}else t.drawImage(d,s,o,h,l,0,0,h,l)}_hitFunc(t){var e=this.animation(),i=this.frameIndex(),r=4*i,a=this.animations()[e],n=this.frameOffsets(),s=a[r+2],o=a[r+3];if(t.beginPath(),n){var h=n[e],l=2*i;t.rect(h[l+0],h[l+1],s,o)}else t.rect(0,0,s,o);t.closePath(),t.fillShape(this)}_useBufferCanvas(){return super._useBufferCanvas(!0)}_setInterval(){var t=this;this.interval=setInterval((function(){t._updateIndex()}),1e3/this.frameRate())}start(){if(!this.isRunning()){var t=this.getLayer();this.anim.setLayers(t),this._setInterval(),this.anim.start()}}stop(){this.anim.stop(),clearInterval(this.interval)}isRunning(){return this.anim.isRunning()}_updateIndex(){var t=this.frameIndex(),e=this.animation();t1&&(v+=s)}}}_hitFunc(t){var e=this.getWidth(),i=this.getHeight();t.beginPath(),t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}setText(t){var e=g._isString(t)?t:null==t?"":t+"";return this._setAttr("text",e),this}getWidth(){return this.attrs.width===Pe||void 0===this.attrs.width?this.getTextWidth()+2*this.padding():this.attrs.width}getHeight(){return this.attrs.height===Pe||void 0===this.attrs.height?this.fontSize()*this.textArr.length*this.lineHeight()+2*this.padding():this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return g.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}measureSize(t){var e,i=Oe(),r=this.fontSize();return i.save(),i.font=this._getContextFont(),e=i.measureText(t),i.restore(),{width:e.width,height:r}}_getContextFont(){return this.fontStyle()+Re+this.fontVariant()+Re+(this.fontSize()+"px ")+this.fontFamily().split(",").map((t=>{const e=(t=t.trim()).indexOf(" ")>=0,i=t.indexOf('"')>=0||t.indexOf("'")>=0;return e&&!i&&(t=`"${t}"`),t})).join(", ")}_addTextLine(t){this.align()===ke&&(t=t.trim());var e=this._getTextWidth(t);return this.textArr.push({text:t,width:e,lastInParagraph:!1})}_getTextWidth(t){var e=this.letterSpacing(),i=t.length;return Oe().measureText(t).width+(i?e*(i-1):0)}_setTextData(){var t=this.text().split("\n"),e=+this.fontSize(),i=0,r=this.lineHeight()*e,a=this.attrs.width,n=this.attrs.height,s=a!==Pe&&void 0!==a,o=n!==Pe&&void 0!==n,h=this.padding(),l=a-2*h,d=n-2*h,c=0,g=this.wrap(),u="char"!==g&&g!==Ee,f=this.ellipsis();this.textArr=[],Oe().font=this._getContextFont();for(var p=f?this._getTextWidth("…"):0,v=0,m=t.length;vl)for(;_.length>0;){for(var x=0,b=_.length,S="",w=0;x>>1,P=_.slice(0,C+1),k=this._getTextWidth(P)+p;k<=l?(x=C+1,S=P,w=k):b=C}if(!S)break;if(u){var T,A=_[S.length];(T=(A===Re||"-"===A)&&w<=l?S.length:Math.max(S.lastIndexOf(Re),S.lastIndexOf("-"))+1)>0&&(x=T,S=S.slice(0,x),w=this._getTextWidth(S))}if(S=S.trimRight(),this._addTextLine(S),i=Math.max(i,w),c+=r,this._shouldHandleEllipsis(c)){this._tryToAddEllipsisToLastLine();break}if((_=(_=_.slice(x)).trimLeft()).length>0&&(y=this._getTextWidth(_))<=l){this._addTextLine(_),c+=r,i=Math.max(i,y);break}}else this._addTextLine(_),c+=r,i=Math.max(i,y),this._shouldHandleEllipsis(c)&&vd)break}this.textHeight=e,this.textWidth=i}_shouldHandleEllipsis(t){var e=+this.fontSize(),i=this.lineHeight()*e,r=this.attrs.height,a=r!==Pe&&void 0!==r,n=r-2*this.padding();return!(this.wrap()!==Ee)||a&&t+i>n}_tryToAddEllipsisToLastLine(){var t=this.attrs.width,e=t!==Pe&&void 0!==t,i=t-2*this.padding(),r=this.ellipsis(),a=this.textArr[this.textArr.length-1];if(a&&r){if(e)this._getTextWidth(a.text+"…")=1){var i=e[0].p0;t.moveTo(i.x,i.y)}for(var r=0;r0&&(s+=t.dataArray[o].pathLength);var h=0;"center"===r&&(h=Math.max(0,s/2-n/2)),"right"===r&&(h=Math.max(0,s-n));for(var l,d,c,g=we(this.text()),u=this.text().split(" ").length-1,f=-1,p=0,v=function(){p=0;for(var e=t.dataArray,i=f+1;i0)return f=i,e[i];"M"===e[i].command&&(l={x:e[i].points[0],y:e[i].points[1]})}return{}},m=function(e){var a=t._getTextSize(e).width+i;" "===e&&"justify"===r&&(a+=(s-n)/u);var o=0,h=0;for(d=void 0;Math.abs(a-o)/a>.01&&h<20;){h++;for(var g=o;void 0===c;)(c=v())&&g+c.pathLengtha?d=ae.getPointOnLine(a,l.x,l.y,c.points[0],c.points[1],l.x,l.y):c=void 0;break;case"A":var m=c.points[4],_=c.points[5],y=c.points[4]+_;0===p?p=m+1e-8:a>o?p+=Math.PI/180*_/Math.abs(_):p-=Math.PI/360*_/Math.abs(_),(_<0&&p=0&&p>y)&&(p=y,f=!0),d=ae.getPointOnEllipticalArc(c.points[0],c.points[1],c.points[2],c.points[3],p,c.points[6]);break;case"C":0===p?p=a>c.pathLength?1e-8:a/c.pathLength:a>o?p+=(a-o)/c.pathLength/2:p=Math.max(p-(o-a)/c.pathLength/2,0),p>1&&(p=1,f=!0),d=ae.getPointOnCubicBezier(p,c.start.x,c.start.y,c.points[0],c.points[1],c.points[2],c.points[3],c.points[4],c.points[5]);break;case"Q":0===p?p=a/c.pathLength:a>o?p+=(a-o)/c.pathLength:p-=(o-a)/c.pathLength,p>1&&(p=1,f=!0),d=ae.getPointOnQuadraticBezier(p,c.start.x,c.start.y,c.points[0],c.points[1],c.points[2],c.points[3])}void 0!==d&&(o=ae.getLineLength(l.x,l.y,d.x,d.y)),f&&(f=!1,c=void 0)}},_=h/(t._getTextSize("C").width+i)-1,y=0;y<_&&(m("C"),void 0!==l&&void 0!==d);y++)l=d;for(var x=0;xt+`.${He}`)).join(" "),Ye="nodesRect",Xe=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange"],je={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135};const Ue="ontouchstart"in i._global;var qe=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"];function Ve(t,e,i){const r=i.x+(t.x-i.x)*Math.cos(e)-(t.y-i.y)*Math.sin(e),a=i.y+(t.x-i.x)*Math.sin(e)+(t.y-i.y)*Math.cos(e);return Object.assign(Object.assign({},t),{rotation:t.rotation+e,x:r,y:a})}function Ke(t,e){const i=function(t){return{x:t.x+t.width/2*Math.cos(t.rotation)+t.height/2*Math.sin(-t.rotation),y:t.y+t.height/2*Math.cos(t.rotation)+t.width/2*Math.sin(t.rotation)}}(t);return Ve(t,e,i)}class Qe extends Xt{constructor(t){super(t),this._transforming=!1,this._createElements(),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this.update=this.update.bind(this),this.on(We,this.update),this.getNode()&&this.update()}attachTo(t){return this.setNode(t),this}setNode(t){return g.warn("tr.setNode(shape), tr.node(shape) and tr.attachTo(shape) methods are deprecated. Please use tr.nodes(nodesArray) instead."),this.setNodes([t])}getNode(){return this._nodes&&this._nodes[0]}_getEventNamespace(){return He+this._id}setNodes(t=[]){this._nodes&&this._nodes.length&&this.detach();const e=t.filter((t=>!t.isAncestorOf(this)||(g.error("Konva.Transformer cannot be an a child of the node you are trying to attach"),!1)));return this._nodes=t=e,1===t.length&&this.useSingleNodeRotation()?this.rotation(t[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach((t=>{const e=()=>{1===this.nodes().length&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),this._transforming||this.isDragging()||this.update()},i=t._attrsAffectingSize.map((t=>t+"Change."+this._getEventNamespace())).join(" ");t.on(i,e),t.on(Xe.map((t=>t+`.${this._getEventNamespace()}`)).join(" "),e),t.on(`absoluteTransformChange.${this._getEventNamespace()}`,e),this._proxyDrag(t)})),this._resetTransformCache(),!!this.findOne(".top-left")&&this.update(),this}_proxyDrag(t){let e;t.on(`dragstart.${this._getEventNamespace()}`,(i=>{e=t.getAbsolutePosition(),this.isDragging()||t===this.findOne(".back")||this.startDrag(i,!1)})),t.on(`dragmove.${this._getEventNamespace()}`,(i=>{if(!e)return;const r=t.getAbsolutePosition(),a=r.x-e.x,n=r.y-e.y;this.nodes().forEach((e=>{if(e===t)return;if(e.isDragging())return;const r=e.getAbsolutePosition();e.setAbsolutePosition({x:r.x+a,y:r.y+n}),e.startDrag(i)})),e=null}))}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){this._nodes&&this._nodes.forEach((t=>{t.off("."+this._getEventNamespace())})),this._nodes=[],this._resetTransformCache()}_resetTransformCache(){this._clearCache(Ye),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(Ye,this.__getNodeRect)}__getNodeShape(t,e=this.rotation(),r){var a=t.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),n=t.getAbsoluteScale(r),s=t.getAbsolutePosition(r),o=a.x*n.x-t.offsetX()*n.x,h=a.y*n.y-t.offsetY()*n.y;const l=(i.getAngle(t.getAbsoluteRotation())+2*Math.PI)%(2*Math.PI);return Ve({x:s.x+o*Math.cos(l)+h*Math.sin(-l),y:s.y+h*Math.cos(l)+o*Math.sin(l),width:a.width*n.x,height:a.height*n.y,rotation:l},-i.getAngle(e),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};const t=[];this.nodes().map((e=>{const i=e.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()});var r=[{x:i.x,y:i.y},{x:i.x+i.width,y:i.y},{x:i.x+i.width,y:i.y+i.height},{x:i.x,y:i.y+i.height}],a=e.getAbsoluteTransform();r.forEach((function(e){var i=a.point(e);t.push(i)}))}));const e=new a;var r,n,s,o;e.rotate(-i.getAngle(this.rotation())),t.forEach((function(t){var i=e.point(t);void 0===r&&(r=s=i.x,n=o=i.y),r=Math.min(r,i.x),n=Math.min(n,i.y),s=Math.max(s,i.x),o=Math.max(o,i.y)})),e.invert();const h=e.point({x:r,y:n});return{x:h.x,y:h.y,width:s-r,height:o-n,rotation:i.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(),qe.forEach(function(t){this._createAnchor(t)}.bind(this)),this._createAnchor("rotater")}_createAnchor(t){var e=new me({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:t+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:Ue?10:"auto"}),r=this;e.on("mousedown touchstart",(function(t){r._handleMouseDown(t)})),e.on("dragstart",(t=>{e.stopDrag(),t.cancelBubble=!0})),e.on("dragend",(t=>{t.cancelBubble=!0})),e.on("mouseenter",(()=>{var r=i.getAngle(this.rotation()),a=function(t,e){if("rotater"===t)return"crosshair";e+=g.degToRad(je[t]||0);var i=(g.radToDeg(e)%360+360)%360;return g._inRange(i,337.5,360)||g._inRange(i,0,22.5)?"ns-resize":g._inRange(i,22.5,67.5)?"nesw-resize":g._inRange(i,67.5,112.5)?"ew-resize":g._inRange(i,112.5,157.5)?"nwse-resize":g._inRange(i,157.5,202.5)?"ns-resize":g._inRange(i,202.5,247.5)?"nesw-resize":g._inRange(i,247.5,292.5)?"ew-resize":g._inRange(i,292.5,337.5)?"nwse-resize":(g.error("Transformer has unknown angle for cursor detection: "+i),"pointer")}(t,r);e.getStage().content&&(e.getStage().content.style.cursor=a),this._cursorChange=!0})),e.on("mouseout",(()=>{e.getStage().content&&(e.getStage().content.style.cursor=""),this._cursorChange=!1})),this.add(e)}_createBack(){var t=new Bt({name:"back",width:0,height:0,draggable:!0,sceneFunc(t){var e=this.getParent(),i=e.padding();t.beginPath(),t.rect(-i,-i,this.width()+2*i,this.height()+2*i),t.moveTo(this.width()/2,-i),e.rotateEnabled()&&t.lineTo(this.width()/2,-e.rotateAnchorOffset()*g._sign(this.height())-i),t.fillStrokeShape(this)},hitFunc:(t,e)=>{if(this.shouldOverdrawWholeArea()){var i=this.padding();t.beginPath(),t.rect(-i,-i,e.width()+2*i,e.height()+2*i),t.fillStrokeShape(e)}}});this.add(t),this._proxyDrag(t),t.on("dragstart",(t=>{t.cancelBubble=!0})),t.on("dragmove",(t=>{t.cancelBubble=!0})),t.on("dragend",(t=>{t.cancelBubble=!0})),this.on("dragmove",(t=>{this.update()}))}_handleMouseDown(t){this._movingAnchorName=t.target.name().split(" ")[0];var e=this._getNodeRect(),i=e.width,r=e.height,a=Math.sqrt(Math.pow(i,2)+Math.pow(r,2));this.sin=Math.abs(r/a),this.cos=Math.abs(i/a),"undefined"!=typeof window&&(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;var n=t.target.getAbsolutePosition(),s=t.target.getStage().getPointerPosition();this._anchorDragOffset={x:s.x-n.x,y:s.y-n.y},this._fire("transformstart",{evt:t.evt,target:this.getNode()}),this._nodes.forEach((e=>{e._fire("transformstart",{evt:t.evt,target:e})}))}_handleMouseMove(t){var e,r,a,n=this.findOne("."+this._movingAnchorName),s=n.getStage();s.setPointersPositions(t);const o=s.getPointerPosition();let h={x:o.x-this._anchorDragOffset.x,y:o.y-this._anchorDragOffset.y};const l=n.getAbsolutePosition();this.anchorDragBoundFunc()&&(h=this.anchorDragBoundFunc()(l,h,t)),n.setAbsolutePosition(h);const d=n.getAbsolutePosition();if(l.x!==d.x||l.y!==d.y)if("rotater"!==this._movingAnchorName){var c=this.keepRatio()||t.shiftKey,g=this.centeredScaling()||t.altKey;if("top-left"===this._movingAnchorName){if(c){var u=g?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-right").x(),y:this.findOne(".bottom-right").y()};a=Math.sqrt(Math.pow(u.x-n.x(),2)+Math.pow(u.y-n.y(),2));var f=this.findOne(".top-left").x()>u.x?-1:1,p=this.findOne(".top-left").y()>u.y?-1:1;e=a*this.cos*f,r=a*this.sin*p,this.findOne(".top-left").x(u.x-e),this.findOne(".top-left").y(u.y-r)}}else if("top-center"===this._movingAnchorName)this.findOne(".top-left").y(n.y());else if("top-right"===this._movingAnchorName){if(c){u=g?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()};a=Math.sqrt(Math.pow(n.x()-u.x,2)+Math.pow(u.y-n.y(),2));f=this.findOne(".top-right").x()u.y?-1:1;e=a*this.cos*f,r=a*this.sin*p,this.findOne(".top-right").x(u.x+e),this.findOne(".top-right").y(u.y-r)}var v=n.position();this.findOne(".top-left").y(v.y),this.findOne(".bottom-right").x(v.x)}else if("middle-left"===this._movingAnchorName)this.findOne(".top-left").x(n.x());else if("middle-right"===this._movingAnchorName)this.findOne(".bottom-right").x(n.x());else if("bottom-left"===this._movingAnchorName){if(c){u=g?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()};a=Math.sqrt(Math.pow(u.x-n.x(),2)+Math.pow(n.y()-u.y,2));f=u.x{e._fire("transformend",{evt:t,target:e})})),this._movingAnchorName=null}}_fitNodesInto(t,e){var r=this._getNodeRect();if(g._inRange(t.width,2*-this.padding()-1,1))return void this.update();if(g._inRange(t.height,2*-this.padding()-1,1))return void this.update();const n=this.flipEnabled();var s=new a;if(s.rotate(i.getAngle(this.rotation())),this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("left")>=0){const e=s.point({x:2*-this.padding(),y:0});if(t.x+=e.x,t.y+=e.y,t.width+=2*this.padding(),this._movingAnchorName=this._movingAnchorName.replace("left","right"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,!n)return void this.update()}else if(this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("right")>=0){const e=s.point({x:2*this.padding(),y:0});if(this._movingAnchorName=this._movingAnchorName.replace("right","left"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.width+=2*this.padding(),!n)return void this.update()}if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("top")>=0){const e=s.point({x:0,y:2*-this.padding()});if(t.x+=e.x,t.y+=e.y,this._movingAnchorName=this._movingAnchorName.replace("top","bottom"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding(),!n)return void this.update()}else if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("bottom")>=0){const e=s.point({x:0,y:2*this.padding()});if(this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding(),!n)return void this.update()}if(this.boundBoxFunc()){const e=this.boundBoxFunc()(r,t);e?t=e:g.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const o=1e7,h=new a;h.translate(r.x,r.y),h.rotate(r.rotation),h.scale(r.width/o,r.height/o);const l=new a;l.translate(t.x,t.y),l.rotate(t.rotation),l.scale(t.width/o,t.height/o);const d=l.multiply(h.invert());this._nodes.forEach((t=>{var i;const r=t.getParent().getAbsoluteTransform(),n=t.getTransform().copy();n.translate(t.offsetX(),t.offsetY());const s=new a;s.multiply(r.copy().invert()).multiply(d).multiply(r).multiply(n);const o=s.decompose();t.setAttrs(o),this._fire("transform",{evt:e,target:t}),t._fire("transform",{evt:e,target:t}),null===(i=t.getLayer())||void 0===i||i.batchDraw()})),this.rotation(g._getRotation(t.rotation)),this._resetTransformCache(),this.update(),this.getLayer().batchDraw()}forceUpdate(){this._resetTransformCache(),this.update()}_batchChangeChild(t,e){this.findOne(t).setAttrs(e)}update(){var t,e=this._getNodeRect();this.rotation(g._getRotation(e.rotation));var i=e.width,r=e.height,a=this.enabledAnchors(),n=this.resizeEnabled(),s=this.padding(),o=this.anchorSize();this.find("._anchor").forEach((t=>{t.setAttrs({width:o,height:o,offsetX:o/2,offsetY:o/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})})),this._batchChangeChild(".top-left",{x:0,y:0,offsetX:o/2+s,offsetY:o/2+s,visible:n&&a.indexOf("top-left")>=0}),this._batchChangeChild(".top-center",{x:i/2,y:0,offsetY:o/2+s,visible:n&&a.indexOf("top-center")>=0}),this._batchChangeChild(".top-right",{x:i,y:0,offsetX:o/2-s,offsetY:o/2+s,visible:n&&a.indexOf("top-right")>=0}),this._batchChangeChild(".middle-left",{x:0,y:r/2,offsetX:o/2+s,visible:n&&a.indexOf("middle-left")>=0}),this._batchChangeChild(".middle-right",{x:i,y:r/2,offsetX:o/2-s,visible:n&&a.indexOf("middle-right")>=0}),this._batchChangeChild(".bottom-left",{x:0,y:r,offsetX:o/2+s,offsetY:o/2-s,visible:n&&a.indexOf("bottom-left")>=0}),this._batchChangeChild(".bottom-center",{x:i/2,y:r,offsetY:o/2-s,visible:n&&a.indexOf("bottom-center")>=0}),this._batchChangeChild(".bottom-right",{x:i,y:r,offsetX:o/2-s,offsetY:o/2-s,visible:n&&a.indexOf("bottom-right")>=0}),this._batchChangeChild(".rotater",{x:i/2,y:-this.rotateAnchorOffset()*g._sign(r)-s,visible:this.rotateEnabled()}),this._batchChangeChild(".back",{width:i,height:r,visible:this.borderEnabled(),stroke:this.borderStroke(),strokeWidth:this.borderStrokeWidth(),dash:this.borderDash(),x:0,y:0}),null===(t=this.getLayer())||void 0===t||t.batchDraw()}isTransforming(){return this._transforming}stopTransform(){if(this._transforming){this._removeEvents();var t=this.findOne("."+this._movingAnchorName);t&&t.stopDrag()}}destroy(){return this.getStage()&&this._cursorChange&&this.getStage().content&&(this.getStage().content.style.cursor=""),Xt.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}toObject(){return V.prototype.toObject.call(this)}clone(t){return V.prototype.clone.call(this,t)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}}Qe.prototype.className="Transformer",r(Qe),w.addGetterSetter(Qe,"enabledAnchors",qe,(function(t){return t instanceof Array||g.warn("enabledAnchors value should be an array"),t instanceof Array&&t.forEach((function(t){-1===qe.indexOf(t)&&g.warn("Unknown anchor name: "+t+". Available names are: "+qe.join(", "))})),t||[]})),w.addGetterSetter(Qe,"flipEnabled",!0,x()),w.addGetterSetter(Qe,"resizeEnabled",!0),w.addGetterSetter(Qe,"anchorSize",10,p()),w.addGetterSetter(Qe,"rotateEnabled",!0),w.addGetterSetter(Qe,"rotationSnaps",[]),w.addGetterSetter(Qe,"rotateAnchorOffset",50,p()),w.addGetterSetter(Qe,"rotationSnapTolerance",5,p()),w.addGetterSetter(Qe,"borderEnabled",!0),w.addGetterSetter(Qe,"anchorStroke","rgb(0, 161, 255)"),w.addGetterSetter(Qe,"anchorStrokeWidth",1,p()),w.addGetterSetter(Qe,"anchorFill","white"),w.addGetterSetter(Qe,"anchorCornerRadius",0,p()),w.addGetterSetter(Qe,"borderStroke","rgb(0, 161, 255)"),w.addGetterSetter(Qe,"borderStrokeWidth",1,p()),w.addGetterSetter(Qe,"borderDash"),w.addGetterSetter(Qe,"keepRatio",!0),w.addGetterSetter(Qe,"centeredScaling",!1),w.addGetterSetter(Qe,"ignoreStroke",!1),w.addGetterSetter(Qe,"padding",0,p()),w.addGetterSetter(Qe,"node"),w.addGetterSetter(Qe,"nodes"),w.addGetterSetter(Qe,"boundBoxFunc"),w.addGetterSetter(Qe,"anchorDragBoundFunc"),w.addGetterSetter(Qe,"shouldOverdrawWholeArea",!1),w.addGetterSetter(Qe,"useSingleNodeRotation",!0),w.backCompat(Qe,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});class Je extends Bt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.radius(),0,i.getAngle(this.angle()),this.clockwise()),t.lineTo(0,0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}function Ze(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}Je.prototype.className="Wedge",Je.prototype._centroid=!0,Je.prototype._attrsAffectingSize=["radius"],r(Je),w.addGetterSetter(Je,"radius",0,p()),w.addGetterSetter(Je,"angle",0,p()),w.addGetterSetter(Je,"clockwise",!1),w.backCompat(Je,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});var $e=[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],ti=[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];w.addGetterSetter(V,"blurRadius",0,p(),w.afterSetFilter);w.addGetterSetter(V,"brightness",0,p(),w.afterSetFilter);w.addGetterSetter(V,"contrast",0,p(),w.afterSetFilter);function ei(t,e,i,r,a){var n=i-e,s=a-r;return 0===n?r+s/2:0===s?r:s*((t-e)/n)+r}w.addGetterSetter(V,"embossStrength",.5,p(),w.afterSetFilter),w.addGetterSetter(V,"embossWhiteLevel",.5,p(),w.afterSetFilter),w.addGetterSetter(V,"embossDirection","top-left",null,w.afterSetFilter),w.addGetterSetter(V,"embossBlend",!1,null,w.afterSetFilter);w.addGetterSetter(V,"enhance",0,p(),w.afterSetFilter);w.addGetterSetter(V,"hue",0,p(),w.afterSetFilter),w.addGetterSetter(V,"saturation",0,p(),w.afterSetFilter),w.addGetterSetter(V,"luminance",0,p(),w.afterSetFilter);w.addGetterSetter(V,"hue",0,p(),w.afterSetFilter),w.addGetterSetter(V,"saturation",0,p(),w.afterSetFilter),w.addGetterSetter(V,"value",0,p(),w.afterSetFilter);function ii(t,e,i){var r=4*(i*t.width+e),a=[];return a.push(t.data[r++],t.data[r++],t.data[r++],t.data[r++]),a}function ri(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2))}w.addGetterSetter(V,"kaleidoscopePower",2,p(),w.afterSetFilter),w.addGetterSetter(V,"kaleidoscopeAngle",0,p(),w.afterSetFilter);w.addGetterSetter(V,"threshold",0,p(),w.afterSetFilter);w.addGetterSetter(V,"noise",.2,p(),w.afterSetFilter);w.addGetterSetter(V,"pixelSize",8,p(),w.afterSetFilter);w.addGetterSetter(V,"levels",.5,p(),w.afterSetFilter);w.addGetterSetter(V,"red",0,(function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)})),w.addGetterSetter(V,"green",0,(function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)})),w.addGetterSetter(V,"blue",0,f,w.afterSetFilter);w.addGetterSetter(V,"red",0,(function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)})),w.addGetterSetter(V,"green",0,(function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)})),w.addGetterSetter(V,"blue",0,f,w.afterSetFilter),w.addGetterSetter(V,"alpha",1,(function(t){return this._filterUpToDate=!1,t>1?1:t<0?0:t}));w.addGetterSetter(V,"threshold",.5,p(),w.afterSetFilter);return $t.Util._assign($t,{Arc:te,Arrow:ne,Circle:se,Ellipse:oe,Image:he,Label:pe,Tag:ve,Line:re,Path:ae,Rect:me,RegularPolygon:_e,Ring:xe,Sprite:be,Star:Se,Text:Ie,TextPath:ze,Transformer:Qe,Wedge:Je,Filters:{Blur:function(t){var e=Math.round(this.blurRadius());e>0&&function(t,e){var i,r,a,n,s,o,h,l,d,c,g,u,f,p,v,m,_,y,x,b,S,w,C,P,k=t.data,T=t.width,A=t.height,M=e+e+1,G=T-1,R=A-1,E=e+1,L=E*(E+1)/2,D=new Ze,O=null,I=D,F=null,N=null,B=$e[e],z=ti[e];for(a=1;a>z,0!==C?(C=255/C,k[o]=(l*B>>z)*C,k[o+1]=(d*B>>z)*C,k[o+2]=(c*B>>z)*C):k[o]=k[o+1]=k[o+2]=0,l-=u,d-=f,c-=p,g-=v,u-=F.r,f-=F.g,p-=F.b,v-=F.a,n=h+((n=i+e+1)>z,C>0?(C=255/C,k[n]=(l*B>>z)*C,k[n+1]=(d*B>>z)*C,k[n+2]=(c*B>>z)*C):k[n]=k[n+1]=k[n+2]=0,l-=u,d-=f,c-=p,g-=v,u-=F.r,f-=F.g,p-=F.b,v-=F.a,n=i+((n=r+E)255?255:n,s=(s*=255)<0?0:s>255?255:s,o=(o*=255)<0?0:o>255?255:o,r[e]=n,r[e+1]=s,r[e+2]=o},Emboss:function(t){var e=10*this.embossStrength(),i=255*this.embossWhiteLevel(),r=this.embossDirection(),a=this.embossBlend(),n=0,s=0,o=t.data,h=t.width,l=t.height,d=4*h,c=l;switch(r){case"top-left":n=-1,s=-1;break;case"top":n=-1,s=0;break;case"top-right":n=-1,s=1;break;case"right":n=0,s=1;break;case"bottom-right":n=1,s=1;break;case"bottom":n=1,s=0;break;case"bottom-left":n=1,s=-1;break;case"left":n=0,s=-1;break;default:g.error("Unknown emboss direction: "+r)}do{var u=(c-1)*d,f=n;c+f<1&&(f=0),c+f>l&&(f=0);var p=(c-1+f)*h*4,v=h;do{var m=u+4*(v-1),_=s;v+_<1&&(_=0),v+_>h&&(_=0);var y=p+4*(v-1+_),x=o[m]-o[y],b=o[m+1]-o[y+1],S=o[m+2]-o[y+2],w=x,C=w>0?w:-w;if((b>0?b:-b)>C&&(w=b),(S>0?S:-S)>C&&(w=S),w*=e,a){var P=o[m]+w,k=o[m+1]+w,T=o[m+2]+w;o[m]=P>255?255:P<0?0:P,o[m+1]=k>255?255:k<0?0:k,o[m+2]=T>255?255:T<0?0:T}else{var A=i-w;A<0?A=0:A>255&&(A=255),o[m]=o[m+1]=o[m+2]=A}}while(--v)}while(--c)},Enhance:function(t){var e,i,r,a,n=t.data,s=n.length,o=n[0],h=o,l=n[1],d=l,c=n[2],g=c,u=this.enhance();if(0!==u){for(a=0;ah&&(h=e),(i=n[a+1])d&&(d=i),(r=n[a+2])g&&(g=r);var f,p,v,m,_,y,x,b,S;for(h===o&&(h=255,o=0),d===l&&(d=255,l=0),g===c&&(g=255,c=0),u>0?(p=h+u*(255-h),v=o-u*(o-0),_=d+u*(255-d),y=l-u*(l-0),b=g+u*(255-g),S=c-u*(c-0)):(p=h+u*(h-(f=.5*(h+o))),v=o+u*(o-f),_=d+u*(d-(m=.5*(d+l))),y=l+u*(l-m),b=g+u*(g-(x=.5*(g+c))),S=c+u*(c-x)),a=0;am?s:m;var _,y,x,b,S=d,w=l,C=360/w*Math.PI/180;for(y=0;yd&&(x=y,b=0,S=-1),i=0;iy?h:y;var x,b,S,w=g,C=c,P=i.polarRotation||0;for(a=0;a=0&&u=0&&f=0&&u=0&&f=1020?255:0}return s}(e=function(t,e,i){for(var r=[1,1,1,1,0,1,1,1,1],a=Math.round(Math.sqrt(r.length)),n=Math.floor(a/2),s=[],o=0;o=0&&u=0&&f=m))for(i=d;i=_||(a+=b[(r=4*(m*i+e))+0],n+=b[r+1],s+=b[r+2],o+=b[r+3],p+=1);for(a/=p,n/=p,s/=p,o/=p,e=h;e=m))for(i=d;i=_||(b[(r=4*(m*i+e))+0]=a,b[r+1]=n,b[r+2]=s,b[r+3]=o)}},Posterize:function(t){var e,i=Math.round(254*this.levels())+1,r=t.data,a=r.length,n=255/i;for(e=0;e127&&(h=255-h),l>127&&(l=255-l),d>127&&(d=255-d),e[o]=h,e[o+1]=l,e[o+2]=d}while(--s)}while(--a)},Threshold:function(t){var e,i=255*this.threshold(),r=t.data,a=r.length;for(e=0;ei.angleDeg?e*t: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,pixelRatio:"undefined"!=typeof window&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging:()=>i.DD.isDragging,isDragReady:()=>!!i.DD.node,releaseCanvasOnDestroy:!0,document:e.document,_injectGlobal(t){e.Konva=t}},r=t=>{i[t.prototype.getClassName()]=t};i._injectGlobal(i);class a{constructor(t=[1,0,0,1,0,0]){this.dirty=!1,this.m=t&&t.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 a(this.m)}copyInto(t){t.m[0]=this.m[0],t.m[1]=this.m[1],t.m[2]=this.m[2],t.m[3]=this.m[3],t.m[4]=this.m[4],t.m[5]=this.m[5]}point(t){var e=this.m;return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}translate(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this}scale(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this}rotate(t){var e=Math.cos(t),i=Math.sin(t),r=this.m[0]*e+this.m[2]*i,a=this.m[1]*e+this.m[3]*i,n=this.m[0]*-i+this.m[2]*e,s=this.m[1]*-i+this.m[3]*e;return this.m[0]=r,this.m[1]=a,this.m[2]=n,this.m[3]=s,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,e){var i=this.m[0]+this.m[2]*e,r=this.m[1]+this.m[3]*e,a=this.m[2]+this.m[0]*t,n=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=r,this.m[2]=a,this.m[3]=n,this}multiply(t){var e=this.m[0]*t.m[0]+this.m[2]*t.m[1],i=this.m[1]*t.m[0]+this.m[3]*t.m[1],r=this.m[0]*t.m[2]+this.m[2]*t.m[3],a=this.m[1]*t.m[2]+this.m[3]*t.m[3],n=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],s=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=e,this.m[1]=i,this.m[2]=r,this.m[3]=a,this.m[4]=n,this.m[5]=s,this}invert(){var t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,i=-this.m[1]*t,r=-this.m[2]*t,a=this.m[0]*t,n=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),s=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=e,this.m[1]=i,this.m[2]=r,this.m[3]=a,this.m[4]=n,this.m[5]=s,this}getMatrix(){return this.m}decompose(){var t=this.m[0],e=this.m[1],i=this.m[2],r=this.m[3],a=t*r-e*i;let n={x:this.m[4],y:this.m[5],rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!=t||0!=e){var s=Math.sqrt(t*t+e*e);n.rotation=e>0?Math.acos(t/s):-Math.acos(t/s),n.scaleX=s,n.scaleY=a/s,n.skewX=(t*i+e*r)/a,n.skewY=0}else if(0!=i||0!=r){var o=Math.sqrt(i*i+r*r);n.rotation=Math.PI/2-(r>0?Math.acos(-i/o):-Math.acos(i/o)),n.scaleX=a/o,n.scaleY=o,n.skewX=0,n.skewY=(t*i+e*r)/a}return n.rotation=g._getRotation(n.rotation),n}}var n=Math.PI/180,s=180/Math.PI,o="Konva error: ",h={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]},l=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,d=[];const c="undefined"!=typeof requestAnimationFrame&&requestAnimationFrame||function(t){setTimeout(t,60)},g={_isElement:t=>!(!t||1!=t.nodeType),_isFunction:t=>!!(t&&t.constructor&&t.call&&t.apply),_isPlainObject:t=>!!t&&t.constructor===Object,_isArray:t=>"[object Array]"===Object.prototype.toString.call(t),_isNumber:t=>"[object Number]"===Object.prototype.toString.call(t)&&!isNaN(t)&&isFinite(t),_isString:t=>"[object String]"===Object.prototype.toString.call(t),_isBoolean:t=>"[object Boolean]"===Object.prototype.toString.call(t),isObject:t=>t instanceof Object,isValidSelector(t){if("string"!=typeof t)return!1;var e=t[0];return"#"===e||"."===e||e===e.toUpperCase()},_sign:t=>0===t||t>0?1:-1,requestAnimFrame(t){d.push(t),1===d.length&&c((function(){const t=d;d=[],t.forEach((function(t){t()}))}))},createCanvasElement(){var t=document.createElement("canvas");try{t.style=t.style||{}}catch(t){}return t},createImageElement:()=>document.createElement("img"),_isInDocument(t){for(;t=t.parentNode;)if(t==document)return!0;return!1},_urlToImage(t,e){var i=g.createImageElement();i.onload=function(){e(i)},i.src=t},_rgbToHex:(t,e,i)=>((1<<24)+(t<<16)+(e<<8)+i).toString(16).slice(1),_hexToRgb(t){t=t.replace("#","");var e=parseInt(t,16);return{r:e>>16&255,g:e>>8&255,b:255&e}},getRandomColor(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},getRGB(t){var e;return t in h?{r:(e=h[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=l.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:t=>(t=t||"black",g._namedColorToRBA(t)||g._hex3ColorToRGBA(t)||g._hex4ColorToRGBA(t)||g._hex6ColorToRGBA(t)||g._hex8ColorToRGBA(t)||g._rgbColorToRGBA(t)||g._rgbaColorToRGBA(t)||g._hslColorToRGBA(t)),_namedColorToRBA(t){var e=h[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map(((t,e)=>"%"===t.slice(-1)?3===e?parseInt(t)/100:parseInt(t)/100*255:Number(t)));return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex8ColorToRGBA(t){if("#"===t[0]&&9===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:parseInt(t.slice(7,9),16)/255}},_hex6ColorToRGBA(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex4ColorToRGBA(t){if("#"===t[0]&&5===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:parseInt(t[4]+t[4],16)/255}},_hex3ColorToRGBA(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_hslColorToRGBA(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){const[e,...i]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),r=Number(i[0])/360,a=Number(i[1])/100,n=Number(i[2])/100;let s,o,h;if(0===a)return h=255*n,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};s=n<.5?n*(1+a):n+a-n*a;const l=2*n-s,d=[0,0,0];for(let t=0;t<3;t++)o=r+1/3*-(t-1),o<0&&o++,o>1&&o--,h=6*o<1?l+6*(s-l)*o:2*o<1?s:3*o<2?l+(s-l)*(2/3-o)*6:l,d[t]=255*h;return{r:Math.round(d[0]),g:Math.round(d[1]),b:Math.round(d[2]),a:1}}},haveIntersection:(t,e)=>!(e.x>t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heightt.slice(0),degToRad:t=>t*n,radToDeg:t=>t*s,_degToRad:t=>(g.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),g.degToRad(t)),_radToDeg:t=>(g.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),g.radToDeg(t)),_getRotation:t=>i.angleDeg?g.radToDeg(t):t,_capitalize:t=>t.charAt(0).toUpperCase()+t.slice(1),throw(t){throw new Error(o+t)},error(t){console.error(o+t)},warn(t){i.showWarnings&&console.warn("Konva warning: "+t)},each(t,e){for(var i in t)e(i,t[i])},_inRange:(t,e,i)=>e<=t&&t1?(s=i,o=r,h=(i-a)*(i-a)+(r-n)*(r-n)):h=((s=t+d*(i-t))-a)*(s-a)+((o=e+d*(r-e))-n)*(o-n)}return[s,o,h]},_getProjectionToLine(t,e,i){var r=g.cloneObject(t),a=Number.MAX_VALUE;return e.forEach((function(n,s){if(i||s!==e.length-1){var o=e[(s+1)%e.length],h=g._getProjectionToSegment(n.x,n.y,o.x,o.y,t.x,t.y),l=h[0],d=h[1],c=h[2];ce.length){var s=e;e=t,t=s}for(r=0;rt.touches?t.changedTouches[0].identifier:t.pointerId||999,releaseCanvas(...t){i.releaseCanvasOnDestroy&&t.forEach((t=>{t.width=0,t.height=0}))},drawRoundedRectPath(t,e,i,r){let a=0,n=0,s=0,o=0;"number"==typeof r?a=n=s=o=Math.min(r,e/2,i/2):(a=Math.min(r[0]||0,e/2,i/2),n=Math.min(r[1]||0,e/2,i/2),o=Math.min(r[2]||0,e/2,i/2),s=Math.min(r[3]||0,e/2,i/2)),t.moveTo(a,0),t.lineTo(e-n,0),t.arc(e-n,n,n,3*Math.PI/2,0,!1),t.lineTo(e,i-o),t.arc(e-o,i-o,o,0,Math.PI/2,!1),t.lineTo(s,i),t.arc(s,i-s,s,Math.PI/2,Math.PI,!1),t.lineTo(0,a),t.arc(a,a,a,Math.PI,3*Math.PI/2,!1)}};function u(t){return g._isString(t)?'"'+t+'"':"[object Number]"===Object.prototype.toString.call(t)||g._isBoolean(t)?t:Object.prototype.toString.call(t)}function f(t){return t>255?255:t<0?0:Math.round(t)}function p(){if(i.isUnminified)return function(t,e){return g._isNumber(t)||g.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),t}}function v(t){if(i.isUnminified)return function(e,i){let r=g._isNumber(e),a=g._isArray(e)&&e.length==t;return r||a||g.warn(u(e)+' is a not valid value for "'+i+'" attribute. The value should be a number or Array('+t+")"),e}}function m(){if(i.isUnminified)return function(t,e){return g._isNumber(t)||"auto"===t||g.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),t}}function _(){if(i.isUnminified)return function(t,e){return g._isString(t)||g.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a string.'),t}}function y(){if(i.isUnminified)return function(t,e){const i=g._isString(t),r="[object CanvasGradient]"===Object.prototype.toString.call(t)||t&&t.addColorStop;return i||r||g.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a string or a native gradient.'),t}}function x(){if(i.isUnminified)return function(t,e){return!0===t||!1===t||g.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),t}}var b="get",S="set";const w={addGetterSetter(t,e,i,r,a){w.addGetter(t,e,i),w.addSetter(t,e,r,a),w.addOverloadedGetterSetter(t,e)},addGetter(t,e,i){var r=b+g._capitalize(e);t.prototype[r]=t.prototype[r]||function(){var t=this.attrs[e];return void 0===t?i:t}},addSetter(t,e,i,r){var a=S+g._capitalize(e);t.prototype[a]||w.overWriteSetter(t,e,i,r)},overWriteSetter(t,e,i,r){var a=S+g._capitalize(e);t.prototype[a]=function(t){return i&&null!=t&&(t=i.call(this,t,e)),this._setAttr(e,t),r&&r.call(this),this}},addComponentsGetterSetter(t,e,r,a,n){var s,o,h=r.length,l=g._capitalize,d=b+l(e),c=S+l(e);t.prototype[d]=function(){var t={};for(s=0;s{this._setAttr(e+l(t),void 0)})),this._fireChangeEvent(e,s,t),n&&n.call(this),this},w.addOverloadedGetterSetter(t,e)},addOverloadedGetterSetter(t,e){var i=g._capitalize(e),r=S+i,a=b+i;t.prototype[e]=function(){return arguments.length?(this[r](arguments[0]),this):this[a]()}},addDeprecatedGetterSetter(t,e,i,r){g.error("Adding deprecated "+e);var a=b+g._capitalize(e),n=e+" property is deprecated and will be removed soon. Look at Konva change log for more information.";t.prototype[a]=function(){g.error(n);var t=this.attrs[e];return void 0===t?i:t},w.addSetter(t,e,r,(function(){g.error(n)})),w.addOverloadedGetterSetter(t,e)},backCompat(t,e){g.each(e,(function(e,i){var r=t.prototype[i],a=b+g._capitalize(e),n=S+g._capitalize(e);function s(){r.apply(this,arguments),g.error('"'+e+'" method is deprecated and will be removed soon. Use ""'+i+'" instead.')}t.prototype[e]=s,t.prototype[a]=s,t.prototype[n]=s}))},afterSetFilter(){this._filterUpToDate=!1}};var C=["arc","arcTo","beginPath","bezierCurveTo","clearRect","clip","closePath","createLinearGradient","createPattern","createRadialGradient","drawImage","ellipse","fill","fillText","getImageData","createImageData","lineTo","moveTo","putImageData","quadraticCurveTo","rect","restore","rotate","save","scale","setLineDash","setTransform","stroke","strokeText","transform","translate"];class P{constructor(t){this.canvas=t,i.enableTrace&&(this.traceArr=[],this._enableTrace())}fillShape(t){t.fillEnabled()&&this._fill(t)}_fill(t){}strokeShape(t){t.hasStroke()&&this._stroke(t)}_stroke(t){}fillStrokeShape(t){t.attrs.fillAfterStrokeEnabled?(this.strokeShape(t),this.fillShape(t)):(this.fillShape(t),this.strokeShape(t))}getTrace(t,e){var i,r,a,n,s=this.traceArr,o=s.length,h="";for(i=0;i"number"==typeof t?Math.floor(t):t))),h+="("+n.join(",")+")")):(h+=r.property,t||(h+="="+r.val)),h+=";";return h}clearTrace(){this.traceArr=[]}_trace(t){var e=this.traceArr;e.push(t),e.length>=100&&e.shift()}reset(){var t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)}getCanvas(){return this.canvas}clear(t){var e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)}_applyLineCap(t){const e=t.attrs.lineCap;e&&this.setAttr("lineCap",e)}_applyOpacity(t){var e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)}_applyLineJoin(t){const e=t.attrs.lineJoin;e&&this.setAttr("lineJoin",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,r,a,n){this._context.arc(t,e,i,r,a,n)}arcTo(t,e,i,r,a){this._context.arcTo(t,e,i,r,a)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,r,a,n){this._context.bezierCurveTo(t,e,i,r,a,n)}clearRect(t,e,i,r){this._context.clearRect(t,e,i,r)}clip(){this._context.clip()}closePath(){this._context.closePath()}createImageData(t,e){var i=arguments;return 2===i.length?this._context.createImageData(t,e):1===i.length?this._context.createImageData(t):void 0}createLinearGradient(t,e,i,r){return this._context.createLinearGradient(t,e,i,r)}createPattern(t,e){return this._context.createPattern(t,e)}createRadialGradient(t,e,i,r,a,n){return this._context.createRadialGradient(t,e,i,r,a,n)}drawImage(t,e,i,r,a,n,s,o,h){var l=arguments,d=this._context;3===l.length?d.drawImage(t,e,i):5===l.length?d.drawImage(t,e,i,r,a):9===l.length&&d.drawImage(t,e,i,r,a,n,s,o,h)}ellipse(t,e,i,r,a,n,s,o){this._context.ellipse(t,e,i,r,a,n,s,o)}isPointInPath(t,e,i,r){return i?this._context.isPointInPath(i,t,e,r):this._context.isPointInPath(t,e,r)}fill(t){t?this._context.fill(t):this._context.fill()}fillRect(t,e,i,r){this._context.fillRect(t,e,i,r)}strokeRect(t,e,i,r){this._context.strokeRect(t,e,i,r)}fillText(t,e,i,r){r?this._context.fillText(t,e,i,r):this._context.fillText(t,e,i)}measureText(t){return this._context.measureText(t)}getImageData(t,e,i,r){return this._context.getImageData(t,e,i,r)}lineTo(t,e){this._context.lineTo(t,e)}moveTo(t,e){this._context.moveTo(t,e)}rect(t,e,i,r){this._context.rect(t,e,i,r)}putImageData(t,e,i){this._context.putImageData(t,e,i)}quadraticCurveTo(t,e,i,r){this._context.quadraticCurveTo(t,e,i,r)}restore(){this._context.restore()}rotate(t){this._context.rotate(t)}save(){this._context.save()}scale(t,e){this._context.scale(t,e)}setLineDash(t){this._context.setLineDash?this._context.setLineDash(t):"mozDash"in this._context?this._context.mozDash=t:"webkitLineDash"in this._context&&(this._context.webkitLineDash=t)}getLineDash(){return this._context.getLineDash()}setTransform(t,e,i,r,a,n){this._context.setTransform(t,e,i,r,a,n)}stroke(t){t?this._context.stroke(t):this._context.stroke()}strokeText(t,e,i,r){this._context.strokeText(t,e,i,r)}transform(t,e,i,r,a,n){this._context.transform(t,e,i,r,a,n)}translate(t,e){this._context.translate(t,e)}_enableTrace(){var t,e,i=this,r=C.length,a=this.setAttr,n=function(t){var r,a=i[t];i[t]=function(){return e=function(t){var e,i,r=[],a=t.length,n=g;for(e=0;e{"dragging"===e.dragStatus&&(t=!0)})),t},justDragged:!1,get node(){var t;return E._dragElements.forEach((e=>{t=e.node})),t},_dragElements:new Map,_drag(t){const e=[];E._dragElements.forEach(((i,r)=>{const{node:a}=i,n=a.getStage();n.setPointersPositions(t),void 0===i.pointerId&&(i.pointerId=g._getFirstPointerId(t));const s=n._changedPointerPositions.find((t=>t.id===i.pointerId));if(s){if("dragging"!==i.dragStatus){var o=a.dragDistance();if(Math.max(Math.abs(s.x-i.startPointerPos.x),Math.abs(s.y-i.startPointerPos.y)){e.fire("dragmove",{type:"dragmove",target:e,evt:t},!0)}))},_endDragBefore(t){const e=[];E._dragElements.forEach((r=>{const{node:a}=r,n=a.getStage();t&&n.setPointersPositions(t);if(!n._changedPointerPositions.find((t=>t.id===r.pointerId)))return;"dragging"!==r.dragStatus&&"stopped"!==r.dragStatus||(E.justDragged=!0,i._mouseListenClick=!1,i._touchListenClick=!1,i._pointerListenClick=!1,r.dragStatus="stopped");const s=r.node.getLayer()||r.node instanceof i.Stage&&r.node;s&&-1===e.indexOf(s)&&e.push(s)})),e.forEach((t=>{t.draw()}))},_endDragAfter(t){E._dragElements.forEach(((e,i)=>{"stopped"===e.dragStatus&&e.node.fire("dragend",{type:"dragend",target:e.node,evt:t},!0),"dragging"!==e.dragStatus&&E._dragElements.delete(i)}))}};i.isBrowser&&(window.addEventListener("mouseup",E._endDragBefore,!0),window.addEventListener("touchend",E._endDragBefore,!0),window.addEventListener("mousemove",E._drag),window.addEventListener("touchmove",E._drag),window.addEventListener("mouseup",E._endDragAfter,!1),window.addEventListener("touchend",E._endDragAfter,!1));var D="absoluteOpacity",L="allEventListeners",O="absoluteTransform",I="absoluteScale",F="canvas",N="listening",B="mouseenter",H="mouseleave",W="Shape",z=" ",Y="stage",X="transform",j="visible",U=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(z);let q=1;class V{constructor(t){this._id=q++,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(t),this._shouldFireChangeEvents=!0}hasChildren(){return!1}_clearCache(t){t!==X&&t!==O||!this._cache.get(t)?t?this._cache.delete(t):this._cache.clear():this._cache.get(t).dirty=!0}_getCache(t,e){var i=this._cache.get(t);return(void 0===i||(t===X||t===O)&&!0===i.dirty)&&(i=e.call(this),this._cache.set(t,i)),i}_calculate(t,e,i){if(!this._attachedDepsListeners.get(t)){const i=e.map((t=>t+"Change.konva")).join(z);this.on(i,(()=>{this._clearCache(t)})),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(F)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===O&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(F)){const{scene:t,filter:e,hit:i}=this._cache.get(F);g.releaseCanvas(t,e,i),this._cache.delete(F)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){var e=t||{},i={};void 0!==e.x&&void 0!==e.y&&void 0!==e.width&&void 0!==e.height||(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()}));var r=Math.ceil(e.width||i.width),a=Math.ceil(e.height||i.height),n=e.pixelRatio,s=void 0===e.x?Math.floor(i.x):e.x,o=void 0===e.y?Math.floor(i.y):e.y,h=e.offset||0,l=e.drawBorder||!1,d=e.hitCanvasPixelRatio||1;if(r&&a){s-=h,o-=h;var c=new G({pixelRatio:n,width:r+=2*h+1,height:a+=2*h+1}),u=new G({pixelRatio:n,width:0,height:0}),f=new R({pixelRatio:d,width:r,height:a}),p=c.getContext(),v=f.getContext();return f.isCache=!0,c.isCache=!0,this._cache.delete(F),this._filterUpToDate=!1,!1===e.imageSmoothingEnabled&&(c.getContext()._context.imageSmoothingEnabled=!1,u.getContext()._context.imageSmoothingEnabled=!1),p.save(),v.save(),p.translate(-s,-o),v.translate(-s,-o),this._isUnderCache=!0,this._clearSelfAndDescendantCache(D),this._clearSelfAndDescendantCache(I),this.drawScene(c,this),this.drawHit(f,this),this._isUnderCache=!1,p.restore(),v.restore(),l&&(p.save(),p.beginPath(),p.rect(0,0,r,a),p.closePath(),p.setAttr("strokeStyle","red"),p.setAttr("lineWidth",5),p.stroke(),p.restore()),this._cache.set(F,{scene:c,filter:u,hit:f,x:s,y:o}),this._requestDraw(),this}g.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.")}isCached(){return this._cache.has(F)}getClientRect(t){throw new Error('abstract "getClientRect" method call')}_transformedRect(t,e){var i,r,a,n,s=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],o=this.getAbsoluteTransform(e);return s.forEach((function(t){var e=o.point(t);void 0===i&&(i=a=e.x,r=n=e.y),i=Math.min(i,e.x),r=Math.min(r,e.y),a=Math.max(a,e.x),n=Math.max(n,e.y)})),{x:i,y:r,width:a-i,height:n-r}}_drawCachedSceneCanvas(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);const e=this._getCanvasCache();t.translate(e.x,e.y);var i=this._getCachedSceneCanvas(),r=i.pixelRatio;t.drawImage(i._canvas,0,0,i.width/r,i.height/r),t.restore()}_drawCachedHitCanvas(t){var e=this._getCanvasCache(),i=e.hit;t.save(),t.translate(e.x,e.y),t.drawImage(i._canvas,0,0,i.width/i.pixelRatio,i.height/i.pixelRatio),t.restore()}_getCachedSceneCanvas(){var t,e,i,r,a=this.filters(),n=this._getCanvasCache(),s=n.scene,o=n.filter,h=o.getContext();if(a){if(!this._filterUpToDate){var l=s.pixelRatio;o.setSize(s.width/s.pixelRatio,s.height/s.pixelRatio);try{for(t=a.length,h.clear(),h.drawImage(s._canvas,0,0,s.getWidth()/l,s.getHeight()/l),e=h.getImageData(0,0,o.getWidth(),o.getHeight()),i=0;i{var e,i;if(!t)return this;for(e in t)"children"!==e&&(i="set"+g._capitalize(e),g._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))})),this}isListening(){return this._getCache(N,this._isListening)}_isListening(t){if(!this.listening())return!1;const e=this.getParent();return!e||e===t||this===t||e._isListening(t)}isVisible(){return this._getCache(j,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const e=this.getParent();return!e||e===t||this===t||e._isVisible(t)}shouldDrawHit(t,e=!1){if(t)return this._isVisible(t)&&this._isListening(t);var r=this.getLayer(),a=!1;E._dragElements.forEach((t=>{"dragging"===t.dragStatus&&("Stage"===t.node.nodeType||t.node.getLayer()===r)&&(a=!0)}));var n=!e&&!i.hitOnDragEnabled&&a;return this.isListening()&&this.isVisible()&&!n}show(){return this.visible(!0),this}hide(){return this.visible(!1),this}getZIndex(){return this.index||0}getAbsoluteZIndex(){var t,e,i,r,a=this.getDepth(),n=this,s=0;return"Stage"!==n.nodeType&&function o(h){for(t=[],e=h.length,i=0;i0&&t[0].getDepth()<=a&&o(t)}(n.getStage().getChildren()),s}getDepth(){for(var t=0,e=this.parent;e;)t++,e=e.parent;return t}_batchTransformChanges(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(X),this._clearSelfAndDescendantCache(O)),this._needClearTransformCache=!1}setPosition(t){return this._batchTransformChanges((()=>{this.x(t.x),this.y(t.y)})),this}getPosition(){return{x:this.x(),y:this.y()}}getRelativePointerPosition(){if(!this.getStage())return null;var t=this.getStage().getPointerPosition();if(!t)return null;var e=this.getAbsoluteTransform().copy();return e.invert(),e.point(t)}getAbsolutePosition(t){let e=!1,i=this.parent;for(;i;){if(i.isCached()){e=!0;break}i=i.parent}e&&!t&&(t=!0);var r=this.getAbsoluteTransform(t).getMatrix(),n=new a,s=this.offset();return n.m=r.slice(),n.translate(s.x,s.y),n.getTranslation()}setAbsolutePosition(t){var e=this._clearTransform();this.attrs.x=e.x,this.attrs.y=e.y,delete e.x,delete e.y,this._clearCache(X);var i=this._getAbsoluteTransform().copy();return i.invert(),i.translate(t.x,t.y),t={x:this.attrs.x+i.getTranslation().x,y:this.attrs.y+i.getTranslation().y},this._setTransform(e),this.setPosition({x:t.x,y:t.y}),this._clearCache(X),this._clearSelfAndDescendantCache(O),this}_setTransform(t){var e;for(e in t)this.attrs[e]=t[e]}_clearTransform(){var t={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,t}move(t){var e=t.x,i=t.y,r=this.x(),a=this.y();return void 0!==e&&(r+=e),void 0!==i&&(a+=i),this.setPosition({x:r,y:a}),this}_eachAncestorReverse(t,e){var i,r,a=[],n=this.getParent();if(!e||e._id!==this._id){for(a.unshift(this);n&&(!e||n._id!==e._id);)a.unshift(n),n=n.parent;for(i=a.length,r=0;r0&&(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0)}moveToBottom(){if(!this.parent)return g.warn("Node has no parent. moveToBottom function is ignored."),!1;var t=this.index;return t>0&&(this.parent.children.splice(t,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0)}setZIndex(t){if(!this.parent)return g.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&g.warn("Unexpected value "+t+" 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)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this}getAbsoluteOpacity(){return this._getCache(D,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t}moveTo(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this}toObject(){var t,e,i,r,a={},n=this.getAttrs();for(t in a.attrs={},n)e=n[t],g.isObject(e)&&!g._isPlainObject(e)&&!g._isArray(e)||(i="function"==typeof this[t]&&this[t],delete n[t],r=i?i.call(this):null,n[t]=e,r!==e&&(a.attrs[t]=e));return a.className=this.getClassName(),g._prepareToStringify(a)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(t,e,i){var r=[];e&&this._isMatch(t)&&r.push(this);for(var a=this.parent;a;){if(a===i)return r;a._isMatch(t)&&r.push(a),a=a.parent}return r}isAncestorOf(t){return!1}findAncestor(t,e,i){return this.findAncestors(t,e,i)[0]}_isMatch(t){if(!t)return!1;if("function"==typeof t)return t(this);var e,i,r=t.replace(/ /g,"").split(","),a=r.length;for(e=0;e{try{const i=null==t?void 0:t.callback;i&&delete t.callback,g._urlToImage(this.toDataURL(t),(function(t){e(t),null==i||i(t)}))}catch(t){i(t)}}))}toBlob(t){return new Promise(((e,i)=>{try{const i=null==t?void 0:t.callback;i&&delete t.callback,this.toCanvas(t).toBlob((t=>{e(t),null==i||i(t)}))}catch(t){i(t)}}))}setSize(t){return this.width(t.width),this.height(t.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return void 0!==this.attrs.dragDistance?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():i.dragDistance}_off(t,e,i){var r,a,n,s=this.eventListeners[t];for(r=0;r=0)&&!this.isDragging()){var e=!1;E._dragElements.forEach((t=>{this.isAncestorOf(t.node)&&(e=!0)})),e||this._createDragElement(t)}}))}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{if(this._dragCleanup(),!this.getStage())return;const t=E._dragElements.get(this._id),e=t&&"dragging"===t.dragStatus,i=t&&"ready"===t.dragStatus;e?this.stopDrag():i&&E._dragElements.delete(this._id)}}_dragCleanup(){this.off("mousedown.konva"),this.off("touchstart.konva")}isClientRectOnScreen(t={x:0,y:0}){const e=this.getStage();if(!e)return!1;const i={x:-t.x,y:-t.y,width:e.width()+2*t.x,height:e.height()+2*t.y};return g.haveIntersection(i,this.getClientRect())}static create(t,e){return g._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)}static _createNode(t,e){var r,a,n,s=V.prototype.getClassName.call(t),o=t.children;e&&(t.attrs.container=e),i[s]||(g.warn('Can not find a node with class name "'+s+'". Fallback to "Shape".'),s="Shape");if(r=new(0,i[s])(t.attrs),o)for(a=o.length,n=0;n0}removeChildren(){return this.getChildren().forEach((t=>{t.parent=null,t.index=0,t.remove()})),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach((t=>{t.parent=null,t.index=0,t.destroy()})),this.children=[],this._requestDraw(),this}add(...t){if(0===t.length)return this;if(t.length>1){for(var e=0;e0?e[0]:void 0}_generalFind(t,e){var i=[];return this._descendants((r=>{const a=r._isMatch(t);return a&&i.push(r),!(!a||!e)})),i}_descendants(t){let e=!1;const i=this.getChildren();for(const r of i){if(e=t(r),e)return!0;if(r.hasChildren()&&(e=r._descendants(t),e))return!0}return!1}toObject(){var t=V.prototype.toObject.call(this);return t.children=[],this.getChildren().forEach((e=>{t.children.push(e.toObject())})),t}isAncestorOf(t){for(var e=t.getParent();e;){if(e._id===this._id)return!0;e=e.getParent()}return!1}clone(t){var e=V.prototype.clone.call(this,t);return this.getChildren().forEach((function(t){e.add(t.clone())})),e}getAllIntersections(t){var e=[];return this.find("Shape").forEach((function(i){i.isVisible()&&i.intersects(t)&&e.push(i)})),e}_clearSelfAndDescendantCache(t){var e;super._clearSelfAndDescendantCache(t),this.isCached()||null===(e=this.children)||void 0===e||e.forEach((function(e){e._clearSelfAndDescendantCache(t)}))}_setChildrenIndices(){var t;null===(t=this.children)||void 0===t||t.forEach((function(t,e){t.index=e})),this._requestDraw()}drawScene(t,e){var i=this.getLayer(),r=t||i&&i.getCanvas(),a=r&&r.getContext(),n=this._getCanvasCache(),s=n&&n.scene,o=r&&r.isCache;if(!this.isVisible()&&!o)return this;if(s){a.save();var h=this.getAbsoluteTransform(e).getMatrix();a.transform(h[0],h[1],h[2],h[3],h[4],h[5]),this._drawCachedSceneCanvas(a),a.restore()}else this._drawChildren("drawScene",r,e);return this}drawHit(t,e){if(!this.shouldDrawHit(e))return this;var i=this.getLayer(),r=t||i&&i.hitCanvas,a=r&&r.getContext(),n=this._getCanvasCache();if(n&&n.hit){a.save();var s=this.getAbsoluteTransform(e).getMatrix();a.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._drawCachedHitCanvas(a),a.restore()}else this._drawChildren("drawHit",r,e);return this}_drawChildren(t,e,i){var r,a=e&&e.getContext(),n=this.clipWidth(),s=this.clipHeight(),o=this.clipFunc(),h=n&&s||o;const l=i===this;if(h){a.save();var d=this.getAbsoluteTransform(i),c=d.getMatrix();if(a.transform(c[0],c[1],c[2],c[3],c[4],c[5]),a.beginPath(),o)o.call(this,a,this);else{var g=this.clipX(),u=this.clipY();a.rect(g,u,n,s)}a.clip(),c=d.copy().invert().getMatrix(),a.transform(c[0],c[1],c[2],c[3],c[4],c[5])}var f=!l&&"source-over"!==this.globalCompositeOperation()&&"drawScene"===t;f&&(a.save(),a._applyGlobalCompositeOperation(this)),null===(r=this.children)||void 0===r||r.forEach((function(r){r[t](e,i)})),f&&a.restore(),h&&a.restore()}getClientRect(t){var e,i,r,a,n,s=(t=t||{}).skipTransform,o=t.relativeTo,h={x:1/0,y:1/0,width:0,height:0},l=this;null===(e=this.children)||void 0===e||e.forEach((function(e){if(e.visible()){var s=e.getClientRect({relativeTo:l,skipShadow:t.skipShadow,skipStroke:t.skipStroke});0===s.width&&0===s.height||(void 0===i?(i=s.x,r=s.y,a=s.x+s.width,n=s.y+s.height):(i=Math.min(i,s.x),r=Math.min(r,s.y),a=Math.max(a,s.x+s.width),n=Math.max(n,s.y+s.height)))}}));for(var d=this.find("Shape"),c=!1,g=0;gt.indexOf("pointer")>=0?"pointer":t.indexOf("touch")>=0?"touch":"mouse",Tt=t=>{const e=kt(t);return"pointer"===e?i.pointerEventsEnabled&&Pt.pointer:"touch"===e?Pt.touch:"mouse"===e?Pt.mouse:void 0};function At(t={}){return(t.clipFunc||t.clipWidth||t.clipHeight)&&g.warn("Stage does not support clipping. Please use clip for Layers or Groups."),t}const Mt=[];class Gt extends Q{constructor(t){super(At(t)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),Mt.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",(()=>{At(this.attrs)})),this._checkVisibility()}_validateAdd(t){const e="Layer"===t.getType(),i="FastLayer"===t.getType();e||i||g.throw("You may only add layers to the stage.")}_checkVisibility(){if(!this.content)return;const t=this.visible()?"":"none";this.content.style.display=t}setContainer(t){if("string"==typeof t){if("."===t.charAt(0)){var e=t.slice(1);t=document.getElementsByClassName(e)[0]}else{var i;i="#"!==t.charAt(0)?t:t.slice(1),t=document.getElementById(i)}if(!t)throw"Can not find container in document with id "+i}return this._setAttr("container",t),this.content&&(this.content.parentElement&&this.content.parentElement.removeChild(this.content),t.appendChild(this.content)),this}shouldDrawHit(){return!0}clear(){var t,e=this.children,i=e.length;for(t=0;t-1&&Mt.splice(e,1),g.releaseCanvas(this.bufferCanvas._canvas,this.bufferHitCanvas._canvas),this}getPointerPosition(){const t=this._pointerPositions[0]||this._changedPointerPositions[0];return t?{x:t.x,y:t.y}:(g.warn("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);"),null)}_getPointerById(t){return this._pointerPositions.find((e=>e.id===t))}getPointersPositions(){return this._pointerPositions}getStage(){return this}getContent(){return this.content}_toKonvaCanvas(t){(t=t||{}).x=t.x||0,t.y=t.y||0,t.width=t.width||this.width(),t.height=t.height||this.height();var e=new G({width:t.width,height:t.height,pixelRatio:t.pixelRatio||1}),i=e.getContext()._context,r=this.children;return(t.x||t.y)&&i.translate(-1*t.x,-1*t.y),r.forEach((function(e){if(e.isVisible()){var r=e._toKonvaCanvas(t);i.drawImage(r._canvas,t.x,t.y,r.getWidth()/r.getPixelRatio(),r.getHeight()/r.getPixelRatio())}})),e}getIntersection(t){if(!t)return null;var e,i=this.children;for(e=i.length-1;e>=0;e--){const r=i[e].getIntersection(t);if(r)return r}return null}_resizeDOM(){var t=this.width(),e=this.height();this.content&&(this.content.style.width=t+"px",this.content.style.height=e+"px"),this.bufferCanvas.setSize(t,e),this.bufferHitCanvas.setSize(t,e),this.children.forEach((i=>{i.setSize({width:t,height:e}),i.draw()}))}add(t,...e){if(arguments.length>1){for(var r=0;r5&&g.warn("The stage has "+a+" 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."),t.setSize({width:this.width(),height:this.height()}),t.draw(),i.isBrowser&&this.content.appendChild(t.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(t){return et(t,this)}setPointerCapture(t){it(t,this)}releaseCapture(t){rt(t)}getLayers(){return this.children}_bindContentEvents(){i.isBrowser&&Ct.forEach((([t,e])=>{this.content.addEventListener(t,(t=>{this[e](t)}),{passive:!1})}))}_pointerenter(t){this.setPointersPositions(t);const e=Tt(t.type);this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);const e=Tt(t.type);this._fire(e.pointerover,{evt:t,target:this,currentTarget:this})}_getTargetShape(t){let e=this[t+"targetShape"];return e&&!e.getStage()&&(e=null),e}_pointerleave(t){const e=Tt(t.type),r=kt(t.type);if(e){this.setPointersPositions(t);var a=this._getTargetShape(r),n=!E.isDragging||i.hitOnDragEnabled;a&&n?(a._fireAndBubble(e.pointerout,{evt:t}),a._fireAndBubble(e.pointerleave,{evt:t}),this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this[r+"targetShape"]=null):n&&(this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this._fire(e.pointerout,{evt:t,target:this,currentTarget:this})),this.pointerPos=void 0,this._pointerPositions=[]}}_pointerdown(t){const e=Tt(t.type),r=kt(t.type);if(e){this.setPointersPositions(t);var a=!1;this._changedPointerPositions.forEach((n=>{var s=this.getIntersection(n);E.justDragged=!1,i["_"+r+"ListenClick"]=!0;if(!(s&&s.isListening()))return;i.capturePointerEventsEnabled&&s.setPointerCapture(n.id),this[r+"ClickStartShape"]=s,s._fireAndBubble(e.pointerdown,{evt:t,pointerId:n.id}),a=!0;const o=t.type.indexOf("touch")>=0;s.preventDefault()&&t.cancelable&&o&&t.preventDefault()})),a||this._fire(e.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}}_pointermove(t){const e=Tt(t.type),r=kt(t.type);if(!e)return;if(E.isDragging&&E.node.preventDefault()&&t.cancelable&&t.preventDefault(),this.setPointersPositions(t),!(!E.isDragging||i.hitOnDragEnabled))return;var a={};let n=!1;var s=this._getTargetShape(r);this._changedPointerPositions.forEach((i=>{const o=$(i.id)||this.getIntersection(i),h=i.id,l={evt:t,pointerId:h};var d=s!==o;if(d&&s&&(s._fireAndBubble(e.pointerout,Object.assign({},l),o),s._fireAndBubble(e.pointerleave,Object.assign({},l),o)),o){if(a[o._id])return;a[o._id]=!0}o&&o.isListening()?(n=!0,d&&(o._fireAndBubble(e.pointerover,Object.assign({},l),s),o._fireAndBubble(e.pointerenter,Object.assign({},l),s),this[r+"targetShape"]=o),o._fireAndBubble(e.pointermove,Object.assign({},l))):s&&(this._fire(e.pointerover,{evt:t,target:this,currentTarget:this,pointerId:h}),this[r+"targetShape"]=null)})),n||this._fire(e.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(t){const e=Tt(t.type),r=kt(t.type);if(!e)return;this.setPointersPositions(t);const a=this[r+"ClickStartShape"],n=this[r+"ClickEndShape"];var s={};let o=!1;this._changedPointerPositions.forEach((h=>{const l=$(h.id)||this.getIntersection(h);if(l){if(l.releaseCapture(h.id),s[l._id])return;s[l._id]=!0}const d=h.id,c={evt:t,pointerId:d};let g=!1;i["_"+r+"InDblClickWindow"]?(g=!0,clearTimeout(this[r+"DblTimeout"])):E.justDragged||(i["_"+r+"InDblClickWindow"]=!0,clearTimeout(this[r+"DblTimeout"])),this[r+"DblTimeout"]=setTimeout((function(){i["_"+r+"InDblClickWindow"]=!1}),i.dblClickWindow),l&&l.isListening()?(o=!0,this[r+"ClickEndShape"]=l,l._fireAndBubble(e.pointerup,Object.assign({},c)),i["_"+r+"ListenClick"]&&a&&a===l&&(l._fireAndBubble(e.pointerclick,Object.assign({},c)),g&&n&&n===l&&l._fireAndBubble(e.pointerdblclick,Object.assign({},c)))):(this[r+"ClickEndShape"]=null,i["_"+r+"ListenClick"]&&this._fire(e.pointerclick,{evt:t,target:this,currentTarget:this,pointerId:d}),g&&this._fire(e.pointerdblclick,{evt:t,target:this,currentTarget:this,pointerId:d}))})),o||this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),i["_"+r+"ListenClick"]=!1,t.cancelable&&"touch"!==r&&t.preventDefault()}_contextmenu(t){this.setPointersPositions(t);var e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(_t,{evt:t}):this._fire(_t,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);var e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(wt,{evt:t}):this._fire(wt,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);const e=$(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(gt,tt(t)),rt(t.pointerId)}_lostpointercapture(t){rt(t.pointerId)}setPointersPositions(t){var e=this._getContentPosition(),i=null,r=null;void 0!==(t=t||window.event).touches?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(t.touches,(t=>{this._pointerPositions.push({id:t.identifier,x:(t.clientX-e.left)/e.scaleX,y:(t.clientY-e.top)/e.scaleY})})),Array.prototype.forEach.call(t.changedTouches||t.touches,(t=>{this._changedPointerPositions.push({id:t.identifier,x:(t.clientX-e.left)/e.scaleX,y:(t.clientY-e.top)/e.scaleY})}))):(i=(t.clientX-e.left)/e.scaleX,r=(t.clientY-e.top)/e.scaleY,this.pointerPos={x:i,y:r},this._pointerPositions=[{x:i,y:r,id:g._getFirstPointerId(t)}],this._changedPointerPositions=[{x:i,y:r,id:g._getFirstPointerId(t)}])}_setPointerPosition(t){g.warn('Method _setPointerPosition is deprecated. Use "stage.setPointersPositions(event)" instead.'),this.setPointersPositions(t)}_getContentPosition(){if(!this.content||!this.content.getBoundingClientRect)return{top:0,left:0,scaleX:1,scaleY:1};var t=this.content.getBoundingClientRect();return{top:t.top,left:t.left,scaleX:t.width/this.content.clientWidth||1,scaleY:t.height/this.content.clientHeight||1}}_buildDOM(){if(this.bufferCanvas=new G({width:this.width(),height:this.height()}),this.bufferHitCanvas=new R({pixelRatio:1,width:this.width(),height:this.height()}),i.isBrowser){var t=this.container();if(!t)throw"Stage has no container. A container is required.";t.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"),t.appendChild(this.content),this._resizeDOM()}}cache(){return g.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(t){t.batchDraw()})),this}}Gt.prototype.nodeType="Stage",r(Gt),w.addGetterSetter(Gt,"container");var Rt="hasShadow",Et="shadowRGBA",Dt="patternImage",Lt="linearGradient",Ot="radialGradient";let It;function Ft(){return It||(It=g.createCanvasElement().getContext("2d"),It)}const Nt={};class Bt extends V{constructor(t){let e;for(super(t);e=g.getRandomColor(),!e||e in Nt;);this.colorKey=e,Nt[e]=this}getContext(){return g.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return g.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(Rt,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&0!==this.shadowOpacity()&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(Dt,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const t=Ft().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(t&&t.setTransform){const e=new a;e.translate(this.fillPatternX(),this.fillPatternY()),e.rotate(i.getAngle(this.fillPatternRotation())),e.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),e.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());const r=e.getMatrix(),n="undefined"==typeof DOMMatrix?{a:r[0],b:r[1],c:r[2],d:r[3],e:r[4],f:r[5]}:new DOMMatrix(r);t.setTransform(n)}return t}}_getLinearGradient(){return this._getCache(Lt,this.__getLinearGradient)}__getLinearGradient(){var t=this.fillLinearGradientColorStops();if(t){for(var e=Ft(),i=this.fillLinearGradientStartPoint(),r=this.fillLinearGradientEndPoint(),a=e.createLinearGradient(i.x,i.y,r.x,r.y),n=0;nthis.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(){const t=this.hitStrokeWidth();return"auto"===t?this.hasStroke():this.strokeEnabled()&&!!t}intersects(t){var e=this.getStage().bufferHitCanvas;return e.getContext().clear(),this.drawHit(e,null,!0),e.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data[3]>0}destroy(){return V.prototype.destroy.call(this),delete Nt[this.colorKey],delete this.colorKey,this}_useBufferCanvas(t){var e;if(!this.getStage())return!1;if(!(null===(e=this.attrs.perfectDrawEnabled)||void 0===e||e))return!1;const i=t||this.hasFill(),r=this.hasStroke(),a=1!==this.getAbsoluteOpacity();if(i&&r&&a)return!0;const n=this.hasShadow(),s=this.shadowForStrokeEnabled();return!!(i&&r&&n&&s)}setStrokeHitEnabled(t){g.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return 0!==this.hitStrokeWidth()}getSelfRect(){var t=this.size();return{x:this._centroid?-t.width/2:0,y:this._centroid?-t.height/2:0,width:t.width,height:t.height}}getClientRect(t={}){const e=t.skipTransform,i=t.relativeTo,r=this.getSelfRect(),a=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,n=r.width+a,s=r.height+a,o=!t.skipShadow&&this.hasShadow(),h=o?this.shadowOffsetX():0,l=o?this.shadowOffsetY():0,d=n+Math.abs(h),c=s+Math.abs(l),g=o&&this.shadowBlur()||0,u={width:d+2*g,height:c+2*g,x:-(a/2+g)+Math.min(h,0)+r.x,y:-(a/2+g)+Math.min(l,0)+r.y};return e?u:this._transformedRect(u,i)}drawScene(t,e){var i,r,a=this.getLayer(),n=t||a.getCanvas(),s=n.getContext(),o=this._getCanvasCache(),h=this.getSceneFunc(),l=this.hasShadow(),d=n.isCache,c=e===this;if(!this.isVisible()&&!c)return this;if(o){s.save();var g=this.getAbsoluteTransform(e).getMatrix();return s.transform(g[0],g[1],g[2],g[3],g[4],g[5]),this._drawCachedSceneCanvas(s),s.restore(),this}if(!h)return this;if(s.save(),this._useBufferCanvas()&&!d){(r=(i=this.getStage().bufferCanvas).getContext()).clear(),r.save(),r._applyLineJoin(this);var u=this.getAbsoluteTransform(e).getMatrix();r.transform(u[0],u[1],u[2],u[3],u[4],u[5]),h.call(this,r,this),r.restore();var f=i.pixelRatio;l&&s._applyShadow(this),s._applyOpacity(this),s._applyGlobalCompositeOperation(this),s.drawImage(i._canvas,0,0,i.width/f,i.height/f)}else{if(s._applyLineJoin(this),!c){u=this.getAbsoluteTransform(e).getMatrix();s.transform(u[0],u[1],u[2],u[3],u[4],u[5]),s._applyOpacity(this),s._applyGlobalCompositeOperation(this)}l&&s._applyShadow(this),h.call(this,s,this)}return s.restore(),this}drawHit(t,e,i=!1){if(!this.shouldDrawHit(e,i))return this;var r=this.getLayer(),a=t||r.hitCanvas,n=a&&a.getContext(),s=this.hitFunc()||this.sceneFunc(),o=this._getCanvasCache(),h=o&&o.hit;if(this.colorKey||g.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()"),h){n.save();var l=this.getAbsoluteTransform(e).getMatrix();return n.transform(l[0],l[1],l[2],l[3],l[4],l[5]),this._drawCachedHitCanvas(n),n.restore(),this}if(!s)return this;n.save(),n._applyLineJoin(this);if(!(this===e)){var d=this.getAbsoluteTransform(e).getMatrix();n.transform(d[0],d[1],d[2],d[3],d[4],d[5])}return s.call(this,n,this),n.restore(),this}drawHitFromCache(t=0){var e,i,r,a,n,s=this._getCanvasCache(),o=this._getCachedSceneCanvas(),h=s.hit,l=h.getContext(),d=h.getWidth(),c=h.getHeight();l.clear(),l.drawImage(o._canvas,0,0,d,c);try{for(r=(i=(e=l.getImageData(0,0,d,c)).data).length,a=g._hexToRgb(this.colorKey),n=0;nt?(i[n]=a.r,i[n+1]=a.g,i[n+2]=a.b,i[n+3]=255):i[n+3]=0;l.putImageData(e,0,0)}catch(t){g.error("Unable to draw hit graph from cached scene canvas. "+t.message)}return this}hasPointerCapture(t){return et(t,this)}setPointerCapture(t){it(t,this)}releaseCapture(t){rt(t)}}Bt.prototype._fillFunc=function(t){t.fill()},Bt.prototype._strokeFunc=function(t){t.stroke()},Bt.prototype._fillFuncHit=function(t){t.fill()},Bt.prototype._strokeFuncHit=function(t){t.stroke()},Bt.prototype._centroid=!1,Bt.prototype.nodeType="Shape",r(Bt),Bt.prototype.eventListeners={},Bt.prototype.on.call(Bt.prototype,"shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",(function(){this._clearCache(Rt)})),Bt.prototype.on.call(Bt.prototype,"shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",(function(){this._clearCache(Et)})),Bt.prototype.on.call(Bt.prototype,"fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",(function(){this._clearCache(Dt)})),Bt.prototype.on.call(Bt.prototype,"fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",(function(){this._clearCache(Lt)})),Bt.prototype.on.call(Bt.prototype,"fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",(function(){this._clearCache(Ot)})),w.addGetterSetter(Bt,"stroke",void 0,y()),w.addGetterSetter(Bt,"strokeWidth",2,p()),w.addGetterSetter(Bt,"fillAfterStrokeEnabled",!1),w.addGetterSetter(Bt,"hitStrokeWidth","auto",m()),w.addGetterSetter(Bt,"strokeHitEnabled",!0,x()),w.addGetterSetter(Bt,"perfectDrawEnabled",!0,x()),w.addGetterSetter(Bt,"shadowForStrokeEnabled",!0,x()),w.addGetterSetter(Bt,"lineJoin"),w.addGetterSetter(Bt,"lineCap"),w.addGetterSetter(Bt,"sceneFunc"),w.addGetterSetter(Bt,"hitFunc"),w.addGetterSetter(Bt,"dash"),w.addGetterSetter(Bt,"dashOffset",0,p()),w.addGetterSetter(Bt,"shadowColor",void 0,_()),w.addGetterSetter(Bt,"shadowBlur",0,p()),w.addGetterSetter(Bt,"shadowOpacity",1,p()),w.addComponentsGetterSetter(Bt,"shadowOffset",["x","y"]),w.addGetterSetter(Bt,"shadowOffsetX",0,p()),w.addGetterSetter(Bt,"shadowOffsetY",0,p()),w.addGetterSetter(Bt,"fillPatternImage"),w.addGetterSetter(Bt,"fill",void 0,y()),w.addGetterSetter(Bt,"fillPatternX",0,p()),w.addGetterSetter(Bt,"fillPatternY",0,p()),w.addGetterSetter(Bt,"fillLinearGradientColorStops"),w.addGetterSetter(Bt,"strokeLinearGradientColorStops"),w.addGetterSetter(Bt,"fillRadialGradientStartRadius",0),w.addGetterSetter(Bt,"fillRadialGradientEndRadius",0),w.addGetterSetter(Bt,"fillRadialGradientColorStops"),w.addGetterSetter(Bt,"fillPatternRepeat","repeat"),w.addGetterSetter(Bt,"fillEnabled",!0),w.addGetterSetter(Bt,"strokeEnabled",!0),w.addGetterSetter(Bt,"shadowEnabled",!0),w.addGetterSetter(Bt,"dashEnabled",!0),w.addGetterSetter(Bt,"strokeScaleEnabled",!0),w.addGetterSetter(Bt,"fillPriority","color"),w.addComponentsGetterSetter(Bt,"fillPatternOffset",["x","y"]),w.addGetterSetter(Bt,"fillPatternOffsetX",0,p()),w.addGetterSetter(Bt,"fillPatternOffsetY",0,p()),w.addComponentsGetterSetter(Bt,"fillPatternScale",["x","y"]),w.addGetterSetter(Bt,"fillPatternScaleX",1,p()),w.addGetterSetter(Bt,"fillPatternScaleY",1,p()),w.addComponentsGetterSetter(Bt,"fillLinearGradientStartPoint",["x","y"]),w.addComponentsGetterSetter(Bt,"strokeLinearGradientStartPoint",["x","y"]),w.addGetterSetter(Bt,"fillLinearGradientStartPointX",0),w.addGetterSetter(Bt,"strokeLinearGradientStartPointX",0),w.addGetterSetter(Bt,"fillLinearGradientStartPointY",0),w.addGetterSetter(Bt,"strokeLinearGradientStartPointY",0),w.addComponentsGetterSetter(Bt,"fillLinearGradientEndPoint",["x","y"]),w.addComponentsGetterSetter(Bt,"strokeLinearGradientEndPoint",["x","y"]),w.addGetterSetter(Bt,"fillLinearGradientEndPointX",0),w.addGetterSetter(Bt,"strokeLinearGradientEndPointX",0),w.addGetterSetter(Bt,"fillLinearGradientEndPointY",0),w.addGetterSetter(Bt,"strokeLinearGradientEndPointY",0),w.addComponentsGetterSetter(Bt,"fillRadialGradientStartPoint",["x","y"]),w.addGetterSetter(Bt,"fillRadialGradientStartPointX",0),w.addGetterSetter(Bt,"fillRadialGradientStartPointY",0),w.addComponentsGetterSetter(Bt,"fillRadialGradientEndPoint",["x","y"]),w.addGetterSetter(Bt,"fillRadialGradientEndPointX",0),w.addGetterSetter(Bt,"fillRadialGradientEndPointY",0),w.addGetterSetter(Bt,"fillPatternRotation",0),w.backCompat(Bt,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});var Ht=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],Wt=Ht.length;class zt extends Q{constructor(t){super(t),this.canvas=new G,this.hitCanvas=new R({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(t){return this.getContext().clear(t),this.getHitCanvas().getContext().clear(t),this}setZIndex(t){super.setZIndex(t);var e=this.getStage();return e&&e.content&&(e.content.removeChild(this.getNativeCanvasElement()),t{this.draw(),this._waitingForDraw=!1}))),this}getIntersection(t){if(!this.isListening()||!this.isVisible())return null;for(var e=1,i=!1;;){for(let r=0;r0?{antialiased:!0}:{}}drawScene(t,e){var i=this.getLayer(),r=t||i&&i.getCanvas();return this._fire("beforeDraw",{node:this}),this.clearBeforeDraw()&&r.getContext().clear(),Q.prototype.drawScene.call(this,r,e),this._fire("draw",{node:this}),this}drawHit(t,e){var i=this.getLayer(),r=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),Q.prototype.drawHit.call(this,r,e),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(t){g.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}getHitGraphEnabled(t){return g.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening()}toggleHitCanvas(){if(this.parent&&this.parent.content){var t=this.parent;!!this.hitCanvas._canvas.parentNode?t.content.removeChild(this.hitCanvas._canvas):t.content.appendChild(this.hitCanvas._canvas)}}destroy(){return g.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}}zt.prototype.nodeType="Layer",r(zt),w.addGetterSetter(zt,"imageSmoothingEnabled",!0),w.addGetterSetter(zt,"clearBeforeDraw",!0),w.addGetterSetter(zt,"hitGraphEnabled",!0,x());class Yt extends zt{constructor(t){super(t),this.listening(!1),g.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}}Yt.prototype.nodeType="FastLayer",r(Yt);class Xt extends Q{_validateAdd(t){var e=t.getType();"Group"!==e&&"Shape"!==e&&g.throw("You may only add groups and shapes to groups.")}}Xt.prototype.nodeType="Group",r(Xt);var jt=e.performance&&e.performance.now?function(){return e.performance.now()}:function(){return(new Date).getTime()};class Ut{constructor(t,e){this.id=Ut.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:jt(),frameRate:0},this.func=t,this.setLayers(e)}setLayers(t){var e=[];return e=t?t.length>0?t:[t]:[],this.layers=e,this}getLayers(){return this.layers}addLayer(t){var e,i=this.layers,r=i.length;for(e=0;ethis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())}getTime(){return this._time}setPosition(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t}getPosition(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)}play(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")}seek(t){this.pause(),this._time=t,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(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)}pause(){this.state=1,this.fire("onPause")}getTimer(){return(new Date).getTime()}}class Jt{constructor(t){var e,r,a=this,n=t.node,s=n._id,o=t.easing||Zt.Linear,h=!!t.yoyo;e=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=n,this._id=Vt++;var l=n.getLayer()||(n instanceof i.Stage?n.getLayers():null);for(r in l||g.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Ut((function(){a.tween.onEnterFrame()}),l),this.tween=new Qt(r,(function(t){a._tweenFunc(t)}),o,0,1,1e3*e,h),this._addListeners(),Jt.attrs[s]||(Jt.attrs[s]={}),Jt.attrs[s][this._id]||(Jt.attrs[s][this._id]={}),Jt.tweens[s]||(Jt.tweens[s]={}),t)void 0===qt[r]&&this._addAttr(r,t[r]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset,this.onUpdate=t.onUpdate}_addAttr(t,e){var i,r,a,n,s,o,h,l,d=this.node,c=d._id;if((a=Jt.tweens[c][t])&&delete Jt.attrs[c][a][t],i=d.getAttr(t),g._isArray(e))if(r=[],s=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(h=i,i=g._prepareArrayForTween(i,e,d.closed())):(o=e,e=g._prepareArrayForTween(e,i,d.closed()))),0===t.indexOf("fill"))for(n=0;n{this.anim.start()},this.tween.onReverse=()=>{this.anim.start()},this.tween.onPause=()=>{this.anim.stop()},this.tween.onFinish=()=>{var t=this.node,e=Jt.attrs[t._id][this._id];e.points&&e.points.trueEnd&&t.setAttr("points",e.points.trueEnd),this.onFinish&&this.onFinish.call(this)},this.tween.onReset=()=>{var t=this.node,e=Jt.attrs[t._id][this._id];e.points&&e.points.trueStart&&t.points(e.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(t){return this.tween.seek(1e3*t),this}pause(){return this.tween.pause(),this}finish(){return this.tween.finish(),this}destroy(){var t,e=this.node._id,i=this._id,r=Jt.tweens[e];for(t in this.pause(),r)delete Jt.tweens[e][t];delete Jt.attrs[e][i]}}Jt.attrs={},Jt.tweens={},V.prototype.to=function(t){var e=t.onFinish;t.node=this,t.onFinish=function(){this.destroy(),e&&e()},new Jt(t).play()};const Zt={BackEaseIn(t,e,i,r){var a=1.70158;return i*(t/=r)*t*((a+1)*t-a)+e},BackEaseOut(t,e,i,r){var a=1.70158;return i*((t=t/r-1)*t*((a+1)*t+a)+1)+e},BackEaseInOut(t,e,i,r){var a=1.70158;return(t/=r/2)<1?i/2*(t*t*((1+(a*=1.525))*t-a))+e:i/2*((t-=2)*t*((1+(a*=1.525))*t+a)+2)+e},ElasticEaseIn(t,e,i,r,a,n){var s=0;return 0===t?e:1==(t/=r)?e+i:(n||(n=.3*r),!a||a(t/=r)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e,BounceEaseIn:(t,e,i,r)=>i-Zt.BounceEaseOut(r-t,0,i,r)+e,BounceEaseInOut:(t,e,i,r)=>ti*(t/=r)*t+e,EaseOut:(t,e,i,r)=>-i*(t/=r)*(t-2)+e,EaseInOut:(t,e,i,r)=>(t/=r/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e,StrongEaseIn:(t,e,i,r)=>i*(t/=r)*t*t*t*t+e,StrongEaseOut:(t,e,i,r)=>i*((t=t/r-1)*t*t*t*t+1)+e,StrongEaseInOut:(t,e,i,r)=>(t/=r/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e,Linear:(t,e,i,r)=>i*t/r+e},$t=g._assign(i,{Util:g,Transform:a,Node:V,Container:Q,Stage:Gt,stages:Mt,Layer:zt,FastLayer:Yt,Group:Xt,DD:E,Shape:Bt,shapes:Nt,Animation:Ut,Tween:Jt,Easings:Zt,Context:P,Canvas:M});class te extends Bt{_sceneFunc(t){var e=i.getAngle(this.angle()),r=this.clockwise();t.beginPath(),t.arc(0,0,this.outerRadius(),0,e,r),t.arc(0,0,this.innerRadius(),e,0,!r),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}getSelfRect(){const t=this.innerRadius(),e=this.outerRadius(),r=this.clockwise(),a=i.getAngle(r?360-this.angle():this.angle()),n=Math.cos(Math.min(a,Math.PI)),s=Math.sin(Math.min(Math.max(Math.PI,a),3*Math.PI/2)),o=Math.sin(Math.min(a,Math.PI/2)),h=n*(n>0?t:e),l=s*(s>0?t:e),d=o*(o>0?e:t);return{x:h,y:r?-1*d:l,width:1*e-h,height:d-l}}}function ee(t,e,i,r,a,n,s){var o=Math.sqrt(Math.pow(i-t,2)+Math.pow(r-e,2)),h=Math.sqrt(Math.pow(a-i,2)+Math.pow(n-r,2)),l=s*o/(o+h),d=s*h/(o+h);return[i-l*(a-t),r-l*(n-e),i+d*(a-t),r+d*(n-e)]}function ie(t,e){var i,r,a=t.length,n=[];for(i=2;i4){for(i=(e=this.getTensionPoints()).length,r=o?0:4,o||t.quadraticCurveTo(e[0],e[1],e[2],e[3]);r{let r,a,n;r=i/2,a=0;for(let i=0;i<20;i++)n=r*ae[20][i]+r,a+=ne[20][i]*le(t,e,n);return r*a},he=(t,e,i)=>{void 0===i&&(i=1);const r=t[0]-2*t[1]+t[2],a=e[0]-2*e[1]+e[2],n=2*t[1]-2*t[0],s=2*e[1]-2*e[0],o=4*(r*r+a*a),h=4*(r*n+a*s),l=n*n+s*s;if(0===o)return i*Math.sqrt(Math.pow(t[2]-t[0],2)+Math.pow(e[2]-e[0],2));const d=h/(2*o),c=i+d,g=l/o-d*d,u=c*c+g>0?Math.sqrt(c*c+g):0,f=d*d+g>0?Math.sqrt(d*d+g):0,p=d+Math.sqrt(d*d+g)!==0?g*Math.log(Math.abs((c+u)/(d+f))):0;return Math.sqrt(o)/2*(c*u-d*f+p)};function le(t,e,i){const r=de(1,i,t),a=de(1,i,e),n=r*r+a*a;return Math.sqrt(n)}const de=(t,e,i)=>{const r=i.length-1;let a,n;if(0===r)return 0;if(0===t){n=0;for(let t=0;t<=r;t++)n+=se[r][t]*Math.pow(1-e,r-t)*Math.pow(e,t)*i[t];return n}a=new Array(r);for(let t=0;t{let r=1,a=t/e,n=(t-i(a))/e,s=0;for(;r>.001;){const o=i(a+n),h=Math.abs(t-o)/e;if(h500)break}return a};class ge extends Bt{constructor(t){super(t),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",(function(){this._readDataAttribute()}))}_readDataAttribute(){this.dataArray=ge.parsePathData(this.data()),this.pathLength=ge.getPathLength(this.dataArray)}_sceneFunc(t){var e=this.dataArray;t.beginPath();for(var i=!1,r=0;rl?h:l,p=h>l?1:h/l,v=h>l?l/h:1;t.translate(s,o),t.rotate(g),t.scale(p,v),t.arc(0,0,f,d,d+c,1-u),t.scale(1/p,1/v),t.rotate(-g),t.translate(-s,-o);break;case"z":i=!0,t.closePath()}}i||this.hasFill()?t.fillStrokeShape(this):t.strokeShape(this)}getSelfRect(){var t=[];this.dataArray.forEach((function(e){if("A"===e.command){var i=e.points[4],r=e.points[5],a=e.points[4]+r,n=Math.PI/180;if(Math.abs(i-a)a;r-=n){const i=ge.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],r,0);t.push(i.x,i.y)}else for(let r=i+n;re[r].pathLength;)t-=e[r].pathLength,++r;if(r===a)return{x:(i=e[r-1].points.slice(-2))[0],y:i[1]};if(t<.01)return{x:(i=e[r].points.slice(0,2))[0],y:i[1]};var n=e[r],s=n.points;switch(n.command){case"L":return ge.getPointOnLine(t,n.start.x,n.start.y,s[0],s[1]);case"C":return ge.getPointOnCubicBezier(ce(t,ge.getPathLength(e),(t=>oe([n.start.x,s[0],s[2],s[4]],[n.start.y,s[1],s[3],s[5]],t))),n.start.x,n.start.y,s[0],s[1],s[2],s[3],s[4],s[5]);case"Q":return ge.getPointOnQuadraticBezier(ce(t,ge.getPathLength(e),(t=>he([n.start.x,s[0],s[2]],[n.start.y,s[1],s[3]],t))),n.start.x,n.start.y,s[0],s[1],s[2],s[3]);case"A":var o=s[0],h=s[1],l=s[2],d=s[3],c=s[4],g=s[5],u=s[6];return c+=g*t/n.pathLength,ge.getPointOnEllipticalArc(o,h,l,d,c,u)}return null}static getPointOnLine(t,e,i,r,a,n,s){void 0===n&&(n=e),void 0===s&&(s=i);var o=(a-i)/(r-e+1e-8),h=Math.sqrt(t*t/(1+o*o));r0&&!isNaN(u[0]);){var m,_,y,x,b,S,w,C,P,k,T=null,A=[],M=h,G=l;switch(g){case"l":h+=u.shift(),l+=u.shift(),T="L",A.push(h,l);break;case"L":h=u.shift(),l=u.shift(),A.push(h,l);break;case"m":var R=u.shift(),E=u.shift();if(h+=R,l+=E,T="M",s.length>2&&"z"===s[s.length-1].command)for(var D=s.length-2;D>=0;D--)if("M"===s[D].command){h=s[D].points[0]+R,l=s[D].points[1]+E;break}A.push(h,l),g="l";break;case"M":h=u.shift(),l=u.shift(),T="M",A.push(h,l),g="L";break;case"h":h+=u.shift(),T="L",A.push(h,l);break;case"H":h=u.shift(),T="L",A.push(h,l);break;case"v":l+=u.shift(),T="L",A.push(h,l);break;case"V":l=u.shift(),T="L",A.push(h,l);break;case"C":A.push(u.shift(),u.shift(),u.shift(),u.shift()),h=u.shift(),l=u.shift(),A.push(h,l);break;case"c":A.push(h+u.shift(),l+u.shift(),h+u.shift(),l+u.shift()),h+=u.shift(),l+=u.shift(),T="C",A.push(h,l);break;case"S":_=h,y=l,"C"===(m=s[s.length-1]).command&&(_=h+(h-m.points[2]),y=l+(l-m.points[3])),A.push(_,y,u.shift(),u.shift()),h=u.shift(),l=u.shift(),T="C",A.push(h,l);break;case"s":_=h,y=l,"C"===(m=s[s.length-1]).command&&(_=h+(h-m.points[2]),y=l+(l-m.points[3])),A.push(_,y,h+u.shift(),l+u.shift()),h+=u.shift(),l+=u.shift(),T="C",A.push(h,l);break;case"Q":A.push(u.shift(),u.shift()),h=u.shift(),l=u.shift(),A.push(h,l);break;case"q":A.push(h+u.shift(),l+u.shift()),h+=u.shift(),l+=u.shift(),T="Q",A.push(h,l);break;case"T":_=h,y=l,"Q"===(m=s[s.length-1]).command&&(_=h+(h-m.points[0]),y=l+(l-m.points[1])),h=u.shift(),l=u.shift(),T="Q",A.push(_,y,h,l);break;case"t":_=h,y=l,"Q"===(m=s[s.length-1]).command&&(_=h+(h-m.points[0]),y=l+(l-m.points[1])),h+=u.shift(),l+=u.shift(),T="Q",A.push(_,y,h,l);break;case"A":x=u.shift(),b=u.shift(),S=u.shift(),w=u.shift(),C=u.shift(),P=h,k=l,h=u.shift(),l=u.shift(),T="A",A=this.convertEndpointToCenterParameterization(P,k,h,l,w,C,x,b,S);break;case"a":x=u.shift(),b=u.shift(),S=u.shift(),w=u.shift(),C=u.shift(),P=h,k=l,h+=u.shift(),l+=u.shift(),T="A",A=this.convertEndpointToCenterParameterization(P,k,h,l,w,C,x,b,S)}s.push({command:T||g,points:A,start:{x:M,y:G},pathLength:this.calcLength(M,G,T||g,A)})}"z"!==g&&"Z"!==g||s.push({command:"z",points:[],start:void 0,pathLength:0})}return s}static calcLength(t,e,i,r){var a,n,s,o,h=ge;switch(i){case"L":return h.getLineLength(t,e,r[0],r[1]);case"C":return oe([t,r[0],r[2],r[4]],[e,r[1],r[3],r[5]],1);case"Q":return he([t,r[0],r[2]],[e,r[1],r[3]],1);case"A":a=0;var l=r[4],d=r[5],c=r[4]+d,g=Math.PI/180;if(Math.abs(l-c)c;o-=g)s=h.getPointOnEllipticalArc(r[0],r[1],r[2],r[3],o,0),a+=h.getLineLength(n.x,n.y,s.x,s.y),n=s;else for(o=l+g;o1&&(s*=Math.sqrt(g),o*=Math.sqrt(g));var u=Math.sqrt((s*s*(o*o)-s*s*(c*c)-o*o*(d*d))/(s*s*(c*c)+o*o*(d*d)));a===n&&(u*=-1),isNaN(u)&&(u=0);var f=u*s*c/o,p=u*-o*d/s,v=(t+i)/2+Math.cos(l)*f-Math.sin(l)*p,m=(e+r)/2+Math.sin(l)*f+Math.cos(l)*p,_=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},y=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(_(t)*_(e))},x=function(t,e){return(t[0]*e[1]=1&&(C=0),0===n&&C>0&&(C-=2*Math.PI),1===n&&C<0&&(C+=2*Math.PI),[v,m,s,o,b,C,l,n]}}ge.prototype.className="Path",ge.prototype._attrsAffectingSize=["data"],r(ge),w.addGetterSetter(ge,"data");class ue extends re{_sceneFunc(t){super._sceneFunc(t);var e=2*Math.PI,i=this.points(),r=i,a=0!==this.tension()&&i.length>4;a&&(r=this.getTensionPoints());var n,s,o=this.pointerLength(),h=i.length;if(a){const t=[r[r.length-4],r[r.length-3],r[r.length-2],r[r.length-1],i[h-2],i[h-1]],e=ge.calcLength(r[r.length-4],r[r.length-3],"C",t),a=ge.getPointOnQuadraticBezier(Math.min(1,1-o/e),t[0],t[1],t[2],t[3],t[4],t[5]);n=i[h-2]-a.x,s=i[h-1]-a.y}else n=i[h-2]-i[h-4],s=i[h-1]-i[h-3];var l=(Math.atan2(s,n)+e)%e,d=this.pointerWidth();this.pointerAtEnding()&&(t.save(),t.beginPath(),t.translate(i[h-2],i[h-1]),t.rotate(l),t.moveTo(0,0),t.lineTo(-o,d/2),t.lineTo(-o,-d/2),t.closePath(),t.restore(),this.__fillStroke(t)),this.pointerAtBeginning()&&(t.save(),t.beginPath(),t.translate(i[0],i[1]),a?(n=(r[0]+r[2])/2-i[0],s=(r[1]+r[3])/2-i[1]):(n=i[2]-i[0],s=i[3]-i[1]),t.rotate((Math.atan2(-s,-n)+e)%e),t.moveTo(0,0),t.lineTo(-o,d/2),t.lineTo(-o,-d/2),t.closePath(),t.restore(),this.__fillStroke(t))}__fillStroke(t){var e=this.dashEnabled();e&&(this.attrs.dashEnabled=!1,t.setLineDash([])),t.fillStrokeShape(this),e&&(this.attrs.dashEnabled=!0)}getSelfRect(){const t=super.getSelfRect(),e=this.pointerWidth()/2;return{x:t.x-e,y:t.y-e,width:t.width+2*e,height:t.height+2*e}}}ue.prototype.className="Arrow",r(ue),w.addGetterSetter(ue,"pointerLength",10,p()),w.addGetterSetter(ue,"pointerWidth",10,p()),w.addGetterSetter(ue,"pointerAtBeginning",!1),w.addGetterSetter(ue,"pointerAtEnding",!0);class fe extends Bt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.attrs.radius||0,0,2*Math.PI,!1),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius()!==t/2&&this.radius(t/2)}setHeight(t){this.radius()!==t/2&&this.radius(t/2)}}fe.prototype._centroid=!0,fe.prototype.className="Circle",fe.prototype._attrsAffectingSize=["radius"],r(fe),w.addGetterSetter(fe,"radius",0,p());class pe extends Bt{_sceneFunc(t){var e=this.radiusX(),i=this.radiusY();t.beginPath(),t.save(),e!==i&&t.scale(1,i/e),t.arc(0,0,e,0,2*Math.PI,!1),t.restore(),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radiusX()}getHeight(){return 2*this.radiusY()}setWidth(t){this.radiusX(t/2)}setHeight(t){this.radiusY(t/2)}}pe.prototype.className="Ellipse",pe.prototype._centroid=!0,pe.prototype._attrsAffectingSize=["radiusX","radiusY"],r(pe),w.addComponentsGetterSetter(pe,"radius",["x","y"]),w.addGetterSetter(pe,"radiusX",0,p()),w.addGetterSetter(pe,"radiusY",0,p());class ve extends Bt{constructor(t){super(t),this.on("imageChange.konva",(()=>{this._setImageLoad()})),this._setImageLoad()}_setImageLoad(){const t=this.image();t&&t.complete||t&&4===t.readyState||t&&t.addEventListener&&t.addEventListener("load",(()=>{this._requestDraw()}))}_useBufferCanvas(){return super._useBufferCanvas(!0)}_sceneFunc(t){const e=this.getWidth(),i=this.getHeight(),r=this.cornerRadius(),a=this.attrs.image;let n;if(a){const t=this.attrs.cropWidth,r=this.attrs.cropHeight;n=t&&r?[a,this.cropX(),this.cropY(),t,r,0,0,e,i]:[a,0,0,e,i]}(this.hasFill()||this.hasStroke()||r)&&(t.beginPath(),r?g.drawRoundedRectPath(t,e,i,r):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)),a&&(r&&t.clip(),t.drawImage.apply(t,n))}_hitFunc(t){var e=this.width(),i=this.height(),r=this.cornerRadius();t.beginPath(),r?g.drawRoundedRectPath(t,e,i,r):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}getWidth(){var t,e;return null!==(t=this.attrs.width)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.width}getHeight(){var t,e;return null!==(t=this.attrs.height)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.height}static fromURL(t,e,i=null){var r=g.createImageElement();r.onload=function(){var t=new ve({image:r});e(t)},r.onerror=i,r.crossOrigin="Anonymous",r.src=t}}ve.prototype.className="Image",r(ve),w.addGetterSetter(ve,"cornerRadius",0,v(4)),w.addGetterSetter(ve,"image"),w.addComponentsGetterSetter(ve,"crop",["x","y","width","height"]),w.addGetterSetter(ve,"cropX",0,p()),w.addGetterSetter(ve,"cropY",0,p()),w.addGetterSetter(ve,"cropWidth",0,p()),w.addGetterSetter(ve,"cropHeight",0,p());var me=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],_e="up",ye="right",xe="down",be="left",Se=me.length;class we extends Xt{constructor(t){super(t),this.on("add.konva",(function(t){this._addListeners(t.child),this._sync()}))}getText(){return this.find("Text")[0]}getTag(){return this.find("Tag")[0]}_addListeners(t){var e,i=this,r=function(){i._sync()};for(e=0;e{e=Math.min(e,t.x),i=Math.max(i,t.x),r=Math.min(r,t.y),a=Math.max(a,t.y)})),{x:e,y:r,width:i-e,height:a-r}}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}ke.prototype.className="RegularPolygon",ke.prototype._centroid=!0,ke.prototype._attrsAffectingSize=["radius"],r(ke),w.addGetterSetter(ke,"radius",0,p()),w.addGetterSetter(ke,"sides",0,p());var Te=2*Math.PI;class Ae extends Bt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.innerRadius(),0,Te,!1),t.moveTo(this.outerRadius(),0),t.arc(0,0,this.outerRadius(),Te,0,!0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}Ae.prototype.className="Ring",Ae.prototype._centroid=!0,Ae.prototype._attrsAffectingSize=["innerRadius","outerRadius"],r(Ae),w.addGetterSetter(Ae,"innerRadius",0,p()),w.addGetterSetter(Ae,"outerRadius",0,p());class Me extends Bt{constructor(t){super(t),this._updated=!0,this.anim=new Ut((()=>{var t=this._updated;return this._updated=!1,t})),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(t){var e=this.animation(),i=this.frameIndex(),r=4*i,a=this.animations()[e],n=this.frameOffsets(),s=a[r+0],o=a[r+1],h=a[r+2],l=a[r+3],d=this.image();if((this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,h,l),t.closePath(),t.fillStrokeShape(this)),d)if(n){var c=n[e],g=2*i;t.drawImage(d,s,o,h,l,c[g+0],c[g+1],h,l)}else t.drawImage(d,s,o,h,l,0,0,h,l)}_hitFunc(t){var e=this.animation(),i=this.frameIndex(),r=4*i,a=this.animations()[e],n=this.frameOffsets(),s=a[r+2],o=a[r+3];if(t.beginPath(),n){var h=n[e],l=2*i;t.rect(h[l+0],h[l+1],s,o)}else t.rect(0,0,s,o);t.closePath(),t.fillShape(this)}_useBufferCanvas(){return super._useBufferCanvas(!0)}_setInterval(){var t=this;this.interval=setInterval((function(){t._updateIndex()}),1e3/this.frameRate())}start(){if(!this.isRunning()){var t=this.getLayer();this.anim.setLayers(t),this._setInterval(),this.anim.start()}}stop(){this.anim.stop(),clearInterval(this.interval)}isRunning(){return this.anim.isRunning()}_updateIndex(){var t=this.frameIndex(),e=this.animation();t1&&(v+=s)}}}_hitFunc(t){var e=this.getWidth(),i=this.getHeight();t.beginPath(),t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}setText(t){var e=g._isString(t)?t:null==t?"":t+"";return this._setAttr("text",e),this}getWidth(){return this.attrs.width===De||void 0===this.attrs.width?this.getTextWidth()+2*this.padding():this.attrs.width}getHeight(){return this.attrs.height===De||void 0===this.attrs.height?this.fontSize()*this.textArr.length*this.lineHeight()+2*this.padding():this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return g.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}measureSize(t){var e,i=Ye(),r=this.fontSize();return i.save(),i.font=this._getContextFont(),e=i.measureText(t),i.restore(),{width:e.width,height:r}}_getContextFont(){return this.fontStyle()+Be+this.fontVariant()+Be+(this.fontSize()+"px ")+this.fontFamily().split(",").map((t=>{const e=(t=t.trim()).indexOf(" ")>=0,i=t.indexOf('"')>=0||t.indexOf("'")>=0;return e&&!i&&(t=`"${t}"`),t})).join(", ")}_addTextLine(t){this.align()===Le&&(t=t.trim());var e=this._getTextWidth(t);return this.textArr.push({text:t,width:e,lastInParagraph:!1})}_getTextWidth(t){var e=this.letterSpacing(),i=t.length;return Ye().measureText(t).width+(i?e*(i-1):0)}_setTextData(){var t=this.text().split("\n"),e=+this.fontSize(),i=0,r=this.lineHeight()*e,a=this.attrs.width,n=this.attrs.height,s=a!==De&&void 0!==a,o=n!==De&&void 0!==n,h=this.padding(),l=a-2*h,d=n-2*h,c=0,g=this.wrap(),u="char"!==g&&g!==He,f=this.ellipsis();this.textArr=[],Ye().font=this._getContextFont();for(var p=f?this._getTextWidth("…"):0,v=0,m=t.length;vl)for(;_.length>0;){for(var x=0,b=_.length,S="",w=0;x>>1,P=_.slice(0,C+1),k=this._getTextWidth(P)+p;k<=l?(x=C+1,S=P,w=k):b=C}if(!S)break;if(u){var T,A=_[S.length];(T=(A===Be||"-"===A)&&w<=l?S.length:Math.max(S.lastIndexOf(Be),S.lastIndexOf("-"))+1)>0&&(x=T,S=S.slice(0,x),w=this._getTextWidth(S))}if(S=S.trimRight(),this._addTextLine(S),i=Math.max(i,w),c+=r,this._shouldHandleEllipsis(c)){this._tryToAddEllipsisToLastLine();break}if((_=(_=_.slice(x)).trimLeft()).length>0&&(y=this._getTextWidth(_))<=l){this._addTextLine(_),c+=r,i=Math.max(i,y);break}}else this._addTextLine(_),c+=r,i=Math.max(i,y),this._shouldHandleEllipsis(c)&&vd)break}this.textHeight=e,this.textWidth=i}_shouldHandleEllipsis(t){var e=+this.fontSize(),i=this.lineHeight()*e,r=this.attrs.height,a=r!==De&&void 0!==r,n=r-2*this.padding();return!(this.wrap()!==He)||a&&t+i>n}_tryToAddEllipsisToLastLine(){var t=this.attrs.width,e=t!==De&&void 0!==t,i=t-2*this.padding(),r=this.ellipsis(),a=this.textArr[this.textArr.length-1];if(a&&r){if(e)this._getTextWidth(a.text+"…")this.pathLength?null:ge.getPointAtLengthOfDataArray(t,this.dataArray)}_readDataAttribute(){this.dataArray=ge.parsePathData(this.attrs.data),this.pathLength=this._getTextPathLength()}_sceneFunc(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",this.textBaseline()),t.setAttr("textAlign","left"),t.save();var e=this.textDecoration(),i=this.fill(),r=this.fontSize(),a=this.glyphInfo;"underline"===e&&t.beginPath();for(var n=0;n=1){var i=e[0].p0;t.moveTo(i.x,i.y)}for(var r=0;rt+`.${Ke}`)).join(" "),Je="nodesRect",Ze=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange"],$e={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135};const ti="ontouchstart"in i._global;var ei=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"];function ii(t,e,i){const r=i.x+(t.x-i.x)*Math.cos(e)-(t.y-i.y)*Math.sin(e),a=i.y+(t.x-i.x)*Math.sin(e)+(t.y-i.y)*Math.cos(e);return Object.assign(Object.assign({},t),{rotation:t.rotation+e,x:r,y:a})}function ri(t,e){const i=function(t){return{x:t.x+t.width/2*Math.cos(t.rotation)+t.height/2*Math.sin(-t.rotation),y:t.y+t.height/2*Math.cos(t.rotation)+t.width/2*Math.sin(t.rotation)}}(t);return ii(t,e,i)}class ai extends Xt{constructor(t){super(t),this._transforming=!1,this._createElements(),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this.update=this.update.bind(this),this.on(Qe,this.update),this.getNode()&&this.update()}attachTo(t){return this.setNode(t),this}setNode(t){return g.warn("tr.setNode(shape), tr.node(shape) and tr.attachTo(shape) methods are deprecated. Please use tr.nodes(nodesArray) instead."),this.setNodes([t])}getNode(){return this._nodes&&this._nodes[0]}_getEventNamespace(){return Ke+this._id}setNodes(t=[]){this._nodes&&this._nodes.length&&this.detach();const e=t.filter((t=>!t.isAncestorOf(this)||(g.error("Konva.Transformer cannot be an a child of the node you are trying to attach"),!1)));return this._nodes=t=e,1===t.length&&this.useSingleNodeRotation()?this.rotation(t[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach((t=>{const e=()=>{1===this.nodes().length&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),this._transforming||this.isDragging()||this.update()},i=t._attrsAffectingSize.map((t=>t+"Change."+this._getEventNamespace())).join(" ");t.on(i,e),t.on(Ze.map((t=>t+`.${this._getEventNamespace()}`)).join(" "),e),t.on(`absoluteTransformChange.${this._getEventNamespace()}`,e),this._proxyDrag(t)})),this._resetTransformCache(),!!this.findOne(".top-left")&&this.update(),this}_proxyDrag(t){let e;t.on(`dragstart.${this._getEventNamespace()}`,(i=>{e=t.getAbsolutePosition(),this.isDragging()||t===this.findOne(".back")||this.startDrag(i,!1)})),t.on(`dragmove.${this._getEventNamespace()}`,(i=>{if(!e)return;const r=t.getAbsolutePosition(),a=r.x-e.x,n=r.y-e.y;this.nodes().forEach((e=>{if(e===t)return;if(e.isDragging())return;const r=e.getAbsolutePosition();e.setAbsolutePosition({x:r.x+a,y:r.y+n}),e.startDrag(i)})),e=null}))}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){this._nodes&&this._nodes.forEach((t=>{t.off("."+this._getEventNamespace())})),this._nodes=[],this._resetTransformCache()}_resetTransformCache(){this._clearCache(Je),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(Je,this.__getNodeRect)}__getNodeShape(t,e=this.rotation(),r){var a=t.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),n=t.getAbsoluteScale(r),s=t.getAbsolutePosition(r),o=a.x*n.x-t.offsetX()*n.x,h=a.y*n.y-t.offsetY()*n.y;const l=(i.getAngle(t.getAbsoluteRotation())+2*Math.PI)%(2*Math.PI);return ii({x:s.x+o*Math.cos(l)+h*Math.sin(-l),y:s.y+h*Math.cos(l)+o*Math.sin(l),width:a.width*n.x,height:a.height*n.y,rotation:l},-i.getAngle(e),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};const t=[];this.nodes().map((e=>{const i=e.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()});var r=[{x:i.x,y:i.y},{x:i.x+i.width,y:i.y},{x:i.x+i.width,y:i.y+i.height},{x:i.x,y:i.y+i.height}],a=e.getAbsoluteTransform();r.forEach((function(e){var i=a.point(e);t.push(i)}))}));const e=new a;var r,n,s,o;e.rotate(-i.getAngle(this.rotation())),t.forEach((function(t){var i=e.point(t);void 0===r&&(r=s=i.x,n=o=i.y),r=Math.min(r,i.x),n=Math.min(n,i.y),s=Math.max(s,i.x),o=Math.max(o,i.y)})),e.invert();const h=e.point({x:r,y:n});return{x:h.x,y:h.y,width:s-r,height:o-n,rotation:i.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(),ei.forEach(function(t){this._createAnchor(t)}.bind(this)),this._createAnchor("rotater")}_createAnchor(t){var e=new Pe({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:t+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:ti?10:"auto"}),r=this;e.on("mousedown touchstart",(function(t){r._handleMouseDown(t)})),e.on("dragstart",(t=>{e.stopDrag(),t.cancelBubble=!0})),e.on("dragend",(t=>{t.cancelBubble=!0})),e.on("mouseenter",(()=>{var r=i.getAngle(this.rotation()),a=function(t,e){if("rotater"===t)return"crosshair";e+=g.degToRad($e[t]||0);var i=(g.radToDeg(e)%360+360)%360;return g._inRange(i,337.5,360)||g._inRange(i,0,22.5)?"ns-resize":g._inRange(i,22.5,67.5)?"nesw-resize":g._inRange(i,67.5,112.5)?"ew-resize":g._inRange(i,112.5,157.5)?"nwse-resize":g._inRange(i,157.5,202.5)?"ns-resize":g._inRange(i,202.5,247.5)?"nesw-resize":g._inRange(i,247.5,292.5)?"ew-resize":g._inRange(i,292.5,337.5)?"nwse-resize":(g.error("Transformer has unknown angle for cursor detection: "+i),"pointer")}(t,r);e.getStage().content&&(e.getStage().content.style.cursor=a),this._cursorChange=!0})),e.on("mouseout",(()=>{e.getStage().content&&(e.getStage().content.style.cursor=""),this._cursorChange=!1})),this.add(e)}_createBack(){var t=new Bt({name:"back",width:0,height:0,draggable:!0,sceneFunc(t){var e=this.getParent(),i=e.padding();t.beginPath(),t.rect(-i,-i,this.width()+2*i,this.height()+2*i),t.moveTo(this.width()/2,-i),e.rotateEnabled()&&t.lineTo(this.width()/2,-e.rotateAnchorOffset()*g._sign(this.height())-i),t.fillStrokeShape(this)},hitFunc:(t,e)=>{if(this.shouldOverdrawWholeArea()){var i=this.padding();t.beginPath(),t.rect(-i,-i,e.width()+2*i,e.height()+2*i),t.fillStrokeShape(e)}}});this.add(t),this._proxyDrag(t),t.on("dragstart",(t=>{t.cancelBubble=!0})),t.on("dragmove",(t=>{t.cancelBubble=!0})),t.on("dragend",(t=>{t.cancelBubble=!0})),this.on("dragmove",(t=>{this.update()}))}_handleMouseDown(t){this._movingAnchorName=t.target.name().split(" ")[0];var e=this._getNodeRect(),i=e.width,r=e.height,a=Math.sqrt(Math.pow(i,2)+Math.pow(r,2));this.sin=Math.abs(r/a),this.cos=Math.abs(i/a),"undefined"!=typeof window&&(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;var n=t.target.getAbsolutePosition(),s=t.target.getStage().getPointerPosition();this._anchorDragOffset={x:s.x-n.x,y:s.y-n.y},this._fire("transformstart",{evt:t.evt,target:this.getNode()}),this._nodes.forEach((e=>{e._fire("transformstart",{evt:t.evt,target:e})}))}_handleMouseMove(t){var e,r,a,n=this.findOne("."+this._movingAnchorName),s=n.getStage();s.setPointersPositions(t);const o=s.getPointerPosition();let h={x:o.x-this._anchorDragOffset.x,y:o.y-this._anchorDragOffset.y};const l=n.getAbsolutePosition();this.anchorDragBoundFunc()&&(h=this.anchorDragBoundFunc()(l,h,t)),n.setAbsolutePosition(h);const d=n.getAbsolutePosition();if(l.x!==d.x||l.y!==d.y)if("rotater"!==this._movingAnchorName){var c=this.keepRatio()||t.shiftKey,g=this.centeredScaling()||t.altKey;if("top-left"===this._movingAnchorName){if(c){var u=g?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-right").x(),y:this.findOne(".bottom-right").y()};a=Math.sqrt(Math.pow(u.x-n.x(),2)+Math.pow(u.y-n.y(),2));var f=this.findOne(".top-left").x()>u.x?-1:1,p=this.findOne(".top-left").y()>u.y?-1:1;e=a*this.cos*f,r=a*this.sin*p,this.findOne(".top-left").x(u.x-e),this.findOne(".top-left").y(u.y-r)}}else if("top-center"===this._movingAnchorName)this.findOne(".top-left").y(n.y());else if("top-right"===this._movingAnchorName){if(c){u=g?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()};a=Math.sqrt(Math.pow(n.x()-u.x,2)+Math.pow(u.y-n.y(),2));f=this.findOne(".top-right").x()u.y?-1:1;e=a*this.cos*f,r=a*this.sin*p,this.findOne(".top-right").x(u.x+e),this.findOne(".top-right").y(u.y-r)}var v=n.position();this.findOne(".top-left").y(v.y),this.findOne(".bottom-right").x(v.x)}else if("middle-left"===this._movingAnchorName)this.findOne(".top-left").x(n.x());else if("middle-right"===this._movingAnchorName)this.findOne(".bottom-right").x(n.x());else if("bottom-left"===this._movingAnchorName){if(c){u=g?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()};a=Math.sqrt(Math.pow(u.x-n.x(),2)+Math.pow(n.y()-u.y,2));f=u.x{e._fire("transformend",{evt:t,target:e})})),this._movingAnchorName=null}}_fitNodesInto(t,e){var r=this._getNodeRect();if(g._inRange(t.width,2*-this.padding()-1,1))return void this.update();if(g._inRange(t.height,2*-this.padding()-1,1))return void this.update();const n=this.flipEnabled();var s=new a;if(s.rotate(i.getAngle(this.rotation())),this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("left")>=0){const e=s.point({x:2*-this.padding(),y:0});if(t.x+=e.x,t.y+=e.y,t.width+=2*this.padding(),this._movingAnchorName=this._movingAnchorName.replace("left","right"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,!n)return void this.update()}else if(this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("right")>=0){const e=s.point({x:2*this.padding(),y:0});if(this._movingAnchorName=this._movingAnchorName.replace("right","left"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.width+=2*this.padding(),!n)return void this.update()}if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("top")>=0){const e=s.point({x:0,y:2*-this.padding()});if(t.x+=e.x,t.y+=e.y,this._movingAnchorName=this._movingAnchorName.replace("top","bottom"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding(),!n)return void this.update()}else if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("bottom")>=0){const e=s.point({x:0,y:2*this.padding()});if(this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding(),!n)return void this.update()}if(this.boundBoxFunc()){const e=this.boundBoxFunc()(r,t);e?t=e:g.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const o=1e7,h=new a;h.translate(r.x,r.y),h.rotate(r.rotation),h.scale(r.width/o,r.height/o);const l=new a;l.translate(t.x,t.y),l.rotate(t.rotation),l.scale(t.width/o,t.height/o);const d=l.multiply(h.invert());this._nodes.forEach((t=>{var i;const r=t.getParent().getAbsoluteTransform(),n=t.getTransform().copy();n.translate(t.offsetX(),t.offsetY());const s=new a;s.multiply(r.copy().invert()).multiply(d).multiply(r).multiply(n);const o=s.decompose();t.setAttrs(o),this._fire("transform",{evt:e,target:t}),t._fire("transform",{evt:e,target:t}),null===(i=t.getLayer())||void 0===i||i.batchDraw()})),this.rotation(g._getRotation(t.rotation)),this._resetTransformCache(),this.update(),this.getLayer().batchDraw()}forceUpdate(){this._resetTransformCache(),this.update()}_batchChangeChild(t,e){this.findOne(t).setAttrs(e)}update(){var t,e=this._getNodeRect();this.rotation(g._getRotation(e.rotation));var i=e.width,r=e.height,a=this.enabledAnchors(),n=this.resizeEnabled(),s=this.padding(),o=this.anchorSize();this.find("._anchor").forEach((t=>{t.setAttrs({width:o,height:o,offsetX:o/2,offsetY:o/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})})),this._batchChangeChild(".top-left",{x:0,y:0,offsetX:o/2+s,offsetY:o/2+s,visible:n&&a.indexOf("top-left")>=0}),this._batchChangeChild(".top-center",{x:i/2,y:0,offsetY:o/2+s,visible:n&&a.indexOf("top-center")>=0}),this._batchChangeChild(".top-right",{x:i,y:0,offsetX:o/2-s,offsetY:o/2+s,visible:n&&a.indexOf("top-right")>=0}),this._batchChangeChild(".middle-left",{x:0,y:r/2,offsetX:o/2+s,visible:n&&a.indexOf("middle-left")>=0}),this._batchChangeChild(".middle-right",{x:i,y:r/2,offsetX:o/2-s,visible:n&&a.indexOf("middle-right")>=0}),this._batchChangeChild(".bottom-left",{x:0,y:r,offsetX:o/2+s,offsetY:o/2-s,visible:n&&a.indexOf("bottom-left")>=0}),this._batchChangeChild(".bottom-center",{x:i/2,y:r,offsetY:o/2-s,visible:n&&a.indexOf("bottom-center")>=0}),this._batchChangeChild(".bottom-right",{x:i,y:r,offsetX:o/2-s,offsetY:o/2-s,visible:n&&a.indexOf("bottom-right")>=0}),this._batchChangeChild(".rotater",{x:i/2,y:-this.rotateAnchorOffset()*g._sign(r)-s,visible:this.rotateEnabled()}),this._batchChangeChild(".back",{width:i,height:r,visible:this.borderEnabled(),stroke:this.borderStroke(),strokeWidth:this.borderStrokeWidth(),dash:this.borderDash(),x:0,y:0}),null===(t=this.getLayer())||void 0===t||t.batchDraw()}isTransforming(){return this._transforming}stopTransform(){if(this._transforming){this._removeEvents();var t=this.findOne("."+this._movingAnchorName);t&&t.stopDrag()}}destroy(){return this.getStage()&&this._cursorChange&&this.getStage().content&&(this.getStage().content.style.cursor=""),Xt.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}toObject(){return V.prototype.toObject.call(this)}clone(t){return V.prototype.clone.call(this,t)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}}ai.prototype.className="Transformer",r(ai),w.addGetterSetter(ai,"enabledAnchors",ei,(function(t){return t instanceof Array||g.warn("enabledAnchors value should be an array"),t instanceof Array&&t.forEach((function(t){-1===ei.indexOf(t)&&g.warn("Unknown anchor name: "+t+". Available names are: "+ei.join(", "))})),t||[]})),w.addGetterSetter(ai,"flipEnabled",!0,x()),w.addGetterSetter(ai,"resizeEnabled",!0),w.addGetterSetter(ai,"anchorSize",10,p()),w.addGetterSetter(ai,"rotateEnabled",!0),w.addGetterSetter(ai,"rotationSnaps",[]),w.addGetterSetter(ai,"rotateAnchorOffset",50,p()),w.addGetterSetter(ai,"rotationSnapTolerance",5,p()),w.addGetterSetter(ai,"borderEnabled",!0),w.addGetterSetter(ai,"anchorStroke","rgb(0, 161, 255)"),w.addGetterSetter(ai,"anchorStrokeWidth",1,p()),w.addGetterSetter(ai,"anchorFill","white"),w.addGetterSetter(ai,"anchorCornerRadius",0,p()),w.addGetterSetter(ai,"borderStroke","rgb(0, 161, 255)"),w.addGetterSetter(ai,"borderStrokeWidth",1,p()),w.addGetterSetter(ai,"borderDash"),w.addGetterSetter(ai,"keepRatio",!0),w.addGetterSetter(ai,"centeredScaling",!1),w.addGetterSetter(ai,"ignoreStroke",!1),w.addGetterSetter(ai,"padding",0,p()),w.addGetterSetter(ai,"node"),w.addGetterSetter(ai,"nodes"),w.addGetterSetter(ai,"boundBoxFunc"),w.addGetterSetter(ai,"anchorDragBoundFunc"),w.addGetterSetter(ai,"shouldOverdrawWholeArea",!1),w.addGetterSetter(ai,"useSingleNodeRotation",!0),w.backCompat(ai,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});class ni extends Bt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.radius(),0,i.getAngle(this.angle()),this.clockwise()),t.lineTo(0,0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}function si(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}ni.prototype.className="Wedge",ni.prototype._centroid=!0,ni.prototype._attrsAffectingSize=["radius"],r(ni),w.addGetterSetter(ni,"radius",0,p()),w.addGetterSetter(ni,"angle",0,p()),w.addGetterSetter(ni,"clockwise",!1),w.backCompat(ni,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});var oi=[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],hi=[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];w.addGetterSetter(V,"blurRadius",0,p(),w.afterSetFilter);w.addGetterSetter(V,"brightness",0,p(),w.afterSetFilter);w.addGetterSetter(V,"contrast",0,p(),w.afterSetFilter);function li(t,e,i,r,a){var n=i-e,s=a-r;return 0===n?r+s/2:0===s?r:s*((t-e)/n)+r}w.addGetterSetter(V,"embossStrength",.5,p(),w.afterSetFilter),w.addGetterSetter(V,"embossWhiteLevel",.5,p(),w.afterSetFilter),w.addGetterSetter(V,"embossDirection","top-left",null,w.afterSetFilter),w.addGetterSetter(V,"embossBlend",!1,null,w.afterSetFilter);w.addGetterSetter(V,"enhance",0,p(),w.afterSetFilter);w.addGetterSetter(V,"hue",0,p(),w.afterSetFilter),w.addGetterSetter(V,"saturation",0,p(),w.afterSetFilter),w.addGetterSetter(V,"luminance",0,p(),w.afterSetFilter);w.addGetterSetter(V,"hue",0,p(),w.afterSetFilter),w.addGetterSetter(V,"saturation",0,p(),w.afterSetFilter),w.addGetterSetter(V,"value",0,p(),w.afterSetFilter);function di(t,e,i){var r=4*(i*t.width+e),a=[];return a.push(t.data[r++],t.data[r++],t.data[r++],t.data[r++]),a}function ci(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2))}w.addGetterSetter(V,"kaleidoscopePower",2,p(),w.afterSetFilter),w.addGetterSetter(V,"kaleidoscopeAngle",0,p(),w.afterSetFilter);w.addGetterSetter(V,"threshold",0,p(),w.afterSetFilter);w.addGetterSetter(V,"noise",.2,p(),w.afterSetFilter);w.addGetterSetter(V,"pixelSize",8,p(),w.afterSetFilter);w.addGetterSetter(V,"levels",.5,p(),w.afterSetFilter);w.addGetterSetter(V,"red",0,(function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)})),w.addGetterSetter(V,"green",0,(function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)})),w.addGetterSetter(V,"blue",0,f,w.afterSetFilter);w.addGetterSetter(V,"red",0,(function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)})),w.addGetterSetter(V,"green",0,(function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)})),w.addGetterSetter(V,"blue",0,f,w.afterSetFilter),w.addGetterSetter(V,"alpha",1,(function(t){return this._filterUpToDate=!1,t>1?1:t<0?0:t}));w.addGetterSetter(V,"threshold",.5,p(),w.afterSetFilter);return $t.Util._assign($t,{Arc:te,Arrow:ue,Circle:fe,Ellipse:pe,Image:ve,Label:we,Tag:Ce,Line:re,Path:ge,Rect:Pe,RegularPolygon:ke,Ring:Ae,Sprite:Me,Star:Ge,Text:Xe,TextPath:Ve,Transformer:ai,Wedge:ni,Filters:{Blur:function(t){var e=Math.round(this.blurRadius());e>0&&function(t,e){var i,r,a,n,s,o,h,l,d,c,g,u,f,p,v,m,_,y,x,b,S,w,C,P,k=t.data,T=t.width,A=t.height,M=e+e+1,G=T-1,R=A-1,E=e+1,D=E*(E+1)/2,L=new si,O=null,I=L,F=null,N=null,B=oi[e],H=hi[e];for(a=1;a>H,0!==C?(C=255/C,k[o]=(l*B>>H)*C,k[o+1]=(d*B>>H)*C,k[o+2]=(c*B>>H)*C):k[o]=k[o+1]=k[o+2]=0,l-=u,d-=f,c-=p,g-=v,u-=F.r,f-=F.g,p-=F.b,v-=F.a,n=h+((n=i+e+1)>H,C>0?(C=255/C,k[n]=(l*B>>H)*C,k[n+1]=(d*B>>H)*C,k[n+2]=(c*B>>H)*C):k[n]=k[n+1]=k[n+2]=0,l-=u,d-=f,c-=p,g-=v,u-=F.r,f-=F.g,p-=F.b,v-=F.a,n=i+((n=r+E)255?255:n,s=(s*=255)<0?0:s>255?255:s,o=(o*=255)<0?0:o>255?255:o,r[e]=n,r[e+1]=s,r[e+2]=o},Emboss:function(t){var e=10*this.embossStrength(),i=255*this.embossWhiteLevel(),r=this.embossDirection(),a=this.embossBlend(),n=0,s=0,o=t.data,h=t.width,l=t.height,d=4*h,c=l;switch(r){case"top-left":n=-1,s=-1;break;case"top":n=-1,s=0;break;case"top-right":n=-1,s=1;break;case"right":n=0,s=1;break;case"bottom-right":n=1,s=1;break;case"bottom":n=1,s=0;break;case"bottom-left":n=1,s=-1;break;case"left":n=0,s=-1;break;default:g.error("Unknown emboss direction: "+r)}do{var u=(c-1)*d,f=n;c+f<1&&(f=0),c+f>l&&(f=0);var p=(c-1+f)*h*4,v=h;do{var m=u+4*(v-1),_=s;v+_<1&&(_=0),v+_>h&&(_=0);var y=p+4*(v-1+_),x=o[m]-o[y],b=o[m+1]-o[y+1],S=o[m+2]-o[y+2],w=x,C=w>0?w:-w;if((b>0?b:-b)>C&&(w=b),(S>0?S:-S)>C&&(w=S),w*=e,a){var P=o[m]+w,k=o[m+1]+w,T=o[m+2]+w;o[m]=P>255?255:P<0?0:P,o[m+1]=k>255?255:k<0?0:k,o[m+2]=T>255?255:T<0?0:T}else{var A=i-w;A<0?A=0:A>255&&(A=255),o[m]=o[m+1]=o[m+2]=A}}while(--v)}while(--c)},Enhance:function(t){var e,i,r,a,n=t.data,s=n.length,o=n[0],h=o,l=n[1],d=l,c=n[2],g=c,u=this.enhance();if(0!==u){for(a=0;ah&&(h=e),(i=n[a+1])d&&(d=i),(r=n[a+2])g&&(g=r);var f,p,v,m,_,y,x,b,S;for(h===o&&(h=255,o=0),d===l&&(d=255,l=0),g===c&&(g=255,c=0),u>0?(p=h+u*(255-h),v=o-u*(o-0),_=d+u*(255-d),y=l-u*(l-0),b=g+u*(255-g),S=c-u*(c-0)):(p=h+u*(h-(f=.5*(h+o))),v=o+u*(o-f),_=d+u*(d-(m=.5*(d+l))),y=l+u*(l-m),b=g+u*(g-(x=.5*(g+c))),S=c+u*(c-x)),a=0;am?s:m;var _,y,x,b,S=d,w=l,C=360/w*Math.PI/180;for(y=0;yd&&(x=y,b=0,S=-1),i=0;iy?h:y;var x,b,S,w=g,C=c,P=i.polarRotation||0;for(a=0;a=0&&u=0&&f=0&&u=0&&f=1020?255:0}return s}(e=function(t,e,i){for(var r=[1,1,1,1,0,1,1,1,1],a=Math.round(Math.sqrt(r.length)),n=Math.floor(a/2),s=[],o=0;o=0&&u=0&&f=m))for(i=d;i=_||(a+=b[(r=4*(m*i+e))+0],n+=b[r+1],s+=b[r+2],o+=b[r+3],p+=1);for(a/=p,n/=p,s/=p,o/=p,e=h;e=m))for(i=d;i=_||(b[(r=4*(m*i+e))+0]=a,b[r+1]=n,b[r+2]=s,b[r+3]=o)}},Posterize:function(t){var e,i=Math.round(254*this.levels())+1,r=t.data,a=r.length,n=255/i;for(e=0;e127&&(h=255-h),l>127&&(l=255-l),d>127&&(d=255-d),e[o]=h,e[o+1]=l,e[o+2]=d}while(--s)}while(--a)},Threshold:function(t){var e,i=255*this.threshold(),r=t.data,a=r.length;for(e=0;e { + let z: number; + let sum: number; + let correctedT: number; + + /*if (xs.length >= tValues.length) { + throw new Error('too high n bezier'); + }*/ + + const n = 20; + + z = t / 2; + sum = 0; + for (let i = 0; i < n; i++) { + correctedT = z * tValues[n][i] + z; + sum += cValues[n][i] * BFunc(xs, ys, correctedT); + } + return z * sum; +}; + +export const getQuadraticArcLength = ( + xs: number[], + ys: number[], + t: number +) => { + if (t === undefined) { + t = 1; + } + const ax = xs[0] - 2 * xs[1] + xs[2]; + const ay = ys[0] - 2 * ys[1] + ys[2]; + const bx = 2 * xs[1] - 2 * xs[0]; + const by = 2 * ys[1] - 2 * ys[0]; + + const A = 4 * (ax * ax + ay * ay); + const B = 4 * (ax * bx + ay * by); + const C = bx * bx + by * by; + + if (A === 0) { + return ( + t * Math.sqrt(Math.pow(xs[2] - xs[0], 2) + Math.pow(ys[2] - ys[0], 2)) + ); + } + const b = B / (2 * A); + const c = C / A; + const u = t + b; + const k = c - b * b; + + const uuk = u * u + k > 0 ? Math.sqrt(u * u + k) : 0; + const bbk = b * b + k > 0 ? Math.sqrt(b * b + k) : 0; + const term = + b + Math.sqrt(b * b + k) !== 0 + ? k * Math.log(Math.abs((u + uuk) / (b + bbk))) + : 0; + + return (Math.sqrt(A) / 2) * (u * uuk - b * bbk + term); +}; + +function BFunc(xs: number[], ys: number[], t: number) { + const xbase = getDerivative(1, t, xs); + const ybase = getDerivative(1, t, ys); + const combined = xbase * xbase + ybase * ybase; + return Math.sqrt(combined); +} + +/** + * Compute the curve derivative (hodograph) at t. + */ +const getDerivative = (derivative: number, t: number, vs: number[]): number => { + // the derivative of any 't'-less function is zero. + const n = vs.length - 1; + let _vs; + let value; + + if (n === 0) { + return 0; + } + + // direct values? compute! + if (derivative === 0) { + value = 0; + for (let k = 0; k <= n; k++) { + value += + binomialCoefficients[n][k] * + Math.pow(1 - t, n - k) * + Math.pow(t, k) * + vs[k]; + } + return value; + } else { + // Still some derivative? go down one order, then try + // for the lower order curve's. + _vs = new Array(n); + for (let k = 0; k < n; k++) { + _vs[k] = n * (vs[k + 1] - vs[k]); + } + return getDerivative(derivative - 1, t, _vs); + } +}; + +export const t2length = ( + length: number, + totalLength: number, + func: (t: number) => number +): number => { + let error = 1; + let t = length / totalLength; + let step = (length - func(t)) / totalLength; + + let numIterations = 0; + while (error > 0.001) { + const increasedTLength = func(t + step); + const increasedTError = Math.abs(length - increasedTLength) / totalLength; + if (increasedTError < error) { + error = increasedTError; + t += step; + } else { + const decreasedTLength = func(t - step); + const decreasedTError = Math.abs(length - decreasedTLength) / totalLength; + if (decreasedTError < error) { + error = decreasedTError; + t -= step; + } else { + step /= 2; + } + } + + numIterations++; + if (numIterations > 500) { + break; + } + } + + return t; +}; diff --git a/src/shapes/Path.ts b/src/shapes/Path.ts index 2295d26f..55497c2b 100644 --- a/src/shapes/Path.ts +++ b/src/shapes/Path.ts @@ -7,7 +7,7 @@ import { getCubicArcLength, getQuadraticArcLength, t2length, -} from './bezier/functions'; +} from '../BezierFunctions'; export interface PathConfig extends ShapeConfig { data?: string; diff --git a/src/shapes/TextPath.ts b/src/shapes/TextPath.ts index 7b7b51ea..60dd7eb6 100644 --- a/src/shapes/TextPath.ts +++ b/src/shapes/TextPath.ts @@ -117,6 +117,12 @@ export class TextPath extends Shape { return null; } + const totalLength = this.pathLength; + // -1px for rounding of the last symbol + if (length - 1 > totalLength) { + return null; + } + return Path.getPointAtLengthOfDataArray(length, this.dataArray); } diff --git a/src/shapes/bezier/functions.ts b/src/shapes/bezier/functions.ts deleted file mode 100644 index f1bc5889..00000000 --- a/src/shapes/bezier/functions.ts +++ /dev/null @@ -1,140 +0,0 @@ -// Credits: rveciana/svg-path-properties - -import { tValues, cValues, binomialCoefficients } from './values'; - -export const getCubicArcLength = (xs: number[], ys: number[], t: number) => { - let z: number; - let sum: number; - let correctedT: number; - - /*if (xs.length >= tValues.length) { - throw new Error('too high n bezier'); - }*/ - - const n = 20; - - z = t / 2; - sum = 0; - for (let i = 0; i < n; i++) { - correctedT = z * tValues[n][i] + z; - sum += cValues[n][i] * BFunc(xs, ys, correctedT); - } - return z * sum; -}; - - -export const getQuadraticArcLength = ( - xs: number[], - ys: number[], - t: number -) => { - if (t === undefined) { - t = 1; - } - const ax = xs[0] - 2 * xs[1] + xs[2]; - const ay = ys[0] - 2 * ys[1] + ys[2]; - const bx = 2 * xs[1] - 2 * xs[0]; - const by = 2 * ys[1] - 2 * ys[0]; - - const A = 4 * (ax * ax + ay * ay); - const B = 4 * (ax * bx + ay * by); - const C = bx * bx + by * by; - - if (A === 0) { - return ( - t * Math.sqrt(Math.pow(xs[2] - xs[0], 2) + Math.pow(ys[2] - ys[0], 2)) - ); - } - const b = B / (2 * A); - const c = C / A; - const u = t + b; - const k = c - b * b; - - const uuk = u * u + k > 0 ? Math.sqrt(u * u + k) : 0; - const bbk = b * b + k > 0 ? Math.sqrt(b * b + k) : 0; - const term = - b + Math.sqrt(b * b + k) !== 0 - ? k * Math.log(Math.abs((u + uuk) / (b + bbk))) - : 0; - - return (Math.sqrt(A) / 2) * (u * uuk - b * bbk + term); -}; - - -function BFunc(xs: number[], ys: number[], t: number) { - const xbase = getDerivative(1, t, xs); - const ybase = getDerivative(1, t, ys); - const combined = xbase * xbase + ybase * ybase; - return Math.sqrt(combined); -} - -/** - * Compute the curve derivative (hodograph) at t. - */ -const getDerivative = (derivative: number, t: number, vs: number[]): number => { - // the derivative of any 't'-less function is zero. - const n = vs.length - 1; - let _vs; - let value; - - if (n === 0) { - return 0; - } - - // direct values? compute! - if (derivative === 0) { - value = 0; - for (let k = 0; k <= n; k++) { - value += - binomialCoefficients[n][k] * - Math.pow(1 - t, n - k) * - Math.pow(t, k) * - vs[k]; - } - return value; - } else { - // Still some derivative? go down one order, then try - // for the lower order curve's. - _vs = new Array(n); - for (let k = 0; k < n; k++) { - _vs[k] = n * (vs[k + 1] - vs[k]); - } - return getDerivative(derivative - 1, t, _vs); - } -}; - -export const t2length = ( - length: number, - totalLength: number, - func: (t: number) => number -): number => { - let error = 1; - let t = length / totalLength; - let step = (length - func(t)) / totalLength; - - let numIterations = 0; - while (error > 0.001) { - const increasedTLength = func(t + step); - const increasedTError = Math.abs(length - increasedTLength) / totalLength; - if (increasedTError < error) { - error = increasedTError; - t += step; - } else { - const decreasedTLength = func(t - step); - const decreasedTError = Math.abs(length - decreasedTLength) / totalLength; - if (decreasedTError < error) { - error = decreasedTError; - t -= step; - } else { - step /= 2; - } - } - - numIterations++; - if (numIterations > 500) { - break; - } - } - - return t; -}; diff --git a/test/unit/Arrow-test.ts b/test/unit/Arrow-test.ts index 1816d329..7bc2c149 100644 --- a/test/unit/Arrow-test.ts +++ b/test/unit/Arrow-test.ts @@ -227,6 +227,6 @@ describe('Arrow', function () { arrow.cache(); layer.draw(); - cloneAndCompareLayer(layer, 200); + cloneAndCompareLayer(layer, 255, 50); }); }); diff --git a/test/unit/Node-cache-test.ts b/test/unit/Node-cache-test.ts index 0bf73907..1fbf759c 100644 --- a/test/unit/Node-cache-test.ts +++ b/test/unit/Node-cache-test.ts @@ -488,12 +488,12 @@ describe('Caching', function () { context.stroke(); context.restore(); - compareLayerAndCanvas(layer, canvas, 150); + compareLayerAndCanvas(layer, canvas, 210, 20); // recache group.cache(); layer.draw(); - compareLayerAndCanvas(layer, canvas, 150); + compareLayerAndCanvas(layer, canvas, 210, 20); }); it('cache group with rectangle and text', function () { diff --git a/test/unit/Star-test.ts b/test/unit/Star-test.ts index d31236da..52cc3fd9 100644 --- a/test/unit/Star-test.ts +++ b/test/unit/Star-test.ts @@ -138,8 +138,9 @@ describe('Star', function () { }); layer.add(star); - star.cache(); + stage.add(layer); + star.cache(); assert.deepEqual(star.getSelfRect(), { x: -50, diff --git a/test/unit/TextPath-test.ts b/test/unit/TextPath-test.ts index 33e1d440..bd322a13 100644 --- a/test/unit/TextPath-test.ts +++ b/test/unit/TextPath-test.ts @@ -77,10 +77,10 @@ describe('TextPath', function () { layer.draw(); - var trace = layer.getContext().getTrace(); + var trace = layer.getContext().getTrace(true); assert.equal( trace, - 'clearRect(0,0,578,200);clearRect(0,0,578,200);save();transform(1,0,0,1,0,0);beginPath();moveTo(10,10);lineTo(60,10);lineWidth=1;strokeStyle=red;stroke();restore();save();transform(1,0,0,1,0,0);font=normal normal 24px Arial;textBaseline=middle;textAlign=left;save();save();translate(10,10);rotate(0);fillStyle=orange;fillText(T,0,0);restore();save();translate(24.66,10);rotate(0);fillStyle=orange;fillText(h,0,0);restore();save();translate(38.008,10);rotate(0);fillStyle=orange;fillText(e,0,0);restore();save();translate(51.355,10);rotate(0);fillStyle=orange;fillText( ,0,0);restore();restore();restore();' + 'clearRect();clearRect();save();transform();beginPath();moveTo();lineTo();lineWidth;strokeStyle;stroke();restore();save();transform();font;textBaseline;textAlign;save();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();restore();restore();' ); }); @@ -761,7 +761,7 @@ describe('TextPath', function () { assert.equal(rect.height, 0, 'check height'); }); - it.only('dashes on line', function () { + it('dashes on line', function () { var stage = addStage(); stage.draggable(true); @@ -773,9 +773,8 @@ describe('TextPath', function () { fontSize: 16, scaleX: 0.8, scaleY: 0.8, - text: '----------------', + text: '_______________', data: 'M 0,10 L 300 10', - textDecoration: 'underline', y: 5, }); layer.add(textpath); @@ -791,18 +790,10 @@ describe('TextPath', function () { var rect = textpath.getClientRect(); // just different results in different envs - if (isBrowser) { - assert.equal(Math.round(rect.height), 331, 'check height'); - } else { - assert.equal(Math.round(rect.height), 333, 'check height'); - } - - textpath.text(''); - rect = textpath.getClientRect(); - assert.equal(rect.height, 0, 'check height'); + assert.equal(Math.round(rect.height), 13, 'check height'); }); - it.only('check bad calculations', function () { + it('check bad calculations', function () { var stage = addStage(); stage.draggable(true); @@ -814,11 +805,19 @@ describe('TextPath', function () { fontSize: 16, scaleX: 0.8, scaleY: 0.8, - textDecoration: 'underline', - text: '__________________________________________________________________________________________________________________________________________________________________________________________________________________', + text: '___________________________________________________________________________________________________________________________________________________________________________________________________________________', data: 'M 109.98618090452261 138.6656132223618 C 135.94577638190955 48.80547503140701 149.91187876884422 79.79800957914573 151.40954773869348 117.23973382537689 S 123.00811620603017 419.616741991206 122.84170854271358 460.0538041771357 S 134.33883542713568 469.8304329459799 149.98115577889448 464.33898005653265 S 245.4620163316583 411.5856081972362 257.1105527638191 412.91686950376885 S 239.31850251256282 474.434854428392 249.96859296482413 475.76611573492465 S 338.21036306532665 425.67526648869347 348.5276381909548 424.3440051821608 S 337.3640408291457 461.1772344535176 338.5288944723618 464.33898005653265 S 346.8778454773869 466.79295744346734 358.52638190954775 451.4834524183417', }); layer.add(textpath); + + layer.draw(); + + var trace = layer.getContext().getTrace(true); + assert.equal( + trace, + 'restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();save();translate();rotate();fillStyle;fillText();restore();restore();restore();' + ); + var path = new Konva.Path({ stroke: 'red', scaleX: 0.8, @@ -881,10 +880,11 @@ describe('TextPath', function () { layer.draw(); var rect = textpath.getClientRect(); - assert.equal(Math.round(rect.width), 299); if (isBrowser) { + assert.equal(Math.round(rect.width), 299); assert.equal(Math.round(rect.height), 171); } else { + assert.equal(Math.round(rect.width), 298); assert.equal(Math.round(rect.height), 170); } });