Editor.js 262 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. (function()
  6. {
  7. if (typeof html4 !== 'undefined')
  8. {
  9. /**
  10. * Enables paste from Lucidchart
  11. */
  12. html4.ATTRIBS['span::data-lucid-content'] = 0;
  13. html4.ATTRIBS['span::data-lucid-type'] = 0;
  14. /**
  15. * Enables custom fonts in labels.
  16. */
  17. html4.ATTRIBS['font::data-font-src'] = 0;
  18. }
  19. /**
  20. * Specifies the app name. Default is document.title.
  21. */
  22. Editor.prototype.appName = 'diagrams.net';
  23. /**
  24. * Known file types.
  25. */
  26. Editor.prototype.diagramFileTypes = [
  27. {description: 'diagramXmlDesc', extension: 'drawio', mimeType: 'text/xml'},
  28. {description: 'diagramPngDesc', extension: 'png', mimeType: 'image/png'},
  29. {description: 'diagramSvgDesc', extension: 'svg', mimeType: 'image/svg'},
  30. {description: 'diagramHtmlDesc', extension: 'html', mimeType: 'text/html'},
  31. {description: 'diagramXmlDesc', extension: 'xml', mimeType: 'text/xml'}];
  32. /**
  33. * Known file types.
  34. */
  35. Editor.prototype.libraryFileTypes = [{description: 'Library (.drawiolib, .xml)', extensions: ['drawiolib', 'xml']}];
  36. /**
  37. * Additional help text for special file extensions.
  38. */
  39. Editor.prototype.fileExtensions = [
  40. {ext: 'html', title: 'filetypeHtml'},
  41. {ext: 'png', title: 'filetypePng'},
  42. {ext: 'svg', title: 'filetypeSvg'}];
  43. /**
  44. *
  45. */
  46. Editor.styles = [{},
  47. {commonStyle: {fontColor: '#5C5C5C', strokeColor: '#006658', fillColor: '#21C0A5'}},
  48. {commonStyle: {fontColor: '#095C86', strokeColor: '#AF45ED', fillColor: '#F694C1'},
  49. edgeStyle: {strokeColor: '#60E696'}},
  50. {commonStyle: {fontColor: '#46495D', strokeColor: '#788AA3', fillColor: '#B2C9AB'}},
  51. {commonStyle: {fontColor: '#5AA9E6', strokeColor: '#FF6392', fillColor: '#FFE45E'}},
  52. {commonStyle: {fontColor: '#1D3557', strokeColor: '#457B9D', fillColor: '#A8DADC'},
  53. graph: {background: '#F1FAEE'}},
  54. {commonStyle: {fontColor: '#393C56', strokeColor: '#E07A5F', fillColor: '#F2CC8F'},
  55. graph: {background: '#F4F1DE', gridColor: '#D4D0C0'}},
  56. {commonStyle: {fontColor: '#143642', strokeColor: '#0F8B8D', fillColor: '#FAE5C7'},
  57. edgeStyle: {strokeColor: '#A8201A'},
  58. graph: {background: '#DAD2D8', gridColor: '#ABA4A9'}},
  59. {commonStyle: {fontColor: '#FEFAE0', strokeColor: '#DDA15E', fillColor: '#BC6C25'},
  60. graph: {background: '#283618', gridColor: '#48632C'}},
  61. {commonStyle: {fontColor: '#E4FDE1', strokeColor: '#028090', fillColor: '#F45B69'},
  62. graph: {background: '#114B5F', gridColor: '#0B3240'}},
  63. {},
  64. {vertexStyle: {strokeColor: '#D0CEE2', fillColor: '#FAD9D5'},
  65. edgeStyle: {strokeColor: '#09555B'},
  66. commonStyle: {fontColor: '#1A1A1A'}},
  67. {vertexStyle: {strokeColor: '#BAC8D3', fillColor: '#09555B', fontColor: '#EEEEEE'},
  68. edgeStyle: {strokeColor: '#0B4D6A'}},
  69. {vertexStyle: {strokeColor: '#D0CEE2', fillColor: '#5D7F99'},
  70. edgeStyle: {strokeColor: '#736CA8'},
  71. commonStyle: {fontColor: '#1A1A1A'}},
  72. {vertexStyle: {strokeColor: '#FFFFFF', fillColor: '#182E3E', fontColor: '#FFFFFF'},
  73. edgeStyle: {strokeColor: '#23445D'},
  74. graph: {background: '#FCE7CD', gridColor: '#CFBDA8'}},
  75. {vertexStyle: {strokeColor: '#FFFFFF', fillColor: '#F08E81'},
  76. edgeStyle: {strokeColor: '#182E3E'},
  77. commonStyle: {fontColor: '#1A1A1A'},
  78. graph: {background: '#B0E3E6', gridColor: '#87AEB0'}},
  79. {vertexStyle: {strokeColor: '#909090', fillColor: '#F5AB50'},
  80. edgeStyle: {strokeColor: '#182E3E'},
  81. commonStyle: {fontColor: '#1A1A1A'},
  82. graph: {background: '#EEEEEE'}},
  83. {vertexStyle: {strokeColor: '#EEEEEE', fillColor: '#56517E', fontColor: '#FFFFFF'},
  84. edgeStyle: {strokeColor: '#182E3E'},
  85. graph: {background: '#FAD9D5', gridColor: '#BFA6A3'}},
  86. {vertexStyle: {strokeColor: '#BAC8D3', fillColor: '#B1DDF0', fontColor: '#182E3E'},
  87. edgeStyle: {strokeColor: '#EEEEEE', fontColor: '#FFFFFF'},
  88. graph: {background: '#09555B', gridColor: '#13B4C2'}},
  89. {vertexStyle: {fillColor: '#EEEEEE', fontColor: '#1A1A1A'},
  90. edgeStyle: {fontColor: '#FFFFFF'},
  91. commonStyle: {strokeColor: '#FFFFFF'},
  92. graph: {background: '#182E3E', gridColor: '#4D94C7'}}
  93. ];
  94. /**
  95. *
  96. */
  97. Editor.logoImage = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIKICAgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMzA2LjE4NSAxMjAuMjk2IgogICB2aWV3Qm94PSIyNCAyNiA2OCA2OCIKICAgeT0iMHB4IgogICB4PSIwcHgiCiAgIHZlcnNpb249IjEuMSI+CiAgIAkgPGc+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNDEuMDYxIgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjkiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTUyOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNzUuMDc2IgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjgiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTAwOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGc+PHBhdGgKICAgICAgICAgZD0iTTUyLjc3Myw3Ny4wODRjMCwxLjk1NC0xLjU5OSwzLjU1My0zLjU1MywzLjU1M0gzNi45OTljLTEuOTU0LDAtMy41NTMtMS41OTktMy41NTMtMy41NTN2LTkuMzc5ICAgIGMwLTEuOTU0LDEuNTk5LTMuNTUzLDMuNTUzLTMuNTUzaDEyLjIyMmMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjc3LjA4NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnCiAgICAgICBpZD0iZzM0MTkiPjxwYXRoCiAgICAgICAgIGQ9Ik02Ny43NjIsNDguMDc0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINTEuOTg4Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M0g2NC4yMWMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjQ4LjA3NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnPjxwYXRoCiAgICAgICAgIGQ9Ik04Mi43NTIsNzcuMDg0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINjYuOTc3Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M2gxMi4yMjJjMS45NTQsMCwzLjU1MywxLjU5OSwzLjU1MywzLjU1M1Y3Ny4wODR6IgogICAgICAgICBmaWxsPSIjRkZGRkZGIiAvPjwvZz48L2c+PC9zdmc+';
  98. Editor.saveImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0iYmxhY2siIHdpZHRoPSIxOHB4IiBoZWlnaHQ9IjE4cHgiPjxwYXRoIGQ9Ik0wIDBoMjR2MjRIMHoiIGZpbGw9Im5vbmUiLz48cGF0aCBkPSJNMTkgMTJ2N0g1di03SDN2N2MwIDEuMS45IDIgMiAyaDE0YzEuMSAwIDItLjkgMi0ydi03aC0yem0tNiAuNjdsMi41OS0yLjU4TDE3IDExLjVsLTUgNS01LTUgMS40MS0xLjQxTDExIDEyLjY3VjNoMnoiLz48L3N2Zz4=';
  99. Editor.globeImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTEuOTkgMkM2LjQ3IDIgMiA2LjQ4IDIgMTJzNC40NyAxMCA5Ljk5IDEwQzE3LjUyIDIyIDIyIDE3LjUyIDIyIDEyUzE3LjUyIDIgMTEuOTkgMnptNi45MyA2aC0yLjk1Yy0uMzItMS4yNS0uNzgtMi40NS0xLjM4LTMuNTYgMS44NC42MyAzLjM3IDEuOTEgNC4zMyAzLjU2ek0xMiA0LjA0Yy44MyAxLjIgMS40OCAyLjUzIDEuOTEgMy45NmgtMy44MmMuNDMtMS40MyAxLjA4LTIuNzYgMS45MS0zLjk2ek00LjI2IDE0QzQuMSAxMy4zNiA0IDEyLjY5IDQgMTJzLjEtMS4zNi4yNi0yaDMuMzhjLS4wOC42Ni0uMTQgMS4zMi0uMTQgMiAwIC42OC4wNiAxLjM0LjE0IDJINC4yNnptLjgyIDJoMi45NWMuMzIgMS4yNS43OCAyLjQ1IDEuMzggMy41Ni0xLjg0LS42My0zLjM3LTEuOS00LjMzLTMuNTZ6bTIuOTUtOEg1LjA4Yy45Ni0xLjY2IDIuNDktMi45MyA0LjMzLTMuNTZDOC44MSA1LjU1IDguMzUgNi43NSA4LjAzIDh6TTEyIDE5Ljk2Yy0uODMtMS4yLTEuNDgtMi41My0xLjkxLTMuOTZoMy44MmMtLjQzIDEuNDMtMS4wOCAyLjc2LTEuOTEgMy45NnpNMTQuMzQgMTRIOS42NmMtLjA5LS42Ni0uMTYtMS4zMi0uMTYtMiAwLS42OC4wNy0xLjM1LjE2LTJoNC42OGMuMDkuNjUuMTYgMS4zMi4xNiAyIDAgLjY4LS4wNyAxLjM0LS4xNiAyem0uMjUgNS41NmMuNi0xLjExIDEuMDYtMi4zMSAxLjM4LTMuNTZoMi45NWMtLjk2IDEuNjUtMi40OSAyLjkzLTQuMzMgMy41NnpNMTYuMzYgMTRjLjA4LS42Ni4xNC0xLjMyLjE0LTIgMC0uNjgtLjA2LTEuMzQtLjE0LTJoMy4zOGMuMTYuNjQuMjYgMS4zMS4yNiAycy0uMSAxLjM2LS4yNiAyaC0zLjM4eiIvPjwvc3ZnPg==';
  100. Editor.commentImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMjEuOTkgNGMwLTEuMS0uODktMi0xLjk5LTJINGMtMS4xIDAtMiAuOS0yIDJ2MTJjMCAxLjEuOSAyIDIgMmgxNGw0IDQtLjAxLTE4ek0xOCAxNEg2di0yaDEydjJ6bTAtM0g2VjloMTJ2MnptMC0zSDZWNmgxMnYyeiIvPjxwYXRoIGQ9Ik0wIDBoMjR2MjRIMHoiIGZpbGw9Im5vbmUiLz48L3N2Zz4=';
  101. Editor.userImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTIgMTJjMi4yMSAwIDQtMS43OSA0LTRzLTEuNzktNC00LTQtNCAxLjc5LTQgNCAxLjc5IDQgNCA0em0wIDJjLTIuNjcgMC04IDEuMzQtOCA0djJoMTZ2LTJjMC0yLjY2LTUuMzMtNC04LTR6Ii8+PC9zdmc+';
  102. Editor.shareImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTggMTYuMDhjLS43NiAwLTEuNDQuMy0xLjk2Ljc3TDguOTEgMTIuN2MuMDUtLjIzLjA5LS40Ni4wOS0uN3MtLjA0LS40Ny0uMDktLjdsNy4wNS00LjExYy41NC41IDEuMjUuODEgMi4wNC44MSAxLjY2IDAgMy0xLjM0IDMtM3MtMS4zNC0zLTMtMy0zIDEuMzQtMyAzYzAgLjI0LjA0LjQ3LjA5LjdMOC4wNCA5LjgxQzcuNSA5LjMxIDYuNzkgOSA2IDljLTEuNjYgMC0zIDEuMzQtMyAzczEuMzQgMyAzIDNjLjc5IDAgMS41LS4zMSAyLjA0LS44MWw3LjEyIDQuMTZjLS4wNS4yMS0uMDguNDMtLjA4LjY1IDAgMS42MSAxLjMxIDIuOTIgMi45MiAyLjkyIDEuNjEgMCAyLjkyLTEuMzEgMi45Mi0yLjkycy0xLjMxLTIuOTItMi45Mi0yLjkyeiIvPjwvc3ZnPg==';
  103. Editor.syncImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTIgNFYxTDggNWw0IDRWNmMzLjMxIDAgNiAyLjY5IDYgNiAwIDEuMDEtLjI1IDEuOTctLjcgMi44bDEuNDYgMS40NkMxOS41NCAxNS4wMyAyMCAxMy41NyAyMCAxMmMwLTQuNDItMy41OC04LTgtOHptMCAxNGMtMy4zMSAwLTYtMi42OS02LTYgMC0xLjAxLjI1LTEuOTcuNy0yLjhMNS4yNCA3Ljc0QzQuNDYgOC45NyA0IDEwLjQzIDQgMTJjMCA0LjQyIDMuNTggOCA4IDh2M2w0LTQtNC00djN6Ii8+PC9zdmc+';
  104. Editor.cloudImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iIzAwMDAwMCI+PHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+PHBhdGggZD0iTTEyIDZjMi42MiAwIDQuODggMS44NiA1LjM5IDQuNDNsLjMgMS41IDEuNTMuMTFjMS41Ni4xIDIuNzggMS40MSAyLjc4IDIuOTYgMCAxLjY1LTEuMzUgMy0zIDNINmMtMi4yMSAwLTQtMS43OS00LTQgMC0yLjA1IDEuNTMtMy43NiAzLjU2LTMuOTdsMS4wNy0uMTEuNS0uOTVDOC4wOCA3LjE0IDkuOTQgNiAxMiA2bTAtMkM5LjExIDQgNi42IDUuNjQgNS4zNSA4LjA0IDIuMzQgOC4zNiAwIDEwLjkxIDAgMTRjMCAzLjMxIDIuNjkgNiA2IDZoMTNjMi43NiAwIDUtMi4yNCA1LTUgMC0yLjY0LTIuMDUtNC43OC00LjY1LTQuOTZDMTguNjcgNi41OSAxNS42NCA0IDEyIDR6Ii8+PC9zdmc+';
  105. Editor.cloudOffImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iIzAwMDAwMCI+PHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+PHBhdGggZD0iTTI0IDE1YzAtMi42NC0yLjA1LTQuNzgtNC42NS00Ljk2QzE4LjY3IDYuNTkgMTUuNjQgNCAxMiA0Yy0xLjMzIDAtMi41Ny4zNi0zLjY1Ljk3bDEuNDkgMS40OUMxMC41MSA2LjE3IDExLjIzIDYgMTIgNmMzLjA0IDAgNS41IDIuNDYgNS41IDUuNXYuNUgxOWMxLjY2IDAgMyAxLjM0IDMgMyAwIC45OS0uNDggMS44NS0xLjIxIDIuNGwxLjQxIDEuNDFjMS4wOS0uOTIgMS44LTIuMjcgMS44LTMuODF6TTQuNDEgMy44NkwzIDUuMjdsMi43NyAyLjc3aC0uNDJDMi4zNCA4LjM2IDAgMTAuOTEgMCAxNGMwIDMuMzEgMi42OSA2IDYgNmgxMS43M2wyIDIgMS40MS0xLjQxTDQuNDEgMy44NnpNNiAxOGMtMi4yMSAwLTQtMS43OS00LTRzMS43OS00IDQtNGgxLjczbDggOEg2eiIvPjwvc3ZnPg==';
  106. Editor.calendarImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDI0IDI0IiBoZWlnaHQ9IjI0cHgiIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0cHgiIGZpbGw9IiMwMDAwMDAiPjxnPjxwYXRoIGQ9Ik0wLDBoMjR2MjRIMFYweiIgZmlsbD0ibm9uZSIvPjwvZz48Zz48cGF0aCBkPSJNMjAsNEg0QzIuOSw0LDIsNC45LDIsNnYxMmMwLDEuMSwwLjksMiwyLDJoMTZjMS4xLDAsMi0wLjksMi0yVjZDMjIsNC45LDIxLjEsNCwyMCw0eiBNOCwxMUg0VjZoNFYxMXogTTE0LDExaC00VjZoNFYxMXogTTIwLDExaC00VjZoNFYxMXogTTgsMThINHYtNWg0VjE4eiBNMTQsMThoLTR2LTVoNFYxOHogTTIwLDE4aC00di01aDRWMTh6Ii8+PC9nPjwvc3ZnPg==';
  107. Editor.syncProblemImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMyAxMmMwIDIuMjEuOTEgNC4yIDIuMzYgNS42NEwzIDIwaDZ2LTZsLTIuMjQgMi4yNEM1LjY4IDE1LjE1IDUgMTMuNjYgNSAxMmMwLTIuNjEgMS42Ny00LjgzIDQtNS42NVY0LjI2QzUuNTUgNS4xNSAzIDguMjcgMyAxMnptOCA1aDJ2LTJoLTJ2MnpNMjEgNGgtNnY2bDIuMjQtMi4yNEMxOC4zMiA4Ljg1IDE5IDEwLjM0IDE5IDEyYzAgMi42MS0xLjY3IDQuODMtNCA1LjY1djIuMDljMy40NS0uODkgNi00LjAxIDYtNy43NCAwLTIuMjEtLjkxLTQuMi0yLjM2LTUuNjRMMjEgNHptLTEwIDloMlY3aC0ydjZ6Ii8+PC9zdmc+';
  108. Editor.tailSpin = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9Ii0yIC0yIDQ0IDQ0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogICAgPGRlZnM+CiAgICAgICAgPGxpbmVhckdyYWRpZW50IHgxPSI4LjA0MiUiIHkxPSIwJSIgeDI9IjY1LjY4MiUiIHkyPSIyMy44NjUlIiBpZD0iYSI+CiAgICAgICAgICAgIDxzdG9wIHN0b3AtY29sb3I9IiM4MDgwODAiIHN0b3Atb3BhY2l0eT0iMCIgb2Zmc2V0PSIwJSIvPgogICAgICAgICAgICA8c3RvcCBzdG9wLWNvbG9yPSIjODA4MDgwIiBzdG9wLW9wYWNpdHk9Ii42MzEiIG9mZnNldD0iNjMuMTQ2JSIvPgogICAgICAgICAgICA8c3RvcCBzdG9wLWNvbG9yPSIjODA4MDgwIiBvZmZzZXQ9IjEwMCUiLz4KICAgICAgICA8L2xpbmVhckdyYWRpZW50PgogICAgPC9kZWZzPgogICAgPGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj4KICAgICAgICA8ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgxIDEpIj4KICAgICAgICAgICAgPHBhdGggZD0iTTM2IDE4YzAtOS45NC04LjA2LTE4LTE4LTE4IiBzdHJva2U9InVybCgjYSkiIHN0cm9rZS13aWR0aD0iNiI+CiAgICAgICAgICAgICAgICA8YW5pbWF0ZVRyYW5zZm9ybQogICAgICAgICAgICAgICAgICAgIGF0dHJpYnV0ZU5hbWU9InRyYW5zZm9ybSIKICAgICAgICAgICAgICAgICAgICB0eXBlPSJyb3RhdGUiCiAgICAgICAgICAgICAgICAgICAgZnJvbT0iMCAxOCAxOCIKICAgICAgICAgICAgICAgICAgICB0bz0iMzYwIDE4IDE4IgogICAgICAgICAgICAgICAgICAgIGR1cj0iMC45cyIKICAgICAgICAgICAgICAgICAgICByZXBlYXRDb3VudD0iaW5kZWZpbml0ZSIgLz4KICAgICAgICAgICAgPC9wYXRoPgogICAgICAgICAgICA8Y2lyY2xlIGZpbGw9IiM4MDgwODAiIGN4PSIzNiIgY3k9IjE4IiByPSIxIj4KICAgICAgICAgICAgICAgIDxhbmltYXRlVHJhbnNmb3JtCiAgICAgICAgICAgICAgICAgICAgYXR0cmlidXRlTmFtZT0idHJhbnNmb3JtIgogICAgICAgICAgICAgICAgICAgIHR5cGU9InJvdGF0ZSIKICAgICAgICAgICAgICAgICAgICBmcm9tPSIwIDE4IDE4IgogICAgICAgICAgICAgICAgICAgIHRvPSIzNjAgMTggMTgiCiAgICAgICAgICAgICAgICAgICAgZHVyPSIwLjlzIgogICAgICAgICAgICAgICAgICAgIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiAvPgogICAgICAgICAgICA8L2NpcmNsZT4KICAgICAgICA8L2c+CiAgICA8L2c+Cjwvc3ZnPgo=';
  109. Editor.mailImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iIzAwMDAwMCI+PHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+PHBhdGggZD0iTTIyIDZjMC0xLjEtLjktMi0yLTJINGMtMS4xIDAtMiAuOS0yIDJ2MTJjMCAxLjEuOSAyIDIgMmgxNmMxLjEgMCAyLS45IDItMlY2em0tMiAwbC04IDQuOTlMNCA2aDE2em0wIDEySDRWOGw4IDUgOC01djEweiIvPjwvc3ZnPg==';
  110. Editor.cameraImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMThweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMThweCIgZmlsbD0iIzAwMDAwMCI+PHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+PHBhdGggZD0iTTE0LjEyIDRsMS44MyAySDIwdjEySDRWNmg0LjA1bDEuODMtMmg0LjI0TTE1IDJIOUw3LjE3IDRINGMtMS4xIDAtMiAuOS0yIDJ2MTJjMCAxLjEuOSAyIDIgMmgxNmMxLjEgMCAyLS45IDItMlY2YzAtMS4xLS45LTItMi0yaC0zLjE3TDE1IDJ6bS0zIDdjMS42NSAwIDMgMS4zNSAzIDNzLTEuMzUgMy0zIDMtMy0xLjM1LTMtMyAxLjM1LTMgMy0zbTAtMmMtMi43NiAwLTUgMi4yNC01IDVzMi4yNCA1IDUgNSA1LTIuMjQgNS01LTIuMjQtNS01LTV6Ii8+PC9zdmc+';
  111. Editor.tagsImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDI0IDI0IiBoZWlnaHQ9IjE4cHgiIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjE4cHgiIGZpbGw9IiMwMDAwMDAiPjxnPjxwYXRoIGQ9Ik0wLDBoMjR2MjRIMFYweiIgZmlsbD0ibm9uZSIvPjwvZz48Zz48Zz48cGF0aCBkPSJNMjEuNDEsMTEuNDFsLTguODMtOC44M0MxMi4yMSwyLjIxLDExLjcsMiwxMS4xNywySDRDMi45LDIsMiwyLjksMiw0djcuMTdjMCwwLjUzLDAuMjEsMS4wNCwwLjU5LDEuNDFsOC44Myw4LjgzIGMwLjc4LDAuNzgsMi4wNSwwLjc4LDIuODMsMGw3LjE3LTcuMTdDMjIuMiwxMy40NiwyMi4yLDEyLjIsMjEuNDEsMTEuNDF6IE0xMi44MywyMEw0LDExLjE3VjRoNy4xN0wyMCwxMi44M0wxMi44MywyMHoiLz48Y2lyY2xlIGN4PSI2LjUiIGN5PSI2LjUiIHI9IjEuNSIvPjwvZz48L2c+PC9zdmc+';
  112. Editor.darkModeImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHdpZHRoPSIyNCI+PHBhdGggZD0iTTEyIDIxcS0zLjc1IDAtNi4zNzUtMi42MjVUMyAxMnEwLTMuNzUgMi42MjUtNi4zNzVUMTIgM3EuMzUgMCAuNjg4LjAyNS4zMzcuMDI1LjY2Mi4wNzUtMS4wMjUuNzI1LTEuNjM3IDEuODg3UTExLjEgNi4xNSAxMS4xIDcuNXEwIDIuMjUgMS41NzUgMy44MjVRMTQuMjUgMTIuOSAxNi41IDEyLjlxMS4zNzUgMCAyLjUyNS0uNjEzIDEuMTUtLjYxMiAxLjg3NS0xLjYzNy4wNS4zMjUuMDc1LjY2MlEyMSAxMS42NSAyMSAxMnEwIDMuNzUtMi42MjUgNi4zNzVUMTIgMjFabTAtMnEyLjIgMCAzLjk1LTEuMjEyIDEuNzUtMS4yMTMgMi41NS0zLjE2My0uNS4xMjUtMSAuMi0uNS4wNzUtMSAuMDc1LTMuMDc1IDAtNS4yMzgtMi4xNjJROS4xIDEwLjU3NSA5LjEgNy41cTAtLjUuMDc1LTF0LjItMXEtMS45NS44LTMuMTYyIDIuNTVRNSA5LjggNSAxMnEwIDIuOSAyLjA1IDQuOTVROS4xIDE5IDEyIDE5Wm0tLjI1LTYuNzVaIi8+PC9zdmc+';
  113. Editor.lightModeImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHdpZHRoPSIyNCI+PHBhdGggZD0iTTEyIDE1cTEuMjUgMCAyLjEyNS0uODc1VDE1IDEycTAtMS4yNS0uODc1LTIuMTI1VDEyIDlxLTEuMjUgMC0yLjEyNS44NzVUOSAxMnEwIDEuMjUuODc1IDIuMTI1VDEyIDE1Wm0wIDJxLTIuMDc1IDAtMy41MzctMS40NjNRNyAxNC4wNzUgNyAxMnQxLjQ2My0zLjUzOFE5LjkyNSA3IDEyIDd0My41MzggMS40NjJRMTcgOS45MjUgMTcgMTJxMCAyLjA3NS0xLjQ2MiAzLjUzN1ExNC4wNzUgMTcgMTIgMTdaTTIgMTNxLS40MjUgMC0uNzEyLS4yODhRMSAxMi40MjUgMSAxMnQuMjg4LS43MTNRMS41NzUgMTEgMiAxMWgycS40MjUgMCAuNzEzLjI4N1E1IDExLjU3NSA1IDEydC0uMjg3LjcxMlE0LjQyNSAxMyA0IDEzWm0xOCAwcS0uNDI1IDAtLjcxMi0uMjg4UTE5IDEyLjQyNSAxOSAxMnQuMjg4LS43MTNRMTkuNTc1IDExIDIwIDExaDJxLjQyNSAwIC43MTIuMjg3LjI4OC4yODguMjg4LjcxM3QtLjI4OC43MTJRMjIuNDI1IDEzIDIyIDEzWm0tOC04cS0uNDI1IDAtLjcxMi0uMjg4UTExIDQuNDI1IDExIDRWMnEwLS40MjUuMjg4LS43MTNRMTEuNTc1IDEgMTIgMXQuNzEzLjI4N1ExMyAxLjU3NSAxMyAydjJxMCAuNDI1LS4yODcuNzEyUTEyLjQyNSA1IDEyIDVabTAgMThxLS40MjUgMC0uNzEyLS4yODhRMTEgMjIuNDI1IDExIDIydi0ycTAtLjQyNS4yODgtLjcxMlExMS41NzUgMTkgMTIgMTl0LjcxMy4yODhRMTMgMTkuNTc1IDEzIDIwdjJxMCAuNDI1LS4yODcuNzEyUTEyLjQyNSAyMyAxMiAyM1pNNS42NSA3LjA1IDQuNTc1IDZxLS4zLS4yNzUtLjI4OC0uNy4wMTMtLjQyNS4yODgtLjcyNS4zLS4zLjcyNS0uM3QuNy4zTDcuMDUgNS42NXEuMjc1LjMuMjc1LjcgMCAuNC0uMjc1LjctLjI3NS4zLS42ODcuMjg3LS40MTMtLjAxMi0uNzEzLS4yODdaTTE4IDE5LjQyNWwtMS4wNS0xLjA3NXEtLjI3NS0uMy0uMjc1LS43MTIgMC0uNDEzLjI3NS0uNjg4LjI3NS0uMy42ODgtLjI4Ny40MTIuMDEyLjcxMi4yODdMMTkuNDI1IDE4cS4zLjI3NS4yODguNy0uMDEzLjQyNS0uMjg4LjcyNS0uMy4zLS43MjUuM3QtLjctLjNaTTE2Ljk1IDcuMDVxLS4zLS4yNzUtLjI4Ny0uNjg4LjAxMi0uNDEyLjI4Ny0uNzEyTDE4IDQuNTc1cS4yNzUtLjMuNy0uMjg4LjQyNS4wMTMuNzI1LjI4OC4zLjMuMy43MjV0LS4zLjdMMTguMzUgNy4wNXEtLjMuMjc1LS43LjI3NS0uNCAwLS43LS4yNzVaTTQuNTc1IDE5LjQyNXEtLjMtLjMtLjMtLjcyNXQuMy0uN2wxLjA3NS0xLjA1cS4zLS4yNzUuNzEzLS4yNzUuNDEyIDAgLjY4Ny4yNzUuMy4yNzUuMjg4LjY4OC0uMDEzLjQxMi0uMjg4LjcxMkw2IDE5LjQyNXEtLjI3NS4zLS43LjI4Ny0uNDI1LS4wMTItLjcyNS0uMjg3Wk0xMiAxMloiLz48L3N2Zz4=';
  114. Editor.spinImage = '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==';
  115. Editor.errorImage = 'data:image/gif;base64,R0lGODlhEAAQAPcAAADGAIQAAISEhP8AAP///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////yH5BAEAAAAALAAAAAAQABAAAAhoAAEIFBigYMGBCAkGGMCQ4cGECxtKHBAAYUQCEzFSHLiQgMeGHjEGEAAg4oCQJz86LCkxpEqHAkwyRClxpEyXGmGaREmTIsmOL1GO/DkzI0yOE2sKIMlRJsWhCQHENDiUaVSpS5cmDAgAOw==';
  116. Editor.smallPlusImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MDdCMTdENjVCOEM4MTFFNDlCRjVBNDdCODU5NjNBNUMiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MDdCMTdENjZCOEM4MTFFNDlCRjVBNDdCODU5NjNBNUMiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDowN0IxN0Q2M0I4QzgxMUU0OUJGNUE0N0I4NTk2M0E1QyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDowN0IxN0Q2NEI4QzgxMUU0OUJGNUE0N0I4NTk2M0E1QyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PtjrjmgAAAAtSURBVHjaYvz//z8DMigvLwcLdHZ2MiKLMzEQCaivkLGsrOw/dU0cAr4GCDAARQsQbTFrv10AAAAASUVORK5CYII=';
  117. Editor.hiResImage = '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=';
  118. Editor.loResImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAAA+CAMAAACLMWy1AAAAS1BMVEVAQEAAAAA1NTVBQUFDQ0NDQ0NFRUVERERBQUFBQUFBQUFAQEBBQUFBQUFCQkJCQkJCQkJBQUFCQkJDQ0NDQ0NCQkJCQkJCQkJGRkb5/XqTAAAAGXRSTlP+AAWODlASCsesX+Lc2LyWe3pwa1tCPjohjSJfoAAAAI1JREFUWMPt1MkKhTAMRuG0anvneXr/J71nUypKcdqI/N8yhLMKMZE1CahnClDQzMPB44ED3EgeCubgDWnWQMHpwTtKwTe+UHD4sJ94wbUEHHFGhILlYDeSnsQeabeCgsPBgB0MOZZ9oGA5GJFiJSfUULAfjLjARrhCwX7wh2YCDwVbwZkUBKqFFJRN+wOcwSgR2sREcgAAAABJRU5ErkJggg==';
  119. Editor.blankImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==';
  120. Editor.facebookImage = IMAGE_PATH + '/facebook.png';
  121. Editor.tweetImage = IMAGE_PATH + '/tweet.png';
  122. /**
  123. * Broken image symbol for offline SVG.
  124. */
  125. Editor.svgBrokenImage = Graph.createSvgImage(10, 10, '<rect x="0" y="0" width="10" height="10" stroke="#000" fill="transparent"/><path d="m 0 0 L 10 10 L 0 10 L 10 0" stroke="#000" fill="transparent"/>');
  126. /**
  127. * Error image for not found images
  128. */
  129. /**
  130. * Error image for not found images
  131. */
  132. Editor.configurationKey = '.configuration';
  133. /**
  134. * Error image for not found images
  135. */
  136. Editor.settingsKey = '.drawio-config';
  137. /**
  138. * Default value for custom libraries in mxSettings.
  139. */
  140. Editor.defaultCustomLibraries = [];
  141. /**
  142. * Default value for custom libraries in mxSettings.
  143. */
  144. Editor.enableCustomLibraries = true;
  145. /**
  146. * Specifies if custom properties should be enabled.
  147. */
  148. Editor.enableCustomProperties = true;
  149. /**
  150. * Sets the default value for including a copy of the diagram.
  151. * Default is true.
  152. */
  153. Editor.defaultIncludeDiagram = true;
  154. /**
  155. * Specifies if custom properties should be enabled.
  156. */
  157. Editor.enableServiceWorker = urlParams['pwa'] != '0' &&
  158. 'serviceWorker' in navigator && (urlParams['offline'] == '1' ||
  159. /.*\.diagrams\.net$/.test(window.location.hostname) ||
  160. /.*\.draw\.io$/.test(window.location.hostname));
  161. /**
  162. * Specifies if web fonts are enabled.
  163. */
  164. Editor.enableWebFonts = urlParams['safe-style-src'] != '1';
  165. /**
  166. * Disables the shadow option in the format panel.
  167. */
  168. Editor.enableShadowOption = !mxClient.IS_SF;
  169. /**
  170. * Disables the export URL function.
  171. */
  172. Editor.enableExportUrl = true;
  173. /**
  174. * Disables fast real time collaboration while keeping slower real time collaboration enabled.
  175. */
  176. Editor.enableRealtime = true;
  177. /**
  178. * Specifies if XML files should be compressed. Default is true.
  179. */
  180. Editor.compressXml = true;
  181. /**
  182. * Specifies if XML files should be compressed. Default is true.
  183. */
  184. Editor.oneDriveInlinePicker = (window.urlParams != null && window.urlParams['inlinePicker'] == '0') ? false : true;
  185. /**
  186. * Specifies global variables.
  187. */
  188. Editor.globalVars = null;
  189. /**
  190. * Reference to the config object passed to <configure>.
  191. */
  192. Editor.config = null;
  193. /**
  194. * Reference to the version of the last config object in
  195. * <configure>. If this is different to the last version in
  196. * mxSettings.parse, then the settings are reset.
  197. */
  198. Editor.configVersion = null;
  199. /**
  200. * Default border for image export (to allow for sketch style).
  201. */
  202. Editor.defaultBorder = 5;
  203. /**
  204. * Common properties for all edges.
  205. */
  206. Editor.commonProperties = [
  207. {name: 'enumerate', dispName: 'Enumerate', type: 'bool', defVal: false, onChange: function(graph)
  208. {
  209. graph.refresh();
  210. }},
  211. {name: 'enumerateValue', dispName: 'Enumerate Value', type: 'string', defVal: '', isVisible: function(state, format)
  212. {
  213. return mxUtils.getValue(state.style, 'enumerate', '0') == '1';
  214. }},
  215. {name: 'comic', dispName: 'Comic', type: 'bool', defVal: false, isVisible: function(state, format)
  216. {
  217. return mxUtils.getValue(state.style, 'sketch', '0') != '1';
  218. }},
  219. {name: 'jiggle', dispName: 'Jiggle', type: 'float', min: 0, defVal: 1, isVisible: function(state, format)
  220. {
  221. return mxUtils.getValue(state.style, 'comic', '0') == '1' ||
  222. mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1';
  223. }},
  224. {name: 'fillWeight', dispName: 'Fill Weight', type: 'int', defVal: -1, isVisible: function(state, format)
  225. {
  226. return mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1' &&
  227. state.vertices.length > 0;
  228. }},
  229. {name: 'hachureGap', dispName: 'Hachure Gap', type: 'int', defVal: -1, isVisible: function(state, format)
  230. {
  231. return mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1' &&
  232. state.vertices.length > 0;
  233. }},
  234. {name: 'hachureAngle', dispName: 'Hachure Angle', type: 'int', defVal: -41, isVisible: function(state, format)
  235. {
  236. return mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1' &&
  237. state.vertices.length > 0;
  238. }},
  239. {name: 'curveFitting', dispName: 'Curve Fitting', type: 'float', defVal: 0.95, isVisible: function(state, format)
  240. {
  241. return mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1';
  242. }},
  243. {name: 'simplification', dispName: 'Simplification', type: 'float', defVal: 0, min: 0, max: 1, isVisible: function(state, format)
  244. {
  245. return mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1';
  246. }},
  247. {name: 'disableMultiStroke', dispName: 'Disable Multi Stroke', type: 'bool', defVal: false, isVisible: function(state, format)
  248. {
  249. return mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1';
  250. }},
  251. {name: 'disableMultiStrokeFill', dispName: 'Disable Multi Stroke Fill', type: 'bool', defVal: false, isVisible: function(state, format)
  252. {
  253. return mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1' &&
  254. state.vertices.length > 0;
  255. }},
  256. {name: 'dashOffset', dispName: 'Dash Offset', type: 'int', defVal: -1, isVisible: function(state, format)
  257. {
  258. return mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1' &&
  259. state.vertices.length > 0;
  260. }},
  261. {name: 'dashGap', dispName: 'Dash Gap', type: 'int', defVal: -1, isVisible: function(state, format)
  262. {
  263. return mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1' &&
  264. state.vertices.length > 0;
  265. }},
  266. {name: 'zigzagOffset', dispName: 'ZigZag Offset', type: 'int', defVal: -1, isVisible: function(state, format)
  267. {
  268. return mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1' &&
  269. state.vertices.length > 0;
  270. }},
  271. {name: 'sketchStyle', dispName: 'Sketch Style', type: 'enum', defVal: 'rough',
  272. enumList: [{val: 'rough', dispName: 'Rough'}, {val: 'comic', dispName: 'Comic'}],
  273. isVisible: function(state, format)
  274. {
  275. return mxUtils.getValue(state.style, 'sketch', (urlParams['rough'] == '1') ? '1' : '0') == '1';
  276. }}
  277. ];
  278. /**
  279. * Common properties for all edges.
  280. */
  281. Editor.commonEdgeProperties = [
  282. {type: 'separator'},
  283. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  284. {name: 'sourcePortConstraint', dispName: 'Source Constraint', type: 'enum', defVal: 'none',
  285. enumList: [{val: 'none', dispName: 'None'}, {val: 'north', dispName: 'North'}, {val: 'east', dispName: 'East'}, {val: 'south', dispName: 'South'}, {val: 'west', dispName: 'West'}]
  286. },
  287. {name: 'targetPortConstraint', dispName: 'Target Constraint', type: 'enum', defVal: 'none',
  288. enumList: [{val: 'none', dispName: 'None'}, {val: 'north', dispName: 'North'}, {val: 'east', dispName: 'East'}, {val: 'south', dispName: 'South'}, {val: 'west', dispName: 'West'}]
  289. },
  290. {name: 'jettySize', dispName: 'Jetty Size', type: 'int', min: 0, defVal: 'auto', allowAuto: true, isVisible: function(state)
  291. {
  292. return mxUtils.getValue(state.style, mxConstants.STYLE_EDGE, null) == 'orthogonalEdgeStyle';
  293. }},
  294. {name: 'fillOpacity', dispName: 'Fill Opacity', type: 'int', min: 0, max: 100, defVal: 100},
  295. {name: 'strokeOpacity', dispName: 'Stroke Opacity', type: 'int', min: 0, max: 100, defVal: 100},
  296. {name: 'startFill', dispName: 'Start Fill', type: 'bool', defVal: true},
  297. {name: 'endFill', dispName: 'End Fill', type: 'bool', defVal: true},
  298. {name: 'perimeterSpacing', dispName: 'Terminal Spacing', type: 'float', defVal: 0},
  299. {name: 'anchorPointDirection', dispName: 'Anchor Direction', type: 'bool', defVal: true},
  300. {name: 'snapToPoint', dispName: 'Snap to Point', type: 'bool', defVal: false},
  301. {name: 'fixDash', dispName: 'Fixed Dash', type: 'bool', defVal: false},
  302. {name: 'editable', dispName: 'Editable', type: 'bool', defVal: true},
  303. {name: 'metaEdit', dispName: 'Edit Dialog', type: 'bool', defVal: false},
  304. {name: 'backgroundOutline', dispName: 'Background Outline', type: 'bool', defVal: false},
  305. {name: 'bendable', dispName: 'Bendable', type: 'bool', defVal: true},
  306. {name: 'movable', dispName: 'Movable', type: 'bool', defVal: true},
  307. {name: 'cloneable', dispName: 'Cloneable', type: 'bool', defVal: true},
  308. {name: 'deletable', dispName: 'Deletable', type: 'bool', defVal: true},
  309. {name: 'noJump', dispName: 'No Jumps', type: 'bool', defVal: false},
  310. {name: 'flowAnimation', dispName: 'Flow Animation', type: 'bool', defVal: false},
  311. {name: 'ignoreEdge', dispName: 'Ignore Edge', type: 'bool', defVal: false},
  312. {name: 'orthogonalLoop', dispName: 'Loop Routing', type: 'bool', defVal: false},
  313. {name: 'orthogonal', dispName: 'Orthogonal', type: 'bool', defVal: false}
  314. ].concat(Editor.commonProperties);
  315. /**
  316. * Common properties for all vertices.
  317. */
  318. Editor.commonVertexProperties = [
  319. {name: 'colspan', dispName: 'Colspan', type: 'int', min: 1, defVal: 1, isVisible: function(state, format)
  320. {
  321. var graph = format.editorUi.editor.graph;
  322. return state.vertices.length == 1 && state.edges.length == 0 && graph.isTableCell(state.vertices[0]);
  323. }},
  324. {name: 'rowspan', dispName: 'Rowspan', type: 'int', min: 1, defVal: 1, isVisible: function(state, format)
  325. {
  326. var graph = format.editorUi.editor.graph;
  327. return state.vertices.length == 1 && state.edges.length == 0 && graph.isTableCell(state.vertices[0]);
  328. }},
  329. {type: 'separator'},
  330. {name: 'resizeLastRow', dispName: 'Resize Last Row', type: 'bool', getDefaultValue: function(state, format)
  331. {
  332. var cell = (state.vertices.length == 1 && state.edges.length == 0) ? state.vertices[0] : null;
  333. var graph = format.editorUi.editor.graph;
  334. var style = graph.getCellStyle(cell);
  335. return mxUtils.getValue(style, 'resizeLastRow', '0') == '1';
  336. }, isVisible: function(state, format)
  337. {
  338. var graph = format.editorUi.editor.graph;
  339. return state.vertices.length == 1 && state.edges.length == 0 &&
  340. graph.isTable(state.vertices[0]);
  341. }},
  342. {name: 'resizeLast', dispName: 'Resize Last Column', type: 'bool', getDefaultValue: function(state, format)
  343. {
  344. var cell = (state.vertices.length == 1 && state.edges.length == 0) ? state.vertices[0] : null;
  345. var graph = format.editorUi.editor.graph;
  346. var style = graph.getCellStyle(cell);
  347. return mxUtils.getValue(style, 'resizeLast', '0') == '1';
  348. }, isVisible: function(state, format)
  349. {
  350. var graph = format.editorUi.editor.graph;
  351. return state.vertices.length == 1 && state.edges.length == 0 &&
  352. graph.isTable(state.vertices[0]);
  353. }},
  354. {name: 'fillOpacity', dispName: 'Fill Opacity', type: 'int', min: 0, max: 100, defVal: 100},
  355. {name: 'strokeOpacity', dispName: 'Stroke Opacity', type: 'int', min: 0, max: 100, defVal: 100},
  356. {name: 'overflow', dispName: 'Text Overflow', defVal: 'visible', type: 'enum',
  357. enumList: [{val: 'visible', dispName: 'Visible'}, {val: 'hidden', dispName: 'Hidden'}, {val: 'block', dispName: 'Block'},
  358. {val: 'fill', dispName: 'Fill'}, {val: 'width', dispName: 'Width'}]
  359. },
  360. {name: 'noLabel', dispName: 'Hide Label', type: 'bool', defVal: false},
  361. {name: 'labelPadding', dispName: 'Label Padding', type: 'float', defVal: 0},
  362. {name: 'direction', dispName: 'Direction', type: 'enum', defVal: 'east',
  363. enumList: [{val: 'north', dispName: 'North'}, {val: 'east', dispName: 'East'}, {val: 'south', dispName: 'South'}, {val: 'west', dispName: 'West'}]
  364. },
  365. {name: 'portConstraint', dispName: 'Constraint', type: 'enum', defVal: 'none',
  366. enumList: [{val: 'none', dispName: 'None'}, {val: 'north', dispName: 'North'}, {val: 'east', dispName: 'East'}, {val: 'south', dispName: 'South'}, {val: 'west', dispName: 'West'}]
  367. },
  368. {name: 'portConstraintRotation', dispName: 'Rotate Constraint', type: 'bool', defVal: false},
  369. {name: 'connectable', dispName: 'Connectable', type: 'bool', getDefaultValue: function(state, format)
  370. {
  371. var cell = (state.vertices.length > 0 && state.edges.length == 0) ? state.vertices[0] : null;
  372. var graph = format.editorUi.editor.graph;
  373. return graph.isCellConnectable(cell);
  374. }, isVisible: function(state, format)
  375. {
  376. return state.vertices.length > 0 && state.edges.length == 0;
  377. }},
  378. {name: 'allowArrows', dispName: 'Allow Arrows', type: 'bool', defVal: true},
  379. {name: 'snapToPoint', dispName: 'Snap to Point', type: 'bool', defVal: false},
  380. {name: 'perimeter', dispName: 'Perimeter', defVal: 'none', type: 'enum',
  381. enumList: [{val: 'none', dispName: 'None'},
  382. {val: 'rectanglePerimeter', dispName: 'Rectangle'}, {val: 'ellipsePerimeter', dispName: 'Ellipse'},
  383. {val: 'rhombusPerimeter', dispName: 'Rhombus'}, {val: 'trianglePerimeter', dispName: 'Triangle'},
  384. {val: 'hexagonPerimeter2', dispName: 'Hexagon'}, {val: 'lifelinePerimeter', dispName: 'Lifeline'},
  385. {val: 'orthogonalPerimeter', dispName: 'Orthogonal'}, {val: 'backbonePerimeter', dispName: 'Backbone'},
  386. {val: 'calloutPerimeter', dispName: 'Callout'}, {val: 'parallelogramPerimeter', dispName: 'Parallelogram'},
  387. {val: 'trapezoidPerimeter', dispName: 'Trapezoid'}, {val: 'stepPerimeter', dispName: 'Step'},
  388. {val: 'centerPerimeter', dispName: 'Center'}]
  389. },
  390. {name: 'fixDash', dispName: 'Fixed Dash', type: 'bool', defVal: false},
  391. {name: 'container', dispName: 'Container', type: 'bool', defVal: false, isVisible: function(state, format)
  392. {
  393. return state.vertices.length == 1 && state.edges.length == 0;
  394. }},
  395. {name: 'dropTarget', dispName: 'Drop Target', type: 'bool', getDefaultValue: function(state, format)
  396. {
  397. var cell = (state.vertices.length == 1 && state.edges.length == 0) ? state.vertices[0] : null;
  398. var graph = format.editorUi.editor.graph;
  399. return cell != null && (graph.isSwimlane(cell) || graph.model.getChildCount(cell) > 0);
  400. }, isVisible: function(state, format)
  401. {
  402. return state.vertices.length == 1 && state.edges.length == 0;
  403. }},
  404. {name: 'collapsible', dispName: 'Collapsible', type: 'bool', getDefaultValue: function(state, format)
  405. {
  406. var cell = (state.vertices.length == 1 && state.edges.length == 0) ? state.vertices[0] : null;
  407. var graph = format.editorUi.editor.graph;
  408. return cell != null && ((graph.isContainer(cell) && state.style['collapsible'] != '0') ||
  409. (!graph.isContainer(cell) && state.style['collapsible'] == '1'));
  410. }, isVisible: function(state, format)
  411. {
  412. return state.vertices.length == 1 && state.edges.length == 0;
  413. }},
  414. {name: 'recursiveResize', dispName: 'Resize Children', type: 'bool', defVal: true, isVisible: function(state, format)
  415. {
  416. return state.vertices.length == 1 && state.edges.length == 0 &&
  417. !format.editorUi.editor.graph.isSwimlane(state.vertices[0]) &&
  418. mxUtils.getValue(state.style, 'childLayout', null) == null;
  419. }},
  420. {name: 'expand', dispName: 'Expand', type: 'bool', defVal: true},
  421. {name: 'part', dispName: 'Part', type: 'bool', defVal: false, isVisible: function(state, format)
  422. {
  423. var model = format.editorUi.editor.graph.model;
  424. return (state.vertices.length > 0) ? model.isVertex(model.getParent(state.vertices[0])) : false;
  425. }},
  426. {name: 'editable', dispName: 'Editable', type: 'bool', defVal: true},
  427. {name: 'metaEdit', dispName: 'Edit Dialog', type: 'bool', defVal: false},
  428. {name: 'backgroundOutline', dispName: 'Background Outline', type: 'bool', defVal: false},
  429. {name: 'movable', dispName: 'Movable', type: 'bool', defVal: true},
  430. {name: 'movableLabel', dispName: 'Movable Label', type: 'bool', defVal: false, isVisible: function(state, format)
  431. {
  432. var geo = (state.vertices.length > 0) ? format.editorUi.editor.graph.getCellGeometry(state.vertices[0]) : null;
  433. return geo != null && !geo.relative;
  434. }},
  435. {name: 'autosize', dispName: 'Autosize', type: 'bool', defVal: false},
  436. {name: 'fixedWidth', dispName: 'Fixed Width', type: 'bool', defVal: false},
  437. {name: 'resizable', dispName: 'Resizable', type: 'bool', defVal: true},
  438. {name: 'resizeWidth', dispName: 'Resize Width', type: 'bool', defVal: false},
  439. {name: 'resizeHeight', dispName: 'Resize Height', type: 'bool', defVal: false},
  440. {name: 'rotatable', dispName: 'Rotatable', type: 'bool', defVal: true},
  441. {name: 'cloneable', dispName: 'Cloneable', type: 'bool', defVal: true},
  442. {name: 'deletable', dispName: 'Deletable', type: 'bool', defVal: true},
  443. {name: 'treeFolding', dispName: 'Tree Folding', type: 'bool', defVal: false},
  444. {name: 'treeMoving', dispName: 'Tree Moving', type: 'bool', defVal: false},
  445. {name: 'pointerEvents', dispName: 'Pointer Events', type: 'bool', defVal: true, isVisible: function(state, format)
  446. {
  447. var fillColor = mxUtils.getValue(state.style, mxConstants.STYLE_FILLCOLOR, null);
  448. return format.editorUi.editor.graph.isSwimlane(state.vertices[0]) ||
  449. fillColor == null || fillColor == mxConstants.NONE ||
  450. mxUtils.getValue(state.style, mxConstants.STYLE_FILL_OPACITY, 100) == 0 ||
  451. mxUtils.getValue(state.style, mxConstants.STYLE_OPACITY, 100) == 0 ||
  452. state.style['pointerEvents'] != null;
  453. }},
  454. {name: 'moveCells', dispName: 'Move Cells on Fold', type: 'bool', defVal: false, isVisible: function(state, format)
  455. {
  456. return state.vertices.length > 0 && format.editorUi.editor.graph.isContainer(state.vertices[0]);
  457. }}
  458. ].concat(Editor.commonProperties);
  459. /**
  460. * Default value for the CSV import dialog.
  461. */
  462. Editor.defaultCsvValue = '##\n' +
  463. '## Example CSV import. Use ## for comments and # for configuration. Paste CSV below.\n' +
  464. '## The following names are reserved and should not be used (or ignored):\n' +
  465. '## id, tooltip, placeholder(s), link and label (see below)\n' +
  466. '##\n' +
  467. '#\n' +
  468. '## Node label with placeholders and HTML.\n' +
  469. '## Default is \'%name_of_first_column%\'.\n' +
  470. '#\n' +
  471. '# label: %name%<br><i style="color:gray;">%position%</i><br><a href="mailto:%email%">Email</a>\n' +
  472. '#\n' +
  473. '## Node style (placeholders are replaced once).\n' +
  474. '## Default is the current style for nodes.\n' +
  475. '#\n' +
  476. '# style: label;image=%image%;whiteSpace=wrap;html=1;rounded=1;fillColor=%fill%;strokeColor=%stroke%;\n' +
  477. '#\n' +
  478. '## Parent style for nodes with child nodes (placeholders are replaced once).\n' +
  479. '#\n' +
  480. '# parentstyle: swimlane;whiteSpace=wrap;html=1;childLayout=stackLayout;horizontal=1;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;\n' +
  481. '#\n' +
  482. '## Style to be used for objects not in the CSV. If this is - then such objects are ignored,\n' +
  483. '## else they are created using this as their style, eg. whiteSpace=wrap;html=1;\n' +
  484. '#\n' +
  485. '# unknownStyle: -\n' +
  486. '#\n' +
  487. '## Optional column name that contains a reference to a named style in styles.\n' +
  488. '## Default is the current style for nodes.\n' +
  489. '#\n' +
  490. '# stylename: -\n' +
  491. '#\n' +
  492. '## JSON for named styles of the form {"name": "style", "name": "style"} where style is a cell style with\n' +
  493. '## placeholders that are replaced once.\n' +
  494. '#\n' +
  495. '# styles: -\n' +
  496. '#\n' +
  497. '## JSON for variables in styles of the form {"name": "value", "name": "value"} where name is a string\n' +
  498. '## that will replace a placeholder in a style.\n' +
  499. '#\n' +
  500. '# vars: -\n' +
  501. '#\n' +
  502. '## Optional column name that contains a reference to a named label in labels.\n' +
  503. '## Default is the current label.\n' +
  504. '#\n' +
  505. '# labelname: -\n' +
  506. '#\n' +
  507. '## JSON for named labels of the form {"name": "label", "name": "label"} where label is a cell label with\n' +
  508. '## placeholders.\n' +
  509. '#\n' +
  510. '# labels: -\n' +
  511. '#\n' +
  512. '## Uses the given column name as the identity for cells (updates existing cells).\n' +
  513. '## Default is no identity (empty value or -).\n' +
  514. '#\n' +
  515. '# identity: -\n' +
  516. '#\n' +
  517. '## Uses the given column name as the parent reference for cells. Default is no parent (empty or -).\n' +
  518. '## The identity above is used for resolving the reference so it must be specified.\n' +
  519. '#\n' +
  520. '# parent: -\n' +
  521. '#\n' +
  522. '## Adds a prefix to the identity of cells to make sure they do not collide with existing cells (whose\n' +
  523. '## IDs are numbers from 0..n, sometimes with a GUID prefix in the context of realtime collaboration).\n' +
  524. '## Default is csvimport-.\n' +
  525. '#\n' +
  526. '# namespace: csvimport-\n' +
  527. '#\n' +
  528. '## Connections between rows ("from": source colum, "to": target column).\n' +
  529. '## Label, style and invert are optional. Defaults are \'\', current style and false.\n' +
  530. '## If placeholders are used in the style, they are replaced with data from the source.\n' +
  531. '## An optional placeholders can be set to target to use data from the target instead.\n' +
  532. '## In addition to label, an optional fromlabel and tolabel can be used to name the column\n' +
  533. '## that contains the text for the label in the edges source or target (invert ignored).\n' +
  534. '## In addition to those, an optional source and targetlabel can be used to specify a label\n' +
  535. '## that contains placeholders referencing the respective columns in the source or target row.\n' +
  536. '## The label is created in the form fromlabel + sourcelabel + label + tolabel + targetlabel.\n' +
  537. '## Additional labels can be added by using an optional labels array with entries of the\n' +
  538. '## form {"label": string, "x": number, "y": number, "dx": number, "dy": number} where\n' +
  539. '## x is from -1 to 1 along the edge, y is orthogonal, and dx/dy are offsets in pixels.\n' +
  540. '## An optional placeholders with the string value "source" or "target" can be specified\n' +
  541. '## to replace placeholders in the additional label with data from the source or target.\n' +
  542. '## The target column may contain a comma-separated list of values.\n' +
  543. '## Multiple connect entries are allowed.\n' +
  544. '#\n' +
  545. '# connect: {"from": "manager", "to": "name", "invert": true, "label": "manages", \\\n' +
  546. '# "style": "curved=1;endArrow=blockThin;endFill=1;fontSize=11;"}\n' +
  547. '# connect: {"from": "refs", "to": "id", "style": "curved=1;fontSize=11;"}\n' +
  548. '#\n' +
  549. '## Node x-coordinate. Possible value is a column name. Default is empty. Layouts will\n' +
  550. '## override this value.\n' +
  551. '#\n' +
  552. '# left: \n' +
  553. '#\n' +
  554. '## Node y-coordinate. Possible value is a column name. Default is empty. Layouts will\n' +
  555. '## override this value.\n' +
  556. '#\n' +
  557. '# top: \n' +
  558. '#\n' +
  559. '## Node width. Possible value is a number (in px), auto or an @ sign followed by a column\n' +
  560. '## name that contains the value for the width. Default is auto.\n' +
  561. '#\n' +
  562. '# width: auto\n' +
  563. '#\n' +
  564. '## Node height. Possible value is a number (in px), auto or an @ sign followed by a column\n' +
  565. '## name that contains the value for the height. Default is auto.\n' +
  566. '#\n' +
  567. '# height: auto\n' +
  568. '#\n' +
  569. '## Collapsed state for vertices. Possible values are true or false. Default is false.\n' +
  570. '#\n' +
  571. '# collapsed: false\n' +
  572. '#\n' +
  573. '## Padding for autosize. Default is 0.\n' +
  574. '#\n' +
  575. '# padding: -12\n' +
  576. '#\n' +
  577. '## Comma-separated list of ignored columns for metadata. (These can be\n' +
  578. '## used for connections and styles but will not be added as metadata.)\n' +
  579. '#\n' +
  580. '# ignore: id,image,fill,stroke,refs,manager\n' +
  581. '#\n' +
  582. '## Column to be renamed to link attribute (used as link).\n' +
  583. '#\n' +
  584. '# link: url\n' +
  585. '#\n' +
  586. '## Spacing between nodes. Default is 40.\n' +
  587. '#\n' +
  588. '# nodespacing: 40\n' +
  589. '#\n' +
  590. '## Spacing between levels of hierarchical layouts. Default is 100.\n' +
  591. '#\n' +
  592. '# levelspacing: 100\n' +
  593. '#\n' +
  594. '## Spacing between parallel edges. Default is 40. Use 0 to disable.\n' +
  595. '#\n' +
  596. '# edgespacing: 40\n' +
  597. '#\n' +
  598. '## Name or JSON of layout. Possible values are auto, none, verticaltree, horizontaltree,\n' +
  599. '## verticalflow, horizontalflow, organic, circle, orgchart or a JSON string as used in\n' +
  600. '## Layout, Apply. Default is auto.\n' +
  601. '#\n' +
  602. '# layout: auto\n' +
  603. '#\n' +
  604. '## ---- CSV below this line. First line are column names. ----\n' +
  605. 'name,position,id,location,manager,email,fill,stroke,refs,url,image\n' +
  606. 'Tessa 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-3-128.png\n' +
  607. 'Edward Morrison,Brand Manager,emo,Office 2,Tessa 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' +
  608. 'Alison Donovan,System Admin,rdo,Office 3,Tessa 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' +
  609. 'Evan Valet,HR Director,tva,Office 4,Tessa Miller,me@example.com,#d5e8d4,#82b366,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-9-2-128.png\n';
  610. /**
  611. * Compresses the given string.
  612. */
  613. Editor.createRoughCanvas = function(c)
  614. {
  615. var rc = rough.canvas(
  616. {
  617. // Provides expected function but return value is not used
  618. getContext: function()
  619. {
  620. return c;
  621. }
  622. });
  623. rc.draw = function(drawable)
  624. {
  625. var sets = drawable.sets || [];
  626. var o = drawable.options || this.getDefaultOptions();
  627. for (var i = 0; i < sets.length; i++)
  628. {
  629. var drawing = sets[i];
  630. switch (drawing.type)
  631. {
  632. case 'path':
  633. if (o.stroke != null)
  634. {
  635. this._drawToContext(c, drawing, o);
  636. }
  637. break;
  638. case 'fillPath':
  639. this._drawToContext(c, drawing, o);
  640. break;
  641. case 'fillSketch':
  642. this.fillSketch(c, drawing, o);
  643. break;
  644. }
  645. }
  646. };
  647. rc.fillSketch = function(ctx, drawing, o)
  648. {
  649. var strokeColor = c.state.strokeColor;
  650. var strokeWidth = c.state.strokeWidth;
  651. var strokeAlpha = c.state.strokeAlpha;
  652. var dashed = c.state.dashed;
  653. var fweight = o.fillWeight;
  654. if (fweight < 0)
  655. {
  656. fweight = o.strokeWidth / 2;
  657. }
  658. c.setStrokeAlpha(c.state.fillAlpha);
  659. c.setStrokeColor(o.fill || '');
  660. c.setStrokeWidth(fweight);
  661. c.setDashed(false);
  662. this._drawToContext(ctx, drawing, o);
  663. c.setDashed(dashed);
  664. c.setStrokeWidth(strokeWidth);
  665. c.setStrokeColor(strokeColor);
  666. c.setStrokeAlpha(strokeAlpha);
  667. };
  668. rc._drawToContext = function(ctx, drawing, o)
  669. {
  670. ctx.begin();
  671. for (var i = 0; i < drawing.ops.length; i++)
  672. {
  673. var item = drawing.ops[i];
  674. var data = item.data;
  675. switch (item.op)
  676. {
  677. case 'move':
  678. ctx.moveTo(data[0], data[1]);
  679. break;
  680. case 'bcurveTo':
  681. ctx.curveTo(data[0], data[1], data[2], data[3], data[4], data[5]);
  682. break;
  683. case 'lineTo':
  684. ctx.lineTo(data[0], data[1]);
  685. break;
  686. }
  687. };
  688. ctx.end();
  689. if (drawing.type === 'fillPath' && o.filled)
  690. {
  691. ctx.fill();
  692. }
  693. else
  694. {
  695. ctx.stroke();
  696. }
  697. };
  698. return rc;
  699. };
  700. /**
  701. * Uses RoughJs for drawing comic shapes.
  702. */
  703. (function()
  704. {
  705. /**
  706. * Adds handJiggle style (jiggle=n sets jiggle)
  707. */
  708. function RoughCanvas(canvas, rc, shape)
  709. {
  710. this.canvas = canvas;
  711. this.rc = rc;
  712. this.shape = shape;
  713. // Avoids "spikes" in the output
  714. this.canvas.setLineJoin('round');
  715. this.canvas.setLineCap('round');
  716. this.originalBegin = this.canvas.begin;
  717. this.canvas.begin = mxUtils.bind(this, RoughCanvas.prototype.begin);
  718. this.originalEnd = this.canvas.end;
  719. this.canvas.end = mxUtils.bind(this, RoughCanvas.prototype.end);
  720. this.originalRect = this.canvas.rect;
  721. this.canvas.rect = mxUtils.bind(this, RoughCanvas.prototype.rect);
  722. this.originalRoundrect = this.canvas.roundrect;
  723. this.canvas.roundrect = mxUtils.bind(this, RoughCanvas.prototype.roundrect);
  724. this.originalEllipse = this.canvas.ellipse;
  725. this.canvas.ellipse = mxUtils.bind(this, RoughCanvas.prototype.ellipse);
  726. this.originalLineTo = this.canvas.lineTo;
  727. this.canvas.lineTo = mxUtils.bind(this, RoughCanvas.prototype.lineTo);
  728. this.originalMoveTo = this.canvas.moveTo;
  729. this.canvas.moveTo = mxUtils.bind(this, RoughCanvas.prototype.moveTo);
  730. this.originalQuadTo = this.canvas.quadTo;
  731. this.canvas.quadTo = mxUtils.bind(this, RoughCanvas.prototype.quadTo);
  732. this.originalCurveTo = this.canvas.curveTo;
  733. this.canvas.curveTo = mxUtils.bind(this, RoughCanvas.prototype.curveTo);
  734. this.originalArcTo = this.canvas.arcTo;
  735. this.canvas.arcTo = mxUtils.bind(this, RoughCanvas.prototype.arcTo);
  736. this.originalClose = this.canvas.close;
  737. this.canvas.close = mxUtils.bind(this, RoughCanvas.prototype.close);
  738. this.originalFill = this.canvas.fill;
  739. this.canvas.fill = mxUtils.bind(this, RoughCanvas.prototype.fill);
  740. this.originalStroke = this.canvas.stroke;
  741. this.canvas.stroke = mxUtils.bind(this, RoughCanvas.prototype.stroke);
  742. this.originalFillAndStroke = this.canvas.fillAndStroke;
  743. this.canvas.fillAndStroke = mxUtils.bind(this, RoughCanvas.prototype.fillAndStroke);
  744. this.path = [];
  745. this.passThrough = false;
  746. };
  747. RoughCanvas.prototype.moveOp = 'M';
  748. RoughCanvas.prototype.lineOp = 'L';
  749. RoughCanvas.prototype.quadOp = 'Q';
  750. RoughCanvas.prototype.curveOp = 'C';
  751. RoughCanvas.prototype.closeOp = 'Z';
  752. RoughCanvas.prototype.getStyle = function(stroke, fill)
  753. {
  754. // Random seed created from cell ID
  755. var seed = 1;
  756. if (this.shape.state != null)
  757. {
  758. var str = this.shape.state.cell.id;
  759. if (str != null)
  760. {
  761. for (var i = 0; i < str.length; i++)
  762. {
  763. seed = ((seed << 5) - seed + str.charCodeAt(i)) << 0;
  764. }
  765. }
  766. }
  767. var style = {strokeWidth: this.canvas.state.strokeWidth, seed: seed, preserveVertices: true};
  768. var defs = this.rc.getDefaultOptions();
  769. if (stroke)
  770. {
  771. style.stroke = this.canvas.state.strokeColor === mxConstants.NONE ?
  772. 'transparent' : this.canvas.state.strokeColor;
  773. }
  774. else
  775. {
  776. style.stroke = mxConstants.NONE;
  777. }
  778. var gradient = null;
  779. style.filled = fill;
  780. if (fill)
  781. {
  782. style.fill = this.canvas.state.fillColor === mxConstants.NONE ?
  783. '' : this.canvas.state.fillColor;
  784. gradient = this.canvas.state.gradientColor === mxConstants.NONE ?
  785. null : this.canvas.state.gradientColor;
  786. }
  787. else
  788. {
  789. style.fill = '';
  790. }
  791. // Applies cell style
  792. style['bowing'] = mxUtils.getValue(this.shape.style, 'bowing', defs['bowing']);
  793. style['hachureAngle'] = mxUtils.getValue(this.shape.style, 'hachureAngle', defs['hachureAngle']);
  794. style['curveFitting'] = mxUtils.getValue(this.shape.style, 'curveFitting', defs['curveFitting']);
  795. style['roughness'] = mxUtils.getValue(this.shape.style, 'jiggle', defs['roughness']);
  796. style['simplification'] = mxUtils.getValue(this.shape.style, 'simplification', defs['simplification']);
  797. style['disableMultiStroke'] = mxUtils.getValue(this.shape.style, 'disableMultiStroke', defs['disableMultiStroke']);
  798. style['disableMultiStrokeFill'] = mxUtils.getValue(this.shape.style, 'disableMultiStrokeFill', defs['disableMultiStrokeFill']);
  799. var hachureGap = mxUtils.getValue(this.shape.style, 'hachureGap', -1);
  800. style['hachureGap'] = (hachureGap == 'auto') ? -1 : hachureGap;
  801. style['dashGap'] = mxUtils.getValue(this.shape.style, 'dashGap', hachureGap);
  802. style['dashOffset'] = mxUtils.getValue(this.shape.style, 'dashOffset', hachureGap);
  803. style['zigzagOffset'] = mxUtils.getValue(this.shape.style, 'zigzagOffset', hachureGap);
  804. var fillWeight = mxUtils.getValue(this.shape.style, 'fillWeight', -1);
  805. style['fillWeight'] = (fillWeight == 'auto') ? -1 : fillWeight;
  806. var fillStyle = mxUtils.getValue(this.shape.style, 'fillStyle', 'auto');
  807. if (fillStyle == 'auto')
  808. {
  809. var bg = mxUtils.hex2rgb((this.shape.state != null) ?
  810. this.shape.state.view.graph.shapeBackgroundColor :
  811. (Editor.isDarkMode() ? Editor.darkColor : '#ffffff'));
  812. fillStyle = (style.fill != null && (gradient != null || (bg != null &&
  813. style.fill == bg))) ? 'solid' : defs['fillStyle'];
  814. }
  815. style['fillStyle'] = fillStyle;
  816. return style;
  817. };
  818. RoughCanvas.prototype.begin = function()
  819. {
  820. if (this.passThrough)
  821. {
  822. this.originalBegin.apply(this.canvas, arguments);
  823. }
  824. else
  825. {
  826. this.path = [];
  827. }
  828. };
  829. RoughCanvas.prototype.end = function()
  830. {
  831. if (this.passThrough)
  832. {
  833. this.originalEnd.apply(this.canvas, arguments);
  834. }
  835. else
  836. {
  837. // do nothing
  838. }
  839. };
  840. RoughCanvas.prototype.addOp = function()
  841. {
  842. if (this.path != null)
  843. {
  844. this.path.push(arguments[0]);
  845. if (arguments.length > 2)
  846. {
  847. var s = this.canvas.state;
  848. for (var i = 2; i < arguments.length; i += 2)
  849. {
  850. this.lastX = arguments[i - 1];
  851. this.lastY = arguments[i];
  852. this.path.push(this.canvas.format((this.lastX)));
  853. this.path.push(this.canvas.format((this.lastY)));
  854. }
  855. }
  856. }
  857. };
  858. RoughCanvas.prototype.lineTo = function(endX, endY)
  859. {
  860. if (this.passThrough)
  861. {
  862. this.originalLineTo.apply(this.canvas, arguments);
  863. }
  864. else
  865. {
  866. this.addOp(this.lineOp, endX, endY);
  867. this.lastX = endX;
  868. this.lastY = endY;
  869. }
  870. };
  871. RoughCanvas.prototype.moveTo = function(endX, endY)
  872. {
  873. if (this.passThrough)
  874. {
  875. this.originalMoveTo.apply(this.canvas, arguments);
  876. }
  877. else
  878. {
  879. this.addOp(this.moveOp, endX, endY);
  880. this.lastX = endX;
  881. this.lastY = endY;
  882. this.firstX = endX;
  883. this.firstY = endY;
  884. }
  885. };
  886. RoughCanvas.prototype.close = function()
  887. {
  888. if (this.passThrough)
  889. {
  890. this.originalClose.apply(this.canvas, arguments);
  891. }
  892. else
  893. {
  894. this.addOp(this.closeOp);
  895. }
  896. };
  897. RoughCanvas.prototype.quadTo = function(x1, y1, x2, y2)
  898. {
  899. if (this.passThrough)
  900. {
  901. this.originalQuadTo.apply(this.canvas, arguments);
  902. }
  903. else
  904. {
  905. this.addOp(this.quadOp, x1, y1, x2, y2);
  906. this.lastX = x2;
  907. this.lastY = y2;
  908. }
  909. };
  910. RoughCanvas.prototype.curveTo = function(x1, y1, x2, y2, x3, y3)
  911. {
  912. if (this.passThrough)
  913. {
  914. this.originalCurveTo.apply(this.canvas, arguments);
  915. }
  916. else
  917. {
  918. this.addOp(this.curveOp, x1, y1, x2, y2, x3, y3);
  919. this.lastX = x3;
  920. this.lastY = y3;
  921. }
  922. };
  923. RoughCanvas.prototype.arcTo = function(rx, ry, angle, largeArcFlag, sweepFlag, x, y)
  924. {
  925. if (this.passThrough)
  926. {
  927. this.originalArcTo.apply(this.canvas, arguments);
  928. }
  929. else
  930. {
  931. var curves = mxUtils.arcToCurves(this.lastX, this.lastY, rx, ry, angle, largeArcFlag, sweepFlag, x, y);
  932. if (curves != null)
  933. {
  934. for (var i = 0; i < curves.length; i += 6)
  935. {
  936. this.curveTo(curves[i], curves[i + 1], curves[i + 2],
  937. curves[i + 3], curves[i + 4], curves[i + 5]);
  938. }
  939. }
  940. this.lastX = x;
  941. this.lastY = y;
  942. }
  943. };
  944. RoughCanvas.prototype.rect = function(x, y, w, h)
  945. {
  946. if (this.passThrough)
  947. {
  948. this.originalRect.apply(this.canvas, arguments);
  949. }
  950. else
  951. {
  952. this.path = [];
  953. this.nextShape = this.rc.generator.rectangle(x, y, w, h, this.getStyle(true, true));
  954. }
  955. };
  956. RoughCanvas.prototype.ellipse = function(x, y, w, h)
  957. {
  958. if (this.passThrough)
  959. {
  960. this.originalEllipse.apply(this.canvas, arguments);
  961. }
  962. else
  963. {
  964. this.path = [];
  965. this.nextShape = this.rc.generator.ellipse(x + w / 2, y + h / 2, w, h, this.getStyle(true, true));
  966. }
  967. };
  968. RoughCanvas.prototype.roundrect = function(x, y, w, h, dx, dy)
  969. {
  970. if (this.passThrough)
  971. {
  972. this.originalRoundrect.apply(this.canvas, arguments);
  973. }
  974. else
  975. {
  976. this.begin();
  977. this.moveTo(x + dx, y);
  978. this.lineTo(x + w - dx, y);
  979. this.quadTo(x + w, y, x + w, y + dy);
  980. this.lineTo(x + w, y + h - dy);
  981. this.quadTo(x + w, y + h, x + w - dx, y + h);
  982. this.lineTo(x + dx, y + h);
  983. this.quadTo(x, y + h, x, y + h - dy);
  984. this.lineTo(x, y + dy);
  985. this.quadTo(x, y, x + dx, y);
  986. }
  987. };
  988. RoughCanvas.prototype.drawPath = function(style)
  989. {
  990. if (this.path.length > 0)
  991. {
  992. this.passThrough = true;
  993. try
  994. {
  995. this.rc.path(this.path.join(' '), style);
  996. }
  997. catch (e)
  998. {
  999. // ignore
  1000. }
  1001. this.passThrough = false;
  1002. }
  1003. else if (this.nextShape != null)
  1004. {
  1005. for (var key in style)
  1006. {
  1007. this.nextShape.options[key] = style[key];
  1008. }
  1009. if (style['stroke'] == mxConstants.NONE ||
  1010. style['stroke'] == null)
  1011. {
  1012. delete this.nextShape.options['stroke'];
  1013. }
  1014. if (!style.filled)
  1015. {
  1016. delete this.nextShape.options['fill'];
  1017. }
  1018. this.passThrough = true;
  1019. this.rc.draw(this.nextShape);
  1020. this.passThrough = false;
  1021. }
  1022. };
  1023. RoughCanvas.prototype.stroke = function()
  1024. {
  1025. if (this.passThrough)
  1026. {
  1027. this.originalStroke.apply(this.canvas, arguments);
  1028. }
  1029. else
  1030. {
  1031. this.drawPath(this.getStyle(true, false));
  1032. }
  1033. };
  1034. RoughCanvas.prototype.fill = function()
  1035. {
  1036. if (this.passThrough)
  1037. {
  1038. this.originalFill.apply(this.canvas, arguments);
  1039. }
  1040. else
  1041. {
  1042. this.drawPath(this.getStyle(false, true));
  1043. }
  1044. };
  1045. RoughCanvas.prototype.fillAndStroke = function()
  1046. {
  1047. if (this.passThrough)
  1048. {
  1049. this.originalFillAndStroke.apply(this.canvas, arguments);
  1050. }
  1051. else
  1052. {
  1053. this.drawPath(this.getStyle(true, true));
  1054. }
  1055. };
  1056. RoughCanvas.prototype.destroy = function()
  1057. {
  1058. this.canvas.lineTo = this.originalLineTo;
  1059. this.canvas.moveTo = this.originalMoveTo;
  1060. this.canvas.close = this.originalClose;
  1061. this.canvas.quadTo = this.originalQuadTo;
  1062. this.canvas.curveTo = this.originalCurveTo;
  1063. this.canvas.arcTo = this.originalArcTo;
  1064. this.canvas.close = this.originalClose;
  1065. this.canvas.fill = this.originalFill;
  1066. this.canvas.stroke = this.originalStroke;
  1067. this.canvas.fillAndStroke = this.originalFillAndStroke;
  1068. this.canvas.begin = this.originalBegin;
  1069. this.canvas.end = this.originalEnd;
  1070. this.canvas.rect = this.originalRect;
  1071. this.canvas.ellipse = this.originalEllipse;
  1072. this.canvas.roundrect = this.originalRoundrect;
  1073. };
  1074. // Returns a new HandJiggle canvas
  1075. mxShape.prototype.createRoughCanvas = function(c)
  1076. {
  1077. return new RoughCanvas(c, Editor.createRoughCanvas(c), this);
  1078. };
  1079. // Overrides to include sketch style
  1080. var shapeCreateHandJiggle = mxShape.prototype.createHandJiggle;
  1081. mxShape.prototype.createHandJiggle = function(c)
  1082. {
  1083. if (!this.outline && this.style != null &&
  1084. mxUtils.getValue(this.style, 'sketch', '0') != '0')
  1085. {
  1086. if (mxUtils.getValue(this.style, 'sketchStyle', 'rough') == 'comic')
  1087. {
  1088. return this.createComicCanvas(c);
  1089. }
  1090. else
  1091. {
  1092. return this.createRoughCanvas(c);
  1093. }
  1094. }
  1095. else
  1096. {
  1097. return shapeCreateHandJiggle.apply(this, arguments);
  1098. }
  1099. };
  1100. // Avoids duplicate painting of images
  1101. var imageShapePaintVertexShape = mxImageShape.prototype.paintVertexShape;
  1102. mxImageShape.prototype.paintVertexShape = function(c, x, y, w, h)
  1103. {
  1104. if (c.handJiggle == null || !c.handJiggle.passThrough)
  1105. {
  1106. imageShapePaintVertexShape.apply(this, arguments);
  1107. }
  1108. };
  1109. // Overrides for event handling on transparent background for sketch style
  1110. var shapePaint = mxShape.prototype.paint;
  1111. mxShape.prototype.paint = function(c)
  1112. {
  1113. var addTolerance = c.addTolerance;
  1114. var events = true;
  1115. if (this.style != null)
  1116. {
  1117. events = mxUtils.getValue(this.style, mxConstants.STYLE_POINTER_EVENTS, '1') == '1';
  1118. }
  1119. if (c.handJiggle != null && c.handJiggle.constructor == RoughCanvas && !this.outline)
  1120. {
  1121. // Save needed for possible transforms applied during paint
  1122. c.save();
  1123. var fill = this.fill;
  1124. var stroke = this.stroke;
  1125. this.fill = null;
  1126. this.stroke = null;
  1127. var configurePointerEvents = this.configurePointerEvents;
  1128. // Ignores color changes during paint
  1129. var setStrokeColor = c.setStrokeColor;
  1130. c.setStrokeColor = function()
  1131. {
  1132. // ignore
  1133. };
  1134. var setFillColor = c.setFillColor;
  1135. c.setFillColor = function()
  1136. {
  1137. // ignore
  1138. };
  1139. // Adds stroke tolerance for plain rendering if filled
  1140. if (!events && fill != null)
  1141. {
  1142. this.configurePointerEvents = function()
  1143. {
  1144. // ignore
  1145. };
  1146. }
  1147. c.handJiggle.passThrough = true;
  1148. shapePaint.apply(this, arguments);
  1149. c.handJiggle.passThrough = false;
  1150. c.setFillColor = setFillColor;
  1151. c.setStrokeColor = setStrokeColor;
  1152. this.configurePointerEvents = configurePointerEvents;
  1153. this.stroke = stroke;
  1154. this.fill = fill;
  1155. c.restore();
  1156. // Bypasses stroke tolerance for sketched rendering if filled
  1157. if (events && fill != null)
  1158. {
  1159. c.addTolerance = function()
  1160. {
  1161. // ignore
  1162. };
  1163. }
  1164. }
  1165. shapePaint.apply(this, arguments);
  1166. c.addTolerance = addTolerance;
  1167. };
  1168. // Overrides glass effect to disable sketch style
  1169. var shapePaintGlassEffect = mxShape.prototype.paintGlassEffect;
  1170. mxShape.prototype.paintGlassEffect = function(c, x, y, w, h, arc)
  1171. {
  1172. if (c.handJiggle != null && c.handJiggle.constructor == RoughCanvas)
  1173. {
  1174. c.handJiggle.passThrough = true;
  1175. shapePaintGlassEffect.apply(this, arguments);
  1176. c.handJiggle.passThrough = false;
  1177. }
  1178. else
  1179. {
  1180. shapePaintGlassEffect.apply(this, arguments);
  1181. }
  1182. };
  1183. })();
  1184. /**
  1185. * Compresses the given string.
  1186. */
  1187. Editor.fastCompress = function(data)
  1188. {
  1189. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  1190. {
  1191. return data;
  1192. }
  1193. else
  1194. {
  1195. return Graph.arrayBufferToString(pako.deflateRaw(data));
  1196. }
  1197. };
  1198. /**
  1199. * Decompresses the given string.
  1200. */
  1201. Editor.fastDecompress = function(data)
  1202. {
  1203. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  1204. {
  1205. return data;
  1206. }
  1207. else
  1208. {
  1209. return pako.inflateRaw(Graph.stringToArrayBuffer(atob(data)), {to: 'string'});
  1210. }
  1211. };
  1212. /**
  1213. * Helper function to extract the graph model XML node.
  1214. */
  1215. Editor.extractGraphModel = function(node, allowMxFile, checked)
  1216. {
  1217. if (node != null && typeof(pako) !== 'undefined')
  1218. {
  1219. var tmp = node.ownerDocument.getElementsByTagName('div');
  1220. var divs = [];
  1221. if (tmp != null && tmp.length > 0)
  1222. {
  1223. for (var i = 0; i < tmp.length; i++)
  1224. {
  1225. if (tmp[i].getAttribute('class') == 'mxgraph')
  1226. {
  1227. divs.push(tmp[i]);
  1228. break;
  1229. }
  1230. }
  1231. }
  1232. if (divs.length > 0)
  1233. {
  1234. var data = divs[0].getAttribute('data-mxgraph');
  1235. if (data != null)
  1236. {
  1237. var config = JSON.parse(data);
  1238. if (config != null && config.xml != null)
  1239. {
  1240. var doc2 = mxUtils.parseXml(config.xml);
  1241. node = doc2.documentElement;
  1242. }
  1243. }
  1244. else
  1245. {
  1246. var divs2 = divs[0].getElementsByTagName('div');
  1247. if (divs2.length > 0)
  1248. {
  1249. var data = mxUtils.getTextContent(divs2[0]);
  1250. data = Graph.decompress(data, null, checked);
  1251. if (data.length > 0)
  1252. {
  1253. var doc2 = mxUtils.parseXml(data);
  1254. node = doc2.documentElement;
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260. if (node != null && node.nodeName == 'svg')
  1261. {
  1262. var tmp = node.getAttribute('content');
  1263. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  1264. {
  1265. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  1266. }
  1267. if (tmp != null && tmp.charAt(0) == '%')
  1268. {
  1269. tmp = decodeURIComponent(tmp);
  1270. }
  1271. if (tmp != null && tmp.length > 0)
  1272. {
  1273. node = mxUtils.parseXml(tmp).documentElement;
  1274. }
  1275. else
  1276. {
  1277. throw {message: mxResources.get('notADiagramFile')};
  1278. }
  1279. }
  1280. if (node != null && !allowMxFile)
  1281. {
  1282. var diagramNode = null;
  1283. if (node.nodeName == 'diagram')
  1284. {
  1285. diagramNode = node;
  1286. }
  1287. else if (node.nodeName == 'mxfile')
  1288. {
  1289. var diagrams = node.getElementsByTagName('diagram');
  1290. if (diagrams.length > 0)
  1291. {
  1292. diagramNode = diagrams[Math.max(0, Math.min(diagrams.length - 1, urlParams['page'] || 0))];
  1293. }
  1294. }
  1295. if (diagramNode != null)
  1296. {
  1297. node = Editor.parseDiagramNode(diagramNode, checked);
  1298. }
  1299. }
  1300. if (node != null && node.nodeName != 'mxGraphModel' && (!allowMxFile || node.nodeName != 'mxfile'))
  1301. {
  1302. node = null;
  1303. }
  1304. return node;
  1305. };
  1306. /**
  1307. * Extracts the XML from the compressed or non-compressed text chunk.
  1308. */
  1309. Editor.parseDiagramNode = function(diagramNode, checked)
  1310. {
  1311. var text = mxUtils.trim(mxUtils.getTextContent(diagramNode));
  1312. var node = null;
  1313. if (text.length > 0)
  1314. {
  1315. var tmp = Graph.decompress(text, null, checked);
  1316. if (tmp != null && tmp.length > 0)
  1317. {
  1318. node = mxUtils.parseXml(tmp).documentElement;
  1319. }
  1320. }
  1321. else
  1322. {
  1323. var temp = mxUtils.getChildNodes(diagramNode);
  1324. if (temp.length > 0)
  1325. {
  1326. // Creates new document for unique IDs within mxGraphModel
  1327. var doc = mxUtils.createXmlDocument();
  1328. doc.appendChild(doc.importNode(temp[0], true));
  1329. node = doc.documentElement;
  1330. }
  1331. }
  1332. return node;
  1333. };
  1334. /**
  1335. * Extracts the XML from the compressed or non-compressed text chunk.
  1336. */
  1337. Editor.getDiagramNodeXml = function(diagramNode)
  1338. {
  1339. var text = mxUtils.getTextContent(diagramNode);
  1340. var xml = null;
  1341. if (text.length > 0)
  1342. {
  1343. xml = Graph.decompress(text);
  1344. }
  1345. else if (diagramNode.firstChild != null)
  1346. {
  1347. xml = mxUtils.getXml(diagramNode.firstChild);
  1348. }
  1349. return xml;
  1350. };
  1351. /**
  1352. * Static method for parsing PDF files.
  1353. */
  1354. Editor.extractGraphModelFromPdf = function(base64)
  1355. {
  1356. base64 = base64.substring(base64.indexOf(',') + 1);
  1357. // Workaround for invalid character error in Safari
  1358. var f = (window.atob && !mxClient.IS_SF) ? atob(base64) : Base64.decode(base64, true);
  1359. //The new format of embedding diagram XML as embedded file (attachment) is in PDF 1.7
  1360. if (f.substring(0, 8) == '%PDF-1.7')
  1361. {
  1362. var blockStart = f.indexOf('EmbeddedFile');
  1363. if (blockStart > -1)
  1364. {
  1365. var streamStart = f.indexOf('stream', blockStart) + 9; //the start of the stream [skipping header check]
  1366. var fileInfo = f.substring(blockStart, streamStart);
  1367. if (fileInfo.indexOf('application#2Fvnd.jgraph.mxfile') > 0)
  1368. {
  1369. var streamEnd = f.indexOf('endstream', streamStart - 1);
  1370. return pako.inflateRaw(Graph.stringToArrayBuffer(f.substring(streamStart, streamEnd)), {to: 'string'});
  1371. }
  1372. }
  1373. //Not found
  1374. return null;
  1375. }
  1376. var check = '/Subject (%3Cmxfile';
  1377. var result = null;
  1378. var curline = '';
  1379. var checked = 0;
  1380. var pos = 0;
  1381. var obj = [];
  1382. var buf = null;
  1383. var nr = null;
  1384. while (pos < f.length)
  1385. {
  1386. var b = f.charCodeAt(pos);
  1387. pos += 1;
  1388. if (b != 10)
  1389. {
  1390. curline += String.fromCharCode(b);
  1391. }
  1392. if (b == check.charCodeAt(checked))
  1393. {
  1394. checked++;
  1395. }
  1396. else
  1397. {
  1398. checked = 0;
  1399. }
  1400. if (checked == check.length)
  1401. {
  1402. var end = f.indexOf('%3C%2Fmxfile%3E)', pos) + 15; //15 is the length of encoded </mxfile>
  1403. pos -= 9; //9 is the length of encoded <mxfile
  1404. // Default case is XML inlined in Subject metadata
  1405. if (end > pos)
  1406. {
  1407. result = f.substring(pos, end);
  1408. break;
  1409. }
  1410. }
  1411. // Creates table for lookup if no inline data is found
  1412. if (b == 10)
  1413. {
  1414. if (curline == 'endobj')
  1415. {
  1416. buf = null;
  1417. }
  1418. else if (curline.substring(curline.length - 3, curline.length) == 'obj' ||
  1419. curline == 'xref' || curline == 'trailer')
  1420. {
  1421. buf = [];
  1422. obj[curline.split(' ')[0]] = buf;
  1423. }
  1424. else if (buf != null)
  1425. {
  1426. buf.push(curline);
  1427. }
  1428. curline = '';
  1429. }
  1430. }
  1431. // Extract XML via references
  1432. if (result == null)
  1433. {
  1434. result = Editor.extractGraphModelFromXref(obj);
  1435. }
  1436. if (result != null)
  1437. {
  1438. result = decodeURIComponent(result.
  1439. replace(/\\\(/g, "(").
  1440. replace(/\\\)/g, ")"));
  1441. }
  1442. return result;
  1443. };
  1444. /**
  1445. * Static method for extracting Subject via references of the form
  1446. *
  1447. * << /Size 33 /Root 20 0 R /Info 1 0 R and 1 0 obj << /Subject 22 0 R
  1448. *
  1449. * Where Info is the metadata block and Subject is the data block.
  1450. */
  1451. Editor.extractGraphModelFromXref = function(obj)
  1452. {
  1453. var trailer = obj['trailer'];
  1454. var result = null;
  1455. // Gets Info object
  1456. if (trailer != null)
  1457. {
  1458. var arr = /.* \/Info (\d+) (\d+) R/g.exec(trailer.join('\n'));
  1459. if (arr != null && arr.length > 0)
  1460. {
  1461. var info = obj[arr[1]];
  1462. if (info != null)
  1463. {
  1464. arr = /.* \/Subject (\d+) (\d+) R/g.exec(info.join('\n'));
  1465. if (arr != null && arr.length > 0)
  1466. {
  1467. var subj = obj[arr[1]];
  1468. if (subj != null)
  1469. {
  1470. subj = subj.join('\n');
  1471. result = subj.substring(1, subj.length - 1);
  1472. }
  1473. }
  1474. }
  1475. }
  1476. }
  1477. return result;
  1478. };
  1479. /**
  1480. * Extracts any parsers errors in the given XML.
  1481. */
  1482. Editor.extractParserError = function(node, defaultCause)
  1483. {
  1484. var cause = null;
  1485. var errors = (node != null) ? node.getElementsByTagName('parsererror') : null;
  1486. if (errors != null && errors.length > 0)
  1487. {
  1488. cause = defaultCause || mxResources.get('invalidChars');
  1489. var divs = errors[0].getElementsByTagName('div');
  1490. if (divs.length > 0)
  1491. {
  1492. cause = mxUtils.getTextContent(divs[0]);
  1493. }
  1494. }
  1495. return (cause != null) ? mxUtils.trim(cause) : cause;
  1496. };
  1497. /**
  1498. * Adds the given retry function to the given error.
  1499. */
  1500. Editor.addRetryToError = function(err, retry)
  1501. {
  1502. if (err != null)
  1503. {
  1504. var e = (err.error != null) ? err.error : err;
  1505. if (e.retry == null)
  1506. {
  1507. e.retry = retry;
  1508. }
  1509. }
  1510. };
  1511. /**
  1512. * Global configuration of the Editor
  1513. * see https://www.diagrams.net/doc/faq/configure-diagram-editor
  1514. *
  1515. * For defaultVertexStyle, defaultEdgeStyle and defaultLibraries, this must be called before
  1516. * mxSettings.load via global config variable window.mxLoadSettings = false.
  1517. */
  1518. Editor.configure = function(config)
  1519. {
  1520. if (config != null)
  1521. {
  1522. Editor.config = config;
  1523. Editor.configVersion = config.version;
  1524. Menus.prototype.defaultFonts = config.defaultFonts || Menus.prototype.defaultFonts;
  1525. ColorDialog.prototype.presetColors = config.presetColors || ColorDialog.prototype.presetColors;
  1526. ColorDialog.prototype.defaultColors = config.defaultColors || ColorDialog.prototype.defaultColors;
  1527. ColorDialog.prototype.colorNames = config.colorNames || ColorDialog.prototype.colorNames;
  1528. StyleFormatPanel.prototype.defaultColorSchemes = config.defaultColorSchemes || StyleFormatPanel.prototype.defaultColorSchemes;
  1529. Graph.prototype.defaultEdgeLength = config.defaultEdgeLength || Graph.prototype.defaultEdgeLength;
  1530. DrawioFile.prototype.autosaveDelay = config.autosaveDelay || DrawioFile.prototype.autosaveDelay;
  1531. // Enables debug output
  1532. if (config.debug)
  1533. {
  1534. urlParams['test'] = '1'
  1535. }
  1536. if (config.templateFile != null)
  1537. {
  1538. EditorUi.templateFile = config.templateFile;
  1539. }
  1540. if (config.styles != null)
  1541. {
  1542. if (Array.isArray(config.styles))
  1543. {
  1544. Editor.styles = config.styles;
  1545. }
  1546. else
  1547. {
  1548. EditorUi.debug('Configuration Error: Array expected for styles');
  1549. }
  1550. }
  1551. if (config.globalVars != null)
  1552. {
  1553. Editor.globalVars = config.globalVars;
  1554. }
  1555. if (config.compressXml != null)
  1556. {
  1557. Editor.compressXml = config.compressXml;
  1558. }
  1559. if (config.includeDiagram != null)
  1560. {
  1561. Editor.defaultIncludeDiagram = config.includeDiagram;
  1562. }
  1563. if (config.simpleLabels != null)
  1564. {
  1565. Editor.simpleLabels = config.simpleLabels;
  1566. }
  1567. if (config.oneDriveInlinePicker != null)
  1568. {
  1569. Editor.oneDriveInlinePicker = config.oneDriveInlinePicker;
  1570. }
  1571. if (config.darkColor != null)
  1572. {
  1573. Editor.darkColor = config.darkColor;
  1574. }
  1575. if (config.lightColor != null)
  1576. {
  1577. Editor.lightColor = config.lightColor;
  1578. }
  1579. if (config.settingsName != null)
  1580. {
  1581. Editor.configurationKey = '.' + config.settingsName + '-configuration';
  1582. Editor.settingsKey = '.' + config.settingsName + '-config';
  1583. mxSettings.key = Editor.settingsKey;
  1584. }
  1585. if (config.customFonts)
  1586. {
  1587. Menus.prototype.defaultFonts = config.customFonts.
  1588. concat(Menus.prototype.defaultFonts);
  1589. }
  1590. if (config.customPresetColors)
  1591. {
  1592. ColorDialog.prototype.presetColors = config.customPresetColors.
  1593. concat(ColorDialog.prototype.presetColors);
  1594. }
  1595. if (config.customColorSchemes != null)
  1596. {
  1597. StyleFormatPanel.prototype.defaultColorSchemes = config.customColorSchemes.
  1598. concat(StyleFormatPanel.prototype.defaultColorSchemes);
  1599. }
  1600. // Custom CSS injected directly into the page
  1601. if (config.css != null)
  1602. {
  1603. var s = document.createElement('style');
  1604. s.setAttribute('type', 'text/css');
  1605. s.appendChild(document.createTextNode(config.css));
  1606. var t = document.getElementsByTagName('script')[0];
  1607. t.parentNode.insertBefore(s, t);
  1608. }
  1609. // Configures the custom libraries
  1610. if (config.libraries != null)
  1611. {
  1612. Sidebar.prototype.customEntries = config.libraries;
  1613. }
  1614. // Defines the enabled built-in libraries.
  1615. if (config.enabledLibraries != null)
  1616. {
  1617. if (Array.isArray(config.enabledLibraries))
  1618. {
  1619. Sidebar.prototype.enabledLibraries = config.enabledLibraries;
  1620. }
  1621. else
  1622. {
  1623. EditorUi.debug('Configuration Error: Array expected for enabledLibraries');
  1624. }
  1625. }
  1626. // Overrides default libraries
  1627. if (config.defaultLibraries != null)
  1628. {
  1629. Sidebar.prototype.defaultEntries = config.defaultLibraries;
  1630. }
  1631. // Overrides default custom libraries
  1632. if (config.defaultCustomLibraries != null)
  1633. {
  1634. Editor.defaultCustomLibraries = config.defaultCustomLibraries;
  1635. }
  1636. // Disables custom libraries
  1637. if (config.enableCustomLibraries != null)
  1638. {
  1639. Editor.enableCustomLibraries = config.enableCustomLibraries;
  1640. }
  1641. // Overrides default vertex style
  1642. if (config.defaultVertexStyle != null)
  1643. {
  1644. Graph.prototype.defaultVertexStyle = config.defaultVertexStyle;
  1645. }
  1646. // Overrides default edge style
  1647. if (config.defaultEdgeStyle != null)
  1648. {
  1649. Graph.prototype.defaultEdgeStyle = config.defaultEdgeStyle;
  1650. }
  1651. // Overrides default page visible
  1652. if (config.defaultPageVisible != null)
  1653. {
  1654. Graph.prototype.defaultPageVisible = config.defaultPageVisible;
  1655. }
  1656. // Overrides default grid enabled
  1657. if (config.defaultGridEnabled != null)
  1658. {
  1659. Graph.prototype.defaultGridEnabled = config.defaultGridEnabled;
  1660. }
  1661. // Overrides mouse wheel function
  1662. if (config.zoomWheel != null)
  1663. {
  1664. Graph.zoomWheel = config.zoomWheel;
  1665. }
  1666. // Overrides zoom factor
  1667. if (config.zoomFactor != null)
  1668. {
  1669. var val = parseFloat(config.zoomFactor);
  1670. if (!isNaN(val) && val > 1)
  1671. {
  1672. Graph.prototype.zoomFactor = val;
  1673. }
  1674. else
  1675. {
  1676. EditorUi.debug('Configuration Error: Float > 1 expected for zoomFactor');
  1677. }
  1678. }
  1679. // Overrides grid steps
  1680. if (config.gridSteps != null)
  1681. {
  1682. var val = parseInt(config.gridSteps);
  1683. if (!isNaN(val) && val > 0)
  1684. {
  1685. mxGraphView.prototype.gridSteps = val;
  1686. }
  1687. else
  1688. {
  1689. EditorUi.debug('Configuration Error: Int > 0 expected for gridSteps');
  1690. }
  1691. }
  1692. if (config.pageFormat != null)
  1693. {
  1694. var w = parseInt(config.pageFormat.width);
  1695. var h = parseInt(config.pageFormat.height);
  1696. if (!isNaN(w) && w > 0 && !isNaN(h) && h > 0)
  1697. {
  1698. mxGraph.prototype.defaultPageFormat = new mxRectangle(0, 0, w, h);
  1699. mxGraph.prototype.pageFormat = mxGraph.prototype.defaultPageFormat;
  1700. }
  1701. else
  1702. {
  1703. EditorUi.debug('Configuration Error: {width: int, height: int} expected for pageFormat');
  1704. }
  1705. }
  1706. if (config.thumbWidth)
  1707. {
  1708. Sidebar.prototype.thumbWidth = config.thumbWidth;
  1709. }
  1710. if (config.thumbHeight)
  1711. {
  1712. Sidebar.prototype.thumbHeight = config.thumbHeight;
  1713. }
  1714. if (config.emptyLibraryXml)
  1715. {
  1716. EditorUi.prototype.emptyLibraryXml = config.emptyLibraryXml;
  1717. }
  1718. if (config.emptyDiagramXml)
  1719. {
  1720. EditorUi.prototype.emptyDiagramXml = config.emptyDiagramXml;
  1721. }
  1722. if (config.sidebarWidth)
  1723. {
  1724. EditorUi.prototype.hsplitPosition = config.sidebarWidth;
  1725. }
  1726. if (config.sidebarTitles)
  1727. {
  1728. Sidebar.prototype.sidebarTitles = config.sidebarTitles;
  1729. }
  1730. if (config.sidebarTitleSize)
  1731. {
  1732. var val = parseInt(config.sidebarTitleSize);
  1733. if (!isNaN(val) && val > 0)
  1734. {
  1735. Sidebar.prototype.sidebarTitleSize = val;
  1736. }
  1737. else
  1738. {
  1739. EditorUi.debug('Configuration Error: Int > 0 expected for sidebarTitleSize');
  1740. }
  1741. }
  1742. if (config.fontCss)
  1743. {
  1744. if (typeof config.fontCss === 'string')
  1745. {
  1746. Editor.configureFontCss(config.fontCss);
  1747. }
  1748. else
  1749. {
  1750. EditorUi.debug('Configuration Error: String expected for fontCss');
  1751. }
  1752. }
  1753. if (config.autosaveDelay != null)
  1754. {
  1755. var val = parseInt(config.autosaveDelay);
  1756. if (!isNaN(val) && val > 0)
  1757. {
  1758. DrawioFile.prototype.autosaveDelay = val;
  1759. }
  1760. else
  1761. {
  1762. EditorUi.debug('Configuration Error: Int > 0 expected for autosaveDelay');
  1763. }
  1764. }
  1765. if(config.maxImageBytes != null)
  1766. {
  1767. EditorUi.prototype.maxImageBytes = config.maxImageBytes;
  1768. }
  1769. if(config.maxImageSize != null)
  1770. {
  1771. EditorUi.prototype.maxImageSize = config.maxImageSize;
  1772. }
  1773. if (config.shareCursorPosition != null)
  1774. {
  1775. EditorUi.prototype.shareCursorPosition = config.shareCursorPosition;
  1776. }
  1777. if (config.showRemoteCursors != null)
  1778. {
  1779. EditorUi.prototype.showRemoteCursors = config.showRemoteCursors;
  1780. }
  1781. }
  1782. };
  1783. /**
  1784. * Adds the global fontCss configuration.
  1785. */
  1786. Editor.configureFontCss = function(fontCss)
  1787. {
  1788. if (fontCss != null)
  1789. {
  1790. Editor.prototype.fontCss = fontCss;
  1791. var t = document.getElementsByTagName('script')[0];
  1792. if (t != null && t.parentNode != null)
  1793. {
  1794. var s = document.createElement('style');
  1795. s.setAttribute('type', 'text/css');
  1796. s.appendChild(document.createTextNode(fontCss));
  1797. t.parentNode.insertBefore(s, t);
  1798. // Preloads fonts where supported
  1799. var parts = fontCss.split('url(');
  1800. for (var i = 1; i < parts.length; i++)
  1801. {
  1802. var idx = parts[i].indexOf(')');
  1803. var url = Editor.trimCssUrl(parts[i].substring(0, idx));
  1804. var l = document.createElement('link');
  1805. l.setAttribute('rel', 'preload');
  1806. l.setAttribute('href', url);
  1807. l.setAttribute('as', 'font');
  1808. l.setAttribute('crossorigin', '');
  1809. t.parentNode.insertBefore(l, t);
  1810. }
  1811. }
  1812. }
  1813. };
  1814. /**
  1815. * Strips leading and trailing quotes and spaces
  1816. */
  1817. Editor.trimCssUrl = function(str)
  1818. {
  1819. return str.replace(new RegExp("^[\\s\"']+", "g"), "").replace(new RegExp("[\\s\"']+$", "g"), "");
  1820. }
  1821. /**
  1822. * Prefix for URLs that reference Google fonts.
  1823. */
  1824. Editor.GOOGLE_FONTS = 'https://fonts.googleapis.com/css?family=';
  1825. /**
  1826. * Alphabet for global unique IDs.
  1827. */
  1828. Editor.GUID_ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_';
  1829. /**
  1830. * Default length for global unique IDs.
  1831. */
  1832. Editor.GUID_LENGTH = 20;
  1833. /**
  1834. * Default length for global unique IDs.
  1835. */
  1836. Editor.guid = function(length)
  1837. {
  1838. var len = (length != null) ? length : Editor.GUID_LENGTH;
  1839. var rtn = [];
  1840. for (var i = 0; i < len; i++)
  1841. {
  1842. rtn.push(Editor.GUID_ALPHABET.charAt(Math.floor(Math.random() * Editor.GUID_ALPHABET.length)));
  1843. }
  1844. return rtn.join('');
  1845. };
  1846. /**
  1847. * General timeout is 25 seconds.
  1848. */
  1849. Editor.prototype.timeout = 25000;
  1850. /**
  1851. * Executes the first step for connecting to Google Drive.
  1852. */
  1853. Editor.prototype.editButtonLink = (urlParams['edit'] != null) ? decodeURIComponent(urlParams['edit']) : null;
  1854. /**
  1855. * Specifies if img.crossOrigin is supported. This is true for all browsers except IE10 and earlier.
  1856. */
  1857. Editor.prototype.crossOriginImages = !mxClient.IS_IE;
  1858. /**
  1859. * Adds support for old stylesheets and compressed files
  1860. */
  1861. var editorSetGraphXml = Editor.prototype.setGraphXml;
  1862. Editor.prototype.setGraphXml = function(node)
  1863. {
  1864. node = (node != null && node.nodeName != 'mxlibrary') ? this.extractGraphModel(node) : null;
  1865. if (node != null)
  1866. {
  1867. // Checks for parser errors
  1868. var cause = Editor.extractParserError(node, mxResources.get('invalidOrMissingFile'));
  1869. if (cause)
  1870. {
  1871. EditorUi.debug('Editor.setGraphXml ParserError', [this],
  1872. 'node', [node], 'cause', [cause]);
  1873. throw new Error(mxResources.get('notADiagramFile') + ' (' + cause + ')');
  1874. }
  1875. else if (node.nodeName == 'mxGraphModel')
  1876. {
  1877. var style = node.getAttribute('style') || 'default-style2';
  1878. // Decodes the style if required
  1879. if (urlParams['embed'] != '1' && (style == null || style == ''))
  1880. {
  1881. var node2 = (this.graph.themes != null) ?
  1882. this.graph.themes['default-old'] :
  1883. mxUtils.load(STYLE_PATH + '/default-old.xml').getDocumentElement();
  1884. if (node2 != null)
  1885. {
  1886. var dec2 = new mxCodec(node2.ownerDocument);
  1887. dec2.decode(node2, this.graph.getStylesheet());
  1888. }
  1889. }
  1890. else if (style != this.graph.currentStyle)
  1891. {
  1892. var node2 = (this.graph.themes != null) ?
  1893. this.graph.themes[style] :
  1894. mxUtils.load(STYLE_PATH + '/' + style + '.xml').getDocumentElement()
  1895. if (node2 != null)
  1896. {
  1897. var dec2 = new mxCodec(node2.ownerDocument);
  1898. dec2.decode(node2, this.graph.getStylesheet());
  1899. }
  1900. }
  1901. this.graph.currentStyle = style;
  1902. this.graph.mathEnabled = (urlParams['math'] == '1' || node.getAttribute('math') == '1');
  1903. var bgImg = node.getAttribute('backgroundImage');
  1904. if (bgImg != null)
  1905. {
  1906. this.graph.setBackgroundImage(this.graph.parseBackgroundImage(bgImg));
  1907. }
  1908. else
  1909. {
  1910. this.graph.setBackgroundImage(null);
  1911. }
  1912. this.graph.useCssTransforms = !mxClient.NO_FO &&
  1913. this.isChromelessView() &&
  1914. this.graph.isCssTransformsSupported();
  1915. this.graph.updateCssTransform();
  1916. this.graph.setShadowVisible(node.getAttribute('shadow') == '1', false);
  1917. var extFonts = node.getAttribute('extFonts');
  1918. if (extFonts)
  1919. {
  1920. try
  1921. {
  1922. extFonts = extFonts.split('|').map(function(ef)
  1923. {
  1924. var parts = ef.split('^');
  1925. return {name: parts[0], url: parts[1]};
  1926. });
  1927. for (var i = 0; i < extFonts.length; i++)
  1928. {
  1929. this.graph.addExtFont(extFonts[i].name, extFonts[i].url);
  1930. }
  1931. }
  1932. catch(e)
  1933. {
  1934. console.log('ExtFonts format error: ' + e.message);
  1935. }
  1936. }
  1937. else if (this.graph.extFonts != null && this.graph.extFonts.length > 0)
  1938. {
  1939. this.graph.extFonts = [];
  1940. }
  1941. }
  1942. // Calls updateGraphComponents
  1943. editorSetGraphXml.apply(this, arguments);
  1944. }
  1945. else
  1946. {
  1947. throw {
  1948. message: mxResources.get('notADiagramFile') || 'Invalid data',
  1949. toString: function() { return this.message; }
  1950. };
  1951. }
  1952. };
  1953. /**
  1954. * Adds persistent style to file
  1955. */
  1956. var editorGetGraphXml = Editor.prototype.getGraphXml;
  1957. Editor.prototype.getGraphXml = function(ignoreSelection, resolveReferences)
  1958. {
  1959. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  1960. var node = editorGetGraphXml.apply(this, arguments);
  1961. // Adds the current style
  1962. if (this.graph.currentStyle != null && this.graph.currentStyle != 'default-style2')
  1963. {
  1964. node.setAttribute('style', this.graph.currentStyle);
  1965. }
  1966. var bgImg = this.graph.getBackgroundImageObject(
  1967. this.graph.backgroundImage,
  1968. resolveReferences);
  1969. // Adds the background image
  1970. if (bgImg != null)
  1971. {
  1972. node.setAttribute('backgroundImage', JSON.stringify(bgImg));
  1973. }
  1974. node.setAttribute('math', (this.graph.mathEnabled) ? '1' : '0');
  1975. node.setAttribute('shadow', (this.graph.shadowVisible) ? '1' : '0');
  1976. if (this.graph.extFonts != null && this.graph.extFonts.length > 0)
  1977. {
  1978. var strExtFonts = this.graph.extFonts.map(function(ef)
  1979. {
  1980. return ef.name + '^' + ef.url;
  1981. });
  1982. node.setAttribute('extFonts', strExtFonts.join('|'));
  1983. }
  1984. return node;
  1985. };
  1986. /**
  1987. * Helper function to extract the graph model XML node.
  1988. */
  1989. Editor.prototype.isDataSvg = function(svg)
  1990. {
  1991. try
  1992. {
  1993. var svgRoot = mxUtils.parseXml(svg).documentElement;
  1994. var tmp = svgRoot.getAttribute('content');
  1995. if (tmp != null)
  1996. {
  1997. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  1998. {
  1999. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  2000. }
  2001. if (tmp != null && tmp.charAt(0) == '%')
  2002. {
  2003. tmp = decodeURIComponent(tmp);
  2004. }
  2005. if (tmp != null && tmp.length > 0)
  2006. {
  2007. var node = mxUtils.parseXml(tmp).documentElement;
  2008. return node.nodeName == 'mxfile' || node.nodeName == 'mxGraphModel';
  2009. }
  2010. }
  2011. }
  2012. catch (e)
  2013. {
  2014. // ignore
  2015. }
  2016. return false;
  2017. };
  2018. /**
  2019. * Helper function to extract the graph model XML node.
  2020. */
  2021. Editor.prototype.extractGraphModel = function(node, allowMxFile, checked)
  2022. {
  2023. return Editor.extractGraphModel.apply(this, arguments);
  2024. };
  2025. /**
  2026. * Overrides reset graph.
  2027. */
  2028. var editorResetGraph = Editor.prototype.resetGraph;
  2029. Editor.prototype.resetGraph = function()
  2030. {
  2031. this.graph.mathEnabled = (urlParams['math'] == '1');
  2032. this.graph.view.x0 = null;
  2033. this.graph.view.y0 = null;
  2034. this.graph.useCssTransforms = !mxClient.NO_FO &&
  2035. this.isChromelessView() &&
  2036. this.graph.isCssTransformsSupported();
  2037. this.graph.updateCssTransform();
  2038. editorResetGraph.apply(this, arguments);
  2039. };
  2040. /**
  2041. * Math support.
  2042. */
  2043. var editorUpdateGraphComponents = Editor.prototype.updateGraphComponents;
  2044. Editor.prototype.updateGraphComponents = function()
  2045. {
  2046. editorUpdateGraphComponents.apply(this, arguments);
  2047. this.graph.useCssTransforms = !mxClient.NO_FO &&
  2048. this.isChromelessView() &&
  2049. this.graph.isCssTransformsSupported();
  2050. this.graph.updateCssTransform();
  2051. };
  2052. /**
  2053. * Initializes math typesetting and loads respective code.
  2054. */
  2055. Editor.initMath = function(src, config)
  2056. {
  2057. if (typeof window.MathJax === 'undefined' && !mxClient.IS_IE && !mxClient.IS_IE11)
  2058. {
  2059. src = (src != null) ? src : DRAW_MATH_URL + '/startup.js';
  2060. Editor.mathJaxQueue = [];
  2061. Editor.doMathJaxRender = function(container)
  2062. {
  2063. try
  2064. {
  2065. MathJax.typesetClear([container]);
  2066. MathJax.typeset([container]);
  2067. Editor.onMathJaxDone();
  2068. }
  2069. catch (e)
  2070. {
  2071. MathJax.typesetClear([container]);
  2072. if (e.retry != null)
  2073. {
  2074. e.retry.then(function()
  2075. {
  2076. MathJax.typesetPromise([container]).then(Editor.onMathJaxDone);
  2077. });
  2078. }
  2079. else if (window.console != null)
  2080. {
  2081. console.log('Error in MathJax: ' + e.toString());
  2082. }
  2083. }
  2084. };
  2085. window.MathJax = (config != null) ? config :
  2086. {
  2087. options:
  2088. {
  2089. skipHtmlTags: {'[+]': ['text']}
  2090. },
  2091. loader:
  2092. {
  2093. load: [(urlParams['math-output'] == 'html') ?
  2094. 'output/chtml' : 'output/svg', 'input/tex',
  2095. 'input/asciimath', 'ui/safe']
  2096. },
  2097. startup:
  2098. {
  2099. pageReady: function()
  2100. {
  2101. for (var i = 0; i < Editor.mathJaxQueue.length; i++)
  2102. {
  2103. Editor.doMathJaxRender(Editor.mathJaxQueue[i]);
  2104. }
  2105. }
  2106. }
  2107. };
  2108. // Adds global enqueue method for async rendering
  2109. Editor.MathJaxRender = function(container)
  2110. {
  2111. if (typeof MathJax !== 'undefined' && typeof MathJax.typeset === 'function')
  2112. {
  2113. Editor.doMathJaxRender(container);
  2114. }
  2115. else
  2116. {
  2117. Editor.mathJaxQueue.push(container);
  2118. }
  2119. };
  2120. // Adds global clear queue method
  2121. Editor.MathJaxClear = function()
  2122. {
  2123. Editor.mathJaxQueue = [];
  2124. };
  2125. // Adds global MathJax render callback
  2126. Editor.onMathJaxDone = function()
  2127. {
  2128. // Hook for listeners
  2129. };
  2130. // Updates math typesetting after changes
  2131. var editorInit = Editor.prototype.init;
  2132. Editor.prototype.init = function()
  2133. {
  2134. editorInit.apply(this, arguments);
  2135. var renderMath = mxUtils.bind(this, function(sender, evt)
  2136. {
  2137. if (this.graph.container != null && this.graph.mathEnabled &&
  2138. !this.graph.blockMathRender)
  2139. {
  2140. Editor.MathJaxRender(this.graph.container);
  2141. }
  2142. });
  2143. this.graph.model.addListener(mxEvent.CHANGE, renderMath);
  2144. this.graph.addListener(mxEvent.REFRESH, renderMath);
  2145. };
  2146. var tags = document.getElementsByTagName('script');
  2147. if (tags != null && tags.length > 0)
  2148. {
  2149. var s = document.createElement('script');
  2150. s.setAttribute('type', 'text/javascript');
  2151. s.setAttribute('src', src);
  2152. tags[0].parentNode.appendChild(s);
  2153. }
  2154. }
  2155. };
  2156. /**
  2157. * Parses line of CSV values according to RFC 4180.
  2158. */
  2159. Editor.prototype.csvToArray = function(text)
  2160. {
  2161. if (text.length > 0)
  2162. {
  2163. var p = '', row = [''], i = 0, s = !0, l;
  2164. for (l of text)
  2165. {
  2166. if ('"' === l)
  2167. {
  2168. if (s && l === p)
  2169. {
  2170. row[i] += l;
  2171. }
  2172. s = !s;
  2173. }
  2174. else if (',' === l && s)
  2175. {
  2176. l = row[++i] = '';
  2177. }
  2178. else
  2179. {
  2180. row[i] += l;
  2181. }
  2182. p = l;
  2183. }
  2184. return row;
  2185. }
  2186. else
  2187. {
  2188. return [];
  2189. }
  2190. };
  2191. /**
  2192. * Returns an URL that is proxied if the given URL is blocked. Uses
  2193. * direct URL if no CSP is used as proxy blocks unknown text content.
  2194. */
  2195. Editor.prototype.getProxiedUrl = function(url)
  2196. {
  2197. if ((/test\.draw\.io$/.test(window.location.hostname) ||
  2198. /app\.diagrams\.net$/.test(window.location.hostname)) &&
  2199. !this.isCorsEnabledForUrl(url))
  2200. {
  2201. var isVisioFilename = /(\.v(dx|sdx?))($|\?)/i.test(url) ||
  2202. /(\.vs(x|sx?))($|\?)/i.test(url);
  2203. var binary = /\.png$/i.test(url) || /\.pdf$/i.test(url);
  2204. var base64 = binary || isVisioFilename;
  2205. var nocache = 't=' + new Date().getTime();
  2206. url = PROXY_URL + '?url=' + encodeURIComponent(url) +
  2207. '&' + nocache + ((base64) ? '&base64=1' : '');
  2208. }
  2209. return url;
  2210. };
  2211. /**
  2212. * Returns true if the given URL is known to have CORS headers and is
  2213. * allowed by CSP.
  2214. */
  2215. Editor.prototype.isCorsEnabledForUrl = function(url)
  2216. {
  2217. // Disables proxy for desktop and chrome app as it is served locally
  2218. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  2219. {
  2220. return true;
  2221. }
  2222. // Does not use proxy for same domain
  2223. if (url.substring(0, window.location.origin.length) == window.location.origin)
  2224. {
  2225. return true;
  2226. }
  2227. // Blocked by CSP in production but allowed for hosted deployment
  2228. if (urlParams['cors'] != null && this.corsRegExp == null)
  2229. {
  2230. this.corsRegExp = new RegExp(decodeURIComponent(urlParams['cors']));
  2231. }
  2232. // No access-control-allow-origin for some Iconfinder images, add this when fixed:
  2233. // /^https?:\/\/[^\/]*\.iconfinder.com\//.test(url) ||
  2234. return (this.corsRegExp != null && this.corsRegExp.test(url)) ||
  2235. url.substring(0, 34) === 'https://raw.githubusercontent.com/' ||
  2236. url.substring(0, 29) === 'https://fonts.googleapis.com/' ||
  2237. url.substring(0, 26) === 'https://fonts.gstatic.com/';
  2238. };
  2239. /**
  2240. * Converts all images in the SVG output to data URIs for immediate rendering
  2241. */
  2242. Editor.prototype.createImageUrlConverter = function()
  2243. {
  2244. var converter = new mxUrlConverter();
  2245. converter.updateBaseUrl();
  2246. // Extends convert to avoid CORS using an image proxy server where needed
  2247. var convert = converter.convert;
  2248. var self = this;
  2249. converter.convert = function(src)
  2250. {
  2251. if (src != null)
  2252. {
  2253. var remote = src.substring(0, 7) == 'http://' || src.substring(0, 8) == 'https://';
  2254. if (remote && !navigator.onLine)
  2255. {
  2256. src = Editor.svgBrokenImage.src;
  2257. }
  2258. else if (remote && src.substring(0, converter.baseUrl.length) != converter.baseUrl &&
  2259. (!self.crossOriginImages || !self.isCorsEnabledForUrl(src)))
  2260. {
  2261. src = PROXY_URL + '?url=' + encodeURIComponent(src);
  2262. }
  2263. else if (src.substring(0, 19) != 'chrome-extension://' && !mxClient.IS_CHROMEAPP)
  2264. {
  2265. src = convert.apply(this, arguments);
  2266. }
  2267. }
  2268. return src;
  2269. };
  2270. return converter;
  2271. };
  2272. /**
  2273. *
  2274. */
  2275. Editor.createSvgDataUri = function(svg)
  2276. {
  2277. return 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
  2278. };
  2279. /**
  2280. *
  2281. */
  2282. Editor.prototype.convertImageToDataUri = function(url, callback)
  2283. {
  2284. try
  2285. {
  2286. var acceptResponse = true;
  2287. var timeoutThread = window.setTimeout(mxUtils.bind(this, function()
  2288. {
  2289. acceptResponse = false;
  2290. callback(Editor.svgBrokenImage.src);
  2291. }), this.timeout);
  2292. if (/(\.svg)$/i.test(url))
  2293. {
  2294. mxUtils.get(url, mxUtils.bind(this, function(req)
  2295. {
  2296. window.clearTimeout(timeoutThread);
  2297. if (acceptResponse)
  2298. {
  2299. callback(Editor.createSvgDataUri(req.getText()));
  2300. }
  2301. }),
  2302. function()
  2303. {
  2304. window.clearTimeout(timeoutThread);
  2305. if (acceptResponse)
  2306. {
  2307. callback(Editor.svgBrokenImage.src);
  2308. }
  2309. });
  2310. }
  2311. else
  2312. {
  2313. var img = new Image();
  2314. if (this.crossOriginImages)
  2315. {
  2316. img.crossOrigin = 'anonymous';
  2317. }
  2318. img.onload = function()
  2319. {
  2320. window.clearTimeout(timeoutThread);
  2321. if (acceptResponse)
  2322. {
  2323. try
  2324. {
  2325. var canvas = document.createElement('canvas');
  2326. var ctx = canvas.getContext('2d');
  2327. canvas.height = img.height;
  2328. canvas.width = img.width;
  2329. ctx.drawImage(img, 0, 0);
  2330. callback(canvas.toDataURL());
  2331. }
  2332. catch (e)
  2333. {
  2334. callback(Editor.svgBrokenImage.src);
  2335. }
  2336. }
  2337. };
  2338. img.onerror = function()
  2339. {
  2340. window.clearTimeout(timeoutThread);
  2341. if (acceptResponse)
  2342. {
  2343. callback(Editor.svgBrokenImage.src);
  2344. }
  2345. };
  2346. img.src = url;
  2347. }
  2348. }
  2349. catch (e)
  2350. {
  2351. callback(Editor.svgBrokenImage.src);
  2352. }
  2353. };
  2354. /**
  2355. * Converts all images in the SVG output to data URIs for immediate rendering
  2356. */
  2357. Editor.prototype.convertImages = function(svgRoot, callback, imageCache, converter)
  2358. {
  2359. // Converts images to data URLs for immediate painting
  2360. if (converter == null)
  2361. {
  2362. converter = this.createImageUrlConverter();
  2363. }
  2364. // Barrier for asynchronous image loading
  2365. var counter = 0;
  2366. function inc()
  2367. {
  2368. counter++;
  2369. };
  2370. function dec()
  2371. {
  2372. counter--;
  2373. if (counter == 0)
  2374. {
  2375. callback(svgRoot);
  2376. }
  2377. };
  2378. var cache = imageCache || new Object();
  2379. var convertImages = mxUtils.bind(this, function(tagName, srcAttr)
  2380. {
  2381. var images = svgRoot.getElementsByTagName(tagName);
  2382. for (var i = 0; i < images.length; i++)
  2383. {
  2384. (mxUtils.bind(this, function(img)
  2385. {
  2386. try
  2387. {
  2388. if (img != null)
  2389. {
  2390. var src = converter.convert(img.getAttribute(srcAttr));
  2391. // Data URIs are pass-through
  2392. if (src != null && src.substring(0, 5) != 'data:')
  2393. {
  2394. var tmp = cache[src];
  2395. if (tmp == null)
  2396. {
  2397. inc();
  2398. this.convertImageToDataUri(src, function(uri)
  2399. {
  2400. if (uri != null)
  2401. {
  2402. cache[src] = uri;
  2403. img.setAttribute(srcAttr, uri);
  2404. }
  2405. dec();
  2406. });
  2407. }
  2408. else
  2409. {
  2410. img.setAttribute(srcAttr, tmp);
  2411. }
  2412. }
  2413. else if (src != null)
  2414. {
  2415. img.setAttribute(srcAttr, src);
  2416. }
  2417. }
  2418. }
  2419. catch (e)
  2420. {
  2421. // ignore
  2422. }
  2423. }))(images[i]);
  2424. }
  2425. });
  2426. // Converts all known image tags in output
  2427. // LATER: Add support for images in CSS
  2428. convertImages('image', 'xlink:href');
  2429. convertImages('img', 'src');
  2430. // All from cache or no images
  2431. if (counter == 0)
  2432. {
  2433. callback(svgRoot);
  2434. }
  2435. };
  2436. /**
  2437. * Base64 encodes the given string. This method seems to be more
  2438. * robust for encoding PNG from binary AJAX responses.
  2439. */
  2440. Editor.base64Encode = function(str)
  2441. {
  2442. var CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  2443. var out = "", i = 0, len = str.length, c1, c2, c3;
  2444. while (i < len)
  2445. {
  2446. c1 = str.charCodeAt(i++) & 0xff;
  2447. if (i == len)
  2448. {
  2449. out += CHARS.charAt(c1 >> 2);
  2450. out += CHARS.charAt((c1 & 0x3) << 4);
  2451. out += "==";
  2452. break;
  2453. }
  2454. c2 = str.charCodeAt(i++);
  2455. if (i == len)
  2456. {
  2457. out += CHARS.charAt(c1 >> 2);
  2458. out += CHARS.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  2459. out += CHARS.charAt((c2 & 0xF) << 2);
  2460. out += "=";
  2461. break;
  2462. }
  2463. c3 = str.charCodeAt(i++);
  2464. out += CHARS.charAt(c1 >> 2);
  2465. out += CHARS.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
  2466. out += CHARS.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
  2467. out += CHARS.charAt(c3 & 0x3F);
  2468. }
  2469. return out;
  2470. };
  2471. /**
  2472. * Checks if the client is authorized and calls the next step.
  2473. */
  2474. Editor.prototype.loadUrl = function(url, success, error, forceBinary, retry, dataUriPrefix, noBinary, headers)
  2475. {
  2476. try
  2477. {
  2478. var binary = !noBinary && (forceBinary || /(\.png)($|\?)/i.test(url) ||
  2479. /(\.jpe?g)($|\?)/i.test(url) || /(\.gif)($|\?)/i.test(url) ||
  2480. /(\.pdf)($|\?)/i.test(url));
  2481. retry = (retry != null) ? retry : true;
  2482. var fn = mxUtils.bind(this, function()
  2483. {
  2484. mxUtils.get(url, mxUtils.bind(this, function(req)
  2485. {
  2486. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  2487. {
  2488. if (success != null)
  2489. {
  2490. var data = req.getText();
  2491. // Returns PNG as base64 encoded data URI
  2492. if (binary)
  2493. {
  2494. // NOTE: This requires BinaryToArray VB script in the page
  2495. if ((document.documentMode == 9 || document.documentMode == 10) &&
  2496. typeof window.mxUtilsBinaryToArray !== 'undefined')
  2497. {
  2498. var bin = mxUtilsBinaryToArray(req.request.responseBody).toArray();
  2499. var tmp = new Array(bin.length);
  2500. for (var i = 0; i < bin.length; i++)
  2501. {
  2502. tmp[i] = String.fromCharCode(bin[i]);
  2503. }
  2504. data = tmp.join('');
  2505. }
  2506. // LATER: Could be JPG but modern browsers
  2507. // ignore the mime type in the data URI
  2508. dataUriPrefix = (dataUriPrefix != null) ? dataUriPrefix : 'data:image/png;base64,';
  2509. data = dataUriPrefix + Editor.base64Encode(data);
  2510. }
  2511. success(data);
  2512. }
  2513. }
  2514. else if (error != null)
  2515. {
  2516. if (req.getStatus() == 0)
  2517. {
  2518. // Handles CORS errors
  2519. error({message: mxResources.get('accessDenied')}, req);
  2520. }
  2521. else if (req.getStatus() == 404)
  2522. {
  2523. error({code: req.getStatus()}, req);
  2524. }
  2525. else
  2526. {
  2527. error({message: mxResources.get('error') + ' ' + req.getStatus()}, req);
  2528. }
  2529. }
  2530. }), function(req)
  2531. {
  2532. if (error != null)
  2533. {
  2534. error({message: mxResources.get('error') + ' ' + req.getStatus()});
  2535. }
  2536. }, binary, this.timeout, function()
  2537. {
  2538. if (retry && error != null)
  2539. {
  2540. error({code: App.ERROR_TIMEOUT, retry: fn});
  2541. }
  2542. }, headers);
  2543. });
  2544. fn();
  2545. }
  2546. catch (e)
  2547. {
  2548. if (error != null)
  2549. {
  2550. error(e);
  2551. }
  2552. }
  2553. };
  2554. /**
  2555. * Makes all relative font URLs absolute in the given font CSS.
  2556. */
  2557. Editor.prototype.absoluteCssFonts = function(fontCss)
  2558. {
  2559. var result = null;
  2560. if (fontCss != null)
  2561. {
  2562. var parts = fontCss.split('url(');
  2563. if (parts.length > 0)
  2564. {
  2565. result = [parts[0]];
  2566. // Gets path for URL
  2567. var path = window.location.pathname;
  2568. var idx = (path != null) ? path.lastIndexOf('/') : -1;
  2569. if (idx >= 0)
  2570. {
  2571. path = path.substring(0, idx + 1);
  2572. }
  2573. // Gets base tag from head
  2574. var temp = document.getElementsByTagName('base');
  2575. var base = null;
  2576. if (temp != null && temp.length > 0)
  2577. {
  2578. base = temp[0].getAttribute('href');
  2579. }
  2580. for (var i = 1; i < parts.length; i++)
  2581. {
  2582. var idx = parts[i].indexOf(')');
  2583. if (idx > 0)
  2584. {
  2585. var url = Editor.trimCssUrl(parts[i].substring(0, idx));
  2586. if (this.graph.isRelativeUrl(url))
  2587. {
  2588. url = (base != null) ? base + url : (window.location.protocol + '//' + window.location.hostname +
  2589. ((url.charAt(0) == '/') ? '' : path) + url);
  2590. }
  2591. result.push('url("' + url + '"' + parts[i].substring(idx));
  2592. }
  2593. else
  2594. {
  2595. result.push(parts[i]);
  2596. }
  2597. }
  2598. }
  2599. else
  2600. {
  2601. result = [fontCss]
  2602. }
  2603. }
  2604. return (result != null) ? result.join('') : null;
  2605. };
  2606. /**
  2607. * Returns the URL and mime type to be used for the given font.
  2608. */
  2609. Editor.prototype.mapFontUrl = function(mime, url, fn)
  2610. {
  2611. if ((/^https?:\/\//.test(url)) && !this.isCorsEnabledForUrl(url))
  2612. {
  2613. url = PROXY_URL + '?url=' + encodeURIComponent(url);
  2614. }
  2615. fn(mime, url);
  2616. };
  2617. /**
  2618. * For the fonts in CSS to be applied when rendering images on canvas, the actual
  2619. * font data must be made available via a data URI encoding of the file.
  2620. */
  2621. Editor.prototype.embedCssFonts = function(fontCss, then)
  2622. {
  2623. var parts = fontCss.split('url(');
  2624. var waiting = 0;
  2625. if (this.cachedFonts == null)
  2626. {
  2627. this.cachedFonts = {};
  2628. }
  2629. var finish = mxUtils.bind(this, function()
  2630. {
  2631. if (waiting == 0)
  2632. {
  2633. // Constructs string
  2634. var result = [parts[0]];
  2635. for (var j = 1; j < parts.length; j++)
  2636. {
  2637. var idx = parts[j].indexOf(')');
  2638. result.push('url("');
  2639. result.push(this.cachedFonts[Editor.trimCssUrl(parts[j].substring(0, idx))]);
  2640. result.push('"' + parts[j].substring(idx));
  2641. }
  2642. then(result.join(''));
  2643. }
  2644. });
  2645. if (parts.length > 0)
  2646. {
  2647. for (var i = 1; i < parts.length; i++)
  2648. {
  2649. var idx = parts[i].indexOf(')');
  2650. var format = null;
  2651. // Checks if there is a format directive
  2652. var fmtIdx = parts[i].indexOf('format(', idx);
  2653. if (fmtIdx > 0)
  2654. {
  2655. format = Editor.trimCssUrl(parts[i].substring(fmtIdx + 7, parts[i].indexOf(')', fmtIdx)));
  2656. }
  2657. (mxUtils.bind(this, function(url)
  2658. {
  2659. if (this.cachedFonts[url] == null)
  2660. {
  2661. // Mark font as being fetched and fetch it
  2662. this.cachedFonts[url] = url;
  2663. waiting++;
  2664. var mime = 'application/x-font-ttf';
  2665. // See https://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts
  2666. if (format == 'svg' || /(\.svg)($|\?)/i.test(url))
  2667. {
  2668. mime = 'image/svg+xml';
  2669. }
  2670. else if (format == 'otf' || format == 'embedded-opentype' || /(\.otf)($|\?)/i.test(url))
  2671. {
  2672. mime = 'application/x-font-opentype';
  2673. }
  2674. else if (format == 'woff' || /(\.woff)($|\?)/i.test(url))
  2675. {
  2676. mime = 'application/font-woff';
  2677. }
  2678. else if (format == 'woff2' || /(\.woff2)($|\?)/i.test(url))
  2679. {
  2680. mime = 'application/font-woff2';
  2681. }
  2682. else if (format == 'eot' || /(\.eot)($|\?)/i.test(url))
  2683. {
  2684. mime = 'application/vnd.ms-fontobject';
  2685. }
  2686. else if (format == 'sfnt' || /(\.sfnt)($|\?)/i.test(url))
  2687. {
  2688. mime = 'application/font-sfnt';
  2689. }
  2690. this.mapFontUrl(mime, url, mxUtils.bind(this, function(realMime, realUrl)
  2691. {
  2692. // LATER: Remove cache-control header
  2693. this.loadUrl(realUrl, mxUtils.bind(this, function(uri)
  2694. {
  2695. this.cachedFonts[url] = uri;
  2696. waiting--;
  2697. finish();
  2698. }), mxUtils.bind(this, function(err)
  2699. {
  2700. // LATER: handle error
  2701. waiting--;
  2702. finish();
  2703. }), true, null, 'data:' + realMime + ';charset=utf-8;base64,');
  2704. }));
  2705. }
  2706. }))(Editor.trimCssUrl(parts[i].substring(0, idx)), format);
  2707. }
  2708. //In case all fonts are cached
  2709. finish();
  2710. }
  2711. else
  2712. {
  2713. //No font urls found
  2714. then(fontCss);
  2715. }
  2716. };
  2717. /**
  2718. * For the fontCSS to be applied when rendering images on canvas, the actual
  2719. * font data must be made available via a data URI encoding of the file.
  2720. */
  2721. Editor.prototype.loadFonts = function(then)
  2722. {
  2723. if (this.fontCss != null && this.resolvedFontCss == null)
  2724. {
  2725. this.embedCssFonts(this.fontCss, mxUtils.bind(this, function(resolvedFontCss)
  2726. {
  2727. this.resolvedFontCss = resolvedFontCss;
  2728. if (then != null)
  2729. {
  2730. then();
  2731. }
  2732. }));
  2733. }
  2734. else if (then != null)
  2735. {
  2736. then();
  2737. }
  2738. };
  2739. /**
  2740. * Returns a CSS mapping for the given CSS URL.
  2741. */
  2742. Editor.prototype.createGoogleFontCache = function()
  2743. {
  2744. var cache = {};
  2745. for (var key in Graph.fontMapping)
  2746. {
  2747. if (Graph.isCssFontUrl(key))
  2748. {
  2749. cache[key] = Graph.fontMapping[key];
  2750. }
  2751. }
  2752. return cache;
  2753. };
  2754. /**
  2755. * Embeds external fonts
  2756. */
  2757. Editor.prototype.embedExtFonts = function(callback)
  2758. {
  2759. var extFonts = this.graph.getCustomFonts();
  2760. if (extFonts.length > 0)
  2761. {
  2762. var content = [];
  2763. var waiting = 0;
  2764. if (this.cachedGoogleFonts == null)
  2765. {
  2766. this.cachedGoogleFonts = this.createGoogleFontCache();
  2767. }
  2768. var googleCssDone = mxUtils.bind(this, function()
  2769. {
  2770. if (waiting == 0)
  2771. {
  2772. this.embedCssFonts(content.join(''), callback);
  2773. }
  2774. });
  2775. for (var i = 0; i < extFonts.length; i++)
  2776. {
  2777. (mxUtils.bind(this, function(fontName, fontUrl)
  2778. {
  2779. if (Graph.isCssFontUrl(fontUrl))
  2780. {
  2781. if (this.cachedGoogleFonts[fontUrl] == null)
  2782. {
  2783. waiting++;
  2784. this.loadUrl(fontUrl, mxUtils.bind(this, function(css)
  2785. {
  2786. this.cachedGoogleFonts[fontUrl] = css;
  2787. content.push(css + '\n');
  2788. waiting--;
  2789. googleCssDone();
  2790. }), mxUtils.bind(this, function(err)
  2791. {
  2792. // LATER: handle error
  2793. waiting--;
  2794. content.push('@import url(' + fontUrl + ');\n');
  2795. googleCssDone();
  2796. }));
  2797. }
  2798. else
  2799. {
  2800. content.push(this.cachedGoogleFonts[fontUrl] + '\n');
  2801. }
  2802. }
  2803. else
  2804. {
  2805. content.push('@font-face {' +
  2806. 'font-family: "' + fontName + '";' +
  2807. 'src: url("' + fontUrl + '")}\n');
  2808. }
  2809. }))(extFonts[i].name, extFonts[i].url);
  2810. }
  2811. googleCssDone();
  2812. }
  2813. else
  2814. {
  2815. callback();
  2816. }
  2817. };
  2818. /**
  2819. * Copies MathJax CSS into the SVG output.
  2820. */
  2821. Editor.prototype.addMathCss = function(svgRoot)
  2822. {
  2823. var defs = svgRoot.getElementsByTagName('defs');
  2824. if (defs != null && defs.length > 0)
  2825. {
  2826. var styles = document.getElementsByTagName('style');
  2827. for (var i = 0; i < styles.length; i++)
  2828. {
  2829. // Ignores style elements with no MathJax CSS
  2830. var content = mxUtils.getTextContent(styles[i]);
  2831. if (content.indexOf('mxPageSelector') < 0 &&
  2832. content.indexOf('MathJax') > 0)
  2833. {
  2834. defs[0].appendChild(styles[i].cloneNode(true));
  2835. }
  2836. }
  2837. }
  2838. };
  2839. /**
  2840. * Adds the global fontCss configuration.
  2841. */
  2842. Editor.prototype.addFontCss = function(svgRoot, fontCss)
  2843. {
  2844. fontCss = (fontCss != null) ? fontCss : this.absoluteCssFonts(this.fontCss);
  2845. // Creates defs element if not available
  2846. if (fontCss != null)
  2847. {
  2848. var defs = svgRoot.getElementsByTagName('defs');
  2849. var svgDoc = svgRoot.ownerDocument;
  2850. var defsElt = null;
  2851. if (defs.length == 0)
  2852. {
  2853. defsElt = (svgDoc.createElementNS != null) ?
  2854. svgDoc.createElementNS(mxConstants.NS_SVG, 'defs') :
  2855. svgDoc.createElement('defs');
  2856. if (svgRoot.firstChild != null)
  2857. {
  2858. svgRoot.insertBefore(defsElt, svgRoot.firstChild);
  2859. }
  2860. else
  2861. {
  2862. svgRoot.appendChild(defsElt);
  2863. }
  2864. }
  2865. else
  2866. {
  2867. defsElt = defs[0];
  2868. }
  2869. var style = (svgDoc.createElementNS != null) ?
  2870. svgDoc.createElementNS(mxConstants.NS_SVG, 'style') :
  2871. svgDoc.createElement('style');
  2872. style.setAttribute('type', 'text/css');
  2873. mxUtils.setTextContent(style, fontCss);
  2874. defsElt.appendChild(style);
  2875. }
  2876. };
  2877. /**
  2878. * Disables client-side image export if math is enabled.
  2879. */
  2880. Editor.prototype.isExportToCanvas = function()
  2881. {
  2882. return mxClient.IS_CHROMEAPP || this.useCanvasForExport;
  2883. };
  2884. /**
  2885. * Returns the maximum possible scale for the given canvas dimension and scale.
  2886. * This will return the given scale or the maximum scale that can be used to
  2887. * generate a valid image in the current browser.
  2888. *
  2889. * See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas
  2890. */
  2891. Editor.prototype.getMaxCanvasScale = function(w, h, scale)
  2892. {
  2893. var max = (mxClient.IS_FF) ? 8192 : 16384;
  2894. return Math.min(scale, Math.min(max / w, max / h));
  2895. };
  2896. /**
  2897. *
  2898. */
  2899. Editor.prototype.exportToCanvas = function(callback, width, imageCache, background, error, limitHeight,
  2900. ignoreSelection, scale, transparentBackground, addShadow, converter, graph, border, noCrop, grid,
  2901. keepTheme, exportType, cells)
  2902. {
  2903. try
  2904. {
  2905. limitHeight = (limitHeight != null) ? limitHeight : true;
  2906. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  2907. graph = (graph != null) ? graph : this.graph;
  2908. border = (border != null) ? border : 0;
  2909. var bg = (transparentBackground) ? null : graph.background;
  2910. if (bg == mxConstants.NONE)
  2911. {
  2912. bg = null;
  2913. }
  2914. if (bg == null)
  2915. {
  2916. bg = background;
  2917. }
  2918. // Handles special case where background is null but transparent is false
  2919. if (bg == null && transparentBackground == false)
  2920. {
  2921. bg = (keepTheme) ? this.graph.defaultPageBackgroundColor : '#ffffff';
  2922. }
  2923. this.convertImages(graph.getSvg(null, null, border, noCrop, null, ignoreSelection,
  2924. null, null, null, addShadow, null, keepTheme, exportType, cells),
  2925. mxUtils.bind(this, function(svgRoot)
  2926. {
  2927. try
  2928. {
  2929. var img = new Image();
  2930. img.onload = mxUtils.bind(this, function()
  2931. {
  2932. try
  2933. {
  2934. var canvas = document.createElement('canvas');
  2935. var w = parseInt(svgRoot.getAttribute('width'));
  2936. var h = parseInt(svgRoot.getAttribute('height'));
  2937. scale = (scale != null) ? scale : 1;
  2938. if (width != null)
  2939. {
  2940. scale = (!limitHeight) ? width / w : Math.min(1, Math.min((width * 3) / (h * 4), width / w));
  2941. }
  2942. scale = this.getMaxCanvasScale(w, h, scale);
  2943. w = Math.ceil(scale * w);
  2944. h = Math.ceil(scale * h);
  2945. canvas.setAttribute('width', w);
  2946. canvas.setAttribute('height', h);
  2947. var ctx = canvas.getContext('2d');
  2948. if (bg != null)
  2949. {
  2950. ctx.beginPath();
  2951. ctx.rect(0, 0, w, h);
  2952. ctx.fillStyle = bg;
  2953. ctx.fill();
  2954. }
  2955. if (scale != 1)
  2956. {
  2957. ctx.scale(scale, scale);
  2958. }
  2959. function drawImage()
  2960. {
  2961. // Workaround for broken data URI images in Safari on first export
  2962. if (mxClient.IS_SF)
  2963. {
  2964. window.setTimeout(function()
  2965. {
  2966. ctx.drawImage(img, 0, 0);
  2967. callback(canvas, svgRoot);
  2968. }, 0);
  2969. }
  2970. else
  2971. {
  2972. ctx.drawImage(img, 0, 0);
  2973. callback(canvas, svgRoot);
  2974. }
  2975. };
  2976. if (grid)
  2977. {
  2978. var view = graph.view;
  2979. var curViewScale = view.scale;
  2980. view.scale = 1; //Reset the scale temporary to generate unscaled grid image which is then scaled
  2981. var gridImage = btoa(unescape(encodeURIComponent(view.createSvgGrid(view.gridColor))));
  2982. view.scale = curViewScale;
  2983. gridImage = 'data:image/svg+xml;base64,' + gridImage;
  2984. var phase = graph.gridSize * view.gridSteps * scale;
  2985. var b = graph.getGraphBounds();
  2986. var tx = view.translate.x * curViewScale;
  2987. var ty = view.translate.y * curViewScale;
  2988. var x0 = tx + (b.x - tx) / curViewScale - border;
  2989. var y0 = ty + (b.y - ty) / curViewScale - border;
  2990. var background = new Image();
  2991. background.onload = function()
  2992. {
  2993. try
  2994. {
  2995. var x = -Math.round(phase - mxUtils.mod((tx - x0) * scale, phase));
  2996. var y = -Math.round(phase - mxUtils.mod((ty - y0) * scale, phase));
  2997. for (var i = x; i < w; i += phase)
  2998. {
  2999. for (var j = y; j < h; j += phase)
  3000. {
  3001. ctx.drawImage(background, i / scale, j / scale);
  3002. }
  3003. }
  3004. drawImage();
  3005. }
  3006. catch (e)
  3007. {
  3008. if (error != null)
  3009. {
  3010. error(e);
  3011. }
  3012. }
  3013. };
  3014. background.onerror = function(e)
  3015. {
  3016. if (error != null)
  3017. {
  3018. error(e);
  3019. }
  3020. };
  3021. background.src = gridImage;
  3022. }
  3023. else
  3024. {
  3025. drawImage();
  3026. }
  3027. }
  3028. catch (e)
  3029. {
  3030. if (error != null)
  3031. {
  3032. error(e);
  3033. }
  3034. }
  3035. });
  3036. img.onerror = function(e)
  3037. {
  3038. //console.log('img', e, img.src);
  3039. if (error != null)
  3040. {
  3041. error(e);
  3042. }
  3043. };
  3044. if (addShadow)
  3045. {
  3046. this.graph.addSvgShadow(svgRoot);
  3047. }
  3048. if (this.graph.mathEnabled)
  3049. {
  3050. this.addMathCss(svgRoot);
  3051. }
  3052. var done = mxUtils.bind(this, function()
  3053. {
  3054. try
  3055. {
  3056. if (this.resolvedFontCss != null)
  3057. {
  3058. this.addFontCss(svgRoot, this.resolvedFontCss);
  3059. }
  3060. img.src = Editor.createSvgDataUri(mxUtils.getXml(svgRoot));
  3061. }
  3062. catch (e)
  3063. {
  3064. if (error != null)
  3065. {
  3066. error(e);
  3067. }
  3068. }
  3069. });
  3070. this.embedExtFonts(mxUtils.bind(this, function(extFontsEmbeddedCss)
  3071. {
  3072. try
  3073. {
  3074. if (extFontsEmbeddedCss != null)
  3075. {
  3076. this.addFontCss(svgRoot, extFontsEmbeddedCss);
  3077. }
  3078. this.loadFonts(done);
  3079. }
  3080. catch (e)
  3081. {
  3082. if (error != null)
  3083. {
  3084. error(e);
  3085. }
  3086. }
  3087. }));
  3088. }
  3089. catch (e)
  3090. {
  3091. //console.log('src', e, img.src);
  3092. if (error != null)
  3093. {
  3094. error(e);
  3095. }
  3096. }
  3097. }), imageCache, converter);
  3098. }
  3099. catch (e)
  3100. {
  3101. if (error != null)
  3102. {
  3103. error(e);
  3104. }
  3105. }
  3106. };
  3107. Editor.crcTable = [];
  3108. for (var n = 0; n < 256; n++)
  3109. {
  3110. var c = n;
  3111. for (var k = 0; k < 8; k++)
  3112. {
  3113. if ((c & 1) == 1)
  3114. {
  3115. c = 0xedb88320 ^ (c >>> 1);
  3116. }
  3117. else
  3118. {
  3119. c >>>= 1;
  3120. }
  3121. Editor.crcTable[n] = c;
  3122. }
  3123. }
  3124. Editor.updateCRC = function(crc, data, off, len)
  3125. {
  3126. var c = crc;
  3127. for (var n = 0; n < len; n++)
  3128. {
  3129. c = Editor.crcTable[(c ^ data.charCodeAt(off + n)) & 0xff] ^ (c >>> 8);
  3130. }
  3131. return c;
  3132. };
  3133. Editor.crc32 = function(str)
  3134. {
  3135. var crc = 0 ^ (-1);
  3136. for (var i = 0; i < str.length; i++ )
  3137. {
  3138. crc = (crc >>> 8) ^ Editor.crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
  3139. }
  3140. return (crc ^ (-1)) >>> 0;
  3141. };
  3142. /**
  3143. * Adds the given text to the compressed or non-compressed text chunk.
  3144. */
  3145. Editor.writeGraphModelToPng = function(data, type, key, value, error)
  3146. {
  3147. var base64 = data.substring(data.indexOf(',') + 1);
  3148. var f = (window.atob) ? atob(base64) : Base64.decode(base64, true);
  3149. var pos = 0;
  3150. function fread(d, count)
  3151. {
  3152. var start = pos;
  3153. pos += count;
  3154. return d.substring(start, pos);
  3155. };
  3156. // Reads unsigned long 32 bit big endian
  3157. function _freadint(d)
  3158. {
  3159. var bytes = fread(d, 4);
  3160. return bytes.charCodeAt(3) + (bytes.charCodeAt(2) << 8) +
  3161. (bytes.charCodeAt(1) << 16) + (bytes.charCodeAt(0) << 24);
  3162. };
  3163. function writeInt(num)
  3164. {
  3165. return String.fromCharCode((num >> 24) & 0x000000ff, (num >> 16) & 0x000000ff,
  3166. (num >> 8) & 0x000000ff, num & 0x000000ff);
  3167. };
  3168. // Checks signature
  3169. if (fread(f,8) != String.fromCharCode(137) + 'PNG' + String.fromCharCode(13, 10, 26, 10))
  3170. {
  3171. if (error != null)
  3172. {
  3173. error();
  3174. }
  3175. return;
  3176. }
  3177. // Reads header chunk
  3178. fread(f,4);
  3179. if (fread(f,4) != 'IHDR')
  3180. {
  3181. if (error != null)
  3182. {
  3183. error();
  3184. }
  3185. return;
  3186. }
  3187. fread(f, 17);
  3188. var result = f.substring(0, pos);
  3189. do
  3190. {
  3191. var n = _freadint(f);
  3192. var chunk = fread(f,4);
  3193. if (chunk == 'IDAT')
  3194. {
  3195. result = f.substring(0, pos - 8);
  3196. if (type == 'pHYs' && key == 'dpi')
  3197. {
  3198. var dpm = Math.round(value / 0.0254); //One inch is equal to exactly 0.0254 meters.
  3199. var chunkData = writeInt(dpm) + writeInt(dpm) + String.fromCharCode(1);
  3200. }
  3201. else
  3202. {
  3203. var chunkData = key + String.fromCharCode(0) +
  3204. ((type == 'zTXt') ? String.fromCharCode(0) : '') +
  3205. value;
  3206. }
  3207. var crc = 0xffffffff;
  3208. crc = Editor.updateCRC(crc, type, 0, 4);
  3209. crc = Editor.updateCRC(crc, chunkData, 0, chunkData.length);
  3210. result += writeInt(chunkData.length) + type + chunkData + writeInt(crc ^ 0xffffffff);
  3211. result += f.substring(pos - 8, f.length);
  3212. break;
  3213. }
  3214. result += f.substring(pos - 8, pos - 4 + n);
  3215. fread(f,n);
  3216. fread(f,4);
  3217. }
  3218. while (n);
  3219. return 'data:image/png;base64,' + ((window.btoa) ? btoa(result) : Base64.encode(result, true));
  3220. };
  3221. /**
  3222. * Adds persistence for recent colors
  3223. */
  3224. if (window.ColorDialog)
  3225. {
  3226. FilenameDialog.filenameHelpLink = 'https://www.diagrams.net/doc/faq/save-file-formats';
  3227. var colorDialogAddRecentColor = ColorDialog.addRecentColor;
  3228. ColorDialog.addRecentColor = function(color, max)
  3229. {
  3230. colorDialogAddRecentColor.apply(this, arguments);
  3231. mxSettings.setRecentColors(ColorDialog.recentColors);
  3232. mxSettings.save();
  3233. };
  3234. var colorDialogResetRecentColors = ColorDialog.resetRecentColors;
  3235. ColorDialog.resetRecentColors = function()
  3236. {
  3237. colorDialogResetRecentColors.apply(this, arguments);
  3238. mxSettings.setRecentColors(ColorDialog.recentColors);
  3239. mxSettings.save();
  3240. };
  3241. }
  3242. // Overrides ID for pages
  3243. if (window.EditDataDialog)
  3244. {
  3245. EditDataDialog.getDisplayIdForCell = function(ui, cell)
  3246. {
  3247. var id = null;
  3248. if (ui.editor.graph.getModel().getParent(cell) != null)
  3249. {
  3250. id = cell.getId();
  3251. }
  3252. else if (ui.currentPage != null)
  3253. {
  3254. id = ui.currentPage.getId();
  3255. }
  3256. return id;
  3257. };
  3258. }
  3259. var AddCustomPropertyDialog = function(editorUi, callback)
  3260. {
  3261. var row, td;
  3262. var table = document.createElement('table');
  3263. var tbody = document.createElement('tbody');
  3264. table.setAttribute('cellpadding', (mxClient.IS_SF) ? '0' : '2');
  3265. row = document.createElement('tr');
  3266. td = document.createElement('td');
  3267. td.style.fontSize = '10pt';
  3268. td.style.width = '100px';
  3269. mxUtils.write(td, mxResources.get('name', null, 'Name') + ':');
  3270. row.appendChild(td);
  3271. var nameInput = document.createElement('input');
  3272. nameInput.style.width = '180px';
  3273. td = document.createElement('td');
  3274. td.appendChild(nameInput);
  3275. row.appendChild(td);
  3276. tbody.appendChild(row);
  3277. row = document.createElement('tr');
  3278. td = document.createElement('td');
  3279. td.style.fontSize = '10pt';
  3280. mxUtils.write(td, mxResources.get('type', null, 'Type') + ':');
  3281. row.appendChild(td);
  3282. var typeSelect = document.createElement('select');
  3283. typeSelect.style.width = '180px';
  3284. var boolOption = document.createElement('option');
  3285. boolOption.setAttribute('value', 'bool');
  3286. mxUtils.write(boolOption, mxResources.get('bool', null, 'Boolean'));
  3287. typeSelect.appendChild(boolOption);
  3288. var clrOption = document.createElement('option');
  3289. clrOption.setAttribute('value', 'color');
  3290. mxUtils.write(clrOption, mxResources.get('color', null, 'Color'));
  3291. typeSelect.appendChild(clrOption);
  3292. var enumOption = document.createElement('option');
  3293. enumOption.setAttribute('value', 'enum');
  3294. mxUtils.write(enumOption, mxResources.get('enum', null, 'Enumeration'));
  3295. typeSelect.appendChild(enumOption);
  3296. var floatOption = document.createElement('option');
  3297. floatOption.setAttribute('value', 'float');
  3298. mxUtils.write(floatOption, mxResources.get('float', null, 'Float'));
  3299. typeSelect.appendChild(floatOption);
  3300. var intOption = document.createElement('option');
  3301. intOption.setAttribute('value', 'int');
  3302. mxUtils.write(intOption, mxResources.get('int', null, 'Int'));
  3303. typeSelect.appendChild(intOption);
  3304. var strOption = document.createElement('option');
  3305. strOption.setAttribute('value', 'string');
  3306. mxUtils.write(strOption, mxResources.get('string', null, 'String'));
  3307. typeSelect.appendChild(strOption);
  3308. td = document.createElement('td');
  3309. td.appendChild(typeSelect);
  3310. row.appendChild(td);
  3311. tbody.appendChild(row);
  3312. row = document.createElement('tr');
  3313. td = document.createElement('td');
  3314. td.style.fontSize = '10pt';
  3315. mxUtils.write(td, mxResources.get('dispName', null, 'Display Name') + ':');
  3316. row.appendChild(td);
  3317. var dispNameInput = document.createElement('input');
  3318. dispNameInput.style.width = '180px';
  3319. td = document.createElement('td');
  3320. td.appendChild(dispNameInput);
  3321. row.appendChild(td);
  3322. tbody.appendChild(row);
  3323. var listRow = document.createElement('tr');
  3324. td = document.createElement('td');
  3325. td.style.fontSize = '10pt';
  3326. mxUtils.write(td, mxResources.get('enumList', null, 'Enum List') + ' (csv):');
  3327. listRow.appendChild(td);
  3328. var enumListInput = document.createElement('input');
  3329. enumListInput.style.width = '180px';
  3330. td = document.createElement('td');
  3331. td.appendChild(enumListInput);
  3332. listRow.appendChild(td);
  3333. listRow.style.display = 'none';
  3334. tbody.appendChild(listRow);
  3335. table.appendChild(tbody);
  3336. function typeChanged()
  3337. {
  3338. if (typeSelect.value === 'enum')
  3339. {
  3340. listRow.style.display = '';
  3341. this.container.parentNode.style.height = "150px";
  3342. }
  3343. else
  3344. {
  3345. listRow.style.display = 'none';
  3346. this.container.parentNode.style.height = "130px";
  3347. }
  3348. };
  3349. mxEvent.addListener(typeSelect, 'change', mxUtils.bind(this, typeChanged));
  3350. row = document.createElement('tr');
  3351. td = document.createElement('td');
  3352. td.setAttribute('align', 'right');
  3353. td.style.paddingTop = '22px';
  3354. td.colSpan = 2;
  3355. var addBtn = mxUtils.button(mxResources.get('add', null, 'Add'), mxUtils.bind(this, function()
  3356. {
  3357. var name = nameInput.value;
  3358. if (name == "")
  3359. {
  3360. nameInput.style.border = "1px solid red";
  3361. return;
  3362. }
  3363. var type = typeSelect.value;
  3364. var dispName = dispNameInput.value;
  3365. if (dispName == "")
  3366. {
  3367. dispNameInput.style.border = "1px solid red";
  3368. return;
  3369. }
  3370. var enumList = enumListInput.value;
  3371. if (enumList == "" && type == "enum")
  3372. {
  3373. enumListInput.style.border = "1px solid red";
  3374. return;
  3375. }
  3376. if (enumList != null)
  3377. {
  3378. enumList = enumList.split(',');
  3379. for (var i = 0; i < enumList.length; i++)
  3380. {
  3381. enumList[i] = enumList[i].trim();
  3382. }
  3383. }
  3384. if (callback)
  3385. {
  3386. callback(editorUi, name, type, dispName, enumList);
  3387. editorUi.hideDialog();
  3388. }
  3389. }));
  3390. addBtn.className = 'geBtn gePrimaryBtn';
  3391. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  3392. {
  3393. editorUi.hideDialog();
  3394. });
  3395. cancelBtn.className = 'geBtn';
  3396. if (editorUi.editor.cancelFirst)
  3397. {
  3398. td.appendChild(cancelBtn);
  3399. td.appendChild(addBtn);
  3400. }
  3401. else
  3402. {
  3403. td.appendChild(addBtn);
  3404. td.appendChild(cancelBtn);
  3405. }
  3406. row.appendChild(td);
  3407. tbody.appendChild(row);
  3408. table.appendChild(tbody);
  3409. this.container = table;
  3410. };
  3411. if (window.StyleFormatPanel != null)
  3412. {
  3413. var formatInit = Format.prototype.init;
  3414. Format.prototype.init = function()
  3415. {
  3416. formatInit.apply(this, arguments);
  3417. this.editorUi.editor.addListener('fileLoaded', this.update);
  3418. };
  3419. var formatRefresh = Format.prototype.refresh;
  3420. Format.prototype.refresh = function()
  3421. {
  3422. if (this.editorUi.getCurrentFile() != null || urlParams['embed'] == '1' ||
  3423. this.editorUi.editor.chromeless)
  3424. {
  3425. formatRefresh.apply(this, arguments);
  3426. }
  3427. else
  3428. {
  3429. this.clear();
  3430. }
  3431. };
  3432. /**
  3433. * Hook for subclassers.
  3434. */
  3435. DiagramFormatPanel.prototype.isShadowOptionVisible = function()
  3436. {
  3437. var file = this.editorUi.getCurrentFile();
  3438. return urlParams['embed'] == '1' || (file != null && file.isEditable());
  3439. };
  3440. /**
  3441. * Option is not visible in default theme.
  3442. */
  3443. DiagramFormatPanel.prototype.isMathOptionVisible = function(div)
  3444. {
  3445. return false;
  3446. };
  3447. /**
  3448. * Add global shadow option.
  3449. */
  3450. var diagramFormatPanelAddView = DiagramFormatPanel.prototype.addView;
  3451. DiagramFormatPanel.prototype.addView = function(div)
  3452. {
  3453. var div = diagramFormatPanelAddView.apply(this, arguments);
  3454. var file = this.editorUi.getCurrentFile();
  3455. if (mxClient.IS_SVG && this.isShadowOptionVisible())
  3456. {
  3457. var ui = this.editorUi;
  3458. var editor = ui.editor;
  3459. var graph = editor.graph;
  3460. var option = this.createOption(mxResources.get('shadow'), function()
  3461. {
  3462. return graph.shadowVisible;
  3463. }, function(checked)
  3464. {
  3465. var change = new ChangePageSetup(ui);
  3466. change.ignoreColor = true;
  3467. change.ignoreImage = true;
  3468. change.shadowVisible = checked;
  3469. graph.model.execute(change);
  3470. },
  3471. {
  3472. install: function(apply)
  3473. {
  3474. this.listener = function()
  3475. {
  3476. apply(graph.shadowVisible);
  3477. };
  3478. ui.addListener('shadowVisibleChanged', this.listener);
  3479. },
  3480. destroy: function()
  3481. {
  3482. ui.removeListener(this.listener);
  3483. }
  3484. });
  3485. if (!Editor.enableShadowOption)
  3486. {
  3487. option.getElementsByTagName('input')[0].setAttribute('disabled', 'disabled');
  3488. mxUtils.setOpacity(option, 60);
  3489. }
  3490. div.appendChild(option);
  3491. }
  3492. return div;
  3493. };
  3494. /**
  3495. * Adds autosave and math typesetting options.
  3496. */
  3497. var diagramFormatPanelAddOptions = DiagramFormatPanel.prototype.addOptions;
  3498. DiagramFormatPanel.prototype.addOptions = function(div)
  3499. {
  3500. div = diagramFormatPanelAddOptions.apply(this, arguments);
  3501. var ui = this.editorUi;
  3502. var editor = ui.editor;
  3503. var graph = editor.graph;
  3504. if (graph.isEnabled())
  3505. {
  3506. var file = ui.getCurrentFile();
  3507. if (file != null && file.isAutosaveOptional())
  3508. {
  3509. var opt = this.createOption(mxResources.get('autosave'), function()
  3510. {
  3511. return ui.editor.autosave;
  3512. }, function(checked)
  3513. {
  3514. ui.editor.setAutosave(checked);
  3515. if (ui.editor.autosave && file.isModified())
  3516. {
  3517. file.fileChanged();
  3518. }
  3519. },
  3520. {
  3521. install: function(apply)
  3522. {
  3523. this.listener = function()
  3524. {
  3525. apply(ui.editor.autosave);
  3526. };
  3527. ui.editor.addListener('autosaveChanged', this.listener);
  3528. },
  3529. destroy: function()
  3530. {
  3531. ui.editor.removeListener(this.listener);
  3532. }
  3533. });
  3534. div.appendChild(opt);
  3535. }
  3536. }
  3537. if (this.isMathOptionVisible() && graph.isEnabled() && typeof(MathJax) !== 'undefined')
  3538. {
  3539. // Math
  3540. var option = this.createOption(mxResources.get('mathematicalTypesetting'), function()
  3541. {
  3542. return graph.mathEnabled;
  3543. }, function(checked)
  3544. {
  3545. ui.actions.get('mathematicalTypesetting').funct();
  3546. },
  3547. {
  3548. install: function(apply)
  3549. {
  3550. this.listener = function()
  3551. {
  3552. apply(graph.mathEnabled);
  3553. };
  3554. ui.addListener('mathEnabledChanged', this.listener);
  3555. },
  3556. destroy: function()
  3557. {
  3558. ui.removeListener(this.listener);
  3559. }
  3560. });
  3561. option.style.paddingTop = '5px';
  3562. div.appendChild(option);
  3563. var help = ui.menus.createHelpLink('https://www.diagrams.net/doc/faq/math-typesetting');
  3564. help.style.position = 'relative';
  3565. help.style.marginLeft = '6px';
  3566. help.style.top = '2px';
  3567. option.appendChild(help);
  3568. }
  3569. return div;
  3570. };
  3571. mxCellRenderer.prototype.defaultVertexShape.prototype.customProperties = [
  3572. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  3573. {name: 'absoluteArcSize', dispName: 'Abs. Arc Size', type: 'bool', defVal: false}
  3574. ];
  3575. mxCellRenderer.defaultShapes['link'].prototype.customProperties = [
  3576. {name: 'width', dispName: 'Width', type: 'float', min:0, defVal: 4}
  3577. ];
  3578. mxCellRenderer.defaultShapes['flexArrow'].prototype.customProperties = [
  3579. {name: 'width', dispName: 'Width', type: 'float', min:0, defVal: 10},
  3580. {name: 'startWidth', dispName: 'Start Width', type: 'float', min:0, defVal: 20},
  3581. {name: 'endWidth', dispName: 'End Width', type: 'float', min:0, defVal: 20}
  3582. ];
  3583. mxCellRenderer.defaultShapes['process'].prototype.customProperties = [
  3584. {name: 'size', dispName: 'Indent', type: 'float', min: 0, max: 0.5, defVal: 0.1}
  3585. ];
  3586. mxCellRenderer.defaultShapes['rhombus'].prototype.customProperties = [
  3587. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, max: 50, defVal: mxConstants.LINE_ARCSIZE},
  3588. {name: 'double', dispName: 'Double', type: 'bool', defVal: false}
  3589. ];
  3590. mxCellRenderer.defaultShapes['partialRectangle'].prototype.customProperties = [
  3591. {name: 'top', dispName: 'Top Line', type: 'bool', defVal: true},
  3592. {name: 'bottom', dispName: 'Bottom Line', type: 'bool', defVal: true},
  3593. {name: 'left', dispName: 'Left Line', type: 'bool', defVal: true},
  3594. {name: 'right', dispName: 'Right Line', type: 'bool', defVal: true}
  3595. ];
  3596. mxCellRenderer.defaultShapes['parallelogram'].prototype.customProperties = [
  3597. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  3598. {name: 'size', dispName: 'Slope Angle', type: 'float', min:0, max: 1, defVal: 0.2}
  3599. ];
  3600. mxCellRenderer.defaultShapes['hexagon'].prototype.customProperties = [
  3601. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  3602. {name: 'size', dispName: 'Slope Angle', type: 'float', min:0, max: 1, defVal: 0.25}
  3603. ];
  3604. mxCellRenderer.defaultShapes['triangle'].prototype.customProperties = [
  3605. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE}
  3606. ];
  3607. mxCellRenderer.defaultShapes['document'].prototype.customProperties = [
  3608. {name: 'size', dispName: 'Size', type: 'float', defVal: 0.3, min:0, max:1}
  3609. ];
  3610. mxCellRenderer.defaultShapes['internalStorage'].prototype.customProperties = [
  3611. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  3612. {name: 'dx', dispName: 'Left Line', type: 'float', min:0, defVal: 20},
  3613. {name: 'dy', dispName: 'Top Line', type: 'float', min:0, defVal: 20}
  3614. ];
  3615. mxCellRenderer.defaultShapes['cube'].prototype.customProperties = [
  3616. {name: 'size', dispName: 'Size', type: 'float', min:0, defVal:20 },
  3617. {name: 'darkOpacity', dispName: 'Dark Opacity', type: 'float', min:-1, max:1, defVal:0 },
  3618. {name: 'darkOpacity2', dispName: 'Dark Opacity 2', type: 'float', min:-1, max:1, defVal:0 }
  3619. ];
  3620. mxCellRenderer.defaultShapes['step'].prototype.customProperties = [
  3621. {name: 'size', dispName: 'Notch Size', type: 'float', min:0, defVal:20},
  3622. {name: 'fixedSize', dispName: 'Fixed Size', type: 'bool', defVal:true}
  3623. ];
  3624. mxCellRenderer.defaultShapes['trapezoid'].prototype.customProperties = [
  3625. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  3626. {name: 'size', dispName: 'Slope Angle', type: 'float', min:0, max: 1, defVal: 0.2}
  3627. ];
  3628. mxCellRenderer.defaultShapes['tape'].prototype.customProperties = [
  3629. {name: 'size', dispName: 'Size', type: 'float', min:0, max:1, defVal:0.4 }
  3630. ];
  3631. mxCellRenderer.defaultShapes['note'].prototype.customProperties = [
  3632. {name: 'size', dispName: 'Fold Size', type: 'float', min:0, defVal: 30},
  3633. {name: 'darkOpacity', dispName: 'Dark Opacity', type: 'float', min:-1, max:1, defVal:0 },
  3634. ];
  3635. mxCellRenderer.defaultShapes['card'].prototype.customProperties = [
  3636. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  3637. {name: 'size', dispName: 'Cutoff Size', type: 'float', min:0, defVal: 30}
  3638. ];
  3639. mxCellRenderer.defaultShapes['callout'].prototype.customProperties = [
  3640. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: mxConstants.LINE_ARCSIZE},
  3641. {name: 'base', dispName: 'Callout Width', type: 'float', min:0, defVal: 20},
  3642. {name: 'size', dispName: 'Callout Length', type: 'float', min:0, defVal: 30},
  3643. {name: 'position', dispName: 'Callout Position', type: 'float', min:0, max:1, defVal: 0.5},
  3644. {name: 'position2', dispName: 'Callout Tip Position', type: 'float', min:0, max:1, defVal: 0.5}
  3645. ];
  3646. mxCellRenderer.defaultShapes['folder'].prototype.customProperties = [
  3647. {name: 'tabWidth', dispName: 'Tab Width', type: 'float'},
  3648. {name: 'tabHeight', dispName: 'Tab Height', type: 'float'},
  3649. {name: 'tabPosition', dispName: 'Tap Position', type: 'enum',
  3650. enumList: [{val: 'left', dispName: 'Left'}, {val: 'right', dispName: 'Right'}]
  3651. }
  3652. ];
  3653. mxCellRenderer.defaultShapes['swimlane'].prototype.customProperties = [
  3654. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 15},
  3655. {name: 'startSize', dispName: 'Header Size', type: 'float'},
  3656. {name: 'swimlaneHead', dispName: 'Head Border', type: 'bool', defVal: true},
  3657. {name: 'swimlaneBody', dispName: 'Body Border', type: 'bool', defVal: true},
  3658. {name: 'horizontal', dispName: 'Horizontal', type: 'bool', defVal: true},
  3659. {name: 'separatorColor', dispName: 'Separator Color', type: 'color', defVal: null},
  3660. ];
  3661. mxCellRenderer.defaultShapes['table'].prototype.customProperties = [
  3662. {name: 'rowLines', dispName: 'Row Lines', type: 'bool', defVal: true},
  3663. {name: 'columnLines', dispName: 'Column Lines', type: 'bool', defVal: true},
  3664. {name: 'fixedRows', dispName: 'Fixed Rows', type: 'bool', defVal: false},
  3665. {name: 'resizeLast', dispName: 'Resize Last Column', type: 'bool', defVal: false},
  3666. {name: 'resizeLastRow', dispName: 'Resize Last Row', type: 'bool', defVal: false}].
  3667. concat(mxCellRenderer.defaultShapes['swimlane'].prototype.customProperties).
  3668. concat(mxCellRenderer.defaultShapes['partialRectangle'].prototype.customProperties);
  3669. mxCellRenderer.defaultShapes['tableRow'].prototype.customProperties =
  3670. mxCellRenderer.defaultShapes['swimlane'].prototype.customProperties.
  3671. concat(mxCellRenderer.defaultShapes['partialRectangle'].prototype.customProperties);
  3672. mxCellRenderer.defaultShapes['doubleEllipse'].prototype.customProperties = [
  3673. {name: 'margin', dispName: 'Indent', type: 'float', min:0, defVal:4}
  3674. ];
  3675. mxCellRenderer.defaultShapes['ext'].prototype.customProperties = [
  3676. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 15},
  3677. {name: 'double', dispName: 'Double', type: 'bool', defVal: false},
  3678. {name: 'margin', dispName: 'Indent', type: 'float', min: 0, defVal:0}
  3679. ];
  3680. mxCellRenderer.defaultShapes['curlyBracket'].prototype.customProperties = [
  3681. {name: 'rounded', dispName: 'Rounded', type: 'bool', defVal: true},
  3682. {name: 'size', dispName: 'Size', type: 'float', min:0, max: 1, defVal: 0.5}
  3683. ];
  3684. mxCellRenderer.defaultShapes['image'].prototype.customProperties = [
  3685. {name: 'imageAspect', dispName: 'Fixed Image Aspect', type: 'bool', defVal:true}
  3686. ];
  3687. mxCellRenderer.defaultShapes['label'].prototype.customProperties = [
  3688. {name: 'imageAspect', dispName: 'Fixed Image Aspect', type: 'bool', defVal:true},
  3689. {name: 'imageAlign', dispName: 'Image Align', type: 'enum',
  3690. enumList: [{val: 'left', dispName: 'Left'},
  3691. {val: 'center', dispName: 'Center'},
  3692. {val: 'right', dispName: 'Right'}], defVal: 'left'},
  3693. {name: 'imageVerticalAlign', dispName: 'Image Vertical Align', type: 'enum',
  3694. enumList: [{val: 'top', dispName: 'Top'},
  3695. {val: 'middle', dispName: 'Middle'},
  3696. {val: 'bottom', dispName: 'Bottom'}], defVal: 'middle'},
  3697. {name: 'imageWidth', dispName: 'Image Width', type: 'float', min:0, defVal: 24},
  3698. {name: 'imageHeight', dispName: 'Image Height', type: 'float', min:0, defVal: 24},
  3699. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 12},
  3700. {name: 'absoluteArcSize', dispName: 'Abs. Arc Size', type: 'bool', defVal: false}
  3701. ];
  3702. mxCellRenderer.defaultShapes['dataStorage'].prototype.customProperties = [
  3703. {name: 'size', dispName: 'Size', type: 'float', min:0, max:1, defVal:0.1 }
  3704. ];
  3705. mxCellRenderer.defaultShapes['manualInput'].prototype.customProperties = [
  3706. {name: 'size', dispName: 'Size', type: 'float', min:0, defVal:30 },
  3707. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 20}
  3708. ];
  3709. mxCellRenderer.defaultShapes['loopLimit'].prototype.customProperties = [
  3710. {name: 'size', dispName: 'Size', type: 'float', min:0, defVal:20 },
  3711. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 20}
  3712. ];
  3713. mxCellRenderer.defaultShapes['offPageConnector'].prototype.customProperties = [
  3714. {name: 'size', dispName: 'Size', type: 'float', min:0, defVal:38 },
  3715. {name: 'arcSize', dispName: 'Arc Size', type: 'float', min:0, defVal: 20}
  3716. ];
  3717. mxCellRenderer.defaultShapes['display'].prototype.customProperties = [
  3718. {name: 'size', dispName: 'Size', type: 'float', min: 0, max: 1, defVal: 0.25 }
  3719. ];
  3720. mxCellRenderer.defaultShapes['singleArrow'].prototype.customProperties = [
  3721. {name: 'arrowWidth', dispName: 'Arrow Width', type: 'float', min: 0, max: 1, defVal: 0.3 },
  3722. {name: 'arrowSize', dispName: 'Arrowhead Length', type: 'float', min: 0, max: 1, defVal: 0.2 }
  3723. ];
  3724. mxCellRenderer.defaultShapes['doubleArrow'].prototype.customProperties = [
  3725. {name: 'arrowWidth', dispName: 'Arrow Width', type: 'float', min: 0, max: 1, defVal: 0.3 },
  3726. {name: 'arrowSize', dispName: 'Arrowhead Length', type: 'float', min: 0, max: 1, defVal: 0.2 }
  3727. ];
  3728. mxCellRenderer.defaultShapes['cross'].prototype.customProperties = [
  3729. {name: 'size', dispName: 'Size', type: 'float', min: 0, max: 1, defVal: 0.2 }
  3730. ];
  3731. mxCellRenderer.defaultShapes['corner'].prototype.customProperties = [
  3732. {name: 'dx', dispName: 'Width1', type: 'float', min: 0, defVal: 20 },
  3733. {name: 'dy', dispName: 'Width2', type: 'float', min: 0, defVal: 20 }
  3734. ];
  3735. mxCellRenderer.defaultShapes['tee'].prototype.customProperties = [
  3736. {name: 'dx', dispName: 'Width1', type: 'float', min: 0, defVal: 20 },
  3737. {name: 'dy', dispName: 'Width2', type: 'float', min: 0, defVal: 20 }
  3738. ];
  3739. mxCellRenderer.defaultShapes['umlLifeline'].prototype.customProperties = [
  3740. {name: 'participant', dispName:'Participant', type:'enum', defVal:'none', enumList:[
  3741. {val:'none', dispName: 'Default'},
  3742. {val:'umlActor', dispName: 'Actor'},
  3743. {val:'umlBoundary', dispName: 'Boundary'},
  3744. {val:'umlEntity', dispName: 'Entity'},
  3745. {val:'umlControl', dispName: 'Control'},
  3746. ]},
  3747. {name: 'size', dispName:'Height', type:'float', defVal:40, min:0}
  3748. ];
  3749. mxCellRenderer.defaultShapes['umlFrame'].prototype.customProperties = [
  3750. {name: 'width', dispName:'Title Width', type:'float', defVal:60, min:0},
  3751. {name: 'height', dispName:'Title Height', type:'float', defVal:30, min:0}
  3752. ];
  3753. /**
  3754. * Configures global color schemes.
  3755. */
  3756. StyleFormatPanel.prototype.defaultColorSchemes = [[{fill: '', stroke: ''}, {fill: '#f5f5f5', stroke: '#666666', font: '#333333'},
  3757. {fill: '#dae8fc', stroke: '#6c8ebf'}, {fill: '#d5e8d4', stroke: '#82b366'},
  3758. {fill: '#ffe6cc', stroke: '#d79b00'}, {fill: '#fff2cc', stroke: '#d6b656'},
  3759. {fill: '#f8cecc', stroke: '#b85450'}, {fill: '#e1d5e7', stroke: '#9673a6'}],
  3760. [{fill: '', stroke: ''}, {fill: '#60a917', stroke: '#2D7600', font: '#ffffff'},
  3761. {fill: '#008a00', stroke: '#005700', font: '#ffffff'}, {fill: '#1ba1e2', stroke: '#006EAF', font: '#ffffff'},
  3762. {fill: '#0050ef', stroke: '#001DBC', font: '#ffffff'}, {fill: '#6a00ff', stroke: '#3700CC', font: '#ffffff'},
  3763. //{fill: '#aa00ff', stroke: '#7700CC', font: '#ffffff'},
  3764. {fill: '#d80073', stroke: '#A50040', font: '#ffffff'}, {fill: '#a20025', stroke: '#6F0000', font: '#ffffff'}],
  3765. [{fill: '#e51400', stroke: '#B20000', font: '#ffffff'}, {fill: '#fa6800', stroke: '#C73500', font: '#000000'},
  3766. {fill: '#f0a30a', stroke: '#BD7000', font: '#000000'}, {fill: '#e3c800', stroke: '#B09500', font: '#000000'},
  3767. {fill: '#6d8764', stroke: '#3A5431', font: '#ffffff'}, {fill: '#647687', stroke: '#314354', font: '#ffffff'},
  3768. {fill: '#76608a', stroke: '#432D57', font: '#ffffff'}, {fill: '#a0522d', stroke: '#6D1F00', font: '#ffffff'}],
  3769. [{fill: '', stroke: ''}, {fill: mxConstants.NONE, stroke: ''},
  3770. {fill: '#fad7ac', stroke: '#b46504'}, {fill: '#fad9d5', stroke: '#ae4132'},
  3771. {fill: '#b0e3e6', stroke: '#0e8088'}, {fill: '#b1ddf0', stroke: '#10739e'},
  3772. {fill: '#d0cee2', stroke: '#56517e'}, {fill: '#bac8d3', stroke: '#23445d'}],
  3773. [{fill: '', stroke: ''},
  3774. {fill: '#f5f5f5', stroke: '#666666', gradient: '#b3b3b3'},
  3775. {fill: '#dae8fc', stroke: '#6c8ebf', gradient: '#7ea6e0'},
  3776. {fill: '#d5e8d4', stroke: '#82b366', gradient: '#97d077'},
  3777. {fill: '#ffcd28', stroke: '#d79b00', gradient: '#ffa500'},
  3778. {fill: '#fff2cc', stroke: '#d6b656', gradient: '#ffd966'},
  3779. {fill: '#f8cecc', stroke: '#b85450', gradient: '#ea6b66'},
  3780. {fill: '#e6d0de', stroke: '#996185', gradient: '#d5739d'}],
  3781. [{fill: '', stroke: ''}, {fill: '#eeeeee', stroke: '#36393d'},
  3782. {fill: '#f9f7ed', stroke: '#36393d'}, {fill: '#ffcc99', stroke: '#36393d'},
  3783. {fill: '#cce5ff', stroke: '#36393d'}, {fill: '#ffff88', stroke: '#36393d'},
  3784. {fill: '#cdeb8b', stroke: '#36393d'}, {fill: '#ffcccc', stroke: '#36393d'}]];
  3785. /**
  3786. * Configures custom color schemes.
  3787. */
  3788. StyleFormatPanel.prototype.customColorSchemes = null;
  3789. StyleFormatPanel.prototype.findCommonProperties = function(cell, properties, addAll)
  3790. {
  3791. if (properties == null) return;
  3792. var handleCustomProp = function(custProperties)
  3793. {
  3794. if (custProperties != null)
  3795. {
  3796. if (addAll)
  3797. {
  3798. for (var i = 0; i < custProperties.length; i++)
  3799. {
  3800. properties[custProperties[i].name] = custProperties[i];
  3801. }
  3802. }
  3803. else
  3804. {
  3805. for (var key in properties)
  3806. {
  3807. var found = false;
  3808. for (var i = 0; i < custProperties.length; i++)
  3809. {
  3810. if (custProperties[i].name == key && custProperties[i].type == properties[key].type)
  3811. {
  3812. found = true;
  3813. break;
  3814. }
  3815. }
  3816. if (!found)
  3817. {
  3818. delete properties[key];
  3819. }
  3820. }
  3821. }
  3822. }
  3823. };
  3824. var view = this.editorUi.editor.graph.view;
  3825. var state = view.getState(cell);
  3826. if (state != null && state.shape != null)
  3827. {
  3828. //Add common properties to all shapes
  3829. if (!state.shape.commonCustomPropAdded)
  3830. {
  3831. state.shape.commonCustomPropAdded = true;
  3832. state.shape.customProperties = state.shape.customProperties || [];
  3833. if (state.cell.vertex)
  3834. {
  3835. Array.prototype.push.apply(state.shape.customProperties, Editor.commonVertexProperties);
  3836. }
  3837. else
  3838. {
  3839. Array.prototype.push.apply(state.shape.customProperties, Editor.commonEdgeProperties);
  3840. }
  3841. }
  3842. handleCustomProp(state.shape.customProperties);
  3843. }
  3844. //This currently is not needed but let's keep it in case we needed in the future
  3845. var userCustomProp = cell.getAttribute('customProperties');
  3846. if (userCustomProp != null)
  3847. {
  3848. try
  3849. {
  3850. handleCustomProp(JSON.parse(userCustomProp));
  3851. }
  3852. catch(e){}
  3853. }
  3854. };
  3855. /**
  3856. * Adds predefiend styles.
  3857. */
  3858. var styleFormatPanelInit = StyleFormatPanel.prototype.init;
  3859. StyleFormatPanel.prototype.init = function()
  3860. {
  3861. var sstate = this.editorUi.getSelectionState();
  3862. if (sstate.style.shape != 'image' && !sstate.containsLabel && sstate.cells.length > 0)
  3863. {
  3864. this.container.appendChild(this.addStyles(this.createPanel()));
  3865. }
  3866. styleFormatPanelInit.apply(this, arguments);
  3867. if (Editor.enableCustomProperties)
  3868. {
  3869. var properties = {};
  3870. var vertices = sstate.vertices;
  3871. var edges = sstate.edges;
  3872. for (var i = 0; i < vertices.length; i++)
  3873. {
  3874. this.findCommonProperties(vertices[i], properties, i == 0);
  3875. }
  3876. for (var i = 0; i < edges.length; i++)
  3877. {
  3878. this.findCommonProperties(edges[i], properties, vertices.length == 0 && i == 0);
  3879. }
  3880. if (Object.getOwnPropertyNames != null && Object.getOwnPropertyNames(properties).length > 0)
  3881. {
  3882. this.container.appendChild(this.addProperties(this.createPanel(), properties, sstate));
  3883. }
  3884. }
  3885. };
  3886. /**
  3887. * Overridden to add copy and paste style.
  3888. */
  3889. var styleFormatPanelAddStyleOps = StyleFormatPanel.prototype.addStyleOps;
  3890. StyleFormatPanel.prototype.addStyleOps = function(div)
  3891. {
  3892. this.addActions(div, ['copyStyle', 'pasteStyle']);
  3893. return styleFormatPanelAddStyleOps.apply(this, arguments);
  3894. };
  3895. /**
  3896. * Initial collapsed state of the properties panel.
  3897. */
  3898. EditorUi.prototype.propertiesCollapsed = true;
  3899. /**
  3900. * Create Properties Panel
  3901. */
  3902. StyleFormatPanel.prototype.addProperties = function(div, properties, state)
  3903. {
  3904. var that = this;
  3905. var graph = this.editorUi.editor.graph;
  3906. var secondLevel = [];
  3907. function insertAfter(newElem, curElem)
  3908. {
  3909. curElem.parentNode.insertBefore(newElem, curElem.nextSibling);
  3910. };
  3911. function applyStyleVal(pName, newVal, prop, delIndex)
  3912. {
  3913. graph.getModel().beginUpdate();
  3914. try
  3915. {
  3916. var changedProps = [];
  3917. var changedVals = [];
  3918. if (prop.index != null)
  3919. {
  3920. var allVals = [];
  3921. var curVal = prop.parentRow.nextSibling;
  3922. while(curVal && curVal.getAttribute('data-pName') == pName)
  3923. {
  3924. allVals.push(curVal.getAttribute('data-pValue'));
  3925. curVal = curVal.nextSibling;
  3926. }
  3927. if (prop.index < allVals.length)
  3928. {
  3929. if (delIndex != null)
  3930. {
  3931. allVals.splice(delIndex, 1);
  3932. }
  3933. else
  3934. {
  3935. allVals[prop.index] = newVal;
  3936. }
  3937. }
  3938. else
  3939. {
  3940. allVals.push(newVal);
  3941. }
  3942. if (prop.size != null && allVals.length > prop.size) //trim the array to the specifies size
  3943. {
  3944. allVals = allVals.slice(0, prop.size);
  3945. }
  3946. newVal = allVals.join(',');
  3947. if (prop.countProperty != null)
  3948. {
  3949. graph.setCellStyles(prop.countProperty, allVals.length, graph.getSelectionCells());
  3950. changedProps.push(prop.countProperty);
  3951. changedVals.push(allVals.length);
  3952. }
  3953. }
  3954. graph.setCellStyles(pName, newVal, graph.getSelectionCells());
  3955. changedProps.push(pName);
  3956. changedVals.push(newVal);
  3957. if (prop.dependentProps != null)
  3958. {
  3959. for (var i = 0; i < prop.dependentProps.length; i++)
  3960. {
  3961. var defVal = prop.dependentPropsDefVal[i];
  3962. var vals = prop.dependentPropsVals[i];
  3963. if (vals.length > newVal)
  3964. {
  3965. vals = vals.slice(0, newVal);
  3966. }
  3967. else
  3968. {
  3969. for (var j = vals.length; j < newVal; j++)
  3970. {
  3971. vals.push(defVal);
  3972. }
  3973. }
  3974. vals = vals.join(',');
  3975. graph.setCellStyles(prop.dependentProps[i], vals, graph.getSelectionCells());
  3976. changedProps.push(prop.dependentProps[i]);
  3977. changedVals.push(vals);
  3978. }
  3979. }
  3980. if (typeof(prop.onChange) == 'function')
  3981. {
  3982. prop.onChange(graph, newVal);
  3983. }
  3984. that.editorUi.fireEvent(new mxEventObject('styleChanged', 'keys', changedProps,
  3985. 'values', changedVals, 'cells', graph.getSelectionCells()));
  3986. }
  3987. finally
  3988. {
  3989. graph.getModel().endUpdate();
  3990. }
  3991. }
  3992. function setElementPos(td, elem, adjustHeight)
  3993. {
  3994. var divPos = mxUtils.getOffset(div, true);
  3995. var pos = mxUtils.getOffset(td, true);
  3996. elem.style.position = 'absolute';
  3997. elem.style.left = (pos.x - divPos.x) + 'px';
  3998. elem.style.top = (pos.y - divPos.y) + 'px';
  3999. elem.style.width = td.offsetWidth + 'px';
  4000. elem.style.height = (td.offsetHeight - (adjustHeight? 4 : 0)) + 'px';
  4001. elem.style.zIndex = 5;
  4002. };
  4003. function createColorBtn(pName, pValue, prop)
  4004. {
  4005. var clrDiv = document.createElement('div');
  4006. clrDiv.style.width = '32px';
  4007. clrDiv.style.height = '4px';
  4008. clrDiv.style.margin = '2px';
  4009. clrDiv.style.border = '1px solid black';
  4010. clrDiv.style.background = !pValue || pValue == 'none'? 'url(\'' + Dialog.prototype.noColorImage + '\')' : pValue;
  4011. btn = mxUtils.button('', mxUtils.bind(that, function(evt)
  4012. {
  4013. this.editorUi.pickColor(pValue, function(color)
  4014. {
  4015. clrDiv.style.background = color == 'none'? 'url(\'' + Dialog.prototype.noColorImage + '\')' : color;
  4016. applyStyleVal(pName, color, prop);
  4017. });
  4018. mxEvent.consume(evt);
  4019. }));
  4020. btn.style.height = '12px';
  4021. btn.style.width = '40px';
  4022. btn.className = 'geColorBtn';
  4023. btn.appendChild(clrDiv);
  4024. return btn;
  4025. };
  4026. function createDynArrList(pName, pValue, subType, defVal, countProperty, myRow, flipBkg)
  4027. {
  4028. if (pValue != null)
  4029. {
  4030. var vals = pValue.split(',');
  4031. secondLevel.push({name: pName, values: vals, type: subType, defVal: defVal, countProperty: countProperty, parentRow: myRow, isDeletable: true, flipBkg: flipBkg});
  4032. }
  4033. btn = mxUtils.button('+', mxUtils.bind(that, function(evt)
  4034. {
  4035. var beforeElem = myRow;
  4036. var index = 0;
  4037. while (beforeElem.nextSibling != null)
  4038. {
  4039. var cur = beforeElem.nextSibling;
  4040. var elemPName = cur.getAttribute('data-pName');
  4041. if (elemPName == pName)
  4042. {
  4043. beforeElem = beforeElem.nextSibling;
  4044. index++;
  4045. }
  4046. else
  4047. {
  4048. break;
  4049. }
  4050. }
  4051. var newProp = {type: subType, parentRow: myRow, index: index, isDeletable: true, defVal: defVal, countProperty: countProperty};
  4052. var arrItem = createPropertyRow(pName, '', newProp, index % 2 == 0, flipBkg);
  4053. applyStyleVal(pName, defVal, newProp);
  4054. insertAfter(arrItem, beforeElem);
  4055. mxEvent.consume(evt);
  4056. }));
  4057. btn.style.height = '16px';
  4058. btn.style.width = '25px';
  4059. btn.className = 'geColorBtn';
  4060. return btn;
  4061. };
  4062. function createStaticArrList(pName, pValue, subType, defVal, size, myRow, flipBkg)
  4063. {
  4064. if (size > 0)
  4065. {
  4066. var vals = new Array(size);
  4067. var curVals = pValue != null? pValue.split(',') : [];
  4068. for (var i = 0; i < size; i++)
  4069. {
  4070. vals[i] = curVals[i] != null? curVals[i] : (defVal != null? defVal : '');
  4071. }
  4072. secondLevel.push({name: pName, values: vals, type: subType, defVal: defVal, parentRow: myRow, flipBkg: flipBkg, size: size});
  4073. }
  4074. return document.createElement('div'); //empty cell
  4075. };
  4076. function createCheckbox(pName, pValue, prop)
  4077. {
  4078. var input = document.createElement('input');
  4079. input.type = 'checkbox';
  4080. input.checked = pValue == '1';
  4081. mxEvent.addListener(input, 'change', function()
  4082. {
  4083. applyStyleVal(pName, input.checked? '1' : '0', prop);
  4084. });
  4085. return input;
  4086. };
  4087. function createPropertyRow(pName, pValue, prop, isOdd, flipBkg)
  4088. {
  4089. var pDiplayName = prop.dispName;
  4090. var pType = prop.type;
  4091. var row = document.createElement('tr');
  4092. row.className = 'gePropRow' + (flipBkg? 'Dark' : '') + (isOdd? 'Alt' : '') + ' gePropNonHeaderRow';
  4093. row.setAttribute('data-pName', pName);
  4094. row.setAttribute('data-pValue', pValue);
  4095. var rightAlig = false;
  4096. if (prop.index != null)
  4097. {
  4098. row.setAttribute('data-index', prop.index);
  4099. pDiplayName = (pDiplayName != null? pDiplayName : '') + '[' + prop.index + ']';
  4100. rightAlig = true;
  4101. }
  4102. var td = document.createElement('td');
  4103. td.className = 'gePropRowCell';
  4104. var label = mxResources.get(pDiplayName, null, pDiplayName);
  4105. mxUtils.write(td, label);
  4106. td.setAttribute('title', label);
  4107. if (rightAlig)
  4108. {
  4109. td.style.textAlign = 'right';
  4110. }
  4111. row.appendChild(td);
  4112. td = document.createElement('td');
  4113. td.className = 'gePropRowCell';
  4114. if (pType == 'color')
  4115. {
  4116. td.appendChild(createColorBtn(pName, pValue, prop));
  4117. }
  4118. else if (pType == 'bool' || pType == 'boolean')
  4119. {
  4120. td.appendChild(createCheckbox(pName, pValue, prop));
  4121. }
  4122. else if (pType == 'enum')
  4123. {
  4124. var pEnumList = prop.enumList;
  4125. for (var i = 0; i < pEnumList.length; i++)
  4126. {
  4127. var op = pEnumList[i];
  4128. if (op.val == pValue)
  4129. {
  4130. mxUtils.write(td, mxResources.get(op.dispName, null, op.dispName));
  4131. break;
  4132. }
  4133. }
  4134. mxEvent.addListener(td, 'click', mxUtils.bind(that, function()
  4135. {
  4136. var select = document.createElement('select');
  4137. setElementPos(td, select);
  4138. for (var i = 0; i < pEnumList.length; i++)
  4139. {
  4140. var op = pEnumList[i];
  4141. var opElem = document.createElement('option');
  4142. opElem.value = mxUtils.htmlEntities(op.val);
  4143. mxUtils.write(opElem, mxResources.get(op.dispName, null, op.dispName));
  4144. select.appendChild(opElem);
  4145. }
  4146. select.value = pValue;
  4147. div.appendChild(select);
  4148. mxEvent.addListener(select, 'change', function()
  4149. {
  4150. var newVal = mxUtils.htmlEntities(select.value);
  4151. applyStyleVal(pName, newVal, prop);
  4152. //set value triggers a redraw of the panel which removes the select and updates the row
  4153. });
  4154. select.focus();
  4155. //FF calls blur on focus! so set the event after focusing (not with selects but to be safe)
  4156. mxEvent.addListener(select, 'blur', function()
  4157. {
  4158. div.removeChild(select);
  4159. });
  4160. }));
  4161. }
  4162. else if (pType == 'dynamicArr')
  4163. {
  4164. td.appendChild(createDynArrList(pName, pValue, prop.subType, prop.subDefVal, prop.countProperty, row, flipBkg));
  4165. }
  4166. else if (pType == 'staticArr')
  4167. {
  4168. td.appendChild(createStaticArrList(pName, pValue, prop.subType, prop.subDefVal, prop.size, row, flipBkg));
  4169. }
  4170. else if (pType == 'readOnly')
  4171. {
  4172. var inp = document.createElement('input');
  4173. inp.setAttribute('readonly', '');
  4174. inp.value = pValue;
  4175. inp.style.width = '96px';
  4176. inp.style.borderWidth = '0px';
  4177. td.appendChild(inp);
  4178. }
  4179. else
  4180. {
  4181. td.innerHTML = mxUtils.htmlEntities(decodeURIComponent(pValue));
  4182. mxEvent.addListener(td, 'click', mxUtils.bind(that, function()
  4183. {
  4184. var input = document.createElement('input');
  4185. setElementPos(td, input, true);
  4186. input.value = decodeURIComponent(pValue);
  4187. input.className = 'gePropEditor';
  4188. if ((pType == 'int' || pType == 'float') && !prop.allowAuto)
  4189. {
  4190. input.type = 'number';
  4191. input.step = pType == 'int'? '1' : 'any';
  4192. if (prop.min != null)
  4193. {
  4194. input.min = parseFloat(prop.min);
  4195. }
  4196. if (prop.max != null)
  4197. {
  4198. input.max = parseFloat(prop.max);
  4199. }
  4200. }
  4201. div.appendChild(input);
  4202. function setInputVal()
  4203. {
  4204. var inputVal = input.value;
  4205. inputVal = inputVal.length == 0 && pType != 'string'? 0 : inputVal;
  4206. if (prop.allowAuto)
  4207. {
  4208. if (inputVal.trim != null && inputVal.trim().toLowerCase() == 'auto')
  4209. {
  4210. inputVal = 'auto';
  4211. pType = 'string';
  4212. }
  4213. else
  4214. {
  4215. inputVal = parseFloat(inputVal);
  4216. inputVal = isNaN(inputVal)? 0 : inputVal;
  4217. }
  4218. }
  4219. if (prop.min != null && inputVal < prop.min)
  4220. {
  4221. inputVal = prop.min;
  4222. }
  4223. else if (prop.max != null && inputVal > prop.max)
  4224. {
  4225. inputVal = prop.max;
  4226. }
  4227. var newVal = encodeURIComponent((pType == 'int'? parseInt(inputVal) : inputVal) + '');
  4228. applyStyleVal(pName, newVal, prop);
  4229. }
  4230. mxEvent.addListener(input, 'keypress', function(e)
  4231. {
  4232. if (e.keyCode == 13)
  4233. {
  4234. setInputVal();
  4235. //set value triggers a redraw of the panel which removes the input
  4236. }
  4237. });
  4238. input.focus();
  4239. //FF calls blur on focus! so set the event after focusing
  4240. mxEvent.addListener(input, 'blur', function()
  4241. {
  4242. setInputVal();
  4243. });
  4244. }));
  4245. }
  4246. if (prop.isDeletable)
  4247. {
  4248. var delBtn = mxUtils.button('-', mxUtils.bind(that, function(evt)
  4249. {
  4250. //delete the node by refreshing the properties
  4251. applyStyleVal(pName, '', prop, prop.index);
  4252. mxEvent.consume(evt);
  4253. }));
  4254. delBtn.style.height = '16px';
  4255. delBtn.style.width = '25px';
  4256. delBtn.style.float = 'right';
  4257. delBtn.className = 'geColorBtn';
  4258. td.appendChild(delBtn);
  4259. }
  4260. row.appendChild(td);
  4261. return row;
  4262. };
  4263. div.style.position = 'relative';
  4264. div.style.padding = '0';
  4265. var grid = document.createElement('table');
  4266. grid.className = 'geProperties';
  4267. grid.style.whiteSpace = 'nowrap';
  4268. grid.style.width = '100%';
  4269. //create header row
  4270. var hrow = document.createElement('tr');
  4271. hrow.className = 'gePropHeader';
  4272. var th = document.createElement('th');
  4273. th.className = 'gePropHeaderCell';
  4274. var collapseImg = document.createElement('img');
  4275. collapseImg.src = Sidebar.prototype.expandedImage;
  4276. collapseImg.style.verticalAlign = 'middle';
  4277. th.appendChild(collapseImg);
  4278. mxUtils.write(th, mxResources.get('property'));
  4279. hrow.style.cursor = 'pointer';
  4280. var onFold = function()
  4281. {
  4282. var rows = grid.querySelectorAll('.gePropNonHeaderRow');
  4283. var display;
  4284. if (!that.editorUi.propertiesCollapsed)
  4285. {
  4286. collapseImg.src = Sidebar.prototype.expandedImage;
  4287. display = '';
  4288. }
  4289. else
  4290. {
  4291. collapseImg.src = Sidebar.prototype.collapsedImage;
  4292. display = 'none';
  4293. for (var e = div.childNodes.length - 1; e >= 0 ; e--)
  4294. {
  4295. //Blur can be executed concurrently with this method and the element is removed before removing it here
  4296. try
  4297. {
  4298. var child = div.childNodes[e];
  4299. var nodeName = child.nodeName.toUpperCase();
  4300. if (nodeName == 'INPUT' || nodeName == 'SELECT')
  4301. {
  4302. div.removeChild(child);
  4303. }
  4304. }
  4305. catch(ex){}
  4306. }
  4307. }
  4308. for (var r = 0; r < rows.length; r++)
  4309. {
  4310. rows[r].style.display = display;
  4311. }
  4312. };
  4313. mxEvent.addListener(hrow, 'click', function()
  4314. {
  4315. that.editorUi.propertiesCollapsed = !that.editorUi.propertiesCollapsed;
  4316. onFold();
  4317. });
  4318. hrow.appendChild(th);
  4319. th = document.createElement('th');
  4320. th.className = 'gePropHeaderCell';
  4321. th.innerHTML = mxResources.get('value');
  4322. hrow.appendChild(th);
  4323. grid.appendChild(hrow);
  4324. var isOdd = false;
  4325. var flipBkg = false;
  4326. var cellId = null;
  4327. if (state.vertices.length == 1 && state.edges.length == 0)
  4328. {
  4329. cellId = state.vertices[0].id;
  4330. }
  4331. else if (state.vertices.length == 0 && state.edges.length == 1)
  4332. {
  4333. cellId = state.edges[0].id;
  4334. }
  4335. //Add it to top (always)
  4336. if (cellId != null)
  4337. {
  4338. grid.appendChild(createPropertyRow('id', mxUtils.htmlEntities(cellId), {dispName: 'ID', type: 'readOnly'}, true, false));
  4339. }
  4340. for (var key in properties)
  4341. {
  4342. var prop = properties[key];
  4343. if (typeof(prop.isVisible) == 'function')
  4344. {
  4345. if (!prop.isVisible(state, this)) continue;
  4346. }
  4347. var pValue = state.style[key] != null? mxUtils.htmlEntities(state.style[key] + '') :
  4348. ((prop.getDefaultValue != null) ? prop.getDefaultValue(state, this) : prop.defVal); //or undefined if defVal is undefined
  4349. if (prop.type == 'separator')
  4350. {
  4351. flipBkg = !flipBkg;
  4352. continue;
  4353. }
  4354. else if (prop.type == 'staticArr') //if dynamic values are needed, a more elegant technique is needed to replace such values
  4355. {
  4356. prop.size = parseInt(state.style[prop.sizeProperty] || properties[prop.sizeProperty].defVal) || 0;
  4357. }
  4358. else if (prop.dependentProps != null)
  4359. {
  4360. var dependentProps = prop.dependentProps;
  4361. var dependentPropsVals = [];
  4362. var dependentPropsDefVal = [];
  4363. for (var i = 0; i < dependentProps.length; i++)
  4364. {
  4365. var propVal = state.style[dependentProps[i]];
  4366. dependentPropsDefVal.push(properties[dependentProps[i]].subDefVal);
  4367. dependentPropsVals.push(propVal != null? propVal.split(',') : []);
  4368. }
  4369. prop.dependentPropsDefVal = dependentPropsDefVal;
  4370. prop.dependentPropsVals = dependentPropsVals;
  4371. }
  4372. grid.appendChild(createPropertyRow(key, pValue, prop, isOdd, flipBkg));
  4373. isOdd = !isOdd;
  4374. }
  4375. for (var i = 0; i < secondLevel.length; i++)
  4376. {
  4377. var prop = secondLevel[i];
  4378. var insertElem = prop.parentRow;
  4379. for (var j = 0; j < prop.values.length; j++)
  4380. {
  4381. //mxUtils.clone failed because of the HTM element, so manual cloning is used
  4382. var iProp = {type: prop.type, parentRow: prop.parentRow, isDeletable: prop.isDeletable, index: j, defVal: prop.defVal, countProperty: prop.countProperty, size: prop.size};
  4383. var arrItem = createPropertyRow(prop.name, prop.values[j], iProp, j % 2 == 0, prop.flipBkg);
  4384. insertAfter(arrItem, insertElem);
  4385. insertElem = arrItem;
  4386. }
  4387. }
  4388. div.appendChild(grid);
  4389. onFold();
  4390. return div;
  4391. };
  4392. /**
  4393. * Creates the buttons for the predefined styles.
  4394. */
  4395. StyleFormatPanel.prototype.addStyles = function(div)
  4396. {
  4397. var ui = this.editorUi;
  4398. var graph = ui.editor.graph;
  4399. var picker = document.createElement('div');
  4400. picker.style.whiteSpace = 'nowrap';
  4401. picker.style.paddingLeft = '24px';
  4402. picker.style.paddingRight = '20px';
  4403. div.style.paddingLeft = '16px';
  4404. div.style.paddingBottom = '6px';
  4405. div.style.position = 'relative';
  4406. div.appendChild(picker);
  4407. var stylenames = ['plain-gray', 'plain-blue', 'plain-green', 'plain-turquoise',
  4408. 'plain-orange', 'plain-yellow', 'plain-red', 'plain-pink', 'plain-purple', 'gray',
  4409. 'blue', 'green', 'turquoise', 'orange', 'yellow', 'red', 'pink', 'purple'];
  4410. // Maximum palettes to switch the switcher
  4411. var maxEntries = 10;
  4412. // Selector
  4413. var switcher = document.createElement('div');
  4414. switcher.style.whiteSpace = 'nowrap';
  4415. switcher.style.position = 'relative';
  4416. switcher.style.textAlign = 'center';
  4417. switcher.style.width = '210px';
  4418. var dots = [];
  4419. for (var i = 0; i < this.defaultColorSchemes.length; i++)
  4420. {
  4421. var dot = document.createElement('div');
  4422. dot.style.display = 'inline-block';
  4423. dot.style.width = '6px';
  4424. dot.style.height = '6px';
  4425. dot.style.marginLeft = '4px';
  4426. dot.style.marginRight = '3px';
  4427. dot.style.borderRadius = '3px';
  4428. dot.style.cursor = 'pointer';
  4429. dot.style.background = 'transparent';
  4430. dot.style.border = '1px solid #b5b6b7';
  4431. (mxUtils.bind(this, function(index)
  4432. {
  4433. mxEvent.addListener(dot, 'click', mxUtils.bind(this, function()
  4434. {
  4435. setScheme(index);
  4436. }));
  4437. }))(i);
  4438. dots.push(dot);
  4439. switcher.appendChild(dot);
  4440. }
  4441. var setScheme = mxUtils.bind(this, function(index)
  4442. {
  4443. if (dots[index] != null)
  4444. {
  4445. if (this.format.currentScheme != null && dots[this.format.currentScheme] != null)
  4446. {
  4447. dots[this.format.currentScheme].style.background = 'transparent';
  4448. }
  4449. this.format.currentScheme = index;
  4450. updateScheme(this.defaultColorSchemes[this.format.currentScheme]);
  4451. dots[this.format.currentScheme].style.background = '#84d7ff';
  4452. }
  4453. });
  4454. var updateScheme = mxUtils.bind(this, function(colorsets)
  4455. {
  4456. var addButton = mxUtils.bind(this, function(colorset)
  4457. {
  4458. var btn = mxUtils.button('', mxUtils.bind(this, function(evt)
  4459. {
  4460. graph.getModel().beginUpdate();
  4461. try
  4462. {
  4463. var cells = ui.getSelectionState().cells;
  4464. for (var i = 0; i < cells.length; i++)
  4465. {
  4466. var style = graph.getModel().getStyle(cells[i]);
  4467. for (var j = 0; j < stylenames.length; j++)
  4468. {
  4469. style = mxUtils.removeStylename(style, stylenames[j]);
  4470. }
  4471. var defaults = (graph.getModel().isVertex(cells[i])) ? graph.defaultVertexStyle : graph.defaultEdgeStyle;
  4472. if (colorset != null)
  4473. {
  4474. if (!mxEvent.isShiftDown(evt))
  4475. {
  4476. if (colorset['fill'] == '')
  4477. {
  4478. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, null);
  4479. }
  4480. else
  4481. {
  4482. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, colorset['fill'] ||
  4483. mxUtils.getValue(defaults, mxConstants.STYLE_FILLCOLOR, null));
  4484. }
  4485. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, colorset['gradient'] ||
  4486. mxUtils.getValue(defaults, mxConstants.STYLE_GRADIENTCOLOR, null));
  4487. if (!mxEvent.isControlDown(evt) && (!mxClient.IS_MAC || !mxEvent.isMetaDown(evt)) &&
  4488. graph.getModel().isVertex(cells[i]))
  4489. {
  4490. style = mxUtils.setStyle(style, mxConstants.STYLE_FONTCOLOR, colorset['font'] ||
  4491. mxUtils.getValue(defaults, mxConstants.STYLE_FONTCOLOR, null));
  4492. }
  4493. }
  4494. if (!mxEvent.isAltDown(evt))
  4495. {
  4496. if (colorset['stroke'] == '')
  4497. {
  4498. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, null);
  4499. }
  4500. else
  4501. {
  4502. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, colorset['stroke'] ||
  4503. mxUtils.getValue(defaults, mxConstants.STYLE_STROKECOLOR, null));
  4504. }
  4505. }
  4506. }
  4507. else
  4508. {
  4509. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR,
  4510. mxUtils.getValue(defaults, mxConstants.STYLE_FILLCOLOR, '#ffffff'));
  4511. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR,
  4512. mxUtils.getValue(defaults, mxConstants.STYLE_STROKECOLOR, '#000000'));
  4513. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR,
  4514. mxUtils.getValue(defaults, mxConstants.STYLE_GRADIENTCOLOR, null));
  4515. if (graph.getModel().isVertex(cells[i]))
  4516. {
  4517. style = mxUtils.setStyle(style, mxConstants.STYLE_FONTCOLOR,
  4518. mxUtils.getValue(defaults, mxConstants.STYLE_FONTCOLOR, null));
  4519. }
  4520. }
  4521. graph.getModel().setStyle(cells[i], style);
  4522. }
  4523. }
  4524. finally
  4525. {
  4526. graph.getModel().endUpdate();
  4527. }
  4528. }));
  4529. btn.className = 'geStyleButton';
  4530. btn.style.width = '36px';
  4531. btn.style.height = (this.defaultColorSchemes.length <= maxEntries) ? '24px' : '30px';
  4532. btn.style.margin = '0px 6px 6px 0px';
  4533. if (colorset != null)
  4534. {
  4535. var b = (urlParams['sketch'] == '1') ? '2px solid' : '1px solid';
  4536. if (colorset['border'] != null)
  4537. {
  4538. b = colorset['border'];
  4539. }
  4540. if (colorset['gradient'] != null)
  4541. {
  4542. if (mxClient.IS_IE && (document.documentMode < 10))
  4543. {
  4544. btn.style.filter = 'progid:DXImageTransform.Microsoft.Gradient('+
  4545. 'StartColorStr=\'' + colorset['fill'] +
  4546. '\', EndColorStr=\'' + colorset['gradient'] + '\', GradientType=0)';
  4547. }
  4548. else
  4549. {
  4550. btn.style.backgroundImage = 'linear-gradient(' + colorset['fill'] + ' 0px,' +
  4551. colorset['gradient'] + ' 100%)';
  4552. }
  4553. }
  4554. else if (colorset['fill'] == mxConstants.NONE)
  4555. {
  4556. btn.style.background = 'url(\'' + Dialog.prototype.noColorImage + '\')';
  4557. }
  4558. else if (colorset['fill'] == '')
  4559. {
  4560. btn.style.backgroundColor = mxUtils.getValue(graph.defaultVertexStyle,
  4561. mxConstants.STYLE_FILLCOLOR, (Editor.isDarkMode()) ? Editor.darkColor : '#ffffff');
  4562. }
  4563. else
  4564. {
  4565. btn.style.backgroundColor = colorset['fill'] || mxUtils.getValue(graph.defaultVertexStyle,
  4566. mxConstants.STYLE_FILLCOLOR, (Editor.isDarkMode()) ? Editor.darkColor : '#ffffff');
  4567. }
  4568. if (colorset['stroke'] == mxConstants.NONE)
  4569. {
  4570. btn.style.border = b + ' transparent';
  4571. }
  4572. else if (colorset['stroke'] == '')
  4573. {
  4574. btn.style.border = b + ' ' + mxUtils.getValue(graph.defaultVertexStyle,
  4575. mxConstants.STYLE_STROKECOLOR, (!Editor.isDarkMode()) ? Editor.darkColor : '#ffffff');
  4576. }
  4577. else
  4578. {
  4579. btn.style.border = b + ' ' + (colorset['stroke'] || mxUtils.getValue(graph.defaultVertexStyle,
  4580. mxConstants.STYLE_STROKECOLOR, (!Editor.isDarkMode()) ? Editor.darkColor : '#ffffff'));
  4581. }
  4582. if (colorset['title'] != null)
  4583. {
  4584. btn.setAttribute('title', colorset['title']);
  4585. }
  4586. }
  4587. else
  4588. {
  4589. var bg = mxUtils.getValue(graph.defaultVertexStyle, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  4590. var bd = mxUtils.getValue(graph.defaultVertexStyle, mxConstants.STYLE_STROKECOLOR, '#000000');
  4591. btn.style.backgroundColor = bg;
  4592. btn.style.border = '1px solid ' + bd;
  4593. }
  4594. btn.style.borderRadius = '0';
  4595. picker.appendChild(btn);
  4596. });
  4597. picker.innerText = '';
  4598. for (var i = 0; i < colorsets.length; i++)
  4599. {
  4600. if (i > 0 && mxUtils.mod(i, 4) == 0)
  4601. {
  4602. mxUtils.br(picker);
  4603. }
  4604. addButton(colorsets[i]);
  4605. }
  4606. });
  4607. if (this.format.currentScheme == null)
  4608. {
  4609. setScheme(Editor.isDarkMode() ? 1 : (urlParams['sketch'] == '1' ? 5 : 0));
  4610. }
  4611. else
  4612. {
  4613. setScheme(this.format.currentScheme);
  4614. }
  4615. var bottom = (this.defaultColorSchemes.length <= maxEntries) ? 28 : 8;
  4616. var left = document.createElement('div');
  4617. left.style.cssText = 'position:absolute;left:10px;top:8px;bottom:' + bottom + 'px;width:20px;margin:4px;opacity:0.5;' +
  4618. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ4eHh3d3d1dXVxcXF2dnZ2dnZ2dnZxcXF2dnYmb3w1AAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADRJREFUCNdjwACMAmBKaiGYs2oJmLPKAZ3DabU8AMRTXpUKopislqFyVzCAuUZgikkBZjoAcMYLnp53P/UAAAAASUVORK5CYII=);';
  4619. mxEvent.addListener(left, 'click', mxUtils.bind(this, function()
  4620. {
  4621. setScheme(mxUtils.mod(this.format.currentScheme - 1, this.defaultColorSchemes.length));
  4622. }));
  4623. var right = document.createElement('div');
  4624. right.style.cssText = 'position:absolute;left:202px;top:8px;bottom:' + bottom + 'px;width:20px;margin:4px;opacity:0.5;' +
  4625. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnYBuwCcAAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADZJREFUCNdjQAOMAmBKaiGY8loF5rKswsZlrVo8AUiFrTICcbIWK8A5DF1gDoMymMPApIAwHwCS0Qx/U7qCBQAAAABJRU5ErkJggg==);';
  4626. if (this.defaultColorSchemes.length > 1)
  4627. {
  4628. div.appendChild(left);
  4629. div.appendChild(right);
  4630. }
  4631. mxEvent.addListener(right, 'click', mxUtils.bind(this, function()
  4632. {
  4633. setScheme(mxUtils.mod(this.format.currentScheme + 1, this.defaultColorSchemes.length));
  4634. }));
  4635. // Hover state
  4636. function addHoverState(elt)
  4637. {
  4638. mxEvent.addListener(elt, 'mouseenter', function()
  4639. {
  4640. elt.style.opacity = '1';
  4641. });
  4642. mxEvent.addListener(elt, 'mouseleave', function()
  4643. {
  4644. elt.style.opacity = '0.5';
  4645. });
  4646. };
  4647. addHoverState(left);
  4648. addHoverState(right);
  4649. updateScheme(this.defaultColorSchemes[this.format.currentScheme]);
  4650. if (this.defaultColorSchemes.length <= maxEntries)
  4651. {
  4652. div.appendChild(switcher);
  4653. }
  4654. return div;
  4655. };
  4656. StyleFormatPanel.prototype.addEditOps = function(div)
  4657. {
  4658. var ss = this.editorUi.getSelectionState();
  4659. var graph = this.editorUi.editor.graph;
  4660. var btn = null;
  4661. if (ss.cells.length == 1)
  4662. {
  4663. btn = mxUtils.button(mxResources.get('editStyle'), mxUtils.bind(this, function(evt)
  4664. {
  4665. this.editorUi.actions.get('editStyle').funct();
  4666. }));
  4667. btn.setAttribute('title', mxResources.get('editStyle') + ' (' + this.editorUi.actions.get('editStyle').shortcut + ')');
  4668. btn.style.width = '210px';
  4669. btn.style.marginBottom = '2px';
  4670. div.appendChild(btn);
  4671. }
  4672. var state = (ss.cells.length == 1) ? graph.view.getState(ss.cells[0]) : null;
  4673. if (state != null && state.shape != null && state.shape.stencil != null)
  4674. {
  4675. var btn2 = mxUtils.button(mxResources.get('editShape'), mxUtils.bind(this, function(evt)
  4676. {
  4677. this.editorUi.actions.get('editShape').funct();
  4678. }));
  4679. btn2.setAttribute('title', mxResources.get('editShape'));
  4680. btn2.style.marginBottom = '2px';
  4681. if (btn == null)
  4682. {
  4683. btn2.style.width = '210px';
  4684. }
  4685. else
  4686. {
  4687. btn.style.width = '104px';
  4688. btn2.style.width = '104px';
  4689. btn2.style.marginLeft = '2px';
  4690. }
  4691. div.appendChild(btn2);
  4692. }
  4693. else if (ss.image && ss.cells.length > 0)
  4694. {
  4695. var btn2 = mxUtils.button(mxResources.get('editImage'), mxUtils.bind(this, function(evt)
  4696. {
  4697. this.editorUi.actions.get('image').funct();
  4698. }));
  4699. btn2.setAttribute('title', mxResources.get('editImage'));
  4700. btn2.style.marginBottom = '2px';
  4701. if (btn == null)
  4702. {
  4703. btn2.style.width = '210px';
  4704. }
  4705. else
  4706. {
  4707. btn.style.width = '104px';
  4708. btn2.style.width = '104px';
  4709. btn2.style.marginLeft = '2px';
  4710. }
  4711. div.appendChild(btn2);
  4712. }
  4713. return div;
  4714. };
  4715. }
  4716. /**
  4717. * Maps fonts to font-face CSS.
  4718. */
  4719. Graph.fontMapping = {'https://fonts.googleapis.com/css?family=Architects+Daughter':
  4720. '@font-face { font-family: "Architects Daughter"; ' +
  4721. 'src: url(' + STYLE_PATH + '/fonts/ArchitectsDaughter-Regular.ttf) format("truetype"); }'};
  4722. /**
  4723. * Lookup table for mapping from font URL and name to elements in the DOM.
  4724. */
  4725. Graph.customFontElements = {};
  4726. /**
  4727. * Lookup table for recent custom fonts.
  4728. */
  4729. Graph.recentCustomFonts = {};
  4730. /**
  4731. * Returns true if the given font URL references a Google font.
  4732. */
  4733. Graph.isGoogleFontUrl = function(url)
  4734. {
  4735. return url.substring(0, Editor.GOOGLE_FONTS.length) == Editor.GOOGLE_FONTS;
  4736. };
  4737. /**
  4738. * Returns true if the given font URL is a CSS file.
  4739. */
  4740. Graph.isCssFontUrl = function(url)
  4741. {
  4742. return Graph.isGoogleFontUrl(url);
  4743. };
  4744. /**
  4745. * Creates the DOM node for the custom font.
  4746. */
  4747. Graph.createFontElement = function(name, url)
  4748. {
  4749. var elt = null;
  4750. var style = Graph.fontMapping[url];
  4751. if (style == null && Graph.isCssFontUrl(url))
  4752. {
  4753. elt = document.createElement('link');
  4754. elt.setAttribute('rel', 'stylesheet');
  4755. elt.setAttribute('type', 'text/css');
  4756. elt.setAttribute('charset', 'UTF-8');
  4757. elt.setAttribute('href', url);
  4758. }
  4759. else
  4760. {
  4761. if (style == null)
  4762. {
  4763. style = '@font-face {\n' +
  4764. 'font-family: "' + name + '";\n' +
  4765. 'src: url("' + url + '");\n}'
  4766. }
  4767. elt = document.createElement('style');
  4768. mxUtils.write(elt, style);
  4769. }
  4770. return elt;
  4771. };
  4772. /**
  4773. * Adds a font to the document.
  4774. */
  4775. Graph.addFont = function(name, url, callback)
  4776. {
  4777. if (name != null && name.length > 0 && url != null && url.length > 0)
  4778. {
  4779. var key = name.toLowerCase();
  4780. // Blocks UI font from being overwritten
  4781. if (key != 'helvetica' && name != 'arial' && key != 'sans-serif')
  4782. {
  4783. var entry = Graph.customFontElements[key];
  4784. // Replaces element if URL has changed
  4785. if (entry != null && entry.url != url)
  4786. {
  4787. entry.elt.parentNode.removeChild(entry.elt);
  4788. entry = null;
  4789. }
  4790. if (entry == null)
  4791. {
  4792. var realUrl = url;
  4793. // Fixes possible mixed content by using proxy
  4794. if (url.substring(0, 5) == 'http:')
  4795. {
  4796. realUrl = PROXY_URL + '?url=' + encodeURIComponent(url);
  4797. }
  4798. entry = {name: name, url: url, elt: Graph.createFontElement(name, realUrl)};
  4799. Graph.customFontElements[key] = entry;
  4800. Graph.recentCustomFonts[key] = entry;
  4801. var head = document.getElementsByTagName('head')[0];
  4802. if (callback != null)
  4803. {
  4804. if (entry.elt.nodeName.toLowerCase() == 'link')
  4805. {
  4806. entry.elt.onload = callback;
  4807. entry.elt.onerror = callback;
  4808. }
  4809. else
  4810. {
  4811. callback();
  4812. }
  4813. }
  4814. if (head != null)
  4815. {
  4816. head.appendChild(entry.elt);
  4817. }
  4818. }
  4819. else if (callback != null)
  4820. {
  4821. callback();
  4822. }
  4823. }
  4824. else if (callback != null)
  4825. {
  4826. callback();
  4827. }
  4828. }
  4829. else if (callback != null)
  4830. {
  4831. callback();
  4832. }
  4833. return name;
  4834. };
  4835. /**
  4836. * Returns the URL for the given font name if it exists in the document.
  4837. * Otherwise it returns the given URL.
  4838. */
  4839. Graph.getFontUrl = function(name, url)
  4840. {
  4841. var font = Graph.customFontElements[name.toLowerCase()];
  4842. if (font != null)
  4843. {
  4844. url = font.url;
  4845. }
  4846. return url;
  4847. };
  4848. /**
  4849. * Processes the fonts in the given element and its descendants.
  4850. */
  4851. Graph.processFontAttributes = function(elt)
  4852. {
  4853. var elts = elt.getElementsByTagName('*');
  4854. for (var i = 0; i < elts.length; i++)
  4855. {
  4856. var url = elts[i].getAttribute('data-font-src');
  4857. if (url != null)
  4858. {
  4859. var name = (elts[i].nodeName == 'FONT') ?
  4860. elts[i].getAttribute('face') :
  4861. elts[i].style.fontFamily;
  4862. if (name != null)
  4863. {
  4864. Graph.addFont(name, url);
  4865. }
  4866. }
  4867. }
  4868. };
  4869. /**
  4870. * Processes the font in the given cell style.
  4871. */
  4872. Graph.processFontStyle = function(style)
  4873. {
  4874. if (style != null)
  4875. {
  4876. var url = mxUtils.getValue(style, 'fontSource', null);
  4877. if (url != null)
  4878. {
  4879. var name = mxUtils.getValue(style, mxConstants.STYLE_FONTFAMILY, null);
  4880. if (name != null)
  4881. {
  4882. Graph.addFont(name, decodeURIComponent(url));
  4883. }
  4884. }
  4885. }
  4886. return style;
  4887. };
  4888. /**
  4889. * Changes the default stylename so that it matches the old named style
  4890. * if one was specified in the XML.
  4891. */
  4892. Graph.prototype.defaultThemeName = 'default-style2';
  4893. /**
  4894. * Contains the last XML that was pasted.
  4895. */
  4896. Graph.prototype.lastPasteXml = null;
  4897. /**
  4898. * Contains the number of times the last XML was pasted.
  4899. */
  4900. Graph.prototype.pasteCounter = 0;
  4901. /**
  4902. * Graph Overrides
  4903. */
  4904. Graph.prototype.defaultScrollbars = urlParams['sb'] != '0';
  4905. /**
  4906. * Specifies if the page should be visible for new files. Default is true.
  4907. */
  4908. Graph.prototype.defaultPageVisible = urlParams['pv'] != '0';
  4909. /**
  4910. * Specifies if the page should be visible for new files. Default is true.
  4911. */
  4912. Graph.prototype.shadowId = 'dropShadow';
  4913. /**
  4914. * Properties for the SVG shadow effect.
  4915. */
  4916. Graph.prototype.svgShadowColor = '#3D4574';
  4917. /**
  4918. * Properties for the SVG shadow effect.
  4919. */
  4920. Graph.prototype.svgShadowOpacity = '0.4';
  4921. /**
  4922. * Properties for the SVG shadow effect.
  4923. */
  4924. Graph.prototype.svgShadowBlur = '1.7';
  4925. /**
  4926. * Properties for the SVG shadow effect.
  4927. */
  4928. Graph.prototype.svgShadowSize = '3';
  4929. /**
  4930. * Enables move of bends/segments without selecting.
  4931. */
  4932. Graph.prototype.edgeMode = urlParams['edge'] != 'move';
  4933. /**
  4934. * Enables move of bends/segments without selecting.
  4935. */
  4936. Graph.prototype.hiddenTags = null;
  4937. /**
  4938. * Enables move of bends/segments without selecting.
  4939. */
  4940. Graph.prototype.defaultMathEnabled = false;
  4941. /**
  4942. * Adds rack child layout style.
  4943. */
  4944. var graphInit = Graph.prototype.init;
  4945. Graph.prototype.init = function()
  4946. {
  4947. graphInit.apply(this, arguments);
  4948. // Array of hidden tags used in isCellVisible override
  4949. this.hiddenTags = [];
  4950. //TODO initialize Freehand in the correct location!
  4951. if (window.mxFreehand)
  4952. {
  4953. this.freehand = new mxFreehand(this);
  4954. }
  4955. // Override insert location for current mouse point
  4956. var mouseEvent = null;
  4957. function setMouseEvent(evt)
  4958. {
  4959. mouseEvent = evt;
  4960. };
  4961. mxEvent.addListener(this.container, 'mouseenter', setMouseEvent);
  4962. mxEvent.addListener(this.container, 'mousemove', setMouseEvent);
  4963. mxEvent.addListener(this.container, 'mouseleave', function(evt)
  4964. {
  4965. mouseEvent = null;
  4966. });
  4967. // Extends getInsertPoint to use the current mouse location
  4968. this.isMouseInsertPoint = function()
  4969. {
  4970. return mouseEvent != null;
  4971. };
  4972. var getInsertPoint = this.getInsertPoint;
  4973. this.getInsertPoint = function()
  4974. {
  4975. if (mouseEvent != null)
  4976. {
  4977. return this.getPointForEvent(mouseEvent);
  4978. }
  4979. return getInsertPoint.apply(this, arguments);
  4980. };
  4981. var layoutManagerGetLayout = this.layoutManager.getLayout;
  4982. this.layoutManager.getLayout = function(cell)
  4983. {
  4984. // Workaround for possible invalid style after change and before view validation
  4985. var style = this.graph.getCellStyle(cell);
  4986. // mxRackContainer may be undefined as it is dynamically loaded at render time
  4987. if (style != null)
  4988. {
  4989. if (style['childLayout'] == 'rack')
  4990. {
  4991. var rackLayout = new mxStackLayout(this.graph, false);
  4992. var unitSize = 20;
  4993. if (style['rackUnitSize'] != null)
  4994. {
  4995. rackLayout.gridSize = parseFloat(style['rackUnitSize']);
  4996. }
  4997. else
  4998. {
  4999. rackLayout.gridSize = (typeof mxRackContainer !== 'undefined') ? mxRackContainer.unitSize : unitSize;
  5000. }
  5001. rackLayout.marginLeft = style['marginLeft'] || 0;
  5002. rackLayout.marginRight = style['marginRight'] || 0;
  5003. rackLayout.marginTop = style['marginTop'] || 0;
  5004. rackLayout.marginBottom = style['marginBottom'] || 0;
  5005. rackLayout.allowGaps = style['allowGaps'] || 0;
  5006. rackLayout.horizontal = mxUtils.getValue(style, 'horizontalRack', '0') == '1';
  5007. rackLayout.resizeParent = false;
  5008. rackLayout.fill = true;
  5009. return rackLayout;
  5010. }
  5011. }
  5012. return layoutManagerGetLayout.apply(this, arguments);
  5013. }
  5014. this.updateGlobalUrlVariables();
  5015. };
  5016. /**
  5017. * Adds support for custom fonts in cell styles.
  5018. */
  5019. var graphPostProcessCellStyle = Graph.prototype.postProcessCellStyle;
  5020. Graph.prototype.postProcessCellStyle = function(cell, style)
  5021. {
  5022. return Graph.processFontStyle(graphPostProcessCellStyle.apply(this, arguments));
  5023. };
  5024. /**
  5025. * Handles custom fonts in labels.
  5026. */
  5027. var mxSvgCanvas2DUpdateTextNodes = mxSvgCanvas2D.prototype.updateTextNodes;
  5028. mxSvgCanvas2D.prototype.updateTextNodes = function(x, y, w, h, align, valign, wrap, overflow, clip, rotation, g)
  5029. {
  5030. mxSvgCanvas2DUpdateTextNodes.apply(this, arguments);
  5031. Graph.processFontAttributes(g);
  5032. };
  5033. /**
  5034. * Handles custom fonts in labels.
  5035. */
  5036. var mxTextRedraw = mxText.prototype.redraw;
  5037. mxText.prototype.redraw = function()
  5038. {
  5039. mxTextRedraw.apply(this, arguments);
  5040. // Handles label rendered without foreign object
  5041. if (this.node != null && this.node.nodeName == 'DIV')
  5042. {
  5043. Graph.processFontAttributes(this.node);
  5044. }
  5045. };
  5046. /**
  5047. * Creates the tags dialog.
  5048. */
  5049. Graph.prototype.createTagsDialog = function(isEnabled, invert, addFn)
  5050. {
  5051. var graph = this;
  5052. var allTags = graph.hiddenTags.slice();
  5053. var div = document.createElement('div');
  5054. div.style.userSelect = 'none';
  5055. div.style.overflow = 'hidden';
  5056. div.style.padding = '10px';
  5057. div.style.height = '100%';
  5058. var tagCloud = document.createElement('div');
  5059. tagCloud.style.boxSizing = 'border-box';
  5060. tagCloud.style.borderRadius = '4px';
  5061. tagCloud.style.userSelect = 'none';
  5062. tagCloud.style.overflow = 'auto';
  5063. tagCloud.style.position = 'absolute';
  5064. tagCloud.style.left = '10px';
  5065. tagCloud.style.right = '10px';
  5066. tagCloud.style.top = '10px';
  5067. tagCloud.style.border = (graph.isEnabled()) ? '1px solid #808080' : 'none';
  5068. tagCloud.style.bottom = (graph.isEnabled()) ? '48px' : '10px';
  5069. div.appendChild(tagCloud);
  5070. function removeInvisibleSelectionCells()
  5071. {
  5072. var cells = graph.getSelectionCells();
  5073. var visible = [];
  5074. for (var i = 0; i < cells.length; i++)
  5075. {
  5076. if (graph.isCellVisible(cells[i]))
  5077. {
  5078. visible.push(cells[i]);
  5079. }
  5080. }
  5081. graph.setSelectionCells(visible);
  5082. };
  5083. function setAllVisible(visible)
  5084. {
  5085. graph.setHiddenTags(visible ? [] : allTags.slice());
  5086. removeInvisibleSelectionCells();
  5087. graph.refresh();
  5088. };
  5089. var resetBtn = mxUtils.button(mxResources.get('reset'), function(evt)
  5090. {
  5091. graph.setHiddenTags([]);
  5092. if (!mxEvent.isShiftDown(evt))
  5093. {
  5094. allTags = graph.hiddenTags.slice();
  5095. }
  5096. removeInvisibleSelectionCells();
  5097. graph.refresh();
  5098. });
  5099. resetBtn.setAttribute('title', mxResources.get('reset'));
  5100. resetBtn.className = 'geBtn';
  5101. resetBtn.style.margin = '0 4px 0 0';
  5102. var addBtn = mxUtils.button(mxResources.get('add'), function()
  5103. {
  5104. if (addFn != null)
  5105. {
  5106. // Takes all tags and callback to update all tags
  5107. addFn(allTags, function(newAllTags)
  5108. {
  5109. allTags = newAllTags;
  5110. refreshUi();
  5111. });
  5112. }
  5113. });
  5114. addBtn.setAttribute('title', mxResources.get('add'));
  5115. addBtn.className = 'geBtn';
  5116. addBtn.style.margin = '0';
  5117. graph.addListener(mxEvent.ROOT, function()
  5118. {
  5119. allTags = graph.hiddenTags.slice();
  5120. });
  5121. function refreshTags(tags, selected)
  5122. {
  5123. tagCloud.innerText = '';
  5124. if (tags.length > 0)
  5125. {
  5126. var table = document.createElement('table');
  5127. table.setAttribute('cellpadding', '2');
  5128. table.style.boxSizing = 'border-box';
  5129. table.style.tableLayout = 'fixed';
  5130. table.style.width = '100%';
  5131. var tbody = document.createElement('tbody');
  5132. if (tags != null && tags.length > 0)
  5133. {
  5134. for (var i = 0; i < tags.length; i++)
  5135. {
  5136. (function(tag)
  5137. {
  5138. function setTagVisible()
  5139. {
  5140. var temp = allTags.slice();
  5141. var index = mxUtils.indexOf(temp, tag);
  5142. temp.splice(index, 1);
  5143. graph.setHiddenTags(temp);
  5144. removeInvisibleSelectionCells();
  5145. graph.refresh();
  5146. };
  5147. function selectCells()
  5148. {
  5149. var cells = graph.getCellsForTags(
  5150. [tag], null, null, true);
  5151. if (graph.isEnabled())
  5152. {
  5153. graph.setSelectionCells(cells);
  5154. }
  5155. else
  5156. {
  5157. graph.highlightCells(cells);
  5158. }
  5159. };
  5160. var visible = mxUtils.indexOf(graph.hiddenTags, tag) < 0;
  5161. var row = document.createElement('tr');
  5162. var td = document.createElement('td');
  5163. td.style.align = 'center';
  5164. td.style.width = '16px';
  5165. var img = document.createElement('img');
  5166. img.setAttribute('src', visible ? Editor.visibleImage : Editor.hiddenImage);
  5167. img.setAttribute('title', mxResources.get(visible ? 'hideIt' : 'show', [tag]));
  5168. mxUtils.setOpacity(img, visible ? 75 : 25);
  5169. img.style.verticalAlign = 'middle';
  5170. img.style.cursor = 'pointer';
  5171. img.style.width = '16px';
  5172. if (invert || Editor.isDarkMode())
  5173. {
  5174. img.style.filter = 'invert(100%)';
  5175. }
  5176. td.appendChild(img);
  5177. mxEvent.addListener(img, 'click', function(evt)
  5178. {
  5179. if (mxEvent.isShiftDown(evt))
  5180. {
  5181. setAllVisible(mxUtils.indexOf(graph.hiddenTags, tag) >= 0);
  5182. }
  5183. else
  5184. {
  5185. graph.toggleHiddenTag(tag);
  5186. removeInvisibleSelectionCells();
  5187. graph.refresh();
  5188. }
  5189. mxEvent.consume(evt);
  5190. });
  5191. row.appendChild(td);
  5192. td = document.createElement('td');
  5193. td.style.overflow = 'hidden';
  5194. td.style.whiteSpace = 'nowrap';
  5195. td.style.textOverflow = 'ellipsis';
  5196. td.style.verticalAlign = 'middle';
  5197. td.style.cursor = 'pointer';
  5198. td.setAttribute('title', tag);
  5199. a = document.createElement('a');
  5200. mxUtils.write(a, tag);
  5201. a.style.textOverflow = 'ellipsis';
  5202. a.style.position = 'relative';
  5203. mxUtils.setOpacity(a, visible ? 100 : 40);
  5204. td.appendChild(a);
  5205. mxEvent.addListener(td, 'click', (function(evt)
  5206. {
  5207. if (mxEvent.isShiftDown(evt))
  5208. {
  5209. setAllVisible(true);
  5210. selectCells();
  5211. }
  5212. else
  5213. {
  5214. if (visible && graph.hiddenTags.length > 0)
  5215. {
  5216. setAllVisible(true);
  5217. }
  5218. else
  5219. {
  5220. setTagVisible();
  5221. }
  5222. }
  5223. mxEvent.consume(evt);
  5224. }));
  5225. row.appendChild(td);
  5226. if (graph.isEnabled())
  5227. {
  5228. td = document.createElement('td');
  5229. td.style.verticalAlign = 'middle';
  5230. td.style.textAlign = 'center';
  5231. td.style.width = '18px';
  5232. if (selected == null)
  5233. {
  5234. td.style.align = 'center';
  5235. td.style.width = '16px';
  5236. var img = document.createElement('img');
  5237. img.setAttribute('src', Editor.crossImage);
  5238. img.setAttribute('title', mxResources.get('removeIt', [tag]));
  5239. mxUtils.setOpacity(img, visible ? 75 : 25);
  5240. img.style.verticalAlign = 'middle';
  5241. img.style.cursor = 'pointer';
  5242. img.style.width = '16px';
  5243. if (invert || Editor.isDarkMode())
  5244. {
  5245. img.style.filter = 'invert(100%)';
  5246. }
  5247. mxEvent.addListener(img, 'click', function(evt)
  5248. {
  5249. var idx = mxUtils.indexOf(allTags, tag);
  5250. if (idx >= 0)
  5251. {
  5252. allTags.splice(idx, 1);
  5253. }
  5254. graph.removeTagsForCells(
  5255. graph.model.getDescendants(
  5256. graph.model.getRoot()), [tag]);
  5257. graph.refresh();
  5258. mxEvent.consume(evt);
  5259. });
  5260. td.appendChild(img);
  5261. }
  5262. else
  5263. {
  5264. var cb2 = document.createElement('input');
  5265. cb2.setAttribute('type', 'checkbox');
  5266. cb2.style.margin = '0px';
  5267. cb2.defaultChecked = (selected != null &&
  5268. mxUtils.indexOf(selected, tag) >= 0);
  5269. cb2.checked = cb2.defaultChecked;
  5270. cb2.style.background = 'transparent';
  5271. cb2.setAttribute('title', mxResources.get(
  5272. cb2.defaultChecked ?
  5273. 'removeIt' : 'add', [tag]));
  5274. mxEvent.addListener(cb2, 'change', function(evt)
  5275. {
  5276. if (cb2.checked)
  5277. {
  5278. graph.addTagsForCells(graph.getSelectionCells(), [tag]);
  5279. }
  5280. else
  5281. {
  5282. graph.removeTagsForCells(graph.getSelectionCells(), [tag]);
  5283. }
  5284. mxEvent.consume(evt);
  5285. });
  5286. td.appendChild(cb2);
  5287. }
  5288. row.appendChild(td);
  5289. }
  5290. tbody.appendChild(row);
  5291. })(tags[i]);
  5292. }
  5293. }
  5294. table.appendChild(tbody);
  5295. tagCloud.appendChild(table);
  5296. }
  5297. };
  5298. var refreshUi = mxUtils.bind(this, function(sender, evt)
  5299. {
  5300. if (isEnabled())
  5301. {
  5302. var tags = graph.getAllTags();
  5303. for (var i = 0; i < tags.length; i++)
  5304. {
  5305. if (mxUtils.indexOf(allTags, tags[i]) < 0)
  5306. {
  5307. allTags.push(tags[i]);
  5308. }
  5309. }
  5310. allTags.sort();
  5311. if (graph.isSelectionEmpty())
  5312. {
  5313. refreshTags(allTags);
  5314. }
  5315. else
  5316. {
  5317. refreshTags(allTags, graph.getCommonTagsForCells(
  5318. graph.getSelectionCells()));
  5319. }
  5320. }
  5321. });
  5322. graph.selectionModel.addListener(mxEvent.CHANGE, refreshUi);
  5323. graph.model.addListener(mxEvent.CHANGE, refreshUi);
  5324. graph.addListener(mxEvent.REFRESH, refreshUi);
  5325. var footer = document.createElement('div');
  5326. footer.style.boxSizing = 'border-box';
  5327. footer.style.whiteSpace = 'nowrap';
  5328. footer.style.position = 'absolute';
  5329. footer.style.overflow = 'hidden';
  5330. footer.style.bottom = '0px';
  5331. footer.style.height = '42px';
  5332. footer.style.right = '10px';
  5333. footer.style.left = '10px';
  5334. if (graph.isEnabled())
  5335. {
  5336. footer.appendChild(resetBtn);
  5337. footer.appendChild(addBtn);
  5338. div.appendChild(footer);
  5339. }
  5340. return {div: div, refresh: refreshUi};
  5341. };
  5342. /**
  5343. * Returns all custom fonts (old and new).
  5344. */
  5345. Graph.prototype.getCustomFonts = function()
  5346. {
  5347. var fonts = this.extFonts;
  5348. if (fonts != null)
  5349. {
  5350. fonts = fonts.slice();
  5351. }
  5352. else
  5353. {
  5354. fonts = [];
  5355. }
  5356. for (var key in Graph.customFontElements)
  5357. {
  5358. var font = Graph.customFontElements[key];
  5359. fonts.push({name: font.name, url: font.url});
  5360. }
  5361. return fonts;
  5362. };
  5363. /**
  5364. * Assigns the given custom font to the selected text.
  5365. */
  5366. Graph.prototype.setFont = function(name, url)
  5367. {
  5368. // Adds the font element to the document
  5369. Graph.addFont(name, url);
  5370. // Only valid known fonts are allowed as parameters so we set
  5371. // the real font name and the data-source-face in the element
  5372. // which is used as the face attribute when editing stops
  5373. // KNOWN: Undo for the DOM change is not working
  5374. document.execCommand('fontname', false, name);
  5375. // Finds element with new font name and checks its data-font-src attribute
  5376. if (url != null)
  5377. {
  5378. var fonts = this.cellEditor.textarea.getElementsByTagName('font');
  5379. // Enforces consistent font naming
  5380. url = Graph.getFontUrl(name, url);
  5381. for (var i = 0; i < fonts.length; i++)
  5382. {
  5383. if (fonts[i].getAttribute('face') == name)
  5384. {
  5385. if (fonts[i].getAttribute('data-font-src') != url)
  5386. {
  5387. fonts[i].setAttribute('data-font-src', url);
  5388. }
  5389. }
  5390. }
  5391. }
  5392. };
  5393. /**
  5394. * Disables fast zoom with shadow in lightbox for Safari
  5395. * to work around blank output on retina screen.
  5396. */
  5397. var graphIsFastZoomEnabled = Graph.prototype.isFastZoomEnabled;
  5398. Graph.prototype.isFastZoomEnabled = function()
  5399. {
  5400. return graphIsFastZoomEnabled.apply(this, arguments) && (!this.shadowVisible || !mxClient.IS_SF);
  5401. };
  5402. /**
  5403. * Updates the global variables from the vars URL parameter.
  5404. */
  5405. Graph.prototype.updateGlobalUrlVariables = function()
  5406. {
  5407. this.globalVars = Editor.globalVars;
  5408. if (urlParams['vars'] != null)
  5409. {
  5410. try
  5411. {
  5412. this.globalVars = (this.globalVars != null) ? mxUtils.clone(this.globalVars) : {};
  5413. var vars = JSON.parse(decodeURIComponent(urlParams['vars']));
  5414. if (vars != null)
  5415. {
  5416. for (var key in vars)
  5417. {
  5418. this.globalVars[key] = vars[key];
  5419. }
  5420. }
  5421. }
  5422. catch (e)
  5423. {
  5424. if (window.console != null)
  5425. {
  5426. console.log('Error in vars URL parameter: ' + e);
  5427. }
  5428. }
  5429. }
  5430. };
  5431. /**
  5432. * Returns all global variables used for export. This function never returns null.
  5433. * This can be overridden by plugins to return global variables for export.
  5434. */
  5435. Graph.prototype.getExportVariables = function()
  5436. {
  5437. return (this.globalVars != null) ? mxUtils.clone(this.globalVars) : {};
  5438. };
  5439. /**
  5440. * Adds support for vars URL parameter.
  5441. */
  5442. var graphGetGlobalVariable = Graph.prototype.getGlobalVariable;
  5443. Graph.prototype.getGlobalVariable = function(name)
  5444. {
  5445. var val = graphGetGlobalVariable.apply(this, arguments);
  5446. if (val == null && this.globalVars != null)
  5447. {
  5448. val = this.globalVars[name];
  5449. }
  5450. return val;
  5451. };
  5452. /**
  5453. * Cached default stylesheet for image export in dark mode.
  5454. */
  5455. Graph.prototype.getDefaultStylesheet = function()
  5456. {
  5457. if (this.defaultStylesheet == null)
  5458. {
  5459. var node = this.themes['default-style2'];
  5460. var dec = new mxCodec(node.ownerDocument);
  5461. this.defaultStylesheet = dec.decode(node);
  5462. }
  5463. return this.defaultStylesheet;
  5464. };
  5465. /**
  5466. * Overiddes function to use url parameter
  5467. */
  5468. Graph.prototype.isViewer = function()
  5469. {
  5470. return urlParams['viewer'];
  5471. };
  5472. /**
  5473. * Temporarily overrides stylesheet during image export in dark mode.
  5474. */
  5475. var graphGetSvg = Graph.prototype.getSvg;
  5476. Graph.prototype.getSvg = function(background, scale, border, nocrop, crisp,
  5477. ignoreSelection, showText, imgExport, linkTarget, hasShadow,
  5478. incExtFonts, keepTheme, exportType, cells)
  5479. {
  5480. var temp = null;
  5481. var tempFg = null;
  5482. var tempBg = null;
  5483. if (!keepTheme && this.themes != null && this.defaultThemeName == 'darkTheme')
  5484. {
  5485. temp = this.stylesheet;
  5486. tempFg = this.shapeForegroundColor;
  5487. tempBg = this.shapeBackgroundColor;
  5488. this.shapeForegroundColor = (this.defaultThemeName == 'darkTheme') ?
  5489. '#000000' : Editor.lightColor;
  5490. this.shapeBackgroundColor = (this.defaultThemeName == 'darkTheme') ?
  5491. '#ffffff' : Editor.darkColor;
  5492. this.stylesheet = this.getDefaultStylesheet();
  5493. // LATER: Fix math export in dark mode by fetching text nodes before
  5494. // calling refresh and changing the font color in-place
  5495. this.refresh();
  5496. }
  5497. var result = graphGetSvg.apply(this, arguments);
  5498. var extFonts = this.getCustomFonts();
  5499. // Adds external fonts
  5500. if (incExtFonts && extFonts.length > 0)
  5501. {
  5502. var svgDoc = result.ownerDocument;
  5503. var style = (svgDoc.createElementNS != null) ?
  5504. svgDoc.createElementNS(mxConstants.NS_SVG, 'style') : svgDoc.createElement('style');
  5505. svgDoc.setAttributeNS != null? style.setAttributeNS('type', 'text/css') : style.setAttribute('type', 'text/css');
  5506. var prefix = '';
  5507. var postfix = '';
  5508. for (var i = 0; i < extFonts.length; i++)
  5509. {
  5510. var fontName = extFonts[i].name, fontUrl = extFonts[i].url;
  5511. if (Graph.isCssFontUrl(fontUrl))
  5512. {
  5513. prefix += '@import url(' + fontUrl + ');\n';
  5514. }
  5515. else
  5516. {
  5517. postfix += '@font-face {\n' +
  5518. 'font-family: "' + fontName + '";\n' +
  5519. 'src: url("' + fontUrl + '");\n}\n';
  5520. }
  5521. }
  5522. style.appendChild(svgDoc.createTextNode(prefix + postfix));
  5523. result.getElementsByTagName('defs')[0].appendChild(style);
  5524. }
  5525. // SVG element must be added to DOM for MathJax to work
  5526. if (this.mathEnabled)
  5527. {
  5528. document.body.appendChild(result);
  5529. Editor.MathJaxRender(result);
  5530. result.parentNode.removeChild(result);
  5531. }
  5532. if (temp != null)
  5533. {
  5534. this.shapeBackgroundColor = tempBg;
  5535. this.shapeForegroundColor = tempFg;
  5536. this.stylesheet = temp;
  5537. this.refresh();
  5538. }
  5539. return result;
  5540. };
  5541. /**
  5542. * Overridden to destroy the shape number.
  5543. */
  5544. var cellRendererDestroy = mxCellRenderer.prototype.destroy;
  5545. mxCellRenderer.prototype.destroy = function(state)
  5546. {
  5547. cellRendererDestroy.apply(this, arguments);
  5548. if (state.secondLabel != null)
  5549. {
  5550. state.secondLabel.destroy();
  5551. state.secondLabel = null;
  5552. }
  5553. };
  5554. /**
  5555. * Includes the shape number in the return value.
  5556. */
  5557. mxCellRenderer.prototype.getShapesForState = function(state)
  5558. {
  5559. return [state.shape, state.text, state.secondLabel, state.control];
  5560. };
  5561. /**
  5562. * Resets the global shape counter.
  5563. */
  5564. var graphViewResetValidationState = mxGraphView.prototype.resetValidationState;
  5565. mxGraphView.prototype.resetValidationState = function()
  5566. {
  5567. graphViewResetValidationState.apply(this, arguments);
  5568. this.enumerationState = 0;
  5569. };
  5570. /**
  5571. * Adds shape number update the validation step.
  5572. */
  5573. var graphViewStateValidated = mxGraphView.prototype.stateValidated;
  5574. mxGraphView.prototype.stateValidated = function(state)
  5575. {
  5576. if (state.shape != null)
  5577. {
  5578. this.redrawEnumerationState(state);
  5579. }
  5580. return graphViewStateValidated.apply(this, arguments);
  5581. };
  5582. /**
  5583. * Returns the markup to be used for the enumeration shape.
  5584. */
  5585. mxGraphView.prototype.createEnumerationValue = function(state)
  5586. {
  5587. var value = decodeURIComponent(mxUtils.getValue(state.style, 'enumerateValue', ''));
  5588. if (value == '')
  5589. {
  5590. value = ++this.enumerationState;
  5591. }
  5592. return '<div style="padding:2px;border:1px solid gray;background:yellow;border-radius:2px;">' +
  5593. mxUtils.htmlEntities(value) + '</div>';
  5594. };
  5595. /**
  5596. * Adds drawing and update of the shape number.
  5597. */
  5598. mxGraphView.prototype.redrawEnumerationState = function(state)
  5599. {
  5600. var enumerate = mxUtils.getValue(state.style, 'enumerate', 0) == '1';
  5601. if (enumerate && state.secondLabel == null)
  5602. {
  5603. state.secondLabel = new mxText('', new mxRectangle(),
  5604. mxConstants.ALIGN_LEFT, mxConstants.ALIGN_BOTTOM);
  5605. state.secondLabel.size = 12;
  5606. state.secondLabel.state = state;
  5607. state.secondLabel.dialect = mxConstants.DIALECT_STRICTHTML;
  5608. this.graph.cellRenderer.initializeLabel(state, state.secondLabel);
  5609. }
  5610. else if (!enumerate && state.secondLabel != null)
  5611. {
  5612. state.secondLabel.destroy();
  5613. state.secondLabel = null;
  5614. }
  5615. var shape = state.secondLabel;
  5616. if (shape != null)
  5617. {
  5618. var s = state.view.scale;
  5619. var value = this.createEnumerationValue(state);
  5620. var bounds = this.graph.model.isVertex(state.cell) ?
  5621. new mxRectangle(state.x + state.width - 4 * s, state.y + 4 * s, 0, 0) :
  5622. mxRectangle.fromPoint(state.view.getPoint(state));
  5623. if (!shape.bounds.equals(bounds) || shape.value != value || shape.scale != s)
  5624. {
  5625. shape.bounds = bounds;
  5626. shape.value = value;
  5627. shape.scale = s;
  5628. shape.redraw();
  5629. }
  5630. }
  5631. };
  5632. /**
  5633. * Adds workaround for math rendering in Chrome.
  5634. *
  5635. * Workaround for https://bugs.webkit.org/show_bug.cgi?id=93358 in WebKit
  5636. *
  5637. * Adding an absolute position DIV before the SVG seems to mitigate the problem.
  5638. */
  5639. var graphViewValidateBackgroundPage = mxGraphView.prototype.validateBackgroundPage;
  5640. mxGraphView.prototype.validateBackgroundPage = function()
  5641. {
  5642. graphViewValidateBackgroundPage.apply(this, arguments);
  5643. if (mxClient.IS_GC && this.getDrawPane() != null)
  5644. {
  5645. var g = this.getDrawPane().parentNode;
  5646. if (this.graph.mathEnabled && !mxClient.NO_FO &&
  5647. (this.webKitForceRepaintNode == null ||
  5648. this.webKitForceRepaintNode.parentNode == null) &&
  5649. this.graph.container.firstChild.nodeName == 'svg')
  5650. {
  5651. this.webKitForceRepaintNode = document.createElement('div');
  5652. this.webKitForceRepaintNode.style.cssText = 'position:absolute;';
  5653. g.ownerSVGElement.parentNode.insertBefore(this.webKitForceRepaintNode, g.ownerSVGElement);
  5654. }
  5655. else if (this.webKitForceRepaintNode != null && (!this.graph.mathEnabled ||
  5656. (this.graph.container.firstChild.nodeName != 'svg' &&
  5657. this.graph.container.firstChild != this.webKitForceRepaintNode)))
  5658. {
  5659. if (this.webKitForceRepaintNode.parentNode != null)
  5660. {
  5661. this.webKitForceRepaintNode.parentNode.removeChild(this.webKitForceRepaintNode);
  5662. }
  5663. this.webKitForceRepaintNode = null;
  5664. }
  5665. }
  5666. };
  5667. /**
  5668. * Updates the SVG for the background image if it references another page.
  5669. */
  5670. var graphRefresh = Graph.prototype.refresh;
  5671. Graph.prototype.refresh = function()
  5672. {
  5673. graphRefresh.apply(this, arguments);
  5674. this.refreshBackgroundImage();
  5675. };
  5676. /**
  5677. * Updates the SVG for the background image if it references another page.
  5678. */
  5679. Graph.prototype.refreshBackgroundImage = function()
  5680. {
  5681. if (this.backgroundImage != null && this.backgroundImage.originalSrc != null)
  5682. {
  5683. this.setBackgroundImage(this.backgroundImage);
  5684. this.view.validateBackgroundImage();
  5685. }
  5686. };
  5687. /**
  5688. * Sets default style (used in editor.get/setGraphXml below)
  5689. */
  5690. var graphLoadStylesheet = Graph.prototype.loadStylesheet;
  5691. Graph.prototype.loadStylesheet = function()
  5692. {
  5693. graphLoadStylesheet.apply(this, arguments);
  5694. this.currentStyle = 'default-style2';
  5695. };
  5696. /**
  5697. * Adds support for data:action/json,{"actions":[actions]} where actions is
  5698. * a comma-separated list of JSON objects.
  5699. *
  5700. * An example action is:
  5701. *
  5702. * data:action/json,{"actions":[{"toggle": {"cells": ["3", "4"]}}]}
  5703. *
  5704. * This toggles the visible state of the cells with ID 3 and 4.
  5705. */
  5706. Graph.prototype.handleCustomLink = function(href)
  5707. {
  5708. if (href.substring(0, 17) == 'data:action/json,')
  5709. {
  5710. var link = JSON.parse(href.substring(17));
  5711. if (link.actions != null)
  5712. {
  5713. this.executeCustomActions(link.actions);
  5714. }
  5715. }
  5716. };
  5717. /**
  5718. * Runs the given actions and invokes done when all actions have been executed.
  5719. * When adding new actions that reference cell IDs support for updating
  5720. * those cell IDs must be handled in Graph.updateCustomLinkActions
  5721. */
  5722. Graph.prototype.executeCustomActions = function(actions, done)
  5723. {
  5724. if (!this.executingCustomActions)
  5725. {
  5726. this.executingCustomActions = true;
  5727. var updatingModel = false;
  5728. var waitCounter = 0;
  5729. var index = 0;
  5730. var beginUpdate = mxUtils.bind(this, function()
  5731. {
  5732. if (!updatingModel)
  5733. {
  5734. updatingModel = true;
  5735. this.model.beginUpdate();
  5736. }
  5737. });
  5738. var endUpdate = mxUtils.bind(this, function()
  5739. {
  5740. if (updatingModel)
  5741. {
  5742. updatingModel = false;
  5743. this.model.endUpdate();
  5744. }
  5745. });
  5746. var waitAndExecute = mxUtils.bind(this, function()
  5747. {
  5748. if (waitCounter > 0)
  5749. {
  5750. waitCounter--;
  5751. }
  5752. if (waitCounter == 0)
  5753. {
  5754. executeNextAction()
  5755. }
  5756. });
  5757. var executeNextAction = mxUtils.bind(this, function()
  5758. {
  5759. if (index < actions.length)
  5760. {
  5761. var stop = this.stoppingCustomActions;
  5762. var action = actions[index++];
  5763. var animations = [];
  5764. // Executes open actions before starting transaction
  5765. if (action.open != null)
  5766. {
  5767. endUpdate();
  5768. if (this.isCustomLink(action.open))
  5769. {
  5770. if (!this.customLinkClicked(action.open))
  5771. {
  5772. return;
  5773. }
  5774. }
  5775. else
  5776. {
  5777. this.openLink(action.open);
  5778. }
  5779. }
  5780. if (action.wait != null && !stop)
  5781. {
  5782. this.pendingExecuteNextAction = mxUtils.bind(this, function()
  5783. {
  5784. this.pendingExecuteNextAction = null;
  5785. this.pendingWaitThread = null;
  5786. waitAndExecute();
  5787. });
  5788. waitCounter++;
  5789. this.pendingWaitThread = window.setTimeout(this.pendingExecuteNextAction,
  5790. (action.wait != '') ? parseInt(action.wait) : 1000);
  5791. endUpdate();
  5792. }
  5793. if (action.opacity != null && action.opacity.value != null)
  5794. {
  5795. Graph.setOpacityForNodes(this.getNodesForCells(
  5796. this.getCellsForAction(action.opacity, true)),
  5797. action.opacity.value);
  5798. }
  5799. if (action.fadeIn != null)
  5800. {
  5801. waitCounter++;
  5802. Graph.fadeNodes(this.getNodesForCells(
  5803. this.getCellsForAction(action.fadeIn, true)),
  5804. 0, 1, waitAndExecute, (stop) ?
  5805. 0 : action.fadeIn.delay);
  5806. }
  5807. if (action.fadeOut != null)
  5808. {
  5809. waitCounter++;
  5810. Graph.fadeNodes(this.getNodesForCells(
  5811. this.getCellsForAction(action.fadeOut, true)),
  5812. 1, 0, waitAndExecute, (stop) ?
  5813. 0 : action.fadeOut.delay);
  5814. }
  5815. if (action.wipeIn != null)
  5816. {
  5817. animations = animations.concat(this.createWipeAnimations(
  5818. this.getCellsForAction(action.wipeIn, true), true));
  5819. }
  5820. if (action.wipeOut != null)
  5821. {
  5822. animations = animations.concat(this.createWipeAnimations(
  5823. this.getCellsForAction(action.wipeOut, true), false));
  5824. }
  5825. // Executes all actions that change cell states
  5826. if (action.toggle != null)
  5827. {
  5828. beginUpdate();
  5829. this.toggleCells(this.getCellsForAction(action.toggle, true));
  5830. }
  5831. if (action.show != null)
  5832. {
  5833. beginUpdate();
  5834. var temp = this.getCellsForAction(action.show, true);
  5835. Graph.setOpacityForNodes(this.getNodesForCells(temp), 1);
  5836. this.setCellsVisible(temp, true);
  5837. }
  5838. if (action.hide != null)
  5839. {
  5840. beginUpdate();
  5841. var temp = this.getCellsForAction(action.hide, true);
  5842. Graph.setOpacityForNodes(this.getNodesForCells(temp), 0);
  5843. this.setCellsVisible(temp, false);
  5844. }
  5845. if (action.toggleStyle != null && action.toggleStyle.key != null)
  5846. {
  5847. beginUpdate();
  5848. this.toggleCellStyles(action.toggleStyle.key, (action.toggleStyle.defaultValue != null) ?
  5849. action.toggleStyle.defaultValue : '0', this.getCellsForAction(action.toggleStyle, true));
  5850. }
  5851. if (action.style != null && action.style.key != null)
  5852. {
  5853. beginUpdate();
  5854. this.setCellStyles(action.style.key, action.style.value,
  5855. this.getCellsForAction(action.style, true));
  5856. }
  5857. // Executes stateless actions on cells
  5858. var cells = [];
  5859. if (action.select != null && this.isEnabled())
  5860. {
  5861. cells = this.getCellsForAction(action.select);
  5862. this.setSelectionCells(cells);
  5863. }
  5864. if (action.highlight != null)
  5865. {
  5866. cells = this.getCellsForAction(action.highlight);
  5867. this.highlightCells(cells, action.highlight.color,
  5868. action.highlight.duration,
  5869. action.highlight.opacity);
  5870. }
  5871. if (action.scroll != null)
  5872. {
  5873. cells = this.getCellsForAction(action.scroll);
  5874. }
  5875. if (action.viewbox != null)
  5876. {
  5877. this.fitWindow(action.viewbox, action.viewbox.border);
  5878. }
  5879. if (cells.length > 0)
  5880. {
  5881. this.scrollCellToVisible(cells[0]);
  5882. }
  5883. if (action.tags != null)
  5884. {
  5885. var hidden = [];
  5886. if (action.tags.hidden != null)
  5887. {
  5888. hidden = hidden.concat(action.tags.hidden);
  5889. }
  5890. if (action.tags.visible != null)
  5891. {
  5892. var all = this.getAllTags();
  5893. for (var i = 0; i < all.length; i++)
  5894. {
  5895. if (mxUtils.indexOf(action.tags.visible, all[i]) < 0 &&
  5896. mxUtils.indexOf(hidden, all[i]) < 0)
  5897. {
  5898. hidden.push(all[i]);
  5899. }
  5900. }
  5901. }
  5902. this.setHiddenTags(hidden);
  5903. this.refresh();
  5904. }
  5905. if (animations.length > 0)
  5906. {
  5907. waitCounter++;
  5908. this.executeAnimations(animations, waitAndExecute,
  5909. (stop) ? 1 : action.steps,
  5910. (stop) ? 0 : action.delay);
  5911. }
  5912. if (waitCounter == 0)
  5913. {
  5914. executeNextAction();
  5915. }
  5916. else
  5917. {
  5918. endUpdate();
  5919. }
  5920. }
  5921. else
  5922. {
  5923. this.executingCustomActions = false;
  5924. this.stoppingCustomActions = false;
  5925. endUpdate();
  5926. if (done != null)
  5927. {
  5928. done();
  5929. }
  5930. }
  5931. });
  5932. executeNextAction();
  5933. }
  5934. else
  5935. {
  5936. this.stoppingCustomActions = true;
  5937. if (this.pendingWaitThread != null)
  5938. {
  5939. window.clearTimeout(this.pendingWaitThread);
  5940. }
  5941. if (this.pendingExecuteNextAction != null)
  5942. {
  5943. this.pendingExecuteNextAction();
  5944. }
  5945. this.fireEvent(new mxEventObject('stopExecutingCustomActions'));
  5946. }
  5947. };
  5948. /**
  5949. * Updates cell IDs in custom links on the given cell and its label.
  5950. */
  5951. Graph.prototype.doUpdateCustomLinksForCell = function(mapping, cell)
  5952. {
  5953. var href = this.getLinkForCell(cell);
  5954. if (href != null && href.substring(0, 17) == 'data:action/json,')
  5955. {
  5956. this.setLinkForCell(cell, this.updateCustomLink(mapping, href));
  5957. }
  5958. if (this.isHtmlLabel(cell))
  5959. {
  5960. var temp = document.createElement('div');
  5961. temp.innerHTML = this.sanitizeHtml(this.getLabel(cell));
  5962. var links = temp.getElementsByTagName('a');
  5963. var changed = false;
  5964. for (var i = 0; i < links.length; i++)
  5965. {
  5966. href = links[i].getAttribute('href');
  5967. if (href != null && href.substring(0, 17) == 'data:action/json,')
  5968. {
  5969. links[i].setAttribute('href', this.updateCustomLink(mapping, href));
  5970. changed = true;
  5971. }
  5972. }
  5973. if (changed)
  5974. {
  5975. this.labelChanged(cell, temp.innerHTML);
  5976. }
  5977. }
  5978. };
  5979. /**
  5980. * Updates cell IDs in the given custom link and returns the updated link.
  5981. */
  5982. Graph.prototype.updateCustomLink = function(mapping, href)
  5983. {
  5984. if (href.substring(0, 17) == 'data:action/json,')
  5985. {
  5986. try
  5987. {
  5988. var link = JSON.parse(href.substring(17));
  5989. if (link.actions != null)
  5990. {
  5991. this.updateCustomLinkActions(mapping, link.actions);
  5992. href = 'data:action/json,' + JSON.stringify(link);
  5993. }
  5994. }
  5995. catch (e)
  5996. {
  5997. // Ignore
  5998. }
  5999. }
  6000. return href;
  6001. };
  6002. /**
  6003. * Updates cell IDs in the given custom link actions.
  6004. */
  6005. Graph.prototype.updateCustomLinkActions = function(mapping, actions)
  6006. {
  6007. for (var i = 0; i < actions.length; i++)
  6008. {
  6009. var action = actions[i];
  6010. for (var name in action)
  6011. {
  6012. this.updateCustomLinkAction(mapping, action[name], 'cells');
  6013. this.updateCustomLinkAction(mapping, action[name], 'excludeCells');
  6014. }
  6015. }
  6016. };
  6017. /**
  6018. * Updates cell IDs in the given custom link action.
  6019. */
  6020. Graph.prototype.updateCustomLinkAction = function(mapping, action, name)
  6021. {
  6022. if (action != null && action[name] != null)
  6023. {
  6024. var result = [];
  6025. for (var i = 0; i < action[name].length; i++)
  6026. {
  6027. if (action[name][i] == '*')
  6028. {
  6029. result.push(action[name][i]);
  6030. }
  6031. else
  6032. {
  6033. var temp = mapping[action[name][i]];
  6034. if (temp != null)
  6035. {
  6036. if (temp != '')
  6037. {
  6038. result.push(temp);
  6039. }
  6040. }
  6041. else
  6042. {
  6043. result.push(action[name][i]);
  6044. }
  6045. }
  6046. }
  6047. action[name] = result;
  6048. }
  6049. };
  6050. /**
  6051. * Handles each action in the action array of a custom link. This code
  6052. * handles toggle actions for cell IDs.
  6053. */
  6054. Graph.prototype.getCellsForAction = function(action, layers)
  6055. {
  6056. var result = this.getCellsById(action.cells).concat(
  6057. this.getCellsForTags(action.tags, null, layers));
  6058. // Removes excluded cells
  6059. if (action.excludeCells != null)
  6060. {
  6061. var temp = [];
  6062. for (var i = 0; i < result.length; i++)
  6063. {
  6064. if (action.excludeCells.indexOf(result[i].id) < 0)
  6065. {
  6066. temp.push(result[i]);
  6067. }
  6068. }
  6069. result = temp;
  6070. }
  6071. return result;
  6072. };
  6073. /**
  6074. * Returns the cells in the model (or given array) that have all of the
  6075. * given tags in their tags property.
  6076. */
  6077. Graph.prototype.getCellsById = function(ids)
  6078. {
  6079. var result = [];
  6080. if (ids != null)
  6081. {
  6082. for (var i = 0; i < ids.length; i++)
  6083. {
  6084. if (ids[i] == '*')
  6085. {
  6086. var parent = this.model.getRoot();
  6087. result = result.concat(this.model.filterDescendants(function(cell)
  6088. {
  6089. return cell != parent;
  6090. }, parent));
  6091. }
  6092. else
  6093. {
  6094. var cell = this.model.getCell(ids[i]);
  6095. if (cell != null)
  6096. {
  6097. result.push(cell);
  6098. }
  6099. }
  6100. }
  6101. }
  6102. return result;
  6103. };
  6104. /**
  6105. * Adds support for custom fonts in cell styles.
  6106. */
  6107. var graphIsCellVisible = Graph.prototype.isCellVisible;
  6108. Graph.prototype.isCellVisible = function(cell)
  6109. {
  6110. return graphIsCellVisible.apply(this, arguments) &&
  6111. !this.isAllTagsHidden(this.getTagsForCell(cell));
  6112. };
  6113. /**
  6114. * Returns the tags for the given cell as a string.
  6115. */
  6116. Graph.prototype.setHiddenTags = function(tags)
  6117. {
  6118. this.hiddenTags = tags;
  6119. this.fireEvent(new mxEventObject('hiddenTagsChanged'));
  6120. };
  6121. /**
  6122. * Returns the tags for the given cell as a string.
  6123. */
  6124. Graph.prototype.toggleHiddenTag = function(tag)
  6125. {
  6126. var idx = mxUtils.indexOf(this.hiddenTags, tag);
  6127. if (idx < 0)
  6128. {
  6129. this.hiddenTags.push(tag);
  6130. }
  6131. else if (idx >= 0)
  6132. {
  6133. this.hiddenTags.splice(idx, 1);
  6134. }
  6135. this.fireEvent(new mxEventObject('hiddenTagsChanged'));
  6136. };
  6137. /**
  6138. * Returns the cells in the model (or given array) that have all of the
  6139. * given tags in their tags property.
  6140. */
  6141. Graph.prototype.isAllTagsHidden = function(tags)
  6142. {
  6143. if (tags == null || tags.length == 0 ||
  6144. this.hiddenTags.length == 0)
  6145. {
  6146. return false;
  6147. }
  6148. else
  6149. {
  6150. var tmp = tags.split(' ');
  6151. if (tmp.length > this.hiddenTags.length)
  6152. {
  6153. return false;
  6154. }
  6155. else
  6156. {
  6157. for (var i = 0; i < tmp.length; i++)
  6158. {
  6159. if (mxUtils.indexOf(this.hiddenTags, tmp[i]) < 0)
  6160. {
  6161. return false;
  6162. }
  6163. }
  6164. return true;
  6165. }
  6166. }
  6167. };
  6168. /**
  6169. * Returns the cells in the model (or given array) that have all of the
  6170. * given tags in their tags property.
  6171. */
  6172. Graph.prototype.getCellsForTags = function(tagList, cells, includeLayers, checkVisible)
  6173. {
  6174. var result = [];
  6175. if (tagList != null)
  6176. {
  6177. cells = (cells != null) ? cells : this.model.getDescendants(this.model.getRoot());
  6178. var tagCount = 0;
  6179. var lookup = {};
  6180. for (var i = 0; i < tagList.length; i++)
  6181. {
  6182. if (tagList[i].length > 0)
  6183. {
  6184. lookup[tagList[i]] = true;
  6185. tagCount++;
  6186. }
  6187. }
  6188. for (var i = 0; i < cells.length; i++)
  6189. {
  6190. if ((includeLayers && this.model.getParent(cells[i]) == this.model.root) ||
  6191. this.model.isVertex(cells[i]) || this.model.isEdge(cells[i]))
  6192. {
  6193. var tags = this.getTagsForCell(cells[i]);
  6194. var match = false;
  6195. if (tags.length > 0)
  6196. {
  6197. var tmp = tags.split(' ');
  6198. if (tmp.length >= tagList.length)
  6199. {
  6200. var matchCount = 0;
  6201. for (var j = 0; j < tmp.length && (matchCount < tagCount); j++)
  6202. {
  6203. if (lookup[tmp[j]] != null)
  6204. {
  6205. matchCount++;
  6206. }
  6207. }
  6208. match = matchCount == tagCount;
  6209. }
  6210. }
  6211. if (match && ((checkVisible != true) || this.isCellVisible(cells[i])))
  6212. {
  6213. result.push(cells[i]);
  6214. }
  6215. }
  6216. }
  6217. }
  6218. return result;
  6219. };
  6220. /**
  6221. * Returns all tags in the diagram.
  6222. */
  6223. Graph.prototype.getAllTags = function()
  6224. {
  6225. return this.getTagsForCells(
  6226. this.model.getDescendants(
  6227. this.model.getRoot()));
  6228. };
  6229. /**
  6230. * Returns the common tags for the given cells as a array.
  6231. */
  6232. Graph.prototype.getCommonTagsForCells = function(cells)
  6233. {
  6234. var commonTokens = null;
  6235. var validTags = [];
  6236. for (var i = 0; i < cells.length; i++)
  6237. {
  6238. var tags = this.getTagsForCell(cells[i]);
  6239. validTags = [];
  6240. if (tags.length > 0)
  6241. {
  6242. var tokens = tags.split(' ');
  6243. var temp = {};
  6244. for (var j = 0; j < tokens.length; j++)
  6245. {
  6246. if (commonTokens == null || commonTokens[tokens[j]] != null)
  6247. {
  6248. temp[tokens[j]] = true;
  6249. validTags.push(tokens[j]);
  6250. }
  6251. }
  6252. commonTokens = temp;
  6253. }
  6254. else
  6255. {
  6256. return [];
  6257. }
  6258. }
  6259. return validTags;
  6260. };
  6261. /**
  6262. * Returns all tags for the given cells as an array.
  6263. */
  6264. Graph.prototype.getTagsForCells = function(cells)
  6265. {
  6266. var tokens = [];
  6267. var temp = {};
  6268. for (var i = 0; i < cells.length; i++)
  6269. {
  6270. var tags = this.getTagsForCell(cells[i]);
  6271. if (tags.length > 0)
  6272. {
  6273. var t = tags.split(' ');
  6274. for (var j = 0; j < t.length; j++)
  6275. {
  6276. if (temp[t[j]] == null)
  6277. {
  6278. temp[t[j]] = true;
  6279. tokens.push(t[j]);
  6280. }
  6281. }
  6282. }
  6283. }
  6284. return tokens;
  6285. };
  6286. /**
  6287. * Returns the tags for the given cell as a string.
  6288. */
  6289. Graph.prototype.getTagsForCell = function(cell)
  6290. {
  6291. return this.getAttributeForCell(cell, 'tags', '');
  6292. };
  6293. /**
  6294. * Adds the given array of tags to the given array cells.
  6295. */
  6296. Graph.prototype.addTagsForCells = function(cells, tagList)
  6297. {
  6298. if (cells.length > 0 && tagList.length > 0)
  6299. {
  6300. this.model.beginUpdate();
  6301. try
  6302. {
  6303. for (var i = 0; i < cells.length; i++)
  6304. {
  6305. var temp = this.getTagsForCell(cells[i]);
  6306. var tags = temp.split(' ');
  6307. var changed = false;
  6308. for (var j = 0; j < tagList.length; j++)
  6309. {
  6310. var tag = mxUtils.trim(tagList[j]);
  6311. if (tag != '' && mxUtils.indexOf(tags, tag) < 0)
  6312. {
  6313. temp = (temp.length > 0) ? temp + ' ' + tag : tag;
  6314. changed = true;
  6315. }
  6316. }
  6317. if (changed)
  6318. {
  6319. this.setAttributeForCell(cells[i], 'tags', temp);
  6320. }
  6321. }
  6322. }
  6323. finally
  6324. {
  6325. this.model.endUpdate();
  6326. }
  6327. }
  6328. };
  6329. /**
  6330. * Removes the given array of tags from the given array cells.
  6331. */
  6332. Graph.prototype.removeTagsForCells = function(cells, tagList)
  6333. {
  6334. if (cells.length > 0 && tagList.length > 0)
  6335. {
  6336. this.model.beginUpdate();
  6337. try
  6338. {
  6339. for (var i = 0; i < cells.length; i++)
  6340. {
  6341. var tags = this.getTagsForCell(cells[i]);
  6342. if (tags.length > 0)
  6343. {
  6344. var tokens = tags.split(' ');
  6345. var changed = false;
  6346. for (var j = 0; j < tagList.length; j++)
  6347. {
  6348. var idx = mxUtils.indexOf(tokens, tagList[j]);
  6349. if (idx >= 0)
  6350. {
  6351. tokens.splice(idx, 1);
  6352. changed = true;
  6353. }
  6354. }
  6355. if (changed)
  6356. {
  6357. this.setAttributeForCell(cells[i], 'tags', tokens.join(' '));
  6358. }
  6359. }
  6360. }
  6361. }
  6362. finally
  6363. {
  6364. this.model.endUpdate();
  6365. }
  6366. }
  6367. };
  6368. /**
  6369. * Shows or hides the given cells.
  6370. */
  6371. Graph.prototype.toggleCells = function(cells)
  6372. {
  6373. this.model.beginUpdate();
  6374. try
  6375. {
  6376. for (var i = 0; i < cells.length; i++)
  6377. {
  6378. this.model.setVisible(cells[i], !this.model.isVisible(cells[i]))
  6379. }
  6380. }
  6381. finally
  6382. {
  6383. this.model.endUpdate();
  6384. }
  6385. };
  6386. /**
  6387. * Shows or hides the given cells.
  6388. */
  6389. Graph.prototype.setCellsVisible = function(cells, visible)
  6390. {
  6391. this.model.beginUpdate();
  6392. try
  6393. {
  6394. for (var i = 0; i < cells.length; i++)
  6395. {
  6396. this.model.setVisible(cells[i], visible);
  6397. }
  6398. }
  6399. finally
  6400. {
  6401. this.model.endUpdate();
  6402. }
  6403. };
  6404. /**
  6405. * Highlights the given cell.
  6406. */
  6407. Graph.prototype.highlightCells = function(cells, color, duration, opacity)
  6408. {
  6409. for (var i = 0; i < cells.length; i++)
  6410. {
  6411. this.highlightCell(cells[i], color, duration, opacity);
  6412. }
  6413. };
  6414. /**
  6415. * Highlights the given cell.
  6416. */
  6417. Graph.prototype.highlightCell = function(cell, color, duration, opacity, strokeWidth)
  6418. {
  6419. color = (color != null) ? color : mxConstants.DEFAULT_VALID_COLOR;
  6420. duration = (duration != null) ? duration : 1000;
  6421. var state = this.view.getState(cell);
  6422. var hl = null;
  6423. if (state != null)
  6424. {
  6425. strokeWidth = (strokeWidth != null) ? strokeWidth : 4;
  6426. var sw = Math.max(strokeWidth + 1, mxUtils.getValue(state.style,
  6427. mxConstants.STYLE_STROKEWIDTH, 1) + strokeWidth);
  6428. hl = new mxCellHighlight(this, color, sw, false);
  6429. if (opacity != null)
  6430. {
  6431. hl.opacity = opacity;
  6432. }
  6433. hl.highlight(state);
  6434. // Fades out the highlight after a duration
  6435. window.setTimeout(function()
  6436. {
  6437. if (hl.shape != null)
  6438. {
  6439. mxUtils.setPrefixedStyle(hl.shape.node.style,
  6440. 'transition', 'all 1200ms ease-in-out');
  6441. hl.shape.node.style.opacity = 0;
  6442. }
  6443. // Destroys the highlight after the fade
  6444. window.setTimeout(function()
  6445. {
  6446. hl.destroy();
  6447. }, 1200);
  6448. }, duration);
  6449. }
  6450. return hl;
  6451. };
  6452. /**
  6453. * Adds a shadow filter to the given svg root.
  6454. */
  6455. Graph.prototype.addSvgShadow = function(svgRoot, group, createOnly, extend)
  6456. {
  6457. createOnly = (createOnly != null) ? createOnly : false;
  6458. extend = (extend != null) ? extend : true;
  6459. var svgDoc = svgRoot.ownerDocument;
  6460. var filter = (svgDoc.createElementNS != null) ?
  6461. svgDoc.createElementNS(mxConstants.NS_SVG, 'filter') : svgDoc.createElement('filter');
  6462. filter.setAttribute('id', this.shadowId);
  6463. var blur = (svgDoc.createElementNS != null) ?
  6464. svgDoc.createElementNS(mxConstants.NS_SVG, 'feGaussianBlur') : svgDoc.createElement('feGaussianBlur');
  6465. blur.setAttribute('in', 'SourceAlpha');
  6466. blur.setAttribute('stdDeviation', this.svgShadowBlur);
  6467. blur.setAttribute('result', 'blur');
  6468. filter.appendChild(blur);
  6469. var offset = (svgDoc.createElementNS != null) ?
  6470. svgDoc.createElementNS(mxConstants.NS_SVG, 'feOffset') : svgDoc.createElement('feOffset');
  6471. offset.setAttribute('in', 'blur');
  6472. offset.setAttribute('dx', this.svgShadowSize);
  6473. offset.setAttribute('dy', this.svgShadowSize);
  6474. offset.setAttribute('result', 'offsetBlur');
  6475. filter.appendChild(offset);
  6476. var flood = (svgDoc.createElementNS != null) ?
  6477. svgDoc.createElementNS(mxConstants.NS_SVG, 'feFlood') : svgDoc.createElement('feFlood');
  6478. flood.setAttribute('flood-color', this.svgShadowColor);
  6479. flood.setAttribute('flood-opacity', this.svgShadowOpacity);
  6480. flood.setAttribute('result', 'offsetColor');
  6481. filter.appendChild(flood);
  6482. var composite = (svgDoc.createElementNS != null) ?
  6483. svgDoc.createElementNS(mxConstants.NS_SVG, 'feComposite') : svgDoc.createElement('feComposite');
  6484. composite.setAttribute('in', 'offsetColor');
  6485. composite.setAttribute('in2', 'offsetBlur');
  6486. composite.setAttribute('operator', 'in');
  6487. composite.setAttribute('result', 'offsetBlur');
  6488. filter.appendChild(composite);
  6489. var feBlend = (svgDoc.createElementNS != null) ?
  6490. svgDoc.createElementNS(mxConstants.NS_SVG, 'feBlend') : svgDoc.createElement('feBlend');
  6491. feBlend.setAttribute('in', 'SourceGraphic');
  6492. feBlend.setAttribute('in2', 'offsetBlur');
  6493. filter.appendChild(feBlend);
  6494. // Creates defs element if not available
  6495. var defs = svgRoot.getElementsByTagName('defs');
  6496. var defsElt = null;
  6497. if (defs.length == 0)
  6498. {
  6499. defsElt = (svgDoc.createElementNS != null) ?
  6500. svgDoc.createElementNS(mxConstants.NS_SVG, 'defs') : svgDoc.createElement('defs');
  6501. if (svgRoot.firstChild != null)
  6502. {
  6503. svgRoot.insertBefore(defsElt, svgRoot.firstChild);
  6504. }
  6505. else
  6506. {
  6507. svgRoot.appendChild(defsElt);
  6508. }
  6509. }
  6510. else
  6511. {
  6512. defsElt = defs[0];
  6513. }
  6514. defsElt.appendChild(filter);
  6515. if (!createOnly)
  6516. {
  6517. group = (group != null) ? group : svgRoot.getElementsByTagName('g')[0];
  6518. if (group != null)
  6519. {
  6520. group.setAttribute('filter', 'url(#' + this.shadowId + ')');
  6521. if (!isNaN(parseInt(svgRoot.getAttribute('width'))) && extend)
  6522. {
  6523. svgRoot.setAttribute('width', parseInt(svgRoot.getAttribute('width')) + 6);
  6524. svgRoot.setAttribute('height', parseInt(svgRoot.getAttribute('height')) + 6);
  6525. // Updates viewbox if one exists
  6526. var vb = svgRoot.getAttribute('viewBox');
  6527. if (vb != null && vb.length > 0)
  6528. {
  6529. var tokens = vb.split(' ');
  6530. if (tokens.length > 3)
  6531. {
  6532. w = parseFloat(tokens[2]) + 6;
  6533. h = parseFloat(tokens[3]) + 6;
  6534. svgRoot.setAttribute('viewBox', tokens[0] + ' ' + tokens[1] + ' ' + w + ' ' + h);
  6535. }
  6536. }
  6537. }
  6538. }
  6539. }
  6540. return filter;
  6541. };
  6542. /**
  6543. * Loads the stylesheet for this graph.
  6544. */
  6545. Graph.prototype.setShadowVisible = function(value, fireEvent)
  6546. {
  6547. if (mxClient.IS_SVG && !mxClient.IS_SF)
  6548. {
  6549. fireEvent = (fireEvent != null) ? fireEvent : true;
  6550. this.shadowVisible = value;
  6551. if (this.shadowVisible)
  6552. {
  6553. this.view.getDrawPane().setAttribute('filter', 'url(#' + this.shadowId + ')');
  6554. }
  6555. else
  6556. {
  6557. this.view.getDrawPane().removeAttribute('filter');
  6558. }
  6559. if (fireEvent)
  6560. {
  6561. this.fireEvent(new mxEventObject('shadowVisibleChanged'));
  6562. }
  6563. }
  6564. };
  6565. /**
  6566. * Selects first unlocked layer if one exists
  6567. */
  6568. Graph.prototype.selectUnlockedLayer = function()
  6569. {
  6570. if (this.defaultParent == null)
  6571. {
  6572. var childCount = this.model.getChildCount(this.model.root);
  6573. var cell = null;
  6574. var index = 0;
  6575. do
  6576. {
  6577. cell = this.model.getChildAt(this.model.root, index);
  6578. } while (index++ < childCount && mxUtils.getValue(this.getCellStyle(cell), 'locked', '0') == '1')
  6579. if (cell != null)
  6580. {
  6581. this.setDefaultParent(cell);
  6582. }
  6583. }
  6584. };
  6585. /**
  6586. * Specifies special libraries that are loaded via dynamic JS. Add cases
  6587. * where the filename cannot be worked out from the package name. The
  6588. * standard scheme for this mapping is stencils/packagename.xml. If there
  6589. * are multiple XML files, any JS files or any anomalies in the filename or
  6590. * directory that contains the file, then an entry must be added here and
  6591. * in EmbedServlet2 for the loading of the shapes to work.
  6592. */
  6593. // Required to avoid 404 for mockup.xml since naming of mxgraph.mockup.anchor does not contain
  6594. // buttons even though it is defined in the mxMockupButtons.js file. This could only be fixed
  6595. // with aliases for existing shapes or aliases for basenames, but this is essentially the same.
  6596. mxStencilRegistry.libraries['mockup'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  6597. mxStencilRegistry.libraries['arrows2'] = [SHAPES_PATH + '/mxArrows.js'];
  6598. mxStencilRegistry.libraries['atlassian'] = [STENCIL_PATH + '/atlassian.xml', SHAPES_PATH + '/mxAtlassian.js'];
  6599. mxStencilRegistry.libraries['bpmn'] = [SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/bpmn.xml', SHAPES_PATH + '/bpmn/mxBpmnShape2.js'];
  6600. mxStencilRegistry.libraries['bpmn2'] = [SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/bpmn.xml', SHAPES_PATH + '/bpmn/mxBpmnShape2.js'];
  6601. mxStencilRegistry.libraries['c4'] = [SHAPES_PATH + '/mxC4.js'];
  6602. mxStencilRegistry.libraries['cisco19'] = [SHAPES_PATH + '/mxCisco19.js', STENCIL_PATH + '/cisco19.xml'];
  6603. mxStencilRegistry.libraries['cisco_safe'] = [SHAPES_PATH + '/mxCiscoSafe.js', STENCIL_PATH + '/cisco_safe/architecture.xml', STENCIL_PATH + '/cisco_safe/business_icons.xml', STENCIL_PATH + '/cisco_safe/capability.xml', STENCIL_PATH + '/cisco_safe/design.xml', STENCIL_PATH + '/cisco_safe/iot_things_icons.xml', STENCIL_PATH + '/cisco_safe/people_places_things_icons.xml', STENCIL_PATH + '/cisco_safe/security_icons.xml', STENCIL_PATH + '/cisco_safe/technology_icons.xml', STENCIL_PATH + '/cisco_safe/threat.xml'];
  6604. mxStencilRegistry.libraries['dfd'] = [SHAPES_PATH + '/mxDFD.js'];
  6605. mxStencilRegistry.libraries['er'] = [SHAPES_PATH + '/er/mxER.js'];
  6606. mxStencilRegistry.libraries['kubernetes'] = [SHAPES_PATH + '/mxKubernetes.js', STENCIL_PATH + '/kubernetes.xml'];
  6607. mxStencilRegistry.libraries['flowchart'] = [SHAPES_PATH + '/mxFlowchart.js', STENCIL_PATH + '/flowchart.xml'];
  6608. mxStencilRegistry.libraries['ios'] = [SHAPES_PATH + '/mockup/mxMockupiOS.js'];
  6609. mxStencilRegistry.libraries['rackGeneral'] = [SHAPES_PATH + '/rack/mxRack.js', STENCIL_PATH + '/rack/general.xml'];
  6610. mxStencilRegistry.libraries['rackF5'] = [STENCIL_PATH + '/rack/f5.xml'];
  6611. mxStencilRegistry.libraries['lean_mapping'] = [SHAPES_PATH + '/mxLeanMap.js', STENCIL_PATH + '/lean_mapping.xml'];
  6612. mxStencilRegistry.libraries['basic'] = [SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/basic.xml'];
  6613. mxStencilRegistry.libraries['ios7icons'] = [STENCIL_PATH + '/ios7/icons.xml'];
  6614. mxStencilRegistry.libraries['ios7ui'] = [SHAPES_PATH + '/ios7/mxIOS7Ui.js', STENCIL_PATH + '/ios7/misc.xml'];
  6615. mxStencilRegistry.libraries['android'] = [SHAPES_PATH + '/mxAndroid.js', STENCIL_PATH + '/android/android.xml'];
  6616. mxStencilRegistry.libraries['electrical/abstract'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/abstract.xml'];
  6617. mxStencilRegistry.libraries['electrical/logic_gates'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/logic_gates.xml'];
  6618. mxStencilRegistry.libraries['electrical/miscellaneous'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/miscellaneous.xml'];
  6619. mxStencilRegistry.libraries['electrical/signal_sources'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/signal_sources.xml'];
  6620. mxStencilRegistry.libraries['electrical/electro-mechanical'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/electro-mechanical.xml'];
  6621. mxStencilRegistry.libraries['electrical/transmission'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/transmission.xml'];
  6622. mxStencilRegistry.libraries['infographic'] = [SHAPES_PATH + '/mxInfographic.js'];
  6623. mxStencilRegistry.libraries['mockup/buttons'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  6624. mxStencilRegistry.libraries['mockup/containers'] = [SHAPES_PATH + '/mockup/mxMockupContainers.js'];
  6625. mxStencilRegistry.libraries['mockup/forms'] = [SHAPES_PATH + '/mockup/mxMockupForms.js'];
  6626. mxStencilRegistry.libraries['mockup/graphics'] = [SHAPES_PATH + '/mockup/mxMockupGraphics.js', STENCIL_PATH + '/mockup/misc.xml'];
  6627. mxStencilRegistry.libraries['mockup/markup'] = [SHAPES_PATH + '/mockup/mxMockupMarkup.js'];
  6628. mxStencilRegistry.libraries['mockup/misc'] = [SHAPES_PATH + '/mockup/mxMockupMisc.js', STENCIL_PATH + '/mockup/misc.xml'];
  6629. mxStencilRegistry.libraries['mockup/navigation'] = [SHAPES_PATH + '/mockup/mxMockupNavigation.js', STENCIL_PATH + '/mockup/misc.xml'];
  6630. mxStencilRegistry.libraries['mockup/text'] = [SHAPES_PATH + '/mockup/mxMockupText.js'];
  6631. mxStencilRegistry.libraries['floorplan'] = [SHAPES_PATH + '/mxFloorplan.js', STENCIL_PATH + '/floorplan.xml'];
  6632. mxStencilRegistry.libraries['bootstrap'] = [SHAPES_PATH + '/mxBootstrap.js', SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/bootstrap.xml'];
  6633. mxStencilRegistry.libraries['gmdl'] = [SHAPES_PATH + '/mxGmdl.js', STENCIL_PATH + '/gmdl.xml'];
  6634. mxStencilRegistry.libraries['gcp2'] = [SHAPES_PATH + '/mxGCP2.js', STENCIL_PATH + '/gcp2.xml'];
  6635. mxStencilRegistry.libraries['ibm'] = [SHAPES_PATH + '/mxIBM.js', STENCIL_PATH + '/ibm.xml'];
  6636. mxStencilRegistry.libraries['cabinets'] = [SHAPES_PATH + '/mxCabinets.js', STENCIL_PATH + '/cabinets.xml'];
  6637. mxStencilRegistry.libraries['archimate'] = [SHAPES_PATH + '/mxArchiMate.js'];
  6638. mxStencilRegistry.libraries['archimate3'] = [SHAPES_PATH + '/mxArchiMate3.js'];
  6639. mxStencilRegistry.libraries['sysml'] = [SHAPES_PATH + '/mxSysML.js'];
  6640. mxStencilRegistry.libraries['eip'] = [SHAPES_PATH + '/mxEip.js', STENCIL_PATH + '/eip.xml'];
  6641. mxStencilRegistry.libraries['networks'] = [SHAPES_PATH + '/mxNetworks.js', STENCIL_PATH + '/networks.xml'];
  6642. mxStencilRegistry.libraries['aws3d'] = [SHAPES_PATH + '/mxAWS3D.js', STENCIL_PATH + '/aws3d.xml'];
  6643. mxStencilRegistry.libraries['aws4'] = [SHAPES_PATH + '/mxAWS4.js', STENCIL_PATH + '/aws4.xml'];
  6644. mxStencilRegistry.libraries['aws4b'] = [SHAPES_PATH + '/mxAWS4.js', STENCIL_PATH + '/aws4.xml'];
  6645. mxStencilRegistry.libraries['uml25'] = [SHAPES_PATH + '/mxUML25.js'];
  6646. mxStencilRegistry.libraries['veeam'] = [STENCIL_PATH + '/veeam/2d.xml', STENCIL_PATH + '/veeam/3d.xml', STENCIL_PATH + '/veeam/veeam.xml'];
  6647. mxStencilRegistry.libraries['veeam2'] = [STENCIL_PATH + '/veeam/2d.xml', STENCIL_PATH + '/veeam/3d.xml', STENCIL_PATH + '/veeam/veeam2.xml'];
  6648. mxStencilRegistry.libraries['pid2inst'] = [SHAPES_PATH + '/pid2/mxPidInstruments.js'];
  6649. mxStencilRegistry.libraries['pid2misc'] = [SHAPES_PATH + '/pid2/mxPidMisc.js', STENCIL_PATH + '/pid/misc.xml'];
  6650. mxStencilRegistry.libraries['pid2valves'] = [SHAPES_PATH + '/pid2/mxPidValves.js'];
  6651. mxStencilRegistry.libraries['pidFlowSensors'] = [STENCIL_PATH + '/pid/flow_sensors.xml'];
  6652. // Triggers dynamic loading for markers
  6653. mxMarker.getPackageForType = function(type)
  6654. {
  6655. var name = null;
  6656. if (type != null && type.length > 0)
  6657. {
  6658. if (type.substring(0, 2) == 'ER')
  6659. {
  6660. name = 'mxgraph.er';
  6661. }
  6662. else if (type.substring(0, 5) == 'sysML')
  6663. {
  6664. name = 'mxgraph.sysml';
  6665. }
  6666. }
  6667. return name;
  6668. };
  6669. var mxMarkerCreateMarker = mxMarker.createMarker;
  6670. mxMarker.createMarker = function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  6671. {
  6672. if (type != null)
  6673. {
  6674. var f = mxMarker.markers[type];
  6675. if (f == null)
  6676. {
  6677. var name = this.getPackageForType(type);
  6678. if (name != null)
  6679. {
  6680. mxStencilRegistry.getStencil(name);
  6681. }
  6682. }
  6683. }
  6684. return mxMarkerCreateMarker.apply(this, arguments);
  6685. };
  6686. /**
  6687. * Adds style to mark stencils as lines.
  6688. */
  6689. var mxStencilDrawShape = mxStencil.prototype.drawShape;
  6690. mxStencil.prototype.drawShape = function(canvas, shape, x, y, w, h)
  6691. {
  6692. if (mxUtils.getValue(shape.style, 'lineShape', null) == '1')
  6693. {
  6694. canvas.setFillColor(mxUtils.getValue(shape.style,
  6695. mxConstants.STYLE_STROKECOLOR, this.stroke));
  6696. }
  6697. return mxStencilDrawShape.apply(this, arguments);
  6698. };
  6699. /**
  6700. * Constructs a new print dialog.
  6701. */
  6702. PrintDialog.prototype.create = function(editorUi, titleText)
  6703. {
  6704. var graph = editorUi.editor.graph;
  6705. var div = document.createElement('div');
  6706. var title = document.createElement('h3');
  6707. title.style.width = '100%';
  6708. title.style.textAlign = 'center';
  6709. title.style.marginTop = '0px';
  6710. mxUtils.write(title, titleText || mxResources.get('print'));
  6711. div.appendChild(title);
  6712. var pageCount = 1;
  6713. var currentPage = 1;
  6714. // Pages
  6715. var pagesSection = document.createElement('div');
  6716. pagesSection.style.cssText = 'border-bottom:1px solid lightGray;padding-bottom:12px;margin-bottom:12px;';
  6717. var allPagesRadio = document.createElement('input');
  6718. allPagesRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  6719. allPagesRadio.setAttribute('value', 'all');
  6720. allPagesRadio.setAttribute('type', 'radio');
  6721. allPagesRadio.setAttribute('name', 'pages-printdialog');
  6722. pagesSection.appendChild(allPagesRadio);
  6723. var span = document.createElement('span');
  6724. mxUtils.write(span, mxResources.get('printAllPages'));
  6725. pagesSection.appendChild(span);
  6726. mxUtils.br(pagesSection);
  6727. // Page range
  6728. var pagesRadio = allPagesRadio.cloneNode(true);
  6729. allPagesRadio.setAttribute('checked', 'checked');
  6730. pagesRadio.setAttribute('value', 'range');
  6731. pagesSection.appendChild(pagesRadio);
  6732. var span = document.createElement('span');
  6733. mxUtils.write(span, mxResources.get('pages') + ':');
  6734. pagesSection.appendChild(span);
  6735. var pagesFromInput = document.createElement('input');
  6736. pagesFromInput.style.cssText = 'margin:0 8px 0 8px;'
  6737. pagesFromInput.setAttribute('value', '1');
  6738. pagesFromInput.setAttribute('type', 'number');
  6739. pagesFromInput.setAttribute('min', '1');
  6740. pagesFromInput.style.width = '50px';
  6741. pagesSection.appendChild(pagesFromInput);
  6742. var span = document.createElement('span');
  6743. mxUtils.write(span, mxResources.get('to'));
  6744. pagesSection.appendChild(span);
  6745. var pagesToInput = pagesFromInput.cloneNode(true);
  6746. pagesSection.appendChild(pagesToInput);
  6747. mxEvent.addListener(pagesFromInput, 'focus', function()
  6748. {
  6749. pagesRadio.checked = true;
  6750. });
  6751. mxEvent.addListener(pagesToInput, 'focus', function()
  6752. {
  6753. pagesRadio.checked = true;
  6754. });
  6755. function validatePageRange()
  6756. {
  6757. pagesToInput.value = Math.max(1, Math.min(pageCount, Math.max(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  6758. pagesFromInput.value = Math.max(1, Math.min(pageCount, Math.min(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  6759. };
  6760. mxEvent.addListener(pagesFromInput, 'change', validatePageRange);
  6761. mxEvent.addListener(pagesToInput, 'change', validatePageRange);
  6762. if (editorUi.pages != null)
  6763. {
  6764. pageCount = editorUi.pages.length;
  6765. if (editorUi.currentPage != null)
  6766. {
  6767. for (var i = 0; i < editorUi.pages.length; i++)
  6768. {
  6769. if (editorUi.currentPage == editorUi.pages[i])
  6770. {
  6771. currentPage = i + 1;
  6772. pagesFromInput.value = currentPage;
  6773. pagesToInput.value = currentPage;
  6774. break;
  6775. }
  6776. }
  6777. }
  6778. }
  6779. pagesFromInput.setAttribute('max', pageCount);
  6780. pagesToInput.setAttribute('max', pageCount);
  6781. if (!editorUi.isPagesEnabled())
  6782. {
  6783. pagesRadio.checked = true;
  6784. }
  6785. else if (pageCount > 1)
  6786. {
  6787. div.appendChild(pagesSection);
  6788. pagesRadio.checked = true;
  6789. }
  6790. mxUtils.br(pagesSection);
  6791. // Selection only
  6792. var selectionOnlyRadio = document.createElement('input');
  6793. selectionOnlyRadio.setAttribute('value', 'all');
  6794. selectionOnlyRadio.setAttribute('type', 'radio');
  6795. selectionOnlyRadio.style.marginRight = '8px';
  6796. if (graph.isSelectionEmpty())
  6797. {
  6798. selectionOnlyRadio.setAttribute('disabled', 'disabled');
  6799. }
  6800. // Adjust to ...
  6801. var adjustSection = document.createElement('div');
  6802. adjustSection.style.marginBottom = '10px';
  6803. if (pageCount == 1)
  6804. {
  6805. selectionOnlyRadio.setAttribute('type', 'checkbox');
  6806. selectionOnlyRadio.style.marginBottom = '12px';
  6807. adjustSection.appendChild(selectionOnlyRadio);
  6808. }
  6809. else
  6810. {
  6811. selectionOnlyRadio.setAttribute('name', 'pages-printdialog');
  6812. selectionOnlyRadio.style.marginBottom = '8px';
  6813. pagesSection.appendChild(selectionOnlyRadio);
  6814. }
  6815. var span = document.createElement('span');
  6816. mxUtils.write(span, mxResources.get('selectionOnly'));
  6817. selectionOnlyRadio.parentNode.appendChild(span);
  6818. if (pageCount == 1)
  6819. {
  6820. mxUtils.br(selectionOnlyRadio.parentNode);
  6821. }
  6822. var adjustRadio = document.createElement('input');
  6823. adjustRadio.style.marginRight = '8px';
  6824. adjustRadio.setAttribute('value', 'adjust');
  6825. adjustRadio.setAttribute('type', 'radio');
  6826. adjustRadio.setAttribute('name', 'printZoom');
  6827. adjustSection.appendChild(adjustRadio);
  6828. var span = document.createElement('span');
  6829. mxUtils.write(span, mxResources.get('adjustTo'));
  6830. adjustSection.appendChild(span);
  6831. var zoomInput = document.createElement('input');
  6832. zoomInput.style.cssText = 'margin:0 8px 0 8px;';
  6833. zoomInput.setAttribute('value', '100 %');
  6834. zoomInput.style.width = '50px';
  6835. adjustSection.appendChild(zoomInput);
  6836. mxEvent.addListener(zoomInput, 'focus', function()
  6837. {
  6838. adjustRadio.checked = true;
  6839. });
  6840. div.appendChild(adjustSection);
  6841. // Fit to ...
  6842. var fitSection = pagesSection.cloneNode(false);
  6843. var fitRadio = adjustRadio.cloneNode(true);
  6844. fitRadio.setAttribute('value', 'fit');
  6845. adjustRadio.setAttribute('checked', 'checked');
  6846. var spanFitRadio = document.createElement('div');
  6847. spanFitRadio.style.cssText = 'display:inline-block;vertical-align:top;padding-top:2px;';
  6848. spanFitRadio.appendChild(fitRadio);
  6849. fitSection.appendChild(spanFitRadio);
  6850. var table = document.createElement('table');
  6851. table.style.display = 'inline-block';
  6852. var tbody = document.createElement('tbody');
  6853. var row1 = document.createElement('tr');
  6854. var row2 = row1.cloneNode(true);
  6855. var td1 = document.createElement('td');
  6856. var td2 = td1.cloneNode(true);
  6857. var td3 = td1.cloneNode(true);
  6858. var td4 = td1.cloneNode(true);
  6859. var td5 = td1.cloneNode(true);
  6860. var td6 = td1.cloneNode(true);
  6861. td1.style.textAlign = 'right';
  6862. td4.style.textAlign = 'right';
  6863. mxUtils.write(td1, mxResources.get('fitTo'));
  6864. var sheetsAcrossInput = document.createElement('input');
  6865. sheetsAcrossInput.style.cssText = 'margin:0 8px 0 8px;';
  6866. sheetsAcrossInput.setAttribute('value', '1');
  6867. sheetsAcrossInput.setAttribute('min', '1');
  6868. sheetsAcrossInput.setAttribute('type', 'number');
  6869. sheetsAcrossInput.style.width = '40px';
  6870. td2.appendChild(sheetsAcrossInput);
  6871. var span = document.createElement('span');
  6872. mxUtils.write(span, mxResources.get('fitToSheetsAcross'));
  6873. td3.appendChild(span);
  6874. mxUtils.write(td4, mxResources.get('fitToBy'));
  6875. var sheetsDownInput = sheetsAcrossInput.cloneNode(true);
  6876. td5.appendChild(sheetsDownInput);
  6877. mxEvent.addListener(sheetsAcrossInput, 'focus', function()
  6878. {
  6879. fitRadio.checked = true;
  6880. });
  6881. mxEvent.addListener(sheetsDownInput, 'focus', function()
  6882. {
  6883. fitRadio.checked = true;
  6884. });
  6885. var span = document.createElement('span');
  6886. mxUtils.write(span, mxResources.get('fitToSheetsDown'));
  6887. td6.appendChild(span);
  6888. row1.appendChild(td1);
  6889. row1.appendChild(td2);
  6890. row1.appendChild(td3);
  6891. row2.appendChild(td4);
  6892. row2.appendChild(td5);
  6893. row2.appendChild(td6);
  6894. tbody.appendChild(row1);
  6895. tbody.appendChild(row2);
  6896. table.appendChild(tbody);
  6897. fitSection.appendChild(table);
  6898. div.appendChild(fitSection);
  6899. // Page scale ...
  6900. var pageScaleSection = document.createElement('div');
  6901. var span = document.createElement('div');
  6902. span.style.fontWeight = 'bold';
  6903. span.style.marginBottom = '12px';
  6904. mxUtils.write(span, mxResources.get('paperSize'));
  6905. pageScaleSection.appendChild(span);
  6906. var span = document.createElement('div');
  6907. span.style.marginBottom = '12px';
  6908. var accessor = PageSetupDialog.addPageFormatPanel(span, 'printdialog',
  6909. editorUi.editor.graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT);
  6910. pageScaleSection.appendChild(span);
  6911. var span = document.createElement('span');
  6912. mxUtils.write(span, mxResources.get('pageScale'));
  6913. pageScaleSection.appendChild(span);
  6914. var pageScaleInput = document.createElement('input');
  6915. pageScaleInput.style.cssText = 'margin:0 8px 0 8px;';
  6916. pageScaleInput.setAttribute('value', '100 %');
  6917. pageScaleInput.style.width = '60px';
  6918. pageScaleSection.appendChild(pageScaleInput);
  6919. div.appendChild(pageScaleSection);
  6920. // Buttons
  6921. var buttons = document.createElement('div');
  6922. buttons.style.cssText = 'text-align:right;margin:48px 0 0 0;';
  6923. // Overall scale for print-out to account for print borders in dialogs etc
  6924. function preview(print)
  6925. {
  6926. var printScale = parseInt(pageScaleInput.value) / 100;
  6927. if (isNaN(printScale))
  6928. {
  6929. printScale = 1;
  6930. pageScaleInput.value = '100 %';
  6931. }
  6932. // Workaround to match available paper size in actual print output
  6933. printScale *= 0.75;
  6934. // Disables dark mode while printing
  6935. var darkStylesheet = null;
  6936. var darkFg = graph.shapeForegroundColor;
  6937. var darkBg = graph.shapeBackgroundColor;
  6938. if (graph.themes != null && graph.defaultThemeName == 'darkTheme')
  6939. {
  6940. darkStylesheet = graph.stylesheet;
  6941. graph.stylesheet = graph.getDefaultStylesheet()
  6942. graph.shapeForegroundColor = '#000000';
  6943. graph.shapeBackgroundColor = '#ffffff';
  6944. graph.refresh();
  6945. }
  6946. function printGraph(thisGraph, pv, forcePageBreaks)
  6947. {
  6948. // Workaround for CSS transforms affecting the print output
  6949. // is to disable during print output and restore after
  6950. var prev = thisGraph.useCssTransforms;
  6951. var prevTranslate = thisGraph.currentTranslate;
  6952. var prevScale = thisGraph.currentScale;
  6953. var prevViewTranslate = thisGraph.view.translate;
  6954. var prevViewScale = thisGraph.view.scale;
  6955. if (thisGraph.useCssTransforms)
  6956. {
  6957. thisGraph.useCssTransforms = false;
  6958. thisGraph.currentTranslate = new mxPoint(0,0);
  6959. thisGraph.currentScale = 1;
  6960. thisGraph.view.translate = new mxPoint(0,0);
  6961. thisGraph.view.scale = 1;
  6962. }
  6963. // Negative coordinates are cropped or shifted if page visible
  6964. var gb = thisGraph.getGraphBounds();
  6965. var border = 0;
  6966. var x0 = 0;
  6967. var y0 = 0;
  6968. var pf = accessor.get();
  6969. var scale = 1 / thisGraph.pageScale;
  6970. var autoOrigin = fitRadio.checked;
  6971. if (autoOrigin)
  6972. {
  6973. var h = parseInt(sheetsAcrossInput.value);
  6974. var v = parseInt(sheetsDownInput.value);
  6975. scale = Math.min((pf.height * v) / (gb.height / thisGraph.view.scale),
  6976. (pf.width * h) / (gb.width / thisGraph.view.scale));
  6977. }
  6978. else
  6979. {
  6980. scale = parseInt(zoomInput.value) / (100 * thisGraph.pageScale);
  6981. if (isNaN(scale))
  6982. {
  6983. printScale = 1 / thisGraph.pageScale;
  6984. zoomInput.value = '100 %';
  6985. }
  6986. }
  6987. // Applies print scale
  6988. pf = mxRectangle.fromRectangle(pf);
  6989. pf.width = Math.ceil(pf.width * printScale);
  6990. pf.height = Math.ceil(pf.height * printScale);
  6991. scale *= printScale;
  6992. // Starts at first visible page
  6993. if (!autoOrigin && thisGraph.pageVisible)
  6994. {
  6995. var layout = thisGraph.getPageLayout();
  6996. x0 -= layout.x * pf.width;
  6997. y0 -= layout.y * pf.height;
  6998. }
  6999. else
  7000. {
  7001. autoOrigin = true;
  7002. }
  7003. if (pv == null)
  7004. {
  7005. pv = PrintDialog.createPrintPreview(thisGraph, scale, pf, border, x0, y0, autoOrigin);
  7006. pv.pageSelector = false;
  7007. pv.mathEnabled = false;
  7008. if (selectionOnlyRadio.checked)
  7009. {
  7010. pv.isCellVisible = function(cell)
  7011. {
  7012. return thisGraph.isCellSelected(cell);
  7013. };
  7014. }
  7015. var file = editorUi.getCurrentFile();
  7016. if (file != null)
  7017. {
  7018. pv.title = file.getTitle();
  7019. }
  7020. var writeHead = pv.writeHead;
  7021. // Overridden to add custom fonts
  7022. pv.writeHead = function(doc)
  7023. {
  7024. writeHead.apply(this, arguments);
  7025. // Fixes bold math when exported to PDF
  7026. if (mxClient.IS_GC)
  7027. {
  7028. doc.writeln('<style type="text/css">');
  7029. doc.writeln('@media print {');
  7030. doc.writeln('.MathJax svg { shape-rendering: crispEdges; }');
  7031. doc.writeln('}');
  7032. doc.writeln('</style>');
  7033. }
  7034. if (editorUi.editor.fontCss != null)
  7035. {
  7036. doc.writeln('<style type="text/css">');
  7037. doc.writeln(editorUi.editor.fontCss);
  7038. doc.writeln('</style>');
  7039. }
  7040. var extFonts = thisGraph.getCustomFonts();
  7041. for (var i = 0; i < extFonts.length; i++)
  7042. {
  7043. var fontName = extFonts[i].name;
  7044. var fontUrl = extFonts[i].url;
  7045. if (Graph.isCssFontUrl(fontUrl))
  7046. {
  7047. doc.writeln('<link rel="stylesheet" href="' +
  7048. mxUtils.htmlEntities(fontUrl) +
  7049. '" charset="UTF-8" type="text/css">');
  7050. }
  7051. else
  7052. {
  7053. doc.writeln('<style type="text/css">');
  7054. doc.writeln('@font-face {\n' +
  7055. 'font-family: "' + mxUtils.htmlEntities(fontName) + '";\n' +
  7056. 'src: url("' + mxUtils.htmlEntities(fontUrl) + '");\n}');
  7057. doc.writeln('</style>');
  7058. }
  7059. }
  7060. };
  7061. if (typeof(MathJax) !== 'undefined')
  7062. {
  7063. // Adds class to ignore if math is disabled
  7064. var printPreviewRenderPage = pv.renderPage;
  7065. pv.renderPage = function(w, h, dx, dy, content, pageNumber)
  7066. {
  7067. var prev = mxClient.NO_FO;
  7068. var result = printPreviewRenderPage.apply(this, arguments);
  7069. mxClient.NO_FO = prev;
  7070. if (this.graph.mathEnabled)
  7071. {
  7072. this.mathEnabled = this.mathEnabled || true;
  7073. }
  7074. else
  7075. {
  7076. result.className = 'geDisableMathJax';
  7077. }
  7078. return result;
  7079. };
  7080. }
  7081. // Switches stylesheet for print output in dark mode
  7082. var temp = null;
  7083. var tempFg = graph.shapeForegroundColor;
  7084. var tempBg = graph.shapeBackgroundColor;
  7085. // Disables dashed printing of flowAnimation
  7086. var enableFlowAnimation = graph.enableFlowAnimation;
  7087. graph.enableFlowAnimation = false;
  7088. if (graph.themes != null && graph.defaultThemeName == 'darkTheme')
  7089. {
  7090. temp = graph.stylesheet;
  7091. graph.stylesheet = graph.getDefaultStylesheet()
  7092. graph.shapeForegroundColor = '#000000';
  7093. graph.shapeBackgroundColor = '#ffffff';
  7094. graph.refresh();
  7095. }
  7096. // Generates the print output
  7097. pv.open(null, null, forcePageBreaks, true);
  7098. // Restores flowAnimation
  7099. graph.enableFlowAnimation = enableFlowAnimation;
  7100. // Restores the stylesheet
  7101. if (temp != null)
  7102. {
  7103. graph.shapeForegroundColor = tempFg;
  7104. graph.shapeBackgroundColor = tempBg;
  7105. graph.stylesheet = temp;
  7106. graph.refresh();
  7107. }
  7108. }
  7109. else
  7110. {
  7111. var bg = thisGraph.background;
  7112. if (bg == null || bg == '' || bg == mxConstants.NONE)
  7113. {
  7114. bg = '#ffffff';
  7115. }
  7116. pv.backgroundColor = bg;
  7117. pv.autoOrigin = autoOrigin;
  7118. pv.appendGraph(thisGraph, scale, x0, y0, forcePageBreaks, true);
  7119. var extFonts = thisGraph.getCustomFonts();
  7120. if (pv.wnd != null)
  7121. {
  7122. for (var i = 0; i < extFonts.length; i++)
  7123. {
  7124. var fontName = extFonts[i].name;
  7125. var fontUrl = extFonts[i].url;
  7126. if (Graph.isCssFontUrl(fontUrl))
  7127. {
  7128. pv.wnd.document.writeln('<link rel="stylesheet" href="' +
  7129. mxUtils.htmlEntities(fontUrl) +
  7130. '" charset="UTF-8" type="text/css">');
  7131. }
  7132. else
  7133. {
  7134. pv.wnd.document.writeln('<style type="text/css">');
  7135. pv.wnd.document.writeln('@font-face {\n' +
  7136. 'font-family: "' + mxUtils.htmlEntities(fontName) + '";\n' +
  7137. 'src: url("' + mxUtils.htmlEntities(fontUrl) + '");\n}');
  7138. pv.wnd.document.writeln('</style>');
  7139. }
  7140. }
  7141. }
  7142. }
  7143. // Restores state if css transforms are used
  7144. if (prev)
  7145. {
  7146. thisGraph.useCssTransforms = prev;
  7147. thisGraph.currentTranslate = prevTranslate;
  7148. thisGraph.currentScale = prevScale;
  7149. thisGraph.view.translate = prevViewTranslate;
  7150. thisGraph.view.scale = prevViewScale;
  7151. }
  7152. return pv;
  7153. };
  7154. var pagesFrom = pagesFromInput.value;
  7155. var pagesTo = pagesToInput.value;
  7156. var ignorePages = !allPagesRadio.checked;
  7157. var pv = null;
  7158. if (EditorUi.isElectronApp)
  7159. {
  7160. PrintDialog.electronPrint(editorUi, allPagesRadio.checked, pagesFrom, pagesTo, fitRadio.checked,
  7161. sheetsAcrossInput.value, sheetsDownInput.value, parseInt(zoomInput.value) / 100,
  7162. parseInt(pageScaleInput.value) / 100, accessor.get());
  7163. return;
  7164. }
  7165. if (ignorePages)
  7166. {
  7167. ignorePages = selectionOnlyRadio.checked ||
  7168. (pagesFrom == currentPage &&
  7169. pagesTo == currentPage);
  7170. }
  7171. if (!ignorePages && editorUi.pages != null && editorUi.pages.length)
  7172. {
  7173. var i0 = 0;
  7174. var imax = editorUi.pages.length - 1;
  7175. if (!allPagesRadio.checked)
  7176. {
  7177. i0 = parseInt(pagesFrom) - 1;
  7178. imax = parseInt(pagesTo) - 1;
  7179. }
  7180. for (var i = i0; i <= imax; i++)
  7181. {
  7182. var page = editorUi.pages[i];
  7183. var tempGraph = (page == editorUi.currentPage) ? graph : null;
  7184. if (tempGraph == null)
  7185. {
  7186. tempGraph = editorUi.createTemporaryGraph(graph.stylesheet);
  7187. tempGraph.shapeForegroundColor = graph.shapeForegroundColor;
  7188. tempGraph.shapeBackgroundColor = graph.shapeBackgroundColor;
  7189. // Restores graph settings that are relevant for printing
  7190. var pageVisible = true;
  7191. var mathEnabled = false;
  7192. var bg = null;
  7193. var bgImage = null;
  7194. if (page.viewState == null)
  7195. {
  7196. // Workaround to extract view state from XML node
  7197. // This changes the state of the page and parses
  7198. // the XML for the graph model even if not needed.
  7199. if (page.root == null)
  7200. {
  7201. editorUi.updatePageRoot(page);
  7202. }
  7203. }
  7204. if (page.viewState != null)
  7205. {
  7206. pageVisible = page.viewState.pageVisible;
  7207. mathEnabled = page.viewState.mathEnabled;
  7208. bg = page.viewState.background;
  7209. bgImage = page.viewState.backgroundImage;
  7210. tempGraph.extFonts = page.viewState.extFonts;
  7211. }
  7212. // Forces update of background page image in offscreen page
  7213. if (bgImage != null && bgImage.originalSrc != null)
  7214. {
  7215. bgImage = editorUi.createImageForPageLink(
  7216. bgImage.originalSrc, page);
  7217. }
  7218. tempGraph.background = bg;
  7219. tempGraph.backgroundImage = (bgImage != null) ? new mxImage(
  7220. bgImage.src, bgImage.width, bgImage.height,
  7221. bgImage.x, bgImage.y) : null;
  7222. tempGraph.pageVisible = pageVisible;
  7223. tempGraph.mathEnabled = mathEnabled;
  7224. // Overrides graph bounds to include background images
  7225. var graphGetGraphBounds = tempGraph.getGraphBounds;
  7226. tempGraph.getGraphBounds = function()
  7227. {
  7228. var bounds = graphGetGraphBounds.apply(this, arguments);
  7229. var img = this.backgroundImage;
  7230. if (img != null && img.width != null && img.height != null)
  7231. {
  7232. var t = this.view.translate;
  7233. var s = this.view.scale;
  7234. bounds = mxRectangle.fromRectangle(bounds);
  7235. bounds.add(new mxRectangle(
  7236. (t.x + img.x) * s, (t.y + img.y) * s,
  7237. img.width * s, img.height * s));
  7238. }
  7239. return bounds;
  7240. };
  7241. // Redirects placeholders to current page
  7242. var graphGetGlobalVariable = tempGraph.getGlobalVariable;
  7243. tempGraph.getGlobalVariable = function(name)
  7244. {
  7245. if (name == 'page')
  7246. {
  7247. return page.getName();
  7248. }
  7249. else if (name == 'pagenumber')
  7250. {
  7251. return i + 1;
  7252. }
  7253. else if (name == 'pagecount')
  7254. {
  7255. return (editorUi.pages != null) ? editorUi.pages.length : 1;
  7256. }
  7257. return graphGetGlobalVariable.apply(this, arguments);
  7258. };
  7259. document.body.appendChild(tempGraph.container);
  7260. editorUi.updatePageRoot(page);
  7261. tempGraph.model.setRoot(page.root);
  7262. }
  7263. pv = printGraph(tempGraph, pv, i != imax);
  7264. if (tempGraph != graph)
  7265. {
  7266. tempGraph.container.parentNode.removeChild(tempGraph.container);
  7267. }
  7268. }
  7269. }
  7270. else
  7271. {
  7272. pv = printGraph(graph);
  7273. }
  7274. if (pv == null)
  7275. {
  7276. editorUi.handleError({message: mxResources.get('errorUpdatingPreview')});
  7277. }
  7278. else
  7279. {
  7280. if (pv.mathEnabled)
  7281. {
  7282. var doc = pv.wnd.document;
  7283. // Adds asynchronous printing when MathJax finishes rendering
  7284. // via global variable that is checked in math-print.js to
  7285. // avoid generating unsafe-inline script or adding SHA to CSP
  7286. if (print)
  7287. {
  7288. pv.wnd.IMMEDIATE_PRINT = true;
  7289. }
  7290. doc.writeln('<script type="text/javascript" src="' + DRAWIO_BASE_URL + '/js/math-print.js"></script>');
  7291. }
  7292. pv.closeDocument();
  7293. if (!pv.mathEnabled && print)
  7294. {
  7295. PrintDialog.printPreview(pv);
  7296. }
  7297. }
  7298. // Restores dark mode
  7299. if (darkStylesheet != null)
  7300. {
  7301. graph.shapeForegroundColor = darkFg;
  7302. graph.shapeBackgroundColor = darkBg;
  7303. graph.stylesheet = darkStylesheet;
  7304. graph.refresh();
  7305. }
  7306. };
  7307. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  7308. {
  7309. editorUi.hideDialog();
  7310. });
  7311. cancelBtn.className = 'geBtn';
  7312. if (editorUi.editor.cancelFirst)
  7313. {
  7314. buttons.appendChild(cancelBtn);
  7315. }
  7316. if (!editorUi.isOffline())
  7317. {
  7318. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  7319. {
  7320. graph.openLink('https://www.diagrams.net/doc/faq/print-diagram');
  7321. });
  7322. helpBtn.className = 'geBtn';
  7323. buttons.appendChild(helpBtn);
  7324. }
  7325. if (PrintDialog.previewEnabled)
  7326. {
  7327. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  7328. {
  7329. editorUi.hideDialog();
  7330. preview(false);
  7331. });
  7332. previewBtn.className = 'geBtn';
  7333. buttons.appendChild(previewBtn);
  7334. }
  7335. var printBtn = mxUtils.button(mxResources.get((!PrintDialog.previewEnabled) ? 'ok' : 'print'), function()
  7336. {
  7337. editorUi.hideDialog();
  7338. preview(true);
  7339. });
  7340. printBtn.className = 'geBtn gePrimaryBtn';
  7341. buttons.appendChild(printBtn);
  7342. if (!editorUi.editor.cancelFirst)
  7343. {
  7344. buttons.appendChild(cancelBtn);
  7345. }
  7346. div.appendChild(buttons);
  7347. this.container = div;
  7348. };
  7349. // Execute fit page on page setup changes
  7350. var changePageSetupExecute = ChangePageSetup.prototype.execute;
  7351. ChangePageSetup.prototype.execute = function()
  7352. {
  7353. if (this.page == null)
  7354. {
  7355. this.page = this.ui.currentPage;
  7356. }
  7357. // Workaround for redo existing change with different current page
  7358. if (this.page != this.ui.currentPage)
  7359. {
  7360. if (this.page.viewState != null)
  7361. {
  7362. if (!this.ignoreColor)
  7363. {
  7364. this.page.viewState.background = this.color;
  7365. }
  7366. if (!this.ignoreImage)
  7367. {
  7368. var img = this.image;
  7369. if (img != null && img.src != null && Graph.isPageLink(img.src))
  7370. {
  7371. img = {originalSrc: img.src};
  7372. }
  7373. this.page.viewState.backgroundImage = img;
  7374. }
  7375. if (this.format != null)
  7376. {
  7377. this.page.viewState.pageFormat = this.format;
  7378. }
  7379. if (this.mathEnabled != null)
  7380. {
  7381. this.page.viewState.mathEnabled = this.mathEnabled;
  7382. }
  7383. if (this.shadowVisible != null)
  7384. {
  7385. this.page.viewState.shadowVisible = this.shadowVisible;
  7386. }
  7387. }
  7388. }
  7389. else
  7390. {
  7391. changePageSetupExecute.apply(this, arguments);
  7392. if (this.mathEnabled != null && this.mathEnabled != this.ui.isMathEnabled())
  7393. {
  7394. this.ui.setMathEnabled(this.mathEnabled);
  7395. this.mathEnabled = !this.mathEnabled;
  7396. }
  7397. if (this.shadowVisible != null && this.shadowVisible != this.ui.editor.graph.shadowVisible)
  7398. {
  7399. this.ui.editor.graph.setShadowVisible(this.shadowVisible);
  7400. this.shadowVisible = !this.shadowVisible;
  7401. }
  7402. }
  7403. };
  7404. /**
  7405. * Capability check for canvas export
  7406. */
  7407. Editor.prototype.useCanvasForExport = false;
  7408. try
  7409. {
  7410. var canvas = document.createElement('canvas');
  7411. var img = new Image();
  7412. // LATER: Capability check should not be async
  7413. img.onload = function()
  7414. {
  7415. try
  7416. {
  7417. var ctx = canvas.getContext('2d');
  7418. ctx.drawImage(img, 0, 0);
  7419. // Works in Chrome, Firefox, Edge, Safari and Opera
  7420. var result = canvas.toDataURL('image/png');
  7421. Editor.prototype.useCanvasForExport = result != null && result.length > 6;
  7422. }
  7423. catch (e)
  7424. {
  7425. // ignore
  7426. }
  7427. };
  7428. // Checks if SVG with foreignObject can be exported
  7429. 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>';
  7430. img.src = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
  7431. }
  7432. catch (e)
  7433. {
  7434. // ignore
  7435. }
  7436. Editor.prototype.useCanvasForExport = false;
  7437. })();
  7438. // Extends codec for ChangePageSetup
  7439. (function()
  7440. {
  7441. var codec = new mxObjectCodec(new ChangePageSetup(), ['ui', 'previousColor', 'previousImage', 'previousFormat']);
  7442. codec.beforeDecode = function(dec, node, obj)
  7443. {
  7444. obj.ui = dec.ui;
  7445. return node;
  7446. };
  7447. codec.afterDecode = function(dec, node, obj)
  7448. {
  7449. obj.previousColor = obj.color;
  7450. obj.previousImage = obj.image;
  7451. obj.previousFormat = obj.format;
  7452. if (obj.foldingEnabled != null)
  7453. {
  7454. obj.foldingEnabled = !obj.foldingEnabled;
  7455. }
  7456. if (obj.mathEnabled != null)
  7457. {
  7458. obj.mathEnabled = !obj.mathEnabled;
  7459. }
  7460. if (obj.shadowVisible != null)
  7461. {
  7462. obj.shadowVisible = !obj.shadowVisible;
  7463. }
  7464. return obj;
  7465. };
  7466. mxCodecRegistry.register(codec);
  7467. })();
  7468. // Extends codec for ChangeGridColor
  7469. (function()
  7470. {
  7471. var codec = new mxObjectCodec(new ChangeGridColor(), ['ui']);
  7472. codec.beforeDecode = function(dec, node, obj)
  7473. {
  7474. obj.ui = dec.ui;
  7475. return node;
  7476. };
  7477. mxCodecRegistry.register(codec);
  7478. })();