flow.module.js 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880
  1. /**
  2. * https://github.com/sunag/flow
  3. */
  4. function __flow__addCSS( css ) {
  5. try {
  6. const style = document.createElement( 'style' );
  7. style.setAttribute( 'type', 'text/css' );
  8. style.innerHTML = css;
  9. document.head.appendChild( style );
  10. } catch ( e ) {}
  11. }
  12. __flow__addCSS( `f-element .ti { vertical-align: middle; font-size: 17px; display: inline-block; margin-right: 5px;}f-element f-disconnect .ti { font-size: 20px; margin-top: -6px; margin-left: 2px;}@keyframes f-animation-open { 0% { transform: scale(.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; }}f-canvas,f-canvas canvas.background,f-canvas canvas.frontground { position: absolute; top: 0; left: 0; margin: 0; padding: 0; width: 100%; height: 100%; -webkit-touch-callout: none; transition: opacity .17s;}f-canvas { cursor: grab;}f-canvas canvas.frontground { z-index: 10;}body.dragging *:not(.drag) { pointer-events: none !important;}f-canvas.grabbing * { cursor: grabbing; user-select: none;}f-canvas canvas.background,f-canvas canvas.frontground { position: fixed; overflow: hidden;}f-canvas canvas.frontground { pointer-events: none;}::-webkit-scrollbar { width: 6px; height: 6px;}::-webkit-scrollbar-thumb:hover{ background: #014fc5;}::-webkit-scrollbar-track { background: #363636;}::-webkit-scrollbar-thumb { background-color: #666666; border-radius: 8px; border: 0;}f-canvas f-content { left: 0; top: 0;}f-canvas f-content,f-canvas f-area { position: absolute; display: block;}f-canvas canvas.map { position: absolute; top: 10px; right: 10px; z-index: 50; backdrop-filter: blur( 10px ); background-color: rgba( 45, 45, 48, .8 );}f-node { position: absolute; margin: 0; padding: 0; user-select: none; width: 320px; z-index: 1; cursor: auto; filter: drop-shadow(0 0 10px #00000061); backdrop-filter: blur(4px);}f-node.selected { z-index: 2;}f-canvas.focusing canvas.background,f-canvas.focusing f-node:not(.selected),f-canvas.focusing f-element f-disconnect:not(.selected) { opacity: 0; pointer-events: none;}.dragging f-canvas f-element f-disconnect { opacity: 0;}.dragging.node f-canvas.focusing canvas.background,.dragging.node f-canvas.focusing f-node:not(.selected) { opacity: .5;}f-node.selected,f-canvas.dragging-rio f-node:hover,f-canvas.dragging-lio f-node:hover { filter: drop-shadow(0 0 10px #00000061) drop-shadow(0 0 8px #4444dd);}f-node.closed f-element:not(:first-child) { display: none;}f-node.center { top: 50%; left: 50%; transform: translate( -50%, -50% );}f-node.top-right { top: 0; right: 0;}f-node.top-center { top: 0; left: 50%; transform: translateX( -50% );}f-node.top-left { top: 0; left: 0;}f-node { transition: filter 0.2s ease, opacity 0.12s ease;}f-node { animation: .2s f-animation-open 1 alternate ease-out;}f-tips,f-drop,f-menu,f-menu input,f-menu button,f-element,f-element input,f-element select,f-element button,f-element textarea { font-family: 'Open Sans', sans-serif; font-size: 12px; text-transform: initial; line-height: normal; color: #eeeeee; outline: solid 0px #000; margin: 0; padding: 0; border: 0; user-select: none; -webkit-tap-highlight-color: transparent; transition: background 0.2s ease, filter 0.2s ease;}f-node.resizable { display: grid; width: auto !important;}f-node.resizable f-element:last-child { resize: both; overflow: auto; min-width: 100px;}f-element input:read-only { color: #666;}f-element input,f-element textarea { text-transform: initial;}f-element input { transition: background 0.1s ease;}f-element input,f-element select,f-element button,f-element textarea { background-color: #232324d1;}f-element { position: relative; width: calc( 100% - 14px ); background: rgba(45, 45, 48, 0.95); pointer-events: auto; border-bottom: 2px solid #232323; display: flex; padding-left: 7px; padding-right: 7px; padding-top: 2px; padding-bottom: 2px;}f-element:after,f-element:before { transition: opacity .17s; opacity: 0; content: '';}f-element[tooltip]:hover:after,f-element[tooltip]:focus-within:after { font-size: 14px !important; display: flex; justify-content: center; position: fixed; margin-left: -7px; width: calc( 100% ); background: #1d1d1de8; border: 1px solid #444444a1; border-radius: 6px; color: #dadada; content: attr( tooltip ); margin-top: -41px; font-size: 16px; padding-top: 3px; padding-bottom: 3px; z-index: 10; opacity: 1; backdrop-filter: blur(4px); white-space: nowrap; overflow: hidden; text-shadow: 1px 1px 0px #0007;}f-element[tooltip]:hover:before,f-element[tooltip]:focus-within:before { border: solid; border-color: #1d1d1de8 transparent; border-width: 12px 6px 0 6px; left: calc( 50% - 6px ); bottom: 30px; position: absolute; opacity: 1; z-index: 11;}f-element[error] { background-color: #ff0000;}f-element[error]:hover:after,f-element[error]:focus-within:after { border: none; background-color: #ff0000bb; filter: drop-shadow( 2px 2px 5px #000 ); color: #fff;}f-element[error]:hover:before,f-element[error]:focus-within:before { border-color: #ff0000bb transparent;}f-element { height: 24px;}f-element input { margin-top: 2px; margin-bottom: 2px; box-shadow: inset 0px 1px 1px rgb(0 0 0 / 20%), 0px 1px 0px rgb(255 255 255 / 5%); margin-left: 2px; margin-right: 2px; width: 100%; padding-left: 4px; padding-right: 4px; line-height: 100%;}f-element f-string:has( i[type=icon] ) input { padding-right: 23px;}f-element input.number { cursor: col-resize;}f-element input:focus[type='text'], f-element input:focus[type='range'], f-element input:focus[type='color'] { background: rgba( 0, 0, 0, 0.6 ); outline: solid 1px rgba( 0, 80, 200, 0.98 );}f-element input[type='color'] { appearance: none; padding: 0; margin-left: 2px; margin-right: 2px; height: calc( 100% - 4px ); margin-top: 2px; border: none;}f-element input[type='color']::-webkit-color-swatch-wrapper { padding: 2px;}f-element input[type='color']::-webkit-color-swatch { border: none; cursor: alias;}f-element input[type='range'] { appearance: none; width: 100%; overflow: hidden; padding: 0; cursor: ew-resize;}f-element input[type='range']::-webkit-slider-runnable-track { appearance: none; height: 10px; color: #13bba4; margin: 0;}f-element input[type='range']::-webkit-slider-thumb { appearance: none; width: 0; background: #434343; box-shadow: -500px 0 0 500px rgba( 0, 120, 255, 0.98 ); border-radius: 50%; border: 0 !important;}f-element input[type='range']::-webkit-slider-runnable-track { margin-left: -4px; margin-right: -5px;}f-element input[type='checkbox'] { appearance: none; cursor: pointer;}f-element input[type='checkbox'].toggle { height: 20px; width: 45px; border-radius: 16px; display: inline-block; position: relative; margin: 0; margin-top: 2px; background: linear-gradient( 0deg, #292929 0%, #0a0a0ac2 100% ); transition: all 0.2s ease;}f-element input[type='checkbox'].toggle:after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: white; box-shadow: 0 1px 2px rgba(44, 44, 44, 0.2); transition: all 0.2s cubic-bezier(0.5, 0.1, 0.75, 1.35);}f-element input[type='checkbox'].toggle:checked { background: linear-gradient( 0deg, #0177fb 0%, #0177fb 100% );}f-element input[type='checkbox'].toggle:checked:after { transform: translatex(25px);}f-element.auto-height { display: table;}f-element textarea { width: calc( 100% - 18px ); padding-top: 1px; padding-bottom: 3px; padding-left: 4px; padding-right: 8px; margin-top: 2px; margin-left: 2px; height: calc( 100% - 8px ); max-height: 300px; border-radius: 2px; resize: none; box-shadow: inset 0px 1px 1px rgb(0 0 0 / 20%), 0px 1px 0px rgb(255 255 255 / 5%);}f-element.auto-height textarea { resize: auto;}f-element select { width: 100%; margin-top: 2px; margin-bottom: 2px; margin-left: 2px; margin-right: 2px; cursor: pointer; box-shadow: inset 0px 1px 1px rgb(0 0 0 / 20%), 0px 1px 0px rgb(255 255 255 / 5%);}f-element f-toolbar { position: absolute; top: 0; height: 100%; align-content: space-around; margin-top: auto; margin-bottom: auto; margin-left: 6px; margin-right: 6px; font-size: 18px; line-height: 18px; display: inline-flex; justify-content: flex-end; left: 2px;}f-element f-toolbar button { opacity: .7; cursor: pointer; font-size: 14px; width: unset; height: unset; border-radius: unset; border: unset; outline: 0; background-color: unset; box-shadow: unset; padding-right: 0; padding-left: 0; margin-left: 0; margin-right: 0;}f-element f-toolbar button span { padding-right: 5px;}f-element f-toolbar button:hover,f-element f-toolbar button:active { opacity: 1; border: 0; background-color: unset;}f-element input.range-value { width: 60px; text-align: center;}f-menu.context button,f-element button { width: 100%; height: calc( 100% - 4px ); margin-left: 2px; margin-right: 2px; margin-top: 3px; border-radius: 3px; cursor: pointer;}f-element button { box-shadow: inset 1px 1px 1px 0 rgb(255 255 255 / 17%), inset -2px -2px 2px 0 rgb(0 0 0 / 26%);}f-element button:hover { color: #fff; background-color: #2a2a2a;}f-element button:active { border: 1px solid rgba( 0, 120, 255, 0.98 );}f-element f-inputs,f-element f-subinputs { display: flex; justify-content: flex-end; width: 100%;}f-element f-inputs { left: 100px; top: 50%; transform: translateY( -50% ); position: absolute; width: calc( 100% - 106px ); height: calc( 100% - 4px );}f-element.inputs-disable f-inputs { filter: grayscale(100%); opacity: .5;}f-element.inputs-disable f-inputs input { pointer-events: none;}f-element f-label,f-element span { margin: auto; text-shadow: 1px 1px 0px #0007;}f-element f-label { padding-left: 4px; white-space: nowrap; position: absolute; top: 50%; transform: translateY( -50% ); width: calc( 100% - 20px );}f-element.right f-label { text-align: right;}f-element.center f-label { text-align: center;}f-element f-label i { font-size: 18px; margin-right: 4px; vertical-align: sub; margin-right: 0;}f-element f-label.center { width: 100%; text-align: center; display: block;}f-element.title { height: 29px; background-color: #3a3a3ab0; background-color: #3b3b43ed; cursor: all-scroll; border-top-left-radius: 6px; border-top-right-radius: 6px;}f-element:last-child { border-bottom-left-radius: 6px; border-bottom-right-radius: 6px;}f-element.blue { background-color: #014fc5;}f-element.red { background-color: #bd0b0b;}f-element.green { background-color: #148d05;}f-element.yellow { background-color: #d6b100;}f-element.title.left { text-align: left; display: inline-grid; justify-content: start;}f-element.title f-title { text-align: center; font-size: 15px; position: absolute; top: 50%; transform: translateY( -50% ); width: calc( 100% - 14px );}f-element.title > i { font-size: 21px; position: absolute; right: 8px; top: 50%; transform: translateY( -50% ); opacity: .7;}f-element.title f-toolbar i { font-size: 22px; display: contents; right: unset; left: unset;}f-element.title.left span { text-align: left;}f-element f-io { border: 2px solid #dadada; width: 7px; height: 7px; position: absolute; background: #242427; border-radius: 8px; float: left; left: -7px; top: calc( 50% - 5px ); cursor: alias; box-shadow: 0 0 3px 2px #0000005e; z-index: 1;}f-element f-io.connect,f-canvas.dragging-rio f-element:hover f-io.lio,f-canvas.dragging-lio f-element:hover f-io.rio { zoom: 1.4;}f-node.io-connect f-io:not(.connect) { border: 2px solid #dadada !important; zoom: 1 !important;}f-element f-io.rio { float: right; right: -7px; left: unset;}f-element f-disconnect { position: absolute; left: -35px; top: 50%; font-size: 22px; transform: translateY( -50% ); filter: drop-shadow(0 0 5px #000); text-shadow: 0px 0px 5px black; cursor: pointer; transition: all .2s;}f-element.input-right f-disconnect { right: -35px; left: unset;}f-element f-disconnect:hover { color: #ff3300;}f-element textarea::-webkit-scrollbar { width: 6px;}f-element textarea::-webkit-scrollbar-track { background: #111; } f-element textarea::-webkit-scrollbar-thumb { background: #0177fb; }f-element textarea::-webkit-scrollbar-thumb:hover { background: #1187ff; }f-element.small { height: 18px;}f-element.large { height: 36px;}f-canvas.dragging-lio f-node:not(.io-connect) f-element.rio:hover,f-canvas.dragging-rio f-node:not(.io-connect) f-element.lio:hover,f-element.select { background-color: rgba(61, 70, 82, 0.98);}f-element.invalid > f-io { zoom: 1 !important;}f-element.invalid::after,.zoom f-element.no-zoom::after { font-size: 14px !important; display: flex; justify-content: center; align-items:center; margin: auto; position: absolute; width: 100%; height: 100%; background: #bd0b0b77; vertical-align: middle; color: #fff; content: 'Incompatible!'; opacity: .95; backdrop-filter: grayscale(100%); white-space: nowrap; overflow: hidden; left: 0; top: 0; text-transform: initial;}.zoom f-element.no-zoom::after { background: #0b3fbd77; content: 'Incompatible with zoom!';}f-treeview { width: 100%; background-color: #232324d1; border-radius: 2px; overflow-y: auto; overflow-x: hidden; margin-top: 2px; margin-left: 2px; height: calc( 100% - 6px ); box-shadow: inset 0px 1px 1px rgb(0 0 0 / 20%), 0px 1px 0px rgb(255 255 255 / 5%);}f-treeview f-treeview-node { position: relative; margin-top: 1px; min-height: 24px;}f-treeview f-treeview-node f-treeview-children { position: relative; display: none; padding-left: 16px;}f-treeview f-treeview-node input[type='checkbox'] { position: absolute; width: 100%; height: 24px; margin-top: 0px; background: none; box-shadow: none; cursor: default; width: calc( 100% + 100px ); padding-top: 3px; margin-left: -100px;}f-treeview f-treeview-node input[type='checkbox']:checked ~ f-treeview-children { display: block;}f-treeview f-arrow { border: solid #999; border-width: 0 2px 2px 0; display: inline-block; padding: 3px; position: absolute; right: 10px; margin-top: 8px; transform: rotate( -45deg ); transition: all 0.1s ease; pointer-events: none;}f-treeview f-treeview-node input[type='checkbox']:checked ~ f-arrow { margin-top: 7px; transform: rotate( 45deg );}f-treeview f-treeview-label { display: flex; align-content: center; width: 100%; height: 22px; background: none; box-shadow: none; cursor: default; width: calc( 100% + 100px ); padding-top: 3px; margin-left: -100px; padding-left: 105px; border-bottom: 1px solid #333; pointer-events: none; z-index: 1;}f-treeview f-treeview-node input[type='checkbox']:hover { background: #2c2c2f;}f-treeview f-treeview-node:has( f-arrow ) > input[type='checkbox'] { background: #2c2c2f;}f-treeview f-treeview-node:has( f-arrow ) > input[type='checkbox']:hover { background: #333339;}f-treeview f-treeview-label { color: #aaa;}f-treeview f-treeview-label spam { margin-top: 1px;}f-treeview f-treeview-label i { color: #ccc; transition: color 0.1s ease; margin-top: 1px;}f-treeview f-treeview-node { position: relative; display: flex; flex-direction: column;}f-treeview f-treeview-node input[type='checkbox']:hover ~ f-treeview-label { color: #eee;}f-treeview f-treeview-node input[type='checkbox']:hover ~ f-treeview-label i { color: #fff;}f-menu.context f-item f-node { position: relative; display: block; width: calc( 100% - 6px ) !important; margin: 3px; animation: unset;}f-treeview f-treeview-node.selected > input[type='checkbox'] { background-color: #014fc5;}f-treeview f-treeview-node.selected > f-treeview-label,f-treeview f-treeview-node.selected > f-treeview-label i { color: #fff;}f-treeview f-treeview-node.selected > input[type='checkbox']:hover { background-color: #06f;}f-string { display: contents;}f-string f-buttons { position: absolute; top: 50%; right: 1px; transform: translateY( -50% );}f-string f-buttons i { color: #999; padding-left: 4px; padding-right: 4px; padding-bottom: 1px; margin-right: 1px; cursor: pointer; background: #252526eb; height: 100%; padding-top: 1px; margin-right: 1px !important;}f-string i[type=icon] { color: #999; position: absolute; right: 8px; top: calc( 50% - 8px ); margin-right: 5px;}f-inputs f-string i[type=icon] { right: 0;}f-string f-buttons i:hover { color: #eeeeee;}f-string input:focus ~ f-string { opacity: .9;}f-string:hover input::placeholder { color: #999;}f-string f-treeview { position: absolute; max-height: 200px; height: 200px; background-color: #000; z-index: 10;}f-drop { width: 100%; height: 100%; position: sticky; left: 0; top: 0; background: #02358417; text-align: center; justify-content: center; align-items: center; display: flex; box-shadow: inset 0 0 20px 10px #464ace17; pointer-events: none; transition: all .07s; opacity: 0; visibility: hidden;}f-drop.visible { visibility: unset; opacity: unset; transition: all .23s;}f-drop span { opacity: .5; font-size: 40px; text-shadow: 0px 0px 5px #000; font-weight: bold;}f-tooltip { pointer-events: none;}f-tooltip { position: absolute; left: 0; top: 0; background: rgba(0,0,0,.8); backdrop-filter: blur(4px); font-size: 14px; padding: 7px; left: 50%; border-radius: 10px; transform: translateX(-50%); visibility: hidden; pointer-events: none; opacity: 0; transition: all 0.3s ease; z-index: 150; white-space: nowrap;}f-menu.context,f-menu.search { position: absolute;}f-menu.context { width: 170px; z-index: 110;}f-menu.search { bottom: 85px; left: 50%; transform: translateX(-50%); z-index: 10; width: 300px;}f-menu.context f-list { display: block; margin: 0; background: #171717e6; font-size: 12px; border-radius: 6px; backdrop-filter: blur(6px); border: 1px solid #7e7e7e45; box-shadow: 3px 3px 6px rgba(0,0,0,.2); transition: opacity 0.2s ease, transform 0.1s ease;}f-menu.search f-list { margin: 0 6px 0 6px; display: flex; flex-direction: column-reverse; margin-bottom: 5px;}f-menu.context.hidden { visibility: hidden; opacity: 0;}f-menu.context f-item,f-menu.search f-item { display: block; position: relative; margin: 0; padding: 0; white-space: nowrap;}f-menu.search f-item { opacity: 0;}f-menu.context f-item.submenu::after { content: ""; position: absolute; right: 6px; top: 50%; -webkit-transform: translateY( -50% ); transform: translateY( -50% ); border: 5px solid transparent; border-left-color: #808080;}f-menu.context f-item:hover > f-menu,f-menu.context f-item.active > f-menu { visibility: unset; transform: unset; opacity: unset;}f-menu.context f-menu { top: 0px; left: calc( 100% - 4px );}f-menu.context f-item button,f-menu.search f-item button { overflow: visible; display: block; width: calc( 100% - 6px ); text-align: left; cursor: pointer; white-space: nowrap; padding: 6px 8px; border-radius: 3px; background: rgba(45, 45, 48, 0.95); border: 0; color: #ddd; margin: 3px; text-shadow: 1px 1px 0px #0007;}f-menu.context f-item button i,f-menu.search f-item button i { float: left; font-size: 20px; margin-top: -1px; margin-right: 3px;}f-menu.context f-item button i { height: 18px; margin-top: -2px;}f-menu.context f-item button span,f-menu.search f-item button span { margin-left: 4px;}f-menu.context f-item:hover > button,f-menu.search f-item:hover > button,f-menu.search f-item.active > button { color: #fff; background-color: rgba(61, 70, 82, 0.98);}f-menu.search f-item:hover,f-menu.search f-item.active { opacity: 1 !important;}f-menu.context f-item button:active { outline: solid 1px rgba( 0, 80, 200, 0.98 );}f-menu.context f-item f-tooltip { margin-left: 85px; top: -50px;}f-menu.search f-item { display: none;}f-menu.search f-item:nth-child(1) { opacity: 1; display: unset;}f-menu.search f-item:nth-child(2) { opacity: .8; display: unset;}f-menu.search f-item:nth-child(3) { opacity: .6; display: unset;}f-menu.search f-item:nth-child(4) { opacity: .4; display: unset;}f-menu.search f-item button { border-radius: 14px;}f-tips { right: 10px; top: 10px; position: absolute; z-index: 100; pointer-events: none; display: flex; flex-direction: column;}f-tips f-tip { width: 450px; font-size: 13px; border-radius: 6px; text-align: center; display: block; height: auto; color: #ffffffe0; margin: 4px; padding: 4px; background: #17171794; border: 1px solid #7e7e7e38; line-height: 100%; backdrop-filter: blur(6px); transition: all 0.2s ease; text-transform: initial; opacity: 0;}f-tips f-tip:nth-child(1) { opacity: 1;}f-tips f-tip:nth-child(2) { opacity: .75;}f-tips f-tip:nth-child(3) { opacity: .25;}f-tips f-tip:nth-child(4) { opacity: .1;}f-tips f-tip.error { background: #b900005e;}f-menu.search input { width: calc( 100% - 28px ); height: 41px; position: absolute; z-index: 10; border-radius: 20px; padding-left: 14px; padding-right: 14px; font-size: 15px; background-color: #17171794; border: 1px solid #7e7e7e45; backdrop-filter: blur(6px); box-shadow: 3px 3px 6px rgb(0 0 0 / 20%); text-transform: initial;}f-menu.circle { position: absolute; z-index: 100;}f-menu.circle.top { top: 40px;}f-menu.circle.left { left: 40px;}f-menu.circle.bottom { bottom: 40px;}f-menu.circle.right { right: 40px;}f-menu.circle f-item { align-content: space-around; margin-right: 20px;}f-menu.circle f-item button { width: 46px; height: 46px; font-size: 22px; background: #17171794; border-radius: 50%; backdrop-filter: blur(6px); border: 1px solid #7e7e7e45; line-height: 100%; cursor: pointer; box-shadow: 3px 3px 6px rgba(0,0,0,.2); margin-bottom: 20px;}f-menu.circle f-item f-tooltip { margin-top: -60px;}f-menu.circle.top f-item f-tooltip { margin-top: 50px;}.f-rounded f-node f-element,.f-rounded f-node f-element.title.left { border-radius: 10px 5px 10px 5px;}.f-rounded f-node f-element input, .f-rounded f-node f-element select,.f-rounded f-node f-element button,.f-rounded f-node f-element textarea,.f-rounded f-node f-element input[type='checkbox'].toggle,.f-rounded f-node f-element input[type='checkbox'].toggle:after { border-radius: 20px 10px;}.f-rounded f-node f-element input { padding-left: 7px; padding-right: 7px;}.f-rounded f-menu.context,.f-rounded f-menu.context f-item button { border-radius: 20px 10px;}@media (hover: hover) and (pointer: fine) { f-node:not(.selected):hover { filter: drop-shadow(0 0 6px #66666630); } f-element f-toolbar { visibility: hidden; opacity: 0; transition: opacity 0.2s ease; } body:not(.connecting) f-node:hover > f-element f-toolbar, f-node.selected f-element f-toolbar { visibility: visible; opacity: 1; } f-element f-io:hover { zoom: 1.4; } f-menu.circle f-item button:hover { background-color: #2a2a2a; } f-menu.search input:hover, f-menu.search input:focus { background-color: #1a1a1a; filter: drop-shadow(0 0 6px #66666630); } f-menu.search input:focus { filter: drop-shadow(0 0 8px #4444dd); } f-menu.circle f-item button:hover > f-tooltip, f-menu.context f-item button:hover > f-tooltip { visibility: visible; opacity: 1; } f-menu.circle f-item button:hover > f-tooltip { margin-top: -50px; } f-menu.circle.top f-item button:hover > f-tooltip { margin-top: 60px; } f-menu.context f-item button:hover > f-tooltip { top: -30px; } f-menu.circle f-item button:focus > f-tooltip, f-menu.context f-item button:focus > f-tooltip { visibility: hidden; opacity: 0; }}@media (hover: none) and (pointer: coarse) { body.dragging f-canvas, body.connecting f-canvas { overflow: hidden !important; }}f-element.invalid > f-inputs,f-element.invalid > f-label,f-element.invalid > f-title,f-element.invalid > f-toolbar,f-element.invalid > input,f-element.invalid > select { opacity: .1 !important;}f-canvas { will-change: top, left;}f-node { will-change: transform !important;}` );
  13. const REVISION = '3';
  14. let _id = 0;
  15. class Serializer extends EventTarget {
  16. constructor() {
  17. super();
  18. this._id = _id ++;
  19. this._serializable = true;
  20. }
  21. get id() {
  22. return this._id;
  23. }
  24. setSerializable( value ) {
  25. this._serializable = value;
  26. return this;
  27. }
  28. getSerializable() {
  29. return this._serializable;
  30. }
  31. serialize( /*data*/ ) {
  32. console.warn( 'Serializer: Abstract function.' );
  33. }
  34. deserialize( /*data*/ ) {
  35. console.warn( 'Serializer: Abstract function.' );
  36. }
  37. deserializeLib( /*data, lib*/ ) {
  38. // Abstract function.
  39. }
  40. get className() {
  41. return this.constructor.name;
  42. }
  43. toJSON( data = null ) {
  44. let object = null;
  45. const id = this.id;
  46. if ( data !== null ) {
  47. const objects = data.objects;
  48. object = objects[ id ];
  49. if ( object === undefined ) {
  50. object = { objects };
  51. this.serialize( object );
  52. delete object.objects;
  53. objects[ id ] = object;
  54. }
  55. } else {
  56. object = { objects: {} };
  57. this.serialize( object );
  58. }
  59. object.id = id;
  60. object.type = this.className;
  61. return object;
  62. }
  63. }
  64. class PointerMonitor {
  65. constructor() {
  66. this.x = 0;
  67. this.y = 0;
  68. this.started = false;
  69. this._onMoveEvent = ( e ) => {
  70. const event = e.touches ? e.touches[ 0 ] : e;
  71. this.x = event.clientX;
  72. this.y = event.clientY;
  73. };
  74. }
  75. start() {
  76. if ( this.started ) return;
  77. this.started = true;
  78. window.addEventListener( 'wheel', this._onMoveEvent, true );
  79. window.addEventListener( 'mousedown', this._onMoveEvent, true );
  80. window.addEventListener( 'touchstart', this._onMoveEvent, true );
  81. window.addEventListener( 'mousemove', this._onMoveEvent, true );
  82. window.addEventListener( 'touchmove', this._onMoveEvent, true );
  83. window.addEventListener( 'dragover', this._onMoveEvent, true );
  84. return this;
  85. }
  86. }
  87. const pointer = new PointerMonitor().start();
  88. const draggableDOM = ( dom, callback = null, settings = {} ) => {
  89. settings = Object.assign( {
  90. className: 'dragging',
  91. click: false,
  92. bypass: false
  93. }, settings );
  94. let dragData = null;
  95. const { className, click, bypass } = settings;
  96. const getZoom = () => {
  97. let zoomDOM = dom;
  98. while ( zoomDOM && zoomDOM !== document ) {
  99. const zoom = zoomDOM.style.zoom;
  100. if ( zoom ) {
  101. return Number( zoom );
  102. }
  103. zoomDOM = zoomDOM.parentNode;
  104. }
  105. return 1;
  106. };
  107. const onMouseDown = ( e ) => {
  108. const event = e.touches ? e.touches[ 0 ] : e;
  109. if ( bypass === false ) e.stopImmediatePropagation();
  110. dragData = {
  111. client: { x: event.clientX, y: event.clientY },
  112. delta: { x: 0, y: 0 },
  113. start: { x: dom.offsetLeft, y: dom.offsetTop },
  114. frame: 0,
  115. isDown: true,
  116. dragging: false,
  117. isTouch: !! e.touches
  118. };
  119. if ( click === true ) {
  120. callback( dragData );
  121. dragData.frame ++;
  122. }
  123. window.addEventListener( 'mousemove', onGlobalMouseMove );
  124. window.addEventListener( 'mouseup', onGlobalMouseUp );
  125. window.addEventListener( 'touchmove', onGlobalMouseMove );
  126. window.addEventListener( 'touchend', onGlobalMouseUp );
  127. };
  128. const onGlobalMouseMove = ( e ) => {
  129. const { start, delta, client } = dragData;
  130. const event = e.touches ? e.touches[ 0 ] : e;
  131. const zoom = getZoom();
  132. delta.x = ( event.clientX - client.x ) / zoom;
  133. delta.y = ( event.clientY - client.y ) / zoom;
  134. dragData.x = start.x + delta.x;
  135. dragData.y = start.y + delta.y;
  136. if ( dragData.dragging === true ) {
  137. if ( callback !== null ) {
  138. callback( dragData );
  139. dragData.frame ++;
  140. } else {
  141. dom.style.cssText += `; left: ${ dragData.x }px; top: ${ dragData.y }px;`;
  142. }
  143. if ( bypass === false ) e.stopImmediatePropagation();
  144. } else {
  145. if ( Math.abs( delta.x ) > 2 || Math.abs( delta.y ) > 2 ) {
  146. dragData.dragging = true;
  147. dom.classList.add( 'drag' );
  148. if ( className ) document.body.classList.add( ...className.split( ' ' ) );
  149. if ( bypass === false ) e.stopImmediatePropagation();
  150. }
  151. }
  152. };
  153. const onGlobalMouseUp = ( e ) => {
  154. if ( bypass === false ) e.stopImmediatePropagation();
  155. dom.classList.remove( 'drag' );
  156. if ( className ) document.body.classList.remove( ...className.split( ' ' ) );
  157. window.removeEventListener( 'mousemove', onGlobalMouseMove );
  158. window.removeEventListener( 'mouseup', onGlobalMouseUp );
  159. window.removeEventListener( 'touchmove', onGlobalMouseMove );
  160. window.removeEventListener( 'touchend', onGlobalMouseUp );
  161. if ( callback === null ) {
  162. dom.removeEventListener( 'mousedown', onMouseDown );
  163. dom.removeEventListener( 'touchstart', onMouseDown );
  164. }
  165. dragData.dragging = false;
  166. dragData.isDown = false;
  167. if ( callback !== null ) {
  168. callback( dragData );
  169. dragData.frame ++;
  170. }
  171. };
  172. if ( dom instanceof Event ) {
  173. const e = dom;
  174. dom = e.target;
  175. onMouseDown( e );
  176. } else {
  177. dom.addEventListener( 'mousedown', onMouseDown );
  178. dom.addEventListener( 'touchstart', onMouseDown );
  179. }
  180. };
  181. const dispatchEventList = ( list, ...params ) => {
  182. for ( const callback of list ) {
  183. if ( callback( ...params ) === false ) {
  184. return false;
  185. }
  186. }
  187. return true;
  188. };
  189. const numberToPX = ( val ) => {
  190. if ( isNaN( val ) === false ) {
  191. val = `${ val }px`;
  192. }
  193. return val;
  194. };
  195. const numberToHex = ( val ) => {
  196. if ( isNaN( val ) === false ) {
  197. val = `#${ val.toString( 16 ).padStart( 6, '0' ) }`;
  198. }
  199. return val;
  200. };
  201. const rgbaToArray = ( rgba ) => {
  202. const values = rgba.substring( rgba.indexOf( '(' ) + 1, rgba.indexOf( ')' ) )
  203. .split( ',' )
  204. .map( num => parseInt( num.trim() ) );
  205. return values;
  206. };
  207. const removeDOMClass = ( dom, classList ) => {
  208. if ( classList ) classList.split( ' ' ).forEach( alignClass => dom.classList.remove( alignClass ) );
  209. };
  210. const addDOMClass = ( dom, classList ) => {
  211. if ( classList ) classList.split( ' ' ).forEach( alignClass => dom.classList.add( alignClass ) );
  212. };
  213. var Utils = /*#__PURE__*/Object.freeze({
  214. __proto__: null,
  215. pointer: pointer,
  216. draggableDOM: draggableDOM,
  217. dispatchEventList: dispatchEventList,
  218. numberToPX: numberToPX,
  219. numberToHex: numberToHex,
  220. rgbaToArray: rgbaToArray,
  221. removeDOMClass: removeDOMClass,
  222. addDOMClass: addDOMClass
  223. });
  224. class Link {
  225. constructor( inputElement = null, outputElement = null ) {
  226. this.inputElement = inputElement;
  227. this.outputElement = outputElement;
  228. }
  229. get lioElement() {
  230. if ( Link.InputDirection === 'left' ) {
  231. return this.outputElement;
  232. } else {
  233. return this.inputElement;
  234. }
  235. }
  236. get rioElement() {
  237. if ( Link.InputDirection === 'left' ) {
  238. return this.inputElement;
  239. } else {
  240. return this.outputElement;
  241. }
  242. }
  243. }
  244. //Link.InputDirection = 'right';
  245. Link.InputDirection = 'left';
  246. let selected = null;
  247. class Element extends Serializer {
  248. constructor( draggable = false ) {
  249. super();
  250. this.isElement = true;
  251. const dom = document.createElement( 'f-element' );
  252. dom.element = this;
  253. const onSelect = ( e ) => {
  254. let element = this;
  255. if ( e.changedTouches && e.changedTouches.length > 0 ) {
  256. const touch = e.changedTouches[ 0 ];
  257. let overDOM = document.elementFromPoint( touch.clientX, touch.clientY );
  258. while ( overDOM && ( ! overDOM.element || ! overDOM.element.isElement ) ) {
  259. overDOM = overDOM.parentNode;
  260. }
  261. element = overDOM ? overDOM.element : null;
  262. }
  263. const type = e.type;
  264. if ( ( type === 'mouseout' ) && selected === element ) {
  265. selected = null;
  266. } else {
  267. selected = element;
  268. }
  269. };
  270. if ( draggable === false ) {
  271. dom.ontouchstart = dom.onmousedown = ( e ) => {
  272. e.stopPropagation();
  273. };
  274. }
  275. dom.addEventListener( 'mouseup', onSelect, true );
  276. dom.addEventListener( 'mouseover', onSelect );
  277. dom.addEventListener( 'mouseout', onSelect );
  278. dom.addEventListener( 'touchmove', onSelect );
  279. dom.addEventListener( 'touchend', onSelect );
  280. this.inputs = [];
  281. this.links = [];
  282. this.dom = dom;
  283. this.lioLength = 0;
  284. this.rioLength = 0;
  285. this.events = {
  286. 'connect': [],
  287. 'connectChildren': [],
  288. 'valid': []
  289. };
  290. this.node = null;
  291. this.style = '';
  292. this.color = null;
  293. this.object = null;
  294. this.objectCallback = null;
  295. this.enabledInputs = true;
  296. this.visible = true;
  297. this.inputsDOM = dom;
  298. this.disconnectDOM = null;
  299. this.lioDOM = this._createIO( 'lio' );
  300. this.rioDOM = this._createIO( 'rio' );
  301. this.dom.classList.add( `input-${ Link.InputDirection }` );
  302. this.addEventListener( 'connect', ( ) => {
  303. dispatchEventList( this.events.connect, this );
  304. } );
  305. this.addEventListener( 'connectChildren', ( ) => {
  306. dispatchEventList( this.events.connectChildren, this );
  307. } );
  308. }
  309. setAttribute( name, value ) {
  310. this.dom.setAttribute( name, value );
  311. return this;
  312. }
  313. onValid( callback ) {
  314. this.events.valid.push( callback );
  315. return this;
  316. }
  317. onConnect( callback, childrens = false ) {
  318. this.events.connect.push( callback );
  319. if ( childrens ) {
  320. this.events.connectChildren.push( callback );
  321. }
  322. return this;
  323. }
  324. setObjectCallback( callback ) {
  325. this.objectCallback = callback;
  326. return this;
  327. }
  328. setObject( value ) {
  329. this.object = value;
  330. return this;
  331. }
  332. getObject( output = null ) {
  333. return this.objectCallback ? this.objectCallback( output ) : this.object;
  334. }
  335. setVisible( value ) {
  336. this.visible = value;
  337. this.dom.style.display = value ? '' : 'none';
  338. return this;
  339. }
  340. getVisible() {
  341. return this.visible;
  342. }
  343. setEnabledInputs( value ) {
  344. const dom = this.dom;
  345. if ( ! this.enabledInputs ) dom.classList.remove( 'inputs-disable' );
  346. if ( ! value ) dom.classList.add( 'inputs-disable' );
  347. this.enabledInputs = value;
  348. return this;
  349. }
  350. getEnabledInputs() {
  351. return this.enabledInputs;
  352. }
  353. setColor( color ) {
  354. this.dom.style[ 'background-color' ] = numberToHex( color );
  355. this.color = null;
  356. return this;
  357. }
  358. getColor() {
  359. if ( this.color === null ) {
  360. const css = window.getComputedStyle( this.dom );
  361. this.color = css.getPropertyValue( 'background-color' );
  362. }
  363. return this.color;
  364. }
  365. setStyle( style ) {
  366. const dom = this.dom;
  367. if ( this.style ) dom.classList.remove( this.style );
  368. if ( style ) dom.classList.add( style );
  369. this.style = style;
  370. this.color = null;
  371. return this;
  372. }
  373. setInput( length ) {
  374. if ( Link.InputDirection === 'left' ) {
  375. return this.setLIO( length );
  376. } else {
  377. return this.setRIO( length );
  378. }
  379. }
  380. setInputColor( color ) {
  381. if ( Link.InputDirection === 'left' ) {
  382. return this.setLIOColor( color );
  383. } else {
  384. return this.setRIOColor( color );
  385. }
  386. }
  387. setOutput( length ) {
  388. if ( Link.InputDirection === 'left' ) {
  389. return this.setRIO( length );
  390. } else {
  391. return this.setLIO( length );
  392. }
  393. }
  394. setOutputColor( color ) {
  395. if ( Link.InputDirection === 'left' ) {
  396. return this.setRIOColor( color );
  397. } else {
  398. return this.setLIOColor( color );
  399. }
  400. }
  401. get inputLength() {
  402. if ( Link.InputDirection === 'left' ) {
  403. return this.lioLength;
  404. } else {
  405. return this.rioLength;
  406. }
  407. }
  408. get outputLength() {
  409. if ( Link.InputDirection === 'left' ) {
  410. return this.rioLength;
  411. } else {
  412. return this.lioLength;
  413. }
  414. }
  415. setLIOColor( color ) {
  416. this.lioDOM.style[ 'border-color' ] = numberToHex( color );
  417. return this;
  418. }
  419. setLIO( length ) {
  420. this.lioLength = length;
  421. this.lioDOM.style.visibility = length > 0 ? '' : 'hidden';
  422. if ( length > 0 ) {
  423. this.dom.classList.add( 'lio' );
  424. this.dom.prepend( this.lioDOM );
  425. } else {
  426. this.dom.classList.remove( 'lio' );
  427. this.lioDOM.remove();
  428. }
  429. return this;
  430. }
  431. getLIOColor() {
  432. return this.lioDOM.style[ 'border-color' ];
  433. }
  434. setRIOColor( color ) {
  435. this.rioDOM.style[ 'border-color' ] = numberToHex( color );
  436. return this;
  437. }
  438. getRIOColor() {
  439. return this.rioDOM.style[ 'border-color' ];
  440. }
  441. setRIO( length ) {
  442. this.rioLength = length;
  443. this.rioDOM.style.visibility = length > 0 ? '' : 'hidden';
  444. if ( length > 0 ) {
  445. this.dom.classList.add( 'rio' );
  446. this.dom.prepend( this.rioDOM );
  447. } else {
  448. this.dom.classList.remove( 'rio' );
  449. this.rioDOM.remove();
  450. }
  451. return this;
  452. }
  453. add( input ) {
  454. this.inputs.push( input );
  455. input.element = this;
  456. this.inputsDOM.append( input.dom );
  457. return this;
  458. }
  459. setHeight( val ) {
  460. this.dom.style.height = numberToPX( val );
  461. return this;
  462. }
  463. getHeight() {
  464. return parseInt( this.dom.style.height );
  465. }
  466. connect( element = null ) {
  467. if ( this.disconnectDOM !== null ) {
  468. // remove the current input
  469. this.disconnectDOM.dispatchEvent( new Event( 'disconnect' ) );
  470. }
  471. if ( element !== null ) {
  472. element = element.baseElement || element;
  473. if ( dispatchEventList( this.events.valid, this, element, 'connect' ) === false ) {
  474. return false;
  475. }
  476. const link = new Link( this, element );
  477. this.links.push( link );
  478. if ( this.disconnectDOM === null ) {
  479. this.disconnectDOM = document.createElement( 'f-disconnect' );
  480. this.disconnectDOM.innerHTML = Element.icons.unlink ? `<i class='${ Element.icons.unlink }'></i>` : '✖';
  481. this.dom.append( this.disconnectDOM );
  482. const onDisconnect = () => {
  483. this.links = [];
  484. this.dom.removeChild( this.disconnectDOM );
  485. this.disconnectDOM.removeEventListener( 'mousedown', onClick, true );
  486. this.disconnectDOM.removeEventListener( 'touchstart', onClick, true );
  487. this.disconnectDOM.removeEventListener( 'disconnect', onDisconnect, true );
  488. element.removeEventListener( 'connect', onConnect );
  489. element.removeEventListener( 'connectChildren', onConnect );
  490. element.removeEventListener( 'nodeConnect', onConnect );
  491. element.removeEventListener( 'nodeConnectChildren', onConnect );
  492. element.removeEventListener( 'dispose', onDispose );
  493. this.disconnectDOM = null;
  494. };
  495. const onConnect = () => {
  496. this.dispatchEvent( new Event( 'connectChildren' ) );
  497. };
  498. const onDispose = () => {
  499. this.connect();
  500. };
  501. const onClick = ( e ) => {
  502. e.stopPropagation();
  503. this.connect();
  504. };
  505. this.disconnectDOM.addEventListener( 'mousedown', onClick, true );
  506. this.disconnectDOM.addEventListener( 'touchstart', onClick, true );
  507. this.disconnectDOM.addEventListener( 'disconnect', onDisconnect, true );
  508. element.addEventListener( 'connect', onConnect );
  509. element.addEventListener( 'connectChildren', onConnect );
  510. element.addEventListener( 'nodeConnect', onConnect );
  511. element.addEventListener( 'nodeConnectChildren', onConnect );
  512. element.addEventListener( 'dispose', onDispose );
  513. }
  514. }
  515. this.dispatchEvent( new Event( 'connect' ) );
  516. return true;
  517. }
  518. dispose() {
  519. this.dispatchEvent( new Event( 'dispose' ) );
  520. }
  521. getInputByProperty( property ) {
  522. for ( const input of this.inputs ) {
  523. if ( input.getProperty() === property ) {
  524. return input;
  525. }
  526. }
  527. }
  528. serialize( data ) {
  529. const inputs = [];
  530. const properties = [];
  531. const links = [];
  532. for ( const input of this.inputs ) {
  533. const id = input.toJSON( data ).id;
  534. const property = input.getProperty();
  535. inputs.push( id );
  536. if ( property !== null ) {
  537. properties.push( { property, id } );
  538. }
  539. }
  540. for ( const link of this.links ) {
  541. if ( link.inputElement !== null && link.outputElement !== null ) {
  542. links.push( link.outputElement.toJSON( data ).id );
  543. }
  544. }
  545. if ( this.inputLength > 0 ) data.inputLength = this.inputLength;
  546. if ( this.outputLength > 0 ) data.outputLength = this.outputLength;
  547. if ( inputs.length > 0 ) data.inputs = inputs;
  548. if ( properties.length > 0 ) data.properties = properties;
  549. if ( links.length > 0 ) data.links = links;
  550. if ( this.style !== '' ) {
  551. data.style = this.style;
  552. }
  553. data.height = this.getHeight();
  554. }
  555. deserialize( data ) {
  556. if ( data.inputLength !== undefined ) this.setInput( data.inputLength );
  557. if ( data.outputLength !== undefined ) this.setOutput( data.outputLength );
  558. if ( data.properties !== undefined ) {
  559. for ( const { id, property } of data.properties ) {
  560. data.objects[ id ] = this.getInputByProperty( property );
  561. }
  562. } else if ( data.inputs !== undefined ) {
  563. const inputs = this.inputs;
  564. if ( inputs.length > 0 ) {
  565. let index = 0;
  566. for ( const id of data.inputs ) {
  567. data.objects[ id ] = inputs[ index ++ ];
  568. }
  569. } else {
  570. for ( const id of data.inputs ) {
  571. this.add( data.objects[ id ] );
  572. }
  573. }
  574. }
  575. if ( data.links !== undefined ) {
  576. for ( const id of data.links ) {
  577. this.connect( data.objects[ id ] );
  578. }
  579. }
  580. if ( data.style !== undefined ) {
  581. this.setStyle( data.style );
  582. }
  583. if ( data.height !== undefined ) {
  584. this.setHeight( data.height );
  585. }
  586. }
  587. getLinkedObject( output = null ) {
  588. const linkedElement = this.getLinkedElement();
  589. return linkedElement ? linkedElement.getObject( output ) : null;
  590. }
  591. getLinkedElement() {
  592. const link = this.getLink();
  593. return link ? link.outputElement : null;
  594. }
  595. getLink() {
  596. return this.links[ 0 ];
  597. }
  598. _createIO( type ) {
  599. const { dom } = this;
  600. const ioDOM = document.createElement( 'f-io' );
  601. ioDOM.style.visibility = 'hidden';
  602. ioDOM.className = type;
  603. const onConnectEvent = ( e ) => {
  604. e.preventDefault();
  605. e.stopPropagation();
  606. selected = null;
  607. const nodeDOM = this.node.dom;
  608. nodeDOM.classList.add( 'io-connect' );
  609. ioDOM.classList.add( 'connect' );
  610. dom.classList.add( 'select' );
  611. const defaultOutput = Link.InputDirection === 'left' ? 'lio' : 'rio';
  612. const link = type === defaultOutput ? new Link( this ) : new Link( null, this );
  613. const previewLink = new Link( link.inputElement, link.outputElement );
  614. this.links.push( link );
  615. draggableDOM( e, ( data ) => {
  616. if ( previewLink.outputElement )
  617. previewLink.outputElement.dom.classList.remove( 'invalid' );
  618. if ( previewLink.inputElement )
  619. previewLink.inputElement.dom.classList.remove( 'invalid' );
  620. previewLink.inputElement = link.inputElement;
  621. previewLink.outputElement = link.outputElement;
  622. if ( type === defaultOutput ) {
  623. previewLink.outputElement = selected;
  624. } else {
  625. previewLink.inputElement = selected;
  626. }
  627. const isInvalid = previewLink.inputElement !== null && previewLink.outputElement !== null &&
  628. previewLink.inputElement.inputLength > 0 && previewLink.outputElement.outputLength > 0 &&
  629. dispatchEventList( previewLink.inputElement.events.valid, previewLink.inputElement, previewLink.outputElement, data.dragging ? 'dragging' : 'dragged' ) === false;
  630. if ( data.dragging && isInvalid ) {
  631. if ( type === defaultOutput ) {
  632. if ( previewLink.outputElement )
  633. previewLink.outputElement.dom.classList.add( 'invalid' );
  634. } else {
  635. if ( previewLink.inputElement )
  636. previewLink.inputElement.dom.classList.add( 'invalid' );
  637. }
  638. return;
  639. }
  640. if ( ! data.dragging ) {
  641. nodeDOM.classList.remove( 'io-connect' );
  642. ioDOM.classList.remove( 'connect' );
  643. dom.classList.remove( 'select' );
  644. this.links.splice( this.links.indexOf( link ), 1 );
  645. if ( selected !== null && ! isInvalid ) {
  646. link.inputElement = previewLink.inputElement;
  647. link.outputElement = previewLink.outputElement;
  648. // check if is an is circular link
  649. if ( link.outputElement.node.isCircular( link.inputElement.node ) ) {
  650. return;
  651. }
  652. //
  653. if ( link.inputElement.inputLength > 0 && link.outputElement.outputLength > 0 ) {
  654. link.inputElement.connect( link.outputElement );
  655. }
  656. }
  657. }
  658. }, { className: 'connecting' } );
  659. };
  660. ioDOM.addEventListener( 'mousedown', onConnectEvent, true );
  661. ioDOM.addEventListener( 'touchstart', onConnectEvent, true );
  662. return ioDOM;
  663. }
  664. }
  665. Element.icons = { unlink: '' };
  666. class Input extends Serializer {
  667. constructor( dom ) {
  668. super();
  669. this.dom = dom;
  670. this.element = null;
  671. this.extra = null;
  672. this.tagColor = null;
  673. this.property = null;
  674. this.events = {
  675. 'change': [],
  676. 'click': []
  677. };
  678. this.addEventListener( 'change', ( ) => {
  679. dispatchEventList( this.events.change, this );
  680. } );
  681. this.addEventListener( 'click', ( ) => {
  682. dispatchEventList( this.events.click, this );
  683. } );
  684. }
  685. setExtra( value ) {
  686. this.extra = value;
  687. return this;
  688. }
  689. getExtra() {
  690. return this.extra;
  691. }
  692. setProperty( name ) {
  693. this.property = name;
  694. return this;
  695. }
  696. getProperty() {
  697. return this.property;
  698. }
  699. setTagColor( color ) {
  700. this.tagColor = color;
  701. this.dom.style[ 'border-left' ] = `2px solid ${color}`;
  702. return this;
  703. }
  704. getTagColor() {
  705. return this.tagColor;
  706. }
  707. setToolTip( text ) {
  708. const div = document.createElement( 'f-tooltip' );
  709. div.innerText = text;
  710. this.dom.append( div );
  711. return this;
  712. }
  713. onChange( callback ) {
  714. this.events.change.push( callback );
  715. return this;
  716. }
  717. onClick( callback ) {
  718. this.events.click.push( callback );
  719. return this;
  720. }
  721. setReadOnly( value ) {
  722. this.getInput().readOnly = value;
  723. return this;
  724. }
  725. getReadOnly() {
  726. return this.getInput().readOnly;
  727. }
  728. setValue( value, dispatch = true ) {
  729. this.getInput().value = value;
  730. if ( dispatch ) this.dispatchEvent( new Event( 'change' ) );
  731. return this;
  732. }
  733. getValue() {
  734. return this.getInput().value;
  735. }
  736. getInput() {
  737. return this.dom;
  738. }
  739. serialize( data ) {
  740. data.value = this.getValue();
  741. }
  742. deserialize( data ) {
  743. this.setValue( data.value );
  744. }
  745. }
  746. Input.prototype.isInput = true;
  747. class Node extends Serializer {
  748. constructor() {
  749. super();
  750. const dom = document.createElement( 'f-node' );
  751. const onDown = () => {
  752. const canvas = this.canvas;
  753. if ( canvas !== null ) {
  754. canvas.select( this );
  755. }
  756. };
  757. dom.addEventListener( 'mousedown', onDown, true );
  758. dom.addEventListener( 'touchstart', onDown, true );
  759. this._onConnect = ( e ) => {
  760. const { target } = e;
  761. for ( const element of this.elements ) {
  762. if ( element !== target ) {
  763. element.dispatchEvent( new Event( 'nodeConnect' ) );
  764. }
  765. }
  766. };
  767. this._onConnectChildren = ( e ) => {
  768. const { target } = e;
  769. for ( const element of this.elements ) {
  770. if ( element !== target ) {
  771. element.dispatchEvent( new Event( 'nodeConnectChildren' ) );
  772. }
  773. }
  774. };
  775. this.dom = dom;
  776. this.style = '';
  777. this.canvas = null;
  778. this.resizable = false;
  779. this.serializePriority = 0;
  780. this.elements = [];
  781. this.events = {
  782. 'focus': [],
  783. 'blur': []
  784. };
  785. this.setWidth( 300 ).setPosition( 0, 0 );
  786. }
  787. get baseElement() {
  788. return this.elements[ 0 ];
  789. }
  790. setAlign( align ) {
  791. const dom = this.dom;
  792. const style = dom.style;
  793. style.left = '';
  794. style.top = '';
  795. style.animation = 'none';
  796. if ( typeof align === 'string' ) {
  797. dom.classList.add( align );
  798. } else if ( align ) {
  799. for ( const name in align ) {
  800. style[ name ] = align[ name ];
  801. }
  802. }
  803. return this;
  804. }
  805. setResizable( val ) {
  806. this.resizable = val === true;
  807. if ( this.resizable ) {
  808. this.dom.classList.add( 'resizable' );
  809. } else {
  810. this.dom.classList.remove( 'resizable' );
  811. }
  812. this.updateSize();
  813. return this;
  814. }
  815. onFocus( callback ) {
  816. this.events.focus.push( callback );
  817. return this;
  818. }
  819. onBlur( callback ) {
  820. this.events.blur.push( callback );
  821. return this;
  822. }
  823. setStyle( style ) {
  824. const dom = this.dom;
  825. if ( this.style ) dom.classList.remove( this.style );
  826. if ( style ) dom.classList.add( style );
  827. this.style = style;
  828. return this;
  829. }
  830. setPosition( x, y ) {
  831. const dom = this.dom;
  832. dom.style.left = numberToPX( x );
  833. dom.style.top = numberToPX( y );
  834. return this;
  835. }
  836. getPosition() {
  837. const dom = this.dom;
  838. return {
  839. x: parseInt( dom.style.left ),
  840. y: parseInt( dom.style.top )
  841. };
  842. }
  843. setWidth( val ) {
  844. this.dom.style.width = numberToPX( val );
  845. this.updateSize();
  846. return this;
  847. }
  848. getWidth() {
  849. return parseInt( this.dom.style.width );
  850. }
  851. getHeight() {
  852. return this.dom.offsetHeight;
  853. }
  854. getBound() {
  855. const { x, y } = this.getPosition();
  856. const { width, height } = this.dom.getBoundingClientRect();
  857. return { x, y, width, height };
  858. }
  859. add( element ) {
  860. this.elements.push( element );
  861. element.node = this;
  862. element.addEventListener( 'connect', this._onConnect );
  863. element.addEventListener( 'connectChildren', this._onConnectChildren );
  864. this.dom.append( element.dom );
  865. this.updateSize();
  866. return this;
  867. }
  868. remove( element ) {
  869. this.elements.splice( this.elements.indexOf( element ), 1 );
  870. element.node = null;
  871. element.removeEventListener( 'connect', this._onConnect );
  872. element.removeEventListener( 'connectChildren', this._onConnectChildren );
  873. this.dom.removeChild( element.dom );
  874. this.updateSize();
  875. return this;
  876. }
  877. dispose() {
  878. const canvas = this.canvas;
  879. if ( canvas !== null ) canvas.remove( this );
  880. for ( const element of this.elements ) {
  881. element.dispose();
  882. }
  883. this.dispatchEvent( new Event( 'dispose' ) );
  884. }
  885. isCircular( node ) {
  886. if ( node === this ) return true;
  887. const links = this.getLinks();
  888. for ( const link of links ) {
  889. if ( link.outputElement.node.isCircular( node ) ) {
  890. return true;
  891. }
  892. }
  893. return false;
  894. }
  895. getLinks() {
  896. const links = [];
  897. for ( const element of this.elements ) {
  898. links.push( ...element.links );
  899. }
  900. return links;
  901. }
  902. getColor() {
  903. return this.elements.length > 0 ? this.elements[ 0 ].getColor() : null;
  904. }
  905. updateSize() {
  906. for ( const element of this.elements ) {
  907. element.dom.style.width = '';
  908. }
  909. if ( this.resizable === true ) {
  910. const element = this.elements[ this.elements.length - 1 ];
  911. if ( element !== undefined ) {
  912. element.dom.style.width = this.dom.style.width;
  913. }
  914. }
  915. }
  916. serialize( data ) {
  917. const { x, y } = this.getPosition();
  918. const elements = [];
  919. for ( const element of this.elements ) {
  920. elements.push( element.toJSON( data ).id );
  921. }
  922. data.x = x;
  923. data.y = y;
  924. data.width = this.getWidth();
  925. data.elements = elements;
  926. data.autoResize = this.resizable;
  927. if ( this.style !== '' ) {
  928. data.style = this.style;
  929. }
  930. }
  931. deserialize( data ) {
  932. this.setPosition( data.x, data.y );
  933. this.setWidth( data.width );
  934. this.setResizable( data.autoResize );
  935. if ( data.style !== undefined ) {
  936. this.setStyle( data.style );
  937. }
  938. const elements = this.elements;
  939. if ( elements.length > 0 ) {
  940. let index = 0;
  941. for ( const id of data.elements ) {
  942. data.objects[ id ] = elements[ index ++ ];
  943. }
  944. } else {
  945. for ( const id of data.elements ) {
  946. this.add( data.objects[ id ] );
  947. }
  948. }
  949. }
  950. }
  951. Node.prototype.isNode = true;
  952. class DraggableElement extends Element {
  953. constructor( draggable = true ) {
  954. super( true );
  955. this.draggable = draggable;
  956. const onDrag = ( e ) => {
  957. e.preventDefault();
  958. if ( this.draggable === true ) {
  959. draggableDOM( this.node.dom, null, { className: 'dragging node' } );
  960. }
  961. };
  962. const { dom } = this;
  963. dom.addEventListener( 'mousedown', onDrag, true );
  964. dom.addEventListener( 'touchstart', onDrag, true );
  965. }
  966. }
  967. class TitleElement extends DraggableElement {
  968. constructor( title, draggable = true ) {
  969. super( draggable );
  970. const { dom } = this;
  971. dom.classList.add( 'title' );
  972. const dbClick = () => {
  973. this.node.canvas.focusSelected = ! this.node.canvas.focusSelected;
  974. };
  975. dom.addEventListener( 'dblclick', dbClick );
  976. const titleDOM = document.createElement( 'f-title' );
  977. titleDOM.innerText = title;
  978. const iconDOM = document.createElement( 'i' );
  979. const toolbarDOM = document.createElement( 'f-toolbar' );
  980. this.buttons = [];
  981. this.titleDOM = titleDOM;
  982. this.iconDOM = iconDOM;
  983. this.toolbarDOM = toolbarDOM;
  984. dom.append( titleDOM );
  985. dom.append( iconDOM );
  986. dom.append( toolbarDOM );
  987. }
  988. setIcon( value ) {
  989. this.iconDOM.className = value;
  990. return this;
  991. }
  992. getIcon() {
  993. return this.iconDOM.className;
  994. }
  995. setTitle( value ) {
  996. this.titleDOM.innerText = value;
  997. return this;
  998. }
  999. getTitle() {
  1000. return this.titleDOM.innerText;
  1001. }
  1002. addButton( button ) {
  1003. this.buttons.push( button );
  1004. this.toolbarDOM.append( button.dom );
  1005. return this;
  1006. }
  1007. serialize( data ) {
  1008. super.serialize( data );
  1009. const title = this.getTitle();
  1010. const icon = this.getIcon();
  1011. data.title = title;
  1012. if ( icon !== '' ) {
  1013. data.icon = icon;
  1014. }
  1015. }
  1016. deserialize( data ) {
  1017. super.deserialize( data );
  1018. this.setTitle( data.title );
  1019. if ( data.icon !== undefined ) {
  1020. this.setIcon( data.icon );
  1021. }
  1022. }
  1023. }
  1024. const drawLine = ( p1x, p1y, p2x, p2y, invert, size, colorA, ctx, colorB = null ) => {
  1025. const dx = p2x - p1x;
  1026. const dy = p2y - p1y;
  1027. const offset = Math.sqrt( ( dx * dx ) + ( dy * dy ) ) * ( invert ? - .3 : .3 );
  1028. ctx.beginPath();
  1029. ctx.moveTo( p1x, p1y );
  1030. ctx.bezierCurveTo(
  1031. p1x + offset, p1y,
  1032. p2x - offset, p2y,
  1033. p2x, p2y
  1034. );
  1035. if ( colorB !== null && colorA !== colorB ) {
  1036. const gradient = ctx.createLinearGradient( p1x, p1y, p2x, p2y );
  1037. gradient.addColorStop( 0, colorA );
  1038. gradient.addColorStop( 1, colorB );
  1039. ctx.strokeStyle = gradient;
  1040. } else {
  1041. ctx.strokeStyle = colorA;
  1042. }
  1043. ctx.lineWidth = size;
  1044. ctx.stroke();
  1045. };
  1046. const colors = [
  1047. '#ff4444',
  1048. '#44ff44',
  1049. '#4444ff'
  1050. ];
  1051. const dropNode = new Node().add( new TitleElement( 'File' ) ).setWidth( 250 );
  1052. class Canvas extends Serializer {
  1053. constructor() {
  1054. super();
  1055. const dom = document.createElement( 'f-canvas' );
  1056. const contentDOM = document.createElement( 'f-content' );
  1057. const areaDOM = document.createElement( 'f-area' );
  1058. const dropDOM = document.createElement( 'f-drop' );
  1059. const canvas = document.createElement( 'canvas' );
  1060. const frontCanvas = document.createElement( 'canvas' );
  1061. const mapCanvas = document.createElement( 'canvas' );
  1062. const context = canvas.getContext( '2d' );
  1063. const frontContext = frontCanvas.getContext( '2d' );
  1064. const mapContext = mapCanvas.getContext( '2d' );
  1065. this.dom = dom;
  1066. this.contentDOM = contentDOM;
  1067. this.areaDOM = areaDOM;
  1068. this.dropDOM = dropDOM;
  1069. this.canvas = canvas;
  1070. this.frontCanvas = frontCanvas;
  1071. this.mapCanvas = mapCanvas;
  1072. this.context = context;
  1073. this.frontContext = frontContext;
  1074. this.mapContext = mapContext;
  1075. this.clientX = 0;
  1076. this.clientY = 0;
  1077. this.relativeClientX = 0;
  1078. this.relativeClientY = 0;
  1079. this.nodes = [];
  1080. this.selected = null;
  1081. this.updating = false;
  1082. this.droppedItems = [];
  1083. this.events = {
  1084. 'drop': []
  1085. };
  1086. this._scrollLeft = 0;
  1087. this._scrollTop = 0;
  1088. this._zoom = 1;
  1089. this._width = 0;
  1090. this._height = 0;
  1091. this._focusSelected = false;
  1092. this._mapInfo = {
  1093. scale: 1,
  1094. screen: {}
  1095. };
  1096. canvas.className = 'background';
  1097. frontCanvas.className = 'frontground';
  1098. mapCanvas.className = 'map';
  1099. dropDOM.innerHTML = '<span>drop your file</span>';
  1100. dom.append( dropDOM );
  1101. dom.append( canvas );
  1102. dom.append( frontCanvas );
  1103. dom.append( contentDOM );
  1104. dom.append( areaDOM );
  1105. dom.append( mapCanvas );
  1106. const zoomTo = ( zoom, clientX = this.clientX, clientY = this.clientY ) => {
  1107. zoom = Math.min( Math.max( zoom, .2 ), 1 );
  1108. this.scrollLeft -= ( clientX / this.zoom ) - ( clientX / zoom );
  1109. this.scrollTop -= ( clientY / this.zoom ) - ( clientY / zoom );
  1110. this.zoom = zoom;
  1111. };
  1112. let touchData = null;
  1113. const onTouchStart = () => {
  1114. touchData = null;
  1115. };
  1116. const classInElements = ( element, className ) => {
  1117. do {
  1118. if ( element.classList ? element.classList.contains( className ) : false ) {
  1119. return true;
  1120. }
  1121. } while ( ( element = element.parentElement ) && element !== dom );
  1122. return false;
  1123. };
  1124. const onMouseZoom = ( e ) => {
  1125. if ( classInElements( e.srcElement, 'f-scroll' ) ) return;
  1126. e.preventDefault();
  1127. e.stopImmediatePropagation();
  1128. const delta = e.deltaY * .003;
  1129. zoomTo( this.zoom - delta );
  1130. };
  1131. const onTouchZoom = ( e ) => {
  1132. if ( e.touches && e.touches.length === 2 ) {
  1133. e.preventDefault();
  1134. e.stopImmediatePropagation();
  1135. const clientX = ( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;
  1136. const clientY = ( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;
  1137. const distance = Math.hypot(
  1138. e.touches[ 0 ].clientX - e.touches[ 1 ].clientX,
  1139. e.touches[ 0 ].clientY - e.touches[ 1 ].clientY
  1140. );
  1141. if ( touchData === null ) {
  1142. touchData = {
  1143. distance
  1144. };
  1145. }
  1146. const delta = ( touchData.distance - distance ) * .003;
  1147. touchData.distance = distance;
  1148. zoomTo( this.zoom - delta, clientX, clientY );
  1149. }
  1150. };
  1151. const onTouchMove = ( e ) => {
  1152. if ( e.touches && e.touches.length === 1 ) {
  1153. e.preventDefault();
  1154. e.stopImmediatePropagation();
  1155. const clientX = e.touches[ 0 ].clientX;
  1156. const clientY = e.touches[ 0 ].clientY;
  1157. if ( touchData === null ) {
  1158. const { scrollLeft, scrollTop } = this;
  1159. touchData = {
  1160. scrollLeft,
  1161. scrollTop,
  1162. clientX,
  1163. clientY
  1164. };
  1165. }
  1166. const zoom = this.zoom;
  1167. this.scrollLeft = touchData.scrollLeft + ( ( clientX - touchData.clientX ) / zoom );
  1168. this.scrollTop = touchData.scrollTop + ( ( clientY - touchData.clientY ) / zoom );
  1169. }
  1170. };
  1171. dom.addEventListener( 'wheel', onMouseZoom );
  1172. dom.addEventListener( 'touchmove', onTouchZoom );
  1173. dom.addEventListener( 'touchstart', onTouchStart );
  1174. canvas.addEventListener( 'touchmove', onTouchMove );
  1175. let dropEnterCount = 0;
  1176. const dragState = ( enter ) => {
  1177. if ( enter ) {
  1178. if ( dropEnterCount ++ === 0 ) {
  1179. this.droppedItems = [];
  1180. dropDOM.classList.add( 'visible' );
  1181. this.add( dropNode );
  1182. }
  1183. } else if ( -- dropEnterCount === 0 ) {
  1184. dropDOM.classList.remove( 'visible' );
  1185. this.remove( dropNode );
  1186. }
  1187. };
  1188. dom.addEventListener( 'dragenter', () => {
  1189. dragState( true );
  1190. } );
  1191. dom.addEventListener( 'dragleave', () => {
  1192. dragState( false );
  1193. } );
  1194. dom.addEventListener( 'dragover', ( e ) => {
  1195. e.preventDefault();
  1196. const { relativeClientX, relativeClientY } = this;
  1197. const centerNodeX = dropNode.getWidth() / 2;
  1198. dropNode.setPosition( relativeClientX - centerNodeX, relativeClientY - 20 );
  1199. } );
  1200. dom.addEventListener( 'drop', ( e ) => {
  1201. e.preventDefault();
  1202. dragState( false );
  1203. this.droppedItems = e.dataTransfer.items;
  1204. dispatchEventList( this.events.drop, this );
  1205. } );
  1206. draggableDOM( dom, ( data ) => {
  1207. const { delta, isTouch } = data;
  1208. if ( ! isTouch ) {
  1209. if ( data.scrollTop === undefined ) {
  1210. data.scrollLeft = this.scrollLeft;
  1211. data.scrollTop = this.scrollTop;
  1212. }
  1213. const zoom = this.zoom;
  1214. this.scrollLeft = data.scrollLeft + ( delta.x / zoom );
  1215. this.scrollTop = data.scrollTop + ( delta.y / zoom );
  1216. }
  1217. if ( data.dragging ) {
  1218. dom.classList.add( 'grabbing' );
  1219. } else {
  1220. dom.classList.remove( 'grabbing' );
  1221. }
  1222. }, { className: 'dragging-canvas' } );
  1223. draggableDOM( mapCanvas, ( data ) => {
  1224. const { scale, screen } = this._mapInfo;
  1225. if ( data.scrollLeft === undefined ) {
  1226. const rect = this.mapCanvas.getBoundingClientRect();
  1227. const clientMapX = data.client.x - rect.left;
  1228. const clientMapY = data.client.y - rect.top;
  1229. const overMapScreen =
  1230. clientMapX > screen.x && clientMapY > screen.y &&
  1231. clientMapX < screen.x + screen.width && clientMapY < screen.y + screen.height;
  1232. if ( overMapScreen === false ) {
  1233. const scaleX = this._mapInfo.width / this.mapCanvas.width;
  1234. let scrollLeft = - this._mapInfo.left - ( clientMapX * scaleX );
  1235. let scrollTop = - this._mapInfo.top - ( clientMapY * ( this._mapInfo.height / this.mapCanvas.height ) );
  1236. scrollLeft += ( screen.width / 2 ) / scale;
  1237. scrollTop += ( screen.height / 2 ) / scale;
  1238. this.scrollLeft = scrollLeft;
  1239. this.scrollTop = scrollTop;
  1240. }
  1241. data.scrollLeft = this.scrollLeft;
  1242. data.scrollTop = this.scrollTop;
  1243. }
  1244. this.scrollLeft = data.scrollLeft - ( data.delta.x / scale );
  1245. this.scrollTop = data.scrollTop - ( data.delta.y / scale );
  1246. }, { click: true } );
  1247. this._onMoveEvent = ( e ) => {
  1248. const event = e.touches ? e.touches[ 0 ] : e;
  1249. const { zoom, rect } = this;
  1250. this.clientX = event.clientX;
  1251. this.clientY = event.clientY;
  1252. const rectClientX = ( this.clientX - rect.left ) / zoom;
  1253. const rectClientY = ( this.clientY - rect.top ) / zoom;
  1254. this.relativeClientX = rectClientX - this.scrollLeft;
  1255. this.relativeClientY = rectClientY - this.scrollTop;
  1256. };
  1257. this._onUpdate = () => {
  1258. this.update();
  1259. };
  1260. this.start();
  1261. }
  1262. getBounds() {
  1263. const bounds = { x: Infinity, y: Infinity, width: - Infinity, height: - Infinity };
  1264. for ( const node of this.nodes ) {
  1265. const { x, y, width, height } = node.getBound();
  1266. bounds.x = Math.min( bounds.x, x );
  1267. bounds.y = Math.min( bounds.y, y );
  1268. bounds.width = Math.max( bounds.width, x + width );
  1269. bounds.height = Math.max( bounds.height, y + height );
  1270. }
  1271. bounds.x = Math.round( bounds.x );
  1272. bounds.y = Math.round( bounds.y );
  1273. bounds.width = Math.round( bounds.width );
  1274. bounds.height = Math.round( bounds.height );
  1275. return bounds;
  1276. }
  1277. get width() {
  1278. return this._width;
  1279. }
  1280. get height() {
  1281. return this._height;
  1282. }
  1283. get rect() {
  1284. return this.dom.getBoundingClientRect();
  1285. }
  1286. get zoom() {
  1287. return this._zoom;
  1288. }
  1289. set zoom( val ) {
  1290. this._zoom = val;
  1291. this.contentDOM.style.zoom = val;
  1292. val === 1 ? this.dom.classList.remove( 'zoom' ) : this.dom.classList.add( 'zoom' );
  1293. this.updateMozTransform();
  1294. }
  1295. set scrollLeft( val ) {
  1296. this._scrollLeft = val;
  1297. this.contentDOM.style.left = numberToPX( val );
  1298. this.updateMozTransform();
  1299. }
  1300. get scrollLeft() {
  1301. return this._scrollLeft;
  1302. }
  1303. set scrollTop( val ) {
  1304. this._scrollTop = val;
  1305. this.contentDOM.style.top = numberToPX( val );
  1306. this.updateMozTransform();
  1307. }
  1308. get scrollTop() {
  1309. return this._scrollTop;
  1310. }
  1311. set focusSelected( value ) {
  1312. if ( this._focusSelected === value ) return;
  1313. const classList = this.dom.classList;
  1314. this._focusSelected = value;
  1315. if ( value ) {
  1316. classList.add( 'focusing' );
  1317. } else {
  1318. classList.remove( 'focusing' );
  1319. }
  1320. }
  1321. get focusSelected() {
  1322. return this._focusSelected;
  1323. }
  1324. get useTransform() {
  1325. return navigator.userAgent.match( /firefox/i ) !== null;
  1326. }
  1327. updateMozTransform() {
  1328. if ( this.useTransform === false ) return;
  1329. this.contentDOM.style[ '-moz-transform' ] = 'scale(' + this.zoom + ')';
  1330. this.contentDOM.style[ '-moz-transform-origin' ] = '-' + this.contentDOM.style.left + ' -' + this.contentDOM.style.top;
  1331. }
  1332. onDrop( callback ) {
  1333. this.events.drop.push( callback );
  1334. return this;
  1335. }
  1336. start() {
  1337. this.updating = true;
  1338. document.addEventListener( 'wheel', this._onMoveEvent, true );
  1339. document.addEventListener( 'mousedown', this._onMoveEvent, true );
  1340. document.addEventListener( 'touchstart', this._onMoveEvent, true );
  1341. document.addEventListener( 'mousemove', this._onMoveEvent, true );
  1342. document.addEventListener( 'touchmove', this._onMoveEvent, true );
  1343. document.addEventListener( 'dragover', this._onMoveEvent, true );
  1344. requestAnimationFrame( this._onUpdate );
  1345. }
  1346. stop() {
  1347. this.updating = false;
  1348. document.removeEventListener( 'wheel', this._onMoveEvent, true );
  1349. document.removeEventListener( 'mousedown', this._onMoveEvent, true );
  1350. document.removeEventListener( 'touchstart', this._onMoveEvent, true );
  1351. document.removeEventListener( 'mousemove', this._onMoveEvent, true );
  1352. document.removeEventListener( 'touchmove', this._onMoveEvent, true );
  1353. document.removeEventListener( 'dragover', this._onMoveEvent, true );
  1354. }
  1355. add( node ) {
  1356. if ( node.canvas === this ) return;
  1357. this.nodes.push( node );
  1358. node.canvas = this;
  1359. this.contentDOM.append( node.dom );
  1360. return this;
  1361. }
  1362. remove( node ) {
  1363. if ( node === this.selected ) {
  1364. this.select();
  1365. }
  1366. this.unlink( node );
  1367. const nodes = this.nodes;
  1368. nodes.splice( nodes.indexOf( node ), 1 );
  1369. node.canvas = null;
  1370. this.contentDOM.removeChild( node.dom );
  1371. node.dispatchEvent( new Event( 'remove' ) );
  1372. return this;
  1373. }
  1374. clear() {
  1375. const nodes = this.nodes;
  1376. while ( nodes.length > 0 ) {
  1377. this.remove( nodes[ 0 ] );
  1378. }
  1379. return this;
  1380. }
  1381. unlink( node ) {
  1382. const links = this.getLinks();
  1383. for ( const link of links ) {
  1384. if ( link.inputElement && link.outputElement ) {
  1385. if ( link.inputElement.node === node ) {
  1386. link.inputElement.connect();
  1387. } else if ( link.outputElement.node === node ) {
  1388. link.inputElement.connect();
  1389. }
  1390. }
  1391. }
  1392. }
  1393. getLinks() {
  1394. const links = [];
  1395. for ( const node of this.nodes ) {
  1396. links.push( ...node.getLinks() );
  1397. }
  1398. return links;
  1399. }
  1400. centralize() {
  1401. const bounds = this.getBounds();
  1402. this.scrollLeft = ( this.canvas.width / 2 ) - ( ( - bounds.x + bounds.width ) / 2 );
  1403. this.scrollTop = ( this.canvas.height / 2 ) - ( ( - bounds.y + bounds.height ) / 2 );
  1404. return this;
  1405. }
  1406. setSize( width, height ) {
  1407. this._width = width;
  1408. this._height = height;
  1409. this.update();
  1410. return this;
  1411. }
  1412. select( node = null ) {
  1413. if ( node === this.selected ) return;
  1414. const previousNode = this.selected;
  1415. if ( previousNode !== null ) {
  1416. this.focusSelected = false;
  1417. previousNode.dom.classList.remove( 'selected' );
  1418. this.selected = null;
  1419. dispatchEventList( previousNode.events.blur, previousNode );
  1420. }
  1421. if ( node !== null ) {
  1422. node.dom.classList.add( 'selected' );
  1423. this.selected = node;
  1424. dispatchEventList( node.events.focus, node );
  1425. }
  1426. }
  1427. updateMap() {
  1428. const { nodes, mapCanvas, mapContext, scrollLeft, scrollTop, canvas, zoom, _mapInfo } = this;
  1429. const bounds = this.getBounds();
  1430. mapCanvas.width = 300;
  1431. mapCanvas.height = 200;
  1432. mapContext.clearRect( 0, 0, mapCanvas.width, mapCanvas.height );
  1433. mapContext.fillStyle = 'rgba( 0, 0, 0, 0 )';
  1434. mapContext.fillRect( 0, 0, mapCanvas.width, mapCanvas.height );
  1435. const boundsWidth = - bounds.x + bounds.width;
  1436. const boundsHeight = - bounds.y + bounds.height;
  1437. const mapScale = Math.min( mapCanvas.width / boundsWidth, mapCanvas.height / boundsHeight ) * .5;
  1438. const boundsMapWidth = boundsWidth * mapScale;
  1439. const boundsMapHeight = boundsHeight * mapScale;
  1440. const boundsOffsetX = ( mapCanvas.width / 2 ) - ( boundsMapWidth / 2 );
  1441. const boundsOffsetY = ( mapCanvas.height / 2 ) - ( boundsMapHeight / 2 );
  1442. let selectedNode = null;
  1443. for ( const node of nodes ) {
  1444. const nodeBound = node.getBound();
  1445. const nodeColor = node.getColor();
  1446. nodeBound.x += - bounds.x;
  1447. nodeBound.y += - bounds.y;
  1448. nodeBound.x *= mapScale;
  1449. nodeBound.y *= mapScale;
  1450. nodeBound.width *= mapScale;
  1451. nodeBound.height *= mapScale;
  1452. nodeBound.x += boundsOffsetX;
  1453. nodeBound.y += boundsOffsetY;
  1454. if ( node !== this.selected ) {
  1455. mapContext.fillStyle = nodeColor;
  1456. mapContext.fillRect( nodeBound.x, nodeBound.y, nodeBound.width, nodeBound.height );
  1457. } else {
  1458. selectedNode = {
  1459. nodeBound,
  1460. nodeColor
  1461. };
  1462. }
  1463. }
  1464. if ( selectedNode !== null ) {
  1465. const { nodeBound, nodeColor } = selectedNode;
  1466. mapContext.fillStyle = nodeColor;
  1467. mapContext.fillRect( nodeBound.x, nodeBound.y, nodeBound.width, nodeBound.height );
  1468. }
  1469. const screenMapX = ( - ( scrollLeft + bounds.x ) * mapScale ) + boundsOffsetX;
  1470. const screenMapY = ( - ( scrollTop + bounds.y ) * mapScale ) + boundsOffsetY;
  1471. const screenMapWidth = ( canvas.width * mapScale ) / zoom;
  1472. const screenMapHeight = ( canvas.height * mapScale ) / zoom;
  1473. mapContext.fillStyle = 'rgba( 200, 200, 200, 0.1 )';
  1474. mapContext.fillRect( screenMapX, screenMapY, screenMapWidth, screenMapHeight );
  1475. //
  1476. _mapInfo.scale = mapScale;
  1477. _mapInfo.left = ( - boundsOffsetX / mapScale ) + bounds.x;
  1478. _mapInfo.top = ( - boundsOffsetY / mapScale ) + bounds.y;
  1479. _mapInfo.width = mapCanvas.width / mapScale;
  1480. _mapInfo.height = mapCanvas.height / mapScale;
  1481. _mapInfo.screen.x = screenMapX;
  1482. _mapInfo.screen.y = screenMapY;
  1483. _mapInfo.screen.width = screenMapWidth;
  1484. _mapInfo.screen.height = screenMapHeight;
  1485. }
  1486. updateLines() {
  1487. const { dom, zoom, canvas, frontCanvas, frontContext, context, _width, _height, useTransform } = this;
  1488. const domRect = this.rect;
  1489. if ( canvas.width !== _width || canvas.height !== _height ) {
  1490. canvas.width = _width;
  1491. canvas.height = _height;
  1492. frontCanvas.width = _width;
  1493. frontCanvas.height = _height;
  1494. }
  1495. context.clearRect( 0, 0, _width, _height );
  1496. frontContext.clearRect( 0, 0, _width, _height );
  1497. //
  1498. context.globalCompositeOperation = 'lighter';
  1499. frontContext.globalCompositeOperation = 'source-over';
  1500. const links = this.getLinks();
  1501. const aPos = { x: 0, y: 0 };
  1502. const bPos = { x: 0, y: 0 };
  1503. const offsetIORadius = 10;
  1504. let dragging = '';
  1505. for ( const link of links ) {
  1506. const { lioElement, rioElement } = link;
  1507. let draggingLink = '';
  1508. let length = 0;
  1509. if ( lioElement !== null ) {
  1510. const rect = lioElement.dom.getBoundingClientRect();
  1511. length = Math.max( length, lioElement.rioLength );
  1512. aPos.x = rect.x + rect.width;
  1513. aPos.y = rect.y + ( rect.height / 2 );
  1514. if ( useTransform ) {
  1515. aPos.x /= zoom;
  1516. aPos.y /= zoom;
  1517. }
  1518. } else {
  1519. aPos.x = this.clientX;
  1520. aPos.y = this.clientY;
  1521. draggingLink = 'lio';
  1522. }
  1523. if ( rioElement !== null ) {
  1524. const rect = rioElement.dom.getBoundingClientRect();
  1525. length = Math.max( length, rioElement.lioLength );
  1526. bPos.x = rect.x;
  1527. bPos.y = rect.y + ( rect.height / 2 );
  1528. if ( useTransform ) {
  1529. bPos.x /= zoom;
  1530. bPos.y /= zoom;
  1531. }
  1532. } else {
  1533. bPos.x = this.clientX;
  1534. bPos.y = this.clientY;
  1535. draggingLink = 'rio';
  1536. }
  1537. dragging = dragging || draggingLink;
  1538. const drawContext = draggingLink ? frontContext : context;
  1539. if ( draggingLink || length === 1 ) {
  1540. let colorA = null,
  1541. colorB = null;
  1542. if ( draggingLink === 'rio' ) {
  1543. colorA = colorB = lioElement.getRIOColor();
  1544. aPos.x += offsetIORadius;
  1545. bPos.x /= zoom;
  1546. bPos.y /= zoom;
  1547. } else if ( draggingLink === 'lio' ) {
  1548. colorA = colorB = rioElement.getLIOColor();
  1549. bPos.x -= offsetIORadius;
  1550. aPos.x /= zoom;
  1551. aPos.y /= zoom;
  1552. } else {
  1553. colorA = lioElement.getRIOColor();
  1554. colorB = rioElement.getLIOColor();
  1555. }
  1556. drawLine(
  1557. aPos.x * zoom, aPos.y * zoom,
  1558. bPos.x * zoom, bPos.y * zoom,
  1559. false, 2, colorA || '#ffffff', drawContext, colorB || '#ffffff'
  1560. );
  1561. } else {
  1562. length = Math.min( length, 4 );
  1563. for ( let i = 0; i < length; i ++ ) {
  1564. const color = colors[ i ] || '#ffffff';
  1565. const marginY = 4;
  1566. const rioLength = Math.min( lioElement.rioLength, length );
  1567. const lioLength = Math.min( rioElement.lioLength, length );
  1568. const colorA = lioElement.getRIOColor() || color;
  1569. const colorB = rioElement.getLIOColor() || color;
  1570. const aCenterY = ( ( rioLength * marginY ) * .5 ) - ( marginY / 2 );
  1571. const bCenterY = ( ( lioLength * marginY ) * .5 ) - ( marginY / 2 );
  1572. const aIndex = Math.min( i, rioLength - 1 );
  1573. const bIndex = Math.min( i, lioLength - 1 );
  1574. const aPosY = ( aIndex * marginY ) - 1;
  1575. const bPosY = ( bIndex * marginY ) - 1;
  1576. drawLine(
  1577. aPos.x * zoom, ( ( aPos.y + aPosY ) - aCenterY ) * zoom,
  1578. bPos.x * zoom, ( ( bPos.y + bPosY ) - bCenterY ) * zoom,
  1579. false, 2, colorA, drawContext, colorB
  1580. );
  1581. }
  1582. }
  1583. }
  1584. context.globalCompositeOperation = 'destination-in';
  1585. context.fillRect( domRect.x, domRect.y, domRect.width, domRect.height );
  1586. if ( dragging !== '' ) {
  1587. dom.classList.add( 'dragging-' + dragging );
  1588. } else {
  1589. dom.classList.remove( 'dragging-lio' );
  1590. dom.classList.remove( 'dragging-rio' );
  1591. }
  1592. }
  1593. update() {
  1594. if ( this.updating === false ) return;
  1595. requestAnimationFrame( this._onUpdate );
  1596. this.updateLines();
  1597. this.updateMap();
  1598. }
  1599. serialize( data ) {
  1600. const nodes = [];
  1601. const serializeNodes = this.nodes.sort( ( a, b ) => a.serializePriority > b.serializePriority ? - 1 : 1 );
  1602. for ( const node of serializeNodes ) {
  1603. nodes.push( node.toJSON( data ).id );
  1604. }
  1605. data.nodes = nodes;
  1606. }
  1607. deserialize( data ) {
  1608. for ( const id of data.nodes ) {
  1609. this.add( data.objects[ id ] );
  1610. }
  1611. }
  1612. }
  1613. class Menu extends EventTarget {
  1614. constructor( className ) {
  1615. super();
  1616. const dom = document.createElement( 'f-menu' );
  1617. dom.className = className + ' bottom left hidden';
  1618. const listDOM = document.createElement( 'f-list' );
  1619. dom.append( listDOM );
  1620. this.dom = dom;
  1621. this.listDOM = listDOM;
  1622. this.visible = false;
  1623. this.align = 'bottom left';
  1624. this.subMenus = new WeakMap();
  1625. this.domButtons = new WeakMap();
  1626. this.buttons = [];
  1627. this.events = {};
  1628. }
  1629. onContext( callback ) {
  1630. this.events.context.push( callback );
  1631. return this;
  1632. }
  1633. setAlign( align ) {
  1634. const dom = this.dom;
  1635. removeDOMClass( dom, this.align );
  1636. addDOMClass( dom, align );
  1637. this.align = align;
  1638. return this;
  1639. }
  1640. getAlign() {
  1641. return this.align;
  1642. }
  1643. show() {
  1644. this.dom.classList.remove( 'hidden' );
  1645. this.visible = true;
  1646. this.dispatchEvent( new Event( 'show' ) );
  1647. return this;
  1648. }
  1649. hide() {
  1650. this.dom.classList.add( 'hidden' );
  1651. this.dispatchEvent( new Event( 'hide' ) );
  1652. this.visible = false;
  1653. }
  1654. add( button, submenu = null ) {
  1655. const liDOM = document.createElement( 'f-item' );
  1656. if ( submenu !== null ) {
  1657. liDOM.classList.add( 'submenu' );
  1658. liDOM.append( submenu.dom );
  1659. this.subMenus.set( button, submenu );
  1660. button.dom.addEventListener( 'mouseover', () => submenu.show() );
  1661. button.dom.addEventListener( 'mouseout', () => submenu.hide() );
  1662. }
  1663. liDOM.append( button.dom );
  1664. this.buttons.push( button );
  1665. this.listDOM.append( liDOM );
  1666. this.domButtons.set( button, liDOM );
  1667. return this;
  1668. }
  1669. clear() {
  1670. this.buttons = [];
  1671. this.subMenus = new WeakMap();
  1672. this.domButtons = new WeakMap();
  1673. while ( this.listDOM.firstChild ) {
  1674. this.listDOM.firstChild.remove();
  1675. }
  1676. }
  1677. }
  1678. let lastContext = null;
  1679. const onCloseLastContext = ( e ) => {
  1680. if ( lastContext && lastContext.visible === true && e.target.closest( 'f-menu.context' ) === null ) {
  1681. lastContext.hide();
  1682. }
  1683. };
  1684. document.body.addEventListener( 'mousedown', onCloseLastContext, true );
  1685. document.body.addEventListener( 'touchstart', onCloseLastContext, true );
  1686. class ContextMenu extends Menu {
  1687. constructor( target = null ) {
  1688. super( 'context' );
  1689. this.events.context = [];
  1690. this._lastButtonClick = null;
  1691. this._onButtonClick = ( e = null ) => {
  1692. const button = e ? e.target : null;
  1693. if ( this._lastButtonClick ) {
  1694. this._lastButtonClick.dom.parentElement.classList.remove( 'active' );
  1695. }
  1696. this._lastButtonClick = button;
  1697. if ( button ) {
  1698. if ( this.subMenus.has( button ) ) {
  1699. this.subMenus.get( button )._onButtonClick();
  1700. }
  1701. button.dom.parentElement.classList.add( 'active' );
  1702. }
  1703. };
  1704. this._onButtonMouseOver = ( e ) => {
  1705. const button = e.target;
  1706. if ( this.subMenus.has( button ) && this._lastButtonClick !== button ) {
  1707. this._onButtonClick();
  1708. }
  1709. };
  1710. this.addEventListener( 'context', ( ) => {
  1711. dispatchEventList( this.events.context, this );
  1712. } );
  1713. this.setTarget( target );
  1714. }
  1715. openFrom( dom ) {
  1716. const rect = dom.getBoundingClientRect();
  1717. return this.open( rect.x + ( rect.width / 2 ), rect.y + ( rect.height / 2 ) );
  1718. }
  1719. open( x = pointer.x, y = pointer.y ) {
  1720. if ( lastContext !== null ) {
  1721. lastContext.hide();
  1722. }
  1723. lastContext = this;
  1724. this.setPosition( x, y );
  1725. document.body.append( this.dom );
  1726. return this.show();
  1727. }
  1728. setWidth( width ) {
  1729. this.dom.style.width = numberToPX( width );
  1730. return this;
  1731. }
  1732. setPosition( x, y ) {
  1733. const dom = this.dom;
  1734. dom.style.left = numberToPX( x );
  1735. dom.style.top = numberToPX( y );
  1736. return this;
  1737. }
  1738. setTarget( target = null ) {
  1739. if ( target !== null ) {
  1740. const onContextMenu = ( e ) => {
  1741. e.preventDefault();
  1742. if ( e.pointerType !== 'mouse' || ( e.pageX === 0 && e.pageY === 0 ) ) return;
  1743. this.dispatchEvent( new Event( 'context' ) );
  1744. this.open();
  1745. };
  1746. this.target = target;
  1747. target.addEventListener( 'contextmenu', onContextMenu, false );
  1748. }
  1749. return this;
  1750. }
  1751. show() {
  1752. if ( ! this.opened ) {
  1753. this.dom.style.left = '';
  1754. this.dom.style.transform = '';
  1755. }
  1756. const domRect = this.dom.getBoundingClientRect();
  1757. let offsetX = Math.min( window.innerWidth - ( domRect.x + domRect.width + 10 ), 0 );
  1758. let offsetY = Math.min( window.innerHeight - ( domRect.y + domRect.height + 10 ), 0 );
  1759. if ( this.opened ) {
  1760. if ( offsetX < 0 ) offsetX = - domRect.width;
  1761. if ( offsetY < 0 ) offsetY = - domRect.height;
  1762. this.setPosition( domRect.x + offsetX, domRect.y + offsetY );
  1763. } else {
  1764. // flip submenus
  1765. if ( offsetX < 0 ) this.dom.style.left = '-100%';
  1766. if ( offsetY < 0 ) this.dom.style.transform = 'translateY( calc( 32px - 100% ) )';
  1767. }
  1768. return super.show();
  1769. }
  1770. hide() {
  1771. if ( this.opened ) {
  1772. lastContext = null;
  1773. }
  1774. return super.hide();
  1775. }
  1776. add( button, submenu = null ) {
  1777. button.addEventListener( 'click', this._onButtonClick );
  1778. button.addEventListener( 'mouseover', this._onButtonMouseOver );
  1779. return super.add( button, submenu );
  1780. }
  1781. get opened() {
  1782. return lastContext === this;
  1783. }
  1784. }
  1785. class CircleMenu extends Menu {
  1786. constructor() {
  1787. super( 'circle' );
  1788. }
  1789. }
  1790. class Tips extends EventTarget {
  1791. constructor() {
  1792. super();
  1793. const dom = document.createElement( 'f-tips' );
  1794. this.dom = dom;
  1795. this.time = 0;
  1796. this.duration = 3000;
  1797. }
  1798. message( str ) {
  1799. return this.tip( str );
  1800. }
  1801. error( str ) {
  1802. return this.tip( str, 'error' );
  1803. }
  1804. tip( html, className = '' ) {
  1805. const dom = document.createElement( 'f-tip' );
  1806. dom.className = className;
  1807. dom.innerHTML = html;
  1808. this.dom.prepend( dom );
  1809. //requestAnimationFrame( () => dom.style.opacity = 1 );
  1810. this.time = Math.min( this.time + this.duration, this.duration );
  1811. setTimeout( () => {
  1812. this.time = Math.max( this.time - this.duration, 0 );
  1813. dom.style.opacity = 0;
  1814. setTimeout( () => dom.remove(), 250 );
  1815. }, this.time );
  1816. return this;
  1817. }
  1818. }
  1819. const filterString = ( str ) => {
  1820. return str.trim().toLowerCase().replace( /\s\s+/g, ' ' );
  1821. };
  1822. class Search extends Menu {
  1823. constructor() {
  1824. super( 'search' );
  1825. this.events.submit = [];
  1826. this.events.filter = [];
  1827. this.tags = new WeakMap();
  1828. const inputDOM = document.createElement( 'input' );
  1829. inputDOM.placeholder = 'Type here';
  1830. let filter = true;
  1831. let filterNeedUpdate = true;
  1832. inputDOM.addEventListener( 'focusout', () => {
  1833. filterNeedUpdate = true;
  1834. this.setValue( '' );
  1835. } );
  1836. inputDOM.onkeydown = ( e ) => {
  1837. const key = e.key;
  1838. if ( key === 'ArrowUp' ) {
  1839. const index = this.filteredIndex;
  1840. if ( this.forceAutoComplete ) {
  1841. this.filteredIndex = index !== null ? ( index + 1 ) % ( this.filtered.length || 1 ) : 0;
  1842. } else {
  1843. this.filteredIndex = index !== null ? Math.min( index + 1, this.filtered.length - 1 ) : 0;
  1844. }
  1845. e.preventDefault();
  1846. filter = false;
  1847. } else if ( key === 'ArrowDown' ) {
  1848. const index = this.filteredIndex;
  1849. if ( this.forceAutoComplete ) {
  1850. this.filteredIndex = index - 1;
  1851. if ( this.filteredIndex === null ) this.filteredIndex = this.filtered.length - 1;
  1852. } else {
  1853. this.filteredIndex = index !== null ? index - 1 : null;
  1854. }
  1855. e.preventDefault();
  1856. filter = false;
  1857. } else if ( key === 'Enter' ) {
  1858. this.value = this.currentFiltered ? this.currentFiltered.button.getValue() : inputDOM.value;
  1859. this.submit();
  1860. e.preventDefault();
  1861. filter = false;
  1862. } else {
  1863. filter = true;
  1864. }
  1865. };
  1866. inputDOM.onkeyup = () => {
  1867. if ( filter ) {
  1868. if ( filterNeedUpdate ) {
  1869. this.dispatchEvent( new Event( 'filter' ) );
  1870. filterNeedUpdate = false;
  1871. }
  1872. this.filter( inputDOM.value );
  1873. }
  1874. };
  1875. this.filtered = [];
  1876. this.currentFiltered = null;
  1877. this.value = '';
  1878. this.forceAutoComplete = false;
  1879. this.dom.append( inputDOM );
  1880. this.inputDOM = inputDOM;
  1881. this.addEventListener( 'filter', ( ) => {
  1882. dispatchEventList( this.events.filter, this );
  1883. } );
  1884. this.addEventListener( 'submit', ( ) => {
  1885. dispatchEventList( this.events.submit, this );
  1886. } );
  1887. }
  1888. submit() {
  1889. this.dispatchEvent( new Event( 'submit' ) );
  1890. return this.setValue( '' );
  1891. }
  1892. setValue( value ) {
  1893. this.inputDOM.value = value;
  1894. this.filter( value );
  1895. return this;
  1896. }
  1897. getValue() {
  1898. return this.value;
  1899. }
  1900. onFilter( callback ) {
  1901. this.events.filter.push( callback );
  1902. return this;
  1903. }
  1904. onSubmit( callback ) {
  1905. this.events.submit.push( callback );
  1906. return this;
  1907. }
  1908. getFilterByButton( button ) {
  1909. for ( const filter of this.filtered ) {
  1910. if ( filter.button === button ) {
  1911. return filter;
  1912. }
  1913. }
  1914. return null;
  1915. }
  1916. add( button ) {
  1917. super.add( button );
  1918. const onDown = () => {
  1919. const filter = this.getFilterByButton( button );
  1920. this.filteredIndex = this.filtered.indexOf( filter );
  1921. this.value = button.getValue();
  1922. this.submit();
  1923. };
  1924. button.dom.addEventListener( 'mousedown', onDown );
  1925. button.dom.addEventListener( 'touchstart', onDown );
  1926. this.domButtons.get( button ).remove();
  1927. return this;
  1928. }
  1929. set filteredIndex( index ) {
  1930. if ( this.currentFiltered ) {
  1931. const buttonDOM = this.domButtons.get( this.currentFiltered.button );
  1932. buttonDOM.classList.remove( 'active' );
  1933. this.currentFiltered = null;
  1934. }
  1935. const filteredItem = this.filtered[ index ];
  1936. if ( filteredItem ) {
  1937. const buttonDOM = this.domButtons.get( filteredItem.button );
  1938. buttonDOM.classList.add( 'active' );
  1939. this.currentFiltered = filteredItem;
  1940. }
  1941. this.updateFilter();
  1942. }
  1943. get filteredIndex() {
  1944. return this.currentFiltered ? this.filtered.indexOf( this.currentFiltered ) : null;
  1945. }
  1946. setTag( button, tags ) {
  1947. this.tags.set( button, tags );
  1948. }
  1949. filter( text ) {
  1950. text = filterString( text );
  1951. const tags = this.tags;
  1952. const filtered = [];
  1953. for ( const button of this.buttons ) {
  1954. const buttonDOM = this.domButtons.get( button );
  1955. buttonDOM.remove();
  1956. const buttonTags = tags.has( button ) ? ' ' + tags.get( button ) : '';
  1957. const label = filterString( button.getValue() + buttonTags );
  1958. if ( text && label.includes( text ) === true ) {
  1959. const score = text.length / label.length;
  1960. filtered.push( {
  1961. button,
  1962. score
  1963. } );
  1964. }
  1965. }
  1966. filtered.sort( ( a, b ) => b.score - a.score );
  1967. this.filtered = filtered;
  1968. this.filteredIndex = this.forceAutoComplete ? 0 : null;
  1969. }
  1970. updateFilter() {
  1971. const filteredIndex = Math.min( this.filteredIndex, this.filteredIndex - 3 );
  1972. for ( let i = 0; i < this.filtered.length; i ++ ) {
  1973. const button = this.filtered[ i ].button;
  1974. const buttonDOM = this.domButtons.get( button );
  1975. buttonDOM.remove();
  1976. if ( i >= filteredIndex ) {
  1977. this.listDOM.append( buttonDOM );
  1978. }
  1979. }
  1980. }
  1981. }
  1982. class LabelElement extends Element {
  1983. constructor( label = '', align = '' ) {
  1984. super();
  1985. this.labelDOM = document.createElement( 'f-label' );
  1986. this.inputsDOM = document.createElement( 'f-inputs' );
  1987. const spanDOM = document.createElement( 'span' );
  1988. this.spanDOM = spanDOM;
  1989. this.iconDOM = null;
  1990. this.labelDOM.append( spanDOM );
  1991. this.dom.append( this.labelDOM );
  1992. this.dom.append( this.inputsDOM );
  1993. this.serializeLabel = false;
  1994. this.setLabel( label );
  1995. this.setAlign( align );
  1996. }
  1997. setIcon( value ) {
  1998. this.iconDOM = this.iconDOM || document.createElement( 'i' );
  1999. this.iconDOM.className = value;
  2000. if ( value ) this.labelDOM.prepend( this.iconDOM );
  2001. else this.iconDOM.remove();
  2002. return this;
  2003. }
  2004. getIcon() {
  2005. return this.iconDOM ? this.iconDOM.className : null;
  2006. }
  2007. setAlign( align ) {
  2008. this.labelDOM.className = align;
  2009. }
  2010. setLabel( val ) {
  2011. this.spanDOM.innerText = val;
  2012. }
  2013. getLabel() {
  2014. return this.spanDOM.innerText;
  2015. }
  2016. serialize( data ) {
  2017. super.serialize( data );
  2018. if ( this.serializeLabel ) {
  2019. const label = this.getLabel();
  2020. const icon = this.getIcon();
  2021. data.label = label;
  2022. if ( icon !== '' ) {
  2023. data.icon = icon;
  2024. }
  2025. }
  2026. }
  2027. deserialize( data ) {
  2028. super.deserialize( data );
  2029. if ( this.serializeLabel ) {
  2030. this.setLabel( data.label );
  2031. if ( data.icon !== undefined ) {
  2032. this.setIcon( data.icon );
  2033. }
  2034. }
  2035. }
  2036. }
  2037. class ButtonInput extends Input {
  2038. constructor( innterText = '' ) {
  2039. const dom = document.createElement( 'button' );
  2040. const spanDOM = document.createElement( 'span' );
  2041. dom.append( spanDOM );
  2042. const iconDOM = document.createElement( 'i' );
  2043. dom.append( iconDOM );
  2044. super( dom );
  2045. this.spanDOM = spanDOM;
  2046. this.iconDOM = iconDOM;
  2047. spanDOM.innerText = innterText;
  2048. dom.onmouseover = () => {
  2049. this.dispatchEvent( new Event( 'mouseover' ) );
  2050. };
  2051. dom.onclick = dom.ontouchstart =
  2052. iconDOM.onclick = iconDOM.ontouchstart = ( e ) => {
  2053. e.preventDefault();
  2054. e.stopPropagation();
  2055. this.dispatchEvent( new Event( 'click' ) );
  2056. };
  2057. }
  2058. setIcon( className ) {
  2059. this.iconDOM.className = className;
  2060. return this;
  2061. }
  2062. getIcon() {
  2063. return this.iconDOM.className;
  2064. }
  2065. setValue( val ) {
  2066. this.spanDOM.innerText = val;
  2067. return this;
  2068. }
  2069. getValue() {
  2070. return this.spanDOM.innerText;
  2071. }
  2072. }
  2073. class ColorInput extends Input {
  2074. constructor( value = 0x0099ff ) {
  2075. const dom = document.createElement( 'input' );
  2076. super( dom );
  2077. dom.type = 'color';
  2078. dom.value = numberToHex( value );
  2079. dom.oninput = () => {
  2080. this.dispatchEvent( new Event( 'change' ) );
  2081. };
  2082. }
  2083. setValue( value, dispatch = true ) {
  2084. return super.setValue( numberToHex( value ), dispatch );
  2085. }
  2086. getValue() {
  2087. return parseInt( super.getValue().substr( 1 ), 16 );
  2088. }
  2089. }
  2090. class NumberInput extends Input {
  2091. constructor( value = 0, min = - Infinity, max = Infinity, step = .01 ) {
  2092. const dom = document.createElement( 'input' );
  2093. super( dom );
  2094. this.min = min;
  2095. this.max = max;
  2096. this.step = step;
  2097. this.integer = false;
  2098. dom.type = 'text';
  2099. dom.className = 'number';
  2100. dom.value = this._getString( value );
  2101. dom.spellcheck = false;
  2102. dom.autocomplete = 'off';
  2103. dom.ondragstart = dom.oncontextmenu = ( e ) => {
  2104. e.preventDefault();
  2105. e.stopPropagation();
  2106. };
  2107. dom.onfocus = dom.onclick = () => {
  2108. dom.select();
  2109. };
  2110. dom.onblur = () => {
  2111. this.dom.value = this._getString( this.dom.value );
  2112. this.dispatchEvent( new Event( 'blur' ) );
  2113. };
  2114. dom.onchange = () => {
  2115. this.dispatchEvent( new Event( 'change' ) );
  2116. };
  2117. dom.onkeydown = ( e ) => {
  2118. if ( e.key.length === 1 && /\d|\.|\-/.test( e.key ) !== true ) {
  2119. return false;
  2120. }
  2121. if ( e.key === 'Enter' ) {
  2122. e.target.blur();
  2123. }
  2124. e.stopPropagation();
  2125. };
  2126. draggableDOM( dom, ( data ) => {
  2127. const { delta } = data;
  2128. if ( dom.readOnly === true ) return;
  2129. if ( data.value === undefined ) {
  2130. data.value = this.getValue();
  2131. }
  2132. const diff = delta.x - delta.y;
  2133. const value = data.value + ( diff * this.step );
  2134. dom.value = this._getString( value.toFixed( this.precision ) );
  2135. this.dispatchEvent( new Event( 'change' ) );
  2136. } );
  2137. }
  2138. setStep( step ) {
  2139. this.step = step;
  2140. return this;
  2141. }
  2142. setRange( min, max, step ) {
  2143. this.min = min;
  2144. this.max = max;
  2145. this.step = step;
  2146. this.dispatchEvent( new Event( 'range' ) );
  2147. return this.setValue( this.getValue() );
  2148. }
  2149. get precision() {
  2150. if ( this.integer === true ) return 0;
  2151. const fract = this.step % 1;
  2152. return fract !== 0 ? fract.toString().split( '.' )[ 1 ].length : 1;
  2153. }
  2154. setValue( val, dispatch = true ) {
  2155. return super.setValue( this._getString( val ), dispatch );
  2156. }
  2157. getValue() {
  2158. return Number( this.dom.value );
  2159. }
  2160. serialize( data ) {
  2161. const { min, max } = this;
  2162. if ( min !== - Infinity && max !== Infinity ) {
  2163. data.min = this.min;
  2164. data.max = this.max;
  2165. data.step = this.step;
  2166. }
  2167. super.serialize( data );
  2168. }
  2169. deserialize( data ) {
  2170. if ( data.min !== undefined ) {
  2171. const { min, max, step } = this;
  2172. this.setRange( min, max, step );
  2173. }
  2174. super.deserialize( data );
  2175. }
  2176. _getString( value ) {
  2177. const num = Math.min( Math.max( Number( value ), this.min ), this.max );
  2178. if ( this.integer === true ) {
  2179. return Math.floor( num );
  2180. } else {
  2181. return num + ( num % 1 ? '' : '.0' );
  2182. }
  2183. }
  2184. }
  2185. class SelectInput extends Input {
  2186. constructor( options = [], value = null ) {
  2187. const dom = document.createElement( 'select' );
  2188. super( dom );
  2189. dom.onchange = () => {
  2190. this.dispatchEvent( new Event( 'change' ) );
  2191. };
  2192. dom.onmousedown = dom.ontouchstart = () => {
  2193. this.dispatchEvent( new Event( 'click' ) );
  2194. };
  2195. this.setOptions( options, value );
  2196. }
  2197. setOptions( options, value = null ) {
  2198. const dom = this.dom;
  2199. const defaultValue = dom.value;
  2200. let containsDefaultValue = false;
  2201. this.options = options;
  2202. dom.innerHTML = '';
  2203. for ( let index = 0; index < options.length; index ++ ) {
  2204. let opt = options[ index ];
  2205. if ( typeof opt === 'string' ) {
  2206. opt = { name: opt, value: index };
  2207. }
  2208. const option = document.createElement( 'option' );
  2209. option.innerText = opt.name;
  2210. option.value = opt.value;
  2211. if ( containsDefaultValue === false && defaultValue === opt.value ) {
  2212. containsDefaultValue = true;
  2213. }
  2214. dom.append( option );
  2215. }
  2216. dom.value = value !== null ? value : containsDefaultValue ? defaultValue : '';
  2217. return this;
  2218. }
  2219. getOptions() {
  2220. return this._options;
  2221. }
  2222. serialize( data ) {
  2223. data.options = [ ...this.options ];
  2224. super.serialize( data );
  2225. }
  2226. deserialize( data ) {
  2227. const currentOptions = this.options;
  2228. if ( currentOptions.length === 0 ) {
  2229. this.setOptions( data.options );
  2230. }
  2231. super.deserialize( data );
  2232. }
  2233. }
  2234. const getStep = ( min, max ) => {
  2235. const sensibility = .001;
  2236. return ( max - min ) * sensibility;
  2237. };
  2238. class SliderInput extends Input {
  2239. constructor( value = 0, min = 0, max = 100 ) {
  2240. const dom = document.createElement( 'f-subinputs' );
  2241. super( dom );
  2242. value = Math.min( Math.max( value, min ), max );
  2243. const step = getStep( min, max );
  2244. const rangeDOM = document.createElement( 'input' );
  2245. rangeDOM.type = 'range';
  2246. rangeDOM.min = min;
  2247. rangeDOM.max = max;
  2248. rangeDOM.step = step;
  2249. rangeDOM.value = value;
  2250. const field = new NumberInput( value, min, max, step );
  2251. field.dom.className = 'range-value';
  2252. field.onChange( () => {
  2253. rangeDOM.value = field.getValue();
  2254. this.dispatchEvent( new Event( 'change' ) );
  2255. } );
  2256. field.addEventListener( 'range', () => {
  2257. rangeDOM.min = field.min;
  2258. rangeDOM.max = field.max;
  2259. rangeDOM.step = field.step;
  2260. rangeDOM.value = field.getValue();
  2261. } );
  2262. dom.append( rangeDOM );
  2263. dom.append( field.dom );
  2264. this.rangeDOM = rangeDOM;
  2265. this.field = field;
  2266. const updateRangeValue = () => {
  2267. let value = Number( rangeDOM.value );
  2268. if ( value !== this.max && value + this.step >= this.max ) {
  2269. // fix not end range fraction
  2270. rangeDOM.value = value = this.max;
  2271. }
  2272. this.field.setValue( value );
  2273. };
  2274. draggableDOM( rangeDOM, () => {
  2275. updateRangeValue();
  2276. this.dispatchEvent( new Event( 'change' ) );
  2277. }, { className: '' } );
  2278. }
  2279. get min() {
  2280. return this.field.min;
  2281. }
  2282. get max() {
  2283. return this.field.max;
  2284. }
  2285. get step() {
  2286. return this.field.step;
  2287. }
  2288. setRange( min, max ) {
  2289. this.field.setRange( min, max, getStep( min, max ) );
  2290. this.dispatchEvent( new Event( 'range' ) );
  2291. this.dispatchEvent( new Event( 'change' ) );
  2292. return this;
  2293. }
  2294. setValue( val, dispatch = true ) {
  2295. this.field.setValue( val );
  2296. this.rangeDOM.value = val;
  2297. if ( dispatch ) this.dispatchEvent( new Event( 'change' ) );
  2298. return this;
  2299. }
  2300. getValue() {
  2301. return this.field.getValue();
  2302. }
  2303. serialize( data ) {
  2304. data.min = this.min;
  2305. data.max = this.max;
  2306. super.serialize( data );
  2307. }
  2308. deserialize( data ) {
  2309. const { min, max } = data;
  2310. this.setRange( min, max );
  2311. super.deserialize( data );
  2312. }
  2313. }
  2314. class StringInput extends Input {
  2315. constructor( value = '' ) {
  2316. const dom = document.createElement( 'f-string' );
  2317. super( dom );
  2318. const inputDOM = document.createElement( 'input' );
  2319. dom.append( inputDOM );
  2320. inputDOM.type = 'text';
  2321. inputDOM.value = value;
  2322. inputDOM.spellcheck = false;
  2323. inputDOM.autocomplete = 'off';
  2324. this._buttonsDOM = null;
  2325. this._datalistDOM = null;
  2326. this.iconDOM = null;
  2327. this.inputDOM = inputDOM;
  2328. this.buttons = [];
  2329. inputDOM.onblur = () => {
  2330. this.dispatchEvent( new Event( 'blur' ) );
  2331. };
  2332. inputDOM.onchange = () => {
  2333. this.dispatchEvent( new Event( 'change' ) );
  2334. };
  2335. let keyDownStr = '';
  2336. inputDOM.onkeydown = () => keyDownStr = inputDOM.value;
  2337. inputDOM.onkeyup = ( e ) => {
  2338. if ( e.key === 'Enter' ) {
  2339. e.target.blur();
  2340. }
  2341. e.stopPropagation();
  2342. if ( keyDownStr !== inputDOM.value ) {
  2343. this.dispatchEvent( new Event( 'change' ) );
  2344. }
  2345. };
  2346. }
  2347. setPlaceHolder( text ) {
  2348. this.inputDOM.placeholder = text;
  2349. return this;
  2350. }
  2351. setIcon( value ) {
  2352. this.iconDOM = this.iconDOM || document.createElement( 'i' );
  2353. this.iconDOM.setAttribute( 'type', 'icon' );
  2354. this.iconDOM.className = value;
  2355. if ( value ) this.dom.prepend( this.iconDOM );
  2356. else this.iconDOM.remove();
  2357. return this;
  2358. }
  2359. getIcon() {
  2360. return this.iconInput ? this.iconInput.getIcon() : '';
  2361. }
  2362. addButton( button ) {
  2363. this.buttonsDOM.prepend( button.iconDOM );
  2364. this.buttons.push( button );
  2365. return this;
  2366. }
  2367. addOption( value ) {
  2368. const option = document.createElement( 'option' );
  2369. option.value = value;
  2370. this.datalistDOM.append( option );
  2371. return this;
  2372. }
  2373. clearOptions() {
  2374. this.datalistDOM.remove();
  2375. }
  2376. get datalistDOM() {
  2377. let dom = this._datalistDOM;
  2378. if ( dom === null ) {
  2379. const datalistId = 'input-dt-' + this.id;
  2380. dom = document.createElement( 'datalist' );
  2381. dom.id = datalistId;
  2382. this._datalistDOM = dom;
  2383. this.inputDOM.autocomplete = 'on';
  2384. this.inputDOM.setAttribute( 'list', datalistId );
  2385. this.dom.prepend( dom );
  2386. }
  2387. return dom;
  2388. }
  2389. get buttonsDOM() {
  2390. let dom = this._buttonsDOM;
  2391. if ( dom === null ) {
  2392. dom = document.createElement( 'f-buttons' );
  2393. this._buttonsDOM = dom;
  2394. this.dom.prepend( dom );
  2395. }
  2396. return dom;
  2397. }
  2398. getInput() {
  2399. return this.inputDOM;
  2400. }
  2401. }
  2402. class TextInput extends Input {
  2403. constructor( innerText = '' ) {
  2404. const dom = document.createElement( 'textarea' );
  2405. super( dom );
  2406. dom.innerText = innerText;
  2407. dom.classList.add( 'f-scroll' );
  2408. dom.onblur = () => {
  2409. this.dispatchEvent( new Event( 'blur' ) );
  2410. };
  2411. dom.onchange = () => {
  2412. this.dispatchEvent( new Event( 'change' ) );
  2413. };
  2414. dom.onkeyup = ( e ) => {
  2415. if ( e.key === 'Enter' ) {
  2416. e.target.blur();
  2417. }
  2418. e.stopPropagation();
  2419. this.dispatchEvent( new Event( 'change' ) );
  2420. };
  2421. }
  2422. }
  2423. class ToggleInput extends Input {
  2424. constructor( value = false ) {
  2425. const dom = document.createElement( 'input' );
  2426. super( dom );
  2427. dom.type = 'checkbox';
  2428. dom.className = 'toggle';
  2429. dom.checked = value;
  2430. dom.onclick = () => this.dispatchEvent( new Event( 'click' ) );
  2431. dom.onchange = () => this.dispatchEvent( new Event( 'change' ) );
  2432. }
  2433. setValue( val ) {
  2434. this.dom.checked = val;
  2435. this.dispatchEvent( new Event( 'change' ) );
  2436. return this;
  2437. }
  2438. getValue() {
  2439. return this.dom.checked;
  2440. }
  2441. }
  2442. class TreeViewNode {
  2443. constructor( name = '' ) {
  2444. const dom = document.createElement( 'f-treeview-node' );
  2445. const labelDOM = document.createElement( 'f-treeview-label' );
  2446. const inputDOM = document.createElement( 'input' );
  2447. const labelSpam = document.createElement( 'spam' );
  2448. labelDOM.append( labelSpam );
  2449. labelSpam.innerText = name;
  2450. inputDOM.type = 'checkbox';
  2451. dom.append( inputDOM );
  2452. dom.append( labelDOM );
  2453. this.dom = dom;
  2454. this.childrenDOM = null;
  2455. this.labelSpam = labelSpam;
  2456. this.labelDOM = labelDOM;
  2457. this.inputDOM = inputDOM;
  2458. this.iconDOM = null;
  2459. this.parent = null;
  2460. this.children = [];
  2461. this.selected = false;
  2462. this.events = {
  2463. 'change': [],
  2464. 'click': []
  2465. };
  2466. dom.addEventListener( 'click', ( ) => {
  2467. dispatchEventList( this.events.click, this );
  2468. } );
  2469. }
  2470. setLabel( value ) {
  2471. this.labelSpam.innerText = value;
  2472. return this;
  2473. }
  2474. getLabel() {
  2475. return this.labelSpam.innerText;
  2476. }
  2477. add( node ) {
  2478. let childrenDOM = this.childrenDOM;
  2479. if ( this.childrenDOM === null ) {
  2480. const dom = this.dom;
  2481. const arrowDOM = document.createElement( 'f-arrow' );
  2482. childrenDOM = document.createElement( 'f-treeview-children' );
  2483. dom.append( arrowDOM );
  2484. dom.append( childrenDOM );
  2485. this.childrenDOM = childrenDOM;
  2486. }
  2487. this.children.push( node );
  2488. childrenDOM.append( node.dom );
  2489. node.parent = this;
  2490. return this;
  2491. }
  2492. setOpened( value ) {
  2493. this.inputDOM.checked = value;
  2494. return this;
  2495. }
  2496. getOpened() {
  2497. return this.inputDOM.checkbox;
  2498. }
  2499. setIcon( value ) {
  2500. this.iconDOM = this.iconDOM || document.createElement( 'i' );
  2501. this.iconDOM.className = value;
  2502. if ( value ) this.labelDOM.prepend( this.iconDOM );
  2503. else this.iconDOM.remove();
  2504. return this;
  2505. }
  2506. getIcon() {
  2507. return this.iconDOM ? this.iconDOM.className : null;
  2508. }
  2509. setVisible( value ) {
  2510. this.dom.style.display = value ? '' : 'none';
  2511. return this;
  2512. }
  2513. setSelected( value ) {
  2514. if ( this.selected === value ) return this;
  2515. if ( value ) this.dom.classList.add( 'selected' );
  2516. else this.dom.classList.remove( 'selected' );
  2517. this.selected = value;
  2518. return this;
  2519. }
  2520. onClick( callback ) {
  2521. this.events.click.push( callback );
  2522. return this;
  2523. }
  2524. }
  2525. class TreeViewInput extends Input {
  2526. constructor( options = [] ) {
  2527. const dom = document.createElement( 'f-treeview' );
  2528. super( dom );
  2529. const childrenDOM = document.createElement( 'f-treeview-children' );
  2530. dom.append( childrenDOM );
  2531. dom.setAttribute( 'type', 'tree' );
  2532. this.childrenDOM = childrenDOM;
  2533. this.children = [];
  2534. }
  2535. add( node ) {
  2536. this.children.push( node );
  2537. this.childrenDOM.append( node.dom );
  2538. return this;
  2539. }
  2540. serialize( data ) {
  2541. //data.options = [ ...this.options ];
  2542. super.serialize( data );
  2543. }
  2544. deserialize( data ) {
  2545. /*const currentOptions = this.options;
  2546. if ( currentOptions.length === 0 ) {
  2547. this.setOptions( data.options );
  2548. }*/
  2549. super.deserialize( data );
  2550. }
  2551. }
  2552. var Flow = /*#__PURE__*/Object.freeze({
  2553. __proto__: null,
  2554. Element: Element,
  2555. Input: Input,
  2556. Node: Node,
  2557. Canvas: Canvas,
  2558. Serializer: Serializer,
  2559. Menu: Menu,
  2560. ContextMenu: ContextMenu,
  2561. CircleMenu: CircleMenu,
  2562. Tips: Tips,
  2563. Search: Search,
  2564. DraggableElement: DraggableElement,
  2565. LabelElement: LabelElement,
  2566. TitleElement: TitleElement,
  2567. ButtonInput: ButtonInput,
  2568. ColorInput: ColorInput,
  2569. NumberInput: NumberInput,
  2570. SelectInput: SelectInput,
  2571. SliderInput: SliderInput,
  2572. StringInput: StringInput,
  2573. TextInput: TextInput,
  2574. ToggleInput: ToggleInput,
  2575. TreeViewInput: TreeViewInput,
  2576. TreeViewNode: TreeViewNode
  2577. });
  2578. const LoaderLib = {};
  2579. class Loader extends EventTarget {
  2580. constructor( parseType = Loader.DEFAULT ) {
  2581. super();
  2582. this.parseType = parseType;
  2583. this.events = {
  2584. 'load': []
  2585. };
  2586. }
  2587. setParseType( type ) {
  2588. this.parseType = type;
  2589. return this;
  2590. }
  2591. getParseType() {
  2592. return this.parseType;
  2593. }
  2594. onLoad( callback ) {
  2595. this.events.load.push( callback );
  2596. return this;
  2597. }
  2598. async load( url, lib = {} ) {
  2599. return await fetch( url )
  2600. .then( response => response.json() )
  2601. .then( result => {
  2602. this.data = this.parse( result, lib );
  2603. dispatchEventList( this.events.load, this );
  2604. return this.data;
  2605. } )
  2606. .catch( err => {
  2607. console.error( 'Loader:', err );
  2608. } );
  2609. }
  2610. parse( json, lib = {} ) {
  2611. json = this._parseObjects( json, lib );
  2612. const parseType = this.parseType;
  2613. if ( parseType === Loader.DEFAULT ) {
  2614. const type = json.type;
  2615. const flowClass = lib[ type ] ? lib[ type ] : ( LoaderLib[ type ] || Flow[ type ] );
  2616. const flowObj = new flowClass();
  2617. if ( flowObj.getSerializable() ) {
  2618. flowObj.deserialize( json );
  2619. }
  2620. return flowObj;
  2621. } else if ( parseType === Loader.OBJECTS ) {
  2622. return json;
  2623. }
  2624. }
  2625. _parseObjects( json, lib = {} ) {
  2626. json = { ...json };
  2627. const objects = {};
  2628. for ( const id in json.objects ) {
  2629. const obj = json.objects[ id ];
  2630. obj.objects = objects;
  2631. const type = obj.type;
  2632. const flowClass = lib[ type ] ? lib[ type ] : ( LoaderLib[ type ] || Flow[ type ] );
  2633. if ( ! flowClass ) {
  2634. console.error( `Class "${ type }" not found!` );
  2635. }
  2636. objects[ id ] = new flowClass();
  2637. objects[ id ].deserializeLib( json.objects[ id ], lib );
  2638. }
  2639. const ref = new Map();
  2640. const deserializePass = ( prop = null ) => {
  2641. for ( const id in json.objects ) {
  2642. const newObject = objects[ id ];
  2643. if ( ref.has( newObject ) === false && ( prop === null || newObject[ prop ] === true ) ) {
  2644. ref.set( newObject, true );
  2645. if ( newObject.getSerializable() ) {
  2646. newObject.deserialize( json.objects[ id ] );
  2647. }
  2648. }
  2649. }
  2650. };
  2651. deserializePass( 'isNode' );
  2652. deserializePass( 'isElement' );
  2653. deserializePass( 'isInput' );
  2654. deserializePass();
  2655. json.objects = objects;
  2656. return json;
  2657. }
  2658. }
  2659. Loader.DEFAULT = 'default';
  2660. Loader.OBJECTS = 'objects';
  2661. export { ButtonInput, Canvas, CircleMenu, ColorInput, ContextMenu, DraggableElement, Element, Input, LabelElement, Loader, LoaderLib, Menu, Node, NumberInput, REVISION, Search, SelectInput, Serializer, SliderInput, StringInput, TextInput, Tips, TitleElement, ToggleInput, TreeViewInput, TreeViewNode, Utils };