123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219 |
- /**
- * https://github.com/sunag/flow
- */
- function __flow__addCSS( css ) {
- try {
- const style = document.createElement( 'style' );
- style.setAttribute( 'type', 'text/css' );
- style.innerHTML = css;
- document.head.appendChild( style );
- } catch( e ) {}
- }
- __flow__addCSS( `f-canvas,f-canvas canvas { position: absolute; top: 0; left: 0; margin: 0; padding: 0; width: 100%; height: 100%; -webkit-touch-callout: none; }f-canvas { overflow: auto; cursor: grab;}f-canvas canvas.front { z-index: 10;}body.dragging f-canvas,body.connecting f-canvas { overflow: hidden !important;}body.dragging *:not(.drag) { pointer-events: none !important;}f-canvas.grabbing * { cursor: grabbing; user-select: none;}f-canvas canvas { position: fixed; overflow: hidden; pointer-events: none;}f-canvas::-webkit-scrollbar { width: 8px; height: 8px;}f-canvas::-webkit-scrollbar-thumb:hover{ background: #014fc5;}f-canvas::-webkit-scrollbar-track { background: #363636;}f-canvas::-webkit-scrollbar-thumb { background-color: #666666; border-radius: 10px; border: 0;}f-canvas f-content,f-canvas f-area { position: absolute; display: block;}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-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;}@keyframes f-open { 0% { transform: scale(.5); filter: blur(30px); } 100% { transform: scale(1); filter: unset }}f-node { animation: .2s f-open 1 alternate ease-out;}f-menu,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: 13px; text-transform: capitalize; color: #eeeeee; outline: solid 0px #000; letter-spacing: .2px; margin: 0; padding: 0; border: 0; user-select: none; -webkit-tap-highlight-color: transparent; transition: background 0.2s ease;}f-element input { transition: background 0.1s ease;}f-element input,f-element select,f-element button,f-element textarea { background-color: #242427;}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 { 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;}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: 3px; 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; padding-left: 5px; 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; display: flex; top: 0; width: 100%; height: 100%; align-content: space-around;}f-element.output-right f-toolbar { right: 7px; float: right; justify-content: end;}f-element f-toolbar { margin-top: auto; margin-bottom: auto; margin-left: 3px; margin-right: 3px; font-size: 18px; line-height: 18px;}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;}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: 2px; 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; width: 100%;}f-element f-inputs { left: 100px; top: 50%; transform: translateY(-50%); position: absolute; width: calc( 100% - 106px ); height: calc( 100% - 4px ); z-index: 1;}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 f-label i { float: left; font-size: 18px; margin-right: 6px;}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.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 span { text-align: center; font-size: 15px; padding-top: 2px;}f-element.title i { font-size: 18px; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); opacity: .5;}f-element.output-right.title i { left: 10px; right: 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 { border: 2px solid #0177fb; 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;}f-element.output-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;}body.connecting f-node:not(.io-connect) f-element:hover,f-element.select { background-color: rgba(61, 70, 82, 0.98);}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; border-radius: 10px; top: 50%; transform: translateY(-50%); visibility: hidden; pointer-events: none; opacity: 0; transition: all 0.3s ease; z-index: 150; white-space: nowrap;}f-menu.context { position: absolute; width: 170px; padding: 2px; margin: 0; background: #17171794; z-index: 110; 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.context.hidden { visibility: hidden; opacity: 0;}f-menu.context f-item { display: block; position: relative; margin: 0; padding: 0; white-space: nowrap;}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 { overflow: visible; display: block; width: calc( 100% - 6px ); text-align: left; cursor: pointer; white-space: nowrap; padding: 6px 8px; border-radius: 3px; background: #2d2d32; border: 0; color: #ddd; margin: 3px; text-shadow: 1px 1px 0px #0007;}f-menu.context f-item button i { float: left; font-size: 16px;}f-menu.context f-item button span { margin-left: 6px;}f-menu.context f-item:hover > button,f-menu.context f-item.active > button { color: #fff; background: #313136;}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: 120px;}f-menu.circle { position: absolute; left: 30px; top: 30px; z-index: 100;}f-menu.circle f-item { display: flex; justify-content: end; align-content: space-around; margin-bottom: 12px;}f-menu.circle f-item button { width: 50px; height: 50px; font-size: 26px; 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);}f-menu.circle f-item f-tooltip { margin-left: 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-element f-io:hover { border: 2px solid #0177fb; zoom: 1.4; } f-menu.circle f-item button:hover { background-color: #2a2a2a; } f-menu.circle f-item button:hover > f-tooltip, f-menu.context f-item button:hover > f-tooltip { visibility: visible; transform: translate(10px, -50%); opacity: 1; } f-menu.circle f-item button:focus > f-tooltip, f-menu.context f-item button:focus > f-tooltip { visibility: hidden; opacity: 0; }}f-canvas { will-change: top, left;}f-node { will-change: transform !important;}` );
- const REVISION = '1';
- let _id = 0;
- class Serializer extends EventTarget {
- constructor() {
- super();
- this._id = _id ++;
- this._serializable = true;
- }
- get id() {
- return this._id;
- }
- setSerializable( value ) {
- this._serializable = value;
- return this;
- }
- getSerializable() {
- return this._serializable;
- }
- serialize( /*data*/ ) {
- console.warn( 'Serializer: Abstract function.' );
- }
- deserialize( /*data*/ ) {
- console.warn( 'Serializer: Abstract function.' );
- }
- toJSON( data = null ) {
- let object = null;
- const id = this.id;
- if ( data !== null ) {
- const objects = data.objects;
- object = objects[ id ];
- if ( object === undefined ) {
- object = { objects };
- this.serialize( object );
- delete object.objects;
- objects[ id ] = object;
- }
- } else {
- object = { objects: {} };
- this.serialize( object );
- }
- object.id = id;
- object.type = this.constructor.name;
- return object;
- }
- }
- const draggableDOM = ( dom, callback = null, className = 'dragging' ) => {
- let dragData = null;
- const getZoom = () => {
- let zoomDOM = dom;
- while ( zoomDOM && zoomDOM !== document ) {
- const zoom = zoomDOM.style.zoom;
- if ( zoom ) {
- return Number( zoom );
- }
- zoomDOM = zoomDOM.parentNode;
- }
- return 1;
- };
- const onMouseDown = ( e ) => {
- const event = e.touches ? e.touches[ 0 ] : e;
- e.stopImmediatePropagation();
- dragData = {
- client: { x: event.clientX, y: event.clientY },
- delta: { x: 0, y: 0 },
- start: { x: dom.offsetLeft, y: dom.offsetTop },
- dragging: false,
- isTouch: !! e.touches
- };
- window.addEventListener( 'mousemove', onGlobalMouseMove );
- window.addEventListener( 'mouseup', onGlobalMouseUp );
- window.addEventListener( 'touchmove', onGlobalMouseMove );
- window.addEventListener( 'touchend', onGlobalMouseUp );
- };
- const onGlobalMouseMove = ( e ) => {
- const { start, delta, client } = dragData;
- const event = e.touches ? e.touches[ 0 ] : e;
- const zoom = getZoom();
- delta.x = ( event.clientX - client.x ) / zoom;
- delta.y = ( event.clientY - client.y ) / zoom;
- dragData.x = start.x + delta.x;
- dragData.y = start.y + delta.y;
- if ( dragData.dragging === true ) {
- if ( callback !== null ) {
- callback( dragData );
- } else {
- dom.style.cssText += `; left: ${ dragData.x }px; top: ${ dragData.y }px;`;
- }
- e.stopImmediatePropagation();
- } else {
- if ( Math.abs( delta.x ) > 2 || Math.abs( delta.y ) > 2 ) {
- dragData.dragging = true;
- dom.classList.add( 'drag' );
- if ( className ) document.body.classList.add( className );
- e.stopImmediatePropagation();
- }
- }
- };
- const onGlobalMouseUp = ( e ) => {
- e.stopImmediatePropagation();
- dom.classList.remove( 'drag' );
- if ( className ) document.body.classList.remove( className );
- window.removeEventListener( 'mousemove', onGlobalMouseMove );
- window.removeEventListener( 'mouseup', onGlobalMouseUp );
- window.removeEventListener( 'touchmove', onGlobalMouseMove );
- window.removeEventListener( 'touchend', onGlobalMouseUp );
- if ( callback === null ) {
- dom.removeEventListener( 'mousedown', onMouseDown );
- dom.removeEventListener( 'touchstart', onMouseDown );
- }
- dragData.dragging = false;
- if ( callback !== null ) {
- callback( dragData );
- }
- };
- if ( dom instanceof Event ) {
- const e = dom;
- dom = e.target;
- onMouseDown( e );
- } else {
- dom.addEventListener( 'mousedown', onMouseDown );
- dom.addEventListener( 'touchstart', onMouseDown );
- }
- };
- const dispatchEventList = ( list, ...params ) => {
- for ( const callback of list ) {
- callback( ...params );
- }
- };
- const toPX = ( val ) => {
- if ( isNaN( val ) === false ) {
- val = `${ val }px`;
- }
- return val;
- };
- const toHex = ( val ) => {
- if ( isNaN( val ) === false ) {
- val = `#${ val.toString( 16 ).padStart( 6, '0' ) }`;
- }
- return val;
- };
- var Utils = /*#__PURE__*/Object.freeze({
- __proto__: null,
- draggableDOM: draggableDOM,
- dispatchEventList: dispatchEventList,
- toPX: toPX,
- toHex: toHex
- });
- class Link {
- constructor( inputElement = null, outputElement = null ) {
- this.inputElement = inputElement;
- this.outputElement = outputElement;
- }
- get lioElement() {
- if ( Link.InputDirection === 'left' ) {
- return this.outputElement;
- } else {
- return this.inputElement;
- }
- }
- get rioElement() {
- if ( Link.InputDirection === 'left' ) {
- return this.inputElement;
- } else {
- return this.outputElement;
- }
- }
- }
- //Link.InputDirection = 'right';
- Link.InputDirection = 'left';
- let selected = null;
- class Element extends Serializer {
- constructor( draggable = false ) {
- super();
- const dom = document.createElement( 'f-element' );
- dom.element = this;
- const onSelect = ( e ) => {
- let element = this;
- if ( e.changedTouches && e.changedTouches.length > 0 ) {
- const touch = e.changedTouches[ 0 ];
- let overDOM = document.elementFromPoint( touch.clientX, touch.clientY );
- while ( overDOM && ( ! overDOM.element || ! overDOM.element.isElement ) ) {
- overDOM = overDOM.parentNode;
- }
- element = overDOM ? overDOM.element : null;
- }
- selected = element;
- };
- if ( draggable === false ) {
- dom.ontouchstart = dom.onmousedown = ( e ) => {
- e.stopPropagation();
- };
- }
- dom.addEventListener( 'mouseup', onSelect, true );
- dom.addEventListener( 'touchend', onSelect );
- this.inputs = [];
- this.links = [];
- this.dom = dom;
- this.lioLength = 0;
- this.rioLength = 0;
- this.events = {
- 'connect': [],
- 'connectChildren': []
- };
- this.node = null;
- this.style = '';
- this.extra = null;
- this.visible = true;
- this.inputsDOM = dom;
- this.disconnectDOM = null;
- this.lioDOM = this._createIO( 'lio' );
- this.rioDOM = this._createIO( 'rio' );
- this.dom.classList.add( `output-${ Link.InputDirection }` );
- this.dom.appendChild( this.lioDOM );
- this.dom.appendChild( this.rioDOM );
- this.addEventListener( 'connect', ( ) => {
- dispatchEventList( this.events.connect, this );
- } );
- this.addEventListener( 'connectChildren', ( ) => {
- dispatchEventList( this.events.connectChildren, this );
- } );
- }
- onConnect( callback, childrens = false ) {
- this.events.connect.push( callback );
- if ( childrens ) {
- this.events.connectChildren.push( callback );
- }
- return this;
- }
- setExtra( value ) {
- this.extra = value;
- return this;
- }
- getExtra() {
- return this.extra;
- }
- setVisible( value ) {
- this.visible = value;
- this.dom.style.display = value ? '' : 'none';
- return this;
- }
- getVisible() {
- return this.visible;
- }
- setStyle( style ) {
- const dom = this.dom;
- if ( this.style ) dom.classList.remove( this.style );
- if ( style ) dom.classList.add( style );
- this.style = style;
- return this;
- }
- setInput( length ) {
- if ( Link.InputDirection === 'left' ) {
- return this.setLIO( length );
- } else {
- return this.setRIO( length );
- }
- }
- setOutput( length ) {
- if ( Link.InputDirection === 'left' ) {
- return this.setRIO( length );
- } else {
- return this.setLIO( length );
- }
- }
- get inputLength() {
- if ( Link.InputDirection === 'left' ) {
- return this.lioLength;
- } else {
- return this.rioLength;
- }
- }
- get outputLength() {
- if ( Link.InputDirection === 'left' ) {
- return this.rioLength;
- } else {
- return this.lioLength;
- }
- }
- setLIO( length ) {
- this.lioLength = length;
- this.lioDOM.style.visibility = length > 0 ? '' : 'hidden';
- return this;
- }
- setRIO( length ) {
- this.rioLength = length;
- this.rioDOM.style.visibility = length > 0 ? '' : 'hidden';
- return this;
- }
- add( input ) {
- this.inputs.push( input );
- input.element = this;
- this.inputsDOM.appendChild( input.dom );
- return this;
- }
- setHeight( val ) {
- this.dom.style.height = toPX( val );
- return this;
- }
- getHeight() {
- return this.dom.style.height;
- }
- connect( element = null ) {
- if ( this.disconnectDOM !== null ) {
- // remove the current input
- this.disconnectDOM.dispatchEvent( new Event( 'disconnect' ) );
- }
- if ( element !== null ) {
- const link = new Link( this, element );
- this.links.push( link );
- if ( this.disconnectDOM === null ) {
- this.disconnectDOM = document.createElement( 'f-disconnect' );
- this.disconnectDOM.innerText = '✖';
- this.dom.appendChild( this.disconnectDOM );
- const onDisconnect = () => {
- this.links = [];
- this.dom.removeChild( this.disconnectDOM );
- this.disconnectDOM.removeEventListener( 'mousedown', onClick, true );
- this.disconnectDOM.removeEventListener( 'touchstart', onClick, true );
- this.disconnectDOM.removeEventListener( 'disconnect', onDisconnect, true );
- element.removeEventListener( 'connect', onConnect );
- element.removeEventListener( 'connectChildren', onConnect );
- element.removeEventListener( 'nodeConnect', onConnect );
- element.removeEventListener( 'nodeConnectChildren', onConnect );
- element.removeEventListener( 'dispose', onDispose );
- this.disconnectDOM = null;
- };
- const onConnect = ( e ) => {
- this.dispatchEvent( new Event( 'connectChildren' ) );
- };
- const onDispose = () => {
- this.connect();
- };
- const onClick = ( e ) => {
- e.stopPropagation();
- this.connect();
- };
- this.disconnectDOM.addEventListener( 'mousedown', onClick, true );
- this.disconnectDOM.addEventListener( 'touchstart', onClick, true );
- this.disconnectDOM.addEventListener( 'disconnect', onDisconnect, true );
- element.addEventListener( 'connect', onConnect );
- element.addEventListener( 'connectChildren', onConnect );
- element.addEventListener( 'nodeConnect', onConnect );
- element.addEventListener( 'nodeConnectChildren', onConnect );
- element.addEventListener( 'dispose', onDispose );
- }
- }
- this.dispatchEvent( new Event( 'connect' ) );
- return this;
- }
- dispose() {
- this.dispatchEvent( new Event( 'dispose' ) );
- }
- serialize( data ) {
- const height = this.getHeight();
- const inputs = [];
- const links = [];
- for ( const input of this.inputs ) {
- inputs.push( input.toJSON( data ).id );
- }
- for ( const link of this.links ) {
- if ( link.inputElement !== null && link.outputElement !== null ) {
- links.push( link.outputElement.toJSON( data ).id );
- }
- }
- if ( this.inputLength > 0 ) data.inputLength = this.inputLength;
- if ( this.outputLength > 0 ) data.outputLength = this.outputLength;
- if ( inputs.length > 0 ) data.inputs = inputs;
- if ( links.length > 0 ) data.links = links;
- if ( this.style !== '' ) {
- data.style = this.style;
- }
- if ( height !== '' ) {
- data.height = height;
- }
- }
- deserialize( data ) {
- if ( data.inputLength !== undefined ) this.setInput( data.inputLength );
- if ( data.outputLength !== undefined ) this.setOutput( data.outputLength );
- if ( data.inputs !== undefined ) {
- const inputs = this.inputs;
- if ( inputs.length > 0 ) {
- let index = 0;
- for ( const id of data.inputs ) {
- data.objects[ id ] = inputs[ index ++ ];
- }
- } else {
- for ( const id of data.inputs ) {
- this.add( data.objects[ id ] );
- }
- }
- }
- if ( data.links !== undefined ) {
- for ( const id of data.links ) {
- this.connect( data.objects[ id ] );
- }
- }
- if ( data.style !== undefined ) {
- this.setStyle( data.style );
- }
- if ( data.height !== undefined ) {
- this.setHeight( data.height );
- }
- }
- get linkedExtra() {
- const linkedElement = this.linkedElement;
- return linkedElement ? linkedElement.getExtra() : null;
- }
- get linkedElement() {
- const link = this.link;
- return link ? link.outputElement : null;
- }
- get link() {
- return this.links[ 0 ];
- }
- _createIO( type ) {
- const { dom } = this;
- const ioDOM = document.createElement( 'f-io' );
- ioDOM.style.visibility = 'hidden';
- ioDOM.className = type;
- const onConnectEvent = ( e ) => {
- e.preventDefault();
- e.stopPropagation();
- selected = null;
- const nodeDOM = this.node.dom;
- nodeDOM.classList.add( 'io-connect' );
- ioDOM.classList.add( 'connect' );
- dom.classList.add( 'select' );
- const defaultOutput = Link.InputDirection === 'left' ? 'lio' : 'rio';
- const link = type === defaultOutput ? new Link( this ) : new Link( null, this );
- this.links.push( link );
- draggableDOM( e, ( data ) => {
- if ( data.dragging === false ) {
- nodeDOM.classList.remove( 'io-connect' );
- ioDOM.classList.remove( 'connect' );
- dom.classList.remove( 'select' );
- this.links.splice( this.links.indexOf( link ), 1 );
- if ( selected !== null ) {
- if ( type === defaultOutput ) {
- link.outputElement = selected;
- } else {
- link.inputElement = selected;
- }
- // check if is an is circular link
- if ( link.outputElement.node.isCircular( link.inputElement.node ) ) {
- return;
- }
- //
- if ( link.inputElement.inputLength > 0 && link.outputElement.outputLength > 0 ) {
- link.inputElement.connect( link.outputElement );
- }
- }
- }
- }, 'connecting' );
- };
- ioDOM.addEventListener( 'mousedown', onConnectEvent, true );
- ioDOM.addEventListener( 'touchstart', onConnectEvent, true );
- return ioDOM;
- }
- }
- Element.prototype.isElement = true;
- class Input extends Serializer {
- constructor( dom ) {
- super();
- this.dom = dom;
- this.element = null;
- this.extra = null;
- this.events = {
- 'change': [],
- 'click': []
- };
- this.addEventListener( 'change', ( ) => {
- dispatchEventList( this.events.change, this );
- } );
- this.addEventListener( 'click', ( ) => {
- dispatchEventList( this.events.click, this );
- } );
- }
- setExtra( value ) {
- this.extra = value;
- return this;
- }
- getExtra() {
- return this.extra;
- }
- setToolTip( text ) {
- const div = document.createElement( 'f-tooltip' );
- div.innerText = text;
- this.dom.appendChild( div );
- return this;
- }
- onChange( callback ) {
- this.events.change.push( callback );
- return this;
- }
- onClick( callback ) {
- this.events.click.push( callback );
- return this;
- }
- setValue( value, dispatch = true ) {
- this.dom.value = value;
- if ( dispatch ) this.dispatchEvent( new Event( 'change' ) );
- return this;
- }
- getValue() {
- return this.dom.value;
- }
- serialize( data ) {
- data.value = this.getValue();
- }
- deserialize( data ) {
- this.setValue( data.value );
- }
- }
- Input.prototype.isInput = true;
- class Node extends Serializer {
- constructor() {
- super();
- const dom = document.createElement( 'f-node' );
- const onDown = () => {
- const canvas = this.canvas;
- if ( canvas !== null ) {
- canvas.select( this );
- }
- };
- dom.addEventListener( 'mousedown', onDown, true );
- dom.addEventListener( 'touchstart', onDown, true );
- this._onConnect = ( e ) => {
- const { target } = e;
- for ( const element of this.elements ) {
- if ( element !== target ) {
- element.dispatchEvent( new Event( 'nodeConnect' ) );
- }
- }
- };
- this._onConnectChildren = ( e ) => {
- const { target } = e;
- for ( const element of this.elements ) {
- if ( element !== target ) {
- element.dispatchEvent( new Event( 'nodeConnectChildren' ) );
- }
- }
- };
- this.dom = dom;
- this.style = '';
- this.canvas = null;
- this.elements = [];
- this.events = {
- 'focus': [],
- 'blur': []
- };
- this.setPosition( 0, 0 );
- }
- onFocus( callback ) {
- this.events.focus.push( callback );
- return this;
- }
- onBlur( callback ) {
- this.events.blur.push( callback );
- return this;
- }
- setStyle( style ) {
- const dom = this.dom;
- if ( this.style ) dom.classList.remove( this.style );
- if ( style ) dom.classList.add( style );
- this.style = style;
- return this;
- }
- setPosition( x, y ) {
- const dom = this.dom;
- dom.style.left = toPX( x );
- dom.style.top = toPX( y );
- return this;
- }
- getPosition() {
- const dom = this.dom;
- return {
- x: parseInt( dom.style.left ),
- y: parseInt( dom.style.top )
- };
- }
- setWidth( val ) {
- this.dom.style.width = toPX( val );
- return this;
- }
- getWidth() {
- return this.dom.style.width;
- }
- add( element ) {
- this.elements.push( element );
- element.node = this;
- element.addEventListener( 'connect', this._onConnect );
- element.addEventListener( 'connectChildren', this._onConnectChildren );
- this.dom.appendChild( element.dom );
- return this;
- }
- remove( element ) {
- this.elements.splice( this.elements.indexOf( element ), 1 );
- element.node = null;
- element.removeEventListener( 'connect', this._onConnect );
- element.removeEventListener( 'connectChildren', this._onConnectChildren );
- this.dom.removeChild( element.dom );
- return this;
- }
- dispose() {
- const canvas = this.canvas;
- if ( canvas !== null ) canvas.remove( this );
- for ( const element of this.elements ) {
- element.dispose();
- }
- this.dispatchEvent( new Event( 'dispose' ) );
- }
- isCircular( node ) {
- if ( node === this ) return true;
- const links = this.getLinks();
- for ( const link of links ) {
- if ( link.outputElement.node.isCircular( node ) ) {
- return true;
- }
- }
- return false;
- }
- getLinks() {
- const links = [];
- for ( const element of this.elements ) {
- links.push( ...element.links );
- }
- return links;
- }
- serialize( data ) {
- const { x, y, style } = this.getPosition();
- const elements = [];
- for ( const element of this.elements ) {
- elements.push( element.toJSON( data ).id );
- }
- data.x = x;
- data.y = y;
- data.width = this.getWidth();
- data.elements = elements;
- if ( style !== '' ) {
- data.style = style;
- }
- }
- deserialize( data ) {
- this.setPosition( data.x, data.y );
- this.setWidth( data.width );
- if ( data.style !== undefined ) {
- this.setStyle( data.style );
- }
- const elements = this.elements;
- if ( elements.length > 0 ) {
- let index = 0;
- for ( const id of data.elements ) {
- data.objects[ id ] = elements[ index ++ ];
- }
- } else {
- for ( const id of data.elements ) {
- this.add( data.objects[ id ] );
- }
- }
- }
- }
- Node.prototype.isNode = true;
- const drawLine = ( p1x, p1y, p2x, p2y, invert, size, color, ctx ) => {
- const offset = 100 * ( invert ? - 1 : 1 );
- ctx.beginPath();
- ctx.moveTo( p1x, p1y );
- ctx.bezierCurveTo(
- p1x + offset, p1y,
- p2x - offset, p2y,
- p2x, p2y
- );
- ctx.lineWidth = size;
- ctx.strokeStyle = color;
- ctx.stroke();
- };
- const colors = [
- '#ff4444',
- '#44ff44',
- '#4444ff'
- ];
- class Canvas extends Serializer {
- constructor() {
- super();
- const dom = document.createElement( 'f-canvas' );
- const contentDOM = document.createElement( 'f-content' );
- const areaDOM = document.createElement( 'f-area' );
- const canvas = document.createElement( 'canvas' );
- const frontCanvas = document.createElement( 'canvas' );
- const context = canvas.getContext( '2d' );
- const frontContext = frontCanvas.getContext( '2d' );
- this.dom = dom;
- this.contentDOM = contentDOM;
- this.areaDOM = areaDOM;
- this.canvas = canvas;
- this.frontCanvas = frontCanvas;
- this.context = context;
- this.frontContext = frontContext;
- this.width = 10000;
- this.height = 10000;
- this.clientX = 0;
- this.clientY = 0;
- this.relativeClientX = 0;
- this.relativeClientY = 0;
- this.zoom = 1;
- this.nodes = [];
- this.selected = null;
- this.updating = false;
- frontCanvas.className = 'front';
- contentDOM.style.left = toPX( this.centerX );
- contentDOM.style.top = toPX( this.centerY );
- areaDOM.style.width = `calc( 100% + ${ this.width }px )`;
- areaDOM.style.height = `calc( 100% + ${ this.height }px )`;
- dom.appendChild( canvas );
- dom.appendChild( frontCanvas );
- dom.appendChild( contentDOM );
- dom.appendChild( areaDOM );
- /*
- let zoomTouchData = null;
- const onZoomStart = () => {
- zoomTouchData = null;
- };
- */
- const onZoom = ( e ) => {
- if ( e.touches ) {
- if ( e.touches.length === 2 ) {
- e.preventDefault();
- e.stopImmediatePropagation();
- /*
- const clientX = ( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;
- const clientY = ( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;
- const distance = Math.hypot(
- e.touches[ 0 ].clientX - e.touches[ 1 ].clientX,
- e.touches[ 0 ].clientY - e.touches[ 1 ].clientY
- );
- if ( zoomTouchData === null ) {
- zoomTouchData = {
- distance
- };
- }
- const delta = ( zoomTouchData.distance - distance );
- zoomTouchData.distance = distance;
- let zoom = Math.min( Math.max( this.zoom - delta * .01, .5 ), 1.2 );
- if ( zoom < .52 ) zoom = .5;
- else if ( zoom > .98 ) zoom = 1;
- contentDOM.style.left = toPX( this.centerX / zoom );
- contentDOM.style.top = toPX( this.centerY / zoom );
- contentDOM.style.zoom = this.zoom = zoom;
- */
- }
- } else {
- e.preventDefault();
- e.stopImmediatePropagation();
- /*
- const delta = e.deltaY / 100;
- const zoom = Math.min( Math.max( this.zoom - delta * .1, .5 ), 1 );
- contentDOM.style.left = toPX( this.centerX / zoom );
- contentDOM.style.top = toPX( this.centerY / zoom );
- contentDOM.style.zoom = this.zoom = zoom;
- */
- }
- };
- dom.addEventListener( 'wheel', onZoom );
- dom.addEventListener( 'touchmove', onZoom );
- //dom.addEventListener( 'touchstart', onZoomStart );
- draggableDOM( dom, ( data ) => {
- const { delta, isTouch } = data;
- if ( ! isTouch ) {
- if ( data.scrollTop === undefined ) {
- data.scrollLeft = dom.scrollLeft;
- data.scrollTop = dom.scrollTop;
- }
- dom.scrollLeft = data.scrollLeft - delta.x;
- dom.scrollTop = data.scrollTop - delta.y;
- }
- if ( data.dragging ) {
- dom.classList.add( 'grabbing' );
- } else {
- dom.classList.remove( 'grabbing' );
- }
- }, 'dragging-canvas' );
- this._onMoveEvent = ( e ) => {
- const event = e.touches ? e.touches[ 0 ] : e;
- const { zoom, rect } = this;
- this.clientX = event.clientX;
- this.clientY = event.clientY;
- this.relativeClientX = ( ( ( dom.scrollLeft - this.centerX ) + event.clientX ) - rect.left ) / zoom;
- this.relativeClientY = ( ( ( dom.scrollTop - this.centerY ) + event.clientY ) - rect.top ) / zoom;
- };
- this._onContentLoaded = () => {
- this.centralize();
- };
- this._onUpdate = () => {
- this.update();
- };
- this.start();
- }
- get rect() {
- return this.dom.getBoundingClientRect();
- }
- get relativeX() {
- return this.dom.scrollLeft - this.centerX;
- }
- get relativeY() {
- return this.dom.scrollTop - this.centerY;
- }
- get centerX() {
- return this.width / 2;
- }
- get centerY() {
- return this.height / 2;
- }
- start() {
- this.updating = true;
- document.addEventListener( 'wheel', this._onMoveEvent, true );
- document.addEventListener( 'mousedown', this._onMoveEvent, true );
- document.addEventListener( 'touchstart', this._onMoveEvent, true );
- document.addEventListener( 'mousemove', this._onMoveEvent, true );
- document.addEventListener( 'touchmove', this._onMoveEvent, true );
- document.addEventListener( 'DOMContentLoaded', this._onContentLoaded );
- requestAnimationFrame( this._onUpdate );
- }
- stop() {
- this.updating = false;
- document.removeEventListener( 'wheel', this._onMoveEvent, true );
- document.removeEventListener( 'mousedown', this._onMoveEvent, true );
- document.removeEventListener( 'touchstart', this._onMoveEvent, true );
- document.removeEventListener( 'mousemove', this._onMoveEvent, true );
- document.removeEventListener( 'touchmove', this._onMoveEvent, true );
- document.removeEventListener( 'DOMContentLoaded', this._onContentLoaded );
- }
- add( node ) {
- this.nodes.push( node );
- node.canvas = this;
- this.contentDOM.appendChild( node.dom );
- return this;
- }
- remove( node ) {
- if ( node === this.selected ) {
- this.select();
- }
- this.unlink( node );
- const nodes = this.nodes;
- nodes.splice( nodes.indexOf( node ), 1 );
- node.canvas = null;
- this.contentDOM.removeChild( node.dom );
- return this;
- }
- clear() {
- const nodes = this.nodes;
- while ( nodes.length > 0 ) {
- this.remove( nodes[ 0 ] );
- }
- return this;
- }
- unlink( node ) {
- const links = this.getLinks();
- for ( const link of links ) {
- if ( link.outputElement && link.outputElement.node === node ) {
- link.inputElement.connect();
- }
- }
- }
- getLinks() {
- const links = [];
- for ( const node of this.nodes ) {
- links.push( ...node.getLinks() );
- }
- return links;
- }
- centralize() {
- this.dom.scroll( this.centerX, this.centerY );
- return this;
- }
- select( node = null ) {
- if ( node === this.selected ) return;
- const previousNode = this.selected;
- if ( previousNode !== null ) {
- previousNode.dom.classList.remove( 'selected' );
- this.selected = null;
- dispatchEventList( previousNode.events.blur, previousNode );
- }
- if ( node !== null ) {
- node.dom.classList.add( 'selected' );
- this.selected = node;
- dispatchEventList( node.events.focus, node );
- }
- }
- update() {
- if ( this.updating === false ) return;
- requestAnimationFrame( this._onUpdate );
- const { dom, zoom, canvas, frontCanvas, frontContext, context } = this;
- const width = window.innerWidth;
- const height = window.innerHeight;
- const domRect = this.rect;
- if ( canvas.width !== width || canvas.height !== height ) {
- canvas.width = width;
- canvas.height = height;
- frontCanvas.width = width;
- frontCanvas.height = height;
- }
- context.clearRect( 0, 0, width, height );
- frontContext.clearRect( 0, 0, width, height );
- context.globalCompositeOperation = 'lighter';
- frontContext.globalCompositeOperation = 'source-over';
- const links = this.getLinks();
- const aPos = { x: 0, y: 0 };
- const bPos = { x: 0, y: 0 };
- const offsetIORadius = 10;
- let dragging = '';
- for ( const link of links ) {
- const { lioElement, rioElement } = link;
- let draggingLink = '';
- let length = 0;
- if ( lioElement !== null ) {
- const rect = lioElement.dom.getBoundingClientRect();
- length = Math.max( length, lioElement.rioLength );
- aPos.x = rect.x + rect.width;
- aPos.y = rect.y + ( rect.height / 2 );
- } else {
- aPos.x = this.clientX;
- aPos.y = this.clientY;
- draggingLink = 'lio';
- }
- if ( rioElement !== null ) {
- const rect = rioElement.dom.getBoundingClientRect();
- length = Math.max( length, rioElement.lioLength );
- bPos.x = rect.x;
- bPos.y = rect.y + ( rect.height / 2 );
- } else {
- bPos.x = this.clientX;
- bPos.y = this.clientY;
- draggingLink = 'rio';
- }
- dragging = dragging || draggingLink;
- const drawContext = draggingLink ? frontContext : context;
- if ( draggingLink || length === 1 ) {
- if ( draggingLink === 'rio' ) {
- aPos.x += offsetIORadius;
- bPos.x /= zoom;
- bPos.y /= zoom;
- } else if ( draggingLink === 'lio' ) {
- bPos.x -= offsetIORadius;
- aPos.x /= zoom;
- aPos.y /= zoom;
- }
- drawLine(
- aPos.x * zoom, aPos.y * zoom,
- bPos.x * zoom, bPos.y * zoom,
- false, 2, '#ffffff', drawContext
- );
- } else {
- length = Math.min( length, 4 );
- for ( let i = 0; i < length; i ++ ) {
- const color = colors[ i ] || '#ffffff';
- const marginY = 4;
- const rioLength = Math.min( lioElement.rioLength, length );
- const lioLength = Math.min( rioElement.lioLength, length );
- const aCenterY = ( ( rioLength * marginY ) * .5 ) - ( marginY / 2 );
- const bCenterY = ( ( lioLength * marginY ) * .5 ) - ( marginY / 2 );
- const aIndex = Math.min( i, rioLength - 1 );
- const bIndex = Math.min( i, lioLength - 1 );
- const aPosY = aIndex * marginY;
- const bPosY = bIndex * marginY;
- drawLine(
- aPos.x * zoom, ( ( aPos.y + aPosY ) - aCenterY ) * zoom,
- bPos.x * zoom, ( ( bPos.y + bPosY ) - bCenterY ) * zoom,
- false, 2, color, drawContext
- );
- }
- }
- }
- context.globalCompositeOperation = 'destination-in';
- context.fillRect( domRect.x, domRect.y, domRect.width, domRect.height );
- if ( dragging !== '' ) {
- dom.classList.add( 'dragging-' + dragging );
- } else {
- dom.classList.remove( 'dragging-lio' );
- dom.classList.remove( 'dragging-rio' );
- }
- }
- serialize( data ) {
- const nodes = [];
- for ( const node of this.nodes ) {
- nodes.push( node.toJSON( data ).id );
- }
- data.nodes = nodes;
- }
- deserialize( data ) {
- for ( const id of data.nodes ) {
- this.add( data.objects[ id ] );
- }
- }
- }
- class ButtonInput extends Input {
- constructor( innterText = '' ) {
- const dom = document.createElement( 'button' );
- const spanDOM = document.createElement( 'span' );
- dom.appendChild( spanDOM );
- const iconDOM = document.createElement( 'i' );
- dom.appendChild( iconDOM );
- super( dom );
- this.spanDOM = spanDOM;
- this.iconDOM = iconDOM;
- spanDOM.innerText = innterText;
- dom.onmouseover = () => {
- this.dispatchEvent( new Event( 'mouseover' ) );
- };
- dom.onclick = dom.ontouchstart = ( e ) => {
- e.preventDefault();
- e.stopPropagation();
- this.dispatchEvent( new Event( 'click' ) );
- };
- }
- setIcon( className ) {
- this.iconDOM.className = className;
- return this;
- }
- setValue( val ) {
- this.spanDOM.innerText = val;
- return this;
- }
- getValue() {
- return this.spanDOM.innerText;
- }
- }
- class DraggableElement extends Element {
- constructor( draggable = true ) {
- super( true );
- this.draggable = draggable;
- const onDrag = ( e ) => {
- e.preventDefault();
- if ( this.draggable === true ) {
- draggableDOM( this.node.dom );
- }
- };
- const { dom } = this;
- dom.addEventListener( 'mousedown', onDrag, true );
- dom.addEventListener( 'touchstart', onDrag, true );
- }
- }
- class TitleElement extends DraggableElement {
- constructor( title, draggable = true ) {
- super( draggable );
- const { dom } = this;
- dom.className = 'title';
- const spanDOM = document.createElement( 'span' );
- spanDOM.innerText = title;
- const iconDOM = document.createElement( 'i' );
- const toolbarDOM = document.createElement( 'f-toolbar' );
- this.buttons = [];
- this.spanDOM = spanDOM;
- this.iconDOM = iconDOM;
- this.toolbarDOM = toolbarDOM;
- dom.appendChild( spanDOM );
- dom.appendChild( iconDOM );
- dom.appendChild( toolbarDOM );
- }
- setIcon( value ) {
- this.iconDOM.className = value;
- return this;
- }
- getIcon() {
- return this.iconDOM.className;
- }
- setTitle( value ) {
- this.spanDOM.innerText = value;
- return this;
- }
- getTitle() {
- return this.spanDOM.innerText;
- }
- addButton( button ) {
- this.buttons.push( button );
- this.toolbarDOM.appendChild( button.dom );
- return this;
- }
- serialize( data ) {
- super.serialize( data );
- const title = this.getTitle();
- const icon = this.getIcon();
- data.title = title;
- if ( icon !== '' ) {
- data.icon = icon;
- }
- }
- deserialize( data ) {
- super.deserialize( data );
- this.setTitle( data.title );
- if ( data.icon !== undefined ) {
- this.setIcon( data.icon );
- }
- }
- }
- class ObjectNode extends Node {
- constructor( name, inputLength, extra = null, width = 300 ) {
- super();
- this.setWidth( width );
- const title = new TitleElement( name )
- .setExtra( extra )
- .setOutput( inputLength );
- const closeButton = new ButtonInput( '✖' ).onClick( () => {
- this.dispose();
- } );
- title.addButton( closeButton );
- this.add( title );
- this.title = title;
- this.closeButton = closeButton;
- }
- setExtra( value ) {
- this.title.setExtra( value );
- return this;
- }
- getExtra( value ) {
- return this.title.getExtra();
- }
- invalidate() {
- this.title.dispatchEvent( new Event( 'connect' ) );
- }
- }
- const ENTER_KEY$1 = 13;
- class StringInput extends Input {
- constructor( value = '' ) {
- const dom = document.createElement( 'input' );
- super( dom );
- dom.type = 'text';
- dom.value = value;
- dom.spellcheck = false;
- dom.autocomplete = 'off';
- dom.onblur = () => {
- this.dispatchEvent( new Event( 'blur' ) );
- };
- dom.onchange = () => {
- this.dispatchEvent( new Event( 'change' ) );
- };
- dom.onkeyup = ( e ) => {
- if ( e.keyCode === ENTER_KEY$1 ) {
- e.target.blur();
- }
- e.stopPropagation();
- this.dispatchEvent( new Event( 'change' ) );
- };
- }
- }
- const ENTER_KEY = 13;
- class NumberInput extends Input {
- constructor( value = 0, min = - Infinity, max = Infinity, step = .01 ) {
- const dom = document.createElement( 'input' );
- super( dom );
- this.min = min;
- this.max = max;
- this.step = step;
- this.integer = false;
- dom.type = 'text';
- dom.className = 'number';
- dom.value = this._getString( value );
- dom.spellcheck = false;
- dom.autocomplete = 'off';
- dom.ondragstart = dom.oncontextmenu = ( e ) => {
- e.preventDefault();
- e.stopPropagation();
- };
- dom.onfocus = dom.onclick = () => {
- dom.select();
- };
- dom.onblur = () => {
- this.dispatchEvent( new Event( 'blur' ) );
- };
- dom.onchange = () => {
- this.dispatchEvent( new Event( 'change' ) );
- };
- dom.onkeydown = ( e ) => {
- if ( e.key.length === 1 && /\d|\./.test( e.key ) !== true ) {
- return false;
- }
- if ( e.keyCode === ENTER_KEY ) {
- e.target.blur();
- }
- e.stopPropagation();
- };
- draggableDOM( dom, ( data ) => {
- const { delta } = data;
- if ( data.value === undefined ) {
- data.value = this.getValue();
- }
- const diff = delta.x - delta.y;
- const value = data.value + ( diff * this.step );
- this.dom.value = this._getString( value.toFixed( this.precision ) );
- this.dispatchEvent( new Event( 'change' ) );
- } );
- }
- setRange( min, max, step ) {
- this.min = min;
- this.max = max;
- this.step = step;
- this.dispatchEvent( new Event( 'range' ) );
- return this.setValue( this.getValue() );
- }
- get precision() {
- if ( this.integer === true ) return 0;
- const fract = this.step % 1;
- return fract !== 0 ? fract.toString().split( '.' )[ 1 ].length : 1;
- }
- setValue( val, dispatch = true ) {
- return super.setValue( this._getString( val ), dispatch );
- }
- getValue() {
- return Number( this.dom.value );
- }
- serialize( data ) {
- const { min, max } = this;
- if ( min !== - Infinity && max !== Infinity ) {
- data.min = this.min;
- data.max = this.max;
- data.step = this.step;
- }
- super.serialize( data );
- }
- deserialize( data ) {
- if ( data.min !== undefined ) {
- const { min, max, step } = this;
- this.setRange( min, max, step );
- }
- super.deserialize( data );
- }
- _getString( value ) {
- let num = Math.min( Math.max( Number( value ), this.min ), this.max );
- if ( this.integer === true ) {
- return Math.floor( num );
- } else {
- return num + ( num % 1 ? '' : '.0' );
- }
- }
- }
- const getStep = ( min, max ) => {
- const sensibility = .001;
- return ( max - min ) * sensibility;
- };
- class SliderInput extends Input {
- constructor( value = 0, min = 0, max = 100 ) {
- const dom = document.createElement( 'f-subinputs' );
- super( dom );
- value = Math.min( Math.max( value, min ), max );
- const step = getStep( min, max );
- const rangeDOM = document.createElement( 'input' );
- rangeDOM.type = 'range';
- rangeDOM.min = min;
- rangeDOM.max = max;
- rangeDOM.step = step;
- rangeDOM.value = value;
- const field = new NumberInput( value, min, max, step );
- field.dom.className = 'range-value';
- field.onChange( () => {
- rangeDOM.value = field.getValue();
- } );
- field.addEventListener( 'range', () => {
- rangeDOM.min = field.min;
- rangeDOM.max = field.max;
- rangeDOM.step = field.step;
- rangeDOM.value = field.getValue();
- } );
- dom.appendChild( rangeDOM );
- dom.appendChild( field.dom );
- this.rangeDOM = rangeDOM;
- this.field = field;
- const updateRangeValue = () => {
- let value = Number( rangeDOM.value );
- if ( value !== this.max && value + this.step >= this.max ) {
- // fix not end range fraction
- rangeDOM.value = value = this.max;
- }
- this.field.setValue( value );
- };
- draggableDOM( rangeDOM, () => {
- updateRangeValue();
- this.dispatchEvent( new Event( 'change' ) );
- }, '' );
- }
- get min() {
- return this.field.min;
- }
- get max() {
- return this.field.max;
- }
- get step() {
- return this.field.step;
- }
- setRange( min, max ) {
- this.field.setRange( min, max, getStep( min, max ) );
- this.dispatchEvent( new Event( 'range' ) );
- this.dispatchEvent( new Event( 'change' ) );
- return this;
- }
- setValue( val, dispatch = true ) {
- this.field.setValue( val );
- this.rangeDOM.value = val;
- if ( dispatch ) this.dispatchEvent( new Event( 'change' ) );
- return this;
- }
- getValue() {
- return this.field.getValue();
- }
- serialize( data ) {
- data.min = this.min;
- data.max = this.max;
- super.serialize( data );
- }
- deserialize( data ) {
- const { min, max } = data;
- this.setRange( min, max );
- super.deserialize( data );
- }
- }
- class ColorInput extends Input {
- constructor( value = 0x0099ff ) {
- const dom = document.createElement( 'input' );
- super( dom );
- dom.type = 'color';
- dom.value = toHex( value );
- dom.oninput = () => {
- this.dispatchEvent( new Event( 'change' ) );
- };
- }
- setValue( value, dispatch = true ) {
- return super.setValue( toHex( value ), dispatch );
- }
- getValue() {
- return parseInt( super.getValue().substr( 1 ), 16 );
- }
- }
- class TextInput extends Input {
- constructor( innerText = '' ) {
- const dom = document.createElement( 'textarea' );
- super( dom );
- dom.innerText = innerText;
- }
- setValue( val ) {
- this.dom.innerText = val;
- return this;
- }
- getValue() {
- return this.dom.innerText;
- }
- }
- class LabelElement extends Element {
- constructor( label = '', align = '' ) {
- super();
- this.labelDOM = document.createElement( 'f-label' );
- this.inputsDOM = document.createElement( 'f-inputs' );
- const spanDOM = document.createElement( 'span' );
- const iconDOM = document.createElement( 'i' );
- this.spanDOM = spanDOM;
- this.iconDOM = iconDOM;
- this.labelDOM.appendChild( this.spanDOM );
- this.labelDOM.appendChild( this.iconDOM );
- this.dom.appendChild( this.labelDOM );
- this.dom.appendChild( this.inputsDOM );
- this.setLabel( label );
- this.setAlign( align );
- }
- setIcon( value ) {
- this.iconDOM.className = value;
- return this;
- }
- getIcon() {
- return this.iconDOM.className;
- }
- setAlign( align ) {
- this.labelDOM.className = align;
- }
- setLabel( val ) {
- this.spanDOM.innerText = val;
- }
- getLabel() {
- return this.spanDOM.innerText;
- }
- serialize( data ) {
- super.serialize( data );
- const label = this.getLabel();
- const icon = this.getIcon();
- data.label = label;
- if ( icon !== '' ) {
- data.icon = icon;
- }
- }
- deserialize( data ) {
- super.deserialize( data );
- this.setLabel( data.label );
- if ( data.icon !== undefined ) {
- this.setIcon( data.icon );
- }
- }
- }
- class PanelNode extends Node {
- constructor( title = 'Panel', align = 'top-right' ) {
- super();
- const titleElement = new TitleElement( title );
- this.add( titleElement );
- const collapseButton = new ButtonInput( '🗕' );
- collapseButton.onClick( () => {
- this.setCollapse( ! this.collapsed );
- } );
- titleElement.addButton( collapseButton );
- this.collapseButton = collapseButton;
- this.titleElement = titleElement;
- this.align = align;
- this.collapsed = false;
- this.setAlign( align );
- this.setStyle( 'rouded' );
- }
- setCollapse( value ) {
- const cssClass = 'closed';
- this.dom.classList.remove( cssClass );
- this.collapsed = value;
- this.collapseButton.value = value ? '🗖' : '🗕';
- if ( value === true ) {
- this.dom.classList.add( cssClass );
- }
- return this;
- }
- setAlign( align ) {
- if ( this.align ) this.dom.classList.remove( this.align );
- this.dom.classList.add( align );
- this.align = align;
- return this;
- }
- addInput( inputClass, object, property, ...params ) {
- const value = object[ property ];
- const input = new inputClass( value, ...params );
- input.onChange( () => {
- object[ property ] = input.value;
- } );
- this.add( new LabelElement( property ).add( input ) );
- return input;
- }
- addSlider( object, property, min, max ) {
- return this.addInput( SliderInput, object, property, min, max );
- }
- addNumber( object, property ) {
- return this.addInput( NumberInput, object, property );
- }
- addColor( object, property ) {
- return this.addInput( ColorInput, object, property );
- }
- addString( object, property ) {
- return this.addInput( StringInput, object, property );
- }
- addText( object, property ) {
- const input = this.addInput( TextInput, object, property );
- input.element.setHeight( 70 );
- return input;
- }
- addButton( name ) {
- const input = new ButtonInput( name );
- this.add( new Element().setHeight( 34 ).add( input ) );
- return input;
- }
- }
- class Menu extends EventTarget {
- constructor( className, target = null ) {
- super();
- const dom = document.createElement( 'f-menu' );
- dom.className = className + ' hidden';
- this.dom = dom;
- this.visible = false;
- this.subMenus = new WeakMap();
- this.domButtons = new WeakMap();
- this.events = {
- 'context': []
- };
- this.addEventListener( 'context', ( ) => {
- dispatchEventList( this.events.context, this );
- } );
- this._lastButtonClick = null;
- this._onButtonClick = ( e = null ) => {
- const button = e ? e.target : null;
- if ( this._lastButtonClick ) {
- this._lastButtonClick.dom.parentElement.classList.remove( 'active' );
- }
- this._lastButtonClick = button;
- if ( button ) {
- if ( this.subMenus.has( button ) ) {
- this.subMenus.get( button )._onButtonClick();
- }
- button.dom.parentElement.classList.add( 'active' );
- }
- };
- this._onButtonMouseOver = ( e ) => {
- const button = e.target;
- if ( this.subMenus.has( button ) && this._lastButtonClick !== button ) {
- this._onButtonClick();
- }
- };
- this.setTarget( target );
- }
- onContext( callback ) {
- this.events.context.push( callback );
- return this;
- }
- show( x = null, y = null ) {
- this._onButtonClick();
- if ( x !== null && y !== null ) {
- this.setPosition( x, y );
- }
- this.dom.classList.remove( 'hidden' );
- this.visible = true;
- this.dispatchEvent( new Event( 'show' ) );
- return this;
- }
- hide() {
- this.dom.classList.add( 'hidden' );
- this.dispatchEvent( new Event( 'hide' ) );
- this.visible = false;
- }
- setTarget( target = null ) {
- if ( target !== null ) {
- const onContextMenu = ( e ) => {
- e.preventDefault();
- if ( e.pointerType !== 'mouse' || ( e.pageX === 0 && e.pageY === 0 ) ) return;
- const rect = this.target.getBoundingClientRect();
- this.dispatchEvent( new Event( 'context' ) );
- this.show( e.pageX - rect.left, e.pageY - rect.top );
- };
- const onDown = ( e ) => {
- if ( this.visible === true && e.target.closest( 'f-menu' ) === null ) {
- this.hide();
- }
- };
- this.target = target;
- target.addEventListener( 'mousedown', onDown, true );
- target.addEventListener( 'touchstart', onDown, true );
- target.addEventListener( 'contextmenu', onContextMenu, false );
- target.appendChild( this.dom );
- }
- return this;
- }
- add( button, submenu = null ) {
- const liDOM = document.createElement( 'f-item' );
- if ( submenu !== null ) {
- liDOM.classList.add( 'submenu' );
- liDOM.appendChild( submenu.dom );
- this.subMenus.set( button, submenu );
- }
- liDOM.appendChild( button.dom );
- button.addEventListener( 'click', this._onButtonClick );
- button.addEventListener( 'mouseover', this._onButtonMouseOver );
- this.dom.appendChild( liDOM );
- this.domButtons.set( liDOM, button );
- return this;
- }
- setPosition( x, y ) {
- const dom = this.dom;
- dom.style.left = toPX( x );
- dom.style.top = toPX( y );
- return this;
- }
- }
- let lastContext = null;
- class ContextMenu extends Menu {
- constructor( target = null ) {
- super( 'context', target );
- }
- show( x, y ) {
- if ( lastContext !== null ) {
- lastContext.hide();
- }
- lastContext = this;
- return super.show( x, y );
- }
- hide() {
- if ( lastContext === this ) {
- lastContext = null;
- }
- return super.hide();
- }
- }
- class CircleMenu extends Menu {
- constructor( target = null ) {
- super( 'circle', target );
- }
-
- }
- class SelectInput extends Input {
- constructor( options = [] ) {
- const dom = document.createElement( 'select' );
- super( dom );
- dom.onchange = () => {
- this.dispatchEvent( new Event( 'change' ) );
- };
- this.setOptions( options );
- }
- setOptions( options ) {
- const dom = this.dom;
- this.options = options;
- dom.innerHTML = '';
- for ( let index = 0; index < options.length; index ++ ) {
- let opt = options[ index ];
- if ( typeof opt === 'string' ) {
- opt = { name: opt, value: index };
- }
- const option = document.createElement( 'option' );
- option.innerText = opt.name;
- option.value = opt.value;
- dom.appendChild( option );
- }
- return this;
- }
- getOptions() {
- return this._options;
- }
- serialize( data ) {
- data.options = [ ...this.options ];
- super.serialize( data );
- }
- deserialize( data ) {
- const currentOptions = this.options;
- if ( currentOptions.length > 0 ) {
- this.setOptions( data.options );
- }
- super.deserialize( data );
- }
- }
- class ToggleInput extends Input {
- constructor( value = false ) {
- const dom = document.createElement( 'input' );
- super( dom );
- dom.type = 'checkbox';
- dom.className = 'toggle';
- dom.checked = value;
- }
- setValue( val ) {
- this.dom.checked = val;
- this.dispatchEvent( new Event( 'change' ) );
- return this;
- }
- getValue() {
- return this.dom.checked;
- }
- }
- var Flow = /*#__PURE__*/Object.freeze({
- __proto__: null,
- Element: Element,
- Input: Input,
- Node: Node,
- Canvas: Canvas,
- Serializer: Serializer,
- ObjectNode: ObjectNode,
- PanelNode: PanelNode,
- Menu: Menu,
- ContextMenu: ContextMenu,
- CircleMenu: CircleMenu,
- DraggableElement: DraggableElement,
- LabelElement: LabelElement,
- TitleElement: TitleElement,
- ButtonInput: ButtonInput,
- ColorInput: ColorInput,
- NumberInput: NumberInput,
- SelectInput: SelectInput,
- SliderInput: SliderInput,
- StringInput: StringInput,
- TextInput: TextInput,
- ToggleInput: ToggleInput
- });
- class Loader extends EventTarget {
- constructor( parseType = Loader.DEFAULT ) {
- super();
- this.parseType = parseType;
- this.events = {
- 'load': []
- };
- }
- setParseType( type ) {
- this.parseType = type;
- return this;
- }
- getParseType() {
- return this.parseType;
- }
- onLoad( callback ) {
- this.events.load.push( callback );
- return this;
- }
- async load( url, lib = null ) {
- return await fetch( url )
- .then( response => response.json() )
- .then( result => {
- this.data = this.parse( result, lib );
- dispatchEventList( this.events.load, this );
- return this.data;
- } )
- .catch( err => {
- console.error( 'Loader:', err );
- } );
- }
- parse( json, lib = null ) {
- json = this._parseObjects( json, lib );
- const parseType = this.parseType;
- if ( parseType === Loader.DEFAULT ) {
- const flowObj = new Flow[ json.type ]();
- if ( flowObj.getSerializable() ) {
- flowObj.deserialize( json );
- }
- return flowObj;
- } else if ( parseType === Loader.OBJECTS ) {
- return json;
- }
- }
- _parseObjects( json, lib = null ) {
- json = { ...json };
- const objects = {};
- for ( const id in json.objects ) {
- const obj = json.objects[ id ];
- obj.objects = objects;
- const Class = lib && lib[ obj.type ] ? lib[ obj.type ] : Flow[ obj.type ];
- objects[ id ] = new Class();
- }
- const ref = new WeakMap();
- const deserializePass = ( prop = null ) => {
- for ( const id in json.objects ) {
- const newObject = objects[ id ];
- if ( ref.has( newObject ) === false && ( prop === null || newObject[ prop ] === true ) ) {
- ref.set( newObject, true );
- if ( newObject.getSerializable() ) {
- newObject.deserialize( json.objects[ id ] );
- }
- }
- }
- };
- deserializePass( 'isNode' );
- deserializePass( 'isElement' );
- deserializePass( 'isInput' );
- deserializePass();
- json.objects = objects;
- return json;
- }
- }
- Loader.DEFAULT = 'default';
- Loader.OBJECTS = 'objects';
- export { ButtonInput, Canvas, CircleMenu, ColorInput, ContextMenu, DraggableElement, Element, Input, LabelElement, Loader, Menu, Node, NumberInput, ObjectNode, PanelNode, REVISION, SelectInput, Serializer, SliderInput, StringInput, TextInput, TitleElement, ToggleInput, Utils };
|