index.umd.js 720 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.G = {}));
  5. }(this, (function (exports) { 'use strict';
  6. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  7. function createCommonjsModule(fn, basedir, module) {
  8. return module = {
  9. path: basedir,
  10. exports: {},
  11. require: function (path, base) {
  12. return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
  13. }
  14. }, fn(module, module.exports), module.exports;
  15. }
  16. function commonjsRequire () {
  17. throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
  18. }
  19. var rbush = createCommonjsModule(function (module, exports) {
  20. (function (global, factory) {
  21. module.exports = factory() ;
  22. }(commonjsGlobal, function () {
  23. function quickselect(arr, k, left, right, compare) {
  24. quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);
  25. }
  26. function quickselectStep(arr, k, left, right, compare) {
  27. while (right > left) {
  28. if (right - left > 600) {
  29. var n = right - left + 1;
  30. var m = k - left + 1;
  31. var z = Math.log(n);
  32. var s = 0.5 * Math.exp(2 * z / 3);
  33. var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
  34. var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
  35. var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
  36. quickselectStep(arr, k, newLeft, newRight, compare);
  37. }
  38. var t = arr[k];
  39. var i = left;
  40. var j = right;
  41. swap(arr, left, k);
  42. if (compare(arr[right], t) > 0) { swap(arr, left, right); }
  43. while (i < j) {
  44. swap(arr, i, j);
  45. i++;
  46. j--;
  47. while (compare(arr[i], t) < 0) { i++; }
  48. while (compare(arr[j], t) > 0) { j--; }
  49. }
  50. if (compare(arr[left], t) === 0) { swap(arr, left, j); }
  51. else {
  52. j++;
  53. swap(arr, j, right);
  54. }
  55. if (j <= k) { left = j + 1; }
  56. if (k <= j) { right = j - 1; }
  57. }
  58. }
  59. function swap(arr, i, j) {
  60. var tmp = arr[i];
  61. arr[i] = arr[j];
  62. arr[j] = tmp;
  63. }
  64. function defaultCompare(a, b) {
  65. return a < b ? -1 : a > b ? 1 : 0;
  66. }
  67. var RBush = function RBush(maxEntries) {
  68. if ( maxEntries === void 0 ) maxEntries = 9;
  69. // max entries in a node is 9 by default; min node fill is 40% for best performance
  70. this._maxEntries = Math.max(4, maxEntries);
  71. this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4));
  72. this.clear();
  73. };
  74. RBush.prototype.all = function all () {
  75. return this._all(this.data, []);
  76. };
  77. RBush.prototype.search = function search (bbox) {
  78. var node = this.data;
  79. var result = [];
  80. if (!intersects(bbox, node)) { return result; }
  81. var toBBox = this.toBBox;
  82. var nodesToSearch = [];
  83. while (node) {
  84. for (var i = 0; i < node.children.length; i++) {
  85. var child = node.children[i];
  86. var childBBox = node.leaf ? toBBox(child) : child;
  87. if (intersects(bbox, childBBox)) {
  88. if (node.leaf) { result.push(child); }
  89. else if (contains(bbox, childBBox)) { this._all(child, result); }
  90. else { nodesToSearch.push(child); }
  91. }
  92. }
  93. node = nodesToSearch.pop();
  94. }
  95. return result;
  96. };
  97. RBush.prototype.collides = function collides (bbox) {
  98. var node = this.data;
  99. if (!intersects(bbox, node)) { return false; }
  100. var nodesToSearch = [];
  101. while (node) {
  102. for (var i = 0; i < node.children.length; i++) {
  103. var child = node.children[i];
  104. var childBBox = node.leaf ? this.toBBox(child) : child;
  105. if (intersects(bbox, childBBox)) {
  106. if (node.leaf || contains(bbox, childBBox)) { return true; }
  107. nodesToSearch.push(child);
  108. }
  109. }
  110. node = nodesToSearch.pop();
  111. }
  112. return false;
  113. };
  114. RBush.prototype.load = function load (data) {
  115. if (!(data && data.length)) { return this; }
  116. if (data.length < this._minEntries) {
  117. for (var i = 0; i < data.length; i++) {
  118. this.insert(data[i]);
  119. }
  120. return this;
  121. }
  122. // recursively build the tree with the given data from scratch using OMT algorithm
  123. var node = this._build(data.slice(), 0, data.length - 1, 0);
  124. if (!this.data.children.length) {
  125. // save as is if tree is empty
  126. this.data = node;
  127. } else if (this.data.height === node.height) {
  128. // split root if trees have the same height
  129. this._splitRoot(this.data, node);
  130. } else {
  131. if (this.data.height < node.height) {
  132. // swap trees if inserted one is bigger
  133. var tmpNode = this.data;
  134. this.data = node;
  135. node = tmpNode;
  136. }
  137. // insert the small tree into the large tree at appropriate level
  138. this._insert(node, this.data.height - node.height - 1, true);
  139. }
  140. return this;
  141. };
  142. RBush.prototype.insert = function insert (item) {
  143. if (item) { this._insert(item, this.data.height - 1); }
  144. return this;
  145. };
  146. RBush.prototype.clear = function clear () {
  147. this.data = createNode([]);
  148. return this;
  149. };
  150. RBush.prototype.remove = function remove (item, equalsFn) {
  151. if (!item) { return this; }
  152. var node = this.data;
  153. var bbox = this.toBBox(item);
  154. var path = [];
  155. var indexes = [];
  156. var i, parent, goingUp;
  157. // depth-first iterative tree traversal
  158. while (node || path.length) {
  159. if (!node) { // go up
  160. node = path.pop();
  161. parent = path[path.length - 1];
  162. i = indexes.pop();
  163. goingUp = true;
  164. }
  165. if (node.leaf) { // check current node
  166. var index = findItem(item, node.children, equalsFn);
  167. if (index !== -1) {
  168. // item found, remove the item and condense tree upwards
  169. node.children.splice(index, 1);
  170. path.push(node);
  171. this._condense(path);
  172. return this;
  173. }
  174. }
  175. if (!goingUp && !node.leaf && contains(node, bbox)) { // go down
  176. path.push(node);
  177. indexes.push(i);
  178. i = 0;
  179. parent = node;
  180. node = node.children[0];
  181. } else if (parent) { // go right
  182. i++;
  183. node = parent.children[i];
  184. goingUp = false;
  185. } else { node = null; } // nothing found
  186. }
  187. return this;
  188. };
  189. RBush.prototype.toBBox = function toBBox (item) { return item; };
  190. RBush.prototype.compareMinX = function compareMinX (a, b) { return a.minX - b.minX; };
  191. RBush.prototype.compareMinY = function compareMinY (a, b) { return a.minY - b.minY; };
  192. RBush.prototype.toJSON = function toJSON () { return this.data; };
  193. RBush.prototype.fromJSON = function fromJSON (data) {
  194. this.data = data;
  195. return this;
  196. };
  197. RBush.prototype._all = function _all (node, result) {
  198. var nodesToSearch = [];
  199. while (node) {
  200. if (node.leaf) { result.push.apply(result, node.children); }
  201. else { nodesToSearch.push.apply(nodesToSearch, node.children); }
  202. node = nodesToSearch.pop();
  203. }
  204. return result;
  205. };
  206. RBush.prototype._build = function _build (items, left, right, height) {
  207. var N = right - left + 1;
  208. var M = this._maxEntries;
  209. var node;
  210. if (N <= M) {
  211. // reached leaf level; return leaf
  212. node = createNode(items.slice(left, right + 1));
  213. calcBBox(node, this.toBBox);
  214. return node;
  215. }
  216. if (!height) {
  217. // target height of the bulk-loaded tree
  218. height = Math.ceil(Math.log(N) / Math.log(M));
  219. // target number of root entries to maximize storage utilization
  220. M = Math.ceil(N / Math.pow(M, height - 1));
  221. }
  222. node = createNode([]);
  223. node.leaf = false;
  224. node.height = height;
  225. // split the items into M mostly square tiles
  226. var N2 = Math.ceil(N / M);
  227. var N1 = N2 * Math.ceil(Math.sqrt(M));
  228. multiSelect(items, left, right, N1, this.compareMinX);
  229. for (var i = left; i <= right; i += N1) {
  230. var right2 = Math.min(i + N1 - 1, right);
  231. multiSelect(items, i, right2, N2, this.compareMinY);
  232. for (var j = i; j <= right2; j += N2) {
  233. var right3 = Math.min(j + N2 - 1, right2);
  234. // pack each entry recursively
  235. node.children.push(this._build(items, j, right3, height - 1));
  236. }
  237. }
  238. calcBBox(node, this.toBBox);
  239. return node;
  240. };
  241. RBush.prototype._chooseSubtree = function _chooseSubtree (bbox, node, level, path) {
  242. while (true) {
  243. path.push(node);
  244. if (node.leaf || path.length - 1 === level) { break; }
  245. var minArea = Infinity;
  246. var minEnlargement = Infinity;
  247. var targetNode = (void 0);
  248. for (var i = 0; i < node.children.length; i++) {
  249. var child = node.children[i];
  250. var area = bboxArea(child);
  251. var enlargement = enlargedArea(bbox, child) - area;
  252. // choose entry with the least area enlargement
  253. if (enlargement < minEnlargement) {
  254. minEnlargement = enlargement;
  255. minArea = area < minArea ? area : minArea;
  256. targetNode = child;
  257. } else if (enlargement === minEnlargement) {
  258. // otherwise choose one with the smallest area
  259. if (area < minArea) {
  260. minArea = area;
  261. targetNode = child;
  262. }
  263. }
  264. }
  265. node = targetNode || node.children[0];
  266. }
  267. return node;
  268. };
  269. RBush.prototype._insert = function _insert (item, level, isNode) {
  270. var bbox = isNode ? item : this.toBBox(item);
  271. var insertPath = [];
  272. // find the best node for accommodating the item, saving all nodes along the path too
  273. var node = this._chooseSubtree(bbox, this.data, level, insertPath);
  274. // put the item into the node
  275. node.children.push(item);
  276. extend(node, bbox);
  277. // split on node overflow; propagate upwards if necessary
  278. while (level >= 0) {
  279. if (insertPath[level].children.length > this._maxEntries) {
  280. this._split(insertPath, level);
  281. level--;
  282. } else { break; }
  283. }
  284. // adjust bboxes along the insertion path
  285. this._adjustParentBBoxes(bbox, insertPath, level);
  286. };
  287. // split overflowed node into two
  288. RBush.prototype._split = function _split (insertPath, level) {
  289. var node = insertPath[level];
  290. var M = node.children.length;
  291. var m = this._minEntries;
  292. this._chooseSplitAxis(node, m, M);
  293. var splitIndex = this._chooseSplitIndex(node, m, M);
  294. var newNode = createNode(node.children.splice(splitIndex, node.children.length - splitIndex));
  295. newNode.height = node.height;
  296. newNode.leaf = node.leaf;
  297. calcBBox(node, this.toBBox);
  298. calcBBox(newNode, this.toBBox);
  299. if (level) { insertPath[level - 1].children.push(newNode); }
  300. else { this._splitRoot(node, newNode); }
  301. };
  302. RBush.prototype._splitRoot = function _splitRoot (node, newNode) {
  303. // split root node
  304. this.data = createNode([node, newNode]);
  305. this.data.height = node.height + 1;
  306. this.data.leaf = false;
  307. calcBBox(this.data, this.toBBox);
  308. };
  309. RBush.prototype._chooseSplitIndex = function _chooseSplitIndex (node, m, M) {
  310. var index;
  311. var minOverlap = Infinity;
  312. var minArea = Infinity;
  313. for (var i = m; i <= M - m; i++) {
  314. var bbox1 = distBBox(node, 0, i, this.toBBox);
  315. var bbox2 = distBBox(node, i, M, this.toBBox);
  316. var overlap = intersectionArea(bbox1, bbox2);
  317. var area = bboxArea(bbox1) + bboxArea(bbox2);
  318. // choose distribution with minimum overlap
  319. if (overlap < minOverlap) {
  320. minOverlap = overlap;
  321. index = i;
  322. minArea = area < minArea ? area : minArea;
  323. } else if (overlap === minOverlap) {
  324. // otherwise choose distribution with minimum area
  325. if (area < minArea) {
  326. minArea = area;
  327. index = i;
  328. }
  329. }
  330. }
  331. return index || M - m;
  332. };
  333. // sorts node children by the best axis for split
  334. RBush.prototype._chooseSplitAxis = function _chooseSplitAxis (node, m, M) {
  335. var compareMinX = node.leaf ? this.compareMinX : compareNodeMinX;
  336. var compareMinY = node.leaf ? this.compareMinY : compareNodeMinY;
  337. var xMargin = this._allDistMargin(node, m, M, compareMinX);
  338. var yMargin = this._allDistMargin(node, m, M, compareMinY);
  339. // if total distributions margin value is minimal for x, sort by minX,
  340. // otherwise it's already sorted by minY
  341. if (xMargin < yMargin) { node.children.sort(compareMinX); }
  342. };
  343. // total margin of all possible split distributions where each node is at least m full
  344. RBush.prototype._allDistMargin = function _allDistMargin (node, m, M, compare) {
  345. node.children.sort(compare);
  346. var toBBox = this.toBBox;
  347. var leftBBox = distBBox(node, 0, m, toBBox);
  348. var rightBBox = distBBox(node, M - m, M, toBBox);
  349. var margin = bboxMargin(leftBBox) + bboxMargin(rightBBox);
  350. for (var i = m; i < M - m; i++) {
  351. var child = node.children[i];
  352. extend(leftBBox, node.leaf ? toBBox(child) : child);
  353. margin += bboxMargin(leftBBox);
  354. }
  355. for (var i$1 = M - m - 1; i$1 >= m; i$1--) {
  356. var child$1 = node.children[i$1];
  357. extend(rightBBox, node.leaf ? toBBox(child$1) : child$1);
  358. margin += bboxMargin(rightBBox);
  359. }
  360. return margin;
  361. };
  362. RBush.prototype._adjustParentBBoxes = function _adjustParentBBoxes (bbox, path, level) {
  363. // adjust bboxes along the given tree path
  364. for (var i = level; i >= 0; i--) {
  365. extend(path[i], bbox);
  366. }
  367. };
  368. RBush.prototype._condense = function _condense (path) {
  369. // go through the path, removing empty nodes and updating bboxes
  370. for (var i = path.length - 1, siblings = (void 0); i >= 0; i--) {
  371. if (path[i].children.length === 0) {
  372. if (i > 0) {
  373. siblings = path[i - 1].children;
  374. siblings.splice(siblings.indexOf(path[i]), 1);
  375. } else { this.clear(); }
  376. } else { calcBBox(path[i], this.toBBox); }
  377. }
  378. };
  379. function findItem(item, items, equalsFn) {
  380. if (!equalsFn) { return items.indexOf(item); }
  381. for (var i = 0; i < items.length; i++) {
  382. if (equalsFn(item, items[i])) { return i; }
  383. }
  384. return -1;
  385. }
  386. // calculate node's bbox from bboxes of its children
  387. function calcBBox(node, toBBox) {
  388. distBBox(node, 0, node.children.length, toBBox, node);
  389. }
  390. // min bounding rectangle of node children from k to p-1
  391. function distBBox(node, k, p, toBBox, destNode) {
  392. if (!destNode) { destNode = createNode(null); }
  393. destNode.minX = Infinity;
  394. destNode.minY = Infinity;
  395. destNode.maxX = -Infinity;
  396. destNode.maxY = -Infinity;
  397. for (var i = k; i < p; i++) {
  398. var child = node.children[i];
  399. extend(destNode, node.leaf ? toBBox(child) : child);
  400. }
  401. return destNode;
  402. }
  403. function extend(a, b) {
  404. a.minX = Math.min(a.minX, b.minX);
  405. a.minY = Math.min(a.minY, b.minY);
  406. a.maxX = Math.max(a.maxX, b.maxX);
  407. a.maxY = Math.max(a.maxY, b.maxY);
  408. return a;
  409. }
  410. function compareNodeMinX(a, b) { return a.minX - b.minX; }
  411. function compareNodeMinY(a, b) { return a.minY - b.minY; }
  412. function bboxArea(a) { return (a.maxX - a.minX) * (a.maxY - a.minY); }
  413. function bboxMargin(a) { return (a.maxX - a.minX) + (a.maxY - a.minY); }
  414. function enlargedArea(a, b) {
  415. return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) *
  416. (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY));
  417. }
  418. function intersectionArea(a, b) {
  419. var minX = Math.max(a.minX, b.minX);
  420. var minY = Math.max(a.minY, b.minY);
  421. var maxX = Math.min(a.maxX, b.maxX);
  422. var maxY = Math.min(a.maxY, b.maxY);
  423. return Math.max(0, maxX - minX) *
  424. Math.max(0, maxY - minY);
  425. }
  426. function contains(a, b) {
  427. return a.minX <= b.minX &&
  428. a.minY <= b.minY &&
  429. b.maxX <= a.maxX &&
  430. b.maxY <= a.maxY;
  431. }
  432. function intersects(a, b) {
  433. return b.minX <= a.maxX &&
  434. b.minY <= a.maxY &&
  435. b.maxX >= a.minX &&
  436. b.maxY >= a.minY;
  437. }
  438. function createNode(children) {
  439. return {
  440. children: children,
  441. height: 1,
  442. leaf: true,
  443. minX: Infinity,
  444. minY: Infinity,
  445. maxX: -Infinity,
  446. maxY: -Infinity
  447. };
  448. }
  449. // sort an array so that items come in groups of n unsorted items, with groups sorted between each other;
  450. // combines selection algorithm with binary divide & conquer approach
  451. function multiSelect(arr, left, right, n, compare) {
  452. var stack = [left, right];
  453. while (stack.length) {
  454. right = stack.pop();
  455. left = stack.pop();
  456. if (right - left <= n) { continue; }
  457. var mid = left + Math.ceil((right - left) / n / 2) * n;
  458. quickselect(arr, mid, left, right, compare);
  459. stack.push(left, mid, mid, right);
  460. }
  461. }
  462. return RBush;
  463. }));
  464. });
  465. /**
  466. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type
  467. */
  468. (function (PropertySyntax) {
  469. /**
  470. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#coordinate
  471. */
  472. PropertySyntax["COORDINATE"] = "<coordinate>";
  473. /**
  474. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#color
  475. */
  476. PropertySyntax["COLOR"] = "<color>";
  477. /**
  478. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#paint
  479. */
  480. PropertySyntax["PAINT"] = "<paint>";
  481. /**
  482. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number
  483. */
  484. PropertySyntax["NUMBER"] = "<number>";
  485. /**
  486. * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/angle
  487. */
  488. PropertySyntax["ANGLE"] = "<angle>";
  489. /**
  490. * <number> with range 0..1
  491. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#opacity_value
  492. */
  493. PropertySyntax["OPACITY_VALUE"] = "<opacity-value>";
  494. /**
  495. * <number> with range 0..Infinity
  496. */
  497. PropertySyntax["SHADOW_BLUR"] = "<shadow-blur>";
  498. /**
  499. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#length
  500. */
  501. PropertySyntax["LENGTH"] = "<length>";
  502. /**
  503. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage
  504. */
  505. PropertySyntax["PERCENTAGE"] = "<percentage>";
  506. PropertySyntax["LENGTH_PERCENTAGE"] = "<length> | <percentage>";
  507. PropertySyntax["LENGTH_PERCENTAGE_12"] = "[<length> | <percentage>]{1,2}";
  508. /**
  509. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/margin#formal_syntax
  510. */
  511. PropertySyntax["LENGTH_PERCENTAGE_14"] = "[<length> | <percentage>]{1,4}";
  512. /**
  513. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#list-of-ts
  514. */
  515. PropertySyntax["LIST_OF_POINTS"] = "<list-of-points>";
  516. PropertySyntax["PATH"] = "<path>";
  517. /**
  518. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter#formal_syntax
  519. */
  520. PropertySyntax["FILTER"] = "<filter>";
  521. PropertySyntax["Z_INDEX"] = "<z-index>";
  522. PropertySyntax["OFFSET_DISTANCE"] = "<offset-distance>";
  523. PropertySyntax["DEFINED_PATH"] = "<defined-path>";
  524. PropertySyntax["MARKER"] = "<marker>";
  525. PropertySyntax["TRANSFORM"] = "<transform>";
  526. PropertySyntax["TRANSFORM_ORIGIN"] = "<transform-origin>";
  527. PropertySyntax["TEXT"] = "<text>";
  528. PropertySyntax["TEXT_TRANSFORM"] = "<text-transform>";
  529. })(exports.PropertySyntax || (exports.PropertySyntax = {}));
  530. function _regeneratorRuntime() {
  531. _regeneratorRuntime = function () {
  532. return exports;
  533. };
  534. var exports = {},
  535. Op = Object.prototype,
  536. hasOwn = Op.hasOwnProperty,
  537. defineProperty = Object.defineProperty || function (obj, key, desc) {
  538. obj[key] = desc.value;
  539. },
  540. $Symbol = "function" == typeof Symbol ? Symbol : {},
  541. iteratorSymbol = $Symbol.iterator || "@@iterator",
  542. asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
  543. toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  544. function define(obj, key, value) {
  545. return Object.defineProperty(obj, key, {
  546. value: value,
  547. enumerable: !0,
  548. configurable: !0,
  549. writable: !0
  550. }), obj[key];
  551. }
  552. try {
  553. define({}, "");
  554. } catch (err) {
  555. define = function (obj, key, value) {
  556. return obj[key] = value;
  557. };
  558. }
  559. function wrap(innerFn, outerFn, self, tryLocsList) {
  560. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
  561. generator = Object.create(protoGenerator.prototype),
  562. context = new Context(tryLocsList || []);
  563. return defineProperty(generator, "_invoke", {
  564. value: makeInvokeMethod(innerFn, self, context)
  565. }), generator;
  566. }
  567. function tryCatch(fn, obj, arg) {
  568. try {
  569. return {
  570. type: "normal",
  571. arg: fn.call(obj, arg)
  572. };
  573. } catch (err) {
  574. return {
  575. type: "throw",
  576. arg: err
  577. };
  578. }
  579. }
  580. exports.wrap = wrap;
  581. var ContinueSentinel = {};
  582. function Generator() {}
  583. function GeneratorFunction() {}
  584. function GeneratorFunctionPrototype() {}
  585. var IteratorPrototype = {};
  586. define(IteratorPrototype, iteratorSymbol, function () {
  587. return this;
  588. });
  589. var getProto = Object.getPrototypeOf,
  590. NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  591. NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
  592. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  593. function defineIteratorMethods(prototype) {
  594. ["next", "throw", "return"].forEach(function (method) {
  595. define(prototype, method, function (arg) {
  596. return this._invoke(method, arg);
  597. });
  598. });
  599. }
  600. function AsyncIterator(generator, PromiseImpl) {
  601. function invoke(method, arg, resolve, reject) {
  602. var record = tryCatch(generator[method], generator, arg);
  603. if ("throw" !== record.type) {
  604. var result = record.arg,
  605. value = result.value;
  606. return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
  607. invoke("next", value, resolve, reject);
  608. }, function (err) {
  609. invoke("throw", err, resolve, reject);
  610. }) : PromiseImpl.resolve(value).then(function (unwrapped) {
  611. result.value = unwrapped, resolve(result);
  612. }, function (error) {
  613. return invoke("throw", error, resolve, reject);
  614. });
  615. }
  616. reject(record.arg);
  617. }
  618. var previousPromise;
  619. defineProperty(this, "_invoke", {
  620. value: function (method, arg) {
  621. function callInvokeWithMethodAndArg() {
  622. return new PromiseImpl(function (resolve, reject) {
  623. invoke(method, arg, resolve, reject);
  624. });
  625. }
  626. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  627. }
  628. });
  629. }
  630. function makeInvokeMethod(innerFn, self, context) {
  631. var state = "suspendedStart";
  632. return function (method, arg) {
  633. if ("executing" === state) throw new Error("Generator is already running");
  634. if ("completed" === state) {
  635. if ("throw" === method) throw arg;
  636. return doneResult();
  637. }
  638. for (context.method = method, context.arg = arg;;) {
  639. var delegate = context.delegate;
  640. if (delegate) {
  641. var delegateResult = maybeInvokeDelegate(delegate, context);
  642. if (delegateResult) {
  643. if (delegateResult === ContinueSentinel) continue;
  644. return delegateResult;
  645. }
  646. }
  647. if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
  648. if ("suspendedStart" === state) throw state = "completed", context.arg;
  649. context.dispatchException(context.arg);
  650. } else "return" === context.method && context.abrupt("return", context.arg);
  651. state = "executing";
  652. var record = tryCatch(innerFn, self, context);
  653. if ("normal" === record.type) {
  654. if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
  655. return {
  656. value: record.arg,
  657. done: context.done
  658. };
  659. }
  660. "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
  661. }
  662. };
  663. }
  664. function maybeInvokeDelegate(delegate, context) {
  665. var methodName = context.method,
  666. method = delegate.iterator[methodName];
  667. if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
  668. var record = tryCatch(method, delegate.iterator, context.arg);
  669. if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
  670. var info = record.arg;
  671. return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
  672. }
  673. function pushTryEntry(locs) {
  674. var entry = {
  675. tryLoc: locs[0]
  676. };
  677. 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
  678. }
  679. function resetTryEntry(entry) {
  680. var record = entry.completion || {};
  681. record.type = "normal", delete record.arg, entry.completion = record;
  682. }
  683. function Context(tryLocsList) {
  684. this.tryEntries = [{
  685. tryLoc: "root"
  686. }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
  687. }
  688. function values(iterable) {
  689. if (iterable) {
  690. var iteratorMethod = iterable[iteratorSymbol];
  691. if (iteratorMethod) return iteratorMethod.call(iterable);
  692. if ("function" == typeof iterable.next) return iterable;
  693. if (!isNaN(iterable.length)) {
  694. var i = -1,
  695. next = function next() {
  696. for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
  697. return next.value = undefined, next.done = !0, next;
  698. };
  699. return next.next = next;
  700. }
  701. }
  702. return {
  703. next: doneResult
  704. };
  705. }
  706. function doneResult() {
  707. return {
  708. value: undefined,
  709. done: !0
  710. };
  711. }
  712. return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
  713. value: GeneratorFunctionPrototype,
  714. configurable: !0
  715. }), defineProperty(GeneratorFunctionPrototype, "constructor", {
  716. value: GeneratorFunction,
  717. configurable: !0
  718. }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
  719. var ctor = "function" == typeof genFun && genFun.constructor;
  720. return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
  721. }, exports.mark = function (genFun) {
  722. return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
  723. }, exports.awrap = function (arg) {
  724. return {
  725. __await: arg
  726. };
  727. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  728. return this;
  729. }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  730. void 0 === PromiseImpl && (PromiseImpl = Promise);
  731. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  732. return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  733. return result.done ? result.value : iter.next();
  734. });
  735. }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
  736. return this;
  737. }), define(Gp, "toString", function () {
  738. return "[object Generator]";
  739. }), exports.keys = function (val) {
  740. var object = Object(val),
  741. keys = [];
  742. for (var key in object) keys.push(key);
  743. return keys.reverse(), function next() {
  744. for (; keys.length;) {
  745. var key = keys.pop();
  746. if (key in object) return next.value = key, next.done = !1, next;
  747. }
  748. return next.done = !0, next;
  749. };
  750. }, exports.values = values, Context.prototype = {
  751. constructor: Context,
  752. reset: function (skipTempReset) {
  753. if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
  754. },
  755. stop: function () {
  756. this.done = !0;
  757. var rootRecord = this.tryEntries[0].completion;
  758. if ("throw" === rootRecord.type) throw rootRecord.arg;
  759. return this.rval;
  760. },
  761. dispatchException: function (exception) {
  762. if (this.done) throw exception;
  763. var context = this;
  764. function handle(loc, caught) {
  765. return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
  766. }
  767. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  768. var entry = this.tryEntries[i],
  769. record = entry.completion;
  770. if ("root" === entry.tryLoc) return handle("end");
  771. if (entry.tryLoc <= this.prev) {
  772. var hasCatch = hasOwn.call(entry, "catchLoc"),
  773. hasFinally = hasOwn.call(entry, "finallyLoc");
  774. if (hasCatch && hasFinally) {
  775. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  776. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  777. } else if (hasCatch) {
  778. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  779. } else {
  780. if (!hasFinally) throw new Error("try statement without catch or finally");
  781. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  782. }
  783. }
  784. }
  785. },
  786. abrupt: function (type, arg) {
  787. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  788. var entry = this.tryEntries[i];
  789. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  790. var finallyEntry = entry;
  791. break;
  792. }
  793. }
  794. finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
  795. var record = finallyEntry ? finallyEntry.completion : {};
  796. return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
  797. },
  798. complete: function (record, afterLoc) {
  799. if ("throw" === record.type) throw record.arg;
  800. return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
  801. },
  802. finish: function (finallyLoc) {
  803. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  804. var entry = this.tryEntries[i];
  805. if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
  806. }
  807. },
  808. catch: function (tryLoc) {
  809. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  810. var entry = this.tryEntries[i];
  811. if (entry.tryLoc === tryLoc) {
  812. var record = entry.completion;
  813. if ("throw" === record.type) {
  814. var thrown = record.arg;
  815. resetTryEntry(entry);
  816. }
  817. return thrown;
  818. }
  819. }
  820. throw new Error("illegal catch attempt");
  821. },
  822. delegateYield: function (iterable, resultName, nextLoc) {
  823. return this.delegate = {
  824. iterator: values(iterable),
  825. resultName: resultName,
  826. nextLoc: nextLoc
  827. }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
  828. }
  829. }, exports;
  830. }
  831. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  832. try {
  833. var info = gen[key](arg);
  834. var value = info.value;
  835. } catch (error) {
  836. reject(error);
  837. return;
  838. }
  839. if (info.done) {
  840. resolve(value);
  841. } else {
  842. Promise.resolve(value).then(_next, _throw);
  843. }
  844. }
  845. function _asyncToGenerator(fn) {
  846. return function () {
  847. var self = this,
  848. args = arguments;
  849. return new Promise(function (resolve, reject) {
  850. var gen = fn.apply(self, args);
  851. function _next(value) {
  852. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  853. }
  854. function _throw(err) {
  855. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  856. }
  857. _next(undefined);
  858. });
  859. };
  860. }
  861. function _defineProperties(target, props) {
  862. for (var i = 0; i < props.length; i++) {
  863. var descriptor = props[i];
  864. descriptor.enumerable = descriptor.enumerable || false;
  865. descriptor.configurable = true;
  866. if ("value" in descriptor) descriptor.writable = true;
  867. Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
  868. }
  869. }
  870. function _createClass(Constructor, protoProps, staticProps) {
  871. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  872. if (staticProps) _defineProperties(Constructor, staticProps);
  873. Object.defineProperty(Constructor, "prototype", {
  874. writable: false
  875. });
  876. return Constructor;
  877. }
  878. function _extends() {
  879. _extends = Object.assign ? Object.assign.bind() : function (target) {
  880. for (var i = 1; i < arguments.length; i++) {
  881. var source = arguments[i];
  882. for (var key in source) {
  883. if (Object.prototype.hasOwnProperty.call(source, key)) {
  884. target[key] = source[key];
  885. }
  886. }
  887. }
  888. return target;
  889. };
  890. return _extends.apply(this, arguments);
  891. }
  892. function _inheritsLoose(subClass, superClass) {
  893. subClass.prototype = Object.create(superClass.prototype);
  894. subClass.prototype.constructor = subClass;
  895. _setPrototypeOf(subClass, superClass);
  896. }
  897. function _setPrototypeOf(o, p) {
  898. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  899. o.__proto__ = p;
  900. return o;
  901. };
  902. return _setPrototypeOf(o, p);
  903. }
  904. function _objectWithoutPropertiesLoose(source, excluded) {
  905. if (source == null) return {};
  906. var target = {};
  907. var sourceKeys = Object.keys(source);
  908. var key, i;
  909. for (i = 0; i < sourceKeys.length; i++) {
  910. key = sourceKeys[i];
  911. if (excluded.indexOf(key) >= 0) continue;
  912. target[key] = source[key];
  913. }
  914. return target;
  915. }
  916. function _assertThisInitialized(self) {
  917. if (self === void 0) {
  918. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  919. }
  920. return self;
  921. }
  922. function _unsupportedIterableToArray(o, minLen) {
  923. if (!o) return;
  924. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  925. var n = Object.prototype.toString.call(o).slice(8, -1);
  926. if (n === "Object" && o.constructor) n = o.constructor.name;
  927. if (n === "Map" || n === "Set") return Array.from(o);
  928. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  929. }
  930. function _arrayLikeToArray(arr, len) {
  931. if (len == null || len > arr.length) len = arr.length;
  932. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  933. return arr2;
  934. }
  935. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  936. var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
  937. if (it) return (it = it.call(o)).next.bind(it);
  938. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  939. if (it) o = it;
  940. var i = 0;
  941. return function () {
  942. if (i >= o.length) return {
  943. done: true
  944. };
  945. return {
  946. done: false,
  947. value: o[i++]
  948. };
  949. };
  950. }
  951. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  952. }
  953. function _toPrimitive(input, hint) {
  954. if (typeof input !== "object" || input === null) return input;
  955. var prim = input[Symbol.toPrimitive];
  956. if (prim !== undefined) {
  957. var res = prim.call(input, hint || "default");
  958. if (typeof res !== "object") return res;
  959. throw new TypeError("@@toPrimitive must return a primitive value.");
  960. }
  961. return (hint === "string" ? String : Number)(input);
  962. }
  963. function _toPropertyKey(arg) {
  964. var key = _toPrimitive(arg, "string");
  965. return typeof key === "symbol" ? key : String(key);
  966. }
  967. /**
  968. * Common utilities
  969. * @module glMatrix
  970. */
  971. // Configuration Constants
  972. var EPSILON = 0.000001;
  973. var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  974. if (!Math.hypot) Math.hypot = function () {
  975. var y = 0,
  976. i = arguments.length;
  977. while (i--) {
  978. y += arguments[i] * arguments[i];
  979. }
  980. return Math.sqrt(y);
  981. };
  982. /**
  983. * 3x3 Matrix
  984. * @module mat3
  985. */
  986. /**
  987. * Creates a new identity mat3
  988. *
  989. * @returns {mat3} a new 3x3 matrix
  990. */
  991. function create() {
  992. var out = new ARRAY_TYPE(9);
  993. if (ARRAY_TYPE != Float32Array) {
  994. out[1] = 0;
  995. out[2] = 0;
  996. out[3] = 0;
  997. out[5] = 0;
  998. out[6] = 0;
  999. out[7] = 0;
  1000. }
  1001. out[0] = 1;
  1002. out[4] = 1;
  1003. out[8] = 1;
  1004. return out;
  1005. }
  1006. /**
  1007. * Copies the upper-left 3x3 values into the given mat3.
  1008. *
  1009. * @param {mat3} out the receiving 3x3 matrix
  1010. * @param {ReadonlyMat4} a the source 4x4 matrix
  1011. * @returns {mat3} out
  1012. */
  1013. function fromMat4(out, a) {
  1014. out[0] = a[0];
  1015. out[1] = a[1];
  1016. out[2] = a[2];
  1017. out[3] = a[4];
  1018. out[4] = a[5];
  1019. out[5] = a[6];
  1020. out[6] = a[8];
  1021. out[7] = a[9];
  1022. out[8] = a[10];
  1023. return out;
  1024. }
  1025. /**
  1026. * Create a new mat3 with the given values
  1027. *
  1028. * @param {Number} m00 Component in column 0, row 0 position (index 0)
  1029. * @param {Number} m01 Component in column 0, row 1 position (index 1)
  1030. * @param {Number} m02 Component in column 0, row 2 position (index 2)
  1031. * @param {Number} m10 Component in column 1, row 0 position (index 3)
  1032. * @param {Number} m11 Component in column 1, row 1 position (index 4)
  1033. * @param {Number} m12 Component in column 1, row 2 position (index 5)
  1034. * @param {Number} m20 Component in column 2, row 0 position (index 6)
  1035. * @param {Number} m21 Component in column 2, row 1 position (index 7)
  1036. * @param {Number} m22 Component in column 2, row 2 position (index 8)
  1037. * @returns {mat3} A new mat3
  1038. */
  1039. function fromValues(m00, m01, m02, m10, m11, m12, m20, m21, m22) {
  1040. var out = new ARRAY_TYPE(9);
  1041. out[0] = m00;
  1042. out[1] = m01;
  1043. out[2] = m02;
  1044. out[3] = m10;
  1045. out[4] = m11;
  1046. out[5] = m12;
  1047. out[6] = m20;
  1048. out[7] = m21;
  1049. out[8] = m22;
  1050. return out;
  1051. }
  1052. /**
  1053. * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
  1054. * @module mat4
  1055. */
  1056. /**
  1057. * Creates a new identity mat4
  1058. *
  1059. * @returns {mat4} a new 4x4 matrix
  1060. */
  1061. function create$1() {
  1062. var out = new ARRAY_TYPE(16);
  1063. if (ARRAY_TYPE != Float32Array) {
  1064. out[1] = 0;
  1065. out[2] = 0;
  1066. out[3] = 0;
  1067. out[4] = 0;
  1068. out[6] = 0;
  1069. out[7] = 0;
  1070. out[8] = 0;
  1071. out[9] = 0;
  1072. out[11] = 0;
  1073. out[12] = 0;
  1074. out[13] = 0;
  1075. out[14] = 0;
  1076. }
  1077. out[0] = 1;
  1078. out[5] = 1;
  1079. out[10] = 1;
  1080. out[15] = 1;
  1081. return out;
  1082. }
  1083. /**
  1084. * Creates a new mat4 initialized with values from an existing matrix
  1085. *
  1086. * @param {ReadonlyMat4} a matrix to clone
  1087. * @returns {mat4} a new 4x4 matrix
  1088. */
  1089. function clone(a) {
  1090. var out = new ARRAY_TYPE(16);
  1091. out[0] = a[0];
  1092. out[1] = a[1];
  1093. out[2] = a[2];
  1094. out[3] = a[3];
  1095. out[4] = a[4];
  1096. out[5] = a[5];
  1097. out[6] = a[6];
  1098. out[7] = a[7];
  1099. out[8] = a[8];
  1100. out[9] = a[9];
  1101. out[10] = a[10];
  1102. out[11] = a[11];
  1103. out[12] = a[12];
  1104. out[13] = a[13];
  1105. out[14] = a[14];
  1106. out[15] = a[15];
  1107. return out;
  1108. }
  1109. /**
  1110. * Copy the values from one mat4 to another
  1111. *
  1112. * @param {mat4} out the receiving matrix
  1113. * @param {ReadonlyMat4} a the source matrix
  1114. * @returns {mat4} out
  1115. */
  1116. function copy(out, a) {
  1117. out[0] = a[0];
  1118. out[1] = a[1];
  1119. out[2] = a[2];
  1120. out[3] = a[3];
  1121. out[4] = a[4];
  1122. out[5] = a[5];
  1123. out[6] = a[6];
  1124. out[7] = a[7];
  1125. out[8] = a[8];
  1126. out[9] = a[9];
  1127. out[10] = a[10];
  1128. out[11] = a[11];
  1129. out[12] = a[12];
  1130. out[13] = a[13];
  1131. out[14] = a[14];
  1132. out[15] = a[15];
  1133. return out;
  1134. }
  1135. /**
  1136. * Create a new mat4 with the given values
  1137. *
  1138. * @param {Number} m00 Component in column 0, row 0 position (index 0)
  1139. * @param {Number} m01 Component in column 0, row 1 position (index 1)
  1140. * @param {Number} m02 Component in column 0, row 2 position (index 2)
  1141. * @param {Number} m03 Component in column 0, row 3 position (index 3)
  1142. * @param {Number} m10 Component in column 1, row 0 position (index 4)
  1143. * @param {Number} m11 Component in column 1, row 1 position (index 5)
  1144. * @param {Number} m12 Component in column 1, row 2 position (index 6)
  1145. * @param {Number} m13 Component in column 1, row 3 position (index 7)
  1146. * @param {Number} m20 Component in column 2, row 0 position (index 8)
  1147. * @param {Number} m21 Component in column 2, row 1 position (index 9)
  1148. * @param {Number} m22 Component in column 2, row 2 position (index 10)
  1149. * @param {Number} m23 Component in column 2, row 3 position (index 11)
  1150. * @param {Number} m30 Component in column 3, row 0 position (index 12)
  1151. * @param {Number} m31 Component in column 3, row 1 position (index 13)
  1152. * @param {Number} m32 Component in column 3, row 2 position (index 14)
  1153. * @param {Number} m33 Component in column 3, row 3 position (index 15)
  1154. * @returns {mat4} A new mat4
  1155. */
  1156. function fromValues$1(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
  1157. var out = new ARRAY_TYPE(16);
  1158. out[0] = m00;
  1159. out[1] = m01;
  1160. out[2] = m02;
  1161. out[3] = m03;
  1162. out[4] = m10;
  1163. out[5] = m11;
  1164. out[6] = m12;
  1165. out[7] = m13;
  1166. out[8] = m20;
  1167. out[9] = m21;
  1168. out[10] = m22;
  1169. out[11] = m23;
  1170. out[12] = m30;
  1171. out[13] = m31;
  1172. out[14] = m32;
  1173. out[15] = m33;
  1174. return out;
  1175. }
  1176. /**
  1177. * Set the components of a mat4 to the given values
  1178. *
  1179. * @param {mat4} out the receiving matrix
  1180. * @param {Number} m00 Component in column 0, row 0 position (index 0)
  1181. * @param {Number} m01 Component in column 0, row 1 position (index 1)
  1182. * @param {Number} m02 Component in column 0, row 2 position (index 2)
  1183. * @param {Number} m03 Component in column 0, row 3 position (index 3)
  1184. * @param {Number} m10 Component in column 1, row 0 position (index 4)
  1185. * @param {Number} m11 Component in column 1, row 1 position (index 5)
  1186. * @param {Number} m12 Component in column 1, row 2 position (index 6)
  1187. * @param {Number} m13 Component in column 1, row 3 position (index 7)
  1188. * @param {Number} m20 Component in column 2, row 0 position (index 8)
  1189. * @param {Number} m21 Component in column 2, row 1 position (index 9)
  1190. * @param {Number} m22 Component in column 2, row 2 position (index 10)
  1191. * @param {Number} m23 Component in column 2, row 3 position (index 11)
  1192. * @param {Number} m30 Component in column 3, row 0 position (index 12)
  1193. * @param {Number} m31 Component in column 3, row 1 position (index 13)
  1194. * @param {Number} m32 Component in column 3, row 2 position (index 14)
  1195. * @param {Number} m33 Component in column 3, row 3 position (index 15)
  1196. * @returns {mat4} out
  1197. */
  1198. function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
  1199. out[0] = m00;
  1200. out[1] = m01;
  1201. out[2] = m02;
  1202. out[3] = m03;
  1203. out[4] = m10;
  1204. out[5] = m11;
  1205. out[6] = m12;
  1206. out[7] = m13;
  1207. out[8] = m20;
  1208. out[9] = m21;
  1209. out[10] = m22;
  1210. out[11] = m23;
  1211. out[12] = m30;
  1212. out[13] = m31;
  1213. out[14] = m32;
  1214. out[15] = m33;
  1215. return out;
  1216. }
  1217. /**
  1218. * Set a mat4 to the identity matrix
  1219. *
  1220. * @param {mat4} out the receiving matrix
  1221. * @returns {mat4} out
  1222. */
  1223. function identity(out) {
  1224. out[0] = 1;
  1225. out[1] = 0;
  1226. out[2] = 0;
  1227. out[3] = 0;
  1228. out[4] = 0;
  1229. out[5] = 1;
  1230. out[6] = 0;
  1231. out[7] = 0;
  1232. out[8] = 0;
  1233. out[9] = 0;
  1234. out[10] = 1;
  1235. out[11] = 0;
  1236. out[12] = 0;
  1237. out[13] = 0;
  1238. out[14] = 0;
  1239. out[15] = 1;
  1240. return out;
  1241. }
  1242. /**
  1243. * Transpose the values of a mat4
  1244. *
  1245. * @param {mat4} out the receiving matrix
  1246. * @param {ReadonlyMat4} a the source matrix
  1247. * @returns {mat4} out
  1248. */
  1249. function transpose(out, a) {
  1250. // If we are transposing ourselves we can skip a few steps but have to cache some values
  1251. if (out === a) {
  1252. var a01 = a[1],
  1253. a02 = a[2],
  1254. a03 = a[3];
  1255. var a12 = a[6],
  1256. a13 = a[7];
  1257. var a23 = a[11];
  1258. out[1] = a[4];
  1259. out[2] = a[8];
  1260. out[3] = a[12];
  1261. out[4] = a01;
  1262. out[6] = a[9];
  1263. out[7] = a[13];
  1264. out[8] = a02;
  1265. out[9] = a12;
  1266. out[11] = a[14];
  1267. out[12] = a03;
  1268. out[13] = a13;
  1269. out[14] = a23;
  1270. } else {
  1271. out[0] = a[0];
  1272. out[1] = a[4];
  1273. out[2] = a[8];
  1274. out[3] = a[12];
  1275. out[4] = a[1];
  1276. out[5] = a[5];
  1277. out[6] = a[9];
  1278. out[7] = a[13];
  1279. out[8] = a[2];
  1280. out[9] = a[6];
  1281. out[10] = a[10];
  1282. out[11] = a[14];
  1283. out[12] = a[3];
  1284. out[13] = a[7];
  1285. out[14] = a[11];
  1286. out[15] = a[15];
  1287. }
  1288. return out;
  1289. }
  1290. /**
  1291. * Inverts a mat4
  1292. *
  1293. * @param {mat4} out the receiving matrix
  1294. * @param {ReadonlyMat4} a the source matrix
  1295. * @returns {mat4} out
  1296. */
  1297. function invert(out, a) {
  1298. var a00 = a[0],
  1299. a01 = a[1],
  1300. a02 = a[2],
  1301. a03 = a[3];
  1302. var a10 = a[4],
  1303. a11 = a[5],
  1304. a12 = a[6],
  1305. a13 = a[7];
  1306. var a20 = a[8],
  1307. a21 = a[9],
  1308. a22 = a[10],
  1309. a23 = a[11];
  1310. var a30 = a[12],
  1311. a31 = a[13],
  1312. a32 = a[14],
  1313. a33 = a[15];
  1314. var b00 = a00 * a11 - a01 * a10;
  1315. var b01 = a00 * a12 - a02 * a10;
  1316. var b02 = a00 * a13 - a03 * a10;
  1317. var b03 = a01 * a12 - a02 * a11;
  1318. var b04 = a01 * a13 - a03 * a11;
  1319. var b05 = a02 * a13 - a03 * a12;
  1320. var b06 = a20 * a31 - a21 * a30;
  1321. var b07 = a20 * a32 - a22 * a30;
  1322. var b08 = a20 * a33 - a23 * a30;
  1323. var b09 = a21 * a32 - a22 * a31;
  1324. var b10 = a21 * a33 - a23 * a31;
  1325. var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
  1326. var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  1327. if (!det) {
  1328. return null;
  1329. }
  1330. det = 1.0 / det;
  1331. out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
  1332. out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
  1333. out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
  1334. out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
  1335. out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
  1336. out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
  1337. out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
  1338. out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
  1339. out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
  1340. out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
  1341. out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
  1342. out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
  1343. out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
  1344. out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
  1345. out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
  1346. out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
  1347. return out;
  1348. }
  1349. /**
  1350. * Calculates the adjugate of a mat4
  1351. *
  1352. * @param {mat4} out the receiving matrix
  1353. * @param {ReadonlyMat4} a the source matrix
  1354. * @returns {mat4} out
  1355. */
  1356. function adjoint(out, a) {
  1357. var a00 = a[0],
  1358. a01 = a[1],
  1359. a02 = a[2],
  1360. a03 = a[3];
  1361. var a10 = a[4],
  1362. a11 = a[5],
  1363. a12 = a[6],
  1364. a13 = a[7];
  1365. var a20 = a[8],
  1366. a21 = a[9],
  1367. a22 = a[10],
  1368. a23 = a[11];
  1369. var a30 = a[12],
  1370. a31 = a[13],
  1371. a32 = a[14],
  1372. a33 = a[15];
  1373. out[0] = a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22);
  1374. out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));
  1375. out[2] = a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12);
  1376. out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));
  1377. out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));
  1378. out[5] = a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22);
  1379. out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));
  1380. out[7] = a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12);
  1381. out[8] = a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21);
  1382. out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));
  1383. out[10] = a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11);
  1384. out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));
  1385. out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));
  1386. out[13] = a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21);
  1387. out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));
  1388. out[15] = a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11);
  1389. return out;
  1390. }
  1391. /**
  1392. * Calculates the determinant of a mat4
  1393. *
  1394. * @param {ReadonlyMat4} a the source matrix
  1395. * @returns {Number} determinant of a
  1396. */
  1397. function determinant(a) {
  1398. var a00 = a[0],
  1399. a01 = a[1],
  1400. a02 = a[2],
  1401. a03 = a[3];
  1402. var a10 = a[4],
  1403. a11 = a[5],
  1404. a12 = a[6],
  1405. a13 = a[7];
  1406. var a20 = a[8],
  1407. a21 = a[9],
  1408. a22 = a[10],
  1409. a23 = a[11];
  1410. var a30 = a[12],
  1411. a31 = a[13],
  1412. a32 = a[14],
  1413. a33 = a[15];
  1414. var b00 = a00 * a11 - a01 * a10;
  1415. var b01 = a00 * a12 - a02 * a10;
  1416. var b02 = a00 * a13 - a03 * a10;
  1417. var b03 = a01 * a12 - a02 * a11;
  1418. var b04 = a01 * a13 - a03 * a11;
  1419. var b05 = a02 * a13 - a03 * a12;
  1420. var b06 = a20 * a31 - a21 * a30;
  1421. var b07 = a20 * a32 - a22 * a30;
  1422. var b08 = a20 * a33 - a23 * a30;
  1423. var b09 = a21 * a32 - a22 * a31;
  1424. var b10 = a21 * a33 - a23 * a31;
  1425. var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
  1426. return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  1427. }
  1428. /**
  1429. * Multiplies two mat4s
  1430. *
  1431. * @param {mat4} out the receiving matrix
  1432. * @param {ReadonlyMat4} a the first operand
  1433. * @param {ReadonlyMat4} b the second operand
  1434. * @returns {mat4} out
  1435. */
  1436. function multiply(out, a, b) {
  1437. var a00 = a[0],
  1438. a01 = a[1],
  1439. a02 = a[2],
  1440. a03 = a[3];
  1441. var a10 = a[4],
  1442. a11 = a[5],
  1443. a12 = a[6],
  1444. a13 = a[7];
  1445. var a20 = a[8],
  1446. a21 = a[9],
  1447. a22 = a[10],
  1448. a23 = a[11];
  1449. var a30 = a[12],
  1450. a31 = a[13],
  1451. a32 = a[14],
  1452. a33 = a[15]; // Cache only the current line of the second matrix
  1453. var b0 = b[0],
  1454. b1 = b[1],
  1455. b2 = b[2],
  1456. b3 = b[3];
  1457. out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  1458. out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  1459. out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  1460. out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  1461. b0 = b[4];
  1462. b1 = b[5];
  1463. b2 = b[6];
  1464. b3 = b[7];
  1465. out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  1466. out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  1467. out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  1468. out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  1469. b0 = b[8];
  1470. b1 = b[9];
  1471. b2 = b[10];
  1472. b3 = b[11];
  1473. out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  1474. out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  1475. out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  1476. out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  1477. b0 = b[12];
  1478. b1 = b[13];
  1479. b2 = b[14];
  1480. b3 = b[15];
  1481. out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  1482. out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  1483. out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  1484. out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  1485. return out;
  1486. }
  1487. /**
  1488. * Translate a mat4 by the given vector
  1489. *
  1490. * @param {mat4} out the receiving matrix
  1491. * @param {ReadonlyMat4} a the matrix to translate
  1492. * @param {ReadonlyVec3} v vector to translate by
  1493. * @returns {mat4} out
  1494. */
  1495. function translate(out, a, v) {
  1496. var x = v[0],
  1497. y = v[1],
  1498. z = v[2];
  1499. var a00, a01, a02, a03;
  1500. var a10, a11, a12, a13;
  1501. var a20, a21, a22, a23;
  1502. if (a === out) {
  1503. out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
  1504. out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
  1505. out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
  1506. out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
  1507. } else {
  1508. a00 = a[0];
  1509. a01 = a[1];
  1510. a02 = a[2];
  1511. a03 = a[3];
  1512. a10 = a[4];
  1513. a11 = a[5];
  1514. a12 = a[6];
  1515. a13 = a[7];
  1516. a20 = a[8];
  1517. a21 = a[9];
  1518. a22 = a[10];
  1519. a23 = a[11];
  1520. out[0] = a00;
  1521. out[1] = a01;
  1522. out[2] = a02;
  1523. out[3] = a03;
  1524. out[4] = a10;
  1525. out[5] = a11;
  1526. out[6] = a12;
  1527. out[7] = a13;
  1528. out[8] = a20;
  1529. out[9] = a21;
  1530. out[10] = a22;
  1531. out[11] = a23;
  1532. out[12] = a00 * x + a10 * y + a20 * z + a[12];
  1533. out[13] = a01 * x + a11 * y + a21 * z + a[13];
  1534. out[14] = a02 * x + a12 * y + a22 * z + a[14];
  1535. out[15] = a03 * x + a13 * y + a23 * z + a[15];
  1536. }
  1537. return out;
  1538. }
  1539. /**
  1540. * Scales the mat4 by the dimensions in the given vec3 not using vectorization
  1541. *
  1542. * @param {mat4} out the receiving matrix
  1543. * @param {ReadonlyMat4} a the matrix to scale
  1544. * @param {ReadonlyVec3} v the vec3 to scale the matrix by
  1545. * @returns {mat4} out
  1546. **/
  1547. function scale(out, a, v) {
  1548. var x = v[0],
  1549. y = v[1],
  1550. z = v[2];
  1551. out[0] = a[0] * x;
  1552. out[1] = a[1] * x;
  1553. out[2] = a[2] * x;
  1554. out[3] = a[3] * x;
  1555. out[4] = a[4] * y;
  1556. out[5] = a[5] * y;
  1557. out[6] = a[6] * y;
  1558. out[7] = a[7] * y;
  1559. out[8] = a[8] * z;
  1560. out[9] = a[9] * z;
  1561. out[10] = a[10] * z;
  1562. out[11] = a[11] * z;
  1563. out[12] = a[12];
  1564. out[13] = a[13];
  1565. out[14] = a[14];
  1566. out[15] = a[15];
  1567. return out;
  1568. }
  1569. /**
  1570. * Rotates a mat4 by the given angle around the given axis
  1571. *
  1572. * @param {mat4} out the receiving matrix
  1573. * @param {ReadonlyMat4} a the matrix to rotate
  1574. * @param {Number} rad the angle to rotate the matrix by
  1575. * @param {ReadonlyVec3} axis the axis to rotate around
  1576. * @returns {mat4} out
  1577. */
  1578. function rotate(out, a, rad, axis) {
  1579. var x = axis[0],
  1580. y = axis[1],
  1581. z = axis[2];
  1582. var len = Math.hypot(x, y, z);
  1583. var s, c, t;
  1584. var a00, a01, a02, a03;
  1585. var a10, a11, a12, a13;
  1586. var a20, a21, a22, a23;
  1587. var b00, b01, b02;
  1588. var b10, b11, b12;
  1589. var b20, b21, b22;
  1590. if (len < EPSILON) {
  1591. return null;
  1592. }
  1593. len = 1 / len;
  1594. x *= len;
  1595. y *= len;
  1596. z *= len;
  1597. s = Math.sin(rad);
  1598. c = Math.cos(rad);
  1599. t = 1 - c;
  1600. a00 = a[0];
  1601. a01 = a[1];
  1602. a02 = a[2];
  1603. a03 = a[3];
  1604. a10 = a[4];
  1605. a11 = a[5];
  1606. a12 = a[6];
  1607. a13 = a[7];
  1608. a20 = a[8];
  1609. a21 = a[9];
  1610. a22 = a[10];
  1611. a23 = a[11]; // Construct the elements of the rotation matrix
  1612. b00 = x * x * t + c;
  1613. b01 = y * x * t + z * s;
  1614. b02 = z * x * t - y * s;
  1615. b10 = x * y * t - z * s;
  1616. b11 = y * y * t + c;
  1617. b12 = z * y * t + x * s;
  1618. b20 = x * z * t + y * s;
  1619. b21 = y * z * t - x * s;
  1620. b22 = z * z * t + c; // Perform rotation-specific matrix multiplication
  1621. out[0] = a00 * b00 + a10 * b01 + a20 * b02;
  1622. out[1] = a01 * b00 + a11 * b01 + a21 * b02;
  1623. out[2] = a02 * b00 + a12 * b01 + a22 * b02;
  1624. out[3] = a03 * b00 + a13 * b01 + a23 * b02;
  1625. out[4] = a00 * b10 + a10 * b11 + a20 * b12;
  1626. out[5] = a01 * b10 + a11 * b11 + a21 * b12;
  1627. out[6] = a02 * b10 + a12 * b11 + a22 * b12;
  1628. out[7] = a03 * b10 + a13 * b11 + a23 * b12;
  1629. out[8] = a00 * b20 + a10 * b21 + a20 * b22;
  1630. out[9] = a01 * b20 + a11 * b21 + a21 * b22;
  1631. out[10] = a02 * b20 + a12 * b21 + a22 * b22;
  1632. out[11] = a03 * b20 + a13 * b21 + a23 * b22;
  1633. if (a !== out) {
  1634. // If the source and destination differ, copy the unchanged last row
  1635. out[12] = a[12];
  1636. out[13] = a[13];
  1637. out[14] = a[14];
  1638. out[15] = a[15];
  1639. }
  1640. return out;
  1641. }
  1642. /**
  1643. * Rotates a matrix by the given angle around the X axis
  1644. *
  1645. * @param {mat4} out the receiving matrix
  1646. * @param {ReadonlyMat4} a the matrix to rotate
  1647. * @param {Number} rad the angle to rotate the matrix by
  1648. * @returns {mat4} out
  1649. */
  1650. function rotateX(out, a, rad) {
  1651. var s = Math.sin(rad);
  1652. var c = Math.cos(rad);
  1653. var a10 = a[4];
  1654. var a11 = a[5];
  1655. var a12 = a[6];
  1656. var a13 = a[7];
  1657. var a20 = a[8];
  1658. var a21 = a[9];
  1659. var a22 = a[10];
  1660. var a23 = a[11];
  1661. if (a !== out) {
  1662. // If the source and destination differ, copy the unchanged rows
  1663. out[0] = a[0];
  1664. out[1] = a[1];
  1665. out[2] = a[2];
  1666. out[3] = a[3];
  1667. out[12] = a[12];
  1668. out[13] = a[13];
  1669. out[14] = a[14];
  1670. out[15] = a[15];
  1671. } // Perform axis-specific matrix multiplication
  1672. out[4] = a10 * c + a20 * s;
  1673. out[5] = a11 * c + a21 * s;
  1674. out[6] = a12 * c + a22 * s;
  1675. out[7] = a13 * c + a23 * s;
  1676. out[8] = a20 * c - a10 * s;
  1677. out[9] = a21 * c - a11 * s;
  1678. out[10] = a22 * c - a12 * s;
  1679. out[11] = a23 * c - a13 * s;
  1680. return out;
  1681. }
  1682. /**
  1683. * Rotates a matrix by the given angle around the Y axis
  1684. *
  1685. * @param {mat4} out the receiving matrix
  1686. * @param {ReadonlyMat4} a the matrix to rotate
  1687. * @param {Number} rad the angle to rotate the matrix by
  1688. * @returns {mat4} out
  1689. */
  1690. function rotateY(out, a, rad) {
  1691. var s = Math.sin(rad);
  1692. var c = Math.cos(rad);
  1693. var a00 = a[0];
  1694. var a01 = a[1];
  1695. var a02 = a[2];
  1696. var a03 = a[3];
  1697. var a20 = a[8];
  1698. var a21 = a[9];
  1699. var a22 = a[10];
  1700. var a23 = a[11];
  1701. if (a !== out) {
  1702. // If the source and destination differ, copy the unchanged rows
  1703. out[4] = a[4];
  1704. out[5] = a[5];
  1705. out[6] = a[6];
  1706. out[7] = a[7];
  1707. out[12] = a[12];
  1708. out[13] = a[13];
  1709. out[14] = a[14];
  1710. out[15] = a[15];
  1711. } // Perform axis-specific matrix multiplication
  1712. out[0] = a00 * c - a20 * s;
  1713. out[1] = a01 * c - a21 * s;
  1714. out[2] = a02 * c - a22 * s;
  1715. out[3] = a03 * c - a23 * s;
  1716. out[8] = a00 * s + a20 * c;
  1717. out[9] = a01 * s + a21 * c;
  1718. out[10] = a02 * s + a22 * c;
  1719. out[11] = a03 * s + a23 * c;
  1720. return out;
  1721. }
  1722. /**
  1723. * Rotates a matrix by the given angle around the Z axis
  1724. *
  1725. * @param {mat4} out the receiving matrix
  1726. * @param {ReadonlyMat4} a the matrix to rotate
  1727. * @param {Number} rad the angle to rotate the matrix by
  1728. * @returns {mat4} out
  1729. */
  1730. function rotateZ(out, a, rad) {
  1731. var s = Math.sin(rad);
  1732. var c = Math.cos(rad);
  1733. var a00 = a[0];
  1734. var a01 = a[1];
  1735. var a02 = a[2];
  1736. var a03 = a[3];
  1737. var a10 = a[4];
  1738. var a11 = a[5];
  1739. var a12 = a[6];
  1740. var a13 = a[7];
  1741. if (a !== out) {
  1742. // If the source and destination differ, copy the unchanged last row
  1743. out[8] = a[8];
  1744. out[9] = a[9];
  1745. out[10] = a[10];
  1746. out[11] = a[11];
  1747. out[12] = a[12];
  1748. out[13] = a[13];
  1749. out[14] = a[14];
  1750. out[15] = a[15];
  1751. } // Perform axis-specific matrix multiplication
  1752. out[0] = a00 * c + a10 * s;
  1753. out[1] = a01 * c + a11 * s;
  1754. out[2] = a02 * c + a12 * s;
  1755. out[3] = a03 * c + a13 * s;
  1756. out[4] = a10 * c - a00 * s;
  1757. out[5] = a11 * c - a01 * s;
  1758. out[6] = a12 * c - a02 * s;
  1759. out[7] = a13 * c - a03 * s;
  1760. return out;
  1761. }
  1762. /**
  1763. * Creates a matrix from a vector translation
  1764. * This is equivalent to (but much faster than):
  1765. *
  1766. * mat4.identity(dest);
  1767. * mat4.translate(dest, dest, vec);
  1768. *
  1769. * @param {mat4} out mat4 receiving operation result
  1770. * @param {ReadonlyVec3} v Translation vector
  1771. * @returns {mat4} out
  1772. */
  1773. function fromTranslation(out, v) {
  1774. out[0] = 1;
  1775. out[1] = 0;
  1776. out[2] = 0;
  1777. out[3] = 0;
  1778. out[4] = 0;
  1779. out[5] = 1;
  1780. out[6] = 0;
  1781. out[7] = 0;
  1782. out[8] = 0;
  1783. out[9] = 0;
  1784. out[10] = 1;
  1785. out[11] = 0;
  1786. out[12] = v[0];
  1787. out[13] = v[1];
  1788. out[14] = v[2];
  1789. out[15] = 1;
  1790. return out;
  1791. }
  1792. /**
  1793. * Creates a matrix from a vector scaling
  1794. * This is equivalent to (but much faster than):
  1795. *
  1796. * mat4.identity(dest);
  1797. * mat4.scale(dest, dest, vec);
  1798. *
  1799. * @param {mat4} out mat4 receiving operation result
  1800. * @param {ReadonlyVec3} v Scaling vector
  1801. * @returns {mat4} out
  1802. */
  1803. function fromScaling(out, v) {
  1804. out[0] = v[0];
  1805. out[1] = 0;
  1806. out[2] = 0;
  1807. out[3] = 0;
  1808. out[4] = 0;
  1809. out[5] = v[1];
  1810. out[6] = 0;
  1811. out[7] = 0;
  1812. out[8] = 0;
  1813. out[9] = 0;
  1814. out[10] = v[2];
  1815. out[11] = 0;
  1816. out[12] = 0;
  1817. out[13] = 0;
  1818. out[14] = 0;
  1819. out[15] = 1;
  1820. return out;
  1821. }
  1822. /**
  1823. * Creates a matrix from a given angle around a given axis
  1824. * This is equivalent to (but much faster than):
  1825. *
  1826. * mat4.identity(dest);
  1827. * mat4.rotate(dest, dest, rad, axis);
  1828. *
  1829. * @param {mat4} out mat4 receiving operation result
  1830. * @param {Number} rad the angle to rotate the matrix by
  1831. * @param {ReadonlyVec3} axis the axis to rotate around
  1832. * @returns {mat4} out
  1833. */
  1834. function fromRotation(out, rad, axis) {
  1835. var x = axis[0],
  1836. y = axis[1],
  1837. z = axis[2];
  1838. var len = Math.hypot(x, y, z);
  1839. var s, c, t;
  1840. if (len < EPSILON) {
  1841. return null;
  1842. }
  1843. len = 1 / len;
  1844. x *= len;
  1845. y *= len;
  1846. z *= len;
  1847. s = Math.sin(rad);
  1848. c = Math.cos(rad);
  1849. t = 1 - c; // Perform rotation-specific matrix multiplication
  1850. out[0] = x * x * t + c;
  1851. out[1] = y * x * t + z * s;
  1852. out[2] = z * x * t - y * s;
  1853. out[3] = 0;
  1854. out[4] = x * y * t - z * s;
  1855. out[5] = y * y * t + c;
  1856. out[6] = z * y * t + x * s;
  1857. out[7] = 0;
  1858. out[8] = x * z * t + y * s;
  1859. out[9] = y * z * t - x * s;
  1860. out[10] = z * z * t + c;
  1861. out[11] = 0;
  1862. out[12] = 0;
  1863. out[13] = 0;
  1864. out[14] = 0;
  1865. out[15] = 1;
  1866. return out;
  1867. }
  1868. /**
  1869. * Creates a matrix from the given angle around the X axis
  1870. * This is equivalent to (but much faster than):
  1871. *
  1872. * mat4.identity(dest);
  1873. * mat4.rotateX(dest, dest, rad);
  1874. *
  1875. * @param {mat4} out mat4 receiving operation result
  1876. * @param {Number} rad the angle to rotate the matrix by
  1877. * @returns {mat4} out
  1878. */
  1879. function fromXRotation(out, rad) {
  1880. var s = Math.sin(rad);
  1881. var c = Math.cos(rad); // Perform axis-specific matrix multiplication
  1882. out[0] = 1;
  1883. out[1] = 0;
  1884. out[2] = 0;
  1885. out[3] = 0;
  1886. out[4] = 0;
  1887. out[5] = c;
  1888. out[6] = s;
  1889. out[7] = 0;
  1890. out[8] = 0;
  1891. out[9] = -s;
  1892. out[10] = c;
  1893. out[11] = 0;
  1894. out[12] = 0;
  1895. out[13] = 0;
  1896. out[14] = 0;
  1897. out[15] = 1;
  1898. return out;
  1899. }
  1900. /**
  1901. * Creates a matrix from the given angle around the Y axis
  1902. * This is equivalent to (but much faster than):
  1903. *
  1904. * mat4.identity(dest);
  1905. * mat4.rotateY(dest, dest, rad);
  1906. *
  1907. * @param {mat4} out mat4 receiving operation result
  1908. * @param {Number} rad the angle to rotate the matrix by
  1909. * @returns {mat4} out
  1910. */
  1911. function fromYRotation(out, rad) {
  1912. var s = Math.sin(rad);
  1913. var c = Math.cos(rad); // Perform axis-specific matrix multiplication
  1914. out[0] = c;
  1915. out[1] = 0;
  1916. out[2] = -s;
  1917. out[3] = 0;
  1918. out[4] = 0;
  1919. out[5] = 1;
  1920. out[6] = 0;
  1921. out[7] = 0;
  1922. out[8] = s;
  1923. out[9] = 0;
  1924. out[10] = c;
  1925. out[11] = 0;
  1926. out[12] = 0;
  1927. out[13] = 0;
  1928. out[14] = 0;
  1929. out[15] = 1;
  1930. return out;
  1931. }
  1932. /**
  1933. * Creates a matrix from the given angle around the Z axis
  1934. * This is equivalent to (but much faster than):
  1935. *
  1936. * mat4.identity(dest);
  1937. * mat4.rotateZ(dest, dest, rad);
  1938. *
  1939. * @param {mat4} out mat4 receiving operation result
  1940. * @param {Number} rad the angle to rotate the matrix by
  1941. * @returns {mat4} out
  1942. */
  1943. function fromZRotation(out, rad) {
  1944. var s = Math.sin(rad);
  1945. var c = Math.cos(rad); // Perform axis-specific matrix multiplication
  1946. out[0] = c;
  1947. out[1] = s;
  1948. out[2] = 0;
  1949. out[3] = 0;
  1950. out[4] = -s;
  1951. out[5] = c;
  1952. out[6] = 0;
  1953. out[7] = 0;
  1954. out[8] = 0;
  1955. out[9] = 0;
  1956. out[10] = 1;
  1957. out[11] = 0;
  1958. out[12] = 0;
  1959. out[13] = 0;
  1960. out[14] = 0;
  1961. out[15] = 1;
  1962. return out;
  1963. }
  1964. /**
  1965. * Creates a matrix from a quaternion rotation and vector translation
  1966. * This is equivalent to (but much faster than):
  1967. *
  1968. * mat4.identity(dest);
  1969. * mat4.translate(dest, vec);
  1970. * let quatMat = mat4.create();
  1971. * quat4.toMat4(quat, quatMat);
  1972. * mat4.multiply(dest, quatMat);
  1973. *
  1974. * @param {mat4} out mat4 receiving operation result
  1975. * @param {quat4} q Rotation quaternion
  1976. * @param {ReadonlyVec3} v Translation vector
  1977. * @returns {mat4} out
  1978. */
  1979. function fromRotationTranslation(out, q, v) {
  1980. // Quaternion math
  1981. var x = q[0],
  1982. y = q[1],
  1983. z = q[2],
  1984. w = q[3];
  1985. var x2 = x + x;
  1986. var y2 = y + y;
  1987. var z2 = z + z;
  1988. var xx = x * x2;
  1989. var xy = x * y2;
  1990. var xz = x * z2;
  1991. var yy = y * y2;
  1992. var yz = y * z2;
  1993. var zz = z * z2;
  1994. var wx = w * x2;
  1995. var wy = w * y2;
  1996. var wz = w * z2;
  1997. out[0] = 1 - (yy + zz);
  1998. out[1] = xy + wz;
  1999. out[2] = xz - wy;
  2000. out[3] = 0;
  2001. out[4] = xy - wz;
  2002. out[5] = 1 - (xx + zz);
  2003. out[6] = yz + wx;
  2004. out[7] = 0;
  2005. out[8] = xz + wy;
  2006. out[9] = yz - wx;
  2007. out[10] = 1 - (xx + yy);
  2008. out[11] = 0;
  2009. out[12] = v[0];
  2010. out[13] = v[1];
  2011. out[14] = v[2];
  2012. out[15] = 1;
  2013. return out;
  2014. }
  2015. /**
  2016. * Creates a new mat4 from a dual quat.
  2017. *
  2018. * @param {mat4} out Matrix
  2019. * @param {ReadonlyQuat2} a Dual Quaternion
  2020. * @returns {mat4} mat4 receiving operation result
  2021. */
  2022. function fromQuat2(out, a) {
  2023. var translation = new ARRAY_TYPE(3);
  2024. var bx = -a[0],
  2025. by = -a[1],
  2026. bz = -a[2],
  2027. bw = a[3],
  2028. ax = a[4],
  2029. ay = a[5],
  2030. az = a[6],
  2031. aw = a[7];
  2032. var magnitude = bx * bx + by * by + bz * bz + bw * bw; //Only scale if it makes sense
  2033. if (magnitude > 0) {
  2034. translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2 / magnitude;
  2035. translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2 / magnitude;
  2036. translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2 / magnitude;
  2037. } else {
  2038. translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
  2039. translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
  2040. translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
  2041. }
  2042. fromRotationTranslation(out, a, translation);
  2043. return out;
  2044. }
  2045. /**
  2046. * Returns the translation vector component of a transformation
  2047. * matrix. If a matrix is built with fromRotationTranslation,
  2048. * the returned vector will be the same as the translation vector
  2049. * originally supplied.
  2050. * @param {vec3} out Vector to receive translation component
  2051. * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
  2052. * @return {vec3} out
  2053. */
  2054. function getTranslation(out, mat) {
  2055. out[0] = mat[12];
  2056. out[1] = mat[13];
  2057. out[2] = mat[14];
  2058. return out;
  2059. }
  2060. /**
  2061. * Returns the scaling factor component of a transformation
  2062. * matrix. If a matrix is built with fromRotationTranslationScale
  2063. * with a normalized Quaternion paramter, the returned vector will be
  2064. * the same as the scaling vector
  2065. * originally supplied.
  2066. * @param {vec3} out Vector to receive scaling factor component
  2067. * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
  2068. * @return {vec3} out
  2069. */
  2070. function getScaling(out, mat) {
  2071. var m11 = mat[0];
  2072. var m12 = mat[1];
  2073. var m13 = mat[2];
  2074. var m21 = mat[4];
  2075. var m22 = mat[5];
  2076. var m23 = mat[6];
  2077. var m31 = mat[8];
  2078. var m32 = mat[9];
  2079. var m33 = mat[10];
  2080. out[0] = Math.hypot(m11, m12, m13);
  2081. out[1] = Math.hypot(m21, m22, m23);
  2082. out[2] = Math.hypot(m31, m32, m33);
  2083. return out;
  2084. }
  2085. /**
  2086. * Returns a quaternion representing the rotational component
  2087. * of a transformation matrix. If a matrix is built with
  2088. * fromRotationTranslation, the returned quaternion will be the
  2089. * same as the quaternion originally supplied.
  2090. * @param {quat} out Quaternion to receive the rotation component
  2091. * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
  2092. * @return {quat} out
  2093. */
  2094. function getRotation(out, mat) {
  2095. var scaling = new ARRAY_TYPE(3);
  2096. getScaling(scaling, mat);
  2097. var is1 = 1 / scaling[0];
  2098. var is2 = 1 / scaling[1];
  2099. var is3 = 1 / scaling[2];
  2100. var sm11 = mat[0] * is1;
  2101. var sm12 = mat[1] * is2;
  2102. var sm13 = mat[2] * is3;
  2103. var sm21 = mat[4] * is1;
  2104. var sm22 = mat[5] * is2;
  2105. var sm23 = mat[6] * is3;
  2106. var sm31 = mat[8] * is1;
  2107. var sm32 = mat[9] * is2;
  2108. var sm33 = mat[10] * is3;
  2109. var trace = sm11 + sm22 + sm33;
  2110. var S = 0;
  2111. if (trace > 0) {
  2112. S = Math.sqrt(trace + 1.0) * 2;
  2113. out[3] = 0.25 * S;
  2114. out[0] = (sm23 - sm32) / S;
  2115. out[1] = (sm31 - sm13) / S;
  2116. out[2] = (sm12 - sm21) / S;
  2117. } else if (sm11 > sm22 && sm11 > sm33) {
  2118. S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
  2119. out[3] = (sm23 - sm32) / S;
  2120. out[0] = 0.25 * S;
  2121. out[1] = (sm12 + sm21) / S;
  2122. out[2] = (sm31 + sm13) / S;
  2123. } else if (sm22 > sm33) {
  2124. S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
  2125. out[3] = (sm31 - sm13) / S;
  2126. out[0] = (sm12 + sm21) / S;
  2127. out[1] = 0.25 * S;
  2128. out[2] = (sm23 + sm32) / S;
  2129. } else {
  2130. S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
  2131. out[3] = (sm12 - sm21) / S;
  2132. out[0] = (sm31 + sm13) / S;
  2133. out[1] = (sm23 + sm32) / S;
  2134. out[2] = 0.25 * S;
  2135. }
  2136. return out;
  2137. }
  2138. /**
  2139. * Creates a matrix from a quaternion rotation, vector translation and vector scale
  2140. * This is equivalent to (but much faster than):
  2141. *
  2142. * mat4.identity(dest);
  2143. * mat4.translate(dest, vec);
  2144. * let quatMat = mat4.create();
  2145. * quat4.toMat4(quat, quatMat);
  2146. * mat4.multiply(dest, quatMat);
  2147. * mat4.scale(dest, scale)
  2148. *
  2149. * @param {mat4} out mat4 receiving operation result
  2150. * @param {quat4} q Rotation quaternion
  2151. * @param {ReadonlyVec3} v Translation vector
  2152. * @param {ReadonlyVec3} s Scaling vector
  2153. * @returns {mat4} out
  2154. */
  2155. function fromRotationTranslationScale(out, q, v, s) {
  2156. // Quaternion math
  2157. var x = q[0],
  2158. y = q[1],
  2159. z = q[2],
  2160. w = q[3];
  2161. var x2 = x + x;
  2162. var y2 = y + y;
  2163. var z2 = z + z;
  2164. var xx = x * x2;
  2165. var xy = x * y2;
  2166. var xz = x * z2;
  2167. var yy = y * y2;
  2168. var yz = y * z2;
  2169. var zz = z * z2;
  2170. var wx = w * x2;
  2171. var wy = w * y2;
  2172. var wz = w * z2;
  2173. var sx = s[0];
  2174. var sy = s[1];
  2175. var sz = s[2];
  2176. out[0] = (1 - (yy + zz)) * sx;
  2177. out[1] = (xy + wz) * sx;
  2178. out[2] = (xz - wy) * sx;
  2179. out[3] = 0;
  2180. out[4] = (xy - wz) * sy;
  2181. out[5] = (1 - (xx + zz)) * sy;
  2182. out[6] = (yz + wx) * sy;
  2183. out[7] = 0;
  2184. out[8] = (xz + wy) * sz;
  2185. out[9] = (yz - wx) * sz;
  2186. out[10] = (1 - (xx + yy)) * sz;
  2187. out[11] = 0;
  2188. out[12] = v[0];
  2189. out[13] = v[1];
  2190. out[14] = v[2];
  2191. out[15] = 1;
  2192. return out;
  2193. }
  2194. /**
  2195. * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin
  2196. * This is equivalent to (but much faster than):
  2197. *
  2198. * mat4.identity(dest);
  2199. * mat4.translate(dest, vec);
  2200. * mat4.translate(dest, origin);
  2201. * let quatMat = mat4.create();
  2202. * quat4.toMat4(quat, quatMat);
  2203. * mat4.multiply(dest, quatMat);
  2204. * mat4.scale(dest, scale)
  2205. * mat4.translate(dest, negativeOrigin);
  2206. *
  2207. * @param {mat4} out mat4 receiving operation result
  2208. * @param {quat4} q Rotation quaternion
  2209. * @param {ReadonlyVec3} v Translation vector
  2210. * @param {ReadonlyVec3} s Scaling vector
  2211. * @param {ReadonlyVec3} o The origin vector around which to scale and rotate
  2212. * @returns {mat4} out
  2213. */
  2214. function fromRotationTranslationScaleOrigin(out, q, v, s, o) {
  2215. // Quaternion math
  2216. var x = q[0],
  2217. y = q[1],
  2218. z = q[2],
  2219. w = q[3];
  2220. var x2 = x + x;
  2221. var y2 = y + y;
  2222. var z2 = z + z;
  2223. var xx = x * x2;
  2224. var xy = x * y2;
  2225. var xz = x * z2;
  2226. var yy = y * y2;
  2227. var yz = y * z2;
  2228. var zz = z * z2;
  2229. var wx = w * x2;
  2230. var wy = w * y2;
  2231. var wz = w * z2;
  2232. var sx = s[0];
  2233. var sy = s[1];
  2234. var sz = s[2];
  2235. var ox = o[0];
  2236. var oy = o[1];
  2237. var oz = o[2];
  2238. var out0 = (1 - (yy + zz)) * sx;
  2239. var out1 = (xy + wz) * sx;
  2240. var out2 = (xz - wy) * sx;
  2241. var out4 = (xy - wz) * sy;
  2242. var out5 = (1 - (xx + zz)) * sy;
  2243. var out6 = (yz + wx) * sy;
  2244. var out8 = (xz + wy) * sz;
  2245. var out9 = (yz - wx) * sz;
  2246. var out10 = (1 - (xx + yy)) * sz;
  2247. out[0] = out0;
  2248. out[1] = out1;
  2249. out[2] = out2;
  2250. out[3] = 0;
  2251. out[4] = out4;
  2252. out[5] = out5;
  2253. out[6] = out6;
  2254. out[7] = 0;
  2255. out[8] = out8;
  2256. out[9] = out9;
  2257. out[10] = out10;
  2258. out[11] = 0;
  2259. out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);
  2260. out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);
  2261. out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);
  2262. out[15] = 1;
  2263. return out;
  2264. }
  2265. /**
  2266. * Calculates a 4x4 matrix from the given quaternion
  2267. *
  2268. * @param {mat4} out mat4 receiving operation result
  2269. * @param {ReadonlyQuat} q Quaternion to create matrix from
  2270. *
  2271. * @returns {mat4} out
  2272. */
  2273. function fromQuat(out, q) {
  2274. var x = q[0],
  2275. y = q[1],
  2276. z = q[2],
  2277. w = q[3];
  2278. var x2 = x + x;
  2279. var y2 = y + y;
  2280. var z2 = z + z;
  2281. var xx = x * x2;
  2282. var yx = y * x2;
  2283. var yy = y * y2;
  2284. var zx = z * x2;
  2285. var zy = z * y2;
  2286. var zz = z * z2;
  2287. var wx = w * x2;
  2288. var wy = w * y2;
  2289. var wz = w * z2;
  2290. out[0] = 1 - yy - zz;
  2291. out[1] = yx + wz;
  2292. out[2] = zx - wy;
  2293. out[3] = 0;
  2294. out[4] = yx - wz;
  2295. out[5] = 1 - xx - zz;
  2296. out[6] = zy + wx;
  2297. out[7] = 0;
  2298. out[8] = zx + wy;
  2299. out[9] = zy - wx;
  2300. out[10] = 1 - xx - yy;
  2301. out[11] = 0;
  2302. out[12] = 0;
  2303. out[13] = 0;
  2304. out[14] = 0;
  2305. out[15] = 1;
  2306. return out;
  2307. }
  2308. /**
  2309. * Generates a frustum matrix with the given bounds
  2310. *
  2311. * @param {mat4} out mat4 frustum matrix will be written into
  2312. * @param {Number} left Left bound of the frustum
  2313. * @param {Number} right Right bound of the frustum
  2314. * @param {Number} bottom Bottom bound of the frustum
  2315. * @param {Number} top Top bound of the frustum
  2316. * @param {Number} near Near bound of the frustum
  2317. * @param {Number} far Far bound of the frustum
  2318. * @returns {mat4} out
  2319. */
  2320. function frustum(out, left, right, bottom, top, near, far) {
  2321. var rl = 1 / (right - left);
  2322. var tb = 1 / (top - bottom);
  2323. var nf = 1 / (near - far);
  2324. out[0] = near * 2 * rl;
  2325. out[1] = 0;
  2326. out[2] = 0;
  2327. out[3] = 0;
  2328. out[4] = 0;
  2329. out[5] = near * 2 * tb;
  2330. out[6] = 0;
  2331. out[7] = 0;
  2332. out[8] = (right + left) * rl;
  2333. out[9] = (top + bottom) * tb;
  2334. out[10] = (far + near) * nf;
  2335. out[11] = -1;
  2336. out[12] = 0;
  2337. out[13] = 0;
  2338. out[14] = far * near * 2 * nf;
  2339. out[15] = 0;
  2340. return out;
  2341. }
  2342. /**
  2343. * Generates a perspective projection matrix with the given bounds.
  2344. * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
  2345. * which matches WebGL/OpenGL's clip volume.
  2346. * Passing null/undefined/no value for far will generate infinite projection matrix.
  2347. *
  2348. * @param {mat4} out mat4 frustum matrix will be written into
  2349. * @param {number} fovy Vertical field of view in radians
  2350. * @param {number} aspect Aspect ratio. typically viewport width/height
  2351. * @param {number} near Near bound of the frustum
  2352. * @param {number} far Far bound of the frustum, can be null or Infinity
  2353. * @returns {mat4} out
  2354. */
  2355. function perspectiveNO(out, fovy, aspect, near, far) {
  2356. var f = 1.0 / Math.tan(fovy / 2),
  2357. nf;
  2358. out[0] = f / aspect;
  2359. out[1] = 0;
  2360. out[2] = 0;
  2361. out[3] = 0;
  2362. out[4] = 0;
  2363. out[5] = f;
  2364. out[6] = 0;
  2365. out[7] = 0;
  2366. out[8] = 0;
  2367. out[9] = 0;
  2368. out[11] = -1;
  2369. out[12] = 0;
  2370. out[13] = 0;
  2371. out[15] = 0;
  2372. if (far != null && far !== Infinity) {
  2373. nf = 1 / (near - far);
  2374. out[10] = (far + near) * nf;
  2375. out[14] = 2 * far * near * nf;
  2376. } else {
  2377. out[10] = -1;
  2378. out[14] = -2 * near;
  2379. }
  2380. return out;
  2381. }
  2382. /**
  2383. * Alias for {@link mat4.perspectiveNO}
  2384. * @function
  2385. */
  2386. var perspective = perspectiveNO;
  2387. /**
  2388. * Generates a perspective projection matrix suitable for WebGPU with the given bounds.
  2389. * The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
  2390. * which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
  2391. * Passing null/undefined/no value for far will generate infinite projection matrix.
  2392. *
  2393. * @param {mat4} out mat4 frustum matrix will be written into
  2394. * @param {number} fovy Vertical field of view in radians
  2395. * @param {number} aspect Aspect ratio. typically viewport width/height
  2396. * @param {number} near Near bound of the frustum
  2397. * @param {number} far Far bound of the frustum, can be null or Infinity
  2398. * @returns {mat4} out
  2399. */
  2400. function perspectiveZO(out, fovy, aspect, near, far) {
  2401. var f = 1.0 / Math.tan(fovy / 2),
  2402. nf;
  2403. out[0] = f / aspect;
  2404. out[1] = 0;
  2405. out[2] = 0;
  2406. out[3] = 0;
  2407. out[4] = 0;
  2408. out[5] = f;
  2409. out[6] = 0;
  2410. out[7] = 0;
  2411. out[8] = 0;
  2412. out[9] = 0;
  2413. out[11] = -1;
  2414. out[12] = 0;
  2415. out[13] = 0;
  2416. out[15] = 0;
  2417. if (far != null && far !== Infinity) {
  2418. nf = 1 / (near - far);
  2419. out[10] = far * nf;
  2420. out[14] = far * near * nf;
  2421. } else {
  2422. out[10] = -1;
  2423. out[14] = -near;
  2424. }
  2425. return out;
  2426. }
  2427. /**
  2428. * Generates a perspective projection matrix with the given field of view.
  2429. * This is primarily useful for generating projection matrices to be used
  2430. * with the still experiemental WebVR API.
  2431. *
  2432. * @param {mat4} out mat4 frustum matrix will be written into
  2433. * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees
  2434. * @param {number} near Near bound of the frustum
  2435. * @param {number} far Far bound of the frustum
  2436. * @returns {mat4} out
  2437. */
  2438. function perspectiveFromFieldOfView(out, fov, near, far) {
  2439. var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);
  2440. var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);
  2441. var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);
  2442. var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0);
  2443. var xScale = 2.0 / (leftTan + rightTan);
  2444. var yScale = 2.0 / (upTan + downTan);
  2445. out[0] = xScale;
  2446. out[1] = 0.0;
  2447. out[2] = 0.0;
  2448. out[3] = 0.0;
  2449. out[4] = 0.0;
  2450. out[5] = yScale;
  2451. out[6] = 0.0;
  2452. out[7] = 0.0;
  2453. out[8] = -((leftTan - rightTan) * xScale * 0.5);
  2454. out[9] = (upTan - downTan) * yScale * 0.5;
  2455. out[10] = far / (near - far);
  2456. out[11] = -1.0;
  2457. out[12] = 0.0;
  2458. out[13] = 0.0;
  2459. out[14] = far * near / (near - far);
  2460. out[15] = 0.0;
  2461. return out;
  2462. }
  2463. /**
  2464. * Generates a orthogonal projection matrix with the given bounds.
  2465. * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
  2466. * which matches WebGL/OpenGL's clip volume.
  2467. *
  2468. * @param {mat4} out mat4 frustum matrix will be written into
  2469. * @param {number} left Left bound of the frustum
  2470. * @param {number} right Right bound of the frustum
  2471. * @param {number} bottom Bottom bound of the frustum
  2472. * @param {number} top Top bound of the frustum
  2473. * @param {number} near Near bound of the frustum
  2474. * @param {number} far Far bound of the frustum
  2475. * @returns {mat4} out
  2476. */
  2477. function orthoNO(out, left, right, bottom, top, near, far) {
  2478. var lr = 1 / (left - right);
  2479. var bt = 1 / (bottom - top);
  2480. var nf = 1 / (near - far);
  2481. out[0] = -2 * lr;
  2482. out[1] = 0;
  2483. out[2] = 0;
  2484. out[3] = 0;
  2485. out[4] = 0;
  2486. out[5] = -2 * bt;
  2487. out[6] = 0;
  2488. out[7] = 0;
  2489. out[8] = 0;
  2490. out[9] = 0;
  2491. out[10] = 2 * nf;
  2492. out[11] = 0;
  2493. out[12] = (left + right) * lr;
  2494. out[13] = (top + bottom) * bt;
  2495. out[14] = (far + near) * nf;
  2496. out[15] = 1;
  2497. return out;
  2498. }
  2499. /**
  2500. * Alias for {@link mat4.orthoNO}
  2501. * @function
  2502. */
  2503. var ortho = orthoNO;
  2504. /**
  2505. * Generates a orthogonal projection matrix with the given bounds.
  2506. * The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
  2507. * which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
  2508. *
  2509. * @param {mat4} out mat4 frustum matrix will be written into
  2510. * @param {number} left Left bound of the frustum
  2511. * @param {number} right Right bound of the frustum
  2512. * @param {number} bottom Bottom bound of the frustum
  2513. * @param {number} top Top bound of the frustum
  2514. * @param {number} near Near bound of the frustum
  2515. * @param {number} far Far bound of the frustum
  2516. * @returns {mat4} out
  2517. */
  2518. function orthoZO(out, left, right, bottom, top, near, far) {
  2519. var lr = 1 / (left - right);
  2520. var bt = 1 / (bottom - top);
  2521. var nf = 1 / (near - far);
  2522. out[0] = -2 * lr;
  2523. out[1] = 0;
  2524. out[2] = 0;
  2525. out[3] = 0;
  2526. out[4] = 0;
  2527. out[5] = -2 * bt;
  2528. out[6] = 0;
  2529. out[7] = 0;
  2530. out[8] = 0;
  2531. out[9] = 0;
  2532. out[10] = nf;
  2533. out[11] = 0;
  2534. out[12] = (left + right) * lr;
  2535. out[13] = (top + bottom) * bt;
  2536. out[14] = near * nf;
  2537. out[15] = 1;
  2538. return out;
  2539. }
  2540. /**
  2541. * Generates a look-at matrix with the given eye position, focal point, and up axis.
  2542. * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
  2543. *
  2544. * @param {mat4} out mat4 frustum matrix will be written into
  2545. * @param {ReadonlyVec3} eye Position of the viewer
  2546. * @param {ReadonlyVec3} center Point the viewer is looking at
  2547. * @param {ReadonlyVec3} up vec3 pointing up
  2548. * @returns {mat4} out
  2549. */
  2550. function lookAt(out, eye, center, up) {
  2551. var x0, x1, x2, y0, y1, y2, z0, z1, z2, len;
  2552. var eyex = eye[0];
  2553. var eyey = eye[1];
  2554. var eyez = eye[2];
  2555. var upx = up[0];
  2556. var upy = up[1];
  2557. var upz = up[2];
  2558. var centerx = center[0];
  2559. var centery = center[1];
  2560. var centerz = center[2];
  2561. if (Math.abs(eyex - centerx) < EPSILON && Math.abs(eyey - centery) < EPSILON && Math.abs(eyez - centerz) < EPSILON) {
  2562. return identity(out);
  2563. }
  2564. z0 = eyex - centerx;
  2565. z1 = eyey - centery;
  2566. z2 = eyez - centerz;
  2567. len = 1 / Math.hypot(z0, z1, z2);
  2568. z0 *= len;
  2569. z1 *= len;
  2570. z2 *= len;
  2571. x0 = upy * z2 - upz * z1;
  2572. x1 = upz * z0 - upx * z2;
  2573. x2 = upx * z1 - upy * z0;
  2574. len = Math.hypot(x0, x1, x2);
  2575. if (!len) {
  2576. x0 = 0;
  2577. x1 = 0;
  2578. x2 = 0;
  2579. } else {
  2580. len = 1 / len;
  2581. x0 *= len;
  2582. x1 *= len;
  2583. x2 *= len;
  2584. }
  2585. y0 = z1 * x2 - z2 * x1;
  2586. y1 = z2 * x0 - z0 * x2;
  2587. y2 = z0 * x1 - z1 * x0;
  2588. len = Math.hypot(y0, y1, y2);
  2589. if (!len) {
  2590. y0 = 0;
  2591. y1 = 0;
  2592. y2 = 0;
  2593. } else {
  2594. len = 1 / len;
  2595. y0 *= len;
  2596. y1 *= len;
  2597. y2 *= len;
  2598. }
  2599. out[0] = x0;
  2600. out[1] = y0;
  2601. out[2] = z0;
  2602. out[3] = 0;
  2603. out[4] = x1;
  2604. out[5] = y1;
  2605. out[6] = z1;
  2606. out[7] = 0;
  2607. out[8] = x2;
  2608. out[9] = y2;
  2609. out[10] = z2;
  2610. out[11] = 0;
  2611. out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
  2612. out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
  2613. out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
  2614. out[15] = 1;
  2615. return out;
  2616. }
  2617. /**
  2618. * Generates a matrix that makes something look at something else.
  2619. *
  2620. * @param {mat4} out mat4 frustum matrix will be written into
  2621. * @param {ReadonlyVec3} eye Position of the viewer
  2622. * @param {ReadonlyVec3} center Point the viewer is looking at
  2623. * @param {ReadonlyVec3} up vec3 pointing up
  2624. * @returns {mat4} out
  2625. */
  2626. function targetTo(out, eye, target, up) {
  2627. var eyex = eye[0],
  2628. eyey = eye[1],
  2629. eyez = eye[2],
  2630. upx = up[0],
  2631. upy = up[1],
  2632. upz = up[2];
  2633. var z0 = eyex - target[0],
  2634. z1 = eyey - target[1],
  2635. z2 = eyez - target[2];
  2636. var len = z0 * z0 + z1 * z1 + z2 * z2;
  2637. if (len > 0) {
  2638. len = 1 / Math.sqrt(len);
  2639. z0 *= len;
  2640. z1 *= len;
  2641. z2 *= len;
  2642. }
  2643. var x0 = upy * z2 - upz * z1,
  2644. x1 = upz * z0 - upx * z2,
  2645. x2 = upx * z1 - upy * z0;
  2646. len = x0 * x0 + x1 * x1 + x2 * x2;
  2647. if (len > 0) {
  2648. len = 1 / Math.sqrt(len);
  2649. x0 *= len;
  2650. x1 *= len;
  2651. x2 *= len;
  2652. }
  2653. out[0] = x0;
  2654. out[1] = x1;
  2655. out[2] = x2;
  2656. out[3] = 0;
  2657. out[4] = z1 * x2 - z2 * x1;
  2658. out[5] = z2 * x0 - z0 * x2;
  2659. out[6] = z0 * x1 - z1 * x0;
  2660. out[7] = 0;
  2661. out[8] = z0;
  2662. out[9] = z1;
  2663. out[10] = z2;
  2664. out[11] = 0;
  2665. out[12] = eyex;
  2666. out[13] = eyey;
  2667. out[14] = eyez;
  2668. out[15] = 1;
  2669. return out;
  2670. }
  2671. /**
  2672. * Returns a string representation of a mat4
  2673. *
  2674. * @param {ReadonlyMat4} a matrix to represent as a string
  2675. * @returns {String} string representation of the matrix
  2676. */
  2677. function str(a) {
  2678. return "mat4(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ", " + a[4] + ", " + a[5] + ", " + a[6] + ", " + a[7] + ", " + a[8] + ", " + a[9] + ", " + a[10] + ", " + a[11] + ", " + a[12] + ", " + a[13] + ", " + a[14] + ", " + a[15] + ")";
  2679. }
  2680. /**
  2681. * Returns Frobenius norm of a mat4
  2682. *
  2683. * @param {ReadonlyMat4} a the matrix to calculate Frobenius norm of
  2684. * @returns {Number} Frobenius norm
  2685. */
  2686. function frob(a) {
  2687. return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15]);
  2688. }
  2689. /**
  2690. * Adds two mat4's
  2691. *
  2692. * @param {mat4} out the receiving matrix
  2693. * @param {ReadonlyMat4} a the first operand
  2694. * @param {ReadonlyMat4} b the second operand
  2695. * @returns {mat4} out
  2696. */
  2697. function add(out, a, b) {
  2698. out[0] = a[0] + b[0];
  2699. out[1] = a[1] + b[1];
  2700. out[2] = a[2] + b[2];
  2701. out[3] = a[3] + b[3];
  2702. out[4] = a[4] + b[4];
  2703. out[5] = a[5] + b[5];
  2704. out[6] = a[6] + b[6];
  2705. out[7] = a[7] + b[7];
  2706. out[8] = a[8] + b[8];
  2707. out[9] = a[9] + b[9];
  2708. out[10] = a[10] + b[10];
  2709. out[11] = a[11] + b[11];
  2710. out[12] = a[12] + b[12];
  2711. out[13] = a[13] + b[13];
  2712. out[14] = a[14] + b[14];
  2713. out[15] = a[15] + b[15];
  2714. return out;
  2715. }
  2716. /**
  2717. * Subtracts matrix b from matrix a
  2718. *
  2719. * @param {mat4} out the receiving matrix
  2720. * @param {ReadonlyMat4} a the first operand
  2721. * @param {ReadonlyMat4} b the second operand
  2722. * @returns {mat4} out
  2723. */
  2724. function subtract(out, a, b) {
  2725. out[0] = a[0] - b[0];
  2726. out[1] = a[1] - b[1];
  2727. out[2] = a[2] - b[2];
  2728. out[3] = a[3] - b[3];
  2729. out[4] = a[4] - b[4];
  2730. out[5] = a[5] - b[5];
  2731. out[6] = a[6] - b[6];
  2732. out[7] = a[7] - b[7];
  2733. out[8] = a[8] - b[8];
  2734. out[9] = a[9] - b[9];
  2735. out[10] = a[10] - b[10];
  2736. out[11] = a[11] - b[11];
  2737. out[12] = a[12] - b[12];
  2738. out[13] = a[13] - b[13];
  2739. out[14] = a[14] - b[14];
  2740. out[15] = a[15] - b[15];
  2741. return out;
  2742. }
  2743. /**
  2744. * Multiply each element of the matrix by a scalar.
  2745. *
  2746. * @param {mat4} out the receiving matrix
  2747. * @param {ReadonlyMat4} a the matrix to scale
  2748. * @param {Number} b amount to scale the matrix's elements by
  2749. * @returns {mat4} out
  2750. */
  2751. function multiplyScalar(out, a, b) {
  2752. out[0] = a[0] * b;
  2753. out[1] = a[1] * b;
  2754. out[2] = a[2] * b;
  2755. out[3] = a[3] * b;
  2756. out[4] = a[4] * b;
  2757. out[5] = a[5] * b;
  2758. out[6] = a[6] * b;
  2759. out[7] = a[7] * b;
  2760. out[8] = a[8] * b;
  2761. out[9] = a[9] * b;
  2762. out[10] = a[10] * b;
  2763. out[11] = a[11] * b;
  2764. out[12] = a[12] * b;
  2765. out[13] = a[13] * b;
  2766. out[14] = a[14] * b;
  2767. out[15] = a[15] * b;
  2768. return out;
  2769. }
  2770. /**
  2771. * Adds two mat4's after multiplying each element of the second operand by a scalar value.
  2772. *
  2773. * @param {mat4} out the receiving vector
  2774. * @param {ReadonlyMat4} a the first operand
  2775. * @param {ReadonlyMat4} b the second operand
  2776. * @param {Number} scale the amount to scale b's elements by before adding
  2777. * @returns {mat4} out
  2778. */
  2779. function multiplyScalarAndAdd(out, a, b, scale) {
  2780. out[0] = a[0] + b[0] * scale;
  2781. out[1] = a[1] + b[1] * scale;
  2782. out[2] = a[2] + b[2] * scale;
  2783. out[3] = a[3] + b[3] * scale;
  2784. out[4] = a[4] + b[4] * scale;
  2785. out[5] = a[5] + b[5] * scale;
  2786. out[6] = a[6] + b[6] * scale;
  2787. out[7] = a[7] + b[7] * scale;
  2788. out[8] = a[8] + b[8] * scale;
  2789. out[9] = a[9] + b[9] * scale;
  2790. out[10] = a[10] + b[10] * scale;
  2791. out[11] = a[11] + b[11] * scale;
  2792. out[12] = a[12] + b[12] * scale;
  2793. out[13] = a[13] + b[13] * scale;
  2794. out[14] = a[14] + b[14] * scale;
  2795. out[15] = a[15] + b[15] * scale;
  2796. return out;
  2797. }
  2798. /**
  2799. * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
  2800. *
  2801. * @param {ReadonlyMat4} a The first matrix.
  2802. * @param {ReadonlyMat4} b The second matrix.
  2803. * @returns {Boolean} True if the matrices are equal, false otherwise.
  2804. */
  2805. function exactEquals(a, b) {
  2806. return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && a[8] === b[8] && a[9] === b[9] && a[10] === b[10] && a[11] === b[11] && a[12] === b[12] && a[13] === b[13] && a[14] === b[14] && a[15] === b[15];
  2807. }
  2808. /**
  2809. * Returns whether or not the matrices have approximately the same elements in the same position.
  2810. *
  2811. * @param {ReadonlyMat4} a The first matrix.
  2812. * @param {ReadonlyMat4} b The second matrix.
  2813. * @returns {Boolean} True if the matrices are equal, false otherwise.
  2814. */
  2815. function equals(a, b) {
  2816. var a0 = a[0],
  2817. a1 = a[1],
  2818. a2 = a[2],
  2819. a3 = a[3];
  2820. var a4 = a[4],
  2821. a5 = a[5],
  2822. a6 = a[6],
  2823. a7 = a[7];
  2824. var a8 = a[8],
  2825. a9 = a[9],
  2826. a10 = a[10],
  2827. a11 = a[11];
  2828. var a12 = a[12],
  2829. a13 = a[13],
  2830. a14 = a[14],
  2831. a15 = a[15];
  2832. var b0 = b[0],
  2833. b1 = b[1],
  2834. b2 = b[2],
  2835. b3 = b[3];
  2836. var b4 = b[4],
  2837. b5 = b[5],
  2838. b6 = b[6],
  2839. b7 = b[7];
  2840. var b8 = b[8],
  2841. b9 = b[9],
  2842. b10 = b[10],
  2843. b11 = b[11];
  2844. var b12 = b[12],
  2845. b13 = b[13],
  2846. b14 = b[14],
  2847. b15 = b[15];
  2848. return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) && Math.abs(a9 - b9) <= EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) && Math.abs(a10 - b10) <= EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) && Math.abs(a11 - b11) <= EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) && Math.abs(a12 - b12) <= EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) && Math.abs(a13 - b13) <= EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) && Math.abs(a14 - b14) <= EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) && Math.abs(a15 - b15) <= EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15));
  2849. }
  2850. /**
  2851. * Alias for {@link mat4.multiply}
  2852. * @function
  2853. */
  2854. var mul = multiply;
  2855. /**
  2856. * Alias for {@link mat4.subtract}
  2857. * @function
  2858. */
  2859. var sub = subtract;
  2860. var mat4 = /*#__PURE__*/Object.freeze({
  2861. __proto__: null,
  2862. create: create$1,
  2863. clone: clone,
  2864. copy: copy,
  2865. fromValues: fromValues$1,
  2866. set: set,
  2867. identity: identity,
  2868. transpose: transpose,
  2869. invert: invert,
  2870. adjoint: adjoint,
  2871. determinant: determinant,
  2872. multiply: multiply,
  2873. translate: translate,
  2874. scale: scale,
  2875. rotate: rotate,
  2876. rotateX: rotateX,
  2877. rotateY: rotateY,
  2878. rotateZ: rotateZ,
  2879. fromTranslation: fromTranslation,
  2880. fromScaling: fromScaling,
  2881. fromRotation: fromRotation,
  2882. fromXRotation: fromXRotation,
  2883. fromYRotation: fromYRotation,
  2884. fromZRotation: fromZRotation,
  2885. fromRotationTranslation: fromRotationTranslation,
  2886. fromQuat2: fromQuat2,
  2887. getTranslation: getTranslation,
  2888. getScaling: getScaling,
  2889. getRotation: getRotation,
  2890. fromRotationTranslationScale: fromRotationTranslationScale,
  2891. fromRotationTranslationScaleOrigin: fromRotationTranslationScaleOrigin,
  2892. fromQuat: fromQuat,
  2893. frustum: frustum,
  2894. perspectiveNO: perspectiveNO,
  2895. perspective: perspective,
  2896. perspectiveZO: perspectiveZO,
  2897. perspectiveFromFieldOfView: perspectiveFromFieldOfView,
  2898. orthoNO: orthoNO,
  2899. ortho: ortho,
  2900. orthoZO: orthoZO,
  2901. lookAt: lookAt,
  2902. targetTo: targetTo,
  2903. str: str,
  2904. frob: frob,
  2905. add: add,
  2906. subtract: subtract,
  2907. multiplyScalar: multiplyScalar,
  2908. multiplyScalarAndAdd: multiplyScalarAndAdd,
  2909. exactEquals: exactEquals,
  2910. equals: equals,
  2911. mul: mul,
  2912. sub: sub
  2913. });
  2914. /**
  2915. * 3 Dimensional Vector
  2916. * @module vec3
  2917. */
  2918. /**
  2919. * Creates a new, empty vec3
  2920. *
  2921. * @returns {vec3} a new 3D vector
  2922. */
  2923. function create$2() {
  2924. var out = new ARRAY_TYPE(3);
  2925. if (ARRAY_TYPE != Float32Array) {
  2926. out[0] = 0;
  2927. out[1] = 0;
  2928. out[2] = 0;
  2929. }
  2930. return out;
  2931. }
  2932. /**
  2933. * Creates a new vec3 initialized with values from an existing vector
  2934. *
  2935. * @param {ReadonlyVec3} a vector to clone
  2936. * @returns {vec3} a new 3D vector
  2937. */
  2938. function clone$1(a) {
  2939. var out = new ARRAY_TYPE(3);
  2940. out[0] = a[0];
  2941. out[1] = a[1];
  2942. out[2] = a[2];
  2943. return out;
  2944. }
  2945. /**
  2946. * Calculates the length of a vec3
  2947. *
  2948. * @param {ReadonlyVec3} a vector to calculate length of
  2949. * @returns {Number} length of a
  2950. */
  2951. function length(a) {
  2952. var x = a[0];
  2953. var y = a[1];
  2954. var z = a[2];
  2955. return Math.hypot(x, y, z);
  2956. }
  2957. /**
  2958. * Creates a new vec3 initialized with the given values
  2959. *
  2960. * @param {Number} x X component
  2961. * @param {Number} y Y component
  2962. * @param {Number} z Z component
  2963. * @returns {vec3} a new 3D vector
  2964. */
  2965. function fromValues$2(x, y, z) {
  2966. var out = new ARRAY_TYPE(3);
  2967. out[0] = x;
  2968. out[1] = y;
  2969. out[2] = z;
  2970. return out;
  2971. }
  2972. /**
  2973. * Copy the values from one vec3 to another
  2974. *
  2975. * @param {vec3} out the receiving vector
  2976. * @param {ReadonlyVec3} a the source vector
  2977. * @returns {vec3} out
  2978. */
  2979. function copy$1(out, a) {
  2980. out[0] = a[0];
  2981. out[1] = a[1];
  2982. out[2] = a[2];
  2983. return out;
  2984. }
  2985. /**
  2986. * Set the components of a vec3 to the given values
  2987. *
  2988. * @param {vec3} out the receiving vector
  2989. * @param {Number} x X component
  2990. * @param {Number} y Y component
  2991. * @param {Number} z Z component
  2992. * @returns {vec3} out
  2993. */
  2994. function set$1(out, x, y, z) {
  2995. out[0] = x;
  2996. out[1] = y;
  2997. out[2] = z;
  2998. return out;
  2999. }
  3000. /**
  3001. * Adds two vec3's
  3002. *
  3003. * @param {vec3} out the receiving vector
  3004. * @param {ReadonlyVec3} a the first operand
  3005. * @param {ReadonlyVec3} b the second operand
  3006. * @returns {vec3} out
  3007. */
  3008. function add$1(out, a, b) {
  3009. out[0] = a[0] + b[0];
  3010. out[1] = a[1] + b[1];
  3011. out[2] = a[2] + b[2];
  3012. return out;
  3013. }
  3014. /**
  3015. * Subtracts vector b from vector a
  3016. *
  3017. * @param {vec3} out the receiving vector
  3018. * @param {ReadonlyVec3} a the first operand
  3019. * @param {ReadonlyVec3} b the second operand
  3020. * @returns {vec3} out
  3021. */
  3022. function subtract$1(out, a, b) {
  3023. out[0] = a[0] - b[0];
  3024. out[1] = a[1] - b[1];
  3025. out[2] = a[2] - b[2];
  3026. return out;
  3027. }
  3028. /**
  3029. * Multiplies two vec3's
  3030. *
  3031. * @param {vec3} out the receiving vector
  3032. * @param {ReadonlyVec3} a the first operand
  3033. * @param {ReadonlyVec3} b the second operand
  3034. * @returns {vec3} out
  3035. */
  3036. function multiply$1(out, a, b) {
  3037. out[0] = a[0] * b[0];
  3038. out[1] = a[1] * b[1];
  3039. out[2] = a[2] * b[2];
  3040. return out;
  3041. }
  3042. /**
  3043. * Scales a vec3 by a scalar number
  3044. *
  3045. * @param {vec3} out the receiving vector
  3046. * @param {ReadonlyVec3} a the vector to scale
  3047. * @param {Number} b amount to scale the vector by
  3048. * @returns {vec3} out
  3049. */
  3050. function scale$1(out, a, b) {
  3051. out[0] = a[0] * b;
  3052. out[1] = a[1] * b;
  3053. out[2] = a[2] * b;
  3054. return out;
  3055. }
  3056. /**
  3057. * Normalize a vec3
  3058. *
  3059. * @param {vec3} out the receiving vector
  3060. * @param {ReadonlyVec3} a vector to normalize
  3061. * @returns {vec3} out
  3062. */
  3063. function normalize(out, a) {
  3064. var x = a[0];
  3065. var y = a[1];
  3066. var z = a[2];
  3067. var len = x * x + y * y + z * z;
  3068. if (len > 0) {
  3069. //TODO: evaluate use of glm_invsqrt here?
  3070. len = 1 / Math.sqrt(len);
  3071. }
  3072. out[0] = a[0] * len;
  3073. out[1] = a[1] * len;
  3074. out[2] = a[2] * len;
  3075. return out;
  3076. }
  3077. /**
  3078. * Calculates the dot product of two vec3's
  3079. *
  3080. * @param {ReadonlyVec3} a the first operand
  3081. * @param {ReadonlyVec3} b the second operand
  3082. * @returns {Number} dot product of a and b
  3083. */
  3084. function dot(a, b) {
  3085. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  3086. }
  3087. /**
  3088. * Computes the cross product of two vec3's
  3089. *
  3090. * @param {vec3} out the receiving vector
  3091. * @param {ReadonlyVec3} a the first operand
  3092. * @param {ReadonlyVec3} b the second operand
  3093. * @returns {vec3} out
  3094. */
  3095. function cross(out, a, b) {
  3096. var ax = a[0],
  3097. ay = a[1],
  3098. az = a[2];
  3099. var bx = b[0],
  3100. by = b[1],
  3101. bz = b[2];
  3102. out[0] = ay * bz - az * by;
  3103. out[1] = az * bx - ax * bz;
  3104. out[2] = ax * by - ay * bx;
  3105. return out;
  3106. }
  3107. /**
  3108. * Performs a linear interpolation between two vec3's
  3109. *
  3110. * @param {vec3} out the receiving vector
  3111. * @param {ReadonlyVec3} a the first operand
  3112. * @param {ReadonlyVec3} b the second operand
  3113. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  3114. * @returns {vec3} out
  3115. */
  3116. function lerp(out, a, b, t) {
  3117. var ax = a[0];
  3118. var ay = a[1];
  3119. var az = a[2];
  3120. out[0] = ax + t * (b[0] - ax);
  3121. out[1] = ay + t * (b[1] - ay);
  3122. out[2] = az + t * (b[2] - az);
  3123. return out;
  3124. }
  3125. /**
  3126. * Transforms the vec3 with a mat4.
  3127. * 4th vector component is implicitly '1'
  3128. *
  3129. * @param {vec3} out the receiving vector
  3130. * @param {ReadonlyVec3} a the vector to transform
  3131. * @param {ReadonlyMat4} m matrix to transform with
  3132. * @returns {vec3} out
  3133. */
  3134. function transformMat4(out, a, m) {
  3135. var x = a[0],
  3136. y = a[1],
  3137. z = a[2];
  3138. var w = m[3] * x + m[7] * y + m[11] * z + m[15];
  3139. w = w || 1.0;
  3140. out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
  3141. out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
  3142. out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
  3143. return out;
  3144. }
  3145. /**
  3146. * Transforms the vec3 with a mat3.
  3147. *
  3148. * @param {vec3} out the receiving vector
  3149. * @param {ReadonlyVec3} a the vector to transform
  3150. * @param {ReadonlyMat3} m the 3x3 matrix to transform with
  3151. * @returns {vec3} out
  3152. */
  3153. function transformMat3(out, a, m) {
  3154. var x = a[0],
  3155. y = a[1],
  3156. z = a[2];
  3157. out[0] = x * m[0] + y * m[3] + z * m[6];
  3158. out[1] = x * m[1] + y * m[4] + z * m[7];
  3159. out[2] = x * m[2] + y * m[5] + z * m[8];
  3160. return out;
  3161. }
  3162. /**
  3163. * Transforms the vec3 with a quat
  3164. * Can also be used for dual quaternions. (Multiply it with the real part)
  3165. *
  3166. * @param {vec3} out the receiving vector
  3167. * @param {ReadonlyVec3} a the vector to transform
  3168. * @param {ReadonlyQuat} q quaternion to transform with
  3169. * @returns {vec3} out
  3170. */
  3171. function transformQuat(out, a, q) {
  3172. // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed
  3173. var qx = q[0],
  3174. qy = q[1],
  3175. qz = q[2],
  3176. qw = q[3];
  3177. var x = a[0],
  3178. y = a[1],
  3179. z = a[2]; // var qvec = [qx, qy, qz];
  3180. // var uv = vec3.cross([], qvec, a);
  3181. var uvx = qy * z - qz * y,
  3182. uvy = qz * x - qx * z,
  3183. uvz = qx * y - qy * x; // var uuv = vec3.cross([], qvec, uv);
  3184. var uuvx = qy * uvz - qz * uvy,
  3185. uuvy = qz * uvx - qx * uvz,
  3186. uuvz = qx * uvy - qy * uvx; // vec3.scale(uv, uv, 2 * w);
  3187. var w2 = qw * 2;
  3188. uvx *= w2;
  3189. uvy *= w2;
  3190. uvz *= w2; // vec3.scale(uuv, uuv, 2);
  3191. uuvx *= 2;
  3192. uuvy *= 2;
  3193. uuvz *= 2; // return vec3.add(out, a, vec3.add(out, uv, uuv));
  3194. out[0] = x + uvx + uuvx;
  3195. out[1] = y + uvy + uuvy;
  3196. out[2] = z + uvz + uuvz;
  3197. return out;
  3198. }
  3199. /**
  3200. * Returns whether or not the vectors have approximately the same elements in the same position.
  3201. *
  3202. * @param {ReadonlyVec3} a The first vector.
  3203. * @param {ReadonlyVec3} b The second vector.
  3204. * @returns {Boolean} True if the vectors are equal, false otherwise.
  3205. */
  3206. function equals$1(a, b) {
  3207. var a0 = a[0],
  3208. a1 = a[1],
  3209. a2 = a[2];
  3210. var b0 = b[0],
  3211. b1 = b[1],
  3212. b2 = b[2];
  3213. return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2));
  3214. }
  3215. /**
  3216. * Alias for {@link vec3.length}
  3217. * @function
  3218. */
  3219. var len = length;
  3220. /**
  3221. * Perform some operation over an array of vec3s.
  3222. *
  3223. * @param {Array} a the array of vectors to iterate over
  3224. * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
  3225. * @param {Number} offset Number of elements to skip at the beginning of the array
  3226. * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
  3227. * @param {Function} fn Function to call for each vector in the array
  3228. * @param {Object} [arg] additional argument to pass to fn
  3229. * @returns {Array} a
  3230. * @function
  3231. */
  3232. var forEach = function () {
  3233. var vec = create$2();
  3234. return function (a, stride, offset, count, fn, arg) {
  3235. var i, l;
  3236. if (!stride) {
  3237. stride = 3;
  3238. }
  3239. if (!offset) {
  3240. offset = 0;
  3241. }
  3242. if (count) {
  3243. l = Math.min(count * stride + offset, a.length);
  3244. } else {
  3245. l = a.length;
  3246. }
  3247. for (i = offset; i < l; i += stride) {
  3248. vec[0] = a[i];
  3249. vec[1] = a[i + 1];
  3250. vec[2] = a[i + 2];
  3251. fn(vec, vec, arg);
  3252. a[i] = vec[0];
  3253. a[i + 1] = vec[1];
  3254. a[i + 2] = vec[2];
  3255. }
  3256. return a;
  3257. };
  3258. }();
  3259. /**
  3260. * 4 Dimensional Vector
  3261. * @module vec4
  3262. */
  3263. /**
  3264. * Creates a new, empty vec4
  3265. *
  3266. * @returns {vec4} a new 4D vector
  3267. */
  3268. function create$3() {
  3269. var out = new ARRAY_TYPE(4);
  3270. if (ARRAY_TYPE != Float32Array) {
  3271. out[0] = 0;
  3272. out[1] = 0;
  3273. out[2] = 0;
  3274. out[3] = 0;
  3275. }
  3276. return out;
  3277. }
  3278. /**
  3279. * Creates a new vec4 initialized with the given values
  3280. *
  3281. * @param {Number} x X component
  3282. * @param {Number} y Y component
  3283. * @param {Number} z Z component
  3284. * @param {Number} w W component
  3285. * @returns {vec4} a new 4D vector
  3286. */
  3287. function fromValues$3(x, y, z, w) {
  3288. var out = new ARRAY_TYPE(4);
  3289. out[0] = x;
  3290. out[1] = y;
  3291. out[2] = z;
  3292. out[3] = w;
  3293. return out;
  3294. }
  3295. /**
  3296. * Copy the values from one vec4 to another
  3297. *
  3298. * @param {vec4} out the receiving vector
  3299. * @param {ReadonlyVec4} a the source vector
  3300. * @returns {vec4} out
  3301. */
  3302. function copy$2(out, a) {
  3303. out[0] = a[0];
  3304. out[1] = a[1];
  3305. out[2] = a[2];
  3306. out[3] = a[3];
  3307. return out;
  3308. }
  3309. /**
  3310. * Normalize a vec4
  3311. *
  3312. * @param {vec4} out the receiving vector
  3313. * @param {ReadonlyVec4} a vector to normalize
  3314. * @returns {vec4} out
  3315. */
  3316. function normalize$1(out, a) {
  3317. var x = a[0];
  3318. var y = a[1];
  3319. var z = a[2];
  3320. var w = a[3];
  3321. var len = x * x + y * y + z * z + w * w;
  3322. if (len > 0) {
  3323. len = 1 / Math.sqrt(len);
  3324. }
  3325. out[0] = x * len;
  3326. out[1] = y * len;
  3327. out[2] = z * len;
  3328. out[3] = w * len;
  3329. return out;
  3330. }
  3331. /**
  3332. * Transforms the vec4 with a mat4.
  3333. *
  3334. * @param {vec4} out the receiving vector
  3335. * @param {ReadonlyVec4} a the vector to transform
  3336. * @param {ReadonlyMat4} m matrix to transform with
  3337. * @returns {vec4} out
  3338. */
  3339. function transformMat4$1(out, a, m) {
  3340. var x = a[0],
  3341. y = a[1],
  3342. z = a[2],
  3343. w = a[3];
  3344. out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
  3345. out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
  3346. out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
  3347. out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
  3348. return out;
  3349. }
  3350. /**
  3351. * Perform some operation over an array of vec4s.
  3352. *
  3353. * @param {Array} a the array of vectors to iterate over
  3354. * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
  3355. * @param {Number} offset Number of elements to skip at the beginning of the array
  3356. * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array
  3357. * @param {Function} fn Function to call for each vector in the array
  3358. * @param {Object} [arg] additional argument to pass to fn
  3359. * @returns {Array} a
  3360. * @function
  3361. */
  3362. var forEach$1 = function () {
  3363. var vec = create$3();
  3364. return function (a, stride, offset, count, fn, arg) {
  3365. var i, l;
  3366. if (!stride) {
  3367. stride = 4;
  3368. }
  3369. if (!offset) {
  3370. offset = 0;
  3371. }
  3372. if (count) {
  3373. l = Math.min(count * stride + offset, a.length);
  3374. } else {
  3375. l = a.length;
  3376. }
  3377. for (i = offset; i < l; i += stride) {
  3378. vec[0] = a[i];
  3379. vec[1] = a[i + 1];
  3380. vec[2] = a[i + 2];
  3381. vec[3] = a[i + 3];
  3382. fn(vec, vec, arg);
  3383. a[i] = vec[0];
  3384. a[i + 1] = vec[1];
  3385. a[i + 2] = vec[2];
  3386. a[i + 3] = vec[3];
  3387. }
  3388. return a;
  3389. };
  3390. }();
  3391. /**
  3392. * Quaternion
  3393. * @module quat
  3394. */
  3395. /**
  3396. * Creates a new identity quat
  3397. *
  3398. * @returns {quat} a new quaternion
  3399. */
  3400. function create$4() {
  3401. var out = new ARRAY_TYPE(4);
  3402. if (ARRAY_TYPE != Float32Array) {
  3403. out[0] = 0;
  3404. out[1] = 0;
  3405. out[2] = 0;
  3406. }
  3407. out[3] = 1;
  3408. return out;
  3409. }
  3410. /**
  3411. * Sets a quat from the given angle and rotation axis,
  3412. * then returns it.
  3413. *
  3414. * @param {quat} out the receiving quaternion
  3415. * @param {ReadonlyVec3} axis the axis around which to rotate
  3416. * @param {Number} rad the angle in radians
  3417. * @returns {quat} out
  3418. **/
  3419. function setAxisAngle(out, axis, rad) {
  3420. rad = rad * 0.5;
  3421. var s = Math.sin(rad);
  3422. out[0] = s * axis[0];
  3423. out[1] = s * axis[1];
  3424. out[2] = s * axis[2];
  3425. out[3] = Math.cos(rad);
  3426. return out;
  3427. }
  3428. /**
  3429. * Multiplies two quat's
  3430. *
  3431. * @param {quat} out the receiving quaternion
  3432. * @param {ReadonlyQuat} a the first operand
  3433. * @param {ReadonlyQuat} b the second operand
  3434. * @returns {quat} out
  3435. */
  3436. function multiply$2(out, a, b) {
  3437. var ax = a[0],
  3438. ay = a[1],
  3439. az = a[2],
  3440. aw = a[3];
  3441. var bx = b[0],
  3442. by = b[1],
  3443. bz = b[2],
  3444. bw = b[3];
  3445. out[0] = ax * bw + aw * bx + ay * bz - az * by;
  3446. out[1] = ay * bw + aw * by + az * bx - ax * bz;
  3447. out[2] = az * bw + aw * bz + ax * by - ay * bx;
  3448. out[3] = aw * bw - ax * bx - ay * by - az * bz;
  3449. return out;
  3450. }
  3451. /**
  3452. * Performs a spherical linear interpolation between two quat
  3453. *
  3454. * @param {quat} out the receiving quaternion
  3455. * @param {ReadonlyQuat} a the first operand
  3456. * @param {ReadonlyQuat} b the second operand
  3457. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  3458. * @returns {quat} out
  3459. */
  3460. function slerp(out, a, b, t) {
  3461. // benchmarks:
  3462. // http://jsperf.com/quaternion-slerp-implementations
  3463. var ax = a[0],
  3464. ay = a[1],
  3465. az = a[2],
  3466. aw = a[3];
  3467. var bx = b[0],
  3468. by = b[1],
  3469. bz = b[2],
  3470. bw = b[3];
  3471. var omega, cosom, sinom, scale0, scale1; // calc cosine
  3472. cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary)
  3473. if (cosom < 0.0) {
  3474. cosom = -cosom;
  3475. bx = -bx;
  3476. by = -by;
  3477. bz = -bz;
  3478. bw = -bw;
  3479. } // calculate coefficients
  3480. if (1.0 - cosom > EPSILON) {
  3481. // standard case (slerp)
  3482. omega = Math.acos(cosom);
  3483. sinom = Math.sin(omega);
  3484. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  3485. scale1 = Math.sin(t * omega) / sinom;
  3486. } else {
  3487. // "from" and "to" quaternions are very close
  3488. // ... so we can do a linear interpolation
  3489. scale0 = 1.0 - t;
  3490. scale1 = t;
  3491. } // calculate final values
  3492. out[0] = scale0 * ax + scale1 * bx;
  3493. out[1] = scale0 * ay + scale1 * by;
  3494. out[2] = scale0 * az + scale1 * bz;
  3495. out[3] = scale0 * aw + scale1 * bw;
  3496. return out;
  3497. }
  3498. /**
  3499. * Calculates the inverse of a quat
  3500. *
  3501. * @param {quat} out the receiving quaternion
  3502. * @param {ReadonlyQuat} a quat to calculate inverse of
  3503. * @returns {quat} out
  3504. */
  3505. function invert$1(out, a) {
  3506. var a0 = a[0],
  3507. a1 = a[1],
  3508. a2 = a[2],
  3509. a3 = a[3];
  3510. var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
  3511. var invDot = dot ? 1.0 / dot : 0; // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
  3512. out[0] = -a0 * invDot;
  3513. out[1] = -a1 * invDot;
  3514. out[2] = -a2 * invDot;
  3515. out[3] = a3 * invDot;
  3516. return out;
  3517. }
  3518. /**
  3519. * Creates a quaternion from the given 3x3 rotation matrix.
  3520. *
  3521. * NOTE: The resultant quaternion is not normalized, so you should be sure
  3522. * to renormalize the quaternion yourself where necessary.
  3523. *
  3524. * @param {quat} out the receiving quaternion
  3525. * @param {ReadonlyMat3} m rotation matrix
  3526. * @returns {quat} out
  3527. * @function
  3528. */
  3529. function fromMat3(out, m) {
  3530. // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
  3531. // article "Quaternion Calculus and Fast Animation".
  3532. var fTrace = m[0] + m[4] + m[8];
  3533. var fRoot;
  3534. if (fTrace > 0.0) {
  3535. // |w| > 1/2, may as well choose w > 1/2
  3536. fRoot = Math.sqrt(fTrace + 1.0); // 2w
  3537. out[3] = 0.5 * fRoot;
  3538. fRoot = 0.5 / fRoot; // 1/(4w)
  3539. out[0] = (m[5] - m[7]) * fRoot;
  3540. out[1] = (m[6] - m[2]) * fRoot;
  3541. out[2] = (m[1] - m[3]) * fRoot;
  3542. } else {
  3543. // |w| <= 1/2
  3544. var i = 0;
  3545. if (m[4] > m[0]) i = 1;
  3546. if (m[8] > m[i * 3 + i]) i = 2;
  3547. var j = (i + 1) % 3;
  3548. var k = (i + 2) % 3;
  3549. fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
  3550. out[i] = 0.5 * fRoot;
  3551. fRoot = 0.5 / fRoot;
  3552. out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
  3553. out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
  3554. out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
  3555. }
  3556. return out;
  3557. }
  3558. /**
  3559. * Creates a quaternion from the given euler angle x, y, z.
  3560. *
  3561. * @param {quat} out the receiving quaternion
  3562. * @param {x} Angle to rotate around X axis in degrees.
  3563. * @param {y} Angle to rotate around Y axis in degrees.
  3564. * @param {z} Angle to rotate around Z axis in degrees.
  3565. * @returns {quat} out
  3566. * @function
  3567. */
  3568. function fromEuler(out, x, y, z) {
  3569. var halfToRad = 0.5 * Math.PI / 180.0;
  3570. x *= halfToRad;
  3571. y *= halfToRad;
  3572. z *= halfToRad;
  3573. var sx = Math.sin(x);
  3574. var cx = Math.cos(x);
  3575. var sy = Math.sin(y);
  3576. var cy = Math.cos(y);
  3577. var sz = Math.sin(z);
  3578. var cz = Math.cos(z);
  3579. out[0] = sx * cy * cz - cx * sy * sz;
  3580. out[1] = cx * sy * cz + sx * cy * sz;
  3581. out[2] = cx * cy * sz - sx * sy * cz;
  3582. out[3] = cx * cy * cz + sx * sy * sz;
  3583. return out;
  3584. }
  3585. /**
  3586. * Creates a new quat initialized with the given values
  3587. *
  3588. * @param {Number} x X component
  3589. * @param {Number} y Y component
  3590. * @param {Number} z Z component
  3591. * @param {Number} w W component
  3592. * @returns {quat} a new quaternion
  3593. * @function
  3594. */
  3595. var fromValues$4 = fromValues$3;
  3596. /**
  3597. * Copy the values from one quat to another
  3598. *
  3599. * @param {quat} out the receiving quaternion
  3600. * @param {ReadonlyQuat} a the source quaternion
  3601. * @returns {quat} out
  3602. * @function
  3603. */
  3604. var copy$3 = copy$2;
  3605. /**
  3606. * Alias for {@link quat.multiply}
  3607. * @function
  3608. */
  3609. var mul$1 = multiply$2;
  3610. /**
  3611. * Normalize a quat
  3612. *
  3613. * @param {quat} out the receiving quaternion
  3614. * @param {ReadonlyQuat} a quaternion to normalize
  3615. * @returns {quat} out
  3616. * @function
  3617. */
  3618. var normalize$2 = normalize$1;
  3619. /**
  3620. * Sets a quaternion to represent the shortest rotation from one
  3621. * vector to another.
  3622. *
  3623. * Both vectors are assumed to be unit length.
  3624. *
  3625. * @param {quat} out the receiving quaternion.
  3626. * @param {ReadonlyVec3} a the initial vector
  3627. * @param {ReadonlyVec3} b the destination vector
  3628. * @returns {quat} out
  3629. */
  3630. var rotationTo = function () {
  3631. var tmpvec3 = create$2();
  3632. var xUnitVec3 = fromValues$2(1, 0, 0);
  3633. var yUnitVec3 = fromValues$2(0, 1, 0);
  3634. return function (out, a, b) {
  3635. var dot$1 = dot(a, b);
  3636. if (dot$1 < -0.999999) {
  3637. cross(tmpvec3, xUnitVec3, a);
  3638. if (len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a);
  3639. normalize(tmpvec3, tmpvec3);
  3640. setAxisAngle(out, tmpvec3, Math.PI);
  3641. return out;
  3642. } else if (dot$1 > 0.999999) {
  3643. out[0] = 0;
  3644. out[1] = 0;
  3645. out[2] = 0;
  3646. out[3] = 1;
  3647. return out;
  3648. } else {
  3649. cross(tmpvec3, a, b);
  3650. out[0] = tmpvec3[0];
  3651. out[1] = tmpvec3[1];
  3652. out[2] = tmpvec3[2];
  3653. out[3] = 1 + dot$1;
  3654. return normalize$2(out, out);
  3655. }
  3656. };
  3657. }();
  3658. /**
  3659. * Performs a spherical linear interpolation with two control points
  3660. *
  3661. * @param {quat} out the receiving quaternion
  3662. * @param {ReadonlyQuat} a the first operand
  3663. * @param {ReadonlyQuat} b the second operand
  3664. * @param {ReadonlyQuat} c the third operand
  3665. * @param {ReadonlyQuat} d the fourth operand
  3666. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  3667. * @returns {quat} out
  3668. */
  3669. var sqlerp = function () {
  3670. var temp1 = create$4();
  3671. var temp2 = create$4();
  3672. return function (out, a, b, c, d, t) {
  3673. slerp(temp1, a, d, t);
  3674. slerp(temp2, b, c, t);
  3675. slerp(out, temp1, temp2, 2 * t * (1 - t));
  3676. return out;
  3677. };
  3678. }();
  3679. /**
  3680. * Sets the specified quaternion with values corresponding to the given
  3681. * axes. Each axis is a vec3 and is expected to be unit length and
  3682. * perpendicular to all other specified axes.
  3683. *
  3684. * @param {ReadonlyVec3} view the vector representing the viewing direction
  3685. * @param {ReadonlyVec3} right the vector representing the local "right" direction
  3686. * @param {ReadonlyVec3} up the vector representing the local "up" direction
  3687. * @returns {quat} out
  3688. */
  3689. var setAxes = function () {
  3690. var matr = create();
  3691. return function (out, view, right, up) {
  3692. matr[0] = right[0];
  3693. matr[3] = right[1];
  3694. matr[6] = right[2];
  3695. matr[1] = up[0];
  3696. matr[4] = up[1];
  3697. matr[7] = up[2];
  3698. matr[2] = -view[0];
  3699. matr[5] = -view[1];
  3700. matr[8] = -view[2];
  3701. return normalize$2(out, fromMat3(out, matr));
  3702. };
  3703. }();
  3704. /**
  3705. * 2 Dimensional Vector
  3706. * @module vec2
  3707. */
  3708. /**
  3709. * Creates a new, empty vec2
  3710. *
  3711. * @returns {vec2} a new 2D vector
  3712. */
  3713. function create$5() {
  3714. var out = new ARRAY_TYPE(2);
  3715. if (ARRAY_TYPE != Float32Array) {
  3716. out[0] = 0;
  3717. out[1] = 0;
  3718. }
  3719. return out;
  3720. }
  3721. /**
  3722. * Creates a new vec2 initialized with the given values
  3723. *
  3724. * @param {Number} x X component
  3725. * @param {Number} y Y component
  3726. * @returns {vec2} a new 2D vector
  3727. */
  3728. function fromValues$5(x, y) {
  3729. var out = new ARRAY_TYPE(2);
  3730. out[0] = x;
  3731. out[1] = y;
  3732. return out;
  3733. }
  3734. /**
  3735. * Copy the values from one vec2 to another
  3736. *
  3737. * @param {vec2} out the receiving vector
  3738. * @param {ReadonlyVec2} a the source vector
  3739. * @returns {vec2} out
  3740. */
  3741. function copy$4(out, a) {
  3742. out[0] = a[0];
  3743. out[1] = a[1];
  3744. return out;
  3745. }
  3746. /**
  3747. * Normalize a vec2
  3748. *
  3749. * @param {vec2} out the receiving vector
  3750. * @param {ReadonlyVec2} a vector to normalize
  3751. * @returns {vec2} out
  3752. */
  3753. function normalize$3(out, a) {
  3754. var x = a[0],
  3755. y = a[1];
  3756. var len = x * x + y * y;
  3757. if (len > 0) {
  3758. //TODO: evaluate use of glm_invsqrt here?
  3759. len = 1 / Math.sqrt(len);
  3760. }
  3761. out[0] = a[0] * len;
  3762. out[1] = a[1] * len;
  3763. return out;
  3764. }
  3765. /**
  3766. * Calculates the dot product of two vec2's
  3767. *
  3768. * @param {ReadonlyVec2} a the first operand
  3769. * @param {ReadonlyVec2} b the second operand
  3770. * @returns {Number} dot product of a and b
  3771. */
  3772. function dot$1(a, b) {
  3773. return a[0] * b[0] + a[1] * b[1];
  3774. }
  3775. /**
  3776. * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)
  3777. *
  3778. * @param {ReadonlyVec2} a The first vector.
  3779. * @param {ReadonlyVec2} b The second vector.
  3780. * @returns {Boolean} True if the vectors are equal, false otherwise.
  3781. */
  3782. function exactEquals$1(a, b) {
  3783. return a[0] === b[0] && a[1] === b[1];
  3784. }
  3785. /**
  3786. * Perform some operation over an array of vec2s.
  3787. *
  3788. * @param {Array} a the array of vectors to iterate over
  3789. * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
  3790. * @param {Number} offset Number of elements to skip at the beginning of the array
  3791. * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
  3792. * @param {Function} fn Function to call for each vector in the array
  3793. * @param {Object} [arg] additional argument to pass to fn
  3794. * @returns {Array} a
  3795. * @function
  3796. */
  3797. var forEach$2 = function () {
  3798. var vec = create$5();
  3799. return function (a, stride, offset, count, fn, arg) {
  3800. var i, l;
  3801. if (!stride) {
  3802. stride = 2;
  3803. }
  3804. if (!offset) {
  3805. offset = 0;
  3806. }
  3807. if (count) {
  3808. l = Math.min(count * stride + offset, a.length);
  3809. } else {
  3810. l = a.length;
  3811. }
  3812. for (i = offset; i < l; i += stride) {
  3813. vec[0] = a[i];
  3814. vec[1] = a[i + 1];
  3815. fn(vec, vec, arg);
  3816. a[i] = vec[0];
  3817. a[i + 1] = vec[1];
  3818. }
  3819. return a;
  3820. };
  3821. }();
  3822. function clonePath(path) {
  3823. return path.map(function (x) { return (Array.isArray(x) ? [].concat(x) : x); });
  3824. }
  3825. /******************************************************************************
  3826. Copyright (c) Microsoft Corporation.
  3827. Permission to use, copy, modify, and/or distribute this software for any
  3828. purpose with or without fee is hereby granted.
  3829. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  3830. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  3831. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  3832. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  3833. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  3834. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  3835. PERFORMANCE OF THIS SOFTWARE.
  3836. ***************************************************************************** */
  3837. var __assign = function() {
  3838. __assign = Object.assign || function __assign(t) {
  3839. for (var s, i = 1, n = arguments.length; i < n; i++) {
  3840. s = arguments[i];
  3841. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  3842. }
  3843. return t;
  3844. };
  3845. return __assign.apply(this, arguments);
  3846. };
  3847. var paramsParser = {
  3848. x1: 0,
  3849. y1: 0,
  3850. x2: 0,
  3851. y2: 0,
  3852. x: 0,
  3853. y: 0,
  3854. qx: null,
  3855. qy: null,
  3856. };
  3857. function fixArc(pathArray, allPathCommands, i) {
  3858. if (pathArray[i].length > 7) {
  3859. pathArray[i].shift();
  3860. var pi = pathArray[i];
  3861. // const ni = i + 1;
  3862. var ni = i;
  3863. while (pi.length) {
  3864. // if created multiple C:s, their original seg is saved
  3865. allPathCommands[i] = 'A';
  3866. // @ts-ignore
  3867. pathArray.splice((ni += 1), 0, ['C'].concat(pi.splice(0, 6)));
  3868. }
  3869. pathArray.splice(i, 1);
  3870. }
  3871. }
  3872. var paramsCount = {
  3873. a: 7,
  3874. c: 6,
  3875. h: 1,
  3876. l: 2,
  3877. m: 2,
  3878. r: 4,
  3879. q: 4,
  3880. s: 4,
  3881. t: 2,
  3882. v: 1,
  3883. z: 0,
  3884. };
  3885. /**
  3886. * Iterates an array to check if it's an actual `PathArray`.
  3887. */
  3888. function isPathArray(path) {
  3889. return (Array.isArray(path) &&
  3890. path.every(function (seg) {
  3891. var lk = seg[0].toLowerCase();
  3892. return paramsCount[lk] === seg.length - 1 && 'achlmqstvz'.includes(lk);
  3893. }));
  3894. }
  3895. /**
  3896. * Iterates an array to check if it's a `PathArray`
  3897. * with all absolute values.
  3898. */
  3899. function isAbsoluteArray(path) {
  3900. return (isPathArray(path) &&
  3901. // @ts-ignore -- `isPathArray` also checks if it's `Array`
  3902. path.every(function (_a) {
  3903. var x = _a[0];
  3904. return x === x.toUpperCase();
  3905. }));
  3906. }
  3907. /**
  3908. * Iterates an array to check if it's a `PathArray`
  3909. * with all segments are in non-shorthand notation
  3910. * with absolute values.
  3911. */
  3912. function isNormalizedArray(path) {
  3913. return isAbsoluteArray(path) && path.every(function (_a) {
  3914. var pc = _a[0];
  3915. return 'ACLMQZ'.includes(pc);
  3916. });
  3917. }
  3918. /**
  3919. * Breaks the parsing of a pathString once a segment is finalized.
  3920. */
  3921. function finalizeSegment(path) {
  3922. var pathCommand = path.pathValue[path.segmentStart];
  3923. var LK = pathCommand.toLowerCase();
  3924. var data = path.data;
  3925. while (data.length >= paramsCount[LK]) {
  3926. // overloaded `moveTo`
  3927. // https://github.com/rveciana/svg-path-properties/blob/master/src/parse.ts
  3928. if (LK === 'm' && data.length > 2) {
  3929. // @ts-ignore
  3930. path.segments.push([pathCommand].concat(data.splice(0, 2)));
  3931. LK = 'l';
  3932. pathCommand = pathCommand === 'm' ? 'l' : 'L';
  3933. }
  3934. else {
  3935. // @ts-ignore
  3936. path.segments.push([pathCommand].concat(data.splice(0, paramsCount[LK])));
  3937. }
  3938. if (!paramsCount[LK]) {
  3939. break;
  3940. }
  3941. }
  3942. }
  3943. /**
  3944. * Validates an A (arc-to) specific path command value.
  3945. * Usually a `large-arc-flag` or `sweep-flag`.
  3946. */
  3947. function scanFlag(path) {
  3948. var index = path.index, pathValue = path.pathValue;
  3949. var code = pathValue.charCodeAt(index);
  3950. if (code === 0x30 /* 0 */) {
  3951. path.param = 0;
  3952. path.index += 1;
  3953. return;
  3954. }
  3955. if (code === 0x31 /* 1 */) {
  3956. path.param = 1;
  3957. path.index += 1;
  3958. return;
  3959. }
  3960. path.err = "[path-util]: invalid Arc flag \"" + pathValue[index] + "\", expecting 0 or 1 at index " + index;
  3961. }
  3962. /**
  3963. * Checks if the character is or belongs to a number.
  3964. * [0-9]|+|-|.
  3965. */
  3966. function isDigitStart(code) {
  3967. return ((code >= 48 && code <= 57) /* 0..9 */ || code === 0x2b /* + */ || code === 0x2d /* - */ || code === 0x2e); /* . */
  3968. }
  3969. function isDigit(code) {
  3970. return code >= 48 && code <= 57; // 0..9
  3971. }
  3972. /**
  3973. * Validates every character of the path string,
  3974. * every path command, negative numbers or floating point numbers.
  3975. */
  3976. function scanParam(path) {
  3977. var max = path.max, pathValue = path.pathValue, start = path.index;
  3978. var index = start;
  3979. var zeroFirst = false;
  3980. var hasCeiling = false;
  3981. var hasDecimal = false;
  3982. var hasDot = false;
  3983. var ch;
  3984. if (index >= max) {
  3985. // path.err = 'SvgPath: missed param (at pos ' + index + ')';
  3986. path.err = "[path-util]: Invalid path value at index " + index + ", \"pathValue\" is missing param";
  3987. return;
  3988. }
  3989. ch = pathValue.charCodeAt(index);
  3990. if (ch === 0x2b /* + */ || ch === 0x2d /* - */) {
  3991. index += 1;
  3992. // ch = (index < max) ? pathValue.charCodeAt(index) : 0;
  3993. ch = pathValue.charCodeAt(index);
  3994. }
  3995. // This logic is shamelessly borrowed from Esprima
  3996. // https://github.com/ariya/esprimas
  3997. if (!isDigit(ch) && ch !== 0x2e /* . */) {
  3998. // path.err = 'SvgPath: param should start with 0..9 or `.` (at pos ' + index + ')';
  3999. path.err = "[path-util]: Invalid path value at index " + index + ", \"" + pathValue[index] + "\" is not a number";
  4000. return;
  4001. }
  4002. if (ch !== 0x2e /* . */) {
  4003. zeroFirst = ch === 0x30 /* 0 */;
  4004. index += 1;
  4005. ch = pathValue.charCodeAt(index);
  4006. if (zeroFirst && index < max) {
  4007. // decimal number starts with '0' such as '09' is illegal.
  4008. if (ch && isDigit(ch)) {
  4009. // path.err = 'SvgPath: numbers started with `0` such as `09`
  4010. // are illegal (at pos ' + start + ')';
  4011. path.err = "[path-util]: Invalid path value at index " + start + ", \"" + pathValue[start] + "\" illegal number";
  4012. return;
  4013. }
  4014. }
  4015. while (index < max && isDigit(pathValue.charCodeAt(index))) {
  4016. index += 1;
  4017. hasCeiling = true;
  4018. }
  4019. ch = pathValue.charCodeAt(index);
  4020. }
  4021. if (ch === 0x2e /* . */) {
  4022. hasDot = true;
  4023. index += 1;
  4024. while (isDigit(pathValue.charCodeAt(index))) {
  4025. index += 1;
  4026. hasDecimal = true;
  4027. }
  4028. ch = pathValue.charCodeAt(index);
  4029. }
  4030. if (ch === 0x65 /* e */ || ch === 0x45 /* E */) {
  4031. if (hasDot && !hasCeiling && !hasDecimal) {
  4032. path.err = "[path-util]: Invalid path value at index " + index + ", \"" + pathValue[index] + "\" invalid float exponent";
  4033. return;
  4034. }
  4035. index += 1;
  4036. ch = pathValue.charCodeAt(index);
  4037. if (ch === 0x2b /* + */ || ch === 0x2d /* - */) {
  4038. index += 1;
  4039. }
  4040. if (index < max && isDigit(pathValue.charCodeAt(index))) {
  4041. while (index < max && isDigit(pathValue.charCodeAt(index))) {
  4042. index += 1;
  4043. }
  4044. }
  4045. else {
  4046. path.err = "[path-util]: Invalid path value at index " + index + ", \"" + pathValue[index] + "\" invalid integer exponent";
  4047. return;
  4048. }
  4049. }
  4050. path.index = index;
  4051. path.param = +path.pathValue.slice(start, index);
  4052. }
  4053. /**
  4054. * Checks if the character is a space.
  4055. */
  4056. function isSpace(ch) {
  4057. var specialSpaces = [
  4058. 0x1680, 0x180e, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200a, 0x202f,
  4059. 0x205f, 0x3000, 0xfeff,
  4060. ];
  4061. /* istanbul ignore next */
  4062. return (ch === 0x0a ||
  4063. ch === 0x0d ||
  4064. ch === 0x2028 ||
  4065. ch === 0x2029 || // Line terminators
  4066. // White spaces
  4067. ch === 0x20 ||
  4068. ch === 0x09 ||
  4069. ch === 0x0b ||
  4070. ch === 0x0c ||
  4071. ch === 0xa0 ||
  4072. (ch >= 0x1680 && specialSpaces.includes(ch)));
  4073. }
  4074. /**
  4075. * Points the parser to the next character in the
  4076. * path string every time it encounters any kind of
  4077. * space character.
  4078. */
  4079. function skipSpaces(path) {
  4080. var pathValue = path.pathValue, max = path.max;
  4081. while (path.index < max && isSpace(pathValue.charCodeAt(path.index))) {
  4082. path.index += 1;
  4083. }
  4084. }
  4085. /**
  4086. * Checks if the character is a path command.
  4087. */
  4088. function isPathCommand(code) {
  4089. // eslint-disable-next-line no-bitwise -- Impossible to satisfy
  4090. switch (code | 0x20) {
  4091. case 0x6d /* m */:
  4092. case 0x7a /* z */:
  4093. case 0x6c /* l */:
  4094. case 0x68 /* h */:
  4095. case 0x76 /* v */:
  4096. case 0x63 /* c */:
  4097. case 0x73 /* s */:
  4098. case 0x71 /* q */:
  4099. case 0x74 /* t */:
  4100. case 0x61 /* a */:
  4101. // case 0x72/* r */:
  4102. return true;
  4103. default:
  4104. return false;
  4105. }
  4106. }
  4107. /**
  4108. * Checks if the character is an A (arc-to) path command.
  4109. */
  4110. function isArcCommand(code) {
  4111. return (code | 0x20) === 0x61;
  4112. }
  4113. /**
  4114. * Scans every character in the path string to determine
  4115. * where a segment starts and where it ends.
  4116. */
  4117. function scanSegment(path) {
  4118. var max = path.max, pathValue = path.pathValue, index = path.index;
  4119. var cmdCode = pathValue.charCodeAt(index);
  4120. var reqParams = paramsCount[pathValue[index].toLowerCase()];
  4121. path.segmentStart = index;
  4122. if (!isPathCommand(cmdCode)) {
  4123. path.err = "[path-util]: Invalid path value \"" + pathValue[index] + "\" is not a path command";
  4124. return;
  4125. }
  4126. path.index += 1;
  4127. skipSpaces(path);
  4128. path.data = [];
  4129. if (!reqParams) {
  4130. // Z
  4131. finalizeSegment(path);
  4132. return;
  4133. }
  4134. for (;;) {
  4135. for (var i = reqParams; i > 0; i -= 1) {
  4136. if (isArcCommand(cmdCode) && (i === 3 || i === 4))
  4137. scanFlag(path);
  4138. else
  4139. scanParam(path);
  4140. if (path.err.length) {
  4141. return;
  4142. }
  4143. path.data.push(path.param);
  4144. skipSpaces(path);
  4145. // after ',' param is mandatory
  4146. if (path.index < max && pathValue.charCodeAt(path.index) === 0x2c /* , */) {
  4147. path.index += 1;
  4148. skipSpaces(path);
  4149. }
  4150. }
  4151. if (path.index >= path.max) {
  4152. break;
  4153. }
  4154. // Stop on next segment
  4155. if (!isDigitStart(pathValue.charCodeAt(path.index))) {
  4156. break;
  4157. }
  4158. }
  4159. finalizeSegment(path);
  4160. }
  4161. /**
  4162. * The `PathParser` is used by the `parsePathString` static method
  4163. * to generate a `pathArray`.
  4164. */
  4165. var PathParser = /** @class */ (function () {
  4166. function PathParser(pathString) {
  4167. this.pathValue = pathString;
  4168. // @ts-ignore
  4169. this.segments = [];
  4170. this.max = pathString.length;
  4171. this.index = 0;
  4172. this.param = 0.0;
  4173. this.segmentStart = 0;
  4174. this.data = [];
  4175. this.err = '';
  4176. }
  4177. return PathParser;
  4178. }());
  4179. /**
  4180. * Parses a path string value and returns an array
  4181. * of segments we like to call `pathArray`.
  4182. */
  4183. function parsePathString(pathInput) {
  4184. if (isPathArray(pathInput)) {
  4185. return clonePath(pathInput);
  4186. }
  4187. var path = new PathParser(pathInput);
  4188. skipSpaces(path);
  4189. while (path.index < path.max && !path.err.length) {
  4190. scanSegment(path);
  4191. }
  4192. return path.err ? path.err : path.segments;
  4193. }
  4194. function path2Absolute(pathInput) {
  4195. if (isAbsoluteArray(pathInput)) {
  4196. return clonePath(pathInput);
  4197. }
  4198. var path = parsePathString(pathInput);
  4199. // if (!path || !path.length) {
  4200. // return [['M', 0, 0]];
  4201. // }
  4202. var x = 0;
  4203. var y = 0;
  4204. var mx = 0;
  4205. var my = 0;
  4206. // @ts-ignore
  4207. return path.map(function (segment) {
  4208. var values = segment.slice(1).map(Number);
  4209. var pathCommand = segment[0];
  4210. var absCommand = pathCommand.toUpperCase();
  4211. if (pathCommand === 'M') {
  4212. x = values[0], y = values[1];
  4213. mx = x;
  4214. my = y;
  4215. return ['M', x, y];
  4216. }
  4217. var absoluteSegment;
  4218. if (pathCommand !== absCommand) {
  4219. switch (absCommand) {
  4220. case 'A':
  4221. absoluteSegment = [
  4222. absCommand,
  4223. values[0],
  4224. values[1],
  4225. values[2],
  4226. values[3],
  4227. values[4],
  4228. values[5] + x,
  4229. values[6] + y,
  4230. ];
  4231. break;
  4232. case 'V':
  4233. absoluteSegment = [absCommand, values[0] + y];
  4234. break;
  4235. case 'H':
  4236. absoluteSegment = [absCommand, values[0] + x];
  4237. break;
  4238. default: {
  4239. // use brakets for `eslint: no-case-declaration`
  4240. // https://stackoverflow.com/a/50753272/803358
  4241. var absValues = values.map(function (n, j) { return n + (j % 2 ? y : x); });
  4242. // for n, l, c, s, q, t
  4243. // @ts-ignore
  4244. absoluteSegment = [absCommand].concat(absValues);
  4245. }
  4246. }
  4247. }
  4248. else {
  4249. // @ts-ignore
  4250. absoluteSegment = [absCommand].concat(values);
  4251. }
  4252. var segLength = absoluteSegment.length;
  4253. switch (absCommand) {
  4254. case 'Z':
  4255. x = mx;
  4256. y = my;
  4257. break;
  4258. case 'H':
  4259. x = absoluteSegment[1];
  4260. break;
  4261. case 'V':
  4262. y = absoluteSegment[1];
  4263. break;
  4264. default:
  4265. x = absoluteSegment[segLength - 2];
  4266. y = absoluteSegment[segLength - 1];
  4267. if (absCommand === 'M') {
  4268. mx = x;
  4269. my = y;
  4270. }
  4271. }
  4272. return absoluteSegment;
  4273. });
  4274. }
  4275. /**
  4276. * Normalizes a single segment of a `PathArray` object.
  4277. * eg. H/V -> L, T -> Q
  4278. */
  4279. function normalizeSegment(segment, params) {
  4280. var pathCommand = segment[0];
  4281. var px1 = params.x1, py1 = params.y1, px2 = params.x2, py2 = params.y2;
  4282. var values = segment.slice(1).map(Number);
  4283. var result = segment;
  4284. if (!'TQ'.includes(pathCommand)) {
  4285. // optional but good to be cautious
  4286. params.qx = null;
  4287. params.qy = null;
  4288. }
  4289. if (pathCommand === 'H') {
  4290. result = ['L', segment[1], py1];
  4291. }
  4292. else if (pathCommand === 'V') {
  4293. result = ['L', px1, segment[1]];
  4294. }
  4295. else if (pathCommand === 'S') {
  4296. var x1 = px1 * 2 - px2;
  4297. var y1 = py1 * 2 - py2;
  4298. params.x1 = x1;
  4299. params.y1 = y1;
  4300. result = ['C', x1, y1].concat(values);
  4301. }
  4302. else if (pathCommand === 'T') {
  4303. var qx = px1 * 2 - params.qx;
  4304. var qy = py1 * 2 - params.qy;
  4305. params.qx = qx;
  4306. params.qy = qy;
  4307. result = ['Q', qx, qy].concat(values);
  4308. }
  4309. else if (pathCommand === 'Q') {
  4310. var nqx = values[0], nqy = values[1];
  4311. params.qx = nqx;
  4312. params.qy = nqy;
  4313. }
  4314. return result;
  4315. }
  4316. /**
  4317. * @example
  4318. * const path = 'M0 0 H50';
  4319. * const normalizedPath = SVGPathCommander.normalizePath(path);
  4320. * // result => [['M', 0, 0], ['L', 50, 0]]
  4321. */
  4322. function normalizePath(pathInput) {
  4323. if (isNormalizedArray(pathInput)) {
  4324. return clonePath(pathInput);
  4325. }
  4326. var path = path2Absolute(pathInput);
  4327. var params = __assign({}, paramsParser);
  4328. for (var i = 0; i < path.length; i += 1) {
  4329. // Save current path command
  4330. path[i] = normalizeSegment(path[i], params);
  4331. var segment = path[i];
  4332. var seglen = segment.length;
  4333. params.x1 = +segment[seglen - 2];
  4334. params.y1 = +segment[seglen - 1];
  4335. params.x2 = +segment[seglen - 4] || params.x1;
  4336. params.y2 = +segment[seglen - 3] || params.y1;
  4337. }
  4338. return path;
  4339. }
  4340. /**
  4341. * Iterates an array to check if it's a `PathArray`
  4342. * with all C (cubic bezier) segments.
  4343. *
  4344. * @param {string | PathArray} path the `Array` to be checked
  4345. * @returns {boolean} iteration result
  4346. */
  4347. function isCurveArray(path) {
  4348. return isNormalizedArray(path) && path.every(function (_a) {
  4349. var pc = _a[0];
  4350. return 'MC'.includes(pc);
  4351. });
  4352. }
  4353. function rotateVector(x, y, rad) {
  4354. var X = x * Math.cos(rad) - y * Math.sin(rad);
  4355. var Y = x * Math.sin(rad) + y * Math.cos(rad);
  4356. return { x: X, y: Y };
  4357. }
  4358. /**
  4359. * Converts A (arc-to) segments to C (cubic-bezier-to).
  4360. *
  4361. * For more information of where this math came from visit:
  4362. * http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  4363. */
  4364. function arcToCubic(X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, recursive) {
  4365. var x1 = X1;
  4366. var y1 = Y1;
  4367. var rx = RX;
  4368. var ry = RY;
  4369. var x2 = X2;
  4370. var y2 = Y2;
  4371. // for more information of where this Math came from visit:
  4372. // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  4373. var d120 = (Math.PI * 120) / 180;
  4374. var rad = (Math.PI / 180) * (+angle || 0);
  4375. /** @type {number[]} */
  4376. var res = [];
  4377. var xy;
  4378. var f1;
  4379. var f2;
  4380. var cx;
  4381. var cy;
  4382. if (!recursive) {
  4383. xy = rotateVector(x1, y1, -rad);
  4384. x1 = xy.x;
  4385. y1 = xy.y;
  4386. xy = rotateVector(x2, y2, -rad);
  4387. x2 = xy.x;
  4388. y2 = xy.y;
  4389. var x = (x1 - x2) / 2;
  4390. var y = (y1 - y2) / 2;
  4391. var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
  4392. if (h > 1) {
  4393. h = Math.sqrt(h);
  4394. rx *= h;
  4395. ry *= h;
  4396. }
  4397. var rx2 = rx * rx;
  4398. var ry2 = ry * ry;
  4399. var k = (LAF === SF ? -1 : 1) *
  4400. Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)));
  4401. cx = (k * rx * y) / ry + (x1 + x2) / 2;
  4402. cy = (k * -ry * x) / rx + (y1 + y2) / 2;
  4403. // eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise
  4404. f1 = Math.asin(((((y1 - cy) / ry) * Math.pow(10, 9)) >> 0) / Math.pow(10, 9));
  4405. // eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise
  4406. f2 = Math.asin(((((y2 - cy) / ry) * Math.pow(10, 9)) >> 0) / Math.pow(10, 9));
  4407. f1 = x1 < cx ? Math.PI - f1 : f1;
  4408. f2 = x2 < cx ? Math.PI - f2 : f2;
  4409. if (f1 < 0)
  4410. f1 = Math.PI * 2 + f1;
  4411. if (f2 < 0)
  4412. f2 = Math.PI * 2 + f2;
  4413. if (SF && f1 > f2) {
  4414. f1 -= Math.PI * 2;
  4415. }
  4416. if (!SF && f2 > f1) {
  4417. f2 -= Math.PI * 2;
  4418. }
  4419. }
  4420. else {
  4421. f1 = recursive[0], f2 = recursive[1], cx = recursive[2], cy = recursive[3];
  4422. }
  4423. var df = f2 - f1;
  4424. if (Math.abs(df) > d120) {
  4425. var f2old = f2;
  4426. var x2old = x2;
  4427. var y2old = y2;
  4428. f2 = f1 + d120 * (SF && f2 > f1 ? 1 : -1);
  4429. x2 = cx + rx * Math.cos(f2);
  4430. y2 = cy + ry * Math.sin(f2);
  4431. res = arcToCubic(x2, y2, rx, ry, angle, 0, SF, x2old, y2old, [f2, f2old, cx, cy]);
  4432. }
  4433. df = f2 - f1;
  4434. var c1 = Math.cos(f1);
  4435. var s1 = Math.sin(f1);
  4436. var c2 = Math.cos(f2);
  4437. var s2 = Math.sin(f2);
  4438. var t = Math.tan(df / 4);
  4439. var hx = (4 / 3) * rx * t;
  4440. var hy = (4 / 3) * ry * t;
  4441. var m1 = [x1, y1];
  4442. var m2 = [x1 + hx * s1, y1 - hy * c1];
  4443. var m3 = [x2 + hx * s2, y2 - hy * c2];
  4444. var m4 = [x2, y2];
  4445. m2[0] = 2 * m1[0] - m2[0];
  4446. m2[1] = 2 * m1[1] - m2[1];
  4447. if (recursive) {
  4448. return m2.concat(m3, m4, res);
  4449. // return [...m2, ...m3, ...m4, ...res];
  4450. }
  4451. res = m2.concat(m3, m4, res);
  4452. // res = [...m2, ...m3, ...m4, ...res];
  4453. var newres = [];
  4454. for (var i = 0, ii = res.length; i < ii; i += 1) {
  4455. newres[i] = i % 2 ? rotateVector(res[i - 1], res[i], rad).y : rotateVector(res[i], res[i + 1], rad).x;
  4456. }
  4457. return newres;
  4458. }
  4459. // const TAU = Math.PI * 2;
  4460. // const mapToEllipse = (
  4461. // { x, y }: { x: number; y: number },
  4462. // rx: number,
  4463. // ry: number,
  4464. // cosphi: number,
  4465. // sinphi: number,
  4466. // centerx: number,
  4467. // centery: number,
  4468. // ) => {
  4469. // x *= rx;
  4470. // y *= ry;
  4471. // const xp = cosphi * x - sinphi * y;
  4472. // const yp = sinphi * x + cosphi * y;
  4473. // return {
  4474. // x: xp + centerx,
  4475. // y: yp + centery,
  4476. // };
  4477. // };
  4478. // const approxUnitArc = (ang1: number, ang2: number) => {
  4479. // // If 90 degree circular arc, use a constant
  4480. // // as derived from http://spencermortensen.com/articles/bezier-circle
  4481. // const a =
  4482. // ang2 === 1.5707963267948966
  4483. // ? 0.551915024494
  4484. // : ang2 === -1.5707963267948966
  4485. // ? -0.551915024494
  4486. // : (4 / 3) * Math.tan(ang2 / 4);
  4487. // const x1 = Math.cos(ang1);
  4488. // const y1 = Math.sin(ang1);
  4489. // const x2 = Math.cos(ang1 + ang2);
  4490. // const y2 = Math.sin(ang1 + ang2);
  4491. // return [
  4492. // {
  4493. // x: x1 - y1 * a,
  4494. // y: y1 + x1 * a,
  4495. // },
  4496. // {
  4497. // x: x2 + y2 * a,
  4498. // y: y2 - x2 * a,
  4499. // },
  4500. // {
  4501. // x: x2,
  4502. // y: y2,
  4503. // },
  4504. // ];
  4505. // };
  4506. // const vectorAngle = (ux: number, uy: number, vx: number, vy: number) => {
  4507. // const sign = ux * vy - uy * vx < 0 ? -1 : 1;
  4508. // let dot = ux * vx + uy * vy;
  4509. // if (dot > 1) {
  4510. // dot = 1;
  4511. // }
  4512. // if (dot < -1) {
  4513. // dot = -1;
  4514. // }
  4515. // return sign * Math.acos(dot);
  4516. // };
  4517. // const getArcCenter = (
  4518. // px: any,
  4519. // py: any,
  4520. // cx: any,
  4521. // cy: any,
  4522. // rx: number,
  4523. // ry: number,
  4524. // largeArcFlag: number,
  4525. // sweepFlag: number,
  4526. // sinphi: number,
  4527. // cosphi: number,
  4528. // pxp: number,
  4529. // pyp: number,
  4530. // ) => {
  4531. // const rxsq = Math.pow(rx, 2);
  4532. // const rysq = Math.pow(ry, 2);
  4533. // const pxpsq = Math.pow(pxp, 2);
  4534. // const pypsq = Math.pow(pyp, 2);
  4535. // let radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;
  4536. // if (radicant < 0) {
  4537. // radicant = 0;
  4538. // }
  4539. // radicant /= rxsq * pypsq + rysq * pxpsq;
  4540. // radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
  4541. // const centerxp = ((radicant * rx) / ry) * pyp;
  4542. // const centeryp = ((radicant * -ry) / rx) * pxp;
  4543. // const centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;
  4544. // const centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;
  4545. // const vx1 = (pxp - centerxp) / rx;
  4546. // const vy1 = (pyp - centeryp) / ry;
  4547. // const vx2 = (-pxp - centerxp) / rx;
  4548. // const vy2 = (-pyp - centeryp) / ry;
  4549. // const ang1 = vectorAngle(1, 0, vx1, vy1);
  4550. // let ang2 = vectorAngle(vx1, vy1, vx2, vy2);
  4551. // if (sweepFlag === 0 && ang2 > 0) {
  4552. // ang2 -= TAU;
  4553. // }
  4554. // if (sweepFlag === 1 && ang2 < 0) {
  4555. // ang2 += TAU;
  4556. // }
  4557. // return [centerx, centery, ang1, ang2];
  4558. // };
  4559. // const arcToBezier = ({ px, py, cx, cy, rx, ry, xAxisRotation = 0, largeArcFlag = 0, sweepFlag = 0 }) => {
  4560. // const curves = [];
  4561. // if (rx === 0 || ry === 0) {
  4562. // return [{ x1: 0, y1: 0, x2: 0, y2: 0, x: cx, y: cy }];
  4563. // }
  4564. // const sinphi = Math.sin((xAxisRotation * TAU) / 360);
  4565. // const cosphi = Math.cos((xAxisRotation * TAU) / 360);
  4566. // const pxp = (cosphi * (px - cx)) / 2 + (sinphi * (py - cy)) / 2;
  4567. // const pyp = (-sinphi * (px - cx)) / 2 + (cosphi * (py - cy)) / 2;
  4568. // if (pxp === 0 && pyp === 0) {
  4569. // return [{ x1: 0, y1: 0, x2: 0, y2: 0, x: cx, y: cy }];
  4570. // }
  4571. // rx = Math.abs(rx);
  4572. // ry = Math.abs(ry);
  4573. // const lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);
  4574. // if (lambda > 1) {
  4575. // rx *= Math.sqrt(lambda);
  4576. // ry *= Math.sqrt(lambda);
  4577. // }
  4578. // let [centerx, centery, ang1, ang2] = getArcCenter(
  4579. // px,
  4580. // py,
  4581. // cx,
  4582. // cy,
  4583. // rx,
  4584. // ry,
  4585. // largeArcFlag,
  4586. // sweepFlag,
  4587. // sinphi,
  4588. // cosphi,
  4589. // pxp,
  4590. // pyp,
  4591. // );
  4592. // // If 'ang2' == 90.0000000001, then `ratio` will evaluate to
  4593. // // 1.0000000001. This causes `segments` to be greater than one, which is an
  4594. // // unecessary split, and adds extra points to the bezier curve. To alleviate
  4595. // // this issue, we round to 1.0 when the ratio is close to 1.0.
  4596. // let ratio = Math.abs(ang2) / (TAU / 4);
  4597. // if (Math.abs(1.0 - ratio) < 0.0000001) {
  4598. // ratio = 1.0;
  4599. // }
  4600. // const segments = Math.max(Math.ceil(ratio), 1);
  4601. // ang2 /= segments;
  4602. // for (let i = 0; i < segments; i++) {
  4603. // curves.push(approxUnitArc(ang1, ang2));
  4604. // ang1 += ang2;
  4605. // }
  4606. // return curves.map((curve) => {
  4607. // const { x: x1, y: y1 } = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery);
  4608. // const { x: x2, y: y2 } = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery);
  4609. // const { x, y } = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery);
  4610. // return { x1, y1, x2, y2, x, y };
  4611. // });
  4612. // };
  4613. // export function arcToCubic(
  4614. // x1: number,
  4615. // y1: number,
  4616. // rx: number,
  4617. // ry: number,
  4618. // angle: number,
  4619. // LAF: number,
  4620. // SF: number,
  4621. // x2: number,
  4622. // y2: number,
  4623. // ) {
  4624. // const curves = arcToBezier({
  4625. // px: x1,
  4626. // py: y1,
  4627. // cx: x2,
  4628. // cy: y2,
  4629. // rx,
  4630. // ry,
  4631. // xAxisRotation: angle,
  4632. // largeArcFlag: LAF,
  4633. // sweepFlag: SF,
  4634. // });
  4635. // return curves.reduce((prev, cur) => {
  4636. // const { x1, y1, x2, y2, x, y } = cur;
  4637. // prev.push(x1, y1, x2, y2, x, y);
  4638. // return prev;
  4639. // }, [] as number[]);
  4640. // }
  4641. function quadToCubic(x1, y1, qx, qy, x2, y2) {
  4642. var r13 = 1 / 3;
  4643. var r23 = 2 / 3;
  4644. return [
  4645. r13 * x1 + r23 * qx,
  4646. r13 * y1 + r23 * qy,
  4647. r13 * x2 + r23 * qx,
  4648. r13 * y2 + r23 * qy,
  4649. x2,
  4650. y2, // x,y
  4651. ];
  4652. }
  4653. function midPoint(a, b, t) {
  4654. var ax = a[0];
  4655. var ay = a[1];
  4656. var bx = b[0];
  4657. var by = b[1];
  4658. return [ax + (bx - ax) * t, ay + (by - ay) * t];
  4659. }
  4660. function distanceSquareRoot(a, b) {
  4661. return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
  4662. }
  4663. /**
  4664. * Returns a {x,y} point at a given length, the total length and
  4665. * the minimum and maximum {x,y} coordinates of a line (L,V,H,Z) segment.
  4666. */
  4667. function segmentLineFactory(x1, y1, x2, y2, distance) {
  4668. var length = distanceSquareRoot([x1, y1], [x2, y2]);
  4669. var point = { x: 0, y: 0 };
  4670. if (typeof distance === 'number') {
  4671. if (distance <= 0) {
  4672. point = { x: x1, y: y1 };
  4673. }
  4674. else if (distance >= length) {
  4675. point = { x: x2, y: y2 };
  4676. }
  4677. else {
  4678. var _a = midPoint([x1, y1], [x2, y2], distance / length), x = _a[0], y = _a[1];
  4679. point = { x: x, y: y };
  4680. }
  4681. }
  4682. return {
  4683. length: length,
  4684. point: point,
  4685. min: {
  4686. x: Math.min(x1, x2),
  4687. y: Math.min(y1, y2),
  4688. },
  4689. max: {
  4690. x: Math.max(x1, x2),
  4691. y: Math.max(y1, y2),
  4692. },
  4693. };
  4694. }
  4695. function lineToCubic(x1, y1, x2, y2) {
  4696. var t = 0.5;
  4697. var p0 = [x1, y1];
  4698. var p1 = [x2, y2];
  4699. var p2 = midPoint(p0, p1, t);
  4700. var p3 = midPoint(p1, p2, t);
  4701. var p4 = midPoint(p2, p3, t);
  4702. var p5 = midPoint(p3, p4, t);
  4703. var p6 = midPoint(p4, p5, t);
  4704. // const seg1 = [...p0, ...p2, ...p4, ...p6, t];
  4705. // @ts-ignore
  4706. var cp1 = segmentLineFactory(p0[0], p0[1], p2[0], p2[1], p4[0]).point;
  4707. // const seg2 = [...p6, ...p5, ...p3, ...p1, 0];
  4708. // @ts-ignore
  4709. var cp2 = segmentLineFactory(p6[0], p6[1], p5[0], p5[1], p3[0]).point;
  4710. return [cp1.x, cp1.y, cp2.x, cp2.y, x2, y2];
  4711. }
  4712. function segmentToCubic(segment, params) {
  4713. var pathCommand = segment[0];
  4714. var values = segment.slice(1).map(Number);
  4715. var x = values[0], y = values[1];
  4716. var args;
  4717. var px1 = params.x1, py1 = params.y1, px = params.x, py = params.y;
  4718. if (!'TQ'.includes(pathCommand)) {
  4719. params.qx = null;
  4720. params.qy = null;
  4721. }
  4722. switch (pathCommand) {
  4723. case 'M':
  4724. params.x = x;
  4725. params.y = y;
  4726. return segment;
  4727. case 'A':
  4728. args = [px1, py1].concat(values);
  4729. // @ts-ignore
  4730. return ['C'].concat(arcToCubic(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]));
  4731. case 'Q':
  4732. params.qx = x;
  4733. params.qy = y;
  4734. args = [px1, py1].concat(values);
  4735. // @ts-ignore
  4736. return ['C'].concat(quadToCubic(args[0], args[1], args[2], args[3], args[4], args[5]));
  4737. case 'L':
  4738. // @ts-ignore
  4739. return ['C'].concat(lineToCubic(px1, py1, x, y));
  4740. case 'Z':
  4741. // prevent NaN from divide 0
  4742. if (px1 === px && py1 === py) {
  4743. return ['C', px1, py1, px, py, px, py];
  4744. }
  4745. // @ts-ignore
  4746. return ['C'].concat(lineToCubic(px1, py1, px, py));
  4747. }
  4748. return segment;
  4749. }
  4750. // import { fixPath } from '../process/fix-path';
  4751. function path2Curve(pathInput, needZCommandIndexes) {
  4752. if (needZCommandIndexes === void 0) { needZCommandIndexes = false; }
  4753. if (isCurveArray(pathInput)) {
  4754. var cloned = clonePath(pathInput);
  4755. if (needZCommandIndexes) {
  4756. return [cloned, []];
  4757. }
  4758. else {
  4759. return cloned;
  4760. }
  4761. }
  4762. // fixPath will remove 'Z' command
  4763. // const path = fixPath(normalizePath(pathInput));
  4764. var path = normalizePath(pathInput);
  4765. var params = __assign({}, paramsParser);
  4766. var allPathCommands = [];
  4767. var pathCommand = '';
  4768. var ii = path.length;
  4769. var segment;
  4770. var seglen;
  4771. var zCommandIndexes = [];
  4772. for (var i = 0; i < ii; i += 1) {
  4773. if (path[i])
  4774. pathCommand = path[i][0];
  4775. allPathCommands[i] = pathCommand;
  4776. var curveSegment = segmentToCubic(path[i], params);
  4777. path[i] = curveSegment;
  4778. fixArc(path, allPathCommands, i);
  4779. ii = path.length; // solves curveArrays ending in Z
  4780. // keep Z command account for lineJoin
  4781. // @see https://github.com/antvis/util/issues/68
  4782. if (pathCommand === 'Z') {
  4783. zCommandIndexes.push(i);
  4784. }
  4785. segment = path[i];
  4786. seglen = segment.length;
  4787. params.x1 = +segment[seglen - 2];
  4788. params.y1 = +segment[seglen - 1];
  4789. params.x2 = +segment[seglen - 4] || params.x1;
  4790. params.y2 = +segment[seglen - 3] || params.y1;
  4791. }
  4792. // validate
  4793. if (needZCommandIndexes) {
  4794. return [path, zCommandIndexes];
  4795. }
  4796. else {
  4797. return path;
  4798. }
  4799. }
  4800. // reverse CURVE based pathArray segments only
  4801. function reverseCurve(pathArray) {
  4802. var rotatedCurve = pathArray
  4803. .slice(1)
  4804. .map(function (x, i, curveOnly) {
  4805. // @ts-ignore
  4806. return !i ? pathArray[0].slice(1).concat(x.slice(1)) : curveOnly[i - 1].slice(-2).concat(x.slice(1));
  4807. })
  4808. // @ts-ignore
  4809. .map(function (x) { return x.map(function (y, i) { return x[x.length - i - 2 * (1 - (i % 2))]; }); })
  4810. .reverse();
  4811. return [['M'].concat(rotatedCurve[0].slice(0, 2))].concat(rotatedCurve.map(function (x) { return ['C'].concat(x.slice(2)); }));
  4812. }
  4813. function angleBetween(v0, v1) {
  4814. var v0x = v0.x, v0y = v0.y;
  4815. var v1x = v1.x, v1y = v1.y;
  4816. var p = v0x * v1x + v0y * v1y;
  4817. var n = Math.sqrt((Math.pow(v0x, 2) + Math.pow(v0y, 2)) * (Math.pow(v1x, 2) + Math.pow(v1y, 2)));
  4818. var sign = v0x * v1y - v0y * v1x < 0 ? -1 : 1;
  4819. var angle = sign * Math.acos(p / n);
  4820. return angle;
  4821. }
  4822. /**
  4823. * Returns a {x,y} point at a given length, the total length and
  4824. * the minimum and maximum {x,y} coordinates of a C (cubic-bezier) segment.
  4825. * @see https://github.com/MadLittleMods/svg-curve-lib/blob/master/src/js/svg-curve-lib.js
  4826. */
  4827. function getPointAtArcSegmentLength(x1, y1, RX, RY, angle, LAF, SF, x, y, t) {
  4828. var abs = Math.abs, sin = Math.sin, cos = Math.cos, sqrt = Math.sqrt, PI = Math.PI;
  4829. var rx = abs(RX);
  4830. var ry = abs(RY);
  4831. var xRot = ((angle % 360) + 360) % 360;
  4832. var xRotRad = xRot * (PI / 180);
  4833. if (x1 === x && y1 === y) {
  4834. return { x: x1, y: y1 };
  4835. }
  4836. if (rx === 0 || ry === 0) {
  4837. return segmentLineFactory(x1, y1, x, y, t).point;
  4838. }
  4839. var dx = (x1 - x) / 2;
  4840. var dy = (y1 - y) / 2;
  4841. var transformedPoint = {
  4842. x: cos(xRotRad) * dx + sin(xRotRad) * dy,
  4843. y: -sin(xRotRad) * dx + cos(xRotRad) * dy,
  4844. };
  4845. var radiiCheck = Math.pow(transformedPoint.x, 2) / Math.pow(rx, 2) + Math.pow(transformedPoint.y, 2) / Math.pow(ry, 2);
  4846. if (radiiCheck > 1) {
  4847. rx *= sqrt(radiiCheck);
  4848. ry *= sqrt(radiiCheck);
  4849. }
  4850. var cSquareNumerator = Math.pow(rx, 2) * Math.pow(ry, 2) - Math.pow(rx, 2) * Math.pow(transformedPoint.y, 2) - Math.pow(ry, 2) * Math.pow(transformedPoint.x, 2);
  4851. var cSquareRootDenom = Math.pow(rx, 2) * Math.pow(transformedPoint.y, 2) + Math.pow(ry, 2) * Math.pow(transformedPoint.x, 2);
  4852. var cRadicand = cSquareNumerator / cSquareRootDenom;
  4853. cRadicand = cRadicand < 0 ? 0 : cRadicand;
  4854. var cCoef = (LAF !== SF ? 1 : -1) * sqrt(cRadicand);
  4855. var transformedCenter = {
  4856. x: cCoef * ((rx * transformedPoint.y) / ry),
  4857. y: cCoef * (-(ry * transformedPoint.x) / rx),
  4858. };
  4859. var center = {
  4860. x: cos(xRotRad) * transformedCenter.x - sin(xRotRad) * transformedCenter.y + (x1 + x) / 2,
  4861. y: sin(xRotRad) * transformedCenter.x + cos(xRotRad) * transformedCenter.y + (y1 + y) / 2,
  4862. };
  4863. var startVector = {
  4864. x: (transformedPoint.x - transformedCenter.x) / rx,
  4865. y: (transformedPoint.y - transformedCenter.y) / ry,
  4866. };
  4867. var startAngle = angleBetween({ x: 1, y: 0 }, startVector);
  4868. var endVector = {
  4869. x: (-transformedPoint.x - transformedCenter.x) / rx,
  4870. y: (-transformedPoint.y - transformedCenter.y) / ry,
  4871. };
  4872. var sweepAngle = angleBetween(startVector, endVector);
  4873. if (!SF && sweepAngle > 0) {
  4874. sweepAngle -= 2 * PI;
  4875. }
  4876. else if (SF && sweepAngle < 0) {
  4877. sweepAngle += 2 * PI;
  4878. }
  4879. sweepAngle %= 2 * PI;
  4880. var alpha = startAngle + sweepAngle * t;
  4881. var ellipseComponentX = rx * cos(alpha);
  4882. var ellipseComponentY = ry * sin(alpha);
  4883. var point = {
  4884. x: cos(xRotRad) * ellipseComponentX - sin(xRotRad) * ellipseComponentY + center.x,
  4885. y: sin(xRotRad) * ellipseComponentX + cos(xRotRad) * ellipseComponentY + center.y,
  4886. };
  4887. // to be used later
  4888. // point.ellipticalArcStartAngle = startAngle;
  4889. // point.ellipticalArcEndAngle = startAngle + sweepAngle;
  4890. // point.ellipticalArcAngle = alpha;
  4891. // point.ellipticalArcCenter = center;
  4892. // point.resultantRx = rx;
  4893. // point.resultantRy = ry;
  4894. return point;
  4895. }
  4896. /**
  4897. * Returns a {x,y} point at a given length, the total length and
  4898. * the shape minimum and maximum {x,y} coordinates of an A (arc-to) segment.
  4899. *
  4900. * For better performance, it can skip calculate bbox or length in some scenario.
  4901. */
  4902. function segmentArcFactory(X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, distance, options) {
  4903. var _a;
  4904. var _b = options.bbox, bbox = _b === void 0 ? true : _b, _c = options.length, length = _c === void 0 ? true : _c, _d = options.sampleSize, sampleSize = _d === void 0 ? 30 : _d;
  4905. var distanceIsNumber = typeof distance === 'number';
  4906. var x = X1;
  4907. var y = Y1;
  4908. var LENGTH = 0;
  4909. var prev = [x, y, LENGTH];
  4910. var cur = [x, y];
  4911. var t = 0;
  4912. var POINT = { x: 0, y: 0 };
  4913. var POINTS = [{ x: x, y: y }];
  4914. if (distanceIsNumber && distance <= 0) {
  4915. POINT = { x: x, y: y };
  4916. }
  4917. // bad perf when size > 100
  4918. for (var j = 0; j <= sampleSize; j += 1) {
  4919. t = j / sampleSize;
  4920. (_a = getPointAtArcSegmentLength(X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, t), x = _a.x, y = _a.y);
  4921. if (bbox) {
  4922. POINTS.push({ x: x, y: y });
  4923. }
  4924. if (length) {
  4925. LENGTH += distanceSquareRoot(cur, [x, y]);
  4926. }
  4927. cur = [x, y];
  4928. if (distanceIsNumber && LENGTH >= distance && distance > prev[2]) {
  4929. var dv = (LENGTH - distance) / (LENGTH - prev[2]);
  4930. POINT = {
  4931. x: cur[0] * (1 - dv) + prev[0] * dv,
  4932. y: cur[1] * (1 - dv) + prev[1] * dv,
  4933. };
  4934. }
  4935. prev = [x, y, LENGTH];
  4936. }
  4937. if (distanceIsNumber && distance >= LENGTH) {
  4938. POINT = { x: X2, y: Y2 };
  4939. }
  4940. return {
  4941. length: LENGTH,
  4942. point: POINT,
  4943. min: {
  4944. x: Math.min.apply(null, POINTS.map(function (n) { return n.x; })),
  4945. y: Math.min.apply(null, POINTS.map(function (n) { return n.y; })),
  4946. },
  4947. max: {
  4948. x: Math.max.apply(null, POINTS.map(function (n) { return n.x; })),
  4949. y: Math.max.apply(null, POINTS.map(function (n) { return n.y; })),
  4950. },
  4951. };
  4952. }
  4953. /**
  4954. * Returns a {x,y} point at a given length, the total length and
  4955. * the minimum and maximum {x,y} coordinates of a C (cubic-bezier) segment.
  4956. */
  4957. function getPointAtCubicSegmentLength(x1, y1, c1x, c1y, c2x, c2y, x2, y2, t) {
  4958. var t1 = 1 - t;
  4959. return {
  4960. x: Math.pow(t1, 3) * x1 + 3 * Math.pow(t1, 2) * t * c1x + 3 * t1 * Math.pow(t, 2) * c2x + Math.pow(t, 3) * x2,
  4961. y: Math.pow(t1, 3) * y1 + 3 * Math.pow(t1, 2) * t * c1y + 3 * t1 * Math.pow(t, 2) * c2y + Math.pow(t, 3) * y2,
  4962. };
  4963. }
  4964. /**
  4965. * Returns the length of a C (cubic-bezier) segment
  4966. * or an {x,y} point at a given length.
  4967. */
  4968. function segmentCubicFactory(x1, y1, c1x, c1y, c2x, c2y, x2, y2, distance, options) {
  4969. var _a;
  4970. var _b = options.bbox, bbox = _b === void 0 ? true : _b, _c = options.length, length = _c === void 0 ? true : _c, _d = options.sampleSize, sampleSize = _d === void 0 ? 10 : _d;
  4971. var distanceIsNumber = typeof distance === 'number';
  4972. var x = x1;
  4973. var y = y1;
  4974. var LENGTH = 0;
  4975. var prev = [x, y, LENGTH];
  4976. var cur = [x, y];
  4977. var t = 0;
  4978. var POINT = { x: 0, y: 0 };
  4979. var POINTS = [{ x: x, y: y }];
  4980. if (distanceIsNumber && distance <= 0) {
  4981. POINT = { x: x, y: y };
  4982. }
  4983. // bad perf when size = 300
  4984. for (var j = 0; j <= sampleSize; j += 1) {
  4985. t = j / sampleSize;
  4986. (_a = getPointAtCubicSegmentLength(x1, y1, c1x, c1y, c2x, c2y, x2, y2, t), x = _a.x, y = _a.y);
  4987. if (bbox) {
  4988. POINTS.push({ x: x, y: y });
  4989. }
  4990. if (length) {
  4991. LENGTH += distanceSquareRoot(cur, [x, y]);
  4992. }
  4993. cur = [x, y];
  4994. if (distanceIsNumber && LENGTH >= distance && distance > prev[2]) {
  4995. var dv = (LENGTH - distance) / (LENGTH - prev[2]);
  4996. POINT = {
  4997. x: cur[0] * (1 - dv) + prev[0] * dv,
  4998. y: cur[1] * (1 - dv) + prev[1] * dv,
  4999. };
  5000. }
  5001. prev = [x, y, LENGTH];
  5002. }
  5003. if (distanceIsNumber && distance >= LENGTH) {
  5004. POINT = { x: x2, y: y2 };
  5005. }
  5006. return {
  5007. length: LENGTH,
  5008. point: POINT,
  5009. min: {
  5010. x: Math.min.apply(null, POINTS.map(function (n) { return n.x; })),
  5011. y: Math.min.apply(null, POINTS.map(function (n) { return n.y; })),
  5012. },
  5013. max: {
  5014. x: Math.max.apply(null, POINTS.map(function (n) { return n.x; })),
  5015. y: Math.max.apply(null, POINTS.map(function (n) { return n.y; })),
  5016. },
  5017. };
  5018. }
  5019. /**
  5020. * Returns the {x,y} coordinates of a point at a
  5021. * given length of a quadratic-bezier segment.
  5022. *
  5023. * @see https://github.com/substack/point-at-length
  5024. */
  5025. function getPointAtQuadSegmentLength(x1, y1, cx, cy, x2, y2, t) {
  5026. var t1 = 1 - t;
  5027. return {
  5028. x: Math.pow(t1, 2) * x1 + 2 * t1 * t * cx + Math.pow(t, 2) * x2,
  5029. y: Math.pow(t1, 2) * y1 + 2 * t1 * t * cy + Math.pow(t, 2) * y2,
  5030. };
  5031. }
  5032. /**
  5033. * Returns a {x,y} point at a given length, the total length and
  5034. * the minimum and maximum {x,y} coordinates of a Q (quadratic-bezier) segment.
  5035. */
  5036. function segmentQuadFactory(x1, y1, qx, qy, x2, y2, distance, options) {
  5037. var _a;
  5038. var _b = options.bbox, bbox = _b === void 0 ? true : _b, _c = options.length, length = _c === void 0 ? true : _c, _d = options.sampleSize, sampleSize = _d === void 0 ? 10 : _d;
  5039. var distanceIsNumber = typeof distance === 'number';
  5040. var x = x1;
  5041. var y = y1;
  5042. var LENGTH = 0;
  5043. var prev = [x, y, LENGTH];
  5044. var cur = [x, y];
  5045. var t = 0;
  5046. var POINT = { x: 0, y: 0 };
  5047. var POINTS = [{ x: x, y: y }];
  5048. if (distanceIsNumber && distance <= 0) {
  5049. POINT = { x: x, y: y };
  5050. }
  5051. for (var j = 0; j <= sampleSize; j += 1) {
  5052. t = j / sampleSize;
  5053. (_a = getPointAtQuadSegmentLength(x1, y1, qx, qy, x2, y2, t), x = _a.x, y = _a.y);
  5054. if (bbox) {
  5055. POINTS.push({ x: x, y: y });
  5056. }
  5057. if (length) {
  5058. LENGTH += distanceSquareRoot(cur, [x, y]);
  5059. }
  5060. cur = [x, y];
  5061. if (distanceIsNumber && LENGTH >= distance && distance > prev[2]) {
  5062. var dv = (LENGTH - distance) / (LENGTH - prev[2]);
  5063. POINT = {
  5064. x: cur[0] * (1 - dv) + prev[0] * dv,
  5065. y: cur[1] * (1 - dv) + prev[1] * dv,
  5066. };
  5067. }
  5068. prev = [x, y, LENGTH];
  5069. }
  5070. /* istanbul ignore else */
  5071. if (distanceIsNumber && distance >= LENGTH) {
  5072. POINT = { x: x2, y: y2 };
  5073. }
  5074. return {
  5075. length: LENGTH,
  5076. point: POINT,
  5077. min: {
  5078. x: Math.min.apply(null, POINTS.map(function (n) { return n.x; })),
  5079. y: Math.min.apply(null, POINTS.map(function (n) { return n.y; })),
  5080. },
  5081. max: {
  5082. x: Math.max.apply(null, POINTS.map(function (n) { return n.x; })),
  5083. y: Math.max.apply(null, POINTS.map(function (n) { return n.y; })),
  5084. },
  5085. };
  5086. }
  5087. /**
  5088. * Returns a {x,y} point at a given length
  5089. * of a shape, the shape total length and
  5090. * the shape minimum and maximum {x,y} coordinates.
  5091. */
  5092. function pathLengthFactory(pathInput, distance, options) {
  5093. var _a, _b, _c, _d, _e, _f;
  5094. var path = normalizePath(pathInput);
  5095. var distanceIsNumber = typeof distance === 'number';
  5096. var isM;
  5097. var data = [];
  5098. var pathCommand;
  5099. var x = 0;
  5100. var y = 0;
  5101. var mx = 0;
  5102. var my = 0;
  5103. var seg;
  5104. var MIN = [];
  5105. var MAX = [];
  5106. var length = 0;
  5107. var min = { x: 0, y: 0 };
  5108. var max = min;
  5109. var point = min;
  5110. var POINT = min;
  5111. var LENGTH = 0;
  5112. for (var i = 0, ll = path.length; i < ll; i += 1) {
  5113. seg = path[i];
  5114. pathCommand = seg[0];
  5115. isM = pathCommand === 'M';
  5116. data = !isM ? [x, y].concat(seg.slice(1)) : data;
  5117. // this segment is always ZERO
  5118. /* istanbul ignore else */
  5119. if (isM) {
  5120. // remember mx, my for Z
  5121. mx = seg[1], my = seg[2];
  5122. min = { x: mx, y: my };
  5123. max = min;
  5124. length = 0;
  5125. if (distanceIsNumber && distance < 0.001) {
  5126. POINT = min;
  5127. }
  5128. }
  5129. else if (pathCommand === 'L') {
  5130. (_a = segmentLineFactory(data[0], data[1], data[2], data[3], (distance || 0) - LENGTH), length = _a.length, min = _a.min, max = _a.max, point = _a.point);
  5131. }
  5132. else if (pathCommand === 'A') {
  5133. (_b = segmentArcFactory(data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], (distance || 0) - LENGTH, options || {}), length = _b.length, min = _b.min, max = _b.max, point = _b.point);
  5134. }
  5135. else if (pathCommand === 'C') {
  5136. (_c = segmentCubicFactory(data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], (distance || 0) - LENGTH, options || {}), length = _c.length, min = _c.min, max = _c.max, point = _c.point);
  5137. }
  5138. else if (pathCommand === 'Q') {
  5139. (_d = segmentQuadFactory(data[0], data[1], data[2], data[3], data[4], data[5], (distance || 0) - LENGTH, options || {}), length = _d.length, min = _d.min, max = _d.max, point = _d.point);
  5140. }
  5141. else if (pathCommand === 'Z') {
  5142. data = [x, y, mx, my];
  5143. (_e = segmentLineFactory(data[0], data[1], data[2], data[3], (distance || 0) - LENGTH), length = _e.length, min = _e.min, max = _e.max, point = _e.point);
  5144. }
  5145. if (distanceIsNumber && LENGTH < distance && LENGTH + length >= distance) {
  5146. POINT = point;
  5147. }
  5148. MAX.push(max);
  5149. MIN.push(min);
  5150. LENGTH += length;
  5151. _f = pathCommand !== 'Z' ? seg.slice(-2) : [mx, my], x = _f[0], y = _f[1];
  5152. }
  5153. // native `getPointAtLength` behavior when the given distance
  5154. // is higher than total length
  5155. if (distanceIsNumber && distance >= LENGTH) {
  5156. POINT = { x: x, y: y };
  5157. }
  5158. return {
  5159. length: LENGTH,
  5160. point: POINT,
  5161. min: {
  5162. x: Math.min.apply(null, MIN.map(function (n) { return n.x; })),
  5163. y: Math.min.apply(null, MIN.map(function (n) { return n.y; })),
  5164. },
  5165. max: {
  5166. x: Math.max.apply(null, MAX.map(function (n) { return n.x; })),
  5167. y: Math.max.apply(null, MAX.map(function (n) { return n.y; })),
  5168. },
  5169. };
  5170. }
  5171. /**
  5172. * Returns the shape total length, or the equivalent to `shape.getTotalLength()`.
  5173. *
  5174. * The `normalizePath` version is lighter, faster, more efficient and more accurate
  5175. * with paths that are not `curveArray`.
  5176. */
  5177. function getTotalLength(pathInput, options) {
  5178. return pathLengthFactory(pathInput, undefined, __assign(__assign({}, options), { bbox: false, length: true })).length;
  5179. }
  5180. function getRotations(a) {
  5181. var segCount = a.length;
  5182. var pointCount = segCount - 1;
  5183. return a.map(function (f, idx) {
  5184. return a.map(function (p, i) {
  5185. var oldSegIdx = idx + i;
  5186. var seg;
  5187. if (i === 0 || (a[oldSegIdx] && a[oldSegIdx][0] === 'M')) {
  5188. seg = a[oldSegIdx];
  5189. return ['M'].concat(seg.slice(-2));
  5190. }
  5191. if (oldSegIdx >= segCount)
  5192. oldSegIdx -= pointCount;
  5193. return a[oldSegIdx];
  5194. });
  5195. });
  5196. }
  5197. function getRotatedCurve(a, b) {
  5198. var segCount = a.length - 1;
  5199. var lineLengths = [];
  5200. var computedIndex = 0;
  5201. var sumLensSqrd = 0;
  5202. var rotations = getRotations(a);
  5203. rotations.forEach(function (r, i) {
  5204. a.slice(1).forEach(function (s, j) {
  5205. // @ts-ignore
  5206. sumLensSqrd += distanceSquareRoot(a[(i + j) % segCount].slice(-2), b[j % segCount].slice(-2));
  5207. });
  5208. lineLengths[i] = sumLensSqrd;
  5209. sumLensSqrd = 0;
  5210. });
  5211. computedIndex = lineLengths.indexOf(Math.min.apply(null, lineLengths));
  5212. return rotations[computedIndex];
  5213. }
  5214. /**
  5215. * Returns the area of a single cubic-bezier segment.
  5216. *
  5217. * http://objectmix.com/graphics/133553-area-closed-bezier-curve.html
  5218. */
  5219. function getCubicSegArea(x1, y1, c1x, c1y, c2x, c2y, x2, y2) {
  5220. // https://stackoverflow.com/a/15845996
  5221. return ((3 *
  5222. ((y2 - y1) * (c1x + c2x) -
  5223. (x2 - x1) * (c1y + c2y) +
  5224. c1y * (x1 - c2x) -
  5225. c1x * (y1 - c2y) +
  5226. y2 * (c2x + x1 / 3) -
  5227. x2 * (c2y + y1 / 3))) /
  5228. 20);
  5229. }
  5230. /**
  5231. * Returns the area of a shape.
  5232. * @author Jürg Lehni & Jonathan Puckey
  5233. *
  5234. * @see https://github.com/paperjs/paper.js/blob/develop/src/path/Path.js
  5235. */
  5236. function getPathArea(path) {
  5237. var x = 0;
  5238. var y = 0;
  5239. var len = 0;
  5240. return path2Curve(path)
  5241. .map(function (seg) {
  5242. var _a;
  5243. switch (seg[0]) {
  5244. case 'M':
  5245. x = seg[1], y = seg[2];
  5246. return 0;
  5247. default:
  5248. // @ts-ignore
  5249. var _b = seg.slice(1), c1x = _b[0], c1y = _b[1], c2x = _b[2], c2y = _b[3], x2 = _b[4], y2 = _b[5];
  5250. len = getCubicSegArea(x, y, c1x, c1y, c2x, c2y, x2, y2);
  5251. _a = seg.slice(-2), x = _a[0], y = _a[1];
  5252. return len;
  5253. }
  5254. })
  5255. .reduce(function (a, b) { return a + b; }, 0);
  5256. }
  5257. // export function getPathArea(pathArray: AbsoluteArray) {
  5258. // let x = 0;
  5259. // let y = 0;
  5260. // let mx = 0;
  5261. // let my = 0;
  5262. // let len = 0;
  5263. // return pathArray
  5264. // .map((seg) => {
  5265. // switch (seg[0]) {
  5266. // case 'M':
  5267. // case 'Z':
  5268. // mx = seg[0] === 'M' ? seg[1] : mx;
  5269. // my = seg[0] === 'M' ? seg[2] : my;
  5270. // x = mx;
  5271. // y = my;
  5272. // return 0;
  5273. // default:
  5274. // // @ts-ignore
  5275. // len = getCubicSegArea.apply(0, [x, y].concat(seg.slice(1)));
  5276. // [x, y] = seg.slice(-2) as [number, number];
  5277. // return len;
  5278. // }
  5279. // })
  5280. // .reduce((a, b) => a + b, 0);
  5281. // }
  5282. function getDrawDirection(pathArray) {
  5283. return getPathArea(pathArray) >= 0;
  5284. }
  5285. /**
  5286. * Returns [x,y] coordinates of a point at a given length of a shape.
  5287. */
  5288. function getPointAtLength(pathInput, distance, options) {
  5289. return pathLengthFactory(pathInput, distance, __assign(__assign({}, options), { bbox: false, length: true })).point;
  5290. }
  5291. function splitCubic(pts, t) {
  5292. if (t === void 0) { t = 0.5; }
  5293. var p0 = pts.slice(0, 2);
  5294. var p1 = pts.slice(2, 4);
  5295. var p2 = pts.slice(4, 6);
  5296. var p3 = pts.slice(6, 8);
  5297. var p4 = midPoint(p0, p1, t);
  5298. var p5 = midPoint(p1, p2, t);
  5299. var p6 = midPoint(p2, p3, t);
  5300. var p7 = midPoint(p4, p5, t);
  5301. var p8 = midPoint(p5, p6, t);
  5302. var p9 = midPoint(p7, p8, t);
  5303. return [
  5304. // @ts-ignore
  5305. ['C'].concat(p4, p7, p9),
  5306. // @ts-ignore
  5307. ['C'].concat(p8, p6, p3),
  5308. ];
  5309. }
  5310. function getCurveArray(segments) {
  5311. return segments.map(function (segment, i, pathArray) {
  5312. // @ts-ignore
  5313. var segmentData = i && pathArray[i - 1].slice(-2).concat(segment.slice(1));
  5314. // @ts-ignore
  5315. var curveLength = i
  5316. ? segmentCubicFactory(segmentData[0], segmentData[1], segmentData[2], segmentData[3], segmentData[4], segmentData[5], segmentData[6], segmentData[7], segmentData[8], { bbox: false }).length
  5317. : 0;
  5318. var subsegs;
  5319. if (i) {
  5320. // must be [segment,segment]
  5321. subsegs = curveLength ? splitCubic(segmentData) : [segment, segment];
  5322. }
  5323. else {
  5324. subsegs = [segment];
  5325. }
  5326. return {
  5327. s: segment,
  5328. ss: subsegs,
  5329. l: curveLength,
  5330. };
  5331. });
  5332. }
  5333. function equalizeSegments(path1, path2, TL) {
  5334. var c1 = getCurveArray(path1);
  5335. var c2 = getCurveArray(path2);
  5336. var L1 = c1.length;
  5337. var L2 = c2.length;
  5338. var l1 = c1.filter(function (x) { return x.l; }).length;
  5339. var l2 = c2.filter(function (x) { return x.l; }).length;
  5340. var m1 = c1.filter(function (x) { return x.l; }).reduce(function (a, _a) {
  5341. var l = _a.l;
  5342. return a + l;
  5343. }, 0) / l1 || 0;
  5344. var m2 = c2.filter(function (x) { return x.l; }).reduce(function (a, _a) {
  5345. var l = _a.l;
  5346. return a + l;
  5347. }, 0) / l2 || 0;
  5348. var tl = TL || Math.max(L1, L2);
  5349. var mm = [m1, m2];
  5350. var dif = [tl - L1, tl - L2];
  5351. var canSplit = 0;
  5352. var result = [c1, c2].map(function (x, i) {
  5353. // @ts-ignore
  5354. return x.l === tl
  5355. ? x.map(function (y) { return y.s; })
  5356. : x
  5357. .map(function (y, j) {
  5358. canSplit = j && dif[i] && y.l >= mm[i];
  5359. dif[i] -= canSplit ? 1 : 0;
  5360. return canSplit ? y.ss : [y.s];
  5361. })
  5362. .flat();
  5363. });
  5364. return result[0].length === result[1].length ? result : equalizeSegments(result[0], result[1], tl);
  5365. }
  5366. // isFinite,
  5367. var isNil = function (value) {
  5368. /**
  5369. * isNil(null) => true
  5370. * isNil() => true
  5371. */
  5372. return value === null || value === undefined;
  5373. };
  5374. var toString = {}.toString;
  5375. var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
  5376. var isArray = (function (value) {
  5377. return Array.isArray ? Array.isArray(value) : isType(value, 'Array');
  5378. });
  5379. var isObject = (function (value) {
  5380. /**
  5381. * isObject({}) => true
  5382. * isObject([1, 2, 3]) => true
  5383. * isObject(Function) => true
  5384. * isObject(null) => false
  5385. */
  5386. var type = typeof value;
  5387. return (value !== null && type === 'object') || type === 'function';
  5388. });
  5389. /**
  5390. * @param {Array} arr The array to iterate over.
  5391. * @return {*} Returns the maximum value.
  5392. * @example
  5393. *
  5394. * max([1, 2]);
  5395. * // => 2
  5396. *
  5397. * max([]);
  5398. * // => undefined
  5399. *
  5400. * const data = new Array(1250010).fill(1).map((d,idx) => idx);
  5401. *
  5402. * max(data);
  5403. * // => 1250010
  5404. * // Math.max(...data) will encounter "Maximum call stack size exceeded" error
  5405. */
  5406. var max = (function (arr) {
  5407. if (!isArray(arr)) {
  5408. return undefined;
  5409. }
  5410. return arr.reduce(function (prev, curr) {
  5411. return Math.max(prev, curr);
  5412. }, arr[0]);
  5413. });
  5414. /**
  5415. * @param {Array} arr The array to iterate over.
  5416. * @return {*} Returns the minimum value.
  5417. * @example
  5418. *
  5419. * min([1, 2]);
  5420. * // => 1
  5421. *
  5422. * min([]);
  5423. * // => undefined
  5424. *
  5425. * const data = new Array(1250010).fill(1).map((d,idx) => idx);
  5426. *
  5427. * min(data);
  5428. * // => 1250010
  5429. * // Math.min(...data) will encounter "Maximum call stack size exceeded" error
  5430. */
  5431. var min = (function (arr) {
  5432. if (!isArray(arr)) {
  5433. return undefined;
  5434. }
  5435. return arr.reduce(function (prev, curr) {
  5436. return Math.min(prev, curr);
  5437. }, arr[0]);
  5438. });
  5439. var isString = (function (str) {
  5440. return isType(str, 'String');
  5441. });
  5442. var clamp = function (a, min, max) {
  5443. if (a < min) {
  5444. return min;
  5445. }
  5446. else if (a > max) {
  5447. return max;
  5448. }
  5449. return a;
  5450. };
  5451. /**
  5452. * 判断是否数字
  5453. * @return {Boolean} 是否数字
  5454. */
  5455. var isNumber = function (value) {
  5456. return isType(value, 'Number');
  5457. };
  5458. var PRECISION = 0.00001; // numbers less than this is considered as 0
  5459. function isNumberEqual(a, b, precision) {
  5460. if (precision === void 0) { precision = PRECISION; }
  5461. return Math.abs(a - b) < precision;
  5462. }
  5463. var mod = function (n, m) {
  5464. return ((n % m) + m) % m;
  5465. };
  5466. /**
  5467. * 是否是布尔类型
  5468. *
  5469. * @param {Object} value 测试的值
  5470. * @return {Boolean}
  5471. */
  5472. var isBoolean = function (value) {
  5473. return isType(value, 'Boolean');
  5474. };
  5475. var isUndefined = function (value) {
  5476. return value === undefined;
  5477. };
  5478. // These units are iterated through, so be careful when adding or changing the
  5479. (function (UnitType) {
  5480. UnitType[UnitType["kUnknown"] = 0] = "kUnknown";
  5481. UnitType[UnitType["kNumber"] = 1] = "kNumber";
  5482. UnitType[UnitType["kPercentage"] = 2] = "kPercentage";
  5483. // Length units
  5484. UnitType[UnitType["kEms"] = 3] = "kEms";
  5485. // kExs,
  5486. UnitType[UnitType["kPixels"] = 4] = "kPixels";
  5487. // kCentimeters,
  5488. // kMillimeters,
  5489. // kInches,
  5490. // kPoints,
  5491. // kPicas,
  5492. // kQuarterMillimeters,
  5493. // https://drafts.csswg.org/css-values-4/#viewport-relative-lengths
  5494. //
  5495. // See also IsViewportPercentageLength.
  5496. // kViewportWidth,
  5497. // kViewportHeight,
  5498. // kViewportInlineSize,
  5499. // kViewportBlockSize,
  5500. // kViewportMin,
  5501. // kViewportMax,
  5502. // kSmallViewportWidth,
  5503. // kSmallViewportHeight,
  5504. // kSmallViewportInlineSize,
  5505. // kSmallViewportBlockSize,
  5506. // kSmallViewportMin,
  5507. // kSmallViewportMax,
  5508. // kLargeViewportWidth,
  5509. // kLargeViewportHeight,
  5510. // kLargeViewportInlineSize,
  5511. // kLargeViewportBlockSize,
  5512. // kLargeViewportMin,
  5513. // kLargeViewportMax,
  5514. // kDynamicViewportWidth,
  5515. // kDynamicViewportHeight,
  5516. // kDynamicViewportInlineSize,
  5517. // kDynamicViewportBlockSize,
  5518. // kDynamicViewportMin,
  5519. // kDynamicViewportMax,
  5520. // https://drafts.csswg.org/css-contain-3/#container-lengths
  5521. //
  5522. // See also IsContainerPercentageLength.
  5523. // kContainerWidth,
  5524. // kContainerHeight,
  5525. // kContainerInlineSize,
  5526. // kContainerBlockSize,
  5527. // kContainerMin,
  5528. // kContainerMax,
  5529. UnitType[UnitType["kRems"] = 5] = "kRems";
  5530. // kChs,
  5531. // kUserUnits, // The SVG term for unitless lengths
  5532. // Angle units
  5533. UnitType[UnitType["kDegrees"] = 6] = "kDegrees";
  5534. UnitType[UnitType["kRadians"] = 7] = "kRadians";
  5535. UnitType[UnitType["kGradians"] = 8] = "kGradians";
  5536. UnitType[UnitType["kTurns"] = 9] = "kTurns";
  5537. // Time units
  5538. UnitType[UnitType["kMilliseconds"] = 10] = "kMilliseconds";
  5539. UnitType[UnitType["kSeconds"] = 11] = "kSeconds";
  5540. // kHertz,
  5541. // kKilohertz,
  5542. // Resolution
  5543. // kDotsPerPixel,
  5544. // kDotsPerInch,
  5545. // kDotsPerCentimeter,
  5546. // Other units
  5547. // kFraction,
  5548. UnitType[UnitType["kInteger"] = 12] = "kInteger";
  5549. // This value is used to handle quirky margins in reflow roots (body, td,
  5550. // and th) like WinIE. The basic idea is that a stylesheet can use the value
  5551. // __qem (for quirky em) instead of em. When the quirky value is used, if
  5552. // you're in quirks mode, the margin will collapse away inside a table cell.
  5553. // This quirk is specified in the HTML spec but our impl is different.
  5554. // TODO: Remove this. crbug.com/443952
  5555. // kQuirkyEms,
  5556. })(exports.UnitType || (exports.UnitType = {}));
  5557. var UnitCategory;
  5558. (function (UnitCategory) {
  5559. UnitCategory[UnitCategory["kUNumber"] = 0] = "kUNumber";
  5560. UnitCategory[UnitCategory["kUPercent"] = 1] = "kUPercent";
  5561. UnitCategory[UnitCategory["kULength"] = 2] = "kULength";
  5562. UnitCategory[UnitCategory["kUAngle"] = 3] = "kUAngle";
  5563. UnitCategory[UnitCategory["kUTime"] = 4] = "kUTime";
  5564. // kUFrequency,
  5565. // kUResolution,
  5566. UnitCategory[UnitCategory["kUOther"] = 5] = "kUOther";
  5567. })(UnitCategory || (UnitCategory = {}));
  5568. var ValueRange;
  5569. (function (ValueRange) {
  5570. ValueRange[ValueRange["kAll"] = 0] = "kAll";
  5571. ValueRange[ValueRange["kNonNegative"] = 1] = "kNonNegative";
  5572. ValueRange[ValueRange["kInteger"] = 2] = "kInteger";
  5573. ValueRange[ValueRange["kNonNegativeInteger"] = 3] = "kNonNegativeInteger";
  5574. ValueRange[ValueRange["kPositiveInteger"] = 4] = "kPositiveInteger";
  5575. })(ValueRange || (ValueRange = {}));
  5576. var Nested;
  5577. (function (Nested) {
  5578. Nested[Nested["kYes"] = 0] = "kYes";
  5579. Nested[Nested["kNo"] = 1] = "kNo";
  5580. })(Nested || (Nested = {}));
  5581. var ParenLess;
  5582. (function (ParenLess) {
  5583. ParenLess[ParenLess["kYes"] = 0] = "kYes";
  5584. ParenLess[ParenLess["kNo"] = 1] = "kNo";
  5585. })(ParenLess || (ParenLess = {}));
  5586. // This file specifies the unit strings used in CSSPrimitiveValues.
  5587. var data = [{
  5588. name: 'em',
  5589. unit_type: exports.UnitType.kEms
  5590. },
  5591. // {
  5592. // name: 'ex',
  5593. // unit_type: UnitType.kExs,
  5594. // },
  5595. {
  5596. name: 'px',
  5597. unit_type: exports.UnitType.kPixels
  5598. },
  5599. // {
  5600. // name: "cm",
  5601. // unit_type: UnitType.kCentimeters,
  5602. // },
  5603. // {
  5604. // name: "mm",
  5605. // unit_type: UnitType.kMillimeters,
  5606. // },
  5607. // {
  5608. // name: "q",
  5609. // unit_type: UnitType.kQuarterMillimeters,
  5610. // },
  5611. // {
  5612. // name: "in",
  5613. // unit_type: UnitType.kInches,
  5614. // },
  5615. // {
  5616. // name: "pt",
  5617. // unit_type: UnitType.kPoints,
  5618. // },
  5619. // {
  5620. // name: "pc",
  5621. // unit_type: UnitType.kPicas,
  5622. // },
  5623. {
  5624. name: 'deg',
  5625. unit_type: exports.UnitType.kDegrees
  5626. }, {
  5627. name: 'rad',
  5628. unit_type: exports.UnitType.kRadians
  5629. }, {
  5630. name: 'grad',
  5631. unit_type: exports.UnitType.kGradians
  5632. }, {
  5633. name: 'ms',
  5634. unit_type: exports.UnitType.kMilliseconds
  5635. }, {
  5636. name: 's',
  5637. unit_type: exports.UnitType.kSeconds
  5638. },
  5639. // {
  5640. // name: "hz",
  5641. // unit_type: UnitType.kHertz,
  5642. // },
  5643. // {
  5644. // name: "khz",
  5645. // unit_type: UnitType.kKilohertz,
  5646. // },
  5647. // {
  5648. // name: "dpi",
  5649. // unit_type: "kDotsPerInch",
  5650. // },
  5651. // {
  5652. // name: "dpcm",
  5653. // unit_type: "kDotsPerCentimeter",
  5654. // },
  5655. // {
  5656. // name: "dppx",
  5657. // unit_type: "kDotsPerPixel",
  5658. // },
  5659. // {
  5660. // name: "x",
  5661. // unit_type: "kDotsPerPixel",
  5662. // },
  5663. // {
  5664. // name: "vw",
  5665. // unit_type: "kViewportWidth",
  5666. // },
  5667. // {
  5668. // name: "vh",
  5669. // unit_type: "kViewportHeight",
  5670. // },
  5671. // {
  5672. // name: "vi",
  5673. // unit_type: "kViewportInlineSize",
  5674. // },
  5675. // {
  5676. // name: "vb",
  5677. // unit_type: "kViewportBlockSize",
  5678. // },
  5679. // {
  5680. // name: "vmin",
  5681. // unit_type: UnitType.kViewportMin,
  5682. // },
  5683. // {
  5684. // name: "vmax",
  5685. // unit_type: UnitType.kViewportMax,
  5686. // },
  5687. // {
  5688. // name: "svw",
  5689. // unit_type: "kSmallViewportWidth",
  5690. // },
  5691. // {
  5692. // name: "svh",
  5693. // unit_type: "kSmallViewportHeight",
  5694. // },
  5695. // {
  5696. // name: "svi",
  5697. // unit_type: "kSmallViewportInlineSize",
  5698. // },
  5699. // {
  5700. // name: "svb",
  5701. // unit_type: "kSmallViewportBlockSize",
  5702. // },
  5703. // {
  5704. // name: "svmin",
  5705. // unit_type: "kSmallViewportMin",
  5706. // },
  5707. // {
  5708. // name: "svmax",
  5709. // unit_type: "kSmallViewportMax",
  5710. // },
  5711. // {
  5712. // name: "lvw",
  5713. // unit_type: "kLargeViewportWidth",
  5714. // },
  5715. // {
  5716. // name: "lvh",
  5717. // unit_type: "kLargeViewportHeight",
  5718. // },
  5719. // {
  5720. // name: "lvi",
  5721. // unit_type: "kLargeViewportInlineSize",
  5722. // },
  5723. // {
  5724. // name: "lvb",
  5725. // unit_type: "kLargeViewportBlockSize",
  5726. // },
  5727. // {
  5728. // name: "lvmin",
  5729. // unit_type: UnitType.kLargeViewportMin,
  5730. // },
  5731. // {
  5732. // name: "lvmax",
  5733. // unit_type: UnitType.kLargeViewportMax,
  5734. // },
  5735. // {
  5736. // name: "dvw",
  5737. // unit_type: UnitType.kDynamicViewportWidth,
  5738. // },
  5739. // {
  5740. // name: "dvh",
  5741. // unit_type: UnitType.kDynamicViewportHeight,
  5742. // },
  5743. // {
  5744. // name: "dvi",
  5745. // unit_type: UnitType.kDynamicViewportInlineSize,
  5746. // },
  5747. // {
  5748. // name: "dvb",
  5749. // unit_type: UnitType.kDynamicViewportBlockSize,
  5750. // },
  5751. // {
  5752. // name: "dvmin",
  5753. // unit_type: UnitType.kDynamicViewportMin,
  5754. // },
  5755. // {
  5756. // name: "dvmax",
  5757. // unit_type: UnitType.kDynamicViewportMax,
  5758. // },
  5759. // {
  5760. // name: "cqw",
  5761. // unit_type: UnitType.kContainerWidth,
  5762. // },
  5763. // {
  5764. // name: "cqh",
  5765. // unit_type: UnitType.kContainerHeight,
  5766. // },
  5767. // {
  5768. // name: "cqi",
  5769. // unit_type: UnitType.kContainerInlineSize,
  5770. // },
  5771. // {
  5772. // name: "cqb",
  5773. // unit_type: UnitType.kContainerBlockSize,
  5774. // },
  5775. // {
  5776. // name: "cqmin",
  5777. // unit_type: UnitType.kContainerMin,
  5778. // },
  5779. // {
  5780. // name: "cqmax",
  5781. // unit_type: UnitType.kContainerMax,
  5782. // },
  5783. {
  5784. name: 'rem',
  5785. unit_type: exports.UnitType.kRems
  5786. },
  5787. // {
  5788. // name: 'fr',
  5789. // unit_type: UnitType.kFraction,
  5790. // },
  5791. {
  5792. name: 'turn',
  5793. unit_type: exports.UnitType.kTurns
  5794. }
  5795. // {
  5796. // name: 'ch',
  5797. // unit_type: UnitType.kChs,
  5798. // },
  5799. // {
  5800. // name: '__qem',
  5801. // unit_type: UnitType.kQuirkyEms,
  5802. // },
  5803. ];
  5804. var CSSStyleValueType;
  5805. (function (CSSStyleValueType) {
  5806. CSSStyleValueType[CSSStyleValueType["kUnknownType"] = 0] = "kUnknownType";
  5807. CSSStyleValueType[CSSStyleValueType["kUnparsedType"] = 1] = "kUnparsedType";
  5808. CSSStyleValueType[CSSStyleValueType["kKeywordType"] = 2] = "kKeywordType";
  5809. // Start of CSSNumericValue subclasses
  5810. CSSStyleValueType[CSSStyleValueType["kUnitType"] = 3] = "kUnitType";
  5811. CSSStyleValueType[CSSStyleValueType["kSumType"] = 4] = "kSumType";
  5812. CSSStyleValueType[CSSStyleValueType["kProductType"] = 5] = "kProductType";
  5813. CSSStyleValueType[CSSStyleValueType["kNegateType"] = 6] = "kNegateType";
  5814. CSSStyleValueType[CSSStyleValueType["kInvertType"] = 7] = "kInvertType";
  5815. CSSStyleValueType[CSSStyleValueType["kMinType"] = 8] = "kMinType";
  5816. CSSStyleValueType[CSSStyleValueType["kMaxType"] = 9] = "kMaxType";
  5817. CSSStyleValueType[CSSStyleValueType["kClampType"] = 10] = "kClampType";
  5818. // End of CSSNumericValue subclasses
  5819. CSSStyleValueType[CSSStyleValueType["kTransformType"] = 11] = "kTransformType";
  5820. CSSStyleValueType[CSSStyleValueType["kPositionType"] = 12] = "kPositionType";
  5821. CSSStyleValueType[CSSStyleValueType["kURLImageType"] = 13] = "kURLImageType";
  5822. CSSStyleValueType[CSSStyleValueType["kColorType"] = 14] = "kColorType";
  5823. CSSStyleValueType[CSSStyleValueType["kUnsupportedColorType"] = 15] = "kUnsupportedColorType";
  5824. })(CSSStyleValueType || (CSSStyleValueType = {}));
  5825. // function parseCSSStyleValue(propertyName: string, value: string): CSSStyleValue[] {
  5826. // // const propertyId = cssPropertyID(propertyName);
  5827. // // if (propertyId === CSSPropertyID.kInvalid) {
  5828. // // return [];
  5829. // // }
  5830. // // const customPropertyName = propertyId === CSSPropertyID.kVariable ? propertyName : null;
  5831. // // return fromString(propertyId, customPropertyName, value);
  5832. // return [];
  5833. // }
  5834. var stringToUnitType = function stringToUnitType(name) {
  5835. return data.find(function (item) {
  5836. return item.name === name;
  5837. }).unit_type;
  5838. };
  5839. var unitFromName = function unitFromName(name) {
  5840. if (!name) {
  5841. return exports.UnitType.kUnknown;
  5842. }
  5843. if (name === 'number') {
  5844. return exports.UnitType.kNumber;
  5845. }
  5846. if (name === 'percent' || name === '%') {
  5847. return exports.UnitType.kPercentage;
  5848. }
  5849. return stringToUnitType(name);
  5850. };
  5851. var unitTypeToUnitCategory = function unitTypeToUnitCategory(type) {
  5852. switch (type) {
  5853. case exports.UnitType.kNumber:
  5854. case exports.UnitType.kInteger:
  5855. return UnitCategory.kUNumber;
  5856. case exports.UnitType.kPercentage:
  5857. return UnitCategory.kUPercent;
  5858. case exports.UnitType.kPixels:
  5859. // case UnitType.kCentimeters:
  5860. // case UnitType.kMillimeters:
  5861. // case UnitType.kQuarterMillimeters:
  5862. // case UnitType.kInches:
  5863. // case UnitType.kPoints:
  5864. // case UnitType.kPicas:
  5865. // case UnitType.kUserUnits:
  5866. return UnitCategory.kULength;
  5867. case exports.UnitType.kMilliseconds:
  5868. case exports.UnitType.kSeconds:
  5869. return UnitCategory.kUTime;
  5870. case exports.UnitType.kDegrees:
  5871. case exports.UnitType.kRadians:
  5872. case exports.UnitType.kGradians:
  5873. case exports.UnitType.kTurns:
  5874. return UnitCategory.kUAngle;
  5875. // case UnitType.kHertz:
  5876. // case UnitType.kKilohertz:
  5877. // return UnitCategory.kUFrequency;
  5878. // case UnitType.kDotsPerPixel:
  5879. // case UnitType.kDotsPerInch:
  5880. // case UnitType.kDotsPerCentimeter:
  5881. // return UnitCategory.kUResolution;
  5882. default:
  5883. return UnitCategory.kUOther;
  5884. }
  5885. };
  5886. var canonicalUnitTypeForCategory = function canonicalUnitTypeForCategory(category) {
  5887. // The canonical unit type is chosen according to the way
  5888. // CSSPropertyParser.ValidUnit() chooses the default unit in each category
  5889. // (based on unitflags).
  5890. switch (category) {
  5891. case UnitCategory.kUNumber:
  5892. return exports.UnitType.kNumber;
  5893. case UnitCategory.kULength:
  5894. return exports.UnitType.kPixels;
  5895. case UnitCategory.kUPercent:
  5896. return exports.UnitType.kPercentage;
  5897. // return UnitType.kUnknown; // Cannot convert between numbers and percent.
  5898. case UnitCategory.kUTime:
  5899. return exports.UnitType.kSeconds;
  5900. case UnitCategory.kUAngle:
  5901. return exports.UnitType.kDegrees;
  5902. // case UnitCategory.kUFrequency:
  5903. // return UnitType.kHertz;
  5904. // case UnitCategory.kUResolution:
  5905. // return UnitType.kDotsPerPixel;
  5906. default:
  5907. return exports.UnitType.kUnknown;
  5908. }
  5909. };
  5910. /**
  5911. * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/css_primitive_value.cc#353
  5912. */
  5913. var conversionToCanonicalUnitsScaleFactor = function conversionToCanonicalUnitsScaleFactor(unit_type) {
  5914. var factor = 1.0;
  5915. // FIXME: the switch can be replaced by an array of scale factors.
  5916. switch (unit_type) {
  5917. // These are "canonical" units in their respective categories.
  5918. case exports.UnitType.kPixels:
  5919. // case UnitType.kUserUnits:
  5920. case exports.UnitType.kDegrees:
  5921. case exports.UnitType.kSeconds:
  5922. // case UnitType.kHertz:
  5923. break;
  5924. case exports.UnitType.kMilliseconds:
  5925. factor = 0.001;
  5926. break;
  5927. // case UnitType.kCentimeters:
  5928. // // factor = kCssPixelsPerCentimeter;
  5929. // break;
  5930. // case UnitType.kDotsPerCentimeter:
  5931. // // factor = 1 / kCssPixelsPerCentimeter;
  5932. // break;
  5933. // case UnitType.kMillimeters:
  5934. // // factor = kCssPixelsPerMillimeter;
  5935. // break;
  5936. // case UnitType.kQuarterMillimeters:
  5937. // // factor = kCssPixelsPerQuarterMillimeter;
  5938. // break;
  5939. // case UnitType.kInches:
  5940. // // factor = kCssPixelsPerInch;
  5941. // break;
  5942. // case UnitType.kDotsPerInch:
  5943. // // factor = 1 / kCssPixelsPerInch;
  5944. // break;
  5945. // case UnitType.kPoints:
  5946. // // factor = kCssPixelsPerPoint;
  5947. // break;
  5948. // case UnitType.kPicas:
  5949. // // factor = kCssPixelsPerPica;
  5950. // break;
  5951. case exports.UnitType.kRadians:
  5952. factor = 180 / Math.PI;
  5953. break;
  5954. case exports.UnitType.kGradians:
  5955. factor = 0.9;
  5956. break;
  5957. case exports.UnitType.kTurns:
  5958. factor = 360;
  5959. break;
  5960. }
  5961. return factor;
  5962. };
  5963. var unitTypeToString = function unitTypeToString(type) {
  5964. switch (type) {
  5965. case exports.UnitType.kNumber:
  5966. case exports.UnitType.kInteger:
  5967. // case UnitType.kUserUnits:
  5968. return '';
  5969. case exports.UnitType.kPercentage:
  5970. return '%';
  5971. case exports.UnitType.kEms:
  5972. // case UnitType.kQuirkyEms:
  5973. return 'em';
  5974. // case UnitType.kExs:
  5975. // return 'ex';
  5976. case exports.UnitType.kRems:
  5977. return 'rem';
  5978. // case UnitType.kChs:
  5979. // return 'ch';
  5980. case exports.UnitType.kPixels:
  5981. return 'px';
  5982. // case UnitType.kCentimeters:
  5983. // return 'cm';
  5984. // case UnitType.kDotsPerPixel:
  5985. // return 'dppx';
  5986. // case UnitType.kDotsPerInch:
  5987. // return 'dpi';
  5988. // case UnitType.kDotsPerCentimeter:
  5989. // return 'dpcm';
  5990. // case UnitType.kMillimeters:
  5991. // return 'mm';
  5992. // case UnitType.kQuarterMillimeters:
  5993. // return 'q';
  5994. // case UnitType.kInches:
  5995. // return 'in';
  5996. // case UnitType.kPoints:
  5997. // return 'pt';
  5998. // case UnitType.kPicas:
  5999. // return 'pc';
  6000. case exports.UnitType.kDegrees:
  6001. return 'deg';
  6002. case exports.UnitType.kRadians:
  6003. return 'rad';
  6004. case exports.UnitType.kGradians:
  6005. return 'grad';
  6006. case exports.UnitType.kMilliseconds:
  6007. return 'ms';
  6008. case exports.UnitType.kSeconds:
  6009. return 's';
  6010. // case UnitType.kHertz:
  6011. // return 'hz';
  6012. // case UnitType.kKilohertz:
  6013. // return 'khz';
  6014. case exports.UnitType.kTurns:
  6015. return 'turn';
  6016. }
  6017. return '';
  6018. };
  6019. /**
  6020. * CSSStyleValue is the base class for all CSS values accessible from Typed OM.
  6021. * Values that are not yet supported as specific types are also returned as base CSSStyleValues.
  6022. *
  6023. * Spec @see https://drafts.css-houdini.org/css-typed-om/#stylevalue-objects
  6024. * Docs @see https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleValue
  6025. */
  6026. var CSSStyleValue = /*#__PURE__*/function () {
  6027. function CSSStyleValue() {}
  6028. // static parse(propertyName: string, value: string): CSSStyleValue {
  6029. // return parseCSSStyleValue(propertyName, value)[0];
  6030. // }
  6031. // static parseAll(propertyName: string, value: string): CSSStyleValue[] {
  6032. // return parseCSSStyleValue(propertyName, value);
  6033. // }
  6034. CSSStyleValue.isAngle = function isAngle(unit) {
  6035. return unit === exports.UnitType.kDegrees || unit === exports.UnitType.kRadians || unit === exports.UnitType.kGradians || unit === exports.UnitType.kTurns;
  6036. }
  6037. // static isViewportPercentageLength(type: UnitType) {
  6038. // return type >= UnitType.kViewportWidth && type <= UnitType.kDynamicViewportMax;
  6039. // }
  6040. // static isContainerPercentageLength(type: UnitType) {
  6041. // return type >= UnitType.kContainerWidth && type <= UnitType.kContainerMax;
  6042. // }
  6043. ;
  6044. CSSStyleValue.isLength = function isLength(type) {
  6045. // return (type >= UnitType.kEms && type <= UnitType.kUserUnits) || type == UnitType.kQuirkyEms;
  6046. return type >= exports.UnitType.kEms && type < exports.UnitType.kDegrees;
  6047. };
  6048. CSSStyleValue.isRelativeUnit = function isRelativeUnit(type) {
  6049. return type === exports.UnitType.kPercentage || type === exports.UnitType.kEms ||
  6050. // type === UnitType.kExs ||
  6051. type === exports.UnitType.kRems
  6052. // type === UnitType.kChs ||
  6053. // this.isViewportPercentageLength(type) ||
  6054. // this.isContainerPercentageLength(type)
  6055. ;
  6056. };
  6057. CSSStyleValue.isTime = function isTime(unit) {
  6058. return unit === exports.UnitType.kSeconds || unit === exports.UnitType.kMilliseconds;
  6059. }
  6060. // protected abstract toCSSValue(): CSSValue;
  6061. ;
  6062. var _proto = CSSStyleValue.prototype;
  6063. _proto.toString = function toString() {
  6064. return this.buildCSSText(Nested.kNo, ParenLess.kNo, '');
  6065. };
  6066. _proto.isNumericValue = function isNumericValue() {
  6067. return this.getType() >= CSSStyleValueType.kUnitType && this.getType() <= CSSStyleValueType.kClampType;
  6068. };
  6069. return CSSStyleValue;
  6070. }();
  6071. /**
  6072. * CSSColorValue is the base class used for the various CSS color interfaces.
  6073. *
  6074. * @see https://drafts.css-houdini.org/css-typed-om-1/#colorvalue-objects
  6075. */
  6076. var CSSColorValue = /*#__PURE__*/function (_CSSStyleValue) {
  6077. _inheritsLoose(CSSColorValue, _CSSStyleValue);
  6078. function CSSColorValue(colorSpace) {
  6079. var _this;
  6080. _this = _CSSStyleValue.call(this) || this;
  6081. _this.colorSpace = void 0;
  6082. _this.colorSpace = colorSpace;
  6083. return _this;
  6084. }
  6085. var _proto = CSSColorValue.prototype;
  6086. _proto.getType = function getType() {
  6087. return CSSStyleValueType.kColorType;
  6088. }
  6089. // buildCSSText(n: Nested, p: ParenLess, result: string): string {
  6090. // let text = '';
  6091. // if (this.colorSpace === 'rgb') {
  6092. // text = `rgba(${this.channels.join(',')},${this.alpha})`;
  6093. // }
  6094. // return (result += text);
  6095. // }
  6096. /**
  6097. * @see https://drafts.css-houdini.org/css-typed-om-1/#dom-csscolorvalue-to
  6098. */;
  6099. _proto.to = function to(colorSpace) {
  6100. return this;
  6101. };
  6102. return CSSColorValue;
  6103. }(CSSStyleValue);
  6104. (function (GradientType) {
  6105. GradientType[GradientType["Constant"] = 0] = "Constant";
  6106. GradientType[GradientType["LinearGradient"] = 1] = "LinearGradient";
  6107. GradientType[GradientType["RadialGradient"] = 2] = "RadialGradient";
  6108. })(exports.GradientType || (exports.GradientType = {}));
  6109. var CSSGradientValue = /*#__PURE__*/function (_CSSStyleValue) {
  6110. _inheritsLoose(CSSGradientValue, _CSSStyleValue);
  6111. function CSSGradientValue(type, value) {
  6112. var _this;
  6113. _this = _CSSStyleValue.call(this) || this;
  6114. _this.type = void 0;
  6115. _this.value = void 0;
  6116. _this.type = type;
  6117. _this.value = value;
  6118. return _this;
  6119. }
  6120. var _proto = CSSGradientValue.prototype;
  6121. _proto.clone = function clone() {
  6122. return new CSSGradientValue(this.type, this.value);
  6123. };
  6124. _proto.buildCSSText = function buildCSSText(n, p, result) {
  6125. return result;
  6126. };
  6127. _proto.getType = function getType() {
  6128. return CSSStyleValueType.kColorType;
  6129. };
  6130. return CSSGradientValue;
  6131. }(CSSStyleValue);
  6132. /**
  6133. * CSSKeywordValue represents CSS Values that are specified as keywords
  6134. * eg. 'initial'
  6135. * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSKeywordValue
  6136. * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_keyword_value.idl
  6137. */
  6138. var CSSKeywordValue = /*#__PURE__*/function (_CSSStyleValue) {
  6139. _inheritsLoose(CSSKeywordValue, _CSSStyleValue);
  6140. function CSSKeywordValue(value) {
  6141. var _this;
  6142. _this = _CSSStyleValue.call(this) || this;
  6143. _this.value = void 0;
  6144. _this.value = value;
  6145. return _this;
  6146. }
  6147. var _proto = CSSKeywordValue.prototype;
  6148. _proto.clone = function clone() {
  6149. return new CSSKeywordValue(this.value);
  6150. };
  6151. _proto.getType = function getType() {
  6152. return CSSStyleValueType.kKeywordType;
  6153. };
  6154. _proto.buildCSSText = function buildCSSText(n, p, result) {
  6155. return result + this.value;
  6156. };
  6157. return CSSKeywordValue;
  6158. }(CSSStyleValue);
  6159. function memoize(func, resolver) {
  6160. if (typeof func !== 'function' || resolver != null && typeof resolver !== 'function') {
  6161. throw new TypeError('Expected a function');
  6162. }
  6163. var memoized = function memoized() {
  6164. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  6165. args[_key] = arguments[_key];
  6166. }
  6167. var key = resolver ? resolver.apply(this, args) : args[0];
  6168. var cache = memoized.cache;
  6169. if (cache.has(key)) {
  6170. return cache.get(key);
  6171. }
  6172. var result = func.apply(this, args);
  6173. memoized.cache = cache.set(key, result) || cache;
  6174. return result;
  6175. };
  6176. memoized.cache = new (memoize.Cache || Map)();
  6177. return memoized;
  6178. }
  6179. memoize.Cache = Map;
  6180. var camelCase = memoize(function (str) {
  6181. if (str === void 0) {
  6182. str = '';
  6183. }
  6184. return str.replace(/-([a-z])/g, function (g) {
  6185. return g[1].toUpperCase();
  6186. });
  6187. });
  6188. var kebabize = function kebabize(str) {
  6189. return str.split('').map(function (letter, idx) {
  6190. return letter.toUpperCase() === letter ? "" + (idx !== 0 ? '-' : '') + letter.toLowerCase() : letter;
  6191. }).join('');
  6192. };
  6193. function DCHECK(bool) {
  6194. if (!bool) {
  6195. throw new Error();
  6196. }
  6197. }
  6198. function isFunction(func) {
  6199. return typeof func === 'function';
  6200. }
  6201. function isSymbol(value) {
  6202. // @see https://github.com/lodash/lodash/blob/master/isSymbol.js
  6203. return typeof value === 'symbol';
  6204. }
  6205. var definedProps = function definedProps(obj) {
  6206. return Object.fromEntries(Object.entries(obj).filter(function (_ref) {
  6207. var v = _ref[1];
  6208. return v !== undefined;
  6209. }));
  6210. };
  6211. var FORMAT_ATTR_MAP = {
  6212. d: {
  6213. alias: 'path'
  6214. },
  6215. strokeDasharray: {
  6216. alias: 'lineDash'
  6217. },
  6218. strokeWidth: {
  6219. alias: 'lineWidth'
  6220. },
  6221. textAnchor: {
  6222. alias: 'textAlign'
  6223. },
  6224. src: {
  6225. alias: 'img'
  6226. }
  6227. };
  6228. var formatAttributeName = memoize(function (name) {
  6229. var attributeName = camelCase(name);
  6230. var map = FORMAT_ATTR_MAP[attributeName];
  6231. attributeName = (map === null || map === void 0 ? void 0 : map.alias) || attributeName;
  6232. return attributeName;
  6233. });
  6234. // type CSSNumericBaseType =
  6235. // | 'length'
  6236. // | 'angle'
  6237. // | 'time'
  6238. // | 'frequency'
  6239. // | 'resolution'
  6240. // | 'flex'
  6241. // | 'percent';
  6242. // https://drafts.css-houdini.org/css-typed-om/#dictdef-cssnumerictype
  6243. // interface CSSNumericType {
  6244. // length: number;
  6245. // angle: number;
  6246. // time: number;
  6247. // frequency: number;
  6248. // resolution: number;
  6249. // flex: number;
  6250. // percent: number;
  6251. // percentHint: CSSNumericBaseType;
  6252. // }
  6253. var formatInfinityOrNaN = function formatInfinityOrNaN(number, suffix) {
  6254. if (suffix === void 0) {
  6255. suffix = '';
  6256. }
  6257. var result = '';
  6258. if (!Number.isFinite(number)) {
  6259. if (number > 0) result = 'infinity';else result = '-infinity';
  6260. } else {
  6261. DCHECK(Number.isNaN(number));
  6262. result = 'NaN';
  6263. }
  6264. return result += suffix;
  6265. };
  6266. var toCanonicalUnit = function toCanonicalUnit(unit) {
  6267. return canonicalUnitTypeForCategory(unitTypeToUnitCategory(unit));
  6268. };
  6269. /**
  6270. * CSSNumericValue is the base class for numeric and length typed CSS Values.
  6271. * @see https://drafts.css-houdini.org/css-typed-om/#numeric-objects
  6272. * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue
  6273. * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.idl
  6274. */
  6275. /**
  6276. * Represents numeric values that can be expressed as a single number plus a
  6277. * unit (or a naked number or percentage).
  6278. * @see https://drafts.css-houdini.org/css-typed-om/#cssunitvalue
  6279. */
  6280. var CSSUnitValue = /*#__PURE__*/function (_CSSStyleValue) {
  6281. _inheritsLoose(CSSUnitValue, _CSSStyleValue);
  6282. function CSSUnitValue(value, unitOrName) {
  6283. var _this;
  6284. if (unitOrName === void 0) {
  6285. unitOrName = exports.UnitType.kNumber;
  6286. }
  6287. _this = _CSSStyleValue.call(this) || this;
  6288. _this.unit = void 0;
  6289. _this.value = void 0;
  6290. var unit;
  6291. if (typeof unitOrName === 'string') {
  6292. unit = unitFromName(unitOrName);
  6293. } else {
  6294. unit = unitOrName;
  6295. }
  6296. _this.unit = unit;
  6297. _this.value = value;
  6298. return _this;
  6299. }
  6300. var _proto = CSSUnitValue.prototype;
  6301. _proto.clone = function clone() {
  6302. return new CSSUnitValue(this.value, this.unit);
  6303. };
  6304. _proto.equals = function equals(other) {
  6305. var other_unit_value = other;
  6306. return this.value === other_unit_value.value && this.unit === other_unit_value.unit;
  6307. };
  6308. _proto.getType = function getType() {
  6309. return CSSStyleValueType.kUnitType;
  6310. };
  6311. _proto.convertTo = function convertTo(target_unit) {
  6312. if (this.unit === target_unit) {
  6313. return new CSSUnitValue(this.value, this.unit);
  6314. }
  6315. // Instead of defining the scale factors for every unit to every other unit,
  6316. // we simply convert to the canonical unit and back since we already have
  6317. // the scale factors for canonical units.
  6318. var canonical_unit = toCanonicalUnit(this.unit);
  6319. if (canonical_unit !== toCanonicalUnit(target_unit) || canonical_unit === exports.UnitType.kUnknown) {
  6320. return null;
  6321. }
  6322. var scale_factor = conversionToCanonicalUnitsScaleFactor(this.unit) / conversionToCanonicalUnitsScaleFactor(target_unit);
  6323. return new CSSUnitValue(this.value * scale_factor, target_unit);
  6324. };
  6325. _proto.buildCSSText = function buildCSSText(n, p, result) {
  6326. var text;
  6327. switch (this.unit) {
  6328. case exports.UnitType.kUnknown:
  6329. // FIXME
  6330. break;
  6331. case exports.UnitType.kInteger:
  6332. text = Number(this.value).toFixed(0);
  6333. break;
  6334. case exports.UnitType.kNumber:
  6335. case exports.UnitType.kPercentage:
  6336. case exports.UnitType.kEms:
  6337. // case UnitType.kQuirkyEms:
  6338. // case UnitType.kExs:
  6339. case exports.UnitType.kRems:
  6340. // case UnitType.kChs:
  6341. case exports.UnitType.kPixels:
  6342. // case UnitType.kCentimeters:
  6343. // case UnitType.kDotsPerPixel:
  6344. // case UnitType.kDotsPerInch:
  6345. // case UnitType.kDotsPerCentimeter:
  6346. // case UnitType.kMillimeters:
  6347. // case UnitType.kQuarterMillimeters:
  6348. // case UnitType.kInches:
  6349. // case UnitType.kPoints:
  6350. // case UnitType.kPicas:
  6351. // case UnitType.kUserUnits:
  6352. case exports.UnitType.kDegrees:
  6353. case exports.UnitType.kRadians:
  6354. case exports.UnitType.kGradians:
  6355. case exports.UnitType.kMilliseconds:
  6356. case exports.UnitType.kSeconds:
  6357. // case UnitType.kHertz:
  6358. // case UnitType.kKilohertz:
  6359. case exports.UnitType.kTurns:
  6360. // case UnitType.kContainerMax: { // case UnitType.kContainerMin: // case UnitType.kContainerBlockSize: // case UnitType.kContainerInlineSize: // case UnitType.kContainerHeight: // case UnitType.kContainerWidth: // case UnitType.kDynamicViewportMax: // case UnitType.kDynamicViewportMin: // case UnitType.kDynamicViewportBlockSize: // case UnitType.kDynamicViewportInlineSize: // case UnitType.kDynamicViewportHeight: // case UnitType.kDynamicViewportWidth: // case UnitType.kLargeViewportMax: // case UnitType.kLargeViewportMin: // case UnitType.kLargeViewportBlockSize: // case UnitType.kLargeViewportInlineSize: // case UnitType.kLargeViewportHeight: // case UnitType.kLargeViewportWidth: // case UnitType.kSmallViewportMax: // case UnitType.kSmallViewportMin: // case UnitType.kSmallViewportBlockSize: // case UnitType.kSmallViewportInlineSize: // case UnitType.kSmallViewportHeight: // case UnitType.kSmallViewportWidth: // case UnitType.kViewportMax: // case UnitType.kViewportMin: // case UnitType.kViewportBlockSize: // case UnitType.kViewportInlineSize: // case UnitType.kViewportHeight: // case UnitType.kViewportWidth: // case UnitType.kFraction:
  6361. {
  6362. var kMinInteger = -999999;
  6363. var kMaxInteger = 999999;
  6364. var value = this.value;
  6365. var unit = unitTypeToString(this.unit);
  6366. if (value < kMinInteger || value > kMaxInteger) {
  6367. var _unit = unitTypeToString(this.unit);
  6368. if (!Number.isFinite(value) || Number.isNaN(value)) {
  6369. text = formatInfinityOrNaN(value, _unit);
  6370. } else {
  6371. text = value + (_unit || '');
  6372. }
  6373. } else {
  6374. text = "" + value + unit;
  6375. }
  6376. }
  6377. }
  6378. result += text;
  6379. return result;
  6380. };
  6381. return CSSUnitValue;
  6382. }(CSSStyleValue);
  6383. var Opx = new CSSUnitValue(0, 'px');
  6384. var Lpx = new CSSUnitValue(1, 'px');
  6385. var Odeg = new CSSUnitValue(0, 'deg');
  6386. /**
  6387. * The CSSRGB class represents the CSS rgb()/rgba() functions.
  6388. *
  6389. * @see https://drafts.css-houdini.org/css-typed-om-1/#cssrgb
  6390. */
  6391. var CSSRGB = /*#__PURE__*/function (_CSSColorValue) {
  6392. _inheritsLoose(CSSRGB, _CSSColorValue);
  6393. function CSSRGB(r, g, b, alpha,
  6394. /**
  6395. * 'transparent' & 'none' has the same rgba data
  6396. */
  6397. isNone) {
  6398. var _this;
  6399. if (alpha === void 0) {
  6400. alpha = 1;
  6401. }
  6402. if (isNone === void 0) {
  6403. isNone = false;
  6404. }
  6405. _this = _CSSColorValue.call(this, 'rgb') || this;
  6406. _this.r = void 0;
  6407. _this.g = void 0;
  6408. _this.b = void 0;
  6409. _this.alpha = void 0;
  6410. _this.isNone = void 0;
  6411. _this.r = r;
  6412. _this.g = g;
  6413. _this.b = b;
  6414. _this.alpha = alpha;
  6415. _this.isNone = isNone;
  6416. return _this;
  6417. }
  6418. var _proto = CSSRGB.prototype;
  6419. _proto.clone = function clone() {
  6420. return new CSSRGB(this.r, this.g, this.b, this.alpha);
  6421. };
  6422. _proto.buildCSSText = function buildCSSText(n, p, result) {
  6423. return result + ("rgba(" + this.r + "," + this.g + "," + this.b + "," + this.alpha + ")");
  6424. };
  6425. return CSSRGB;
  6426. }(CSSColorValue);
  6427. /**
  6428. * holds useful CSS-related methods.
  6429. * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS
  6430. *
  6431. * * CSS Typed OM @see https://developer.mozilla.org/en-US/docs/Web/API/CSS/factory_functions
  6432. * * register property @see https://developer.mozilla.org/en-US/docs/Web/API/CSS/RegisterProperty
  6433. * * CSS Layout API
  6434. */
  6435. var CSS = {
  6436. /**
  6437. * <number>
  6438. * @see https://drafts.csswg.org/css-values-4/#number-value
  6439. */
  6440. number: function number(n) {
  6441. return new CSSUnitValue(n);
  6442. },
  6443. /**
  6444. * <percentage>
  6445. * @see https://drafts.csswg.org/css-values-4/#percentage-value
  6446. */
  6447. percent: function percent(n) {
  6448. return new CSSUnitValue(n, '%');
  6449. },
  6450. /**
  6451. * <length>
  6452. */
  6453. px: function px(n) {
  6454. return new CSSUnitValue(n, 'px');
  6455. },
  6456. /**
  6457. * <length>
  6458. */
  6459. em: function em(n) {
  6460. return new CSSUnitValue(n, 'em');
  6461. },
  6462. rem: function rem(n) {
  6463. return new CSSUnitValue(n, 'rem');
  6464. },
  6465. /**
  6466. * <angle>
  6467. */
  6468. deg: function deg(n) {
  6469. return new CSSUnitValue(n, 'deg');
  6470. },
  6471. /**
  6472. * <angle>
  6473. */
  6474. grad: function grad(n) {
  6475. return new CSSUnitValue(n, 'grad');
  6476. },
  6477. /**
  6478. * <angle>
  6479. */
  6480. rad: function rad(n) {
  6481. return new CSSUnitValue(n, 'rad');
  6482. },
  6483. /**
  6484. * <angle>
  6485. */
  6486. turn: function turn(n) {
  6487. return new CSSUnitValue(n, 'turn');
  6488. },
  6489. /**
  6490. * <time>
  6491. */
  6492. s: function s(n) {
  6493. return new CSSUnitValue(n, 's');
  6494. },
  6495. /**
  6496. * <time>
  6497. */
  6498. ms: function ms(n) {
  6499. return new CSSUnitValue(n, 'ms');
  6500. },
  6501. /**
  6502. * CSS Properties & Values API
  6503. *
  6504. * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS_Properties_and_Values_API
  6505. * @see https://drafts.css-houdini.org/css-properties-values-api/#registering-custom-properties
  6506. * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS/RegisterProperty
  6507. */
  6508. registerProperty: function registerProperty(definition) {
  6509. var name = definition.name,
  6510. inherits = definition.inherits,
  6511. interpolable = definition.interpolable,
  6512. initialValue = definition.initialValue,
  6513. syntax = definition.syntax;
  6514. runtime.styleValueRegistry.registerMetadata({
  6515. n: name,
  6516. inh: inherits,
  6517. int: interpolable,
  6518. d: initialValue,
  6519. syntax: syntax
  6520. });
  6521. },
  6522. /**
  6523. * CSS Layout API
  6524. * register layout
  6525. *
  6526. * @see https://github.com/w3c/css-houdini-drafts/blob/main/css-layout-api/EXPLAINER.md
  6527. * @see https://developer.mozilla.org/en-US/docs/Web/Guide/Houdini#css_layout_api
  6528. */
  6529. registerLayout: function registerLayout(name, clazz) {
  6530. runtime.layoutRegistry.registerLayout(name, clazz);
  6531. }
  6532. };
  6533. /**
  6534. * CSSKeywordValue
  6535. */
  6536. var unsetKeywordValue = new CSSKeywordValue('unset');
  6537. var initialKeywordValue = new CSSKeywordValue('initial');
  6538. var inheritKeywordValue = new CSSKeywordValue('inherit');
  6539. var keywordCache = {
  6540. '': unsetKeywordValue,
  6541. unset: unsetKeywordValue,
  6542. initial: initialKeywordValue,
  6543. inherit: inheritKeywordValue
  6544. };
  6545. var getOrCreateKeyword = function getOrCreateKeyword(name) {
  6546. if (!keywordCache[name]) {
  6547. keywordCache[name] = new CSSKeywordValue(name);
  6548. }
  6549. return keywordCache[name];
  6550. };
  6551. /**
  6552. * CSSColor
  6553. */
  6554. var noneColor = new CSSRGB(0, 0, 0, 0, true);
  6555. var transparentColor = new CSSRGB(0, 0, 0, 0);
  6556. var getOrCreateRGBA = memoize(function (r, g, b, a) {
  6557. return new CSSRGB(r, g, b, a);
  6558. }, function (r, g, b, a) {
  6559. return "rgba(" + r + "," + g + "," + b + "," + a + ")";
  6560. });
  6561. // export const getOrCreateUnitValue = memoize(
  6562. // (value: number, unitOrName: UnitType | string = UnitType.kNumber) => {
  6563. // return new CSSUnitValue(value, unitOrName);
  6564. // },
  6565. // (value: number, unitOrName: UnitType | string = UnitType.kNumber) => {
  6566. // return `${value}${unitOrName}`;
  6567. // },
  6568. // );
  6569. var getOrCreateUnitValue = function getOrCreateUnitValue(value, unitOrName) {
  6570. if (unitOrName === void 0) {
  6571. unitOrName = exports.UnitType.kNumber;
  6572. }
  6573. return new CSSUnitValue(value, unitOrName);
  6574. };
  6575. var PECENTAGE_50 = new CSSUnitValue(50, '%');
  6576. function define(constructor, factory, prototype) {
  6577. constructor.prototype = factory.prototype = prototype;
  6578. prototype.constructor = constructor;
  6579. }
  6580. function extend(parent, definition) {
  6581. var prototype = Object.create(parent.prototype);
  6582. for (var key in definition) prototype[key] = definition[key];
  6583. return prototype;
  6584. }
  6585. function Color() {}
  6586. var darker = 0.7;
  6587. var brighter = 1 / darker;
  6588. var reI = "\\s*([+-]?\\d+)\\s*",
  6589. reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  6590. reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  6591. reHex = /^#([0-9a-f]{3,8})$/,
  6592. reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
  6593. reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
  6594. reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
  6595. reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
  6596. reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
  6597. reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  6598. var named = {
  6599. aliceblue: 0xf0f8ff,
  6600. antiquewhite: 0xfaebd7,
  6601. aqua: 0x00ffff,
  6602. aquamarine: 0x7fffd4,
  6603. azure: 0xf0ffff,
  6604. beige: 0xf5f5dc,
  6605. bisque: 0xffe4c4,
  6606. black: 0x000000,
  6607. blanchedalmond: 0xffebcd,
  6608. blue: 0x0000ff,
  6609. blueviolet: 0x8a2be2,
  6610. brown: 0xa52a2a,
  6611. burlywood: 0xdeb887,
  6612. cadetblue: 0x5f9ea0,
  6613. chartreuse: 0x7fff00,
  6614. chocolate: 0xd2691e,
  6615. coral: 0xff7f50,
  6616. cornflowerblue: 0x6495ed,
  6617. cornsilk: 0xfff8dc,
  6618. crimson: 0xdc143c,
  6619. cyan: 0x00ffff,
  6620. darkblue: 0x00008b,
  6621. darkcyan: 0x008b8b,
  6622. darkgoldenrod: 0xb8860b,
  6623. darkgray: 0xa9a9a9,
  6624. darkgreen: 0x006400,
  6625. darkgrey: 0xa9a9a9,
  6626. darkkhaki: 0xbdb76b,
  6627. darkmagenta: 0x8b008b,
  6628. darkolivegreen: 0x556b2f,
  6629. darkorange: 0xff8c00,
  6630. darkorchid: 0x9932cc,
  6631. darkred: 0x8b0000,
  6632. darksalmon: 0xe9967a,
  6633. darkseagreen: 0x8fbc8f,
  6634. darkslateblue: 0x483d8b,
  6635. darkslategray: 0x2f4f4f,
  6636. darkslategrey: 0x2f4f4f,
  6637. darkturquoise: 0x00ced1,
  6638. darkviolet: 0x9400d3,
  6639. deeppink: 0xff1493,
  6640. deepskyblue: 0x00bfff,
  6641. dimgray: 0x696969,
  6642. dimgrey: 0x696969,
  6643. dodgerblue: 0x1e90ff,
  6644. firebrick: 0xb22222,
  6645. floralwhite: 0xfffaf0,
  6646. forestgreen: 0x228b22,
  6647. fuchsia: 0xff00ff,
  6648. gainsboro: 0xdcdcdc,
  6649. ghostwhite: 0xf8f8ff,
  6650. gold: 0xffd700,
  6651. goldenrod: 0xdaa520,
  6652. gray: 0x808080,
  6653. green: 0x008000,
  6654. greenyellow: 0xadff2f,
  6655. grey: 0x808080,
  6656. honeydew: 0xf0fff0,
  6657. hotpink: 0xff69b4,
  6658. indianred: 0xcd5c5c,
  6659. indigo: 0x4b0082,
  6660. ivory: 0xfffff0,
  6661. khaki: 0xf0e68c,
  6662. lavender: 0xe6e6fa,
  6663. lavenderblush: 0xfff0f5,
  6664. lawngreen: 0x7cfc00,
  6665. lemonchiffon: 0xfffacd,
  6666. lightblue: 0xadd8e6,
  6667. lightcoral: 0xf08080,
  6668. lightcyan: 0xe0ffff,
  6669. lightgoldenrodyellow: 0xfafad2,
  6670. lightgray: 0xd3d3d3,
  6671. lightgreen: 0x90ee90,
  6672. lightgrey: 0xd3d3d3,
  6673. lightpink: 0xffb6c1,
  6674. lightsalmon: 0xffa07a,
  6675. lightseagreen: 0x20b2aa,
  6676. lightskyblue: 0x87cefa,
  6677. lightslategray: 0x778899,
  6678. lightslategrey: 0x778899,
  6679. lightsteelblue: 0xb0c4de,
  6680. lightyellow: 0xffffe0,
  6681. lime: 0x00ff00,
  6682. limegreen: 0x32cd32,
  6683. linen: 0xfaf0e6,
  6684. magenta: 0xff00ff,
  6685. maroon: 0x800000,
  6686. mediumaquamarine: 0x66cdaa,
  6687. mediumblue: 0x0000cd,
  6688. mediumorchid: 0xba55d3,
  6689. mediumpurple: 0x9370db,
  6690. mediumseagreen: 0x3cb371,
  6691. mediumslateblue: 0x7b68ee,
  6692. mediumspringgreen: 0x00fa9a,
  6693. mediumturquoise: 0x48d1cc,
  6694. mediumvioletred: 0xc71585,
  6695. midnightblue: 0x191970,
  6696. mintcream: 0xf5fffa,
  6697. mistyrose: 0xffe4e1,
  6698. moccasin: 0xffe4b5,
  6699. navajowhite: 0xffdead,
  6700. navy: 0x000080,
  6701. oldlace: 0xfdf5e6,
  6702. olive: 0x808000,
  6703. olivedrab: 0x6b8e23,
  6704. orange: 0xffa500,
  6705. orangered: 0xff4500,
  6706. orchid: 0xda70d6,
  6707. palegoldenrod: 0xeee8aa,
  6708. palegreen: 0x98fb98,
  6709. paleturquoise: 0xafeeee,
  6710. palevioletred: 0xdb7093,
  6711. papayawhip: 0xffefd5,
  6712. peachpuff: 0xffdab9,
  6713. peru: 0xcd853f,
  6714. pink: 0xffc0cb,
  6715. plum: 0xdda0dd,
  6716. powderblue: 0xb0e0e6,
  6717. purple: 0x800080,
  6718. rebeccapurple: 0x663399,
  6719. red: 0xff0000,
  6720. rosybrown: 0xbc8f8f,
  6721. royalblue: 0x4169e1,
  6722. saddlebrown: 0x8b4513,
  6723. salmon: 0xfa8072,
  6724. sandybrown: 0xf4a460,
  6725. seagreen: 0x2e8b57,
  6726. seashell: 0xfff5ee,
  6727. sienna: 0xa0522d,
  6728. silver: 0xc0c0c0,
  6729. skyblue: 0x87ceeb,
  6730. slateblue: 0x6a5acd,
  6731. slategray: 0x708090,
  6732. slategrey: 0x708090,
  6733. snow: 0xfffafa,
  6734. springgreen: 0x00ff7f,
  6735. steelblue: 0x4682b4,
  6736. tan: 0xd2b48c,
  6737. teal: 0x008080,
  6738. thistle: 0xd8bfd8,
  6739. tomato: 0xff6347,
  6740. turquoise: 0x40e0d0,
  6741. violet: 0xee82ee,
  6742. wheat: 0xf5deb3,
  6743. white: 0xffffff,
  6744. whitesmoke: 0xf5f5f5,
  6745. yellow: 0xffff00,
  6746. yellowgreen: 0x9acd32
  6747. };
  6748. define(Color, color, {
  6749. copy: function(channels) {
  6750. return Object.assign(new this.constructor, this, channels);
  6751. },
  6752. displayable: function() {
  6753. return this.rgb().displayable();
  6754. },
  6755. hex: color_formatHex, // Deprecated! Use color.formatHex.
  6756. formatHex: color_formatHex,
  6757. formatHsl: color_formatHsl,
  6758. formatRgb: color_formatRgb,
  6759. toString: color_formatRgb
  6760. });
  6761. function color_formatHex() {
  6762. return this.rgb().formatHex();
  6763. }
  6764. function color_formatHsl() {
  6765. return hslConvert(this).formatHsl();
  6766. }
  6767. function color_formatRgb() {
  6768. return this.rgb().formatRgb();
  6769. }
  6770. function color(format) {
  6771. var m, l;
  6772. format = (format + "").trim().toLowerCase();
  6773. return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
  6774. : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00
  6775. : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
  6776. : l === 4 ? rgba((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000
  6777. : null) // invalid hex
  6778. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  6779. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  6780. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  6781. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  6782. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  6783. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  6784. : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
  6785. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  6786. : null;
  6787. }
  6788. function rgbn(n) {
  6789. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  6790. }
  6791. function rgba(r, g, b, a) {
  6792. if (a <= 0) r = g = b = NaN;
  6793. return new Rgb(r, g, b, a);
  6794. }
  6795. function rgbConvert(o) {
  6796. if (!(o instanceof Color)) o = color(o);
  6797. if (!o) return new Rgb;
  6798. o = o.rgb();
  6799. return new Rgb(o.r, o.g, o.b, o.opacity);
  6800. }
  6801. function rgb(r, g, b, opacity) {
  6802. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  6803. }
  6804. function Rgb(r, g, b, opacity) {
  6805. this.r = +r;
  6806. this.g = +g;
  6807. this.b = +b;
  6808. this.opacity = +opacity;
  6809. }
  6810. define(Rgb, rgb, extend(Color, {
  6811. brighter: function(k) {
  6812. k = k == null ? brighter : Math.pow(brighter, k);
  6813. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  6814. },
  6815. darker: function(k) {
  6816. k = k == null ? darker : Math.pow(darker, k);
  6817. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  6818. },
  6819. rgb: function() {
  6820. return this;
  6821. },
  6822. displayable: function() {
  6823. return (-0.5 <= this.r && this.r < 255.5)
  6824. && (-0.5 <= this.g && this.g < 255.5)
  6825. && (-0.5 <= this.b && this.b < 255.5)
  6826. && (0 <= this.opacity && this.opacity <= 1);
  6827. },
  6828. hex: rgb_formatHex, // Deprecated! Use color.formatHex.
  6829. formatHex: rgb_formatHex,
  6830. formatRgb: rgb_formatRgb,
  6831. toString: rgb_formatRgb
  6832. }));
  6833. function rgb_formatHex() {
  6834. return "#" + hex(this.r) + hex(this.g) + hex(this.b);
  6835. }
  6836. function rgb_formatRgb() {
  6837. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  6838. return (a === 1 ? "rgb(" : "rgba(")
  6839. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  6840. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  6841. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  6842. + (a === 1 ? ")" : ", " + a + ")");
  6843. }
  6844. function hex(value) {
  6845. value = Math.max(0, Math.min(255, Math.round(value) || 0));
  6846. return (value < 16 ? "0" : "") + value.toString(16);
  6847. }
  6848. function hsla(h, s, l, a) {
  6849. if (a <= 0) h = s = l = NaN;
  6850. else if (l <= 0 || l >= 1) h = s = NaN;
  6851. else if (s <= 0) h = NaN;
  6852. return new Hsl(h, s, l, a);
  6853. }
  6854. function hslConvert(o) {
  6855. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  6856. if (!(o instanceof Color)) o = color(o);
  6857. if (!o) return new Hsl;
  6858. if (o instanceof Hsl) return o;
  6859. o = o.rgb();
  6860. var r = o.r / 255,
  6861. g = o.g / 255,
  6862. b = o.b / 255,
  6863. min = Math.min(r, g, b),
  6864. max = Math.max(r, g, b),
  6865. h = NaN,
  6866. s = max - min,
  6867. l = (max + min) / 2;
  6868. if (s) {
  6869. if (r === max) h = (g - b) / s + (g < b) * 6;
  6870. else if (g === max) h = (b - r) / s + 2;
  6871. else h = (r - g) / s + 4;
  6872. s /= l < 0.5 ? max + min : 2 - max - min;
  6873. h *= 60;
  6874. } else {
  6875. s = l > 0 && l < 1 ? 0 : h;
  6876. }
  6877. return new Hsl(h, s, l, o.opacity);
  6878. }
  6879. function hsl(h, s, l, opacity) {
  6880. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  6881. }
  6882. function Hsl(h, s, l, opacity) {
  6883. this.h = +h;
  6884. this.s = +s;
  6885. this.l = +l;
  6886. this.opacity = +opacity;
  6887. }
  6888. define(Hsl, hsl, extend(Color, {
  6889. brighter: function(k) {
  6890. k = k == null ? brighter : Math.pow(brighter, k);
  6891. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  6892. },
  6893. darker: function(k) {
  6894. k = k == null ? darker : Math.pow(darker, k);
  6895. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  6896. },
  6897. rgb: function() {
  6898. var h = this.h % 360 + (this.h < 0) * 360,
  6899. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  6900. l = this.l,
  6901. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  6902. m1 = 2 * l - m2;
  6903. return new Rgb(
  6904. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  6905. hsl2rgb(h, m1, m2),
  6906. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  6907. this.opacity
  6908. );
  6909. },
  6910. displayable: function() {
  6911. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  6912. && (0 <= this.l && this.l <= 1)
  6913. && (0 <= this.opacity && this.opacity <= 1);
  6914. },
  6915. formatHsl: function() {
  6916. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  6917. return (a === 1 ? "hsl(" : "hsla(")
  6918. + (this.h || 0) + ", "
  6919. + (this.s || 0) * 100 + "%, "
  6920. + (this.l || 0) * 100 + "%"
  6921. + (a === 1 ? ")" : ", " + a + ")");
  6922. }
  6923. }));
  6924. /* From FvD 13.37, CSS Color Module Level 3 */
  6925. function hsl2rgb(h, m1, m2) {
  6926. return (h < 60 ? m1 + (m2 - m1) * h / 60
  6927. : h < 180 ? m2
  6928. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  6929. : m1) * 255;
  6930. }
  6931. var canvasMap = {};
  6932. var defaultCanvasIdCounter = 0;
  6933. /**
  6934. * destroy existed canvas with the same id
  6935. */
  6936. function cleanExistedCanvas(container, canvas) {
  6937. if (container) {
  6938. var id = typeof container === 'string' ? container : container.id || defaultCanvasIdCounter++;
  6939. if (canvasMap[id]) {
  6940. canvasMap[id].destroy();
  6941. }
  6942. canvasMap[id] = canvas;
  6943. }
  6944. }
  6945. var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
  6946. function sortedIndex(array, value) {
  6947. var low = 0;
  6948. var high = array.length;
  6949. while (low < high) {
  6950. var mid = low + high >>> 1;
  6951. if (sortByZIndex(array[mid], value) < 0) {
  6952. low = mid + 1;
  6953. } else {
  6954. high = mid;
  6955. }
  6956. }
  6957. return low;
  6958. }
  6959. function sortByZIndex(o1, o2) {
  6960. var zIndex1 = Number(o1.parsedStyle.zIndex);
  6961. var zIndex2 = Number(o2.parsedStyle.zIndex);
  6962. if (zIndex1 === zIndex2) {
  6963. var parent = o1.parentNode;
  6964. if (parent) {
  6965. var children = parent.childNodes || [];
  6966. return children.indexOf(o1) - children.indexOf(o2);
  6967. }
  6968. }
  6969. return zIndex1 - zIndex2;
  6970. }
  6971. function findClosestClipPathTarget(object) {
  6972. var el = object;
  6973. do {
  6974. var _el$parsedStyle;
  6975. var clipPath = (_el$parsedStyle = el.parsedStyle) === null || _el$parsedStyle === void 0 ? void 0 : _el$parsedStyle.clipPath;
  6976. if (clipPath) return el;
  6977. el = el.parentElement;
  6978. } while (el !== null);
  6979. return null;
  6980. }
  6981. var PX_SUFFIX = 'px';
  6982. function setDOMSize($el, width, height) {
  6983. if (isBrowser && $el.style) {
  6984. $el.style.width = width + PX_SUFFIX;
  6985. $el.style.height = height + PX_SUFFIX;
  6986. }
  6987. }
  6988. function getStyle($el, property) {
  6989. if (isBrowser) {
  6990. return document.defaultView.getComputedStyle($el, null).getPropertyValue(property);
  6991. }
  6992. }
  6993. function getWidth($el) {
  6994. var width = getStyle($el, 'width');
  6995. if (width === 'auto') {
  6996. return $el.offsetWidth;
  6997. }
  6998. return parseFloat(width);
  6999. }
  7000. function getHeight($el) {
  7001. var height = getStyle($el, 'height');
  7002. if (height === 'auto') {
  7003. return $el.offsetHeight;
  7004. }
  7005. return parseFloat(height);
  7006. }
  7007. var ERROR_MSG_METHOD_NOT_IMPLEMENTED = 'Method not implemented.';
  7008. var ERROR_MSG_USE_DOCUMENT_ELEMENT = 'Use document.documentElement instead.';
  7009. var ERROR_MSG_APPEND_DESTROYED_ELEMENT = 'Cannot append a destroyed element.';
  7010. // borrow from hammer.js
  7011. var MOUSE_POINTER_ID = 1;
  7012. var TOUCH_TO_POINTER = {
  7013. touchstart: 'pointerdown',
  7014. touchend: 'pointerup',
  7015. touchendoutside: 'pointerupoutside',
  7016. touchmove: 'pointermove',
  7017. touchcancel: 'pointercancel'
  7018. };
  7019. function copyVec3(a, b) {
  7020. a[0] = b[0];
  7021. a[1] = b[1];
  7022. a[2] = b[2];
  7023. return a;
  7024. }
  7025. function subVec3(o, a, b) {
  7026. o[0] = a[0] - b[0];
  7027. o[1] = a[1] - b[1];
  7028. o[2] = a[2] - b[2];
  7029. return o;
  7030. }
  7031. function addVec3(o, a, b) {
  7032. o[0] = a[0] + b[0];
  7033. o[1] = a[1] + b[1];
  7034. o[2] = a[2] + b[2];
  7035. return o;
  7036. }
  7037. function scaleVec3(o, a, b) {
  7038. o[0] = a[0] * b;
  7039. o[1] = a[1] * b;
  7040. o[2] = a[2] * b;
  7041. return o;
  7042. }
  7043. function maxVec3(o, a, b) {
  7044. o[0] = Math.max(a[0], b[0]);
  7045. o[1] = Math.max(a[1], b[1]);
  7046. o[2] = Math.max(a[2], b[2]);
  7047. return o;
  7048. }
  7049. function minVec3(o, a, b) {
  7050. o[0] = Math.min(a[0], b[0]);
  7051. o[1] = Math.min(a[1], b[1]);
  7052. o[2] = Math.min(a[2], b[2]);
  7053. return o;
  7054. }
  7055. function getAngle(angle) {
  7056. if (angle === undefined) {
  7057. return 0;
  7058. } else if (angle > 360 || angle < -360) {
  7059. return angle % 360;
  7060. }
  7061. return angle;
  7062. }
  7063. function createVec3(x, y, z) {
  7064. if (y === void 0) {
  7065. y = 0;
  7066. }
  7067. if (z === void 0) {
  7068. z = 0;
  7069. }
  7070. if (Array.isArray(x) && x.length === 3) {
  7071. return clone$1(x);
  7072. }
  7073. if (isNumber(x)) {
  7074. return fromValues$2(x, y, z);
  7075. }
  7076. return fromValues$2(x[0], x[1] || y, x[2] || z);
  7077. }
  7078. function deg2rad(deg) {
  7079. return deg * (Math.PI / 180);
  7080. }
  7081. function rad2deg(rad) {
  7082. return rad * (180 / Math.PI);
  7083. }
  7084. function grad2deg(grads) {
  7085. grads = grads % 400;
  7086. if (grads < 0) {
  7087. grads += 400;
  7088. }
  7089. return grads / 400 * 360;
  7090. }
  7091. function deg2turn(deg) {
  7092. return deg / 360;
  7093. }
  7094. function turn2deg(turn) {
  7095. return 360 * turn;
  7096. }
  7097. function getEulerFromQuat(out, quat) {
  7098. var x = quat[0];
  7099. var y = quat[1];
  7100. var z = quat[2];
  7101. var w = quat[3];
  7102. var x2 = x * x;
  7103. var y2 = y * y;
  7104. var z2 = z * z;
  7105. var w2 = w * w;
  7106. var unit = x2 + y2 + z2 + w2;
  7107. var test = x * w - y * z;
  7108. if (test > 0.499995 * unit) {
  7109. // TODO: Use glmatrix.EPSILON
  7110. // singularity at the north pole
  7111. out[0] = Math.PI / 2;
  7112. out[1] = 2 * Math.atan2(y, x);
  7113. out[2] = 0;
  7114. } else if (test < -0.499995 * unit) {
  7115. //TODO: Use glmatrix.EPSILON
  7116. // singularity at the south pole
  7117. out[0] = -Math.PI / 2;
  7118. out[1] = 2 * Math.atan2(y, x);
  7119. out[2] = 0;
  7120. } else {
  7121. out[0] = Math.asin(2 * (x * z - w * y));
  7122. out[1] = Math.atan2(2 * (x * w + y * z), 1 - 2 * (z2 + w2));
  7123. out[2] = Math.atan2(2 * (x * y + z * w), 1 - 2 * (y2 + z2));
  7124. }
  7125. // TODO: Return them as degrees and not as radians
  7126. return out;
  7127. }
  7128. function getEulerFromMat4(out, m) {
  7129. var x;
  7130. var z;
  7131. var halfPi = Math.PI * 0.5;
  7132. var _mat4$getScaling = getScaling(create$2(), m),
  7133. sx = _mat4$getScaling[0],
  7134. sy = _mat4$getScaling[1],
  7135. sz = _mat4$getScaling[2];
  7136. var y = Math.asin(-m[2] / sx);
  7137. if (y < halfPi) {
  7138. if (y > -halfPi) {
  7139. x = Math.atan2(m[6] / sy, m[10] / sz);
  7140. z = Math.atan2(m[1] / sx, m[0] / sx);
  7141. } else {
  7142. // Not a unique solution
  7143. z = 0;
  7144. x = -Math.atan2(m[4] / sy, m[5] / sy);
  7145. }
  7146. } else {
  7147. // Not a unique solution
  7148. z = 0;
  7149. x = Math.atan2(m[4] / sy, m[5] / sy);
  7150. }
  7151. out[0] = x;
  7152. out[1] = y;
  7153. out[2] = z;
  7154. return out;
  7155. }
  7156. /**
  7157. * @see https://github.com/toji/gl-matrix/issues/329
  7158. * @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
  7159. */
  7160. function getEuler(out, quat) {
  7161. if (quat.length === 16) {
  7162. return getEulerFromMat4(out, quat);
  7163. } else {
  7164. return getEulerFromQuat(out, quat);
  7165. }
  7166. }
  7167. function fromRotationTranslationScale$1(rotation, x, y, scaleX, scaleY) {
  7168. var cos = Math.cos(rotation);
  7169. var sin = Math.sin(rotation);
  7170. return fromValues(scaleX * cos, scaleY * sin, 0, -scaleX * sin, scaleY * cos, 0, x, y, 1);
  7171. }
  7172. function makePerspective(out, left, right, top, bottom, near, far) {
  7173. var x = 2 * near / (right - left);
  7174. var y = 2 * near / (top - bottom);
  7175. var a = (right + left) / (right - left);
  7176. var b = (top + bottom) / (top - bottom);
  7177. var c = -(far + near) / (far - near);
  7178. var d = -2 * far * near / (far - near);
  7179. out[0] = x;
  7180. out[1] = 0;
  7181. out[2] = 0;
  7182. out[3] = 0;
  7183. out[4] = 0;
  7184. out[5] = y;
  7185. out[6] = 0;
  7186. out[7] = 0;
  7187. out[8] = a;
  7188. out[9] = b;
  7189. out[10] = c;
  7190. out[11] = -1;
  7191. out[12] = 0;
  7192. out[13] = 0;
  7193. out[14] = d;
  7194. out[15] = 0;
  7195. return out;
  7196. }
  7197. function decompose(mat) {
  7198. var row0x = mat[0];
  7199. var row0y = mat[1];
  7200. var row1x = mat[3];
  7201. var row1y = mat[4];
  7202. // decompose 3x3 matrix
  7203. // @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
  7204. var scalingX = Math.sqrt(row0x * row0x + row0y * row0y);
  7205. var scalingY = Math.sqrt(row1x * row1x + row1y * row1y);
  7206. // If determinant is negative, one axis was flipped.
  7207. var determinant = row0x * row1y - row0y * row1x;
  7208. if (determinant < 0) {
  7209. // Flip axis with minimum unit vector dot product.
  7210. if (row0x < row1y) {
  7211. scalingX = -scalingX;
  7212. } else {
  7213. scalingY = -scalingY;
  7214. }
  7215. }
  7216. // Renormalize matrix to remove scale.
  7217. if (scalingX) {
  7218. row0x *= 1 / scalingX;
  7219. row0y *= 1 / scalingX;
  7220. }
  7221. if (scalingY) {
  7222. row1x *= 1 / scalingY;
  7223. row1y *= 1 / scalingY;
  7224. }
  7225. // Compute rotation and renormalize matrix.
  7226. var rotation = Math.atan2(row0y, row0x);
  7227. var angle = rad2deg(rotation);
  7228. return [mat[6], mat[7], scalingX, scalingY, angle];
  7229. }
  7230. var tmp = create$1();
  7231. var perspectiveMatrix = create$1();
  7232. var tmpVec4 = create$3();
  7233. var row = [create$2(), create$2(), create$2()];
  7234. var pdum3 = create$2();
  7235. /*
  7236. Input: matrix ; a 4x4 matrix
  7237. Output: translation ; a 3 component vector
  7238. scale ; a 3 component vector
  7239. skew ; skew factors XY,XZ,YZ represented as a 3 component vector
  7240. perspective ; a 4 component vector
  7241. quaternion ; a 4 component vector
  7242. Returns false if the matrix cannot be decomposed, true if it can
  7243. References:
  7244. https://github.com/kamicane/matrix3d/blob/master/lib/Matrix3d.js
  7245. https://github.com/ChromiumWebApps/chromium/blob/master/ui/gfx/transform_util.cc
  7246. http://www.w3.org/TR/css3-transforms/#decomposing-a-3d-matrix
  7247. */
  7248. function decomposeMat4(matrix, translation, scale, skew, perspective, quaternion) {
  7249. //normalize, if not possible then bail out early
  7250. if (!normalize$4(tmp, matrix)) return false;
  7251. // perspectiveMatrix is used to solve for perspective, but it also provides
  7252. // an easy way to test for singularity of the upper 3x3 component.
  7253. copy(perspectiveMatrix, tmp);
  7254. perspectiveMatrix[3] = 0;
  7255. perspectiveMatrix[7] = 0;
  7256. perspectiveMatrix[11] = 0;
  7257. perspectiveMatrix[15] = 1;
  7258. // If the perspectiveMatrix is not invertible, we are also unable to
  7259. // decompose, so we'll bail early. Constant taken from SkMatrix44::invert.
  7260. if (Math.abs(determinant(perspectiveMatrix)) < 1e-8) return false;
  7261. var a03 = tmp[3],
  7262. a13 = tmp[7],
  7263. a23 = tmp[11],
  7264. a30 = tmp[12],
  7265. a31 = tmp[13],
  7266. a32 = tmp[14],
  7267. a33 = tmp[15];
  7268. // First, isolate perspective.
  7269. if (a03 !== 0 || a13 !== 0 || a23 !== 0) {
  7270. tmpVec4[0] = a03;
  7271. tmpVec4[1] = a13;
  7272. tmpVec4[2] = a23;
  7273. tmpVec4[3] = a33;
  7274. // Solve the equation by inverting perspectiveMatrix and multiplying
  7275. // rightHandSide by the inverse.
  7276. // resuing the perspectiveMatrix here since it's no longer needed
  7277. var ret = invert(perspectiveMatrix, perspectiveMatrix);
  7278. if (!ret) return false;
  7279. transpose(perspectiveMatrix, perspectiveMatrix);
  7280. //multiply by transposed inverse perspective matrix, into perspective vec4
  7281. transformMat4$1(perspective, tmpVec4, perspectiveMatrix);
  7282. } else {
  7283. //no perspective
  7284. perspective[0] = perspective[1] = perspective[2] = 0;
  7285. perspective[3] = 1;
  7286. }
  7287. // Next take care of translation
  7288. translation[0] = a30;
  7289. translation[1] = a31;
  7290. translation[2] = a32;
  7291. // Now get scale and shear. 'row' is a 3 element array of 3 component vectors
  7292. mat3from4(row, tmp);
  7293. // Compute X scale factor and normalize first row.
  7294. scale[0] = length(row[0]);
  7295. normalize(row[0], row[0]);
  7296. // Compute XY shear factor and make 2nd row orthogonal to 1st.
  7297. skew[0] = dot(row[0], row[1]);
  7298. combine(row[1], row[1], row[0], 1.0, -skew[0]);
  7299. // Now, compute Y scale and normalize 2nd row.
  7300. scale[1] = length(row[1]);
  7301. normalize(row[1], row[1]);
  7302. skew[0] /= scale[1];
  7303. // Compute XZ and YZ shears, orthogonalize 3rd row
  7304. skew[1] = dot(row[0], row[2]);
  7305. combine(row[2], row[2], row[0], 1.0, -skew[1]);
  7306. skew[2] = dot(row[1], row[2]);
  7307. combine(row[2], row[2], row[1], 1.0, -skew[2]);
  7308. // Next, get Z scale and normalize 3rd row.
  7309. scale[2] = length(row[2]);
  7310. normalize(row[2], row[2]);
  7311. skew[1] /= scale[2];
  7312. skew[2] /= scale[2];
  7313. // At this point, the matrix (in rows) is orthonormal.
  7314. // Check for a coordinate system flip. If the determinant
  7315. // is -1, then negate the matrix and the scaling factors.
  7316. cross(pdum3, row[1], row[2]);
  7317. if (dot(row[0], pdum3) < 0) {
  7318. for (var i = 0; i < 3; i++) {
  7319. scale[i] *= -1;
  7320. row[i][0] *= -1;
  7321. row[i][1] *= -1;
  7322. row[i][2] *= -1;
  7323. }
  7324. }
  7325. // Now, get the rotations out
  7326. quaternion[0] = 0.5 * Math.sqrt(Math.max(1 + row[0][0] - row[1][1] - row[2][2], 0));
  7327. quaternion[1] = 0.5 * Math.sqrt(Math.max(1 - row[0][0] + row[1][1] - row[2][2], 0));
  7328. quaternion[2] = 0.5 * Math.sqrt(Math.max(1 - row[0][0] - row[1][1] + row[2][2], 0));
  7329. quaternion[3] = 0.5 * Math.sqrt(Math.max(1 + row[0][0] + row[1][1] + row[2][2], 0));
  7330. if (row[2][1] > row[1][2]) quaternion[0] = -quaternion[0];
  7331. if (row[0][2] > row[2][0]) quaternion[1] = -quaternion[1];
  7332. if (row[1][0] > row[0][1]) quaternion[2] = -quaternion[2];
  7333. return true;
  7334. }
  7335. function normalize$4(out, mat) {
  7336. var m44 = mat[15];
  7337. // Cannot normalize.
  7338. if (m44 === 0) return false;
  7339. var scale = 1 / m44;
  7340. for (var i = 0; i < 16; i++) out[i] = mat[i] * scale;
  7341. return true;
  7342. }
  7343. //gets upper-left of a 4x4 matrix into a 3x3 of vectors
  7344. function mat3from4(out, mat4x4) {
  7345. out[0][0] = mat4x4[0];
  7346. out[0][1] = mat4x4[1];
  7347. out[0][2] = mat4x4[2];
  7348. out[1][0] = mat4x4[4];
  7349. out[1][1] = mat4x4[5];
  7350. out[1][2] = mat4x4[6];
  7351. out[2][0] = mat4x4[8];
  7352. out[2][1] = mat4x4[9];
  7353. out[2][2] = mat4x4[10];
  7354. }
  7355. function combine(out, a, b, scale1, scale2) {
  7356. out[0] = a[0] * scale1 + b[0] * scale2;
  7357. out[1] = a[1] * scale1 + b[1] * scale2;
  7358. out[2] = a[2] * scale1 + b[2] * scale2;
  7359. }
  7360. var tmpMat4 = create$1();
  7361. function parsedTransformToMat4(transform, object) {
  7362. if (transform && transform.length) {
  7363. var defX = 0;
  7364. var defY = 0;
  7365. if (object) {
  7366. defX = object.parsedStyle.defX || 0;
  7367. defY = object.parsedStyle.defY || 0;
  7368. // reset transform
  7369. object.resetLocalTransform();
  7370. object.setLocalPosition(defX, defY);
  7371. } else {
  7372. object = new DisplayObject({});
  7373. }
  7374. transform.forEach(function (parsed) {
  7375. var t = parsed.t,
  7376. d = parsed.d;
  7377. if (t === 'scale') {
  7378. // scale(1) scale(1, 1)
  7379. var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
  7380. return s.value;
  7381. })) || [1, 1];
  7382. object.scaleLocal(newScale[0], newScale[1], 1);
  7383. } else if (t === 'scalex') {
  7384. var _newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
  7385. return s.value;
  7386. })) || [1];
  7387. object.scaleLocal(_newScale[0], 1, 1);
  7388. } else if (t === 'scaley') {
  7389. var _newScale2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
  7390. return s.value;
  7391. })) || [1];
  7392. object.scaleLocal(1, _newScale2[0], 1);
  7393. } else if (t === 'scalez') {
  7394. var _newScale3 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
  7395. return s.value;
  7396. })) || [1];
  7397. object.scaleLocal(1, 1, _newScale3[0]);
  7398. } else if (t === 'scale3d') {
  7399. var _newScale4 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
  7400. return s.value;
  7401. })) || [1, 1, 1];
  7402. object.scaleLocal(_newScale4[0], _newScale4[1], _newScale4[2]);
  7403. } else if (t === 'translate') {
  7404. var newTranslation = d || [Opx, Opx];
  7405. object.translateLocal(newTranslation[0].value, newTranslation[1].value, 0);
  7406. } else if (t === 'translatex') {
  7407. var _newTranslation = d || [Opx];
  7408. object.translateLocal(_newTranslation[0].value, 0, 0);
  7409. } else if (t === 'translatey') {
  7410. var _newTranslation2 = d || [Opx];
  7411. object.translateLocal(0, _newTranslation2[0].value, 0);
  7412. } else if (t === 'translatez') {
  7413. var _newTranslation3 = d || [Opx];
  7414. object.translateLocal(0, 0, _newTranslation3[0].value);
  7415. } else if (t === 'translate3d') {
  7416. var _newTranslation4 = d || [Opx, Opx, Opx];
  7417. object.translateLocal(_newTranslation4[0].value, _newTranslation4[1].value, _newTranslation4[2].value);
  7418. } else if (t === 'rotate') {
  7419. var newAngles = d || [Odeg];
  7420. object.rotateLocal(0, 0, convertAngleUnit(newAngles[0]));
  7421. } else if (t === 'rotatex') {
  7422. var _newAngles = d || [Odeg];
  7423. object.rotateLocal(convertAngleUnit(_newAngles[0]), 0, 0);
  7424. } else if (t === 'rotatey') {
  7425. var _newAngles2 = d || [Odeg];
  7426. object.rotateLocal(0, convertAngleUnit(_newAngles2[0]), 0);
  7427. } else if (t === 'rotatez') {
  7428. var _newAngles3 = d || [Odeg];
  7429. object.rotateLocal(0, 0, convertAngleUnit(_newAngles3[0]));
  7430. } else if (t === 'rotate3d') ; else if (t === 'skew') {
  7431. var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
  7432. return s.value;
  7433. })) || [0, 0];
  7434. object.setLocalSkew(deg2rad(newSkew[0]), deg2rad(newSkew[1]));
  7435. } else if (t === 'skewx') {
  7436. var _newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
  7437. return s.value;
  7438. })) || [0];
  7439. object.setLocalSkew(deg2rad(_newSkew[0]), object.getLocalSkew()[1]);
  7440. } else if (t === 'skewy') {
  7441. var _newSkew2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
  7442. return s.value;
  7443. })) || [0];
  7444. object.setLocalSkew(object.getLocalSkew()[0], deg2rad(_newSkew2[0]));
  7445. } else if (t === 'matrix') {
  7446. var _d$map = d.map(function (s) {
  7447. return s.value;
  7448. }),
  7449. a = _d$map[0],
  7450. b = _d$map[1],
  7451. c = _d$map[2],
  7452. dd = _d$map[3],
  7453. tx = _d$map[4],
  7454. ty = _d$map[5];
  7455. object.setLocalTransform(set(tmpMat4, a, b, 0, 0, c, dd, 0, 0, 0, 0, 1, 0, tx + defX, ty + defY, 0, 1));
  7456. } else if (t === 'matrix3d') {
  7457. // @ts-ignore
  7458. set.apply(mat4, [tmpMat4].concat(d.map(function (s) {
  7459. return s.value;
  7460. })));
  7461. tmpMat4[12] += defX;
  7462. tmpMat4[13] += defY;
  7463. object.setLocalTransform(tmpMat4);
  7464. }
  7465. });
  7466. }
  7467. return object.getLocalTransform();
  7468. }
  7469. /**
  7470. * borrow from gradient-parser, but we delete some browser compatible prefix such as `-webkit-`
  7471. * @see https://github.com/rafaelcaricio/gradient-parser
  7472. */
  7473. function colorStopToString(colorStop) {
  7474. var type = colorStop.type,
  7475. value = colorStop.value;
  7476. if (type === 'hex') {
  7477. return "#" + value;
  7478. } else if (type === 'literal') {
  7479. return value;
  7480. } else if (type === 'rgb') {
  7481. return "rgb(" + value.join(',') + ")";
  7482. } else {
  7483. return "rgba(" + value.join(',') + ")";
  7484. }
  7485. }
  7486. var parseGradient = function () {
  7487. var tokens = {
  7488. linearGradient: /^(linear\-gradient)/i,
  7489. repeatingLinearGradient: /^(repeating\-linear\-gradient)/i,
  7490. radialGradient: /^(radial\-gradient)/i,
  7491. repeatingRadialGradient: /^(repeating\-radial\-gradient)/i,
  7492. /**
  7493. * @see https://projects.verou.me/conic-gradient/
  7494. */
  7495. conicGradient: /^(conic\-gradient)/i,
  7496. sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
  7497. extentKeywords: /^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,
  7498. positionKeywords: /^(left|center|right|top|bottom)/i,
  7499. pixelValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,
  7500. percentageValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,
  7501. emValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,
  7502. angleValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,
  7503. startCall: /^\(/,
  7504. endCall: /^\)/,
  7505. comma: /^,/,
  7506. hexColor: /^\#([0-9a-fA-F]+)/,
  7507. literalColor: /^([a-zA-Z]+)/,
  7508. rgbColor: /^rgb/i,
  7509. rgbaColor: /^rgba/i,
  7510. number: /^(([0-9]*\.[0-9]+)|([0-9]+\.?))/
  7511. };
  7512. var input = '';
  7513. function error(msg) {
  7514. throw new Error(input + ': ' + msg);
  7515. }
  7516. function getAST() {
  7517. var ast = matchListDefinitions();
  7518. if (input.length > 0) {
  7519. error('Invalid input not EOF');
  7520. }
  7521. return ast;
  7522. }
  7523. function matchListDefinitions() {
  7524. return matchListing(matchDefinition);
  7525. }
  7526. function matchDefinition() {
  7527. return matchGradient('linear-gradient', tokens.linearGradient, matchLinearOrientation) || matchGradient('repeating-linear-gradient', tokens.repeatingLinearGradient, matchLinearOrientation) || matchGradient('radial-gradient', tokens.radialGradient, matchListRadialOrientations) || matchGradient('repeating-radial-gradient', tokens.repeatingRadialGradient, matchListRadialOrientations) || matchGradient('conic-gradient', tokens.conicGradient, matchListRadialOrientations);
  7528. }
  7529. function matchGradient(gradientType, pattern, orientationMatcher) {
  7530. return matchCall(pattern, function (captures) {
  7531. var orientation = orientationMatcher();
  7532. if (orientation) {
  7533. if (!scan(tokens.comma)) {
  7534. error('Missing comma before color stops');
  7535. }
  7536. }
  7537. return {
  7538. type: gradientType,
  7539. orientation: orientation,
  7540. colorStops: matchListing(matchColorStop)
  7541. };
  7542. });
  7543. }
  7544. function matchCall(pattern, callback) {
  7545. var captures = scan(pattern);
  7546. if (captures) {
  7547. if (!scan(tokens.startCall)) {
  7548. error('Missing (');
  7549. }
  7550. var result = callback(captures);
  7551. if (!scan(tokens.endCall)) {
  7552. error('Missing )');
  7553. }
  7554. return result;
  7555. }
  7556. }
  7557. function matchLinearOrientation() {
  7558. return matchSideOrCorner() || matchAngle();
  7559. }
  7560. function matchSideOrCorner() {
  7561. return match('directional', tokens.sideOrCorner, 1);
  7562. }
  7563. function matchAngle() {
  7564. return match('angular', tokens.angleValue, 1);
  7565. }
  7566. function matchListRadialOrientations() {
  7567. var radialOrientations,
  7568. radialOrientation = matchRadialOrientation(),
  7569. lookaheadCache;
  7570. if (radialOrientation) {
  7571. radialOrientations = [];
  7572. radialOrientations.push(radialOrientation);
  7573. lookaheadCache = input;
  7574. if (scan(tokens.comma)) {
  7575. radialOrientation = matchRadialOrientation();
  7576. if (radialOrientation) {
  7577. radialOrientations.push(radialOrientation);
  7578. } else {
  7579. input = lookaheadCache;
  7580. }
  7581. }
  7582. }
  7583. return radialOrientations;
  7584. }
  7585. function matchRadialOrientation() {
  7586. var radialType = matchCircle() || matchEllipse();
  7587. if (radialType) {
  7588. // @ts-ignore
  7589. radialType.at = matchAtPosition();
  7590. } else {
  7591. var extent = matchExtentKeyword();
  7592. if (extent) {
  7593. radialType = extent;
  7594. var positionAt = matchAtPosition();
  7595. if (positionAt) {
  7596. // @ts-ignore
  7597. radialType.at = positionAt;
  7598. }
  7599. } else {
  7600. var defaultPosition = matchPositioning();
  7601. if (defaultPosition) {
  7602. radialType = {
  7603. type: 'default-radial',
  7604. // @ts-ignore
  7605. at: defaultPosition
  7606. };
  7607. }
  7608. }
  7609. }
  7610. return radialType;
  7611. }
  7612. function matchCircle() {
  7613. var circle = match('shape', /^(circle)/i, 0);
  7614. if (circle) {
  7615. // @ts-ignore
  7616. circle.style = matchLength() || matchExtentKeyword();
  7617. }
  7618. return circle;
  7619. }
  7620. function matchEllipse() {
  7621. var ellipse = match('shape', /^(ellipse)/i, 0);
  7622. if (ellipse) {
  7623. // @ts-ignore
  7624. ellipse.style = matchDistance() || matchExtentKeyword();
  7625. }
  7626. return ellipse;
  7627. }
  7628. function matchExtentKeyword() {
  7629. return match('extent-keyword', tokens.extentKeywords, 1);
  7630. }
  7631. function matchAtPosition() {
  7632. if (match('position', /^at/, 0)) {
  7633. var positioning = matchPositioning();
  7634. if (!positioning) {
  7635. error('Missing positioning value');
  7636. }
  7637. return positioning;
  7638. }
  7639. }
  7640. function matchPositioning() {
  7641. var location = matchCoordinates();
  7642. if (location.x || location.y) {
  7643. return {
  7644. type: 'position',
  7645. value: location
  7646. };
  7647. }
  7648. }
  7649. function matchCoordinates() {
  7650. return {
  7651. x: matchDistance(),
  7652. y: matchDistance()
  7653. };
  7654. }
  7655. function matchListing(matcher) {
  7656. var captures = matcher();
  7657. var result = [];
  7658. if (captures) {
  7659. result.push(captures);
  7660. while (scan(tokens.comma)) {
  7661. captures = matcher();
  7662. if (captures) {
  7663. result.push(captures);
  7664. } else {
  7665. error('One extra comma');
  7666. }
  7667. }
  7668. }
  7669. return result;
  7670. }
  7671. function matchColorStop() {
  7672. var color = matchColor();
  7673. if (!color) {
  7674. error('Expected color definition');
  7675. }
  7676. color.length = matchDistance();
  7677. return color;
  7678. }
  7679. function matchColor() {
  7680. return matchHexColor() || matchRGBAColor() || matchRGBColor() || matchLiteralColor();
  7681. }
  7682. function matchLiteralColor() {
  7683. return match('literal', tokens.literalColor, 0);
  7684. }
  7685. function matchHexColor() {
  7686. return match('hex', tokens.hexColor, 1);
  7687. }
  7688. function matchRGBColor() {
  7689. return matchCall(tokens.rgbColor, function () {
  7690. return {
  7691. type: 'rgb',
  7692. value: matchListing(matchNumber)
  7693. };
  7694. });
  7695. }
  7696. function matchRGBAColor() {
  7697. return matchCall(tokens.rgbaColor, function () {
  7698. return {
  7699. type: 'rgba',
  7700. value: matchListing(matchNumber)
  7701. };
  7702. });
  7703. }
  7704. function matchNumber() {
  7705. return scan(tokens.number)[1];
  7706. }
  7707. function matchDistance() {
  7708. return match('%', tokens.percentageValue, 1) || matchPositionKeyword() || matchLength();
  7709. }
  7710. function matchPositionKeyword() {
  7711. return match('position-keyword', tokens.positionKeywords, 1);
  7712. }
  7713. function matchLength() {
  7714. return match('px', tokens.pixelValue, 1) || match('em', tokens.emValue, 1);
  7715. }
  7716. function match(type, pattern, captureIndex) {
  7717. var captures = scan(pattern);
  7718. if (captures) {
  7719. return {
  7720. type: type,
  7721. value: captures[captureIndex]
  7722. };
  7723. }
  7724. }
  7725. function scan(regexp) {
  7726. var blankCaptures = /^[\n\r\t\s]+/.exec(input);
  7727. if (blankCaptures) {
  7728. consume(blankCaptures[0].length);
  7729. }
  7730. var captures = regexp.exec(input);
  7731. if (captures) {
  7732. consume(captures[0].length);
  7733. }
  7734. return captures;
  7735. }
  7736. function consume(size) {
  7737. input = input.substring(size);
  7738. }
  7739. return function (code) {
  7740. input = code;
  7741. return getAST();
  7742. };
  7743. }();
  7744. function computeLinearGradient(width, height, angle) {
  7745. var rad = deg2rad(angle.value);
  7746. var rx = 0;
  7747. var ry = 0;
  7748. var rcx = rx + width / 2;
  7749. var rcy = ry + height / 2;
  7750. // get the length of gradient line
  7751. // @see https://observablehq.com/@danburzo/css-gradient-line
  7752. var length = Math.abs(width * Math.cos(rad)) + Math.abs(height * Math.sin(rad));
  7753. var x1 = rcx - Math.cos(rad) * length / 2;
  7754. var y1 = rcy - Math.sin(rad) * length / 2;
  7755. var x2 = rcx + Math.cos(rad) * length / 2;
  7756. var y2 = rcy + Math.sin(rad) * length / 2;
  7757. return {
  7758. x1: x1,
  7759. y1: y1,
  7760. x2: x2,
  7761. y2: y2
  7762. };
  7763. }
  7764. function computeRadialGradient(width, height, cx, cy, size) {
  7765. // 'px'
  7766. var x = cx.value;
  7767. var y = cy.value;
  7768. // TODO: 'em'
  7769. // '%'
  7770. if (cx.unit === exports.UnitType.kPercentage) {
  7771. x = cx.value / 100 * width;
  7772. }
  7773. if (cy.unit === exports.UnitType.kPercentage) {
  7774. y = cy.value / 100 * height;
  7775. }
  7776. // default to farthest-side
  7777. var r = Math.max(distanceSquareRoot([0, 0], [x, y]), distanceSquareRoot([0, height], [x, y]), distanceSquareRoot([width, height], [x, y]), distanceSquareRoot([width, 0], [x, y]));
  7778. if (size) {
  7779. if (size instanceof CSSUnitValue) {
  7780. r = size.value;
  7781. } else if (size instanceof CSSKeywordValue) {
  7782. // @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/CSS_Images/Using_CSS_gradients#example_closest-side_for_circles
  7783. if (size.value === 'closest-side') {
  7784. r = Math.min(x, width - x, y, height - y);
  7785. } else if (size.value === 'farthest-side') {
  7786. r = Math.max(x, width - x, y, height - y);
  7787. } else if (size.value === 'closest-corner') {
  7788. r = Math.min(distanceSquareRoot([0, 0], [x, y]), distanceSquareRoot([0, height], [x, y]), distanceSquareRoot([width, height], [x, y]), distanceSquareRoot([width, 0], [x, y]));
  7789. }
  7790. }
  7791. }
  7792. return {
  7793. x: x,
  7794. y: y,
  7795. r: r
  7796. };
  7797. }
  7798. /**
  7799. * 两点之间的距离
  7800. * @param {number} x1 起始点 x
  7801. * @param {number} y1 起始点 y
  7802. * @param {number} x2 结束点 x
  7803. * @param {number} y2 结束点 y
  7804. * @return {number} 距离
  7805. */
  7806. function distance(x1, y1, x2, y2) {
  7807. var dx = x1 - x2;
  7808. var dy = y1 - y2;
  7809. return Math.sqrt(dx * dx + dy * dy);
  7810. }
  7811. function isNumberEqual$1(v1, v2) {
  7812. return Math.abs(v1 - v2) < 0.001;
  7813. }
  7814. function getBBoxByArray(xArr, yArr) {
  7815. var minX = Math.min.apply(Math, xArr);
  7816. var minY = Math.min.apply(Math, yArr);
  7817. var maxX = Math.max.apply(Math, xArr);
  7818. var maxY = Math.max.apply(Math, yArr);
  7819. return {
  7820. x: minX,
  7821. y: minY,
  7822. width: maxX - minX,
  7823. height: maxY - minY
  7824. };
  7825. }
  7826. function piMod(angle) {
  7827. return (angle + Math.PI * 2) % (Math.PI * 2);
  7828. }
  7829. var line = {
  7830. /**
  7831. * 计算线段的包围盒
  7832. * @param {number} x1 起始点 x
  7833. * @param {number} y1 起始点 y
  7834. * @param {number} x2 结束点 x
  7835. * @param {number} y2 结束点 y
  7836. * @return {object} 包围盒对象
  7837. */
  7838. box: function box(x1, y1, x2, y2) {
  7839. return getBBoxByArray([x1, x2], [y1, y2]);
  7840. },
  7841. /**
  7842. * 线段的长度
  7843. * @param {number} x1 起始点 x
  7844. * @param {number} y1 起始点 y
  7845. * @param {number} x2 结束点 x
  7846. * @param {number} y2 结束点 y
  7847. * @return {number} 距离
  7848. */
  7849. length: function length(x1, y1, x2, y2) {
  7850. return distance(x1, y1, x2, y2);
  7851. },
  7852. /**
  7853. * 根据比例获取点
  7854. * @param {number} x1 起始点 x
  7855. * @param {number} y1 起始点 y
  7856. * @param {number} x2 结束点 x
  7857. * @param {number} y2 结束点 y
  7858. * @param {number} t 指定比例
  7859. * @return {object} 包含 x, y 的点
  7860. */
  7861. pointAt: function pointAt(x1, y1, x2, y2, t) {
  7862. return {
  7863. x: (1 - t) * x1 + t * x2,
  7864. y: (1 - t) * y1 + t * y2
  7865. };
  7866. },
  7867. /**
  7868. * 点到线段的距离
  7869. * @param {number} x1 起始点 x
  7870. * @param {number} y1 起始点 y
  7871. * @param {number} x2 结束点 x
  7872. * @param {number} y2 结束点 y
  7873. * @param {number} x 测试点 x
  7874. * @param {number} y 测试点 y
  7875. * @return {number} 距离
  7876. */
  7877. pointDistance: function pointDistance(x1, y1, x2, y2, x, y) {
  7878. // 投影距离 x1, y1 的向量,假设 p, p1, p2 三个点,投影点为 a
  7879. // p1a = p1p.p1p2/|p1p2| * (p1p 的单位向量)
  7880. var cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
  7881. if (cross < 0) {
  7882. return distance(x1, y1, x, y);
  7883. }
  7884. var lengthSquare = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
  7885. if (cross > lengthSquare) {
  7886. return distance(x2, y2, x, y);
  7887. }
  7888. return this.pointToLine(x1, y1, x2, y2, x, y);
  7889. },
  7890. /**
  7891. * 点到直线的距离,而不是点到线段的距离
  7892. * @param {number} x1 起始点 x
  7893. * @param {number} y1 起始点 y
  7894. * @param {number} x2 结束点 x
  7895. * @param {number} y2 结束点 y
  7896. * @param {number} x 测试点 x
  7897. * @param {number} y 测试点 y
  7898. * @return {number} 距离
  7899. */
  7900. pointToLine: function pointToLine(x1, y1, x2, y2, x, y) {
  7901. var d = [x2 - x1, y2 - y1];
  7902. // 如果端点相等,则判定点到点的距离
  7903. if (exactEquals$1(d, [0, 0])) {
  7904. return Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
  7905. }
  7906. var u = [-d[1], d[0]];
  7907. normalize$3(u, u);
  7908. var a = [x - x1, y - y1];
  7909. return Math.abs(dot$1(a, u));
  7910. },
  7911. /**
  7912. * 线段的角度
  7913. * @param {number} x1 起始点 x
  7914. * @param {number} y1 起始点 y
  7915. * @param {number} x2 结束点 x
  7916. * @param {number} y2 结束点 y
  7917. * @return {number} 导数
  7918. */
  7919. tangentAngle: function tangentAngle(x1, y1, x2, y2) {
  7920. return Math.atan2(y2 - y1, x2 - x1);
  7921. }
  7922. };
  7923. var EPSILON$1 = 0.0001;
  7924. /**
  7925. * 使用牛顿切割法求最近的点
  7926. * @param {number[]} xArr 点的 x 数组
  7927. * @param {number[]} yArr 点的 y 数组
  7928. * @param {number} x 指定的点 x
  7929. * @param {number} y 指定的点 y
  7930. * @param {Function} tCallback 差值函数
  7931. */
  7932. function nearestPoint(xArr, yArr, x, y, tCallback, length) {
  7933. var t = -1;
  7934. var d = Infinity;
  7935. var v0 = [x, y];
  7936. var segNum = 20;
  7937. if (length && length > 200) {
  7938. segNum = length / 10;
  7939. }
  7940. var increaseRate = 1 / segNum;
  7941. var interval = increaseRate / 10;
  7942. for (var i = 0; i <= segNum; i++) {
  7943. var _t = i * increaseRate;
  7944. var v1 = [tCallback.apply(void 0, xArr.concat([_t])), tCallback.apply(void 0, yArr.concat([_t]))];
  7945. var d1 = distance(v0[0], v0[1], v1[0], v1[1]);
  7946. if (d1 < d) {
  7947. t = _t;
  7948. d = d1;
  7949. }
  7950. }
  7951. // 提前终止
  7952. if (t === 0) {
  7953. return {
  7954. x: xArr[0],
  7955. y: yArr[0]
  7956. };
  7957. }
  7958. if (t === 1) {
  7959. var count = xArr.length;
  7960. return {
  7961. x: xArr[count - 1],
  7962. y: yArr[count - 1]
  7963. };
  7964. }
  7965. d = Infinity;
  7966. for (var _i = 0; _i < 32; _i++) {
  7967. if (interval < EPSILON$1) {
  7968. break;
  7969. }
  7970. var prev = t - interval;
  7971. var next = t + interval;
  7972. var _v = [tCallback.apply(void 0, xArr.concat([prev])), tCallback.apply(void 0, yArr.concat([prev]))];
  7973. var _d = distance(v0[0], v0[1], _v[0], _v[1]);
  7974. if (prev >= 0 && _d < d) {
  7975. t = prev;
  7976. d = _d;
  7977. } else {
  7978. var v2 = [tCallback.apply(void 0, xArr.concat([next])), tCallback.apply(void 0, yArr.concat([next]))];
  7979. var d2 = distance(v0[0], v0[1], v2[0], v2[1]);
  7980. if (next <= 1 && d2 < d) {
  7981. t = next;
  7982. d = d2;
  7983. } else {
  7984. interval *= 0.5;
  7985. }
  7986. }
  7987. }
  7988. return {
  7989. x: tCallback.apply(void 0, xArr.concat([t])),
  7990. y: tCallback.apply(void 0, yArr.concat([t]))
  7991. };
  7992. }
  7993. // 近似求解 https://community.khronos.org/t/3d-cubic-bezier-segment-length/62363/2
  7994. function snapLength(xArr, yArr) {
  7995. var totalLength = 0;
  7996. var count = xArr.length;
  7997. for (var i = 0; i < count; i++) {
  7998. var x = xArr[i];
  7999. var y = yArr[i];
  8000. var nextX = xArr[(i + 1) % count];
  8001. var nextY = yArr[(i + 1) % count];
  8002. totalLength += distance(x, y, nextX, nextY);
  8003. }
  8004. return totalLength / 2;
  8005. }
  8006. // 差值公式
  8007. function quadraticAt(p0, p1, p2, t) {
  8008. var onet = 1 - t;
  8009. return onet * onet * p0 + 2 * t * onet * p1 + t * t * p2;
  8010. }
  8011. // 求极值
  8012. function extrema(p0, p1, p2) {
  8013. var a = p0 + p2 - 2 * p1;
  8014. if (isNumberEqual$1(a, 0)) {
  8015. return [0.5];
  8016. }
  8017. var rst = (p0 - p1) / a;
  8018. if (rst <= 1 && rst >= 0) {
  8019. return [rst];
  8020. }
  8021. return [];
  8022. }
  8023. function derivativeAt(p0, p1, p2, t) {
  8024. return 2 * (1 - t) * (p1 - p0) + 2 * t * (p2 - p1);
  8025. }
  8026. // 分割贝塞尔曲线
  8027. function divideQuadratic(x1, y1, x2, y2, x3, y3, t) {
  8028. // 划分点
  8029. var xt = quadraticAt(x1, x2, x3, t);
  8030. var yt = quadraticAt(y1, y2, y3, t);
  8031. // 分割的第一条曲线的控制点
  8032. var controlPoint1 = line.pointAt(x1, y1, x2, y2, t);
  8033. // 分割的第二条曲线的控制点
  8034. var controlPoint2 = line.pointAt(x2, y2, x3, y3, t);
  8035. return [[x1, y1, controlPoint1.x, controlPoint1.y, xt, yt], [xt, yt, controlPoint2.x, controlPoint2.y, x3, y3]];
  8036. }
  8037. // 使用迭代法取贝塞尔曲线的长度
  8038. function quadraticLength(x1, y1, x2, y2, x3, y3, iterationCount) {
  8039. if (iterationCount === 0) {
  8040. return (distance(x1, y1, x2, y2) + distance(x2, y2, x3, y3) + distance(x1, y1, x3, y3)) / 2;
  8041. }
  8042. var quadratics = divideQuadratic(x1, y1, x2, y2, x3, y3, 0.5);
  8043. var left = quadratics[0];
  8044. var right = quadratics[1];
  8045. left.push(iterationCount - 1);
  8046. right.push(iterationCount - 1);
  8047. return quadraticLength.apply(void 0, left) + quadraticLength.apply(void 0, right);
  8048. }
  8049. var quadratic = {
  8050. box: function box(x1, y1, x2, y2, x3, y3) {
  8051. var xExtrema = extrema(x1, x2, x3)[0];
  8052. var yExtrema = extrema(y1, y2, y3)[0];
  8053. // 控制点不加入 box 的计算
  8054. var xArr = [x1, x3];
  8055. var yArr = [y1, y3];
  8056. if (xExtrema !== undefined) {
  8057. xArr.push(quadraticAt(x1, x2, x3, xExtrema));
  8058. }
  8059. if (yExtrema !== undefined) {
  8060. yArr.push(quadraticAt(y1, y2, y3, yExtrema));
  8061. }
  8062. return getBBoxByArray(xArr, yArr);
  8063. },
  8064. length: function length(x1, y1, x2, y2, x3, y3) {
  8065. return quadraticLength(x1, y1, x2, y2, x3, y3, 3);
  8066. },
  8067. nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x0, y0) {
  8068. return nearestPoint([x1, x2, x3], [y1, y2, y3], x0, y0, quadraticAt);
  8069. },
  8070. pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x0, y0) {
  8071. var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x0, y0);
  8072. return distance(point.x, point.y, x0, y0);
  8073. },
  8074. interpolationAt: quadraticAt,
  8075. pointAt: function pointAt(x1, y1, x2, y2, x3, y3, t) {
  8076. return {
  8077. x: quadraticAt(x1, x2, x3, t),
  8078. y: quadraticAt(y1, y2, y3, t)
  8079. };
  8080. },
  8081. divide: function divide(x1, y1, x2, y2, x3, y3, t) {
  8082. return divideQuadratic(x1, y1, x2, y2, x3, y3, t);
  8083. },
  8084. tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, t) {
  8085. var dx = derivativeAt(x1, x2, x3, t);
  8086. var dy = derivativeAt(y1, y2, y3, t);
  8087. var angle = Math.atan2(dy, dx);
  8088. return piMod(angle);
  8089. }
  8090. };
  8091. function cubicAt(p0, p1, p2, p3, t) {
  8092. var onet = 1 - t; // t * t * t 的性能大概是 Math.pow(t, 3) 的三倍
  8093. return onet * onet * onet * p0 + 3 * p1 * t * onet * onet + 3 * p2 * t * t * onet + p3 * t * t * t;
  8094. }
  8095. function derivativeAt$1(p0, p1, p2, p3, t) {
  8096. var onet = 1 - t;
  8097. return 3 * (onet * onet * (p1 - p0) + 2 * onet * t * (p2 - p1) + t * t * (p3 - p2));
  8098. }
  8099. function extrema$1(p0, p1, p2, p3) {
  8100. var a = -3 * p0 + 9 * p1 - 9 * p2 + 3 * p3;
  8101. var b = 6 * p0 - 12 * p1 + 6 * p2;
  8102. var c = 3 * p1 - 3 * p0;
  8103. var extremas = [];
  8104. var t1;
  8105. var t2;
  8106. var discSqrt;
  8107. if (isNumberEqual$1(a, 0)) {
  8108. if (!isNumberEqual$1(b, 0)) {
  8109. t1 = -c / b;
  8110. if (t1 >= 0 && t1 <= 1) {
  8111. extremas.push(t1);
  8112. }
  8113. }
  8114. } else {
  8115. var disc = b * b - 4 * a * c;
  8116. if (isNumberEqual$1(disc, 0)) {
  8117. extremas.push(-b / (2 * a));
  8118. } else if (disc > 0) {
  8119. discSqrt = Math.sqrt(disc);
  8120. t1 = (-b + discSqrt) / (2 * a);
  8121. t2 = (-b - discSqrt) / (2 * a);
  8122. if (t1 >= 0 && t1 <= 1) {
  8123. extremas.push(t1);
  8124. }
  8125. if (t2 >= 0 && t2 <= 1) {
  8126. extremas.push(t2);
  8127. }
  8128. }
  8129. }
  8130. return extremas;
  8131. }
  8132. // 分割贝塞尔曲线
  8133. function divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t) {
  8134. // 划分点
  8135. var xt = cubicAt(x1, x2, x3, x4, t);
  8136. var yt = cubicAt(y1, y2, y3, y4, t);
  8137. // 计算两点之间的差值点
  8138. var c1 = line.pointAt(x1, y1, x2, y2, t);
  8139. var c2 = line.pointAt(x2, y2, x3, y3, t);
  8140. var c3 = line.pointAt(x3, y3, x4, y4, t);
  8141. var c12 = line.pointAt(c1.x, c1.y, c2.x, c2.y, t);
  8142. var c23 = line.pointAt(c2.x, c2.y, c3.x, c3.y, t);
  8143. return [[x1, y1, c1.x, c1.y, c12.x, c12.y, xt, yt], [xt, yt, c23.x, c23.y, c3.x, c3.y, x4, y4]];
  8144. }
  8145. // 使用迭代法取贝塞尔曲线的长度,二阶和三阶分开写,更清晰和便于调试
  8146. function cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, iterationCount) {
  8147. if (iterationCount === 0) {
  8148. return snapLength([x1, x2, x3, x4], [y1, y2, y3, y4]);
  8149. }
  8150. var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5);
  8151. var left = [].concat(cubics[0], [iterationCount - 1]);
  8152. var right = [].concat(cubics[1], [iterationCount - 1]);
  8153. return cubicLength.apply(void 0, left) + cubicLength.apply(void 0, right);
  8154. }
  8155. var cubic = {
  8156. extrema: extrema$1,
  8157. box: function box(x1, y1, x2, y2, x3, y3, x4, y4) {
  8158. var xArr = [x1, x4];
  8159. var yArr = [y1, y4];
  8160. var xExtrema = extrema$1(x1, x2, x3, x4);
  8161. var yExtrema = extrema$1(y1, y2, y3, y4);
  8162. for (var i = 0; i < xExtrema.length; i++) {
  8163. xArr.push(cubicAt(x1, x2, x3, x4, xExtrema[i]));
  8164. }
  8165. for (var _i = 0; _i < yExtrema.length; _i++) {
  8166. yArr.push(cubicAt(y1, y2, y3, y4, yExtrema[_i]));
  8167. }
  8168. return getBBoxByArray(xArr, yArr);
  8169. },
  8170. length: function length(x1, y1, x2, y2, x3, y3, x4, y4) {
  8171. // 迭代三次,划分成 8 段求长度
  8172. return cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, 3);
  8173. },
  8174. nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
  8175. return nearestPoint([x1, x2, x3, x4], [y1, y2, y3, y4], x0, y0, cubicAt, length);
  8176. },
  8177. pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
  8178. var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length);
  8179. return distance(point.x, point.y, x0, y0);
  8180. },
  8181. interpolationAt: cubicAt,
  8182. pointAt: function pointAt(x1, y1, x2, y2, x3, y3, x4, y4, t) {
  8183. return {
  8184. x: cubicAt(x1, x2, x3, x4, t),
  8185. y: cubicAt(y1, y2, y3, y4, t)
  8186. };
  8187. },
  8188. divide: function divide(x1, y1, x2, y2, x3, y3, x4, y4, t) {
  8189. return divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t);
  8190. },
  8191. tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, x4, y4, t) {
  8192. var dx = derivativeAt$1(x1, x2, x3, x4, t);
  8193. var dy = derivativeAt$1(y1, y2, y3, y4, t);
  8194. return piMod(Math.atan2(dy, dx));
  8195. }
  8196. };
  8197. /**
  8198. * @fileoverview 椭圆的一些计算,
  8199. * - 周长计算参考:https://www.mathsisfun.com/geometry/ellipse-perimeter.html
  8200. * - 距离计算参考:https://wet-robots.ghost.io/simple-method-for-distance-to-ellipse/
  8201. * @author dxq613@gmail.com
  8202. */
  8203. function copysign(v1, v2) {
  8204. var absv = Math.abs(v1);
  8205. return v2 > 0 ? absv : absv * -1;
  8206. }
  8207. var ellipse = {
  8208. /**
  8209. * 包围盒计算
  8210. * @param {number} x 椭圆中心 x
  8211. * @param {number} y 椭圆中心 y
  8212. * @param {number} rx 椭圆 x 方向半径
  8213. * @param {number} ry 椭圆 y 方向半径
  8214. * @return {object} 包围盒
  8215. */
  8216. box: function box(x, y, rx, ry) {
  8217. return {
  8218. x: x - rx,
  8219. y: y - ry,
  8220. width: rx * 2,
  8221. height: ry * 2
  8222. };
  8223. },
  8224. /**
  8225. * 计算周长,使用近似法
  8226. * @param {number} x 椭圆中心 x
  8227. * @param {number} y 椭圆中心 y
  8228. * @param {number} rx 椭圆 x 方向半径
  8229. * @param {number} ry 椭圆 y 方向半径
  8230. * @return {number} 椭圆周长
  8231. */
  8232. length: function length(x, y, rx, ry) {
  8233. return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
  8234. },
  8235. /**
  8236. * 距离椭圆最近的点
  8237. * @param {number} x 椭圆中心 x
  8238. * @param {number} y 椭圆中心 y
  8239. * @param {number} rx 椭圆 x 方向半径
  8240. * @param {number} ry 椭圆 y 方向半径
  8241. * @param {number} x0 指定的点 x
  8242. * @param {number} y0 指定的点 y
  8243. * @return {object} 椭圆上距离指定点最近的点
  8244. */
  8245. nearestPoint: function nearestPoint(x, y, rx, ry, x0, y0) {
  8246. var a = rx;
  8247. var b = ry;
  8248. // 假如椭圆半径为0则返回圆心
  8249. if (a === 0 || b === 0) {
  8250. return {
  8251. x: x,
  8252. y: y
  8253. };
  8254. }
  8255. // 转换成 0, 0 为中心的椭圆计算
  8256. var relativeX = x0 - x;
  8257. var relativeY = y0 - y;
  8258. var px = Math.abs(relativeX);
  8259. var py = Math.abs(relativeY);
  8260. var squareA = a * a;
  8261. var squareB = b * b;
  8262. // const angle0 = Math.atan2(relativeY, relativeX);
  8263. var t = Math.PI / 4;
  8264. var nearestX = 0; // 椭圆上的任一点
  8265. var nearestY = 0;
  8266. // 迭代 4 次
  8267. for (var i = 0; i < 4; i++) {
  8268. nearestX = a * Math.cos(t);
  8269. nearestY = b * Math.sin(t);
  8270. var ex = (squareA - squareB) * Math.pow(Math.cos(t), 3) / a;
  8271. var ey = (squareB - squareA) * Math.pow(Math.sin(t), 3) / b;
  8272. var rx1 = nearestX - ex;
  8273. var ry1 = nearestY - ey;
  8274. var qx = px - ex;
  8275. var qy = py - ey;
  8276. var r = Math.hypot(ry1, rx1);
  8277. var q = Math.hypot(qy, qx);
  8278. var delta_c = r * Math.asin((rx1 * qy - ry1 * qx) / (r * q));
  8279. var delta_t = delta_c / Math.sqrt(squareA + squareB - nearestX * nearestX - nearestY * nearestY);
  8280. t += delta_t;
  8281. t = Math.min(Math.PI / 2, Math.max(0, t));
  8282. }
  8283. return {
  8284. x: x + copysign(nearestX, relativeX),
  8285. y: y + copysign(nearestY, relativeY)
  8286. };
  8287. },
  8288. /**
  8289. * 点到椭圆最近的距离
  8290. * @param {number} x 椭圆中心 x
  8291. * @param {number} y 椭圆中心 y
  8292. * @param {number} rx 椭圆 x 方向半径
  8293. * @param {number} ry 椭圆 y 方向半径
  8294. * @param {number} x0 指定的点 x
  8295. * @param {number} y0 指定的点 y
  8296. * @return {number} 点到椭圆的距离
  8297. */
  8298. pointDistance: function pointDistance(x, y, rx, ry, x0, y0) {
  8299. var nearestPoint = this.nearestPoint(x, y, rx, ry, x0, y0);
  8300. return distance(nearestPoint.x, nearestPoint.y, x0, y0);
  8301. },
  8302. /**
  8303. * 根据比例获取点
  8304. * @param {number} x 椭圆中心 x
  8305. * @param {number} y 椭圆中心 y
  8306. * @param {number} rx 椭圆 x 方向半径
  8307. * @param {number} ry 椭圆 y 方向半径
  8308. * @param {number} t 指定比例,x轴方向为 0
  8309. * @return {object} 点
  8310. */
  8311. pointAt: function pointAt(x, y, rx, ry, t) {
  8312. var angle = 2 * Math.PI * t; // 按照角度进行计算,而不按照周长计算
  8313. return {
  8314. x: x + rx * Math.cos(angle),
  8315. y: y + ry * Math.sin(angle)
  8316. };
  8317. },
  8318. /**
  8319. * 根据比例计算切线角度
  8320. * @param {number} x 椭圆中心 x
  8321. * @param {number} y 椭圆中心 y
  8322. * @param {number} rx 椭圆 x 方向半径
  8323. * @param {number} ry 椭圆 y 方向半径
  8324. * @param {number} t 指定比例 0 - 1 之间,x轴方向为 0。在 0-1 范围之外是循环还是返回 null,还需要调整
  8325. * @return {number} 角度,在 0 - 2PI 之间
  8326. */
  8327. tangentAngle: function tangentAngle(x, y, rx, ry, t) {
  8328. var angle = 2 * Math.PI * t; // 按照角度进行计算,而不按照周长计算
  8329. // 直接使用 x,y 的导数计算, x' = -rx * sin(t); y' = ry * cos(t);
  8330. var tangentAngle = Math.atan2(ry * Math.cos(angle), -rx * Math.sin(angle));
  8331. // 也可以使用指定点的切线方程计算,成本有些高
  8332. // const point = this.pointAt(0, 0, rx, ry, t); // 椭圆的切线同椭圆的中心不相关
  8333. // let tangentAngle = -1 * Math.atan((ry * ry * point.x) / (rx * rx * point.y));
  8334. // if (angle >= 0 && angle <= Math.PI) {
  8335. // tangentAngle += Math.PI;
  8336. // }
  8337. return piMod(tangentAngle);
  8338. }
  8339. };
  8340. // 偏导数 x
  8341. function derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) {
  8342. return -1 * rx * Math.cos(xRotation) * Math.sin(angle) - ry * Math.sin(xRotation) * Math.cos(angle);
  8343. }
  8344. // 偏导数 y
  8345. function derivativeYAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) {
  8346. return -1 * rx * Math.sin(xRotation) * Math.sin(angle) + ry * Math.cos(xRotation) * Math.cos(angle);
  8347. }
  8348. // x 的极值
  8349. function xExtrema(rx, ry, xRotation) {
  8350. return Math.atan(-ry / rx * Math.tan(xRotation));
  8351. }
  8352. // y 的极值
  8353. function yExtrema(rx, ry, xRotation) {
  8354. return Math.atan(ry / (rx * Math.tan(xRotation)));
  8355. }
  8356. // 根据角度求 x 坐标
  8357. function xAt(cx, cy, rx, ry, xRotation, angle) {
  8358. return rx * Math.cos(xRotation) * Math.cos(angle) - ry * Math.sin(xRotation) * Math.sin(angle) + cx;
  8359. }
  8360. // 根据角度求 y 坐标
  8361. function yAt(cx, cy, rx, ry, xRotation, angle) {
  8362. return rx * Math.sin(xRotation) * Math.cos(angle) + ry * Math.cos(xRotation) * Math.sin(angle) + cy;
  8363. }
  8364. // 获取点在椭圆上的角度
  8365. function getAngle$1(rx, ry, x0, y0) {
  8366. var angle = Math.atan2(y0 * rx, x0 * ry);
  8367. // 转换到 0 - 2PI 内
  8368. return (angle + Math.PI * 2) % (Math.PI * 2);
  8369. }
  8370. // 根据角度获取,x,y
  8371. function getPoint(rx, ry, angle) {
  8372. return {
  8373. x: rx * Math.cos(angle),
  8374. y: ry * Math.sin(angle)
  8375. };
  8376. }
  8377. // 旋转
  8378. function rotate$1(x, y, angle) {
  8379. var cos = Math.cos(angle);
  8380. var sin = Math.sin(angle);
  8381. return [x * cos - y * sin, x * sin + y * cos];
  8382. }
  8383. var arc = {
  8384. /**
  8385. * 计算包围盒
  8386. * @param {number} cx 圆心 x
  8387. * @param {number} cy 圆心 y
  8388. * @param {number} rx x 轴方向的半径
  8389. * @param {number} ry y 轴方向的半径
  8390. * @param {number} xRotation 旋转角度
  8391. * @param {number} startAngle 起始角度
  8392. * @param {number} endAngle 结束角度
  8393. * @return {object} 包围盒对象
  8394. */
  8395. box: function box(cx, cy, rx, ry, xRotation, startAngle, endAngle) {
  8396. var xDim = xExtrema(rx, ry, xRotation);
  8397. var minX = Infinity;
  8398. var maxX = -Infinity;
  8399. var xs = [startAngle, endAngle];
  8400. for (var i = -Math.PI * 2; i <= Math.PI * 2; i += Math.PI) {
  8401. var xAngle = xDim + i;
  8402. if (startAngle < endAngle) {
  8403. if (startAngle < xAngle && xAngle < endAngle) {
  8404. xs.push(xAngle);
  8405. }
  8406. } else {
  8407. if (endAngle < xAngle && xAngle < startAngle) {
  8408. xs.push(xAngle);
  8409. }
  8410. }
  8411. }
  8412. for (var _i = 0; _i < xs.length; _i++) {
  8413. var x = xAt(cx, cy, rx, ry, xRotation, xs[_i]);
  8414. if (x < minX) {
  8415. minX = x;
  8416. }
  8417. if (x > maxX) {
  8418. maxX = x;
  8419. }
  8420. }
  8421. var yDim = yExtrema(rx, ry, xRotation);
  8422. var minY = Infinity;
  8423. var maxY = -Infinity;
  8424. var ys = [startAngle, endAngle];
  8425. for (var _i2 = -Math.PI * 2; _i2 <= Math.PI * 2; _i2 += Math.PI) {
  8426. var yAngle = yDim + _i2;
  8427. if (startAngle < endAngle) {
  8428. if (startAngle < yAngle && yAngle < endAngle) {
  8429. ys.push(yAngle);
  8430. }
  8431. } else {
  8432. if (endAngle < yAngle && yAngle < startAngle) {
  8433. ys.push(yAngle);
  8434. }
  8435. }
  8436. }
  8437. for (var _i3 = 0; _i3 < ys.length; _i3++) {
  8438. var y = yAt(cx, cy, rx, ry, xRotation, ys[_i3]);
  8439. if (y < minY) {
  8440. minY = y;
  8441. }
  8442. if (y > maxY) {
  8443. maxY = y;
  8444. }
  8445. }
  8446. return {
  8447. x: minX,
  8448. y: minY,
  8449. width: maxX - minX,
  8450. height: maxY - minY
  8451. };
  8452. },
  8453. /**
  8454. * 获取圆弧的长度,计算圆弧长度时不考虑旋转角度,
  8455. * 仅跟 rx, ry, startAngle, endAngle 相关
  8456. * @param {number} cx 圆心 x
  8457. * @param {number} cy 圆心 y
  8458. * @param {number} rx x 轴方向的半径
  8459. * @param {number} ry y 轴方向的半径
  8460. * @param {number} xRotation 旋转角度
  8461. * @param {number} startAngle 起始角度
  8462. * @param {number} endAngle 结束角度
  8463. */
  8464. length: function length(cx, cy, rx, ry, xRotation, startAngle, endAngle) {},
  8465. /**
  8466. * 获取指定点到圆弧的最近距离的点
  8467. * @param {number} cx 圆心 x
  8468. * @param {number} cy 圆心 y
  8469. * @param {number} rx x 轴方向的半径
  8470. * @param {number} ry y 轴方向的半径
  8471. * @param {number} xRotation 旋转角度
  8472. * @param {number} startAngle 起始角度
  8473. * @param {number} endAngle 结束角度
  8474. * @param {number} x0 指定点的 x
  8475. * @param {number} y0 指定点的 y
  8476. * @return {object} 到指定点最近距离的点
  8477. */
  8478. nearestPoint: function nearestPoint(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0) {
  8479. // 将最近距离问题转换成到椭圆中心 0,0 没有旋转的椭圆问题
  8480. var relativeVector = rotate$1(x0 - cx, y0 - cy, -xRotation);
  8481. var x1 = relativeVector[0],
  8482. y1 = relativeVector[1];
  8483. // 计算点到椭圆的最近的点
  8484. var relativePoint = ellipse.nearestPoint(0, 0, rx, ry, x1, y1);
  8485. // 获取点在椭圆上的角度
  8486. var angle = getAngle$1(rx, ry, relativePoint.x, relativePoint.y);
  8487. // 点没有在圆弧上
  8488. if (angle < startAngle) {
  8489. // 小于起始圆弧
  8490. relativePoint = getPoint(rx, ry, startAngle);
  8491. } else if (angle > endAngle) {
  8492. // 大于结束圆弧
  8493. relativePoint = getPoint(rx, ry, endAngle);
  8494. }
  8495. // 旋转到 xRotation 的角度
  8496. var vector = rotate$1(relativePoint.x, relativePoint.y, xRotation);
  8497. return {
  8498. x: vector[0] + cx,
  8499. y: vector[1] + cy
  8500. };
  8501. },
  8502. pointDistance: function pointDistance(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0) {
  8503. var nearestPoint = this.nearestPoint(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0);
  8504. return distance(nearestPoint.x, nearestPoint.y, x0, y0);
  8505. },
  8506. pointAt: function pointAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, t) {
  8507. var angle = (endAngle - startAngle) * t + startAngle;
  8508. return {
  8509. x: xAt(cx, cy, rx, ry, xRotation, angle),
  8510. y: yAt(cx, cy, rx, ry, xRotation, angle)
  8511. };
  8512. },
  8513. tangentAngle: function tangentAngle(cx, cy, rx, ry, xRotation, startAngle, endAngle, t) {
  8514. var angle = (endAngle - startAngle) * t + startAngle;
  8515. var dx = derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle);
  8516. var dy = derivativeYAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle);
  8517. return piMod(Math.atan2(dy, dx));
  8518. }
  8519. };
  8520. function analyzePoints(points) {
  8521. // 计算每段的长度和总的长度
  8522. var totalLength = 0;
  8523. var segments = [];
  8524. for (var i = 0; i < points.length - 1; i++) {
  8525. var from = points[i];
  8526. var to = points[i + 1];
  8527. var length = distance(from[0], from[1], to[0], to[1]);
  8528. var seg = {
  8529. from: from,
  8530. to: to,
  8531. length: length
  8532. };
  8533. segments.push(seg);
  8534. totalLength += length;
  8535. }
  8536. return {
  8537. segments: segments,
  8538. totalLength: totalLength
  8539. };
  8540. }
  8541. function lengthOfSegment(points) {
  8542. if (points.length < 2) {
  8543. return 0;
  8544. }
  8545. var totalLength = 0;
  8546. for (var i = 0; i < points.length - 1; i++) {
  8547. var from = points[i];
  8548. var to = points[i + 1];
  8549. totalLength += distance(from[0], from[1], to[0], to[1]);
  8550. }
  8551. return totalLength;
  8552. }
  8553. /**
  8554. * 按照比例在数据片段中获取点
  8555. * @param {array} points 点的集合
  8556. * @param {number} t 百分比 0-1
  8557. * @return {object} 点的坐标
  8558. */
  8559. function pointAtSegments(points, t) {
  8560. // 边界判断
  8561. if (t > 1 || t < 0 || points.length < 2) {
  8562. return null;
  8563. }
  8564. var _analyzePoints = analyzePoints(points),
  8565. segments = _analyzePoints.segments,
  8566. totalLength = _analyzePoints.totalLength;
  8567. // 多个点有可能重合
  8568. if (totalLength === 0) {
  8569. return {
  8570. x: points[0][0],
  8571. y: points[0][1]
  8572. };
  8573. }
  8574. // 计算比例
  8575. var startRatio = 0;
  8576. var point = null;
  8577. for (var i = 0; i < segments.length; i++) {
  8578. var seg = segments[i];
  8579. var from = seg.from,
  8580. to = seg.to;
  8581. var currentRatio = seg.length / totalLength;
  8582. if (t >= startRatio && t <= startRatio + currentRatio) {
  8583. var localRatio = (t - startRatio) / currentRatio;
  8584. point = line.pointAt(from[0], from[1], to[0], to[1], localRatio);
  8585. break;
  8586. }
  8587. startRatio += currentRatio;
  8588. }
  8589. return point;
  8590. }
  8591. /**
  8592. * 按照比例在数据片段中获取切线的角度
  8593. * @param {array} points 点的集合
  8594. * @param {number} t 百分比 0-1
  8595. */
  8596. function angleAtSegments(points, t) {
  8597. // 边界判断
  8598. if (t > 1 || t < 0 || points.length < 2) {
  8599. return 0;
  8600. }
  8601. var _analyzePoints2 = analyzePoints(points),
  8602. segments = _analyzePoints2.segments,
  8603. totalLength = _analyzePoints2.totalLength;
  8604. // 计算比例
  8605. var startRatio = 0;
  8606. var angle = 0;
  8607. for (var i = 0; i < segments.length; i++) {
  8608. var seg = segments[i];
  8609. var from = seg.from,
  8610. to = seg.to;
  8611. var currentRatio = seg.length / totalLength;
  8612. if (t >= startRatio && t <= startRatio + currentRatio) {
  8613. angle = Math.atan2(to[1] - from[1], to[0] - from[0]);
  8614. break;
  8615. }
  8616. startRatio += currentRatio;
  8617. }
  8618. return angle;
  8619. }
  8620. function distanceAtSegment(points, x, y) {
  8621. var minDistance = Infinity;
  8622. for (var i = 0; i < points.length - 1; i++) {
  8623. var point = points[i];
  8624. var nextPoint = points[i + 1];
  8625. var _distance = line.pointDistance(point[0], point[1], nextPoint[0], nextPoint[1], x, y);
  8626. if (_distance < minDistance) {
  8627. minDistance = _distance;
  8628. }
  8629. }
  8630. return minDistance;
  8631. }
  8632. var polyline = {
  8633. /**
  8634. * 计算多折线的包围盒
  8635. * @param {array} points 点的集合 [x,y] 的形式
  8636. * @return {object} 包围盒
  8637. */
  8638. box: function box(points) {
  8639. var xArr = [];
  8640. var yArr = [];
  8641. for (var i = 0; i < points.length; i++) {
  8642. var point = points[i];
  8643. xArr.push(point[0]);
  8644. yArr.push(point[1]);
  8645. }
  8646. return getBBoxByArray(xArr, yArr);
  8647. },
  8648. /**
  8649. * 计算多折线的长度
  8650. * @param {array} points 点的集合 [x,y] 的形式
  8651. * @return {object} 多条边的长度
  8652. */
  8653. length: function length(points) {
  8654. return lengthOfSegment(points);
  8655. },
  8656. /**
  8657. * 根据比例获取多折线的点
  8658. * @param {array} points 点的集合 [x,y] 的形式
  8659. * @param {number} t 在多折线的长度上的比例
  8660. * @return {object} 根据比例值计算出来的点
  8661. */
  8662. pointAt: function pointAt(points, t) {
  8663. return pointAtSegments(points, t);
  8664. },
  8665. /**
  8666. * 指定点到多折线的距离
  8667. * @param {array} points 点的集合 [x,y] 的形式
  8668. * @param {number} x 指定点的 x
  8669. * @param {number} y 指定点的 y
  8670. * @return {number} 点到多折线的距离
  8671. */
  8672. pointDistance: function pointDistance(points, x, y) {
  8673. return distanceAtSegment(points, x, y);
  8674. },
  8675. /**
  8676. * 根据比例获取多折线的切线角度
  8677. * @param {array} points 点的集合 [x,y] 的形式
  8678. * @param {number} t 在多折线的长度上的比例
  8679. * @return {object} 根据比例值计算出来的角度
  8680. */
  8681. tangentAngle: function tangentAngle(points, t) {
  8682. return angleAtSegments(points, t);
  8683. }
  8684. };
  8685. (function (Shape) {
  8686. Shape["GROUP"] = "g";
  8687. Shape["CIRCLE"] = "circle";
  8688. Shape["ELLIPSE"] = "ellipse";
  8689. Shape["IMAGE"] = "image";
  8690. Shape["RECT"] = "rect";
  8691. Shape["LINE"] = "line";
  8692. Shape["POLYLINE"] = "polyline";
  8693. Shape["POLYGON"] = "polygon";
  8694. Shape["TEXT"] = "text";
  8695. Shape["PATH"] = "path";
  8696. Shape["HTML"] = "html";
  8697. Shape["MESH"] = "mesh";
  8698. })(exports.Shape || (exports.Shape = {}));
  8699. function getOrCalculatePathTotalLength(path) {
  8700. if (path.parsedStyle.path.totalLength === 0) {
  8701. path.parsedStyle.path.totalLength = getTotalLength(path.parsedStyle.path.absolutePath);
  8702. }
  8703. return path.parsedStyle.path.totalLength;
  8704. }
  8705. function hasArcOrBezier(path) {
  8706. var hasArc = false;
  8707. var count = path.length;
  8708. for (var i = 0; i < count; i++) {
  8709. var params = path[i];
  8710. var cmd = params[0];
  8711. if (cmd === 'C' || cmd === 'A' || cmd === 'Q') {
  8712. hasArc = true;
  8713. break;
  8714. }
  8715. }
  8716. return hasArc;
  8717. }
  8718. function extractPolygons(pathArray) {
  8719. var polygons = [];
  8720. var polylines = [];
  8721. var points = []; // 防止第一个命令不是 'M'
  8722. for (var i = 0; i < pathArray.length; i++) {
  8723. var params = pathArray[i];
  8724. var cmd = params[0];
  8725. if (cmd === 'M') {
  8726. // 遇到 'M' 判定是否是新数组,新数组中没有点
  8727. if (points.length) {
  8728. // 如果存在点,则说明没有遇到 'Z',开始了一个新的多边形
  8729. polylines.push(points);
  8730. points = []; // 创建新的点
  8731. }
  8732. points.push([params[1], params[2]]);
  8733. } else if (cmd === 'Z') {
  8734. if (points.length) {
  8735. // 存在点
  8736. polygons.push(points);
  8737. points = []; // 开始新的点集合
  8738. }
  8739. // 如果不存在点,同时 'Z',则说明是错误,不处理
  8740. } else {
  8741. points.push([params[1], params[2]]);
  8742. }
  8743. }
  8744. // 说明 points 未放入 polygons 或者 polyline
  8745. // 仅当只有一个 M,没有 Z 时会发生这种情况
  8746. if (points.length > 0) {
  8747. polylines.push(points);
  8748. }
  8749. return {
  8750. polygons: polygons,
  8751. polylines: polylines
  8752. };
  8753. }
  8754. function isSamePoint(point1, point2) {
  8755. return point1[0] === point2[0] && point1[1] === point2[1];
  8756. }
  8757. function getPathBBox(segments, lineWidth) {
  8758. var xArr = [];
  8759. var yArr = [];
  8760. var segmentsWithAngle = [];
  8761. for (var i = 0; i < segments.length; i++) {
  8762. var segment = segments[i];
  8763. var currentPoint = segment.currentPoint,
  8764. params = segment.params,
  8765. prePoint = segment.prePoint;
  8766. var box = void 0;
  8767. switch (segment.command) {
  8768. case 'Q':
  8769. box = quadratic.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4]);
  8770. break;
  8771. case 'C':
  8772. box = cubic.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4], params[5], params[6]);
  8773. break;
  8774. case 'A':
  8775. var arcParams = segment.arcParams;
  8776. box = arc.box(arcParams.cx, arcParams.cy, arcParams.rx, arcParams.ry, arcParams.xRotation, arcParams.startAngle, arcParams.endAngle);
  8777. break;
  8778. default:
  8779. xArr.push(currentPoint[0]);
  8780. yArr.push(currentPoint[1]);
  8781. break;
  8782. }
  8783. if (box) {
  8784. segment.box = box;
  8785. xArr.push(box.x, box.x + box.width);
  8786. yArr.push(box.y, box.y + box.height);
  8787. }
  8788. if (lineWidth && (segment.command === 'L' || segment.command === 'M') && segment.prePoint && segment.nextPoint) {
  8789. segmentsWithAngle.push(segment);
  8790. }
  8791. }
  8792. // bbox calculation should ignore NaN for path attribute
  8793. // ref: https://github.com/antvis/g/issues/210
  8794. // ref: https://github.com/antvis/G2/issues/3109
  8795. xArr = xArr.filter(function (item) {
  8796. return !Number.isNaN(item) && item !== Infinity && item !== -Infinity;
  8797. });
  8798. yArr = yArr.filter(function (item) {
  8799. return !Number.isNaN(item) && item !== Infinity && item !== -Infinity;
  8800. });
  8801. var minX = min(xArr);
  8802. var minY = min(yArr);
  8803. var maxX = max(xArr);
  8804. var maxY = max(yArr);
  8805. if (segmentsWithAngle.length === 0) {
  8806. return {
  8807. x: minX,
  8808. y: minY,
  8809. width: maxX - minX,
  8810. height: maxY - minY
  8811. };
  8812. }
  8813. for (var _i = 0; _i < segmentsWithAngle.length; _i++) {
  8814. var _segment = segmentsWithAngle[_i];
  8815. var _currentPoint = _segment.currentPoint;
  8816. var extra = void 0;
  8817. if (_currentPoint[0] === minX) {
  8818. extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
  8819. minX = minX - extra.xExtra;
  8820. } else if (_currentPoint[0] === maxX) {
  8821. extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
  8822. maxX = maxX + extra.xExtra;
  8823. }
  8824. if (_currentPoint[1] === minY) {
  8825. extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
  8826. minY = minY - extra.yExtra;
  8827. } else if (_currentPoint[1] === maxY) {
  8828. extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
  8829. maxY = maxY + extra.yExtra;
  8830. }
  8831. }
  8832. return {
  8833. x: minX,
  8834. y: minY,
  8835. width: maxX - minX,
  8836. height: maxY - minY
  8837. };
  8838. }
  8839. function getExtraFromSegmentWithAngle(segment, lineWidth) {
  8840. var prePoint = segment.prePoint,
  8841. currentPoint = segment.currentPoint,
  8842. nextPoint = segment.nextPoint;
  8843. var currentAndPre = Math.pow(currentPoint[0] - prePoint[0], 2) + Math.pow(currentPoint[1] - prePoint[1], 2);
  8844. var currentAndNext = Math.pow(currentPoint[0] - nextPoint[0], 2) + Math.pow(currentPoint[1] - nextPoint[1], 2);
  8845. var preAndNext = Math.pow(prePoint[0] - nextPoint[0], 2) + Math.pow(prePoint[1] - nextPoint[1], 2);
  8846. // 以 currentPoint 为顶点的夹角
  8847. var currentAngle = Math.acos((currentAndPre + currentAndNext - preAndNext) / (2 * Math.sqrt(currentAndPre) * Math.sqrt(currentAndNext)));
  8848. // 夹角为空、 0 或 PI 时,不需要计算夹角处的额外宽度
  8849. // 注意: 由于计算精度问题,夹角为 0 的情况计算出来的角度可能是一个很小的值,还需要判断其与 0 是否近似相等
  8850. if (!currentAngle || Math.sin(currentAngle) === 0 || isNumberEqual(currentAngle, 0)) {
  8851. return {
  8852. xExtra: 0,
  8853. yExtra: 0
  8854. };
  8855. }
  8856. var xAngle = Math.abs(Math.atan2(nextPoint[1] - currentPoint[1], nextPoint[0] - currentPoint[0]));
  8857. var yAngle = Math.abs(Math.atan2(nextPoint[0] - currentPoint[0], nextPoint[1] - currentPoint[1]));
  8858. // 将夹角转为锐角
  8859. xAngle = xAngle > Math.PI / 2 ? Math.PI - xAngle : xAngle;
  8860. yAngle = yAngle > Math.PI / 2 ? Math.PI - yAngle : yAngle;
  8861. // 这里不考虑在水平和垂直方向的投影,直接使用最大差值
  8862. // 由于上层统一加减了二分之一线宽,这里需要进行弥补
  8863. var extra = {
  8864. // 水平方向投影
  8865. xExtra: Math.cos(currentAngle / 2 - xAngle) * (lineWidth / 2 * (1 / Math.sin(currentAngle / 2))) - lineWidth / 2 || 0,
  8866. // 垂直方向投影
  8867. yExtra: Math.cos(yAngle - currentAngle / 2) * (lineWidth / 2 * (1 / Math.sin(currentAngle / 2))) - lineWidth / 2 || 0
  8868. };
  8869. return extra;
  8870. }
  8871. // 点对称
  8872. function toSymmetry(point, center) {
  8873. return [center[0] + (center[0] - point[0]), center[1] + (center[1] - point[1])];
  8874. }
  8875. var angleBetween$1 = function angleBetween(v0, v1) {
  8876. var p = v0.x * v1.x + v0.y * v1.y;
  8877. var n = Math.sqrt((Math.pow(v0.x, 2) + Math.pow(v0.y, 2)) * (Math.pow(v1.x, 2) + Math.pow(v1.y, 2)));
  8878. var sign = v0.x * v1.y - v0.y * v1.x < 0 ? -1 : 1;
  8879. var angle = sign * Math.acos(p / n);
  8880. return angle;
  8881. };
  8882. /**
  8883. * @see https://github.com/rveciana/svg-path-properties/blob/b6bd9a322966f6ef7a311872d80c56e3718de861/src/arc.ts#L121
  8884. */
  8885. var pointOnEllipticalArc = function pointOnEllipticalArc(p0, rx, ry, xAxisRotation, largeArcFlag, sweepFlag, p1, t) {
  8886. // In accordance to: http://www.w3.org/TR/SVG/implnote.html#ArcOutOfRangeParameters
  8887. rx = Math.abs(rx);
  8888. ry = Math.abs(ry);
  8889. xAxisRotation = mod(xAxisRotation, 360);
  8890. var xAxisRotationRadians = deg2rad(xAxisRotation);
  8891. // If the endpoints are identical, then this is equivalent to omitting the elliptical arc segment entirely.
  8892. if (p0.x === p1.x && p0.y === p1.y) {
  8893. return {
  8894. x: p0.x,
  8895. y: p0.y,
  8896. ellipticalArcAngle: 0
  8897. }; // Check if angle is correct
  8898. }
  8899. // If rx = 0 or ry = 0 then this arc is treated as a straight line segment joining the endpoints.
  8900. if (rx === 0 || ry === 0) {
  8901. //return this.pointOnLine(p0, p1, t);
  8902. return {
  8903. x: 0,
  8904. y: 0,
  8905. ellipticalArcAngle: 0
  8906. }; // Check if angle is correct
  8907. }
  8908. // Following "Conversion from endpoint to center parameterization"
  8909. // http://www.w3.org/TR/SVG/implnote.html#ArcConversionEndpointToCenter
  8910. // Step #1: Compute transformedPoint
  8911. var dx = (p0.x - p1.x) / 2;
  8912. var dy = (p0.y - p1.y) / 2;
  8913. var transformedPoint = {
  8914. x: Math.cos(xAxisRotationRadians) * dx + Math.sin(xAxisRotationRadians) * dy,
  8915. y: -Math.sin(xAxisRotationRadians) * dx + Math.cos(xAxisRotationRadians) * dy
  8916. };
  8917. // Ensure radii are large enough
  8918. var radiiCheck = Math.pow(transformedPoint.x, 2) / Math.pow(rx, 2) + Math.pow(transformedPoint.y, 2) / Math.pow(ry, 2);
  8919. if (radiiCheck > 1) {
  8920. rx = Math.sqrt(radiiCheck) * rx;
  8921. ry = Math.sqrt(radiiCheck) * ry;
  8922. }
  8923. // Step #2: Compute transformedCenter
  8924. var cSquareNumerator = Math.pow(rx, 2) * Math.pow(ry, 2) - Math.pow(rx, 2) * Math.pow(transformedPoint.y, 2) - Math.pow(ry, 2) * Math.pow(transformedPoint.x, 2);
  8925. var cSquareRootDenom = Math.pow(rx, 2) * Math.pow(transformedPoint.y, 2) + Math.pow(ry, 2) * Math.pow(transformedPoint.x, 2);
  8926. var cRadicand = cSquareNumerator / cSquareRootDenom;
  8927. // Make sure this never drops below zero because of precision
  8928. cRadicand = cRadicand < 0 ? 0 : cRadicand;
  8929. var cCoef = (largeArcFlag !== sweepFlag ? 1 : -1) * Math.sqrt(cRadicand);
  8930. var transformedCenter = {
  8931. x: cCoef * (rx * transformedPoint.y / ry),
  8932. y: cCoef * (-(ry * transformedPoint.x) / rx)
  8933. };
  8934. // Step #3: Compute center
  8935. var center = {
  8936. x: Math.cos(xAxisRotationRadians) * transformedCenter.x - Math.sin(xAxisRotationRadians) * transformedCenter.y + (p0.x + p1.x) / 2,
  8937. y: Math.sin(xAxisRotationRadians) * transformedCenter.x + Math.cos(xAxisRotationRadians) * transformedCenter.y + (p0.y + p1.y) / 2
  8938. };
  8939. // Step #4: Compute start/sweep angles
  8940. // Start angle of the elliptical arc prior to the stretch and rotate operations.
  8941. // Difference between the start and end angles
  8942. var startVector = {
  8943. x: (transformedPoint.x - transformedCenter.x) / rx,
  8944. y: (transformedPoint.y - transformedCenter.y) / ry
  8945. };
  8946. var startAngle = angleBetween$1({
  8947. x: 1,
  8948. y: 0
  8949. }, startVector);
  8950. var endVector = {
  8951. x: (-transformedPoint.x - transformedCenter.x) / rx,
  8952. y: (-transformedPoint.y - transformedCenter.y) / ry
  8953. };
  8954. var sweepAngle = angleBetween$1(startVector, endVector);
  8955. if (!sweepFlag && sweepAngle > 0) {
  8956. sweepAngle -= 2 * Math.PI;
  8957. } else if (sweepFlag && sweepAngle < 0) {
  8958. sweepAngle += 2 * Math.PI;
  8959. }
  8960. // We use % instead of `mod(..)` because we want it to be -360deg to 360deg(but actually in radians)
  8961. sweepAngle %= 2 * Math.PI;
  8962. // From http://www.w3.org/TR/SVG/implnote.html#ArcParameterizationAlternatives
  8963. var angle = startAngle + sweepAngle * t;
  8964. var ellipseComponentX = rx * Math.cos(angle);
  8965. var ellipseComponentY = ry * Math.sin(angle);
  8966. var point = {
  8967. x: Math.cos(xAxisRotationRadians) * ellipseComponentX - Math.sin(xAxisRotationRadians) * ellipseComponentY + center.x,
  8968. y: Math.sin(xAxisRotationRadians) * ellipseComponentX + Math.cos(xAxisRotationRadians) * ellipseComponentY + center.y,
  8969. ellipticalArcStartAngle: startAngle,
  8970. ellipticalArcEndAngle: startAngle + sweepAngle,
  8971. ellipticalArcAngle: angle,
  8972. ellipticalArcCenter: center,
  8973. resultantRx: rx,
  8974. resultantRy: ry
  8975. };
  8976. return point;
  8977. };
  8978. function path2Segments(path) {
  8979. var segments = [];
  8980. var currentPoint = null; // 当前图形
  8981. var nextParams = null; // 下一节点的 path 参数
  8982. var startMovePoint = null; // 开始 M 的点,可能会有多个
  8983. var lastStartMovePointIndex = 0; // 最近一个开始点 M 的索引
  8984. var count = path.length;
  8985. for (var i = 0; i < count; i++) {
  8986. var params = path[i];
  8987. nextParams = path[i + 1];
  8988. var command = params[0];
  8989. // 数学定义上的参数,便于后面的计算
  8990. var segment = {
  8991. command: command,
  8992. prePoint: currentPoint,
  8993. params: params,
  8994. startTangent: null,
  8995. endTangent: null,
  8996. currentPoint: null,
  8997. nextPoint: null,
  8998. arcParams: null,
  8999. box: null,
  9000. cubicParams: null
  9001. };
  9002. switch (command) {
  9003. case 'M':
  9004. startMovePoint = [params[1], params[2]];
  9005. lastStartMovePointIndex = i;
  9006. break;
  9007. case 'A':
  9008. var arcParams = getArcParams(currentPoint, params);
  9009. segment.arcParams = arcParams;
  9010. break;
  9011. }
  9012. if (command === 'Z') {
  9013. // 有了 Z 后,当前节点从开始 M 的点开始
  9014. currentPoint = startMovePoint;
  9015. // 如果当前点的命令为 Z,相当于当前点为最近一个 M 点,则下一个点直接指向最近一个 M 点的下一个点
  9016. nextParams = path[lastStartMovePointIndex + 1];
  9017. } else {
  9018. var len = params.length;
  9019. currentPoint = [params[len - 2], params[len - 1]];
  9020. }
  9021. if (nextParams && nextParams[0] === 'Z') {
  9022. // 如果下一个点的命令为 Z,则下一个点直接指向最近一个 M 点
  9023. nextParams = path[lastStartMovePointIndex];
  9024. if (segments[lastStartMovePointIndex]) {
  9025. // 如果下一个点的命令为 Z,则最近一个 M 点的前一个点为当前点
  9026. segments[lastStartMovePointIndex].prePoint = currentPoint;
  9027. }
  9028. }
  9029. segment.currentPoint = currentPoint;
  9030. // 如果当前点与最近一个 M 点相同,则最近一个 M 点的前一个点为当前点的前一个点
  9031. if (segments[lastStartMovePointIndex] && isSamePoint(currentPoint, segments[lastStartMovePointIndex].currentPoint)) {
  9032. segments[lastStartMovePointIndex].prePoint = segment.prePoint;
  9033. }
  9034. var nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null;
  9035. segment.nextPoint = nextPoint;
  9036. // Add startTangent and endTangent
  9037. var prePoint = segment.prePoint;
  9038. if (['L', 'H', 'V'].includes(command)) {
  9039. segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
  9040. segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
  9041. } else if (command === 'Q') {
  9042. // 二次贝塞尔曲线只有一个控制点
  9043. var cp = [params[1], params[2]];
  9044. // 二次贝塞尔曲线的终点为 currentPoint
  9045. segment.startTangent = [prePoint[0] - cp[0], prePoint[1] - cp[1]];
  9046. segment.endTangent = [currentPoint[0] - cp[0], currentPoint[1] - cp[1]];
  9047. } else if (command === 'T') {
  9048. var preSegment = segments[i - 1];
  9049. var _cp = toSymmetry(preSegment.currentPoint, prePoint);
  9050. if (preSegment.command === 'Q') {
  9051. segment.command = 'Q';
  9052. segment.startTangent = [prePoint[0] - _cp[0], prePoint[1] - _cp[1]];
  9053. segment.endTangent = [currentPoint[0] - _cp[0], currentPoint[1] - _cp[1]];
  9054. } else {
  9055. // @ts-ignore
  9056. segment.command = 'TL';
  9057. segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
  9058. segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
  9059. }
  9060. } else if (command === 'C') {
  9061. // 三次贝塞尔曲线有两个控制点
  9062. var cp1 = [params[1], params[2]];
  9063. var cp2 = [params[3], params[4]];
  9064. segment.startTangent = [prePoint[0] - cp1[0], prePoint[1] - cp1[1]];
  9065. segment.endTangent = [currentPoint[0] - cp2[0], currentPoint[1] - cp2[1]];
  9066. // horizontal line, eg. ['C', 100, 100, 100, 100, 200, 200]
  9067. if (segment.startTangent[0] === 0 && segment.startTangent[1] === 0) {
  9068. segment.startTangent = [cp1[0] - cp2[0], cp1[1] - cp2[1]];
  9069. }
  9070. if (segment.endTangent[0] === 0 && segment.endTangent[1] === 0) {
  9071. segment.endTangent = [cp2[0] - cp1[0], cp2[1] - cp1[1]];
  9072. }
  9073. } else if (command === 'S') {
  9074. var _preSegment = segments[i - 1];
  9075. var _cp2 = toSymmetry(_preSegment.currentPoint, prePoint);
  9076. var _cp3 = [params[1], params[2]];
  9077. if (_preSegment.command === 'C') {
  9078. segment.command = 'C'; // 将 S 命令变换为 C 命令
  9079. segment.startTangent = [prePoint[0] - _cp2[0], prePoint[1] - _cp2[1]];
  9080. segment.endTangent = [currentPoint[0] - _cp3[0], currentPoint[1] - _cp3[1]];
  9081. } else {
  9082. // @ts-ignore
  9083. segment.command = 'SQ'; // 将 S 命令变换为 SQ 命令
  9084. segment.startTangent = [prePoint[0] - _cp3[0], prePoint[1] - _cp3[1]];
  9085. segment.endTangent = [currentPoint[0] - _cp3[0], currentPoint[1] - _cp3[1]];
  9086. }
  9087. } else if (command === 'A') {
  9088. var _getTangentAtRatio = getTangentAtRatio(segment, 0),
  9089. dx1 = _getTangentAtRatio.x,
  9090. dy1 = _getTangentAtRatio.y;
  9091. var _getTangentAtRatio2 = getTangentAtRatio(segment, 1, false),
  9092. dx2 = _getTangentAtRatio2.x,
  9093. dy2 = _getTangentAtRatio2.y;
  9094. segment.startTangent = [dx1, dy1];
  9095. segment.endTangent = [dx2, dy2];
  9096. }
  9097. segments.push(segment);
  9098. }
  9099. return segments;
  9100. }
  9101. /**
  9102. * Use length instead of ratio
  9103. */
  9104. function getTangentAtRatio(segment, ratio, sign) {
  9105. if (sign === void 0) {
  9106. sign = true;
  9107. }
  9108. var _segment$arcParams = segment.arcParams,
  9109. _segment$arcParams$rx = _segment$arcParams.rx,
  9110. rx = _segment$arcParams$rx === void 0 ? 0 : _segment$arcParams$rx,
  9111. _segment$arcParams$ry = _segment$arcParams.ry,
  9112. ry = _segment$arcParams$ry === void 0 ? 0 : _segment$arcParams$ry,
  9113. xRotation = _segment$arcParams.xRotation,
  9114. arcFlag = _segment$arcParams.arcFlag,
  9115. sweepFlag = _segment$arcParams.sweepFlag;
  9116. var p1 = pointOnEllipticalArc({
  9117. x: segment.prePoint[0],
  9118. y: segment.prePoint[1]
  9119. }, rx, ry, xRotation, !!arcFlag, !!sweepFlag, {
  9120. x: segment.currentPoint[0],
  9121. y: segment.currentPoint[1]
  9122. }, ratio);
  9123. var p2 = pointOnEllipticalArc({
  9124. x: segment.prePoint[0],
  9125. y: segment.prePoint[1]
  9126. }, rx, ry, xRotation, !!arcFlag, !!sweepFlag, {
  9127. x: segment.currentPoint[0],
  9128. y: segment.currentPoint[1]
  9129. }, sign ? ratio + 0.005 : ratio - 0.005);
  9130. var xDist = p2.x - p1.x;
  9131. var yDist = p2.y - p1.y;
  9132. var dist = Math.sqrt(xDist * xDist + yDist * yDist);
  9133. return {
  9134. x: -xDist / dist,
  9135. y: -yDist / dist
  9136. };
  9137. }
  9138. // 向量长度
  9139. function vMag(v) {
  9140. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  9141. }
  9142. // u.v/|u||v|,计算夹角的余弦值
  9143. function vRatio(u, v) {
  9144. // 当存在一个向量的长度为 0 时,夹角也为 0,即夹角的余弦值为 1
  9145. return vMag(u) * vMag(v) ? (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v)) : 1;
  9146. }
  9147. // 向量角度
  9148. function vAngle(u, v) {
  9149. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
  9150. }
  9151. function getArcParams(startPoint, params) {
  9152. var rx = params[1];
  9153. var ry = params[2];
  9154. var xRotation = mod(deg2rad(params[3]), Math.PI * 2);
  9155. var arcFlag = params[4];
  9156. var sweepFlag = params[5];
  9157. // 弧形起点坐标
  9158. var x1 = startPoint[0];
  9159. var y1 = startPoint[1];
  9160. // 弧形终点坐标
  9161. var x2 = params[6];
  9162. var y2 = params[7];
  9163. var xp = Math.cos(xRotation) * (x1 - x2) / 2.0 + Math.sin(xRotation) * (y1 - y2) / 2.0;
  9164. var yp = -1 * Math.sin(xRotation) * (x1 - x2) / 2.0 + Math.cos(xRotation) * (y1 - y2) / 2.0;
  9165. var lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry);
  9166. if (lambda > 1) {
  9167. rx *= Math.sqrt(lambda);
  9168. ry *= Math.sqrt(lambda);
  9169. }
  9170. var diff = rx * rx * (yp * yp) + ry * ry * (xp * xp);
  9171. var f = diff ? Math.sqrt((rx * rx * (ry * ry) - diff) / diff) : 1;
  9172. if (arcFlag === sweepFlag) {
  9173. f *= -1;
  9174. }
  9175. if (isNaN(f)) {
  9176. f = 0;
  9177. }
  9178. // 旋转前的起点坐标,且当长半轴和短半轴的长度为 0 时,坐标按 (0, 0) 处理
  9179. var cxp = ry ? f * rx * yp / ry : 0;
  9180. var cyp = rx ? f * -ry * xp / rx : 0;
  9181. // 椭圆圆心坐标
  9182. var cx = (x1 + x2) / 2.0 + Math.cos(xRotation) * cxp - Math.sin(xRotation) * cyp;
  9183. var cy = (y1 + y2) / 2.0 + Math.sin(xRotation) * cxp + Math.cos(xRotation) * cyp;
  9184. // 起始点的单位向量
  9185. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  9186. // 终止点的单位向量
  9187. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  9188. // 计算起始点和圆心的连线,与 x 轴正方向的夹角
  9189. var theta = vAngle([1, 0], u);
  9190. // 计算圆弧起始点和终止点与椭圆圆心连线的夹角
  9191. var dTheta = vAngle(u, v);
  9192. if (vRatio(u, v) <= -1) {
  9193. dTheta = Math.PI;
  9194. }
  9195. if (vRatio(u, v) >= 1) {
  9196. dTheta = 0;
  9197. }
  9198. if (sweepFlag === 0 && dTheta > 0) {
  9199. dTheta = dTheta - 2 * Math.PI;
  9200. }
  9201. if (sweepFlag === 1 && dTheta < 0) {
  9202. dTheta = dTheta + 2 * Math.PI;
  9203. }
  9204. return {
  9205. cx: cx,
  9206. cy: cy,
  9207. // 弧形的起点和终点相同时,长轴和短轴的长度按 0 处理
  9208. rx: isSamePoint(startPoint, [x2, y2]) ? 0 : rx,
  9209. ry: isSamePoint(startPoint, [x2, y2]) ? 0 : ry,
  9210. startAngle: theta,
  9211. endAngle: theta + dTheta,
  9212. xRotation: xRotation,
  9213. arcFlag: arcFlag,
  9214. sweepFlag: sweepFlag
  9215. };
  9216. }
  9217. function commandsToPathString(commands, object, transform) {
  9218. var _object$parsedStyle = object.parsedStyle,
  9219. _object$parsedStyle$d = _object$parsedStyle.defX,
  9220. defX = _object$parsedStyle$d === void 0 ? 0 : _object$parsedStyle$d,
  9221. _object$parsedStyle$d2 = _object$parsedStyle.defY,
  9222. defY = _object$parsedStyle$d2 === void 0 ? 0 : _object$parsedStyle$d2;
  9223. return commands.reduce(function (prev, cur) {
  9224. var path = '';
  9225. if (cur[0] === 'M' || cur[0] === 'L') {
  9226. var p = fromValues$2(cur[1] - defX, cur[2] - defY, 0);
  9227. if (transform) {
  9228. transformMat4(p, p, transform);
  9229. }
  9230. path = "" + cur[0] + p[0] + "," + p[1];
  9231. } else if (cur[0] === 'Z') {
  9232. path = cur[0];
  9233. } else if (cur[0] === 'C') {
  9234. var p1 = fromValues$2(cur[1] - defX, cur[2] - defY, 0);
  9235. var p2 = fromValues$2(cur[3] - defX, cur[4] - defY, 0);
  9236. var p3 = fromValues$2(cur[5] - defX, cur[6] - defY, 0);
  9237. if (transform) {
  9238. transformMat4(p1, p1, transform);
  9239. transformMat4(p2, p2, transform);
  9240. transformMat4(p3, p3, transform);
  9241. }
  9242. path = "" + cur[0] + p1[0] + "," + p1[1] + "," + p2[0] + "," + p2[1] + "," + p3[0] + "," + p3[1];
  9243. } else if (cur[0] === 'A') {
  9244. var c = fromValues$2(cur[6] - defX, cur[7] - defY, 0);
  9245. if (transform) {
  9246. transformMat4(c, c, transform);
  9247. }
  9248. path = "" + cur[0] + cur[1] + "," + cur[2] + "," + cur[3] + "," + cur[4] + "," + cur[5] + "," + c[0] + "," + c[1];
  9249. } else if (cur[0] === 'Q') {
  9250. var _p = fromValues$2(cur[1] - defX, cur[2] - defY, 0);
  9251. var _p2 = fromValues$2(cur[3] - defX, cur[4] - defY, 0);
  9252. if (transform) {
  9253. transformMat4(_p, _p, transform);
  9254. transformMat4(_p2, _p2, transform);
  9255. }
  9256. path = "" + cur[0] + cur[1] + "," + cur[2] + "," + cur[3] + "," + cur[4] + "}";
  9257. }
  9258. return prev += path;
  9259. }, '');
  9260. }
  9261. function lineToCommands(x1, y1, x2, y2) {
  9262. return [['M', x1, y1], ['L', x2, y2]];
  9263. }
  9264. function ellipseToCommands(rx, ry, cx, cy) {
  9265. var factor = (-1 + Math.sqrt(2)) / 3 * 4;
  9266. var dx = rx * factor;
  9267. var dy = ry * factor;
  9268. var left = cx - rx;
  9269. var right = cx + rx;
  9270. var top = cy - ry;
  9271. var bottom = cy + ry;
  9272. return [['M', left, cy], ['C', left, cy - dy, cx - dx, top, cx, top], ['C', cx + dx, top, right, cy - dy, right, cy], ['C', right, cy + dy, cx + dx, bottom, cx, bottom], ['C', cx - dx, bottom, left, cy + dy, left, cy], ['Z']];
  9273. }
  9274. function polygonToCommands(points, closed) {
  9275. var result = points.map(function (point, i) {
  9276. return [i === 0 ? 'M' : 'L', point[0], point[1]];
  9277. });
  9278. if (closed) {
  9279. result.push(['Z']);
  9280. }
  9281. return result;
  9282. }
  9283. function rectToCommands(width, height, x, y, radius) {
  9284. // @see https://gist.github.com/danielpquinn/dd966af424030d47e476
  9285. if (radius) {
  9286. var tlr = radius[0],
  9287. trr = radius[1],
  9288. brr = radius[2],
  9289. blr = radius[3];
  9290. var signX = width > 0 ? 1 : -1;
  9291. var signY = height > 0 ? 1 : -1;
  9292. // sweep-flag @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths#arcs
  9293. var sweepFlag = signX + signY !== 0 ? 1 : 0;
  9294. return [['M', signX * tlr + x, y], ['L', width - signX * trr + x, y], trr ? ['A', trr, trr, 0, 0, sweepFlag, width + x, signY * trr + y] : null, ['L', width + x, height - signY * brr + y], brr ? ['A', brr, brr, 0, 0, sweepFlag, width + x - signX * brr, height + y] : null, ['L', x + signX * blr, height + y], blr ? ['A', blr, blr, 0, 0, sweepFlag, x, height + y - signY * blr] : null, ['L', x, signY * tlr + y], tlr ? ['A', tlr, tlr, 0, 0, sweepFlag, signX * tlr + x, y] : null, ['Z']].filter(function (command) {
  9295. return command;
  9296. });
  9297. }
  9298. return [['M', x, y], ['L', x + width, y], ['L', x + width, y + height], ['L', x, y + height], ['Z']];
  9299. }
  9300. /**
  9301. * convert object to path, should account for:
  9302. * * transform & origin
  9303. * * anchor
  9304. * * lineWidth
  9305. */
  9306. function convertToPath(object, transform) {
  9307. if (transform === void 0) {
  9308. transform = object.getLocalTransform();
  9309. }
  9310. var commands = [];
  9311. switch (object.nodeName) {
  9312. case exports.Shape.LINE:
  9313. var _object$parsedStyle2 = object.parsedStyle,
  9314. x1 = _object$parsedStyle2.x1,
  9315. y1 = _object$parsedStyle2.y1,
  9316. x2 = _object$parsedStyle2.x2,
  9317. y2 = _object$parsedStyle2.y2;
  9318. commands = lineToCommands(x1, y1, x2, y2);
  9319. break;
  9320. case exports.Shape.CIRCLE:
  9321. {
  9322. var _object$parsedStyle3 = object.parsedStyle,
  9323. r = _object$parsedStyle3.r,
  9324. cx = _object$parsedStyle3.cx,
  9325. cy = _object$parsedStyle3.cy;
  9326. commands = ellipseToCommands(r, r, cx, cy);
  9327. break;
  9328. }
  9329. case exports.Shape.ELLIPSE:
  9330. {
  9331. var _object$parsedStyle4 = object.parsedStyle,
  9332. rx = _object$parsedStyle4.rx,
  9333. ry = _object$parsedStyle4.ry,
  9334. _cx = _object$parsedStyle4.cx,
  9335. _cy = _object$parsedStyle4.cy;
  9336. commands = ellipseToCommands(rx, ry, _cx, _cy);
  9337. break;
  9338. }
  9339. case exports.Shape.POLYLINE:
  9340. case exports.Shape.POLYGON:
  9341. var points = object.parsedStyle.points;
  9342. commands = polygonToCommands(points.points, object.nodeName === exports.Shape.POLYGON);
  9343. break;
  9344. case exports.Shape.RECT:
  9345. var _object$parsedStyle5 = object.parsedStyle,
  9346. width = _object$parsedStyle5.width,
  9347. height = _object$parsedStyle5.height,
  9348. x = _object$parsedStyle5.x,
  9349. y = _object$parsedStyle5.y,
  9350. radius = _object$parsedStyle5.radius;
  9351. var hasRadius = radius && radius.some(function (r) {
  9352. return r !== 0;
  9353. });
  9354. commands = rectToCommands(width, height, x, y, hasRadius && radius.map(function (r) {
  9355. return clamp(r, 0, Math.min(Math.abs(width) / 2, Math.abs(height) / 2));
  9356. }));
  9357. break;
  9358. case exports.Shape.PATH:
  9359. var absolutePath = object.parsedStyle.path.absolutePath;
  9360. commands = [].concat(absolutePath);
  9361. break;
  9362. }
  9363. if (commands.length) {
  9364. return commandsToPathString(commands, object, transform);
  9365. }
  9366. }
  9367. function translatePathToString(absolutePath, defX, defY, startOffsetX, startOffsetY, endOffsetX, endOffsetY) {
  9368. if (startOffsetX === void 0) {
  9369. startOffsetX = 0;
  9370. }
  9371. if (startOffsetY === void 0) {
  9372. startOffsetY = 0;
  9373. }
  9374. if (endOffsetX === void 0) {
  9375. endOffsetX = 0;
  9376. }
  9377. if (endOffsetY === void 0) {
  9378. endOffsetY = 0;
  9379. }
  9380. var newValue = absolutePath.map(function (params, i) {
  9381. var command = params[0];
  9382. var nextSegment = absolutePath[i + 1];
  9383. var useStartOffset = i === 0 && (startOffsetX !== 0 || startOffsetY !== 0);
  9384. var useEndOffset = (i === absolutePath.length - 1 || nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z')) && endOffsetX !== 0 && endOffsetY !== 0;
  9385. switch (command) {
  9386. case 'M':
  9387. // Use start marker offset
  9388. if (useStartOffset) {
  9389. return "M " + (params[1] - defX + startOffsetX) + "," + (params[2] - defY + startOffsetY) + " L " + (params[1] - defX) + "," + (params[2] - defY);
  9390. } else {
  9391. return "M " + (params[1] - defX) + "," + (params[2] - defY);
  9392. }
  9393. case 'L':
  9394. return "L " + (params[1] - defX + (useEndOffset ? endOffsetX : 0)) + "," + (params[2] - defY + (useEndOffset ? endOffsetY : 0));
  9395. case 'Q':
  9396. return "Q " + (params[1] - defX) + " " + (params[2] - defY) + "," + (params[3] - defX) + " " + (params[4] - defY) + (useEndOffset ? " L " + (params[3] - defX + endOffsetX) + "," + (params[4] - defY + endOffsetY) : '');
  9397. case 'C':
  9398. return "C " + (params[1] - defX) + " " + (params[2] - defY) + "," + (params[3] - defX) + " " + (params[4] - defY) + "," + (params[5] - defX) + " " + (params[6] - defY) + (useEndOffset ? " L " + (params[5] - defX + endOffsetX) + "," + (params[6] - defY + endOffsetY) : '');
  9399. case 'A':
  9400. return "A " + params[1] + " " + params[2] + " " + params[3] + " " + params[4] + " " + params[5] + " " + (params[6] - defX) + " " + (params[7] - defY) + (useEndOffset ? " L " + (params[6] - defX + endOffsetX) + "," + (params[7] - defY + endOffsetY) : '');
  9401. case 'Z':
  9402. return 'Z';
  9403. }
  9404. }).join(' ');
  9405. if (~newValue.indexOf('NaN')) {
  9406. return '';
  9407. }
  9408. return newValue;
  9409. }
  9410. function isFillOrStrokeAffected(pointerEvents, fill, stroke) {
  9411. // account for pointerEvents
  9412. // @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
  9413. var hasFill = false;
  9414. var hasStroke = false;
  9415. var isFillOtherThanNone = !!fill && !fill.isNone;
  9416. var isStrokeOtherThanNone = !!stroke && !stroke.isNone;
  9417. if (pointerEvents === 'visiblepainted' || pointerEvents === 'painted' || pointerEvents === 'auto') {
  9418. hasFill = isFillOtherThanNone;
  9419. hasStroke = isStrokeOtherThanNone;
  9420. } else if (pointerEvents === 'visiblefill' || pointerEvents === 'fill') {
  9421. hasFill = true;
  9422. } else if (pointerEvents === 'visiblestroke' || pointerEvents === 'stroke') {
  9423. hasStroke = true;
  9424. } else if (pointerEvents === 'visible' || pointerEvents === 'all') {
  9425. // The values of the fill and stroke do not affect event processing.
  9426. hasFill = true;
  9427. hasStroke = true;
  9428. }
  9429. return [hasFill, hasStroke];
  9430. }
  9431. var AsyncParallelHook = /*#__PURE__*/function () {
  9432. function AsyncParallelHook() {
  9433. this.callbacks = [];
  9434. }
  9435. var _proto = AsyncParallelHook.prototype;
  9436. _proto.getCallbacksNum = function getCallbacksNum() {
  9437. return this.callbacks.length;
  9438. };
  9439. _proto.tapPromise = function tapPromise(options, fn) {
  9440. this.callbacks.push(fn);
  9441. };
  9442. _proto.promise = function promise() {
  9443. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  9444. args[_key] = arguments[_key];
  9445. }
  9446. return Promise.all(this.callbacks.map(function (callback) {
  9447. return callback.apply(void 0, args);
  9448. }));
  9449. };
  9450. return AsyncParallelHook;
  9451. }();
  9452. var AsyncSeriesWaterfallHook = /*#__PURE__*/function () {
  9453. function AsyncSeriesWaterfallHook() {
  9454. this.callbacks = [];
  9455. }
  9456. var _proto = AsyncSeriesWaterfallHook.prototype;
  9457. _proto.tapPromise = function tapPromise(options, fn) {
  9458. this.callbacks.push(fn);
  9459. };
  9460. _proto.promise = /*#__PURE__*/function () {
  9461. var _promise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
  9462. var _this$callbacks,
  9463. result,
  9464. i,
  9465. callback,
  9466. _args = arguments;
  9467. return _regeneratorRuntime().wrap(function _callee$(_context) {
  9468. while (1) switch (_context.prev = _context.next) {
  9469. case 0:
  9470. if (!this.callbacks.length) {
  9471. _context.next = 14;
  9472. break;
  9473. }
  9474. _context.next = 3;
  9475. return (_this$callbacks = this.callbacks)[0].apply(_this$callbacks, _args);
  9476. case 3:
  9477. result = _context.sent;
  9478. i = 0;
  9479. case 5:
  9480. if (!(i < this.callbacks.length - 1)) {
  9481. _context.next = 13;
  9482. break;
  9483. }
  9484. callback = this.callbacks[i]; // @ts-ignore
  9485. _context.next = 9;
  9486. return callback(result);
  9487. case 9:
  9488. result = _context.sent;
  9489. case 10:
  9490. i++;
  9491. _context.next = 5;
  9492. break;
  9493. case 13:
  9494. return _context.abrupt("return", result);
  9495. case 14:
  9496. return _context.abrupt("return", null);
  9497. case 15:
  9498. case "end":
  9499. return _context.stop();
  9500. }
  9501. }, _callee, this);
  9502. }));
  9503. function promise() {
  9504. return _promise.apply(this, arguments);
  9505. }
  9506. return promise;
  9507. }();
  9508. return AsyncSeriesWaterfallHook;
  9509. }();
  9510. var SyncHook = /*#__PURE__*/function () {
  9511. function SyncHook() {
  9512. this.callbacks = [];
  9513. }
  9514. var _proto = SyncHook.prototype;
  9515. _proto.tap = function tap(options, fn) {
  9516. this.callbacks.push(fn);
  9517. };
  9518. _proto.call = function call() {
  9519. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  9520. args[_key] = arguments[_key];
  9521. }
  9522. this.callbacks.forEach(function (callback) {
  9523. callback.apply(void 0, args);
  9524. });
  9525. };
  9526. return SyncHook;
  9527. }();
  9528. var SyncWaterfallHook = /*#__PURE__*/function () {
  9529. function SyncWaterfallHook() {
  9530. this.callbacks = [];
  9531. }
  9532. var _proto = SyncWaterfallHook.prototype;
  9533. _proto.tap = function tap(options, fn) {
  9534. this.callbacks.push(fn);
  9535. };
  9536. _proto.call = function call() {
  9537. if (this.callbacks.length) {
  9538. var _this$callbacks;
  9539. var result = (_this$callbacks = this.callbacks)[0].apply(_this$callbacks, arguments);
  9540. for (var i = 0; i < this.callbacks.length - 1; i++) {
  9541. var callback = this.callbacks[i];
  9542. // @ts-ignore
  9543. result = callback(result);
  9544. }
  9545. return result;
  9546. }
  9547. return null;
  9548. };
  9549. return SyncWaterfallHook;
  9550. }();
  9551. var genericFontFamilies = ['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy', 'system-ui'];
  9552. var stringRegExp = /([\"\'])[^\'\"]+\1/;
  9553. function toFontString(attributes) {
  9554. var fontSize = attributes.fontSize,
  9555. fontFamily = attributes.fontFamily,
  9556. fontStyle = attributes.fontStyle,
  9557. fontVariant = attributes.fontVariant,
  9558. fontWeight = attributes.fontWeight;
  9559. // build canvas api font setting from individual components. Convert a numeric this.fontSize to px
  9560. // const fontSizeString: string = isNumber(fontSize) ? `${fontSize}px` : fontSize.toString();
  9561. var fontSizeString = isNumber(fontSize) && fontSize + "px" || '16px';
  9562. // Clean-up fontFamily property by quoting each font name
  9563. // this will support font names with spaces
  9564. var fontFamilies = fontFamily.split(',');
  9565. for (var i = fontFamilies.length - 1; i >= 0; i--) {
  9566. // Trim any extra white-space
  9567. var _fontFamily = fontFamilies[i].trim();
  9568. // Check if font already contains strings
  9569. if (!stringRegExp.test(_fontFamily) && genericFontFamilies.indexOf(_fontFamily) < 0) {
  9570. _fontFamily = "\"" + _fontFamily + "\"";
  9571. }
  9572. fontFamilies[i] = _fontFamily;
  9573. }
  9574. return fontStyle + " " + fontVariant + " " + fontWeight + " " + fontSizeString + " " + fontFamilies.join(',');
  9575. }
  9576. /**
  9577. * Thanks for following contributor of codes
  9578. * https://gist.github.com/1866474
  9579. * http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  9580. * http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
  9581. * https://github.com/Financial-Times/polyfill-library/blob/master/polyfills/requestAnimationFrame/polyfill.js
  9582. **/
  9583. var uId = 1;
  9584. var uniqueId = function uniqueId() {
  9585. return uId++;
  9586. };
  9587. // We use `self` instead of `window` for `WebWorker` support.
  9588. var root = typeof self === 'object' && self.self == self ? self :
  9589. // @ts-ignore
  9590. typeof global === 'object' && global.global == global ?
  9591. // @ts-ignore
  9592. global : {};
  9593. var nowOffset = Date.now();
  9594. // use performance api if exist, otherwise use Date.now.
  9595. // Date.now polyfill required.
  9596. var pnow = function pnow() {
  9597. if (root.performance && typeof root.performance.now === 'function') {
  9598. return root.performance.now();
  9599. }
  9600. // fallback
  9601. return Date.now() - nowOffset;
  9602. };
  9603. var reservedCBs = {};
  9604. var lastTime = Date.now();
  9605. var polyfillRaf = function polyfillRaf(callback) {
  9606. if (typeof callback !== 'function') {
  9607. throw new TypeError(callback + ' is not a function');
  9608. }
  9609. var currentTime = Date.now();
  9610. var gap = currentTime - lastTime;
  9611. var delay = gap > 16 ? 0 : 16 - gap;
  9612. var id = uniqueId();
  9613. reservedCBs[id] = callback;
  9614. // keys(reservedCBs).length > 1 의미는 이미 setTimeout 이 걸려있는 경우.
  9615. // 함께 callback 이 실행될 수 있게 reservedCBs 에만 추가해주고 return
  9616. if (Object.keys(reservedCBs).length > 1) return id;
  9617. setTimeout(function () {
  9618. lastTime = currentTime;
  9619. var copied = reservedCBs;
  9620. reservedCBs = {};
  9621. Object.keys(copied).forEach(function (key) {
  9622. return copied[key](pnow());
  9623. });
  9624. }, delay);
  9625. return id;
  9626. };
  9627. var polyfillCaf = function polyfillCaf(id) {
  9628. delete reservedCBs[id];
  9629. };
  9630. var vendorPrefixes = ['', 'webkit', 'moz', 'ms', 'o'];
  9631. var getRequestAnimationFrame = function getRequestAnimationFrame(vp) {
  9632. if (typeof vp !== 'string') return polyfillRaf;
  9633. if (vp === '') return root['requestAnimationFrame'];
  9634. return root[vp + 'RequestAnimationFrame'];
  9635. };
  9636. var getCancelAnimationFrame = function getCancelAnimationFrame(vp) {
  9637. if (typeof vp !== 'string') return polyfillCaf;
  9638. if (vp === '') return root['cancelAnimationFrame'];
  9639. return root[vp + 'CancelAnimationFrame'] || root[vp + 'CancelRequestAnimationFrame'];
  9640. };
  9641. var find = function find(arr, predicate) {
  9642. var i = 0;
  9643. while (arr[i] !== void 0) {
  9644. if (predicate(arr[i])) return arr[i];
  9645. i = i + 1;
  9646. }
  9647. };
  9648. var vp = find(vendorPrefixes, function (vp) {
  9649. return !!getRequestAnimationFrame(vp);
  9650. });
  9651. var raf = getRequestAnimationFrame(vp);
  9652. var caf = getCancelAnimationFrame(vp);
  9653. root.requestAnimationFrame = raf;
  9654. root.cancelAnimationFrame = caf;
  9655. var regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
  9656. var regexRG = /^r\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)\s*(.*)/i;
  9657. var regexPR = /^p\s*\(\s*([axyn])\s*\)\s*(.*)/i;
  9658. var regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/gi;
  9659. function spaceColorStops(colorStops) {
  9660. var _colorStops$length;
  9661. var length = colorStops.length;
  9662. colorStops[length - 1].length = (_colorStops$length = colorStops[length - 1].length) !== null && _colorStops$length !== void 0 ? _colorStops$length : {
  9663. type: '%',
  9664. value: '100'
  9665. };
  9666. if (length > 1) {
  9667. var _colorStops$0$length;
  9668. colorStops[0].length = (_colorStops$0$length = colorStops[0].length) !== null && _colorStops$0$length !== void 0 ? _colorStops$0$length : {
  9669. type: '%',
  9670. value: '0'
  9671. };
  9672. }
  9673. var previousIndex = 0;
  9674. var previousOffset = Number(colorStops[0].length.value);
  9675. for (var i = 1; i < length; i++) {
  9676. var _colorStops$i$length;
  9677. // support '%' & 'px'
  9678. var offset = (_colorStops$i$length = colorStops[i].length) === null || _colorStops$i$length === void 0 ? void 0 : _colorStops$i$length.value;
  9679. if (!isNil(offset) && !isNil(previousOffset)) {
  9680. for (var j = 1; j < i - previousIndex; j++) colorStops[previousIndex + j].length = {
  9681. type: '%',
  9682. value: "" + (previousOffset + (Number(offset) - previousOffset) * j / (i - previousIndex))
  9683. };
  9684. previousIndex = i;
  9685. previousOffset = Number(offset);
  9686. }
  9687. }
  9688. }
  9689. // The position of the gradient line's starting point.
  9690. // different from CSS side(to top) @see https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient#values
  9691. var SideOrCornerToDegMap = {
  9692. left: 270 - 90,
  9693. top: 0 - 90,
  9694. bottom: 180 - 90,
  9695. right: 90 - 90,
  9696. 'left top': 315 - 90,
  9697. 'top left': 315 - 90,
  9698. 'left bottom': 225 - 90,
  9699. 'bottom left': 225 - 90,
  9700. 'right top': 45 - 90,
  9701. 'top right': 45 - 90,
  9702. 'right bottom': 135 - 90,
  9703. 'bottom right': 135 - 90
  9704. };
  9705. var angleToDeg = memoize(function (orientation) {
  9706. var angle;
  9707. if (orientation.type === 'angular') {
  9708. angle = Number(orientation.value);
  9709. } else {
  9710. angle = SideOrCornerToDegMap[orientation.value] || 0;
  9711. }
  9712. return getOrCreateUnitValue(angle, 'deg');
  9713. });
  9714. var positonToCSSUnitValue = memoize(function (position) {
  9715. var cx = 50;
  9716. var cy = 50;
  9717. var unitX = '%';
  9718. var unitY = '%';
  9719. if ((position === null || position === void 0 ? void 0 : position.type) === 'position') {
  9720. var _position$value = position.value,
  9721. x = _position$value.x,
  9722. y = _position$value.y;
  9723. if ((x === null || x === void 0 ? void 0 : x.type) === 'position-keyword') {
  9724. if (x.value === 'left') {
  9725. cx = 0;
  9726. } else if (x.value === 'center') {
  9727. cx = 50;
  9728. } else if (x.value === 'right') {
  9729. cx = 100;
  9730. } else if (x.value === 'top') {
  9731. cy = 0;
  9732. } else if (x.value === 'bottom') {
  9733. cy = 100;
  9734. }
  9735. }
  9736. if ((y === null || y === void 0 ? void 0 : y.type) === 'position-keyword') {
  9737. if (y.value === 'left') {
  9738. cx = 0;
  9739. } else if (y.value === 'center') {
  9740. cy = 50;
  9741. } else if (y.value === 'right') {
  9742. cx = 100;
  9743. } else if (y.value === 'top') {
  9744. cy = 0;
  9745. } else if (y.value === 'bottom') {
  9746. cy = 100;
  9747. }
  9748. }
  9749. if ((x === null || x === void 0 ? void 0 : x.type) === 'px' || (x === null || x === void 0 ? void 0 : x.type) === '%' || (x === null || x === void 0 ? void 0 : x.type) === 'em') {
  9750. unitX = x === null || x === void 0 ? void 0 : x.type;
  9751. cx = Number(x.value);
  9752. }
  9753. if ((y === null || y === void 0 ? void 0 : y.type) === 'px' || (y === null || y === void 0 ? void 0 : y.type) === '%' || (y === null || y === void 0 ? void 0 : y.type) === 'em') {
  9754. unitY = y === null || y === void 0 ? void 0 : y.type;
  9755. cy = Number(y.value);
  9756. }
  9757. }
  9758. return {
  9759. cx: getOrCreateUnitValue(cx, unitX),
  9760. cy: getOrCreateUnitValue(cy, unitY)
  9761. };
  9762. });
  9763. var parseGradient$1 = memoize(function (colorStr) {
  9764. if (colorStr.indexOf('linear') > -1 || colorStr.indexOf('radial') > -1) {
  9765. var ast = parseGradient(colorStr);
  9766. return ast.map(function (_ref) {
  9767. var type = _ref.type,
  9768. orientation = _ref.orientation,
  9769. colorStops = _ref.colorStops;
  9770. spaceColorStops(colorStops);
  9771. var steps = colorStops.map(function (colorStop) {
  9772. // TODO: only support % for now, should calc percentage of axis length when using px/em
  9773. return {
  9774. offset: getOrCreateUnitValue(Number(colorStop.length.value), '%'),
  9775. color: colorStopToString(colorStop)
  9776. };
  9777. });
  9778. if (type === 'linear-gradient') {
  9779. return new CSSGradientValue(exports.GradientType.LinearGradient, {
  9780. angle: orientation ? angleToDeg(orientation) : Odeg,
  9781. steps: steps
  9782. });
  9783. } else if (type === 'radial-gradient') {
  9784. if (!orientation) {
  9785. orientation = [{
  9786. type: 'shape',
  9787. value: 'circle'
  9788. }];
  9789. }
  9790. if (orientation[0].type === 'shape' && orientation[0].value === 'circle') {
  9791. var _positonToCSSUnitValu = positonToCSSUnitValue(orientation[0].at),
  9792. cx = _positonToCSSUnitValu.cx,
  9793. cy = _positonToCSSUnitValu.cy;
  9794. var size;
  9795. if (orientation[0].style) {
  9796. var _orientation$0$style = orientation[0].style,
  9797. _type = _orientation$0$style.type,
  9798. value = _orientation$0$style.value;
  9799. if (_type === 'extent-keyword') {
  9800. size = getOrCreateKeyword(value);
  9801. } else {
  9802. size = getOrCreateUnitValue(value, _type);
  9803. }
  9804. }
  9805. return new CSSGradientValue(exports.GradientType.RadialGradient, {
  9806. cx: cx,
  9807. cy: cy,
  9808. size: size,
  9809. steps: steps
  9810. });
  9811. }
  9812. // TODO: support ellipse shape
  9813. // TODO: repeating-linear-gradient & repeating-radial-gradient
  9814. // } else if (type === 'repeating-linear-gradient') {
  9815. // } else if (type === 'repeating-radial-gradient') {
  9816. }
  9817. });
  9818. }
  9819. // legacy format, should be deprecated later
  9820. var type = colorStr[0];
  9821. if (colorStr[1] === '(' || colorStr[2] === '(') {
  9822. if (type === 'l') {
  9823. var arr = regexLG.exec(colorStr);
  9824. if (arr) {
  9825. var _arr$2$match;
  9826. var steps = ((_arr$2$match = arr[2].match(regexColorStop)) === null || _arr$2$match === void 0 ? void 0 : _arr$2$match.map(function (stop) {
  9827. return stop.split(':');
  9828. })) || [];
  9829. return [new CSSGradientValue(exports.GradientType.LinearGradient, {
  9830. angle: getOrCreateUnitValue(parseFloat(arr[1]), 'deg'),
  9831. steps: steps.map(function (_ref2) {
  9832. var offset = _ref2[0],
  9833. color = _ref2[1];
  9834. return {
  9835. offset: getOrCreateUnitValue(Number(offset) * 100, '%'),
  9836. color: color
  9837. };
  9838. })
  9839. })];
  9840. }
  9841. } else if (type === 'r') {
  9842. var parsedRadialGradient = parseRadialGradient(colorStr);
  9843. if (parsedRadialGradient) {
  9844. if (isString(parsedRadialGradient)) {
  9845. colorStr = parsedRadialGradient;
  9846. } else {
  9847. return [new CSSGradientValue(exports.GradientType.RadialGradient, parsedRadialGradient)];
  9848. }
  9849. }
  9850. } else if (type === 'p') {
  9851. return parsePattern(colorStr);
  9852. }
  9853. }
  9854. });
  9855. function parseRadialGradient(gradientStr) {
  9856. var arr = regexRG.exec(gradientStr);
  9857. if (arr) {
  9858. var _arr$4$match;
  9859. var steps = ((_arr$4$match = arr[4].match(regexColorStop)) === null || _arr$4$match === void 0 ? void 0 : _arr$4$match.map(function (stop) {
  9860. return stop.split(':');
  9861. })) || [];
  9862. return {
  9863. cx: getOrCreateUnitValue(50, '%'),
  9864. cy: getOrCreateUnitValue(50, '%'),
  9865. steps: steps.map(function (_ref3) {
  9866. var offset = _ref3[0],
  9867. color = _ref3[1];
  9868. return {
  9869. offset: getOrCreateUnitValue(Number(offset) * 100, '%'),
  9870. color: color
  9871. };
  9872. })
  9873. };
  9874. }
  9875. return null;
  9876. }
  9877. function parsePattern(patternStr) {
  9878. var arr = regexPR.exec(patternStr);
  9879. if (arr) {
  9880. var repetition = arr[1];
  9881. var src = arr[2];
  9882. switch (repetition) {
  9883. case 'a':
  9884. repetition = 'repeat';
  9885. break;
  9886. case 'x':
  9887. repetition = 'repeat-x';
  9888. break;
  9889. case 'y':
  9890. repetition = 'repeat-y';
  9891. break;
  9892. case 'n':
  9893. repetition = 'no-repeat';
  9894. break;
  9895. default:
  9896. repetition = 'no-repeat';
  9897. }
  9898. return {
  9899. image: src,
  9900. // @ts-ignore
  9901. repetition: repetition
  9902. };
  9903. }
  9904. return null;
  9905. }
  9906. function isCSSGradientValue(object) {
  9907. return !!object.type && !!object.value;
  9908. }
  9909. function isPattern(object) {
  9910. return object && !!object.image;
  9911. }
  9912. function isCSSRGB(object) {
  9913. return object && !isNil(object.r) && !isNil(object.g) && !isNil(object.b);
  9914. }
  9915. /**
  9916. * @see https://github.com/WebKit/WebKit/blob/main/Source/WebCore/css/parser/CSSParser.cpp#L97
  9917. */
  9918. var parseColor = memoize(function (colorStr) {
  9919. if (isPattern(colorStr)) {
  9920. return _extends({
  9921. repetition: 'repeat'
  9922. }, colorStr);
  9923. }
  9924. if (isNil(colorStr)) {
  9925. colorStr = '';
  9926. }
  9927. if (colorStr === 'transparent') {
  9928. // transparent black
  9929. return transparentColor;
  9930. } else if (colorStr === 'currentColor') {
  9931. // @see https://github.com/adobe-webplatform/Snap.svg/issues/526
  9932. colorStr = 'black';
  9933. }
  9934. // support CSS gradient syntax
  9935. var g = parseGradient$1(colorStr);
  9936. if (g) {
  9937. return g;
  9938. }
  9939. // constants
  9940. var color$1 = color(colorStr);
  9941. var rgba = [0, 0, 0, 0];
  9942. if (color$1 !== null) {
  9943. rgba[0] = color$1.r || 0;
  9944. rgba[1] = color$1.g || 0;
  9945. rgba[2] = color$1.b || 0;
  9946. rgba[3] = color$1.opacity;
  9947. }
  9948. // return new CSSRGB(...rgba);
  9949. return getOrCreateRGBA.apply(void 0, rgba);
  9950. });
  9951. function mergeColors(left, right) {
  9952. // only support constant value, exclude gradient & pattern
  9953. if (!isCSSRGB(left) || !isCSSRGB(right)) {
  9954. return;
  9955. }
  9956. return [[Number(left.r), Number(left.g), Number(left.b), Number(left.alpha)], [Number(right.r), Number(right.g), Number(right.b), Number(right.alpha)], function (color) {
  9957. var rgba = color.slice();
  9958. if (rgba[3]) {
  9959. for (var i = 0; i < 3; i++) rgba[i] = Math.round(clamp(rgba[i], 0, 255));
  9960. }
  9961. rgba[3] = clamp(rgba[3], 0, 1);
  9962. return "rgba(" + rgba.join(',') + ")";
  9963. }];
  9964. }
  9965. function parseDimension(unitRegExp, string) {
  9966. if (isNil(string)) {
  9967. return getOrCreateUnitValue(0, 'px');
  9968. }
  9969. string = ("" + string).trim().toLowerCase();
  9970. if (isFinite(Number(string))) {
  9971. if ('px'.search(unitRegExp) >= 0) {
  9972. return getOrCreateUnitValue(Number(string), 'px');
  9973. } else if ('deg'.search(unitRegExp) >= 0) {
  9974. return getOrCreateUnitValue(Number(string), 'deg');
  9975. }
  9976. }
  9977. var matchedUnits = [];
  9978. string = string.replace(unitRegExp, function (match) {
  9979. matchedUnits.push(match);
  9980. return 'U' + match;
  9981. });
  9982. var taggedUnitRegExp = 'U(' + unitRegExp.source + ')';
  9983. return matchedUnits.map(function (unit) {
  9984. return getOrCreateUnitValue(Number(string.replace(new RegExp('U' + unit, 'g'), '').replace(new RegExp(taggedUnitRegExp, 'g'), '*0')), unit);
  9985. })[0];
  9986. }
  9987. /**
  9988. * <length>
  9989. * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/length
  9990. * length with only absolute unit, eg. 1px
  9991. */
  9992. var parseLength = memoize(function (css) {
  9993. return parseDimension(new RegExp('px', 'g'), css);
  9994. });
  9995. /**
  9996. * <percentage>
  9997. * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/percentage
  9998. */
  9999. var parserPercentage = memoize(function (css) {
  10000. return parseDimension(new RegExp('%', 'g'), css);
  10001. });
  10002. /**
  10003. * length with absolute or relative unit,
  10004. * eg. 1px, 0.7em, 50%, calc(100% - 200px);
  10005. *
  10006. * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/length-percentage
  10007. */
  10008. // export const parseLengthOrPercentage = memoize((css: string): CSSUnitValue => {
  10009. // if (isNumber(css) || isFinite(Number(css))) {
  10010. // return getOrCreateUnitValue(Number(css), 'px');
  10011. // }
  10012. // return parseDimension(new RegExp('px|%|em|rem', 'g'), css) as CSSUnitValue;
  10013. // });
  10014. var parseLengthOrPercentage = function parseLengthOrPercentage(css) {
  10015. if (isNumber(css) || isFinite(Number(css))) {
  10016. // Number(css) is NaN
  10017. return getOrCreateUnitValue(Number(css) || 0, 'px');
  10018. // return Number(css);
  10019. }
  10020. return parseDimension(new RegExp('px|%|em|rem', 'g'), css);
  10021. };
  10022. var parseAngle = memoize(function (css) {
  10023. return parseDimension(new RegExp('deg|rad|grad|turn', 'g'), css);
  10024. });
  10025. /**
  10026. * merge CSSUnitValue
  10027. *
  10028. * @example
  10029. * 10px + 20px = 30px
  10030. * 10deg + 10rad
  10031. * 10% + 20% = 30%
  10032. */
  10033. function mergeDimensions(left, right, target, nonNegative, index) {
  10034. if (index === void 0) {
  10035. index = 0;
  10036. }
  10037. var unit = '';
  10038. var leftValue = left.value || 0;
  10039. var rightValue = right.value || 0;
  10040. var canonicalUnit = toCanonicalUnit(left.unit);
  10041. var leftCanonicalUnitValue = left.convertTo(canonicalUnit);
  10042. var rightCanonicalUnitValue = right.convertTo(canonicalUnit);
  10043. if (leftCanonicalUnitValue && rightCanonicalUnitValue) {
  10044. leftValue = leftCanonicalUnitValue.value;
  10045. rightValue = rightCanonicalUnitValue.value;
  10046. unit = unitTypeToString(left.unit);
  10047. } else {
  10048. // format '%' to 'px'
  10049. if (CSSUnitValue.isLength(left.unit) || CSSUnitValue.isLength(right.unit)) {
  10050. leftValue = convertPercentUnit(left, index, target);
  10051. rightValue = convertPercentUnit(right, index, target);
  10052. unit = 'px';
  10053. }
  10054. }
  10055. // // format 'rad' 'turn' to 'deg'
  10056. // if (CSSUnitValue.isAngle(left.unit) || CSSUnitValue.isAngle(right.unit)) {
  10057. // leftValue = convertAngleUnit(left);
  10058. // rightValue = convertAngleUnit(right);
  10059. // unit = 'deg';
  10060. // }
  10061. return [leftValue, rightValue, function (value) {
  10062. if (nonNegative) {
  10063. value = Math.max(value, 0);
  10064. }
  10065. return value + unit;
  10066. }];
  10067. }
  10068. function convertAngleUnit(value) {
  10069. var deg = 0;
  10070. if (value.unit === exports.UnitType.kDegrees) {
  10071. deg = value.value;
  10072. } else if (value.unit === exports.UnitType.kRadians) {
  10073. deg = rad2deg(Number(value.value));
  10074. } else if (value.unit === exports.UnitType.kTurns) {
  10075. deg = turn2deg(Number(value.value));
  10076. }
  10077. return deg;
  10078. }
  10079. function parseDimensionArrayFormat(string, size) {
  10080. var parsed;
  10081. if (Array.isArray(string)) {
  10082. // [1, '2px', 3]
  10083. parsed = string.map(function (segment) {
  10084. return Number(segment);
  10085. });
  10086. } else if (isString(string)) {
  10087. parsed = string.split(' ').map(function (segment) {
  10088. return Number(segment);
  10089. });
  10090. } else if (isNumber(string)) {
  10091. parsed = [string];
  10092. }
  10093. if (size === 2) {
  10094. if (parsed.length === 1) {
  10095. return [parsed[0], parsed[0]];
  10096. } else {
  10097. return [parsed[0], parsed[1]];
  10098. }
  10099. } else {
  10100. if (parsed.length === 1) {
  10101. return [parsed[0], parsed[0], parsed[0], parsed[0]];
  10102. } else if (parsed.length === 2) {
  10103. return [parsed[0], parsed[1], parsed[0], parsed[1]];
  10104. } else if (parsed.length === 3) {
  10105. return [parsed[0], parsed[1], parsed[2], parsed[1]];
  10106. } else {
  10107. return [parsed[0], parsed[1], parsed[2], parsed[3]];
  10108. }
  10109. }
  10110. }
  10111. function parseDimensionArray(string) {
  10112. if (isString(string)) {
  10113. // "1px 2px 3px"
  10114. return string.split(' ').map(function (segment) {
  10115. return parseLengthOrPercentage(segment);
  10116. });
  10117. } else {
  10118. // [1, '2px', 3]
  10119. return string.map(function (segment) {
  10120. return parseLengthOrPercentage(segment.toString());
  10121. });
  10122. }
  10123. }
  10124. // export function mergeDimensionList(
  10125. // left: CSSUnitValue[],
  10126. // right: CSSUnitValue[],
  10127. // target: IElement | null,
  10128. // ): [number[], number[], (list: number[]) => string] | undefined {
  10129. // if (left.length !== right.length) {
  10130. // return;
  10131. // }
  10132. // const unit = left[0].unit;
  10133. // return [
  10134. // left.map((l) => l.value),
  10135. // right.map((l) => l.value),
  10136. // (values: number[]) => {
  10137. // return values.map((n) => new CSSUnitValue(n, unit)).join(' ');
  10138. // },
  10139. // ];
  10140. // }
  10141. function convertPercentUnit(valueWithUnit, vec3Index, target) {
  10142. if (valueWithUnit.value === 0) {
  10143. return 0;
  10144. }
  10145. if (valueWithUnit.unit === exports.UnitType.kPixels) {
  10146. return Number(valueWithUnit.value);
  10147. } else if (valueWithUnit.unit === exports.UnitType.kPercentage && target) {
  10148. var bounds = target.nodeName === exports.Shape.GROUP ? target.getLocalBounds() :
  10149. // : target.getGeometryBounds();
  10150. target.geometry.contentBounds;
  10151. return valueWithUnit.value / 100 * bounds.halfExtents[vec3Index] * 2;
  10152. }
  10153. return 0;
  10154. }
  10155. var parseParam = function parseParam(css) {
  10156. return parseDimension(/deg|rad|grad|turn|px|%/g, css);
  10157. };
  10158. var supportedFilters = ['blur', 'brightness', 'drop-shadow', 'contrast', 'grayscale', 'sepia', 'saturate', 'hue-rotate', 'invert'];
  10159. function parseFilter(filterStr) {
  10160. if (filterStr === void 0) {
  10161. filterStr = '';
  10162. }
  10163. filterStr = filterStr.toLowerCase().trim();
  10164. if (filterStr === 'none') {
  10165. return [];
  10166. }
  10167. var filterRegExp = /\s*([\w-]+)\(([^)]*)\)/g;
  10168. var result = [];
  10169. var match;
  10170. var prevLastIndex = 0;
  10171. while (match = filterRegExp.exec(filterStr)) {
  10172. if (match.index !== prevLastIndex) {
  10173. return [];
  10174. }
  10175. prevLastIndex = match.index + match[0].length;
  10176. if (supportedFilters.indexOf(match[1]) > -1) {
  10177. result.push({
  10178. name: match[1],
  10179. params: match[2].split(' ').map(function (p) {
  10180. return parseParam(p) || parseColor(p);
  10181. })
  10182. });
  10183. }
  10184. if (filterRegExp.lastIndex === filterStr.length) {
  10185. return result;
  10186. }
  10187. }
  10188. return [];
  10189. }
  10190. function numberToString(x) {
  10191. // scale(0.00000001) -> scale(0)
  10192. // return x.toFixed(6).replace(/0+$/, '').replace(/\.$/, '');
  10193. return x.toString();
  10194. }
  10195. /**
  10196. * parse string or number to CSSUnitValue(numeric)
  10197. *
  10198. * eg.
  10199. * * 0 -> CSSUnitValue(0)
  10200. * * '2' -> CSSUnitValue(2)
  10201. */
  10202. var parseNumber = memoize(function (string) {
  10203. if (typeof string === 'number') {
  10204. return getOrCreateUnitValue(string);
  10205. }
  10206. if (/^\s*[-+]?(\d*\.)?\d+\s*$/.test(string)) {
  10207. return getOrCreateUnitValue(Number(string));
  10208. } else {
  10209. return getOrCreateUnitValue(0);
  10210. }
  10211. });
  10212. /**
  10213. * separate string to array
  10214. * eg.
  10215. * * [0.5, 0.5] -> [CSSUnitValue, CSSUnitValue]
  10216. */
  10217. var parseNumberList = memoize(function (string) {
  10218. if (isString(string)) {
  10219. return string.split(' ').map(parseNumber);
  10220. } else {
  10221. return string.map(parseNumber);
  10222. }
  10223. });
  10224. function mergeNumbers(left, right) {
  10225. return [left, right, numberToString];
  10226. }
  10227. function clampedMergeNumbers(min, max) {
  10228. return function (left, right) {
  10229. return [left, right, function (x) {
  10230. return numberToString(clamp(x, min, max));
  10231. }];
  10232. };
  10233. }
  10234. function mergeNumberLists(left, right) {
  10235. if (left.length !== right.length) {
  10236. return;
  10237. }
  10238. return [left, right, function (numberList) {
  10239. return numberList;
  10240. }];
  10241. }
  10242. var internalParsePath = function internalParsePath(path) {
  10243. // empty path
  10244. if (path === '' || Array.isArray(path) && path.length === 0) {
  10245. return {
  10246. absolutePath: [],
  10247. hasArc: false,
  10248. segments: [],
  10249. polygons: [],
  10250. polylines: [],
  10251. curve: null,
  10252. totalLength: 0,
  10253. rect: {
  10254. x: 0,
  10255. y: 0,
  10256. width: 0,
  10257. height: 0
  10258. }
  10259. };
  10260. }
  10261. var absolutePath;
  10262. try {
  10263. absolutePath = normalizePath(path);
  10264. } catch (e) {
  10265. absolutePath = normalizePath('');
  10266. console.error("[g]: Invalid SVG Path definition: " + path);
  10267. }
  10268. var hasArc = hasArcOrBezier(absolutePath);
  10269. var _extractPolygons = extractPolygons(absolutePath),
  10270. polygons = _extractPolygons.polygons,
  10271. polylines = _extractPolygons.polylines;
  10272. // for later use
  10273. var segments = path2Segments(absolutePath);
  10274. // Only calculate bbox here since we don't need length now.
  10275. var _getPathBBox = getPathBBox(segments, 0),
  10276. x = _getPathBBox.x,
  10277. y = _getPathBBox.y,
  10278. width = _getPathBBox.width,
  10279. height = _getPathBBox.height;
  10280. return {
  10281. absolutePath: absolutePath,
  10282. hasArc: hasArc,
  10283. segments: segments,
  10284. polygons: polygons,
  10285. polylines: polylines,
  10286. // curve,
  10287. // Delay the calculation of length.
  10288. totalLength: 0,
  10289. rect: {
  10290. x: Number.isFinite(x) ? x : 0,
  10291. y: Number.isFinite(y) ? y : 0,
  10292. width: Number.isFinite(width) ? width : 0,
  10293. height: Number.isFinite(height) ? height : 0
  10294. }
  10295. };
  10296. };
  10297. var memoizedParsePath = memoize(internalParsePath);
  10298. function parsePath(path, object) {
  10299. var result = isString(path) ? memoizedParsePath(path) : internalParsePath(path);
  10300. if (object) {
  10301. object.parsedStyle.defX = result.rect.x;
  10302. object.parsedStyle.defY = result.rect.y;
  10303. }
  10304. return result;
  10305. }
  10306. function mergePaths(left, right, object) {
  10307. var curve1 = left.curve;
  10308. var curve2 = right.curve;
  10309. if (!curve1 || curve1.length === 0) {
  10310. // convert to curves to do morphing & picking later
  10311. // @see http://thednp.github.io/kute.js/svgCubicMorph.html
  10312. curve1 = path2Curve(left.absolutePath, false);
  10313. left.curve = curve1;
  10314. }
  10315. if (!curve2 || curve2.length === 0) {
  10316. curve2 = path2Curve(right.absolutePath, false);
  10317. right.curve = curve2;
  10318. }
  10319. var curves = [curve1, curve2];
  10320. if (curve1.length !== curve2.length) {
  10321. curves = equalizeSegments(curve1, curve2);
  10322. }
  10323. var curve0 = getDrawDirection(curves[0]) !== getDrawDirection(curves[1]) ? reverseCurve(curves[0]) : clonePath(curves[0]);
  10324. return [curve0, getRotatedCurve(curves[1], curve0), function (pathArray) {
  10325. // need converting to path string?
  10326. return pathArray;
  10327. }];
  10328. }
  10329. /**
  10330. * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/points
  10331. *
  10332. * @example
  10333. * points="100,10 250,150 200,110"
  10334. */
  10335. function parsePoints(pointsOrStr, object) {
  10336. var points;
  10337. if (isString(pointsOrStr)) {
  10338. points = pointsOrStr.split(' ').map(function (pointStr) {
  10339. var _pointStr$split = pointStr.split(','),
  10340. x = _pointStr$split[0],
  10341. y = _pointStr$split[1];
  10342. return [Number(x), Number(y)];
  10343. });
  10344. } else {
  10345. points = pointsOrStr;
  10346. }
  10347. var segments = [];
  10348. var tempLength = 0;
  10349. var segmentT;
  10350. var segmentL;
  10351. var totalLength = polyline.length(points);
  10352. points.forEach(function (p, i) {
  10353. if (points[i + 1]) {
  10354. segmentT = [0, 0];
  10355. segmentT[0] = tempLength / totalLength;
  10356. segmentL = line.length(p[0], p[1], points[i + 1][0], points[i + 1][1]);
  10357. tempLength += segmentL;
  10358. segmentT[1] = tempLength / totalLength;
  10359. segments.push(segmentT);
  10360. }
  10361. });
  10362. var minX = Math.min.apply(Math, points.map(function (point) {
  10363. return point[0];
  10364. }));
  10365. var minY = Math.min.apply(Math, points.map(function (point) {
  10366. return point[1];
  10367. }));
  10368. if (object) {
  10369. object.parsedStyle.defX = minX;
  10370. object.parsedStyle.defY = minY;
  10371. }
  10372. return {
  10373. points: points,
  10374. totalLength: totalLength,
  10375. segments: segments
  10376. };
  10377. }
  10378. function mergePoints(left, right) {
  10379. return [left.points, right.points, function (points) {
  10380. return points;
  10381. }];
  10382. }
  10383. var _ = null;
  10384. function cast(pattern) {
  10385. return function (contents) {
  10386. var i = 0;
  10387. return pattern.map(function (x) {
  10388. return x === _ ? contents[i++] : x;
  10389. });
  10390. };
  10391. }
  10392. function id(x) {
  10393. return x;
  10394. }
  10395. // type: [argTypes, convertTo3D, convertTo2D]
  10396. // In the argument types string, lowercase characters represent optional arguments
  10397. var transformFunctions = {
  10398. // @ts-ignore
  10399. matrix: ['NNNNNN', [_, _, 0, 0, _, _, 0, 0, 0, 0, 1, 0, _, _, 0, 1], id],
  10400. matrix3d: ['NNNNNNNNNNNNNNNN', id],
  10401. rotate: ['A'],
  10402. rotatex: ['A'],
  10403. rotatey: ['A'],
  10404. rotatez: ['A'],
  10405. rotate3d: ['NNNA'],
  10406. perspective: ['L'],
  10407. scale: ['Nn', cast([_, _, new CSSUnitValue(1)]), id],
  10408. scalex: ['N', cast([_, new CSSUnitValue(1), new CSSUnitValue(1)]), cast([_, new CSSUnitValue(1)])],
  10409. scaley: ['N', cast([new CSSUnitValue(1), _, new CSSUnitValue(1)]), cast([new CSSUnitValue(1), _])],
  10410. scalez: ['N', cast([new CSSUnitValue(1), new CSSUnitValue(1), _])],
  10411. scale3d: ['NNN', id],
  10412. skew: ['Aa', null, id],
  10413. skewx: ['A', null, cast([_, Odeg])],
  10414. skewy: ['A', null, cast([Odeg, _])],
  10415. translate: ['Tt', cast([_, _, Opx]), id],
  10416. translatex: ['T', cast([_, Opx, Opx]), cast([_, Opx])],
  10417. translatey: ['T', cast([Opx, _, Opx]), cast([Opx, _])],
  10418. translatez: ['L', cast([Opx, Opx, _])],
  10419. translate3d: ['TTL', id]
  10420. };
  10421. /**
  10422. * none
  10423. * scale(1) scale(1, 2)
  10424. * scaleX(1)
  10425. */
  10426. function parseTransform(string) {
  10427. string = (string || 'none').toLowerCase().trim();
  10428. if (string === 'none') {
  10429. return [];
  10430. }
  10431. var transformRegExp = /\s*(\w+)\(([^)]*)\)/g;
  10432. var result = [];
  10433. var match;
  10434. var prevLastIndex = 0;
  10435. while (match = transformRegExp.exec(string)) {
  10436. if (match.index !== prevLastIndex) {
  10437. return [];
  10438. }
  10439. prevLastIndex = match.index + match[0].length;
  10440. var functionName = match[1]; // scale
  10441. var functionData = transformFunctions[functionName]; // scale(1, 2)
  10442. if (!functionData) {
  10443. // invalid, eg. scale()
  10444. return [];
  10445. }
  10446. var args = match[2].split(','); // 1,2
  10447. var argTypes = functionData[0]; // Nn
  10448. if (argTypes.length < args.length) {
  10449. // scale(N, n)
  10450. return [];
  10451. }
  10452. var parsedArgs = [];
  10453. for (var i = 0; i < argTypes.length; i++) {
  10454. var arg = args[i];
  10455. var type = argTypes[i];
  10456. var parsedArg = void 0;
  10457. if (!arg) {
  10458. // @ts-ignore
  10459. parsedArg = {
  10460. a: Odeg,
  10461. n: parsedArgs[0],
  10462. t: Opx
  10463. }[type];
  10464. } else {
  10465. // @ts-ignore
  10466. parsedArg = {
  10467. A: function A(s) {
  10468. return s.trim() === '0' ? Odeg : parseAngle(s);
  10469. },
  10470. N: parseNumber,
  10471. T: parseLengthOrPercentage,
  10472. L: parseLength
  10473. }[type.toUpperCase()](arg);
  10474. }
  10475. if (parsedArg === undefined) {
  10476. return [];
  10477. }
  10478. parsedArgs.push(parsedArg);
  10479. }
  10480. result.push({
  10481. t: functionName,
  10482. d: parsedArgs
  10483. }); // { t: scale, d: [1, 2] }
  10484. if (transformRegExp.lastIndex === string.length) {
  10485. return result;
  10486. }
  10487. }
  10488. return [];
  10489. }
  10490. function convertItemToMatrix(item) {
  10491. var x;
  10492. var y;
  10493. var z;
  10494. var angle;
  10495. switch (item.t) {
  10496. case 'rotatex':
  10497. angle = deg2rad(convertAngleUnit(item.d[0]));
  10498. return [1, 0, 0, 0, 0, Math.cos(angle), Math.sin(angle), 0, 0, -Math.sin(angle), Math.cos(angle), 0, 0, 0, 0, 1];
  10499. case 'rotatey':
  10500. angle = deg2rad(convertAngleUnit(item.d[0]));
  10501. return [Math.cos(angle), 0, -Math.sin(angle), 0, 0, 1, 0, 0, Math.sin(angle), 0, Math.cos(angle), 0, 0, 0, 0, 1];
  10502. case 'rotate':
  10503. case 'rotatez':
  10504. angle = deg2rad(convertAngleUnit(item.d[0]));
  10505. return [Math.cos(angle), Math.sin(angle), 0, 0, -Math.sin(angle), Math.cos(angle), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  10506. case 'rotate3d':
  10507. x = item.d[0].value;
  10508. y = item.d[1].value;
  10509. z = item.d[2].value;
  10510. angle = deg2rad(convertAngleUnit(item.d[3]));
  10511. var sqrLength = x * x + y * y + z * z;
  10512. if (sqrLength === 0) {
  10513. x = 1;
  10514. y = 0;
  10515. z = 0;
  10516. } else if (sqrLength !== 1) {
  10517. var length = Math.sqrt(sqrLength);
  10518. x /= length;
  10519. y /= length;
  10520. z /= length;
  10521. }
  10522. var s = Math.sin(angle / 2);
  10523. var sc = s * Math.cos(angle / 2);
  10524. var sq = s * s;
  10525. return [1 - 2 * (y * y + z * z) * sq, 2 * (x * y * sq + z * sc), 2 * (x * z * sq - y * sc), 0, 2 * (x * y * sq - z * sc), 1 - 2 * (x * x + z * z) * sq, 2 * (y * z * sq + x * sc), 0, 2 * (x * z * sq + y * sc), 2 * (y * z * sq - x * sc), 1 - 2 * (x * x + y * y) * sq, 0, 0, 0, 0, 1];
  10526. case 'scale':
  10527. return [item.d[0].value, 0, 0, 0, 0, item.d[1].value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  10528. case 'scalex':
  10529. return [item.d[0].value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  10530. case 'scaley':
  10531. return [1, 0, 0, 0, 0, item.d[0].value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  10532. case 'scalez':
  10533. return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, item.d[0].value, 0, 0, 0, 0, 1];
  10534. case 'scale3d':
  10535. return [item.d[0].value, 0, 0, 0, 0, item.d[1].value, 0, 0, 0, 0, item.d[2].value, 0, 0, 0, 0, 1];
  10536. case 'skew':
  10537. var xAngle = deg2rad(convertAngleUnit(item.d[0]));
  10538. var yAngle = deg2rad(convertAngleUnit(item.d[1]));
  10539. return [1, Math.tan(yAngle), 0, 0, Math.tan(xAngle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  10540. case 'skewx':
  10541. angle = deg2rad(convertAngleUnit(item.d[0]));
  10542. return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  10543. case 'skewy':
  10544. angle = deg2rad(convertAngleUnit(item.d[0]));
  10545. return [1, Math.tan(angle), 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  10546. case 'translate':
  10547. // TODO: pass target
  10548. x = convertPercentUnit(item.d[0], 0, null) || 0;
  10549. y = convertPercentUnit(item.d[1], 0, null) || 0;
  10550. return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, 0, 1];
  10551. case 'translatex':
  10552. x = convertPercentUnit(item.d[0], 0, null) || 0;
  10553. return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, 0, 0, 1];
  10554. case 'translatey':
  10555. y = convertPercentUnit(item.d[0], 0, null) || 0;
  10556. return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, y, 0, 1];
  10557. case 'translatez':
  10558. z = convertPercentUnit(item.d[0], 0, null) || 0;
  10559. return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, z, 1];
  10560. case 'translate3d':
  10561. x = convertPercentUnit(item.d[0], 0, null) || 0;
  10562. y = convertPercentUnit(item.d[1], 0, null) || 0;
  10563. z = convertPercentUnit(item.d[2], 0, null) || 0;
  10564. return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1];
  10565. case 'perspective':
  10566. var t = convertPercentUnit(item.d[0], 0, null) || 0;
  10567. var p = t ? -1 / t : 0;
  10568. return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, p, 0, 0, 0, 1];
  10569. case 'matrix':
  10570. return [item.d[0].value, item.d[1].value, 0, 0, item.d[2].value, item.d[3].value, 0, 0, 0, 0, 1, 0, item.d[4].value, item.d[5].value, 0, 1];
  10571. case 'matrix3d':
  10572. return item.d.map(function (d) {
  10573. return d.value;
  10574. });
  10575. }
  10576. }
  10577. function multiplyMatrices(a, b) {
  10578. return [a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3], a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3], a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3], a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3], a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7], a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7], a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7], a[3] * b[4] + a[7] * b[5] + a[11] * b[6] + a[15] * b[7], a[0] * b[8] + a[4] * b[9] + a[8] * b[10] + a[12] * b[11], a[1] * b[8] + a[5] * b[9] + a[9] * b[10] + a[13] * b[11], a[2] * b[8] + a[6] * b[9] + a[10] * b[10] + a[14] * b[11], a[3] * b[8] + a[7] * b[9] + a[11] * b[10] + a[15] * b[11], a[0] * b[12] + a[4] * b[13] + a[8] * b[14] + a[12] * b[15], a[1] * b[12] + a[5] * b[13] + a[9] * b[14] + a[13] * b[15], a[2] * b[12] + a[6] * b[13] + a[10] * b[14] + a[14] * b[15], a[3] * b[12] + a[7] * b[13] + a[11] * b[14] + a[15] * b[15]];
  10579. }
  10580. function convertToMatrix(transformList) {
  10581. if (transformList.length === 0) {
  10582. return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  10583. }
  10584. return transformList.map(convertItemToMatrix).reduce(multiplyMatrices);
  10585. }
  10586. function makeMatrixDecomposition(transformList) {
  10587. var translate = [0, 0, 0];
  10588. var scale = [1, 1, 1];
  10589. var skew = [0, 0, 0];
  10590. var perspective = [0, 0, 0, 1];
  10591. var quaternion = [0, 0, 0, 1];
  10592. // @ts-ignore
  10593. decomposeMat4(convertToMatrix(transformList), translate, scale, skew, perspective, quaternion);
  10594. return [[translate, scale, skew, quaternion, perspective]];
  10595. }
  10596. var composeMatrix = function () {
  10597. function multiply(a, b) {
  10598. var result = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
  10599. for (var i = 0; i < 4; i++) {
  10600. for (var j = 0; j < 4; j++) {
  10601. for (var k = 0; k < 4; k++) {
  10602. result[i][j] += b[i][k] * a[k][j];
  10603. }
  10604. }
  10605. }
  10606. return result;
  10607. }
  10608. function is2D(m) {
  10609. return m[0][2] == 0 && m[0][3] == 0 && m[1][2] == 0 && m[1][3] == 0 && m[2][0] == 0 && m[2][1] == 0 && m[2][2] == 1 && m[2][3] == 0 && m[3][2] == 0 && m[3][3] == 1;
  10610. }
  10611. function composeMatrix(translate, scale, skew, quat, perspective) {
  10612. var matrix = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
  10613. for (var i = 0; i < 4; i++) {
  10614. matrix[i][3] = perspective[i];
  10615. }
  10616. for (var _i = 0; _i < 3; _i++) {
  10617. for (var j = 0; j < 3; j++) {
  10618. matrix[3][_i] += translate[j] * matrix[j][_i];
  10619. }
  10620. }
  10621. var x = quat[0],
  10622. y = quat[1],
  10623. z = quat[2],
  10624. w = quat[3];
  10625. var rotMatrix = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
  10626. rotMatrix[0][0] = 1 - 2 * (y * y + z * z);
  10627. rotMatrix[0][1] = 2 * (x * y - z * w);
  10628. rotMatrix[0][2] = 2 * (x * z + y * w);
  10629. rotMatrix[1][0] = 2 * (x * y + z * w);
  10630. rotMatrix[1][1] = 1 - 2 * (x * x + z * z);
  10631. rotMatrix[1][2] = 2 * (y * z - x * w);
  10632. rotMatrix[2][0] = 2 * (x * z - y * w);
  10633. rotMatrix[2][1] = 2 * (y * z + x * w);
  10634. rotMatrix[2][2] = 1 - 2 * (x * x + y * y);
  10635. matrix = multiply(matrix, rotMatrix);
  10636. var temp = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
  10637. if (skew[2]) {
  10638. temp[2][1] = skew[2];
  10639. matrix = multiply(matrix, temp);
  10640. }
  10641. if (skew[1]) {
  10642. temp[2][1] = 0;
  10643. temp[2][0] = skew[0];
  10644. matrix = multiply(matrix, temp);
  10645. }
  10646. if (skew[0]) {
  10647. temp[2][0] = 0;
  10648. temp[1][0] = skew[0];
  10649. matrix = multiply(matrix, temp);
  10650. }
  10651. for (var _i2 = 0; _i2 < 3; _i2++) {
  10652. for (var _j = 0; _j < 3; _j++) {
  10653. matrix[_i2][_j] *= scale[_i2];
  10654. }
  10655. }
  10656. if (is2D(matrix)) {
  10657. return [matrix[0][0], matrix[0][1], matrix[1][0], matrix[1][1], matrix[3][0], matrix[3][1]];
  10658. }
  10659. return matrix[0].concat(matrix[1], matrix[2], matrix[3]);
  10660. }
  10661. return composeMatrix;
  10662. }();
  10663. function numberToLongString(x) {
  10664. return x.toFixed(6).replace('.000000', '');
  10665. }
  10666. function mergeMatrices(left, right) {
  10667. var leftArgs;
  10668. var rightArgs;
  10669. // @ts-ignore
  10670. if (left.decompositionPair !== right) {
  10671. // @ts-ignore
  10672. left.decompositionPair = right;
  10673. // @ts-ignore
  10674. leftArgs = makeMatrixDecomposition(left);
  10675. }
  10676. // @ts-ignore
  10677. if (right.decompositionPair !== left) {
  10678. // @ts-ignore
  10679. right.decompositionPair = left;
  10680. // @ts-ignore
  10681. rightArgs = makeMatrixDecomposition(right);
  10682. }
  10683. if (leftArgs[0] === null || rightArgs[0] === null) return [
  10684. // @ts-ignore
  10685. [false],
  10686. // @ts-ignore
  10687. [true],
  10688. // @ts-ignore
  10689. function (x) {
  10690. return x ? right[0].d : left[0].d;
  10691. }];
  10692. leftArgs[0].push(0);
  10693. rightArgs[0].push(1);
  10694. return [leftArgs, rightArgs,
  10695. // @ts-ignore
  10696. function (list) {
  10697. // @ts-ignore
  10698. var q = quat(leftArgs[0][3], rightArgs[0][3], list[5]);
  10699. var mat = composeMatrix(list[0], list[1], list[2], q, list[4]);
  10700. var stringifiedArgs = mat.map(numberToLongString).join(',');
  10701. return stringifiedArgs;
  10702. }];
  10703. }
  10704. function dot$2(v1, v2) {
  10705. var result = 0;
  10706. for (var i = 0; i < v1.length; i++) {
  10707. result += v1[i] * v2[i];
  10708. }
  10709. return result;
  10710. }
  10711. function quat(fromQ, toQ, f) {
  10712. var product = dot$2(fromQ, toQ);
  10713. product = clamp(product, -1.0, 1.0);
  10714. var quat = [];
  10715. if (product === 1.0) {
  10716. quat = fromQ;
  10717. } else {
  10718. var theta = Math.acos(product);
  10719. var w = Math.sin(f * theta) * 1 / Math.sqrt(1 - product * product);
  10720. for (var i = 0; i < 4; i++) {
  10721. quat.push(fromQ[i] * (Math.cos(f * theta) - product * w) + toQ[i] * w);
  10722. }
  10723. }
  10724. return quat;
  10725. }
  10726. // scalex/y/z -> scale
  10727. function typeTo2D(type) {
  10728. return type.replace(/[xy]/, '');
  10729. }
  10730. // scalex/y/z -> scale3d
  10731. function typeTo3D(type) {
  10732. return type.replace(/(x|y|z|3d)?$/, '3d');
  10733. }
  10734. var isMatrixOrPerspective = function isMatrixOrPerspective(lt, rt) {
  10735. return lt === 'perspective' && rt === 'perspective' || (lt === 'matrix' || lt === 'matrix3d') && (rt === 'matrix' || rt === 'matrix3d');
  10736. };
  10737. function mergeTransforms(left, right, target) {
  10738. var flipResults = false;
  10739. // padding empty transform, eg. merge 'scale(10)' with 'none' -> scale(1)
  10740. if (!left.length || !right.length) {
  10741. if (!left.length) {
  10742. flipResults = true;
  10743. left = right;
  10744. right = [];
  10745. }
  10746. var _loop = function _loop() {
  10747. var _left$i = left[i],
  10748. type = _left$i.t,
  10749. args = _left$i.d;
  10750. // none -> scale(1)/translateX(0)
  10751. var defaultValue = type.substring(0, 5) === 'scale' ? 1 : 0;
  10752. right.push({
  10753. t: type,
  10754. d: args.map(function (arg) {
  10755. if (typeof arg === 'number') {
  10756. return getOrCreateUnitValue(defaultValue);
  10757. }
  10758. return getOrCreateUnitValue(defaultValue, arg.unit);
  10759. // {
  10760. // unit: arg.unit,
  10761. // value: defaultValue,
  10762. // };
  10763. })
  10764. });
  10765. };
  10766. for (var i = 0; i < left.length; i++) {
  10767. _loop();
  10768. }
  10769. }
  10770. var leftResult = [];
  10771. var rightResult = [];
  10772. var types = [];
  10773. // merge matrix() with matrix3d()
  10774. if (left.length !== right.length) {
  10775. var merged = mergeMatrices(left, right);
  10776. // @ts-ignore
  10777. leftResult = [merged[0]];
  10778. // @ts-ignore
  10779. rightResult = [merged[1]];
  10780. types = [['matrix', [merged[2]]]];
  10781. } else {
  10782. for (var _i3 = 0; _i3 < left.length; _i3++) {
  10783. var leftType = left[_i3].t;
  10784. var rightType = right[_i3].t;
  10785. var leftArgs = left[_i3].d;
  10786. var rightArgs = right[_i3].d;
  10787. var leftFunctionData = transformFunctions[leftType];
  10788. var rightFunctionData = transformFunctions[rightType];
  10789. var type = void 0;
  10790. if (isMatrixOrPerspective(leftType, rightType)) {
  10791. var _merged = mergeMatrices([left[_i3]], [right[_i3]]);
  10792. // @ts-ignore
  10793. leftResult.push(_merged[0]);
  10794. // @ts-ignore
  10795. rightResult.push(_merged[1]);
  10796. types.push(['matrix', [_merged[2]]]);
  10797. continue;
  10798. } else if (leftType === rightType) {
  10799. type = leftType;
  10800. } else if (leftFunctionData[2] && rightFunctionData[2] && typeTo2D(leftType) === typeTo2D(rightType)) {
  10801. type = typeTo2D(leftType);
  10802. // @ts-ignore
  10803. leftArgs = leftFunctionData[2](leftArgs);
  10804. // @ts-ignore
  10805. rightArgs = rightFunctionData[2](rightArgs);
  10806. } else if (leftFunctionData[1] && rightFunctionData[1] && typeTo3D(leftType) === typeTo3D(rightType)) {
  10807. type = typeTo3D(leftType);
  10808. // @ts-ignore
  10809. leftArgs = leftFunctionData[1](leftArgs);
  10810. // @ts-ignore
  10811. rightArgs = rightFunctionData[1](rightArgs);
  10812. } else {
  10813. var _merged2 = mergeMatrices(left, right);
  10814. // @ts-ignore
  10815. leftResult = [_merged2[0]];
  10816. // @ts-ignore
  10817. rightResult = [_merged2[1]];
  10818. types = [['matrix', [_merged2[2]]]];
  10819. break;
  10820. }
  10821. var leftArgsCopy = [];
  10822. var rightArgsCopy = [];
  10823. var stringConversions = [];
  10824. for (var j = 0; j < leftArgs.length; j++) {
  10825. // const merge = leftArgs[j].unit === UnitType.kNumber ? mergeDimensions : mergeDimensions;
  10826. var _merged3 = mergeDimensions(leftArgs[j], rightArgs[j], target, false, j);
  10827. leftArgsCopy[j] = _merged3[0];
  10828. rightArgsCopy[j] = _merged3[1];
  10829. stringConversions.push(_merged3[2]);
  10830. }
  10831. leftResult.push(leftArgsCopy);
  10832. rightResult.push(rightArgsCopy);
  10833. types.push([type, stringConversions]);
  10834. }
  10835. }
  10836. if (flipResults) {
  10837. var tmp = leftResult;
  10838. leftResult = rightResult;
  10839. rightResult = tmp;
  10840. }
  10841. return [leftResult, rightResult, function (list) {
  10842. return list.map(function (args, i) {
  10843. var stringifiedArgs = args.map(function (arg, j) {
  10844. return types[i][1][j](arg);
  10845. }).join(',');
  10846. if (types[i][0] === 'matrix' && stringifiedArgs.split(',').length === 16) {
  10847. types[i][0] = 'matrix3d';
  10848. }
  10849. if (types[i][0] === 'matrix3d' && stringifiedArgs.split(',').length === 6) {
  10850. types[i][0] = 'matrix';
  10851. }
  10852. return types[i][0] + '(' + stringifiedArgs + ')';
  10853. }).join(' ');
  10854. }];
  10855. }
  10856. /**
  10857. * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/transform-origin
  10858. * eg. 'center' 'top left' '50px 50px'
  10859. */
  10860. var parseTransformOrigin = memoize(function (value) {
  10861. if (isString(value)) {
  10862. if (value === 'text-anchor') {
  10863. return [getOrCreateUnitValue(0, 'px'), getOrCreateUnitValue(0, 'px')];
  10864. }
  10865. var values = value.split(' ');
  10866. if (values.length === 1) {
  10867. if (values[0] === 'top' || values[0] === 'bottom') {
  10868. // 'top' -> 'center top'
  10869. values[1] = values[0];
  10870. values[0] = 'center';
  10871. } else {
  10872. // '50px' -> '50px center'
  10873. values[1] = 'center';
  10874. }
  10875. }
  10876. if (values.length !== 2) {
  10877. return null;
  10878. }
  10879. // eg. center bottom
  10880. return [parseLengthOrPercentage(convertKeyword2Percent(values[0])), parseLengthOrPercentage(convertKeyword2Percent(values[1]))];
  10881. } else {
  10882. return [getOrCreateUnitValue(value[0] || 0, 'px'), getOrCreateUnitValue(value[1] || 0, 'px')];
  10883. }
  10884. });
  10885. function convertKeyword2Percent(keyword) {
  10886. if (keyword === 'center') {
  10887. return '50%';
  10888. } else if (keyword === 'left' || keyword === 'top') {
  10889. return '0';
  10890. } else if (keyword === 'right' || keyword === 'bottom') {
  10891. return '100%';
  10892. }
  10893. return keyword;
  10894. }
  10895. var CSSPropertyAngle = /*#__PURE__*/function () {
  10896. function CSSPropertyAngle() {
  10897. this.parser = parseAngle;
  10898. this.parserWithCSSDisabled = null;
  10899. this.mixer = mergeNumbers;
  10900. }
  10901. var _proto = CSSPropertyAngle.prototype;
  10902. _proto.calculator = function calculator(name, oldParsed, parsed, object) {
  10903. return convertAngleUnit(parsed);
  10904. };
  10905. return CSSPropertyAngle;
  10906. }();
  10907. /**
  10908. * clipPath / textPath / offsetPath
  10909. */
  10910. var CSSPropertyClipPath = /*#__PURE__*/function () {
  10911. function CSSPropertyClipPath() {}
  10912. var _proto = CSSPropertyClipPath.prototype;
  10913. _proto.calculator = function calculator(name, oldPath, newPath, object) {
  10914. // unset
  10915. if (newPath instanceof CSSKeywordValue) {
  10916. newPath = null;
  10917. }
  10918. runtime.sceneGraphService.updateDisplayObjectDependency(name, oldPath, newPath, object);
  10919. if (name === 'clipPath') {
  10920. // should affect children
  10921. object.forEach(function (leaf) {
  10922. if (leaf.childNodes.length === 0) {
  10923. runtime.sceneGraphService.dirtifyToRoot(leaf);
  10924. }
  10925. });
  10926. }
  10927. return newPath;
  10928. };
  10929. return CSSPropertyClipPath;
  10930. }();
  10931. var CSSPropertyColor = /*#__PURE__*/function () {
  10932. function CSSPropertyColor() {
  10933. this.parser = parseColor;
  10934. this.parserWithCSSDisabled = parseColor;
  10935. this.mixer = mergeColors;
  10936. }
  10937. var _proto = CSSPropertyColor.prototype;
  10938. _proto.calculator = function calculator(name, oldParsed, parsed, object) {
  10939. if (parsed instanceof CSSKeywordValue) {
  10940. // 'unset' 'none'
  10941. return parsed.value === 'none' ? noneColor : transparentColor;
  10942. }
  10943. return parsed;
  10944. };
  10945. return CSSPropertyColor;
  10946. }();
  10947. var CSSPropertyFilter = /*#__PURE__*/function () {
  10948. function CSSPropertyFilter() {
  10949. this.parser = parseFilter;
  10950. }
  10951. var _proto = CSSPropertyFilter.prototype;
  10952. _proto.calculator = function calculator(name, oldParsed, parsed) {
  10953. // unset or none
  10954. if (parsed instanceof CSSKeywordValue) {
  10955. return [];
  10956. }
  10957. return parsed;
  10958. };
  10959. return CSSPropertyFilter;
  10960. }();
  10961. function getFontSize(object) {
  10962. var fontSize = object.parsedStyle.fontSize;
  10963. return isNil(fontSize) ? null : fontSize;
  10964. }
  10965. /**
  10966. * <length> & <percentage>
  10967. */
  10968. var CSSPropertyLengthOrPercentage = /*#__PURE__*/function () {
  10969. function CSSPropertyLengthOrPercentage() {
  10970. this.parser = parseLengthOrPercentage;
  10971. this.parserWithCSSDisabled = null;
  10972. this.mixer = mergeNumbers;
  10973. }
  10974. var _proto = CSSPropertyLengthOrPercentage.prototype;
  10975. /**
  10976. * according to parent's bounds
  10977. *
  10978. * @example
  10979. * CSS.percent(50) -> CSS.px(0.5 * parent.width)
  10980. */
  10981. _proto.calculator = function calculator(name, oldParsed, computed, object, registry) {
  10982. if (isNumber(computed)) {
  10983. return computed;
  10984. }
  10985. if (CSSUnitValue.isRelativeUnit(computed.unit)) {
  10986. if (computed.unit === exports.UnitType.kPercentage) {
  10987. // TODO: merge dimensions
  10988. return 0;
  10989. } else if (computed.unit === exports.UnitType.kEms) {
  10990. if (object.parentNode) {
  10991. var fontSize = getFontSize(object.parentNode);
  10992. if (fontSize) {
  10993. fontSize *= computed.value;
  10994. return fontSize;
  10995. } else {
  10996. registry.addUnresolveProperty(object, name);
  10997. }
  10998. } else {
  10999. registry.addUnresolveProperty(object, name);
  11000. }
  11001. return 0;
  11002. } else if (computed.unit === exports.UnitType.kRems) {
  11003. var _object$ownerDocument;
  11004. if (object === null || object === void 0 ? void 0 : (_object$ownerDocument = object.ownerDocument) === null || _object$ownerDocument === void 0 ? void 0 : _object$ownerDocument.documentElement) {
  11005. var _fontSize = getFontSize(object.ownerDocument.documentElement);
  11006. if (_fontSize) {
  11007. _fontSize *= computed.value;
  11008. return _fontSize;
  11009. } else {
  11010. registry.addUnresolveProperty(object, name);
  11011. }
  11012. } else {
  11013. registry.addUnresolveProperty(object, name);
  11014. }
  11015. return 0;
  11016. }
  11017. } else {
  11018. // remove listener if exists
  11019. // registry.unregisterParentGeometryBoundsChangedHandler(object, name);
  11020. // return absolute value
  11021. return computed.value;
  11022. }
  11023. };
  11024. return CSSPropertyLengthOrPercentage;
  11025. }();
  11026. /**
  11027. * format to Tuple2<CSSUnitValue>
  11028. *
  11029. * @example
  11030. * rect.style.lineDash = 10;
  11031. * rect.style.lineDash = [10, 10];
  11032. * rect.style.lineDash = '10 10';
  11033. */
  11034. var CSSPropertyLengthOrPercentage12 = /*#__PURE__*/function () {
  11035. function CSSPropertyLengthOrPercentage12() {
  11036. this.mixer = mergeNumberLists;
  11037. }
  11038. var _proto = CSSPropertyLengthOrPercentage12.prototype;
  11039. _proto.parser = function parser(radius) {
  11040. var parsed = parseDimensionArray(isNumber(radius) ? [radius] : radius);
  11041. var formatted;
  11042. if (parsed.length === 1) {
  11043. formatted = [parsed[0], parsed[0]];
  11044. } else {
  11045. formatted = [parsed[0], parsed[1]];
  11046. }
  11047. return formatted;
  11048. };
  11049. _proto.calculator = function calculator(name, oldParsed, computed) {
  11050. return computed.map(function (c) {
  11051. return c.value;
  11052. });
  11053. };
  11054. return CSSPropertyLengthOrPercentage12;
  11055. }();
  11056. /**
  11057. * used in rounded rect
  11058. *
  11059. * @example
  11060. * rect.style.radius = 10;
  11061. * rect.style.radius = '10 10';
  11062. * rect.style.radius = '10 10 10 10';
  11063. */
  11064. var CSSPropertyLengthOrPercentage14 = /*#__PURE__*/function () {
  11065. function CSSPropertyLengthOrPercentage14() {
  11066. this.mixer = mergeNumberLists;
  11067. }
  11068. var _proto = CSSPropertyLengthOrPercentage14.prototype;
  11069. _proto.parser = function parser(radius) {
  11070. var parsed = parseDimensionArray(isNumber(radius) ? [radius] : radius);
  11071. var formatted;
  11072. // format to Tuple<CSSUnitValue>
  11073. if (parsed.length === 1) {
  11074. formatted = [parsed[0], parsed[0], parsed[0], parsed[0]];
  11075. } else if (parsed.length === 2) {
  11076. formatted = [parsed[0], parsed[1], parsed[0], parsed[1]];
  11077. } else if (parsed.length === 3) {
  11078. formatted = [parsed[0], parsed[1], parsed[2], parsed[1]];
  11079. } else {
  11080. formatted = [parsed[0], parsed[1], parsed[2], parsed[3]];
  11081. }
  11082. return formatted;
  11083. };
  11084. _proto.calculator = function calculator(name, oldParsed, computed) {
  11085. return computed.map(function (c) {
  11086. return c.value;
  11087. });
  11088. };
  11089. return CSSPropertyLengthOrPercentage14;
  11090. }();
  11091. /**
  11092. * local position
  11093. */
  11094. var CSSPropertyLocalPosition = /*#__PURE__*/function (_CSSPropertyLengthOrP) {
  11095. _inheritsLoose(CSSPropertyLocalPosition, _CSSPropertyLengthOrP);
  11096. function CSSPropertyLocalPosition() {
  11097. return _CSSPropertyLengthOrP.apply(this, arguments) || this;
  11098. }
  11099. var _proto = CSSPropertyLocalPosition.prototype;
  11100. /**
  11101. * update local position
  11102. */
  11103. _proto.postProcessor = function postProcessor(object, attributes) {
  11104. var x;
  11105. var y;
  11106. var z;
  11107. switch (object.nodeName) {
  11108. case exports.Shape.CIRCLE:
  11109. case exports.Shape.ELLIPSE:
  11110. var _object$parsedStyle = object.parsedStyle,
  11111. cx = _object$parsedStyle.cx,
  11112. cy = _object$parsedStyle.cy,
  11113. cz = _object$parsedStyle.cz;
  11114. if (!isNil(cx)) {
  11115. x = cx;
  11116. }
  11117. if (!isNil(cy)) {
  11118. y = cy;
  11119. }
  11120. if (!isNil(cz)) {
  11121. z = cz;
  11122. }
  11123. break;
  11124. case exports.Shape.LINE:
  11125. var _object$parsedStyle2 = object.parsedStyle,
  11126. x1 = _object$parsedStyle2.x1,
  11127. x2 = _object$parsedStyle2.x2,
  11128. y1 = _object$parsedStyle2.y1,
  11129. y2 = _object$parsedStyle2.y2;
  11130. var minX = Math.min(x1, x2);
  11131. var minY = Math.min(y1, y2);
  11132. x = minX;
  11133. y = minY;
  11134. z = 0;
  11135. break;
  11136. case exports.Shape.RECT:
  11137. case exports.Shape.IMAGE:
  11138. case exports.Shape.GROUP:
  11139. case exports.Shape.HTML:
  11140. case exports.Shape.TEXT:
  11141. case exports.Shape.MESH:
  11142. if (!isNil(object.parsedStyle.x)) {
  11143. x = object.parsedStyle.x;
  11144. }
  11145. if (!isNil(object.parsedStyle.y)) {
  11146. y = object.parsedStyle.y;
  11147. }
  11148. if (!isNil(object.parsedStyle.z)) {
  11149. z = object.parsedStyle.z;
  11150. }
  11151. break;
  11152. }
  11153. if (object.nodeName !== exports.Shape.PATH && object.nodeName !== exports.Shape.POLYLINE && object.nodeName !== exports.Shape.POLYGON) {
  11154. object.parsedStyle.defX = x || 0;
  11155. object.parsedStyle.defY = y || 0;
  11156. }
  11157. var needResetLocalPosition = !isNil(x) || !isNil(y) || !isNil(z);
  11158. // only if `transform` won't be processed later
  11159. if (needResetLocalPosition && attributes.indexOf('transform') === -1) {
  11160. // account for current transform if needed
  11161. var transform = object.parsedStyle.transform;
  11162. if (transform && transform.length) {
  11163. parsedTransformToMat4(transform, object);
  11164. } else {
  11165. var _object$getLocalPosit = object.getLocalPosition(),
  11166. ox = _object$getLocalPosit[0],
  11167. oy = _object$getLocalPosit[1],
  11168. oz = _object$getLocalPosit[2];
  11169. object.setLocalPosition(isNil(x) ? ox : x, isNil(y) ? oy : y, isNil(z) ? oz : z);
  11170. }
  11171. }
  11172. };
  11173. return CSSPropertyLocalPosition;
  11174. }(CSSPropertyLengthOrPercentage);
  11175. var CSSPropertyMarker = /*#__PURE__*/function () {
  11176. function CSSPropertyMarker() {}
  11177. var _proto = CSSPropertyMarker.prototype;
  11178. _proto.calculator = function calculator(name, oldMarker, newMarker, object) {
  11179. var _newMarker;
  11180. // unset
  11181. if (newMarker instanceof CSSKeywordValue) {
  11182. newMarker = null;
  11183. }
  11184. var cloned = (_newMarker = newMarker) === null || _newMarker === void 0 ? void 0 : _newMarker.cloneNode(true);
  11185. if (cloned) {
  11186. // FIXME: SVG should not inherit parent's style, add a flag here
  11187. cloned.style.isMarker = true;
  11188. }
  11189. return cloned;
  11190. };
  11191. return CSSPropertyMarker;
  11192. }();
  11193. var CSSPropertyNumber = /*#__PURE__*/function () {
  11194. function CSSPropertyNumber() {
  11195. this.mixer = mergeNumbers;
  11196. this.parser = parseNumber;
  11197. this.parserWithCSSDisabled = null;
  11198. }
  11199. var _proto = CSSPropertyNumber.prototype;
  11200. _proto.calculator = function calculator(name, oldParsed, computed) {
  11201. return computed.value;
  11202. };
  11203. return CSSPropertyNumber;
  11204. }();
  11205. var CSSPropertyOffsetDistance = /*#__PURE__*/function () {
  11206. function CSSPropertyOffsetDistance() {
  11207. this.parser = parseNumber;
  11208. this.parserWithCSSDisabled = null;
  11209. this.mixer = clampedMergeNumbers(0, 1);
  11210. }
  11211. var _proto = CSSPropertyOffsetDistance.prototype;
  11212. _proto.calculator = function calculator(name, oldParsed, computed) {
  11213. return computed.value;
  11214. };
  11215. _proto.postProcessor = function postProcessor(object) {
  11216. var _object$parsedStyle = object.parsedStyle,
  11217. offsetPath = _object$parsedStyle.offsetPath,
  11218. offsetDistance = _object$parsedStyle.offsetDistance;
  11219. if (!offsetPath) {
  11220. return;
  11221. }
  11222. var nodeName = offsetPath.nodeName;
  11223. if (nodeName === exports.Shape.LINE || nodeName === exports.Shape.PATH || nodeName === exports.Shape.POLYLINE) {
  11224. // set position in world space
  11225. var point = offsetPath.getPoint(offsetDistance);
  11226. if (point) {
  11227. object.parsedStyle.defX = point.x;
  11228. object.parsedStyle.defY = point.y;
  11229. object.setLocalPosition(point.x, point.y);
  11230. }
  11231. }
  11232. };
  11233. return CSSPropertyOffsetDistance;
  11234. }();
  11235. /**
  11236. * opacity
  11237. */
  11238. var CSSPropertyOpacity = /*#__PURE__*/function () {
  11239. function CSSPropertyOpacity() {
  11240. this.parser = parseNumber;
  11241. this.parserWithCSSDisabled = null;
  11242. this.mixer = clampedMergeNumbers(0, 1);
  11243. }
  11244. var _proto = CSSPropertyOpacity.prototype;
  11245. _proto.calculator = function calculator(name, oldParsed, computed) {
  11246. return computed.value;
  11247. };
  11248. return CSSPropertyOpacity;
  11249. }();
  11250. /**
  11251. * Axis-Aligned Bounding Box
  11252. * 为了便于后续 Frustum Culling,通过查找表定义 p-vertex 和 n-vertex
  11253. * @see https://github.com/antvis/GWebGPUEngine/issues/3
  11254. */
  11255. var AABB = /*#__PURE__*/function () {
  11256. function AABB() {
  11257. this.center = [0, 0, 0];
  11258. this.halfExtents = [0, 0, 0];
  11259. this.min = [0, 0, 0];
  11260. this.max = [0, 0, 0];
  11261. }
  11262. AABB.isEmpty = function isEmpty(aabb) {
  11263. return !aabb || aabb.halfExtents[0] === 0 && aabb.halfExtents[1] === 0 && aabb.halfExtents[2] === 0;
  11264. };
  11265. var _proto = AABB.prototype;
  11266. // center: vec3 = vec3.create();
  11267. // halfExtents: vec3 = vec3.create();
  11268. // min: vec3 = vec3.create();
  11269. // max: vec3 = vec3.create();
  11270. _proto.update = function update(center, halfExtents) {
  11271. copyVec3(this.center, center);
  11272. copyVec3(this.halfExtents, halfExtents);
  11273. subVec3(this.min, this.center, this.halfExtents);
  11274. addVec3(this.max, this.center, this.halfExtents);
  11275. // vec3.copy(this.center, center);
  11276. // vec3.copy(this.halfExtents, halfExtents);
  11277. // vec3.sub(this.min, this.center, this.halfExtents);
  11278. // vec3.add(this.max, this.center, this.halfExtents);
  11279. };
  11280. _proto.setMinMax = function setMinMax(min, max) {
  11281. // vec3.add(this.center, max, min);
  11282. // vec3.scale(this.center, this.center, 0.5);
  11283. // vec3.sub(this.halfExtents, max, min);
  11284. // vec3.scale(this.halfExtents, this.halfExtents, 0.5);
  11285. // vec3.copy(this.min, min);
  11286. // vec3.copy(this.max, max);
  11287. addVec3(this.center, max, min);
  11288. scaleVec3(this.center, this.center, 0.5);
  11289. subVec3(this.halfExtents, max, min);
  11290. scaleVec3(this.halfExtents, this.halfExtents, 0.5);
  11291. copyVec3(this.min, min);
  11292. copyVec3(this.max, max);
  11293. };
  11294. _proto.getMin = function getMin() {
  11295. return this.min;
  11296. };
  11297. _proto.getMax = function getMax() {
  11298. return this.max;
  11299. };
  11300. _proto.add = function add(aabb) {
  11301. if (AABB.isEmpty(aabb)) {
  11302. return;
  11303. }
  11304. if (AABB.isEmpty(this)) {
  11305. this.setMinMax(aabb.getMin(), aabb.getMax());
  11306. return;
  11307. }
  11308. var tc = this.center;
  11309. var tcx = tc[0];
  11310. var tcy = tc[1];
  11311. var tcz = tc[2];
  11312. var th = this.halfExtents;
  11313. var thx = th[0];
  11314. var thy = th[1];
  11315. var thz = th[2];
  11316. var tminx = tcx - thx;
  11317. var tmaxx = tcx + thx;
  11318. var tminy = tcy - thy;
  11319. var tmaxy = tcy + thy;
  11320. var tminz = tcz - thz;
  11321. var tmaxz = tcz + thz;
  11322. var oc = aabb.center;
  11323. var ocx = oc[0];
  11324. var ocy = oc[1];
  11325. var ocz = oc[2];
  11326. var oh = aabb.halfExtents;
  11327. var ohx = oh[0];
  11328. var ohy = oh[1];
  11329. var ohz = oh[2];
  11330. var ominx = ocx - ohx;
  11331. var omaxx = ocx + ohx;
  11332. var ominy = ocy - ohy;
  11333. var omaxy = ocy + ohy;
  11334. var ominz = ocz - ohz;
  11335. var omaxz = ocz + ohz;
  11336. if (ominx < tminx) {
  11337. tminx = ominx;
  11338. }
  11339. if (omaxx > tmaxx) {
  11340. tmaxx = omaxx;
  11341. }
  11342. if (ominy < tminy) {
  11343. tminy = ominy;
  11344. }
  11345. if (omaxy > tmaxy) {
  11346. tmaxy = omaxy;
  11347. }
  11348. if (ominz < tminz) {
  11349. tminz = ominz;
  11350. }
  11351. if (omaxz > tmaxz) {
  11352. tmaxz = omaxz;
  11353. }
  11354. tc[0] = (tminx + tmaxx) * 0.5;
  11355. tc[1] = (tminy + tmaxy) * 0.5;
  11356. tc[2] = (tminz + tmaxz) * 0.5;
  11357. th[0] = (tmaxx - tminx) * 0.5;
  11358. th[1] = (tmaxy - tminy) * 0.5;
  11359. th[2] = (tmaxz - tminz) * 0.5;
  11360. this.min[0] = tminx;
  11361. this.min[1] = tminy;
  11362. this.min[2] = tminz;
  11363. this.max[0] = tmaxx;
  11364. this.max[1] = tmaxy;
  11365. this.max[2] = tmaxz;
  11366. };
  11367. _proto.setFromTransformedAABB = function setFromTransformedAABB(aabb, m) {
  11368. var bc = this.center;
  11369. var br = this.halfExtents;
  11370. var ac = aabb.center;
  11371. var ar = aabb.halfExtents;
  11372. var mx0 = m[0];
  11373. var mx1 = m[4];
  11374. var mx2 = m[8];
  11375. var my0 = m[1];
  11376. var my1 = m[5];
  11377. var my2 = m[9];
  11378. var mz0 = m[2];
  11379. var mz1 = m[6];
  11380. var mz2 = m[10];
  11381. var mx0a = Math.abs(mx0);
  11382. var mx1a = Math.abs(mx1);
  11383. var mx2a = Math.abs(mx2);
  11384. var my0a = Math.abs(my0);
  11385. var my1a = Math.abs(my1);
  11386. var my2a = Math.abs(my2);
  11387. var mz0a = Math.abs(mz0);
  11388. var mz1a = Math.abs(mz1);
  11389. var mz2a = Math.abs(mz2);
  11390. bc[0] = m[12] + mx0 * ac[0] + mx1 * ac[1] + mx2 * ac[2];
  11391. bc[1] = m[13] + my0 * ac[0] + my1 * ac[1] + my2 * ac[2];
  11392. bc[2] = m[14] + mz0 * ac[0] + mz1 * ac[1] + mz2 * ac[2];
  11393. // vec3.set(
  11394. // bc,
  11395. // m[12] + mx0 * ac[0] + mx1 * ac[1] + mx2 * ac[2],
  11396. // m[13] + my0 * ac[0] + my1 * ac[1] + my2 * ac[2],
  11397. // m[14] + mz0 * ac[0] + mz1 * ac[1] + mz2 * ac[2],
  11398. // );
  11399. br[0] = mx0a * ar[0] + mx1a * ar[1] + mx2a * ar[2];
  11400. br[1] = my0a * ar[0] + my1a * ar[1] + my2a * ar[2];
  11401. br[2] = mz0a * ar[0] + mz1a * ar[1] + mz2a * ar[2];
  11402. // vec3.set(
  11403. // br,
  11404. // mx0a * ar[0] + mx1a * ar[1] + mx2a * ar[2],
  11405. // my0a * ar[0] + my1a * ar[1] + my2a * ar[2],
  11406. // mz0a * ar[0] + mz1a * ar[1] + mz2a * ar[2],
  11407. // );
  11408. // this.min = vec3.sub(this.min, bc, br);
  11409. // this.max = vec3.add(this.max, bc, br);
  11410. subVec3(this.min, bc, br);
  11411. addVec3(this.max, bc, br);
  11412. };
  11413. _proto.intersects = function intersects(aabb) {
  11414. var aMax = this.getMax();
  11415. var aMin = this.getMin();
  11416. var bMax = aabb.getMax();
  11417. var bMin = aabb.getMin();
  11418. return aMin[0] <= bMax[0] && aMax[0] >= bMin[0] && aMin[1] <= bMax[1] && aMax[1] >= bMin[1] && aMin[2] <= bMax[2] && aMax[2] >= bMin[2];
  11419. };
  11420. _proto.intersection = function intersection(aabb) {
  11421. if (!this.intersects(aabb)) {
  11422. return null;
  11423. }
  11424. var intersection = new AABB();
  11425. // const min = vec3.max(vec3.create(), this.getMin(), aabb.getMin());
  11426. // const max = vec3.min(vec3.create(), this.getMax(), aabb.getMax());
  11427. var min = maxVec3([0, 0, 0], this.getMin(), aabb.getMin());
  11428. var max = minVec3([0, 0, 0], this.getMax(), aabb.getMax());
  11429. intersection.setMinMax(min, max);
  11430. return intersection;
  11431. }
  11432. // containsPoint(point: vec3) {
  11433. // const min = this.getMin();
  11434. // const max = this.getMax();
  11435. // return !(
  11436. // point[0] < min[0] ||
  11437. // point[0] > max[0] ||
  11438. // point[1] < min[1] ||
  11439. // point[1] > max[1] ||
  11440. // point[2] < min[2] ||
  11441. // point[2] > max[2]
  11442. // );
  11443. // }
  11444. /**
  11445. * get n-vertex
  11446. * @param plane plane of CullingVolume
  11447. */;
  11448. _proto.getNegativeFarPoint = function getNegativeFarPoint(plane) {
  11449. if (plane.pnVertexFlag === 0x111) {
  11450. return copyVec3([0, 0, 0], this.min);
  11451. // return vec3.copy(vec3.create(), this.min);
  11452. } else if (plane.pnVertexFlag === 0x110) {
  11453. return [this.min[0], this.min[1], this.max[2]];
  11454. // return vec3.fromValues(this.min[0], this.min[1], this.max[2]);
  11455. } else if (plane.pnVertexFlag === 0x101) {
  11456. return [this.min[0], this.max[1], this.min[2]];
  11457. // return vec3.fromValues(this.min[0], this.max[1], this.min[2]);
  11458. } else if (plane.pnVertexFlag === 0x100) {
  11459. return [this.min[0], this.max[1], this.max[2]];
  11460. // return vec3.fromValues(this.min[0], this.max[1], this.max[2]);
  11461. } else if (plane.pnVertexFlag === 0x011) {
  11462. return [this.max[0], this.min[1], this.min[2]];
  11463. // return vec3.fromValues(this.max[0], this.min[1], this.min[2]);
  11464. } else if (plane.pnVertexFlag === 0x010) {
  11465. return [this.max[0], this.min[1], this.max[2]];
  11466. // return vec3.fromValues(this.max[0], this.min[1], this.max[2]);
  11467. } else if (plane.pnVertexFlag === 0x001) {
  11468. return [this.max[0], this.max[1], this.min[2]];
  11469. // return vec3.fromValues(this.max[0], this.max[1], this.min[2]);
  11470. } else {
  11471. return [this.max[0], this.max[1], this.max[2]];
  11472. // return vec3.fromValues(this.max[0], this.max[1], this.max[2]);
  11473. }
  11474. }
  11475. /**
  11476. * get p-vertex
  11477. * @param plane plane of CullingVolume
  11478. */;
  11479. _proto.getPositiveFarPoint = function getPositiveFarPoint(plane) {
  11480. if (plane.pnVertexFlag === 0x111) {
  11481. return copyVec3([0, 0, 0], this.max);
  11482. // return vec3.copy(vec3.create(), this.max);
  11483. } else if (plane.pnVertexFlag === 0x110) {
  11484. return [this.max[0], this.max[1], this.min[2]];
  11485. // return vec3.fromValues(this.max[0], this.max[1], this.min[2]);
  11486. } else if (plane.pnVertexFlag === 0x101) {
  11487. return [this.max[0], this.min[1], this.max[2]];
  11488. // return vec3.fromValues(this.max[0], this.min[1], this.max[2]);
  11489. } else if (plane.pnVertexFlag === 0x100) {
  11490. return [this.max[0], this.min[1], this.min[2]];
  11491. // return vec3.fromValues(this.max[0], this.min[1], this.min[2]);
  11492. } else if (plane.pnVertexFlag === 0x011) {
  11493. return [this.min[0], this.max[1], this.max[2]];
  11494. // return vec3.fromValues(this.min[0], this.max[1], this.max[2]);
  11495. } else if (plane.pnVertexFlag === 0x010) {
  11496. return [this.min[0], this.max[1], this.min[2]];
  11497. // return vec3.fromValues(this.min[0], this.max[1], this.min[2]);
  11498. } else if (plane.pnVertexFlag === 0x001) {
  11499. return [this.min[0], this.min[1], this.max[2]];
  11500. // return vec3.fromValues(this.min[0], this.min[1], this.max[2]);
  11501. } else {
  11502. return [this.min[0], this.min[1], this.min[2]];
  11503. // return vec3.fromValues(this.min[0], this.min[1], this.min[2]);
  11504. }
  11505. };
  11506. return AABB;
  11507. }();
  11508. var Plane = /*#__PURE__*/function () {
  11509. function Plane(distance, normal) {
  11510. this.distance = void 0;
  11511. this.normal = void 0;
  11512. /**
  11513. * lookup table for p-vertex & n-vertex when doing frustum culling
  11514. */
  11515. this.pnVertexFlag = void 0;
  11516. this.distance = distance || 0;
  11517. this.normal = normal || fromValues$2(0, 1, 0);
  11518. this.updatePNVertexFlag();
  11519. }
  11520. var _proto = Plane.prototype;
  11521. _proto.updatePNVertexFlag = function updatePNVertexFlag() {
  11522. this.pnVertexFlag = (Number(this.normal[0] >= 0) << 8) + (Number(this.normal[1] >= 0) << 4) + Number(this.normal[2] >= 0);
  11523. };
  11524. _proto.distanceToPoint = function distanceToPoint(point) {
  11525. return dot(point, this.normal) - this.distance;
  11526. };
  11527. _proto.normalize = function normalize() {
  11528. var invLen = 1 / len(this.normal);
  11529. scale$1(this.normal, this.normal, invLen);
  11530. this.distance *= invLen;
  11531. };
  11532. _proto.intersectsLine = function intersectsLine(start, end, point) {
  11533. var d0 = this.distanceToPoint(start);
  11534. var d1 = this.distanceToPoint(end);
  11535. var t = d0 / (d0 - d1);
  11536. var intersects = t >= 0 && t <= 1;
  11537. if (intersects && point) {
  11538. lerp(point, start, end, t);
  11539. }
  11540. return intersects;
  11541. };
  11542. return Plane;
  11543. }();
  11544. (function (Mask) {
  11545. Mask[Mask["OUTSIDE"] = 4294967295] = "OUTSIDE";
  11546. Mask[Mask["INSIDE"] = 0] = "INSIDE";
  11547. Mask[Mask["INDETERMINATE"] = 2147483647] = "INDETERMINATE";
  11548. })(exports.Mask || (exports.Mask = {}));
  11549. var Frustum = /*#__PURE__*/function () {
  11550. function Frustum(planes) {
  11551. this.planes = [];
  11552. if (planes) {
  11553. this.planes = planes;
  11554. } else {
  11555. for (var i = 0; i < 6; i++) {
  11556. this.planes.push(new Plane());
  11557. }
  11558. }
  11559. }
  11560. /**
  11561. * extract 6 planes from projectionMatrix
  11562. * @see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
  11563. */
  11564. var _proto = Frustum.prototype;
  11565. _proto.extractFromVPMatrix = function extractFromVPMatrix(projectionMatrix) {
  11566. // @ts-ignore
  11567. var m0 = projectionMatrix[0],
  11568. m1 = projectionMatrix[1],
  11569. m2 = projectionMatrix[2],
  11570. m3 = projectionMatrix[3],
  11571. m4 = projectionMatrix[4],
  11572. m5 = projectionMatrix[5],
  11573. m6 = projectionMatrix[6],
  11574. m7 = projectionMatrix[7],
  11575. m8 = projectionMatrix[8],
  11576. m9 = projectionMatrix[9],
  11577. m10 = projectionMatrix[10],
  11578. m11 = projectionMatrix[11],
  11579. m12 = projectionMatrix[12],
  11580. m13 = projectionMatrix[13],
  11581. m14 = projectionMatrix[14],
  11582. m15 = projectionMatrix[15];
  11583. // right
  11584. set$1(this.planes[0].normal, m3 - m0, m7 - m4, m11 - m8);
  11585. this.planes[0].distance = m15 - m12;
  11586. // left
  11587. set$1(this.planes[1].normal, m3 + m0, m7 + m4, m11 + m8);
  11588. this.planes[1].distance = m15 + m12;
  11589. // bottom
  11590. set$1(this.planes[2].normal, m3 + m1, m7 + m5, m11 + m9);
  11591. this.planes[2].distance = m15 + m13;
  11592. // top
  11593. set$1(this.planes[3].normal, m3 - m1, m7 - m5, m11 - m9);
  11594. this.planes[3].distance = m15 - m13;
  11595. // far
  11596. set$1(this.planes[4].normal, m3 - m2, m7 - m6, m11 - m10);
  11597. this.planes[4].distance = m15 - m14;
  11598. // near
  11599. set$1(this.planes[5].normal, m3 + m2, m7 + m6, m11 + m10);
  11600. this.planes[5].distance = m15 + m14;
  11601. this.planes.forEach(function (plane) {
  11602. plane.normalize();
  11603. plane.updatePNVertexFlag();
  11604. });
  11605. };
  11606. return Frustum;
  11607. }();
  11608. var Point = /*#__PURE__*/function () {
  11609. function Point(x, y) {
  11610. if (x === void 0) {
  11611. x = 0;
  11612. }
  11613. if (y === void 0) {
  11614. y = 0;
  11615. }
  11616. this.x = 0;
  11617. this.y = 0;
  11618. this.x = x;
  11619. this.y = y;
  11620. }
  11621. var _proto = Point.prototype;
  11622. _proto.clone = function clone() {
  11623. return new Point(this.x, this.y);
  11624. };
  11625. _proto.copyFrom = function copyFrom(p) {
  11626. this.x = p.x;
  11627. this.y = p.y;
  11628. };
  11629. return Point;
  11630. }();
  11631. var Rectangle = /*#__PURE__*/function () {
  11632. function Rectangle(x, y, width, height) {
  11633. this.x = void 0;
  11634. this.y = void 0;
  11635. this.width = void 0;
  11636. this.height = void 0;
  11637. this.left = void 0;
  11638. this.right = void 0;
  11639. this.top = void 0;
  11640. this.bottom = void 0;
  11641. this.x = x;
  11642. this.y = y;
  11643. this.width = width;
  11644. this.height = height;
  11645. this.left = x;
  11646. this.right = x + width;
  11647. this.top = y;
  11648. this.bottom = y + height;
  11649. }
  11650. var _proto = Rectangle.prototype;
  11651. _proto.toJSON = function toJSON() {};
  11652. return Rectangle;
  11653. }();
  11654. var CSSPropertyPath = /*#__PURE__*/function () {
  11655. function CSSPropertyPath() {
  11656. /**
  11657. * path2Curve
  11658. */
  11659. this.parser = parsePath;
  11660. this.parserWithCSSDisabled = parsePath;
  11661. this.mixer = mergePaths;
  11662. }
  11663. var _proto = CSSPropertyPath.prototype;
  11664. _proto.calculator = function calculator(name, oldParsed, parsed) {
  11665. // unset
  11666. if (parsed instanceof CSSKeywordValue && parsed.value === 'unset') {
  11667. return {
  11668. absolutePath: [],
  11669. hasArc: false,
  11670. segments: [],
  11671. polygons: [],
  11672. polylines: [],
  11673. curve: null,
  11674. totalLength: 0,
  11675. rect: new Rectangle(0, 0, 0, 0)
  11676. };
  11677. }
  11678. return parsed;
  11679. };
  11680. /**
  11681. * update local position
  11682. */
  11683. _proto.postProcessor = function postProcessor(object, attributes) {
  11684. if (object.nodeName === exports.Shape.PATH && attributes.indexOf('transform') === -1) {
  11685. var _object$parsedStyle = object.parsedStyle,
  11686. _object$parsedStyle$d = _object$parsedStyle.defX,
  11687. defX = _object$parsedStyle$d === void 0 ? 0 : _object$parsedStyle$d,
  11688. _object$parsedStyle$d2 = _object$parsedStyle.defY,
  11689. defY = _object$parsedStyle$d2 === void 0 ? 0 : _object$parsedStyle$d2;
  11690. object.setLocalPosition(defX, defY);
  11691. }
  11692. };
  11693. return CSSPropertyPath;
  11694. }();
  11695. var CSSPropertyPoints = /*#__PURE__*/function () {
  11696. function CSSPropertyPoints() {
  11697. this.parser = parsePoints;
  11698. this.mixer = mergePoints;
  11699. }
  11700. var _proto = CSSPropertyPoints.prototype;
  11701. /**
  11702. * update local position
  11703. */
  11704. _proto.postProcessor = function postProcessor(object, attributes) {
  11705. if ((object.nodeName === exports.Shape.POLYGON || object.nodeName === exports.Shape.POLYLINE) && attributes.indexOf('transform') === -1) {
  11706. var _object$parsedStyle = object.parsedStyle,
  11707. defX = _object$parsedStyle.defX,
  11708. defY = _object$parsedStyle.defY;
  11709. object.setLocalPosition(defX, defY);
  11710. }
  11711. };
  11712. return CSSPropertyPoints;
  11713. }();
  11714. var CSSPropertyShadowBlur = /*#__PURE__*/function (_CSSPropertyLengthOrP) {
  11715. _inheritsLoose(CSSPropertyShadowBlur, _CSSPropertyLengthOrP);
  11716. function CSSPropertyShadowBlur() {
  11717. var _this;
  11718. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  11719. args[_key] = arguments[_key];
  11720. }
  11721. _this = _CSSPropertyLengthOrP.call.apply(_CSSPropertyLengthOrP, [this].concat(args)) || this;
  11722. _this.mixer = clampedMergeNumbers(0, Infinity);
  11723. return _this;
  11724. }
  11725. return CSSPropertyShadowBlur;
  11726. }(CSSPropertyLengthOrPercentage);
  11727. var CSSPropertyText = /*#__PURE__*/function () {
  11728. function CSSPropertyText() {}
  11729. var _proto = CSSPropertyText.prototype;
  11730. _proto.calculator = function calculator(name, oldParsed, parsed, object) {
  11731. if (parsed instanceof CSSKeywordValue) {
  11732. if (parsed.value === 'unset') {
  11733. return '';
  11734. } else {
  11735. return parsed.value;
  11736. }
  11737. }
  11738. // allow number as valid text content
  11739. return "" + parsed;
  11740. };
  11741. _proto.postProcessor = function postProcessor(object) {
  11742. object.nodeValue = "" + object.parsedStyle.text || '';
  11743. };
  11744. return CSSPropertyText;
  11745. }();
  11746. /**
  11747. * it must transform after text get parsed
  11748. * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/text-transform
  11749. */
  11750. var CSSPropertyTextTransform = /*#__PURE__*/function () {
  11751. function CSSPropertyTextTransform() {}
  11752. var _proto = CSSPropertyTextTransform.prototype;
  11753. _proto.calculator = function calculator(name, oldParsed, parsed, object) {
  11754. var rawText = object.getAttribute('text');
  11755. if (rawText) {
  11756. var transformedText = rawText;
  11757. if (parsed.value === 'capitalize') {
  11758. transformedText = rawText.charAt(0).toUpperCase() + rawText.slice(1);
  11759. } else if (parsed.value === 'lowercase') {
  11760. transformedText = rawText.toLowerCase();
  11761. } else if (parsed.value === 'uppercase') {
  11762. transformedText = rawText.toUpperCase();
  11763. }
  11764. object.parsedStyle.text = transformedText;
  11765. }
  11766. return parsed.value;
  11767. };
  11768. return CSSPropertyTextTransform;
  11769. }();
  11770. /**
  11771. * @see /zh/docs/api/animation#支持变换的属性
  11772. *
  11773. * support the following formats like CSS Transform:
  11774. *
  11775. * scale
  11776. * * scale(x, y)
  11777. * * scaleX(x)
  11778. * * scaleY(x)
  11779. * * scaleZ(z)
  11780. * * scale3d(x, y, z)
  11781. *
  11782. * translate (unit: none, px, %(relative to its bounds))
  11783. * * translate(x, y) eg. translate(0, 0) translate(0, 30px) translate(100%, 100%)
  11784. * * translateX(0)
  11785. * * translateY(0)
  11786. * * translateZ(0)
  11787. * * translate3d(0, 0, 0)
  11788. *
  11789. * rotate (unit: deg rad turn)
  11790. * * rotate(0.5turn) rotate(30deg) rotate(1rad)
  11791. *
  11792. * none
  11793. *
  11794. * unsupported for now:
  11795. * * calc() eg. translate(calc(100% + 10px))
  11796. * * matrix/matrix3d()
  11797. * * skew/skewX/skewY
  11798. * * perspective
  11799. */
  11800. var CSSPropertyTransform = /*#__PURE__*/function () {
  11801. function CSSPropertyTransform() {
  11802. this.parser = parseTransform;
  11803. this.parserWithCSSDisabled = parseTransform;
  11804. this.mixer = mergeTransforms;
  11805. }
  11806. var _proto = CSSPropertyTransform.prototype;
  11807. _proto.calculator = function calculator(name, oldParsed, parsed, object) {
  11808. // 'none'
  11809. if (parsed instanceof CSSKeywordValue) {
  11810. return [];
  11811. }
  11812. return parsed;
  11813. };
  11814. _proto.postProcessor = function postProcessor(object) {
  11815. var transform = object.parsedStyle.transform;
  11816. parsedTransformToMat4(transform, object);
  11817. };
  11818. return CSSPropertyTransform;
  11819. }();
  11820. /**
  11821. * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/transform-origin
  11822. * @example
  11823. * [10px, 10px] [10%, 10%]
  11824. */
  11825. var CSSPropertyTransformOrigin = function CSSPropertyTransformOrigin() {
  11826. this.parser = parseTransformOrigin;
  11827. };
  11828. /**
  11829. * @see https://doc.babylonjs.com/how_to/optimizing_your_scene#changing-mesh-culling-strategy
  11830. */
  11831. (function (Strategy) {
  11832. Strategy[Strategy["Standard"] = 0] = "Standard";
  11833. })(exports.Strategy || (exports.Strategy = {}));
  11834. (function (SortReason) {
  11835. SortReason[SortReason["ADDED"] = 0] = "ADDED";
  11836. SortReason[SortReason["REMOVED"] = 1] = "REMOVED";
  11837. SortReason[SortReason["Z_INDEX_CHANGED"] = 2] = "Z_INDEX_CHANGED";
  11838. })(exports.SortReason || (exports.SortReason = {}));
  11839. var CSSPropertyZIndex = /*#__PURE__*/function () {
  11840. function CSSPropertyZIndex() {
  11841. this.parser = parseNumber;
  11842. }
  11843. var _proto = CSSPropertyZIndex.prototype;
  11844. _proto.calculator = function calculator(name, oldParsed, computed, object) {
  11845. return computed.value;
  11846. };
  11847. _proto.postProcessor = function postProcessor(object) {
  11848. if (object.parentNode) {
  11849. var parentEntity = object.parentNode;
  11850. var parentRenderable = parentEntity.renderable;
  11851. var parentSortable = parentEntity.sortable;
  11852. if (parentRenderable) {
  11853. parentRenderable.dirty = true;
  11854. }
  11855. // need re-sort on parent
  11856. if (parentSortable) {
  11857. parentSortable.dirty = true;
  11858. parentSortable.dirtyReason = exports.SortReason.Z_INDEX_CHANGED;
  11859. }
  11860. }
  11861. };
  11862. return CSSPropertyZIndex;
  11863. }();
  11864. /**
  11865. * canvas.customElements
  11866. *
  11867. * @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry
  11868. */
  11869. var CustomElementRegistry = /*#__PURE__*/function () {
  11870. function CustomElementRegistry() {
  11871. this.registry = {};
  11872. this.define(exports.Shape.CIRCLE, Circle);
  11873. this.define(exports.Shape.ELLIPSE, Ellipse);
  11874. this.define(exports.Shape.RECT, Rect);
  11875. this.define(exports.Shape.IMAGE, Image);
  11876. this.define(exports.Shape.LINE, Line);
  11877. this.define(exports.Shape.GROUP, Group);
  11878. this.define(exports.Shape.PATH, Path);
  11879. this.define(exports.Shape.POLYGON, Polygon);
  11880. this.define(exports.Shape.POLYLINE, Polyline);
  11881. this.define(exports.Shape.TEXT, Text);
  11882. this.define(exports.Shape.HTML, HTML);
  11883. }
  11884. var _proto = CustomElementRegistry.prototype;
  11885. _proto.define = function define(name, constructor) {
  11886. this.registry[name] = constructor;
  11887. }
  11888. /**
  11889. * @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/get
  11890. */;
  11891. _proto.get = function get(name) {
  11892. return this.registry[name];
  11893. };
  11894. return CustomElementRegistry;
  11895. }();
  11896. function isFederatedEvent(value) {
  11897. return !!value.type;
  11898. }
  11899. /**
  11900. * An DOM-compatible synthetic event implementation that is "forwarded" on behalf of an original
  11901. * FederatedEvent or native {@link https://dom.spec.whatwg.org/#event Event}.
  11902. */
  11903. var FederatedEvent = /*#__PURE__*/function () {
  11904. /**
  11905. * The event boundary which manages this event. Propagation can only occur
  11906. * within the boundary's jurisdiction.
  11907. */
  11908. function FederatedEvent(manager) {
  11909. /**
  11910. * The type of event, supports the following:
  11911. * * pointerdown
  11912. * * touchstart
  11913. * * mousedown
  11914. * * rightdown
  11915. * * ...
  11916. */
  11917. this.type = void 0;
  11918. /**
  11919. * The propagation phase.
  11920. * @see https://developer.mozilla.org/en-US/docs/Web/API/Event/eventPhase
  11921. */
  11922. this.eventPhase = FederatedEvent.prototype.NONE;
  11923. /**
  11924. * can be used to implement event delegation
  11925. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/target
  11926. */
  11927. this.target = void 0;
  11928. /**
  11929. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/bubbles
  11930. */
  11931. this.bubbles = true;
  11932. /**
  11933. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/cancelBubble
  11934. */
  11935. this.cancelBubble = true;
  11936. /**
  11937. * @see https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable
  11938. */
  11939. this.cancelable = false;
  11940. /** the event target when listeners binded */
  11941. this.currentTarget = void 0;
  11942. /** Flags whether the default response of the user agent was prevent through this event. */
  11943. this.defaultPrevented = false;
  11944. /**
  11945. * timestamp when the event created
  11946. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/timeStamp
  11947. */
  11948. this.timeStamp = void 0;
  11949. /**
  11950. * the original event.
  11951. */
  11952. this.nativeEvent = void 0;
  11953. /** The original event that caused this event, if any. */
  11954. this.originalEvent = void 0;
  11955. /** Flags whether propagation was stopped. */
  11956. this.propagationStopped = false;
  11957. /** Flags whether propagation was immediately stopped. */
  11958. this.propagationImmediatelyStopped = false;
  11959. this.manager = void 0;
  11960. /** Event-specific detail */
  11961. this.detail = void 0;
  11962. /**
  11963. * The coordinates of the evnet relative to the nearest DOM layer.
  11964. * This is a non-standard property.
  11965. */
  11966. this.layer = new Point();
  11967. /**
  11968. * The coordinates of the event relative to the DOM document.
  11969. * This is a non-standard property.
  11970. * relative to the DOM document.
  11971. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/pageX
  11972. */
  11973. this.page = new Point();
  11974. /**
  11975. * relative to Canvas, origin is left-top
  11976. */
  11977. this.canvas = new Point();
  11978. /**
  11979. * relative to Viewport, account for Camera
  11980. */
  11981. this.viewport = new Point();
  11982. this.path = void 0;
  11983. /**
  11984. * @see https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/view
  11985. */
  11986. this.view = void 0;
  11987. this.which = void 0;
  11988. this.returnValue = void 0;
  11989. this.srcElement = void 0;
  11990. this.composed = false;
  11991. this.isTrusted = void 0;
  11992. this.NONE = 0;
  11993. this.CAPTURING_PHASE = 1;
  11994. this.AT_TARGET = 2;
  11995. this.BUBBLING_PHASE = 3;
  11996. this.manager = manager;
  11997. }
  11998. var _proto = FederatedEvent.prototype;
  11999. /**
  12000. * The propagation path for this event
  12001. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/composedPath
  12002. *
  12003. * So composedPath()[0] represents the original target.
  12004. * @see https://polymer-library.polymer-project.org/3.0/docs/devguide/events#retargeting
  12005. */
  12006. _proto.composedPath = function composedPath() {
  12007. if (this.manager && (!this.path || this.path[0] !== this.target)) {
  12008. this.path = this.target ? this.manager.propagationPath(this.target) : [];
  12009. }
  12010. return this.path;
  12011. }
  12012. /**
  12013. * @deprecated
  12014. */;
  12015. /**
  12016. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/preventDefault
  12017. */
  12018. _proto.preventDefault = function preventDefault() {
  12019. if (this.nativeEvent instanceof Event && this.nativeEvent.cancelable) {
  12020. this.nativeEvent.preventDefault();
  12021. }
  12022. this.defaultPrevented = true;
  12023. }
  12024. /**
  12025. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/stopImmediatePropagation
  12026. */;
  12027. _proto.stopImmediatePropagation = function stopImmediatePropagation() {
  12028. this.propagationImmediatelyStopped = true;
  12029. }
  12030. /**
  12031. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/stopPropagation
  12032. */;
  12033. _proto.stopPropagation = function stopPropagation() {
  12034. this.propagationStopped = true;
  12035. };
  12036. /**
  12037. * added for compatibility with DOM Event,
  12038. * deprecated props and methods
  12039. */
  12040. _proto.initEvent = function initEvent() {};
  12041. _proto.initUIEvent = function initUIEvent() {};
  12042. _proto.clone = function clone() {
  12043. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  12044. };
  12045. _createClass(FederatedEvent, [{
  12046. key: "name",
  12047. get:
  12048. /**
  12049. * @deprecated
  12050. */
  12051. function get() {
  12052. return this.type;
  12053. }
  12054. }, {
  12055. key: "layerX",
  12056. get: function get() {
  12057. return this.layer.x;
  12058. }
  12059. }, {
  12060. key: "layerY",
  12061. get: function get() {
  12062. return this.layer.y;
  12063. }
  12064. }, {
  12065. key: "pageX",
  12066. get: function get() {
  12067. return this.page.x;
  12068. }
  12069. }, {
  12070. key: "pageY",
  12071. get: function get() {
  12072. return this.page.y;
  12073. }
  12074. }, {
  12075. key: "x",
  12076. get: function get() {
  12077. return this.canvas.x;
  12078. }
  12079. }, {
  12080. key: "y",
  12081. get: function get() {
  12082. return this.canvas.y;
  12083. }
  12084. }, {
  12085. key: "canvasX",
  12086. get: function get() {
  12087. return this.canvas.x;
  12088. }
  12089. }, {
  12090. key: "canvasY",
  12091. get: function get() {
  12092. return this.canvas.y;
  12093. }
  12094. }, {
  12095. key: "viewportX",
  12096. get: function get() {
  12097. return this.viewport.x;
  12098. }
  12099. }, {
  12100. key: "viewportY",
  12101. get: function get() {
  12102. return this.viewport.y;
  12103. }
  12104. }, {
  12105. key: "propagationPath",
  12106. get: function get() {
  12107. return this.composedPath();
  12108. }
  12109. }]);
  12110. return FederatedEvent;
  12111. }();
  12112. /**
  12113. * @see https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events
  12114. *
  12115. * @example
  12116. const event = new CustomEvent('build', { detail: { prop1: 'xx' } });
  12117. circle.addEventListener('build', (e) => {
  12118. e.target; // circle
  12119. e.detail; // { prop1: 'xx' }
  12120. });
  12121. circle.dispatchEvent(event);
  12122. */
  12123. var CustomEvent = /*#__PURE__*/function (_FederatedEvent) {
  12124. _inheritsLoose(CustomEvent, _FederatedEvent);
  12125. // eslint-disable-next-line @typescript-eslint/ban-types
  12126. function CustomEvent(eventName, object) {
  12127. var _this;
  12128. _this = _FederatedEvent.call(this, null) || this;
  12129. _this.type = eventName;
  12130. _this.detail = object;
  12131. // compatible with G 3.0
  12132. Object.assign(_assertThisInitialized(_this), object);
  12133. return _this;
  12134. }
  12135. return CustomEvent;
  12136. }(FederatedEvent);
  12137. var eventemitter3 = createCommonjsModule(function (module) {
  12138. var has = Object.prototype.hasOwnProperty
  12139. , prefix = '~';
  12140. /**
  12141. * Constructor to create a storage for our `EE` objects.
  12142. * An `Events` instance is a plain object whose properties are event names.
  12143. *
  12144. * @constructor
  12145. * @private
  12146. */
  12147. function Events() {}
  12148. //
  12149. // We try to not inherit from `Object.prototype`. In some engines creating an
  12150. // instance in this way is faster than calling `Object.create(null)` directly.
  12151. // If `Object.create(null)` is not supported we prefix the event names with a
  12152. // character to make sure that the built-in object properties are not
  12153. // overridden or used as an attack vector.
  12154. //
  12155. if (Object.create) {
  12156. Events.prototype = Object.create(null);
  12157. //
  12158. // This hack is needed because the `__proto__` property is still inherited in
  12159. // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
  12160. //
  12161. if (!new Events().__proto__) prefix = false;
  12162. }
  12163. /**
  12164. * Representation of a single event listener.
  12165. *
  12166. * @param {Function} fn The listener function.
  12167. * @param {*} context The context to invoke the listener with.
  12168. * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
  12169. * @constructor
  12170. * @private
  12171. */
  12172. function EE(fn, context, once) {
  12173. this.fn = fn;
  12174. this.context = context;
  12175. this.once = once || false;
  12176. }
  12177. /**
  12178. * Add a listener for a given event.
  12179. *
  12180. * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
  12181. * @param {(String|Symbol)} event The event name.
  12182. * @param {Function} fn The listener function.
  12183. * @param {*} context The context to invoke the listener with.
  12184. * @param {Boolean} once Specify if the listener is a one-time listener.
  12185. * @returns {EventEmitter}
  12186. * @private
  12187. */
  12188. function addListener(emitter, event, fn, context, once) {
  12189. if (typeof fn !== 'function') {
  12190. throw new TypeError('The listener must be a function');
  12191. }
  12192. var listener = new EE(fn, context || emitter, once)
  12193. , evt = prefix ? prefix + event : event;
  12194. if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
  12195. else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
  12196. else emitter._events[evt] = [emitter._events[evt], listener];
  12197. return emitter;
  12198. }
  12199. /**
  12200. * Clear event by name.
  12201. *
  12202. * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
  12203. * @param {(String|Symbol)} evt The Event name.
  12204. * @private
  12205. */
  12206. function clearEvent(emitter, evt) {
  12207. if (--emitter._eventsCount === 0) emitter._events = new Events();
  12208. else delete emitter._events[evt];
  12209. }
  12210. /**
  12211. * Minimal `EventEmitter` interface that is molded against the Node.js
  12212. * `EventEmitter` interface.
  12213. *
  12214. * @constructor
  12215. * @public
  12216. */
  12217. function EventEmitter() {
  12218. this._events = new Events();
  12219. this._eventsCount = 0;
  12220. }
  12221. /**
  12222. * Return an array listing the events for which the emitter has registered
  12223. * listeners.
  12224. *
  12225. * @returns {Array}
  12226. * @public
  12227. */
  12228. EventEmitter.prototype.eventNames = function eventNames() {
  12229. var names = []
  12230. , events
  12231. , name;
  12232. if (this._eventsCount === 0) return names;
  12233. for (name in (events = this._events)) {
  12234. if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
  12235. }
  12236. if (Object.getOwnPropertySymbols) {
  12237. return names.concat(Object.getOwnPropertySymbols(events));
  12238. }
  12239. return names;
  12240. };
  12241. /**
  12242. * Return the listeners registered for a given event.
  12243. *
  12244. * @param {(String|Symbol)} event The event name.
  12245. * @returns {Array} The registered listeners.
  12246. * @public
  12247. */
  12248. EventEmitter.prototype.listeners = function listeners(event) {
  12249. var evt = prefix ? prefix + event : event
  12250. , handlers = this._events[evt];
  12251. if (!handlers) return [];
  12252. if (handlers.fn) return [handlers.fn];
  12253. for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
  12254. ee[i] = handlers[i].fn;
  12255. }
  12256. return ee;
  12257. };
  12258. /**
  12259. * Return the number of listeners listening to a given event.
  12260. *
  12261. * @param {(String|Symbol)} event The event name.
  12262. * @returns {Number} The number of listeners.
  12263. * @public
  12264. */
  12265. EventEmitter.prototype.listenerCount = function listenerCount(event) {
  12266. var evt = prefix ? prefix + event : event
  12267. , listeners = this._events[evt];
  12268. if (!listeners) return 0;
  12269. if (listeners.fn) return 1;
  12270. return listeners.length;
  12271. };
  12272. /**
  12273. * Calls each of the listeners registered for a given event.
  12274. *
  12275. * @param {(String|Symbol)} event The event name.
  12276. * @returns {Boolean} `true` if the event had listeners, else `false`.
  12277. * @public
  12278. */
  12279. EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
  12280. var evt = prefix ? prefix + event : event;
  12281. if (!this._events[evt]) return false;
  12282. var listeners = this._events[evt]
  12283. , len = arguments.length
  12284. , args
  12285. , i;
  12286. if (listeners.fn) {
  12287. if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
  12288. switch (len) {
  12289. case 1: return listeners.fn.call(listeners.context), true;
  12290. case 2: return listeners.fn.call(listeners.context, a1), true;
  12291. case 3: return listeners.fn.call(listeners.context, a1, a2), true;
  12292. case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
  12293. case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
  12294. case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
  12295. }
  12296. for (i = 1, args = new Array(len -1); i < len; i++) {
  12297. args[i - 1] = arguments[i];
  12298. }
  12299. listeners.fn.apply(listeners.context, args);
  12300. } else {
  12301. var length = listeners.length
  12302. , j;
  12303. for (i = 0; i < length; i++) {
  12304. if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
  12305. switch (len) {
  12306. case 1: listeners[i].fn.call(listeners[i].context); break;
  12307. case 2: listeners[i].fn.call(listeners[i].context, a1); break;
  12308. case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
  12309. case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
  12310. default:
  12311. if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
  12312. args[j - 1] = arguments[j];
  12313. }
  12314. listeners[i].fn.apply(listeners[i].context, args);
  12315. }
  12316. }
  12317. }
  12318. return true;
  12319. };
  12320. /**
  12321. * Add a listener for a given event.
  12322. *
  12323. * @param {(String|Symbol)} event The event name.
  12324. * @param {Function} fn The listener function.
  12325. * @param {*} [context=this] The context to invoke the listener with.
  12326. * @returns {EventEmitter} `this`.
  12327. * @public
  12328. */
  12329. EventEmitter.prototype.on = function on(event, fn, context) {
  12330. return addListener(this, event, fn, context, false);
  12331. };
  12332. /**
  12333. * Add a one-time listener for a given event.
  12334. *
  12335. * @param {(String|Symbol)} event The event name.
  12336. * @param {Function} fn The listener function.
  12337. * @param {*} [context=this] The context to invoke the listener with.
  12338. * @returns {EventEmitter} `this`.
  12339. * @public
  12340. */
  12341. EventEmitter.prototype.once = function once(event, fn, context) {
  12342. return addListener(this, event, fn, context, true);
  12343. };
  12344. /**
  12345. * Remove the listeners of a given event.
  12346. *
  12347. * @param {(String|Symbol)} event The event name.
  12348. * @param {Function} fn Only remove the listeners that match this function.
  12349. * @param {*} context Only remove the listeners that have this context.
  12350. * @param {Boolean} once Only remove one-time listeners.
  12351. * @returns {EventEmitter} `this`.
  12352. * @public
  12353. */
  12354. EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
  12355. var evt = prefix ? prefix + event : event;
  12356. if (!this._events[evt]) return this;
  12357. if (!fn) {
  12358. clearEvent(this, evt);
  12359. return this;
  12360. }
  12361. var listeners = this._events[evt];
  12362. if (listeners.fn) {
  12363. if (
  12364. listeners.fn === fn &&
  12365. (!once || listeners.once) &&
  12366. (!context || listeners.context === context)
  12367. ) {
  12368. clearEvent(this, evt);
  12369. }
  12370. } else {
  12371. for (var i = 0, events = [], length = listeners.length; i < length; i++) {
  12372. if (
  12373. listeners[i].fn !== fn ||
  12374. (once && !listeners[i].once) ||
  12375. (context && listeners[i].context !== context)
  12376. ) {
  12377. events.push(listeners[i]);
  12378. }
  12379. }
  12380. //
  12381. // Reset the array, or remove it completely if we have no more listeners.
  12382. //
  12383. if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
  12384. else clearEvent(this, evt);
  12385. }
  12386. return this;
  12387. };
  12388. /**
  12389. * Remove all listeners, or those of the specified event.
  12390. *
  12391. * @param {(String|Symbol)} [event] The event name.
  12392. * @returns {EventEmitter} `this`.
  12393. * @public
  12394. */
  12395. EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
  12396. var evt;
  12397. if (event) {
  12398. evt = prefix ? prefix + event : event;
  12399. if (this._events[evt]) clearEvent(this, evt);
  12400. } else {
  12401. this._events = new Events();
  12402. this._eventsCount = 0;
  12403. }
  12404. return this;
  12405. };
  12406. //
  12407. // Alias methods names because people roll like that.
  12408. //
  12409. EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
  12410. EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  12411. //
  12412. // Expose the prefix.
  12413. //
  12414. EventEmitter.prefixed = prefix;
  12415. //
  12416. // Allow `EventEmitter` to be imported as module namespace.
  12417. //
  12418. EventEmitter.EventEmitter = EventEmitter;
  12419. //
  12420. // Expose the module.
  12421. //
  12422. {
  12423. module.exports = EventEmitter;
  12424. }
  12425. });
  12426. var DELEGATION_SPLITTER = ':';
  12427. /**
  12428. * Objects that can receive events and may have listeners for them.
  12429. * eg. Element, Canvas, DisplayObject
  12430. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
  12431. */
  12432. var EventTarget = /*#__PURE__*/function () {
  12433. function EventTarget() {
  12434. /**
  12435. * event emitter
  12436. */
  12437. this.emitter = new eventemitter3();
  12438. }
  12439. var _proto = EventTarget.prototype;
  12440. /**
  12441. * @deprecated
  12442. * @alias addEventListener
  12443. */
  12444. _proto.on = function on(type, listener, options) {
  12445. this.addEventListener(type, listener, options);
  12446. return this;
  12447. }
  12448. /**
  12449. * support `capture` & `once` in options
  12450. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget/addEventListener
  12451. */;
  12452. _proto.addEventListener = function addEventListener(type, listener, options) {
  12453. var capture = isBoolean(options) && options || isObject(options) && options.capture;
  12454. var once = isObject(options) && options.once;
  12455. var context = isFunction(listener) ? undefined : listener;
  12456. // compatible with G 3.0
  12457. // support using delegate name in event type, eg. 'node:click'
  12458. var useDelegatedName = false;
  12459. var delegatedName = '';
  12460. if (type.indexOf(DELEGATION_SPLITTER) > -1) {
  12461. var _type$split = type.split(DELEGATION_SPLITTER),
  12462. name = _type$split[0],
  12463. eventType = _type$split[1];
  12464. type = eventType;
  12465. delegatedName = name;
  12466. useDelegatedName = true;
  12467. }
  12468. type = capture ? type + "capture" : type;
  12469. listener = isFunction(listener) ? listener : listener.handleEvent;
  12470. // compatible with G 3.0
  12471. if (useDelegatedName) {
  12472. var originListener = listener;
  12473. listener = function listener() {
  12474. var _args$0$target;
  12475. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  12476. args[_key] = arguments[_key];
  12477. }
  12478. if (((_args$0$target = args[0].target) === null || _args$0$target === void 0 ? void 0 : _args$0$target.name) !== delegatedName) {
  12479. return;
  12480. }
  12481. // @ts-ignore
  12482. originListener.apply(void 0, args);
  12483. };
  12484. }
  12485. if (once) {
  12486. this.emitter.once(type, listener, context);
  12487. } else {
  12488. this.emitter.on(type, listener, context);
  12489. }
  12490. return this;
  12491. }
  12492. /**
  12493. * @deprecated
  12494. * @alias removeEventListener
  12495. */;
  12496. _proto.off = function off(type, listener, options) {
  12497. if (type) {
  12498. this.removeEventListener(type, listener, options);
  12499. } else {
  12500. // remove all listeners
  12501. this.removeAllEventListeners();
  12502. }
  12503. return this;
  12504. };
  12505. _proto.removeAllEventListeners = function removeAllEventListeners() {
  12506. this.emitter.removeAllListeners();
  12507. };
  12508. _proto.removeEventListener = function removeEventListener(type, listener, options) {
  12509. var _listener;
  12510. var capture = isBoolean(options) && options || isObject(options) && options.capture;
  12511. var context = isFunction(listener) ? undefined : listener;
  12512. type = capture ? type + "capture" : type;
  12513. listener = isFunction(listener) ? listener : (_listener = listener) === null || _listener === void 0 ? void 0 : _listener.handleEvent;
  12514. this.emitter.off(type, listener, context);
  12515. return this;
  12516. }
  12517. /**
  12518. * @deprecated
  12519. * @alias dispatchEvent
  12520. */
  12521. // eslint-disable-next-line @typescript-eslint/ban-types
  12522. ;
  12523. _proto.emit = function emit(eventName, object) {
  12524. this.dispatchEvent(new CustomEvent(eventName, object));
  12525. }
  12526. /**
  12527. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent
  12528. */;
  12529. _proto.dispatchEvent = function dispatchEvent(e, skipPropagate) {
  12530. if (skipPropagate === void 0) {
  12531. skipPropagate = false;
  12532. }
  12533. if (!isFederatedEvent(e)) {
  12534. throw new Error('DisplayObject cannot propagate events outside of the Federated Events API');
  12535. }
  12536. // should account for Element / Document / Canvas
  12537. var canvas;
  12538. // @ts-ignore
  12539. if (this.document) {
  12540. canvas = this;
  12541. // @ts-ignore
  12542. } else if (this.defaultView) {
  12543. canvas = this.defaultView;
  12544. } else {
  12545. var _this$ownerDocument;
  12546. canvas = (_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : _this$ownerDocument.defaultView;
  12547. }
  12548. // assign event manager
  12549. if (canvas) {
  12550. var _e$manager;
  12551. e.manager = canvas.getEventService() || null;
  12552. if (!e.manager) {
  12553. return false;
  12554. }
  12555. e.defaultPrevented = false;
  12556. e.path = [];
  12557. if (!skipPropagate) {
  12558. e.target = this;
  12559. }
  12560. (_e$manager = e.manager) === null || _e$manager === void 0 ? void 0 : _e$manager.dispatchEvent(e, e.type, skipPropagate);
  12561. }
  12562. return !e.defaultPrevented;
  12563. };
  12564. return EventTarget;
  12565. }();
  12566. /**
  12567. * @see https://developer.mozilla.org/en-US/docs/Web/API/Node
  12568. */
  12569. var Node = /*#__PURE__*/function (_EventTarget) {
  12570. _inheritsLoose(Node, _EventTarget);
  12571. function Node() {
  12572. var _this;
  12573. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  12574. args[_key] = arguments[_key];
  12575. }
  12576. _this = _EventTarget.call.apply(_EventTarget, [this].concat(args)) || this;
  12577. _this.shadow = false;
  12578. /**
  12579. * points to canvas.document
  12580. * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/ownerDocument
  12581. */
  12582. _this.ownerDocument = null;
  12583. /**
  12584. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/isConnected
  12585. * @example
  12586. circle.isConnected; // false
  12587. canvas.appendChild(circle);
  12588. circle.isConnected; // true
  12589. */
  12590. _this.isConnected = false;
  12591. /**
  12592. * Returns node's node document's document base URL.
  12593. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node
  12594. */
  12595. _this.baseURI = '';
  12596. /**
  12597. * Returns the children.
  12598. * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes
  12599. */
  12600. _this.childNodes = [];
  12601. /**
  12602. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/nodeType
  12603. */
  12604. _this.nodeType = 0;
  12605. /**
  12606. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/nodeName
  12607. */
  12608. _this.nodeName = '';
  12609. /**
  12610. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/nodeValue
  12611. */
  12612. _this.nodeValue = null;
  12613. /**
  12614. * @see https://developer.mozilla.org/en-US/docs/Web/API/ParentNode
  12615. */
  12616. _this.parentNode = null;
  12617. return _this;
  12618. }
  12619. Node.isNode = function isNode(target) {
  12620. return !!target.childNodes;
  12621. };
  12622. var _proto = Node.prototype;
  12623. /**
  12624. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/getRootNode
  12625. */
  12626. _proto.getRootNode = function getRootNode(opts) {
  12627. if (opts === void 0) {
  12628. opts = {};
  12629. }
  12630. if (this.parentNode) {
  12631. return this.parentNode.getRootNode(opts);
  12632. }
  12633. if (opts.composed && this.host) {
  12634. return this.host.getRootNode(opts);
  12635. }
  12636. return this;
  12637. };
  12638. _proto.hasChildNodes = function hasChildNodes() {
  12639. return this.childNodes.length > 0;
  12640. };
  12641. _proto.isDefaultNamespace = function isDefaultNamespace(namespace) {
  12642. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  12643. };
  12644. _proto.lookupNamespaceURI = function lookupNamespaceURI(prefix) {
  12645. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  12646. };
  12647. _proto.lookupPrefix = function lookupPrefix(namespace) {
  12648. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  12649. };
  12650. _proto.normalize = function normalize() {
  12651. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  12652. }
  12653. /**
  12654. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/isEqualNode
  12655. */;
  12656. _proto.isEqualNode = function isEqualNode(otherNode) {
  12657. // TODO: compare 2 nodes, not sameness
  12658. return this === otherNode;
  12659. };
  12660. _proto.isSameNode = function isSameNode(otherNode) {
  12661. return this.isEqualNode(otherNode);
  12662. };
  12663. /**
  12664. * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
  12665. * @see https://github.com/b-fuze/deno-dom/blob/master/src/dom/node.ts#L338
  12666. */
  12667. _proto.compareDocumentPosition = function compareDocumentPosition(other) {
  12668. if (other === this) {
  12669. // same node
  12670. return 0;
  12671. }
  12672. // if (!(other instanceof Node)) {
  12673. // throw new TypeError(
  12674. // 'Node.compareDocumentPosition: Argument 1 does not implement interface Node.',
  12675. // );
  12676. // }
  12677. var node1Root = other;
  12678. // eslint-disable-next-line @typescript-eslint/no-this-alias
  12679. var node2Root = this;
  12680. var node1Hierarchy = [node1Root];
  12681. var node2Hierarchy = [node2Root];
  12682. while ((_node1Root$parentNode = node1Root.parentNode) !== null && _node1Root$parentNode !== void 0 ? _node1Root$parentNode : node2Root.parentNode) {
  12683. var _node1Root$parentNode;
  12684. node1Root = node1Root.parentNode ? (node1Hierarchy.push(node1Root.parentNode), node1Root.parentNode) : node1Root;
  12685. node2Root = node2Root.parentNode ? (node2Hierarchy.push(node2Root.parentNode), node2Root.parentNode) : node2Root;
  12686. }
  12687. // Check if they don't share the same root node
  12688. if (node1Root !== node2Root) {
  12689. return Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | Node.DOCUMENT_POSITION_PRECEDING;
  12690. }
  12691. var longerHierarchy = node1Hierarchy.length > node2Hierarchy.length ? node1Hierarchy : node2Hierarchy;
  12692. var shorterHierarchy = longerHierarchy === node1Hierarchy ? node2Hierarchy : node1Hierarchy;
  12693. // Check if either is a container of the other
  12694. if (longerHierarchy[longerHierarchy.length - shorterHierarchy.length] === shorterHierarchy[0]) {
  12695. return longerHierarchy === node1Hierarchy ?
  12696. // other is a child of this
  12697. Node.DOCUMENT_POSITION_CONTAINED_BY | Node.DOCUMENT_POSITION_FOLLOWING :
  12698. // this is a child of other
  12699. Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING;
  12700. }
  12701. // Find their first common ancestor and see whether they
  12702. // are preceding or following
  12703. var longerStart = longerHierarchy.length - shorterHierarchy.length;
  12704. for (var i = shorterHierarchy.length - 1; i >= 0; i--) {
  12705. var shorterHierarchyNode = shorterHierarchy[i];
  12706. var longerHierarchyNode = longerHierarchy[longerStart + i];
  12707. // We found the first common ancestor
  12708. if (longerHierarchyNode !== shorterHierarchyNode) {
  12709. var siblings = shorterHierarchyNode.parentNode.childNodes;
  12710. if (siblings.indexOf(shorterHierarchyNode) < siblings.indexOf(longerHierarchyNode)) {
  12711. // Shorter is before longer
  12712. if (shorterHierarchy === node1Hierarchy) {
  12713. // Other is before this
  12714. return Node.DOCUMENT_POSITION_PRECEDING;
  12715. } else {
  12716. // This is before other
  12717. return Node.DOCUMENT_POSITION_FOLLOWING;
  12718. }
  12719. } else {
  12720. // Longer is before shorter
  12721. if (longerHierarchy === node1Hierarchy) {
  12722. // Other is before this
  12723. return Node.DOCUMENT_POSITION_PRECEDING;
  12724. } else {
  12725. // Other is after this
  12726. return Node.DOCUMENT_POSITION_FOLLOWING;
  12727. }
  12728. }
  12729. }
  12730. }
  12731. return Node.DOCUMENT_POSITION_FOLLOWING;
  12732. }
  12733. /**
  12734. * @deprecated
  12735. * @alias contains
  12736. */;
  12737. _proto.contain = function contain(other) {
  12738. return this.contains(other);
  12739. };
  12740. _proto.contains = function contains(other) {
  12741. // the node itself, one of its direct children
  12742. var tmp = other;
  12743. // @see https://developer.mozilla.org/en-US/docs/Web/API/Node/contains
  12744. while (tmp && this !== tmp) {
  12745. tmp = tmp.parentNode;
  12746. }
  12747. return !!tmp;
  12748. };
  12749. _proto.getAncestor = function getAncestor(n) {
  12750. // eslint-disable-next-line @typescript-eslint/no-this-alias
  12751. var temp = this;
  12752. while (n > 0 && temp) {
  12753. temp = temp.parentNode;
  12754. n--;
  12755. }
  12756. return temp;
  12757. };
  12758. _proto.forEach = function forEach(callback, assigned) {
  12759. if (assigned === void 0) {
  12760. assigned = false;
  12761. }
  12762. if (!callback(this)) {
  12763. (assigned ? this.childNodes.slice() : this.childNodes).forEach(function (child) {
  12764. child.forEach(callback);
  12765. });
  12766. }
  12767. };
  12768. _createClass(Node, [{
  12769. key: "textContent",
  12770. get:
  12771. /**
  12772. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/textContent
  12773. */
  12774. function get() {
  12775. var out = '';
  12776. if (this.nodeName === exports.Shape.TEXT) {
  12777. // @ts-ignore
  12778. out += this.style.text;
  12779. }
  12780. for (var _iterator = _createForOfIteratorHelperLoose(this.childNodes), _step; !(_step = _iterator()).done;) {
  12781. var child = _step.value;
  12782. if (child.nodeName === exports.Shape.TEXT) {
  12783. out += child.nodeValue;
  12784. } else {
  12785. out += child.textContent;
  12786. }
  12787. }
  12788. return out;
  12789. },
  12790. set: function set(content) {
  12791. var _this2 = this;
  12792. // remove all children
  12793. this.childNodes.slice().forEach(function (child) {
  12794. _this2.removeChild(child);
  12795. });
  12796. if (this.nodeName === exports.Shape.TEXT) {
  12797. // @ts-ignore
  12798. this.style.text = "" + content;
  12799. }
  12800. }
  12801. }, {
  12802. key: "parent",
  12803. get:
  12804. /**
  12805. * @deprecated
  12806. * @alias parentNode
  12807. */
  12808. function get() {
  12809. return this.parentNode;
  12810. }
  12811. }, {
  12812. key: "parentElement",
  12813. get: function get() {
  12814. return null;
  12815. }
  12816. }, {
  12817. key: "nextSibling",
  12818. get: function get() {
  12819. return null;
  12820. }
  12821. }, {
  12822. key: "previousSibling",
  12823. get: function get() {
  12824. return null;
  12825. }
  12826. }, {
  12827. key: "firstChild",
  12828. get: function get() {
  12829. return this.childNodes.length > 0 ? this.childNodes[0] : null;
  12830. }
  12831. }, {
  12832. key: "lastChild",
  12833. get: function get() {
  12834. return this.childNodes.length > 0 ? this.childNodes[this.childNodes.length - 1] : null;
  12835. }
  12836. }]);
  12837. return Node;
  12838. }(EventTarget);
  12839. /**
  12840. * Both nodes are in different documents or different trees in the same document.
  12841. */
  12842. Node.DOCUMENT_POSITION_DISCONNECTED = 1;
  12843. /**
  12844. * otherNode precedes the node in either a pre-order depth-first traversal
  12845. * of a tree containing both (e.g., as an ancestor or previous sibling or a descendant of a previous sibling or previous sibling of an ancestor) or (if they are disconnected) in an arbitrary but consistent ordering.
  12846. */
  12847. Node.DOCUMENT_POSITION_PRECEDING = 2;
  12848. /**
  12849. * otherNode follows the node in either a pre-order depth-first traversal of a tree containing both (e.g., as a descendant or following sibling or a descendant of a following sibling or following sibling of an ancestor) or (if they are disconnected) in an arbitrary but consistent ordering.
  12850. */
  12851. Node.DOCUMENT_POSITION_FOLLOWING = 4;
  12852. /**
  12853. * otherNode is an ancestor of the node.
  12854. */
  12855. Node.DOCUMENT_POSITION_CONTAINS = 8;
  12856. /**
  12857. * otherNode is a descendant of the node.
  12858. */
  12859. Node.DOCUMENT_POSITION_CONTAINED_BY = 16;
  12860. /**
  12861. * The result relies upon arbitrary and/or implementation-specific behavior and is not guaranteed to be portable.
  12862. */
  12863. Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32;
  12864. /**
  12865. * the entry of DOM tree
  12866. * Document -> Node -> EventTarget
  12867. * @see https://developer.mozilla.org/en-US/docs/Web/API/Document
  12868. */
  12869. var Document = /*#__PURE__*/function (_Node) {
  12870. _inheritsLoose(Document, _Node);
  12871. function Document() {
  12872. var _this;
  12873. _this = _Node.call(this) || this;
  12874. /**
  12875. * only document has defaultView, points to canvas,
  12876. * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/defaultView
  12877. */
  12878. _this.defaultView = null;
  12879. /**
  12880. * the root element of document, eg. <html>
  12881. * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement
  12882. */
  12883. _this.documentElement = void 0;
  12884. /**
  12885. * document.timeline in WAAPI
  12886. */
  12887. _this.timeline = void 0;
  12888. _this.ownerDocument = null;
  12889. _this.nodeName = 'document';
  12890. // create timeline
  12891. try {
  12892. _this.timeline = new runtime.AnimationTimeline(_assertThisInitialized(_this));
  12893. } catch (e) {}
  12894. /**
  12895. * for inherited properties, the initial value is used on the root element only,
  12896. * as long as no specified value is supplied.
  12897. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/initial_value
  12898. */
  12899. var initialStyle = {};
  12900. BUILT_IN_PROPERTIES.forEach(function (_ref) {
  12901. var n = _ref.n,
  12902. inh = _ref.inh,
  12903. d = _ref.d;
  12904. if (inh && d) {
  12905. initialStyle[n] = isFunction(d) ? d(exports.Shape.GROUP) : d;
  12906. }
  12907. });
  12908. // like <html> in DOM tree
  12909. _this.documentElement = new Group({
  12910. id: 'g-root',
  12911. style: initialStyle
  12912. });
  12913. _this.documentElement.ownerDocument = _assertThisInitialized(_this);
  12914. _this.documentElement.parentNode = _assertThisInitialized(_this);
  12915. _this.childNodes = [_this.documentElement];
  12916. return _this;
  12917. }
  12918. var _proto = Document.prototype;
  12919. /**
  12920. * @example const circle = document.createElement('circle', { style: { r: 10 } });
  12921. */
  12922. _proto.createElement = function createElement(tagName, options) {
  12923. // @observablehq/plot will create <svg>
  12924. if (tagName === 'svg') {
  12925. return this.documentElement;
  12926. }
  12927. // d3 will use <tspan>
  12928. var clazz = this.defaultView.customElements.get(tagName);
  12929. if (!clazz) {
  12930. console.warn('Unsupported tagName: ', tagName);
  12931. clazz = tagName === 'tspan' ? Text : Group;
  12932. }
  12933. var shape = new clazz(options);
  12934. shape.ownerDocument = this;
  12935. return shape;
  12936. };
  12937. _proto.createElementNS = function createElementNS(namespaceURI, tagName, options) {
  12938. return this.createElement(tagName, options);
  12939. };
  12940. _proto.cloneNode = function cloneNode(deep) {
  12941. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  12942. };
  12943. _proto.destroy = function destroy() {
  12944. try {
  12945. this.documentElement.destroyChildren();
  12946. this.timeline.destroy();
  12947. } catch (e) {}
  12948. }
  12949. /**
  12950. * Picking 2D graphics with RBush based on BBox, fast but inaccurate.
  12951. */;
  12952. _proto.elementsFromBBox = function elementsFromBBox(minX, minY, maxX, maxY) {
  12953. var rBush = this.defaultView.context.rBushRoot;
  12954. var rBushNodes = rBush.search({
  12955. minX: minX,
  12956. minY: minY,
  12957. maxX: maxX,
  12958. maxY: maxY
  12959. });
  12960. var hitTestList = [];
  12961. rBushNodes.forEach(function (_ref2) {
  12962. var displayObject = _ref2.displayObject;
  12963. var pointerEvents = displayObject.parsedStyle.pointerEvents;
  12964. // account for `visibility`
  12965. // @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
  12966. var isVisibilityAffected = ['auto', 'visiblepainted', 'visiblefill', 'visiblestroke', 'visible'].includes(pointerEvents);
  12967. if ((!isVisibilityAffected || isVisibilityAffected && displayObject.isVisible()) && !displayObject.isCulled() && displayObject.isInteractive()) {
  12968. hitTestList.push(displayObject);
  12969. }
  12970. });
  12971. // find group with max z-index
  12972. hitTestList.sort(function (a, b) {
  12973. return b.sortable.renderOrder - a.sortable.renderOrder;
  12974. });
  12975. return hitTestList;
  12976. };
  12977. _proto.elementFromPointSync = function elementFromPointSync(x, y) {
  12978. var _this$defaultView$can = this.defaultView.canvas2Viewport({
  12979. x: x,
  12980. y: y
  12981. }),
  12982. viewportX = _this$defaultView$can.x,
  12983. viewportY = _this$defaultView$can.y;
  12984. var _this$defaultView$get = this.defaultView.getConfig(),
  12985. width = _this$defaultView$get.width,
  12986. height = _this$defaultView$get.height;
  12987. // outside canvas' viewport
  12988. if (viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height) {
  12989. return null;
  12990. }
  12991. var _this$defaultView$vie = this.defaultView.viewport2Client({
  12992. x: viewportX,
  12993. y: viewportY
  12994. }),
  12995. clientX = _this$defaultView$vie.x,
  12996. clientY = _this$defaultView$vie.y;
  12997. var _this$defaultView$get2 = this.defaultView.getRenderingService().hooks.pickSync.call({
  12998. topmost: true,
  12999. position: {
  13000. x: x,
  13001. y: y,
  13002. viewportX: viewportX,
  13003. viewportY: viewportY,
  13004. clientX: clientX,
  13005. clientY: clientY
  13006. },
  13007. picked: []
  13008. }),
  13009. picked = _this$defaultView$get2.picked;
  13010. return picked && picked[0] || this.documentElement;
  13011. }
  13012. /**
  13013. * Do picking with API instead of triggering interactive events.
  13014. *
  13015. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementFromPoint
  13016. */;
  13017. _proto.elementFromPoint =
  13018. /*#__PURE__*/
  13019. function () {
  13020. var _elementFromPoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(x, y) {
  13021. var _this$defaultView$can2, viewportX, viewportY, _this$defaultView$get3, width, height, _this$defaultView$vie2, clientX, clientY, _yield$this$defaultVi, picked;
  13022. return _regeneratorRuntime().wrap(function _callee$(_context) {
  13023. while (1) switch (_context.prev = _context.next) {
  13024. case 0:
  13025. _this$defaultView$can2 = this.defaultView.canvas2Viewport({
  13026. x: x,
  13027. y: y
  13028. }), viewportX = _this$defaultView$can2.x, viewportY = _this$defaultView$can2.y;
  13029. _this$defaultView$get3 = this.defaultView.getConfig(), width = _this$defaultView$get3.width, height = _this$defaultView$get3.height; // outside canvas' viewport
  13030. if (!(viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height)) {
  13031. _context.next = 4;
  13032. break;
  13033. }
  13034. return _context.abrupt("return", null);
  13035. case 4:
  13036. _this$defaultView$vie2 = this.defaultView.viewport2Client({
  13037. x: viewportX,
  13038. y: viewportY
  13039. }), clientX = _this$defaultView$vie2.x, clientY = _this$defaultView$vie2.y;
  13040. _context.next = 7;
  13041. return this.defaultView.getRenderingService().hooks.pick.promise({
  13042. topmost: true,
  13043. position: {
  13044. x: x,
  13045. y: y,
  13046. viewportX: viewportX,
  13047. viewportY: viewportY,
  13048. clientX: clientX,
  13049. clientY: clientY
  13050. },
  13051. picked: []
  13052. });
  13053. case 7:
  13054. _yield$this$defaultVi = _context.sent;
  13055. picked = _yield$this$defaultVi.picked;
  13056. return _context.abrupt("return", picked && picked[0] || this.documentElement);
  13057. case 10:
  13058. case "end":
  13059. return _context.stop();
  13060. }
  13061. }, _callee, this);
  13062. }));
  13063. function elementFromPoint(_x, _x2) {
  13064. return _elementFromPoint.apply(this, arguments);
  13065. }
  13066. return elementFromPoint;
  13067. }();
  13068. _proto.elementsFromPointSync = function elementsFromPointSync(x, y) {
  13069. var _this$defaultView$can3 = this.defaultView.canvas2Viewport({
  13070. x: x,
  13071. y: y
  13072. }),
  13073. viewportX = _this$defaultView$can3.x,
  13074. viewportY = _this$defaultView$can3.y;
  13075. var _this$defaultView$get4 = this.defaultView.getConfig(),
  13076. width = _this$defaultView$get4.width,
  13077. height = _this$defaultView$get4.height;
  13078. // outside canvas' viewport
  13079. if (viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height) {
  13080. return [];
  13081. }
  13082. var _this$defaultView$vie3 = this.defaultView.viewport2Client({
  13083. x: viewportX,
  13084. y: viewportY
  13085. }),
  13086. clientX = _this$defaultView$vie3.x,
  13087. clientY = _this$defaultView$vie3.y;
  13088. var _this$defaultView$get5 = this.defaultView.getRenderingService().hooks.pickSync.call({
  13089. topmost: false,
  13090. position: {
  13091. x: x,
  13092. y: y,
  13093. viewportX: viewportX,
  13094. viewportY: viewportY,
  13095. clientX: clientX,
  13096. clientY: clientY
  13097. },
  13098. picked: []
  13099. }),
  13100. picked = _this$defaultView$get5.picked;
  13101. if (picked[picked.length - 1] !== this.documentElement) {
  13102. picked.push(this.documentElement);
  13103. }
  13104. return picked;
  13105. }
  13106. /**
  13107. * Do picking with API instead of triggering interactive events.
  13108. *
  13109. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementsFromPoint
  13110. */;
  13111. _proto.elementsFromPoint =
  13112. /*#__PURE__*/
  13113. function () {
  13114. var _elementsFromPoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(x, y) {
  13115. var _this$defaultView$can4, viewportX, viewportY, _this$defaultView$get6, width, height, _this$defaultView$vie4, clientX, clientY, _yield$this$defaultVi2, picked;
  13116. return _regeneratorRuntime().wrap(function _callee2$(_context2) {
  13117. while (1) switch (_context2.prev = _context2.next) {
  13118. case 0:
  13119. _this$defaultView$can4 = this.defaultView.canvas2Viewport({
  13120. x: x,
  13121. y: y
  13122. }), viewportX = _this$defaultView$can4.x, viewportY = _this$defaultView$can4.y;
  13123. _this$defaultView$get6 = this.defaultView.getConfig(), width = _this$defaultView$get6.width, height = _this$defaultView$get6.height; // outside canvas' viewport
  13124. if (!(viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height)) {
  13125. _context2.next = 4;
  13126. break;
  13127. }
  13128. return _context2.abrupt("return", []);
  13129. case 4:
  13130. _this$defaultView$vie4 = this.defaultView.viewport2Client({
  13131. x: viewportX,
  13132. y: viewportY
  13133. }), clientX = _this$defaultView$vie4.x, clientY = _this$defaultView$vie4.y;
  13134. _context2.next = 7;
  13135. return this.defaultView.getRenderingService().hooks.pick.promise({
  13136. topmost: false,
  13137. position: {
  13138. x: x,
  13139. y: y,
  13140. viewportX: viewportX,
  13141. viewportY: viewportY,
  13142. clientX: clientX,
  13143. clientY: clientY
  13144. },
  13145. picked: []
  13146. });
  13147. case 7:
  13148. _yield$this$defaultVi2 = _context2.sent;
  13149. picked = _yield$this$defaultVi2.picked;
  13150. if (picked[picked.length - 1] !== this.documentElement) {
  13151. picked.push(this.documentElement);
  13152. }
  13153. return _context2.abrupt("return", picked);
  13154. case 11:
  13155. case "end":
  13156. return _context2.stop();
  13157. }
  13158. }, _callee2, this);
  13159. }));
  13160. function elementsFromPoint(_x3, _x4) {
  13161. return _elementsFromPoint.apply(this, arguments);
  13162. }
  13163. return elementsFromPoint;
  13164. }()
  13165. /**
  13166. * eg. Uncaught DOMException: Failed to execute 'appendChild' on 'Node': Only one element on document allowed.
  13167. */
  13168. ;
  13169. _proto.appendChild = function appendChild(newChild, index) {
  13170. throw new Error(ERROR_MSG_USE_DOCUMENT_ELEMENT);
  13171. };
  13172. _proto.insertBefore = function insertBefore(newChild, refChild) {
  13173. throw new Error(ERROR_MSG_USE_DOCUMENT_ELEMENT);
  13174. };
  13175. _proto.removeChild = function removeChild(oldChild, destroy) {
  13176. throw new Error(ERROR_MSG_USE_DOCUMENT_ELEMENT);
  13177. };
  13178. _proto.replaceChild = function replaceChild(newChild, oldChild, destroy) {
  13179. throw new Error(ERROR_MSG_USE_DOCUMENT_ELEMENT);
  13180. };
  13181. _proto.append = function append() {
  13182. throw new Error(ERROR_MSG_USE_DOCUMENT_ELEMENT);
  13183. };
  13184. _proto.prepend = function prepend() {
  13185. throw new Error(ERROR_MSG_USE_DOCUMENT_ELEMENT);
  13186. }
  13187. /**
  13188. * Execute query on documentElement.
  13189. */;
  13190. _proto.getElementById = function getElementById(id) {
  13191. return this.documentElement.getElementById(id);
  13192. };
  13193. _proto.getElementsByName = function getElementsByName(name) {
  13194. return this.documentElement.getElementsByName(name);
  13195. };
  13196. _proto.getElementsByTagName = function getElementsByTagName(tagName) {
  13197. return this.documentElement.getElementsByTagName(tagName);
  13198. };
  13199. _proto.getElementsByClassName = function getElementsByClassName(className) {
  13200. return this.documentElement.getElementsByClassName(className);
  13201. };
  13202. _proto.querySelector = function querySelector(selectors) {
  13203. return this.documentElement.querySelector(selectors);
  13204. };
  13205. _proto.querySelectorAll = function querySelectorAll(selectors) {
  13206. return this.documentElement.querySelectorAll(selectors);
  13207. };
  13208. _proto.find = function find(filter) {
  13209. return this.documentElement.find(filter);
  13210. };
  13211. _proto.findAll = function findAll(filter) {
  13212. return this.documentElement.findAll(filter);
  13213. };
  13214. _createClass(Document, [{
  13215. key: "children",
  13216. get: function get() {
  13217. return this.childNodes;
  13218. }
  13219. }, {
  13220. key: "childElementCount",
  13221. get: function get() {
  13222. return this.childNodes.length;
  13223. }
  13224. }, {
  13225. key: "firstElementChild",
  13226. get: function get() {
  13227. return this.firstChild;
  13228. }
  13229. }, {
  13230. key: "lastElementChild",
  13231. get: function get() {
  13232. return this.lastChild;
  13233. }
  13234. }]);
  13235. return Document;
  13236. }(Node);
  13237. /**
  13238. * built-in events for element
  13239. * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationEvent
  13240. *
  13241. * TODO: use MutationObserver instead
  13242. * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
  13243. */
  13244. (function (ElementEvent) {
  13245. ElementEvent["REPARENT"] = "reparent";
  13246. ElementEvent["DESTROY"] = "destroy";
  13247. /**
  13248. * @see https://www.w3.org/TR/DOM-Level-3-Events/#event-type-DOMAttrModified
  13249. */
  13250. ElementEvent["ATTR_MODIFIED"] = "DOMAttrModified";
  13251. /**
  13252. * it has been inserted
  13253. * @see https://www.w3.org/TR/DOM-Level-3-Events/#event-type-DOMNodeInserted
  13254. */
  13255. ElementEvent["INSERTED"] = "DOMNodeInserted";
  13256. /**
  13257. * it is being removed
  13258. * @see https://www.w3.org/TR/DOM-Level-3-Events/#event-type-DOMNodeRemoved
  13259. */
  13260. ElementEvent["REMOVED"] = "removed";
  13261. /**
  13262. * @see https://www.w3.org/TR/DOM-Level-3-Events/#domnodeinsertedintodocument
  13263. */
  13264. ElementEvent["MOUNTED"] = "DOMNodeInsertedIntoDocument";
  13265. /**
  13266. * @see https://www.w3.org/TR/DOM-Level-3-Events/#domnoderemovedfromdocument
  13267. */
  13268. ElementEvent["UNMOUNTED"] = "DOMNodeRemovedFromDocument";
  13269. ElementEvent["BOUNDS_CHANGED"] = "bounds-changed";
  13270. ElementEvent["CULLED"] = "culled";
  13271. })(exports.ElementEvent || (exports.ElementEvent = {}));
  13272. var MutationEvent = /*#__PURE__*/function (_FederatedEvent) {
  13273. _inheritsLoose(MutationEvent, _FederatedEvent);
  13274. function MutationEvent(typeArg, relatedNode, prevValue, newValue, attrName, attrChange, prevParsedValue, newParsedValue) {
  13275. var _this;
  13276. _this = _FederatedEvent.call(this, null) || this;
  13277. _this.relatedNode = void 0;
  13278. _this.prevValue = void 0;
  13279. _this.newValue = void 0;
  13280. _this.attrName = void 0;
  13281. _this.attrChange = void 0;
  13282. _this.prevParsedValue = void 0;
  13283. _this.newParsedValue = void 0;
  13284. _this.relatedNode = relatedNode;
  13285. _this.prevValue = prevValue;
  13286. _this.newValue = newValue;
  13287. _this.attrName = attrName;
  13288. _this.attrChange = attrChange;
  13289. _this.prevParsedValue = prevParsedValue;
  13290. _this.newParsedValue = newParsedValue;
  13291. _this.type = typeArg;
  13292. return _this;
  13293. }
  13294. return MutationEvent;
  13295. }(FederatedEvent);
  13296. MutationEvent.ADDITION = 2;
  13297. MutationEvent.MODIFICATION = 1;
  13298. MutationEvent.REMOVAL = 3;
  13299. var entityCounter = 0;
  13300. function resetEntityCounter() {
  13301. entityCounter = 0;
  13302. }
  13303. var insertedEvent = new MutationEvent(exports.ElementEvent.INSERTED, null, '', '', '', 0, '', '');
  13304. var removedEvent = new MutationEvent(exports.ElementEvent.REMOVED, null, '', '', '', 0, '', '');
  13305. var destroyEvent = new CustomEvent(exports.ElementEvent.DESTROY);
  13306. /**
  13307. * Has following capabilities:
  13308. * * Node insert/remove, eg. appendChild, removeChild, remove...
  13309. * * Query eg. querySelector getElementById...
  13310. * * Animation
  13311. */
  13312. var Element = /*#__PURE__*/function (_Node) {
  13313. _inheritsLoose(Element, _Node);
  13314. function Element() {
  13315. var _this;
  13316. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  13317. args[_key] = arguments[_key];
  13318. }
  13319. _this = _Node.call.apply(_Node, [this].concat(args)) || this;
  13320. /**
  13321. * Unique id.
  13322. */
  13323. _this.entity = entityCounter++;
  13324. _this.renderable = {
  13325. bounds: undefined,
  13326. boundsDirty: true,
  13327. renderBounds: undefined,
  13328. renderBoundsDirty: true,
  13329. dirtyRenderBounds: undefined,
  13330. dirty: false,
  13331. proxyNodeName: undefined
  13332. };
  13333. _this.cullable = {
  13334. strategy: exports.Strategy.Standard,
  13335. visibilityPlaneMask: -1,
  13336. visible: true,
  13337. enable: true
  13338. };
  13339. _this.transformable = {
  13340. dirtyFlag: false,
  13341. localDirtyFlag: false,
  13342. frozen: false,
  13343. localPosition: [0, 0, 0],
  13344. localRotation: [0, 0, 0, 1],
  13345. localScale: [1, 1, 1],
  13346. localTransform: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
  13347. localSkew: [0, 0],
  13348. position: [0, 0, 0],
  13349. rotation: [0, 0, 0, 1],
  13350. scaling: [1, 1, 1],
  13351. worldTransform: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
  13352. origin: [0, 0, 0]
  13353. };
  13354. _this.sortable = {
  13355. dirty: false,
  13356. sorted: undefined,
  13357. renderOrder: 0,
  13358. dirtyChildren: [],
  13359. dirtyReason: undefined
  13360. };
  13361. _this.geometry = {
  13362. contentBounds: undefined,
  13363. renderBounds: undefined
  13364. };
  13365. _this.rBushNode = {
  13366. aabb: undefined
  13367. };
  13368. /**
  13369. * used with `getElementById()`
  13370. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/id
  13371. */
  13372. _this.id = void 0;
  13373. /**
  13374. * used in `getElementsByName`
  13375. * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByName
  13376. */
  13377. _this.name = void 0;
  13378. /**
  13379. * https://developer.mozilla.org/zh-CN/docs/Web/API/Element/namespaceURI
  13380. */
  13381. _this.namespaceURI = 'g';
  13382. _this.scrollLeft = 0;
  13383. _this.scrollTop = 0;
  13384. /**
  13385. * We don't support border now
  13386. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/clientTop
  13387. */
  13388. _this.clientTop = 0;
  13389. _this.clientLeft = 0;
  13390. /**
  13391. * is destroyed or not
  13392. */
  13393. _this.destroyed = false;
  13394. /**
  13395. * compatible with `style`
  13396. * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
  13397. */
  13398. _this.style = {};
  13399. _this.computedStyle = runtime.enableCSSParsing ? {
  13400. anchor: unsetKeywordValue,
  13401. opacity: unsetKeywordValue,
  13402. fillOpacity: unsetKeywordValue,
  13403. strokeOpacity: unsetKeywordValue,
  13404. fill: unsetKeywordValue,
  13405. stroke: unsetKeywordValue,
  13406. transform: unsetKeywordValue,
  13407. transformOrigin: unsetKeywordValue,
  13408. visibility: unsetKeywordValue,
  13409. pointerEvents: unsetKeywordValue,
  13410. lineWidth: unsetKeywordValue,
  13411. lineCap: unsetKeywordValue,
  13412. lineJoin: unsetKeywordValue,
  13413. increasedLineWidthForHitTesting: unsetKeywordValue,
  13414. fontSize: unsetKeywordValue,
  13415. fontFamily: unsetKeywordValue,
  13416. fontStyle: unsetKeywordValue,
  13417. fontWeight: unsetKeywordValue,
  13418. fontVariant: unsetKeywordValue,
  13419. textAlign: unsetKeywordValue,
  13420. textBaseline: unsetKeywordValue,
  13421. textTransform: unsetKeywordValue,
  13422. zIndex: unsetKeywordValue,
  13423. filter: unsetKeywordValue,
  13424. shadowType: unsetKeywordValue
  13425. } : null;
  13426. /**
  13427. * Renderers will use these used values.
  13428. */
  13429. _this.parsedStyle = {
  13430. // opacity: '',
  13431. // fillOpacity: '',
  13432. // strokeOpacity: '',
  13433. // transformOrigin: '',
  13434. // visibility: '',
  13435. // pointerEvents: '',
  13436. // lineWidth: '',
  13437. // lineCap: '',
  13438. // lineJoin: '',
  13439. // increasedLineWidthForHitTesting: '',
  13440. // fontSize: '',
  13441. // fontFamily: '',
  13442. // fontStyle: '',
  13443. // fontWeight: '',
  13444. // fontVariant: '',
  13445. // textAlign: '',
  13446. // textBaseline: '',
  13447. // textTransform: '',
  13448. };
  13449. /**
  13450. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes
  13451. */
  13452. _this.attributes = {};
  13453. return _this;
  13454. }
  13455. Element.isElement = function isElement(target) {
  13456. return !!target.getAttribute;
  13457. };
  13458. var _proto = Element.prototype;
  13459. _proto.cloneNode = function cloneNode(deep) {
  13460. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13461. };
  13462. _proto.appendChild = function appendChild(child, index) {
  13463. var _this$ownerDocument;
  13464. if (child.destroyed) {
  13465. throw new Error(ERROR_MSG_APPEND_DESTROYED_ELEMENT);
  13466. }
  13467. runtime.sceneGraphService.attach(child, this, index);
  13468. if ((_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : _this$ownerDocument.defaultView) {
  13469. this.ownerDocument.defaultView.mountChildren(child);
  13470. }
  13471. insertedEvent.relatedNode = this;
  13472. child.dispatchEvent(insertedEvent);
  13473. return child;
  13474. };
  13475. _proto.insertBefore = function insertBefore(newChild, refChild) {
  13476. if (!refChild) {
  13477. this.appendChild(newChild);
  13478. } else {
  13479. var index = this.childNodes.indexOf(refChild);
  13480. this.appendChild(newChild, index - 1);
  13481. }
  13482. return newChild;
  13483. };
  13484. _proto.replaceChild = function replaceChild(newChild, oldChild) {
  13485. var index = this.childNodes.indexOf(oldChild);
  13486. this.removeChild(oldChild);
  13487. this.appendChild(newChild, index);
  13488. return oldChild;
  13489. };
  13490. _proto.removeChild = function removeChild(child) {
  13491. var _child$ownerDocument;
  13492. // should emit on itself before detach
  13493. removedEvent.relatedNode = this;
  13494. child.dispatchEvent(removedEvent);
  13495. if ((_child$ownerDocument = child.ownerDocument) === null || _child$ownerDocument === void 0 ? void 0 : _child$ownerDocument.defaultView) {
  13496. child.ownerDocument.defaultView.unmountChildren(child);
  13497. }
  13498. // remove from scene graph
  13499. runtime.sceneGraphService.detach(child);
  13500. return child;
  13501. }
  13502. /**
  13503. * Remove all children which can be appended to its original parent later again.
  13504. */;
  13505. _proto.removeChildren = function removeChildren() {
  13506. for (var i = this.childNodes.length - 1; i >= 0; i--) {
  13507. var child = this.childNodes[i];
  13508. this.removeChild(child);
  13509. }
  13510. }
  13511. /**
  13512. * Recursively destroy all children which can not be appended to its original parent later again.
  13513. */;
  13514. _proto.destroyChildren = function destroyChildren() {
  13515. for (var i = this.childNodes.length - 1; i >= 0; i--) {
  13516. var child = this.childNodes[i];
  13517. if (child.childNodes.length) {
  13518. child.destroyChildren();
  13519. }
  13520. child.destroy();
  13521. }
  13522. }
  13523. /**
  13524. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
  13525. */;
  13526. _proto.matches = function matches(selector) {
  13527. return runtime.sceneGraphService.matches(selector, this);
  13528. };
  13529. _proto.getElementById = function getElementById(id) {
  13530. return runtime.sceneGraphService.querySelector("#" + id, this);
  13531. };
  13532. _proto.getElementsByName = function getElementsByName(name) {
  13533. return runtime.sceneGraphService.querySelectorAll("[name=\"" + name + "\"]", this);
  13534. };
  13535. _proto.getElementsByClassName = function getElementsByClassName(className) {
  13536. return runtime.sceneGraphService.querySelectorAll("." + className, this);
  13537. };
  13538. _proto.getElementsByTagName = function getElementsByTagName(tagName) {
  13539. return runtime.sceneGraphService.querySelectorAll(tagName, this);
  13540. };
  13541. _proto.querySelector = function querySelector(selectors) {
  13542. return runtime.sceneGraphService.querySelector(selectors, this);
  13543. };
  13544. _proto.querySelectorAll = function querySelectorAll(selectors) {
  13545. return runtime.sceneGraphService.querySelectorAll(selectors, this);
  13546. }
  13547. /**
  13548. * should traverses the element and its parents (heading toward the document root)
  13549. * until it finds a node that matches the specified CSS selector.
  13550. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/closest
  13551. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#polyfill
  13552. */;
  13553. _proto.closest = function closest(selectors) {
  13554. var el = this;
  13555. do {
  13556. if (runtime.sceneGraphService.matches(selectors, el)) return el;
  13557. el = el.parentElement;
  13558. } while (el !== null);
  13559. return null;
  13560. }
  13561. /**
  13562. * search in scene group, but should not include itself
  13563. */;
  13564. _proto.find = function find(filter) {
  13565. var _this2 = this;
  13566. var target = null;
  13567. this.forEach(function (object) {
  13568. if (object !== _this2 && filter(object)) {
  13569. target = object;
  13570. return true;
  13571. }
  13572. return false;
  13573. });
  13574. return target;
  13575. };
  13576. _proto.findAll = function findAll(filter) {
  13577. var _this3 = this;
  13578. var objects = [];
  13579. this.forEach(function (object) {
  13580. if (object !== _this3 && filter(object)) {
  13581. objects.push(object);
  13582. }
  13583. });
  13584. return objects;
  13585. }
  13586. /**
  13587. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/after
  13588. */;
  13589. _proto.after = function after() {
  13590. var _this4 = this;
  13591. if (this.parentNode) {
  13592. var index = this.parentNode.childNodes.indexOf(this);
  13593. for (var _len2 = arguments.length, nodes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  13594. nodes[_key2] = arguments[_key2];
  13595. }
  13596. nodes.forEach(function (node, i) {
  13597. var _this4$parentNode;
  13598. return (_this4$parentNode = _this4.parentNode) === null || _this4$parentNode === void 0 ? void 0 : _this4$parentNode.appendChild(node, index + i + 1);
  13599. });
  13600. }
  13601. }
  13602. /**
  13603. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/before
  13604. */;
  13605. _proto.before = function before() {
  13606. if (this.parentNode) {
  13607. var index = this.parentNode.childNodes.indexOf(this);
  13608. for (var _len3 = arguments.length, nodes = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  13609. nodes[_key3] = arguments[_key3];
  13610. }
  13611. var first = nodes[0],
  13612. rest = nodes.slice(1);
  13613. this.parentNode.appendChild(first, index);
  13614. first.after.apply(first, rest);
  13615. }
  13616. }
  13617. /**
  13618. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/replaceWith
  13619. */;
  13620. _proto.replaceWith = function replaceWith() {
  13621. this.after.apply(this, arguments);
  13622. this.remove();
  13623. }
  13624. /**
  13625. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/append
  13626. */;
  13627. _proto.append = function append() {
  13628. var _this5 = this;
  13629. for (var _len4 = arguments.length, nodes = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  13630. nodes[_key4] = arguments[_key4];
  13631. }
  13632. nodes.forEach(function (node) {
  13633. return _this5.appendChild(node);
  13634. });
  13635. }
  13636. /**
  13637. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/prepend
  13638. */;
  13639. _proto.prepend = function prepend() {
  13640. var _this6 = this;
  13641. for (var _len5 = arguments.length, nodes = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
  13642. nodes[_key5] = arguments[_key5];
  13643. }
  13644. nodes.forEach(function (node, i) {
  13645. return _this6.appendChild(node, i);
  13646. });
  13647. }
  13648. /**
  13649. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/replaceChildren
  13650. */;
  13651. _proto.replaceChildren = function replaceChildren() {
  13652. while (this.childNodes.length && this.firstChild) {
  13653. this.removeChild(this.firstChild);
  13654. }
  13655. this.append.apply(this, arguments);
  13656. }
  13657. /**
  13658. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/remove
  13659. */;
  13660. _proto.remove = function remove() {
  13661. if (this.parentNode) {
  13662. return this.parentNode.removeChild(this);
  13663. }
  13664. return this;
  13665. };
  13666. _proto.destroy = function destroy() {
  13667. // destroy itself before remove
  13668. this.dispatchEvent(destroyEvent);
  13669. // remove from scenegraph first
  13670. this.remove();
  13671. // remove event listeners
  13672. this.emitter.removeAllListeners();
  13673. this.destroyed = true;
  13674. };
  13675. _proto.getGeometryBounds = function getGeometryBounds() {
  13676. return runtime.sceneGraphService.getGeometryBounds(this);
  13677. };
  13678. _proto.getRenderBounds = function getRenderBounds() {
  13679. return runtime.sceneGraphService.getBounds(this, true);
  13680. }
  13681. /**
  13682. * get bounds in world space, account for children
  13683. */;
  13684. _proto.getBounds = function getBounds() {
  13685. return runtime.sceneGraphService.getBounds(this);
  13686. }
  13687. /**
  13688. * get bounds in local space, account for children
  13689. */;
  13690. _proto.getLocalBounds = function getLocalBounds() {
  13691. return runtime.sceneGraphService.getLocalBounds(this);
  13692. }
  13693. /**
  13694. * account for context's bounds in client space,
  13695. * but not accounting for children
  13696. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
  13697. */;
  13698. _proto.getBoundingClientRect = function getBoundingClientRect() {
  13699. return runtime.sceneGraphService.getBoundingClientRect(this);
  13700. }
  13701. /**
  13702. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getClientRects
  13703. */;
  13704. _proto.getClientRects = function getClientRects() {
  13705. return [this.getBoundingClientRect()];
  13706. };
  13707. /**
  13708. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/computedStyleMap
  13709. * eg. circle.computedStyleMap().get('fill');
  13710. */
  13711. _proto.computedStyleMap = function computedStyleMap() {
  13712. return new Map(Object.entries(this.computedStyle));
  13713. };
  13714. /**
  13715. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttributeNames
  13716. */
  13717. _proto.getAttributeNames = function getAttributeNames() {
  13718. return Object.keys(this.attributes);
  13719. }
  13720. /**
  13721. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute
  13722. */;
  13723. _proto.getAttribute = function getAttribute(name) {
  13724. // @see https://github.com/antvis/G/issues/1267
  13725. if (isSymbol(name)) {
  13726. return runtime.enableCSSParsing ? null : undefined;
  13727. }
  13728. var value = this.attributes[name];
  13729. if (value === undefined) {
  13730. var attributeName = formatAttributeName(name);
  13731. value = this.attributes[attributeName];
  13732. // if the given attribute does not exist, the value returned will either be null or ""
  13733. return runtime.enableCSSParsing ? isNil(value) ? null : value : value;
  13734. } else {
  13735. return value;
  13736. }
  13737. }
  13738. /**
  13739. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute
  13740. */;
  13741. _proto.hasAttribute = function hasAttribute(qualifiedName) {
  13742. return this.getAttributeNames().includes(qualifiedName);
  13743. }
  13744. /**
  13745. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttributes
  13746. */;
  13747. _proto.hasAttributes = function hasAttributes() {
  13748. return !!this.getAttributeNames().length;
  13749. }
  13750. /**
  13751. * should use removeAttribute() instead of setting the attribute value to null either directly or using setAttribute(). Many attributes will not behave as expected if you set them to null.
  13752. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute
  13753. */;
  13754. _proto.removeAttribute = function removeAttribute(attributeName) {
  13755. this.setAttribute(attributeName, null);
  13756. delete this.attributes[attributeName];
  13757. }
  13758. /**
  13759. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
  13760. */;
  13761. _proto.setAttribute = function setAttribute(attributeName, value, force) {
  13762. this.attributes[attributeName] = value;
  13763. };
  13764. _proto.getAttributeNS = function getAttributeNS(namespace, localName) {
  13765. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13766. };
  13767. _proto.getAttributeNode = function getAttributeNode(qualifiedName) {
  13768. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13769. };
  13770. _proto.getAttributeNodeNS = function getAttributeNodeNS(namespace, localName) {
  13771. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13772. };
  13773. _proto.hasAttributeNS = function hasAttributeNS(namespace, localName) {
  13774. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13775. };
  13776. _proto.removeAttributeNS = function removeAttributeNS(namespace, localName) {
  13777. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13778. };
  13779. _proto.removeAttributeNode = function removeAttributeNode(attr) {
  13780. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13781. };
  13782. _proto.setAttributeNS = function setAttributeNS(namespace, qualifiedName, value) {
  13783. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13784. };
  13785. _proto.setAttributeNode = function setAttributeNode(attr) {
  13786. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13787. };
  13788. _proto.setAttributeNodeNS = function setAttributeNodeNS(attr) {
  13789. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13790. };
  13791. _proto.toggleAttribute = function toggleAttribute(qualifiedName, force) {
  13792. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13793. };
  13794. _createClass(Element, [{
  13795. key: "className",
  13796. get:
  13797. /**
  13798. * used in `getElementsByClassName`
  13799. * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
  13800. */
  13801. function get() {
  13802. // @ts-ignore
  13803. return this.getAttribute('class') || '';
  13804. },
  13805. set: function set(className) {
  13806. this.setAttribute('class', className);
  13807. }
  13808. }, {
  13809. key: "classList",
  13810. get:
  13811. /**
  13812. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
  13813. */
  13814. function get() {
  13815. return this.className.split(' ').filter(function (c) {
  13816. return c !== '';
  13817. });
  13818. }
  13819. }, {
  13820. key: "tagName",
  13821. get: function get() {
  13822. return this.nodeName;
  13823. }
  13824. }, {
  13825. key: "children",
  13826. get: function get() {
  13827. return this.childNodes;
  13828. }
  13829. }, {
  13830. key: "childElementCount",
  13831. get: function get() {
  13832. return this.childNodes.length;
  13833. }
  13834. }, {
  13835. key: "firstElementChild",
  13836. get: function get() {
  13837. return this.firstChild;
  13838. }
  13839. }, {
  13840. key: "lastElementChild",
  13841. get: function get() {
  13842. return this.lastChild;
  13843. }
  13844. }, {
  13845. key: "parentElement",
  13846. get: function get() {
  13847. return this.parentNode;
  13848. }
  13849. }, {
  13850. key: "nextSibling",
  13851. get: function get() {
  13852. if (this.parentNode) {
  13853. var index = this.parentNode.childNodes.indexOf(this);
  13854. return this.parentNode.childNodes[index + 1] || null;
  13855. }
  13856. return null;
  13857. }
  13858. }, {
  13859. key: "previousSibling",
  13860. get: function get() {
  13861. if (this.parentNode) {
  13862. var index = this.parentNode.childNodes.indexOf(this);
  13863. return this.parentNode.childNodes[index - 1] || null;
  13864. }
  13865. return null;
  13866. }
  13867. }]);
  13868. return Element;
  13869. }(Node);
  13870. var FederatedMouseEvent = /*#__PURE__*/function (_FederatedEvent) {
  13871. _inheritsLoose(FederatedMouseEvent, _FederatedEvent);
  13872. function FederatedMouseEvent() {
  13873. var _this;
  13874. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  13875. args[_key] = arguments[_key];
  13876. }
  13877. _this = _FederatedEvent.call.apply(_FederatedEvent, [this].concat(args)) || this;
  13878. /** Whether the "alt" key was pressed when this mouse event occurred. */
  13879. _this.altKey = void 0;
  13880. /** The specific button that was pressed in this mouse event. */
  13881. _this.button = void 0;
  13882. /** The button depressed when this event occurred. */
  13883. _this.buttons = void 0;
  13884. /** Whether the "control" key was pressed when this mouse event occurred. */
  13885. _this.ctrlKey = void 0;
  13886. /** Whether the "meta" key was pressed when this mouse event occurred. */
  13887. _this.metaKey = void 0;
  13888. /** This is currently not implemented in the Federated Events API. */
  13889. _this.relatedTarget = void 0;
  13890. /** Whether the "shift" key was pressed when this mouse event occurred. */
  13891. _this.shiftKey = void 0;
  13892. /**
  13893. * The coordinates of the mouse event relative to the canvas.
  13894. */
  13895. _this.client = new Point();
  13896. /**
  13897. * The movement in this pointer relative to the last `mousemove` event.
  13898. */
  13899. _this.movement = new Point();
  13900. /**
  13901. * The offset of the pointer coordinates w.r.t. target DisplayObject in world space. This is
  13902. * not supported at the moment.
  13903. */
  13904. _this.offset = new Point();
  13905. /**
  13906. * The pointer coordinates in world space.
  13907. */
  13908. _this.global = new Point();
  13909. /**
  13910. * The pointer coordinates in sceen space.
  13911. */
  13912. _this.screen = new Point();
  13913. return _this;
  13914. }
  13915. var _proto = FederatedMouseEvent.prototype;
  13916. _proto.getModifierState = function getModifierState(key) {
  13917. return 'getModifierState' in this.nativeEvent && this.nativeEvent.getModifierState(key);
  13918. };
  13919. _proto.initMouseEvent = function initMouseEvent() {
  13920. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  13921. };
  13922. _createClass(FederatedMouseEvent, [{
  13923. key: "clientX",
  13924. get: function get() {
  13925. return this.client.x;
  13926. }
  13927. }, {
  13928. key: "clientY",
  13929. get: function get() {
  13930. return this.client.y;
  13931. }
  13932. }, {
  13933. key: "movementX",
  13934. get: function get() {
  13935. return this.movement.x;
  13936. }
  13937. }, {
  13938. key: "movementY",
  13939. get: function get() {
  13940. return this.movement.y;
  13941. }
  13942. }, {
  13943. key: "offsetX",
  13944. get: function get() {
  13945. return this.offset.x;
  13946. }
  13947. }, {
  13948. key: "offsetY",
  13949. get: function get() {
  13950. return this.offset.y;
  13951. }
  13952. }, {
  13953. key: "globalX",
  13954. get: function get() {
  13955. return this.global.x;
  13956. }
  13957. }, {
  13958. key: "globalY",
  13959. get: function get() {
  13960. return this.global.y;
  13961. }
  13962. }, {
  13963. key: "screenX",
  13964. get: function get() {
  13965. return this.screen.x;
  13966. }
  13967. }, {
  13968. key: "screenY",
  13969. get: function get() {
  13970. return this.screen.y;
  13971. }
  13972. }]);
  13973. return FederatedMouseEvent;
  13974. }(FederatedEvent);
  13975. var FederatedPointerEvent = /*#__PURE__*/function (_FederatedMouseEvent) {
  13976. _inheritsLoose(FederatedPointerEvent, _FederatedMouseEvent);
  13977. function FederatedPointerEvent() {
  13978. var _this;
  13979. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  13980. args[_key] = arguments[_key];
  13981. }
  13982. _this = _FederatedMouseEvent.call.apply(_FederatedMouseEvent, [this].concat(args)) || this;
  13983. /**
  13984. * The unique identifier of the pointer.
  13985. *
  13986. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerId
  13987. */
  13988. _this.pointerId = void 0;
  13989. /**
  13990. * The width of the pointer's contact along the x-axis, measured in CSS pixels.
  13991. * radiusX of TouchEvents will be represented by this value.
  13992. *
  13993. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/width
  13994. */
  13995. _this.width = 0;
  13996. /**
  13997. * The height of the pointer's contact along the y-axis, measured in CSS pixels.
  13998. * radiusY of TouchEvents will be represented by this value.
  13999. *
  14000. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/height
  14001. */
  14002. _this.height = 0;
  14003. /**
  14004. * Indicates whether or not the pointer device that created the event is the primary pointer.
  14005. *
  14006. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/isPrimary
  14007. */
  14008. _this.isPrimary = false;
  14009. /**
  14010. * The type of pointer that triggered the event.
  14011. *
  14012. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType
  14013. */
  14014. _this.pointerType = void 0;
  14015. /**
  14016. * Pressure applied by the pointing device during the event.
  14017. *s
  14018. * A Touch's force property will be represented by this value.
  14019. *
  14020. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pressure
  14021. */
  14022. _this.pressure = void 0;
  14023. /**
  14024. * Barrel pressure on a stylus pointer.
  14025. *
  14026. * @see https://w3c.github.io/pointerevents/#pointerevent-interface
  14027. */
  14028. _this.tangentialPressure = void 0;
  14029. /**
  14030. * The angle, in degrees, between the pointer device and the screen.
  14031. *
  14032. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltX
  14033. */
  14034. _this.tiltX = void 0;
  14035. /**
  14036. * The angle, in degrees, between the pointer device and the screen.
  14037. *
  14038. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltY
  14039. */
  14040. _this.tiltY = void 0;
  14041. /**
  14042. * Twist of a stylus pointer.
  14043. *
  14044. * @see https://w3c.github.io/pointerevents/#pointerevent-interface
  14045. */
  14046. _this.twist = void 0;
  14047. return _this;
  14048. }
  14049. var _proto = FederatedPointerEvent.prototype;
  14050. /**
  14051. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/getCoalescedEvents
  14052. */
  14053. _proto.getCoalescedEvents = function getCoalescedEvents() {
  14054. if (this.type === 'pointermove' || this.type === 'mousemove' || this.type === 'touchmove') {
  14055. return [this];
  14056. }
  14057. return [];
  14058. }
  14059. /**
  14060. * @see https://chromestatus.com/feature/5765569655603200
  14061. */;
  14062. _proto.getPredictedEvents = function getPredictedEvents() {
  14063. throw new Error('getPredictedEvents is not supported!');
  14064. }
  14065. /**
  14066. * @see https://github.com/antvis/G/issues/1115
  14067. * We currently reuses event objects in the event system,
  14068. * avoiding the creation of a large number of event objects.
  14069. * Reused objects are only used to carry different data,
  14070. * such as coordinate information, native event objects,
  14071. * and therefore the lifecycle is limited to the event handler,
  14072. * which can lead to unintended consequences if an attempt is made to cache the entire event object.
  14073. *
  14074. * Therefore, while keeping the above performance considerations in mind, it is possible to provide a clone method that creates a new object when the user really wants to cache it, e.g.
  14075. */;
  14076. _proto.clone = function clone() {
  14077. return this.manager.clonePointerEvent(this);
  14078. };
  14079. return FederatedPointerEvent;
  14080. }(FederatedMouseEvent);
  14081. var FederatedWheelEvent = /*#__PURE__*/function (_FederatedMouseEvent) {
  14082. _inheritsLoose(FederatedWheelEvent, _FederatedMouseEvent);
  14083. function FederatedWheelEvent() {
  14084. var _this;
  14085. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  14086. args[_key] = arguments[_key];
  14087. }
  14088. _this = _FederatedMouseEvent.call.apply(_FederatedMouseEvent, [this].concat(args)) || this;
  14089. /**
  14090. * The units of `deltaX`, `deltaY`, and `deltaZ`. This is one of `DOM_DELTA_LINE`,
  14091. * `DOM_DELTA_PAGE`, `DOM_DELTA_PIXEL`.
  14092. */
  14093. _this.deltaMode = void 0;
  14094. /** Horizontal scroll amount */
  14095. _this.deltaX = void 0;
  14096. /** Vertical scroll amount */
  14097. _this.deltaY = void 0;
  14098. /** z-axis scroll amount. */
  14099. _this.deltaZ = void 0;
  14100. /** Units specified in lines. */
  14101. _this.DOM_DELTA_LINE = 0;
  14102. /** Units specified in pages. */
  14103. _this.DOM_DELTA_PAGE = 1;
  14104. /** Units specified in pixels. */
  14105. _this.DOM_DELTA_PIXEL = 2;
  14106. return _this;
  14107. }
  14108. var _proto = FederatedWheelEvent.prototype;
  14109. _proto.clone = function clone() {
  14110. return this.manager.cloneWheelEvent(this);
  14111. };
  14112. return FederatedWheelEvent;
  14113. }(FederatedMouseEvent);
  14114. function isDisplayObject(value) {
  14115. return !!(value === null || value === void 0 ? void 0 : value.nodeName);
  14116. }
  14117. var mutationEvent = new MutationEvent(exports.ElementEvent.ATTR_MODIFIED, null, null, null, null, MutationEvent.MODIFICATION, null, null);
  14118. var DEFAULT_STYLE_PROPS = {
  14119. anchor: '',
  14120. opacity: '',
  14121. fillOpacity: '',
  14122. strokeOpacity: '',
  14123. fill: '',
  14124. stroke: '',
  14125. transform: '',
  14126. transformOrigin: '',
  14127. visibility: '',
  14128. pointerEvents: '',
  14129. lineWidth: '',
  14130. lineCap: '',
  14131. lineJoin: '',
  14132. increasedLineWidthForHitTesting: '',
  14133. fontSize: '',
  14134. fontFamily: '',
  14135. fontStyle: '',
  14136. fontWeight: '',
  14137. fontVariant: '',
  14138. textAlign: '',
  14139. textBaseline: '',
  14140. textTransform: '',
  14141. zIndex: '',
  14142. filter: '',
  14143. shadowType: ''
  14144. };
  14145. var DEFAULT_PARSED_STYLE_PROPS = {
  14146. anchor: [0, 0],
  14147. fill: noneColor,
  14148. stroke: noneColor,
  14149. transform: [],
  14150. zIndex: 0,
  14151. filter: [],
  14152. shadowType: 'outer',
  14153. miterLimit: 10
  14154. };
  14155. var DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED = _extends({}, DEFAULT_PARSED_STYLE_PROPS, {
  14156. opacity: 1,
  14157. fillOpacity: 1,
  14158. strokeOpacity: 1,
  14159. visibility: 'visible',
  14160. pointerEvents: 'auto',
  14161. lineWidth: 1,
  14162. lineCap: 'butt',
  14163. lineJoin: 'miter',
  14164. increasedLineWidthForHitTesting: 0,
  14165. fillRule: 'nonzero'
  14166. // TODO: transformOrigin
  14167. });
  14168. var INHERITABLE_BASE_STYLE_PROPS = ['opacity', 'fillOpacity', 'strokeOpacity', 'transformOrigin', 'visibility', 'pointerEvents', 'lineWidth', 'lineCap', 'lineJoin', 'increasedLineWidthForHitTesting'];
  14169. var INHERITABLE_STYLE_PROPS = [].concat(INHERITABLE_BASE_STYLE_PROPS, ['fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'textAlign', 'textBaseline', 'textTransform']);
  14170. var DATASET_PREFIX = 'data-';
  14171. /**
  14172. * prototype chains: DisplayObject -> Element -> Node -> EventTarget
  14173. *
  14174. * mixins: Animatable, Transformable, Visible
  14175. * @see https://github.com/tannerntannern/ts-mixer/blob/master/README.md#mixing-generic-classes
  14176. *
  14177. * Provide abilities in scene graph, such as:
  14178. * * transform `translate/rotate/scale`
  14179. * * add/remove child
  14180. * * visibility and z-index
  14181. *
  14182. * Those abilities are implemented with those components: `Transform/Sortable/Visible`.
  14183. *
  14184. * Emit following events:
  14185. * * init
  14186. * * destroy
  14187. * * attributeChanged
  14188. */
  14189. var DisplayObject = /*#__PURE__*/function (_Element) {
  14190. _inheritsLoose(DisplayObject, _Element);
  14191. function DisplayObject(config) {
  14192. var _this$config$capture;
  14193. var _this;
  14194. _this = _Element.call(this) || this;
  14195. // assign name, id to config
  14196. // eg. group.get('name')
  14197. /**
  14198. * contains style props in constructor's params, eg. fill, stroke...
  14199. */
  14200. _this.config = void 0;
  14201. _this.isCustomElement = false;
  14202. _this.isMutationObserved = false;
  14203. /**
  14204. * push to active animations after calling `animate()`
  14205. */
  14206. _this.activeAnimations = [];
  14207. /**
  14208. * Use data-* attribute.
  14209. * @see https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
  14210. * @example
  14211. * group.dataset.prop1 = 1;
  14212. * group.getAttribute('data-prop1'); // 1
  14213. */
  14214. _this.dataset = void 0;
  14215. /**
  14216. * Use `this.style.clipPath` instead.
  14217. * @deprecated
  14218. */
  14219. _this.getClip = function () {
  14220. return this.style.clipPath || null;
  14221. };
  14222. _this.config = config;
  14223. // compatible with G 3.0
  14224. _this.config.interactive = (_this$config$capture = _this.config.capture) !== null && _this$config$capture !== void 0 ? _this$config$capture : _this.config.interactive;
  14225. // init scene graph node
  14226. _this.id = _this.config.id || '';
  14227. _this.name = _this.config.name || '';
  14228. if (_this.config.className || _this.config.class) {
  14229. _this.className = _this.config.className || _this.config.class;
  14230. }
  14231. _this.nodeName = _this.config.type || exports.Shape.GROUP;
  14232. // compatible with G 3.0
  14233. _this.config.style = _this.config.style || _this.config.attrs || {};
  14234. Object.assign(_this.config.style, _this.config.attrs);
  14235. // this.config.style = {
  14236. // // ...DEFAULT_STYLE_PROPS,
  14237. // ...this.config.style,
  14238. // ...this.config.attrs,
  14239. // };
  14240. if (_this.config.visible != null) {
  14241. _this.config.style.visibility = _this.config.visible === false ? 'hidden' : 'visible';
  14242. }
  14243. if (_this.config.interactive != null) {
  14244. _this.config.style.pointerEvents = _this.config.interactive === false ? 'none' : 'auto';
  14245. }
  14246. // merge parsed value
  14247. Object.assign(_this.parsedStyle, runtime.enableCSSParsing ? DEFAULT_PARSED_STYLE_PROPS : DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED, _this.config.initialParsedStyle);
  14248. if (runtime.enableCSSParsing) {
  14249. Object.assign(_this.attributes, DEFAULT_STYLE_PROPS);
  14250. }
  14251. // start to process attributes
  14252. _this.initAttributes(_this.config.style);
  14253. var Proxy = runtime.globalThis.Proxy ? runtime.globalThis.Proxy : function () {};
  14254. if (runtime.enableDataset) {
  14255. _this.dataset = new Proxy({}, {
  14256. get: function get(target, name) {
  14257. var formattedName = "" + DATASET_PREFIX + kebabize(name);
  14258. if (target[formattedName] !== undefined) {
  14259. return target[formattedName];
  14260. }
  14261. return _this.getAttribute(formattedName);
  14262. },
  14263. set: function set(_, prop, value) {
  14264. _this.setAttribute("" + DATASET_PREFIX + kebabize(prop), value);
  14265. return true;
  14266. }
  14267. });
  14268. }
  14269. if (runtime.enableStyleSyntax) {
  14270. _this.style = new Proxy(
  14271. // @ts-ignore
  14272. {
  14273. // ...this.attributes,
  14274. setProperty: function setProperty(propertyName, value) {
  14275. _this.setAttribute(propertyName, value);
  14276. },
  14277. getPropertyValue: function getPropertyValue(propertyName) {
  14278. return _this.getAttribute(propertyName);
  14279. },
  14280. removeProperty: function removeProperty(propertyName) {
  14281. _this.removeAttribute(propertyName);
  14282. },
  14283. item: function item() {
  14284. return '';
  14285. }
  14286. }, {
  14287. get: function get(target, name) {
  14288. if (target[name] !== undefined) {
  14289. // if (name in target) {
  14290. return target[name];
  14291. }
  14292. return _this.getAttribute(name);
  14293. },
  14294. set: function set(_, prop, value) {
  14295. _this.setAttribute(prop, value);
  14296. return true;
  14297. }
  14298. });
  14299. }
  14300. return _this;
  14301. }
  14302. var _proto = DisplayObject.prototype;
  14303. _proto.destroy = function destroy() {
  14304. _Element.prototype.destroy.call(this);
  14305. // stop all active animations
  14306. this.getAnimations().forEach(function (animation) {
  14307. animation.cancel();
  14308. });
  14309. // FIXME
  14310. // this.renderable = null;
  14311. // this.cullable = null;
  14312. // this.transformable = null;
  14313. // this.rBushNode = null;
  14314. // this.geometry = null;
  14315. // this.sortable = null;
  14316. };
  14317. _proto.cloneNode = function cloneNode(deep, customCloneFunc) {
  14318. var clonedStyle = _extends({}, this.attributes);
  14319. for (var attributeName in clonedStyle) {
  14320. var attribute = clonedStyle[attributeName];
  14321. // @see https://github.com/antvis/G/issues/1095
  14322. if (isDisplayObject(attribute) &&
  14323. // share the same clipPath if possible
  14324. attributeName !== 'clipPath' && attributeName !== 'offsetPath' && attributeName !== 'textPath') {
  14325. clonedStyle[attributeName] = attribute.cloneNode(deep);
  14326. }
  14327. // TODO: clone other type
  14328. if (customCloneFunc) {
  14329. clonedStyle[attributeName] = customCloneFunc(attributeName, attribute);
  14330. }
  14331. }
  14332. var cloned = new this.constructor({
  14333. // copy id & name
  14334. // @see https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode#notes
  14335. id: this.id,
  14336. name: this.name,
  14337. className: this.name,
  14338. interactive: this.interactive,
  14339. style: clonedStyle
  14340. });
  14341. // apply transform
  14342. cloned.setLocalTransform(this.getLocalTransform());
  14343. if (deep) {
  14344. this.children.forEach(function (child) {
  14345. // skip marker
  14346. if (!child.style.isMarker) {
  14347. var clonedChild = child.cloneNode(deep);
  14348. cloned.appendChild(clonedChild);
  14349. }
  14350. });
  14351. }
  14352. return cloned;
  14353. };
  14354. _proto.initAttributes = function initAttributes(attributes) {
  14355. if (attributes === void 0) {
  14356. attributes = {};
  14357. }
  14358. var renderable = this.renderable;
  14359. var options = {
  14360. forceUpdateGeometry: true
  14361. // usedAttributes:
  14362. // // only Group / Text should account for text relative props
  14363. // this.tagName === Shape.GROUP || this.tagName === Shape.TEXT
  14364. // ? INHERITABLE_STYLE_PROPS
  14365. // : INHERITABLE_BASE_STYLE_PROPS,
  14366. };
  14367. if (runtime.enableCSSParsing) {
  14368. // @ts-ignore
  14369. options.usedAttributes = INHERITABLE_STYLE_PROPS;
  14370. }
  14371. // account for FCP, process properties as less as possible
  14372. var formattedAttributes = {};
  14373. for (var name in attributes) {
  14374. var attributeName = formatAttributeName(name);
  14375. formattedAttributes[attributeName] = attributes[name];
  14376. }
  14377. runtime.styleValueRegistry.processProperties(this, formattedAttributes, options);
  14378. // redraw at next frame
  14379. renderable.dirty = true;
  14380. };
  14381. _proto.setAttribute = function setAttribute(name, value, force) {
  14382. if (force === void 0) {
  14383. force = false;
  14384. }
  14385. var attributeName = formatAttributeName(name);
  14386. // ignore undefined value
  14387. if (isUndefined(value)) {
  14388. return;
  14389. }
  14390. if (force || value !== this.attributes[attributeName]) {
  14391. this.internalSetAttribute(attributeName, value);
  14392. _Element.prototype.setAttribute.call(this, attributeName, value);
  14393. }
  14394. }
  14395. /**
  14396. * called when attributes get changed or initialized
  14397. */;
  14398. _proto.internalSetAttribute = function internalSetAttribute(name, value, parseOptions) {
  14399. var _runtime$styleValueRe;
  14400. if (parseOptions === void 0) {
  14401. parseOptions = {};
  14402. }
  14403. var renderable = this.renderable;
  14404. var oldValue = this.attributes[name];
  14405. var oldParsedValue = this.parsedStyle[name];
  14406. runtime.styleValueRegistry.processProperties(this, (_runtime$styleValueRe = {}, _runtime$styleValueRe[name] = value, _runtime$styleValueRe), parseOptions);
  14407. // redraw at next frame
  14408. renderable.dirty = true;
  14409. var newParsedValue = this.parsedStyle[name];
  14410. if (this.isConnected) {
  14411. mutationEvent.relatedNode = this;
  14412. mutationEvent.prevValue = oldValue;
  14413. mutationEvent.newValue = value;
  14414. mutationEvent.attrName = name;
  14415. mutationEvent.prevParsedValue = oldParsedValue;
  14416. mutationEvent.newParsedValue = newParsedValue;
  14417. if (this.isMutationObserved) {
  14418. this.dispatchEvent(mutationEvent);
  14419. } else {
  14420. mutationEvent.target = this;
  14421. this.ownerDocument.defaultView.dispatchEvent(mutationEvent, true);
  14422. }
  14423. }
  14424. if ((this.isCustomElement && this.isConnected || !this.isCustomElement) && this.attributeChangedCallback) {
  14425. this.attributeChangedCallback(name, oldValue, value, oldParsedValue, newParsedValue);
  14426. }
  14427. }
  14428. // #region transformable
  14429. /**
  14430. * returns different values than getBoundingClientRect(), as the latter returns value relative to the viewport
  14431. * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox
  14432. *
  14433. * FIXME: It is worth noting that getBBox responds to original untransformed values of a drawn object.
  14434. * @see https://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html#getBBox
  14435. */;
  14436. _proto.getBBox = function getBBox() {
  14437. var aabb = this.getBounds();
  14438. var _aabb$getMin = aabb.getMin(),
  14439. left = _aabb$getMin[0],
  14440. top = _aabb$getMin[1];
  14441. var _aabb$getMax = aabb.getMax(),
  14442. right = _aabb$getMax[0],
  14443. bottom = _aabb$getMax[1];
  14444. return new Rectangle(left, top, right - left, bottom - top);
  14445. };
  14446. _proto.setOrigin = function setOrigin(position, y, z) {
  14447. if (y === void 0) {
  14448. y = 0;
  14449. }
  14450. if (z === void 0) {
  14451. z = 0;
  14452. }
  14453. runtime.sceneGraphService.setOrigin(this, createVec3(position, y, z));
  14454. return this;
  14455. };
  14456. _proto.getOrigin = function getOrigin() {
  14457. return runtime.sceneGraphService.getOrigin(this);
  14458. }
  14459. /**
  14460. * set position in world space
  14461. */;
  14462. _proto.setPosition = function setPosition(position, y, z) {
  14463. if (y === void 0) {
  14464. y = 0;
  14465. }
  14466. if (z === void 0) {
  14467. z = 0;
  14468. }
  14469. runtime.sceneGraphService.setPosition(this, createVec3(position, y, z));
  14470. return this;
  14471. }
  14472. /**
  14473. * set position in local space
  14474. */;
  14475. _proto.setLocalPosition = function setLocalPosition(position, y, z) {
  14476. if (y === void 0) {
  14477. y = 0;
  14478. }
  14479. if (z === void 0) {
  14480. z = 0;
  14481. }
  14482. runtime.sceneGraphService.setLocalPosition(this, createVec3(position, y, z));
  14483. return this;
  14484. }
  14485. /**
  14486. * translate in world space
  14487. */;
  14488. _proto.translate = function translate(position, y, z) {
  14489. if (y === void 0) {
  14490. y = 0;
  14491. }
  14492. if (z === void 0) {
  14493. z = 0;
  14494. }
  14495. runtime.sceneGraphService.translate(this, createVec3(position, y, z));
  14496. return this;
  14497. }
  14498. /**
  14499. * translate in local space
  14500. */;
  14501. _proto.translateLocal = function translateLocal(position, y, z) {
  14502. if (y === void 0) {
  14503. y = 0;
  14504. }
  14505. if (z === void 0) {
  14506. z = 0;
  14507. }
  14508. runtime.sceneGraphService.translateLocal(this, createVec3(position, y, z));
  14509. return this;
  14510. };
  14511. _proto.getPosition = function getPosition() {
  14512. return runtime.sceneGraphService.getPosition(this);
  14513. };
  14514. _proto.getLocalPosition = function getLocalPosition() {
  14515. return runtime.sceneGraphService.getLocalPosition(this);
  14516. }
  14517. /**
  14518. * compatible with G 3.0
  14519. *
  14520. * scaling in local space
  14521. * scale(10) = scale(10, 10, 10)
  14522. *
  14523. * we can't set scale in world space
  14524. */;
  14525. _proto.scale = function scale(scaling, y, z) {
  14526. return this.scaleLocal(scaling, y, z);
  14527. };
  14528. _proto.scaleLocal = function scaleLocal(scaling, y, z) {
  14529. if (typeof scaling === 'number') {
  14530. y = y || scaling;
  14531. z = z || scaling;
  14532. scaling = createVec3(scaling, y, z);
  14533. }
  14534. runtime.sceneGraphService.scaleLocal(this, scaling);
  14535. return this;
  14536. }
  14537. /**
  14538. * set scaling in local space
  14539. */;
  14540. _proto.setLocalScale = function setLocalScale(scaling, y, z) {
  14541. if (typeof scaling === 'number') {
  14542. y = y || scaling;
  14543. z = z || scaling;
  14544. scaling = createVec3(scaling, y, z);
  14545. }
  14546. runtime.sceneGraphService.setLocalScale(this, scaling);
  14547. return this;
  14548. }
  14549. /**
  14550. * get scaling in local space
  14551. */;
  14552. _proto.getLocalScale = function getLocalScale() {
  14553. return runtime.sceneGraphService.getLocalScale(this);
  14554. }
  14555. /**
  14556. * get scaling in world space
  14557. */;
  14558. _proto.getScale = function getScale() {
  14559. return runtime.sceneGraphService.getScale(this);
  14560. }
  14561. /**
  14562. * only return degrees of Z axis in world space
  14563. */;
  14564. _proto.getEulerAngles = function getEulerAngles() {
  14565. var _getEuler = getEuler(create$2(), runtime.sceneGraphService.getWorldTransform(this)),
  14566. ez = _getEuler[2];
  14567. return rad2deg(ez);
  14568. }
  14569. /**
  14570. * only return degrees of Z axis in local space
  14571. */;
  14572. _proto.getLocalEulerAngles = function getLocalEulerAngles() {
  14573. var _getEuler2 = getEuler(create$2(), runtime.sceneGraphService.getLocalRotation(this)),
  14574. ez = _getEuler2[2];
  14575. return rad2deg(ez);
  14576. }
  14577. /**
  14578. * set euler angles(degrees) in world space
  14579. */;
  14580. _proto.setEulerAngles = function setEulerAngles(z) {
  14581. runtime.sceneGraphService.setEulerAngles(this, 0, 0, z);
  14582. return this;
  14583. }
  14584. /**
  14585. * set euler angles(degrees) in local space
  14586. */;
  14587. _proto.setLocalEulerAngles = function setLocalEulerAngles(z) {
  14588. runtime.sceneGraphService.setLocalEulerAngles(this, 0, 0, z);
  14589. return this;
  14590. };
  14591. _proto.rotateLocal = function rotateLocal(x, y, z) {
  14592. if (isNil(y) && isNil(z)) {
  14593. runtime.sceneGraphService.rotateLocal(this, 0, 0, x);
  14594. } else {
  14595. runtime.sceneGraphService.rotateLocal(this, x, y, z);
  14596. }
  14597. return this;
  14598. };
  14599. _proto.rotate = function rotate(x, y, z) {
  14600. if (isNil(y) && isNil(z)) {
  14601. runtime.sceneGraphService.rotate(this, 0, 0, x);
  14602. } else {
  14603. runtime.sceneGraphService.rotate(this, x, y, z);
  14604. }
  14605. return this;
  14606. };
  14607. _proto.setRotation = function setRotation(rotation, y, z, w) {
  14608. runtime.sceneGraphService.setRotation(this, rotation, y, z, w);
  14609. return this;
  14610. };
  14611. _proto.setLocalRotation = function setLocalRotation(rotation, y, z, w) {
  14612. runtime.sceneGraphService.setLocalRotation(this, rotation, y, z, w);
  14613. return this;
  14614. };
  14615. _proto.setLocalSkew = function setLocalSkew(skew, y) {
  14616. runtime.sceneGraphService.setLocalSkew(this, skew, y);
  14617. return this;
  14618. };
  14619. _proto.getRotation = function getRotation() {
  14620. return runtime.sceneGraphService.getRotation(this);
  14621. };
  14622. _proto.getLocalRotation = function getLocalRotation() {
  14623. return runtime.sceneGraphService.getLocalRotation(this);
  14624. };
  14625. _proto.getLocalSkew = function getLocalSkew() {
  14626. return runtime.sceneGraphService.getLocalSkew(this);
  14627. };
  14628. _proto.getLocalTransform = function getLocalTransform() {
  14629. return runtime.sceneGraphService.getLocalTransform(this);
  14630. };
  14631. _proto.getWorldTransform = function getWorldTransform() {
  14632. return runtime.sceneGraphService.getWorldTransform(this);
  14633. };
  14634. _proto.setLocalTransform = function setLocalTransform(transform) {
  14635. runtime.sceneGraphService.setLocalTransform(this, transform);
  14636. return this;
  14637. };
  14638. _proto.resetLocalTransform = function resetLocalTransform() {
  14639. runtime.sceneGraphService.resetLocalTransform(this);
  14640. }
  14641. // #endregion transformable
  14642. // #region animatable
  14643. /**
  14644. * returns an array of all Animation objects affecting this element
  14645. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAnimations
  14646. */;
  14647. _proto.getAnimations = function getAnimations() {
  14648. return this.activeAnimations;
  14649. }
  14650. /**
  14651. * create an animation with WAAPI
  14652. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/animate
  14653. */;
  14654. _proto.animate = function animate(keyframes, options) {
  14655. var _this$ownerDocument;
  14656. var timeline = (_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : _this$ownerDocument.timeline;
  14657. if (timeline) {
  14658. return timeline.play(this, keyframes, options);
  14659. }
  14660. return null;
  14661. }
  14662. // #endregion animatable
  14663. // #region visible
  14664. /**
  14665. * shortcut for Used value of `visibility`
  14666. */;
  14667. _proto.isVisible = function isVisible() {
  14668. var _this$parsedStyle;
  14669. return ((_this$parsedStyle = this.parsedStyle) === null || _this$parsedStyle === void 0 ? void 0 : _this$parsedStyle.visibility) === 'visible';
  14670. };
  14671. _proto.isInteractive = function isInteractive() {
  14672. var _this$parsedStyle2;
  14673. return ((_this$parsedStyle2 = this.parsedStyle) === null || _this$parsedStyle2 === void 0 ? void 0 : _this$parsedStyle2.pointerEvents) !== 'none';
  14674. };
  14675. _proto.isCulled = function isCulled() {
  14676. return !!(this.cullable && this.cullable.enable && !this.cullable.visible);
  14677. }
  14678. /**
  14679. * bring to front in current group
  14680. */;
  14681. _proto.toFront = function toFront() {
  14682. if (this.parentNode) {
  14683. this.style.zIndex = Math.max.apply(Math, this.parentNode.children.map(function (child) {
  14684. return Number(child.style.zIndex);
  14685. })) + 1;
  14686. }
  14687. return this;
  14688. }
  14689. /**
  14690. * send to back in current group
  14691. */;
  14692. _proto.toBack = function toBack() {
  14693. if (this.parentNode) {
  14694. this.style.zIndex = Math.min.apply(Math, this.parentNode.children.map(function (child) {
  14695. return Number(child.style.zIndex);
  14696. })) - 1;
  14697. }
  14698. return this;
  14699. }
  14700. // #endregion visible
  14701. // #region deprecated
  14702. /**
  14703. * compatible with G 3.0
  14704. * @alias object.config
  14705. * @deprecated
  14706. */;
  14707. _proto.getConfig = function getConfig() {
  14708. return this.config;
  14709. };
  14710. _proto.attr = function attr() {
  14711. var _this2 = this;
  14712. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  14713. args[_key] = arguments[_key];
  14714. }
  14715. var name = args[0],
  14716. value = args[1];
  14717. if (!name) {
  14718. return this.attributes;
  14719. }
  14720. if (isObject(name)) {
  14721. Object.keys(name).forEach(function (key) {
  14722. _this2.setAttribute(key, name[key]);
  14723. });
  14724. return this;
  14725. }
  14726. if (args.length === 2) {
  14727. this.setAttribute(name, value);
  14728. return this;
  14729. }
  14730. return this.attributes[name];
  14731. }
  14732. /**
  14733. * return 3x3 matrix in world space
  14734. * @deprecated
  14735. */;
  14736. _proto.getMatrix = function getMatrix(transformMat4) {
  14737. var transform = transformMat4 || this.getWorldTransform();
  14738. var _mat4$getTranslation = getTranslation(create$2(), transform),
  14739. tx = _mat4$getTranslation[0],
  14740. ty = _mat4$getTranslation[1];
  14741. var _mat4$getScaling = getScaling(create$2(), transform),
  14742. sx = _mat4$getScaling[0],
  14743. sy = _mat4$getScaling[1];
  14744. var rotation = getRotation(create$4(), transform);
  14745. var _getEuler3 = getEuler(create$2(), rotation),
  14746. eux = _getEuler3[0],
  14747. euz = _getEuler3[2];
  14748. // gimbal lock at 90 degrees
  14749. return fromRotationTranslationScale$1(eux || euz, tx, ty, sx, sy);
  14750. }
  14751. /**
  14752. * return 3x3 matrix in local space
  14753. * @deprecated
  14754. */;
  14755. _proto.getLocalMatrix = function getLocalMatrix() {
  14756. return this.getMatrix(this.getLocalTransform());
  14757. }
  14758. /**
  14759. * set 3x3 matrix in world space
  14760. * @deprecated
  14761. */;
  14762. _proto.setMatrix = function setMatrix(mat) {
  14763. var _decompose = decompose(mat),
  14764. tx = _decompose[0],
  14765. ty = _decompose[1],
  14766. scalingX = _decompose[2],
  14767. scalingY = _decompose[3],
  14768. angle = _decompose[4];
  14769. this.setEulerAngles(angle).setPosition(tx, ty).setLocalScale(scalingX, scalingY);
  14770. }
  14771. /**
  14772. * set 3x3 matrix in local space
  14773. * @deprecated
  14774. */;
  14775. _proto.setLocalMatrix = function setLocalMatrix(mat) {
  14776. var _decompose2 = decompose(mat),
  14777. tx = _decompose2[0],
  14778. ty = _decompose2[1],
  14779. scalingX = _decompose2[2],
  14780. scalingY = _decompose2[3],
  14781. angle = _decompose2[4];
  14782. this.setLocalEulerAngles(angle).setLocalPosition(tx, ty).setLocalScale(scalingX, scalingY);
  14783. }
  14784. /**
  14785. * Use `visibility: visible` instead.
  14786. * @deprecated
  14787. */;
  14788. _proto.show = function show() {
  14789. if (runtime.enableCSSParsing) {
  14790. this.style.visibility = 'visible';
  14791. } else {
  14792. this.forEach(function (object) {
  14793. object.style.visibility = 'visible';
  14794. });
  14795. }
  14796. }
  14797. /**
  14798. * Use `visibility: hidden` instead.
  14799. * @deprecated
  14800. */;
  14801. _proto.hide = function hide() {
  14802. if (runtime.enableCSSParsing) {
  14803. this.style.visibility = 'hidden';
  14804. } else {
  14805. this.forEach(function (object) {
  14806. object.style.visibility = 'hidden';
  14807. });
  14808. }
  14809. }
  14810. /**
  14811. * Use `childElementCount` instead.
  14812. * @deprecated
  14813. */;
  14814. _proto.getCount = function getCount() {
  14815. return this.childElementCount;
  14816. }
  14817. /**
  14818. * Use `parentElement` instead.
  14819. * @deprecated
  14820. */;
  14821. _proto.getParent = function getParent() {
  14822. return this.parentElement;
  14823. }
  14824. /**
  14825. * Use `children` instead.
  14826. * @deprecated
  14827. */;
  14828. _proto.getChildren = function getChildren() {
  14829. return this.children;
  14830. }
  14831. /**
  14832. * Use `firstElementChild` instead.
  14833. * @deprecated
  14834. */;
  14835. _proto.getFirst = function getFirst() {
  14836. return this.firstElementChild;
  14837. }
  14838. /**
  14839. * Use `lastElementChild` instead.
  14840. * @deprecated
  14841. */;
  14842. _proto.getLast = function getLast() {
  14843. return this.lastElementChild;
  14844. }
  14845. /**
  14846. * Use `this.children[index]` instead.
  14847. * @deprecated
  14848. */;
  14849. _proto.getChildByIndex = function getChildByIndex(index) {
  14850. return this.children[index] || null;
  14851. }
  14852. /**
  14853. * Use `appendChild` instead.
  14854. * @deprecated
  14855. */;
  14856. _proto.add = function add(child, index) {
  14857. return this.appendChild(child, index);
  14858. }
  14859. /**
  14860. * Use `this.style.clipPath` instead.
  14861. * @deprecated
  14862. */;
  14863. _proto.setClip = function setClip(clipPath) {
  14864. this.style.clipPath = clipPath;
  14865. };
  14866. /**
  14867. * @deprecated
  14868. */
  14869. _proto.set = function set(name, value) {
  14870. // @ts-ignore
  14871. this.config[name] = value;
  14872. }
  14873. /**
  14874. * @deprecated
  14875. */;
  14876. _proto.get = function get(name) {
  14877. return this.config[name];
  14878. }
  14879. /**
  14880. * Use `setPosition` instead.
  14881. * @deprecated
  14882. */;
  14883. _proto.moveTo = function moveTo(position, y, z) {
  14884. if (y === void 0) {
  14885. y = 0;
  14886. }
  14887. if (z === void 0) {
  14888. z = 0;
  14889. }
  14890. this.setPosition(position, y, z);
  14891. return this;
  14892. }
  14893. /**
  14894. * Use `setPosition` instead.
  14895. * @deprecated
  14896. */;
  14897. _proto.move = function move(position, y, z) {
  14898. if (y === void 0) {
  14899. y = 0;
  14900. }
  14901. if (z === void 0) {
  14902. z = 0;
  14903. }
  14904. this.setPosition(position, y, z);
  14905. return this;
  14906. }
  14907. /**
  14908. * Use `this.style.zIndex` instead.
  14909. * @deprecated
  14910. */;
  14911. _proto.setZIndex = function setZIndex(zIndex) {
  14912. this.style.zIndex = zIndex;
  14913. return this;
  14914. };
  14915. _createClass(DisplayObject, [{
  14916. key: "interactive",
  14917. get: function get() {
  14918. return this.isInteractive();
  14919. },
  14920. set: function set(b) {
  14921. this.style.pointerEvents = b ? 'auto' : 'none';
  14922. }
  14923. }]);
  14924. return DisplayObject;
  14925. }(Element);
  14926. var _excluded = ["style"];
  14927. var Circle = /*#__PURE__*/function (_DisplayObject) {
  14928. _inheritsLoose(Circle, _DisplayObject);
  14929. function Circle(_temp) {
  14930. var _ref = _temp === void 0 ? {} : _temp,
  14931. style = _ref.style,
  14932. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  14933. return _DisplayObject.call(this, _extends({
  14934. type: exports.Shape.CIRCLE,
  14935. style: runtime.enableCSSParsing ? _extends({
  14936. cx: '',
  14937. cy: '',
  14938. r: ''
  14939. }, style) : _extends({}, style),
  14940. initialParsedStyle: {
  14941. anchor: [0.5, 0.5],
  14942. transformOrigin: runtime.enableCSSParsing ? null : [PECENTAGE_50, PECENTAGE_50]
  14943. }
  14944. }, rest)) || this;
  14945. }
  14946. return Circle;
  14947. }(DisplayObject);
  14948. var _excluded$1 = ["style"];
  14949. /**
  14950. * shadow root
  14951. * @see https://yuque.antfin-inc.com/antv/czqvg5/pgqipg
  14952. */
  14953. var CustomElement = /*#__PURE__*/function (_DisplayObject) {
  14954. _inheritsLoose(CustomElement, _DisplayObject);
  14955. // private shadowNodes: DisplayObject[] = [];
  14956. function CustomElement(_temp) {
  14957. var _this;
  14958. var _ref = _temp === void 0 ? {} : _temp,
  14959. style = _ref.style,
  14960. rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
  14961. _this = _DisplayObject.call(this, _extends({
  14962. style: runtime.enableCSSParsing ? _extends({
  14963. x: '',
  14964. y: ''
  14965. }, style) : _extends({}, style)
  14966. }, rest)) || this;
  14967. // static get observedAttributes(): string[] {
  14968. // return [];
  14969. // }
  14970. _this.isCustomElement = true;
  14971. return _this;
  14972. }
  14973. return CustomElement;
  14974. }(DisplayObject);
  14975. var _excluded$2 = ["style"];
  14976. var Ellipse = /*#__PURE__*/function (_DisplayObject) {
  14977. _inheritsLoose(Ellipse, _DisplayObject);
  14978. function Ellipse(_temp) {
  14979. var _ref = _temp === void 0 ? {} : _temp,
  14980. style = _ref.style,
  14981. rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
  14982. return _DisplayObject.call(this, _extends({
  14983. type: exports.Shape.ELLIPSE,
  14984. style: runtime.enableCSSParsing ? _extends({
  14985. cx: '',
  14986. cy: '',
  14987. rx: '',
  14988. ry: ''
  14989. }, style) : _extends({}, style),
  14990. initialParsedStyle: {
  14991. anchor: [0.5, 0.5],
  14992. transformOrigin: runtime.enableCSSParsing ? null : [PECENTAGE_50, PECENTAGE_50]
  14993. }
  14994. }, rest)) || this;
  14995. }
  14996. return Ellipse;
  14997. }(DisplayObject);
  14998. var _excluded$3 = ["style"];
  14999. /**
  15000. * its attributes are inherited by its children.
  15001. * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/g
  15002. *
  15003. * @example
  15004. * <g fill="white" stroke="green" stroke-width="5">
  15005. <circle cx="40" cy="40" r="25" />
  15006. <circle cx="60" cy="60" r="25" />
  15007. </g>
  15008. */
  15009. var Group = /*#__PURE__*/function (_DisplayObject) {
  15010. _inheritsLoose(Group, _DisplayObject);
  15011. function Group(_temp) {
  15012. var _ref = _temp === void 0 ? {} : _temp,
  15013. style = _ref.style,
  15014. rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
  15015. return _DisplayObject.call(this, _extends({
  15016. type: exports.Shape.GROUP,
  15017. style: runtime.enableCSSParsing ? _extends({
  15018. x: '',
  15019. y: '',
  15020. width: '',
  15021. height: ''
  15022. }, style) : _extends({}, style)
  15023. }, rest)) || this;
  15024. }
  15025. return Group;
  15026. }(DisplayObject);
  15027. var _excluded$4 = ["style"];
  15028. /**
  15029. * HTML container
  15030. * @see https://github.com/pmndrs/drei#html
  15031. */
  15032. var HTML = /*#__PURE__*/function (_DisplayObject) {
  15033. _inheritsLoose(HTML, _DisplayObject);
  15034. function HTML(_temp) {
  15035. var _this;
  15036. var _ref = _temp === void 0 ? {} : _temp,
  15037. style = _ref.style,
  15038. rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
  15039. _this = _DisplayObject.call(this, _extends({
  15040. type: exports.Shape.HTML,
  15041. style: runtime.enableCSSParsing ? _extends({
  15042. x: '',
  15043. y: '',
  15044. width: 'auto',
  15045. height: 'auto',
  15046. innerHTML: ''
  15047. }, style) : _extends({}, style)
  15048. }, rest)) || this;
  15049. _this.cullable.enable = false;
  15050. return _this;
  15051. }
  15052. /**
  15053. * return wrapper HTMLElement
  15054. * * <div> in g-webgl/canvas
  15055. * * <foreignObject> in g-svg
  15056. */
  15057. var _proto = HTML.prototype;
  15058. _proto.getDomElement = function getDomElement() {
  15059. return this.parsedStyle.$el;
  15060. }
  15061. /**
  15062. * override with $el.getBoundingClientRect
  15063. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect
  15064. */;
  15065. _proto.getBoundingClientRect = function getBoundingClientRect() {
  15066. return this.parsedStyle.$el.getBoundingClientRect();
  15067. };
  15068. _proto.getClientRects = function getClientRects() {
  15069. return [this.getBoundingClientRect()];
  15070. };
  15071. _proto.getBounds = function getBounds() {
  15072. var _this$ownerDocument, _this$ownerDocument$d;
  15073. var clientRect = this.getBoundingClientRect();
  15074. // calc context's offset
  15075. // @ts-ignore
  15076. var canvasRect = (_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : (_this$ownerDocument$d = _this$ownerDocument.defaultView) === null || _this$ownerDocument$d === void 0 ? void 0 : _this$ownerDocument$d.getContextService().getBoundingClientRect();
  15077. if (canvasRect) {
  15078. var minX = clientRect.left - canvasRect.left;
  15079. var minY = clientRect.top - canvasRect.top;
  15080. var aabb = new AABB();
  15081. // aabb.setMinMax(
  15082. // vec3.fromValues(minX, minY, 0),
  15083. // vec3.fromValues(minX + clientRect.width, minY + clientRect.height, 0),
  15084. // );
  15085. aabb.setMinMax([minX, minY, 0], [minX + clientRect.width, minY + clientRect.height, 0]);
  15086. return aabb;
  15087. }
  15088. return null;
  15089. };
  15090. _proto.getLocalBounds = function getLocalBounds() {
  15091. if (this.parentNode) {
  15092. var parentInvert = invert(create$1(), this.parentNode.getWorldTransform());
  15093. var bounds = this.getBounds();
  15094. if (!AABB.isEmpty(bounds)) {
  15095. var localBounds = new AABB();
  15096. localBounds.setFromTransformedAABB(bounds, parentInvert);
  15097. return localBounds;
  15098. }
  15099. }
  15100. return this.getBounds();
  15101. };
  15102. return HTML;
  15103. }(DisplayObject);
  15104. var _excluded$5 = ["style"];
  15105. var Image = /*#__PURE__*/function (_DisplayObject) {
  15106. _inheritsLoose(Image, _DisplayObject);
  15107. function Image(_temp) {
  15108. var _ref = _temp === void 0 ? {} : _temp,
  15109. style = _ref.style,
  15110. rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
  15111. return _DisplayObject.call(this, _extends({
  15112. type: exports.Shape.IMAGE,
  15113. style: runtime.enableCSSParsing ? _extends({
  15114. x: '',
  15115. y: '',
  15116. img: '',
  15117. width: '',
  15118. height: ''
  15119. }, style) : _extends({}, style)
  15120. }, rest)) || this;
  15121. }
  15122. return Image;
  15123. }(DisplayObject);
  15124. var _excluded$6 = ["style"];
  15125. /**
  15126. * Create a line connecting two points.
  15127. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/line
  15128. *
  15129. * Also support for using marker.
  15130. */
  15131. var Line = /*#__PURE__*/function (_DisplayObject) {
  15132. _inheritsLoose(Line, _DisplayObject);
  15133. function Line(_temp) {
  15134. var _this;
  15135. var _ref = _temp === void 0 ? {} : _temp,
  15136. style = _ref.style,
  15137. rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
  15138. _this = _DisplayObject.call(this, _extends({
  15139. type: exports.Shape.LINE,
  15140. style: _extends({
  15141. x1: 0,
  15142. y1: 0,
  15143. x2: 0,
  15144. y2: 0,
  15145. z1: 0,
  15146. z2: 0,
  15147. isBillboard: false
  15148. }, style)
  15149. }, rest)) || this;
  15150. _this.markerStartAngle = 0;
  15151. _this.markerEndAngle = 0;
  15152. var _this$parsedStyle = _this.parsedStyle,
  15153. markerStart = _this$parsedStyle.markerStart,
  15154. markerEnd = _this$parsedStyle.markerEnd;
  15155. if (markerStart && isDisplayObject(markerStart)) {
  15156. _this.markerStartAngle = markerStart.getLocalEulerAngles();
  15157. _this.appendChild(markerStart);
  15158. }
  15159. if (markerEnd && isDisplayObject(markerEnd)) {
  15160. _this.markerEndAngle = markerEnd.getLocalEulerAngles();
  15161. _this.appendChild(markerEnd);
  15162. }
  15163. _this.transformMarker(true);
  15164. _this.transformMarker(false);
  15165. return _this;
  15166. }
  15167. var _proto = Line.prototype;
  15168. _proto.attributeChangedCallback = function attributeChangedCallback(attrName, oldValue, newValue, prevParsedValue, newParsedValue) {
  15169. if (attrName === 'x1' || attrName === 'y1' || attrName === 'x2' || attrName === 'y2' || attrName === 'markerStartOffset' || attrName === 'markerEndOffset') {
  15170. this.transformMarker(true);
  15171. this.transformMarker(false);
  15172. } else if (attrName === 'markerStart') {
  15173. if (prevParsedValue && isDisplayObject(prevParsedValue)) {
  15174. this.markerStartAngle = 0;
  15175. prevParsedValue.remove();
  15176. }
  15177. // CSSKeyword 'unset'
  15178. if (newParsedValue && isDisplayObject(newParsedValue)) {
  15179. this.markerStartAngle = newParsedValue.getLocalEulerAngles();
  15180. this.appendChild(newParsedValue);
  15181. this.transformMarker(true);
  15182. }
  15183. } else if (attrName === 'markerEnd') {
  15184. if (prevParsedValue && isDisplayObject(prevParsedValue)) {
  15185. this.markerEndAngle = 0;
  15186. prevParsedValue.remove();
  15187. }
  15188. if (newParsedValue && isDisplayObject(newParsedValue)) {
  15189. this.markerEndAngle = newParsedValue.getLocalEulerAngles();
  15190. this.appendChild(newParsedValue);
  15191. this.transformMarker(false);
  15192. }
  15193. }
  15194. };
  15195. _proto.transformMarker = function transformMarker(isStart) {
  15196. var _this$parsedStyle2 = this.parsedStyle,
  15197. markerStart = _this$parsedStyle2.markerStart,
  15198. markerEnd = _this$parsedStyle2.markerEnd,
  15199. markerStartOffset = _this$parsedStyle2.markerStartOffset,
  15200. markerEndOffset = _this$parsedStyle2.markerEndOffset,
  15201. x1 = _this$parsedStyle2.x1,
  15202. x2 = _this$parsedStyle2.x2,
  15203. y1 = _this$parsedStyle2.y1,
  15204. y2 = _this$parsedStyle2.y2,
  15205. defX = _this$parsedStyle2.defX,
  15206. defY = _this$parsedStyle2.defY;
  15207. var marker = isStart ? markerStart : markerEnd;
  15208. if (!marker || !isDisplayObject(marker)) {
  15209. return;
  15210. }
  15211. var rad = 0;
  15212. var x;
  15213. var y;
  15214. var ox;
  15215. var oy;
  15216. var offset;
  15217. var originalAngle;
  15218. if (isStart) {
  15219. ox = x1 - defX;
  15220. oy = y1 - defY;
  15221. x = x2 - x1;
  15222. y = y2 - y1;
  15223. offset = markerStartOffset || 0;
  15224. originalAngle = this.markerStartAngle;
  15225. } else {
  15226. ox = x2 - defX;
  15227. oy = y2 - defY;
  15228. x = x1 - x2;
  15229. y = y1 - y2;
  15230. offset = markerEndOffset || 0;
  15231. originalAngle = this.markerEndAngle;
  15232. }
  15233. rad = Math.atan2(y, x);
  15234. // account for markerOffset
  15235. marker.setLocalEulerAngles(rad * 180 / Math.PI + originalAngle);
  15236. marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
  15237. };
  15238. _proto.getPoint = function getPoint(ratio, inWorldSpace) {
  15239. if (inWorldSpace === void 0) {
  15240. inWorldSpace = false;
  15241. }
  15242. // TODO: account for z1/z2 in 3D line
  15243. var _this$parsedStyle3 = this.parsedStyle,
  15244. x1 = _this$parsedStyle3.x1,
  15245. y1 = _this$parsedStyle3.y1,
  15246. x2 = _this$parsedStyle3.x2,
  15247. y2 = _this$parsedStyle3.y2,
  15248. defX = _this$parsedStyle3.defX,
  15249. defY = _this$parsedStyle3.defY;
  15250. var _LineUtil$pointAt = line.pointAt(x1, y1, x2, y2, ratio),
  15251. x = _LineUtil$pointAt.x,
  15252. y = _LineUtil$pointAt.y;
  15253. var transformed = transformMat4(create$2(), fromValues$2(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform());
  15254. // apply local transformation
  15255. return new Point(transformed[0], transformed[1]);
  15256. };
  15257. _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
  15258. if (inWorldSpace === void 0) {
  15259. inWorldSpace = false;
  15260. }
  15261. return this.getPoint(distance / this.getTotalLength(), inWorldSpace);
  15262. };
  15263. _proto.getTotalLength = function getTotalLength() {
  15264. // TODO: account for z1/z2 in 3D line
  15265. var _this$parsedStyle4 = this.parsedStyle,
  15266. x1 = _this$parsedStyle4.x1,
  15267. y1 = _this$parsedStyle4.y1,
  15268. x2 = _this$parsedStyle4.x2,
  15269. y2 = _this$parsedStyle4.y2;
  15270. return line.length(x1, y1, x2, y2);
  15271. };
  15272. return Line;
  15273. }(DisplayObject);
  15274. var _excluded$7 = ["style"];
  15275. var EMPTY_PARSED_PATH = {
  15276. absolutePath: [],
  15277. hasArc: false,
  15278. segments: [],
  15279. polygons: [],
  15280. polylines: [],
  15281. curve: null,
  15282. totalLength: 0,
  15283. rect: new Rectangle(0, 0, 0, 0)
  15284. };
  15285. var Path = /*#__PURE__*/function (_DisplayObject) {
  15286. _inheritsLoose(Path, _DisplayObject);
  15287. function Path(_temp) {
  15288. var _this;
  15289. var _ref = _temp === void 0 ? {} : _temp,
  15290. style = _ref.style,
  15291. rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
  15292. _this = _DisplayObject.call(this, _extends({
  15293. type: exports.Shape.PATH,
  15294. style: runtime.enableCSSParsing ? _extends({
  15295. path: '',
  15296. miterLimit: ''
  15297. }, style) : _extends({}, style),
  15298. initialParsedStyle: runtime.enableCSSParsing ? null : {
  15299. miterLimit: 4,
  15300. path: _extends({}, EMPTY_PARSED_PATH)
  15301. }
  15302. }, rest)) || this;
  15303. _this.markerStartAngle = 0;
  15304. _this.markerEndAngle = 0;
  15305. /**
  15306. * markers placed at the mid
  15307. */
  15308. _this.markerMidList = [];
  15309. var _this$parsedStyle = _this.parsedStyle,
  15310. markerStart = _this$parsedStyle.markerStart,
  15311. markerEnd = _this$parsedStyle.markerEnd,
  15312. markerMid = _this$parsedStyle.markerMid;
  15313. if (markerStart && isDisplayObject(markerStart)) {
  15314. _this.markerStartAngle = markerStart.getLocalEulerAngles();
  15315. _this.appendChild(markerStart);
  15316. }
  15317. if (markerMid && isDisplayObject(markerMid)) {
  15318. _this.placeMarkerMid(markerMid);
  15319. }
  15320. if (markerEnd && isDisplayObject(markerEnd)) {
  15321. _this.markerEndAngle = markerEnd.getLocalEulerAngles();
  15322. _this.appendChild(markerEnd);
  15323. }
  15324. _this.transformMarker(true);
  15325. _this.transformMarker(false);
  15326. return _this;
  15327. }
  15328. var _proto = Path.prototype;
  15329. _proto.attributeChangedCallback = function attributeChangedCallback(attrName, oldValue, newValue, prevParsedValue, newParsedValue) {
  15330. if (attrName === 'path') {
  15331. // recalc markers
  15332. this.transformMarker(true);
  15333. this.transformMarker(false);
  15334. this.placeMarkerMid(this.parsedStyle.markerMid);
  15335. } else if (attrName === 'markerStartOffset' || attrName === 'markerEndOffset') {
  15336. this.transformMarker(true);
  15337. this.transformMarker(false);
  15338. } else if (attrName === 'markerStart') {
  15339. if (prevParsedValue && isDisplayObject(prevParsedValue)) {
  15340. this.markerStartAngle = 0;
  15341. prevParsedValue.remove();
  15342. }
  15343. // CSSKeyword 'unset'
  15344. if (newParsedValue && isDisplayObject(newParsedValue)) {
  15345. this.markerStartAngle = newParsedValue.getLocalEulerAngles();
  15346. this.appendChild(newParsedValue);
  15347. this.transformMarker(true);
  15348. }
  15349. } else if (attrName === 'markerEnd') {
  15350. if (prevParsedValue && isDisplayObject(prevParsedValue)) {
  15351. this.markerEndAngle = 0;
  15352. prevParsedValue.remove();
  15353. }
  15354. if (newParsedValue && isDisplayObject(newParsedValue)) {
  15355. this.markerEndAngle = newParsedValue.getLocalEulerAngles();
  15356. this.appendChild(newParsedValue);
  15357. this.transformMarker(false);
  15358. }
  15359. } else if (attrName === 'markerMid') {
  15360. this.placeMarkerMid(newParsedValue);
  15361. }
  15362. };
  15363. _proto.transformMarker = function transformMarker(isStart) {
  15364. var _this$parsedStyle2 = this.parsedStyle,
  15365. markerStart = _this$parsedStyle2.markerStart,
  15366. markerEnd = _this$parsedStyle2.markerEnd,
  15367. markerStartOffset = _this$parsedStyle2.markerStartOffset,
  15368. markerEndOffset = _this$parsedStyle2.markerEndOffset,
  15369. defX = _this$parsedStyle2.defX,
  15370. defY = _this$parsedStyle2.defY;
  15371. var marker = isStart ? markerStart : markerEnd;
  15372. if (!marker || !isDisplayObject(marker)) {
  15373. return;
  15374. }
  15375. var rad = 0;
  15376. var x;
  15377. var y;
  15378. var ox;
  15379. var oy;
  15380. var offset;
  15381. var originalAngle;
  15382. if (isStart) {
  15383. var _this$getStartTangent = this.getStartTangent(),
  15384. p1 = _this$getStartTangent[0],
  15385. p2 = _this$getStartTangent[1];
  15386. ox = p2[0] - defX;
  15387. oy = p2[1] - defY;
  15388. x = p1[0] - p2[0];
  15389. y = p1[1] - p2[1];
  15390. offset = markerStartOffset || 0;
  15391. originalAngle = this.markerStartAngle;
  15392. } else {
  15393. var _this$getEndTangent = this.getEndTangent(),
  15394. _p = _this$getEndTangent[0],
  15395. _p2 = _this$getEndTangent[1];
  15396. ox = _p2[0] - defX;
  15397. oy = _p2[1] - defY;
  15398. x = _p[0] - _p2[0];
  15399. y = _p[1] - _p2[1];
  15400. offset = markerEndOffset || 0;
  15401. originalAngle = this.markerEndAngle;
  15402. }
  15403. rad = Math.atan2(y, x);
  15404. // account for markerOffset
  15405. marker.setLocalEulerAngles(rad * 180 / Math.PI + originalAngle);
  15406. marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
  15407. };
  15408. _proto.placeMarkerMid = function placeMarkerMid(marker) {
  15409. var _this$parsedStyle3 = this.parsedStyle,
  15410. segments = _this$parsedStyle3.path.segments,
  15411. defX = _this$parsedStyle3.defX,
  15412. defY = _this$parsedStyle3.defY;
  15413. // clear all existed markers
  15414. this.markerMidList.forEach(function (marker) {
  15415. marker.remove();
  15416. });
  15417. if (marker && isDisplayObject(marker)) {
  15418. for (var i = 1; i < segments.length - 1; i++) {
  15419. var _segments$i$currentPo = segments[i].currentPoint,
  15420. ox = _segments$i$currentPo[0],
  15421. oy = _segments$i$currentPo[1];
  15422. var cloned = i === 1 ? marker : marker.cloneNode(true);
  15423. this.markerMidList.push(cloned);
  15424. this.appendChild(cloned);
  15425. cloned.setLocalPosition(ox - defX, oy - defY);
  15426. // TODO: orient of marker
  15427. }
  15428. }
  15429. }
  15430. /**
  15431. * Returns the total length of the path.
  15432. * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getTotalLength
  15433. */;
  15434. _proto.getTotalLength = function getTotalLength() {
  15435. return getOrCalculatePathTotalLength(this);
  15436. }
  15437. /**
  15438. * Returns the point at a given distance along the path.
  15439. * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getPointAtLength
  15440. */;
  15441. _proto.getPointAtLength = function getPointAtLength$1(distance, inWorldSpace) {
  15442. if (inWorldSpace === void 0) {
  15443. inWorldSpace = false;
  15444. }
  15445. var _this$parsedStyle4 = this.parsedStyle,
  15446. defX = _this$parsedStyle4.defX,
  15447. defY = _this$parsedStyle4.defY,
  15448. absolutePath = _this$parsedStyle4.path.absolutePath;
  15449. var _getPointAtLength2 = getPointAtLength(absolutePath, distance),
  15450. x = _getPointAtLength2.x,
  15451. y = _getPointAtLength2.y;
  15452. var transformed = transformMat4(create$2(), fromValues$2(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform());
  15453. // apply local transformation
  15454. return new Point(transformed[0], transformed[1]);
  15455. }
  15456. /**
  15457. * Returns the point at a given ratio of the total length in path.
  15458. */;
  15459. _proto.getPoint = function getPoint(ratio, inWorldSpace) {
  15460. if (inWorldSpace === void 0) {
  15461. inWorldSpace = false;
  15462. }
  15463. return this.getPointAtLength(ratio * getOrCalculatePathTotalLength(this), inWorldSpace);
  15464. }
  15465. /**
  15466. * Get start tangent vector
  15467. */;
  15468. _proto.getStartTangent = function getStartTangent() {
  15469. var segments = this.parsedStyle.path.segments;
  15470. var result = [];
  15471. if (segments.length > 1) {
  15472. var startPoint = segments[0].currentPoint;
  15473. var endPoint = segments[1].currentPoint;
  15474. var tangent = segments[1].startTangent;
  15475. result = [];
  15476. if (tangent) {
  15477. result.push([startPoint[0] - tangent[0], startPoint[1] - tangent[1]]);
  15478. result.push([startPoint[0], startPoint[1]]);
  15479. } else {
  15480. result.push([endPoint[0], endPoint[1]]);
  15481. result.push([startPoint[0], startPoint[1]]);
  15482. }
  15483. }
  15484. return result;
  15485. }
  15486. /**
  15487. * Get end tangent vector
  15488. */;
  15489. _proto.getEndTangent = function getEndTangent() {
  15490. var segments = this.parsedStyle.path.segments;
  15491. var length = segments.length;
  15492. var result = [];
  15493. if (length > 1) {
  15494. var startPoint = segments[length - 2].currentPoint;
  15495. var endPoint = segments[length - 1].currentPoint;
  15496. var tangent = segments[length - 1].endTangent;
  15497. result = [];
  15498. if (tangent) {
  15499. result.push([endPoint[0] - tangent[0], endPoint[1] - tangent[1]]);
  15500. result.push([endPoint[0], endPoint[1]]);
  15501. } else {
  15502. result.push([startPoint[0], startPoint[1]]);
  15503. result.push([endPoint[0], endPoint[1]]);
  15504. }
  15505. }
  15506. return result;
  15507. };
  15508. return Path;
  15509. }(DisplayObject);
  15510. var _excluded$8 = ["style"];
  15511. var Polygon = /*#__PURE__*/function (_DisplayObject) {
  15512. _inheritsLoose(Polygon, _DisplayObject);
  15513. function Polygon(_temp) {
  15514. var _this;
  15515. var _ref = _temp === void 0 ? {} : _temp,
  15516. style = _ref.style,
  15517. rest = _objectWithoutPropertiesLoose(_ref, _excluded$8);
  15518. _this = _DisplayObject.call(this, _extends({
  15519. type: exports.Shape.POLYGON,
  15520. style: runtime.enableCSSParsing ? _extends({
  15521. points: '',
  15522. miterLimit: '',
  15523. isClosed: true
  15524. }, style) : _extends({}, style),
  15525. initialParsedStyle: runtime.enableCSSParsing ? null : {
  15526. points: {
  15527. points: [],
  15528. totalLength: 0,
  15529. segments: []
  15530. },
  15531. miterLimit: 4,
  15532. isClosed: true
  15533. }
  15534. }, rest)) || this;
  15535. _this.markerStartAngle = 0;
  15536. _this.markerEndAngle = 0;
  15537. /**
  15538. * markers placed at the mid
  15539. */
  15540. _this.markerMidList = [];
  15541. var _this$parsedStyle = _this.parsedStyle,
  15542. markerStart = _this$parsedStyle.markerStart,
  15543. markerEnd = _this$parsedStyle.markerEnd,
  15544. markerMid = _this$parsedStyle.markerMid;
  15545. if (markerStart && isDisplayObject(markerStart)) {
  15546. _this.markerStartAngle = markerStart.getLocalEulerAngles();
  15547. _this.appendChild(markerStart);
  15548. }
  15549. if (markerMid && isDisplayObject(markerMid)) {
  15550. _this.placeMarkerMid(markerMid);
  15551. }
  15552. if (markerEnd && isDisplayObject(markerEnd)) {
  15553. _this.markerEndAngle = markerEnd.getLocalEulerAngles();
  15554. _this.appendChild(markerEnd);
  15555. }
  15556. _this.transformMarker(true);
  15557. _this.transformMarker(false);
  15558. return _this;
  15559. }
  15560. var _proto = Polygon.prototype;
  15561. _proto.attributeChangedCallback = function attributeChangedCallback(attrName, oldValue, newValue, prevParsedValue, newParsedValue) {
  15562. if (attrName === 'points') {
  15563. // recalc markers
  15564. this.transformMarker(true);
  15565. this.transformMarker(false);
  15566. this.placeMarkerMid(this.parsedStyle.markerMid);
  15567. } else if (attrName === 'markerStartOffset' || attrName === 'markerEndOffset') {
  15568. this.transformMarker(true);
  15569. this.transformMarker(false);
  15570. } else if (attrName === 'markerStart') {
  15571. if (prevParsedValue && isDisplayObject(prevParsedValue)) {
  15572. this.markerStartAngle = 0;
  15573. prevParsedValue.remove();
  15574. }
  15575. // CSSKeyword 'unset'
  15576. if (newParsedValue && isDisplayObject(newParsedValue)) {
  15577. this.markerStartAngle = newParsedValue.getLocalEulerAngles();
  15578. this.appendChild(newParsedValue);
  15579. this.transformMarker(true);
  15580. }
  15581. } else if (attrName === 'markerEnd') {
  15582. if (prevParsedValue && isDisplayObject(prevParsedValue)) {
  15583. this.markerEndAngle = 0;
  15584. prevParsedValue.remove();
  15585. }
  15586. if (newParsedValue && isDisplayObject(newParsedValue)) {
  15587. this.markerEndAngle = newParsedValue.getLocalEulerAngles();
  15588. this.appendChild(newParsedValue);
  15589. this.transformMarker(false);
  15590. }
  15591. } else if (attrName === 'markerMid') {
  15592. this.placeMarkerMid(newParsedValue);
  15593. }
  15594. };
  15595. _proto.transformMarker = function transformMarker(isStart) {
  15596. var _this$parsedStyle2 = this.parsedStyle,
  15597. markerStart = _this$parsedStyle2.markerStart,
  15598. markerEnd = _this$parsedStyle2.markerEnd,
  15599. markerStartOffset = _this$parsedStyle2.markerStartOffset,
  15600. markerEndOffset = _this$parsedStyle2.markerEndOffset,
  15601. points = _this$parsedStyle2.points.points,
  15602. defX = _this$parsedStyle2.defX,
  15603. defY = _this$parsedStyle2.defY;
  15604. var marker = isStart ? markerStart : markerEnd;
  15605. if (!marker || !isDisplayObject(marker)) {
  15606. return;
  15607. }
  15608. var rad = 0;
  15609. var x;
  15610. var y;
  15611. var ox;
  15612. var oy;
  15613. var offset;
  15614. var originalAngle;
  15615. ox = points[0][0] - defX;
  15616. oy = points[0][1] - defY;
  15617. if (isStart) {
  15618. x = points[1][0] - points[0][0];
  15619. y = points[1][1] - points[0][1];
  15620. offset = markerStartOffset || 0;
  15621. originalAngle = this.markerStartAngle;
  15622. } else {
  15623. var length = points.length;
  15624. if (!this.parsedStyle.isClosed) {
  15625. ox = points[length - 1][0] - defX;
  15626. oy = points[length - 1][1] - defY;
  15627. x = points[length - 2][0] - points[length - 1][0];
  15628. y = points[length - 2][1] - points[length - 1][1];
  15629. } else {
  15630. x = points[length - 1][0] - points[0][0];
  15631. y = points[length - 1][1] - points[0][1];
  15632. }
  15633. offset = markerEndOffset || 0;
  15634. originalAngle = this.markerEndAngle;
  15635. }
  15636. rad = Math.atan2(y, x);
  15637. // account for markerOffset
  15638. marker.setLocalEulerAngles(rad * 180 / Math.PI + originalAngle);
  15639. marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
  15640. };
  15641. _proto.placeMarkerMid = function placeMarkerMid(marker) {
  15642. var _this$parsedStyle3 = this.parsedStyle,
  15643. points = _this$parsedStyle3.points.points,
  15644. defX = _this$parsedStyle3.defX,
  15645. defY = _this$parsedStyle3.defY;
  15646. // clear all existed markers
  15647. this.markerMidList.forEach(function (marker) {
  15648. marker.remove();
  15649. });
  15650. this.markerMidList = [];
  15651. if (marker && isDisplayObject(marker)) {
  15652. for (var i = 1; i < (this.parsedStyle.isClosed ? points.length : points.length - 1); i++) {
  15653. var ox = points[i][0] - defX;
  15654. var oy = points[i][1] - defY;
  15655. var cloned = i === 1 ? marker : marker.cloneNode(true);
  15656. this.markerMidList.push(cloned);
  15657. this.appendChild(cloned);
  15658. cloned.setLocalPosition(ox, oy);
  15659. // TODO: orient of marker
  15660. }
  15661. }
  15662. };
  15663. return Polygon;
  15664. }(DisplayObject);
  15665. var _excluded$9 = ["style"];
  15666. /**
  15667. * Polyline inherits the marker-related capabilities of Polygon.
  15668. */
  15669. var Polyline = /*#__PURE__*/function (_Polygon) {
  15670. _inheritsLoose(Polyline, _Polygon);
  15671. function Polyline(_temp) {
  15672. var _ref = _temp === void 0 ? {} : _temp,
  15673. style = _ref.style,
  15674. rest = _objectWithoutPropertiesLoose(_ref, _excluded$9);
  15675. return _Polygon.call(this, _extends({
  15676. type: exports.Shape.POLYLINE,
  15677. style: runtime.enableCSSParsing ? _extends({
  15678. points: '',
  15679. miterLimit: '',
  15680. isClosed: false
  15681. }, style) : _extends({}, style),
  15682. initialParsedStyle: runtime.enableCSSParsing ? null : {
  15683. points: {
  15684. points: [],
  15685. totalLength: 0,
  15686. segments: []
  15687. },
  15688. miterLimit: 4,
  15689. isClosed: false
  15690. }
  15691. }, rest)) || this;
  15692. }
  15693. var _proto = Polyline.prototype;
  15694. _proto.getTotalLength = function getTotalLength() {
  15695. return this.parsedStyle.points.totalLength;
  15696. };
  15697. _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
  15698. if (inWorldSpace === void 0) {
  15699. inWorldSpace = false;
  15700. }
  15701. return this.getPoint(distance / this.getTotalLength(), inWorldSpace);
  15702. };
  15703. _proto.getPoint = function getPoint(ratio, inWorldSpace) {
  15704. if (inWorldSpace === void 0) {
  15705. inWorldSpace = false;
  15706. }
  15707. var _this$parsedStyle = this.parsedStyle,
  15708. defX = _this$parsedStyle.defX,
  15709. defY = _this$parsedStyle.defY,
  15710. _this$parsedStyle$poi = _this$parsedStyle.points,
  15711. points = _this$parsedStyle$poi.points,
  15712. segments = _this$parsedStyle$poi.segments;
  15713. var subt = 0;
  15714. var index = 0;
  15715. segments.forEach(function (v, i) {
  15716. if (ratio >= v[0] && ratio <= v[1]) {
  15717. subt = (ratio - v[0]) / (v[1] - v[0]);
  15718. index = i;
  15719. }
  15720. });
  15721. var _LineUtil$pointAt = line.pointAt(points[index][0], points[index][1], points[index + 1][0], points[index + 1][1], subt),
  15722. x = _LineUtil$pointAt.x,
  15723. y = _LineUtil$pointAt.y;
  15724. var transformed = transformMat4(create$2(), fromValues$2(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform());
  15725. // apply local transformation
  15726. return new Point(transformed[0], transformed[1]);
  15727. };
  15728. _proto.getStartTangent = function getStartTangent() {
  15729. var points = this.parsedStyle.points.points;
  15730. var result = [];
  15731. result.push([points[1][0], points[1][1]]);
  15732. result.push([points[0][0], points[0][1]]);
  15733. return result;
  15734. };
  15735. _proto.getEndTangent = function getEndTangent() {
  15736. var points = this.parsedStyle.points.points;
  15737. var l = points.length - 1;
  15738. var result = [];
  15739. result.push([points[l - 1][0], points[l - 1][1]]);
  15740. result.push([points[l][0], points[l][1]]);
  15741. return result;
  15742. };
  15743. return Polyline;
  15744. }(Polygon);
  15745. var _excluded$a = ["style"];
  15746. var Rect = /*#__PURE__*/function (_DisplayObject) {
  15747. _inheritsLoose(Rect, _DisplayObject);
  15748. function Rect(_temp) {
  15749. var _ref = _temp === void 0 ? {} : _temp,
  15750. style = _ref.style,
  15751. rest = _objectWithoutPropertiesLoose(_ref, _excluded$a);
  15752. return _DisplayObject.call(this, _extends({
  15753. type: exports.Shape.RECT,
  15754. style: runtime.enableCSSParsing ? _extends({
  15755. x: '',
  15756. y: '',
  15757. width: '',
  15758. height: '',
  15759. radius: ''
  15760. }, style) : _extends({}, style)
  15761. }, rest)) || this;
  15762. }
  15763. return Rect;
  15764. }(DisplayObject);
  15765. var _excluded$b = ["style"];
  15766. /**
  15767. * <text> @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextElement
  15768. */
  15769. var Text = /*#__PURE__*/function (_DisplayObject) {
  15770. _inheritsLoose(Text, _DisplayObject);
  15771. /**
  15772. * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement#constants
  15773. */
  15774. // LENGTHADJUST_SPACING: number = 1;
  15775. // LENGTHADJUST_SPACINGANDGLYPHS: number = 2;
  15776. // LENGTHADJUST_UNKNOWN: number = 0;
  15777. function Text(_temp) {
  15778. var _ref = _temp === void 0 ? {} : _temp,
  15779. style = _ref.style,
  15780. rest = _objectWithoutPropertiesLoose(_ref, _excluded$b);
  15781. return _DisplayObject.call(this, _extends({
  15782. type: exports.Shape.TEXT,
  15783. style: runtime.enableCSSParsing ? _extends({
  15784. x: '',
  15785. y: '',
  15786. text: '',
  15787. fontSize: '',
  15788. fontFamily: '',
  15789. fontStyle: '',
  15790. fontWeight: '',
  15791. fontVariant: '',
  15792. textAlign: '',
  15793. textBaseline: '',
  15794. textTransform: '',
  15795. fill: 'black',
  15796. letterSpacing: '',
  15797. lineHeight: '',
  15798. miterLimit: '',
  15799. // whiteSpace: 'pre',
  15800. wordWrap: false,
  15801. wordWrapWidth: 0,
  15802. leading: 0,
  15803. dx: '',
  15804. dy: '',
  15805. isBillboard: false,
  15806. sizeAttenuation: true
  15807. }, style) : _extends({
  15808. fill: 'black'
  15809. }, style),
  15810. initialParsedStyle: runtime.enableCSSParsing ? {} : {
  15811. x: 0,
  15812. y: 0,
  15813. fontSize: 16,
  15814. fontFamily: 'sans-serif',
  15815. fontStyle: 'normal',
  15816. fontWeight: 'normal',
  15817. fontVariant: 'normal',
  15818. lineHeight: 0,
  15819. letterSpacing: 0,
  15820. textBaseline: 'alphabetic',
  15821. textAlign: 'start',
  15822. wordWrap: false,
  15823. wordWrapWidth: 0,
  15824. leading: 0,
  15825. dx: 0,
  15826. dy: 0,
  15827. isBillboard: false,
  15828. sizeAttenuation: true
  15829. }
  15830. }, rest)) || this;
  15831. }
  15832. // lengthAdjust: SVGAnimatedEnumeration;
  15833. // textLength: SVGAnimatedLength;
  15834. // getCharNumAtPosition(point?: DOMPointInit): number {
  15835. // throw new Error('Method not implemented.');
  15836. // }
  15837. /**
  15838. * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement
  15839. */
  15840. var _proto = Text.prototype;
  15841. _proto.getComputedTextLength = function getComputedTextLength() {
  15842. var _this$parsedStyle$met;
  15843. return ((_this$parsedStyle$met = this.parsedStyle.metrics) === null || _this$parsedStyle$met === void 0 ? void 0 : _this$parsedStyle$met.maxLineWidth) || 0;
  15844. }
  15845. // getEndPositionOfChar(charnum: number): DOMPoint {
  15846. // throw new Error('Method not implemented.');
  15847. // }
  15848. // getExtentOfChar(charnum: number): DOMRect {
  15849. // throw new Error('Method not implemented.');
  15850. // }
  15851. // getNumberOfChars(): number {
  15852. // throw new Error('Method not implemented.');
  15853. // }
  15854. // getRotationOfChar(charnum: number): number {
  15855. // throw new Error('Method not implemented.');
  15856. // }
  15857. // getStartPositionOfChar(charnum: number): DOMPoint {
  15858. // throw new Error('Method not implemented.');
  15859. // }
  15860. // getSubStringLength(charnum: number, nchars: number): number {
  15861. // throw new Error('Method not implemented.');
  15862. // }
  15863. // selectSubString(charnum: number, nchars: number): void {
  15864. // throw new Error('Method not implemented.');
  15865. // }
  15866. ;
  15867. _proto.getLineBoundingRects = function getLineBoundingRects() {
  15868. var _this$parsedStyle$met2;
  15869. return ((_this$parsedStyle$met2 = this.parsedStyle.metrics) === null || _this$parsedStyle$met2 === void 0 ? void 0 : _this$parsedStyle$met2.lineMetrics) || [];
  15870. };
  15871. _proto.isOverflowing = function isOverflowing() {
  15872. return !!this.parsedStyle.isOverflowing;
  15873. };
  15874. return Text;
  15875. }(DisplayObject);
  15876. /**
  15877. * Blink used them in code generation(css_properties.json5)
  15878. */
  15879. var BUILT_IN_PROPERTIES = [{
  15880. /**
  15881. * used in CSS Layout API
  15882. * eg. `display: 'flex'`
  15883. */
  15884. n: 'display',
  15885. k: ['none']
  15886. }, {
  15887. /**
  15888. * range [0.0, 1.0]
  15889. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/opacity
  15890. */
  15891. n: 'opacity',
  15892. int: true,
  15893. inh: true,
  15894. d: '1',
  15895. syntax: exports.PropertySyntax.OPACITY_VALUE
  15896. }, {
  15897. /**
  15898. * inheritable, range [0.0, 1.0]
  15899. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-opacity
  15900. * @see https://svgwg.org/svg2-draft/painting.html#FillOpacity
  15901. */
  15902. n: 'fillOpacity',
  15903. int: true,
  15904. inh: true,
  15905. d: '1',
  15906. syntax: exports.PropertySyntax.OPACITY_VALUE
  15907. }, {
  15908. /**
  15909. * inheritable, range [0.0, 1.0]
  15910. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-opacity
  15911. * @see https://svgwg.org/svg2-draft/painting.html#StrokeOpacity
  15912. */
  15913. n: 'strokeOpacity',
  15914. int: true,
  15915. inh: true,
  15916. d: '1',
  15917. syntax: exports.PropertySyntax.OPACITY_VALUE
  15918. }, {
  15919. /**
  15920. * background-color is not inheritable
  15921. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Fills_and_Strokes
  15922. */
  15923. n: 'fill',
  15924. int: true,
  15925. k: ['none'],
  15926. d: 'none',
  15927. syntax: exports.PropertySyntax.PAINT
  15928. }, {
  15929. n: 'fillRule',
  15930. k: ['nonzero', 'evenodd'],
  15931. d: 'nonzero'
  15932. },
  15933. /**
  15934. * default to none
  15935. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke#usage_notes
  15936. */
  15937. {
  15938. n: 'stroke',
  15939. int: true,
  15940. k: ['none'],
  15941. d: 'none',
  15942. syntax: exports.PropertySyntax.PAINT,
  15943. /**
  15944. * Stroke 'none' won't affect geometry but others will.
  15945. */
  15946. l: true
  15947. }, {
  15948. n: 'shadowType',
  15949. k: ['inner', 'outer', 'both'],
  15950. d: 'outer',
  15951. l: true
  15952. }, {
  15953. n: 'shadowColor',
  15954. int: true,
  15955. syntax: exports.PropertySyntax.COLOR
  15956. }, {
  15957. n: 'shadowOffsetX',
  15958. int: true,
  15959. l: true,
  15960. d: '0',
  15961. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  15962. }, {
  15963. n: 'shadowOffsetY',
  15964. int: true,
  15965. l: true,
  15966. d: '0',
  15967. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  15968. }, {
  15969. n: 'shadowBlur',
  15970. int: true,
  15971. l: true,
  15972. d: '0',
  15973. syntax: exports.PropertySyntax.SHADOW_BLUR
  15974. }, {
  15975. /**
  15976. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-width
  15977. */
  15978. n: 'lineWidth',
  15979. int: true,
  15980. inh: true,
  15981. d: '1',
  15982. l: true,
  15983. a: ['strokeWidth'],
  15984. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  15985. }, {
  15986. n: 'increasedLineWidthForHitTesting',
  15987. inh: true,
  15988. d: '0',
  15989. l: true,
  15990. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  15991. }, {
  15992. n: 'lineJoin',
  15993. inh: true,
  15994. l: true,
  15995. a: ['strokeLinejoin'],
  15996. k: ['miter', 'bevel', 'round'],
  15997. d: 'miter'
  15998. }, {
  15999. n: 'lineCap',
  16000. inh: true,
  16001. l: true,
  16002. a: ['strokeLinecap'],
  16003. k: ['butt', 'round', 'square'],
  16004. d: 'butt'
  16005. }, {
  16006. n: 'lineDash',
  16007. int: true,
  16008. inh: true,
  16009. k: ['none'],
  16010. a: ['strokeDasharray'],
  16011. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE_12
  16012. }, {
  16013. n: 'lineDashOffset',
  16014. int: true,
  16015. inh: true,
  16016. d: '0',
  16017. a: ['strokeDashoffset'],
  16018. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  16019. }, {
  16020. n: 'offsetPath',
  16021. syntax: exports.PropertySyntax.DEFINED_PATH
  16022. }, {
  16023. n: 'offsetDistance',
  16024. int: true,
  16025. syntax: exports.PropertySyntax.OFFSET_DISTANCE
  16026. }, {
  16027. n: 'dx',
  16028. int: true,
  16029. l: true,
  16030. d: '0',
  16031. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  16032. }, {
  16033. n: 'dy',
  16034. int: true,
  16035. l: true,
  16036. d: '0',
  16037. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  16038. }, {
  16039. n: 'zIndex',
  16040. ind: true,
  16041. int: true,
  16042. d: '0',
  16043. k: ['auto'],
  16044. syntax: exports.PropertySyntax.Z_INDEX
  16045. }, {
  16046. n: 'visibility',
  16047. k: ['visible', 'hidden'],
  16048. ind: true,
  16049. inh: true,
  16050. /**
  16051. * support interpolation
  16052. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/visibility#interpolation
  16053. */
  16054. int: true,
  16055. d: 'visible'
  16056. }, {
  16057. n: 'pointerEvents',
  16058. inh: true,
  16059. k: ['none', 'auto', 'stroke', 'fill', 'painted', 'visible', 'visiblestroke', 'visiblefill', 'visiblepainted',
  16060. // 'bounding-box',
  16061. 'all'],
  16062. d: 'auto'
  16063. }, {
  16064. n: 'filter',
  16065. ind: true,
  16066. l: true,
  16067. k: ['none'],
  16068. d: 'none',
  16069. syntax: exports.PropertySyntax.FILTER
  16070. }, {
  16071. n: 'clipPath',
  16072. syntax: exports.PropertySyntax.DEFINED_PATH
  16073. }, {
  16074. n: 'textPath',
  16075. syntax: exports.PropertySyntax.DEFINED_PATH
  16076. }, {
  16077. n: 'textPathSide',
  16078. k: ['left', 'right'],
  16079. d: 'left'
  16080. }, {
  16081. n: 'textPathStartOffset',
  16082. l: true,
  16083. d: '0',
  16084. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  16085. }, {
  16086. n: 'transform',
  16087. p: 100,
  16088. int: true,
  16089. k: ['none'],
  16090. d: 'none',
  16091. syntax: exports.PropertySyntax.TRANSFORM
  16092. }, {
  16093. n: 'transformOrigin',
  16094. p: 100,
  16095. // int: true,
  16096. d: function d(nodeName) {
  16097. if (nodeName === exports.Shape.CIRCLE || nodeName === exports.Shape.ELLIPSE) {
  16098. return 'center';
  16099. }
  16100. if (nodeName === exports.Shape.TEXT) {
  16101. return 'text-anchor';
  16102. }
  16103. return 'left top';
  16104. },
  16105. l: true,
  16106. syntax: exports.PropertySyntax.TRANSFORM_ORIGIN
  16107. }, {
  16108. n: 'anchor',
  16109. p: 99,
  16110. d: function d(nodeName) {
  16111. if (nodeName === exports.Shape.CIRCLE || nodeName === exports.Shape.ELLIPSE) {
  16112. return '0.5 0.5';
  16113. }
  16114. return '0 0';
  16115. },
  16116. l: true,
  16117. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE_12
  16118. },
  16119. // <circle> & <ellipse>
  16120. {
  16121. n: 'cx',
  16122. int: true,
  16123. d: '0',
  16124. syntax: exports.PropertySyntax.COORDINATE
  16125. }, {
  16126. n: 'cy',
  16127. int: true,
  16128. d: '0',
  16129. syntax: exports.PropertySyntax.COORDINATE
  16130. }, {
  16131. n: 'cz',
  16132. int: true,
  16133. d: '0',
  16134. syntax: exports.PropertySyntax.COORDINATE
  16135. }, {
  16136. n: 'r',
  16137. int: true,
  16138. l: true,
  16139. d: '0',
  16140. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  16141. }, {
  16142. n: 'rx',
  16143. int: true,
  16144. l: true,
  16145. d: '0',
  16146. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  16147. }, {
  16148. n: 'ry',
  16149. int: true,
  16150. l: true,
  16151. d: '0',
  16152. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  16153. },
  16154. // Rect Image Group
  16155. {
  16156. // x in local space
  16157. n: 'x',
  16158. int: true,
  16159. d: '0',
  16160. syntax: exports.PropertySyntax.COORDINATE
  16161. }, {
  16162. // y in local space
  16163. n: 'y',
  16164. int: true,
  16165. d: '0',
  16166. syntax: exports.PropertySyntax.COORDINATE
  16167. }, {
  16168. // z in local space
  16169. n: 'z',
  16170. int: true,
  16171. d: '0',
  16172. syntax: exports.PropertySyntax.COORDINATE
  16173. }, {
  16174. n: 'width',
  16175. int: true,
  16176. l: true,
  16177. /**
  16178. * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/width
  16179. */
  16180. k: ['auto', 'fit-content', 'min-content', 'max-content'],
  16181. d: '0',
  16182. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  16183. }, {
  16184. n: 'height',
  16185. int: true,
  16186. l: true,
  16187. /**
  16188. * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/height
  16189. */
  16190. k: ['auto', 'fit-content', 'min-content', 'max-content'],
  16191. d: '0',
  16192. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  16193. }, {
  16194. n: 'radius',
  16195. int: true,
  16196. l: true,
  16197. d: '0',
  16198. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE_14
  16199. },
  16200. // Line
  16201. {
  16202. n: 'x1',
  16203. int: true,
  16204. l: true,
  16205. syntax: exports.PropertySyntax.COORDINATE
  16206. }, {
  16207. n: 'y1',
  16208. int: true,
  16209. l: true,
  16210. syntax: exports.PropertySyntax.COORDINATE
  16211. }, {
  16212. n: 'z1',
  16213. int: true,
  16214. l: true,
  16215. syntax: exports.PropertySyntax.COORDINATE
  16216. }, {
  16217. n: 'x2',
  16218. int: true,
  16219. l: true,
  16220. syntax: exports.PropertySyntax.COORDINATE
  16221. }, {
  16222. n: 'y2',
  16223. int: true,
  16224. l: true,
  16225. syntax: exports.PropertySyntax.COORDINATE
  16226. }, {
  16227. n: 'z2',
  16228. int: true,
  16229. l: true,
  16230. syntax: exports.PropertySyntax.COORDINATE
  16231. },
  16232. // Path
  16233. {
  16234. n: 'path',
  16235. int: true,
  16236. l: true,
  16237. d: '',
  16238. a: ['d'],
  16239. syntax: exports.PropertySyntax.PATH,
  16240. p: 50
  16241. },
  16242. // Polyline & Polygon
  16243. {
  16244. n: 'points',
  16245. /**
  16246. * support interpolation
  16247. */
  16248. int: true,
  16249. l: true,
  16250. syntax: exports.PropertySyntax.LIST_OF_POINTS,
  16251. p: 50
  16252. },
  16253. // Text
  16254. {
  16255. n: 'text',
  16256. l: true,
  16257. d: '',
  16258. syntax: exports.PropertySyntax.TEXT,
  16259. p: 50
  16260. }, {
  16261. n: 'textTransform',
  16262. l: true,
  16263. inh: true,
  16264. k: ['capitalize', 'uppercase', 'lowercase', 'none'],
  16265. d: 'none',
  16266. syntax: exports.PropertySyntax.TEXT_TRANSFORM,
  16267. p: 51 // it must get parsed after text
  16268. }, {
  16269. n: 'font',
  16270. l: true
  16271. }, {
  16272. n: 'fontSize',
  16273. int: true,
  16274. inh: true,
  16275. /**
  16276. * @see https://www.w3schools.com/css/css_font_size.asp
  16277. */
  16278. d: '16px',
  16279. l: true,
  16280. syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
  16281. }, {
  16282. n: 'fontFamily',
  16283. l: true,
  16284. inh: true,
  16285. d: 'sans-serif'
  16286. }, {
  16287. n: 'fontStyle',
  16288. l: true,
  16289. inh: true,
  16290. k: ['normal', 'italic', 'oblique'],
  16291. d: 'normal'
  16292. }, {
  16293. n: 'fontWeight',
  16294. l: true,
  16295. inh: true,
  16296. k: ['normal', 'bold', 'bolder', 'lighter'],
  16297. d: 'normal'
  16298. }, {
  16299. n: 'fontVariant',
  16300. l: true,
  16301. inh: true,
  16302. k: ['normal', 'small-caps'],
  16303. d: 'normal'
  16304. }, {
  16305. n: 'lineHeight',
  16306. l: true,
  16307. syntax: exports.PropertySyntax.LENGTH,
  16308. int: true,
  16309. d: '0'
  16310. }, {
  16311. n: 'letterSpacing',
  16312. l: true,
  16313. syntax: exports.PropertySyntax.LENGTH,
  16314. int: true,
  16315. d: '0'
  16316. }, {
  16317. n: 'miterLimit',
  16318. l: true,
  16319. syntax: exports.PropertySyntax.NUMBER,
  16320. d: function d(nodeName) {
  16321. if (nodeName === exports.Shape.PATH || nodeName === exports.Shape.POLYGON || nodeName === exports.Shape.POLYLINE) {
  16322. return '4';
  16323. }
  16324. return '10';
  16325. }
  16326. }, {
  16327. n: 'wordWrap',
  16328. l: true
  16329. }, {
  16330. n: 'wordWrapWidth',
  16331. l: true
  16332. }, {
  16333. n: 'maxLines',
  16334. l: true
  16335. }, {
  16336. n: 'textOverflow',
  16337. l: true,
  16338. d: 'clip'
  16339. }, {
  16340. n: 'leading',
  16341. l: true
  16342. }, {
  16343. n: 'textBaseline',
  16344. l: true,
  16345. inh: true,
  16346. k: ['top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom'],
  16347. d: 'alphabetic'
  16348. }, {
  16349. n: 'textAlign',
  16350. l: true,
  16351. inh: true,
  16352. k: ['start', 'center', 'middle', 'end', 'left', 'right'],
  16353. d: 'start'
  16354. },
  16355. // {
  16356. // n: 'whiteSpace',
  16357. // l: true,
  16358. // },
  16359. {
  16360. n: 'markerStart',
  16361. syntax: exports.PropertySyntax.MARKER
  16362. }, {
  16363. n: 'markerEnd',
  16364. syntax: exports.PropertySyntax.MARKER
  16365. }, {
  16366. n: 'markerMid',
  16367. syntax: exports.PropertySyntax.MARKER
  16368. }, {
  16369. n: 'markerStartOffset',
  16370. syntax: exports.PropertySyntax.LENGTH,
  16371. l: true,
  16372. int: true,
  16373. d: '0'
  16374. }, {
  16375. n: 'markerEndOffset',
  16376. syntax: exports.PropertySyntax.LENGTH,
  16377. l: true,
  16378. int: true,
  16379. d: '0'
  16380. }];
  16381. var GEOMETRY_ATTRIBUTE_NAMES = BUILT_IN_PROPERTIES.filter(function (n) {
  16382. return !!n.l;
  16383. }).map(function (n) {
  16384. return n.n;
  16385. });
  16386. var propertyMetadataCache = {};
  16387. var unresolvedProperties = new WeakMap();
  16388. // const uniqueAttributeSet = new Set<string>();
  16389. // const tmpVec3a = vec3.create();
  16390. // const tmpVec3b = vec3.create();
  16391. // const tmpVec3c = vec3.create();
  16392. var isPropertyResolved = function isPropertyResolved(object, name) {
  16393. var properties = unresolvedProperties.get(object);
  16394. if (!properties || properties.length === 0) {
  16395. return true;
  16396. }
  16397. return properties.includes(name);
  16398. };
  16399. var DefaultStyleValueRegistry = /*#__PURE__*/function () {
  16400. /**
  16401. * need recalc later
  16402. */
  16403. // dirty = false;
  16404. function DefaultStyleValueRegistry() {
  16405. var _this = this;
  16406. BUILT_IN_PROPERTIES.forEach(function (property) {
  16407. _this.registerMetadata(property);
  16408. });
  16409. }
  16410. var _proto = DefaultStyleValueRegistry.prototype;
  16411. _proto.registerMetadata = function registerMetadata(metadata) {
  16412. [metadata.n].concat(metadata.a || []).forEach(function (name) {
  16413. propertyMetadataCache[name] = metadata;
  16414. });
  16415. };
  16416. _proto.unregisterMetadata = function unregisterMetadata(name) {
  16417. delete propertyMetadataCache[name];
  16418. };
  16419. _proto.getPropertySyntax = function getPropertySyntax(syntax) {
  16420. return runtime.CSSPropertySyntaxFactory[syntax];
  16421. }
  16422. /**
  16423. * * parse value, eg.
  16424. * fill: 'red' => CSSRGB
  16425. * translateX: '10px' => CSSUnitValue { unit: 'px', value: 10 }
  16426. * fontSize: '2em' => { unit: 'px', value: 32 }
  16427. *
  16428. * * calculate used value
  16429. * * post process
  16430. */;
  16431. _proto.processProperties = function processProperties(object, attributes, options) {
  16432. var _this2 = this;
  16433. if (options === void 0) {
  16434. options = {
  16435. skipUpdateAttribute: false,
  16436. skipParse: false,
  16437. forceUpdateGeometry: false,
  16438. usedAttributes: []
  16439. };
  16440. }
  16441. if (!runtime.enableCSSParsing) {
  16442. Object.assign(object.attributes, attributes);
  16443. var _attributeNames = Object.keys(attributes);
  16444. // clipPath
  16445. var oldClipPath = object.parsedStyle.clipPath;
  16446. var oldOffsetPath = object.parsedStyle.offsetPath;
  16447. object.parsedStyle = Object.assign(object.parsedStyle, attributes);
  16448. var _needUpdateGeometry = !!options.forceUpdateGeometry;
  16449. if (!_needUpdateGeometry) {
  16450. for (var i = 0; i < GEOMETRY_ATTRIBUTE_NAMES.length; i++) {
  16451. if (GEOMETRY_ATTRIBUTE_NAMES[i] in attributes) {
  16452. _needUpdateGeometry = true;
  16453. break;
  16454. }
  16455. }
  16456. }
  16457. if (attributes.fill) {
  16458. object.parsedStyle.fill = parseColor(attributes.fill);
  16459. }
  16460. if (attributes.stroke) {
  16461. object.parsedStyle.stroke = parseColor(attributes.stroke);
  16462. }
  16463. if (attributes.shadowColor) {
  16464. object.parsedStyle.shadowColor = parseColor(attributes.shadowColor);
  16465. }
  16466. if (attributes.filter) {
  16467. object.parsedStyle.filter = parseFilter(attributes.filter);
  16468. }
  16469. // Rect
  16470. // @ts-ignore
  16471. if (!isNil(attributes.radius)) {
  16472. // @ts-ignore
  16473. object.parsedStyle.radius = parseDimensionArrayFormat(
  16474. // @ts-ignore
  16475. attributes.radius, 4);
  16476. }
  16477. // Polyline
  16478. if (!isNil(attributes.lineDash)) {
  16479. object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 2);
  16480. }
  16481. // @ts-ignore
  16482. if (attributes.points) {
  16483. // @ts-ignore
  16484. object.parsedStyle.points = parsePoints(attributes.points, object);
  16485. }
  16486. // Path
  16487. // @ts-ignore
  16488. if (attributes.path === '') {
  16489. object.parsedStyle.path = _extends({}, EMPTY_PARSED_PATH);
  16490. }
  16491. // @ts-ignore
  16492. if (attributes.path) {
  16493. object.parsedStyle.path = parsePath(
  16494. // @ts-ignore
  16495. attributes.path, object);
  16496. }
  16497. // Text
  16498. if (attributes.textTransform) {
  16499. runtime.CSSPropertySyntaxFactory['<text-transform>'].calculator(null, null, {
  16500. value: attributes.textTransform
  16501. }, object, null);
  16502. }
  16503. if (attributes.clipPath) {
  16504. runtime.CSSPropertySyntaxFactory['<defined-path>'].calculator('clipPath', oldClipPath, attributes.clipPath, object, this);
  16505. }
  16506. if (attributes.offsetPath) {
  16507. runtime.CSSPropertySyntaxFactory['<defined-path>'].calculator('offsetPath', oldOffsetPath, attributes.offsetPath, object, this);
  16508. }
  16509. if (attributes.anchor) {
  16510. object.parsedStyle.anchor = parseDimensionArrayFormat(
  16511. // @ts-ignorex
  16512. attributes.anchor, 2);
  16513. }
  16514. if (attributes.transform) {
  16515. object.parsedStyle.transform = parseTransform(attributes.transform);
  16516. }
  16517. if (attributes.transformOrigin) {
  16518. object.parsedStyle.transformOrigin = parseTransformOrigin(attributes.transformOrigin);
  16519. }
  16520. // Marker
  16521. // @ts-ignore
  16522. if (attributes.markerStart) {
  16523. // @ts-ignore
  16524. object.parsedStyle.markerStart = runtime.CSSPropertySyntaxFactory['<marker>'].calculator(null,
  16525. // @ts-ignore
  16526. attributes.markerStart,
  16527. // @ts-ignore
  16528. attributes.markerStart, null, null);
  16529. }
  16530. // @ts-ignore
  16531. if (attributes.markerEnd) {
  16532. // @ts-ignore
  16533. object.parsedStyle.markerEnd = runtime.CSSPropertySyntaxFactory['<marker>'].calculator(null,
  16534. // @ts-ignore
  16535. attributes.markerEnd,
  16536. // @ts-ignore
  16537. attributes.markerEnd, null, null);
  16538. }
  16539. // @ts-ignore
  16540. if (attributes.markerMid) {
  16541. // @ts-ignore
  16542. object.parsedStyle.markerMid = runtime.CSSPropertySyntaxFactory['<marker>'].calculator('',
  16543. // @ts-ignore
  16544. attributes.markerMid,
  16545. // @ts-ignore
  16546. attributes.markerMid, null, null);
  16547. }
  16548. if (
  16549. // Circle & Ellipse
  16550. (object.nodeName === exports.Shape.CIRCLE || object.nodeName === exports.Shape.ELLIPSE) && (
  16551. // @ts-ignore
  16552. !isNil(attributes.cx) ||
  16553. // @ts-ignore
  16554. !isNil(attributes.cy)) || (object.nodeName === exports.Shape.RECT || object.nodeName === exports.Shape.IMAGE || object.nodeName === exports.Shape.GROUP || object.nodeName === exports.Shape.HTML || object.nodeName === exports.Shape.TEXT || object.nodeName === exports.Shape.MESH) && (
  16555. // @ts-ignore
  16556. !isNil(attributes.x) ||
  16557. // @ts-ignore
  16558. !isNil(attributes.y) ||
  16559. // @ts-ignore
  16560. !isNil(attributes.z)) ||
  16561. // Line
  16562. object.nodeName === exports.Shape.LINE && (
  16563. // @ts-ignore
  16564. !isNil(attributes.x1) ||
  16565. // @ts-ignore
  16566. !isNil(attributes.y1) ||
  16567. // @ts-ignore
  16568. !isNil(attributes.z1) ||
  16569. // @ts-ignore
  16570. !isNil(attributes.x2) ||
  16571. // @ts-ignore
  16572. !isNil(attributes.y2) ||
  16573. // @ts-ignore
  16574. !isNil(attributes.z2))) {
  16575. runtime.CSSPropertySyntaxFactory['<coordinate>'].postProcessor(object, _attributeNames);
  16576. }
  16577. if (!isNil(attributes.zIndex)) {
  16578. runtime.CSSPropertySyntaxFactory['<z-index>'].postProcessor(object, _attributeNames);
  16579. }
  16580. // @ts-ignore
  16581. if (attributes.path) {
  16582. runtime.CSSPropertySyntaxFactory['<path>'].postProcessor(object, _attributeNames);
  16583. }
  16584. // @ts-ignore
  16585. if (attributes.points) {
  16586. runtime.CSSPropertySyntaxFactory['<list-of-points>'].postProcessor(object, _attributeNames);
  16587. }
  16588. if (!isNil(attributes.offsetDistance)) {
  16589. runtime.CSSPropertySyntaxFactory['<offset-distance>'].postProcessor(object, _attributeNames);
  16590. }
  16591. if (attributes.transform) {
  16592. runtime.CSSPropertySyntaxFactory['<transform>'].postProcessor(object, _attributeNames);
  16593. }
  16594. if (_needUpdateGeometry) {
  16595. this.updateGeometry(object);
  16596. }
  16597. return;
  16598. }
  16599. var _options = options,
  16600. skipUpdateAttribute = _options.skipUpdateAttribute,
  16601. skipParse = _options.skipParse,
  16602. forceUpdateGeometry = _options.forceUpdateGeometry,
  16603. usedAttributes = _options.usedAttributes;
  16604. var needUpdateGeometry = forceUpdateGeometry;
  16605. var attributeNames = Object.keys(attributes);
  16606. attributeNames.forEach(function (attributeName) {
  16607. var _propertyMetadataCach;
  16608. if (!skipUpdateAttribute) {
  16609. object.attributes[attributeName] = attributes[attributeName];
  16610. }
  16611. if (!needUpdateGeometry && ((_propertyMetadataCach = propertyMetadataCache[attributeName]) === null || _propertyMetadataCach === void 0 ? void 0 : _propertyMetadataCach.l)) {
  16612. needUpdateGeometry = true;
  16613. }
  16614. });
  16615. if (!skipParse) {
  16616. attributeNames.forEach(function (name) {
  16617. object.computedStyle[name] = _this2.parseProperty(name, object.attributes[name], object);
  16618. });
  16619. }
  16620. // let hasUnresolvedProperties = false;
  16621. // parse according to priority
  16622. // path 50
  16623. // points 50
  16624. // text 50
  16625. // textTransform 51
  16626. // anchor 99
  16627. // transform 100
  16628. // transformOrigin 100
  16629. if (usedAttributes === null || usedAttributes === void 0 ? void 0 : usedAttributes.length) {
  16630. // uniqueAttributeSet.clear();
  16631. attributeNames = Array.from(new Set(attributeNames.concat(usedAttributes)));
  16632. }
  16633. // [
  16634. // 'path',
  16635. // 'points',
  16636. // 'text',
  16637. // 'textTransform',
  16638. // 'anchor',
  16639. // 'transform',
  16640. // 'transformOrigin',
  16641. // ].forEach((name) => {
  16642. // const index = attributeNames.indexOf(name);
  16643. // if (index > -1) {
  16644. // attributeNames.splice(index, 1);
  16645. // attributeNames.push(name);
  16646. // }
  16647. // });
  16648. attributeNames.forEach(function (name) {
  16649. // some style props maybe deleted after parsing such as `anchor` in Text
  16650. if (name in object.computedStyle) {
  16651. object.parsedStyle[name] = _this2.computeProperty(name, object.computedStyle[name], object);
  16652. }
  16653. });
  16654. // if (hasUnresolvedProperties) {
  16655. // this.dirty = true;
  16656. // return;
  16657. // }
  16658. // update geometry
  16659. if (needUpdateGeometry) {
  16660. // object.geometry.dirty = true;
  16661. // runtime.sceneGraphService.dirtifyToRoot(object);
  16662. this.updateGeometry(object);
  16663. }
  16664. attributeNames.forEach(function (name) {
  16665. if (name in object.parsedStyle) {
  16666. _this2.postProcessProperty(name, object, attributeNames);
  16667. }
  16668. });
  16669. if (runtime.enableCSSParsing && object.children.length) {
  16670. attributeNames.forEach(function (name) {
  16671. if (name in object.parsedStyle && _this2.isPropertyInheritable(name)) {
  16672. // update children's inheritable
  16673. object.children.forEach(function (child) {
  16674. child.internalSetAttribute(name, null, {
  16675. skipUpdateAttribute: true,
  16676. skipParse: true
  16677. });
  16678. });
  16679. }
  16680. });
  16681. }
  16682. }
  16683. /**
  16684. * string -> parsed value
  16685. */;
  16686. _proto.parseProperty = function parseProperty(name, value, object) {
  16687. var metadata = propertyMetadataCache[name];
  16688. var computed = value;
  16689. if (value === '' || isNil(value)) {
  16690. value = 'unset';
  16691. }
  16692. if (value === 'unset' || value === 'initial' || value === 'inherit') {
  16693. // computed = new CSSKeywordValue(value);
  16694. computed = getOrCreateKeyword(value);
  16695. } else {
  16696. if (metadata) {
  16697. var keywords = metadata.k,
  16698. syntax = metadata.syntax;
  16699. var handler = syntax && this.getPropertySyntax(syntax);
  16700. // use keywords
  16701. if (keywords && keywords.indexOf(value) > -1) {
  16702. // computed = new CSSKeywordValue(value);
  16703. computed = getOrCreateKeyword(value);
  16704. } else if (handler && handler.parser) {
  16705. // try to parse it to CSSStyleValue, eg. '10px' -> CSS.px(10)
  16706. computed = handler.parser(value, object);
  16707. }
  16708. }
  16709. }
  16710. return computed;
  16711. }
  16712. /**
  16713. * computed value -> used value
  16714. */;
  16715. _proto.computeProperty = function computeProperty(name, computed, object) {
  16716. var metadata = propertyMetadataCache[name];
  16717. var isDocumentElement = object.id === 'g-root';
  16718. // let used: CSSStyleValue = computed instanceof CSSStyleValue ? computed.clone() : computed;
  16719. var used = computed;
  16720. if (metadata) {
  16721. var syntax = metadata.syntax,
  16722. inherited = metadata.inh,
  16723. defaultValue = metadata.d;
  16724. if (computed instanceof CSSKeywordValue) {
  16725. var value = computed.value;
  16726. /**
  16727. * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/unset
  16728. */
  16729. if (value === 'unset') {
  16730. if (inherited && !isDocumentElement) {
  16731. value = 'inherit';
  16732. } else {
  16733. value = 'initial';
  16734. }
  16735. }
  16736. if (value === 'initial') {
  16737. // @see https://developer.mozilla.org/en-US/docs/Web/CSS/initial
  16738. if (!isNil(defaultValue)) {
  16739. computed = this.parseProperty(name, isFunction(defaultValue) ? defaultValue(object.nodeName) : defaultValue, object);
  16740. }
  16741. } else if (value === 'inherit') {
  16742. // @see https://developer.mozilla.org/en-US/docs/Web/CSS/inherit
  16743. // behave like `inherit`
  16744. var resolved = this.tryToResolveProperty(object, name, {
  16745. inherited: true
  16746. });
  16747. if (!isNil(resolved)) {
  16748. // object.parsedStyle[name] = resolved;
  16749. // return false;
  16750. return resolved;
  16751. } else {
  16752. this.addUnresolveProperty(object, name);
  16753. return;
  16754. }
  16755. }
  16756. }
  16757. var handler = syntax && this.getPropertySyntax(syntax);
  16758. if (handler && handler.calculator) {
  16759. // convert computed value to used value
  16760. var oldParsedValue = object.parsedStyle[name];
  16761. used = handler.calculator(name, oldParsedValue, computed, object, this);
  16762. } else if (computed instanceof CSSKeywordValue) {
  16763. used = computed.value;
  16764. } else {
  16765. used = computed;
  16766. }
  16767. }
  16768. // object.parsedStyle[name] = used;
  16769. // return false;
  16770. return used;
  16771. };
  16772. _proto.postProcessProperty = function postProcessProperty(name, object, attributes) {
  16773. var metadata = propertyMetadataCache[name];
  16774. if (metadata && metadata.syntax) {
  16775. var handler = metadata.syntax && this.getPropertySyntax(metadata.syntax);
  16776. var propertyHandler = handler;
  16777. if (propertyHandler && propertyHandler.postProcessor) {
  16778. propertyHandler.postProcessor(object, attributes);
  16779. }
  16780. }
  16781. }
  16782. /**
  16783. * resolve later
  16784. */;
  16785. _proto.addUnresolveProperty = function addUnresolveProperty(object, name) {
  16786. var properties = unresolvedProperties.get(object);
  16787. if (!properties) {
  16788. unresolvedProperties.set(object, []);
  16789. properties = unresolvedProperties.get(object);
  16790. }
  16791. if (properties.indexOf(name) === -1) {
  16792. properties.push(name);
  16793. }
  16794. };
  16795. _proto.tryToResolveProperty = function tryToResolveProperty(object, name, options) {
  16796. if (options === void 0) {
  16797. options = {};
  16798. }
  16799. var _options2 = options,
  16800. inherited = _options2.inherited;
  16801. if (inherited) {
  16802. if (object.parentElement && isPropertyResolved(object.parentElement, name)) {
  16803. // const computedValue = object.parentElement.computedStyle[name];
  16804. var usedValue = object.parentElement.parsedStyle[name];
  16805. if (
  16806. // usedValue instanceof CSSKeywordValue &&
  16807. usedValue === 'unset' || usedValue === 'initial' || usedValue === 'inherit') {
  16808. return;
  16809. }
  16810. // else if (
  16811. // usedValue instanceof CSSUnitValue &&
  16812. // CSSUnitValue.isRelativeUnit(usedValue.unit)
  16813. // ) {
  16814. // return false;
  16815. // }
  16816. return usedValue;
  16817. }
  16818. }
  16819. return;
  16820. };
  16821. _proto.recalc = function recalc(object) {
  16822. var properties = unresolvedProperties.get(object);
  16823. if (properties && properties.length) {
  16824. var attributes = {};
  16825. properties.forEach(function (property) {
  16826. attributes[property] = object.attributes[property];
  16827. });
  16828. this.processProperties(object, attributes);
  16829. unresolvedProperties.delete(object);
  16830. }
  16831. }
  16832. /**
  16833. * update geometry when relative props changed,
  16834. * eg. r of Circle, width/height of Rect
  16835. */;
  16836. _proto.updateGeometry = function updateGeometry(object) {
  16837. var nodeName = object.nodeName;
  16838. var geometryUpdater = runtime.geometryUpdaterFactory[nodeName];
  16839. if (geometryUpdater) {
  16840. var geometry = object.geometry;
  16841. if (!geometry.contentBounds) {
  16842. geometry.contentBounds = new AABB();
  16843. }
  16844. if (!geometry.renderBounds) {
  16845. geometry.renderBounds = new AABB();
  16846. }
  16847. var parsedStyle = object.parsedStyle;
  16848. var _geometryUpdater$upda = geometryUpdater.update(parsedStyle, object),
  16849. width = _geometryUpdater$upda.width,
  16850. height = _geometryUpdater$upda.height,
  16851. _geometryUpdater$upda2 = _geometryUpdater$upda.depth,
  16852. depth = _geometryUpdater$upda2 === void 0 ? 0 : _geometryUpdater$upda2,
  16853. _geometryUpdater$upda3 = _geometryUpdater$upda.offsetX,
  16854. offsetX = _geometryUpdater$upda3 === void 0 ? 0 : _geometryUpdater$upda3,
  16855. _geometryUpdater$upda4 = _geometryUpdater$upda.offsetY,
  16856. offsetY = _geometryUpdater$upda4 === void 0 ? 0 : _geometryUpdater$upda4,
  16857. _geometryUpdater$upda5 = _geometryUpdater$upda.offsetZ,
  16858. offsetZ = _geometryUpdater$upda5 === void 0 ? 0 : _geometryUpdater$upda5;
  16859. // init with content box
  16860. var halfExtents = [Math.abs(width) / 2, Math.abs(height) / 2, depth / 2];
  16861. // const halfExtents = vec3.set(
  16862. // tmpVec3a,
  16863. // Math.abs(width) / 2,
  16864. // Math.abs(height) / 2,
  16865. // depth / 2,
  16866. // );
  16867. // anchor is center by default, don't account for lineWidth here
  16868. var stroke = parsedStyle.stroke,
  16869. lineWidth = parsedStyle.lineWidth,
  16870. increasedLineWidthForHitTesting = parsedStyle.increasedLineWidthForHitTesting,
  16871. shadowType = parsedStyle.shadowType,
  16872. shadowColor = parsedStyle.shadowColor,
  16873. _parsedStyle$filter = parsedStyle.filter,
  16874. filter = _parsedStyle$filter === void 0 ? [] : _parsedStyle$filter,
  16875. transformOrigin = parsedStyle.transformOrigin;
  16876. var anchor = parsedStyle.anchor;
  16877. // <Text> use textAlign & textBaseline instead of anchor
  16878. if (nodeName === exports.Shape.TEXT) {
  16879. delete parsedStyle.anchor;
  16880. } else if (nodeName === exports.Shape.MESH) {
  16881. parsedStyle.anchor[2] = 0.5;
  16882. }
  16883. var center = [(1 - (anchor && anchor[0] || 0) * 2) * width / 2 + offsetX, (1 - (anchor && anchor[1] || 0) * 2) * height / 2 + offsetY, (1 - (anchor && anchor[2] || 0) * 2) * halfExtents[2] + offsetZ];
  16884. // const center = vec3.set(
  16885. // tmpVec3b,
  16886. // ((1 - ((anchor && anchor[0]) || 0) * 2) * width) / 2 + offsetX,
  16887. // ((1 - ((anchor && anchor[1]) || 0) * 2) * height) / 2 + offsetY,
  16888. // (1 - ((anchor && anchor[2]) || 0) * 2) * halfExtents[2] + offsetZ,
  16889. // );
  16890. // update geometry's AABB
  16891. geometry.contentBounds.update(center, halfExtents);
  16892. // @see https://github.molgen.mpg.de/git-mirror/cairo/blob/master/src/cairo-stroke-style.c#L97..L128
  16893. var expansion = nodeName === exports.Shape.POLYLINE || nodeName === exports.Shape.POLYGON || nodeName === exports.Shape.PATH ? Math.SQRT2 : 0.5;
  16894. // if (lineCap?.value === 'square') {
  16895. // expansion = Math.SQRT1_2;
  16896. // }
  16897. // if (lineJoin?.value === 'miter' && expansion < Math.SQRT2 * miterLimit) {
  16898. // expansion = Math.SQRT1_2 * miterLimit;
  16899. // }
  16900. // append border only if stroke existed
  16901. var hasStroke = stroke && !stroke.isNone;
  16902. if (hasStroke) {
  16903. var halfLineWidth = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) * expansion;
  16904. // halfExtents[0] += halfLineWidth[0];
  16905. // halfExtents[1] += halfLineWidth[1];
  16906. halfExtents[0] += halfLineWidth;
  16907. halfExtents[1] += halfLineWidth;
  16908. // vec3.add(
  16909. // halfExtents,
  16910. // halfExtents,
  16911. // vec3.set(tmpVec3c, halfLineWidth, halfLineWidth, 0),
  16912. // );
  16913. }
  16914. geometry.renderBounds.update(center, halfExtents);
  16915. // account for shadow, only support constant value now
  16916. if (shadowColor && shadowType && shadowType !== 'inner') {
  16917. var _geometry$renderBound = geometry.renderBounds,
  16918. min = _geometry$renderBound.min,
  16919. max = _geometry$renderBound.max;
  16920. var shadowBlur = parsedStyle.shadowBlur,
  16921. shadowOffsetX = parsedStyle.shadowOffsetX,
  16922. shadowOffsetY = parsedStyle.shadowOffsetY;
  16923. var shadowBlurInPixels = shadowBlur || 0;
  16924. var shadowOffsetXInPixels = shadowOffsetX || 0;
  16925. var shadowOffsetYInPixels = shadowOffsetY || 0;
  16926. var shadowLeft = min[0] - shadowBlurInPixels + shadowOffsetXInPixels;
  16927. var shadowRight = max[0] + shadowBlurInPixels + shadowOffsetXInPixels;
  16928. var shadowTop = min[1] - shadowBlurInPixels + shadowOffsetYInPixels;
  16929. var shadowBottom = max[1] + shadowBlurInPixels + shadowOffsetYInPixels;
  16930. min[0] = Math.min(min[0], shadowLeft);
  16931. max[0] = Math.max(max[0], shadowRight);
  16932. min[1] = Math.min(min[1], shadowTop);
  16933. max[1] = Math.max(max[1], shadowBottom);
  16934. geometry.renderBounds.setMinMax(min, max);
  16935. }
  16936. // account for filter, eg. blur(5px), drop-shadow()
  16937. filter.forEach(function (_ref) {
  16938. var name = _ref.name,
  16939. params = _ref.params;
  16940. if (name === 'blur') {
  16941. var blurRadius = params[0].value;
  16942. geometry.renderBounds.update(geometry.renderBounds.center, addVec3(geometry.renderBounds.halfExtents, geometry.renderBounds.halfExtents, [blurRadius, blurRadius, 0]));
  16943. } else if (name === 'drop-shadow') {
  16944. var _shadowOffsetX = params[0].value;
  16945. var _shadowOffsetY = params[1].value;
  16946. var _shadowBlur = params[2].value;
  16947. var _geometry$renderBound2 = geometry.renderBounds,
  16948. _min = _geometry$renderBound2.min,
  16949. _max = _geometry$renderBound2.max;
  16950. var _shadowLeft = _min[0] - _shadowBlur + _shadowOffsetX;
  16951. var _shadowRight = _max[0] + _shadowBlur + _shadowOffsetX;
  16952. var _shadowTop = _min[1] - _shadowBlur + _shadowOffsetY;
  16953. var _shadowBottom = _max[1] + _shadowBlur + _shadowOffsetY;
  16954. _min[0] = Math.min(_min[0], _shadowLeft);
  16955. _max[0] = Math.max(_max[0], _shadowRight);
  16956. _min[1] = Math.min(_min[1], _shadowTop);
  16957. _max[1] = Math.max(_max[1], _shadowBottom);
  16958. geometry.renderBounds.setMinMax(_min, _max);
  16959. }
  16960. });
  16961. anchor = parsedStyle.anchor;
  16962. // if (nodeName === Shape.RECT) {
  16963. // account for negative width / height of Rect
  16964. // @see https://github.com/antvis/g/issues/957
  16965. var flipY = width < 0;
  16966. var flipX = height < 0;
  16967. // } else {
  16968. // }
  16969. // set transform origin
  16970. var usedOriginXValue = (flipY ? -1 : 1) * (transformOrigin ? convertPercentUnit(transformOrigin[0], 0, object) : 0);
  16971. var usedOriginYValue = (flipX ? -1 : 1) * (transformOrigin ? convertPercentUnit(transformOrigin[1], 1, object) : 0);
  16972. usedOriginXValue = usedOriginXValue - (flipY ? -1 : 1) * (anchor && anchor[0] || 0) * geometry.contentBounds.halfExtents[0] * 2;
  16973. usedOriginYValue = usedOriginYValue - (flipX ? -1 : 1) * (anchor && anchor[1] || 0) * geometry.contentBounds.halfExtents[1] * 2;
  16974. object.setOrigin(usedOriginXValue, usedOriginYValue);
  16975. // FIXME setOrigin may have already dirtified to root.
  16976. runtime.sceneGraphService.dirtifyToRoot(object);
  16977. }
  16978. };
  16979. _proto.isPropertyInheritable = function isPropertyInheritable(name) {
  16980. var metadata = propertyMetadataCache[name];
  16981. if (!metadata) {
  16982. return false;
  16983. }
  16984. return metadata.inh;
  16985. };
  16986. return DefaultStyleValueRegistry;
  16987. }();
  16988. /**
  16989. * Different type of cameras, eg. simple camera used in 2D scene or
  16990. * advanced camera which can do actions & switch between landmarks.
  16991. */
  16992. (function (CameraType) {
  16993. /**
  16994. * Performs all the rotational operations with the focal point instead of the camera position.
  16995. * This type of camera is useful in applications(like CAD) where 3D objects are being designed or explored.
  16996. * Camera cannot orbits over the north & south poles.
  16997. * @see http://voxelent.com/tutorial-cameras/
  16998. *
  16999. * In Three.js it's used in OrbitControls.
  17000. * @see https://threejs.org/docs/#examples/zh/controls/OrbitControls
  17001. */
  17002. CameraType[CameraType["ORBITING"] = 0] = "ORBITING";
  17003. /**
  17004. * It's similar to the ORBITING camera, but it allows the camera to orbit over the north or south poles.
  17005. *
  17006. * In Three.js it's used in OrbitControls.
  17007. * @see https://threejs.org/docs/#examples/en/controls/TrackballControls
  17008. */
  17009. CameraType[CameraType["EXPLORING"] = 1] = "EXPLORING";
  17010. /**
  17011. * Performs all the rotational operations with the camera position.
  17012. * It's useful in first person shooting games.
  17013. * Camera cannot orbits over the north & south poles.
  17014. *
  17015. * In Three.js it's used in FirstPersonControls.
  17016. * @see https://threejs.org/docs/#examples/en/controls/FirstPersonControls
  17017. */
  17018. CameraType[CameraType["TRACKING"] = 2] = "TRACKING";
  17019. })(exports.CameraType || (exports.CameraType = {}));
  17020. (function (CameraTrackingMode) {
  17021. CameraTrackingMode[CameraTrackingMode["DEFAULT"] = 0] = "DEFAULT";
  17022. CameraTrackingMode[CameraTrackingMode["ROTATIONAL"] = 1] = "ROTATIONAL";
  17023. CameraTrackingMode[CameraTrackingMode["TRANSLATIONAL"] = 2] = "TRANSLATIONAL";
  17024. CameraTrackingMode[CameraTrackingMode["CINEMATIC"] = 3] = "CINEMATIC";
  17025. })(exports.CameraTrackingMode || (exports.CameraTrackingMode = {}));
  17026. (function (CameraProjectionMode) {
  17027. CameraProjectionMode[CameraProjectionMode["ORTHOGRAPHIC"] = 0] = "ORTHOGRAPHIC";
  17028. CameraProjectionMode[CameraProjectionMode["PERSPECTIVE"] = 1] = "PERSPECTIVE";
  17029. })(exports.CameraProjectionMode || (exports.CameraProjectionMode = {}));
  17030. var CameraEvent = {
  17031. UPDATED: 'updated'
  17032. };
  17033. var MIN_DISTANCE = 0.0002;
  17034. /**
  17035. * 参考「WebGL Insights - 23.Designing Cameras for WebGL Applications」,基于 Responsible Camera 思路设计
  17036. * @see https://github.com/d13g0/nucleo.js/blob/master/source/camera/Camera.js
  17037. *
  17038. * 保存相机参数,定义相机动作:
  17039. * 1. dolly 沿 n 轴移动
  17040. * 2. pan 沿 u v 轴移动
  17041. * 3. rotate 以方位角旋转
  17042. * 4. 移动到 Landmark,具有平滑的动画效果,其间禁止其他用户交互
  17043. */
  17044. var Camera = /*#__PURE__*/function () {
  17045. function Camera() {
  17046. this.canvas = void 0;
  17047. this.eventEmitter = new eventemitter3();
  17048. /**
  17049. * 相机矩阵
  17050. */
  17051. this.matrix = create$1();
  17052. /**
  17053. * u 轴
  17054. * @see http://learnwebgl.brown37.net/07_cameras/camera_introduction.html#a-camera-definition
  17055. */
  17056. this.right = fromValues$2(1, 0, 0);
  17057. /**
  17058. * v 轴 +Y is down
  17059. */
  17060. this.up = fromValues$2(0, 1, 0);
  17061. /**
  17062. * n 轴 +Z is inside
  17063. */
  17064. this.forward = fromValues$2(0, 0, 1);
  17065. /**
  17066. * 相机位置
  17067. */
  17068. this.position = fromValues$2(0, 0, 1);
  17069. /**
  17070. * 视点位置
  17071. */
  17072. this.focalPoint = fromValues$2(0, 0, 0);
  17073. /**
  17074. * 视点到相机位置的向量
  17075. * focalPoint - position
  17076. */
  17077. this.distanceVector = fromValues$2(0, 0, -1);
  17078. /**
  17079. * 相机位置到视点距离
  17080. * length(focalPoint - position)
  17081. */
  17082. this.distance = 1;
  17083. /**
  17084. * @see https://en.wikipedia.org/wiki/Azimuth
  17085. */
  17086. this.azimuth = 0;
  17087. this.elevation = 0;
  17088. this.roll = 0;
  17089. this.relAzimuth = 0;
  17090. this.relElevation = 0;
  17091. this.relRoll = 0;
  17092. /**
  17093. * 沿 n 轴移动时,保证移动速度从快到慢
  17094. */
  17095. this.dollyingStep = 0;
  17096. this.maxDistance = Infinity;
  17097. this.minDistance = -Infinity;
  17098. /**
  17099. * zoom factor of the camera, default is 1
  17100. * eg. https://threejs.org/docs/#api/en/cameras/OrthographicCamera.zoom
  17101. */
  17102. this.zoom = 1;
  17103. /**
  17104. * invert the horizontal coordinate system HCS
  17105. */
  17106. this.rotateWorld = false;
  17107. /**
  17108. * 投影矩阵参数
  17109. */
  17110. /**
  17111. * field of view [0-360]
  17112. * @see http://en.wikipedia.org/wiki/Angle_of_view
  17113. */
  17114. this.fov = 30;
  17115. this.near = 0.1;
  17116. this.far = 1000;
  17117. this.aspect = 1;
  17118. this.left = void 0;
  17119. this.rright = void 0;
  17120. this.top = void 0;
  17121. this.bottom = void 0;
  17122. this.projectionMatrix = create$1();
  17123. this.projectionMatrixInverse = create$1();
  17124. this.jitteredProjectionMatrix = undefined;
  17125. this.view = void 0;
  17126. this.enableUpdate = true;
  17127. // protected following = undefined;
  17128. this.type = exports.CameraType.EXPLORING;
  17129. this.trackingMode = exports.CameraTrackingMode.DEFAULT;
  17130. this.projectionMode = exports.CameraProjectionMode.PERSPECTIVE;
  17131. /**
  17132. * for culling use
  17133. */
  17134. this.frustum = new Frustum();
  17135. /**
  17136. * ortho matrix for Canvas2D & SVG
  17137. */
  17138. this.orthoMatrix = create$1();
  17139. }
  17140. var _proto = Camera.prototype;
  17141. // constructor(type = CameraType.EXPLORING, trackingMode = CameraTrackingMode.DEFAULT) {
  17142. // this.setType(type, trackingMode);
  17143. // }
  17144. _proto.isOrtho = function isOrtho() {
  17145. return this.projectionMode === exports.CameraProjectionMode.ORTHOGRAPHIC;
  17146. };
  17147. _proto.getProjectionMode = function getProjectionMode() {
  17148. return this.projectionMode;
  17149. };
  17150. _proto.getPerspective = function getPerspective() {
  17151. // account for TAA
  17152. return this.jitteredProjectionMatrix || this.projectionMatrix;
  17153. };
  17154. _proto.getPerspectiveInverse = function getPerspectiveInverse() {
  17155. return this.projectionMatrixInverse;
  17156. };
  17157. _proto.getFrustum = function getFrustum() {
  17158. return this.frustum;
  17159. };
  17160. _proto.getPosition = function getPosition() {
  17161. return this.position;
  17162. };
  17163. _proto.getFocalPoint = function getFocalPoint() {
  17164. return this.focalPoint;
  17165. };
  17166. _proto.getDollyingStep = function getDollyingStep() {
  17167. return this.dollyingStep;
  17168. };
  17169. _proto.getNear = function getNear() {
  17170. return this.near;
  17171. };
  17172. _proto.getFar = function getFar() {
  17173. return this.far;
  17174. };
  17175. _proto.getZoom = function getZoom() {
  17176. return this.zoom;
  17177. };
  17178. _proto.getOrthoMatrix = function getOrthoMatrix() {
  17179. return this.orthoMatrix;
  17180. };
  17181. _proto.getView = function getView() {
  17182. return this.view;
  17183. };
  17184. _proto.setEnableUpdate = function setEnableUpdate(enabled) {
  17185. this.enableUpdate = enabled;
  17186. };
  17187. _proto.setType = function setType(type, trackingMode) {
  17188. this.type = type;
  17189. if (this.type === exports.CameraType.EXPLORING) {
  17190. this.setWorldRotation(true);
  17191. } else {
  17192. this.setWorldRotation(false);
  17193. }
  17194. this._getAngles();
  17195. if (this.type === exports.CameraType.TRACKING && trackingMode !== undefined) {
  17196. this.setTrackingMode(trackingMode);
  17197. }
  17198. return this;
  17199. };
  17200. _proto.setProjectionMode = function setProjectionMode(projectionMode) {
  17201. this.projectionMode = projectionMode;
  17202. return this;
  17203. };
  17204. _proto.setTrackingMode = function setTrackingMode(trackingMode) {
  17205. if (this.type !== exports.CameraType.TRACKING) {
  17206. throw new Error('Impossible to set a tracking mode if the camera is not of tracking type');
  17207. }
  17208. this.trackingMode = trackingMode;
  17209. return this;
  17210. }
  17211. /**
  17212. * If flag is true, it reverses the azimuth and elevation angles.
  17213. * Subsequent calls to rotate, setAzimuth, setElevation,
  17214. * changeAzimuth or changeElevation will cause the inverted effect.
  17215. * setRoll or changeRoll is not affected by this method.
  17216. *
  17217. * This inversion is useful when one wants to simulate that the world
  17218. * is moving, instead of the camera.
  17219. *
  17220. * By default the camera angles are not reversed.
  17221. * @param {Boolean} flag the boolean flag to reverse the angles.
  17222. */;
  17223. _proto.setWorldRotation = function setWorldRotation(flag) {
  17224. this.rotateWorld = flag;
  17225. this._getAngles();
  17226. return this;
  17227. }
  17228. /**
  17229. * 计算 MV 矩阵,为相机矩阵的逆矩阵
  17230. */;
  17231. _proto.getViewTransform = function getViewTransform() {
  17232. return invert(create$1(), this.matrix);
  17233. };
  17234. _proto.getWorldTransform = function getWorldTransform() {
  17235. return this.matrix;
  17236. };
  17237. _proto.jitterProjectionMatrix = function jitterProjectionMatrix(x, y) {
  17238. var translation = fromTranslation(create$1(), [x, y, 0]);
  17239. this.jitteredProjectionMatrix = multiply(create$1(), translation, this.projectionMatrix);
  17240. };
  17241. _proto.clearJitterProjectionMatrix = function clearJitterProjectionMatrix() {
  17242. this.jitteredProjectionMatrix = undefined;
  17243. }
  17244. /**
  17245. * 设置相机矩阵
  17246. */;
  17247. _proto.setMatrix = function setMatrix(matrix) {
  17248. this.matrix = matrix;
  17249. this._update();
  17250. return this;
  17251. };
  17252. _proto.setFov = function setFov(fov) {
  17253. this.setPerspective(this.near, this.far, fov, this.aspect);
  17254. return this;
  17255. };
  17256. _proto.setAspect = function setAspect(aspect) {
  17257. this.setPerspective(this.near, this.far, this.fov, aspect);
  17258. return this;
  17259. };
  17260. _proto.setNear = function setNear(near) {
  17261. if (this.projectionMode === exports.CameraProjectionMode.PERSPECTIVE) {
  17262. this.setPerspective(near, this.far, this.fov, this.aspect);
  17263. } else {
  17264. this.setOrthographic(this.left, this.rright, this.top, this.bottom, near, this.far);
  17265. }
  17266. return this;
  17267. };
  17268. _proto.setFar = function setFar(far) {
  17269. if (this.projectionMode === exports.CameraProjectionMode.PERSPECTIVE) {
  17270. this.setPerspective(this.near, far, this.fov, this.aspect);
  17271. } else {
  17272. this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, far);
  17273. }
  17274. return this;
  17275. }
  17276. /**
  17277. * Sets an offset in a larger frustum, used in PixelPicking
  17278. */;
  17279. _proto.setViewOffset = function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  17280. this.aspect = fullWidth / fullHeight;
  17281. if (this.view === undefined) {
  17282. this.view = {
  17283. enabled: true,
  17284. fullWidth: 1,
  17285. fullHeight: 1,
  17286. offsetX: 0,
  17287. offsetY: 0,
  17288. width: 1,
  17289. height: 1
  17290. };
  17291. }
  17292. this.view.enabled = true;
  17293. this.view.fullWidth = fullWidth;
  17294. this.view.fullHeight = fullHeight;
  17295. this.view.offsetX = x;
  17296. this.view.offsetY = y;
  17297. this.view.width = width;
  17298. this.view.height = height;
  17299. if (this.projectionMode === exports.CameraProjectionMode.PERSPECTIVE) {
  17300. this.setPerspective(this.near, this.far, this.fov, this.aspect);
  17301. } else {
  17302. this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
  17303. }
  17304. return this;
  17305. };
  17306. _proto.clearViewOffset = function clearViewOffset() {
  17307. if (this.view !== undefined) {
  17308. this.view.enabled = false;
  17309. }
  17310. if (this.projectionMode === exports.CameraProjectionMode.PERSPECTIVE) {
  17311. this.setPerspective(this.near, this.far, this.fov, this.aspect);
  17312. } else {
  17313. this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
  17314. }
  17315. return this;
  17316. };
  17317. _proto.setZoom = function setZoom(zoom) {
  17318. this.zoom = zoom;
  17319. if (this.projectionMode === exports.CameraProjectionMode.ORTHOGRAPHIC) {
  17320. this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
  17321. } else if (this.projectionMode === exports.CameraProjectionMode.PERSPECTIVE) {
  17322. this.setPerspective(this.near, this.far, this.fov, this.aspect);
  17323. }
  17324. return this;
  17325. }
  17326. /**
  17327. * Zoom by specified point in viewport coordinates.
  17328. */;
  17329. _proto.setZoomByViewportPoint = function setZoomByViewportPoint(zoom, viewportPoint) {
  17330. var _this$canvas$viewport = this.canvas.viewport2Canvas({
  17331. x: viewportPoint[0],
  17332. y: viewportPoint[1]
  17333. }),
  17334. ox = _this$canvas$viewport.x,
  17335. oy = _this$canvas$viewport.y;
  17336. var roll = this.roll;
  17337. this.rotate(0, 0, -roll);
  17338. this.setPosition(ox, oy);
  17339. this.setFocalPoint(ox, oy);
  17340. this.setZoom(zoom);
  17341. this.rotate(0, 0, roll);
  17342. var _this$canvas$viewport2 = this.canvas.viewport2Canvas({
  17343. x: viewportPoint[0],
  17344. y: viewportPoint[1]
  17345. }),
  17346. cx = _this$canvas$viewport2.x,
  17347. cy = _this$canvas$viewport2.y;
  17348. // project to rotated axis
  17349. var dvec = fromValues$2(cx - ox, cy - oy, 0);
  17350. var dx = dot(dvec, this.right) / length(this.right);
  17351. var dy = dot(dvec, this.up) / length(this.up);
  17352. this.pan(-dx, -dy);
  17353. return this;
  17354. };
  17355. _proto.setPerspective = function setPerspective(near, far, fov, aspect) {
  17356. var _this$view;
  17357. this.projectionMode = exports.CameraProjectionMode.PERSPECTIVE;
  17358. this.fov = fov;
  17359. this.near = near;
  17360. this.far = far;
  17361. this.aspect = aspect;
  17362. var top = this.near * Math.tan(deg2rad(0.5 * this.fov)) / this.zoom;
  17363. var height = 2 * top;
  17364. var width = this.aspect * height;
  17365. var left = -0.5 * width;
  17366. if ((_this$view = this.view) === null || _this$view === void 0 ? void 0 : _this$view.enabled) {
  17367. var fullWidth = this.view.fullWidth;
  17368. var fullHeight = this.view.fullHeight;
  17369. left += this.view.offsetX * width / fullWidth;
  17370. top -= this.view.offsetY * height / fullHeight;
  17371. width *= this.view.width / fullWidth;
  17372. height *= this.view.height / fullHeight;
  17373. }
  17374. makePerspective(this.projectionMatrix, left, left + width, top, top - height, near, this.far);
  17375. // flipY since the origin of OpenGL/WebGL is bottom-left compared with top-left in Canvas2D
  17376. scale(this.projectionMatrix, this.projectionMatrix, fromValues$2(1, -1, 1));
  17377. invert(this.projectionMatrixInverse, this.projectionMatrix);
  17378. this.triggerUpdate();
  17379. return this;
  17380. };
  17381. _proto.setOrthographic = function setOrthographic(l, r, t, b, near, far) {
  17382. var _this$view2;
  17383. this.projectionMode = exports.CameraProjectionMode.ORTHOGRAPHIC;
  17384. this.rright = r;
  17385. this.left = l;
  17386. this.top = t;
  17387. this.bottom = b;
  17388. this.near = near;
  17389. this.far = far;
  17390. var dx = (this.rright - this.left) / (2 * this.zoom);
  17391. var dy = (this.top - this.bottom) / (2 * this.zoom);
  17392. var cx = (this.rright + this.left) / 2;
  17393. var cy = (this.top + this.bottom) / 2;
  17394. var left = cx - dx;
  17395. var right = cx + dx;
  17396. var top = cy + dy;
  17397. var bottom = cy - dy;
  17398. if ((_this$view2 = this.view) === null || _this$view2 === void 0 ? void 0 : _this$view2.enabled) {
  17399. var scaleW = (this.rright - this.left) / this.view.fullWidth / this.zoom;
  17400. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  17401. left += scaleW * this.view.offsetX;
  17402. right = left + scaleW * this.view.width;
  17403. top -= scaleH * this.view.offsetY;
  17404. bottom = top - scaleH * this.view.height;
  17405. }
  17406. ortho(this.projectionMatrix, left, right, bottom, top, near, far);
  17407. // flipY since the origin of OpenGL/WebGL is bottom-left compared with top-left in Canvas2D
  17408. scale(this.projectionMatrix, this.projectionMatrix, fromValues$2(1, -1, 1));
  17409. invert(this.projectionMatrixInverse, this.projectionMatrix);
  17410. this._getOrthoMatrix();
  17411. this.triggerUpdate();
  17412. return this;
  17413. }
  17414. /**
  17415. * Move the camera in world coordinates.
  17416. * It will keep looking at the current focal point.
  17417. *
  17418. * support scalars or vectors.
  17419. * @example
  17420. * setPosition(1, 2, 3);
  17421. * setPosition([1, 2, 3]);
  17422. */;
  17423. _proto.setPosition = function setPosition(x, y, z) {
  17424. if (y === void 0) {
  17425. y = this.position[1];
  17426. }
  17427. if (z === void 0) {
  17428. z = this.position[2];
  17429. }
  17430. var position = createVec3(x, y, z);
  17431. this._setPosition(position);
  17432. this.setFocalPoint(this.focalPoint);
  17433. this.triggerUpdate();
  17434. return this;
  17435. }
  17436. /**
  17437. * Sets the focal point of this camera in world coordinates.
  17438. *
  17439. * support scalars or vectors.
  17440. * @example
  17441. * setFocalPoint(1, 2, 3);
  17442. * setFocalPoint([1, 2, 3]);
  17443. */;
  17444. _proto.setFocalPoint = function setFocalPoint(x, y, z) {
  17445. if (y === void 0) {
  17446. y = this.focalPoint[1];
  17447. }
  17448. if (z === void 0) {
  17449. z = this.focalPoint[2];
  17450. }
  17451. var up = fromValues$2(0, 1, 0);
  17452. this.focalPoint = createVec3(x, y, z);
  17453. if (this.trackingMode === exports.CameraTrackingMode.CINEMATIC) {
  17454. var d = subtract$1(create$2(), this.focalPoint, this.position);
  17455. x = d[0];
  17456. y = d[1];
  17457. z = d[2];
  17458. var r = length(d);
  17459. var el = rad2deg(Math.asin(y / r));
  17460. var az = 90 + rad2deg(Math.atan2(z, x));
  17461. var m = create$1();
  17462. rotateY(m, m, deg2rad(az));
  17463. rotateX(m, m, deg2rad(el));
  17464. up = transformMat4(create$2(), [0, 1, 0], m);
  17465. }
  17466. invert(this.matrix, lookAt(create$1(), this.position, this.focalPoint, up));
  17467. this._getAxes();
  17468. this._getDistance();
  17469. this._getAngles();
  17470. this.triggerUpdate();
  17471. return this;
  17472. };
  17473. _proto.getDistance = function getDistance() {
  17474. return this.distance;
  17475. };
  17476. _proto.getDistanceVector = function getDistanceVector() {
  17477. return this.distanceVector;
  17478. }
  17479. /**
  17480. * Moves the camera towards/from the focal point.
  17481. */;
  17482. _proto.setDistance = function setDistance(d) {
  17483. if (this.distance === d || d < 0) {
  17484. return this;
  17485. }
  17486. this.distance = d;
  17487. if (this.distance < MIN_DISTANCE) {
  17488. this.distance = MIN_DISTANCE;
  17489. }
  17490. this.dollyingStep = this.distance / 100;
  17491. var pos = create$2();
  17492. d = this.distance;
  17493. var n = this.forward;
  17494. var f = this.focalPoint;
  17495. pos[0] = d * n[0] + f[0];
  17496. pos[1] = d * n[1] + f[1];
  17497. pos[2] = d * n[2] + f[2];
  17498. this._setPosition(pos);
  17499. this.triggerUpdate();
  17500. return this;
  17501. };
  17502. _proto.setMaxDistance = function setMaxDistance(d) {
  17503. this.maxDistance = d;
  17504. return this;
  17505. };
  17506. _proto.setMinDistance = function setMinDistance(d) {
  17507. this.minDistance = d;
  17508. return this;
  17509. }
  17510. /**
  17511. * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
  17512. * the azimuth in degrees
  17513. */;
  17514. _proto.setAzimuth = function setAzimuth(az) {
  17515. this.azimuth = getAngle(az);
  17516. this.computeMatrix();
  17517. this._getAxes();
  17518. if (this.type === exports.CameraType.ORBITING || this.type === exports.CameraType.EXPLORING) {
  17519. this._getPosition();
  17520. } else if (this.type === exports.CameraType.TRACKING) {
  17521. this._getFocalPoint();
  17522. }
  17523. this.triggerUpdate();
  17524. return this;
  17525. };
  17526. _proto.getAzimuth = function getAzimuth() {
  17527. return this.azimuth;
  17528. }
  17529. /**
  17530. * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
  17531. */;
  17532. _proto.setElevation = function setElevation(el) {
  17533. this.elevation = getAngle(el);
  17534. this.computeMatrix();
  17535. this._getAxes();
  17536. if (this.type === exports.CameraType.ORBITING || this.type === exports.CameraType.EXPLORING) {
  17537. this._getPosition();
  17538. } else if (this.type === exports.CameraType.TRACKING) {
  17539. this._getFocalPoint();
  17540. }
  17541. this.triggerUpdate();
  17542. return this;
  17543. };
  17544. _proto.getElevation = function getElevation() {
  17545. return this.elevation;
  17546. }
  17547. /**
  17548. * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
  17549. */;
  17550. _proto.setRoll = function setRoll(angle) {
  17551. this.roll = getAngle(angle);
  17552. this.computeMatrix();
  17553. this._getAxes();
  17554. if (this.type === exports.CameraType.ORBITING || this.type === exports.CameraType.EXPLORING) {
  17555. this._getPosition();
  17556. } else if (this.type === exports.CameraType.TRACKING) {
  17557. this._getFocalPoint();
  17558. }
  17559. this.triggerUpdate();
  17560. return this;
  17561. };
  17562. _proto.getRoll = function getRoll() {
  17563. return this.roll;
  17564. }
  17565. /**
  17566. * 根据相机矩阵重新计算各种相机参数
  17567. */;
  17568. _proto._update = function _update() {
  17569. this._getAxes();
  17570. this._getPosition();
  17571. this._getDistance();
  17572. this._getAngles();
  17573. this._getOrthoMatrix();
  17574. this.triggerUpdate();
  17575. }
  17576. /**
  17577. * 计算相机矩阵
  17578. */;
  17579. _proto.computeMatrix = function computeMatrix() {
  17580. // 使用四元数描述 3D 旋转
  17581. // @see https://xiaoiver.github.io/coding/2018/12/28/Camera-%E8%AE%BE%E8%AE%A1-%E4%B8%80.html
  17582. var rotZ = setAxisAngle(create$4(), [0, 0, 1], deg2rad(this.roll));
  17583. identity(this.matrix);
  17584. // only consider HCS for EXPLORING and ORBITING cameras
  17585. var rotX = setAxisAngle(create$4(), [1, 0, 0], deg2rad((this.rotateWorld && this.type !== exports.CameraType.TRACKING || this.type === exports.CameraType.TRACKING ? 1 : -1) * this.elevation));
  17586. var rotY = setAxisAngle(create$4(), [0, 1, 0], deg2rad((this.rotateWorld && this.type !== exports.CameraType.TRACKING || this.type === exports.CameraType.TRACKING ? 1 : -1) * this.azimuth));
  17587. var rotQ = multiply$2(create$4(), rotY, rotX);
  17588. rotQ = multiply$2(create$4(), rotQ, rotZ);
  17589. var rotMatrix = fromQuat(create$1(), rotQ);
  17590. if (this.type === exports.CameraType.ORBITING || this.type === exports.CameraType.EXPLORING) {
  17591. translate(this.matrix, this.matrix, this.focalPoint);
  17592. multiply(this.matrix, this.matrix, rotMatrix);
  17593. translate(this.matrix, this.matrix, [0, 0, this.distance]);
  17594. } else if (this.type === exports.CameraType.TRACKING) {
  17595. translate(this.matrix, this.matrix, this.position);
  17596. multiply(this.matrix, this.matrix, rotMatrix);
  17597. }
  17598. }
  17599. /**
  17600. * Sets the camera position in the camera matrix
  17601. */;
  17602. _proto._setPosition = function _setPosition(x, y, z) {
  17603. this.position = createVec3(x, y, z);
  17604. var m = this.matrix;
  17605. m[12] = this.position[0];
  17606. m[13] = this.position[1];
  17607. m[14] = this.position[2];
  17608. m[15] = 1;
  17609. this._getOrthoMatrix();
  17610. }
  17611. /**
  17612. * Recalculates axes based on the current matrix
  17613. */;
  17614. _proto._getAxes = function _getAxes() {
  17615. copy$1(this.right, createVec3(transformMat4$1(create$3(), [1, 0, 0, 0], this.matrix)));
  17616. copy$1(this.up, createVec3(transformMat4$1(create$3(), [0, 1, 0, 0], this.matrix)));
  17617. copy$1(this.forward, createVec3(transformMat4$1(create$3(), [0, 0, 1, 0], this.matrix)));
  17618. normalize(this.right, this.right);
  17619. normalize(this.up, this.up);
  17620. normalize(this.forward, this.forward);
  17621. }
  17622. /**
  17623. * Recalculates euler angles based on the current state
  17624. */;
  17625. _proto._getAngles = function _getAngles() {
  17626. // Recalculates angles
  17627. var x = this.distanceVector[0];
  17628. var y = this.distanceVector[1];
  17629. var z = this.distanceVector[2];
  17630. var r = length(this.distanceVector);
  17631. // FAST FAIL: If there is no distance we cannot compute angles
  17632. if (r === 0) {
  17633. this.elevation = 0;
  17634. this.azimuth = 0;
  17635. return;
  17636. }
  17637. if (this.type === exports.CameraType.TRACKING) {
  17638. this.elevation = rad2deg(Math.asin(y / r));
  17639. this.azimuth = rad2deg(Math.atan2(-x, -z));
  17640. } else {
  17641. if (this.rotateWorld) {
  17642. this.elevation = rad2deg(Math.asin(y / r));
  17643. this.azimuth = rad2deg(Math.atan2(-x, -z));
  17644. } else {
  17645. this.elevation = -rad2deg(Math.asin(y / r));
  17646. this.azimuth = -rad2deg(Math.atan2(-x, -z));
  17647. }
  17648. }
  17649. }
  17650. /**
  17651. * 重新计算相机位置,只有 ORBITING 模式相机位置才会发生变化
  17652. */;
  17653. _proto._getPosition = function _getPosition() {
  17654. copy$1(this.position, createVec3(transformMat4$1(create$3(), [0, 0, 0, 1], this.matrix)));
  17655. // 相机位置变化,需要重新计算视距
  17656. this._getDistance();
  17657. }
  17658. /**
  17659. * 重新计算视点,只有 TRACKING 模式视点才会发生变化
  17660. */;
  17661. _proto._getFocalPoint = function _getFocalPoint() {
  17662. transformMat3(this.distanceVector, [0, 0, -this.distance], fromMat4(create(), this.matrix));
  17663. add$1(this.focalPoint, this.position, this.distanceVector);
  17664. // 视点变化,需要重新计算视距
  17665. this._getDistance();
  17666. }
  17667. /**
  17668. * 重新计算视距
  17669. */;
  17670. _proto._getDistance = function _getDistance() {
  17671. this.distanceVector = subtract$1(create$2(), this.focalPoint, this.position);
  17672. this.distance = length(this.distanceVector);
  17673. this.dollyingStep = this.distance / 100;
  17674. };
  17675. _proto._getOrthoMatrix = function _getOrthoMatrix() {
  17676. if (this.projectionMode !== exports.CameraProjectionMode.ORTHOGRAPHIC) {
  17677. return;
  17678. }
  17679. var position = this.position;
  17680. var rotZ = setAxisAngle(create$4(), [0, 0, 1], -this.roll * Math.PI / 180);
  17681. fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, fromValues$2((this.rright - this.left) / 2 - position[0], (this.top - this.bottom) / 2 - position[1], 0), fromValues$2(this.zoom, this.zoom, 1), position);
  17682. };
  17683. _proto.triggerUpdate = function triggerUpdate() {
  17684. if (this.enableUpdate) {
  17685. // update frustum
  17686. var viewMatrix = this.getViewTransform();
  17687. var vpMatrix = multiply(create$1(), this.getPerspective(), viewMatrix);
  17688. this.getFrustum().extractFromVPMatrix(vpMatrix);
  17689. this.eventEmitter.emit(CameraEvent.UPDATED);
  17690. }
  17691. };
  17692. _proto.rotate = function rotate(azimuth, elevation, roll) {
  17693. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  17694. };
  17695. _proto.pan = function pan(tx, ty) {
  17696. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  17697. };
  17698. _proto.dolly = function dolly(value) {
  17699. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  17700. };
  17701. _proto.createLandmark = function createLandmark(name, params) {
  17702. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  17703. };
  17704. _proto.gotoLandmark = function gotoLandmark(name, options) {
  17705. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  17706. };
  17707. _proto.cancelLandmarkAnimation = function cancelLandmarkAnimation() {
  17708. throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  17709. };
  17710. return Camera;
  17711. }();
  17712. var CircleUpdater = /*#__PURE__*/function () {
  17713. function CircleUpdater() {}
  17714. var _proto = CircleUpdater.prototype;
  17715. _proto.update = function update(parsedStyle, object) {
  17716. var r = parsedStyle.r;
  17717. var width = r * 2;
  17718. var height = r * 2;
  17719. return {
  17720. width: width,
  17721. height: height
  17722. };
  17723. };
  17724. return CircleUpdater;
  17725. }();
  17726. var EllipseUpdater = /*#__PURE__*/function () {
  17727. function EllipseUpdater() {}
  17728. var _proto = EllipseUpdater.prototype;
  17729. _proto.update = function update(parsedStyle, object) {
  17730. var rx = parsedStyle.rx,
  17731. ry = parsedStyle.ry;
  17732. var width = rx * 2;
  17733. var height = ry * 2;
  17734. return {
  17735. width: width,
  17736. height: height
  17737. };
  17738. };
  17739. return EllipseUpdater;
  17740. }();
  17741. var LineUpdater = /*#__PURE__*/function () {
  17742. function LineUpdater() {}
  17743. var _proto = LineUpdater.prototype;
  17744. _proto.update = function update(parsedStyle) {
  17745. var x1 = parsedStyle.x1,
  17746. y1 = parsedStyle.y1,
  17747. x2 = parsedStyle.x2,
  17748. y2 = parsedStyle.y2;
  17749. var minX = Math.min(x1, x2);
  17750. var maxX = Math.max(x1, x2);
  17751. var minY = Math.min(y1, y2);
  17752. var maxY = Math.max(y1, y2);
  17753. var width = maxX - minX;
  17754. var height = maxY - minY;
  17755. return {
  17756. width: width,
  17757. height: height
  17758. };
  17759. };
  17760. return LineUpdater;
  17761. }();
  17762. var PathUpdater = /*#__PURE__*/function () {
  17763. function PathUpdater() {}
  17764. var _proto = PathUpdater.prototype;
  17765. _proto.update = function update(parsedStyle) {
  17766. var path = parsedStyle.path;
  17767. var _path$rect = path.rect,
  17768. width = _path$rect.width,
  17769. height = _path$rect.height;
  17770. return {
  17771. width: width,
  17772. height: height
  17773. };
  17774. };
  17775. return PathUpdater;
  17776. }();
  17777. var PolylineUpdater = /*#__PURE__*/function () {
  17778. function PolylineUpdater() {}
  17779. var _proto = PolylineUpdater.prototype;
  17780. _proto.update = function update(parsedStyle) {
  17781. var points = parsedStyle.points.points;
  17782. // FIXME: account for miter lineJoin
  17783. var minX = Math.min.apply(Math, points.map(function (point) {
  17784. return point[0];
  17785. }));
  17786. var maxX = Math.max.apply(Math, points.map(function (point) {
  17787. return point[0];
  17788. }));
  17789. var minY = Math.min.apply(Math, points.map(function (point) {
  17790. return point[1];
  17791. }));
  17792. var maxY = Math.max.apply(Math, points.map(function (point) {
  17793. return point[1];
  17794. }));
  17795. var width = maxX - minX;
  17796. var height = maxY - minY;
  17797. return {
  17798. width: width,
  17799. height: height
  17800. };
  17801. };
  17802. return PolylineUpdater;
  17803. }();
  17804. var RectUpdater = /*#__PURE__*/function () {
  17805. function RectUpdater() {}
  17806. var _proto = RectUpdater.prototype;
  17807. _proto.update = function update(parsedStyle, object) {
  17808. var img = parsedStyle.img,
  17809. _parsedStyle$width = parsedStyle.width,
  17810. width = _parsedStyle$width === void 0 ? 0 : _parsedStyle$width,
  17811. _parsedStyle$height = parsedStyle.height,
  17812. height = _parsedStyle$height === void 0 ? 0 : _parsedStyle$height;
  17813. var contentWidth = width;
  17814. var contentHeight = height;
  17815. // resize with HTMLImageElement's size
  17816. if (img && !isString(img)) {
  17817. if (!contentWidth) {
  17818. contentWidth = img.width;
  17819. parsedStyle.width = contentWidth;
  17820. }
  17821. if (!contentHeight) {
  17822. contentHeight = img.height;
  17823. parsedStyle.height = contentHeight;
  17824. }
  17825. }
  17826. return {
  17827. width: contentWidth,
  17828. height: contentHeight
  17829. };
  17830. };
  17831. return RectUpdater;
  17832. }();
  17833. var TextUpdater = /*#__PURE__*/function () {
  17834. function TextUpdater(globalRuntime) {
  17835. this.globalRuntime = void 0;
  17836. this.globalRuntime = globalRuntime;
  17837. }
  17838. var _proto = TextUpdater.prototype;
  17839. _proto.isReadyToMeasure = function isReadyToMeasure(parsedStyle, object) {
  17840. var text = parsedStyle.text,
  17841. textAlign = parsedStyle.textAlign,
  17842. textBaseline = parsedStyle.textBaseline,
  17843. fontSize = parsedStyle.fontSize,
  17844. fontStyle = parsedStyle.fontStyle,
  17845. fontWeight = parsedStyle.fontWeight,
  17846. fontVariant = parsedStyle.fontVariant,
  17847. lineWidth = parsedStyle.lineWidth;
  17848. return text && fontSize && fontStyle && fontWeight && fontVariant && textAlign && textBaseline && !isNil(lineWidth);
  17849. };
  17850. _proto.update = function update(parsedStyle, object) {
  17851. var _object$ownerDocument, _object$ownerDocument2;
  17852. var text = parsedStyle.text,
  17853. textAlign = parsedStyle.textAlign,
  17854. lineWidth = parsedStyle.lineWidth,
  17855. textBaseline = parsedStyle.textBaseline,
  17856. dx = parsedStyle.dx,
  17857. dy = parsedStyle.dy;
  17858. var _ref = (object === null || object === void 0 ? void 0 : (_object$ownerDocument = object.ownerDocument) === null || _object$ownerDocument === void 0 ? void 0 : (_object$ownerDocument2 = _object$ownerDocument.defaultView) === null || _object$ownerDocument2 === void 0 ? void 0 : _object$ownerDocument2.getConfig()) || {},
  17859. offscreenCanvas = _ref.offscreenCanvas;
  17860. if (!this.isReadyToMeasure(parsedStyle, object)) {
  17861. parsedStyle.metrics = {
  17862. font: '',
  17863. width: 0,
  17864. height: 0,
  17865. lines: [],
  17866. lineWidths: [],
  17867. lineHeight: 0,
  17868. maxLineWidth: 0,
  17869. fontProperties: {
  17870. ascent: 0,
  17871. descent: 0,
  17872. fontSize: 0
  17873. },
  17874. lineMetrics: []
  17875. };
  17876. return {
  17877. width: 0,
  17878. height: 0,
  17879. x: 0,
  17880. y: 0,
  17881. offsetX: 0,
  17882. offsetY: 0
  17883. };
  17884. }
  17885. var metrics = this.globalRuntime.textService.measureText(text, parsedStyle, offscreenCanvas);
  17886. parsedStyle.metrics = metrics;
  17887. var width = metrics.width,
  17888. height = metrics.height,
  17889. lineHeight = metrics.lineHeight,
  17890. fontProperties = metrics.fontProperties;
  17891. // anchor is left-top by default
  17892. var halfExtents = [width / 2, height / 2, 0];
  17893. // default 'left'
  17894. var anchor = [0, 1];
  17895. var lineXOffset = 0;
  17896. if (textAlign === 'center' || textAlign === 'middle') {
  17897. lineXOffset = lineWidth / 2;
  17898. anchor = [0.5, 1];
  17899. } else if (textAlign === 'right' || textAlign === 'end') {
  17900. lineXOffset = lineWidth;
  17901. anchor = [1, 1];
  17902. }
  17903. var lineYOffset = 0;
  17904. if (textBaseline === 'middle') {
  17905. // eslint-disable-next-line prefer-destructuring
  17906. lineYOffset = halfExtents[1];
  17907. } else if (textBaseline === 'top' || textBaseline === 'hanging') {
  17908. lineYOffset = halfExtents[1] * 2;
  17909. } else if (textBaseline === 'alphabetic') {
  17910. // prevent calling getImageData for ascent metrics
  17911. lineYOffset = runtime.enableCSSParsing ? lineHeight - fontProperties.ascent : 0;
  17912. } else if (textBaseline === 'bottom' || textBaseline === 'ideographic') {
  17913. lineYOffset = 0;
  17914. }
  17915. // TODO: ideographic & bottom
  17916. if (dx) {
  17917. lineXOffset += dx;
  17918. }
  17919. if (dy) {
  17920. lineYOffset += dy;
  17921. }
  17922. // update anchor
  17923. parsedStyle.anchor = [anchor[0], anchor[1], 0];
  17924. return {
  17925. width: halfExtents[0] * 2,
  17926. height: halfExtents[1] * 2,
  17927. offsetX: lineXOffset,
  17928. offsetY: lineYOffset
  17929. };
  17930. };
  17931. return TextUpdater;
  17932. }();
  17933. var PROPAGATION_LIMIT = 2048;
  17934. var EventService = /*#__PURE__*/function () {
  17935. function EventService(globalRuntime, context) {
  17936. var _this = this;
  17937. this.globalRuntime = void 0;
  17938. this.context = void 0;
  17939. this.rootTarget = void 0;
  17940. this.emitter = new eventemitter3();
  17941. this.cursor = 'default';
  17942. this.mappingTable = {};
  17943. this.mappingState = {
  17944. trackingData: {}
  17945. };
  17946. this.eventPool = new Map();
  17947. this.pickHandler = void 0;
  17948. this.tmpMatrix = create$1();
  17949. this.tmpVec3 = create$2();
  17950. this.onPointerDown = function (from) {
  17951. // if (!(from instanceof FederatedPointerEvent)) {
  17952. // return;
  17953. // }
  17954. var e = _this.createPointerEvent(from);
  17955. _this.dispatchEvent(e, 'pointerdown');
  17956. if (e.pointerType === 'touch') {
  17957. _this.dispatchEvent(e, 'touchstart');
  17958. } else if (e.pointerType === 'mouse' || e.pointerType === 'pen') {
  17959. var isRightButton = e.button === 2;
  17960. _this.dispatchEvent(e, isRightButton ? 'rightdown' : 'mousedown');
  17961. }
  17962. var trackingData = _this.trackingData(from.pointerId);
  17963. trackingData.pressTargetsByButton[from.button] = e.composedPath();
  17964. _this.freeEvent(e);
  17965. };
  17966. this.onPointerUp = function (from) {
  17967. // if (!(from instanceof FederatedPointerEvent)) {
  17968. // return;
  17969. // }
  17970. var now = performance.now();
  17971. var e = _this.createPointerEvent(from, undefined, undefined, _this.context.config.alwaysTriggerPointerEventOnCanvas ? _this.rootTarget : undefined);
  17972. _this.dispatchEvent(e, 'pointerup');
  17973. if (e.pointerType === 'touch') {
  17974. _this.dispatchEvent(e, 'touchend');
  17975. } else if (e.pointerType === 'mouse' || e.pointerType === 'pen') {
  17976. var isRightButton = e.button === 2;
  17977. _this.dispatchEvent(e, isRightButton ? 'rightup' : 'mouseup');
  17978. }
  17979. var trackingData = _this.trackingData(from.pointerId);
  17980. var pressTarget = _this.findMountedTarget(trackingData.pressTargetsByButton[from.button]);
  17981. var clickTarget = pressTarget;
  17982. // pointerupoutside only bubbles. It only bubbles upto the parent that doesn't contain
  17983. // the pointerup location.
  17984. if (pressTarget && !e.composedPath().includes(pressTarget)) {
  17985. var currentTarget = pressTarget;
  17986. while (currentTarget && !e.composedPath().includes(currentTarget)) {
  17987. e.currentTarget = currentTarget;
  17988. _this.notifyTarget(e, 'pointerupoutside');
  17989. if (e.pointerType === 'touch') {
  17990. _this.notifyTarget(e, 'touchendoutside');
  17991. } else if (e.pointerType === 'mouse' || e.pointerType === 'pen') {
  17992. var _isRightButton = e.button === 2;
  17993. _this.notifyTarget(e, _isRightButton ? 'rightupoutside' : 'mouseupoutside');
  17994. }
  17995. if (Node.isNode(currentTarget)) {
  17996. currentTarget = currentTarget.parentNode;
  17997. }
  17998. }
  17999. delete trackingData.pressTargetsByButton[from.button];
  18000. // currentTarget is the most specific ancestor holding both the pointerdown and pointerup
  18001. // targets. That is - it's our click target!
  18002. clickTarget = currentTarget;
  18003. }
  18004. if (clickTarget) {
  18005. var _e$detail;
  18006. var clickEvent = _this.clonePointerEvent(e, 'click');
  18007. clickEvent.target = clickTarget;
  18008. clickEvent.path = [];
  18009. if (!trackingData.clicksByButton[from.button]) {
  18010. trackingData.clicksByButton[from.button] = {
  18011. clickCount: 0,
  18012. target: clickEvent.target,
  18013. timeStamp: now
  18014. };
  18015. }
  18016. var clickHistory = trackingData.clicksByButton[from.button];
  18017. if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < 200) {
  18018. ++clickHistory.clickCount;
  18019. } else {
  18020. clickHistory.clickCount = 1;
  18021. }
  18022. clickHistory.target = clickEvent.target;
  18023. clickHistory.timeStamp = now;
  18024. clickEvent.detail = clickHistory.clickCount;
  18025. // @see https://github.com/antvis/G/issues/1091
  18026. if (!((_e$detail = e.detail) === null || _e$detail === void 0 ? void 0 : _e$detail.preventClick)) {
  18027. if (!_this.context.config.useNativeClickEvent && (clickEvent.pointerType === 'mouse' || clickEvent.pointerType === 'touch')) {
  18028. _this.dispatchEvent(clickEvent, 'click');
  18029. }
  18030. _this.dispatchEvent(clickEvent, 'pointertap');
  18031. }
  18032. _this.freeEvent(clickEvent);
  18033. }
  18034. _this.freeEvent(e);
  18035. };
  18036. this.onPointerMove = function (from) {
  18037. // if (!(from instanceof FederatedPointerEvent)) {
  18038. // return;
  18039. // }
  18040. var e = _this.createPointerEvent(from, undefined, undefined, _this.context.config.alwaysTriggerPointerEventOnCanvas ? _this.rootTarget : undefined);
  18041. var isMouse = e.pointerType === 'mouse' || e.pointerType === 'pen';
  18042. var trackingData = _this.trackingData(from.pointerId);
  18043. var outTarget = _this.findMountedTarget(trackingData.overTargets);
  18044. // First pointerout/pointerleave
  18045. if (trackingData.overTargets && outTarget !== e.target) {
  18046. // pointerout always occurs on the overTarget when the pointer hovers over another element.
  18047. var outType = from.type === 'mousemove' ? 'mouseout' : 'pointerout';
  18048. var outEvent = _this.createPointerEvent(from, outType, outTarget || undefined);
  18049. _this.dispatchEvent(outEvent, 'pointerout');
  18050. if (isMouse) _this.dispatchEvent(outEvent, 'mouseout');
  18051. // If the pointer exits overTarget and its descendants, then a pointerleave event is also fired. This event
  18052. // is dispatched to all ancestors that no longer capture the pointer.
  18053. if (!e.composedPath().includes(outTarget)) {
  18054. var leaveEvent = _this.createPointerEvent(from, 'pointerleave', outTarget || undefined);
  18055. leaveEvent.eventPhase = leaveEvent.AT_TARGET;
  18056. while (leaveEvent.target && !e.composedPath().includes(leaveEvent.target)) {
  18057. leaveEvent.currentTarget = leaveEvent.target;
  18058. _this.notifyTarget(leaveEvent);
  18059. if (isMouse) {
  18060. _this.notifyTarget(leaveEvent, 'mouseleave');
  18061. }
  18062. if (Node.isNode(leaveEvent.target)) {
  18063. leaveEvent.target = leaveEvent.target.parentNode;
  18064. }
  18065. }
  18066. _this.freeEvent(leaveEvent);
  18067. }
  18068. _this.freeEvent(outEvent);
  18069. }
  18070. // Then pointerover
  18071. if (outTarget !== e.target) {
  18072. // pointerover always occurs on the new overTarget
  18073. var overType = from.type === 'mousemove' ? 'mouseover' : 'pointerover';
  18074. var overEvent = _this.clonePointerEvent(e, overType); // clone faster
  18075. _this.dispatchEvent(overEvent, 'pointerover');
  18076. if (isMouse) _this.dispatchEvent(overEvent, 'mouseover');
  18077. // Probe whether the newly hovered Node is an ancestor of the original overTarget.
  18078. var overTargetAncestor = outTarget && Node.isNode(outTarget) && outTarget.parentNode;
  18079. while (overTargetAncestor && overTargetAncestor !== (Node.isNode(_this.rootTarget) && _this.rootTarget.parentNode)) {
  18080. if (overTargetAncestor === e.target) break;
  18081. overTargetAncestor = overTargetAncestor.parentNode;
  18082. }
  18083. // The pointer has entered a non-ancestor of the original overTarget. This means we need a pointerentered
  18084. // event.
  18085. var didPointerEnter = !overTargetAncestor || overTargetAncestor === (Node.isNode(_this.rootTarget) && _this.rootTarget.parentNode);
  18086. if (didPointerEnter) {
  18087. var enterEvent = _this.clonePointerEvent(e, 'pointerenter');
  18088. enterEvent.eventPhase = enterEvent.AT_TARGET;
  18089. while (enterEvent.target && enterEvent.target !== outTarget && enterEvent.target !== (Node.isNode(_this.rootTarget) && _this.rootTarget.parentNode)) {
  18090. enterEvent.currentTarget = enterEvent.target;
  18091. _this.notifyTarget(enterEvent);
  18092. if (isMouse) _this.notifyTarget(enterEvent, 'mouseenter');
  18093. if (Node.isNode(enterEvent.target)) {
  18094. enterEvent.target = enterEvent.target.parentNode;
  18095. }
  18096. }
  18097. _this.freeEvent(enterEvent);
  18098. }
  18099. _this.freeEvent(overEvent);
  18100. }
  18101. // Then pointermove
  18102. _this.dispatchEvent(e, 'pointermove');
  18103. if (e.pointerType === 'touch') _this.dispatchEvent(e, 'touchmove');
  18104. if (isMouse) {
  18105. _this.dispatchEvent(e, 'mousemove');
  18106. _this.cursor = _this.getCursor(e.target);
  18107. }
  18108. trackingData.overTargets = e.composedPath();
  18109. _this.freeEvent(e);
  18110. };
  18111. this.onPointerOut = function (from) {
  18112. // if (!(from instanceof FederatedPointerEvent)) {
  18113. // return;
  18114. // }
  18115. var trackingData = _this.trackingData(from.pointerId);
  18116. if (trackingData.overTargets) {
  18117. var isMouse = from.pointerType === 'mouse' || from.pointerType === 'pen';
  18118. var outTarget = _this.findMountedTarget(trackingData.overTargets);
  18119. // pointerout first
  18120. var outEvent = _this.createPointerEvent(from, 'pointerout', outTarget || undefined);
  18121. _this.dispatchEvent(outEvent);
  18122. if (isMouse) _this.dispatchEvent(outEvent, 'mouseout');
  18123. // pointerleave(s) are also dispatched b/c the pointer must've left rootTarget and its descendants to
  18124. // get an upstream pointerout event (upstream events do not know rootTarget has descendants).
  18125. var leaveEvent = _this.createPointerEvent(from, 'pointerleave', outTarget || undefined);
  18126. leaveEvent.eventPhase = leaveEvent.AT_TARGET;
  18127. while (leaveEvent.target && leaveEvent.target !== (Node.isNode(_this.rootTarget) && _this.rootTarget.parentNode)) {
  18128. leaveEvent.currentTarget = leaveEvent.target;
  18129. _this.notifyTarget(leaveEvent);
  18130. if (isMouse) {
  18131. _this.notifyTarget(leaveEvent, 'mouseleave');
  18132. }
  18133. if (Node.isNode(leaveEvent.target)) {
  18134. leaveEvent.target = leaveEvent.target.parentNode;
  18135. }
  18136. }
  18137. trackingData.overTargets = null;
  18138. _this.freeEvent(outEvent);
  18139. _this.freeEvent(leaveEvent);
  18140. }
  18141. _this.cursor = null;
  18142. };
  18143. this.onPointerOver = function (from) {
  18144. // if (!(from instanceof FederatedPointerEvent)) {
  18145. // return;
  18146. // }
  18147. var trackingData = _this.trackingData(from.pointerId);
  18148. var e = _this.createPointerEvent(from);
  18149. var isMouse = e.pointerType === 'mouse' || e.pointerType === 'pen';
  18150. _this.dispatchEvent(e, 'pointerover');
  18151. if (isMouse) _this.dispatchEvent(e, 'mouseover');
  18152. if (e.pointerType === 'mouse') _this.cursor = _this.getCursor(e.target);
  18153. // pointerenter events must be fired since the pointer entered from upstream.
  18154. var enterEvent = _this.clonePointerEvent(e, 'pointerenter');
  18155. enterEvent.eventPhase = enterEvent.AT_TARGET;
  18156. while (enterEvent.target && enterEvent.target !== (Node.isNode(_this.rootTarget) && _this.rootTarget.parentNode)) {
  18157. enterEvent.currentTarget = enterEvent.target;
  18158. _this.notifyTarget(enterEvent);
  18159. if (isMouse) {
  18160. // mouseenter should not bubble
  18161. // @see https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseenter_event#usage_notes
  18162. _this.notifyTarget(enterEvent, 'mouseenter');
  18163. }
  18164. if (Node.isNode(enterEvent.target)) {
  18165. enterEvent.target = enterEvent.target.parentNode;
  18166. }
  18167. }
  18168. trackingData.overTargets = e.composedPath();
  18169. _this.freeEvent(e);
  18170. _this.freeEvent(enterEvent);
  18171. };
  18172. this.onPointerUpOutside = function (from) {
  18173. // if (!(from instanceof FederatedPointerEvent)) {
  18174. // return;
  18175. // }
  18176. var trackingData = _this.trackingData(from.pointerId);
  18177. var pressTarget = _this.findMountedTarget(trackingData.pressTargetsByButton[from.button]);
  18178. var e = _this.createPointerEvent(from);
  18179. if (pressTarget) {
  18180. var currentTarget = pressTarget;
  18181. while (currentTarget) {
  18182. e.currentTarget = currentTarget;
  18183. _this.notifyTarget(e, 'pointerupoutside');
  18184. if (e.pointerType === 'touch') ; else if (e.pointerType === 'mouse' || e.pointerType === 'pen') {
  18185. _this.notifyTarget(e, e.button === 2 ? 'rightupoutside' : 'mouseupoutside');
  18186. }
  18187. if (Node.isNode(currentTarget)) {
  18188. currentTarget = currentTarget.parentNode;
  18189. }
  18190. }
  18191. delete trackingData.pressTargetsByButton[from.button];
  18192. }
  18193. _this.freeEvent(e);
  18194. };
  18195. this.onWheel = function (from) {
  18196. // if (!(from instanceof FederatedWheelEvent)) {
  18197. // return;
  18198. // }
  18199. var wheelEvent = _this.createWheelEvent(from);
  18200. _this.dispatchEvent(wheelEvent);
  18201. _this.freeEvent(wheelEvent);
  18202. };
  18203. this.onClick = function (from) {
  18204. if (_this.context.config.useNativeClickEvent) {
  18205. var e = _this.createPointerEvent(from);
  18206. _this.dispatchEvent(e);
  18207. _this.freeEvent(e);
  18208. }
  18209. };
  18210. this.onPointerCancel = function (from) {
  18211. var e = _this.createPointerEvent(from, undefined, undefined, _this.context.config.alwaysTriggerPointerEventOnCanvas ? _this.rootTarget : undefined);
  18212. _this.dispatchEvent(e);
  18213. _this.freeEvent(e);
  18214. };
  18215. this.globalRuntime = globalRuntime;
  18216. this.context = context;
  18217. }
  18218. var _proto = EventService.prototype;
  18219. _proto.init = function init() {
  18220. this.rootTarget = this.context.renderingContext.root.parentNode; // document
  18221. this.addEventMapping('pointerdown', this.onPointerDown);
  18222. this.addEventMapping('pointerup', this.onPointerUp);
  18223. this.addEventMapping('pointermove', this.onPointerMove);
  18224. this.addEventMapping('pointerout', this.onPointerOut);
  18225. this.addEventMapping('pointerleave', this.onPointerOut);
  18226. this.addEventMapping('pointercancel', this.onPointerCancel);
  18227. this.addEventMapping('pointerover', this.onPointerOver);
  18228. this.addEventMapping('pointerupoutside', this.onPointerUpOutside);
  18229. this.addEventMapping('wheel', this.onWheel);
  18230. this.addEventMapping('click', this.onClick);
  18231. };
  18232. _proto.destroy = function destroy() {
  18233. this.emitter.removeAllListeners();
  18234. this.mappingTable = {};
  18235. this.mappingState = {};
  18236. this.eventPool.clear();
  18237. };
  18238. _proto.client2Viewport = function client2Viewport(client) {
  18239. var bbox = this.context.contextService.getBoundingClientRect();
  18240. return new Point(client.x - ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0), client.y - ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0));
  18241. };
  18242. _proto.viewport2Client = function viewport2Client(canvas) {
  18243. var bbox = this.context.contextService.getBoundingClientRect();
  18244. return new Point(canvas.x + ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0), canvas.y + ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0));
  18245. };
  18246. _proto.viewport2Canvas = function viewport2Canvas(_ref) {
  18247. var x = _ref.x,
  18248. y = _ref.y;
  18249. var canvas = this.rootTarget.defaultView;
  18250. var camera = canvas.getCamera();
  18251. var _this$context$config = this.context.config,
  18252. width = _this$context$config.width,
  18253. height = _this$context$config.height;
  18254. var projectionMatrixInverse = camera.getPerspectiveInverse();
  18255. var worldMatrix = camera.getWorldTransform();
  18256. var vpMatrix = multiply(this.tmpMatrix, worldMatrix, projectionMatrixInverse);
  18257. var viewport = set$1(this.tmpVec3, x / width * 2 - 1, (1 - y / height) * 2 - 1, 0);
  18258. transformMat4(viewport, viewport, vpMatrix);
  18259. return new Point(viewport[0], viewport[1]);
  18260. };
  18261. _proto.canvas2Viewport = function canvas2Viewport(canvasP) {
  18262. var canvas = this.rootTarget.defaultView;
  18263. var camera = canvas.getCamera();
  18264. // World -> Clip
  18265. var projectionMatrix = camera.getPerspective();
  18266. var viewMatrix = camera.getViewTransform();
  18267. var vpMatrix = multiply(this.tmpMatrix, projectionMatrix, viewMatrix);
  18268. var clip = set$1(this.tmpVec3, canvasP.x, canvasP.y, 0);
  18269. transformMat4(this.tmpVec3, this.tmpVec3, vpMatrix);
  18270. // Clip -> NDC -> Viewport, flip Y
  18271. var _this$context$config2 = this.context.config,
  18272. width = _this$context$config2.width,
  18273. height = _this$context$config2.height;
  18274. return new Point((clip[0] + 1) / 2 * width, (1 - (clip[1] + 1) / 2) * height);
  18275. };
  18276. _proto.setPickHandler = function setPickHandler(pickHandler) {
  18277. this.pickHandler = pickHandler;
  18278. };
  18279. _proto.addEventMapping = function addEventMapping(type, fn) {
  18280. if (!this.mappingTable[type]) {
  18281. this.mappingTable[type] = [];
  18282. }
  18283. this.mappingTable[type].push({
  18284. fn: fn,
  18285. priority: 0
  18286. });
  18287. this.mappingTable[type].sort(function (a, b) {
  18288. return a.priority - b.priority;
  18289. });
  18290. };
  18291. _proto.mapEvent = function mapEvent(e) {
  18292. if (!this.rootTarget) {
  18293. return;
  18294. }
  18295. var mappers = this.mappingTable[e.type];
  18296. if (mappers) {
  18297. for (var i = 0, j = mappers.length; i < j; i++) {
  18298. mappers[i].fn(e);
  18299. }
  18300. } else {
  18301. console.warn("[EventService]: Event mapping not defined for " + e.type);
  18302. }
  18303. };
  18304. _proto.dispatchEvent = function dispatchEvent(e, type, skipPropagate) {
  18305. // Canvas should skip
  18306. if (!skipPropagate) {
  18307. e.propagationStopped = false;
  18308. e.propagationImmediatelyStopped = false;
  18309. this.propagate(e, type);
  18310. } else {
  18311. // target phase
  18312. e.eventPhase = e.AT_TARGET;
  18313. var canvas = this.rootTarget.defaultView || null;
  18314. e.currentTarget = canvas;
  18315. this.notifyListeners(e, type);
  18316. }
  18317. this.emitter.emit(type || e.type, e);
  18318. };
  18319. _proto.propagate = function propagate(e, type) {
  18320. if (!e.target) {
  18321. return;
  18322. }
  18323. // [target, parent, root, Canvas]
  18324. var composedPath = e.composedPath();
  18325. // event flow: capture -> target -> bubbling
  18326. // capture phase
  18327. e.eventPhase = e.CAPTURING_PHASE;
  18328. for (var i = composedPath.length - 1; i >= 1; i--) {
  18329. e.currentTarget = composedPath[i];
  18330. this.notifyTarget(e, type);
  18331. if (e.propagationStopped || e.propagationImmediatelyStopped) return;
  18332. }
  18333. // target phase
  18334. e.eventPhase = e.AT_TARGET;
  18335. e.currentTarget = e.target;
  18336. this.notifyTarget(e, type);
  18337. if (e.propagationStopped || e.propagationImmediatelyStopped) return;
  18338. // find current target in composed path
  18339. var index = composedPath.indexOf(e.currentTarget);
  18340. // bubbling phase
  18341. e.eventPhase = e.BUBBLING_PHASE;
  18342. for (var _i = index + 1; _i < composedPath.length; _i++) {
  18343. e.currentTarget = composedPath[_i];
  18344. this.notifyTarget(e, type);
  18345. if (e.propagationStopped || e.propagationImmediatelyStopped) return;
  18346. }
  18347. };
  18348. _proto.propagationPath = function propagationPath(target) {
  18349. var propagationPath = [target];
  18350. var canvas = this.rootTarget.defaultView || null;
  18351. if (canvas && canvas === target) {
  18352. propagationPath.unshift(canvas.document);
  18353. return propagationPath;
  18354. }
  18355. for (var i = 0; i < PROPAGATION_LIMIT && target !== this.rootTarget; i++) {
  18356. // if (Node.isNode(target) && !target.parentNode) {
  18357. // throw new Error('Cannot find propagation path to disconnected target');
  18358. // }
  18359. if (Node.isNode(target) && target.parentNode) {
  18360. // [target, parent, parent, root]
  18361. propagationPath.push(target.parentNode);
  18362. target = target.parentNode;
  18363. }
  18364. }
  18365. if (canvas) {
  18366. // @ts-ignore
  18367. propagationPath.push(canvas);
  18368. }
  18369. return propagationPath;
  18370. };
  18371. _proto.hitTest = function hitTest(position) {
  18372. var viewportX = position.viewportX,
  18373. viewportY = position.viewportY;
  18374. var _this$context$config3 = this.context.config,
  18375. width = _this$context$config3.width,
  18376. height = _this$context$config3.height;
  18377. // outside canvas
  18378. if (viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height) {
  18379. return null;
  18380. }
  18381. return this.pickHandler(position) || this.rootTarget ||
  18382. // return Document
  18383. null;
  18384. }
  18385. /**
  18386. * whether the native event trigger came from Canvas,
  18387. * should account for HTML shape
  18388. */;
  18389. _proto.isNativeEventFromCanvas = function isNativeEventFromCanvas(event) {
  18390. var _event$nativeEvent;
  18391. var $el = this.context.contextService.getDomElement();
  18392. var target = (_event$nativeEvent = event.nativeEvent) === null || _event$nativeEvent === void 0 ? void 0 : _event$nativeEvent.target;
  18393. if (target) {
  18394. // from <canvas>
  18395. if (target === $el) {
  18396. return true;
  18397. }
  18398. // from <svg>
  18399. if ($el && $el.contains) {
  18400. return $el.contains(target);
  18401. }
  18402. }
  18403. if (event.nativeEvent.composedPath) {
  18404. return event.nativeEvent.composedPath().indexOf($el) > -1;
  18405. }
  18406. // account for Touch
  18407. return false;
  18408. }
  18409. /**
  18410. * Find HTML from composed path in native UI event.
  18411. */;
  18412. _proto.getExistedHTML = function getExistedHTML(event) {
  18413. if (event.nativeEvent.composedPath) {
  18414. for (var _iterator = _createForOfIteratorHelperLoose(event.nativeEvent.composedPath()), _step; !(_step = _iterator()).done;) {
  18415. var eventTarget = _step.value;
  18416. var existed = runtime.nativeHTMLMap.get(eventTarget);
  18417. if (existed) {
  18418. return existed;
  18419. }
  18420. }
  18421. }
  18422. return null;
  18423. };
  18424. _proto.pickTarget = function pickTarget(event) {
  18425. return this.hitTest({
  18426. clientX: event.clientX,
  18427. clientY: event.clientY,
  18428. viewportX: event.viewportX,
  18429. viewportY: event.viewportY,
  18430. x: event.canvasX,
  18431. y: event.canvasY
  18432. });
  18433. };
  18434. _proto.createPointerEvent = function createPointerEvent(from, type, target, fallbackTarget) {
  18435. var event = this.allocateEvent(FederatedPointerEvent);
  18436. this.copyPointerData(from, event);
  18437. this.copyMouseData(from, event);
  18438. this.copyData(from, event);
  18439. event.nativeEvent = from.nativeEvent;
  18440. event.originalEvent = from;
  18441. var existedHTML = this.getExistedHTML(event);
  18442. event.target = target !== null && target !== void 0 ? target : existedHTML || this.isNativeEventFromCanvas(event) && this.pickTarget(event) || fallbackTarget;
  18443. if (typeof type === 'string') {
  18444. event.type = type;
  18445. }
  18446. return event;
  18447. };
  18448. _proto.createWheelEvent = function createWheelEvent(from) {
  18449. var event = this.allocateEvent(FederatedWheelEvent);
  18450. this.copyWheelData(from, event);
  18451. this.copyMouseData(from, event);
  18452. this.copyData(from, event);
  18453. event.nativeEvent = from.nativeEvent;
  18454. event.originalEvent = from;
  18455. var existedHTML = this.getExistedHTML(event);
  18456. event.target = existedHTML || this.isNativeEventFromCanvas(event) && this.pickTarget(event);
  18457. return event;
  18458. };
  18459. _proto.trackingData = function trackingData(id) {
  18460. if (!this.mappingState.trackingData[id]) {
  18461. this.mappingState.trackingData[id] = {
  18462. pressTargetsByButton: {},
  18463. clicksByButton: {},
  18464. overTarget: null
  18465. };
  18466. }
  18467. return this.mappingState.trackingData[id];
  18468. };
  18469. _proto.cloneWheelEvent = function cloneWheelEvent(from) {
  18470. var event = this.allocateEvent(FederatedWheelEvent);
  18471. event.nativeEvent = from.nativeEvent;
  18472. event.originalEvent = from.originalEvent;
  18473. this.copyWheelData(from, event);
  18474. this.copyMouseData(from, event);
  18475. this.copyData(from, event);
  18476. event.target = from.target;
  18477. event.path = from.composedPath().slice();
  18478. event.type = from.type;
  18479. return event;
  18480. };
  18481. _proto.clonePointerEvent = function clonePointerEvent(from, type) {
  18482. var event = this.allocateEvent(FederatedPointerEvent);
  18483. event.nativeEvent = from.nativeEvent;
  18484. event.originalEvent = from.originalEvent;
  18485. this.copyPointerData(from, event);
  18486. this.copyMouseData(from, event);
  18487. this.copyData(from, event);
  18488. event.target = from.target;
  18489. event.path = from.composedPath().slice();
  18490. event.type = type !== null && type !== void 0 ? type : event.type;
  18491. return event;
  18492. };
  18493. _proto.copyPointerData = function copyPointerData(from, to) {
  18494. // if (
  18495. // !(
  18496. // from instanceof FederatedPointerEvent &&
  18497. // to instanceof FederatedPointerEvent
  18498. // )
  18499. // )
  18500. // return;
  18501. to.pointerId = from.pointerId;
  18502. to.width = from.width;
  18503. to.height = from.height;
  18504. to.isPrimary = from.isPrimary;
  18505. to.pointerType = from.pointerType;
  18506. to.pressure = from.pressure;
  18507. to.tangentialPressure = from.tangentialPressure;
  18508. to.tiltX = from.tiltX;
  18509. to.tiltY = from.tiltY;
  18510. to.twist = from.twist;
  18511. };
  18512. _proto.copyMouseData = function copyMouseData(from, to) {
  18513. // if (
  18514. // !(
  18515. // from instanceof FederatedMouseEvent && to instanceof FederatedMouseEvent
  18516. // )
  18517. // )
  18518. // return;
  18519. to.altKey = from.altKey;
  18520. to.button = from.button;
  18521. to.buttons = from.buttons;
  18522. to.ctrlKey = from.ctrlKey;
  18523. to.metaKey = from.metaKey;
  18524. to.shiftKey = from.shiftKey;
  18525. to.client.copyFrom(from.client);
  18526. to.movement.copyFrom(from.movement);
  18527. to.canvas.copyFrom(from.canvas);
  18528. to.screen.copyFrom(from.screen);
  18529. to.global.copyFrom(from.global);
  18530. to.offset.copyFrom(from.offset);
  18531. };
  18532. _proto.copyWheelData = function copyWheelData(from, to) {
  18533. to.deltaMode = from.deltaMode;
  18534. to.deltaX = from.deltaX;
  18535. to.deltaY = from.deltaY;
  18536. to.deltaZ = from.deltaZ;
  18537. };
  18538. _proto.copyData = function copyData(from, to) {
  18539. to.isTrusted = from.isTrusted;
  18540. to.timeStamp = performance.now();
  18541. to.type = from.type;
  18542. to.detail = from.detail;
  18543. to.view = from.view;
  18544. to.page.copyFrom(from.page);
  18545. to.viewport.copyFrom(from.viewport);
  18546. };
  18547. _proto.allocateEvent = function allocateEvent(constructor) {
  18548. if (!this.eventPool.has(constructor)) {
  18549. this.eventPool.set(constructor, []);
  18550. }
  18551. // @ts-ignore
  18552. var event = this.eventPool.get(constructor).pop() || new constructor(this);
  18553. event.eventPhase = event.NONE;
  18554. event.currentTarget = null;
  18555. event.path = [];
  18556. event.target = null;
  18557. return event;
  18558. };
  18559. _proto.freeEvent = function freeEvent(event) {
  18560. if (event.manager !== this) throw new Error('It is illegal to free an event not managed by this EventBoundary!');
  18561. var constructor = event.constructor;
  18562. if (!this.eventPool.has(constructor)) {
  18563. this.eventPool.set(constructor, []);
  18564. }
  18565. // @ts-ignore
  18566. this.eventPool.get(constructor).push(event);
  18567. };
  18568. _proto.notifyTarget = function notifyTarget(e, type) {
  18569. var _type;
  18570. type = (_type = type) !== null && _type !== void 0 ? _type : e.type;
  18571. var key = e.eventPhase === e.CAPTURING_PHASE || e.eventPhase === e.AT_TARGET ? type + "capture" : type;
  18572. this.notifyListeners(e, key);
  18573. if (e.eventPhase === e.AT_TARGET) {
  18574. this.notifyListeners(e, type);
  18575. }
  18576. };
  18577. _proto.notifyListeners = function notifyListeners(e, type) {
  18578. // hack EventEmitter, stops if the `propagationImmediatelyStopped` flag is set
  18579. // @ts-ignore
  18580. var emitter = e.currentTarget.emitter;
  18581. // @ts-ignore
  18582. var listeners = emitter._events[type];
  18583. if (!listeners) return;
  18584. if ('fn' in listeners) {
  18585. if (listeners.once) {
  18586. emitter.removeListener(type, listeners.fn, undefined, true);
  18587. }
  18588. listeners.fn.call(e.currentTarget || listeners.context, e);
  18589. // listeners.fn.call(listeners.context, e);
  18590. } else {
  18591. for (var i = 0; i < listeners.length && !e.propagationImmediatelyStopped; i++) {
  18592. if (listeners[i].once) {
  18593. emitter.removeListener(type, listeners[i].fn, undefined, true);
  18594. }
  18595. listeners[i].fn.call(e.currentTarget || listeners[i].context, e);
  18596. // listeners[i].fn.call(listeners[i].context, e);
  18597. }
  18598. }
  18599. }
  18600. /**
  18601. * some detached nodes may exist in propagation path, need to skip them
  18602. */;
  18603. _proto.findMountedTarget = function findMountedTarget(propagationPath) {
  18604. if (!propagationPath) {
  18605. return null;
  18606. }
  18607. var currentTarget = propagationPath[propagationPath.length - 1];
  18608. for (var i = propagationPath.length - 2; i >= 0; i--) {
  18609. var target = propagationPath[i];
  18610. if (target === this.rootTarget || Node.isNode(target) && target.parentNode === currentTarget) {
  18611. currentTarget = propagationPath[i];
  18612. } else {
  18613. break;
  18614. }
  18615. }
  18616. return currentTarget;
  18617. };
  18618. _proto.getCursor = function getCursor(target) {
  18619. var tmp = target;
  18620. while (tmp) {
  18621. var cursor = Element.isElement(tmp) && tmp.getAttribute('cursor');
  18622. if (cursor) {
  18623. return cursor;
  18624. }
  18625. tmp = Node.isNode(tmp) && tmp.parentNode;
  18626. }
  18627. };
  18628. return EventService;
  18629. }();
  18630. /**
  18631. * used in following scenes:
  18632. * - g `ctx.measureText`
  18633. * - g-plugin-canvas-picker `ctx.isPointInPath`
  18634. * - g-plugin-device-renderer `ctx.createLinearGradient` and generate texture
  18635. *
  18636. * @see https://blog.scottlogic.com/2020/03/19/offscreen-canvas.html
  18637. */
  18638. var OffscreenCanvasCreator = /*#__PURE__*/function () {
  18639. function OffscreenCanvasCreator() {
  18640. this.canvas = void 0;
  18641. this.context = void 0;
  18642. }
  18643. var _proto = OffscreenCanvasCreator.prototype;
  18644. _proto.getOrCreateCanvas = function getOrCreateCanvas(offscreenCanvas, contextAttributes) {
  18645. if (this.canvas) {
  18646. return this.canvas;
  18647. }
  18648. // user-defined offscreen canvas
  18649. if (offscreenCanvas) {
  18650. this.canvas = offscreenCanvas;
  18651. this.context = this.canvas.getContext('2d', contextAttributes);
  18652. } else {
  18653. try {
  18654. // OffscreenCanvas2D measureText can be up to 40% faster.
  18655. this.canvas = new window.OffscreenCanvas(0, 0);
  18656. this.context = this.canvas.getContext('2d', contextAttributes);
  18657. if (!this.context || !this.context.measureText) {
  18658. this.canvas = document.createElement('canvas');
  18659. this.context = this.canvas.getContext('2d');
  18660. }
  18661. } catch (ex) {
  18662. this.canvas = document.createElement('canvas');
  18663. this.context = this.canvas.getContext('2d', contextAttributes);
  18664. }
  18665. }
  18666. this.canvas.width = 10;
  18667. this.canvas.height = 10;
  18668. return this.canvas;
  18669. };
  18670. _proto.getOrCreateContext = function getOrCreateContext(offscreenCanvas, contextAttributes) {
  18671. if (this.context) {
  18672. return this.context;
  18673. }
  18674. this.getOrCreateCanvas(offscreenCanvas, contextAttributes);
  18675. return this.context;
  18676. };
  18677. return OffscreenCanvasCreator;
  18678. }();
  18679. /**
  18680. * why we need re-render
  18681. */
  18682. (function (RenderReason) {
  18683. RenderReason[RenderReason["CAMERA_CHANGED"] = 0] = "CAMERA_CHANGED";
  18684. RenderReason[RenderReason["DISPLAY_OBJECT_CHANGED"] = 1] = "DISPLAY_OBJECT_CHANGED";
  18685. RenderReason[RenderReason["NONE"] = 2] = "NONE";
  18686. })(exports.RenderReason || (exports.RenderReason = {}));
  18687. /**
  18688. * Use frame renderer implemented by `g-canvas/svg/webgl`, in every frame we do followings:
  18689. * * update & merge dirty rectangles
  18690. * * begin frame
  18691. * * filter by visible
  18692. * * sort by z-index in scene graph
  18693. * * culling with strategies registered in `g-canvas/webgl`
  18694. * * end frame
  18695. */
  18696. var RenderingService = /*#__PURE__*/function () {
  18697. function RenderingService(globalRuntime, context) {
  18698. this.globalRuntime = void 0;
  18699. this.context = void 0;
  18700. this.inited = false;
  18701. this.stats = {
  18702. /**
  18703. * total display objects in scenegraph
  18704. */
  18705. total: 0,
  18706. /**
  18707. * number of display objects need to render in current frame
  18708. */
  18709. rendered: 0
  18710. };
  18711. this.zIndexCounter = 0;
  18712. this.hooks = {
  18713. /**
  18714. * called before any frame rendered
  18715. */
  18716. init: new SyncHook(),
  18717. initAsync: new AsyncParallelHook(),
  18718. /**
  18719. * only dirty object which has sth changed will be rendered
  18720. */
  18721. dirtycheck: new SyncWaterfallHook(),
  18722. /**
  18723. * do culling
  18724. */
  18725. cull: new SyncWaterfallHook(),
  18726. /**
  18727. * called at beginning of each frame, won't get called if nothing to re-render
  18728. */
  18729. beginFrame: new SyncHook(),
  18730. /**
  18731. * called before every dirty object get rendered
  18732. */
  18733. beforeRender: new SyncHook(),
  18734. /**
  18735. * called when every dirty object rendering even it's culled
  18736. */
  18737. render: new SyncHook(),
  18738. /**
  18739. * called after every dirty object get rendered
  18740. */
  18741. afterRender: new SyncHook(),
  18742. endFrame: new SyncHook(),
  18743. destroy: new SyncHook(),
  18744. /**
  18745. * use async but faster method such as GPU-based picking in `g-plugin-device-renderer`
  18746. */
  18747. pick: new AsyncSeriesWaterfallHook(),
  18748. /**
  18749. * Unsafe but sync version of pick.
  18750. */
  18751. pickSync: new SyncWaterfallHook(),
  18752. /**
  18753. * used in event system
  18754. */
  18755. pointerDown: new SyncHook(),
  18756. pointerUp: new SyncHook(),
  18757. pointerMove: new SyncHook(),
  18758. pointerOut: new SyncHook(),
  18759. pointerOver: new SyncHook(),
  18760. pointerWheel: new SyncHook(),
  18761. pointerCancel: new SyncHook(),
  18762. click: new SyncHook()
  18763. };
  18764. this.globalRuntime = globalRuntime;
  18765. this.context = context;
  18766. }
  18767. var _proto = RenderingService.prototype;
  18768. _proto.init = function init(callback) {
  18769. var _this = this;
  18770. var context = _extends({}, this.globalRuntime, this.context);
  18771. // register rendering plugins
  18772. this.context.renderingPlugins.forEach(function (plugin) {
  18773. plugin.apply(context, runtime);
  18774. });
  18775. this.hooks.init.call();
  18776. if (this.hooks.initAsync.getCallbacksNum() === 0) {
  18777. this.inited = true;
  18778. callback();
  18779. } else {
  18780. this.hooks.initAsync.promise().then(function () {
  18781. _this.inited = true;
  18782. callback();
  18783. });
  18784. }
  18785. };
  18786. _proto.getStats = function getStats() {
  18787. return this.stats;
  18788. }
  18789. /**
  18790. * Meet the following conditions:
  18791. * * disable DirtyRectangleRendering
  18792. * * camera changed
  18793. */;
  18794. _proto.disableDirtyRectangleRendering = function disableDirtyRectangleRendering() {
  18795. var renderer = this.context.config.renderer;
  18796. var _renderer$getConfig = renderer.getConfig(),
  18797. enableDirtyRectangleRendering = _renderer$getConfig.enableDirtyRectangleRendering;
  18798. return !enableDirtyRectangleRendering || this.context.renderingContext.renderReasons.has(exports.RenderReason.CAMERA_CHANGED);
  18799. };
  18800. _proto.render = function render(canvasConfig, rerenderCallback) {
  18801. var _this2 = this;
  18802. this.stats.total = 0;
  18803. this.stats.rendered = 0;
  18804. this.zIndexCounter = 0;
  18805. var renderingContext = this.context.renderingContext;
  18806. this.globalRuntime.sceneGraphService.syncHierarchy(renderingContext.root);
  18807. this.globalRuntime.sceneGraphService.triggerPendingEvents();
  18808. if (renderingContext.renderReasons.size && this.inited) {
  18809. this.renderDisplayObject(renderingContext.root, canvasConfig, renderingContext);
  18810. this.hooks.beginFrame.call();
  18811. renderingContext.renderListCurrentFrame.forEach(function (object) {
  18812. _this2.hooks.beforeRender.call(object);
  18813. _this2.hooks.render.call(object);
  18814. _this2.hooks.afterRender.call(object);
  18815. });
  18816. this.hooks.endFrame.call();
  18817. renderingContext.renderListCurrentFrame = [];
  18818. renderingContext.renderReasons.clear();
  18819. rerenderCallback();
  18820. }
  18821. // console.log('stats', this.stats);
  18822. };
  18823. _proto.renderDisplayObject = function renderDisplayObject(displayObject, canvasConfig, renderingContext) {
  18824. var _this3 = this;
  18825. var _canvasConfig$rendere = canvasConfig.renderer.getConfig(),
  18826. enableDirtyCheck = _canvasConfig$rendere.enableDirtyCheck,
  18827. enableCulling = _canvasConfig$rendere.enableCulling;
  18828. // recalc style values
  18829. if (this.globalRuntime.enableCSSParsing) {
  18830. this.globalRuntime.styleValueRegistry.recalc(displayObject);
  18831. }
  18832. // TODO: relayout
  18833. // dirtycheck first
  18834. var objectChanged = enableDirtyCheck ? this.hooks.dirtycheck.call(displayObject) : displayObject;
  18835. if (objectChanged) {
  18836. var objectToRender = enableCulling ? this.hooks.cull.call(objectChanged, this.context.camera) : objectChanged;
  18837. if (objectToRender) {
  18838. this.stats.rendered++;
  18839. renderingContext.renderListCurrentFrame.push(objectToRender);
  18840. }
  18841. }
  18842. displayObject.renderable.dirty = false;
  18843. displayObject.sortable.renderOrder = this.zIndexCounter++;
  18844. this.stats.total++;
  18845. // sort is very expensive, use cached result if possible
  18846. var sortable = displayObject.sortable;
  18847. if (sortable.dirty) {
  18848. this.sort(displayObject, sortable);
  18849. sortable.dirty = false;
  18850. sortable.dirtyChildren = [];
  18851. sortable.dirtyReason = undefined;
  18852. }
  18853. // recursive rendering its children
  18854. (sortable.sorted || displayObject.childNodes).forEach(function (child) {
  18855. _this3.renderDisplayObject(child, canvasConfig, renderingContext);
  18856. });
  18857. };
  18858. _proto.sort = function sort(displayObject, sortable) {
  18859. if (sortable.sorted && sortable.dirtyReason !== exports.SortReason.Z_INDEX_CHANGED) {
  18860. // avoid re-sorting the whole children list
  18861. sortable.dirtyChildren.forEach(function (child) {
  18862. var index = displayObject.childNodes.indexOf(child);
  18863. if (index === -1) {
  18864. // remove from sorted list
  18865. var _index = sortable.sorted.indexOf(child);
  18866. if (_index >= 0) {
  18867. sortable.sorted.splice(_index, 1);
  18868. }
  18869. } else {
  18870. if (sortable.sorted.length === 0) {
  18871. sortable.sorted.push(child);
  18872. } else {
  18873. var _index2 = sortedIndex(sortable.sorted, child);
  18874. sortable.sorted.splice(_index2, 0, child);
  18875. }
  18876. }
  18877. });
  18878. } else {
  18879. sortable.sorted = displayObject.childNodes.slice().sort(sortByZIndex);
  18880. }
  18881. };
  18882. _proto.destroy = function destroy() {
  18883. this.inited = false;
  18884. this.hooks.destroy.call();
  18885. this.globalRuntime.sceneGraphService.clearPendingEvents();
  18886. };
  18887. _proto.dirtify = function dirtify() {
  18888. // need re-render
  18889. this.context.renderingContext.renderReasons.add(exports.RenderReason.DISPLAY_OBJECT_CHANGED);
  18890. };
  18891. return RenderingService;
  18892. }();
  18893. var ATTRIBUTE_REGEXP = /\[\s*(.*)=(.*)\s*\]/;
  18894. /**
  18895. * support the following DOM API:
  18896. * * getElementById
  18897. * * getElementsByClassName
  18898. * * getElementsByName
  18899. * * getElementsByTag
  18900. * * querySelector
  18901. * * querySelectorAll
  18902. */
  18903. var DefaultSceneGraphSelector = /*#__PURE__*/function () {
  18904. function DefaultSceneGraphSelector() {}
  18905. var _proto = DefaultSceneGraphSelector.prototype;
  18906. _proto.selectOne = function selectOne(query, root) {
  18907. var _this = this;
  18908. if (query.startsWith('.')) {
  18909. return root.find(function (node) {
  18910. // return !node.shadow && node.id === query.substring(1);
  18911. return ((node === null || node === void 0 ? void 0 : node.classList) || []).indexOf(_this.getIdOrClassname(query)) > -1;
  18912. });
  18913. } else if (query.startsWith('#')) {
  18914. // getElementById('id')
  18915. return root.find(function (node) {
  18916. // return !node.shadow && node.id === query.substring(1);
  18917. return node.id === _this.getIdOrClassname(query);
  18918. });
  18919. } else if (query.startsWith('[')) {
  18920. var _this$getAttribute = this.getAttribute(query),
  18921. name = _this$getAttribute.name,
  18922. value = _this$getAttribute.value;
  18923. if (name) {
  18924. // getElementByName();
  18925. return root.find(function (node) {
  18926. return root !== node && (name === 'name' ? node.name === value : _this.attributeToString(node, name) === value);
  18927. });
  18928. } else {
  18929. return null;
  18930. }
  18931. } else {
  18932. // getElementsByTag('circle');
  18933. return root.find(function (node) {
  18934. return root !== node && node.nodeName === query;
  18935. });
  18936. }
  18937. };
  18938. _proto.selectAll = function selectAll(query, root) {
  18939. var _this2 = this;
  18940. // only support `[name="${name}"]` `.className` `#id`
  18941. if (query.startsWith('.')) {
  18942. // getElementsByClassName('className');
  18943. // should not include itself
  18944. return root.findAll(function (node) {
  18945. return root !== node && ((node === null || node === void 0 ? void 0 : node.classList) || []).indexOf(_this2.getIdOrClassname(query)) > -1;
  18946. });
  18947. } else if (query.startsWith('#')) {
  18948. return root.findAll(function (node) {
  18949. return root !== node && node.id === _this2.getIdOrClassname(query);
  18950. });
  18951. } else if (query.startsWith('[')) {
  18952. var _this$getAttribute2 = this.getAttribute(query),
  18953. name = _this$getAttribute2.name,
  18954. value = _this$getAttribute2.value;
  18955. if (name) {
  18956. // getElementsByName();
  18957. return root.findAll(function (node) {
  18958. return root !== node && (name === 'name' ? node.name === value : _this2.attributeToString(node, name) === value);
  18959. });
  18960. } else {
  18961. return [];
  18962. }
  18963. } else {
  18964. // getElementsByTag('circle');
  18965. return root.findAll(function (node) {
  18966. return root !== node && node.nodeName === query;
  18967. });
  18968. }
  18969. };
  18970. _proto.is = function is(query, node) {
  18971. // a simple `matches` implementation
  18972. if (query.startsWith('.')) {
  18973. return node.className === this.getIdOrClassname(query);
  18974. } else if (query.startsWith('#')) {
  18975. return node.id === this.getIdOrClassname(query);
  18976. } else if (query.startsWith('[')) {
  18977. var _this$getAttribute3 = this.getAttribute(query),
  18978. name = _this$getAttribute3.name,
  18979. value = _this$getAttribute3.value;
  18980. return name === 'name' ? node.name === value : this.attributeToString(node, name) === value;
  18981. } else {
  18982. return node.nodeName === query;
  18983. }
  18984. };
  18985. _proto.getIdOrClassname = function getIdOrClassname(query) {
  18986. return query.substring(1);
  18987. };
  18988. _proto.getAttribute = function getAttribute(query) {
  18989. var matches = query.match(ATTRIBUTE_REGEXP);
  18990. var name = '';
  18991. var value = '';
  18992. if (matches && matches.length > 2) {
  18993. name = matches[1].replace(/"/g, '');
  18994. value = matches[2].replace(/"/g, '');
  18995. }
  18996. return {
  18997. name: name,
  18998. value: value
  18999. };
  19000. };
  19001. _proto.attributeToString = function attributeToString(node, name) {
  19002. if (!node.getAttribute) {
  19003. return '';
  19004. }
  19005. var value = node.getAttribute(name);
  19006. if (isNil(value)) {
  19007. return '';
  19008. }
  19009. if (value.toString) {
  19010. return value.toString();
  19011. }
  19012. return '';
  19013. };
  19014. return DefaultSceneGraphSelector;
  19015. }();
  19016. function markRenderableDirty(e) {
  19017. var renderable = e.renderable;
  19018. if (renderable) {
  19019. renderable.renderBoundsDirty = true;
  19020. renderable.boundsDirty = true;
  19021. }
  19022. }
  19023. var reparentEvent = new MutationEvent(exports.ElementEvent.REPARENT, null, '', '', '', 0, '', '');
  19024. /**
  19025. * update transform in scene graph
  19026. *
  19027. * @see https://community.khronos.org/t/scene-graphs/50542/7
  19028. */
  19029. var DefaultSceneGraphService = /*#__PURE__*/function () {
  19030. function DefaultSceneGraphService(runtime) {
  19031. var _this = this;
  19032. this.runtime = void 0;
  19033. this.pendingEvents = [];
  19034. this.boundsChangedEvent = new CustomEvent(exports.ElementEvent.BOUNDS_CHANGED);
  19035. /**
  19036. * rotate in world space
  19037. */
  19038. this.rotate = function () {
  19039. var parentInvertRotation = create$4();
  19040. return function (element, degrees, y, z) {
  19041. if (y === void 0) {
  19042. y = 0;
  19043. }
  19044. if (z === void 0) {
  19045. z = 0;
  19046. }
  19047. if (typeof degrees === 'number') {
  19048. degrees = fromValues$2(degrees, y, z);
  19049. }
  19050. var transform = element.transformable;
  19051. if (element.parentNode === null || !element.parentNode.transformable) {
  19052. _this.rotateLocal(element, degrees);
  19053. } else {
  19054. var rotation = create$4();
  19055. fromEuler(rotation, degrees[0], degrees[1], degrees[2]);
  19056. var rot = _this.getRotation(element);
  19057. var parentRot = _this.getRotation(element.parentNode);
  19058. copy$3(parentInvertRotation, parentRot);
  19059. invert$1(parentInvertRotation, parentInvertRotation);
  19060. multiply$2(rotation, parentInvertRotation, rotation);
  19061. multiply$2(transform.localRotation, rotation, rot);
  19062. normalize$2(transform.localRotation, transform.localRotation);
  19063. _this.dirtifyLocal(element, transform);
  19064. }
  19065. };
  19066. }();
  19067. /**
  19068. * rotate in local space
  19069. * @see @see https://docs.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-xmquaternionrotationrollpitchyaw
  19070. */
  19071. this.rotateLocal = function () {
  19072. var rotation = create$4();
  19073. return function (element, degrees, y, z) {
  19074. if (y === void 0) {
  19075. y = 0;
  19076. }
  19077. if (z === void 0) {
  19078. z = 0;
  19079. }
  19080. if (typeof degrees === 'number') {
  19081. degrees = fromValues$2(degrees, y, z);
  19082. }
  19083. var transform = element.transformable;
  19084. fromEuler(rotation, degrees[0], degrees[1], degrees[2]);
  19085. mul$1(transform.localRotation, transform.localRotation, rotation);
  19086. _this.dirtifyLocal(element, transform);
  19087. };
  19088. }();
  19089. /**
  19090. * set euler angles(degrees) in world space
  19091. */
  19092. this.setEulerAngles = function () {
  19093. var invParentRot = create$4();
  19094. return function (element, degrees, y, z) {
  19095. if (y === void 0) {
  19096. y = 0;
  19097. }
  19098. if (z === void 0) {
  19099. z = 0;
  19100. }
  19101. if (typeof degrees === 'number') {
  19102. degrees = fromValues$2(degrees, y, z);
  19103. }
  19104. var transform = element.transformable;
  19105. if (element.parentNode === null || !element.parentNode.transformable) {
  19106. _this.setLocalEulerAngles(element, degrees);
  19107. } else {
  19108. fromEuler(transform.localRotation, degrees[0], degrees[1], degrees[2]);
  19109. var parentRotation = _this.getRotation(element.parentNode);
  19110. copy$3(invParentRot, invert$1(create$4(), parentRotation));
  19111. mul$1(transform.localRotation, transform.localRotation, invParentRot);
  19112. _this.dirtifyLocal(element, transform);
  19113. }
  19114. };
  19115. }();
  19116. /**
  19117. * translate in local space
  19118. *
  19119. * @example
  19120. * ```
  19121. * translateLocal(x, y, z)
  19122. * translateLocal(vec3(x, y, z))
  19123. * ```
  19124. */
  19125. this.translateLocal = function () {
  19126. return function (element, translation, y, z) {
  19127. if (y === void 0) {
  19128. y = 0;
  19129. }
  19130. if (z === void 0) {
  19131. z = 0;
  19132. }
  19133. if (typeof translation === 'number') {
  19134. translation = fromValues$2(translation, y, z);
  19135. }
  19136. var transform = element.transformable;
  19137. if (equals$1(translation, create$2())) {
  19138. return;
  19139. }
  19140. transformQuat(translation, translation, transform.localRotation);
  19141. add$1(transform.localPosition, transform.localPosition, translation);
  19142. _this.dirtifyLocal(element, transform);
  19143. };
  19144. }();
  19145. /**
  19146. * move to position in world space
  19147. *
  19148. * 对应 g 原版的 move/moveTo
  19149. * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L684-L689
  19150. */
  19151. this.setPosition = function () {
  19152. var parentInvertMatrix = create$1();
  19153. var tmpPosition = create$2();
  19154. return function (element, position) {
  19155. var transform = element.transformable;
  19156. tmpPosition[0] = position[0];
  19157. tmpPosition[1] = position[1];
  19158. tmpPosition[2] = position[2] || 0;
  19159. if (equals$1(_this.getPosition(element), tmpPosition)) {
  19160. return;
  19161. }
  19162. copy$1(transform.position, tmpPosition);
  19163. if (element.parentNode === null || !element.parentNode.transformable) {
  19164. copy$1(transform.localPosition, tmpPosition);
  19165. } else {
  19166. var parentTransform = element.parentNode.transformable;
  19167. copy(parentInvertMatrix, parentTransform.worldTransform);
  19168. invert(parentInvertMatrix, parentInvertMatrix);
  19169. transformMat4(transform.localPosition, tmpPosition, parentInvertMatrix);
  19170. }
  19171. _this.dirtifyLocal(element, transform);
  19172. };
  19173. }();
  19174. /**
  19175. * move to position in local space
  19176. */
  19177. this.setLocalPosition = function () {
  19178. var tmpPosition = create$2();
  19179. return function (element, position) {
  19180. var transform = element.transformable;
  19181. tmpPosition[0] = position[0];
  19182. tmpPosition[1] = position[1];
  19183. tmpPosition[2] = position[2] || 0;
  19184. if (equals$1(transform.localPosition, tmpPosition)) {
  19185. return;
  19186. }
  19187. copy$1(transform.localPosition, tmpPosition);
  19188. _this.dirtifyLocal(element, transform);
  19189. };
  19190. }();
  19191. /**
  19192. * translate in world space
  19193. *
  19194. * @example
  19195. * ```
  19196. * translate(x, y, z)
  19197. * translate(vec3(x, y, z))
  19198. * ```
  19199. *
  19200. * 对应 g 原版的 translate 2D
  19201. * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L665-L676
  19202. */
  19203. this.translate = function () {
  19204. var zeroVec3 = create$2();
  19205. var tmpVec3 = create$2();
  19206. var tr = create$2();
  19207. return function (element, translation, y, z) {
  19208. if (y === void 0) {
  19209. y = 0;
  19210. }
  19211. if (z === void 0) {
  19212. z = 0;
  19213. }
  19214. if (typeof translation === 'number') {
  19215. translation = set$1(tmpVec3, translation, y, z);
  19216. }
  19217. if (equals$1(translation, zeroVec3)) {
  19218. return;
  19219. }
  19220. add$1(tr, _this.getPosition(element), translation);
  19221. _this.setPosition(element, tr);
  19222. };
  19223. }();
  19224. this.setRotation = function () {
  19225. var parentInvertRotation = create$4();
  19226. return function (element, rotation, y, z, w) {
  19227. var transform = element.transformable;
  19228. if (typeof rotation === 'number') {
  19229. rotation = fromValues$4(rotation, y, z, w);
  19230. }
  19231. if (element.parentNode === null || !element.parentNode.transformable) {
  19232. _this.setLocalRotation(element, rotation);
  19233. } else {
  19234. var parentRot = _this.getRotation(element.parentNode);
  19235. copy$3(parentInvertRotation, parentRot);
  19236. invert$1(parentInvertRotation, parentInvertRotation);
  19237. multiply$2(transform.localRotation, parentInvertRotation, rotation);
  19238. normalize$2(transform.localRotation, transform.localRotation);
  19239. _this.dirtifyLocal(element, transform);
  19240. }
  19241. };
  19242. };
  19243. this.displayObjectDependencyMap = new WeakMap();
  19244. this.calcLocalTransform = function () {
  19245. var tmpMat = create$1();
  19246. var tmpPosition = create$2();
  19247. var tmpQuat = fromValues$4(0, 0, 0, 1);
  19248. return function (transform) {
  19249. var hasSkew = transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0;
  19250. if (hasSkew) {
  19251. fromRotationTranslationScaleOrigin(transform.localTransform, transform.localRotation, transform.localPosition, fromValues$2(1, 1, 1), transform.origin);
  19252. // apply skew2D
  19253. if (transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0) {
  19254. var tmpMat4 = identity(tmpMat);
  19255. tmpMat4[4] = Math.tan(transform.localSkew[0]);
  19256. tmpMat4[1] = Math.tan(transform.localSkew[1]);
  19257. multiply(transform.localTransform, transform.localTransform, tmpMat4);
  19258. }
  19259. var scaling = fromRotationTranslationScaleOrigin(tmpMat, tmpQuat, tmpPosition, transform.localScale, transform.origin);
  19260. multiply(transform.localTransform, transform.localTransform, scaling);
  19261. } else {
  19262. // @see https://github.com/mattdesl/css-mat4/blob/master/index.js
  19263. fromRotationTranslationScaleOrigin(transform.localTransform, transform.localRotation, transform.localPosition, transform.localScale, transform.origin);
  19264. }
  19265. };
  19266. }();
  19267. this.runtime = runtime;
  19268. }
  19269. var _proto = DefaultSceneGraphService.prototype;
  19270. _proto.matches = function matches(query, root) {
  19271. return this.runtime.sceneGraphSelector.is(query, root);
  19272. };
  19273. _proto.querySelector = function querySelector(query, root) {
  19274. return this.runtime.sceneGraphSelector.selectOne(query, root);
  19275. };
  19276. _proto.querySelectorAll = function querySelectorAll(query, root) {
  19277. return this.runtime.sceneGraphSelector.selectAll(query, root);
  19278. // .filter((node) => !node.shadow);
  19279. };
  19280. _proto.attach = function attach(child, parent, index) {
  19281. var _sortable$sorted, _child$style;
  19282. var detached = false;
  19283. if (child.parentNode) {
  19284. detached = child.parentNode !== parent;
  19285. this.detach(child);
  19286. }
  19287. child.parentNode = parent;
  19288. if (!isNil(index)) {
  19289. child.parentNode.childNodes.splice(index, 0, child);
  19290. } else {
  19291. child.parentNode.childNodes.push(child);
  19292. }
  19293. // parent needs re-sort
  19294. var sortable = parent.sortable;
  19295. if ((sortable === null || sortable === void 0 ? void 0 : (_sortable$sorted = sortable.sorted) === null || _sortable$sorted === void 0 ? void 0 : _sortable$sorted.length) || ((_child$style = child.style) === null || _child$style === void 0 ? void 0 : _child$style.zIndex)) {
  19296. if (sortable.dirtyChildren.indexOf(child) === -1) {
  19297. sortable.dirtyChildren.push(child);
  19298. }
  19299. // if (sortable) {
  19300. // only child has z-Index
  19301. sortable.dirty = true;
  19302. sortable.dirtyReason = exports.SortReason.ADDED;
  19303. }
  19304. // this.updateGraphDepth(child);
  19305. var transform = child.transformable;
  19306. if (transform) {
  19307. this.dirtifyWorld(child, transform);
  19308. }
  19309. if (transform.frozen) {
  19310. this.unfreezeParentToRoot(child);
  19311. }
  19312. if (detached) {
  19313. child.dispatchEvent(reparentEvent);
  19314. }
  19315. };
  19316. _proto.detach = function detach(child) {
  19317. if (child.parentNode) {
  19318. var _sortable$sorted2, _child$style2;
  19319. var transform = child.transformable;
  19320. // if (transform) {
  19321. // const worldTransform = this.getWorldTransform(child, transform);
  19322. // mat4.getScaling(transform.localScale, worldTransform);
  19323. // mat4.getTranslation(transform.localPosition, worldTransform);
  19324. // mat4.getRotation(transform.localRotation, worldTransform);
  19325. // transform.localDirtyFlag = true;
  19326. // }
  19327. // parent needs re-sort
  19328. var sortable = child.parentNode.sortable;
  19329. // if (sortable) {
  19330. if ((sortable === null || sortable === void 0 ? void 0 : (_sortable$sorted2 = sortable.sorted) === null || _sortable$sorted2 === void 0 ? void 0 : _sortable$sorted2.length) || ((_child$style2 = child.style) === null || _child$style2 === void 0 ? void 0 : _child$style2.zIndex)) {
  19331. if (sortable.dirtyChildren.indexOf(child) === -1) {
  19332. sortable.dirtyChildren.push(child);
  19333. }
  19334. sortable.dirty = true;
  19335. sortable.dirtyReason = exports.SortReason.REMOVED;
  19336. }
  19337. var index = child.parentNode.childNodes.indexOf(child);
  19338. if (index > -1) {
  19339. child.parentNode.childNodes.splice(index, 1);
  19340. }
  19341. if (transform) {
  19342. this.dirtifyWorld(child, transform);
  19343. }
  19344. child.parentNode = null;
  19345. }
  19346. };
  19347. _proto.getOrigin = function getOrigin(element) {
  19348. return element.transformable.origin;
  19349. }
  19350. /**
  19351. * same as pivot in Pixi.js
  19352. *
  19353. * @see https://stackoverflow.com/questions/40748452/how-to-change-css-transform-origin-but-preserve-transformation
  19354. */;
  19355. _proto.setOrigin = function setOrigin(element, origin, y, z) {
  19356. if (y === void 0) {
  19357. y = 0;
  19358. }
  19359. if (z === void 0) {
  19360. z = 0;
  19361. }
  19362. if (typeof origin === 'number') {
  19363. origin = [origin, y, z];
  19364. }
  19365. var transform = element.transformable;
  19366. if (origin[0] === transform.origin[0] && origin[1] === transform.origin[1] && origin[2] === transform.origin[2]) {
  19367. return;
  19368. }
  19369. var originVec = transform.origin;
  19370. // const delta = vec3.subtract(vec3.create(), origin, originVec);
  19371. // vec3.add(transform.localPosition, transform.localPosition, delta);
  19372. // update origin
  19373. originVec[0] = origin[0];
  19374. originVec[1] = origin[1];
  19375. originVec[2] = origin[2] || 0;
  19376. this.dirtifyLocal(element, transform);
  19377. };
  19378. /**
  19379. * set euler angles(degrees) in local space
  19380. */
  19381. _proto.setLocalEulerAngles = function setLocalEulerAngles(element, degrees, y, z) {
  19382. if (y === void 0) {
  19383. y = 0;
  19384. }
  19385. if (z === void 0) {
  19386. z = 0;
  19387. }
  19388. if (typeof degrees === 'number') {
  19389. degrees = fromValues$2(degrees, y, z);
  19390. }
  19391. var transform = element.transformable;
  19392. fromEuler(transform.localRotation, degrees[0], degrees[1], degrees[2]);
  19393. this.dirtifyLocal(element, transform);
  19394. };
  19395. /**
  19396. * scale in local space
  19397. */
  19398. _proto.scaleLocal = function scaleLocal(element, scaling) {
  19399. var transform = element.transformable;
  19400. multiply$1(transform.localScale, transform.localScale, fromValues$2(scaling[0], scaling[1], scaling[2] || 1));
  19401. this.dirtifyLocal(element, transform);
  19402. };
  19403. _proto.setLocalScale = function setLocalScale(element, scaling) {
  19404. var transform = element.transformable;
  19405. var updatedScaling = fromValues$2(scaling[0], scaling[1], scaling[2] || transform.localScale[2]);
  19406. if (equals$1(updatedScaling, transform.localScale)) {
  19407. return;
  19408. }
  19409. copy$1(transform.localScale, updatedScaling);
  19410. this.dirtifyLocal(element, transform);
  19411. };
  19412. _proto.setLocalRotation = function setLocalRotation(element, rotation, y, z, w) {
  19413. if (typeof rotation === 'number') {
  19414. rotation = fromValues$4(rotation, y, z, w);
  19415. }
  19416. var transform = element.transformable;
  19417. copy$3(transform.localRotation, rotation);
  19418. this.dirtifyLocal(element, transform);
  19419. };
  19420. _proto.setLocalSkew = function setLocalSkew(element, skew, y) {
  19421. if (typeof skew === 'number') {
  19422. skew = fromValues$5(skew, y);
  19423. }
  19424. var transform = element.transformable;
  19425. copy$4(transform.localSkew, skew);
  19426. this.dirtifyLocal(element, transform);
  19427. };
  19428. _proto.dirtifyLocal = function dirtifyLocal(element, transform) {
  19429. if (!transform.localDirtyFlag) {
  19430. transform.localDirtyFlag = true;
  19431. if (!transform.dirtyFlag) {
  19432. this.dirtifyWorld(element, transform);
  19433. }
  19434. }
  19435. };
  19436. _proto.dirtifyWorld = function dirtifyWorld(element, transform) {
  19437. if (!transform.dirtyFlag) {
  19438. this.unfreezeParentToRoot(element);
  19439. }
  19440. this.dirtifyWorldInternal(element, transform);
  19441. this.dirtifyToRoot(element, true);
  19442. };
  19443. _proto.triggerPendingEvents = function triggerPendingEvents() {
  19444. var _this2 = this;
  19445. var set = new Set();
  19446. var trigger = function trigger(element, detail) {
  19447. if (element.isConnected && !set.has(element.entity)) {
  19448. _this2.boundsChangedEvent.detail = detail;
  19449. _this2.boundsChangedEvent.target = element;
  19450. if (element.isMutationObserved) {
  19451. element.dispatchEvent(_this2.boundsChangedEvent);
  19452. } else {
  19453. element.ownerDocument.defaultView.dispatchEvent(_this2.boundsChangedEvent, true);
  19454. }
  19455. set.add(element.entity);
  19456. }
  19457. };
  19458. this.pendingEvents.forEach(function (_ref) {
  19459. var element = _ref[0],
  19460. detail = _ref[1];
  19461. if (detail.affectChildren) {
  19462. element.forEach(function (e) {
  19463. trigger(e, detail);
  19464. });
  19465. } else {
  19466. trigger(element, detail);
  19467. }
  19468. });
  19469. this.clearPendingEvents();
  19470. set.clear();
  19471. };
  19472. _proto.clearPendingEvents = function clearPendingEvents() {
  19473. this.pendingEvents = [];
  19474. };
  19475. _proto.dirtifyToRoot = function dirtifyToRoot(element, affectChildren) {
  19476. if (affectChildren === void 0) {
  19477. affectChildren = false;
  19478. }
  19479. var p = element;
  19480. // only need to re-render itself
  19481. if (p.renderable) {
  19482. p.renderable.dirty = true;
  19483. }
  19484. while (p) {
  19485. markRenderableDirty(p);
  19486. p = p.parentNode;
  19487. }
  19488. if (affectChildren) {
  19489. element.forEach(function (e) {
  19490. markRenderableDirty(e);
  19491. });
  19492. }
  19493. // inform dependencies
  19494. this.informDependentDisplayObjects(element);
  19495. // reuse the same custom event
  19496. this.pendingEvents.push([element, {
  19497. affectChildren: affectChildren
  19498. }]);
  19499. };
  19500. _proto.updateDisplayObjectDependency = function updateDisplayObjectDependency(name, oldPath, newPath, object) {
  19501. // clear ref to old clip path
  19502. if (oldPath && oldPath !== newPath) {
  19503. var oldDependencyMap = this.displayObjectDependencyMap.get(oldPath);
  19504. if (oldDependencyMap && oldDependencyMap[name]) {
  19505. var index = oldDependencyMap[name].indexOf(object);
  19506. oldDependencyMap[name].splice(index, 1);
  19507. }
  19508. }
  19509. if (newPath) {
  19510. var newDependencyMap = this.displayObjectDependencyMap.get(newPath);
  19511. if (!newDependencyMap) {
  19512. this.displayObjectDependencyMap.set(newPath, {});
  19513. newDependencyMap = this.displayObjectDependencyMap.get(newPath);
  19514. }
  19515. if (!newDependencyMap[name]) {
  19516. newDependencyMap[name] = [];
  19517. }
  19518. newDependencyMap[name].push(object);
  19519. }
  19520. };
  19521. _proto.informDependentDisplayObjects = function informDependentDisplayObjects(object) {
  19522. var _this3 = this;
  19523. var dependencyMap = this.displayObjectDependencyMap.get(object);
  19524. if (dependencyMap) {
  19525. Object.keys(dependencyMap).forEach(function (name) {
  19526. dependencyMap[name].forEach(function (target) {
  19527. _this3.dirtifyToRoot(target, true);
  19528. target.dispatchEvent(new MutationEvent(exports.ElementEvent.ATTR_MODIFIED, target, _this3, _this3, name, MutationEvent.MODIFICATION, _this3, _this3));
  19529. if (target.isCustomElement && target.isConnected) {
  19530. if (target.attributeChangedCallback) {
  19531. target.attributeChangedCallback(name, _this3, _this3);
  19532. }
  19533. }
  19534. });
  19535. });
  19536. }
  19537. };
  19538. _proto.getPosition = function getPosition(element) {
  19539. var transform = element.transformable;
  19540. return getTranslation(transform.position, this.getWorldTransform(element, transform));
  19541. };
  19542. _proto.getRotation = function getRotation$1(element) {
  19543. var transform = element.transformable;
  19544. return getRotation(transform.rotation, this.getWorldTransform(element, transform));
  19545. };
  19546. _proto.getScale = function getScale(element) {
  19547. var transform = element.transformable;
  19548. return getScaling(transform.scaling, this.getWorldTransform(element, transform));
  19549. };
  19550. _proto.getWorldTransform = function getWorldTransform(element, transform) {
  19551. if (transform === void 0) {
  19552. transform = element.transformable;
  19553. }
  19554. if (!transform.localDirtyFlag && !transform.dirtyFlag) {
  19555. return transform.worldTransform;
  19556. }
  19557. if (element.parentNode && element.parentNode.transformable) {
  19558. this.getWorldTransform(element.parentNode);
  19559. }
  19560. this.sync(element, transform);
  19561. return transform.worldTransform;
  19562. };
  19563. _proto.getLocalPosition = function getLocalPosition(element) {
  19564. return element.transformable.localPosition;
  19565. };
  19566. _proto.getLocalRotation = function getLocalRotation(element) {
  19567. return element.transformable.localRotation;
  19568. };
  19569. _proto.getLocalScale = function getLocalScale(element) {
  19570. return element.transformable.localScale;
  19571. };
  19572. _proto.getLocalSkew = function getLocalSkew(element) {
  19573. return element.transformable.localSkew;
  19574. };
  19575. _proto.getLocalTransform = function getLocalTransform(element) {
  19576. var transform = element.transformable;
  19577. if (transform.localDirtyFlag) {
  19578. this.calcLocalTransform(transform);
  19579. transform.localDirtyFlag = false;
  19580. }
  19581. return transform.localTransform;
  19582. };
  19583. _proto.setLocalTransform = function setLocalTransform(element, transform) {
  19584. var t = getTranslation(create$2(), transform);
  19585. var r = getRotation(create$4(), transform);
  19586. var s = getScaling(create$2(), transform);
  19587. this.setLocalScale(element, s);
  19588. this.setLocalPosition(element, t);
  19589. this.setLocalRotation(element, r);
  19590. };
  19591. _proto.resetLocalTransform = function resetLocalTransform(element) {
  19592. this.setLocalScale(element, [1, 1, 1]);
  19593. this.setLocalPosition(element, [0, 0, 0]);
  19594. this.setLocalEulerAngles(element, [0, 0, 0]);
  19595. this.setLocalSkew(element, [0, 0]);
  19596. };
  19597. _proto.getTransformedGeometryBounds = function getTransformedGeometryBounds(element, render, existedAABB) {
  19598. if (render === void 0) {
  19599. render = false;
  19600. }
  19601. var bounds = this.getGeometryBounds(element, render);
  19602. if (!AABB.isEmpty(bounds)) {
  19603. var aabb = existedAABB || new AABB();
  19604. aabb.setFromTransformedAABB(bounds, this.getWorldTransform(element));
  19605. return aabb;
  19606. } else {
  19607. return null;
  19608. }
  19609. }
  19610. /**
  19611. * won't account for children
  19612. */;
  19613. _proto.getGeometryBounds = function getGeometryBounds(element, render) {
  19614. if (render === void 0) {
  19615. render = false;
  19616. }
  19617. var geometry = element.geometry;
  19618. var bounds = render ? geometry.renderBounds : geometry.contentBounds || null;
  19619. // return (bounds && new AABB(bounds.center, bounds.halfExtents)) || new AABB();
  19620. return bounds || new AABB();
  19621. }
  19622. /**
  19623. * account for children in world space
  19624. */;
  19625. _proto.getBounds = function getBounds(element, render) {
  19626. var _this4 = this;
  19627. if (render === void 0) {
  19628. render = false;
  19629. }
  19630. var renderable = element.renderable;
  19631. if (!renderable.boundsDirty && !render && renderable.bounds) {
  19632. return renderable.bounds;
  19633. }
  19634. if (!renderable.renderBoundsDirty && render && renderable.renderBounds) {
  19635. return renderable.renderBounds;
  19636. }
  19637. // reuse existed if possible
  19638. var existedAABB = render ? renderable.renderBounds : renderable.bounds;
  19639. // reset with geometry's aabb
  19640. var aabb = this.getTransformedGeometryBounds(element, render, existedAABB);
  19641. // merge children's aabbs
  19642. var children = element.childNodes;
  19643. children.forEach(function (child) {
  19644. var childBounds = _this4.getBounds(child, render);
  19645. if (childBounds) {
  19646. if (!aabb) {
  19647. aabb = existedAABB || new AABB();
  19648. aabb.update(childBounds.center, childBounds.halfExtents);
  19649. } else {
  19650. aabb.add(childBounds);
  19651. }
  19652. }
  19653. });
  19654. if (render) {
  19655. // FIXME: account for clip path
  19656. var clipped = findClosestClipPathTarget(element);
  19657. if (clipped) {
  19658. // use bounds under world space
  19659. var clipPathBounds = clipped.parsedStyle.clipPath.getBounds(render);
  19660. if (!aabb) {
  19661. aabb = clipPathBounds;
  19662. } else if (clipPathBounds) {
  19663. aabb = clipPathBounds.intersection(aabb);
  19664. }
  19665. }
  19666. }
  19667. if (!aabb) {
  19668. aabb = new AABB();
  19669. }
  19670. if (aabb) {
  19671. if (render) {
  19672. renderable.renderBounds = aabb;
  19673. } else {
  19674. renderable.bounds = aabb;
  19675. }
  19676. }
  19677. if (render) {
  19678. renderable.renderBoundsDirty = false;
  19679. } else {
  19680. renderable.boundsDirty = false;
  19681. }
  19682. return aabb;
  19683. }
  19684. /**
  19685. * account for children in local space
  19686. */;
  19687. _proto.getLocalBounds = function getLocalBounds(element) {
  19688. if (element.parentNode) {
  19689. var parentInvert = create$1();
  19690. if (element.parentNode.transformable) {
  19691. parentInvert = invert(create$1(), this.getWorldTransform(element.parentNode));
  19692. }
  19693. var bounds = this.getBounds(element);
  19694. if (!AABB.isEmpty(bounds)) {
  19695. var localBounds = new AABB();
  19696. localBounds.setFromTransformedAABB(bounds, parentInvert);
  19697. return localBounds;
  19698. }
  19699. }
  19700. return this.getBounds(element);
  19701. };
  19702. _proto.getBoundingClientRect = function getBoundingClientRect(element) {
  19703. var _element$ownerDocumen, _element$ownerDocumen2;
  19704. var aabb;
  19705. var bounds = this.getGeometryBounds(element);
  19706. if (!AABB.isEmpty(bounds)) {
  19707. aabb = new AABB();
  19708. // apply transformation to aabb
  19709. aabb.setFromTransformedAABB(bounds, this.getWorldTransform(element));
  19710. }
  19711. // calc context's offset
  19712. var bbox = (_element$ownerDocumen = element.ownerDocument) === null || _element$ownerDocumen === void 0 ? void 0 : (_element$ownerDocumen2 = _element$ownerDocumen.defaultView) === null || _element$ownerDocumen2 === void 0 ? void 0 : _element$ownerDocumen2.getContextService().getBoundingClientRect();
  19713. if (aabb) {
  19714. var _aabb$getMin = aabb.getMin(),
  19715. left = _aabb$getMin[0],
  19716. top = _aabb$getMin[1];
  19717. var _aabb$getMax = aabb.getMax(),
  19718. right = _aabb$getMax[0],
  19719. bottom = _aabb$getMax[1];
  19720. return new Rectangle(left + ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0), top + ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0), right - left, bottom - top);
  19721. }
  19722. return new Rectangle((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0, (bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0, 0, 0);
  19723. };
  19724. _proto.dirtifyWorldInternal = function dirtifyWorldInternal(element, transform) {
  19725. var _this5 = this;
  19726. if (!transform.dirtyFlag) {
  19727. transform.dirtyFlag = true;
  19728. transform.frozen = false;
  19729. element.childNodes.forEach(function (child) {
  19730. var childTransform = child.transformable;
  19731. if (!childTransform.dirtyFlag) {
  19732. _this5.dirtifyWorldInternal(child, childTransform);
  19733. }
  19734. });
  19735. var renderable = element.renderable;
  19736. if (renderable) {
  19737. renderable.renderBoundsDirty = true;
  19738. renderable.boundsDirty = true;
  19739. renderable.dirty = true;
  19740. }
  19741. }
  19742. };
  19743. _proto.syncHierarchy = function syncHierarchy(element) {
  19744. var transform = element.transformable;
  19745. if (transform.frozen) {
  19746. return;
  19747. }
  19748. transform.frozen = true;
  19749. if (transform.localDirtyFlag || transform.dirtyFlag) {
  19750. this.sync(element, transform);
  19751. }
  19752. var children = element.childNodes;
  19753. for (var i = 0; i < children.length; i++) {
  19754. this.syncHierarchy(children[i]);
  19755. }
  19756. };
  19757. _proto.sync = function sync(element, transform) {
  19758. if (transform.localDirtyFlag) {
  19759. this.calcLocalTransform(transform);
  19760. transform.localDirtyFlag = false;
  19761. }
  19762. if (transform.dirtyFlag) {
  19763. var parent = element.parentNode;
  19764. var parentTransform = parent && parent.transformable;
  19765. if (parent === null || !parentTransform) {
  19766. copy(transform.worldTransform, transform.localTransform);
  19767. } else {
  19768. // TODO: should we support scale compensation?
  19769. // @see https://github.com/playcanvas/engine/issues/1077#issuecomment-359765557
  19770. multiply(transform.worldTransform, parentTransform.worldTransform, transform.localTransform);
  19771. }
  19772. transform.dirtyFlag = false;
  19773. }
  19774. };
  19775. _proto.unfreezeParentToRoot = function unfreezeParentToRoot(child) {
  19776. var p = child.parentNode;
  19777. while (p) {
  19778. var transform = p.transformable;
  19779. if (transform) {
  19780. transform.frozen = false;
  19781. }
  19782. p = p.parentNode;
  19783. }
  19784. };
  19785. return DefaultSceneGraphService;
  19786. }();
  19787. var TEXT_METRICS = {
  19788. MetricsString: '|ÉqÅ',
  19789. BaselineSymbol: 'M',
  19790. BaselineMultiplier: 1.4,
  19791. HeightMultiplier: 2,
  19792. Newlines: [0x000a, 0x000d // carriage return
  19793. ],
  19794. BreakingSpaces: [0x0009, 0x0020, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2008, 0x2009, 0x200a, 0x205f, 0x3000 // ideographic space
  19795. ]
  19796. };
  19797. var LATIN_REGEX = /[a-zA-Z0-9\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff!"#$%&'()*+,-./:;]/;
  19798. // Line breaking rules in CJK (Kinsoku Shori)
  19799. // Refer from https://en.wikipedia.org/wiki/Line_breaking_rules_in_East_Asian_languages
  19800. var regexCannotStartZhCn = /[!%),.:;?\]}¢°·'""†‡›℃∶、。〃〆〕〗〞﹚﹜!"%'),.:;?!]}~]/;
  19801. var regexCannotEndZhCn = /[$(£¥·'"〈《「『【〔〖〝﹙﹛$(.[{£¥]/;
  19802. var regexCannotStartZhTw = /[!),.:;?\]}¢·–—'"•"、。〆〞〕〉》」︰︱︲︳﹐﹑﹒﹓﹔﹕﹖﹘﹚﹜!),.:;?︶︸︺︼︾﹀﹂﹗]|}、]/;
  19803. var regexCannotEndZhTw = /[([{£¥'"‵〈《「『〔〝︴﹙﹛({︵︷︹︻︽︿﹁﹃﹏]/;
  19804. var regexCannotStartJaJp = /[)\]}〕〉》」』】〙〗〟'"⦆»ヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻‐゠–〜?!‼⁇⁈⁉・、:;,。.]/;
  19805. var regexCannotEndJaJp = /[([{〔〈《「『【〘〖〝'"⦅«—...‥〳〴〵]/;
  19806. var regexCannotStartKoKr = /[!%),.:;?\]}¢°'"†‡℃〆〈《「『〕!%),.:;?]}]/;
  19807. var regexCannotEndKoKr = /[$([{£¥'"々〇〉》」〔$([{⦆¥₩#]/;
  19808. var regexCannotStart = new RegExp(regexCannotStartZhCn.source + "|" + regexCannotStartZhTw.source + "|" + regexCannotStartJaJp.source + "|" + regexCannotStartKoKr.source);
  19809. var regexCannotEnd = new RegExp(regexCannotEndZhCn.source + "|" + regexCannotEndZhTw.source + "|" + regexCannotEndJaJp.source + "|" + regexCannotEndKoKr.source);
  19810. /**
  19811. * Borrow from pixi/packages/text/src/TextMetrics.ts
  19812. */
  19813. var TextService = /*#__PURE__*/function () {
  19814. function TextService(runtime) {
  19815. var _this = this;
  19816. this.runtime = void 0;
  19817. /**
  19818. * font metrics cache
  19819. */
  19820. this.fontMetricsCache = {};
  19821. this.shouldBreakByKinsokuShorui = function (char, nextChar) {
  19822. if (_this.isBreakingSpace(nextChar)) return false;
  19823. if (char) {
  19824. // Line breaking rules in CJK (Kinsoku Shori)
  19825. if (regexCannotEnd.exec(nextChar) || regexCannotStart.exec(char)) {
  19826. return true;
  19827. }
  19828. }
  19829. return false;
  19830. };
  19831. this.trimByKinsokuShorui = function (prev) {
  19832. var next = [].concat(prev);
  19833. var prevLine = next[next.length - 2];
  19834. if (!prevLine) {
  19835. return prev;
  19836. }
  19837. var lastChar = prevLine[prevLine.length - 1];
  19838. next[next.length - 2] = prevLine.slice(0, -1);
  19839. next[next.length - 1] = lastChar + next[next.length - 1];
  19840. return next;
  19841. };
  19842. this.runtime = runtime;
  19843. }
  19844. var _proto = TextService.prototype;
  19845. /**
  19846. * Calculates the ascent, descent and fontSize of a given font-style.
  19847. */
  19848. _proto.measureFont = function measureFont(font, offscreenCanvas) {
  19849. // as this method is used for preparing assets, don't recalculate things if we don't need to
  19850. if (this.fontMetricsCache[font]) {
  19851. return this.fontMetricsCache[font];
  19852. }
  19853. var properties = {
  19854. ascent: 0,
  19855. descent: 0,
  19856. fontSize: 0
  19857. };
  19858. var canvas = this.runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
  19859. var context = this.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas, {
  19860. willReadFrequently: true
  19861. });
  19862. context.font = font;
  19863. var metricsString = TEXT_METRICS.MetricsString + TEXT_METRICS.BaselineSymbol;
  19864. var width = Math.ceil(context.measureText(metricsString).width);
  19865. var baseline = Math.ceil(context.measureText(TEXT_METRICS.BaselineSymbol).width);
  19866. var height = TEXT_METRICS.HeightMultiplier * baseline;
  19867. baseline = baseline * TEXT_METRICS.BaselineMultiplier | 0;
  19868. // @ts-ignore
  19869. canvas.width = width;
  19870. // @ts-ignore
  19871. canvas.height = height;
  19872. context.fillStyle = '#f00';
  19873. context.fillRect(0, 0, width, height);
  19874. context.font = font;
  19875. context.textBaseline = 'alphabetic';
  19876. context.fillStyle = '#000';
  19877. context.fillText(metricsString, 0, baseline);
  19878. var imagedata = context.getImageData(0, 0, width || 1, height || 1).data;
  19879. var pixels = imagedata.length;
  19880. var line = width * 4;
  19881. var i = 0;
  19882. var idx = 0;
  19883. var stop = false;
  19884. // ascent. scan from top to bottom until we find a non red pixel
  19885. for (i = 0; i < baseline; ++i) {
  19886. for (var j = 0; j < line; j += 4) {
  19887. if (imagedata[idx + j] !== 255) {
  19888. stop = true;
  19889. break;
  19890. }
  19891. }
  19892. if (!stop) {
  19893. idx += line;
  19894. } else {
  19895. break;
  19896. }
  19897. }
  19898. properties.ascent = baseline - i;
  19899. idx = pixels - line;
  19900. stop = false;
  19901. // descent. scan from bottom to top until we find a non red pixel
  19902. for (i = height; i > baseline; --i) {
  19903. for (var _j = 0; _j < line; _j += 4) {
  19904. if (imagedata[idx + _j] !== 255) {
  19905. stop = true;
  19906. break;
  19907. }
  19908. }
  19909. if (!stop) {
  19910. idx -= line;
  19911. } else {
  19912. break;
  19913. }
  19914. }
  19915. properties.descent = i - baseline;
  19916. properties.fontSize = properties.ascent + properties.descent;
  19917. this.fontMetricsCache[font] = properties;
  19918. return properties;
  19919. };
  19920. _proto.measureText = function measureText(text, parsedStyle, offscreenCanvas) {
  19921. var fontSize = parsedStyle.fontSize,
  19922. wordWrap = parsedStyle.wordWrap,
  19923. strokeHeight = parsedStyle.lineHeight,
  19924. lineWidth = parsedStyle.lineWidth,
  19925. textBaseline = parsedStyle.textBaseline,
  19926. textAlign = parsedStyle.textAlign,
  19927. letterSpacing = parsedStyle.letterSpacing,
  19928. textPath = parsedStyle.textPath,
  19929. textPathSide = parsedStyle.textPathSide,
  19930. textPathStartOffset = parsedStyle.textPathStartOffset,
  19931. _parsedStyle$leading = parsedStyle.leading,
  19932. leading = _parsedStyle$leading === void 0 ? 0 : _parsedStyle$leading;
  19933. var font = toFontString(parsedStyle);
  19934. // if (runtime.enableCSSParsing) {
  19935. var fontProperties = this.measureFont(font, offscreenCanvas);
  19936. // fallback in case UA disallow canvas data extraction
  19937. // (toDataURI, getImageData functions)
  19938. if (fontProperties.fontSize === 0) {
  19939. fontProperties.fontSize = fontSize;
  19940. fontProperties.ascent = fontSize;
  19941. }
  19942. // } else {
  19943. // fontProperties = {
  19944. // fontSize,
  19945. // };
  19946. // }
  19947. var context = this.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
  19948. context.font = font;
  19949. // no overflowing by default
  19950. parsedStyle.isOverflowing = false;
  19951. var outputText = wordWrap ? this.wordWrap(text, parsedStyle, offscreenCanvas) : text;
  19952. var lines = outputText.split(/(?:\r\n|\r|\n)/);
  19953. var lineWidths = new Array(lines.length);
  19954. var maxLineWidth = 0;
  19955. // account for textPath
  19956. if (textPath) {
  19957. var totalPathLength = textPath.getTotalLength();
  19958. // const startingPoint = textPath.getPoint(0);
  19959. for (var i = 0; i < lines.length; i++) {
  19960. var width = context.measureText(lines[i]).width + (lines[i].length - 1) * letterSpacing;
  19961. // for (
  19962. // let i = reverse ? lines[0].length - 1 : 0;
  19963. // reverse ? i >= 0 : i < lines[0].length;
  19964. // reverse ? i-- : i++
  19965. // ) {
  19966. // graphemeInfo = lineBounds[i];
  19967. // if (positionInPath > totalPathLength) {
  19968. // positionInPath %= totalPathLength;
  19969. // } else if (positionInPath < 0) {
  19970. // positionInPath += totalPathLength;
  19971. // }
  19972. // // it would probably much faster to send all the grapheme position for a line
  19973. // // and calculate path position/angle at once.
  19974. // this.setGraphemeOnPath(
  19975. // positionInPath,
  19976. // graphemeInfo,
  19977. // startingPoint
  19978. // );
  19979. // positionInPath += graphemeInfo.kernedWidth;
  19980. // }
  19981. }
  19982. } else {
  19983. for (var _i = 0; _i < lines.length; _i++) {
  19984. // char width + letterSpacing
  19985. var _lineWidth = context.measureText(lines[_i]).width + (lines[_i].length - 1) * letterSpacing;
  19986. lineWidths[_i] = _lineWidth;
  19987. maxLineWidth = Math.max(maxLineWidth, _lineWidth);
  19988. }
  19989. var _width = maxLineWidth + lineWidth;
  19990. // if (dropShadow) {
  19991. // width += dropShadowDistance;
  19992. // }
  19993. var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth;
  19994. var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth) + (lines.length - 1) * (lineHeight + leading);
  19995. // if (dropShadow) {
  19996. // height += dropShadowDistance;
  19997. // }
  19998. lineHeight += leading;
  19999. // handle vertical text baseline
  20000. var offsetY = 0;
  20001. if (textBaseline === 'middle') {
  20002. offsetY = -height / 2;
  20003. } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
  20004. offsetY = -height;
  20005. } else if (textBaseline === 'top' || textBaseline === 'hanging') {
  20006. offsetY = 0;
  20007. }
  20008. return {
  20009. font: font,
  20010. width: _width,
  20011. height: height,
  20012. lines: lines,
  20013. lineWidths: lineWidths,
  20014. lineHeight: lineHeight,
  20015. maxLineWidth: maxLineWidth,
  20016. fontProperties: fontProperties,
  20017. lineMetrics: lineWidths.map(function (width, i) {
  20018. var offsetX = 0;
  20019. // handle horizontal text align
  20020. if (textAlign === 'center' || textAlign === 'middle') {
  20021. offsetX -= width / 2;
  20022. } else if (textAlign === 'right' || textAlign === 'end') {
  20023. offsetX -= width;
  20024. }
  20025. return new Rectangle(offsetX - lineWidth / 2, offsetY + i * lineHeight, width + lineWidth, lineHeight);
  20026. })
  20027. };
  20028. }
  20029. };
  20030. _proto.setGraphemeOnPath = function setGraphemeOnPath() {};
  20031. _proto.wordWrap = function wordWrap(text, parsedStyle, offscreenCanvas) {
  20032. var _this2 = this;
  20033. var _parsedStyle$wordWrap = parsedStyle.wordWrapWidth,
  20034. wordWrapWidth = _parsedStyle$wordWrap === void 0 ? 0 : _parsedStyle$wordWrap,
  20035. letterSpacing = parsedStyle.letterSpacing,
  20036. _parsedStyle$maxLines = parsedStyle.maxLines,
  20037. maxLines = _parsedStyle$maxLines === void 0 ? Infinity : _parsedStyle$maxLines,
  20038. textOverflow = parsedStyle.textOverflow;
  20039. var context = this.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
  20040. var maxWidth = wordWrapWidth + letterSpacing;
  20041. var ellipsis = '';
  20042. if (textOverflow === 'ellipsis') {
  20043. ellipsis = '...';
  20044. } else if (textOverflow && textOverflow !== 'clip') {
  20045. ellipsis = textOverflow;
  20046. }
  20047. var lines = [];
  20048. var currentIndex = 0;
  20049. var currentWidth = 0;
  20050. var cache = {};
  20051. var calcWidth = function calcWidth(char) {
  20052. return _this2.getFromCache(char, letterSpacing, cache, context);
  20053. };
  20054. var ellipsisWidth = Array.from(ellipsis).reduce(function (prev, cur) {
  20055. return prev + calcWidth(cur);
  20056. }, 0);
  20057. var chars = Array.from(text);
  20058. for (var i = 0; i < chars.length; i++) {
  20059. var char = chars[i];
  20060. var prevChar = text[i - 1];
  20061. var nextChar = text[i + 1];
  20062. var charWidth = calcWidth(char);
  20063. if (this.isNewline(char)) {
  20064. currentIndex++;
  20065. // exceed maxLines, break immediately
  20066. if (currentIndex >= maxLines) {
  20067. parsedStyle.isOverflowing = true;
  20068. break;
  20069. }
  20070. currentWidth = 0;
  20071. lines[currentIndex] = '';
  20072. continue;
  20073. }
  20074. if (currentWidth > 0 && currentWidth + charWidth > maxWidth) {
  20075. if (currentIndex + 1 >= maxLines) {
  20076. parsedStyle.isOverflowing = true;
  20077. // If there is not enough space to display the string itself, it is clipped.
  20078. // @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow#values
  20079. if (ellipsisWidth > 0 && ellipsisWidth <= maxWidth) {
  20080. // Backspace from line's end.
  20081. var currentLineLength = lines[currentIndex].length;
  20082. var lastLineWidth = 0;
  20083. var lastLineIndex = currentLineLength;
  20084. for (var _i2 = 0; _i2 < currentLineLength; _i2++) {
  20085. var width = calcWidth(lines[currentIndex][_i2]);
  20086. if (lastLineWidth + width + ellipsisWidth > maxWidth) {
  20087. lastLineIndex = _i2;
  20088. break;
  20089. }
  20090. lastLineWidth += width;
  20091. }
  20092. lines[currentIndex] = (lines[currentIndex] || '').slice(0, lastLineIndex) + ellipsis;
  20093. }
  20094. break;
  20095. }
  20096. currentIndex++;
  20097. currentWidth = 0;
  20098. lines[currentIndex] = '';
  20099. if (this.isBreakingSpace(char)) {
  20100. continue;
  20101. }
  20102. if (!this.canBreakInLastChar(char)) {
  20103. lines = this.trimToBreakable(lines);
  20104. currentWidth = this.sumTextWidthByCache(lines[currentIndex] || '', cache);
  20105. }
  20106. if (this.shouldBreakByKinsokuShorui(char, nextChar)) {
  20107. lines = this.trimByKinsokuShorui(lines);
  20108. currentWidth += calcWidth(prevChar || '');
  20109. }
  20110. }
  20111. currentWidth += charWidth;
  20112. lines[currentIndex] = (lines[currentIndex] || '') + char;
  20113. }
  20114. return lines.join('\n');
  20115. };
  20116. _proto.isBreakingSpace = function isBreakingSpace(char) {
  20117. if (typeof char !== 'string') {
  20118. return false;
  20119. }
  20120. return TEXT_METRICS.BreakingSpaces.indexOf(char.charCodeAt(0)) >= 0;
  20121. };
  20122. _proto.isNewline = function isNewline(char) {
  20123. if (typeof char !== 'string') {
  20124. return false;
  20125. }
  20126. return TEXT_METRICS.Newlines.indexOf(char.charCodeAt(0)) >= 0;
  20127. };
  20128. _proto.trimToBreakable = function trimToBreakable(prev) {
  20129. var next = [].concat(prev);
  20130. var prevLine = next[next.length - 2];
  20131. var index = this.findBreakableIndex(prevLine);
  20132. if (index === -1 || !prevLine) return next;
  20133. var trimmedChar = prevLine.slice(index, index + 1);
  20134. var isTrimmedWithSpace = this.isBreakingSpace(trimmedChar);
  20135. var trimFrom = index + 1;
  20136. var trimTo = index + (isTrimmedWithSpace ? 0 : 1);
  20137. next[next.length - 1] += prevLine.slice(trimFrom, prevLine.length);
  20138. next[next.length - 2] = prevLine.slice(0, trimTo);
  20139. return next;
  20140. };
  20141. _proto.canBreakInLastChar = function canBreakInLastChar(char) {
  20142. if (char && LATIN_REGEX.test(char)) return false;
  20143. return true;
  20144. };
  20145. _proto.sumTextWidthByCache = function sumTextWidthByCache(text, cache) {
  20146. return text.split('').reduce(function (sum, c) {
  20147. if (!cache[c]) throw Error('cannot count the word without cache');
  20148. return sum + cache[c];
  20149. }, 0);
  20150. };
  20151. _proto.findBreakableIndex = function findBreakableIndex(line) {
  20152. for (var i = line.length - 1; i >= 0; i--) {
  20153. if (!LATIN_REGEX.test(line[i])) return i;
  20154. }
  20155. return -1;
  20156. };
  20157. _proto.getFromCache = function getFromCache(key, letterSpacing, cache, context) {
  20158. var width = cache[key];
  20159. if (typeof width !== 'number') {
  20160. var spacing = key.length * letterSpacing;
  20161. width = context.measureText(key).width + spacing;
  20162. cache[key] = width;
  20163. }
  20164. return width;
  20165. };
  20166. return TextService;
  20167. }();
  20168. var _this = undefined;
  20169. var runtime = {};
  20170. /**
  20171. * Replace with IoC container
  20172. */
  20173. var geometryUpdaterFactory = function () {
  20174. var _ref;
  20175. var rectUpdater = new RectUpdater();
  20176. var polylineUpdater = new PolylineUpdater();
  20177. return _ref = {}, _ref[exports.Shape.CIRCLE] = new CircleUpdater(), _ref[exports.Shape.ELLIPSE] = new EllipseUpdater(), _ref[exports.Shape.RECT] = rectUpdater, _ref[exports.Shape.IMAGE] = rectUpdater, _ref[exports.Shape.GROUP] = rectUpdater, _ref[exports.Shape.LINE] = new LineUpdater(), _ref[exports.Shape.TEXT] = new TextUpdater(runtime), _ref[exports.Shape.POLYLINE] = polylineUpdater, _ref[exports.Shape.POLYGON] = polylineUpdater, _ref[exports.Shape.PATH] = new PathUpdater(), _ref[exports.Shape.HTML] = null, _ref[exports.Shape.MESH] = null, _ref;
  20178. }();
  20179. var CSSPropertySyntaxFactory = function () {
  20180. var _ref2;
  20181. var color = new CSSPropertyColor();
  20182. var length = new CSSPropertyLengthOrPercentage();
  20183. return _ref2 = {}, _ref2[exports.PropertySyntax.PERCENTAGE] = null, _ref2[exports.PropertySyntax.NUMBER] = new CSSPropertyNumber(), _ref2[exports.PropertySyntax.ANGLE] = new CSSPropertyAngle(), _ref2[exports.PropertySyntax.DEFINED_PATH] = new CSSPropertyClipPath(), _ref2[exports.PropertySyntax.PAINT] = color, _ref2[exports.PropertySyntax.COLOR] = color, _ref2[exports.PropertySyntax.FILTER] = new CSSPropertyFilter(), _ref2[exports.PropertySyntax.LENGTH] = length, _ref2[exports.PropertySyntax.LENGTH_PERCENTAGE] = length, _ref2[exports.PropertySyntax.LENGTH_PERCENTAGE_12] = new CSSPropertyLengthOrPercentage12(), _ref2[exports.PropertySyntax.LENGTH_PERCENTAGE_14] = new CSSPropertyLengthOrPercentage14(), _ref2[exports.PropertySyntax.COORDINATE] = new CSSPropertyLocalPosition(), _ref2[exports.PropertySyntax.OFFSET_DISTANCE] = new CSSPropertyOffsetDistance(), _ref2[exports.PropertySyntax.OPACITY_VALUE] = new CSSPropertyOpacity(), _ref2[exports.PropertySyntax.PATH] = new CSSPropertyPath(), _ref2[exports.PropertySyntax.LIST_OF_POINTS] = new CSSPropertyPoints(), _ref2[exports.PropertySyntax.SHADOW_BLUR] = new CSSPropertyShadowBlur(), _ref2[exports.PropertySyntax.TEXT] = new CSSPropertyText(), _ref2[exports.PropertySyntax.TEXT_TRANSFORM] = new CSSPropertyTextTransform(), _ref2[exports.PropertySyntax.TRANSFORM] = new CSSPropertyTransform(), _ref2[exports.PropertySyntax.TRANSFORM_ORIGIN] = new CSSPropertyTransformOrigin(), _ref2[exports.PropertySyntax.Z_INDEX] = new CSSPropertyZIndex(), _ref2[exports.PropertySyntax.MARKER] = new CSSPropertyMarker(), _ref2;
  20184. }();
  20185. var getGlobalThis = function getGlobalThis() {
  20186. if (typeof globalThis !== 'undefined') return globalThis;
  20187. if (typeof self !== 'undefined') return self;
  20188. if (typeof window !== 'undefined') return window;
  20189. // @ts-ignore
  20190. if (typeof global !== 'undefined') return global;
  20191. if (typeof _this !== 'undefined') return _this;
  20192. throw new Error('Unable to locate global `this`');
  20193. };
  20194. /**
  20195. * Camera
  20196. * `g-camera-api` will provide an advanced implementation
  20197. */
  20198. runtime.CameraContribution = Camera;
  20199. /**
  20200. * `g-web-animations-api` will provide an AnimationTimeline
  20201. */
  20202. runtime.AnimationTimeline = null;
  20203. runtime.EasingFunction = null;
  20204. runtime.offscreenCanvas = new OffscreenCanvasCreator();
  20205. runtime.nativeHTMLMap = new WeakMap();
  20206. runtime.sceneGraphSelector = new DefaultSceneGraphSelector();
  20207. runtime.sceneGraphService = new DefaultSceneGraphService(runtime);
  20208. runtime.textService = new TextService(runtime);
  20209. runtime.geometryUpdaterFactory = geometryUpdaterFactory;
  20210. runtime.CSSPropertySyntaxFactory = CSSPropertySyntaxFactory;
  20211. runtime.styleValueRegistry = new DefaultStyleValueRegistry();
  20212. runtime.layoutRegistry = null;
  20213. runtime.globalThis = getGlobalThis();
  20214. runtime.enableCSSParsing = true;
  20215. runtime.enableDataset = false;
  20216. runtime.enableStyleSyntax = true;
  20217. var AbstractRendererPlugin = /*#__PURE__*/function () {
  20218. function AbstractRendererPlugin() {
  20219. this.context = void 0;
  20220. this.plugins = [];
  20221. }
  20222. var _proto = AbstractRendererPlugin.prototype;
  20223. _proto.addRenderingPlugin = function addRenderingPlugin(plugin) {
  20224. this.plugins.push(plugin);
  20225. this.context.renderingPlugins.push(plugin);
  20226. };
  20227. _proto.removeAllRenderingPlugins = function removeAllRenderingPlugins() {
  20228. var _this = this;
  20229. this.plugins.forEach(function (plugin) {
  20230. var index = _this.context.renderingPlugins.indexOf(plugin);
  20231. if (index >= 0) {
  20232. _this.context.renderingPlugins.splice(index, 1);
  20233. }
  20234. });
  20235. };
  20236. return AbstractRendererPlugin;
  20237. }();
  20238. var AbstractRenderer = /*#__PURE__*/function () {
  20239. function AbstractRenderer(config) {
  20240. this.plugins = [];
  20241. this.config = void 0;
  20242. this.config = _extends({
  20243. /**
  20244. * only dirty object will cause re-render
  20245. */
  20246. enableDirtyCheck: true,
  20247. enableCulling: false,
  20248. /**
  20249. * enable auto rendering by default
  20250. */
  20251. enableAutoRendering: true,
  20252. /**
  20253. * enable dirty rectangle rendering by default
  20254. */
  20255. enableDirtyRectangleRendering: true,
  20256. enableDirtyRectangleRenderingDebug: false
  20257. }, config);
  20258. }
  20259. var _proto2 = AbstractRenderer.prototype;
  20260. _proto2.registerPlugin = function registerPlugin(plugin) {
  20261. var index = this.plugins.findIndex(function (p) {
  20262. return p === plugin;
  20263. });
  20264. if (index === -1) {
  20265. this.plugins.push(plugin);
  20266. }
  20267. };
  20268. _proto2.unregisterPlugin = function unregisterPlugin(plugin) {
  20269. var index = this.plugins.findIndex(function (p) {
  20270. return p === plugin;
  20271. });
  20272. if (index > -1) {
  20273. this.plugins.splice(index, 1);
  20274. }
  20275. };
  20276. _proto2.getPlugins = function getPlugins() {
  20277. return this.plugins;
  20278. };
  20279. _proto2.getPlugin = function getPlugin(name) {
  20280. return this.plugins.find(function (plugin) {
  20281. return plugin.name === name;
  20282. });
  20283. };
  20284. _proto2.getConfig = function getConfig() {
  20285. return this.config;
  20286. };
  20287. _proto2.setConfig = function setConfig(config) {
  20288. Object.assign(this.config, config);
  20289. };
  20290. return AbstractRenderer;
  20291. }();
  20292. /**
  20293. * apply following rules:
  20294. * 1. `visibility` in scenegraph node
  20295. * 2. other custom culling strategies, eg. frustum culling
  20296. */
  20297. var CullingPlugin = /*#__PURE__*/function () {
  20298. function CullingPlugin(strategies) {
  20299. this.strategies = void 0;
  20300. this.strategies = strategies;
  20301. }
  20302. var _proto = CullingPlugin.prototype;
  20303. _proto.apply = function apply(context) {
  20304. var camera = context.camera,
  20305. renderingService = context.renderingService,
  20306. renderingContext = context.renderingContext;
  20307. var strategies = this.strategies;
  20308. renderingService.hooks.cull.tap(CullingPlugin.tag, function (object) {
  20309. if (object) {
  20310. var cullable = object.cullable;
  20311. // cullable.visible = true;
  20312. // const renderBounds = object.getRenderBounds();
  20313. // if (AABB.isEmpty(renderBounds)) {
  20314. // cullable.visible = false;
  20315. // } else {
  20316. // const isShape2D = shape2D.indexOf(object.nodeName as Shape) > -1;
  20317. // const [p0, p1, p2, p3] = camera.getFrustum().planes;
  20318. // tmpAABB.setMinMax([-p1.distance, -p3.distance, 0], [p0.distance, p2.distance, 0]);
  20319. // cullable.visible = isShape2D ? renderBounds.intersects(tmpAABB) : true;
  20320. // }
  20321. if (strategies.length === 0) {
  20322. cullable.visible = renderingContext.unculledEntities.indexOf(object.entity) > -1;
  20323. } else {
  20324. // eg. implemented by g-webgl(frustum culling)
  20325. cullable.visible = strategies.every(function (strategy) {
  20326. return strategy.isVisible(camera, object);
  20327. });
  20328. }
  20329. if (!object.isCulled() && object.isVisible()) {
  20330. return object;
  20331. } else {
  20332. // if (this.renderingContext.renderListLastFrame.indexOf(object) > -1) {
  20333. object.dispatchEvent(new CustomEvent(exports.ElementEvent.CULLED));
  20334. // }
  20335. }
  20336. return null;
  20337. }
  20338. return object;
  20339. });
  20340. renderingService.hooks.afterRender.tap(CullingPlugin.tag, function (object) {
  20341. object.cullable.visibilityPlaneMask = -1;
  20342. });
  20343. };
  20344. return CullingPlugin;
  20345. }();
  20346. CullingPlugin.tag = 'Culling';
  20347. /**
  20348. * Filter dirty renderables and calculate the "dirty rectangle" which will be clear when frame began
  20349. */
  20350. var DirtyCheckPlugin = /*#__PURE__*/function () {
  20351. function DirtyCheckPlugin() {}
  20352. var _proto = DirtyCheckPlugin.prototype;
  20353. _proto.apply = function apply(context) {
  20354. var renderingService = context.renderingService;
  20355. renderingService.hooks.dirtycheck.tap(DirtyCheckPlugin.tag, function (object) {
  20356. if (object) {
  20357. var renderable = object.renderable;
  20358. var isDirty = renderable.dirty || renderingService.disableDirtyRectangleRendering();
  20359. if (isDirty) {
  20360. return object;
  20361. } else {
  20362. return null;
  20363. }
  20364. }
  20365. return object;
  20366. });
  20367. };
  20368. return DirtyCheckPlugin;
  20369. }();
  20370. DirtyCheckPlugin.tag = 'DirtyCheck';
  20371. /**
  20372. * support mouse & touch events
  20373. * @see https://github.com/pixijs/pixi.js/blob/dev/packages/interaction/README.md
  20374. *
  20375. * also provide some extra events such as `drag`
  20376. */
  20377. var EventPlugin = /*#__PURE__*/function () {
  20378. function EventPlugin() {
  20379. var _this = this;
  20380. this.autoPreventDefault = false;
  20381. this.rootPointerEvent = new FederatedPointerEvent(null);
  20382. this.rootWheelEvent = new FederatedWheelEvent(null);
  20383. this.context = void 0;
  20384. this.onPointerMove = function (nativeEvent) {
  20385. var _this$context$renderi, _this$context$renderi2;
  20386. var canvas = (_this$context$renderi = _this.context.renderingContext.root) === null || _this$context$renderi === void 0 ? void 0 : (_this$context$renderi2 = _this$context$renderi.ownerDocument) === null || _this$context$renderi2 === void 0 ? void 0 : _this$context$renderi2.defaultView;
  20387. if (canvas.supportsTouchEvents && nativeEvent.pointerType === 'touch') return;
  20388. var normalizedEvents = _this.normalizeToPointerEvent(nativeEvent, canvas);
  20389. for (var _iterator = _createForOfIteratorHelperLoose(normalizedEvents), _step; !(_step = _iterator()).done;) {
  20390. var normalizedEvent = _step.value;
  20391. var event = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, canvas, nativeEvent);
  20392. _this.context.eventService.mapEvent(event);
  20393. }
  20394. _this.setCursor(_this.context.eventService.cursor);
  20395. };
  20396. this.onClick = function (nativeEvent) {
  20397. var _this$context$renderi3, _this$context$renderi4;
  20398. var canvas = (_this$context$renderi3 = _this.context.renderingContext.root) === null || _this$context$renderi3 === void 0 ? void 0 : (_this$context$renderi4 = _this$context$renderi3.ownerDocument) === null || _this$context$renderi4 === void 0 ? void 0 : _this$context$renderi4.defaultView;
  20399. var normalizedEvents = _this.normalizeToPointerEvent(nativeEvent, canvas);
  20400. for (var _iterator2 = _createForOfIteratorHelperLoose(normalizedEvents), _step2; !(_step2 = _iterator2()).done;) {
  20401. var normalizedEvent = _step2.value;
  20402. var event = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, canvas, nativeEvent);
  20403. _this.context.eventService.mapEvent(event);
  20404. }
  20405. _this.setCursor(_this.context.eventService.cursor);
  20406. };
  20407. }
  20408. var _proto = EventPlugin.prototype;
  20409. _proto.apply = function apply(context) {
  20410. var _this2 = this;
  20411. this.context = context;
  20412. var renderingService = context.renderingService;
  20413. var canvas = this.context.renderingContext.root.ownerDocument.defaultView;
  20414. this.context.eventService.setPickHandler(function (position) {
  20415. var _this2$context$render = _this2.context.renderingService.hooks.pickSync.call({
  20416. position: position,
  20417. picked: [],
  20418. topmost: true // we only concern the topmost element
  20419. }),
  20420. picked = _this2$context$render.picked;
  20421. return picked[0] || null;
  20422. });
  20423. renderingService.hooks.pointerWheel.tap(EventPlugin.tag, function (nativeEvent) {
  20424. var wheelEvent = _this2.normalizeWheelEvent(nativeEvent);
  20425. _this2.context.eventService.mapEvent(wheelEvent);
  20426. });
  20427. renderingService.hooks.pointerDown.tap(EventPlugin.tag, function (nativeEvent) {
  20428. if (canvas.supportsTouchEvents && nativeEvent.pointerType === 'touch') return;
  20429. var events = _this2.normalizeToPointerEvent(nativeEvent, canvas);
  20430. if (_this2.autoPreventDefault && events[0].isNormalized) {
  20431. var cancelable = nativeEvent.cancelable || !('cancelable' in nativeEvent);
  20432. if (cancelable) {
  20433. nativeEvent.preventDefault();
  20434. }
  20435. }
  20436. for (var _iterator3 = _createForOfIteratorHelperLoose(events), _step3; !(_step3 = _iterator3()).done;) {
  20437. var event = _step3.value;
  20438. var federatedEvent = _this2.bootstrapEvent(_this2.rootPointerEvent, event, canvas, nativeEvent);
  20439. _this2.context.eventService.mapEvent(federatedEvent);
  20440. }
  20441. _this2.setCursor(_this2.context.eventService.cursor);
  20442. });
  20443. renderingService.hooks.pointerUp.tap(EventPlugin.tag, function (nativeEvent) {
  20444. if (canvas.supportsTouchEvents && nativeEvent.pointerType === 'touch') return;
  20445. // account for element in SVG
  20446. var $element = _this2.context.contextService.getDomElement();
  20447. var outside = 'outside';
  20448. try {
  20449. outside = $element && nativeEvent.target && nativeEvent.target !== $element && $element.contains && !$element.contains(nativeEvent.target) ? 'outside' : '';
  20450. } catch (e) {
  20451. // nativeEvent.target maybe not Node, such as Window
  20452. // @see https://github.com/antvis/G/issues/1235
  20453. }
  20454. var normalizedEvents = _this2.normalizeToPointerEvent(nativeEvent, canvas);
  20455. for (var _iterator4 = _createForOfIteratorHelperLoose(normalizedEvents), _step4; !(_step4 = _iterator4()).done;) {
  20456. var normalizedEvent = _step4.value;
  20457. var event = _this2.bootstrapEvent(_this2.rootPointerEvent, normalizedEvent, canvas, nativeEvent);
  20458. event.type += outside;
  20459. _this2.context.eventService.mapEvent(event);
  20460. }
  20461. _this2.setCursor(_this2.context.eventService.cursor);
  20462. });
  20463. renderingService.hooks.pointerMove.tap(EventPlugin.tag, this.onPointerMove);
  20464. renderingService.hooks.pointerOver.tap(EventPlugin.tag, this.onPointerMove);
  20465. renderingService.hooks.pointerOut.tap(EventPlugin.tag, this.onPointerMove);
  20466. renderingService.hooks.click.tap(EventPlugin.tag, this.onClick);
  20467. renderingService.hooks.pointerCancel.tap(EventPlugin.tag, function (nativeEvent) {
  20468. var normalizedEvents = _this2.normalizeToPointerEvent(nativeEvent, canvas);
  20469. for (var _iterator5 = _createForOfIteratorHelperLoose(normalizedEvents), _step5; !(_step5 = _iterator5()).done;) {
  20470. var normalizedEvent = _step5.value;
  20471. var event = _this2.bootstrapEvent(_this2.rootPointerEvent, normalizedEvent, canvas, nativeEvent);
  20472. _this2.context.eventService.mapEvent(event);
  20473. }
  20474. _this2.setCursor(_this2.context.eventService.cursor);
  20475. });
  20476. };
  20477. _proto.getViewportXY = function getViewportXY(nativeEvent) {
  20478. var x;
  20479. var y;
  20480. /**
  20481. * Should account for CSS Transform applied on container.
  20482. * @see https://github.com/antvis/G/issues/1161
  20483. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/offsetX
  20484. */
  20485. var offsetX = nativeEvent.offsetX,
  20486. offsetY = nativeEvent.offsetY,
  20487. clientX = nativeEvent.clientX,
  20488. clientY = nativeEvent.clientY;
  20489. if (this.context.config.supportsCSSTransform && !isNil(offsetX) && !isNil(offsetY)) {
  20490. x = offsetX;
  20491. y = offsetY;
  20492. } else {
  20493. var point = this.context.eventService.client2Viewport(new Point(clientX, clientY));
  20494. x = point.x;
  20495. y = point.y;
  20496. }
  20497. return {
  20498. x: x,
  20499. y: y
  20500. };
  20501. };
  20502. _proto.bootstrapEvent = function bootstrapEvent(event, normalizedEvent, view, nativeEvent) {
  20503. event.view = view;
  20504. event.originalEvent = null;
  20505. event.nativeEvent = nativeEvent;
  20506. event.pointerId = normalizedEvent.pointerId;
  20507. event.width = normalizedEvent.width;
  20508. event.height = normalizedEvent.height;
  20509. event.isPrimary = normalizedEvent.isPrimary;
  20510. event.pointerType = normalizedEvent.pointerType;
  20511. event.pressure = normalizedEvent.pressure;
  20512. event.tangentialPressure = normalizedEvent.tangentialPressure;
  20513. event.tiltX = normalizedEvent.tiltX;
  20514. event.tiltY = normalizedEvent.tiltY;
  20515. event.twist = normalizedEvent.twist;
  20516. this.transferMouseData(event, normalizedEvent);
  20517. var _this$getViewportXY = this.getViewportXY(normalizedEvent),
  20518. x = _this$getViewportXY.x,
  20519. y = _this$getViewportXY.y;
  20520. event.viewport.x = x;
  20521. event.viewport.y = y;
  20522. var _this$context$eventSe = this.context.eventService.viewport2Canvas(event.viewport),
  20523. canvasX = _this$context$eventSe.x,
  20524. canvasY = _this$context$eventSe.y;
  20525. event.canvas.x = canvasX;
  20526. event.canvas.y = canvasY;
  20527. event.global.copyFrom(event.canvas);
  20528. event.offset.copyFrom(event.canvas);
  20529. event.isTrusted = nativeEvent.isTrusted;
  20530. if (event.type === 'pointerleave') {
  20531. event.type = 'pointerout';
  20532. }
  20533. if (event.type.startsWith('mouse')) {
  20534. event.type = event.type.replace('mouse', 'pointer');
  20535. }
  20536. if (event.type.startsWith('touch')) {
  20537. event.type = TOUCH_TO_POINTER[event.type] || event.type;
  20538. }
  20539. return event;
  20540. };
  20541. _proto.normalizeWheelEvent = function normalizeWheelEvent(nativeEvent) {
  20542. var event = this.rootWheelEvent;
  20543. this.transferMouseData(event, nativeEvent);
  20544. event.deltaMode = nativeEvent.deltaMode;
  20545. event.deltaX = nativeEvent.deltaX;
  20546. event.deltaY = nativeEvent.deltaY;
  20547. event.deltaZ = nativeEvent.deltaZ;
  20548. var _this$getViewportXY2 = this.getViewportXY(nativeEvent),
  20549. x = _this$getViewportXY2.x,
  20550. y = _this$getViewportXY2.y;
  20551. event.viewport.x = x;
  20552. event.viewport.y = y;
  20553. var _this$context$eventSe2 = this.context.eventService.viewport2Canvas(event.viewport),
  20554. canvasX = _this$context$eventSe2.x,
  20555. canvasY = _this$context$eventSe2.y;
  20556. event.canvas.x = canvasX;
  20557. event.canvas.y = canvasY;
  20558. event.global.copyFrom(event.canvas);
  20559. event.offset.copyFrom(event.canvas);
  20560. event.nativeEvent = nativeEvent;
  20561. event.type = nativeEvent.type;
  20562. return event;
  20563. }
  20564. /**
  20565. * Transfers base & mouse event data from the nativeEvent to the federated event.
  20566. */;
  20567. _proto.transferMouseData = function transferMouseData(event, nativeEvent) {
  20568. event.isTrusted = nativeEvent.isTrusted;
  20569. event.srcElement = nativeEvent.srcElement;
  20570. event.timeStamp = performance.now();
  20571. event.type = nativeEvent.type;
  20572. event.altKey = nativeEvent.altKey;
  20573. event.metaKey = nativeEvent.metaKey;
  20574. event.shiftKey = nativeEvent.shiftKey;
  20575. event.ctrlKey = nativeEvent.ctrlKey;
  20576. event.button = nativeEvent.button;
  20577. event.buttons = nativeEvent.buttons;
  20578. event.client.x = nativeEvent.clientX;
  20579. event.client.y = nativeEvent.clientY;
  20580. event.movement.x = nativeEvent.movementX;
  20581. event.movement.y = nativeEvent.movementY;
  20582. event.page.x = nativeEvent.pageX;
  20583. event.page.y = nativeEvent.pageY;
  20584. event.screen.x = nativeEvent.screenX;
  20585. event.screen.y = nativeEvent.screenY;
  20586. event.relatedTarget = null;
  20587. };
  20588. _proto.setCursor = function setCursor(cursor) {
  20589. this.context.contextService.applyCursorStyle(cursor || this.context.config.cursor || 'default');
  20590. };
  20591. _proto.normalizeToPointerEvent = function normalizeToPointerEvent(event, canvas) {
  20592. var normalizedEvents = [];
  20593. if (canvas.isTouchEvent(event)) {
  20594. for (var i = 0; i < event.changedTouches.length; i++) {
  20595. var touch = event.changedTouches[i];
  20596. // use changedTouches instead of touches since touchend has no touches
  20597. // @see https://stackoverflow.com/a/10079076
  20598. if (isUndefined(touch.button)) touch.button = 0;
  20599. if (isUndefined(touch.buttons)) touch.buttons = 1;
  20600. if (isUndefined(touch.isPrimary)) {
  20601. touch.isPrimary = event.touches.length === 1 && event.type === 'touchstart';
  20602. }
  20603. if (isUndefined(touch.width)) touch.width = touch.radiusX || 1;
  20604. if (isUndefined(touch.height)) touch.height = touch.radiusY || 1;
  20605. if (isUndefined(touch.tiltX)) touch.tiltX = 0;
  20606. if (isUndefined(touch.tiltY)) touch.tiltY = 0;
  20607. if (isUndefined(touch.pointerType)) touch.pointerType = 'touch';
  20608. // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Touch/identifier
  20609. if (isUndefined(touch.pointerId)) touch.pointerId = touch.identifier || 0;
  20610. if (isUndefined(touch.pressure)) touch.pressure = touch.force || 0.5;
  20611. if (isUndefined(touch.twist)) touch.twist = 0;
  20612. if (isUndefined(touch.tangentialPressure)) touch.tangentialPressure = 0;
  20613. touch.isNormalized = true;
  20614. touch.type = event.type;
  20615. normalizedEvents.push(touch);
  20616. }
  20617. } else if (canvas.isMouseEvent(event)) {
  20618. var tempEvent = event;
  20619. if (isUndefined(tempEvent.isPrimary)) tempEvent.isPrimary = true;
  20620. if (isUndefined(tempEvent.width)) tempEvent.width = 1;
  20621. if (isUndefined(tempEvent.height)) tempEvent.height = 1;
  20622. if (isUndefined(tempEvent.tiltX)) tempEvent.tiltX = 0;
  20623. if (isUndefined(tempEvent.tiltY)) tempEvent.tiltY = 0;
  20624. if (isUndefined(tempEvent.pointerType)) tempEvent.pointerType = 'mouse';
  20625. if (isUndefined(tempEvent.pointerId)) tempEvent.pointerId = MOUSE_POINTER_ID;
  20626. if (isUndefined(tempEvent.pressure)) tempEvent.pressure = 0.5;
  20627. if (isUndefined(tempEvent.twist)) tempEvent.twist = 0;
  20628. if (isUndefined(tempEvent.tangentialPressure)) tempEvent.tangentialPressure = 0;
  20629. tempEvent.isNormalized = true;
  20630. normalizedEvents.push(tempEvent);
  20631. } else {
  20632. normalizedEvents.push(event);
  20633. }
  20634. return normalizedEvents;
  20635. };
  20636. return EventPlugin;
  20637. }();
  20638. EventPlugin.tag = 'Event';
  20639. // group is not a 2d shape
  20640. var shape2D = [exports.Shape.CIRCLE, exports.Shape.ELLIPSE, exports.Shape.IMAGE, exports.Shape.RECT, exports.Shape.LINE, exports.Shape.POLYLINE, exports.Shape.POLYGON, exports.Shape.TEXT, exports.Shape.PATH, exports.Shape.HTML];
  20641. var FrustumCullingStrategy = /*#__PURE__*/function () {
  20642. function FrustumCullingStrategy() {}
  20643. var _proto = FrustumCullingStrategy.prototype;
  20644. _proto.isVisible = function isVisible(camera, object) {
  20645. var _object$parentNode, _object$parentNode$cu;
  20646. // return true;
  20647. var cullable = object.cullable;
  20648. if (!cullable.enable) {
  20649. return true;
  20650. }
  20651. var renderBounds = object.getRenderBounds();
  20652. if (AABB.isEmpty(renderBounds)) {
  20653. return false;
  20654. }
  20655. // get VP matrix from camera
  20656. var frustum = camera.getFrustum();
  20657. var parentVisibilityPlaneMask = (_object$parentNode = object.parentNode) === null || _object$parentNode === void 0 ? void 0 : (_object$parentNode$cu = _object$parentNode.cullable) === null || _object$parentNode$cu === void 0 ? void 0 : _object$parentNode$cu.visibilityPlaneMask;
  20658. cullable.visibilityPlaneMask = this.computeVisibilityWithPlaneMask(object, renderBounds, parentVisibilityPlaneMask || exports.Mask.INDETERMINATE, frustum.planes);
  20659. cullable.visible = cullable.visibilityPlaneMask !== exports.Mask.OUTSIDE;
  20660. return cullable.visible;
  20661. }
  20662. /**
  20663. *
  20664. * @see「Optimized View Frustum Culling Algorithms for Bounding Boxes」
  20665. * @see https://github.com/antvis/GWebGPUEngine/issues/3
  20666. *
  20667. * * 基础相交测试 the basic intersection test
  20668. * * 标记 masking @see https://cesium.com/blog/2015/08/04/fast-hierarchical-culling/
  20669. * * TODO: 平面一致性测试 the plane-coherency test
  20670. * * TODO: 支持 mesh 指定自身的剔除策略,参考 Babylon.js @see https://doc.babylonjs.com/how_to/optimizing_your_scene#changing-mesh-culling-strategy
  20671. *
  20672. * @param aabb aabb
  20673. * @param parentPlaneMask mask of parent
  20674. * @param planes planes of frustum
  20675. */;
  20676. _proto.computeVisibilityWithPlaneMask = function computeVisibilityWithPlaneMask(object, aabb, parentPlaneMask, planes) {
  20677. if (parentPlaneMask === exports.Mask.OUTSIDE || parentPlaneMask === exports.Mask.INSIDE) {
  20678. // 父节点完全位于视锥内或者外部,直接返回
  20679. return parentPlaneMask;
  20680. }
  20681. // Start with MASK_INSIDE (all zeros) so that after the loop, the return value can be compared with MASK_INSIDE.
  20682. // (Because if there are fewer than 31 planes, the upper bits wont be changed.)
  20683. var mask = exports.Mask.INSIDE;
  20684. var isShape2D = shape2D.indexOf(object.nodeName) > -1;
  20685. // Use viewport culling for 2D shapes
  20686. // @see https://github.com/antvis/g/issues/914
  20687. for (var k = 0, len = planes.length; k < len; ++k) {
  20688. // For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.
  20689. var flag = 1 << k;
  20690. if ((parentPlaneMask & flag) === 0) {
  20691. // 父节点处于当前面内部,可以跳过
  20692. continue;
  20693. }
  20694. // skip near & far planes when testing 2D shapes
  20695. if (isShape2D && (k === 4 || k === 5)) {
  20696. continue;
  20697. }
  20698. // p-vertex n-vertex <-|plane p-vertex n-vertex
  20699. // 使用 p-vertex 和 n-vertex 加速,避免进行平面和 aabb 全部顶点的相交检测
  20700. var _planes$k = planes[k],
  20701. normal = _planes$k.normal,
  20702. distance = _planes$k.distance;
  20703. if (dot(normal, aabb.getPositiveFarPoint(planes[k])) + distance < 0) {
  20704. return exports.Mask.OUTSIDE;
  20705. }
  20706. if (dot(normal, aabb.getNegativeFarPoint(planes[k])) + distance < 0) {
  20707. // 和当前面相交,对应位置为1,继续检测下一个面
  20708. mask |= flag;
  20709. }
  20710. }
  20711. return mask;
  20712. };
  20713. return FrustumCullingStrategy;
  20714. }();
  20715. var PrepareRendererPlugin = /*#__PURE__*/function () {
  20716. function PrepareRendererPlugin() {
  20717. this.rBush = void 0;
  20718. /**
  20719. * sync to RBush later
  20720. */
  20721. this.toSync = new Set();
  20722. }
  20723. var _proto = PrepareRendererPlugin.prototype;
  20724. // private isFirstTimeRendering = true;
  20725. // private syncing = false;
  20726. _proto.apply = function apply(context) {
  20727. var _this = this;
  20728. var renderingService = context.renderingService,
  20729. renderingContext = context.renderingContext,
  20730. rBushRoot = context.rBushRoot;
  20731. var canvas = renderingContext.root.ownerDocument.defaultView;
  20732. this.rBush = rBushRoot;
  20733. var handleAttributeChanged = function handleAttributeChanged(e) {
  20734. var object = e.target;
  20735. object.renderable.dirty = true;
  20736. renderingService.dirtify();
  20737. };
  20738. var handleBoundsChanged = function handleBoundsChanged(e) {
  20739. var affectChildren = e.detail.affectChildren;
  20740. var object = e.target;
  20741. if (affectChildren) {
  20742. object.forEach(function (node) {
  20743. _this.toSync.add(node);
  20744. });
  20745. }
  20746. var p = object;
  20747. while (p) {
  20748. if (p.renderable) {
  20749. _this.toSync.add(p);
  20750. }
  20751. p = p.parentElement;
  20752. }
  20753. // this.pushToSync(e.composedPath().slice(0, -2) as DisplayObject[]);
  20754. renderingService.dirtify();
  20755. };
  20756. var handleMounted = function handleMounted(e) {
  20757. var object = e.target;
  20758. if (runtime.enableCSSParsing) {
  20759. // recalc style values
  20760. runtime.styleValueRegistry.recalc(object);
  20761. }
  20762. runtime.sceneGraphService.dirtifyToRoot(object);
  20763. renderingService.dirtify();
  20764. };
  20765. var handleUnmounted = function handleUnmounted(e) {
  20766. var object = e.target;
  20767. var rBushNode = object.rBushNode;
  20768. if (rBushNode.aabb) {
  20769. _this.rBush.remove(rBushNode.aabb);
  20770. }
  20771. _this.toSync.delete(object);
  20772. runtime.sceneGraphService.dirtifyToRoot(object);
  20773. renderingService.dirtify();
  20774. };
  20775. renderingService.hooks.init.tap(PrepareRendererPlugin.tag, function () {
  20776. canvas.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
  20777. canvas.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
  20778. canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
  20779. canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
  20780. });
  20781. renderingService.hooks.destroy.tap(PrepareRendererPlugin.tag, function () {
  20782. canvas.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
  20783. canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
  20784. canvas.removeEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
  20785. canvas.removeEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
  20786. _this.toSync.clear();
  20787. });
  20788. renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
  20789. // if (this.isFirstTimeRendering) {
  20790. // this.isFirstTimeRendering = false;
  20791. // this.syncing = true;
  20792. // // @see https://github.com/antvis/G/issues/1117
  20793. // setTimeout(() => {
  20794. // this.syncRTree();
  20795. // console.log('fcp...');
  20796. // });
  20797. // } else {
  20798. // console.log('next...');
  20799. _this.syncRTree();
  20800. // }
  20801. });
  20802. };
  20803. _proto.syncRTree = function syncRTree() {
  20804. var _this2 = this;
  20805. // if (this.syncing) {
  20806. // return;
  20807. // }
  20808. // bounds changed, need re-inserting its children
  20809. var bulk = [];
  20810. Array.from(this.toSync)
  20811. // some objects may be removed since last frame
  20812. .filter(function (object) {
  20813. return object.isConnected;
  20814. }).forEach(function (node) {
  20815. var rBushNode = node.rBushNode;
  20816. // clear dirty node
  20817. if (rBushNode && rBushNode.aabb) {
  20818. _this2.rBush.remove(rBushNode.aabb);
  20819. }
  20820. var renderBounds = node.getRenderBounds();
  20821. if (renderBounds) {
  20822. var _renderBounds$getMin = renderBounds.getMin(),
  20823. minX = _renderBounds$getMin[0],
  20824. minY = _renderBounds$getMin[1];
  20825. var _renderBounds$getMax = renderBounds.getMax(),
  20826. maxX = _renderBounds$getMax[0],
  20827. maxY = _renderBounds$getMax[1];
  20828. if (!rBushNode.aabb) {
  20829. rBushNode.aabb = {};
  20830. }
  20831. rBushNode.aabb.displayObject = node;
  20832. rBushNode.aabb.minX = minX;
  20833. rBushNode.aabb.minY = minY;
  20834. rBushNode.aabb.maxX = maxX;
  20835. rBushNode.aabb.maxY = maxY;
  20836. }
  20837. if (rBushNode.aabb) {
  20838. // TODO: NaN occurs when width/height of Rect is 0
  20839. if (!isNaN(rBushNode.aabb.maxX) && !isNaN(rBushNode.aabb.maxX) && !isNaN(rBushNode.aabb.minX) && !isNaN(rBushNode.aabb.minY)) {
  20840. bulk.push(rBushNode.aabb);
  20841. }
  20842. }
  20843. });
  20844. // use bulk inserting, which is ~2-3 times faster
  20845. // @see https://github.com/mourner/rbush#bulk-inserting-data
  20846. this.rBush.load(bulk);
  20847. bulk.length = 0;
  20848. this.toSync.clear();
  20849. // this.syncing = false;
  20850. };
  20851. return PrepareRendererPlugin;
  20852. }();
  20853. PrepareRendererPlugin.tag = 'Prepare';
  20854. function isCanvas(value) {
  20855. return !!value.document;
  20856. }
  20857. (function (CanvasEvent) {
  20858. CanvasEvent["READY"] = "ready";
  20859. CanvasEvent["BEFORE_RENDER"] = "beforerender";
  20860. CanvasEvent["RERENDER"] = "rerender";
  20861. CanvasEvent["AFTER_RENDER"] = "afterrender";
  20862. CanvasEvent["BEFORE_DESTROY"] = "beforedestroy";
  20863. CanvasEvent["AFTER_DESTROY"] = "afterdestroy";
  20864. CanvasEvent["RESIZE"] = "resize";
  20865. CanvasEvent["DIRTY_RECTANGLE"] = "dirtyrectangle";
  20866. CanvasEvent["RENDERER_CHANGED"] = "rendererchanged";
  20867. })(exports.CanvasEvent || (exports.CanvasEvent = {}));
  20868. var DEFAULT_CAMERA_Z = 500;
  20869. var DEFAULT_CAMERA_NEAR = 0.1;
  20870. var DEFAULT_CAMERA_FAR = 1000;
  20871. /**
  20872. * reuse custom event preventing from re-create them in every frame
  20873. */
  20874. var mountedEvent = new CustomEvent(exports.ElementEvent.MOUNTED);
  20875. var unmountedEvent = new CustomEvent(exports.ElementEvent.UNMOUNTED);
  20876. var beforeRenderEvent = new CustomEvent(exports.CanvasEvent.BEFORE_RENDER);
  20877. var rerenderEvent = new CustomEvent(exports.CanvasEvent.RERENDER);
  20878. var afterRenderEvent = new CustomEvent(exports.CanvasEvent.AFTER_RENDER);
  20879. /**
  20880. * can be treated like Window in DOM
  20881. * provide some extra methods like `window`, such as:
  20882. * * `window.requestAnimationFrame`
  20883. * * `window.devicePixelRatio`
  20884. *
  20885. * prototype chains: Canvas(Window) -> EventTarget
  20886. */
  20887. var Canvas = /*#__PURE__*/function (_EventTarget) {
  20888. _inheritsLoose(Canvas, _EventTarget);
  20889. function Canvas(config) {
  20890. var _this;
  20891. _this = _EventTarget.call(this) || this;
  20892. // create document
  20893. /**
  20894. * window.document
  20895. */
  20896. _this.document = void 0;
  20897. /**
  20898. * @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry
  20899. */
  20900. _this.customElements = void 0;
  20901. /**
  20902. * @see https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
  20903. */
  20904. _this.requestAnimationFrame = void 0;
  20905. /**
  20906. * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame
  20907. */
  20908. _this.cancelAnimationFrame = void 0;
  20909. /**
  20910. * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio
  20911. */
  20912. _this.devicePixelRatio = void 0;
  20913. /**
  20914. * whether the runtime supports PointerEvent?
  20915. * if not, the event system won't trigger pointer events like `pointerdown`
  20916. */
  20917. _this.supportsPointerEvents = void 0;
  20918. /**
  20919. * whether the runtime supports TouchEvent?
  20920. * if not, the event system won't trigger touch events like `touchstart`
  20921. */
  20922. _this.supportsTouchEvents = void 0;
  20923. /**
  20924. * is this native event a TouchEvent?
  20925. */
  20926. _this.isTouchEvent = void 0;
  20927. /**
  20928. * is this native event a MouseEvent?
  20929. */
  20930. _this.isMouseEvent = void 0;
  20931. /**
  20932. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element
  20933. */
  20934. _this.Element = DisplayObject;
  20935. /**
  20936. * rAF in auto rendering
  20937. */
  20938. _this.frameId = void 0;
  20939. _this.inited = false;
  20940. _this.readyPromise = void 0;
  20941. _this.resolveReadyPromise = void 0;
  20942. _this.context = {};
  20943. _this.document = new Document();
  20944. _this.document.defaultView = _assertThisInitialized(_this);
  20945. // create registry of custom elements
  20946. _this.customElements = new CustomElementRegistry();
  20947. var container = config.container,
  20948. canvas = config.canvas,
  20949. offscreenCanvas = config.offscreenCanvas,
  20950. width = config.width,
  20951. height = config.height,
  20952. devicePixelRatio = config.devicePixelRatio,
  20953. renderer = config.renderer,
  20954. background = config.background,
  20955. cursor = config.cursor,
  20956. document = config.document,
  20957. requestAnimationFrame = config.requestAnimationFrame,
  20958. cancelAnimationFrame = config.cancelAnimationFrame,
  20959. createImage = config.createImage,
  20960. supportsPointerEvents = config.supportsPointerEvents,
  20961. supportsTouchEvents = config.supportsTouchEvents,
  20962. supportsCSSTransform = config.supportsCSSTransform,
  20963. useNativeClickEvent = config.useNativeClickEvent,
  20964. alwaysTriggerPointerEventOnCanvas = config.alwaysTriggerPointerEventOnCanvas,
  20965. isTouchEvent = config.isTouchEvent,
  20966. isMouseEvent = config.isMouseEvent;
  20967. cleanExistedCanvas(container, _assertThisInitialized(_this));
  20968. var canvasWidth = width;
  20969. var canvasHeight = height;
  20970. var dpr = devicePixelRatio;
  20971. // use user-defined <canvas> or OffscreenCanvas
  20972. if (canvas) {
  20973. // infer width & height with dpr
  20974. dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
  20975. dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
  20976. canvasWidth = width || getWidth(canvas) || canvas.width / dpr;
  20977. canvasHeight = height || getHeight(canvas) || canvas.height / dpr;
  20978. }
  20979. /**
  20980. * implements `Window` interface
  20981. */
  20982. _this.devicePixelRatio = dpr;
  20983. _this.requestAnimationFrame = requestAnimationFrame !== null && requestAnimationFrame !== void 0 ? requestAnimationFrame : raf.bind(runtime.globalThis);
  20984. _this.cancelAnimationFrame = cancelAnimationFrame !== null && cancelAnimationFrame !== void 0 ? cancelAnimationFrame : caf.bind(runtime.globalThis);
  20985. /**
  20986. * limits query
  20987. */
  20988. // the following feature-detect from hammer.js
  20989. // @see https://github.com/hammerjs/hammer.js/blob/master/src/inputjs/input-consts.js#L5
  20990. _this.supportsTouchEvents = supportsTouchEvents !== null && supportsTouchEvents !== void 0 ? supportsTouchEvents : 'ontouchstart' in runtime.globalThis;
  20991. _this.supportsPointerEvents = supportsPointerEvents !== null && supportsPointerEvents !== void 0 ? supportsPointerEvents : !!runtime.globalThis.PointerEvent;
  20992. _this.isTouchEvent = isTouchEvent !== null && isTouchEvent !== void 0 ? isTouchEvent : function (event) {
  20993. return _this.supportsTouchEvents && event instanceof runtime.globalThis.TouchEvent;
  20994. };
  20995. _this.isMouseEvent = isMouseEvent !== null && isMouseEvent !== void 0 ? isMouseEvent : function (event) {
  20996. return !runtime.globalThis.MouseEvent || event instanceof runtime.globalThis.MouseEvent && (!_this.supportsPointerEvents || !(event instanceof runtime.globalThis.PointerEvent));
  20997. };
  20998. _this.initRenderingContext({
  20999. container: container,
  21000. canvas: canvas,
  21001. width: canvasWidth,
  21002. height: canvasHeight,
  21003. renderer: renderer,
  21004. offscreenCanvas: offscreenCanvas,
  21005. devicePixelRatio: dpr,
  21006. cursor: cursor || 'default',
  21007. background: background || 'transparent',
  21008. createImage: createImage,
  21009. document: document,
  21010. supportsCSSTransform: supportsCSSTransform,
  21011. useNativeClickEvent: useNativeClickEvent,
  21012. alwaysTriggerPointerEventOnCanvas: alwaysTriggerPointerEventOnCanvas
  21013. });
  21014. _this.initDefaultCamera(canvasWidth, canvasHeight);
  21015. _this.initRenderer(renderer, true);
  21016. return _this;
  21017. }
  21018. var _proto = Canvas.prototype;
  21019. _proto.initRenderingContext = function initRenderingContext(mergedConfig) {
  21020. this.context.config = mergedConfig;
  21021. // bind rendering context, shared by all renderers
  21022. this.context.renderingContext = {
  21023. /**
  21024. * the root node in scene graph
  21025. */
  21026. root: this.document.documentElement,
  21027. renderListCurrentFrame: [],
  21028. unculledEntities: [],
  21029. renderReasons: new Set(),
  21030. force: false,
  21031. dirty: false
  21032. };
  21033. };
  21034. _proto.initDefaultCamera = function initDefaultCamera(width, height) {
  21035. var _this2 = this;
  21036. // set a default ortho camera
  21037. var camera = new runtime.CameraContribution();
  21038. camera.setType(exports.CameraType.EXPLORING, exports.CameraTrackingMode.DEFAULT).setPosition(width / 2, height / 2, DEFAULT_CAMERA_Z).setFocalPoint(width / 2, height / 2, 0).setOrthographic(width / -2, width / 2, height / 2, height / -2, DEFAULT_CAMERA_NEAR, DEFAULT_CAMERA_FAR);
  21039. // keep ref since it will use raf in camera animation
  21040. camera.canvas = this;
  21041. // redraw when camera changed
  21042. camera.eventEmitter.on(CameraEvent.UPDATED, function () {
  21043. _this2.context.renderingContext.renderReasons.add(exports.RenderReason.CAMERA_CHANGED);
  21044. });
  21045. // bind camera
  21046. this.context.camera = camera;
  21047. };
  21048. _proto.getConfig = function getConfig() {
  21049. return this.context.config;
  21050. }
  21051. /**
  21052. * get the root displayObject in scenegraph
  21053. * @alias this.document.documentElement
  21054. */;
  21055. _proto.getRoot = function getRoot() {
  21056. return this.document.documentElement;
  21057. }
  21058. /**
  21059. * get the camera of canvas
  21060. */;
  21061. _proto.getCamera = function getCamera() {
  21062. return this.context.camera;
  21063. };
  21064. _proto.getContextService = function getContextService() {
  21065. return this.context.contextService;
  21066. };
  21067. _proto.getEventService = function getEventService() {
  21068. return this.context.eventService;
  21069. };
  21070. _proto.getRenderingService = function getRenderingService() {
  21071. return this.context.renderingService;
  21072. };
  21073. _proto.getRenderingContext = function getRenderingContext() {
  21074. return this.context.renderingContext;
  21075. };
  21076. _proto.getStats = function getStats() {
  21077. return this.getRenderingService().getStats();
  21078. }
  21079. // /**
  21080. // * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getComputedStyle
  21081. // */
  21082. // getComputedStyle(node: DisplayObject) {
  21083. // return node.computedStyle;
  21084. // }
  21085. ;
  21086. /**
  21087. * `cleanUp` means clean all the internal services of Canvas which happens when calling `canvas.destroy()`.
  21088. */
  21089. _proto.destroy = function destroy(cleanUp, skipTriggerEvent) {
  21090. if (cleanUp === void 0) {
  21091. cleanUp = true;
  21092. }
  21093. if (skipTriggerEvent === void 0) {
  21094. skipTriggerEvent = false;
  21095. }
  21096. if (!skipTriggerEvent) {
  21097. this.dispatchEvent(new CustomEvent(exports.CanvasEvent.BEFORE_DESTROY));
  21098. }
  21099. if (this.frameId) {
  21100. var cancelRAF = this.getConfig().cancelAnimationFrame || cancelAnimationFrame;
  21101. cancelRAF(this.frameId);
  21102. }
  21103. // unmount all children
  21104. var root = this.getRoot();
  21105. this.unmountChildren(root);
  21106. if (cleanUp) {
  21107. // destroy Document
  21108. this.document.destroy();
  21109. this.getEventService().destroy();
  21110. }
  21111. // destroy services
  21112. this.getRenderingService().destroy();
  21113. this.getContextService().destroy();
  21114. // clear root after renderservice destroyed
  21115. if (cleanUp && this.context.rBushRoot) {
  21116. // clear rbush
  21117. this.context.rBushRoot.clear();
  21118. this.context.rBushRoot = null;
  21119. this.context.renderingContext.root = null;
  21120. }
  21121. if (!skipTriggerEvent) {
  21122. this.dispatchEvent(new CustomEvent(exports.CanvasEvent.AFTER_DESTROY));
  21123. }
  21124. }
  21125. /**
  21126. * compatible with G 3.0
  21127. * @deprecated
  21128. * @alias resize
  21129. */;
  21130. _proto.changeSize = function changeSize(width, height) {
  21131. this.resize(width, height);
  21132. };
  21133. _proto.resize = function resize(width, height) {
  21134. // update canvas' config
  21135. var canvasConfig = this.context.config;
  21136. canvasConfig.width = width;
  21137. canvasConfig.height = height;
  21138. // resize context
  21139. this.getContextService().resize(width, height);
  21140. // resize camera
  21141. var camera = this.context.camera;
  21142. var projectionMode = camera.getProjectionMode();
  21143. camera.setPosition(width / 2, height / 2, DEFAULT_CAMERA_Z).setFocalPoint(width / 2, height / 2, 0);
  21144. if (projectionMode === exports.CameraProjectionMode.ORTHOGRAPHIC) {
  21145. camera.setOrthographic(width / -2, width / 2, height / 2, height / -2, camera.getNear(), camera.getFar());
  21146. } else {
  21147. camera.setAspect(width / height);
  21148. }
  21149. this.dispatchEvent(new CustomEvent(exports.CanvasEvent.RESIZE, {
  21150. width: width,
  21151. height: height
  21152. }));
  21153. }
  21154. // proxy to document.documentElement
  21155. ;
  21156. _proto.appendChild = function appendChild(child, index) {
  21157. return this.document.documentElement.appendChild(child, index);
  21158. };
  21159. _proto.insertBefore = function insertBefore(newChild, refChild) {
  21160. return this.document.documentElement.insertBefore(newChild, refChild);
  21161. };
  21162. _proto.removeChild = function removeChild(child) {
  21163. return this.document.documentElement.removeChild(child);
  21164. }
  21165. /**
  21166. * Remove all children which can be appended to its original parent later again.
  21167. */;
  21168. _proto.removeChildren = function removeChildren() {
  21169. this.document.documentElement.removeChildren();
  21170. }
  21171. /**
  21172. * Recursively destroy all children which can not be appended to its original parent later again.
  21173. * But the canvas remains running which means display objects can be appended later.
  21174. */;
  21175. _proto.destroyChildren = function destroyChildren() {
  21176. this.document.documentElement.destroyChildren();
  21177. };
  21178. _proto.render = function render() {
  21179. var _this3 = this;
  21180. this.dispatchEvent(beforeRenderEvent);
  21181. var renderingService = this.getRenderingService();
  21182. renderingService.render(this.getConfig(), function () {
  21183. // trigger actual rerender event
  21184. // @see https://github.com/antvis/G/issues/1268
  21185. _this3.dispatchEvent(rerenderEvent);
  21186. });
  21187. this.dispatchEvent(afterRenderEvent);
  21188. };
  21189. _proto.run = function run() {
  21190. var _this4 = this;
  21191. var tick = function tick() {
  21192. _this4.render();
  21193. _this4.frameId = _this4.requestAnimationFrame(tick);
  21194. };
  21195. tick();
  21196. };
  21197. _proto.initRenderer = function initRenderer(renderer, firstContentfullPaint) {
  21198. var _this5 = this;
  21199. if (firstContentfullPaint === void 0) {
  21200. firstContentfullPaint = false;
  21201. }
  21202. if (!renderer) {
  21203. throw new Error('Renderer is required.');
  21204. }
  21205. // reset
  21206. this.inited = false;
  21207. this.readyPromise = undefined;
  21208. // FIXME: should re-create here?
  21209. this.context.rBushRoot = new rbush();
  21210. // reset rendering plugins
  21211. this.context.renderingPlugins = [];
  21212. this.context.renderingPlugins.push(new EventPlugin(), new PrepareRendererPlugin(), new DirtyCheckPlugin(), new CullingPlugin([new FrustumCullingStrategy()]));
  21213. //
  21214. this.loadRendererContainerModule(renderer);
  21215. // init context service
  21216. this.context.contextService = new this.context.ContextService(_extends({}, runtime, this.context));
  21217. // init rendering service
  21218. this.context.renderingService = new RenderingService(runtime, this.context);
  21219. // init event service
  21220. this.context.eventService = new EventService(runtime, this.context);
  21221. this.context.eventService.init();
  21222. if (this.context.contextService.init) {
  21223. this.context.contextService.init();
  21224. this.initRenderingService(renderer, firstContentfullPaint, true);
  21225. } else {
  21226. this.context.contextService.initAsync().then(function () {
  21227. _this5.initRenderingService(renderer, firstContentfullPaint);
  21228. });
  21229. }
  21230. };
  21231. _proto.initRenderingService = function initRenderingService(renderer, firstContentfullPaint, async) {
  21232. var _this6 = this;
  21233. if (firstContentfullPaint === void 0) {
  21234. firstContentfullPaint = false;
  21235. }
  21236. if (async === void 0) {
  21237. async = false;
  21238. }
  21239. this.context.renderingService.init(function () {
  21240. _this6.inited = true;
  21241. if (firstContentfullPaint) {
  21242. if (async) {
  21243. _this6.requestAnimationFrame(function () {
  21244. _this6.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
  21245. });
  21246. } else {
  21247. _this6.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
  21248. }
  21249. if (_this6.readyPromise) {
  21250. _this6.resolveReadyPromise();
  21251. }
  21252. } else {
  21253. _this6.dispatchEvent(new CustomEvent(exports.CanvasEvent.RENDERER_CHANGED));
  21254. }
  21255. if (!firstContentfullPaint) {
  21256. _this6.getRoot().forEach(function (node) {
  21257. var renderable = node.renderable;
  21258. if (renderable) {
  21259. renderable.renderBoundsDirty = true;
  21260. renderable.boundsDirty = true;
  21261. renderable.dirty = true;
  21262. }
  21263. });
  21264. }
  21265. // keep current scenegraph unchanged, just trigger mounted event
  21266. _this6.mountChildren(_this6.getRoot());
  21267. if (renderer.getConfig().enableAutoRendering) {
  21268. _this6.run();
  21269. }
  21270. });
  21271. };
  21272. _proto.loadRendererContainerModule = function loadRendererContainerModule(renderer) {
  21273. var _this7 = this;
  21274. // load other container modules provided by g-canvas/g-svg/g-webgl
  21275. var plugins = renderer.getPlugins();
  21276. plugins.forEach(function (plugin) {
  21277. plugin.context = _this7.context;
  21278. plugin.init(runtime);
  21279. });
  21280. };
  21281. _proto.setRenderer = function setRenderer(renderer) {
  21282. // update canvas' config
  21283. var canvasConfig = this.getConfig();
  21284. if (canvasConfig.renderer === renderer) {
  21285. return;
  21286. }
  21287. var oldRenderer = canvasConfig.renderer;
  21288. canvasConfig.renderer = renderer;
  21289. // keep all children undestroyed
  21290. this.destroy(false, true);
  21291. // destroy all plugins, reverse will mutate origin array
  21292. [].concat(oldRenderer === null || oldRenderer === void 0 ? void 0 : oldRenderer.getPlugins()).reverse().forEach(function (plugin) {
  21293. plugin.destroy(runtime);
  21294. });
  21295. this.initRenderer(renderer);
  21296. };
  21297. _proto.setCursor = function setCursor(cursor) {
  21298. var canvasConfig = this.getConfig();
  21299. canvasConfig.cursor = cursor;
  21300. this.getContextService().applyCursorStyle(cursor);
  21301. };
  21302. _proto.unmountChildren = function unmountChildren(parent) {
  21303. var _this8 = this;
  21304. // unmountChildren recursively
  21305. parent.childNodes.forEach(function (child) {
  21306. _this8.unmountChildren(child);
  21307. });
  21308. if (this.inited) {
  21309. if (parent.isMutationObserved) {
  21310. parent.dispatchEvent(unmountedEvent);
  21311. } else {
  21312. unmountedEvent.target = parent;
  21313. this.dispatchEvent(unmountedEvent, true);
  21314. }
  21315. // skip document.documentElement
  21316. if (parent !== this.document.documentElement) {
  21317. parent.ownerDocument = null;
  21318. }
  21319. parent.isConnected = false;
  21320. }
  21321. // trigger after unmounted
  21322. if (parent.isCustomElement) {
  21323. if (parent.disconnectedCallback) {
  21324. parent.disconnectedCallback();
  21325. }
  21326. }
  21327. };
  21328. _proto.mountChildren = function mountChildren(parent) {
  21329. var _this9 = this;
  21330. if (this.inited) {
  21331. if (!parent.isConnected) {
  21332. parent.ownerDocument = this.document;
  21333. parent.isConnected = true;
  21334. if (parent.isMutationObserved) {
  21335. parent.dispatchEvent(mountedEvent);
  21336. } else {
  21337. mountedEvent.target = parent;
  21338. this.dispatchEvent(mountedEvent, true);
  21339. }
  21340. }
  21341. } else {
  21342. console.warn("[g]: You are trying to call `canvas.appendChild` before canvas' initialization finished. You can either await `canvas.ready` or listen to `CanvasEvent.READY` manually.", 'appended child: ', parent.nodeName);
  21343. }
  21344. // recursively mount children
  21345. parent.childNodes.forEach(function (child) {
  21346. _this9.mountChildren(child);
  21347. });
  21348. // trigger after mounted
  21349. if (parent.isCustomElement) {
  21350. if (parent.connectedCallback) {
  21351. parent.connectedCallback();
  21352. }
  21353. }
  21354. };
  21355. _proto.client2Viewport = function client2Viewport(client) {
  21356. return this.getEventService().client2Viewport(client);
  21357. };
  21358. _proto.viewport2Client = function viewport2Client(canvas) {
  21359. return this.getEventService().viewport2Client(canvas);
  21360. };
  21361. _proto.viewport2Canvas = function viewport2Canvas(viewport) {
  21362. return this.getEventService().viewport2Canvas(viewport);
  21363. };
  21364. _proto.canvas2Viewport = function canvas2Viewport(canvas) {
  21365. return this.getEventService().canvas2Viewport(canvas);
  21366. }
  21367. /**
  21368. * @deprecated
  21369. * @alias client2Viewport
  21370. */;
  21371. _proto.getPointByClient = function getPointByClient(clientX, clientY) {
  21372. return this.client2Viewport({
  21373. x: clientX,
  21374. y: clientY
  21375. });
  21376. }
  21377. /**
  21378. * @deprecated
  21379. * @alias viewport2Client
  21380. */;
  21381. _proto.getClientByPoint = function getClientByPoint(x, y) {
  21382. return this.viewport2Client({
  21383. x: x,
  21384. y: y
  21385. });
  21386. };
  21387. _createClass(Canvas, [{
  21388. key: "ready",
  21389. get: function get() {
  21390. var _this10 = this;
  21391. if (!this.readyPromise) {
  21392. this.readyPromise = new Promise(function (resolve) {
  21393. _this10.resolveReadyPromise = function () {
  21394. resolve(_this10);
  21395. };
  21396. });
  21397. if (this.inited) {
  21398. this.resolveReadyPromise();
  21399. }
  21400. }
  21401. return this.readyPromise;
  21402. }
  21403. }]);
  21404. return Canvas;
  21405. }(EventTarget);
  21406. exports.AABB = AABB;
  21407. exports.AbstractRenderer = AbstractRenderer;
  21408. exports.AbstractRendererPlugin = AbstractRendererPlugin;
  21409. exports.BUILT_IN_PROPERTIES = BUILT_IN_PROPERTIES;
  21410. exports.CSS = CSS;
  21411. exports.CSSGradientValue = CSSGradientValue;
  21412. exports.CSSKeywordValue = CSSKeywordValue;
  21413. exports.CSSRGB = CSSRGB;
  21414. exports.CSSStyleValue = CSSStyleValue;
  21415. exports.CSSUnitValue = CSSUnitValue;
  21416. exports.Camera = Camera;
  21417. exports.CameraEvent = CameraEvent;
  21418. exports.Canvas = Canvas;
  21419. exports.Circle = Circle;
  21420. exports.CircleUpdater = CircleUpdater;
  21421. exports.CustomElement = CustomElement;
  21422. exports.CustomElementRegistry = CustomElementRegistry;
  21423. exports.CustomEvent = CustomEvent;
  21424. exports.DefaultSceneGraphSelector = DefaultSceneGraphSelector;
  21425. exports.DefaultSceneGraphService = DefaultSceneGraphService;
  21426. exports.DisplayObject = DisplayObject;
  21427. exports.Document = Document;
  21428. exports.EMPTY_PARSED_PATH = EMPTY_PARSED_PATH;
  21429. exports.ERROR_MSG_METHOD_NOT_IMPLEMENTED = ERROR_MSG_METHOD_NOT_IMPLEMENTED;
  21430. exports.Element = Element;
  21431. exports.Ellipse = Ellipse;
  21432. exports.EllipseUpdater = EllipseUpdater;
  21433. exports.EventService = EventService;
  21434. exports.EventTarget = EventTarget;
  21435. exports.FederatedEvent = FederatedEvent;
  21436. exports.FederatedMouseEvent = FederatedMouseEvent;
  21437. exports.FederatedPointerEvent = FederatedPointerEvent;
  21438. exports.FederatedWheelEvent = FederatedWheelEvent;
  21439. exports.Frustum = Frustum;
  21440. exports.Group = Group;
  21441. exports.HTML = HTML;
  21442. exports.Image = Image;
  21443. exports.Line = Line;
  21444. exports.LineUpdater = LineUpdater;
  21445. exports.MutationEvent = MutationEvent;
  21446. exports.Node = Node;
  21447. exports.OffscreenCanvasCreator = OffscreenCanvasCreator;
  21448. exports.Path = Path;
  21449. exports.PathUpdater = PathUpdater;
  21450. exports.Plane = Plane;
  21451. exports.Point = Point;
  21452. exports.Polygon = Polygon;
  21453. exports.Polyline = Polyline;
  21454. exports.PolylineUpdater = PolylineUpdater;
  21455. exports.RBush = rbush;
  21456. exports.Rect = Rect;
  21457. exports.RectUpdater = RectUpdater;
  21458. exports.Rectangle = Rectangle;
  21459. exports.RenderingService = RenderingService;
  21460. exports.Text = Text;
  21461. exports.TextService = TextService;
  21462. exports.TextUpdater = TextUpdater;
  21463. exports.computeLinearGradient = computeLinearGradient;
  21464. exports.computeRadialGradient = computeRadialGradient;
  21465. exports.convertToPath = convertToPath;
  21466. exports.createVec3 = createVec3;
  21467. exports.decompose = decompose;
  21468. exports.definedProps = definedProps;
  21469. exports.deg2rad = deg2rad;
  21470. exports.deg2turn = deg2turn;
  21471. exports.findClosestClipPathTarget = findClosestClipPathTarget;
  21472. exports.fromRotationTranslationScale = fromRotationTranslationScale$1;
  21473. exports.getAngle = getAngle;
  21474. exports.getEuler = getEuler;
  21475. exports.getOrCalculatePathTotalLength = getOrCalculatePathTotalLength;
  21476. exports.grad2deg = grad2deg;
  21477. exports.isBrowser = isBrowser;
  21478. exports.isCSSGradientValue = isCSSGradientValue;
  21479. exports.isCSSRGB = isCSSRGB;
  21480. exports.isCanvas = isCanvas;
  21481. exports.isDisplayObject = isDisplayObject;
  21482. exports.isFederatedEvent = isFederatedEvent;
  21483. exports.isFillOrStrokeAffected = isFillOrStrokeAffected;
  21484. exports.isPattern = isPattern;
  21485. exports.mergeColors = mergeColors;
  21486. exports.parseColor = parseColor;
  21487. exports.parseLength = parseLength;
  21488. exports.parsePath = parsePath;
  21489. exports.parseTransform = parseTransform;
  21490. exports.parsedTransformToMat4 = parsedTransformToMat4;
  21491. exports.propertyMetadataCache = propertyMetadataCache;
  21492. exports.rad2deg = rad2deg;
  21493. exports.resetEntityCounter = resetEntityCounter;
  21494. exports.runtime = runtime;
  21495. exports.setDOMSize = setDOMSize;
  21496. exports.translatePathToString = translatePathToString;
  21497. exports.turn2deg = turn2deg;
  21498. Object.defineProperty(exports, '__esModule', { value: true });
  21499. })));