Editor.js 183 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. (function()
  6. {
  7. /**
  8. * Specifies the app name. Default is document.title.
  9. */
  10. Editor.prototype.appName = 'draw.io';
  11. /**
  12. * Known extensions for own files.
  13. */
  14. Editor.prototype.fileExtensions = [
  15. {ext: 'html', title: 'filetypeHtml'},
  16. {ext: 'png', title: 'filetypePng'},
  17. {ext: 'svg', title: 'filetypeSvg'}];
  18. /**
  19. * Used in the GraphViewer lightbox.
  20. */
  21. Editor.closeImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/delete.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAApVBMVEUAAAD////k5OT///8AAAB1dXXMzMz9/f39/f37+/v5+fn+/v7///9iYmJaWlqFhYWnp6ejo6OHh4f////////////////7+/v5+fnx8fH///8AAAD///8bGxv7+/v5+fkoKCghISFDQ0MYGBjh4eHY2Njb29tQUFBvb29HR0c/Pz82NjYrKyu/v78SEhLu7u7s7OzV1dVVVVU7OzsVFRXAv78QEBBzqehMAAAAG3RSTlMAA/7p/vz5xZlrTiPL/v78+/v7+OXd2TYQDs8L70ZbAAABKUlEQVQoz3VS13LCMBBUXHChd8iukDslQChJ/v/TchaG4cXS+OSb1c7trU7V60OpdRz2ZtNZL4zXNlcN8BEtSG6+NxIXkeRPoBuQ1cjvZ31/VJFB10ISli6diYfH8iYO3WUNCcNlB0gTrXOtkxTo0O1aKKiBBMhhv2MNBQKoiA5wxlZo0JDzD3AYKbWacyj3fs01wxey0pyEP+R8pWKWXoqtIZ0DDg5pbki9krEKOa6LVDQsdoXEsi46Zqh69KFz7B1u7Hb2yDV8firXDKBlZ4UFiswKGRhXTS93/ECK7yxnJ3+S3y/ThpO+cfSD017nqa18aasabU0/t7d+tk0/1oMEJ1NaD67iwdF68OabFSLn+eHb0+vjy+uk8br9fdrftH0O2menfd7+AQfYM/lNjoDHAAAAAElFTkSuQmCC';
  22. /**
  23. *
  24. */
  25. Editor.plusImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/plus.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MDdCMTdENjVCOEM4MTFFNDlCRjVBNDdCODU5NjNBNUMiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MDdCMTdENjZCOEM4MTFFNDlCRjVBNDdCODU5NjNBNUMiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDowN0IxN0Q2M0I4QzgxMUU0OUJGNUE0N0I4NTk2M0E1QyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDowN0IxN0Q2NEI4QzgxMUU0OUJGNUE0N0I4NTk2M0E1QyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PtjrjmgAAAAtSURBVHjaYvz//z8DMigvLwcLdHZ2MiKLMzEQCaivkLGsrOw/dU0cAr4GCDAARQsQbTFrv10AAAAASUVORK5CYII=';
  26. /**
  27. *
  28. */
  29. Editor.spinImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/spin.gif' : 'data:image/gif;base64,R0lGODlhDAAMAPUxAEVriVp7lmCAmmGBm2OCnGmHn3OPpneSqYKbr4OcsIScsI2kto6kt46lt5KnuZmtvpquvpuvv56ywaCzwqK1xKu7yay9yq+/zLHAzbfF0bjG0bzJ1LzK1MDN18jT28nT3M3X3tHa4dTc49Xd5Njf5dng5t3k6d/l6uDm6uru8e7x8/Dz9fT29/b4+Pj5+fj5+vr6+v///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkKADEAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAADAAMAAAGR8CYcEgsOgYAIax4CCQuQldrCBEsiK8VS2hoFGOrlJDA+cZQwkLnqyoJFZKviSS0ICrE0ec0jDAwIiUeGyBFGhMPFBkhZo1BACH5BAkKAC4ALAAAAAAMAAwAhVB0kFR3k1V4k2CAmmWEnW6Lo3KOpXeSqH2XrIOcsISdsImhtIqhtJCmuJGnuZuwv52wwJ+ywZ+ywqm6yLHBzbLCzrXEz7fF0LnH0rrI0r7L1b/M1sXR2cfT28rV3czW3s/Z4Nfe5Nvi6ODm6uLn6+Ln7OLo7OXq7efs7+zw8u/y9PDy9PX3+Pr7+////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZDQJdwSCxGDAIAoVFkFBwYSyIwGE4OkCJxIdG6WkJEx8sSKj7elfBB0a5SQg1EQ0SVVMPKhDM6iUIkRR4ZFxsgJl6JQQAh+QQJCgAxACwAAAAADAAMAIVGa4lcfZdjgpxkg51nhp5ui6N3kqh5lKqFnbGHn7KIoLOQp7iRp7mSqLmTqbqarr6br7+fssGitcOitcSuvsuuv8uwwMyzw861xNC5x9K6x9K/zNbDztjE0NnG0drJ1NzQ2eDS2+LT2+LV3ePZ4Oba4ebb4ufc4+jm6+7t8PLt8PPt8fPx8/Xx9PX09vf19/j3+Pn///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQ8CYcEgsUhQFggFSjCQmnE1jcBhqGBXiIuAQSi7FGEIgfIzCFoCXFCZiPO0hKBMiwl7ET6eUYqlWLkUnISImKC1xbUEAIfkECQoAMgAsAAAAAAwADACFTnKPT3KPVHaTYoKcb4yjcY6leZSpf5mtgZuvh5+yiqG0i6K1jqW3kae5nrHBnrLBn7LCoLPCobTDqbrIqrvIs8LOtMPPtcPPtcTPuMbRucfSvcrUvsvVwMzWxdHaydTcytXdzNbezdff0drh2ODl2+Ln3eTp4Obq4ujs5Ont5uvu6O3w6u7w6u7x7/L09vj5+vr7+vv7////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABkdAmXBILHIcicOCUqxELKKPxKAYgiYd4oMAEWo8RVmjIMScwhmBcJMKXwLCECmMGAhPI1QRwBiaSixCMDFhLSorLi8wYYxCQQAh+QQJCgAxACwAAAAADAAMAIVZepVggJphgZtnhp5vjKN2kah3kqmBmq+KobSLorWNpLaRp7mWq7ybr7+gs8KitcSktsWnuManucexwM2ywc63xtG6yNO9ytS+ytW/zNbDz9jH0tvL1d3N197S2+LU3OPU3ePV3eTX3+Xa4efb4ufd5Onl6u7r7vHs7/Lt8PLw8/Xy9Pby9fb09ff2+Pn3+Pn6+vr///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGSMCYcEgseiwSR+RS7GA4JFGF8RiWNiEiJTERgkjFGAQh/KTCGoJwpApnBkITKrwoCFWnFlEhaAxXLC9CBwAGRS4wQgELYY1CQQAh+QQJCgAzACwAAAAADAAMAIVMcI5SdZFhgZtti6JwjaR4k6mAma6Cm6+KobSLorWLo7WNo7aPpredsMCescGitMOitcSmuMaqu8ixwc2zws63xdC4xtG5x9K9ytXAzdfCztjF0NnF0drK1d3M1t7P2N/P2eDT2+LX3+Xe5Onh5+vi5+vj6Ozk6e3n7O/o7O/q7vHs7/Lt8PPu8fPx8/X3+Pn6+vv7+/v8/Pz///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGRcCZcEgsmkIbTOZTLIlGqZNnchm2SCgiJ6IRqljFmQUiXIVnoITQde4chC9Y+LEQxmTFRkFSNFAqDAMIRQoCAAEEDmeLQQAh+QQJCgAwACwAAAAADAAMAIVXeZRefplff5lhgZtph59yjqV2kaeAmq6FnbGFnrGLorWNpLaQp7mRqLmYrb2essGgs8Klt8apusitvcquv8u2xNC7yNO8ydS8ytTAzdfBzdfM1t7N197Q2eDU3OPX3+XZ4ObZ4ebc4+jf5erg5erg5uvp7fDu8fPv8vTz9fb09vf19/j3+Pn4+fn5+vr6+/v///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGRUCYcEgspkwjEKhUVJ1QsBNp0xm2VixiSOMRvlxFGAcTJook5eEHIhQcwpWIkAFQECkNy9AQWFwyEAkPRQ4FAwQIE2llQQAh+QQJCgAvACwAAAAADAAMAIVNcY5SdZFigptph6BvjKN0kKd8lquAmq+EnbGGn7KHn7ONpLaOpbearr+csMCdscCescGhtMOnuMauvsuzws60w862xdC9ytW/y9a/zNbCztjG0drH0tvK1N3M1t7N19/U3ePb4uff5urj6Ozk6e3l6u7m6u7o7PDq7vDt8PPv8vTw8vTw8/X19vf6+vv///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQ8CXcEgsvlytVUplJLJIpSEDUESFTELBwSgCCQEV42kjDFiMo4uQsDB2MkLHoEHUTD7DRAHC8VAiZ0QSCgYIDxhNiUEAOw==';
  30. /**
  31. *
  32. */
  33. Editor.globeImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTEuOTkgMkM2LjQ3IDIgMiA2LjQ4IDIgMTJzNC40NyAxMCA5Ljk5IDEwQzE3LjUyIDIyIDIyIDE3LjUyIDIyIDEyUzE3LjUyIDIgMTEuOTkgMnptNi45MyA2aC0yLjk1Yy0uMzItMS4yNS0uNzgtMi40NS0xLjM4LTMuNTYgMS44NC42MyAzLjM3IDEuOTEgNC4zMyAzLjU2ek0xMiA0LjA0Yy44MyAxLjIgMS40OCAyLjUzIDEuOTEgMy45NmgtMy44MmMuNDMtMS40MyAxLjA4LTIuNzYgMS45MS0zLjk2ek00LjI2IDE0QzQuMSAxMy4zNiA0IDEyLjY5IDQgMTJzLjEtMS4zNi4yNi0yaDMuMzhjLS4wOC42Ni0uMTQgMS4zMi0uMTQgMiAwIC42OC4wNiAxLjM0LjE0IDJINC4yNnptLjgyIDJoMi45NWMuMzIgMS4yNS43OCAyLjQ1IDEuMzggMy41Ni0xLjg0LS42My0zLjM3LTEuOS00LjMzLTMuNTZ6bTIuOTUtOEg1LjA4Yy45Ni0xLjY2IDIuNDktMi45MyA0LjMzLTMuNTZDOC44MSA1LjU1IDguMzUgNi43NSA4LjAzIDh6TTEyIDE5Ljk2Yy0uODMtMS4yLTEuNDgtMi41My0xLjkxLTMuOTZoMy44MmMtLjQzIDEuNDMtMS4wOCAyLjc2LTEuOTEgMy45NnpNMTQuMzQgMTRIOS42NmMtLjA5LS42Ni0uMTYtMS4zMi0uMTYtMiAwLS42OC4wNy0xLjM1LjE2LTJoNC42OGMuMDkuNjUuMTYgMS4zMi4xNiAyIDAgLjY4LS4wNyAxLjM0LS4xNiAyem0uMjUgNS41NmMuNi0xLjExIDEuMDYtMi4zMSAxLjM4LTMuNTZoMi45NWMtLjk2IDEuNjUtMi40OSAyLjkzLTQuMzMgMy41NnpNMTYuMzYgMTRjLjA4LS42Ni4xNC0xLjMyLjE0LTIgMC0uNjgtLjA2LTEuMzQtLjE0LTJoMy4zOGMuMTYuNjQuMjYgMS4zMS4yNiAycy0uMSAxLjM2LS4yNiAyaC0zLjM4eiIvPjwvc3ZnPg==';
  34. /**
  35. *
  36. */
  37. Editor.commentImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMjEuOTkgNGMwLTEuMS0uODktMi0xLjk5LTJINGMtMS4xIDAtMiAuOS0yIDJ2MTJjMCAxLjEuOSAyIDIgMmgxNGw0IDQtLjAxLTE4ek0xOCAxNEg2di0yaDEydjJ6bTAtM0g2VjloMTJ2MnptMC0zSDZWNmgxMnYyeiIvPjxwYXRoIGQ9Ik0wIDBoMjR2MjRIMHoiIGZpbGw9Im5vbmUiLz48L3N2Zz4=';
  38. /**
  39. *
  40. */
  41. Editor.commentImageInverted = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABLElEQVRYR+2Wvy4FQRjFf4dINAq9XqtSaVRqXArPINEodUqlhxC5/pU6nYdQSHQeQTRHNtmVuXuXrIxv1k1sN5vMOb85c75kxMCfBvZnCsD2ErAGzAfAvUt6THUnAGwfAWfAQoB5I3kh6aBZfALYXgGeg80b31VJT9UiBRgB48CTp9Lbku7aAPvAZSGAHUm3swEgKWtUbbsj1f4JDA4AbGb24iErgUzzr7bvSrrpVcKgK5ghgKAO9E/gvwNBJRxJuu41BUEd+BFARA3+JsAWcB9x3A7NzgSqt+ALsFwAYhqgMrW9Ub8J14G5QJBugAhD2yfAaUt7T9LVxBhGmDeato/rZJtfZQHq600hygPUEIfAOTAMQALxWrQD7X7ZXpT0VqyE3xU868n9G5PzASPvpiHavBAUAAAAAElFTkSuQmCC';
  42. /**
  43. *
  44. */
  45. Editor.userImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTIgMTJjMi4yMSAwIDQtMS43OSA0LTRzLTEuNzktNC00LTQtNCAxLjc5LTQgNCAxLjc5IDQgNCA0em0wIDJjLTIuNjcgMC04IDEuMzQtOCA0djJoMTZ2LTJjMC0yLjY2LTUuMzMtNC04LTR6Ii8+PC9zdmc+';
  46. /**
  47. *
  48. */
  49. Editor.shareImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTggMTYuMDhjLS43NiAwLTEuNDQuMy0xLjk2Ljc3TDguOTEgMTIuN2MuMDUtLjIzLjA5LS40Ni4wOS0uN3MtLjA0LS40Ny0uMDktLjdsNy4wNS00LjExYy41NC41IDEuMjUuODEgMi4wNC44MSAxLjY2IDAgMy0xLjM0IDMtM3MtMS4zNC0zLTMtMy0zIDEuMzQtMyAzYzAgLjI0LjA0LjQ3LjA5LjdMOC4wNCA5LjgxQzcuNSA5LjMxIDYuNzkgOSA2IDljLTEuNjYgMC0zIDEuMzQtMyAzczEuMzQgMyAzIDNjLjc5IDAgMS41LS4zMSAyLjA0LS44MWw3LjEyIDQuMTZjLS4wNS4yMS0uMDguNDMtLjA4LjY1IDAgMS42MSAxLjMxIDIuOTIgMi45MiAyLjkyIDEuNjEgMCAyLjkyLTEuMzEgMi45Mi0yLjkycy0xLjMxLTIuOTItMi45Mi0yLjkyeiIvPjwvc3ZnPg==';
  50. /**
  51. *
  52. */
  53. Editor.syncImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTIgNFYxTDggNWw0IDRWNmMzLjMxIDAgNiAyLjY5IDYgNiAwIDEuMDEtLjI1IDEuOTctLjcgMi44bDEuNDYgMS40NkMxOS41NCAxNS4wMyAyMCAxMy41NyAyMCAxMmMwLTQuNDItMy41OC04LTgtOHptMCAxNGMtMy4zMSAwLTYtMi42OS02LTYgMC0xLjAxLjI1LTEuOTcuNy0yLjhMNS4yNCA3Ljc0QzQuNDYgOC45NyA0IDEwLjQzIDQgMTJjMCA0LjQyIDMuNTggOCA4IDh2M2w0LTQtNC00djN6Ii8+PC9zdmc+';
  54. /**
  55. *
  56. */
  57. Editor.syncDisabledImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTAgNi4zNVY0LjI2Yy0uOC4yMS0xLjU1LjU0LTIuMjMuOTZsMS40NiAxLjQ2Yy4yNS0uMTIuNS0uMjQuNzctLjMzem0tNy4xNC0uOTRsMi4zNiAyLjM2QzQuNDUgOC45OSA0IDEwLjQ0IDQgMTJjMCAyLjIxLjkxIDQuMiAyLjM2IDUuNjRMNCAyMGg2di02bC0yLjI0IDIuMjRDNi42OCAxNS4xNSA2IDEzLjY2IDYgMTJjMC0xIC4yNS0xLjk0LjY4LTIuNzdsOC4wOCA4LjA4Yy0uMjUuMTMtLjUuMjUtLjc3LjM0djIuMDljLjgtLjIxIDEuNTUtLjU0IDIuMjMtLjk2bDIuMzYgMi4zNiAxLjI3LTEuMjdMNC4xNCA0LjE0IDIuODYgNS40MXpNMjAgNGgtNnY2bDIuMjQtMi4yNEMxNy4zMiA4Ljg1IDE4IDEwLjM0IDE4IDEyYzAgMS0uMjUgMS45NC0uNjggMi43N2wxLjQ2IDEuNDZDMTkuNTUgMTUuMDEgMjAgMTMuNTYgMjAgMTJjMC0yLjIxLS45MS00LjItMi4zNi01LjY0TDIwIDR6Ii8+PC9zdmc+';
  58. /**
  59. *
  60. */
  61. Editor.syncProblemImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMyAxMmMwIDIuMjEuOTEgNC4yIDIuMzYgNS42NEwzIDIwaDZ2LTZsLTIuMjQgMi4yNEM1LjY4IDE1LjE1IDUgMTMuNjYgNSAxMmMwLTIuNjEgMS42Ny00LjgzIDQtNS42NVY0LjI2QzUuNTUgNS4xNSAzIDguMjcgMyAxMnptOCA1aDJ2LTJoLTJ2MnpNMjEgNGgtNnY2bDIuMjQtMi4yNEMxOC4zMiA4Ljg1IDE5IDEwLjM0IDE5IDEyYzAgMi42MS0xLjY3IDQuODMtNCA1LjY1djIuMDljMy40NS0uODkgNi00LjAxIDYtNy43NCAwLTIuMjEtLjkxLTQuMi0yLjM2LTUuNjRMMjEgNHptLTEwIDloMlY3aC0ydjZ6Ii8+PC9zdmc+';
  62. /**
  63. * Used in the GraphViewer lightbox.
  64. */
  65. Editor.tweetImage = IMAGE_PATH + '/tweet.png';
  66. /**
  67. * Used in the GraphViewer lightbox.
  68. */
  69. Editor.facebookImage = IMAGE_PATH + '/facebook.png';
  70. /**
  71. * Blank 1x1 pixel transparent PNG image.
  72. */
  73. Editor.blankImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==';
  74. /**
  75. * Blank 1x1 pixel transparent PNG image.
  76. */
  77. Editor.hiResImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAAA+CAMAAACLMWy1AAAAh1BMVEUAAABMTExERERBQUFBQUFFRUVAQEBCQkJAQEA6OjpDQ0NKSkpBQUFBQUFERERERERBQUFCQkJCQkJCQkJJSUlBQUFCQkJDQ0NDQ0NCQkJDQ0NBQUFBQUFCQkJBQUFCQkJCQkJDQ0NCQkJHR0dBQUFCQkJCQkJAQEBCQkJDQ0NAQEBERERCQkIk1hS2AAAAKnRSTlMAAjj96BL7PgQFRwfu3TYazKuVjRXl1V1DPCn1uLGjnWNVIgy9hU40eGqPkM38AAACG0lEQVRYw+2X63KbMBCFzwZblgGDceN74muatpLe//m6MHV3gHGFAv2RjM94MAbxzdnVsQbBDKwH8AH8MDAyafzjqYeyOG04XE7RS8nIRDXg6BlT+rA0nmtAPh+NQRDxIASIMG44rAMrGunBgHwy3uUldxggIStGKp2f+DQc2O4h4eQsX3O2IFB/oEbsjOKbStnjAEA+zJ0ylZTbgvoDn8xNyn6Dbj5Kd4GsNpABa6duQPfSdEj88TgMAhKuCWjAkgmFXPLnsD0pWd3OFGdrMugQII/eOMPEiGOzqPMIeWrcSoMCg71W1pXBPvCP+gS/OdXqQ3uW23+93XGWLl/OaBb805bNcBPoEIcVJsnHzcxpZH86u5KZ9gDby5dQCcnKqdbke4ItI4Tzd7IW9hZQt4EO6GG9b9sYuuK9Wwn8TIr2xKbF2+3Nhr+qxChJ/AI6pIfCu4z4Zowp4ZUNihz79vewzctnHDwTvQO/hCdFBzrUGDOPn2Y/F8YKT4oOATLvlhOznzmBSdFBJWtc58y7r+UVFOCQczy3wpN6pegDqHtsCPTGvH9JuTO0Dyg8icldYPk+RB6g8Aofj4m2EKBvtTmUPD9xDd1pPcSReV2U5iD/ik2yrngtvvqBfPzOvKiDTKTsCdoHZJ7pLLffgTwlJ5vJdtJV2/jiAYaLvLGhMAEDO5QcDg2M/jOw/8Zn+K3ZwJvHT7ZffgC/NvA3zcybTeIfE4EAAAAASUVORK5CYII=' : IMAGE_PATH + '/img-hi-res.png';
  78. /**
  79. * Blank 1x1 pixel transparent PNG image.
  80. */
  81. Editor.loResImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAAA+CAMAAACLMWy1AAAAS1BMVEVAQEAAAAA1NTVBQUFDQ0NDQ0NFRUVERERBQUFBQUFBQUFAQEBBQUFBQUFCQkJCQkJCQkJBQUFCQkJDQ0NDQ0NCQkJCQkJCQkJGRkb5/XqTAAAAGXRSTlP+AAWODlASCsesX+Lc2LyWe3pwa1tCPjohjSJfoAAAAI1JREFUWMPt1MkKhTAMRuG0anvneXr/J71nUypKcdqI/N8yhLMKMZE1CahnClDQzMPB44ED3EgeCubgDWnWQMHpwTtKwTe+UHD4sJ94wbUEHHFGhILlYDeSnsQeabeCgsPBgB0MOZZ9oGA5GJFiJSfUULAfjLjARrhCwX7wh2YCDwVbwZkUBKqFFJRN+wOcwSgR2sREcgAAAABJRU5ErkJggg==' : IMAGE_PATH + '/img-lo-res.png';
  82. /**
  83. * Only needed in browsers with SVG support for export via lightbox toolbar.
  84. */
  85. Editor.cameraLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAAA/BJREFUWAnFl0uIjWEYx885buPSuGwmSYwtwsY1ikKSNYNclmQnadgrZSPlsnBLSlaGBdNYKY0Vdi4L4zYzIqxGxmXG//d+7//0+uY7nWMiT/2/53mf+3v7vnNKpf9M5UbrDw8Pj4m+wzmeT1FBUS6Xf+YNox6reMONukijMXUTM3NmI75PyXcJPwRWg5kS7xysDLNmfEUxpx2rceNE50IlYjyRklcLf0prY+x4BTqfmx3ZUHQaO9ISGngYq38V/1EH+ECPa+QaK1u1kVBQirDMChiS3CTeIkwWvghtwhKBpZ8g1CO2B99FynVU/KowSRgQ3mlrBsVZ1awmQlS0SGbfXglfBPbdRGMm5O8RXg2P835pDCvzWjghTHETcLpZLHwS8kTCtBEK1SN83Egam8YxyVZqc+Do5qkwS+gT9grNwkUBG6cbsG/gs3BTuC/0ChCxq4QtwgzBMdwUZBPyN4Ftfi4sYPZHktbOSRlIuutRP5jYj0ueZp88xyYcS/zZoiLyQT1IA/cTj7eSlwnrhI+JnkQbCwo2Sx/2M7VJt17wdhVtgxvrpoFnAuSAbJQ97biZAlKxBfD9wgOhV+BgIR/AZtJ4kwD5PGSj7OmmekjWEy0oAQHAS3+KpBpzXqYK3UItopHpSRMno2N+cm7gDYnfRCcr3QBqriMHLJDkeyhFfiG5aVbK+8rhtP9M6QcIEJHX5Fp9NMAyQlYiu+OOJNlODCIXyka/P23bncTdiC7OydC1+v1Bsb+5r84DK8S3Rdmf5cRUFW3bXtWUSt1Rdk6G4SyJV2o1YId+vNUxr+x5yCJiapFtcxQzLjrxboGcMxvFJwEOKnLwjIbkx/sdSmeSaUY++SwTAxV+4DJT7RVwkbk46gNCsifIItuy0e9PF33Cb4homhN5YRyzL5q5V2VNkv98kqgoGTo3YF9CnMM5Y5rItFfvBSi9JulVXOgI+VwIntkt+SaZ6weQfcovJf7zpTfl86P/wAF7Fz18NeKwmvAWCaX0Z/uMHQr42ZxvR/Rxcw5xM+9J/CJq8w2gduDhmDgso/QrBH47dEXQ1IqczyHpIOfIRtnTtV7SwO1oKXKkU3fbToFGSDHtMWcaH1WBuVYnDbRFi99iqSMySdzxXckrazUh23KBVYGIcfNBkTxca0e4ATJ0KukGYVBgr/MnlhPOtQq/ksUfCbzh+EFCjtnCUoHfjhA/OsiTv2HcEvJMELp0VakZDliTmriTdPivxU4VmEhtPrGV+KJhO7ZKt0doFZh1fgZSBWIW2AGEHwg3BUWOnKtH+suqdw07tYMfglCrWPD5mw9qVYuniaXkT0OtWaSuo5LJTY1RBf+roF9X5+y/5qU+DAAAAABJRU5ErkJggg==';
  86. /**
  87. * Default value for custom libraries in mxSettings.
  88. */
  89. Editor.defaultCustomLibraries = [];
  90. /**
  91. * Default value for custom libraries in mxSettings.
  92. */
  93. Editor.enableCustomLibraries = true;
  94. /**
  95. * Specifies if custom properties should be enabled.
  96. */
  97. Editor.enableCustomProperties = true;
  98. /**
  99. * Specifies if XML files should be compressed. Default is true.
  100. */
  101. Editor.compressXml = true;
  102. /**
  103. * Specifies global variables.
  104. */
  105. Editor.globalVars = null;
  106. /**
  107. * Disables the shadow option in the format panel.
  108. */
  109. Editor.shadowOptionEnabled = true;
  110. /**
  111. * Reference to the config object passed to <configure>.
  112. */
  113. Editor.config = null;
  114. /**
  115. * Reference to the version of the last config object in
  116. * <configure>. If this is different to the last version in
  117. * mxSettings.parse, then the settings are reset.
  118. */
  119. Editor.configVersion = null;
  120. /**
  121. * Common properties for all edges.
  122. */
  123. Editor.commonEdgeProperties = [
  124. {type: 'separator'},
  125. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  126. {name: 'sourcePortConstraint', dispName: 'Source Constraint', type: 'enum', defVal: 'none',
  127. enumList: [{val: 'none', dispName: 'None'}, {val: 'north', dispName: 'North'}, {val: 'east', dispName: 'East'}, {val: 'south', dispName: 'South'}, {val: 'west', dispName: 'West'}]
  128. },
  129. {name: 'targetPortConstraint', dispName: 'Target Constraint', type: 'enum', defVal: 'none',
  130. enumList: [{val: 'none', dispName: 'None'}, {val: 'north', dispName: 'North'}, {val: 'east', dispName: 'East'}, {val: 'south', dispName: 'South'}, {val: 'west', dispName: 'West'}]
  131. },
  132. {name: 'jettySize', dispName: 'Jetty Size', type: 'int', min: 0, defVal: 'auto', allowAuto: true, isVisible: function(state)
  133. {
  134. return mxUtils.getValue(state.style, mxConstants.STYLE_EDGE, null) == 'orthogonalEdgeStyle';
  135. }},
  136. {name: 'fillOpacity', dispName: 'Fill Opacity', type: 'int', min: 0, max: 100, defVal: 100},
  137. {name: 'strokeOpacity', dispName: 'Stroke Opacity', type: 'int', min: 0, max: 100, defVal: 100},
  138. {name: 'startFill', dispName: 'Start Fill', type: 'bool', defVal: true},
  139. {name: 'endFill', dispName: 'End Fill', type: 'bool', defVal: true},
  140. {name: 'perimeterSpacing', dispName: 'Terminal Spacing', type: 'float', defVal: 0},
  141. {name: 'anchorPointDirection', dispName: 'Anchor Direction', type: 'bool', defVal: true},
  142. {name: 'snapToPoint', dispName: 'Snap to Point', type: 'bool', defVal: false},
  143. {name: 'fixDash', dispName: 'Fixed Dash', type: 'bool', defVal: false},
  144. {name: 'jiggle', dispName: 'Jiggle', type: 'float', min: 0, defVal: 1.5, isVisible: function(state)
  145. {
  146. return mxUtils.getValue(state.style, 'comic', '0') == '1';
  147. }},
  148. {name: 'editable', dispName: 'Editable', type: 'bool', defVal: true},
  149. {name: 'backgroundOutline', dispName: 'Background Outline', type: 'bool', defVal: false},
  150. {name: 'bendable', dispName: 'Bendable', type: 'bool', defVal: true},
  151. {name: 'movable', dispName: 'Movable', type: 'bool', defVal: true},
  152. {name: 'cloneable', dispName: 'Cloneable', type: 'bool', defVal: true},
  153. {name: 'deletable', dispName: 'Deletable', type: 'bool', defVal: true},
  154. {name: 'orthogonalLoop', dispName: 'Loop Routing', type: 'bool', defVal: false},
  155. {name: 'noJump', dispName: 'No Jumps', type: 'bool', defVal: false}
  156. ];
  157. /**
  158. * Common properties for all vertices.
  159. */
  160. Editor.commonVertexProperties = [
  161. {type: 'separator'},
  162. {name: 'fillOpacity', dispName: 'Fill Opacity', type: 'int', min: 0, max: 100, defVal: 100},
  163. {name: 'strokeOpacity', dispName: 'Stroke Opacity', type: 'int', min: 0, max: 100, defVal: 100},
  164. {name: 'overflow', dispName: 'Text Overflow', defVal: 'visible', type: 'enum',
  165. enumList: [{val: 'visible', dispName: 'Visible'}, {val: 'hidden', dispName: 'Hidden'}, {val: 'fill', dispName: 'Fill'}, {val: 'width', dispName: 'Width'}]
  166. },
  167. {name: 'noLabel', dispName: 'Hide Label', type: 'bool', defVal: false},
  168. {name: 'labelPadding', dispName: 'Label Padding', type: 'float', defVal: 0},
  169. {name: 'direction', dispName: 'Direction', type: 'enum', defVal: 'east',
  170. enumList: [{val: 'north', dispName: 'North'}, {val: 'east', dispName: 'East'}, {val: 'south', dispName: 'South'}, {val: 'west', dispName: 'West'}]
  171. },
  172. {name: 'portConstraint', dispName: 'Constraint', type: 'enum', defVal: 'none',
  173. enumList: [{val: 'none', dispName: 'None'}, {val: 'north', dispName: 'North'}, {val: 'east', dispName: 'East'}, {val: 'south', dispName: 'South'}, {val: 'west', dispName: 'West'}]
  174. },
  175. {name: 'portConstraintRotation', dispName: 'Rotate Constraint', type: 'bool', defVal: false},
  176. {name: 'connectable', dispName: 'Connectable', type: 'bool', defVal: true},
  177. {name: 'allowArrows', dispName: 'Allow Arrows', type: 'bool', defVal: true},
  178. {name: 'snapToPoint', dispName: 'Snap to Point', type: 'bool', defVal: false},
  179. {name: 'perimeter', dispName: 'Perimeter', defVal: 'none', type: 'enum',
  180. enumList: [{val: 'none', dispName: 'None'},
  181. {val: 'rectanglePerimeter', dispName: 'Rectangle'}, {val: 'ellipsePerimeter', dispName: 'Ellipse'},
  182. {val: 'rhombusPerimeter', dispName: 'Rhombus'}, {val: 'trianglePerimeter', dispName: 'Triangle'},
  183. {val: 'hexagonPerimeter2', dispName: 'Hexagon'}, {val: 'lifelinePerimeter', dispName: 'Lifeline'},
  184. {val: 'orthogonalPerimeter', dispName: 'Orthogonal'}, {val: 'backbonePerimeter', dispName: 'Backbone'},
  185. {val: 'calloutPerimeter', dispName: 'Callout'}, {val: 'parallelogramPerimeter', dispName: 'Parallelogram'},
  186. {val: 'trapezoidPerimeter', dispName: 'Trapezoid'}, {val: 'stepPerimeter', dispName: 'Step'}]
  187. },
  188. {name: 'fixDash', dispName: 'Fixed Dash', type: 'bool', defVal: false},
  189. {name: 'jiggle', dispName: 'Jiggle', type: 'float', min: 0, defVal: 1.5, isVisible: function(state)
  190. {
  191. return mxUtils.getValue(state.style, 'comic', '0') == '1';
  192. }},
  193. {name: 'autosize', dispName: 'Autosize', type: 'bool', defVal: false},
  194. {name: 'collapsible', dispName: 'Collapsible', type: 'bool', defVal: false},
  195. {name: 'container', dispName: 'Container', type: 'bool', defVal: false},
  196. {name: 'recursiveResize', dispName: 'Resize Children', type: 'bool', defVal: true},
  197. {name: 'part', dispName: 'Part', type: 'bool', defVal: false},
  198. {name: 'editable', dispName: 'Editable', type: 'bool', defVal: true},
  199. {name: 'backgroundOutline', dispName: 'Background Outline', type: 'bool', defVal: false},
  200. {name: 'movable', dispName: 'Movable', type: 'bool', defVal: true},
  201. {name: 'movableLabel', dispName: 'Movable Label', type: 'bool', defVal: false, isVisible: function(state, format)
  202. {
  203. var geo = (state.vertices.length > 0) ? format.editorUi.editor.graph.getCellGeometry(state.vertices[0]) : null;
  204. return geo != null && !geo.relative;
  205. }},
  206. {name: 'resizable', dispName: 'Resizable', type: 'bool', defVal: true},
  207. {name: 'resizeWidth', dispName: 'Resize Width', type: 'bool', defVal: false},
  208. {name: 'resizeHeight', dispName: 'Resize Height', type: 'bool', defVal: false},
  209. {name: 'rotatable', dispName: 'Rotatable', type: 'bool', defVal: true},
  210. {name: 'cloneable', dispName: 'Cloneable', type: 'bool', defVal: true},
  211. {name: 'deletable', dispName: 'Deletable', type: 'bool', defVal: true},
  212. {name: 'treeFolding', dispName: 'Tree Folding', type: 'bool', defVal: false},
  213. {name: 'treeMoving', dispName: 'Tree Moving', type: 'bool', defVal: false},
  214. {name: 'moveCells', dispName: 'Move Cells on Fold', type: 'bool', defVal: false, isVisible: function(state, format)
  215. {
  216. return state.vertices.length > 0 && format.editorUi.editor.graph.isContainer(state.vertices[0]);
  217. }}
  218. ];
  219. /**
  220. * Default value for the CSV import dialog.
  221. */
  222. Editor.defaultCsvValue = '##\n' +
  223. '## Example CSV import. Use ## for comments and # for configuration. Paste CSV below.\n' +
  224. '## The following names are reserved and should not be used (or ignored):\n' +
  225. '## id, tooltip, placeholder(s), link and label (see below)\n' +
  226. '##\n' +
  227. '#\n' +
  228. '## Node label with placeholders and HTML.\n' +
  229. '## Default is \'%name_of_first_column%\'.\n' +
  230. '#\n' +
  231. '# label: %name%<br><i style="color:gray;">%position%</i><br><a href="mailto:%email%">Email</a>\n' +
  232. '#\n' +
  233. '## Node style (placeholders are replaced once).\n' +
  234. '## Default is the current style for nodes.\n' +
  235. '#\n' +
  236. '# style: label;image=%image%;whiteSpace=wrap;html=1;rounded=1;fillColor=%fill%;strokeColor=%stroke%;\n' +
  237. '#\n' +
  238. '## Parent style for nodes with child nodes (placeholders are replaced once).\n' +
  239. '#\n' +
  240. '# parentstyle: swimlane;whiteSpace=wrap;html=1;childLayout=stackLayout;horizontal=1;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;\n' +
  241. '#\n' +
  242. '## Optional column name that contains a reference to a named style in styles.\n' +
  243. '## Default is the current style for nodes.\n' +
  244. '#\n' +
  245. '# stylename: -\n' +
  246. '#\n' +
  247. '## JSON for named styles of the form {"name": "style", "name": "style"} where style is a cell style with\n' +
  248. '## placeholders that are replaced once.\n' +
  249. '#\n' +
  250. '# styles: -\n' +
  251. '#\n' +
  252. '## Optional column name that contains a reference to a named label in labels.\n' +
  253. '## Default is the current label.\n' +
  254. '#\n' +
  255. '# labelname: -\n' +
  256. '#\n' +
  257. '## JSON for named labels of the form {"name": "label", "name": "label"} where label is a cell label with\n' +
  258. '## placeholders.\n' +
  259. '#\n' +
  260. '# labels: -\n' +
  261. '#\n' +
  262. '## Uses the given column name as the identity for cells (updates existing cells).\n' +
  263. '## Default is no identity (empty value or -).\n' +
  264. '#\n' +
  265. '# identity: -\n' +
  266. '#\n' +
  267. '## Uses the given column name as the parent reference for cells. Default is no parent (empty or -).\n' +
  268. '## The identity above is used for resolving the reference so it must be specified.\n' +
  269. '#\n' +
  270. '# parent: -\n' +
  271. '#\n' +
  272. '## Adds a prefix to the identity of cells to make sure they do not collide with existing cells (whose\n' +
  273. '## IDs are numbers from 0..n, sometimes with a GUID prefix in the context of realtime collaboration).\n' +
  274. '## Default is csvimport-.\n' +
  275. '#\n' +
  276. '# namespace: csvimport-\n' +
  277. '#\n' +
  278. '## Connections between rows ("from": source colum, "to": target column).\n' +
  279. '## Label, style and invert are optional. Defaults are \'\', current style and false.\n' +
  280. '## In addition to label, an optional fromlabel and tolabel can be used to name the column\n' +
  281. '## that contains the text for the label in the edges source or target (invert ignored).\n' +
  282. '## The label is concatenated in the form fromlabel + label + tolabel if all are defined.\n' +
  283. '## The target column may contain a comma-separated list of values.\n' +
  284. '## Multiple connect entries are allowed.\n' +
  285. '#\n' +
  286. '# connect: {"from": "manager", "to": "name", "invert": true, "label": "manages", \\\n' +
  287. '# "style": "curved=1;endArrow=blockThin;endFill=1;fontSize=11;"}\n' +
  288. '# connect: {"from": "refs", "to": "id", "style": "curved=1;fontSize=11;"}\n' +
  289. '#\n' +
  290. '## Node x-coordinate. Possible value is a column name. Default is empty. Layouts will\n' +
  291. '## override this value.\n' +
  292. '#\n' +
  293. '# left: \n' +
  294. '#\n' +
  295. '## Node y-coordinate. Possible value is a column name. Default is empty. Layouts will\n' +
  296. '## override this value.\n' +
  297. '#\n' +
  298. '# top: \n' +
  299. '#\n' +
  300. '## Node width. Possible value is a number (in px), auto or an @ sign followed by a column\n' +
  301. '## name that contains the value for the width. Default is auto.\n' +
  302. '#\n' +
  303. '# width: auto\n' +
  304. '#\n' +
  305. '## Node height. Possible value is a number (in px), auto or an @ sign followed by a column\n' +
  306. '## name that contains the value for the height. Default is auto.\n' +
  307. '#\n' +
  308. '# height: auto\n' +
  309. '#\n' +
  310. '## Padding for autosize. Default is 0.\n' +
  311. '#\n' +
  312. '# padding: -12\n' +
  313. '#\n' +
  314. '## Comma-separated list of ignored columns for metadata. (These can be\n' +
  315. '## used for connections and styles but will not be added as metadata.)\n' +
  316. '#\n' +
  317. '# ignore: id,image,fill,stroke,refs,manager\n' +
  318. '#\n' +
  319. '## Column to be renamed to link attribute (used as link).\n' +
  320. '#\n' +
  321. '# link: url\n' +
  322. '#\n' +
  323. '## Spacing between nodes. Default is 40.\n' +
  324. '#\n' +
  325. '# nodespacing: 40\n' +
  326. '#\n' +
  327. '## Spacing between levels of hierarchical layouts. Default is 100.\n' +
  328. '#\n' +
  329. '# levelspacing: 100\n' +
  330. '#\n' +
  331. '## Spacing between parallel edges. Default is 40. Use 0 to disable.\n' +
  332. '#\n' +
  333. '# edgespacing: 40\n' +
  334. '#\n' +
  335. '## Name or JSON of layout. Possible values are auto, none, verticaltree, horizontaltree,\n' +
  336. '## verticalflow, horizontalflow, organic, circle or a JSON string as used in Layout, Apply.\n' +
  337. '## Default is auto.\n' +
  338. '#\n' +
  339. '# layout: auto\n' +
  340. '#\n' +
  341. '## ---- CSV below this line. First line are column names. ----\n' +
  342. 'name,position,id,location,manager,email,fill,stroke,refs,url,image\n' +
  343. 'Evan Miller,CFO,emi,Office 1,,me@example.com,#dae8fc,#6c8ebf,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-9-2-128.png\n' +
  344. 'Edward Morrison,Brand Manager,emo,Office 2,Evan Miller,me@example.com,#d5e8d4,#82b366,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-10-3-128.png\n' +
  345. 'Ron Donovan,System Admin,rdo,Office 3,Evan Miller,me@example.com,#d5e8d4,#82b366,"emo,tva",https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-2-128.png\n' +
  346. 'Tessa Valet,HR Director,tva,Office 4,Evan Miller,me@example.com,#d5e8d4,#82b366,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-3-128.png\n';
  347. /**
  348. * Compresses the given string.
  349. */
  350. Editor.fastCompress = function(data)
  351. {
  352. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  353. {
  354. return data;
  355. }
  356. else
  357. {
  358. return pako.deflateRaw(data, {to: 'string'});
  359. }
  360. };
  361. /**
  362. * Decompresses the given string.
  363. */
  364. Editor.fastDecompress = function(data)
  365. {
  366. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  367. {
  368. return data;
  369. }
  370. else
  371. {
  372. return pako.inflateRaw(data, {to: 'string'});
  373. }
  374. };
  375. /**
  376. * Helper function to extract the graph model XML node.
  377. */
  378. Editor.extractGraphModel = function(node, allowMxFile)
  379. {
  380. if (node != null && typeof(pako) !== 'undefined')
  381. {
  382. var tmp = node.ownerDocument.getElementsByTagName('div');
  383. var divs = [];
  384. if (tmp != null && tmp.length > 0)
  385. {
  386. for (var i = 0; i < tmp.length; i++)
  387. {
  388. if (tmp[i].getAttribute('class') == 'mxgraph')
  389. {
  390. divs.push(tmp[i]);
  391. break;
  392. }
  393. }
  394. }
  395. if (divs.length > 0)
  396. {
  397. var data = divs[0].getAttribute('data-mxgraph');
  398. if (data != null)
  399. {
  400. var config = JSON.parse(data);
  401. if (config != null && config.xml != null)
  402. {
  403. var doc2 = mxUtils.parseXml(config.xml);
  404. node = doc2.documentElement;
  405. }
  406. }
  407. else
  408. {
  409. var divs2 = divs[0].getElementsByTagName('div');
  410. if (divs2.length > 0)
  411. {
  412. var data = mxUtils.getTextContent(divs2[0]);
  413. data = Graph.decompress(data);
  414. if (data.length > 0)
  415. {
  416. var doc2 = mxUtils.parseXml(data);
  417. node = doc2.documentElement;
  418. }
  419. }
  420. }
  421. }
  422. }
  423. if (node != null && node.nodeName == 'svg')
  424. {
  425. var tmp = node.getAttribute('content');
  426. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  427. {
  428. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  429. }
  430. if (tmp != null && tmp.charAt(0) == '%')
  431. {
  432. tmp = decodeURIComponent(tmp);
  433. }
  434. if (tmp != null && tmp.length > 0)
  435. {
  436. node = mxUtils.parseXml(tmp).documentElement;
  437. }
  438. else
  439. {
  440. throw {message: mxResources.get('notADiagramFile')};
  441. }
  442. }
  443. if (node != null && !allowMxFile)
  444. {
  445. var diagramNode = null;
  446. if (node.nodeName == 'diagram')
  447. {
  448. diagramNode = node;
  449. }
  450. else if (node.nodeName == 'mxfile')
  451. {
  452. var diagrams = node.getElementsByTagName('diagram');
  453. if (diagrams.length > 0)
  454. {
  455. diagramNode = diagrams[Math.max(0, Math.min(diagrams.length - 1, urlParams['page'] || 0))];
  456. }
  457. }
  458. if (diagramNode != null)
  459. {
  460. node = Editor.parseDiagramNode(diagramNode);
  461. }
  462. }
  463. if (node != null && node.nodeName != 'mxGraphModel' && (!allowMxFile || node.nodeName != 'mxfile'))
  464. {
  465. node = null;
  466. }
  467. return node;
  468. };
  469. /**
  470. * Extracts the XML from the compressed or non-compressed text chunk.
  471. */
  472. Editor.parseDiagramNode = function(diagramNode)
  473. {
  474. var text = mxUtils.trim(mxUtils.getTextContent(diagramNode));
  475. var node = null;
  476. if (text.length > 0)
  477. {
  478. var tmp = Graph.decompress(text);
  479. if (tmp != null && tmp.length > 0)
  480. {
  481. node = mxUtils.parseXml(tmp).documentElement;
  482. }
  483. }
  484. else
  485. {
  486. var temp = mxUtils.getChildNodes(diagramNode);
  487. if (temp.length > 0)
  488. {
  489. // Creates new document for unique IDs within mxGraphModel
  490. var doc = mxUtils.createXmlDocument();
  491. doc.appendChild(doc.importNode(temp[0], true));
  492. node = doc.documentElement;
  493. }
  494. }
  495. return node;
  496. };
  497. /**
  498. * Extracts the XML from the compressed or non-compressed text chunk.
  499. */
  500. Editor.getDiagramNodeXml = function(diagramNode)
  501. {
  502. var text = mxUtils.getTextContent(diagramNode);
  503. var xml = null;
  504. if (text.length > 0)
  505. {
  506. xml = Graph.decompress(text);
  507. }
  508. else if (diagramNode.firstChild != null)
  509. {
  510. xml = mxUtils.getXml(diagramNode.firstChild);
  511. }
  512. return xml;
  513. };
  514. /**
  515. * Static method for parsing PDF files.
  516. */
  517. Editor.extractGraphModelFromPdf = function(base64)
  518. {
  519. base64 = base64.substring(base64.indexOf(',') + 1);
  520. // Workaround for invalid character error in Safari
  521. var f = (window.atob && !mxClient.IS_SF) ? atob(base64) : Base64.decode(base64, true);
  522. var check = '\n/Subject (';
  523. var result = null;
  524. var curline = '';
  525. var checked = 0;
  526. var pos = 0;
  527. var obj = [];
  528. var buf = null;
  529. var nr = null;
  530. while (pos < f.length)
  531. {
  532. var b = f.charCodeAt(pos);
  533. pos += 1;
  534. if (b != 10)
  535. {
  536. curline += String.fromCharCode(b);
  537. }
  538. if (b == check.charCodeAt(checked))
  539. {
  540. checked++;
  541. }
  542. else
  543. {
  544. checked = 0;
  545. }
  546. if (checked == check.length)
  547. {
  548. var end = f.indexOf(')\n', pos);
  549. // Default case is XML inlined in Subject metadata
  550. if (end > pos)
  551. {
  552. result = f.substring(pos, end);
  553. break;
  554. }
  555. }
  556. // Creates table for lookup if no inline data is found
  557. if (b == 10)
  558. {
  559. if (curline == 'endobj')
  560. {
  561. buf = null;
  562. }
  563. else if (curline.substring(curline.length - 3, curline.length) == 'obj' ||
  564. curline == 'xref' || curline == 'trailer')
  565. {
  566. buf = [];
  567. obj[curline.split(' ')[0]] = buf;
  568. }
  569. else if (buf != null)
  570. {
  571. buf.push(curline);
  572. }
  573. curline = '';
  574. }
  575. }
  576. // Extract XML via references
  577. if (result == null)
  578. {
  579. result = Editor.extractGraphModelFromXref(obj);
  580. }
  581. if (result != null)
  582. {
  583. result = decodeURIComponent(result.
  584. replace(/\\\(/g, "(").
  585. replace(/\\\)/g, ")"));
  586. }
  587. return result;
  588. };
  589. /**
  590. * Static method for extracting Subject via references of the form
  591. *
  592. * << /Size 33 /Root 20 0 R /Info 1 0 R and 1 0 obj << /Subject 22 0 R
  593. *
  594. * Where Info is the metadata block and Subject is the data block.
  595. */
  596. Editor.extractGraphModelFromXref = function(obj)
  597. {
  598. var trailer = obj['trailer'];
  599. var result = null;
  600. // Gets Info object
  601. if (trailer != null)
  602. {
  603. var arr = /.* \/Info (\d+) (\d+) R/g.exec(trailer.join('\n'));
  604. if (arr != null && arr.length > 0)
  605. {
  606. var info = obj[arr[1]];
  607. if (info != null)
  608. {
  609. arr = /.* \/Subject (\d+) (\d+) R/g.exec(info.join('\n'));
  610. if (arr != null && arr.length > 0)
  611. {
  612. var subj = obj[arr[1]];
  613. if (subj != null)
  614. {
  615. subj = subj.join('\n');
  616. result = subj.substring(1, subj.length - 1);
  617. }
  618. }
  619. }
  620. }
  621. }
  622. return result;
  623. };
  624. /**
  625. * Extracts the XML from the compressed or non-compressed text chunk.
  626. */
  627. Editor.extractGraphModelFromPng = function(data)
  628. {
  629. var result = null;
  630. try
  631. {
  632. var base64 = data.substring(data.indexOf(',') + 1);
  633. // Workaround for invalid character error in Safari
  634. var binary = (window.atob && !mxClient.IS_SF) ? atob(base64) : Base64.decode(base64, true);
  635. EditorUi.parsePng(binary, mxUtils.bind(this, function(pos, type, length)
  636. {
  637. var value = binary.substring(pos + 8, pos + 8 + length);
  638. if (type == 'zTXt')
  639. {
  640. var idx = value.indexOf(String.fromCharCode(0));
  641. if (value.substring(0, idx) == 'mxGraphModel')
  642. {
  643. // Workaround for Java URL Encoder using + for spaces, which isn't compatible with JS
  644. var xmlData = pako.inflateRaw(value.substring(idx + 2),
  645. {to: 'string'}).replace(/\+/g,' ');
  646. if (xmlData != null && xmlData.length > 0)
  647. {
  648. result = xmlData;
  649. }
  650. }
  651. }
  652. // Uncompressed section is normally not used
  653. else if (type == 'tEXt')
  654. {
  655. var vals = value.split(String.fromCharCode(0));
  656. if (vals.length > 1 && (vals[0] == 'mxGraphModel' ||
  657. vals[0] == 'mxfile'))
  658. {
  659. result = vals[1];
  660. }
  661. }
  662. if (result != null || type == 'IDAT')
  663. {
  664. // Stops processing the file as our text chunks
  665. // are always placed before the data section
  666. return true;
  667. }
  668. }));
  669. }
  670. catch (e)
  671. {
  672. // ignores decoding errors
  673. }
  674. if (result != null && result.charAt(0) == '%')
  675. {
  676. result = decodeURIComponent(result);
  677. }
  678. // Workaround for double encoded content
  679. if (result != null && result.charAt(0) == '%')
  680. {
  681. result = decodeURIComponent(result);
  682. }
  683. return result;
  684. };
  685. /**
  686. * Extracts any parsers errors in the given XML.
  687. */
  688. Editor.extractParserError = function(node, defaultCause)
  689. {
  690. var cause = null;
  691. var errors = (node != null) ? node.getElementsByTagName('parsererror') : null;
  692. if (errors != null && errors.length > 0)
  693. {
  694. cause = defaultCause || mxResources.get('invalidChars');
  695. var divs = errors[0].getElementsByTagName('div');
  696. if (divs.length > 0)
  697. {
  698. cause = mxUtils.getTextContent(divs[0]);
  699. }
  700. }
  701. return cause;
  702. };
  703. /**
  704. * Global configuration of the Editor
  705. * see https://desk.draw.io/solution/articles/16000058316
  706. *
  707. * For defaultVertexStyle, defaultEdgeStyle and defaultLibraries, this must be called before
  708. * mxSettings.load via global config variable window.mxLoadSettings = false.
  709. */
  710. Editor.configure = function(config, untrusted)
  711. {
  712. if (config != null)
  713. {
  714. Editor.config = config;
  715. Editor.configVersion = config.version;
  716. Menus.prototype.defaultFonts = config.defaultFonts || Menus.prototype.defaultFonts;
  717. ColorDialog.prototype.presetColors = config.presetColors || ColorDialog.prototype.presetColors;
  718. ColorDialog.prototype.defaultColors = config.defaultColors || ColorDialog.prototype.defaultColors;
  719. StyleFormatPanel.prototype.defaultColorSchemes = config.defaultColorSchemes || StyleFormatPanel.prototype.defaultColorSchemes;
  720. Graph.prototype.defaultEdgeLength = config.defaultEdgeLength || Graph.prototype.defaultEdgeLength;
  721. DrawioFile.prototype.autosaveDelay = config.autosaveDelay || DrawioFile.prototype.autosaveDelay;
  722. if (config.templateFile != null)
  723. {
  724. EditorUi.templateFile = config.templateFile;
  725. }
  726. if (config.globalVars != null)
  727. {
  728. Editor.globalVars = config.globalVars;
  729. }
  730. if (config.compressXml != null)
  731. {
  732. Editor.compressXml = config.compressXml;
  733. }
  734. if (config.customFonts)
  735. {
  736. Menus.prototype.defaultFonts = config.customFonts.
  737. concat(Menus.prototype.defaultFonts);
  738. }
  739. if (config.customPresetColors)
  740. {
  741. ColorDialog.prototype.presetColors = config.customPresetColors.
  742. concat(ColorDialog.prototype.presetColors);
  743. }
  744. if (config.customColorSchemes != null)
  745. {
  746. StyleFormatPanel.prototype.defaultColorSchemes = config.customColorSchemes.
  747. concat(StyleFormatPanel.prototype.defaultColorSchemes);
  748. }
  749. // Custom CSS injected directly into the page
  750. if (config.css != null)
  751. {
  752. var s = document.createElement('style');
  753. s.setAttribute('type', 'text/css');
  754. s.appendChild(document.createTextNode(config.css));
  755. var t = document.getElementsByTagName('script')[0];
  756. t.parentNode.insertBefore(s, t);
  757. }
  758. // Configures the custom libraries
  759. if (config.libraries != null)
  760. {
  761. Sidebar.prototype.customEntries = config.libraries;
  762. }
  763. // Defines the enabled built-in libraries.
  764. if (config.enabledLibraries != null)
  765. {
  766. Sidebar.prototype.enabledLibraries = config.enabledLibraries;
  767. }
  768. // Overrides default libraries
  769. if (config.defaultLibraries != null)
  770. {
  771. Sidebar.prototype.defaultEntries = config.defaultLibraries;
  772. }
  773. // Overrides default custom libraries
  774. if (config.defaultCustomLibraries != null)
  775. {
  776. Editor.defaultCustomLibraries = config.defaultCustomLibraries;
  777. }
  778. // Disables custom libraries
  779. if (config.enableCustomLibraries != null)
  780. {
  781. Editor.enableCustomLibraries = config.enableCustomLibraries;
  782. }
  783. // Overrides default vertex style
  784. if (config.defaultVertexStyle != null)
  785. {
  786. Graph.prototype.defaultVertexStyle = config.defaultVertexStyle;
  787. }
  788. // Overrides default edge style
  789. if (config.defaultEdgeStyle != null)
  790. {
  791. Graph.prototype.defaultEdgeStyle = config.defaultEdgeStyle;
  792. }
  793. if (config.emptyDiagramXml)
  794. {
  795. EditorUi.prototype.emptyDiagramXml = config.emptyDiagramXml;
  796. }
  797. if (config.thumbWidth)
  798. {
  799. Sidebar.prototype.thumbWidth = config.thumbWidth;
  800. }
  801. if (config.thumbHeight)
  802. {
  803. Sidebar.prototype.thumbHeight = config.thumbHeight;
  804. }
  805. if (config.emptyLibraryXml)
  806. {
  807. EditorUi.prototype.emptyLibraryXml = config.emptyLibraryXml;
  808. }
  809. if (config.sidebarWidth)
  810. {
  811. EditorUi.prototype.hsplitPosition = config.sidebarWidth;
  812. }
  813. if (config.fontCss)
  814. {
  815. Editor.configureFontCss(config.fontCss);
  816. }
  817. if (config.autosaveDelay != null)
  818. {
  819. var val = parseInt(config.autosaveDelay);
  820. if (!isNaN(val) && val > 0)
  821. {
  822. DrawioFile.prototype.autosaveDelay = val;
  823. }
  824. else
  825. {
  826. EditorUi.debug('Invalid autosaveDelay: ' + config.autosaveDelay);
  827. }
  828. }
  829. if (config.plugins != null && !untrusted)
  830. {
  831. // Required for callback
  832. App.initPluginCallback();
  833. for (var i = 0; i < config.plugins.length; i++)
  834. {
  835. mxscript(config.plugins[i]);
  836. }
  837. }
  838. }
  839. };
  840. /**
  841. * Adds the global fontCss configuration.
  842. */
  843. Editor.configureFontCss = function(fontCss)
  844. {
  845. if (fontCss != null)
  846. {
  847. Editor.prototype.fontCss = fontCss;
  848. var t = document.getElementsByTagName('script')[0];
  849. if (t != null && t.parentNode != null)
  850. {
  851. var s = document.createElement('style');
  852. s.setAttribute('type', 'text/css');
  853. s.appendChild(document.createTextNode(fontCss));
  854. t.parentNode.insertBefore(s, t);
  855. // Preloads fonts where supported
  856. var parts = fontCss.split('url(');
  857. // Strips leading and trailing quotes and spaces
  858. function trimString(str)
  859. {
  860. return str.replace(new RegExp("^[\\s\"']+", "g"), "").replace(new RegExp("[\\s\"']+$", "g"), "");
  861. };
  862. for (var i = 1; i < parts.length; i++)
  863. {
  864. var idx = parts[i].indexOf(')');
  865. var url = trimString(parts[i].substring(0, idx));
  866. var l = document.createElement('link');
  867. l.setAttribute('rel', 'preload');
  868. l.setAttribute('href', url);
  869. l.setAttribute('as', 'font');
  870. l.setAttribute('crossorigin', '');
  871. t.parentNode.insertBefore(l, t);
  872. }
  873. }
  874. }
  875. };
  876. Editor.GOOGLE_FONTS = 'https://fonts.googleapis.com/css?family=';
  877. /**
  878. * Generates a unique ID of the given length
  879. */
  880. Editor.GUID_ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_';
  881. /**
  882. * Generates a unique ID of the given length
  883. */
  884. Editor.GUID_LENGTH = 20;
  885. /**
  886. * Generates a unique ID of the given length
  887. */
  888. Editor.guid = function(length)
  889. {
  890. var len = (length != null) ? length : Editor.GUID_LENGTH;
  891. var rtn = [];
  892. for (var i = 0; i < len; i++)
  893. {
  894. rtn.push(Editor.GUID_ALPHABET.charAt(Math.floor(Math.random() * Editor.GUID_ALPHABET.length)));
  895. }
  896. return rtn.join('');
  897. };
  898. /**
  899. * General timeout is 25 seconds.
  900. */
  901. Editor.prototype.timeout = 25000;
  902. /**
  903. * Zoomed mathjax output is causing problems in Safari.
  904. */
  905. Editor.prototype.useForeignObjectForMath = !mxClient.IS_SF;
  906. /**
  907. * Executes the first step for connecting to Google Drive.
  908. */
  909. Editor.prototype.editButtonLink = (urlParams['edit'] != null) ? decodeURIComponent(urlParams['edit']) : null;
  910. /**
  911. * Adds support for old stylesheets and compressed files
  912. */
  913. var editorSetGraphXml = Editor.prototype.setGraphXml;
  914. Editor.prototype.setGraphXml = function(node)
  915. {
  916. node = (node != null && node.nodeName != 'mxlibrary') ? this.extractGraphModel(node) : null;
  917. if (node != null)
  918. {
  919. // Checks input for parser errors
  920. var errs = node.getElementsByTagName('parsererror');
  921. if (errs != null && errs.length > 0)
  922. {
  923. var elt = errs[0];
  924. var divs = elt.getElementsByTagName('div');
  925. if (divs != null && divs.length > 0)
  926. {
  927. elt = divs[0];
  928. }
  929. throw {message: mxUtils.getTextContent(elt)};
  930. }
  931. else if (node.nodeName == 'mxGraphModel')
  932. {
  933. var style = node.getAttribute('style') || 'default-style2';
  934. // Decodes the style if required
  935. if (urlParams['embed'] != '1' && (style == null || style == ''))
  936. {
  937. var node2 = (this.graph.themes != null) ?
  938. this.graph.themes['default-old'] :
  939. mxUtils.load(STYLE_PATH + '/default-old.xml').getDocumentElement();
  940. if (node2 != null)
  941. {
  942. var dec2 = new mxCodec(node2.ownerDocument);
  943. dec2.decode(node2, this.graph.getStylesheet());
  944. }
  945. }
  946. else if (style != this.graph.currentStyle)
  947. {
  948. var node2 = (this.graph.themes != null) ?
  949. this.graph.themes[style] :
  950. mxUtils.load(STYLE_PATH + '/' + style + '.xml').getDocumentElement()
  951. if (node2 != null)
  952. {
  953. var dec2 = new mxCodec(node2.ownerDocument);
  954. dec2.decode(node2, this.graph.getStylesheet());
  955. }
  956. }
  957. this.graph.currentStyle = style;
  958. this.graph.mathEnabled = (urlParams['math'] == '1' || node.getAttribute('math') == '1');
  959. var bgImg = node.getAttribute('backgroundImage');
  960. if (bgImg != null)
  961. {
  962. bgImg = JSON.parse(bgImg);
  963. this.graph.setBackgroundImage(new mxImage(bgImg.src, bgImg.width, bgImg.height));
  964. }
  965. else
  966. {
  967. this.graph.setBackgroundImage(null);
  968. }
  969. mxClient.NO_FO = ((this.graph.mathEnabled && !this.useForeignObjectForMath)) ?
  970. true : this.originalNoForeignObject;
  971. this.graph.useCssTransforms = !mxClient.NO_FO &&
  972. this.isChromelessView() &&
  973. this.graph.isCssTransformsSupported();
  974. this.graph.updateCssTransform();
  975. this.graph.setShadowVisible(node.getAttribute('shadow') == '1', false);
  976. var extFonts = node.getAttribute('extFonts');
  977. if (extFonts)
  978. {
  979. try
  980. {
  981. extFonts = extFonts.split('|').map(function(ef)
  982. {
  983. var parts = ef.split('^');
  984. return {name: parts[0], url: parts[1]};
  985. });
  986. for (var i = 0; i < extFonts.length; i++)
  987. {
  988. this.graph.addExtFont(extFonts[i].name, extFonts[i].url);
  989. }
  990. }
  991. catch(e)
  992. {
  993. console.log('ExtFonts format error: ' + e.message);
  994. }
  995. }
  996. }
  997. // Calls updateGraphComponents
  998. editorSetGraphXml.apply(this, arguments);
  999. }
  1000. else
  1001. {
  1002. throw {
  1003. message: mxResources.get('notADiagramFile') || 'Invalid data',
  1004. toString: function() { return this.message; }
  1005. };
  1006. }
  1007. };
  1008. /**
  1009. * Adds persistent style to file
  1010. */
  1011. var editorGetGraphXml = Editor.prototype.getGraphXml;
  1012. Editor.prototype.getGraphXml = function(ignoreSelection)
  1013. {
  1014. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  1015. var node = editorGetGraphXml.apply(this, arguments);
  1016. // Adds the current style
  1017. if (this.graph.currentStyle != null && this.graph.currentStyle != 'default-style2')
  1018. {
  1019. node.setAttribute('style', this.graph.currentStyle);
  1020. }
  1021. // Adds the background image
  1022. if (this.graph.backgroundImage != null)
  1023. {
  1024. node.setAttribute('backgroundImage', JSON.stringify(this.graph.backgroundImage));
  1025. }
  1026. node.setAttribute('math', (this.graph.mathEnabled) ? '1' : '0');
  1027. node.setAttribute('shadow', (this.graph.shadowVisible) ? '1' : '0');
  1028. if (this.graph.extFonts != null && this.graph.extFonts.length > 0)
  1029. {
  1030. var strExtFonts = this.graph.extFonts.map(function(ef)
  1031. {
  1032. return ef.name + '^' + ef.url;
  1033. });
  1034. node.setAttribute('extFonts', strExtFonts.join('|'));
  1035. }
  1036. return node;
  1037. };
  1038. /**
  1039. * Helper function to extract the graph model XML node.
  1040. */
  1041. Editor.prototype.isDataSvg = function(svg)
  1042. {
  1043. try
  1044. {
  1045. var svgRoot = mxUtils.parseXml(svg).documentElement;
  1046. var tmp = svgRoot.getAttribute('content');
  1047. if (tmp != null)
  1048. {
  1049. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  1050. {
  1051. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  1052. }
  1053. if (tmp != null && tmp.charAt(0) == '%')
  1054. {
  1055. tmp = decodeURIComponent(tmp);
  1056. }
  1057. if (tmp != null && tmp.length > 0)
  1058. {
  1059. var node = mxUtils.parseXml(tmp).documentElement;
  1060. return node.nodeName == 'mxfile' || node.nodeName == 'mxGraphModel';
  1061. }
  1062. }
  1063. }
  1064. catch (e)
  1065. {
  1066. // ignore
  1067. }
  1068. return false;
  1069. };
  1070. /**
  1071. * Helper function to extract the graph model XML node.
  1072. */
  1073. Editor.prototype.extractGraphModel = function(node, allowMxFile)
  1074. {
  1075. return Editor.extractGraphModel.apply(this, arguments);
  1076. };
  1077. /**
  1078. * Overrides reset graph.
  1079. */
  1080. var editorResetGraph = Editor.prototype.resetGraph;
  1081. Editor.prototype.resetGraph = function()
  1082. {
  1083. this.graph.mathEnabled = (urlParams['math'] == '1');
  1084. this.graph.view.x0 = null;
  1085. this.graph.view.y0 = null;
  1086. mxClient.NO_FO = ((this.graph.mathEnabled && !this.useForeignObjectForMath)) ?
  1087. true : this.originalNoForeignObject;
  1088. this.graph.useCssTransforms = !mxClient.NO_FO &&
  1089. this.isChromelessView() &&
  1090. this.graph.isCssTransformsSupported();
  1091. this.graph.updateCssTransform();
  1092. editorResetGraph.apply(this, arguments);
  1093. };
  1094. /**
  1095. * Math support.
  1096. */
  1097. var editorUpdateGraphComponents = Editor.prototype.updateGraphComponents;
  1098. Editor.prototype.updateGraphComponents = function()
  1099. {
  1100. editorUpdateGraphComponents.apply(this, arguments);
  1101. mxClient.NO_FO = ((this.graph.mathEnabled && !this.useForeignObjectForMath) &&
  1102. Editor.MathJaxRender != null) ? true : this.originalNoForeignObject;
  1103. this.graph.useCssTransforms = !mxClient.NO_FO &&
  1104. this.isChromelessView() &&
  1105. this.graph.isCssTransformsSupported();
  1106. this.graph.updateCssTransform();
  1107. };
  1108. /**
  1109. * Initializes math typesetting and loads respective code.
  1110. */
  1111. Editor.initMath = function(src, config)
  1112. {
  1113. src = (src != null) ? src : DRAW_MATH_URL + '/MathJax.js?config=TeX-MML-AM_HTMLorMML';
  1114. Editor.mathJaxQueue = [];
  1115. Editor.doMathJaxRender = function(container)
  1116. {
  1117. window.setTimeout(function()
  1118. {
  1119. if (container.style.visibility != 'hidden')
  1120. {
  1121. MathJax.Hub.Queue(['Typeset', MathJax.Hub, container]);
  1122. }
  1123. }, 0);
  1124. };
  1125. // Disables global typesetting and messages on startup, adds queue for
  1126. // asynchronous rendering while MathJax is loading
  1127. window.MathJax =
  1128. {
  1129. skipStartupTypeset: true,
  1130. showMathMenu: false,
  1131. messageStyle: 'none',
  1132. AuthorInit: function ()
  1133. {
  1134. // Specification recommends using SVG over HTML-CSS if browser is known
  1135. // Check if too inconsistent with image export and print output
  1136. MathJax.Hub.Config(config || {
  1137. jax: ['input/TeX', 'input/MathML', 'input/AsciiMath', 'output/HTML-CSS'],
  1138. extensions: ['tex2jax.js', 'mml2jax.js', 'asciimath2jax.js'],
  1139. 'HTML-CSS': {
  1140. imageFont: null
  1141. },
  1142. TeX: {
  1143. extensions: ['AMSmath.js', 'AMSsymbols.js', 'noErrors.js', 'noUndefined.js']
  1144. },
  1145. // Ignores math in in-place editor
  1146. tex2jax: {
  1147. ignoreClass: 'mxCellEditor'
  1148. },
  1149. asciimath2jax: {
  1150. ignoreClass: 'mxCellEditor'
  1151. }
  1152. });
  1153. MathJax.Hub.Register.StartupHook('Begin', function()
  1154. {
  1155. for (var i = 0; i < Editor.mathJaxQueue.length; i++)
  1156. {
  1157. Editor.doMathJaxRender(Editor.mathJaxQueue[i]);
  1158. }
  1159. });
  1160. }
  1161. };
  1162. // Adds global enqueue method for async rendering
  1163. Editor.MathJaxRender = function(container)
  1164. {
  1165. // Initial rendering when MathJax finished loading
  1166. if (typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined')
  1167. {
  1168. Editor.doMathJaxRender(container);
  1169. }
  1170. else
  1171. {
  1172. Editor.mathJaxQueue.push(container);
  1173. }
  1174. };
  1175. // Adds global clear queue method
  1176. Editor.MathJaxClear = function()
  1177. {
  1178. Editor.mathJaxQueue = [];
  1179. };
  1180. // Updates math typesetting after changes
  1181. var editorInit = Editor.prototype.init;
  1182. Editor.prototype.init = function()
  1183. {
  1184. editorInit.apply(this, arguments);
  1185. this.graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  1186. {
  1187. if (this.graph.container != null && this.graph.mathEnabled && !this.graph.blockMathRender)
  1188. {
  1189. Editor.MathJaxRender(this.graph.container);
  1190. }
  1191. }));
  1192. };
  1193. var tags = document.getElementsByTagName('script');
  1194. if (tags != null && tags.length > 0)
  1195. {
  1196. var script = document.createElement('script');
  1197. script.type = 'text/javascript';
  1198. script.src = src;
  1199. tags[0].parentNode.appendChild(script);
  1200. }
  1201. };
  1202. /**
  1203. * Return array of string values, or NULL if CSV string not well formed.
  1204. */
  1205. Editor.prototype.csvToArray = function(text)
  1206. {
  1207. var re_valid = /^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;
  1208. var re_value = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g;
  1209. // Return NULL if input string is not well formed CSV string.
  1210. if (!re_valid.test(text)) return null;
  1211. var a = []; // Initialize array to receive values.
  1212. text.replace(re_value, // "Walk" the string using replace with callback.
  1213. function(m0, m1, m2, m3) {
  1214. // Remove backslash from \' in single quoted values.
  1215. if (m1 !== undefined) a.push(m1.replace(/\\'/g, "'"));
  1216. // Remove backslash from \" in double quoted values.
  1217. else if (m2 !== undefined) a.push(m2.replace(/\\"/g, '"'));
  1218. else if (m3 !== undefined) a.push(m3);
  1219. return ''; // Return empty string.
  1220. });
  1221. // Handle special case of empty last value.
  1222. if (/,\s*$/.test(text)) a.push('');
  1223. return a;
  1224. };
  1225. /**
  1226. * Returns true if the given URL is known to have CORS headers.
  1227. */
  1228. Editor.prototype.isCorsEnabledForUrl = function(url)
  1229. {
  1230. //Disable proxy for electron since it doesn't exist (it is served locally) and it works with most of the sites
  1231. //The same with Chrome App, never use proxy
  1232. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  1233. {
  1234. return true;
  1235. }
  1236. if (urlParams['cors'] != null && this.corsRegExp == null)
  1237. {
  1238. this.corsRegExp = new RegExp(decodeURIComponent(urlParams['cors']));
  1239. }
  1240. return (this.corsRegExp != null && this.corsRegExp.test(url)) ||
  1241. url.substring(0, 34) === 'https://raw.githubusercontent.com/' ||
  1242. url.substring(0, 23) === 'https://cdn.rawgit.com/' ||
  1243. url.substring(0, 19) === 'https://rawgit.com/' ||
  1244. /^https?:\/\/[^\/]*\.blob.core.windows.net\//.test(url) ||
  1245. /^https?:\/\/[^\/]*\.iconfinder.com\//.test(url) ||
  1246. /^https?:\/\/[^\/]*\.draw\.io\/proxy/.test(url) ||
  1247. /^https?:\/\/[^\/]*\.github\.io\//.test(url);
  1248. };
  1249. //TODO This function is a replica of EditorUi one, it is planned to replace all calls to EditorUi one to point to this one
  1250. /**
  1251. * Converts all images in the SVG output to data URIs for immediate rendering
  1252. */
  1253. Editor.prototype.createImageUrlConverter = function()
  1254. {
  1255. var converter = new mxUrlConverter();
  1256. converter.updateBaseUrl();
  1257. // Extends convert to avoid CORS using an image proxy server where needed
  1258. var convert = converter.convert;
  1259. var self = this;
  1260. converter.convert = function(src)
  1261. {
  1262. if (src != null)
  1263. {
  1264. var remote = src.substring(0, 7) == 'http://' || src.substring(0, 8) == 'https://';
  1265. if (remote && !navigator.onLine)
  1266. {
  1267. src = EditorUi.prototype.svgBrokenImage.src; //TODO move it to Editor?
  1268. }
  1269. else if (remote && src.substring(0, converter.baseUrl.length) != converter.baseUrl &&
  1270. (!EditorUi.prototype.crossOriginImages || !self.isCorsEnabledForUrl(src))) //TODO move it to Editor?
  1271. {
  1272. src = PROXY_URL + '?url=' + encodeURIComponent(src);
  1273. }
  1274. else if (src.substring(0, 19) != 'chrome-extension://' && !mxClient.IS_CHROMEAPP)
  1275. {
  1276. src = convert.apply(this, arguments);
  1277. }
  1278. }
  1279. return src;
  1280. };
  1281. return converter;
  1282. };
  1283. //TODO This function is a replica of EditorUi one, it is planned to replace all calls to EditorUi one to point to this one
  1284. /**
  1285. *
  1286. */
  1287. Editor.prototype.createSvgDataUri = function(svg)
  1288. {
  1289. return 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
  1290. };
  1291. //TODO This function is a replica of EditorUi one, it is planned to replace all calls to EditorUi one to point to this one
  1292. /**
  1293. *
  1294. */
  1295. Editor.prototype.convertImageToDataUri = function(url, callback)
  1296. {
  1297. if (/(\.svg)$/i.test(url))
  1298. {
  1299. mxUtils.get(url, mxUtils.bind(this, function(req)
  1300. {
  1301. callback(this.createSvgDataUri(req.getText()));
  1302. }),
  1303. function()
  1304. {
  1305. callback(EditorUi.prototype.svgBrokenImage.src);
  1306. });
  1307. }
  1308. else
  1309. {
  1310. var img = new Image();
  1311. var self = this;
  1312. if (EditorUi.prototype.crossOriginImages)
  1313. {
  1314. img.crossOrigin = 'anonymous';
  1315. }
  1316. img.onload = function()
  1317. {
  1318. var canvas = document.createElement('canvas');
  1319. var ctx = canvas.getContext('2d');
  1320. canvas.height = img.height;
  1321. canvas.width = img.width;
  1322. ctx.drawImage(img, 0, 0);
  1323. try
  1324. {
  1325. callback(canvas.toDataURL());
  1326. }
  1327. catch (e)
  1328. {
  1329. callback(EditorUi.prototype.svgBrokenImage.src);
  1330. }
  1331. };
  1332. img.onerror = function()
  1333. {
  1334. callback(EditorUi.prototype.svgBrokenImage.src);
  1335. };
  1336. img.src = url;
  1337. }
  1338. };
  1339. //TODO This function is a replica of EditorUi one, it is planned to replace all calls to EditorUi one to point to this one
  1340. /**
  1341. * Converts all images in the SVG output to data URIs for immediate rendering
  1342. */
  1343. Editor.prototype.convertImages = function(svgRoot, callback, imageCache, converter)
  1344. {
  1345. // Converts images to data URLs for immediate painting
  1346. if (converter == null)
  1347. {
  1348. converter = this.createImageUrlConverter();
  1349. }
  1350. // Barrier for asynchronous image loading
  1351. var counter = 0;
  1352. function inc()
  1353. {
  1354. counter++;
  1355. };
  1356. function dec()
  1357. {
  1358. counter--;
  1359. if (counter == 0)
  1360. {
  1361. callback(svgRoot);
  1362. }
  1363. };
  1364. var cache = imageCache || new Object();
  1365. var convertImages = mxUtils.bind(this, function(tagName, srcAttr)
  1366. {
  1367. var images = svgRoot.getElementsByTagName(tagName);
  1368. for (var i = 0; i < images.length; i++)
  1369. {
  1370. (mxUtils.bind(this, function(img)
  1371. {
  1372. var src = converter.convert(img.getAttribute(srcAttr));
  1373. // Data URIs are pass-through
  1374. if (src != null && src.substring(0, 5) != 'data:')
  1375. {
  1376. var tmp = cache[src];
  1377. if (tmp == null)
  1378. {
  1379. inc();
  1380. this.convertImageToDataUri(src, function(uri)
  1381. {
  1382. if (uri != null)
  1383. {
  1384. cache[src] = uri;
  1385. img.setAttribute(srcAttr, uri);
  1386. }
  1387. dec();
  1388. });
  1389. }
  1390. else
  1391. {
  1392. img.setAttribute(srcAttr, tmp);
  1393. }
  1394. }
  1395. else if (src != null)
  1396. {
  1397. img.setAttribute(srcAttr, src);
  1398. }
  1399. }))(images[i]);
  1400. }
  1401. });
  1402. // Converts all known image tags in output
  1403. // LATER: Add support for images in CSS
  1404. convertImages('image', 'xlink:href');
  1405. convertImages('img', 'src');
  1406. // All from cache or no images
  1407. if (counter == 0)
  1408. {
  1409. callback(svgRoot);
  1410. }
  1411. };
  1412. //TODO This function is a replica of EditorUi one, it is planned to replace all calls to EditorUi one to point to this one
  1413. /**
  1414. * Base64 encodes the given string. This method seems to be more
  1415. * robust for encoding PNG from binary AJAX responses.
  1416. */
  1417. Editor.prototype.base64Encode = function(str)
  1418. {
  1419. var CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  1420. var out = "", i = 0, len = str.length, c1, c2, c3;
  1421. while (i < len)
  1422. {
  1423. c1 = str.charCodeAt(i++) & 0xff;
  1424. if (i == len)
  1425. {
  1426. out += CHARS.charAt(c1 >> 2);
  1427. out += CHARS.charAt((c1 & 0x3) << 4);
  1428. out += "==";
  1429. break;
  1430. }
  1431. c2 = str.charCodeAt(i++);
  1432. if (i == len)
  1433. {
  1434. out += CHARS.charAt(c1 >> 2);
  1435. out += CHARS.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  1436. out += CHARS.charAt((c2 & 0xF) << 2);
  1437. out += "=";
  1438. break;
  1439. }
  1440. c3 = str.charCodeAt(i++);
  1441. out += CHARS.charAt(c1 >> 2);
  1442. out += CHARS.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
  1443. out += CHARS.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
  1444. out += CHARS.charAt(c3 & 0x3F);
  1445. }
  1446. return out;
  1447. };
  1448. //TODO This function is a replica of EditorUi one, it is planned to replace all calls to EditorUi one to point to this one
  1449. /**
  1450. * Checks if the client is authorized and calls the next step.
  1451. */
  1452. Editor.prototype.loadUrl = function(url, success, error, forceBinary, retry, dataUriPrefix)
  1453. {
  1454. try
  1455. {
  1456. var binary = forceBinary || /(\.png)($|\?)/i.test(url) ||
  1457. /(\.jpe?g)($|\?)/i.test(url) || /(\.gif)($|\?)/i.test(url);
  1458. retry = (retry != null) ? retry : true;
  1459. var fn = mxUtils.bind(this, function()
  1460. {
  1461. mxUtils.get(url, mxUtils.bind(this, function(req)
  1462. {
  1463. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  1464. {
  1465. if (success != null)
  1466. {
  1467. var data = req.getText();
  1468. // Returns PNG as base64 encoded data URI
  1469. if (binary)
  1470. {
  1471. // NOTE: This requires BinaryToArray VB script in the page
  1472. if ((document.documentMode == 9 || document.documentMode == 10) &&
  1473. typeof window.mxUtilsBinaryToArray !== 'undefined')
  1474. {
  1475. var bin = mxUtilsBinaryToArray(req.request.responseBody).toArray();
  1476. var tmp = new Array(bin.length);
  1477. for (var i = 0; i < bin.length; i++)
  1478. {
  1479. tmp[i] = String.fromCharCode(bin[i]);
  1480. }
  1481. data = tmp.join('');
  1482. }
  1483. // LATER: Could be JPG but modern browsers
  1484. // ignore the mime type in the data URI
  1485. dataUriPrefix = (dataUriPrefix != null) ? dataUriPrefix : 'data:image/png;base64,';
  1486. data = dataUriPrefix + this.base64Encode(data);
  1487. }
  1488. success(data);
  1489. }
  1490. }
  1491. else if (error != null)
  1492. {
  1493. error({code: App.ERROR_UNKNOWN}, req);
  1494. }
  1495. }), function()
  1496. {
  1497. if (error != null)
  1498. {
  1499. error({code: App.ERROR_UNKNOWN});
  1500. }
  1501. }, binary, this.timeout, function()
  1502. {
  1503. if (retry && error != null)
  1504. {
  1505. error({code: App.ERROR_TIMEOUT, retry: fn});
  1506. }
  1507. });
  1508. });
  1509. fn();
  1510. }
  1511. catch (e)
  1512. {
  1513. if (error != null)
  1514. {
  1515. error(e);
  1516. }
  1517. }
  1518. };
  1519. //TODO This function is a replica of EditorUi one, it is planned to replace all calls to EditorUi one to point to this one
  1520. /**
  1521. * For the fontCSS to be applied when rendering images on canvas, the actual
  1522. * font data must be made available via a data URI encoding of the file.
  1523. */
  1524. Editor.prototype.loadFonts = function(then)
  1525. {
  1526. if (this.fontCss != null && this.resolvedFontCss == null)
  1527. {
  1528. var parts = this.fontCss.split('url(');
  1529. var waiting = 0;
  1530. var fonts = {};
  1531. // Strips leading and trailing quotes and spaces
  1532. function trimString(str)
  1533. {
  1534. return str.replace(new RegExp("^[\\s\"']+", "g"), "").replace(new RegExp("[\\s\"']+$", "g"), "");
  1535. };
  1536. var finish = mxUtils.bind(this, function()
  1537. {
  1538. if (waiting == 0)
  1539. {
  1540. // Constructs string
  1541. var result = [parts[0]];
  1542. for (var j = 1; j < parts.length; j++)
  1543. {
  1544. var idx = parts[j].indexOf(')');
  1545. result.push('url("');
  1546. result.push(fonts[trimString(parts[j].substring(0, idx))]);
  1547. result.push('"' + parts[j].substring(idx));
  1548. }
  1549. this.resolvedFontCss = result.join('');
  1550. then();
  1551. }
  1552. });
  1553. if (parts.length > 0)
  1554. {
  1555. for (var i = 1; i < parts.length; i++)
  1556. {
  1557. var idx = parts[i].indexOf(')');
  1558. var format = null;
  1559. // Checks if there is a format directive
  1560. var fmtIdx = parts[i].indexOf('format(', idx);
  1561. if (fmtIdx > 0)
  1562. {
  1563. format = trimString(parts[i].substring(fmtIdx + 7, parts[i].indexOf(')', fmtIdx)));
  1564. }
  1565. (mxUtils.bind(this, function(url)
  1566. {
  1567. if (fonts[url] == null)
  1568. {
  1569. // Mark font es being fetched and fetch it
  1570. fonts[url] = url;
  1571. waiting++;
  1572. var mime = 'application/x-font-ttf';
  1573. // See https://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts
  1574. if (format == 'svg' || /(\.svg)($|\?)/i.test(url))
  1575. {
  1576. mime = 'image/svg+xml';
  1577. }
  1578. else if (format == 'otf' || format == 'embedded-opentype' || /(\.otf)($|\?)/i.test(url))
  1579. {
  1580. mime = 'application/x-font-opentype';
  1581. }
  1582. else if (format == 'woff' || /(\.woff)($|\?)/i.test(url))
  1583. {
  1584. mime = 'application/font-woff';
  1585. }
  1586. else if (format == 'woff2' || /(\.woff2)($|\?)/i.test(url))
  1587. {
  1588. mime = 'application/font-woff2';
  1589. }
  1590. else if (format == 'eot' || /(\.eot)($|\?)/i.test(url))
  1591. {
  1592. mime = 'application/vnd.ms-fontobject';
  1593. }
  1594. else if (format == 'sfnt' || /(\.sfnt)($|\?)/i.test(url))
  1595. {
  1596. mime = 'application/font-sfnt';
  1597. }
  1598. var realUrl = url;
  1599. if ((/^https?:\/\//.test(realUrl)) && !this.isCorsEnabledForUrl(realUrl))
  1600. {
  1601. realUrl = PROXY_URL + '?url=' + encodeURIComponent(url);
  1602. }
  1603. // LATER: Remove cache-control header
  1604. this.loadUrl(realUrl, mxUtils.bind(this, function(uri)
  1605. {
  1606. fonts[url] = uri;
  1607. waiting--;
  1608. finish();
  1609. }), mxUtils.bind(this, function(err)
  1610. {
  1611. // LATER: handle error
  1612. waiting--;
  1613. finish();
  1614. }), true, null, 'data:' + mime + ';charset=utf-8;base64,');
  1615. }
  1616. }))(trimString(parts[i].substring(0, idx)), format);
  1617. }
  1618. }
  1619. }
  1620. else
  1621. {
  1622. then();
  1623. }
  1624. };
  1625. /**
  1626. * Copies MathJax CSS into the SVG output.
  1627. */
  1628. Editor.prototype.addMathCss = function(svgRoot)
  1629. {
  1630. var defs = svgRoot.getElementsByTagName('defs');
  1631. if (defs != null && defs.length > 0)
  1632. {
  1633. var styles = document.getElementsByTagName('style');
  1634. for (var i = 0; i < styles.length; i++)
  1635. {
  1636. // Ignores style elements with no MathJax CSS
  1637. if (mxUtils.getTextContent(styles[i]).indexOf('MathJax') > 0)
  1638. {
  1639. defs[0].appendChild(styles[i].cloneNode(true));
  1640. }
  1641. }
  1642. }
  1643. };
  1644. /**
  1645. * Adds the global fontCss configuration.
  1646. */
  1647. Editor.prototype.addFontCss = function(svgRoot, fontCss)
  1648. {
  1649. fontCss = (fontCss != null) ? fontCss : this.fontCss;
  1650. // Creates defs element if not available
  1651. if (fontCss != null)
  1652. {
  1653. var defs = svgRoot.getElementsByTagName('defs');
  1654. var svgDoc = svgRoot.ownerDocument;
  1655. var defsElt = null;
  1656. if (defs.length == 0)
  1657. {
  1658. defsElt = (svgDoc.createElementNS != null) ?
  1659. svgDoc.createElementNS(mxConstants.NS_SVG, 'defs') : svgDoc.createElement('defs');
  1660. if (svgRoot.firstChild != null)
  1661. {
  1662. svgRoot.insertBefore(defsElt, svgRoot.firstChild);
  1663. }
  1664. else
  1665. {
  1666. svgRoot.appendChild(defsElt);
  1667. }
  1668. }
  1669. else
  1670. {
  1671. defsElt = defs[0];
  1672. }
  1673. var style = (svgDoc.createElementNS != null) ?
  1674. svgDoc.createElementNS(mxConstants.NS_SVG, 'style') : svgDoc.createElement('style');
  1675. style.setAttribute('type', 'text/css');
  1676. mxUtils.setTextContent(style, fontCss);
  1677. defsElt.appendChild(style);
  1678. }
  1679. };
  1680. /**
  1681. * See fixme in convertMath for client-side image generation with math.
  1682. */
  1683. Editor.prototype.isExportToCanvas = function()
  1684. {
  1685. // LATER: Fix math rendering in Safari and CSS in Chrome on Windows and Linux
  1686. return mxClient.IS_CHROMEAPP || (this.useCanvasForExport && (!this.graph.mathEnabled ||
  1687. (!mxClient.IS_SF && !((mxClient.IS_GC || mxClient.IS_EDGE) && !mxClient.IS_MAC))));
  1688. };
  1689. //TODO This function is a replica of EditorUi one, it is planned to replace all calls to EditorUi one to point to this one
  1690. /**
  1691. *
  1692. */
  1693. Editor.prototype.exportToCanvas = function(callback, width, imageCache, background, error, limitHeight,
  1694. ignoreSelection, scale, transparentBackground, addShadow, converter, graph, border, noCrop)
  1695. {
  1696. limitHeight = (limitHeight != null) ? limitHeight : true;
  1697. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  1698. graph = (graph != null) ? graph : this.graph;
  1699. border = (border != null) ? border : 0;
  1700. var bg = (transparentBackground) ? null : graph.background;
  1701. if (bg == mxConstants.NONE)
  1702. {
  1703. bg = null;
  1704. }
  1705. if (bg == null)
  1706. {
  1707. bg = background;
  1708. }
  1709. // Handles special case where background is null but transparent is false
  1710. if (bg == null && transparentBackground == false)
  1711. {
  1712. bg = this.graph.defaultPageBackgroundColor;
  1713. }
  1714. this.convertImages(graph.getSvg(bg, null, null, noCrop, null, ignoreSelection, null, null, null, addShadow),
  1715. mxUtils.bind(this, function(svgRoot)
  1716. {
  1717. var img = new Image();
  1718. img.onload = mxUtils.bind(this, function()
  1719. {
  1720. try
  1721. {
  1722. var canvas = document.createElement('canvas');
  1723. var w = parseInt(svgRoot.getAttribute('width'));
  1724. var h = parseInt(svgRoot.getAttribute('height'));
  1725. scale = (scale != null) ? scale : 1;
  1726. if (width != null)
  1727. {
  1728. scale = (!limitHeight) ? width / w : Math.min(1, Math.min((width * 3) / (h * 4), width / w));
  1729. }
  1730. w = Math.ceil(scale * w) + 2 * border;
  1731. h = Math.ceil(scale * h) + 2 * border;
  1732. canvas.setAttribute('width', w);
  1733. canvas.setAttribute('height', h);
  1734. var ctx = canvas.getContext('2d');
  1735. if (bg != null)
  1736. {
  1737. ctx.beginPath();
  1738. ctx.rect(0, 0, w, h);
  1739. ctx.fillStyle = bg;
  1740. ctx.fill();
  1741. }
  1742. ctx.scale(scale, scale);
  1743. // Workaround for broken data URI images in Safari on first export
  1744. if (mxClient.IS_SF)
  1745. {
  1746. window.setTimeout(function()
  1747. {
  1748. ctx.drawImage(img, border / scale, border / scale);
  1749. callback(canvas);
  1750. }, 0);
  1751. }
  1752. else
  1753. {
  1754. ctx.drawImage(img, border / scale, border / scale);
  1755. callback(canvas);
  1756. }
  1757. }
  1758. catch (e)
  1759. {
  1760. if (error != null)
  1761. {
  1762. error(e);
  1763. }
  1764. }
  1765. });
  1766. img.onerror = function(e)
  1767. {
  1768. //console.log('img', e, img.src);
  1769. if (error != null)
  1770. {
  1771. error(e);
  1772. }
  1773. };
  1774. try
  1775. {
  1776. if (addShadow)
  1777. {
  1778. this.graph.addSvgShadow(svgRoot);
  1779. }
  1780. var done = mxUtils.bind(this, function()
  1781. {
  1782. if (this.resolvedFontCss != null)
  1783. {
  1784. var st = document.createElement('style');
  1785. st.setAttribute('type', 'text/css');
  1786. st.innerHTML = this.resolvedFontCss;
  1787. // Must be in defs section for FF to work
  1788. var defs = svgRoot.getElementsByTagName('defs');
  1789. defs[0].appendChild(st);
  1790. }
  1791. if (graph.mathEnabled)
  1792. {
  1793. this.addMathCss(svgRoot);
  1794. }
  1795. img.src = this.createSvgDataUri(mxUtils.getXml(svgRoot));
  1796. });
  1797. this.loadFonts(done);
  1798. }
  1799. catch (e)
  1800. {
  1801. //console.log('src', e, img.src);
  1802. if (error != null)
  1803. {
  1804. error(e);
  1805. }
  1806. }
  1807. }), imageCache, converter);
  1808. };
  1809. //TODO This function is a replica of EditorUi one, it is planned to replace all calls to EditorUi one to point to this one
  1810. /**
  1811. * Adds the given text to the compressed or non-compressed text chunk.
  1812. */
  1813. Editor.prototype.writeGraphModelToPng = function(data, type, key, value, error)
  1814. {
  1815. var base64 = data.substring(data.indexOf(',') + 1);
  1816. var f = (window.atob) ? atob(base64) : Base64.decode(base64, true);
  1817. var pos = 0;
  1818. function fread(d, count)
  1819. {
  1820. var start = pos;
  1821. pos += count;
  1822. return d.substring(start, pos);
  1823. };
  1824. // Reads unsigned long 32 bit big endian
  1825. function _freadint(d)
  1826. {
  1827. var bytes = fread(d, 4);
  1828. return bytes.charCodeAt(3) + (bytes.charCodeAt(2) << 8) +
  1829. (bytes.charCodeAt(1) << 16) + (bytes.charCodeAt(0) << 24);
  1830. };
  1831. function writeInt(num)
  1832. {
  1833. return String.fromCharCode((num >> 24) & 0x000000ff, (num >> 16) & 0x000000ff,
  1834. (num >> 8) & 0x000000ff, num & 0x000000ff);
  1835. };
  1836. // Checks signature
  1837. if (fread(f,8) != String.fromCharCode(137) + 'PNG' + String.fromCharCode(13, 10, 26, 10))
  1838. {
  1839. if (error != null)
  1840. {
  1841. error();
  1842. }
  1843. return;
  1844. }
  1845. // Reads header chunk
  1846. fread(f,4);
  1847. if (fread(f,4) != 'IHDR')
  1848. {
  1849. if (error != null)
  1850. {
  1851. error();
  1852. }
  1853. return;
  1854. }
  1855. fread(f, 17);
  1856. var result = f.substring(0, pos);
  1857. do
  1858. {
  1859. var n = _freadint(f);
  1860. var chunk = fread(f,4);
  1861. if (chunk == 'IDAT')
  1862. {
  1863. result = f.substring(0, pos - 8);
  1864. var chunkData = key + String.fromCharCode(0) +
  1865. ((type == 'zTXt') ? String.fromCharCode(0) : '') +
  1866. value;
  1867. var crc = 0xffffffff;
  1868. crc = EditorUi.prototype.updateCRC(crc, type, 0, 4); //TODO move code to Editor?
  1869. crc = EditorUi.prototype.updateCRC(crc, chunkData, 0, chunkData.length);
  1870. result += writeInt(chunkData.length) + type + chunkData + writeInt(crc ^ 0xffffffff);
  1871. result += f.substring(pos - 8, f.length);
  1872. break;
  1873. }
  1874. result += f.substring(pos - 8, pos - 4 + n);
  1875. fread(f,n);
  1876. fread(f,4);
  1877. }
  1878. while (n);
  1879. return 'data:image/png;base64,' + ((window.btoa) ? btoa(result) : Base64.encode(result, true));
  1880. }
  1881. /**
  1882. * Adds persistence for recent colors
  1883. */
  1884. if (window.ColorDialog)
  1885. {
  1886. FilenameDialog.filenameHelpLink = 'https://desk.draw.io/support/solutions/articles/16000091426';
  1887. var colorDialogAddRecentColor = ColorDialog.addRecentColor;
  1888. ColorDialog.addRecentColor = function(color, max)
  1889. {
  1890. colorDialogAddRecentColor.apply(this, arguments);
  1891. mxSettings.setRecentColors(ColorDialog.recentColors);
  1892. mxSettings.save();
  1893. };
  1894. var colorDialogResetRecentColors = ColorDialog.resetRecentColors;
  1895. ColorDialog.resetRecentColors = function()
  1896. {
  1897. colorDialogResetRecentColors.apply(this, arguments);
  1898. mxSettings.setRecentColors(ColorDialog.recentColors);
  1899. mxSettings.save();
  1900. };
  1901. }
  1902. // Overrides ID for pages
  1903. if (window.EditDataDialog)
  1904. {
  1905. EditDataDialog.getDisplayIdForCell = function(ui, cell)
  1906. {
  1907. var id = null;
  1908. if (ui.editor.graph.getModel().getParent(cell) != null)
  1909. {
  1910. id = cell.getId();
  1911. }
  1912. else if (ui.currentPage != null)
  1913. {
  1914. id = ui.currentPage.getId();
  1915. }
  1916. return id;
  1917. };
  1918. }
  1919. var AddCustomPropertyDialog = function(editorUi, callback)
  1920. {
  1921. var row, td;
  1922. var table = document.createElement('table');
  1923. var tbody = document.createElement('tbody');
  1924. table.setAttribute('cellpadding', (mxClient.IS_SF) ? '0' : '2');
  1925. row = document.createElement('tr');
  1926. td = document.createElement('td');
  1927. td.style.fontSize = '10pt';
  1928. td.style.width = '100px';
  1929. mxUtils.write(td, mxResources.get('name', null, 'Name') + ':');
  1930. row.appendChild(td);
  1931. var nameInput = document.createElement('input');
  1932. nameInput.style.width = '180px';
  1933. td = document.createElement('td');
  1934. td.appendChild(nameInput);
  1935. row.appendChild(td);
  1936. tbody.appendChild(row);
  1937. row = document.createElement('tr');
  1938. td = document.createElement('td');
  1939. td.style.fontSize = '10pt';
  1940. mxUtils.write(td, mxResources.get('type', null, 'Type') + ':');
  1941. row.appendChild(td);
  1942. var typeSelect = document.createElement('select');
  1943. typeSelect.style.width = '180px';
  1944. var boolOption = document.createElement('option');
  1945. boolOption.setAttribute('value', 'bool');
  1946. mxUtils.write(boolOption, mxResources.get('bool', null, 'Boolean'));
  1947. typeSelect.appendChild(boolOption);
  1948. var clrOption = document.createElement('option');
  1949. clrOption.setAttribute('value', 'color');
  1950. mxUtils.write(clrOption, mxResources.get('color', null, 'Color'));
  1951. typeSelect.appendChild(clrOption);
  1952. var enumOption = document.createElement('option');
  1953. enumOption.setAttribute('value', 'enum');
  1954. mxUtils.write(enumOption, mxResources.get('enum', null, 'Enumeration'));
  1955. typeSelect.appendChild(enumOption);
  1956. var floatOption = document.createElement('option');
  1957. floatOption.setAttribute('value', 'float');
  1958. mxUtils.write(floatOption, mxResources.get('float', null, 'Float'));
  1959. typeSelect.appendChild(floatOption);
  1960. var intOption = document.createElement('option');
  1961. intOption.setAttribute('value', 'int');
  1962. mxUtils.write(intOption, mxResources.get('int', null, 'Int'));
  1963. typeSelect.appendChild(intOption);
  1964. var strOption = document.createElement('option');
  1965. strOption.setAttribute('value', 'string');
  1966. mxUtils.write(strOption, mxResources.get('string', null, 'String'));
  1967. typeSelect.appendChild(strOption);
  1968. td = document.createElement('td');
  1969. td.appendChild(typeSelect);
  1970. row.appendChild(td);
  1971. tbody.appendChild(row);
  1972. row = document.createElement('tr');
  1973. td = document.createElement('td');
  1974. td.style.fontSize = '10pt';
  1975. mxUtils.write(td, mxResources.get('dispName', null, 'Display Name') + ':');
  1976. row.appendChild(td);
  1977. var dispNameInput = document.createElement('input');
  1978. dispNameInput.style.width = '180px';
  1979. td = document.createElement('td');
  1980. td.appendChild(dispNameInput);
  1981. row.appendChild(td);
  1982. tbody.appendChild(row);
  1983. var listRow = document.createElement('tr');
  1984. td = document.createElement('td');
  1985. td.style.fontSize = '10pt';
  1986. mxUtils.write(td, mxResources.get('enumList', null, 'Enum List') + ' (csv):');
  1987. listRow.appendChild(td);
  1988. var enumListInput = document.createElement('input');
  1989. enumListInput.style.width = '180px';
  1990. td = document.createElement('td');
  1991. td.appendChild(enumListInput);
  1992. listRow.appendChild(td);
  1993. listRow.style.display = 'none';
  1994. tbody.appendChild(listRow);
  1995. table.appendChild(tbody);
  1996. function typeChanged()
  1997. {
  1998. if (typeSelect.value === 'enum')
  1999. {
  2000. listRow.style.display = '';
  2001. this.container.parentNode.style.height = "150px";
  2002. }
  2003. else
  2004. {
  2005. listRow.style.display = 'none';
  2006. this.container.parentNode.style.height = "130px";
  2007. }
  2008. };
  2009. mxEvent.addListener(typeSelect, 'change', mxUtils.bind(this, typeChanged));
  2010. row = document.createElement('tr');
  2011. td = document.createElement('td');
  2012. td.setAttribute('align', 'right');
  2013. td.style.paddingTop = '22px';
  2014. td.colSpan = 2;
  2015. var addBtn = mxUtils.button(mxResources.get('add', null, 'Add'), mxUtils.bind(this, function()
  2016. {
  2017. var name = nameInput.value;
  2018. if (name == "")
  2019. {
  2020. nameInput.style.border = "1px solid red";
  2021. return;
  2022. }
  2023. var type = typeSelect.value;
  2024. var dispName = dispNameInput.value;
  2025. if (dispName == "")
  2026. {
  2027. dispNameInput.style.border = "1px solid red";
  2028. return;
  2029. }
  2030. var enumList = enumListInput.value;
  2031. if (enumList == "" && type == "enum")
  2032. {
  2033. enumListInput.style.border = "1px solid red";
  2034. return;
  2035. }
  2036. if (enumList != null)
  2037. {
  2038. enumList = enumList.split(',');
  2039. for (var i = 0; i < enumList.length; i++)
  2040. {
  2041. enumList[i] = enumList[i].trim();
  2042. }
  2043. }
  2044. if (callback)
  2045. {
  2046. callback(editorUi, name, type, dispName, enumList);
  2047. editorUi.hideDialog();
  2048. }
  2049. }));
  2050. addBtn.className = 'geBtn gePrimaryBtn';
  2051. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  2052. {
  2053. editorUi.hideDialog();
  2054. });
  2055. cancelBtn.className = 'geBtn';
  2056. if (editorUi.editor.cancelFirst)
  2057. {
  2058. td.appendChild(cancelBtn);
  2059. td.appendChild(addBtn);
  2060. }
  2061. else
  2062. {
  2063. td.appendChild(addBtn);
  2064. td.appendChild(cancelBtn);
  2065. }
  2066. row.appendChild(td);
  2067. tbody.appendChild(row);
  2068. table.appendChild(tbody);
  2069. this.container = table;
  2070. };
  2071. if (window.StyleFormatPanel != null)
  2072. {
  2073. var formatInit = Format.prototype.init;
  2074. Format.prototype.init = function()
  2075. {
  2076. formatInit.apply(this, arguments);
  2077. this.editorUi.editor.addListener('fileLoaded', this.update);
  2078. };
  2079. var formatRefresh = Format.prototype.refresh;
  2080. Format.prototype.refresh = function()
  2081. {
  2082. if (this.editorUi.getCurrentFile() != null || urlParams['embed'] == '1' ||
  2083. this.editorUi.editor.chromeless)
  2084. {
  2085. formatRefresh.apply(this, arguments);
  2086. }
  2087. else
  2088. {
  2089. this.clear();
  2090. }
  2091. };
  2092. /**
  2093. * Hook for subclassers.
  2094. */
  2095. DiagramFormatPanel.prototype.isShadowOptionVisible = function()
  2096. {
  2097. var file = this.editorUi.getCurrentFile();
  2098. return urlParams['embed'] == '1' || (file != null && file.isEditable());
  2099. };
  2100. /**
  2101. * Option is not visible in default theme.
  2102. */
  2103. DiagramFormatPanel.prototype.isMathOptionVisible = function(div)
  2104. {
  2105. return false;
  2106. };
  2107. /**
  2108. * Add global shadow option.
  2109. */
  2110. var diagramFormatPanelAddView = DiagramFormatPanel.prototype.addView;
  2111. DiagramFormatPanel.prototype.addView = function(div)
  2112. {
  2113. var div = diagramFormatPanelAddView.apply(this, arguments);
  2114. var file = this.editorUi.getCurrentFile();
  2115. if (mxClient.IS_SVG && this.isShadowOptionVisible())
  2116. {
  2117. var ui = this.editorUi;
  2118. var editor = ui.editor;
  2119. var graph = editor.graph;
  2120. var option = this.createOption(mxResources.get('shadow'), function()
  2121. {
  2122. return graph.shadowVisible;
  2123. }, function(checked)
  2124. {
  2125. var change = new ChangePageSetup(ui);
  2126. change.ignoreColor = true;
  2127. change.ignoreImage = true;
  2128. change.shadowVisible = checked;
  2129. graph.model.execute(change);
  2130. },
  2131. {
  2132. install: function(apply)
  2133. {
  2134. this.listener = function()
  2135. {
  2136. apply(graph.shadowVisible);
  2137. };
  2138. ui.addListener('shadowVisibleChanged', this.listener);
  2139. },
  2140. destroy: function()
  2141. {
  2142. ui.removeListener(this.listener);
  2143. }
  2144. });
  2145. if (!Editor.shadowOptionEnabled)
  2146. {
  2147. option.getElementsByTagName('input')[0].setAttribute('disabled', 'disabled');
  2148. mxUtils.setOpacity(option, 60);
  2149. }
  2150. div.appendChild(option);
  2151. }
  2152. return div;
  2153. };
  2154. /**
  2155. * Adds autosave and math typesetting options.
  2156. */
  2157. var diagramFormatPanelAddOptions = DiagramFormatPanel.prototype.addOptions;
  2158. DiagramFormatPanel.prototype.addOptions = function(div)
  2159. {
  2160. div = diagramFormatPanelAddOptions.apply(this, arguments);
  2161. var ui = this.editorUi;
  2162. var editor = ui.editor;
  2163. var graph = editor.graph;
  2164. if (graph.isEnabled())
  2165. {
  2166. var file = ui.getCurrentFile();
  2167. if (file != null && file.isAutosaveOptional())
  2168. {
  2169. var opt = this.createOption(mxResources.get('autosave'), function()
  2170. {
  2171. return ui.editor.autosave;
  2172. }, function(checked)
  2173. {
  2174. ui.editor.setAutosave(checked);
  2175. if (ui.editor.autosave && file.isModified())
  2176. {
  2177. file.fileChanged();
  2178. }
  2179. },
  2180. {
  2181. install: function(apply)
  2182. {
  2183. this.listener = function()
  2184. {
  2185. apply(ui.editor.autosave);
  2186. };
  2187. ui.editor.addListener('autosaveChanged', this.listener);
  2188. },
  2189. destroy: function()
  2190. {
  2191. ui.editor.removeListener(this.listener);
  2192. }
  2193. });
  2194. div.appendChild(opt);
  2195. }
  2196. }
  2197. if (this.isMathOptionVisible() && graph.isEnabled() && typeof(MathJax) !== 'undefined')
  2198. {
  2199. // Math
  2200. var option = this.createOption(mxResources.get('mathematicalTypesetting'), function()
  2201. {
  2202. return graph.mathEnabled;
  2203. }, function(checked)
  2204. {
  2205. ui.actions.get('mathematicalTypesetting').funct();
  2206. },
  2207. {
  2208. install: function(apply)
  2209. {
  2210. this.listener = function()
  2211. {
  2212. apply(graph.mathEnabled);
  2213. };
  2214. ui.addListener('mathEnabledChanged', this.listener);
  2215. },
  2216. destroy: function()
  2217. {
  2218. ui.removeListener(this.listener);
  2219. }
  2220. });
  2221. option.style.paddingTop = '5px';
  2222. div.appendChild(option);
  2223. var help = ui.menus.createHelpLink('https://desk.draw.io/support/solutions/articles/16000032875');
  2224. help.style.position = 'relative';
  2225. help.style.marginLeft = '6px';
  2226. help.style.top = '2px';
  2227. option.appendChild(help);
  2228. }
  2229. return div;
  2230. };
  2231. mxCellRenderer.prototype.defaultVertexShape.prototype.customProperties = [
  2232. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  2233. {name: 'absoluteArcSize', dispName: 'Abs. Arc Size', type: 'bool', defVal: false}
  2234. ];
  2235. mxCellRenderer.defaultShapes['link'].prototype.customProperties = [
  2236. {name: 'width', dispName: 'Width', type: 'float', min:0, defVal: 4}
  2237. ];
  2238. mxCellRenderer.defaultShapes['flexArrow'].prototype.customProperties = [
  2239. {name: 'width', dispName: 'Width', type: 'float', min:0, defVal: 10},
  2240. {name: 'startWidth', dispName: 'Start Width', type: 'float', min:0, defVal: 20},
  2241. {name: 'endWidth', dispName: 'End Width', type: 'float', min:0, defVal: 20}
  2242. ];
  2243. mxCellRenderer.defaultShapes['process'].prototype.customProperties = [
  2244. {name: 'size', dispName: 'Indent', type: 'float', min: 0, max: 0.5, defVal: 0.1}
  2245. ];
  2246. mxCellRenderer.defaultShapes['rhombus'].prototype.customProperties = [
  2247. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, max: 50, defVal: mxConstants.LINE_ARCSIZE},
  2248. {name: 'double', dispName: 'Double', type: 'bool', defVal: false}
  2249. ];
  2250. mxCellRenderer.defaultShapes['partialRectangle'].prototype.customProperties = [
  2251. {name: 'top', dispName: 'Top Line', type: 'bool', defVal: true},
  2252. {name: 'bottom', dispName: 'Bottom Line', type: 'bool', defVal: true},
  2253. {name: 'left', dispName: 'Left Line', type: 'bool', defVal: true},
  2254. {name: 'right', dispName: 'Right Line', type: 'bool', defVal: true}
  2255. ];
  2256. mxCellRenderer.defaultShapes['parallelogram'].prototype.customProperties = [
  2257. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  2258. {name: 'size', dispName: 'Slope Angle', type: 'float', min:0, max: 1, defVal: 0.2}
  2259. ];
  2260. mxCellRenderer.defaultShapes['hexagon'].prototype.customProperties = [
  2261. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  2262. {name: 'size', dispName: 'Slope Angle', type: 'float', min:0, max: 1, defVal: 0.25}
  2263. ];
  2264. mxCellRenderer.defaultShapes['triangle'].prototype.customProperties = [
  2265. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE}
  2266. ];
  2267. mxCellRenderer.defaultShapes['document'].prototype.customProperties = [
  2268. {name: 'size', dispName: 'Size', type: 'float', defVal: 0.3, min:0, max:1}
  2269. ];
  2270. mxCellRenderer.defaultShapes['internalStorage'].prototype.customProperties = [
  2271. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  2272. {name: 'dx', dispName: 'Left Line', type: 'float', min:0, defVal: 20},
  2273. {name: 'dy', dispName: 'Top Line', type: 'float', min:0, defVal: 20}
  2274. ];
  2275. mxCellRenderer.defaultShapes['cube'].prototype.customProperties = [
  2276. {name: 'size', dispName: 'Size', type: 'float', min:0, defVal:20 },
  2277. {name: 'darkOpacity', dispName: 'Dark Opacity', type: 'float', min:-1, max:1, defVal:0 },
  2278. {name: 'darkOpacity2', dispName: 'Dark Opacity 2', type: 'float', min:-1, max:1, defVal:0 }
  2279. ];
  2280. mxCellRenderer.defaultShapes['step'].prototype.customProperties = [
  2281. {name: 'size', dispName: 'Notch Size', type: 'float', min:0, defVal:20},
  2282. {name: 'fixedSize', dispName: 'Fixed Size', type: 'bool', defVal:true}
  2283. ];
  2284. mxCellRenderer.defaultShapes['trapezoid'].prototype.customProperties = [
  2285. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  2286. {name: 'size', dispName: 'Slope Angle', type: 'float', min:0, max: 1, defVal: 0.2}
  2287. ];
  2288. mxCellRenderer.defaultShapes['tape'].prototype.customProperties = [
  2289. {name: 'size', dispName: 'Size', type: 'float', min:0, max:1, defVal:0.4 }
  2290. ];
  2291. mxCellRenderer.defaultShapes['note'].prototype.customProperties = [
  2292. {name: 'size', dispName: 'Fold Size', type: 'float', min:0, defVal: 30},
  2293. {name: 'darkOpacity', dispName: 'Dark Opacity', type: 'float', min:-1, max:1, defVal:0 },
  2294. ];
  2295. mxCellRenderer.defaultShapes['card'].prototype.customProperties = [
  2296. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  2297. {name: 'size', dispName: 'Cutoff Size', type: 'float', min:0, defVal: 30}
  2298. ];
  2299. mxCellRenderer.defaultShapes['callout'].prototype.customProperties = [
  2300. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  2301. {name: 'base', dispName: 'Callout Width', type: 'float', min:0, defVal: 20},
  2302. {name: 'size', dispName: 'Callout Length', type: 'float', min:0, defVal: 30},
  2303. {name: 'position', dispName: 'Callout Position', type: 'float', min:0, max:1, defVal: 0.5},
  2304. {name: 'position2', dispName: 'Callout Tip Position', type: 'float', min:0, max:1, defVal: 0.5}
  2305. ];
  2306. mxCellRenderer.defaultShapes['folder'].prototype.customProperties = [
  2307. {name: 'tabWidth', dispName: 'Tab Width', type: 'float'},
  2308. {name: 'tabHeight', dispName: 'Tab Height', type: 'float'},
  2309. {name: 'tabPosition', dispName: 'Tap Position', type: 'enum',
  2310. enumList: [{val: 'left', dispName: 'Left'}, {val: 'right', dispName: 'Right'}]
  2311. }
  2312. ];
  2313. mxCellRenderer.defaultShapes['swimlane'].prototype.customProperties = [
  2314. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 15},
  2315. {name: 'startSize', dispName: 'Header Size', type: 'float'},
  2316. {name: 'horizontal', dispName: 'Horizontal', type: 'bool', defVal: true},
  2317. {name: 'separatorColor', dispName: 'Separator Color', type: 'color', defVal: null},
  2318. ];
  2319. mxCellRenderer.defaultShapes['doubleEllipse'].prototype.customProperties = [
  2320. {name: 'margin', dispName: 'Indent', type: 'float', min:0, defVal:4}
  2321. ];
  2322. mxCellRenderer.defaultShapes['ext'].prototype.customProperties = [
  2323. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 15},
  2324. {name: 'double', dispName: 'Double', type: 'bool', defVal: false},
  2325. {name: 'margin', dispName: 'Indent', type: 'float', min: 0, defVal:0}
  2326. ];
  2327. mxCellRenderer.defaultShapes['curlyBracket'].prototype.customProperties = [
  2328. {name: 'rounded', dispName: 'Rounded', type: 'bool', defVal: true},
  2329. {name: 'size', dispName: 'Size', type: 'float', min:0, max: 1, defVal: 0.5}
  2330. ];
  2331. mxCellRenderer.defaultShapes['image'].prototype.customProperties = [
  2332. {name: 'imageAspect', dispName: 'Fixed Image Aspect', type: 'bool', defVal:true}
  2333. ];
  2334. mxCellRenderer.defaultShapes['label'].prototype.customProperties = [
  2335. {name: 'imageAspect', dispName: 'Fixed Image Aspect', type: 'bool', defVal:true},
  2336. {name: 'imageAlign', dispName: 'Image Align', type: 'enum',
  2337. enumList: [{val: 'left', dispName: 'Left'},
  2338. {val: 'center', dispName: 'Center'},
  2339. {val: 'right', dispName: 'Right'}], defVal: 'left'},
  2340. {name: 'imageVerticalAlign', dispName: 'Image Vertical Align', type: 'enum',
  2341. enumList: [{val: 'top', dispName: 'Top'},
  2342. {val: 'middle', dispName: 'Middle'},
  2343. {val: 'bottom', dispName: 'Bottom'}], defVal: 'middle'},
  2344. {name: 'imageWidth', dispName: 'Image Width', type: 'float', min:0, defVal: 24},
  2345. {name: 'imageHeight', dispName: 'Image Height', type: 'float', min:0, defVal: 24},
  2346. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 12},
  2347. {name: 'absoluteArcSize', dispName: 'Abs. Arc Size', type: 'bool', defVal: false}
  2348. ];
  2349. mxCellRenderer.defaultShapes['dataStorage'].prototype.customProperties = [
  2350. {name: 'size', dispName: 'Size', type: 'float', min:0, max:1, defVal:0.1 }
  2351. ];
  2352. mxCellRenderer.defaultShapes['manualInput'].prototype.customProperties = [
  2353. {name: 'size', dispName: 'Size', type: 'float', min:0, defVal:30 },
  2354. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 20}
  2355. ];
  2356. mxCellRenderer.defaultShapes['loopLimit'].prototype.customProperties = [
  2357. {name: 'size', dispName: 'Size', type: 'float', min:0, defVal:20 },
  2358. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 20}
  2359. ];
  2360. mxCellRenderer.defaultShapes['offPageConnector'].prototype.customProperties = [
  2361. {name: 'size', dispName: 'Size', type: 'float', min:0, defVal:38 },
  2362. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 20}
  2363. ];
  2364. mxCellRenderer.defaultShapes['display'].prototype.customProperties = [
  2365. {name: 'size', dispName: 'Size', type: 'float', min: 0, max: 1, defVal: 0.25 }
  2366. ];
  2367. mxCellRenderer.defaultShapes['singleArrow'].prototype.customProperties = [
  2368. {name: 'arrowWidth', dispName: 'Arrow Width', type: 'float', min: 0, max: 1, defVal: 0.3 },
  2369. {name: 'arrowSize', dispName: 'Arrowhead Length', type: 'float', min: 0, max: 1, defVal: 0.2 }
  2370. ];
  2371. mxCellRenderer.defaultShapes['doubleArrow'].prototype.customProperties = [
  2372. {name: 'arrowWidth', dispName: 'Arrow Width', type: 'float', min: 0, max: 1, defVal: 0.3 },
  2373. {name: 'arrowSize', dispName: 'Arrowhead Length', type: 'float', min: 0, max: 1, defVal: 0.2 }
  2374. ];
  2375. mxCellRenderer.defaultShapes['cross'].prototype.customProperties = [
  2376. {name: 'size', dispName: 'Size', type: 'float', min: 0, max: 1, defVal: 0.2 }
  2377. ];
  2378. mxCellRenderer.defaultShapes['corner'].prototype.customProperties = [
  2379. {name: 'dx', dispName: 'Width1', type: 'float', min: 0, defVal: 20 },
  2380. {name: 'dy', dispName: 'Width2', type: 'float', min: 0, defVal: 20 }
  2381. ];
  2382. mxCellRenderer.defaultShapes['tee'].prototype.customProperties = [
  2383. {name: 'dx', dispName: 'Width1', type: 'float', min: 0, defVal: 20 },
  2384. {name: 'dy', dispName: 'Width2', type: 'float', min: 0, defVal: 20 }
  2385. ];
  2386. mxCellRenderer.defaultShapes['umlLifeline'].prototype.customProperties = [
  2387. {name: 'participant', dispName:'Participant', type:'enum', defVal:'none', enumList:[
  2388. {val:'none', dispName: 'Default'},
  2389. {val:'umlActor', dispName: 'Actor'},
  2390. {val:'umlBoundary', dispName: 'Boundary'},
  2391. {val:'umlEntity', dispName: 'Entity'},
  2392. {val:'umlControl', dispName: 'Control'},
  2393. ]},
  2394. {name: 'size', dispName:'Height', type:'float', defVal:40, min:0}
  2395. ];
  2396. mxCellRenderer.defaultShapes['umlFrame'].prototype.customProperties = [
  2397. {name: 'width', dispName:'Title Width', type:'float', defVal:60, min:0},
  2398. {name: 'height', dispName:'Title Height', type:'float', defVal:30, min:0}
  2399. ];
  2400. /**
  2401. * Configures global color schemes.
  2402. */
  2403. StyleFormatPanel.prototype.defaultColorSchemes = [[{fill: '', stroke: ''}, {fill: '#f5f5f5', stroke: '#666666', font: '#333333'},
  2404. {fill: '#dae8fc', stroke: '#6c8ebf'}, {fill: '#d5e8d4', stroke: '#82b366'},
  2405. {fill: '#ffe6cc', stroke: '#d79b00'}, {fill: '#fff2cc', stroke: '#d6b656'},
  2406. {fill: '#f8cecc', stroke: '#b85450'}, {fill: '#e1d5e7', stroke: '#9673a6'}],
  2407. [{fill: '#60a917', stroke: '#2D7600', font: '#ffffff'}, {fill: '#008a00', stroke: '#005700', font: '#ffffff'},
  2408. {fill: '#1ba1e2', stroke: '#006EAF', font: '#ffffff'}, {fill: '#0050ef', stroke: '#001DBC', font: '#ffffff'},
  2409. {fill: '#6a00ff', stroke: '#3700CC', font: '#ffffff'}, {fill: '#aa00ff', stroke: '#7700CC', font: '#ffffff'},
  2410. {fill: '#d80073', stroke: '#A50040', font: '#ffffff'}, {fill: '#a20025', stroke: '#6F0000', font: '#ffffff'}],
  2411. [{fill: '#e51400', stroke: '#B20000', font: '#ffffff'}, {fill: '#fa6800', stroke: '#C73500', font: '#ffffff'},
  2412. {fill: '#f0a30a', stroke: '#BD7000', font: '#ffffff'}, {fill: '#e3c800', stroke: '#B09500', font: '#ffffff'},
  2413. {fill: '#6d8764', stroke: '#3A5431', font: '#ffffff'}, {fill: '#647687', stroke: '#314354', font: '#ffffff'},
  2414. {fill: '#76608a', stroke: '#432D57', font: '#ffffff'}, {fill: '#a0522d', stroke: '#6D1F00', font: '#ffffff'}],
  2415. [{fill: '', stroke: ''}, {fill: mxConstants.NONE, stroke: ''},
  2416. {fill: '#fad7ac', stroke: '#b46504'}, {fill: '#fad9d5', stroke: '#ae4132'},
  2417. {fill: '#b0e3e6', stroke: '#0e8088'}, {fill: '#b1ddf0', stroke: '#10739e'},
  2418. {fill: '#d0cee2', stroke: '#56517e'}, {fill: '#bac8d3', stroke: '#23445d'}],
  2419. [{fill: '', stroke: ''},
  2420. {fill: '#f5f5f5', stroke: '#666666', gradient: '#b3b3b3'},
  2421. {fill: '#dae8fc', stroke: '#6c8ebf', gradient: '#7ea6e0'},
  2422. {fill: '#d5e8d4', stroke: '#82b366', gradient: '#97d077'},
  2423. {fill: '#ffcd28', stroke: '#d79b00', gradient: '#ffa500'},
  2424. {fill: '#fff2cc', stroke: '#d6b656', gradient: '#ffd966'},
  2425. {fill: '#f8cecc', stroke: '#b85450', gradient: '#ea6b66'},
  2426. {fill: '#e6d0de', stroke: '#996185', gradient: '#d5739d'}],
  2427. [{fill: '', stroke: ''}, {fill: '#eeeeee', stroke: '#36393d'},
  2428. {fill: '#f9f7ed', stroke: '#36393d'}, {fill: '#ffcc99', stroke: '#36393d'},
  2429. {fill: '#cce5ff', stroke: '#36393d'}, {fill: '#ffff88', stroke: '#36393d'},
  2430. {fill: '#cdeb8b', stroke: '#36393d'}, {fill: '#ffcccc', stroke: '#36393d'}]];
  2431. /**
  2432. * Configures custom color schemes.
  2433. */
  2434. StyleFormatPanel.prototype.customColorSchemes = null;
  2435. StyleFormatPanel.prototype.findCommonProperties = function(cell, properties, addAll)
  2436. {
  2437. if (properties == null) return;
  2438. var handleCustomProp = function(custProperties)
  2439. {
  2440. if (custProperties != null)
  2441. {
  2442. if (addAll)
  2443. {
  2444. for (var i = 0; i < custProperties.length; i++)
  2445. {
  2446. properties[custProperties[i].name] = custProperties[i];
  2447. }
  2448. }
  2449. else
  2450. {
  2451. for (var key in properties)
  2452. {
  2453. var found = false;
  2454. for (var i = 0; i < custProperties.length; i++)
  2455. {
  2456. if (custProperties[i].name == key && custProperties[i].type == properties[key].type)
  2457. {
  2458. found = true;
  2459. break;
  2460. }
  2461. }
  2462. if (!found)
  2463. {
  2464. delete properties[key];
  2465. }
  2466. }
  2467. }
  2468. }
  2469. };
  2470. var view = this.editorUi.editor.graph.view;
  2471. var state = view.getState(cell);
  2472. if (state != null && state.shape != null)
  2473. {
  2474. //Add common properties to all shapes
  2475. if (!state.shape.commonCustomPropAdded)
  2476. {
  2477. state.shape.commonCustomPropAdded = true;
  2478. state.shape.customProperties = state.shape.customProperties || [];
  2479. if (state.cell.vertex)
  2480. {
  2481. Array.prototype.push.apply(state.shape.customProperties, Editor.commonVertexProperties);
  2482. }
  2483. else
  2484. {
  2485. Array.prototype.push.apply(state.shape.customProperties, Editor.commonEdgeProperties);
  2486. }
  2487. }
  2488. handleCustomProp(state.shape.customProperties);
  2489. }
  2490. //This currently is not needed but let's keep it in case we needed in the future
  2491. var userCustomProp = cell.getAttribute('customProperties');
  2492. if (userCustomProp != null)
  2493. {
  2494. try
  2495. {
  2496. handleCustomProp(JSON.parse(userCustomProp));
  2497. }
  2498. catch(e){}
  2499. }
  2500. };
  2501. /**
  2502. * Adds predefiend styles.
  2503. */
  2504. var styleFormatPanelInit = StyleFormatPanel.prototype.init;
  2505. StyleFormatPanel.prototype.init = function()
  2506. {
  2507. // TODO: Update sstate in Format
  2508. var sstate = this.format.createSelectionState();
  2509. if (sstate.style.shape != 'image' && !sstate.containsLabel)
  2510. {
  2511. this.container.appendChild(this.addStyles(this.createPanel()));
  2512. }
  2513. styleFormatPanelInit.apply(this, arguments);
  2514. if (Editor.enableCustomProperties)
  2515. {
  2516. var properties = {};
  2517. var vertices = sstate.vertices;
  2518. var edges = sstate.edges;
  2519. for (var i = 0; i < vertices.length; i++)
  2520. {
  2521. this.findCommonProperties(vertices[i], properties, i == 0);
  2522. }
  2523. for (var i = 0; i < edges.length; i++)
  2524. {
  2525. this.findCommonProperties(edges[i], properties, vertices.length == 0 && i == 0);
  2526. }
  2527. if (Object.getOwnPropertyNames != null && Object.getOwnPropertyNames(properties).length > 0)
  2528. {
  2529. this.container.appendChild(this.addProperties(this.createPanel(), properties, sstate));
  2530. }
  2531. }
  2532. };
  2533. /**
  2534. * Overridden to add copy and paste style.
  2535. */
  2536. var styleFormatPanelAddStyleOps = StyleFormatPanel.prototype.addStyleOps;
  2537. StyleFormatPanel.prototype.addStyleOps = function(div)
  2538. {
  2539. var graph = this.editorUi.editor.graph;
  2540. var btn = mxUtils.button(mxResources.get('copyStyle'), mxUtils.bind(this, function(evt)
  2541. {
  2542. this.editorUi.actions.get('copyStyle').funct();
  2543. }));
  2544. btn.setAttribute('title', mxResources.get('copyStyle') + ' (' + this.editorUi.actions.get('copyStyle').shortcut + ')');
  2545. btn.style.marginBottom = '2px';
  2546. btn.style.width = '100px';
  2547. btn.style.marginRight = '2px';
  2548. div.appendChild(btn);
  2549. var btn = mxUtils.button(mxResources.get('pasteStyle'), mxUtils.bind(this, function(evt)
  2550. {
  2551. this.editorUi.actions.get('pasteStyle').funct();
  2552. }));
  2553. btn.setAttribute('title', mxResources.get('pasteStyle') + ' (' + this.editorUi.actions.get('pasteStyle').shortcut + ')');
  2554. btn.style.marginBottom = '2px';
  2555. btn.style.width = '100px';
  2556. div.appendChild(btn);
  2557. mxUtils.br(div);
  2558. return styleFormatPanelAddStyleOps.apply(this, arguments);
  2559. };
  2560. /**
  2561. * Initial collapsed state of the properties panel.
  2562. */
  2563. EditorUi.prototype.propertiesCollapsed = true;
  2564. /**
  2565. * Create Properties Panel
  2566. */
  2567. StyleFormatPanel.prototype.addProperties = function(div, properties, state)
  2568. {
  2569. var that = this;
  2570. var graph = this.editorUi.editor.graph;
  2571. var secondLevel = [];
  2572. function insertAfter(newElem, curElem)
  2573. {
  2574. curElem.parentNode.insertBefore(newElem, curElem.nextSibling);
  2575. };
  2576. function applyStyleVal(pName, newVal, prop, delIndex)
  2577. {
  2578. graph.getModel().beginUpdate();
  2579. try
  2580. {
  2581. var changedProps = [];
  2582. var changedVals = [];
  2583. if (prop.index != null)
  2584. {
  2585. var allVals = [];
  2586. var curVal = prop.parentRow.nextSibling;
  2587. while(curVal && curVal.getAttribute('data-pName') == pName)
  2588. {
  2589. allVals.push(curVal.getAttribute('data-pValue'));
  2590. curVal = curVal.nextSibling;
  2591. }
  2592. if (prop.index < allVals.length)
  2593. {
  2594. if (delIndex != null)
  2595. {
  2596. allVals.splice(delIndex, 1);
  2597. }
  2598. else
  2599. {
  2600. allVals[prop.index] = newVal;
  2601. }
  2602. }
  2603. else
  2604. {
  2605. allVals.push(newVal);
  2606. }
  2607. if (prop.size != null && allVals.length > prop.size) //trim the array to the specifies size
  2608. {
  2609. allVals = allVals.slice(0, prop.size);
  2610. }
  2611. newVal = allVals.join(',');
  2612. if (prop.countProperty != null)
  2613. {
  2614. graph.setCellStyles(prop.countProperty, allVals.length, graph.getSelectionCells());
  2615. changedProps.push(prop.countProperty);
  2616. changedVals.push(allVals.length);
  2617. }
  2618. }
  2619. graph.setCellStyles(pName, newVal, graph.getSelectionCells());
  2620. changedProps.push(pName);
  2621. changedVals.push(newVal);
  2622. if (prop.dependentProps != null)
  2623. {
  2624. for (var i = 0; i < prop.dependentProps.length; i++)
  2625. {
  2626. var defVal = prop.dependentPropsDefVal[i];
  2627. var vals = prop.dependentPropsVals[i];
  2628. if (vals.length > newVal)
  2629. {
  2630. vals = vals.slice(0, newVal);
  2631. }
  2632. else
  2633. {
  2634. for (var j = vals.length; j < newVal; j++)
  2635. {
  2636. vals.push(defVal);
  2637. }
  2638. }
  2639. vals = vals.join(',');
  2640. graph.setCellStyles(prop.dependentProps[i], vals, graph.getSelectionCells());
  2641. changedProps.push(prop.dependentProps[i]);
  2642. changedVals.push(vals);
  2643. }
  2644. }
  2645. if (typeof(prop.onChange) == 'function')
  2646. {
  2647. prop.onChange(graph, newVal);
  2648. }
  2649. that.editorUi.fireEvent(new mxEventObject('styleChanged', 'keys', changedProps,
  2650. 'values', changedVals, 'cells', graph.getSelectionCells()));
  2651. }
  2652. finally
  2653. {
  2654. graph.getModel().endUpdate();
  2655. }
  2656. }
  2657. function setElementPos(td, elem, adjustHeight)
  2658. {
  2659. var divPos = mxUtils.getOffset(div, true);
  2660. var pos = mxUtils.getOffset(td, true);
  2661. elem.style.position = 'absolute';
  2662. elem.style.left = (pos.x - divPos.x) + 'px';
  2663. elem.style.top = (pos.y - divPos.y) + 'px';
  2664. elem.style.width = td.offsetWidth + 'px';
  2665. elem.style.height = (td.offsetHeight - (adjustHeight? 4 : 0)) + 'px';
  2666. elem.style.zIndex = 5;
  2667. };
  2668. function createColorBtn(pName, pValue, prop)
  2669. {
  2670. var clrDiv = document.createElement('div');
  2671. clrDiv.style.width = '32px';
  2672. clrDiv.style.height = '4px';
  2673. clrDiv.style.margin = '2px';
  2674. clrDiv.style.border = '1px solid black';
  2675. clrDiv.style.background = !pValue || pValue == 'none'? 'url(\'' + Dialog.prototype.noColorImage + '\')' : pValue;
  2676. btn = mxUtils.button('', mxUtils.bind(that, function(evt)
  2677. {
  2678. this.editorUi.pickColor(pValue, function(color)
  2679. {
  2680. clrDiv.style.background = color == 'none'? 'url(\'' + Dialog.prototype.noColorImage + '\')' : color;
  2681. applyStyleVal(pName, color, prop);
  2682. });
  2683. mxEvent.consume(evt);
  2684. }));
  2685. btn.style.height = '12px';
  2686. btn.style.width = '40px';
  2687. btn.className = 'geColorBtn';
  2688. btn.appendChild(clrDiv);
  2689. return btn;
  2690. };
  2691. function createDynArrList(pName, pValue, subType, defVal, countProperty, myRow, flipBkg)
  2692. {
  2693. if (pValue != null)
  2694. {
  2695. var vals = pValue.split(',');
  2696. secondLevel.push({name: pName, values: vals, type: subType, defVal: defVal, countProperty: countProperty, parentRow: myRow, isDeletable: true, flipBkg: flipBkg});
  2697. }
  2698. btn = mxUtils.button('+', mxUtils.bind(that, function(evt)
  2699. {
  2700. var beforeElem = myRow;
  2701. var index = 0;
  2702. while (beforeElem.nextSibling != null)
  2703. {
  2704. var cur = beforeElem.nextSibling;
  2705. var elemPName = cur.getAttribute('data-pName');
  2706. if (elemPName == pName)
  2707. {
  2708. beforeElem = beforeElem.nextSibling;
  2709. index++;
  2710. }
  2711. else
  2712. {
  2713. break;
  2714. }
  2715. }
  2716. var newProp = {type: subType, parentRow: myRow, index: index, isDeletable: true, defVal: defVal, countProperty: countProperty};
  2717. var arrItem = createPropertyRow(pName, '', newProp, index % 2 == 0, flipBkg);
  2718. applyStyleVal(pName, defVal, newProp);
  2719. insertAfter(arrItem, beforeElem);
  2720. mxEvent.consume(evt);
  2721. }));
  2722. btn.style.height = '16px';
  2723. btn.style.width = '25px';
  2724. btn.className = 'geColorBtn';
  2725. return btn;
  2726. };
  2727. function createStaticArrList(pName, pValue, subType, defVal, size, myRow, flipBkg)
  2728. {
  2729. if (size > 0)
  2730. {
  2731. var vals = new Array(size);
  2732. var curVals = pValue != null? pValue.split(',') : [];
  2733. for (var i = 0; i < size; i++)
  2734. {
  2735. vals[i] = curVals[i] != null? curVals[i] : (defVal != null? defVal : '');
  2736. }
  2737. secondLevel.push({name: pName, values: vals, type: subType, defVal: defVal, parentRow: myRow, flipBkg: flipBkg, size: size});
  2738. }
  2739. return document.createElement('div'); //empty cell
  2740. };
  2741. function createCheckbox(pName, pValue, prop)
  2742. {
  2743. var input = document.createElement('input');
  2744. input.type = 'checkbox';
  2745. input.checked = pValue == '1';
  2746. mxEvent.addListener(input, 'change', function()
  2747. {
  2748. applyStyleVal(pName, input.checked? '1' : '0', prop);
  2749. });
  2750. return input;
  2751. };
  2752. function createPropertyRow(pName, pValue, prop, isOdd, flipBkg)
  2753. {
  2754. var pDiplayName = prop.dispName;
  2755. var pType = prop.type;
  2756. var row = document.createElement('tr');
  2757. row.className = 'gePropRow' + (flipBkg? 'Dark' : '') + (isOdd? 'Alt' : '') + ' gePropNonHeaderRow';
  2758. row.setAttribute('data-pName', pName);
  2759. row.setAttribute('data-pValue', pValue);
  2760. var rightAlig = false;
  2761. if (prop.index != null)
  2762. {
  2763. row.setAttribute('data-index', prop.index);
  2764. pDiplayName = (pDiplayName != null? pDiplayName : '') + '[' + prop.index + ']';
  2765. rightAlig = true;
  2766. }
  2767. var td = document.createElement('td');
  2768. td.className = 'gePropRowCell';
  2769. td.innerHTML = mxUtils.htmlEntities(mxResources.get(pDiplayName, null, pDiplayName));
  2770. if (rightAlig)
  2771. {
  2772. td.style.textAlign = 'right';
  2773. }
  2774. row.appendChild(td);
  2775. td = document.createElement('td');
  2776. td.className = 'gePropRowCell';
  2777. if (pType == 'color')
  2778. {
  2779. td.appendChild(createColorBtn(pName, pValue, prop));
  2780. }
  2781. else if (pType == 'bool' || pType == 'boolean')
  2782. {
  2783. td.appendChild(createCheckbox(pName, pValue, prop));
  2784. }
  2785. else if (pType == 'enum')
  2786. {
  2787. var pEnumList = prop.enumList;
  2788. for (var i = 0; i < pEnumList.length; i++)
  2789. {
  2790. var op = pEnumList[i];
  2791. if (op.val == pValue)
  2792. {
  2793. td.innerHTML = mxUtils.htmlEntities(mxResources.get(op.dispName, null, op.dispName));
  2794. break;
  2795. }
  2796. }
  2797. mxEvent.addListener(td, 'click', mxUtils.bind(that, function()
  2798. {
  2799. var select = document.createElement('select');
  2800. setElementPos(td, select);
  2801. for (var i = 0; i < pEnumList.length; i++)
  2802. {
  2803. var op = pEnumList[i];
  2804. var opElem = document.createElement('option');
  2805. opElem.value = mxUtils.htmlEntities(op.val);
  2806. opElem.innerHTML = mxUtils.htmlEntities(mxResources.get(op.dispName, null, op.dispName));
  2807. select.appendChild(opElem);
  2808. }
  2809. select.value = pValue;
  2810. div.appendChild(select);
  2811. mxEvent.addListener(select, 'change', function()
  2812. {
  2813. var newVal = mxUtils.htmlEntities(select.value);
  2814. applyStyleVal(pName, newVal, prop);
  2815. //set value triggers a redraw of the panel which removes the select and updates the row
  2816. });
  2817. select.focus();
  2818. //FF calls blur on focus! so set the event after focusing (not with selects but to be safe)
  2819. mxEvent.addListener(select, 'blur', function()
  2820. {
  2821. div.removeChild(select);
  2822. });
  2823. }));
  2824. }
  2825. else if (pType == 'dynamicArr')
  2826. {
  2827. td.appendChild(createDynArrList(pName, pValue, prop.subType, prop.subDefVal, prop.countProperty, row, flipBkg));
  2828. }
  2829. else if (pType == 'staticArr')
  2830. {
  2831. td.appendChild(createStaticArrList(pName, pValue, prop.subType, prop.subDefVal, prop.size, row, flipBkg));
  2832. }
  2833. else
  2834. {
  2835. td.innerHTML = pValue;
  2836. mxEvent.addListener(td, 'click', mxUtils.bind(that, function()
  2837. {
  2838. var input = document.createElement('input');
  2839. setElementPos(td, input, true);
  2840. input.value = pValue;
  2841. input.className = 'gePropEditor';
  2842. if ((pType == 'int' || pType == 'float') && !prop.allowAuto)
  2843. {
  2844. input.type = 'number';
  2845. input.step = pType == 'int'? '1' : 'any';
  2846. if (prop.min != null)
  2847. {
  2848. input.min = parseFloat(prop.min);
  2849. }
  2850. if (prop.max != null)
  2851. {
  2852. input.max = parseFloat(prop.max);
  2853. }
  2854. }
  2855. div.appendChild(input);
  2856. function setInputVal()
  2857. {
  2858. var inputVal = input.value;
  2859. inputVal = inputVal.length == 0 && pType != 'string'? 0 : inputVal;
  2860. if (prop.allowAuto)
  2861. {
  2862. if (inputVal.trim != null && inputVal.trim().toLowerCase() == 'auto')
  2863. {
  2864. inputVal = 'auto';
  2865. pType = 'string';
  2866. }
  2867. else
  2868. {
  2869. inputVal = parseFloat(inputVal);
  2870. inputVal = isNaN(inputVal)? 0 : inputVal;
  2871. }
  2872. }
  2873. if (prop.min != null && inputVal < prop.min)
  2874. {
  2875. inputVal = prop.min;
  2876. }
  2877. else if (prop.max != null && inputVal > prop.max)
  2878. {
  2879. inputVal = prop.max;
  2880. }
  2881. var newVal = mxUtils.htmlEntities((pType == 'int'? parseInt(inputVal) : inputVal) + '');
  2882. applyStyleVal(pName, newVal, prop);
  2883. }
  2884. mxEvent.addListener(input, 'keypress', function(e)
  2885. {
  2886. if (e.keyCode == 13)
  2887. {
  2888. setInputVal();
  2889. //set value triggers a redraw of the panel which removes the input
  2890. }
  2891. });
  2892. input.focus();
  2893. //FF calls blur on focus! so set the event after focusing
  2894. mxEvent.addListener(input, 'blur', function()
  2895. {
  2896. setInputVal();
  2897. });
  2898. }));
  2899. }
  2900. if (prop.isDeletable)
  2901. {
  2902. var delBtn = mxUtils.button('-', mxUtils.bind(that, function(evt)
  2903. {
  2904. //delete the node by refreshing the properties
  2905. applyStyleVal(pName, '', prop, prop.index);
  2906. mxEvent.consume(evt);
  2907. }));
  2908. delBtn.style.height = '16px';
  2909. delBtn.style.width = '25px';
  2910. delBtn.style.float = 'right';
  2911. delBtn.className = 'geColorBtn';
  2912. td.appendChild(delBtn);
  2913. }
  2914. row.appendChild(td);
  2915. return row;
  2916. };
  2917. div.style.position = 'relative';
  2918. div.style.padding = '0';
  2919. var grid = document.createElement('table');
  2920. grid.style.whiteSpace = 'nowrap';
  2921. grid.style.width = '100%';
  2922. //create header row
  2923. var hrow = document.createElement('tr');
  2924. hrow.className = 'gePropHeader';
  2925. var th = document.createElement('th');
  2926. th.className = 'gePropHeaderCell';
  2927. var collapseImg = document.createElement('img');
  2928. collapseImg.src = Sidebar.prototype.expandedImage;
  2929. th.appendChild(collapseImg);
  2930. mxUtils.write(th, mxResources.get('property'));
  2931. hrow.style.cursor = 'pointer';
  2932. var onFold = function()
  2933. {
  2934. var rows = grid.querySelectorAll('.gePropNonHeaderRow');
  2935. var display;
  2936. if (!that.editorUi.propertiesCollapsed)
  2937. {
  2938. collapseImg.src = Sidebar.prototype.expandedImage;
  2939. display = '';
  2940. }
  2941. else
  2942. {
  2943. collapseImg.src = Sidebar.prototype.collapsedImage;
  2944. display = 'none';
  2945. for (var e = div.childNodes.length - 1; e >= 0 ; e--)
  2946. {
  2947. //Blur can be executed concurrently with this method and the element is removed before removing it here
  2948. try
  2949. {
  2950. var child = div.childNodes[e];
  2951. var nodeName = child.nodeName.toUpperCase();
  2952. if (nodeName == 'INPUT' || nodeName == 'SELECT')
  2953. {
  2954. div.removeChild(child);
  2955. }
  2956. }
  2957. catch(ex){}
  2958. }
  2959. }
  2960. for (var r = 0; r < rows.length; r++)
  2961. {
  2962. rows[r].style.display = display;
  2963. }
  2964. };
  2965. mxEvent.addListener(hrow, 'click', function()
  2966. {
  2967. that.editorUi.propertiesCollapsed = !that.editorUi.propertiesCollapsed;
  2968. onFold();
  2969. });
  2970. hrow.appendChild(th);
  2971. th = document.createElement('th');
  2972. th.className = 'gePropHeaderCell';
  2973. th.innerHTML = mxResources.get('value');
  2974. hrow.appendChild(th);
  2975. grid.appendChild(hrow);
  2976. var isOdd = false;
  2977. var flipBkg = false;
  2978. for (var key in properties)
  2979. {
  2980. var prop = properties[key];
  2981. if (typeof(prop.isVisible) == 'function')
  2982. {
  2983. if (!prop.isVisible(state, this)) continue;
  2984. }
  2985. var pValue = state.style[key] != null? mxUtils.htmlEntities(state.style[key] + '') : prop.defVal; //or undefined if defVal is undefined
  2986. if (prop.type == 'separator')
  2987. {
  2988. flipBkg = !flipBkg;
  2989. continue;
  2990. }
  2991. else if (prop.type == 'staticArr') //if dynamic values are needed, a more elegant technique is needed to replace such values
  2992. {
  2993. prop.size = parseInt(state.style[prop.sizeProperty] || properties[prop.sizeProperty].defVal) || 0;
  2994. }
  2995. else if (prop.dependentProps != null)
  2996. {
  2997. var dependentProps = prop.dependentProps;
  2998. var dependentPropsVals = [];
  2999. var dependentPropsDefVal = [];
  3000. for (var i = 0; i < dependentProps.length; i++)
  3001. {
  3002. var propVal = state.style[dependentProps[i]];
  3003. dependentPropsDefVal.push(properties[dependentProps[i]].subDefVal);
  3004. dependentPropsVals.push(propVal != null? propVal.split(',') : []);
  3005. }
  3006. prop.dependentPropsDefVal = dependentPropsDefVal;
  3007. prop.dependentPropsVals = dependentPropsVals;
  3008. }
  3009. grid.appendChild(createPropertyRow(key, pValue, prop, isOdd, flipBkg));
  3010. isOdd = !isOdd;
  3011. }
  3012. for (var i = 0; i < secondLevel.length; i++)
  3013. {
  3014. var prop = secondLevel[i];
  3015. var insertElem = prop.parentRow;
  3016. for (var j = 0; j < prop.values.length; j++)
  3017. {
  3018. //mxUtils.clone failed because of the HTM element, so manual cloning is used
  3019. var iProp = {type: prop.type, parentRow: prop.parentRow, isDeletable: prop.isDeletable, index: j, defVal: prop.defVal, countProperty: prop.countProperty, size: prop.size};
  3020. var arrItem = createPropertyRow(prop.name, prop.values[j], iProp, j % 2 == 0, prop.flipBkg);
  3021. insertAfter(arrItem, insertElem);
  3022. insertElem = arrItem;
  3023. }
  3024. }
  3025. div.appendChild(grid);
  3026. onFold();
  3027. return div;
  3028. };
  3029. /**
  3030. * Creates the buttons for the predefined styles.
  3031. */
  3032. StyleFormatPanel.prototype.addStyles = function(div)
  3033. {
  3034. var graph = this.editorUi.editor.graph;
  3035. var picker = document.createElement('div');
  3036. picker.style.whiteSpace = 'nowrap';
  3037. picker.style.paddingLeft = '24px';
  3038. picker.style.paddingRight = '20px';
  3039. div.style.paddingLeft = '16px';
  3040. div.style.paddingBottom = '6px';
  3041. div.style.position = 'relative';
  3042. div.appendChild(picker);
  3043. var stylenames = ['plain-gray', 'plain-blue', 'plain-green', 'plain-turquoise',
  3044. 'plain-orange', 'plain-yellow', 'plain-red', 'plain-pink', 'plain-purple', 'gray',
  3045. 'blue', 'green', 'turquoise', 'orange', 'yellow', 'red', 'pink', 'purple'];
  3046. function updateScheme(colorsets)
  3047. {
  3048. function addButton(colorset)
  3049. {
  3050. var btn = mxUtils.button('', function(evt)
  3051. {
  3052. graph.getModel().beginUpdate();
  3053. try
  3054. {
  3055. var cells = graph.getSelectionCells();
  3056. for (var i = 0; i < cells.length; i++)
  3057. {
  3058. var style = graph.getModel().getStyle(cells[i]);
  3059. for (var j = 0; j < stylenames.length; j++)
  3060. {
  3061. style = mxUtils.removeStylename(style, stylenames[j]);
  3062. }
  3063. var defaults = (graph.getModel().isVertex(cells[i])) ? graph.defaultVertexStyle : graph.defaultEdgeStyle;
  3064. if (colorset != null)
  3065. {
  3066. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, colorset['gradient'] ||
  3067. mxUtils.getValue(defaults, mxConstants.STYLE_GRADIENTCOLOR, null));
  3068. if (colorset['fill'] == '')
  3069. {
  3070. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR,null);
  3071. }
  3072. else
  3073. {
  3074. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, colorset['fill'] ||
  3075. mxUtils.getValue(defaults, mxConstants.STYLE_FILLCOLOR, null));
  3076. }
  3077. if (colorset['stroke'] == '')
  3078. {
  3079. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, null);
  3080. }
  3081. else
  3082. {
  3083. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, colorset['stroke'] ||
  3084. mxUtils.getValue(defaults, mxConstants.STYLE_STROKECOLOR, null));
  3085. }
  3086. if (graph.getModel().isVertex(cells[i]))
  3087. {
  3088. style = mxUtils.setStyle(style, mxConstants.STYLE_FONTCOLOR, colorset['font'] ||
  3089. mxUtils.getValue(defaults, mxConstants.STYLE_FONTCOLOR, null));
  3090. }
  3091. }
  3092. else
  3093. {
  3094. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR,
  3095. mxUtils.getValue(defaults, mxConstants.STYLE_FILLCOLOR, '#ffffff'));
  3096. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR,
  3097. mxUtils.getValue(defaults, mxConstants.STYLE_STROKECOLOR, '#000000'));
  3098. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR,
  3099. mxUtils.getValue(defaults, mxConstants.STYLE_GRADIENTCOLOR, null));
  3100. if (graph.getModel().isVertex(cells[i]))
  3101. {
  3102. style = mxUtils.setStyle(style, mxConstants.STYLE_FONTCOLOR,
  3103. mxUtils.getValue(defaults, mxConstants.STYLE_FONTCOLOR, null));
  3104. }
  3105. }
  3106. graph.getModel().setStyle(cells[i], style);
  3107. }
  3108. }
  3109. finally
  3110. {
  3111. graph.getModel().endUpdate();
  3112. }
  3113. })
  3114. btn.className = 'geStyleButton';
  3115. btn.style.width = '36px';
  3116. btn.style.height = '30px';
  3117. btn.style.margin = '0px 6px 6px 0px';
  3118. if (colorset != null)
  3119. {
  3120. if (colorset['gradient'] != null)
  3121. {
  3122. if (mxClient.IS_IE && (mxClient.IS_QUIRKS || document.documentMode < 10))
  3123. {
  3124. btn.style.filter = 'progid:DXImageTransform.Microsoft.Gradient('+
  3125. 'StartColorStr=\'' + colorset['fill'] +
  3126. '\', EndColorStr=\'' + colorset['gradient'] + '\', GradientType=0)';
  3127. }
  3128. else
  3129. {
  3130. btn.style.backgroundImage = 'linear-gradient(' + colorset['fill'] + ' 0px,' +
  3131. colorset['gradient'] + ' 100%)';
  3132. }
  3133. }
  3134. else if (colorset['fill'] == mxConstants.NONE)
  3135. {
  3136. btn.style.background = 'url(\'' + Dialog.prototype.noColorImage + '\')';
  3137. }
  3138. else if (colorset['fill'] == '')
  3139. {
  3140. btn.style.backgroundColor = mxUtils.getValue(graph.defaultVertexStyle,
  3141. mxConstants.STYLE_FILLCOLOR, (uiTheme == 'dark') ?'#2a2a2a' : '#ffffff');
  3142. }
  3143. else
  3144. {
  3145. btn.style.backgroundColor = colorset['fill'] || mxUtils.getValue(graph.defaultVertexStyle,
  3146. mxConstants.STYLE_FILLCOLOR, (uiTheme == 'dark') ?'#2a2a2a' : '#ffffff');
  3147. }
  3148. if (colorset['stroke'] == mxConstants.NONE)
  3149. {
  3150. btn.style.border = '1px solid transparent';
  3151. }
  3152. else if (colorset['stroke'] == '')
  3153. {
  3154. btn.style.border = '1px solid ' + mxUtils.getValue(graph.defaultVertexStyle,
  3155. mxConstants.STYLE_STROKECOLOR, (uiTheme != 'dark') ?'#2a2a2a' : '#ffffff');
  3156. }
  3157. else
  3158. {
  3159. btn.style.border = '1px solid ' + (colorset['stroke'] || mxUtils.getValue(graph.defaultVertexStyle,
  3160. mxConstants.STYLE_STROKECOLOR, (uiTheme != 'dark') ?'#2a2a2a' : '#ffffff'));
  3161. }
  3162. }
  3163. else
  3164. {
  3165. var bg = mxUtils.getValue(graph.defaultVertexStyle, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  3166. var bd = mxUtils.getValue(graph.defaultVertexStyle, mxConstants.STYLE_STROKECOLOR, '#000000');
  3167. btn.style.backgroundColor = bg;
  3168. btn.style.border = '1px solid ' + bd;
  3169. }
  3170. picker.appendChild(btn);
  3171. };
  3172. picker.innerHTML = '';
  3173. for (var i = 0; i < colorsets.length; i++)
  3174. {
  3175. if (i > 0 && mxUtils.mod(i, 4) == 0)
  3176. {
  3177. mxUtils.br(picker);
  3178. }
  3179. addButton(colorsets[i]);
  3180. }
  3181. };
  3182. if (this.editorUi.currentScheme == null)
  3183. {
  3184. this.editorUi.currentScheme = 0;
  3185. }
  3186. var left = document.createElement('div');
  3187. left.style.cssText = 'position:absolute;left:10px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  3188. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ4eHh3d3d1dXVxcXF2dnZ2dnZ2dnZxcXF2dnYmb3w1AAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADRJREFUCNdjwACMAmBKaiGYs2oJmLPKAZ3DabU8AMRTXpUKopislqFyVzCAuUZgikkBZjoAcMYLnp53P/UAAAAASUVORK5CYII=);';
  3189. mxEvent.addListener(left, 'click', mxUtils.bind(this, function()
  3190. {
  3191. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme - 1, this.defaultColorSchemes.length);
  3192. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  3193. }));
  3194. var right = document.createElement('div');
  3195. right.style.cssText = 'position:absolute;left:202px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  3196. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnYBuwCcAAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADZJREFUCNdjQAOMAmBKaiGY8loF5rKswsZlrVo8AUiFrTICcbIWK8A5DF1gDoMymMPApIAwHwCS0Qx/U7qCBQAAAABJRU5ErkJggg==);';
  3197. if (this.defaultColorSchemes.length > 1)
  3198. {
  3199. div.appendChild(left);
  3200. div.appendChild(right);
  3201. }
  3202. mxEvent.addListener(right, 'click', mxUtils.bind(this, function()
  3203. {
  3204. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme + 1, this.defaultColorSchemes.length);
  3205. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  3206. }));
  3207. // Hover state
  3208. function addHoverState(elt)
  3209. {
  3210. mxEvent.addListener(elt, 'mouseenter', function()
  3211. {
  3212. elt.style.opacity = '1';
  3213. });
  3214. mxEvent.addListener(elt, 'mouseleave', function()
  3215. {
  3216. elt.style.opacity = '0.5';
  3217. });
  3218. };
  3219. addHoverState(left);
  3220. addHoverState(right);
  3221. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  3222. return div;
  3223. };
  3224. StyleFormatPanel.prototype.addEditOps = function(div)
  3225. {
  3226. var ss = this.format.getSelectionState();
  3227. var btn = null;
  3228. if (this.editorUi.editor.graph.getSelectionCount() == 1)
  3229. {
  3230. btn = mxUtils.button(mxResources.get('editStyle'), mxUtils.bind(this, function(evt)
  3231. {
  3232. this.editorUi.actions.get('editStyle').funct();
  3233. }));
  3234. btn.setAttribute('title', mxResources.get('editStyle') + ' (' + this.editorUi.actions.get('editStyle').shortcut + ')');
  3235. btn.style.width = '202px';
  3236. btn.style.marginBottom = '2px';
  3237. div.appendChild(btn);
  3238. }
  3239. var graph = this.editorUi.editor.graph;
  3240. var state = graph.view.getState(graph.getSelectionCell());
  3241. if (graph.getSelectionCount() == 1 && state != null && state.shape != null && state.shape.stencil != null)
  3242. {
  3243. var btn2 = mxUtils.button(mxResources.get('editShape'), mxUtils.bind(this, function(evt)
  3244. {
  3245. this.editorUi.actions.get('editShape').funct();
  3246. }));
  3247. btn2.setAttribute('title', mxResources.get('editShape'));
  3248. btn2.style.marginBottom = '2px';
  3249. if (btn == null)
  3250. {
  3251. btn2.style.width = '202px';
  3252. }
  3253. else
  3254. {
  3255. btn.style.width = '100px';
  3256. btn2.style.width = '100px';
  3257. btn2.style.marginLeft = '2px';
  3258. }
  3259. div.appendChild(btn2);
  3260. }
  3261. else if (ss.image)
  3262. {
  3263. var btn2 = mxUtils.button(mxResources.get('editImage'), mxUtils.bind(this, function(evt)
  3264. {
  3265. this.editorUi.actions.get('image').funct();
  3266. }));
  3267. btn2.setAttribute('title', mxResources.get('editImage'));
  3268. btn2.style.marginBottom = '2px';
  3269. if (btn == null)
  3270. {
  3271. btn2.style.width = '202px';
  3272. }
  3273. else
  3274. {
  3275. btn.style.width = '100px';
  3276. btn2.style.width = '100px';
  3277. btn2.style.marginLeft = '2px';
  3278. }
  3279. div.appendChild(btn2);
  3280. }
  3281. return div;
  3282. };
  3283. }
  3284. /**
  3285. * Changes the default stylename so that it matches the old named style
  3286. * if one was specified in the XML.
  3287. */
  3288. Graph.prototype.defaultThemeName = 'default-style2';
  3289. /**
  3290. * Contains the last XML that was pasted.
  3291. */
  3292. Graph.prototype.lastPasteXml = null;
  3293. /**
  3294. * Contains the number of times the last XML was pasted.
  3295. */
  3296. Graph.prototype.pasteCounter = 0;
  3297. /**
  3298. * Graph Overrides
  3299. */
  3300. Graph.prototype.defaultScrollbars = urlParams['sb'] != '0';
  3301. /**
  3302. * Specifies if the page should be visible for new files. Default is true.
  3303. */
  3304. Graph.prototype.defaultPageVisible = urlParams['pv'] != '0';
  3305. /**
  3306. * Specifies if the page should be visible for new files. Default is true.
  3307. */
  3308. Graph.prototype.shadowId = 'dropShadow';
  3309. /**
  3310. * Properties for the SVG shadow effect.
  3311. */
  3312. Graph.prototype.svgShadowColor = '#3D4574';
  3313. /**
  3314. * Properties for the SVG shadow effect.
  3315. */
  3316. Graph.prototype.svgShadowOpacity = '0.4';
  3317. /**
  3318. * Properties for the SVG shadow effect.
  3319. */
  3320. Graph.prototype.svgShadowBlur = '1.7';
  3321. /**
  3322. * Properties for the SVG shadow effect.
  3323. */
  3324. Graph.prototype.svgShadowSize = '3';
  3325. /**
  3326. * Enables move of bends/segments without selecting.
  3327. */
  3328. Graph.prototype.edgeMode = urlParams['edge'] != 'move';
  3329. /**
  3330. * Adds rack child layout style.
  3331. */
  3332. var graphInit = Graph.prototype.init;
  3333. Graph.prototype.init = function()
  3334. {
  3335. graphInit.apply(this, arguments);
  3336. //TODO initialize Freehand in the correct location!
  3337. if (window.mxFreehand)
  3338. {
  3339. this.freehand = new mxFreehand(this);
  3340. }
  3341. // Override insert location for current mouse point
  3342. var mouseEvent = null;
  3343. function setMouseEvent(evt)
  3344. {
  3345. mouseEvent = evt;
  3346. // Workaround for member not found in IE8-
  3347. try
  3348. {
  3349. if (mxClient.IS_QUIRKS || document.documentMode == 7 || document.documentMode == 8)
  3350. {
  3351. mouseEvent = document.createEventObject(evt);
  3352. mouseEvent.type = evt.type;
  3353. mouseEvent.canBubble = evt.canBubble;
  3354. mouseEvent.cancelable = evt.cancelable;
  3355. mouseEvent.view = evt.view;
  3356. mouseEvent.detail = evt.detail;
  3357. mouseEvent.screenX = evt.screenX;
  3358. mouseEvent.screenY = evt.screenY;
  3359. mouseEvent.clientX = evt.clientX;
  3360. mouseEvent.clientY = evt.clientY;
  3361. mouseEvent.ctrlKey = evt.ctrlKey;
  3362. mouseEvent.altKey = evt.altKey;
  3363. mouseEvent.shiftKey = evt.shiftKey;
  3364. mouseEvent.metaKey = evt.metaKey;
  3365. mouseEvent.button = evt.button;
  3366. mouseEvent.relatedTarget = evt.relatedTarget;
  3367. }
  3368. }
  3369. catch (e)
  3370. {
  3371. // ignores possible event cloning errors
  3372. }
  3373. };
  3374. mxEvent.addListener(this.container, 'mouseenter', setMouseEvent);
  3375. mxEvent.addListener(this.container, 'mousemove', setMouseEvent);
  3376. mxEvent.addListener(this.container, 'mouseleave', function(evt)
  3377. {
  3378. mouseEvent = null;
  3379. });
  3380. // Extends getInsertPoint to use the current mouse location
  3381. this.isMouseInsertPoint = function()
  3382. {
  3383. return mouseEvent != null;
  3384. };
  3385. var getInsertPoint = this.getInsertPoint;
  3386. this.getInsertPoint = function()
  3387. {
  3388. if (mouseEvent != null)
  3389. {
  3390. return this.getPointForEvent(mouseEvent);
  3391. }
  3392. return getInsertPoint.apply(this, arguments);
  3393. };
  3394. var layoutManagerGetLayout = this.layoutManager.getLayout;
  3395. this.layoutManager.getLayout = function(cell)
  3396. {
  3397. // Workaround for possible invalid style after change and before view validation
  3398. var style = this.graph.getCellStyle(cell);
  3399. // mxRackContainer may be undefined as it is dynamically loaded at render time
  3400. if (style != null)
  3401. {
  3402. if (style['childLayout'] == 'rack')
  3403. {
  3404. var rackLayout = new mxStackLayout(this.graph, false);
  3405. var unitSize = 20;
  3406. if (style['rackUnitSize'] != null)
  3407. {
  3408. rackLayout.gridSize = parseFloat(style['rackUnitSize']);
  3409. }
  3410. else
  3411. {
  3412. rackLayout.gridSize = (typeof mxRackContainer !== 'undefined') ? mxRackContainer.unitSize : unitSize;
  3413. }
  3414. rackLayout.fill = true;
  3415. rackLayout.marginLeft = style['marginLeft'] || 0;
  3416. rackLayout.marginRight = style['marginRight'] || 0;
  3417. rackLayout.marginTop = style['marginTop'] || 0;
  3418. rackLayout.marginBottom = style['marginBottom'] || 0;
  3419. rackLayout.allowGaps = style['allowGaps'] || 0;
  3420. rackLayout.resizeParent = false;
  3421. return rackLayout;
  3422. }
  3423. else if (typeof mxTableLayout !== 'undefined' && style['childLayout'] == 'tableLayout')
  3424. {
  3425. var tableLayout = new mxTableLayout(this.graph);
  3426. tableLayout.rows = style['tableRows'] || 2;
  3427. tableLayout.columns = style['tableColumns'] || 2;
  3428. tableLayout.colPercentages = style['colPercentages'];
  3429. tableLayout.rowPercentages = style['rowPercentages'];
  3430. tableLayout.equalColumns = mxUtils.getValue(style, 'equalColumns', tableLayout.colPercentages? '0' : '1') == '1';
  3431. tableLayout.equalRows = mxUtils.getValue(style, 'equalRows', tableLayout.rowPercentages? '0' : '1') == '1';
  3432. tableLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  3433. tableLayout.border = style['tableBorder'] || tableLayout.border;
  3434. tableLayout.marginLeft = style['marginLeft'] || 0;
  3435. tableLayout.marginRight = style['marginRight'] || 0;
  3436. tableLayout.marginTop = style['marginTop'] || 0;
  3437. tableLayout.marginBottom = style['marginBottom'] || 0;
  3438. tableLayout.autoAddCol = mxUtils.getValue(style, 'autoAddCol', '0') == '1';
  3439. tableLayout.autoAddRow = mxUtils.getValue(style, 'autoAddRow', tableLayout.autoAddCol? '0' : '1') == '1';
  3440. tableLayout.colWidths = style['colWidths'] || "100";
  3441. tableLayout.rowHeights = style['rowHeights'] || "50";
  3442. return tableLayout;
  3443. }
  3444. }
  3445. return layoutManagerGetLayout.apply(this, arguments);
  3446. }
  3447. this.updateGlobalUrlVariables();
  3448. };
  3449. /**
  3450. * Updates the global variables from the vars URL parameter.
  3451. */
  3452. Graph.prototype.updateGlobalUrlVariables = function()
  3453. {
  3454. this.globalVars = Editor.globalVars;
  3455. if (urlParams['vars'] != null)
  3456. {
  3457. try
  3458. {
  3459. this.globalVars = (this.globalVars != null) ? mxUtils.clone(this.globalVars) : {};
  3460. var vars = JSON.parse(decodeURIComponent(urlParams['vars']));
  3461. if (vars != null)
  3462. {
  3463. for (var key in vars)
  3464. {
  3465. this.globalVars[key] = vars[key];
  3466. }
  3467. }
  3468. }
  3469. catch (e)
  3470. {
  3471. if (window.console != null)
  3472. {
  3473. console.log('Error in vars URL parameter: ' + e);
  3474. }
  3475. }
  3476. }
  3477. };
  3478. /**
  3479. * Returns all global variables used for export. This function never returns null.
  3480. * This can be overridden by plugins to return global variables for export.
  3481. */
  3482. Graph.prototype.getExportVariables = function()
  3483. {
  3484. return (this.globalVars != null) ? mxUtils.clone(this.globalVars) : {};
  3485. };
  3486. /**
  3487. * Adds support for vars URL parameter.
  3488. */
  3489. var graphGetGlobalVariable = Graph.prototype.getGlobalVariable;
  3490. Graph.prototype.getGlobalVariable = function(name)
  3491. {
  3492. var val = graphGetGlobalVariable.apply(this, arguments);
  3493. if (val == null && this.globalVars != null)
  3494. {
  3495. val = this.globalVars[name];
  3496. }
  3497. return val;
  3498. };
  3499. /**
  3500. * Cached default stylesheet for image export in dark mode.
  3501. */
  3502. Graph.prototype.getDefaultStylesheet = function()
  3503. {
  3504. if (this.defaultStylesheet == null)
  3505. {
  3506. var node = this.themes['default-style2'];
  3507. var dec = new mxCodec(node.ownerDocument);
  3508. this.defaultStylesheet = dec.decode(node);
  3509. }
  3510. return this.defaultStylesheet;
  3511. };
  3512. /**
  3513. * Overiddes function to use url parameter
  3514. */
  3515. Graph.prototype.isViewer = function()
  3516. {
  3517. return urlParams['viewer'];
  3518. };
  3519. /**
  3520. * Temporarily overrides stylesheet during image export in dark mode.
  3521. */
  3522. var graphGetSvg = Graph.prototype.getSvg;
  3523. Graph.prototype.getSvg = function(background, scale, border, nocrop, crisp,
  3524. ignoreSelection, showText, imgExport, linkTarget, hasShadow, incExtFonts)
  3525. {
  3526. var temp = null;
  3527. if (this.themes != null && this.defaultThemeName == 'darkTheme')
  3528. {
  3529. temp = this.stylesheet;
  3530. this.stylesheet = this.getDefaultStylesheet()
  3531. this.refresh();
  3532. }
  3533. var result = graphGetSvg.apply(this, arguments);
  3534. // Adds extrnal fonts
  3535. if (incExtFonts && this.extFonts != null && this.extFonts.length > 0)
  3536. {
  3537. var svgDoc = result.ownerDocument;
  3538. var style = (svgDoc.createElementNS != null) ?
  3539. svgDoc.createElementNS(mxConstants.NS_SVG, 'style') : svgDoc.createElement('style');
  3540. svgDoc.setAttributeNS != null? style.setAttributeNS('type', 'text/css') : style.setAttribute('type', 'text/css');
  3541. var prefix = '';
  3542. var postfix = '';
  3543. for (var i = 0; i < this.extFonts.length; i++)
  3544. {
  3545. var fontName = this.extFonts[i].name, fontUrl = this.extFonts[i].url;
  3546. if (fontUrl.indexOf(Editor.GOOGLE_FONTS) == 0)
  3547. {
  3548. prefix += '@import url(' + fontUrl + ');\n';
  3549. }
  3550. else
  3551. {
  3552. postfix += '@font-face {\n' +
  3553. 'font-family: "'+ fontName +'";\n' +
  3554. 'src: url("'+ fontUrl +'");\n' +
  3555. '}\n';
  3556. }
  3557. }
  3558. style.appendChild(svgDoc.createTextNode(prefix + postfix));
  3559. result.getElementsByTagName('defs')[0].appendChild(style);
  3560. }
  3561. if (temp != null)
  3562. {
  3563. this.stylesheet = temp;
  3564. this.refresh();
  3565. }
  3566. return result;
  3567. };
  3568. /**
  3569. * Overridden to support client-side math typesetting.
  3570. */
  3571. var graphCreateSvgImageExport = Graph.prototype.createSvgImageExport;
  3572. Graph.prototype.createSvgImageExport = function()
  3573. {
  3574. var imgExport = graphCreateSvgImageExport.apply(this, arguments);
  3575. if (this.mathEnabled)
  3576. {
  3577. var graph = this;
  3578. var origin = graph.container.getBoundingClientRect();
  3579. var y0 = graph.container.scrollTop - origin.y;
  3580. var x0 = graph.container.scrollLeft - origin.x;
  3581. var drawText = imgExport.drawText;
  3582. // Replaces input with rendered markup
  3583. imgExport.drawText = function(state, c)
  3584. {
  3585. if (state.text != null && state.text.value != null && state.text.checkBounds() &&
  3586. (mxUtils.isNode(state.text.value) || state.text.dialect == mxConstants.DIALECT_STRICTHTML))
  3587. {
  3588. var clone = state.text.getContentNode();
  3589. if (clone != null)
  3590. {
  3591. clone = clone.cloneNode(true);
  3592. // Removes duplicate math output
  3593. if (clone.getElementsByTagNameNS)
  3594. {
  3595. var ele = clone.getElementsByTagNameNS('http://www.w3.org/1998/Math/MathML', 'math');
  3596. while (ele.length > 0)
  3597. {
  3598. ele[0].parentNode.removeChild(ele[0]);
  3599. }
  3600. }
  3601. if (clone.innerHTML != null)
  3602. {
  3603. var prev = state.text.value;
  3604. state.text.value = clone.innerHTML;
  3605. drawText.apply(this, arguments);
  3606. state.text.value = prev;
  3607. }
  3608. }
  3609. }
  3610. else
  3611. {
  3612. drawText.apply(this, arguments);
  3613. }
  3614. };
  3615. }
  3616. return imgExport;
  3617. };
  3618. /**
  3619. * Adds workaround for math rendering in Chrome.
  3620. *
  3621. * Workaround for https://bugs.webkit.org/show_bug.cgi?id=93358 in WebKit
  3622. *
  3623. * Adding an absolute position DIV before the SVG seems to mitigate the problem.
  3624. */
  3625. var graphViewValidateBackgroundPage = mxGraphView.prototype.validateBackgroundPage;
  3626. mxGraphView.prototype.validateBackgroundPage = function()
  3627. {
  3628. graphViewValidateBackgroundPage.apply(this, arguments);
  3629. if (mxClient.IS_GC && this.getDrawPane() != null)
  3630. {
  3631. var g = this.getDrawPane().parentNode;
  3632. if (this.graph.mathEnabled && !mxClient.NO_FO &&
  3633. (this.webKitForceRepaintNode == null ||
  3634. this.webKitForceRepaintNode.parentNode == null) &&
  3635. this.graph.container.firstChild.nodeName == 'svg')
  3636. {
  3637. this.webKitForceRepaintNode = document.createElement('div');
  3638. this.webKitForceRepaintNode.style.cssText = 'position:absolute;';
  3639. g.ownerSVGElement.parentNode.insertBefore(this.webKitForceRepaintNode, g.ownerSVGElement);
  3640. }
  3641. else if (this.webKitForceRepaintNode != null && (!this.graph.mathEnabled ||
  3642. (this.graph.container.firstChild.nodeName != 'svg' &&
  3643. this.graph.container.firstChild != this.webKitForceRepaintNode)))
  3644. {
  3645. if (this.webKitForceRepaintNode.parentNode != null)
  3646. {
  3647. this.webKitForceRepaintNode.parentNode.removeChild(this.webKitForceRepaintNode);
  3648. }
  3649. this.webKitForceRepaintNode = null;
  3650. }
  3651. }
  3652. };
  3653. /**
  3654. * Sets default style (used in editor.get/setGraphXml below)
  3655. */
  3656. var graphLoadStylesheet = Graph.prototype.loadStylesheet;
  3657. Graph.prototype.loadStylesheet = function()
  3658. {
  3659. graphLoadStylesheet.apply(this, arguments);
  3660. this.currentStyle = 'default-style2';
  3661. };
  3662. /**
  3663. * Adds support for data:action/json,{"actions":[actions]} where actions is
  3664. * a comma-separated list of JSON objects with the following possible keys:
  3665. *
  3666. * "open": string - opens a standard or custom link (including page links)
  3667. * "toggle"/"show"/"hide"/"highlight": cellset - toggles, shows, hides or
  3668. * highlights the given cells
  3669. * "select": cellset - selects the given cells if the graph is editable
  3670. * "scroll": cellset - scrolls to the first cell in the given celllset
  3671. * If no scroll action is specified, then the first cell of the select
  3672. * or highlight action is scrolled to visible (select has precedence).
  3673. * A cellset is an array of cell IDs or tags or both, eg.
  3674. * {"cells": ["id1", "id2"], "tags": ["tag1", "tag2"]}
  3675. * To specify all cells, use "cells": ["*"], to specify all cells with
  3676. * a tag, use "tags": [] (empty array).
  3677. *
  3678. * An example action is:
  3679. *
  3680. * data:action/json,{"actions":[{"toggle": {"cells": ["3", "4"]}}]}
  3681. *
  3682. * This toggles the visible state of the cells with ID 3 and 4.
  3683. */
  3684. Graph.prototype.handleCustomLink = function(href)
  3685. {
  3686. if (href.substring(0, 17) == 'data:action/json,')
  3687. {
  3688. // Some actions are stateless and must be handled before the transaction
  3689. var link = JSON.parse(href.substring(17));
  3690. // When adding new actions that reference cell IDs support for updating
  3691. // those cell IDs must be handled in Graph.updateCustomLinkActions
  3692. if (link.actions != null)
  3693. {
  3694. // Executes open actions before starting transaction
  3695. for (var i = 0; i < link.actions.length; i++)
  3696. {
  3697. var action = link.actions[i];
  3698. if (action.open != null)
  3699. {
  3700. if (this.isCustomLink(action.open))
  3701. {
  3702. if (!this.customLinkClicked(action.open))
  3703. {
  3704. return;
  3705. }
  3706. }
  3707. else
  3708. {
  3709. this.openLink(action.open);
  3710. }
  3711. }
  3712. }
  3713. // Executes all actions that change cell states
  3714. this.model.beginUpdate();
  3715. try
  3716. {
  3717. for (var i = 0; i < link.actions.length; i++)
  3718. {
  3719. var action = link.actions[i];
  3720. if (action.toggle != null)
  3721. {
  3722. this.toggleCells(this.getCellsForAction(action.toggle, true));
  3723. }
  3724. if (action.show != null)
  3725. {
  3726. this.setCellsVisible(this.getCellsForAction(action.show, true), true);
  3727. }
  3728. if (action.hide != null)
  3729. {
  3730. this.setCellsVisible(this.getCellsForAction(action.hide, true), false);
  3731. }
  3732. }
  3733. }
  3734. finally
  3735. {
  3736. this.model.endUpdate();
  3737. }
  3738. // Executes stateless actions on cells
  3739. for (var i = 0; i < link.actions.length; i++)
  3740. {
  3741. var action = link.actions[i];
  3742. var cells = [];
  3743. if (action.select != null && this.isEnabled())
  3744. {
  3745. cells = this.getCellsForAction(action.select);
  3746. this.setSelectionCells(cells);
  3747. }
  3748. if (action.highlight != null)
  3749. {
  3750. cells = this.getCellsForAction(action.highlight);
  3751. this.highlightCells(cells, action.highlight.color,
  3752. action.highlight.duration, action.highlight.opacity);
  3753. }
  3754. if (action.scroll != null)
  3755. {
  3756. cells = this.getCellsForAction(action.scroll);
  3757. }
  3758. if (cells.length > 0)
  3759. {
  3760. this.scrollCellToVisible(cells[0]);
  3761. }
  3762. }
  3763. }
  3764. }
  3765. };
  3766. /**
  3767. * Updates cell IDs in custom links on the given cell and its label.
  3768. */
  3769. Graph.prototype.updateCustomLinksForCell = function(mapping, cell)
  3770. {
  3771. var href = this.getLinkForCell(cell);
  3772. if (href != null && href.substring(0, 17) == 'data:action/json,')
  3773. {
  3774. this.setLinkForCell(cell, this.updateCustomLink(mapping, href));
  3775. }
  3776. if (this.isHtmlLabel(cell))
  3777. {
  3778. var temp = document.createElement('div');
  3779. temp.innerHTML = this.getLabel(cell);
  3780. var links = temp.getElementsByTagName('a');
  3781. var changed = false;
  3782. for (var i = 0; i < links.length; i++)
  3783. {
  3784. href = links[i].getAttribute('href');
  3785. if (href != null && href.substring(0, 17) == 'data:action/json,')
  3786. {
  3787. links[i].setAttribute('href', this.updateCustomLink(mapping, href));
  3788. changed = true;
  3789. }
  3790. }
  3791. if (changed)
  3792. {
  3793. this.labelChanged(cell, temp.innerHTML);
  3794. }
  3795. }
  3796. };
  3797. /**
  3798. * Updates cell IDs in the given custom link and returns the updated link.
  3799. */
  3800. Graph.prototype.updateCustomLink = function(mapping, href)
  3801. {
  3802. if (href.substring(0, 17) == 'data:action/json,')
  3803. {
  3804. try
  3805. {
  3806. // Some actions are stateless and must be handled before the transaction
  3807. var link = JSON.parse(href.substring(17));
  3808. if (link.actions != null)
  3809. {
  3810. this.updateCustomLinkActions(mapping, link.actions);
  3811. href = 'data:action/json,' + JSON.stringify(link);
  3812. }
  3813. }
  3814. catch (e)
  3815. {
  3816. // Ignore
  3817. }
  3818. }
  3819. return href;
  3820. };
  3821. /**
  3822. * Updates cell IDs in the given custom link actions.
  3823. */
  3824. Graph.prototype.updateCustomLinkActions = function(mapping, actions)
  3825. {
  3826. for (var i = 0; i < actions.length; i++)
  3827. {
  3828. var action = actions[i];
  3829. this.updateCustomLinkAction(mapping, action.toggle);
  3830. this.updateCustomLinkAction(mapping, action.show);
  3831. this.updateCustomLinkAction(mapping, action.hide);
  3832. this.updateCustomLinkAction(mapping, action.select);
  3833. this.updateCustomLinkAction(mapping, action.highlight);
  3834. this.updateCustomLinkAction(mapping, action.scroll);
  3835. }
  3836. };
  3837. /**
  3838. * Updates cell IDs in the given custom link action.
  3839. */
  3840. Graph.prototype.updateCustomLinkAction = function(mapping, action)
  3841. {
  3842. if (action != null && action.cells != null)
  3843. {
  3844. var result = [];
  3845. for (var i = 0; i < action.cells.length; i++)
  3846. {
  3847. if (action.cells[i] == '*')
  3848. {
  3849. result.push(action.cells[i]);
  3850. }
  3851. else
  3852. {
  3853. var temp = mapping[action.cells[i]];
  3854. if (temp != null)
  3855. {
  3856. if (temp != '')
  3857. {
  3858. result.push(temp);
  3859. }
  3860. }
  3861. else
  3862. {
  3863. result.push(action.cells[i]);
  3864. }
  3865. }
  3866. }
  3867. action.cells = result;
  3868. }
  3869. };
  3870. /**
  3871. * Handles each action in the action array of a custom link. This code
  3872. * handles toggle actions for cell IDs.
  3873. */
  3874. Graph.prototype.getCellsForAction = function(action, includeLayers)
  3875. {
  3876. return this.getCellsById(action.cells).concat(
  3877. this.getCellsForTags(action.tags, null, null, includeLayers));
  3878. };
  3879. /**
  3880. * Returns the cells in the model (or given array) that have all of the
  3881. * given tags in their tags property.
  3882. */
  3883. Graph.prototype.getCellsById = function(ids)
  3884. {
  3885. var result = [];
  3886. if (ids != null)
  3887. {
  3888. for (var i = 0; i < ids.length; i++)
  3889. {
  3890. if (ids[i] == '*')
  3891. {
  3892. var parent = this.getDefaultParent();
  3893. result = result.concat(this.model.filterDescendants(function(cell)
  3894. {
  3895. return cell != parent;
  3896. }, parent));
  3897. }
  3898. else
  3899. {
  3900. var cell = this.model.getCell(ids[i]);
  3901. if (cell != null)
  3902. {
  3903. result.push(cell);
  3904. }
  3905. }
  3906. }
  3907. }
  3908. return result;
  3909. };
  3910. /**
  3911. * Returns the cells in the model (or given array) that have all of the
  3912. * given tags in their tags property.
  3913. */
  3914. Graph.prototype.getCellsForTags = function(tagList, cells, propertyName, includeLayers)
  3915. {
  3916. var result = [];
  3917. if (tagList != null)
  3918. {
  3919. cells = (cells != null) ? cells : this.model.getDescendants(this.model.getRoot());
  3920. propertyName = (propertyName != null) ? propertyName : 'tags';
  3921. var tagCount = 0;
  3922. var lookup = {};
  3923. for (var i = 0; i < tagList.length; i++)
  3924. {
  3925. if (tagList[i].length > 0)
  3926. {
  3927. lookup[tagList[i].toLowerCase()] = true;
  3928. tagCount++;
  3929. }
  3930. }
  3931. for (var i = 0; i < cells.length; i++)
  3932. {
  3933. if ((includeLayers && this.model.getParent(cells[i]) == this.model.root) ||
  3934. this.model.isVertex(cells[i]) || this.model.isEdge(cells[i]))
  3935. {
  3936. var tags = (cells[i].value != null && typeof(cells[i].value) == 'object') ?
  3937. mxUtils.trim(cells[i].value.getAttribute(propertyName) || '') : '';
  3938. var match = false;
  3939. if (tags.length > 0)
  3940. {
  3941. var tmp = tags.toLowerCase().split(' ');
  3942. if (tmp.length >= tagList.length)
  3943. {
  3944. var matchCount = 0;
  3945. for (var j = 0; j < tmp.length && (matchCount < tagCount); j++)
  3946. {
  3947. if (lookup[tmp[j]] != null)
  3948. {
  3949. matchCount++;
  3950. }
  3951. }
  3952. match = matchCount == tagCount;
  3953. }
  3954. }
  3955. else
  3956. {
  3957. match = tagList.length == 0;
  3958. }
  3959. if (match)
  3960. {
  3961. result.push(cells[i]);
  3962. }
  3963. }
  3964. }
  3965. }
  3966. return result;
  3967. };
  3968. /**
  3969. * Shows or hides the given cells.
  3970. */
  3971. Graph.prototype.toggleCells = function(cells)
  3972. {
  3973. this.model.beginUpdate();
  3974. try
  3975. {
  3976. for (var i = 0; i < cells.length; i++)
  3977. {
  3978. this.model.setVisible(cells[i], !this.model.isVisible(cells[i]))
  3979. }
  3980. }
  3981. finally
  3982. {
  3983. this.model.endUpdate();
  3984. }
  3985. };
  3986. /**
  3987. * Shows or hides the given cells.
  3988. */
  3989. Graph.prototype.setCellsVisible = function(cells, visible)
  3990. {
  3991. this.model.beginUpdate();
  3992. try
  3993. {
  3994. for (var i = 0; i < cells.length; i++)
  3995. {
  3996. this.model.setVisible(cells[i], visible);
  3997. }
  3998. }
  3999. finally
  4000. {
  4001. this.model.endUpdate();
  4002. }
  4003. };
  4004. /**
  4005. * Highlights the given cell.
  4006. */
  4007. Graph.prototype.highlightCells = function(cells, color, duration, opacity)
  4008. {
  4009. for (var i = 0; i < cells.length; i++)
  4010. {
  4011. this.highlightCell(cells[i], color, duration, opacity);
  4012. }
  4013. };
  4014. /**
  4015. * Highlights the given cell.
  4016. */
  4017. Graph.prototype.highlightCell = function(cell, color, duration, opacity)
  4018. {
  4019. color = (color != null) ? color : mxConstants.DEFAULT_VALID_COLOR;
  4020. duration = (duration != null) ? duration : 1000;
  4021. var state = this.view.getState(cell);
  4022. if (state != null)
  4023. {
  4024. var sw = Math.max(5, mxUtils.getValue(state.style, mxConstants.STYLE_STROKEWIDTH, 1) + 4);
  4025. var hl = new mxCellHighlight(this, color, sw, false);
  4026. if (opacity != null)
  4027. {
  4028. hl.opacity = opacity;
  4029. }
  4030. hl.highlight(state);
  4031. // Fades out the highlight after a duration
  4032. window.setTimeout(function()
  4033. {
  4034. if (hl.shape != null)
  4035. {
  4036. mxUtils.setPrefixedStyle(hl.shape.node.style, 'transition', 'all 1200ms ease-in-out');
  4037. hl.shape.node.style.opacity = 0;
  4038. }
  4039. // Destroys the highlight after the fade
  4040. window.setTimeout(function()
  4041. {
  4042. hl.destroy();
  4043. }, 1200);
  4044. }, duration);
  4045. }
  4046. };
  4047. /**
  4048. * Adds a shadow filter to the given svg root.
  4049. */
  4050. Graph.prototype.addSvgShadow = function(svgRoot, group, createOnly)
  4051. {
  4052. createOnly = (createOnly != null) ? createOnly : false;
  4053. var svgDoc = svgRoot.ownerDocument;
  4054. var filter = (svgDoc.createElementNS != null) ?
  4055. svgDoc.createElementNS(mxConstants.NS_SVG, 'filter') : svgDoc.createElement('filter');
  4056. filter.setAttribute('id', this.shadowId);
  4057. var blur = (svgDoc.createElementNS != null) ?
  4058. svgDoc.createElementNS(mxConstants.NS_SVG, 'feGaussianBlur') : svgDoc.createElement('feGaussianBlur');
  4059. blur.setAttribute('in', 'SourceAlpha');
  4060. blur.setAttribute('stdDeviation', this.svgShadowBlur);
  4061. blur.setAttribute('result', 'blur');
  4062. filter.appendChild(blur);
  4063. var offset = (svgDoc.createElementNS != null) ?
  4064. svgDoc.createElementNS(mxConstants.NS_SVG, 'feOffset') : svgDoc.createElement('feOffset');
  4065. offset.setAttribute('in', 'blur');
  4066. offset.setAttribute('dx', this.svgShadowSize);
  4067. offset.setAttribute('dy', this.svgShadowSize);
  4068. offset.setAttribute('result', 'offsetBlur');
  4069. filter.appendChild(offset);
  4070. var flood = (svgDoc.createElementNS != null) ?
  4071. svgDoc.createElementNS(mxConstants.NS_SVG, 'feFlood') : svgDoc.createElement('feFlood');
  4072. flood.setAttribute('flood-color', this.svgShadowColor);
  4073. flood.setAttribute('flood-opacity', this.svgShadowOpacity);
  4074. flood.setAttribute('result', 'offsetColor');
  4075. filter.appendChild(flood);
  4076. var composite = (svgDoc.createElementNS != null) ?
  4077. svgDoc.createElementNS(mxConstants.NS_SVG, 'feComposite') : svgDoc.createElement('feComposite');
  4078. composite.setAttribute('in', 'offsetColor');
  4079. composite.setAttribute('in2', 'offsetBlur');
  4080. composite.setAttribute('operator', 'in');
  4081. composite.setAttribute('result', 'offsetBlur');
  4082. filter.appendChild(composite);
  4083. var feBlend = (svgDoc.createElementNS != null) ?
  4084. svgDoc.createElementNS(mxConstants.NS_SVG, 'feBlend') : svgDoc.createElement('feBlend');
  4085. feBlend.setAttribute('in', 'SourceGraphic');
  4086. feBlend.setAttribute('in2', 'offsetBlur');
  4087. filter.appendChild(feBlend);
  4088. // Creates defs element if not available
  4089. var defs = svgRoot.getElementsByTagName('defs');
  4090. var defsElt = null;
  4091. if (defs.length == 0)
  4092. {
  4093. defsElt = (svgDoc.createElementNS != null) ?
  4094. svgDoc.createElementNS(mxConstants.NS_SVG, 'defs') : svgDoc.createElement('defs');
  4095. if (svgRoot.firstChild != null)
  4096. {
  4097. svgRoot.insertBefore(defsElt, svgRoot.firstChild);
  4098. }
  4099. else
  4100. {
  4101. svgRoot.appendChild(defsElt);
  4102. }
  4103. }
  4104. else
  4105. {
  4106. defsElt = defs[0];
  4107. }
  4108. defsElt.appendChild(filter);
  4109. if (!createOnly)
  4110. {
  4111. group = (group != null) ? group : svgRoot.getElementsByTagName('g')[0];
  4112. if (group != null)
  4113. {
  4114. group.setAttribute('filter', 'url(#' + this.shadowId + ')');
  4115. if (!isNaN(parseInt(svgRoot.getAttribute('width'))))
  4116. {
  4117. svgRoot.setAttribute('width', parseInt(svgRoot.getAttribute('width')) + 6);
  4118. svgRoot.setAttribute('height', parseInt(svgRoot.getAttribute('height')) + 6);
  4119. // Updates viewbox if one exists
  4120. var vb = svgRoot.getAttribute('viewBox');
  4121. if (vb != null && vb.length > 0)
  4122. {
  4123. var tokens = vb.split(' ');
  4124. if (tokens.length > 3)
  4125. {
  4126. w = parseFloat(tokens[2]) + 6;
  4127. h = parseFloat(tokens[3]) + 6;
  4128. svgRoot.setAttribute('viewBox', tokens[0] + ' ' + tokens[1] + ' ' + w + ' ' + h);
  4129. }
  4130. }
  4131. }
  4132. }
  4133. }
  4134. return filter;
  4135. };
  4136. /**
  4137. * Loads the stylesheet for this graph.
  4138. */
  4139. Graph.prototype.setShadowVisible = function(value, fireEvent)
  4140. {
  4141. if (mxClient.IS_SVG)
  4142. {
  4143. fireEvent = (fireEvent != null) ? fireEvent : true;
  4144. this.shadowVisible = value;
  4145. if (this.shadowVisible)
  4146. {
  4147. this.view.getDrawPane().setAttribute('filter', 'url(#' + this.shadowId + ')');
  4148. }
  4149. else
  4150. {
  4151. this.view.getDrawPane().removeAttribute('filter');
  4152. }
  4153. if (fireEvent)
  4154. {
  4155. this.fireEvent(new mxEventObject('shadowVisibleChanged'));
  4156. }
  4157. }
  4158. };
  4159. /**
  4160. * Selects first unlocked layer if one exists
  4161. */
  4162. Graph.prototype.selectUnlockedLayer = function()
  4163. {
  4164. if (this.defaultParent == null)
  4165. {
  4166. var childCount = this.model.getChildCount(this.model.root);
  4167. var cell = null;
  4168. var index = 0;
  4169. do
  4170. {
  4171. cell = this.model.getChildAt(this.model.root, index);
  4172. } while (index++ < childCount && mxUtils.getValue(this.getCellStyle(cell), 'locked', '0') == '1')
  4173. if (cell != null)
  4174. {
  4175. this.setDefaultParent(cell);
  4176. }
  4177. }
  4178. };
  4179. /**
  4180. * Specifies special libraries that are loaded via dynamic JS. Add cases
  4181. * where the filename cannot be worked out from the package name. The
  4182. * standard scheme for this mapping is stencils/packagename.xml. If there
  4183. * are multiple XML files, any JS files or any anomalies in the filename or
  4184. * directory that contains the file, then an entry must be added here and
  4185. * in EmbedServlet2 for the loading of the shapes to work.
  4186. */
  4187. // Required to avoid 404 for mockup.xml since naming of mxgraph.mockup.anchor does not contain
  4188. // buttons even though it is defined in the mxMockupButtons.js file. This could only be fixed
  4189. // with aliases for existing shapes or aliases for basenames, but this is essentially the same.
  4190. mxStencilRegistry.libraries['mockup'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  4191. mxStencilRegistry.libraries['arrows2'] = [SHAPES_PATH + '/mxArrows.js'];
  4192. mxStencilRegistry.libraries['atlassian'] = [STENCIL_PATH + '/atlassian.xml', SHAPES_PATH + '/mxAtlassian.js'];
  4193. mxStencilRegistry.libraries['bpmn'] = [SHAPES_PATH + '/bpmn/mxBpmnShape2.js', STENCIL_PATH + '/bpmn.xml'];
  4194. mxStencilRegistry.libraries['c4'] = [SHAPES_PATH + '/mxC4.js'];
  4195. mxStencilRegistry.libraries['cisco19'] = [SHAPES_PATH + '/mxCisco19.js', STENCIL_PATH + '/cisco19.xml'];
  4196. mxStencilRegistry.libraries['dfd'] = [SHAPES_PATH + '/mxDFD.js'];
  4197. mxStencilRegistry.libraries['er'] = [SHAPES_PATH + '/er/mxER.js'];
  4198. mxStencilRegistry.libraries['kubernetes'] = [SHAPES_PATH + '/mxKubernetes.js', STENCIL_PATH + '/kubernetes.xml'];
  4199. mxStencilRegistry.libraries['flowchart'] = [SHAPES_PATH + '/mxFlowchart.js', STENCIL_PATH + '/flowchart.xml'];
  4200. mxStencilRegistry.libraries['ios'] = [SHAPES_PATH + '/mockup/mxMockupiOS.js'];
  4201. mxStencilRegistry.libraries['rackGeneral'] = [SHAPES_PATH + '/rack/mxRack.js', STENCIL_PATH + '/rack/general.xml'];
  4202. mxStencilRegistry.libraries['rackF5'] = [STENCIL_PATH + '/rack/f5.xml'];
  4203. mxStencilRegistry.libraries['lean_mapping'] = [SHAPES_PATH + '/mxLeanMap.js', STENCIL_PATH + '/lean_mapping.xml'];
  4204. mxStencilRegistry.libraries['basic'] = [SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/basic.xml'];
  4205. mxStencilRegistry.libraries['ios7icons'] = [STENCIL_PATH + '/ios7/icons.xml'];
  4206. mxStencilRegistry.libraries['ios7ui'] = [SHAPES_PATH + '/ios7/mxIOS7Ui.js', STENCIL_PATH + '/ios7/misc.xml'];
  4207. mxStencilRegistry.libraries['android'] = [SHAPES_PATH + '/mxAndroid.js', STENCIL_PATH + '/android/android.xml'];
  4208. mxStencilRegistry.libraries['electrical/miscellaneous'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/miscellaneous.xml'];
  4209. mxStencilRegistry.libraries['electrical/transmission'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/transmission.xml'];
  4210. mxStencilRegistry.libraries['electrical/logic_gates'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/logic_gates.xml'];
  4211. mxStencilRegistry.libraries['electrical/abstract'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/abstract.xml'];
  4212. mxStencilRegistry.libraries['infographic'] = [SHAPES_PATH + '/mxInfographic.js'];
  4213. mxStencilRegistry.libraries['mockup/buttons'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  4214. mxStencilRegistry.libraries['mockup/containers'] = [SHAPES_PATH + '/mockup/mxMockupContainers.js'];
  4215. mxStencilRegistry.libraries['mockup/forms'] = [SHAPES_PATH + '/mockup/mxMockupForms.js'];
  4216. mxStencilRegistry.libraries['mockup/graphics'] = [SHAPES_PATH + '/mockup/mxMockupGraphics.js', STENCIL_PATH + '/mockup/misc.xml'];
  4217. mxStencilRegistry.libraries['mockup/markup'] = [SHAPES_PATH + '/mockup/mxMockupMarkup.js'];
  4218. mxStencilRegistry.libraries['mockup/misc'] = [SHAPES_PATH + '/mockup/mxMockupMisc.js', STENCIL_PATH + '/mockup/misc.xml'];
  4219. mxStencilRegistry.libraries['mockup/navigation'] = [SHAPES_PATH + '/mockup/mxMockupNavigation.js', STENCIL_PATH + '/mockup/misc.xml'];
  4220. mxStencilRegistry.libraries['mockup/text'] = [SHAPES_PATH + '/mockup/mxMockupText.js'];
  4221. mxStencilRegistry.libraries['floorplan'] = [SHAPES_PATH + '/mxFloorplan.js', STENCIL_PATH + '/floorplan.xml'];
  4222. mxStencilRegistry.libraries['bootstrap'] = [SHAPES_PATH + '/mxBootstrap.js', STENCIL_PATH + '/bootstrap.xml'];
  4223. mxStencilRegistry.libraries['gmdl'] = [SHAPES_PATH + '/mxGmdl.js', STENCIL_PATH + '/gmdl.xml'];
  4224. mxStencilRegistry.libraries['gcp2'] = [SHAPES_PATH + '/mxGCP2.js', STENCIL_PATH + '/gcp2.xml'];
  4225. mxStencilRegistry.libraries['cabinets'] = [SHAPES_PATH + '/mxCabinets.js', STENCIL_PATH + '/cabinets.xml'];
  4226. mxStencilRegistry.libraries['archimate'] = [SHAPES_PATH + '/mxArchiMate.js'];
  4227. mxStencilRegistry.libraries['archimate3'] = [SHAPES_PATH + '/mxArchiMate3.js'];
  4228. mxStencilRegistry.libraries['sysml'] = [SHAPES_PATH + '/mxSysML.js'];
  4229. mxStencilRegistry.libraries['eip'] = [SHAPES_PATH + '/mxEip.js', STENCIL_PATH + '/eip.xml'];
  4230. mxStencilRegistry.libraries['networks'] = [SHAPES_PATH + '/mxNetworks.js', STENCIL_PATH + '/networks.xml'];
  4231. mxStencilRegistry.libraries['aws3d'] = [SHAPES_PATH + '/mxAWS3D.js', STENCIL_PATH + '/aws3d.xml'];
  4232. mxStencilRegistry.libraries['aws4'] = [SHAPES_PATH + '/mxAWS4.js', STENCIL_PATH + '/aws4.xml'];
  4233. mxStencilRegistry.libraries['aws4b'] = [SHAPES_PATH + '/mxAWS4.js', STENCIL_PATH + '/aws4.xml'];
  4234. mxStencilRegistry.libraries['veeam'] = [STENCIL_PATH + '/veeam/2d.xml', STENCIL_PATH + '/veeam/3d.xml', STENCIL_PATH + '/veeam/veeam.xml'];
  4235. mxStencilRegistry.libraries['pid2inst'] = [SHAPES_PATH + '/pid2/mxPidInstruments.js'];
  4236. mxStencilRegistry.libraries['pid2misc'] = [SHAPES_PATH + '/pid2/mxPidMisc.js', STENCIL_PATH + '/pid/misc.xml'];
  4237. mxStencilRegistry.libraries['pid2valves'] = [SHAPES_PATH + '/pid2/mxPidValves.js'];
  4238. mxStencilRegistry.libraries['pidFlowSensors'] = [STENCIL_PATH + '/pid/flow_sensors.xml'];
  4239. // Triggers dynamic loading for markers
  4240. mxMarker.getPackageForType = function(type)
  4241. {
  4242. var name = null;
  4243. if (type != null && type.length > 0)
  4244. {
  4245. if (type.substring(0, 2) == 'ER')
  4246. {
  4247. name = 'mxgraph.er';
  4248. }
  4249. else if (type.substring(0, 5) == 'sysML')
  4250. {
  4251. name = 'mxgraph.sysml';
  4252. }
  4253. }
  4254. return name;
  4255. };
  4256. var mxMarkerCreateMarker = mxMarker.createMarker;
  4257. mxMarker.createMarker = function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  4258. {
  4259. if (type != null)
  4260. {
  4261. var f = mxMarker.markers[type];
  4262. if (f == null)
  4263. {
  4264. var name = this.getPackageForType(type);
  4265. if (name != null)
  4266. {
  4267. mxStencilRegistry.getStencil(name);
  4268. }
  4269. }
  4270. }
  4271. return mxMarkerCreateMarker.apply(this, arguments);
  4272. };
  4273. /**
  4274. * Constructs a new print dialog.
  4275. */
  4276. PrintDialog.prototype.create = function(editorUi, titleText)
  4277. {
  4278. var graph = editorUi.editor.graph;
  4279. var div = document.createElement('div');
  4280. var title = document.createElement('h3');
  4281. title.style.width = '100%';
  4282. title.style.textAlign = 'center';
  4283. title.style.marginTop = '0px';
  4284. mxUtils.write(title, titleText || mxResources.get('print'));
  4285. div.appendChild(title);
  4286. var pageCount = 1;
  4287. var currentPage = 1;
  4288. // Pages
  4289. var pagesSection = document.createElement('div');
  4290. pagesSection.style.cssText = 'border-bottom:1px solid lightGray;padding-bottom:12px;margin-bottom:12px;';
  4291. var allPagesRadio = document.createElement('input');
  4292. allPagesRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  4293. allPagesRadio.setAttribute('value', 'all');
  4294. allPagesRadio.setAttribute('type', 'radio');
  4295. allPagesRadio.setAttribute('name', 'pages-printdialog');
  4296. pagesSection.appendChild(allPagesRadio);
  4297. var span = document.createElement('span');
  4298. mxUtils.write(span, mxResources.get('printAllPages'));
  4299. pagesSection.appendChild(span);
  4300. mxUtils.br(pagesSection);
  4301. // Pages ... to ...
  4302. var pagesRadio = allPagesRadio.cloneNode(true);
  4303. allPagesRadio.setAttribute('checked', 'checked');
  4304. pagesRadio.setAttribute('value', 'range');
  4305. pagesSection.appendChild(pagesRadio);
  4306. var span = document.createElement('span');
  4307. mxUtils.write(span, mxResources.get('pages') + ':');
  4308. pagesSection.appendChild(span);
  4309. var pagesFromInput = document.createElement('input');
  4310. pagesFromInput.style.cssText = 'margin:0 8px 0 8px;'
  4311. pagesFromInput.setAttribute('value', '1');
  4312. pagesFromInput.setAttribute('type', 'number');
  4313. pagesFromInput.setAttribute('min', '1');
  4314. pagesFromInput.style.width = '50px';
  4315. pagesSection.appendChild(pagesFromInput);
  4316. var span = document.createElement('span');
  4317. mxUtils.write(span, mxResources.get('to'));
  4318. pagesSection.appendChild(span);
  4319. var pagesToInput = pagesFromInput.cloneNode(true);
  4320. pagesSection.appendChild(pagesToInput);
  4321. mxEvent.addListener(pagesFromInput, 'focus', function()
  4322. {
  4323. pagesRadio.checked = true;
  4324. });
  4325. mxEvent.addListener(pagesToInput, 'focus', function()
  4326. {
  4327. pagesRadio.checked = true;
  4328. });
  4329. function validatePageRange()
  4330. {
  4331. pagesToInput.value = Math.max(1, Math.min(pageCount, Math.max(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  4332. pagesFromInput.value = Math.max(1, Math.min(pageCount, Math.min(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  4333. };
  4334. mxEvent.addListener(pagesFromInput, 'change', validatePageRange);
  4335. mxEvent.addListener(pagesToInput, 'change', validatePageRange);
  4336. if (editorUi.pages != null)
  4337. {
  4338. pageCount = editorUi.pages.length;
  4339. if (editorUi.currentPage != null)
  4340. {
  4341. for (var i = 0; i < editorUi.pages.length; i++)
  4342. {
  4343. if (editorUi.currentPage == editorUi.pages[i])
  4344. {
  4345. currentPage = i + 1;
  4346. pagesFromInput.value = currentPage;
  4347. pagesToInput.value = currentPage;
  4348. break;
  4349. }
  4350. }
  4351. }
  4352. }
  4353. pagesFromInput.setAttribute('max', pageCount);
  4354. pagesToInput.setAttribute('max', pageCount);
  4355. if (pageCount > 1)
  4356. {
  4357. div.appendChild(pagesSection);
  4358. }
  4359. // Adjust to ...
  4360. var adjustSection = document.createElement('div');
  4361. adjustSection.style.marginBottom = '10px';
  4362. var adjustRadio = document.createElement('input');
  4363. adjustRadio.style.marginRight = '8px';
  4364. adjustRadio.setAttribute('value', 'adjust');
  4365. adjustRadio.setAttribute('type', 'radio');
  4366. adjustRadio.setAttribute('name', 'printZoom');
  4367. adjustSection.appendChild(adjustRadio);
  4368. var span = document.createElement('span');
  4369. mxUtils.write(span, mxResources.get('adjustTo'));
  4370. adjustSection.appendChild(span);
  4371. var zoomInput = document.createElement('input');
  4372. zoomInput.style.cssText = 'margin:0 8px 0 8px;';
  4373. zoomInput.setAttribute('value', '100 %');
  4374. zoomInput.style.width = '50px';
  4375. adjustSection.appendChild(zoomInput);
  4376. mxEvent.addListener(zoomInput, 'focus', function()
  4377. {
  4378. adjustRadio.checked = true;
  4379. });
  4380. div.appendChild(adjustSection);
  4381. // Fit to ...
  4382. var fitSection = pagesSection.cloneNode(false);
  4383. var fitRadio = adjustRadio.cloneNode(true);
  4384. fitRadio.setAttribute('value', 'fit');
  4385. adjustRadio.setAttribute('checked', 'checked');
  4386. var spanFitRadio = document.createElement('div');
  4387. spanFitRadio.style.cssText = 'display:inline-block;height:100%;vertical-align:top;padding-top:2px;';
  4388. spanFitRadio.appendChild(fitRadio);
  4389. fitSection.appendChild(spanFitRadio);
  4390. var table = document.createElement('table');
  4391. table.style.display = 'inline-block';
  4392. var tbody = document.createElement('tbody');
  4393. var row1 = document.createElement('tr');
  4394. var row2 = row1.cloneNode(true);
  4395. var td1 = document.createElement('td');
  4396. var td2 = td1.cloneNode(true);
  4397. var td3 = td1.cloneNode(true);
  4398. var td4 = td1.cloneNode(true);
  4399. var td5 = td1.cloneNode(true);
  4400. var td6 = td1.cloneNode(true);
  4401. td1.style.textAlign = 'right';
  4402. td4.style.textAlign = 'right';
  4403. mxUtils.write(td1, mxResources.get('fitTo'));
  4404. var sheetsAcrossInput = document.createElement('input');
  4405. sheetsAcrossInput.style.cssText = 'margin:0 8px 0 8px;';
  4406. sheetsAcrossInput.setAttribute('value', '1');
  4407. sheetsAcrossInput.setAttribute('min', '1');
  4408. sheetsAcrossInput.setAttribute('type', 'number');
  4409. sheetsAcrossInput.style.width = '40px';
  4410. td2.appendChild(sheetsAcrossInput);
  4411. var span = document.createElement('span');
  4412. mxUtils.write(span, mxResources.get('fitToSheetsAcross'));
  4413. td3.appendChild(span);
  4414. mxUtils.write(td4, mxResources.get('fitToBy'));
  4415. var sheetsDownInput = sheetsAcrossInput.cloneNode(true);
  4416. td5.appendChild(sheetsDownInput);
  4417. mxEvent.addListener(sheetsAcrossInput, 'focus', function()
  4418. {
  4419. fitRadio.checked = true;
  4420. });
  4421. mxEvent.addListener(sheetsDownInput, 'focus', function()
  4422. {
  4423. fitRadio.checked = true;
  4424. });
  4425. var span = document.createElement('span');
  4426. mxUtils.write(span, mxResources.get('fitToSheetsDown'));
  4427. td6.appendChild(span);
  4428. row1.appendChild(td1);
  4429. row1.appendChild(td2);
  4430. row1.appendChild(td3);
  4431. row2.appendChild(td4);
  4432. row2.appendChild(td5);
  4433. row2.appendChild(td6);
  4434. tbody.appendChild(row1);
  4435. tbody.appendChild(row2);
  4436. table.appendChild(tbody);
  4437. fitSection.appendChild(table);
  4438. div.appendChild(fitSection);
  4439. // Page scale ...
  4440. var pageScaleSection = document.createElement('div');
  4441. var span = document.createElement('div');
  4442. span.style.fontWeight = 'bold';
  4443. span.style.marginBottom = '12px';
  4444. mxUtils.write(span, mxResources.get('paperSize'));
  4445. pageScaleSection.appendChild(span);
  4446. var span = document.createElement('div');
  4447. span.style.marginBottom = '12px';
  4448. var accessor = PageSetupDialog.addPageFormatPanel(span, 'printdialog',
  4449. editorUi.editor.graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT);
  4450. pageScaleSection.appendChild(span);
  4451. var span = document.createElement('span');
  4452. mxUtils.write(span, mxResources.get('pageScale'));
  4453. pageScaleSection.appendChild(span);
  4454. var pageScaleInput = document.createElement('input');
  4455. pageScaleInput.style.cssText = 'margin:0 8px 0 8px;';
  4456. pageScaleInput.setAttribute('value', '100 %');
  4457. pageScaleInput.style.width = '60px';
  4458. pageScaleSection.appendChild(pageScaleInput);
  4459. div.appendChild(pageScaleSection);
  4460. // Buttons
  4461. var buttons = document.createElement('div');
  4462. buttons.style.cssText = 'text-align:right;margin:48px 0 0 0;';
  4463. // Overall scale for print-out to account for print borders in dialogs etc
  4464. function preview(print)
  4465. {
  4466. var printScale = parseInt(pageScaleInput.value) / 100;
  4467. if (isNaN(printScale))
  4468. {
  4469. printScale = 1;
  4470. pageScaleInput.value = '100 %';
  4471. }
  4472. // Workaround to match available paper size in actual print output
  4473. printScale *= 0.75;
  4474. function printGraph(thisGraph, pv, forcePageBreaks)
  4475. {
  4476. // Workaround for CSS transforms affecting the print output
  4477. // is to disable during print output and restore after
  4478. var prev = thisGraph.useCssTransforms;
  4479. var prevTranslate = thisGraph.currentTranslate;
  4480. var prevScale = thisGraph.currentScale;
  4481. var prevViewTranslate = thisGraph.view.translate;
  4482. var prevViewScale = thisGraph.view.scale;
  4483. if (thisGraph.useCssTransforms)
  4484. {
  4485. thisGraph.useCssTransforms = false;
  4486. thisGraph.currentTranslate = new mxPoint(0,0);
  4487. thisGraph.currentScale = 1;
  4488. thisGraph.view.translate = new mxPoint(0,0);
  4489. thisGraph.view.scale = 1;
  4490. }
  4491. // Negative coordinates are cropped or shifted if page visible
  4492. var gb = thisGraph.getGraphBounds();
  4493. var border = 0;
  4494. var x0 = 0;
  4495. var y0 = 0;
  4496. var pf = accessor.get();
  4497. var scale = 1 / thisGraph.pageScale;
  4498. var autoOrigin = fitRadio.checked;
  4499. if (autoOrigin)
  4500. {
  4501. var h = parseInt(sheetsAcrossInput.value);
  4502. var v = parseInt(sheetsDownInput.value);
  4503. scale = Math.min((pf.height * v) / (gb.height / thisGraph.view.scale),
  4504. (pf.width * h) / (gb.width / thisGraph.view.scale));
  4505. }
  4506. else
  4507. {
  4508. scale = parseInt(zoomInput.value) / (100 * thisGraph.pageScale);
  4509. if (isNaN(scale))
  4510. {
  4511. printScale = 1 / thisGraph.pageScale;
  4512. zoomInput.value = '100 %';
  4513. }
  4514. }
  4515. // Applies print scale
  4516. pf = mxRectangle.fromRectangle(pf);
  4517. pf.width = Math.ceil(pf.width * printScale);
  4518. pf.height = Math.ceil(pf.height * printScale);
  4519. scale *= printScale;
  4520. // Starts at first visible page
  4521. if (!autoOrigin && thisGraph.pageVisible)
  4522. {
  4523. var layout = thisGraph.getPageLayout();
  4524. x0 -= layout.x * pf.width;
  4525. y0 -= layout.y * pf.height;
  4526. }
  4527. else
  4528. {
  4529. autoOrigin = true;
  4530. }
  4531. if (pv == null)
  4532. {
  4533. pv = PrintDialog.createPrintPreview(thisGraph, scale, pf, border, x0, y0, autoOrigin);
  4534. pv.pageSelector = false;
  4535. pv.mathEnabled = false;
  4536. var file = editorUi.getCurrentFile();
  4537. if (file != null)
  4538. {
  4539. pv.title = file.getTitle();
  4540. }
  4541. var writeHead = pv.writeHead;
  4542. // Overridden to add custom fonts
  4543. pv.writeHead = function(doc)
  4544. {
  4545. writeHead.apply(this, arguments);
  4546. if (editorUi.editor.fontCss != null)
  4547. {
  4548. doc.writeln('<style type="text/css">');
  4549. doc.writeln(editorUi.editor.fontCss);
  4550. doc.writeln('</style>');
  4551. }
  4552. if (thisGraph.extFonts != null)
  4553. {
  4554. for (var i = 0; i < thisGraph.extFonts.length; i++)
  4555. {
  4556. var fontName = thisGraph.extFonts[i].name;
  4557. var fontUrl = thisGraph.extFonts[i].url;
  4558. if (fontUrl.indexOf(Editor.GOOGLE_FONTS) == 0)
  4559. {
  4560. doc.writeln('<link rel="stylesheet" href="' + fontUrl + '" charset="UTF-8" type="text/css">');
  4561. }
  4562. else
  4563. {
  4564. doc.writeln('<style type="text/css">');
  4565. doc.writeln('@font-face {\n' +
  4566. '\tfont-family: "'+ fontName +'";\n' +
  4567. '\tsrc: url("'+ fontUrl +'");\n' +
  4568. '}');
  4569. doc.writeln('</style>');
  4570. }
  4571. }
  4572. }
  4573. };
  4574. if (typeof(MathJax) !== 'undefined')
  4575. {
  4576. // Adds class to ignore if math is disabled
  4577. var printPreviewRenderPage = pv.renderPage;
  4578. pv.renderPage = function(w, h, dx, dy, content, pageNumber)
  4579. {
  4580. var prev = mxClient.NO_FO;
  4581. mxClient.NO_FO = (this.graph.mathEnabled && !editorUi.editor.useForeignObjectForMath) ?
  4582. true : editorUi.editor.originalNoForeignObject;
  4583. var result = printPreviewRenderPage.apply(this, arguments);
  4584. mxClient.NO_FO = prev;
  4585. if (this.graph.mathEnabled)
  4586. {
  4587. this.mathEnabled = this.mathEnabled || true;
  4588. }
  4589. else
  4590. {
  4591. result.className = 'geDisableMathJax';
  4592. }
  4593. return result;
  4594. };
  4595. }
  4596. // Switches stylesheet for print output in dark mode
  4597. var temp = null;
  4598. if (graph.themes != null && graph.defaultThemeName == 'darkTheme')
  4599. {
  4600. temp = graph.stylesheet;
  4601. graph.stylesheet = graph.getDefaultStylesheet()
  4602. graph.refresh();
  4603. }
  4604. // Generates the print output
  4605. pv.open(null, null, forcePageBreaks, true);
  4606. // Restores the stylesheet
  4607. if (temp != null)
  4608. {
  4609. graph.stylesheet = temp;
  4610. graph.refresh();
  4611. }
  4612. }
  4613. else
  4614. {
  4615. var bg = thisGraph.background;
  4616. if (bg == null || bg == '' || bg == mxConstants.NONE)
  4617. {
  4618. bg = '#ffffff';
  4619. }
  4620. pv.backgroundColor = bg;
  4621. pv.autoOrigin = autoOrigin;
  4622. pv.appendGraph(thisGraph, scale, x0, y0, forcePageBreaks, true);
  4623. if (thisGraph.extFonts != null && pv.wnd != null)
  4624. {
  4625. for (var i = 0; i < thisGraph.extFonts.length; i++)
  4626. {
  4627. var fontName = thisGraph.extFonts[i].name;
  4628. var fontUrl = thisGraph.extFonts[i].url;
  4629. if (fontUrl.indexOf(Editor.GOOGLE_FONTS) == 0)
  4630. {
  4631. pv.wnd.document.writeln('<link rel="stylesheet" href="' + fontUrl + '" charset="UTF-8" type="text/css">');
  4632. }
  4633. else
  4634. {
  4635. pv.wnd.document.writeln('<style type="text/css">');
  4636. pv.wnd.document.writeln('@font-face {\n' +
  4637. '\tfont-family: "'+ fontName +'";\n' +
  4638. '\tsrc: url("'+ fontUrl +'");\n' +
  4639. '}');
  4640. pv.wnd.document.writeln('</style>');
  4641. }
  4642. }
  4643. }
  4644. }
  4645. // Restores state if css transforms are used
  4646. if (prev)
  4647. {
  4648. thisGraph.useCssTransforms = prev;
  4649. thisGraph.currentTranslate = prevTranslate;
  4650. thisGraph.currentScale = prevScale;
  4651. thisGraph.view.translate = prevViewTranslate;
  4652. thisGraph.view.scale = prevViewScale;
  4653. }
  4654. return pv;
  4655. };
  4656. var pagesFrom = pagesFromInput.value;
  4657. var pagesTo = pagesToInput.value;
  4658. var ignorePages = !allPagesRadio.checked;
  4659. var pv = null;
  4660. if (ignorePages)
  4661. {
  4662. ignorePages = pagesFrom == currentPage && pagesTo == currentPage;
  4663. }
  4664. if (!ignorePages && editorUi.pages != null && editorUi.pages.length)
  4665. {
  4666. var i0 = 0;
  4667. var imax = editorUi.pages.length - 1;
  4668. if (!allPagesRadio.checked)
  4669. {
  4670. i0 = parseInt(pagesFrom) - 1;
  4671. imax = parseInt(pagesTo) - 1;
  4672. }
  4673. for (var i = i0; i <= imax; i++)
  4674. {
  4675. var page = editorUi.pages[i];
  4676. var tempGraph = (page == editorUi.currentPage) ? graph : null;
  4677. if (tempGraph == null)
  4678. {
  4679. tempGraph = editorUi.createTemporaryGraph(graph.getStylesheet());
  4680. // Restores graph settings that are relevant for printing
  4681. var pageVisible = true;
  4682. var mathEnabled = false;
  4683. var bg = null;
  4684. var bgImage = null;
  4685. if (page.viewState == null)
  4686. {
  4687. // Workaround to extract view state from XML node
  4688. // This changes the state of the page and parses
  4689. // the XML for the graph model even if not needed.
  4690. if (page.root == null)
  4691. {
  4692. editorUi.updatePageRoot(page);
  4693. }
  4694. }
  4695. if (page.viewState != null)
  4696. {
  4697. pageVisible = page.viewState.pageVisible;
  4698. mathEnabled = page.viewState.mathEnabled;
  4699. bg = page.viewState.background;
  4700. bgImage = page.viewState.backgroundImage;
  4701. tempGraph.extFonts = page.viewState.extFonts;
  4702. }
  4703. tempGraph.background = bg;
  4704. tempGraph.backgroundImage = (bgImage != null) ? new mxImage(bgImage.src, bgImage.width, bgImage.height) : null;
  4705. tempGraph.pageVisible = pageVisible;
  4706. tempGraph.mathEnabled = mathEnabled;
  4707. // Redirects placeholders to current page
  4708. var graphGetGlobalVariable = tempGraph.getGlobalVariable;
  4709. tempGraph.getGlobalVariable = function(name)
  4710. {
  4711. if (name == 'page')
  4712. {
  4713. return page.getName();
  4714. }
  4715. else if (name == 'pagenumber')
  4716. {
  4717. return i + 1;
  4718. }
  4719. else if (name == 'pagecount')
  4720. {
  4721. return (editorUi.pages != null) ? editorUi.pages.length : 1;
  4722. }
  4723. return graphGetGlobalVariable.apply(this, arguments);
  4724. };
  4725. document.body.appendChild(tempGraph.container);
  4726. editorUi.updatePageRoot(page);
  4727. tempGraph.model.setRoot(page.root);
  4728. }
  4729. pv = printGraph(tempGraph, pv, i != imax);
  4730. if (tempGraph != graph)
  4731. {
  4732. tempGraph.container.parentNode.removeChild(tempGraph.container);
  4733. }
  4734. }
  4735. }
  4736. else
  4737. {
  4738. pv = printGraph(graph);
  4739. }
  4740. if (pv == null)
  4741. {
  4742. editorUi.handleError({message: mxResources.get('errorUpdatingPreview')});
  4743. }
  4744. else
  4745. {
  4746. if (pv.mathEnabled)
  4747. {
  4748. var doc = pv.wnd.document;
  4749. doc.writeln('<script type="text/x-mathjax-config">');
  4750. doc.writeln('MathJax.Hub.Config({');
  4751. doc.writeln('showMathMenu: false,');
  4752. doc.writeln('messageStyle: "none",');
  4753. doc.writeln('jax: ["input/TeX", "input/MathML", "input/AsciiMath", "output/HTML-CSS"],');
  4754. doc.writeln('extensions: ["tex2jax.js", "mml2jax.js", "asciimath2jax.js"],');
  4755. doc.writeln('"HTML-CSS": {');
  4756. doc.writeln('imageFont: null');
  4757. doc.writeln('},');
  4758. doc.writeln('TeX: {');
  4759. doc.writeln('extensions: ["AMSmath.js", "AMSsymbols.js", "noErrors.js", "noUndefined.js"]');
  4760. doc.writeln('},');
  4761. doc.writeln('tex2jax: {');
  4762. doc.writeln(' ignoreClass: "geDisableMathJax"');
  4763. doc.writeln('},');
  4764. doc.writeln('asciimath2jax: {');
  4765. doc.writeln(' ignoreClass: "geDisableMathJax"');
  4766. doc.writeln('}');
  4767. doc.writeln('});');
  4768. // Adds asynchronous printing when MathJax finished rendering
  4769. if (print)
  4770. {
  4771. doc.writeln('MathJax.Hub.Queue(function () {');
  4772. doc.writeln('window.print();');
  4773. doc.writeln('});');
  4774. }
  4775. doc.writeln('</script>');
  4776. doc.writeln('<script type="text/javascript" src="' + DRAW_MATH_URL + '/MathJax.js"></script>');
  4777. }
  4778. pv.closeDocument();
  4779. if (!pv.mathEnabled && print)
  4780. {
  4781. PrintDialog.printPreview(pv);
  4782. }
  4783. }
  4784. };
  4785. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  4786. {
  4787. editorUi.hideDialog();
  4788. });
  4789. cancelBtn.className = 'geBtn';
  4790. if (editorUi.editor.cancelFirst)
  4791. {
  4792. buttons.appendChild(cancelBtn);
  4793. }
  4794. if (!editorUi.isOffline())
  4795. {
  4796. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  4797. {
  4798. graph.openLink('https://desk.draw.io/support/solutions/articles/16000048947');
  4799. });
  4800. helpBtn.className = 'geBtn';
  4801. buttons.appendChild(helpBtn);
  4802. }
  4803. if (PrintDialog.previewEnabled)
  4804. {
  4805. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  4806. {
  4807. editorUi.hideDialog();
  4808. preview(false);
  4809. });
  4810. previewBtn.className = 'geBtn';
  4811. buttons.appendChild(previewBtn);
  4812. }
  4813. var printBtn = mxUtils.button(mxResources.get((!PrintDialog.previewEnabled) ? 'ok' : 'print'), function()
  4814. {
  4815. editorUi.hideDialog();
  4816. preview(true);
  4817. });
  4818. printBtn.className = 'geBtn gePrimaryBtn';
  4819. buttons.appendChild(printBtn);
  4820. if (!editorUi.editor.cancelFirst)
  4821. {
  4822. buttons.appendChild(cancelBtn);
  4823. }
  4824. div.appendChild(buttons);
  4825. this.container = div;
  4826. };
  4827. // Execute fit page on page setup changes
  4828. var changePageSetupExecute = ChangePageSetup.prototype.execute;
  4829. ChangePageSetup.prototype.execute = function()
  4830. {
  4831. if (this.page == null)
  4832. {
  4833. this.page = this.ui.currentPage;
  4834. }
  4835. // Workaround for redo existing change with different current page
  4836. if (this.page != this.ui.currentPage)
  4837. {
  4838. if (this.page.viewState != null)
  4839. {
  4840. if (!this.ignoreColor)
  4841. {
  4842. this.page.viewState.background = this.color;
  4843. }
  4844. if (!this.ignoreImage)
  4845. {
  4846. this.page.viewState.backgroundImage = this.image;
  4847. }
  4848. if (this.format != null)
  4849. {
  4850. this.page.viewState.pageFormat = this.format;
  4851. }
  4852. if (this.mathEnabled != null)
  4853. {
  4854. this.page.viewState.mathEnabled = this.mathEnabled;
  4855. }
  4856. if (this.shadowVisible != null)
  4857. {
  4858. this.page.viewState.shadowVisible = this.shadowVisible;
  4859. }
  4860. }
  4861. }
  4862. else
  4863. {
  4864. changePageSetupExecute.apply(this, arguments);
  4865. if (this.mathEnabled != null && this.mathEnabled != this.ui.isMathEnabled())
  4866. {
  4867. this.ui.setMathEnabled(this.mathEnabled);
  4868. this.mathEnabled = !this.mathEnabled;
  4869. }
  4870. if (this.shadowVisible != null && this.shadowVisible != this.ui.editor.graph.shadowVisible)
  4871. {
  4872. this.ui.editor.graph.setShadowVisible(this.shadowVisible);
  4873. this.shadowVisible = !this.shadowVisible;
  4874. }
  4875. }
  4876. };
  4877. /**
  4878. * Capability check for canvas export
  4879. */
  4880. Editor.prototype.useCanvasForExport = false;
  4881. try
  4882. {
  4883. var canvas = document.createElement('canvas');
  4884. var img = new Image();
  4885. // LATER: Capability check should not be async
  4886. img.onload = function()
  4887. {
  4888. try
  4889. {
  4890. var ctx = canvas.getContext('2d');
  4891. ctx.drawImage(img, 0, 0);
  4892. // Works in Chrome, Firefox, Edge, Safari and Opera
  4893. var result = canvas.toDataURL('image/png');
  4894. Editor.prototype.useCanvasForExport = result != null && result.length > 6;
  4895. }
  4896. catch (e)
  4897. {
  4898. // ignore
  4899. }
  4900. };
  4901. // Checks if SVG with foreignObject can be exported
  4902. var svg = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1px" height="1px" version="1.1"><foreignObject pointer-events="all" width="1" height="1"><div xmlns="http://www.w3.org/1999/xhtml"></div></foreignObject></svg>';
  4903. img.src = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
  4904. }
  4905. catch (e)
  4906. {
  4907. // ignore
  4908. }
  4909. })();
  4910. // Extends codec for ChangePageSetup
  4911. (function()
  4912. {
  4913. var codec = new mxObjectCodec(new ChangePageSetup(), ['ui', 'previousColor', 'previousImage', 'previousFormat']);
  4914. codec.beforeDecode = function(dec, node, obj)
  4915. {
  4916. obj.ui = dec.ui;
  4917. return node;
  4918. };
  4919. codec.afterDecode = function(dec, node, obj)
  4920. {
  4921. obj.previousColor = obj.color;
  4922. obj.previousImage = obj.image;
  4923. obj.previousFormat = obj.format;
  4924. if (obj.foldingEnabled != null)
  4925. {
  4926. obj.foldingEnabled = !obj.foldingEnabled;
  4927. }
  4928. if (obj.mathEnabled != null)
  4929. {
  4930. obj.mathEnabled = !obj.mathEnabled;
  4931. }
  4932. if (obj.shadowVisible != null)
  4933. {
  4934. obj.shadowVisible = !obj.shadowVisible;
  4935. }
  4936. return obj;
  4937. };
  4938. mxCodecRegistry.register(codec);
  4939. })();