index.umd.js 180 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@antv/g-lite')) :
  3. typeof define === 'function' && define.amd ? define(['exports', '@antv/g-lite'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.Canvas2D = {}), global.window.G));
  5. }(this, (function (exports, gLite) { 'use strict';
  6. function _regeneratorRuntime() {
  7. _regeneratorRuntime = function () {
  8. return exports;
  9. };
  10. var exports = {},
  11. Op = Object.prototype,
  12. hasOwn = Op.hasOwnProperty,
  13. defineProperty = Object.defineProperty || function (obj, key, desc) {
  14. obj[key] = desc.value;
  15. },
  16. $Symbol = "function" == typeof Symbol ? Symbol : {},
  17. iteratorSymbol = $Symbol.iterator || "@@iterator",
  18. asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
  19. toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  20. function define(obj, key, value) {
  21. return Object.defineProperty(obj, key, {
  22. value: value,
  23. enumerable: !0,
  24. configurable: !0,
  25. writable: !0
  26. }), obj[key];
  27. }
  28. try {
  29. define({}, "");
  30. } catch (err) {
  31. define = function (obj, key, value) {
  32. return obj[key] = value;
  33. };
  34. }
  35. function wrap(innerFn, outerFn, self, tryLocsList) {
  36. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
  37. generator = Object.create(protoGenerator.prototype),
  38. context = new Context(tryLocsList || []);
  39. return defineProperty(generator, "_invoke", {
  40. value: makeInvokeMethod(innerFn, self, context)
  41. }), generator;
  42. }
  43. function tryCatch(fn, obj, arg) {
  44. try {
  45. return {
  46. type: "normal",
  47. arg: fn.call(obj, arg)
  48. };
  49. } catch (err) {
  50. return {
  51. type: "throw",
  52. arg: err
  53. };
  54. }
  55. }
  56. exports.wrap = wrap;
  57. var ContinueSentinel = {};
  58. function Generator() {}
  59. function GeneratorFunction() {}
  60. function GeneratorFunctionPrototype() {}
  61. var IteratorPrototype = {};
  62. define(IteratorPrototype, iteratorSymbol, function () {
  63. return this;
  64. });
  65. var getProto = Object.getPrototypeOf,
  66. NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  67. NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
  68. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  69. function defineIteratorMethods(prototype) {
  70. ["next", "throw", "return"].forEach(function (method) {
  71. define(prototype, method, function (arg) {
  72. return this._invoke(method, arg);
  73. });
  74. });
  75. }
  76. function AsyncIterator(generator, PromiseImpl) {
  77. function invoke(method, arg, resolve, reject) {
  78. var record = tryCatch(generator[method], generator, arg);
  79. if ("throw" !== record.type) {
  80. var result = record.arg,
  81. value = result.value;
  82. return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
  83. invoke("next", value, resolve, reject);
  84. }, function (err) {
  85. invoke("throw", err, resolve, reject);
  86. }) : PromiseImpl.resolve(value).then(function (unwrapped) {
  87. result.value = unwrapped, resolve(result);
  88. }, function (error) {
  89. return invoke("throw", error, resolve, reject);
  90. });
  91. }
  92. reject(record.arg);
  93. }
  94. var previousPromise;
  95. defineProperty(this, "_invoke", {
  96. value: function (method, arg) {
  97. function callInvokeWithMethodAndArg() {
  98. return new PromiseImpl(function (resolve, reject) {
  99. invoke(method, arg, resolve, reject);
  100. });
  101. }
  102. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  103. }
  104. });
  105. }
  106. function makeInvokeMethod(innerFn, self, context) {
  107. var state = "suspendedStart";
  108. return function (method, arg) {
  109. if ("executing" === state) throw new Error("Generator is already running");
  110. if ("completed" === state) {
  111. if ("throw" === method) throw arg;
  112. return doneResult();
  113. }
  114. for (context.method = method, context.arg = arg;;) {
  115. var delegate = context.delegate;
  116. if (delegate) {
  117. var delegateResult = maybeInvokeDelegate(delegate, context);
  118. if (delegateResult) {
  119. if (delegateResult === ContinueSentinel) continue;
  120. return delegateResult;
  121. }
  122. }
  123. if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
  124. if ("suspendedStart" === state) throw state = "completed", context.arg;
  125. context.dispatchException(context.arg);
  126. } else "return" === context.method && context.abrupt("return", context.arg);
  127. state = "executing";
  128. var record = tryCatch(innerFn, self, context);
  129. if ("normal" === record.type) {
  130. if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
  131. return {
  132. value: record.arg,
  133. done: context.done
  134. };
  135. }
  136. "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
  137. }
  138. };
  139. }
  140. function maybeInvokeDelegate(delegate, context) {
  141. var methodName = context.method,
  142. method = delegate.iterator[methodName];
  143. 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;
  144. var record = tryCatch(method, delegate.iterator, context.arg);
  145. if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
  146. var info = record.arg;
  147. 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);
  148. }
  149. function pushTryEntry(locs) {
  150. var entry = {
  151. tryLoc: locs[0]
  152. };
  153. 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
  154. }
  155. function resetTryEntry(entry) {
  156. var record = entry.completion || {};
  157. record.type = "normal", delete record.arg, entry.completion = record;
  158. }
  159. function Context(tryLocsList) {
  160. this.tryEntries = [{
  161. tryLoc: "root"
  162. }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
  163. }
  164. function values(iterable) {
  165. if (iterable) {
  166. var iteratorMethod = iterable[iteratorSymbol];
  167. if (iteratorMethod) return iteratorMethod.call(iterable);
  168. if ("function" == typeof iterable.next) return iterable;
  169. if (!isNaN(iterable.length)) {
  170. var i = -1,
  171. next = function next() {
  172. for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
  173. return next.value = undefined, next.done = !0, next;
  174. };
  175. return next.next = next;
  176. }
  177. }
  178. return {
  179. next: doneResult
  180. };
  181. }
  182. function doneResult() {
  183. return {
  184. value: undefined,
  185. done: !0
  186. };
  187. }
  188. return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
  189. value: GeneratorFunctionPrototype,
  190. configurable: !0
  191. }), defineProperty(GeneratorFunctionPrototype, "constructor", {
  192. value: GeneratorFunction,
  193. configurable: !0
  194. }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
  195. var ctor = "function" == typeof genFun && genFun.constructor;
  196. return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
  197. }, exports.mark = function (genFun) {
  198. return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
  199. }, exports.awrap = function (arg) {
  200. return {
  201. __await: arg
  202. };
  203. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  204. return this;
  205. }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  206. void 0 === PromiseImpl && (PromiseImpl = Promise);
  207. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  208. return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  209. return result.done ? result.value : iter.next();
  210. });
  211. }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
  212. return this;
  213. }), define(Gp, "toString", function () {
  214. return "[object Generator]";
  215. }), exports.keys = function (val) {
  216. var object = Object(val),
  217. keys = [];
  218. for (var key in object) keys.push(key);
  219. return keys.reverse(), function next() {
  220. for (; keys.length;) {
  221. var key = keys.pop();
  222. if (key in object) return next.value = key, next.done = !1, next;
  223. }
  224. return next.done = !0, next;
  225. };
  226. }, exports.values = values, Context.prototype = {
  227. constructor: Context,
  228. reset: function (skipTempReset) {
  229. 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);
  230. },
  231. stop: function () {
  232. this.done = !0;
  233. var rootRecord = this.tryEntries[0].completion;
  234. if ("throw" === rootRecord.type) throw rootRecord.arg;
  235. return this.rval;
  236. },
  237. dispatchException: function (exception) {
  238. if (this.done) throw exception;
  239. var context = this;
  240. function handle(loc, caught) {
  241. return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
  242. }
  243. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  244. var entry = this.tryEntries[i],
  245. record = entry.completion;
  246. if ("root" === entry.tryLoc) return handle("end");
  247. if (entry.tryLoc <= this.prev) {
  248. var hasCatch = hasOwn.call(entry, "catchLoc"),
  249. hasFinally = hasOwn.call(entry, "finallyLoc");
  250. if (hasCatch && hasFinally) {
  251. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  252. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  253. } else if (hasCatch) {
  254. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  255. } else {
  256. if (!hasFinally) throw new Error("try statement without catch or finally");
  257. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  258. }
  259. }
  260. }
  261. },
  262. abrupt: function (type, arg) {
  263. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  264. var entry = this.tryEntries[i];
  265. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  266. var finallyEntry = entry;
  267. break;
  268. }
  269. }
  270. finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
  271. var record = finallyEntry ? finallyEntry.completion : {};
  272. return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
  273. },
  274. complete: function (record, afterLoc) {
  275. if ("throw" === record.type) throw record.arg;
  276. 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;
  277. },
  278. finish: function (finallyLoc) {
  279. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  280. var entry = this.tryEntries[i];
  281. if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
  282. }
  283. },
  284. catch: function (tryLoc) {
  285. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  286. var entry = this.tryEntries[i];
  287. if (entry.tryLoc === tryLoc) {
  288. var record = entry.completion;
  289. if ("throw" === record.type) {
  290. var thrown = record.arg;
  291. resetTryEntry(entry);
  292. }
  293. return thrown;
  294. }
  295. }
  296. throw new Error("illegal catch attempt");
  297. },
  298. delegateYield: function (iterable, resultName, nextLoc) {
  299. return this.delegate = {
  300. iterator: values(iterable),
  301. resultName: resultName,
  302. nextLoc: nextLoc
  303. }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
  304. }
  305. }, exports;
  306. }
  307. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  308. try {
  309. var info = gen[key](arg);
  310. var value = info.value;
  311. } catch (error) {
  312. reject(error);
  313. return;
  314. }
  315. if (info.done) {
  316. resolve(value);
  317. } else {
  318. Promise.resolve(value).then(_next, _throw);
  319. }
  320. }
  321. function _asyncToGenerator(fn) {
  322. return function () {
  323. var self = this,
  324. args = arguments;
  325. return new Promise(function (resolve, reject) {
  326. var gen = fn.apply(self, args);
  327. function _next(value) {
  328. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  329. }
  330. function _throw(err) {
  331. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  332. }
  333. _next(undefined);
  334. });
  335. };
  336. }
  337. function _inheritsLoose(subClass, superClass) {
  338. subClass.prototype = Object.create(superClass.prototype);
  339. subClass.prototype.constructor = subClass;
  340. _setPrototypeOf(subClass, superClass);
  341. }
  342. function _setPrototypeOf(o, p) {
  343. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  344. o.__proto__ = p;
  345. return o;
  346. };
  347. return _setPrototypeOf(o, p);
  348. }
  349. /**
  350. * Common utilities
  351. * @module glMatrix
  352. */
  353. var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  354. if (!Math.hypot) Math.hypot = function () {
  355. var y = 0,
  356. i = arguments.length;
  357. while (i--) {
  358. y += arguments[i] * arguments[i];
  359. }
  360. return Math.sqrt(y);
  361. };
  362. /**
  363. * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
  364. * @module mat4
  365. */
  366. /**
  367. * Creates a new identity mat4
  368. *
  369. * @returns {mat4} a new 4x4 matrix
  370. */
  371. function create() {
  372. var out = new ARRAY_TYPE(16);
  373. if (ARRAY_TYPE != Float32Array) {
  374. out[1] = 0;
  375. out[2] = 0;
  376. out[3] = 0;
  377. out[4] = 0;
  378. out[6] = 0;
  379. out[7] = 0;
  380. out[8] = 0;
  381. out[9] = 0;
  382. out[11] = 0;
  383. out[12] = 0;
  384. out[13] = 0;
  385. out[14] = 0;
  386. }
  387. out[0] = 1;
  388. out[5] = 1;
  389. out[10] = 1;
  390. out[15] = 1;
  391. return out;
  392. }
  393. /**
  394. * Copy the values from one mat4 to another
  395. *
  396. * @param {mat4} out the receiving matrix
  397. * @param {ReadonlyMat4} a the source matrix
  398. * @returns {mat4} out
  399. */
  400. function copy(out, a) {
  401. out[0] = a[0];
  402. out[1] = a[1];
  403. out[2] = a[2];
  404. out[3] = a[3];
  405. out[4] = a[4];
  406. out[5] = a[5];
  407. out[6] = a[6];
  408. out[7] = a[7];
  409. out[8] = a[8];
  410. out[9] = a[9];
  411. out[10] = a[10];
  412. out[11] = a[11];
  413. out[12] = a[12];
  414. out[13] = a[13];
  415. out[14] = a[14];
  416. out[15] = a[15];
  417. return out;
  418. }
  419. /**
  420. * Inverts a mat4
  421. *
  422. * @param {mat4} out the receiving matrix
  423. * @param {ReadonlyMat4} a the source matrix
  424. * @returns {mat4} out
  425. */
  426. function invert(out, a) {
  427. var a00 = a[0],
  428. a01 = a[1],
  429. a02 = a[2],
  430. a03 = a[3];
  431. var a10 = a[4],
  432. a11 = a[5],
  433. a12 = a[6],
  434. a13 = a[7];
  435. var a20 = a[8],
  436. a21 = a[9],
  437. a22 = a[10],
  438. a23 = a[11];
  439. var a30 = a[12],
  440. a31 = a[13],
  441. a32 = a[14],
  442. a33 = a[15];
  443. var b00 = a00 * a11 - a01 * a10;
  444. var b01 = a00 * a12 - a02 * a10;
  445. var b02 = a00 * a13 - a03 * a10;
  446. var b03 = a01 * a12 - a02 * a11;
  447. var b04 = a01 * a13 - a03 * a11;
  448. var b05 = a02 * a13 - a03 * a12;
  449. var b06 = a20 * a31 - a21 * a30;
  450. var b07 = a20 * a32 - a22 * a30;
  451. var b08 = a20 * a33 - a23 * a30;
  452. var b09 = a21 * a32 - a22 * a31;
  453. var b10 = a21 * a33 - a23 * a31;
  454. var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
  455. var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  456. if (!det) {
  457. return null;
  458. }
  459. det = 1.0 / det;
  460. out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
  461. out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
  462. out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
  463. out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
  464. out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
  465. out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
  466. out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
  467. out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
  468. out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
  469. out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
  470. out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
  471. out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
  472. out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
  473. out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
  474. out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
  475. out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
  476. return out;
  477. }
  478. /**
  479. * Multiplies two mat4s
  480. *
  481. * @param {mat4} out the receiving matrix
  482. * @param {ReadonlyMat4} a the first operand
  483. * @param {ReadonlyMat4} b the second operand
  484. * @returns {mat4} out
  485. */
  486. function multiply(out, a, b) {
  487. var a00 = a[0],
  488. a01 = a[1],
  489. a02 = a[2],
  490. a03 = a[3];
  491. var a10 = a[4],
  492. a11 = a[5],
  493. a12 = a[6],
  494. a13 = a[7];
  495. var a20 = a[8],
  496. a21 = a[9],
  497. a22 = a[10],
  498. a23 = a[11];
  499. var a30 = a[12],
  500. a31 = a[13],
  501. a32 = a[14],
  502. a33 = a[15]; // Cache only the current line of the second matrix
  503. var b0 = b[0],
  504. b1 = b[1],
  505. b2 = b[2],
  506. b3 = b[3];
  507. out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  508. out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  509. out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  510. out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  511. b0 = b[4];
  512. b1 = b[5];
  513. b2 = b[6];
  514. b3 = b[7];
  515. out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  516. out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  517. out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  518. out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  519. b0 = b[8];
  520. b1 = b[9];
  521. b2 = b[10];
  522. b3 = b[11];
  523. out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  524. out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  525. out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  526. out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  527. b0 = b[12];
  528. b1 = b[13];
  529. b2 = b[14];
  530. b3 = b[15];
  531. out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  532. out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  533. out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  534. out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  535. return out;
  536. }
  537. /**
  538. * Translate a mat4 by the given vector
  539. *
  540. * @param {mat4} out the receiving matrix
  541. * @param {ReadonlyMat4} a the matrix to translate
  542. * @param {ReadonlyVec3} v vector to translate by
  543. * @returns {mat4} out
  544. */
  545. function translate(out, a, v) {
  546. var x = v[0],
  547. y = v[1],
  548. z = v[2];
  549. var a00, a01, a02, a03;
  550. var a10, a11, a12, a13;
  551. var a20, a21, a22, a23;
  552. if (a === out) {
  553. out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
  554. out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
  555. out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
  556. out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
  557. } else {
  558. a00 = a[0];
  559. a01 = a[1];
  560. a02 = a[2];
  561. a03 = a[3];
  562. a10 = a[4];
  563. a11 = a[5];
  564. a12 = a[6];
  565. a13 = a[7];
  566. a20 = a[8];
  567. a21 = a[9];
  568. a22 = a[10];
  569. a23 = a[11];
  570. out[0] = a00;
  571. out[1] = a01;
  572. out[2] = a02;
  573. out[3] = a03;
  574. out[4] = a10;
  575. out[5] = a11;
  576. out[6] = a12;
  577. out[7] = a13;
  578. out[8] = a20;
  579. out[9] = a21;
  580. out[10] = a22;
  581. out[11] = a23;
  582. out[12] = a00 * x + a10 * y + a20 * z + a[12];
  583. out[13] = a01 * x + a11 * y + a21 * z + a[13];
  584. out[14] = a02 * x + a12 * y + a22 * z + a[14];
  585. out[15] = a03 * x + a13 * y + a23 * z + a[15];
  586. }
  587. return out;
  588. }
  589. /**
  590. * Creates a matrix from a vector scaling
  591. * This is equivalent to (but much faster than):
  592. *
  593. * mat4.identity(dest);
  594. * mat4.scale(dest, dest, vec);
  595. *
  596. * @param {mat4} out mat4 receiving operation result
  597. * @param {ReadonlyVec3} v Scaling vector
  598. * @returns {mat4} out
  599. */
  600. function fromScaling(out, v) {
  601. out[0] = v[0];
  602. out[1] = 0;
  603. out[2] = 0;
  604. out[3] = 0;
  605. out[4] = 0;
  606. out[5] = v[1];
  607. out[6] = 0;
  608. out[7] = 0;
  609. out[8] = 0;
  610. out[9] = 0;
  611. out[10] = v[2];
  612. out[11] = 0;
  613. out[12] = 0;
  614. out[13] = 0;
  615. out[14] = 0;
  616. out[15] = 1;
  617. return out;
  618. }
  619. /**
  620. * 3 Dimensional Vector
  621. * @module vec3
  622. */
  623. /**
  624. * Creates a new, empty vec3
  625. *
  626. * @returns {vec3} a new 3D vector
  627. */
  628. function create$1() {
  629. var out = new ARRAY_TYPE(3);
  630. if (ARRAY_TYPE != Float32Array) {
  631. out[0] = 0;
  632. out[1] = 0;
  633. out[2] = 0;
  634. }
  635. return out;
  636. }
  637. /**
  638. * Set the components of a vec3 to the given values
  639. *
  640. * @param {vec3} out the receiving vector
  641. * @param {Number} x X component
  642. * @param {Number} y Y component
  643. * @param {Number} z Z component
  644. * @returns {vec3} out
  645. */
  646. function set(out, x, y, z) {
  647. out[0] = x;
  648. out[1] = y;
  649. out[2] = z;
  650. return out;
  651. }
  652. /**
  653. * Transforms the vec3 with a mat4.
  654. * 4th vector component is implicitly '1'
  655. *
  656. * @param {vec3} out the receiving vector
  657. * @param {ReadonlyVec3} a the vector to transform
  658. * @param {ReadonlyMat4} m matrix to transform with
  659. * @returns {vec3} out
  660. */
  661. function transformMat4(out, a, m) {
  662. var x = a[0],
  663. y = a[1],
  664. z = a[2];
  665. var w = m[3] * x + m[7] * y + m[11] * z + m[15];
  666. w = w || 1.0;
  667. out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
  668. out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
  669. out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
  670. return out;
  671. }
  672. /**
  673. * Perform some operation over an array of vec3s.
  674. *
  675. * @param {Array} a the array of vectors to iterate over
  676. * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
  677. * @param {Number} offset Number of elements to skip at the beginning of the array
  678. * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
  679. * @param {Function} fn Function to call for each vector in the array
  680. * @param {Object} [arg] additional argument to pass to fn
  681. * @returns {Array} a
  682. * @function
  683. */
  684. var forEach = function () {
  685. var vec = create$1();
  686. return function (a, stride, offset, count, fn, arg) {
  687. var i, l;
  688. if (!stride) {
  689. stride = 3;
  690. }
  691. if (!offset) {
  692. offset = 0;
  693. }
  694. if (count) {
  695. l = Math.min(count * stride + offset, a.length);
  696. } else {
  697. l = a.length;
  698. }
  699. for (i = offset; i < l; i += stride) {
  700. vec[0] = a[i];
  701. vec[1] = a[i + 1];
  702. vec[2] = a[i + 2];
  703. fn(vec, vec, arg);
  704. a[i] = vec[0];
  705. a[i + 1] = vec[1];
  706. a[i + 2] = vec[2];
  707. }
  708. return a;
  709. };
  710. }();
  711. /**
  712. * 2 Dimensional Vector
  713. * @module vec2
  714. */
  715. /**
  716. * Creates a new, empty vec2
  717. *
  718. * @returns {vec2} a new 2D vector
  719. */
  720. function create$2() {
  721. var out = new ARRAY_TYPE(2);
  722. if (ARRAY_TYPE != Float32Array) {
  723. out[0] = 0;
  724. out[1] = 0;
  725. }
  726. return out;
  727. }
  728. /**
  729. * Normalize a vec2
  730. *
  731. * @param {vec2} out the receiving vector
  732. * @param {ReadonlyVec2} a vector to normalize
  733. * @returns {vec2} out
  734. */
  735. function normalize(out, a) {
  736. var x = a[0],
  737. y = a[1];
  738. var len = x * x + y * y;
  739. if (len > 0) {
  740. //TODO: evaluate use of glm_invsqrt here?
  741. len = 1 / Math.sqrt(len);
  742. }
  743. out[0] = a[0] * len;
  744. out[1] = a[1] * len;
  745. return out;
  746. }
  747. /**
  748. * Calculates the dot product of two vec2's
  749. *
  750. * @param {ReadonlyVec2} a the first operand
  751. * @param {ReadonlyVec2} b the second operand
  752. * @returns {Number} dot product of a and b
  753. */
  754. function dot(a, b) {
  755. return a[0] * b[0] + a[1] * b[1];
  756. }
  757. /**
  758. * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)
  759. *
  760. * @param {ReadonlyVec2} a The first vector.
  761. * @param {ReadonlyVec2} b The second vector.
  762. * @returns {Boolean} True if the vectors are equal, false otherwise.
  763. */
  764. function exactEquals(a, b) {
  765. return a[0] === b[0] && a[1] === b[1];
  766. }
  767. /**
  768. * Perform some operation over an array of vec2s.
  769. *
  770. * @param {Array} a the array of vectors to iterate over
  771. * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
  772. * @param {Number} offset Number of elements to skip at the beginning of the array
  773. * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
  774. * @param {Function} fn Function to call for each vector in the array
  775. * @param {Object} [arg] additional argument to pass to fn
  776. * @returns {Array} a
  777. * @function
  778. */
  779. var forEach$1 = function () {
  780. var vec = create$2();
  781. return function (a, stride, offset, count, fn, arg) {
  782. var i, l;
  783. if (!stride) {
  784. stride = 2;
  785. }
  786. if (!offset) {
  787. offset = 0;
  788. }
  789. if (count) {
  790. l = Math.min(count * stride + offset, a.length);
  791. } else {
  792. l = a.length;
  793. }
  794. for (i = offset; i < l; i += stride) {
  795. vec[0] = a[i];
  796. vec[1] = a[i + 1];
  797. fn(vec, vec, arg);
  798. a[i] = vec[0];
  799. a[i + 1] = vec[1];
  800. }
  801. return a;
  802. };
  803. }();
  804. function rotateVector(x, y, rad) {
  805. var X = x * Math.cos(rad) - y * Math.sin(rad);
  806. var Y = x * Math.sin(rad) + y * Math.cos(rad);
  807. return { x: X, y: Y };
  808. }
  809. /**
  810. * Converts A (arc-to) segments to C (cubic-bezier-to).
  811. *
  812. * For more information of where this math came from visit:
  813. * http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  814. */
  815. function arcToCubic(X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, recursive) {
  816. var x1 = X1;
  817. var y1 = Y1;
  818. var rx = RX;
  819. var ry = RY;
  820. var x2 = X2;
  821. var y2 = Y2;
  822. // for more information of where this Math came from visit:
  823. // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  824. var d120 = (Math.PI * 120) / 180;
  825. var rad = (Math.PI / 180) * (+angle || 0);
  826. /** @type {number[]} */
  827. var res = [];
  828. var xy;
  829. var f1;
  830. var f2;
  831. var cx;
  832. var cy;
  833. if (!recursive) {
  834. xy = rotateVector(x1, y1, -rad);
  835. x1 = xy.x;
  836. y1 = xy.y;
  837. xy = rotateVector(x2, y2, -rad);
  838. x2 = xy.x;
  839. y2 = xy.y;
  840. var x = (x1 - x2) / 2;
  841. var y = (y1 - y2) / 2;
  842. var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
  843. if (h > 1) {
  844. h = Math.sqrt(h);
  845. rx *= h;
  846. ry *= h;
  847. }
  848. var rx2 = rx * rx;
  849. var ry2 = ry * ry;
  850. var k = (LAF === SF ? -1 : 1) *
  851. Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)));
  852. cx = (k * rx * y) / ry + (x1 + x2) / 2;
  853. cy = (k * -ry * x) / rx + (y1 + y2) / 2;
  854. // eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise
  855. f1 = Math.asin(((((y1 - cy) / ry) * Math.pow(10, 9)) >> 0) / Math.pow(10, 9));
  856. // eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise
  857. f2 = Math.asin(((((y2 - cy) / ry) * Math.pow(10, 9)) >> 0) / Math.pow(10, 9));
  858. f1 = x1 < cx ? Math.PI - f1 : f1;
  859. f2 = x2 < cx ? Math.PI - f2 : f2;
  860. if (f1 < 0)
  861. f1 = Math.PI * 2 + f1;
  862. if (f2 < 0)
  863. f2 = Math.PI * 2 + f2;
  864. if (SF && f1 > f2) {
  865. f1 -= Math.PI * 2;
  866. }
  867. if (!SF && f2 > f1) {
  868. f2 -= Math.PI * 2;
  869. }
  870. }
  871. else {
  872. f1 = recursive[0], f2 = recursive[1], cx = recursive[2], cy = recursive[3];
  873. }
  874. var df = f2 - f1;
  875. if (Math.abs(df) > d120) {
  876. var f2old = f2;
  877. var x2old = x2;
  878. var y2old = y2;
  879. f2 = f1 + d120 * (SF && f2 > f1 ? 1 : -1);
  880. x2 = cx + rx * Math.cos(f2);
  881. y2 = cy + ry * Math.sin(f2);
  882. res = arcToCubic(x2, y2, rx, ry, angle, 0, SF, x2old, y2old, [f2, f2old, cx, cy]);
  883. }
  884. df = f2 - f1;
  885. var c1 = Math.cos(f1);
  886. var s1 = Math.sin(f1);
  887. var c2 = Math.cos(f2);
  888. var s2 = Math.sin(f2);
  889. var t = Math.tan(df / 4);
  890. var hx = (4 / 3) * rx * t;
  891. var hy = (4 / 3) * ry * t;
  892. var m1 = [x1, y1];
  893. var m2 = [x1 + hx * s1, y1 - hy * c1];
  894. var m3 = [x2 + hx * s2, y2 - hy * c2];
  895. var m4 = [x2, y2];
  896. m2[0] = 2 * m1[0] - m2[0];
  897. m2[1] = 2 * m1[1] - m2[1];
  898. if (recursive) {
  899. return m2.concat(m3, m4, res);
  900. // return [...m2, ...m3, ...m4, ...res];
  901. }
  902. res = m2.concat(m3, m4, res);
  903. // res = [...m2, ...m3, ...m4, ...res];
  904. var newres = [];
  905. for (var i = 0, ii = res.length; i < ii; i += 1) {
  906. newres[i] = i % 2 ? rotateVector(res[i - 1], res[i], rad).y : rotateVector(res[i], res[i + 1], rad).x;
  907. }
  908. return newres;
  909. }
  910. // const TAU = Math.PI * 2;
  911. // const mapToEllipse = (
  912. // { x, y }: { x: number; y: number },
  913. // rx: number,
  914. // ry: number,
  915. // cosphi: number,
  916. // sinphi: number,
  917. // centerx: number,
  918. // centery: number,
  919. // ) => {
  920. // x *= rx;
  921. // y *= ry;
  922. // const xp = cosphi * x - sinphi * y;
  923. // const yp = sinphi * x + cosphi * y;
  924. // return {
  925. // x: xp + centerx,
  926. // y: yp + centery,
  927. // };
  928. // };
  929. // const approxUnitArc = (ang1: number, ang2: number) => {
  930. // // If 90 degree circular arc, use a constant
  931. // // as derived from http://spencermortensen.com/articles/bezier-circle
  932. // const a =
  933. // ang2 === 1.5707963267948966
  934. // ? 0.551915024494
  935. // : ang2 === -1.5707963267948966
  936. // ? -0.551915024494
  937. // : (4 / 3) * Math.tan(ang2 / 4);
  938. // const x1 = Math.cos(ang1);
  939. // const y1 = Math.sin(ang1);
  940. // const x2 = Math.cos(ang1 + ang2);
  941. // const y2 = Math.sin(ang1 + ang2);
  942. // return [
  943. // {
  944. // x: x1 - y1 * a,
  945. // y: y1 + x1 * a,
  946. // },
  947. // {
  948. // x: x2 + y2 * a,
  949. // y: y2 - x2 * a,
  950. // },
  951. // {
  952. // x: x2,
  953. // y: y2,
  954. // },
  955. // ];
  956. // };
  957. // const vectorAngle = (ux: number, uy: number, vx: number, vy: number) => {
  958. // const sign = ux * vy - uy * vx < 0 ? -1 : 1;
  959. // let dot = ux * vx + uy * vy;
  960. // if (dot > 1) {
  961. // dot = 1;
  962. // }
  963. // if (dot < -1) {
  964. // dot = -1;
  965. // }
  966. // return sign * Math.acos(dot);
  967. // };
  968. // const getArcCenter = (
  969. // px: any,
  970. // py: any,
  971. // cx: any,
  972. // cy: any,
  973. // rx: number,
  974. // ry: number,
  975. // largeArcFlag: number,
  976. // sweepFlag: number,
  977. // sinphi: number,
  978. // cosphi: number,
  979. // pxp: number,
  980. // pyp: number,
  981. // ) => {
  982. // const rxsq = Math.pow(rx, 2);
  983. // const rysq = Math.pow(ry, 2);
  984. // const pxpsq = Math.pow(pxp, 2);
  985. // const pypsq = Math.pow(pyp, 2);
  986. // let radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;
  987. // if (radicant < 0) {
  988. // radicant = 0;
  989. // }
  990. // radicant /= rxsq * pypsq + rysq * pxpsq;
  991. // radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
  992. // const centerxp = ((radicant * rx) / ry) * pyp;
  993. // const centeryp = ((radicant * -ry) / rx) * pxp;
  994. // const centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;
  995. // const centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;
  996. // const vx1 = (pxp - centerxp) / rx;
  997. // const vy1 = (pyp - centeryp) / ry;
  998. // const vx2 = (-pxp - centerxp) / rx;
  999. // const vy2 = (-pyp - centeryp) / ry;
  1000. // const ang1 = vectorAngle(1, 0, vx1, vy1);
  1001. // let ang2 = vectorAngle(vx1, vy1, vx2, vy2);
  1002. // if (sweepFlag === 0 && ang2 > 0) {
  1003. // ang2 -= TAU;
  1004. // }
  1005. // if (sweepFlag === 1 && ang2 < 0) {
  1006. // ang2 += TAU;
  1007. // }
  1008. // return [centerx, centery, ang1, ang2];
  1009. // };
  1010. // const arcToBezier = ({ px, py, cx, cy, rx, ry, xAxisRotation = 0, largeArcFlag = 0, sweepFlag = 0 }) => {
  1011. // const curves = [];
  1012. // if (rx === 0 || ry === 0) {
  1013. // return [{ x1: 0, y1: 0, x2: 0, y2: 0, x: cx, y: cy }];
  1014. // }
  1015. // const sinphi = Math.sin((xAxisRotation * TAU) / 360);
  1016. // const cosphi = Math.cos((xAxisRotation * TAU) / 360);
  1017. // const pxp = (cosphi * (px - cx)) / 2 + (sinphi * (py - cy)) / 2;
  1018. // const pyp = (-sinphi * (px - cx)) / 2 + (cosphi * (py - cy)) / 2;
  1019. // if (pxp === 0 && pyp === 0) {
  1020. // return [{ x1: 0, y1: 0, x2: 0, y2: 0, x: cx, y: cy }];
  1021. // }
  1022. // rx = Math.abs(rx);
  1023. // ry = Math.abs(ry);
  1024. // const lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);
  1025. // if (lambda > 1) {
  1026. // rx *= Math.sqrt(lambda);
  1027. // ry *= Math.sqrt(lambda);
  1028. // }
  1029. // let [centerx, centery, ang1, ang2] = getArcCenter(
  1030. // px,
  1031. // py,
  1032. // cx,
  1033. // cy,
  1034. // rx,
  1035. // ry,
  1036. // largeArcFlag,
  1037. // sweepFlag,
  1038. // sinphi,
  1039. // cosphi,
  1040. // pxp,
  1041. // pyp,
  1042. // );
  1043. // // If 'ang2' == 90.0000000001, then `ratio` will evaluate to
  1044. // // 1.0000000001. This causes `segments` to be greater than one, which is an
  1045. // // unecessary split, and adds extra points to the bezier curve. To alleviate
  1046. // // this issue, we round to 1.0 when the ratio is close to 1.0.
  1047. // let ratio = Math.abs(ang2) / (TAU / 4);
  1048. // if (Math.abs(1.0 - ratio) < 0.0000001) {
  1049. // ratio = 1.0;
  1050. // }
  1051. // const segments = Math.max(Math.ceil(ratio), 1);
  1052. // ang2 /= segments;
  1053. // for (let i = 0; i < segments; i++) {
  1054. // curves.push(approxUnitArc(ang1, ang2));
  1055. // ang1 += ang2;
  1056. // }
  1057. // return curves.map((curve) => {
  1058. // const { x: x1, y: y1 } = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery);
  1059. // const { x: x2, y: y2 } = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery);
  1060. // const { x, y } = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery);
  1061. // return { x1, y1, x2, y2, x, y };
  1062. // });
  1063. // };
  1064. // export function arcToCubic(
  1065. // x1: number,
  1066. // y1: number,
  1067. // rx: number,
  1068. // ry: number,
  1069. // angle: number,
  1070. // LAF: number,
  1071. // SF: number,
  1072. // x2: number,
  1073. // y2: number,
  1074. // ) {
  1075. // const curves = arcToBezier({
  1076. // px: x1,
  1077. // py: y1,
  1078. // cx: x2,
  1079. // cy: y2,
  1080. // rx,
  1081. // ry,
  1082. // xAxisRotation: angle,
  1083. // largeArcFlag: LAF,
  1084. // sweepFlag: SF,
  1085. // });
  1086. // return curves.reduce((prev, cur) => {
  1087. // const { x1, y1, x2, y2, x, y } = cur;
  1088. // prev.push(x1, y1, x2, y2, x, y);
  1089. // return prev;
  1090. // }, [] as number[]);
  1091. // }
  1092. // isFinite,
  1093. var isNil = function (value) {
  1094. /**
  1095. * isNil(null) => true
  1096. * isNil() => true
  1097. */
  1098. return value === null || value === undefined;
  1099. };
  1100. var toString = {}.toString;
  1101. var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
  1102. var isString = (function (str) {
  1103. return isType(str, 'String');
  1104. });
  1105. var clamp = function (a, min, max) {
  1106. if (a < min) {
  1107. return min;
  1108. }
  1109. else if (a > max) {
  1110. return max;
  1111. }
  1112. return a;
  1113. };
  1114. /**
  1115. * 判断是否数字
  1116. * @return {Boolean} 是否数字
  1117. */
  1118. var isNumber = function (value) {
  1119. return isType(value, 'Number');
  1120. };
  1121. function _inheritsLoose$1(subClass, superClass) {
  1122. subClass.prototype = Object.create(superClass.prototype);
  1123. subClass.prototype.constructor = subClass;
  1124. _setPrototypeOf$1(subClass, superClass);
  1125. }
  1126. function _setPrototypeOf$1(o, p) {
  1127. _setPrototypeOf$1 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  1128. o.__proto__ = p;
  1129. return o;
  1130. };
  1131. return _setPrototypeOf$1(o, p);
  1132. }
  1133. function generatePath(context, parsedStyle) {
  1134. var r = parsedStyle.r;
  1135. context.arc(r, r, r, 0, Math.PI * 2, false);
  1136. }
  1137. function generatePath$1(context, parsedStyle) {
  1138. var rxInPixels = parsedStyle.rx,
  1139. ryInPixels = parsedStyle.ry;
  1140. var rx = rxInPixels;
  1141. var ry = ryInPixels;
  1142. // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse
  1143. if (context.ellipse) {
  1144. context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false);
  1145. } else {
  1146. // 如果不支持,则使用圆来绘制,进行变形
  1147. var r = rx > ry ? rx : ry;
  1148. var scaleX = rx > ry ? 1 : rx / ry;
  1149. var scaleY = rx > ry ? ry / rx : 1;
  1150. context.save();
  1151. context.scale(scaleX, scaleY);
  1152. context.arc(0, 0, r, 0, Math.PI * 2);
  1153. }
  1154. }
  1155. function generatePath$2(context, parsedStyle) {
  1156. var x1 = parsedStyle.x1,
  1157. y1 = parsedStyle.y1,
  1158. x2 = parsedStyle.x2,
  1159. y2 = parsedStyle.y2,
  1160. _parsedStyle$defX = parsedStyle.defX,
  1161. defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
  1162. _parsedStyle$defY = parsedStyle.defY,
  1163. defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
  1164. markerStart = parsedStyle.markerStart,
  1165. markerEnd = parsedStyle.markerEnd,
  1166. markerStartOffset = parsedStyle.markerStartOffset,
  1167. markerEndOffset = parsedStyle.markerEndOffset;
  1168. var startOffsetX = 0;
  1169. var startOffsetY = 0;
  1170. var endOffsetX = 0;
  1171. var endOffsetY = 0;
  1172. var rad = 0;
  1173. var x;
  1174. var y;
  1175. if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
  1176. x = x2 - x1;
  1177. y = y2 - y1;
  1178. rad = Math.atan2(y, x);
  1179. startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
  1180. startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
  1181. }
  1182. if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
  1183. x = x1 - x2;
  1184. y = y1 - y2;
  1185. rad = Math.atan2(y, x);
  1186. endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
  1187. endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
  1188. }
  1189. context.moveTo(x1 - defX + startOffsetX, y1 - defY + startOffsetY);
  1190. context.lineTo(x2 - defX + endOffsetX, y2 - defY + endOffsetY);
  1191. }
  1192. function generatePath$3(context, parsedStyle) {
  1193. var _parsedStyle$defX = parsedStyle.defX,
  1194. defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
  1195. _parsedStyle$defY = parsedStyle.defY,
  1196. defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
  1197. markerStart = parsedStyle.markerStart,
  1198. markerEnd = parsedStyle.markerEnd,
  1199. markerStartOffset = parsedStyle.markerStartOffset,
  1200. markerEndOffset = parsedStyle.markerEndOffset;
  1201. var _parsedStyle$path = parsedStyle.path,
  1202. absolutePath = _parsedStyle$path.absolutePath,
  1203. segments = _parsedStyle$path.segments;
  1204. var startOffsetX = 0;
  1205. var startOffsetY = 0;
  1206. var endOffsetX = 0;
  1207. var endOffsetY = 0;
  1208. var rad = 0;
  1209. var x;
  1210. var y;
  1211. if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
  1212. var _markerStart$parentNo = markerStart.parentNode.getStartTangent(),
  1213. p1 = _markerStart$parentNo[0],
  1214. p2 = _markerStart$parentNo[1];
  1215. x = p1[0] - p2[0];
  1216. y = p1[1] - p2[1];
  1217. rad = Math.atan2(y, x);
  1218. startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
  1219. startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
  1220. }
  1221. if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
  1222. var _markerEnd$parentNode = markerEnd.parentNode.getEndTangent(),
  1223. _p = _markerEnd$parentNode[0],
  1224. _p2 = _markerEnd$parentNode[1];
  1225. x = _p[0] - _p2[0];
  1226. y = _p[1] - _p2[1];
  1227. rad = Math.atan2(y, x);
  1228. endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
  1229. endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
  1230. }
  1231. for (var i = 0; i < absolutePath.length; i++) {
  1232. var params = absolutePath[i];
  1233. var command = params[0];
  1234. var nextSegment = absolutePath[i + 1];
  1235. var useStartOffset = i === 0 && (startOffsetX !== 0 || startOffsetY !== 0);
  1236. var useEndOffset = (i === absolutePath.length - 1 || nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z')) && endOffsetX !== 0 && endOffsetY !== 0;
  1237. switch (command) {
  1238. case 'M':
  1239. // Use start marker offset
  1240. if (useStartOffset) {
  1241. context.moveTo(params[1] - defX + startOffsetX, params[2] - defY + startOffsetY);
  1242. context.lineTo(params[1] - defX, params[2] - defY);
  1243. } else {
  1244. context.moveTo(params[1] - defX, params[2] - defY);
  1245. }
  1246. break;
  1247. case 'L':
  1248. if (useEndOffset) {
  1249. context.lineTo(params[1] - defX + endOffsetX, params[2] - defY + endOffsetY);
  1250. } else {
  1251. context.lineTo(params[1] - defX, params[2] - defY);
  1252. }
  1253. break;
  1254. case 'Q':
  1255. context.quadraticCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY);
  1256. if (useEndOffset) {
  1257. context.lineTo(params[3] - defX + endOffsetX, params[4] - defY + endOffsetY);
  1258. }
  1259. break;
  1260. case 'C':
  1261. context.bezierCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY, params[5] - defX, params[6] - defY);
  1262. if (useEndOffset) {
  1263. context.lineTo(params[5] - defX + endOffsetX, params[6] - defY + endOffsetY);
  1264. }
  1265. break;
  1266. case 'A':
  1267. {
  1268. var arcParams = segments[i].arcParams;
  1269. var cx = arcParams.cx,
  1270. cy = arcParams.cy,
  1271. rx = arcParams.rx,
  1272. ry = arcParams.ry,
  1273. startAngle = arcParams.startAngle,
  1274. endAngle = arcParams.endAngle,
  1275. xRotation = arcParams.xRotation,
  1276. sweepFlag = arcParams.sweepFlag;
  1277. // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse
  1278. if (context.ellipse) {
  1279. context.ellipse(cx - defX, cy - defY, rx, ry, xRotation, startAngle, endAngle, !!(1 - sweepFlag));
  1280. } else {
  1281. // @see https://stackoverflow.com/a/47494351
  1282. var r = rx > ry ? rx : ry;
  1283. var scaleX = rx > ry ? 1 : rx / ry;
  1284. var scaleY = rx > ry ? ry / rx : 1;
  1285. context.translate(cx - defX, cy - defY);
  1286. context.rotate(xRotation);
  1287. context.scale(scaleX, scaleY);
  1288. context.arc(0, 0, r, startAngle, endAngle, !!(1 - sweepFlag));
  1289. context.scale(1 / scaleX, 1 / scaleY);
  1290. context.rotate(-xRotation);
  1291. context.translate(-(cx - defX), -(cy - defY));
  1292. }
  1293. if (useEndOffset) {
  1294. context.lineTo(params[6] - defX + endOffsetX, params[7] - defY + endOffsetY);
  1295. }
  1296. break;
  1297. }
  1298. case 'Z':
  1299. context.closePath();
  1300. break;
  1301. }
  1302. }
  1303. }
  1304. function generatePath$4(context, parsedStyle) {
  1305. var _parsedStyle$defX = parsedStyle.defX,
  1306. defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
  1307. _parsedStyle$defY = parsedStyle.defY,
  1308. defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
  1309. markerStart = parsedStyle.markerStart,
  1310. markerEnd = parsedStyle.markerEnd,
  1311. markerStartOffset = parsedStyle.markerStartOffset,
  1312. markerEndOffset = parsedStyle.markerEndOffset;
  1313. var points = parsedStyle.points.points;
  1314. var length = points.length;
  1315. var x1 = points[0][0] - defX;
  1316. var y1 = points[0][1] - defY;
  1317. var x2 = points[length - 1][0] - defX;
  1318. var y2 = points[length - 1][1] - defY;
  1319. var startOffsetX = 0;
  1320. var startOffsetY = 0;
  1321. var endOffsetX = 0;
  1322. var endOffsetY = 0;
  1323. var rad = 0;
  1324. var x;
  1325. var y;
  1326. if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
  1327. x = points[1][0] - points[0][0];
  1328. y = points[1][1] - points[0][1];
  1329. rad = Math.atan2(y, x);
  1330. startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
  1331. startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
  1332. }
  1333. if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
  1334. x = points[length - 1][0] - points[0][0];
  1335. y = points[length - 1][1] - points[0][1];
  1336. rad = Math.atan2(y, x);
  1337. endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
  1338. endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
  1339. }
  1340. context.moveTo(x1 + (startOffsetX || endOffsetX), y1 + (startOffsetY || endOffsetY));
  1341. for (var i = 1; i < length - 1; i++) {
  1342. var point = points[i];
  1343. context.lineTo(point[0] - defX, point[1] - defY);
  1344. }
  1345. context.lineTo(x2, y2);
  1346. }
  1347. function generatePath$5(context, parsedStyle) {
  1348. var _parsedStyle$defX = parsedStyle.defX,
  1349. defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
  1350. _parsedStyle$defY = parsedStyle.defY,
  1351. defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
  1352. markerStart = parsedStyle.markerStart,
  1353. markerEnd = parsedStyle.markerEnd,
  1354. markerStartOffset = parsedStyle.markerStartOffset,
  1355. markerEndOffset = parsedStyle.markerEndOffset;
  1356. var points = parsedStyle.points.points;
  1357. var length = points.length;
  1358. var x1 = points[0][0] - defX;
  1359. var y1 = points[0][1] - defY;
  1360. var x2 = points[length - 1][0] - defX;
  1361. var y2 = points[length - 1][1] - defY;
  1362. var startOffsetX = 0;
  1363. var startOffsetY = 0;
  1364. var endOffsetX = 0;
  1365. var endOffsetY = 0;
  1366. var rad = 0;
  1367. var x;
  1368. var y;
  1369. if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
  1370. x = points[1][0] - points[0][0];
  1371. y = points[1][1] - points[0][1];
  1372. rad = Math.atan2(y, x);
  1373. startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
  1374. startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
  1375. }
  1376. if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
  1377. x = points[length - 2][0] - points[length - 1][0];
  1378. y = points[length - 2][1] - points[length - 1][1];
  1379. rad = Math.atan2(y, x);
  1380. endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
  1381. endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
  1382. }
  1383. context.moveTo(x1 + startOffsetX, y1 + startOffsetY);
  1384. for (var i = 1; i < length - 1; i++) {
  1385. var point = points[i];
  1386. context.lineTo(point[0] - defX, point[1] - defY);
  1387. }
  1388. context.lineTo(x2 + endOffsetX, y2 + endOffsetY);
  1389. }
  1390. function generatePath$6(context, parsedStyle) {
  1391. var radius = parsedStyle.radius,
  1392. width = parsedStyle.width,
  1393. height = parsedStyle.height;
  1394. var w = width;
  1395. var h = height;
  1396. var hasRadius = radius && radius.some(function (r) {
  1397. return r !== 0;
  1398. });
  1399. if (!hasRadius) {
  1400. // Canvas support negative width/height of rect
  1401. context.rect(0, 0, w, h);
  1402. } else {
  1403. var signX = width > 0 ? 1 : -1;
  1404. var signY = height > 0 ? 1 : -1;
  1405. var sweepFlag = signX + signY === 0;
  1406. var _radius$map = radius.map(function (r) {
  1407. return clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2));
  1408. }),
  1409. tlr = _radius$map[0],
  1410. trr = _radius$map[1],
  1411. brr = _radius$map[2],
  1412. blr = _radius$map[3];
  1413. context.moveTo(signX * tlr, 0);
  1414. context.lineTo(w - signX * trr, 0);
  1415. if (trr !== 0) {
  1416. context.arc(w - signX * trr, signY * trr, trr, -signY * Math.PI / 2, signX > 0 ? 0 : Math.PI, sweepFlag);
  1417. }
  1418. context.lineTo(w, h - signY * brr);
  1419. if (brr !== 0) {
  1420. context.arc(w - signX * brr, h - signY * brr, brr, signX > 0 ? 0 : Math.PI, signY > 0 ? Math.PI / 2 : 1.5 * Math.PI, sweepFlag);
  1421. }
  1422. context.lineTo(signX * blr, h);
  1423. if (blr !== 0) {
  1424. context.arc(signX * blr, h - signY * blr, blr, signY > 0 ? Math.PI / 2 : -Math.PI / 2, signX > 0 ? Math.PI : 0, sweepFlag);
  1425. }
  1426. context.lineTo(0, signY * tlr);
  1427. if (tlr !== 0) {
  1428. context.arc(signX * tlr, signY * tlr, tlr, signX > 0 ? Math.PI : 0, signY > 0 ? Math.PI * 1.5 : Math.PI / 2, sweepFlag);
  1429. }
  1430. }
  1431. }
  1432. var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
  1433. _inheritsLoose$1(Plugin, _AbstractRendererPlug);
  1434. function Plugin() {
  1435. var _this;
  1436. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  1437. args[_key] = arguments[_key];
  1438. }
  1439. _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
  1440. _this.name = 'canvas-path-generator';
  1441. return _this;
  1442. }
  1443. var _proto = Plugin.prototype;
  1444. _proto.init = function init() {
  1445. var _pathGeneratorFactory;
  1446. var pathGeneratorFactory = (_pathGeneratorFactory = {}, _pathGeneratorFactory[gLite.Shape.CIRCLE] = generatePath, _pathGeneratorFactory[gLite.Shape.ELLIPSE] = generatePath$1, _pathGeneratorFactory[gLite.Shape.RECT] = generatePath$6, _pathGeneratorFactory[gLite.Shape.LINE] = generatePath$2, _pathGeneratorFactory[gLite.Shape.POLYLINE] = generatePath$5, _pathGeneratorFactory[gLite.Shape.POLYGON] = generatePath$4, _pathGeneratorFactory[gLite.Shape.PATH] = generatePath$3, _pathGeneratorFactory[gLite.Shape.TEXT] = undefined, _pathGeneratorFactory[gLite.Shape.GROUP] = undefined, _pathGeneratorFactory[gLite.Shape.IMAGE] = undefined, _pathGeneratorFactory[gLite.Shape.HTML] = undefined, _pathGeneratorFactory[gLite.Shape.MESH] = undefined, _pathGeneratorFactory);
  1447. // @ts-ignore
  1448. this.context.pathGeneratorFactory = pathGeneratorFactory;
  1449. };
  1450. _proto.destroy = function destroy() {
  1451. // @ts-ignore
  1452. delete this.context.pathGeneratorFactory;
  1453. };
  1454. return Plugin;
  1455. }(gLite.AbstractRendererPlugin);
  1456. var index_esm = /*#__PURE__*/Object.freeze({
  1457. __proto__: null,
  1458. Plugin: Plugin
  1459. });
  1460. function _regeneratorRuntime$1() {
  1461. _regeneratorRuntime$1 = function _regeneratorRuntime() {
  1462. return exports;
  1463. };
  1464. var exports = {},
  1465. Op = Object.prototype,
  1466. hasOwn = Op.hasOwnProperty,
  1467. defineProperty = Object.defineProperty || function (obj, key, desc) {
  1468. obj[key] = desc.value;
  1469. },
  1470. $Symbol = "function" == typeof Symbol ? Symbol : {},
  1471. iteratorSymbol = $Symbol.iterator || "@@iterator",
  1472. asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
  1473. toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  1474. function define(obj, key, value) {
  1475. return Object.defineProperty(obj, key, {
  1476. value: value,
  1477. enumerable: !0,
  1478. configurable: !0,
  1479. writable: !0
  1480. }), obj[key];
  1481. }
  1482. try {
  1483. define({}, "");
  1484. } catch (err) {
  1485. define = function define(obj, key, value) {
  1486. return obj[key] = value;
  1487. };
  1488. }
  1489. function wrap(innerFn, outerFn, self, tryLocsList) {
  1490. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
  1491. generator = Object.create(protoGenerator.prototype),
  1492. context = new Context(tryLocsList || []);
  1493. return defineProperty(generator, "_invoke", {
  1494. value: makeInvokeMethod(innerFn, self, context)
  1495. }), generator;
  1496. }
  1497. function tryCatch(fn, obj, arg) {
  1498. try {
  1499. return {
  1500. type: "normal",
  1501. arg: fn.call(obj, arg)
  1502. };
  1503. } catch (err) {
  1504. return {
  1505. type: "throw",
  1506. arg: err
  1507. };
  1508. }
  1509. }
  1510. exports.wrap = wrap;
  1511. var ContinueSentinel = {};
  1512. function Generator() {}
  1513. function GeneratorFunction() {}
  1514. function GeneratorFunctionPrototype() {}
  1515. var IteratorPrototype = {};
  1516. define(IteratorPrototype, iteratorSymbol, function () {
  1517. return this;
  1518. });
  1519. var getProto = Object.getPrototypeOf,
  1520. NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  1521. NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
  1522. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  1523. function defineIteratorMethods(prototype) {
  1524. ["next", "throw", "return"].forEach(function (method) {
  1525. define(prototype, method, function (arg) {
  1526. return this._invoke(method, arg);
  1527. });
  1528. });
  1529. }
  1530. function AsyncIterator(generator, PromiseImpl) {
  1531. function invoke(method, arg, resolve, reject) {
  1532. var record = tryCatch(generator[method], generator, arg);
  1533. if ("throw" !== record.type) {
  1534. var result = record.arg,
  1535. value = result.value;
  1536. return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
  1537. invoke("next", value, resolve, reject);
  1538. }, function (err) {
  1539. invoke("throw", err, resolve, reject);
  1540. }) : PromiseImpl.resolve(value).then(function (unwrapped) {
  1541. result.value = unwrapped, resolve(result);
  1542. }, function (error) {
  1543. return invoke("throw", error, resolve, reject);
  1544. });
  1545. }
  1546. reject(record.arg);
  1547. }
  1548. var previousPromise;
  1549. defineProperty(this, "_invoke", {
  1550. value: function value(method, arg) {
  1551. function callInvokeWithMethodAndArg() {
  1552. return new PromiseImpl(function (resolve, reject) {
  1553. invoke(method, arg, resolve, reject);
  1554. });
  1555. }
  1556. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  1557. }
  1558. });
  1559. }
  1560. function makeInvokeMethod(innerFn, self, context) {
  1561. var state = "suspendedStart";
  1562. return function (method, arg) {
  1563. if ("executing" === state) throw new Error("Generator is already running");
  1564. if ("completed" === state) {
  1565. if ("throw" === method) throw arg;
  1566. return doneResult();
  1567. }
  1568. for (context.method = method, context.arg = arg;;) {
  1569. var delegate = context.delegate;
  1570. if (delegate) {
  1571. var delegateResult = maybeInvokeDelegate(delegate, context);
  1572. if (delegateResult) {
  1573. if (delegateResult === ContinueSentinel) continue;
  1574. return delegateResult;
  1575. }
  1576. }
  1577. if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
  1578. if ("suspendedStart" === state) throw state = "completed", context.arg;
  1579. context.dispatchException(context.arg);
  1580. } else "return" === context.method && context.abrupt("return", context.arg);
  1581. state = "executing";
  1582. var record = tryCatch(innerFn, self, context);
  1583. if ("normal" === record.type) {
  1584. if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
  1585. return {
  1586. value: record.arg,
  1587. done: context.done
  1588. };
  1589. }
  1590. "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
  1591. }
  1592. };
  1593. }
  1594. function maybeInvokeDelegate(delegate, context) {
  1595. var methodName = context.method,
  1596. method = delegate.iterator[methodName];
  1597. 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;
  1598. var record = tryCatch(method, delegate.iterator, context.arg);
  1599. if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
  1600. var info = record.arg;
  1601. 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);
  1602. }
  1603. function pushTryEntry(locs) {
  1604. var entry = {
  1605. tryLoc: locs[0]
  1606. };
  1607. 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
  1608. }
  1609. function resetTryEntry(entry) {
  1610. var record = entry.completion || {};
  1611. record.type = "normal", delete record.arg, entry.completion = record;
  1612. }
  1613. function Context(tryLocsList) {
  1614. this.tryEntries = [{
  1615. tryLoc: "root"
  1616. }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
  1617. }
  1618. function values(iterable) {
  1619. if (iterable) {
  1620. var iteratorMethod = iterable[iteratorSymbol];
  1621. if (iteratorMethod) return iteratorMethod.call(iterable);
  1622. if ("function" == typeof iterable.next) return iterable;
  1623. if (!isNaN(iterable.length)) {
  1624. var i = -1,
  1625. next = function next() {
  1626. for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
  1627. return next.value = undefined, next.done = !0, next;
  1628. };
  1629. return next.next = next;
  1630. }
  1631. }
  1632. return {
  1633. next: doneResult
  1634. };
  1635. }
  1636. function doneResult() {
  1637. return {
  1638. value: undefined,
  1639. done: !0
  1640. };
  1641. }
  1642. return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
  1643. value: GeneratorFunctionPrototype,
  1644. configurable: !0
  1645. }), defineProperty(GeneratorFunctionPrototype, "constructor", {
  1646. value: GeneratorFunction,
  1647. configurable: !0
  1648. }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
  1649. var ctor = "function" == typeof genFun && genFun.constructor;
  1650. return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
  1651. }, exports.mark = function (genFun) {
  1652. return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
  1653. }, exports.awrap = function (arg) {
  1654. return {
  1655. __await: arg
  1656. };
  1657. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  1658. return this;
  1659. }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  1660. void 0 === PromiseImpl && (PromiseImpl = Promise);
  1661. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  1662. return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  1663. return result.done ? result.value : iter.next();
  1664. });
  1665. }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
  1666. return this;
  1667. }), define(Gp, "toString", function () {
  1668. return "[object Generator]";
  1669. }), exports.keys = function (val) {
  1670. var object = Object(val),
  1671. keys = [];
  1672. for (var key in object) keys.push(key);
  1673. return keys.reverse(), function next() {
  1674. for (; keys.length;) {
  1675. var key = keys.pop();
  1676. if (key in object) return next.value = key, next.done = !1, next;
  1677. }
  1678. return next.done = !0, next;
  1679. };
  1680. }, exports.values = values, Context.prototype = {
  1681. constructor: Context,
  1682. reset: function reset(skipTempReset) {
  1683. 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);
  1684. },
  1685. stop: function stop() {
  1686. this.done = !0;
  1687. var rootRecord = this.tryEntries[0].completion;
  1688. if ("throw" === rootRecord.type) throw rootRecord.arg;
  1689. return this.rval;
  1690. },
  1691. dispatchException: function dispatchException(exception) {
  1692. if (this.done) throw exception;
  1693. var context = this;
  1694. function handle(loc, caught) {
  1695. return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
  1696. }
  1697. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  1698. var entry = this.tryEntries[i],
  1699. record = entry.completion;
  1700. if ("root" === entry.tryLoc) return handle("end");
  1701. if (entry.tryLoc <= this.prev) {
  1702. var hasCatch = hasOwn.call(entry, "catchLoc"),
  1703. hasFinally = hasOwn.call(entry, "finallyLoc");
  1704. if (hasCatch && hasFinally) {
  1705. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  1706. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  1707. } else if (hasCatch) {
  1708. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  1709. } else {
  1710. if (!hasFinally) throw new Error("try statement without catch or finally");
  1711. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  1712. }
  1713. }
  1714. }
  1715. },
  1716. abrupt: function abrupt(type, arg) {
  1717. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  1718. var entry = this.tryEntries[i];
  1719. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  1720. var finallyEntry = entry;
  1721. break;
  1722. }
  1723. }
  1724. finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
  1725. var record = finallyEntry ? finallyEntry.completion : {};
  1726. return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
  1727. },
  1728. complete: function complete(record, afterLoc) {
  1729. if ("throw" === record.type) throw record.arg;
  1730. 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;
  1731. },
  1732. finish: function finish(finallyLoc) {
  1733. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  1734. var entry = this.tryEntries[i];
  1735. if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
  1736. }
  1737. },
  1738. catch: function _catch(tryLoc) {
  1739. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  1740. var entry = this.tryEntries[i];
  1741. if (entry.tryLoc === tryLoc) {
  1742. var record = entry.completion;
  1743. if ("throw" === record.type) {
  1744. var thrown = record.arg;
  1745. resetTryEntry(entry);
  1746. }
  1747. return thrown;
  1748. }
  1749. }
  1750. throw new Error("illegal catch attempt");
  1751. },
  1752. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  1753. return this.delegate = {
  1754. iterator: values(iterable),
  1755. resultName: resultName,
  1756. nextLoc: nextLoc
  1757. }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
  1758. }
  1759. }, exports;
  1760. }
  1761. function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
  1762. try {
  1763. var info = gen[key](arg);
  1764. var value = info.value;
  1765. } catch (error) {
  1766. reject(error);
  1767. return;
  1768. }
  1769. if (info.done) {
  1770. resolve(value);
  1771. } else {
  1772. Promise.resolve(value).then(_next, _throw);
  1773. }
  1774. }
  1775. function _asyncToGenerator$1(fn) {
  1776. return function () {
  1777. var self = this,
  1778. args = arguments;
  1779. return new Promise(function (resolve, reject) {
  1780. var gen = fn.apply(self, args);
  1781. function _next(value) {
  1782. asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
  1783. }
  1784. function _throw(err) {
  1785. asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
  1786. }
  1787. _next(undefined);
  1788. });
  1789. };
  1790. }
  1791. function _inheritsLoose$2(subClass, superClass) {
  1792. subClass.prototype = Object.create(superClass.prototype);
  1793. subClass.prototype.constructor = subClass;
  1794. _setPrototypeOf$2(subClass, superClass);
  1795. }
  1796. function _setPrototypeOf$2(o, p) {
  1797. _setPrototypeOf$2 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  1798. o.__proto__ = p;
  1799. return o;
  1800. };
  1801. return _setPrototypeOf$2(o, p);
  1802. }
  1803. function _unsupportedIterableToArray(o, minLen) {
  1804. if (!o) return;
  1805. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  1806. var n = Object.prototype.toString.call(o).slice(8, -1);
  1807. if (n === "Object" && o.constructor) n = o.constructor.name;
  1808. if (n === "Map" || n === "Set") return Array.from(o);
  1809. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  1810. }
  1811. function _arrayLikeToArray(arr, len) {
  1812. if (len == null || len > arr.length) len = arr.length;
  1813. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  1814. return arr2;
  1815. }
  1816. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  1817. var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
  1818. if (it) return (it = it.call(o)).next.bind(it);
  1819. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  1820. if (it) o = it;
  1821. var i = 0;
  1822. return function () {
  1823. if (i >= o.length) return {
  1824. done: true
  1825. };
  1826. return {
  1827. done: false,
  1828. value: o[i++]
  1829. };
  1830. };
  1831. }
  1832. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  1833. }
  1834. var tmpVec3a = create$1();
  1835. var tmpVec3b = create$1();
  1836. var tmpVec3c = create$1();
  1837. var tmpMat4 = create();
  1838. /**
  1839. * pick shape(s) with Mouse/Touch event
  1840. *
  1841. * 1. find AABB with r-tree
  1842. * 2. do math calculation with geometry in an accurate way
  1843. */
  1844. var CanvasPickerPlugin = /*#__PURE__*/function () {
  1845. function CanvasPickerPlugin() {
  1846. var _this = this;
  1847. this.context = void 0;
  1848. this.runtime = void 0;
  1849. this.isHit = function (displayObject, position, worldTransform, isClipPath) {
  1850. // use picker for current shape's type
  1851. var pick = _this.context.pointInPathPickerFactory[displayObject.nodeName];
  1852. if (pick) {
  1853. // invert with world matrix
  1854. var invertWorldMat = invert(tmpMat4, worldTransform);
  1855. // transform client position to local space, do picking in local space
  1856. var localPosition = transformMat4(tmpVec3b, set(tmpVec3c, position[0], position[1], 0), invertWorldMat);
  1857. // account for anchor
  1858. var _displayObject$getGeo = displayObject.getGeometryBounds(),
  1859. halfExtents = _displayObject$getGeo.halfExtents;
  1860. var anchor = displayObject.parsedStyle.anchor;
  1861. localPosition[0] += (anchor && anchor[0] || 0) * halfExtents[0] * 2;
  1862. localPosition[1] += (anchor && anchor[1] || 0) * halfExtents[1] * 2;
  1863. if (pick(displayObject, new gLite.Point(localPosition[0], localPosition[1]), isClipPath, _this.isPointInPath, _this.context, _this.runtime)) {
  1864. return true;
  1865. }
  1866. }
  1867. return false;
  1868. };
  1869. /**
  1870. * use native picking method
  1871. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/isPointInPath
  1872. */
  1873. this.isPointInPath = function (displayObject, position) {
  1874. var context = _this.runtime.offscreenCanvas.getOrCreateContext(_this.context.config.offscreenCanvas);
  1875. var generatePath = _this.context.pathGeneratorFactory[displayObject.nodeName];
  1876. if (generatePath) {
  1877. context.beginPath();
  1878. generatePath(context, displayObject.parsedStyle);
  1879. context.closePath();
  1880. }
  1881. return context.isPointInPath(position.x, position.y);
  1882. };
  1883. }
  1884. var _proto = CanvasPickerPlugin.prototype;
  1885. _proto.apply = function apply(context, runtime) {
  1886. var _renderingContext$roo,
  1887. _this2 = this;
  1888. var renderingService = context.renderingService,
  1889. renderingContext = context.renderingContext;
  1890. this.context = context;
  1891. this.runtime = runtime;
  1892. var document = (_renderingContext$roo = renderingContext.root) === null || _renderingContext$roo === void 0 ? void 0 : _renderingContext$roo.ownerDocument;
  1893. renderingService.hooks.pick.tapPromise(CanvasPickerPlugin.tag, /*#__PURE__*/function () {
  1894. var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(result) {
  1895. return _regeneratorRuntime$1().wrap(function _callee$(_context) {
  1896. while (1) switch (_context.prev = _context.next) {
  1897. case 0:
  1898. return _context.abrupt("return", _this2.pick(document, result));
  1899. case 1:
  1900. case "end":
  1901. return _context.stop();
  1902. }
  1903. }, _callee);
  1904. }));
  1905. return function (_x) {
  1906. return _ref.apply(this, arguments);
  1907. };
  1908. }());
  1909. renderingService.hooks.pickSync.tap(CanvasPickerPlugin.tag, function (result) {
  1910. return _this2.pick(document, result);
  1911. });
  1912. };
  1913. _proto.pick = function pick(document, result) {
  1914. var topmost = result.topmost,
  1915. _result$position = result.position,
  1916. x = _result$position.x,
  1917. y = _result$position.y;
  1918. // position in world space
  1919. var position = set(tmpVec3a, x, y, 0);
  1920. // query by AABB first with spatial index(r-tree)
  1921. var hitTestList = document.elementsFromBBox(position[0], position[1], position[0], position[1]);
  1922. // test with clip path & origin shape
  1923. // @see https://github.com/antvis/g/issues/1064
  1924. var pickedDisplayObjects = [];
  1925. for (var _iterator = _createForOfIteratorHelperLoose(hitTestList), _step; !(_step = _iterator()).done;) {
  1926. var displayObject = _step.value;
  1927. var worldTransform = displayObject.getWorldTransform();
  1928. var isHitOriginShape = this.isHit(displayObject, position, worldTransform, false);
  1929. if (isHitOriginShape) {
  1930. // should look up in the ancestor node
  1931. var clipped = gLite.findClosestClipPathTarget(displayObject);
  1932. if (clipped) {
  1933. var clipPath = clipped.parsedStyle.clipPath;
  1934. var isHitClipPath = this.isHit(clipPath, position, clipPath.getWorldTransform(), true);
  1935. if (isHitClipPath) {
  1936. if (topmost) {
  1937. result.picked = [displayObject];
  1938. return result;
  1939. } else {
  1940. pickedDisplayObjects.push(displayObject);
  1941. }
  1942. }
  1943. } else {
  1944. if (topmost) {
  1945. result.picked = [displayObject];
  1946. return result;
  1947. } else {
  1948. pickedDisplayObjects.push(displayObject);
  1949. }
  1950. }
  1951. }
  1952. }
  1953. result.picked = pickedDisplayObjects;
  1954. return result;
  1955. };
  1956. return CanvasPickerPlugin;
  1957. }();
  1958. CanvasPickerPlugin.tag = 'CanvasPicker';
  1959. /**
  1960. * 两点之间的距离
  1961. * @param {number} x1 起始点 x
  1962. * @param {number} y1 起始点 y
  1963. * @param {number} x2 结束点 x
  1964. * @param {number} y2 结束点 y
  1965. * @return {number} 距离
  1966. */
  1967. function distance(x1, y1, x2, y2) {
  1968. var dx = x1 - x2;
  1969. var dy = y1 - y2;
  1970. return Math.sqrt(dx * dx + dy * dy);
  1971. }
  1972. function isNumberEqual(v1, v2) {
  1973. return Math.abs(v1 - v2) < 0.001;
  1974. }
  1975. function getBBoxByArray(xArr, yArr) {
  1976. var minX = Math.min.apply(Math, xArr);
  1977. var minY = Math.min.apply(Math, yArr);
  1978. var maxX = Math.max.apply(Math, xArr);
  1979. var maxY = Math.max.apply(Math, yArr);
  1980. return {
  1981. x: minX,
  1982. y: minY,
  1983. width: maxX - minX,
  1984. height: maxY - minY
  1985. };
  1986. }
  1987. function piMod(angle) {
  1988. return (angle + Math.PI * 2) % (Math.PI * 2);
  1989. }
  1990. var line = {
  1991. /**
  1992. * 计算线段的包围盒
  1993. * @param {number} x1 起始点 x
  1994. * @param {number} y1 起始点 y
  1995. * @param {number} x2 结束点 x
  1996. * @param {number} y2 结束点 y
  1997. * @return {object} 包围盒对象
  1998. */
  1999. box: function box(x1, y1, x2, y2) {
  2000. return getBBoxByArray([x1, x2], [y1, y2]);
  2001. },
  2002. /**
  2003. * 线段的长度
  2004. * @param {number} x1 起始点 x
  2005. * @param {number} y1 起始点 y
  2006. * @param {number} x2 结束点 x
  2007. * @param {number} y2 结束点 y
  2008. * @return {number} 距离
  2009. */
  2010. length: function length(x1, y1, x2, y2) {
  2011. return distance(x1, y1, x2, y2);
  2012. },
  2013. /**
  2014. * 根据比例获取点
  2015. * @param {number} x1 起始点 x
  2016. * @param {number} y1 起始点 y
  2017. * @param {number} x2 结束点 x
  2018. * @param {number} y2 结束点 y
  2019. * @param {number} t 指定比例
  2020. * @return {object} 包含 x, y 的点
  2021. */
  2022. pointAt: function pointAt(x1, y1, x2, y2, t) {
  2023. return {
  2024. x: (1 - t) * x1 + t * x2,
  2025. y: (1 - t) * y1 + t * y2
  2026. };
  2027. },
  2028. /**
  2029. * 点到线段的距离
  2030. * @param {number} x1 起始点 x
  2031. * @param {number} y1 起始点 y
  2032. * @param {number} x2 结束点 x
  2033. * @param {number} y2 结束点 y
  2034. * @param {number} x 测试点 x
  2035. * @param {number} y 测试点 y
  2036. * @return {number} 距离
  2037. */
  2038. pointDistance: function pointDistance(x1, y1, x2, y2, x, y) {
  2039. // 投影距离 x1, y1 的向量,假设 p, p1, p2 三个点,投影点为 a
  2040. // p1a = p1p.p1p2/|p1p2| * (p1p 的单位向量)
  2041. var cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
  2042. if (cross < 0) {
  2043. return distance(x1, y1, x, y);
  2044. }
  2045. var lengthSquare = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
  2046. if (cross > lengthSquare) {
  2047. return distance(x2, y2, x, y);
  2048. }
  2049. return this.pointToLine(x1, y1, x2, y2, x, y);
  2050. },
  2051. /**
  2052. * 点到直线的距离,而不是点到线段的距离
  2053. * @param {number} x1 起始点 x
  2054. * @param {number} y1 起始点 y
  2055. * @param {number} x2 结束点 x
  2056. * @param {number} y2 结束点 y
  2057. * @param {number} x 测试点 x
  2058. * @param {number} y 测试点 y
  2059. * @return {number} 距离
  2060. */
  2061. pointToLine: function pointToLine(x1, y1, x2, y2, x, y) {
  2062. var d = [x2 - x1, y2 - y1];
  2063. // 如果端点相等,则判定点到点的距离
  2064. if (exactEquals(d, [0, 0])) {
  2065. return Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
  2066. }
  2067. var u = [-d[1], d[0]];
  2068. normalize(u, u);
  2069. var a = [x - x1, y - y1];
  2070. return Math.abs(dot(a, u));
  2071. },
  2072. /**
  2073. * 线段的角度
  2074. * @param {number} x1 起始点 x
  2075. * @param {number} y1 起始点 y
  2076. * @param {number} x2 结束点 x
  2077. * @param {number} y2 结束点 y
  2078. * @return {number} 导数
  2079. */
  2080. tangentAngle: function tangentAngle(x1, y1, x2, y2) {
  2081. return Math.atan2(y2 - y1, x2 - x1);
  2082. }
  2083. };
  2084. var EPSILON = 0.0001;
  2085. /**
  2086. * 使用牛顿切割法求最近的点
  2087. * @param {number[]} xArr 点的 x 数组
  2088. * @param {number[]} yArr 点的 y 数组
  2089. * @param {number} x 指定的点 x
  2090. * @param {number} y 指定的点 y
  2091. * @param {Function} tCallback 差值函数
  2092. */
  2093. function nearestPoint(xArr, yArr, x, y, tCallback, length) {
  2094. var t = -1;
  2095. var d = Infinity;
  2096. var v0 = [x, y];
  2097. var segNum = 20;
  2098. if (length && length > 200) {
  2099. segNum = length / 10;
  2100. }
  2101. var increaseRate = 1 / segNum;
  2102. var interval = increaseRate / 10;
  2103. for (var i = 0; i <= segNum; i++) {
  2104. var _t = i * increaseRate;
  2105. var v1 = [tCallback.apply(void 0, xArr.concat([_t])), tCallback.apply(void 0, yArr.concat([_t]))];
  2106. var d1 = distance(v0[0], v0[1], v1[0], v1[1]);
  2107. if (d1 < d) {
  2108. t = _t;
  2109. d = d1;
  2110. }
  2111. }
  2112. // 提前终止
  2113. if (t === 0) {
  2114. return {
  2115. x: xArr[0],
  2116. y: yArr[0]
  2117. };
  2118. }
  2119. if (t === 1) {
  2120. var count = xArr.length;
  2121. return {
  2122. x: xArr[count - 1],
  2123. y: yArr[count - 1]
  2124. };
  2125. }
  2126. d = Infinity;
  2127. for (var _i = 0; _i < 32; _i++) {
  2128. if (interval < EPSILON) {
  2129. break;
  2130. }
  2131. var prev = t - interval;
  2132. var next = t + interval;
  2133. var _v = [tCallback.apply(void 0, xArr.concat([prev])), tCallback.apply(void 0, yArr.concat([prev]))];
  2134. var _d = distance(v0[0], v0[1], _v[0], _v[1]);
  2135. if (prev >= 0 && _d < d) {
  2136. t = prev;
  2137. d = _d;
  2138. } else {
  2139. var v2 = [tCallback.apply(void 0, xArr.concat([next])), tCallback.apply(void 0, yArr.concat([next]))];
  2140. var d2 = distance(v0[0], v0[1], v2[0], v2[1]);
  2141. if (next <= 1 && d2 < d) {
  2142. t = next;
  2143. d = d2;
  2144. } else {
  2145. interval *= 0.5;
  2146. }
  2147. }
  2148. }
  2149. return {
  2150. x: tCallback.apply(void 0, xArr.concat([t])),
  2151. y: tCallback.apply(void 0, yArr.concat([t]))
  2152. };
  2153. }
  2154. // 近似求解 https://community.khronos.org/t/3d-cubic-bezier-segment-length/62363/2
  2155. function snapLength(xArr, yArr) {
  2156. var totalLength = 0;
  2157. var count = xArr.length;
  2158. for (var i = 0; i < count; i++) {
  2159. var x = xArr[i];
  2160. var y = yArr[i];
  2161. var nextX = xArr[(i + 1) % count];
  2162. var nextY = yArr[(i + 1) % count];
  2163. totalLength += distance(x, y, nextX, nextY);
  2164. }
  2165. return totalLength / 2;
  2166. }
  2167. // 差值公式
  2168. function quadraticAt(p0, p1, p2, t) {
  2169. var onet = 1 - t;
  2170. return onet * onet * p0 + 2 * t * onet * p1 + t * t * p2;
  2171. }
  2172. // 求极值
  2173. function extrema(p0, p1, p2) {
  2174. var a = p0 + p2 - 2 * p1;
  2175. if (isNumberEqual(a, 0)) {
  2176. return [0.5];
  2177. }
  2178. var rst = (p0 - p1) / a;
  2179. if (rst <= 1 && rst >= 0) {
  2180. return [rst];
  2181. }
  2182. return [];
  2183. }
  2184. function derivativeAt(p0, p1, p2, t) {
  2185. return 2 * (1 - t) * (p1 - p0) + 2 * t * (p2 - p1);
  2186. }
  2187. // 分割贝塞尔曲线
  2188. function divideQuadratic(x1, y1, x2, y2, x3, y3, t) {
  2189. // 划分点
  2190. var xt = quadraticAt(x1, x2, x3, t);
  2191. var yt = quadraticAt(y1, y2, y3, t);
  2192. // 分割的第一条曲线的控制点
  2193. var controlPoint1 = line.pointAt(x1, y1, x2, y2, t);
  2194. // 分割的第二条曲线的控制点
  2195. var controlPoint2 = line.pointAt(x2, y2, x3, y3, t);
  2196. return [[x1, y1, controlPoint1.x, controlPoint1.y, xt, yt], [xt, yt, controlPoint2.x, controlPoint2.y, x3, y3]];
  2197. }
  2198. // 使用迭代法取贝塞尔曲线的长度
  2199. function quadraticLength(x1, y1, x2, y2, x3, y3, iterationCount) {
  2200. if (iterationCount === 0) {
  2201. return (distance(x1, y1, x2, y2) + distance(x2, y2, x3, y3) + distance(x1, y1, x3, y3)) / 2;
  2202. }
  2203. var quadratics = divideQuadratic(x1, y1, x2, y2, x3, y3, 0.5);
  2204. var left = quadratics[0];
  2205. var right = quadratics[1];
  2206. left.push(iterationCount - 1);
  2207. right.push(iterationCount - 1);
  2208. return quadraticLength.apply(void 0, left) + quadraticLength.apply(void 0, right);
  2209. }
  2210. var quadratic = {
  2211. box: function box(x1, y1, x2, y2, x3, y3) {
  2212. var xExtrema = extrema(x1, x2, x3)[0];
  2213. var yExtrema = extrema(y1, y2, y3)[0];
  2214. // 控制点不加入 box 的计算
  2215. var xArr = [x1, x3];
  2216. var yArr = [y1, y3];
  2217. if (xExtrema !== undefined) {
  2218. xArr.push(quadraticAt(x1, x2, x3, xExtrema));
  2219. }
  2220. if (yExtrema !== undefined) {
  2221. yArr.push(quadraticAt(y1, y2, y3, yExtrema));
  2222. }
  2223. return getBBoxByArray(xArr, yArr);
  2224. },
  2225. length: function length(x1, y1, x2, y2, x3, y3) {
  2226. return quadraticLength(x1, y1, x2, y2, x3, y3, 3);
  2227. },
  2228. nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x0, y0) {
  2229. return nearestPoint([x1, x2, x3], [y1, y2, y3], x0, y0, quadraticAt);
  2230. },
  2231. pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x0, y0) {
  2232. var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x0, y0);
  2233. return distance(point.x, point.y, x0, y0);
  2234. },
  2235. interpolationAt: quadraticAt,
  2236. pointAt: function pointAt(x1, y1, x2, y2, x3, y3, t) {
  2237. return {
  2238. x: quadraticAt(x1, x2, x3, t),
  2239. y: quadraticAt(y1, y2, y3, t)
  2240. };
  2241. },
  2242. divide: function divide(x1, y1, x2, y2, x3, y3, t) {
  2243. return divideQuadratic(x1, y1, x2, y2, x3, y3, t);
  2244. },
  2245. tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, t) {
  2246. var dx = derivativeAt(x1, x2, x3, t);
  2247. var dy = derivativeAt(y1, y2, y3, t);
  2248. var angle = Math.atan2(dy, dx);
  2249. return piMod(angle);
  2250. }
  2251. };
  2252. function cubicAt(p0, p1, p2, p3, t) {
  2253. var onet = 1 - t; // t * t * t 的性能大概是 Math.pow(t, 3) 的三倍
  2254. return onet * onet * onet * p0 + 3 * p1 * t * onet * onet + 3 * p2 * t * t * onet + p3 * t * t * t;
  2255. }
  2256. function derivativeAt$1(p0, p1, p2, p3, t) {
  2257. var onet = 1 - t;
  2258. return 3 * (onet * onet * (p1 - p0) + 2 * onet * t * (p2 - p1) + t * t * (p3 - p2));
  2259. }
  2260. function extrema$1(p0, p1, p2, p3) {
  2261. var a = -3 * p0 + 9 * p1 - 9 * p2 + 3 * p3;
  2262. var b = 6 * p0 - 12 * p1 + 6 * p2;
  2263. var c = 3 * p1 - 3 * p0;
  2264. var extremas = [];
  2265. var t1;
  2266. var t2;
  2267. var discSqrt;
  2268. if (isNumberEqual(a, 0)) {
  2269. if (!isNumberEqual(b, 0)) {
  2270. t1 = -c / b;
  2271. if (t1 >= 0 && t1 <= 1) {
  2272. extremas.push(t1);
  2273. }
  2274. }
  2275. } else {
  2276. var disc = b * b - 4 * a * c;
  2277. if (isNumberEqual(disc, 0)) {
  2278. extremas.push(-b / (2 * a));
  2279. } else if (disc > 0) {
  2280. discSqrt = Math.sqrt(disc);
  2281. t1 = (-b + discSqrt) / (2 * a);
  2282. t2 = (-b - discSqrt) / (2 * a);
  2283. if (t1 >= 0 && t1 <= 1) {
  2284. extremas.push(t1);
  2285. }
  2286. if (t2 >= 0 && t2 <= 1) {
  2287. extremas.push(t2);
  2288. }
  2289. }
  2290. }
  2291. return extremas;
  2292. }
  2293. // 分割贝塞尔曲线
  2294. function divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t) {
  2295. // 划分点
  2296. var xt = cubicAt(x1, x2, x3, x4, t);
  2297. var yt = cubicAt(y1, y2, y3, y4, t);
  2298. // 计算两点之间的差值点
  2299. var c1 = line.pointAt(x1, y1, x2, y2, t);
  2300. var c2 = line.pointAt(x2, y2, x3, y3, t);
  2301. var c3 = line.pointAt(x3, y3, x4, y4, t);
  2302. var c12 = line.pointAt(c1.x, c1.y, c2.x, c2.y, t);
  2303. var c23 = line.pointAt(c2.x, c2.y, c3.x, c3.y, t);
  2304. 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]];
  2305. }
  2306. // 使用迭代法取贝塞尔曲线的长度,二阶和三阶分开写,更清晰和便于调试
  2307. function cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, iterationCount) {
  2308. if (iterationCount === 0) {
  2309. return snapLength([x1, x2, x3, x4], [y1, y2, y3, y4]);
  2310. }
  2311. var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5);
  2312. var left = [].concat(cubics[0], [iterationCount - 1]);
  2313. var right = [].concat(cubics[1], [iterationCount - 1]);
  2314. return cubicLength.apply(void 0, left) + cubicLength.apply(void 0, right);
  2315. }
  2316. var cubic = {
  2317. extrema: extrema$1,
  2318. box: function box(x1, y1, x2, y2, x3, y3, x4, y4) {
  2319. var xArr = [x1, x4];
  2320. var yArr = [y1, y4];
  2321. var xExtrema = extrema$1(x1, x2, x3, x4);
  2322. var yExtrema = extrema$1(y1, y2, y3, y4);
  2323. for (var i = 0; i < xExtrema.length; i++) {
  2324. xArr.push(cubicAt(x1, x2, x3, x4, xExtrema[i]));
  2325. }
  2326. for (var _i = 0; _i < yExtrema.length; _i++) {
  2327. yArr.push(cubicAt(y1, y2, y3, y4, yExtrema[_i]));
  2328. }
  2329. return getBBoxByArray(xArr, yArr);
  2330. },
  2331. length: function length(x1, y1, x2, y2, x3, y3, x4, y4) {
  2332. // 迭代三次,划分成 8 段求长度
  2333. return cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, 3);
  2334. },
  2335. nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
  2336. return nearestPoint([x1, x2, x3, x4], [y1, y2, y3, y4], x0, y0, cubicAt, length);
  2337. },
  2338. pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
  2339. var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length);
  2340. return distance(point.x, point.y, x0, y0);
  2341. },
  2342. interpolationAt: cubicAt,
  2343. pointAt: function pointAt(x1, y1, x2, y2, x3, y3, x4, y4, t) {
  2344. return {
  2345. x: cubicAt(x1, x2, x3, x4, t),
  2346. y: cubicAt(y1, y2, y3, y4, t)
  2347. };
  2348. },
  2349. divide: function divide(x1, y1, x2, y2, x3, y3, x4, y4, t) {
  2350. return divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t);
  2351. },
  2352. tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, x4, y4, t) {
  2353. var dx = derivativeAt$1(x1, x2, x3, x4, t);
  2354. var dy = derivativeAt$1(y1, y2, y3, y4, t);
  2355. return piMod(Math.atan2(dy, dx));
  2356. }
  2357. };
  2358. function distance$1(x1, y1, x2, y2) {
  2359. var dx = x1 - x2;
  2360. var dy = y1 - y2;
  2361. return Math.sqrt(dx * dx + dy * dy);
  2362. }
  2363. function inBox(minX, minY, width, height, x, y) {
  2364. return x >= minX && x <= minX + width && y >= minY && y <= minY + height;
  2365. }
  2366. function inRect(minX, minY, width, height, lineWidth, x, y) {
  2367. var halfWidth = lineWidth / 2;
  2368. // 将四个边看做矩形来检测,比边的检测算法要快
  2369. return inBox(minX - halfWidth, minY - halfWidth, width, lineWidth, x, y) ||
  2370. // 上边
  2371. inBox(minX + width - halfWidth, minY - halfWidth, lineWidth, height, x, y) ||
  2372. // 右边
  2373. inBox(minX + halfWidth, minY + height - halfWidth, width, lineWidth, x, y) ||
  2374. // 下边
  2375. inBox(minX - halfWidth, minY + halfWidth, lineWidth, height, x, y); // 左边
  2376. }
  2377. function inArc(cx, cy, r, startAngle, endAngle, lineWidth, x, y) {
  2378. var angle = (Math.atan2(y - cy, x - cx) + Math.PI * 2) % (Math.PI * 2); // 转换到 0 - 2 * Math.PI 之间
  2379. // if (angle < startAngle || angle > endAngle) {
  2380. // return false;
  2381. // }
  2382. var point = {
  2383. x: cx + r * Math.cos(angle),
  2384. y: cy + r * Math.sin(angle)
  2385. };
  2386. return distance$1(point.x, point.y, x, y) <= lineWidth / 2;
  2387. }
  2388. function inLine(x1, y1, x2, y2, lineWidth, x, y) {
  2389. var minX = Math.min(x1, x2);
  2390. var maxX = Math.max(x1, x2);
  2391. var minY = Math.min(y1, y2);
  2392. var maxY = Math.max(y1, y2);
  2393. var halfWidth = lineWidth / 2;
  2394. // 因为目前的方案是计算点到直线的距离,而有可能会在延长线上,所以要先判断是否在包围盒内
  2395. // 这种方案会在水平或者竖直的情况下载线的延长线上有半 lineWidth 的误差
  2396. if (!(x >= minX - halfWidth && x <= maxX + halfWidth && y >= minY - halfWidth && y <= maxY + halfWidth)) {
  2397. return false;
  2398. }
  2399. // 因为已经计算了包围盒,所以仅需要计算到直线的距离即可,可以显著提升性能
  2400. return line.pointToLine(x1, y1, x2, y2, x, y) <= lineWidth / 2;
  2401. }
  2402. function inPolyline(points, lineWidth, x, y, isClose) {
  2403. var count = points.length;
  2404. if (count < 2) {
  2405. return false;
  2406. }
  2407. for (var i = 0; i < count - 1; i++) {
  2408. var x1 = points[i][0];
  2409. var y1 = points[i][1];
  2410. var x2 = points[i + 1][0];
  2411. var y2 = points[i + 1][1];
  2412. if (inLine(x1, y1, x2, y2, lineWidth, x, y)) {
  2413. return true;
  2414. }
  2415. }
  2416. // 如果封闭,则计算起始点和结束点的边
  2417. if (isClose) {
  2418. var first = points[0];
  2419. var last = points[count - 1];
  2420. if (inLine(first[0], first[1], last[0], last[1], lineWidth, x, y)) {
  2421. return true;
  2422. }
  2423. }
  2424. return false;
  2425. }
  2426. // 多边形的射线检测,参考:https://blog.csdn.net/WilliamSun0122/article/details/77994526
  2427. var tolerance = 1e-6;
  2428. // 三态函数,判断两个double在eps精度下的大小关系
  2429. function dcmp(x) {
  2430. if (Math.abs(x) < tolerance) {
  2431. return 0;
  2432. }
  2433. return x < 0 ? -1 : 1;
  2434. }
  2435. // 判断点Q是否在p1和p2的线段上
  2436. function onSegment(p1, p2, q) {
  2437. if ((q[0] - p1[0]) * (p2[1] - p1[1]) === (p2[0] - p1[0]) * (q[1] - p1[1]) && Math.min(p1[0], p2[0]) <= q[0] && q[0] <= Math.max(p1[0], p2[0]) && Math.min(p1[1], p2[1]) <= q[1] && q[1] <= Math.max(p1[1], p2[1])) {
  2438. return true;
  2439. }
  2440. return false;
  2441. }
  2442. // 判断点P在多边形内-射线法
  2443. function inPolygon(points, x, y) {
  2444. var isHit = false;
  2445. var n = points.length;
  2446. if (n <= 2) {
  2447. // svg 中点小于 3 个时,不显示,也无法被拾取
  2448. return false;
  2449. }
  2450. for (var i = 0; i < n; i++) {
  2451. var p1 = points[i];
  2452. var p2 = points[(i + 1) % n];
  2453. if (onSegment(p1, p2, [x, y])) {
  2454. // 点在多边形一条边上
  2455. return true;
  2456. }
  2457. // 前一个判断min(p1[1],p2[1])<P.y<=max(p1[1],p2[1])
  2458. // 后一个判断被测点 在 射线与边交点 的左边
  2459. if (dcmp(p1[1] - y) > 0 !== dcmp(p2[1] - y) > 0 && dcmp(x - (y - p1[1]) * (p1[0] - p2[0]) / (p1[1] - p2[1]) - p1[0]) < 0) {
  2460. isHit = !isHit;
  2461. }
  2462. }
  2463. return isHit;
  2464. }
  2465. function inPolygons(polygons, x, y) {
  2466. var isHit = false;
  2467. for (var i = 0; i < polygons.length; i++) {
  2468. var points = polygons[i];
  2469. isHit = inPolygon(points, x, y);
  2470. if (isHit) {
  2471. break;
  2472. }
  2473. }
  2474. return isHit;
  2475. }
  2476. function isPointInPath(displayObject, position, isClipPath) {
  2477. var _displayObject$parsed = displayObject.parsedStyle,
  2478. r = _displayObject$parsed.r,
  2479. fill = _displayObject$parsed.fill,
  2480. stroke = _displayObject$parsed.stroke,
  2481. lineWidth = _displayObject$parsed.lineWidth,
  2482. increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
  2483. pointerEvents = _displayObject$parsed.pointerEvents;
  2484. var halfLineWidth = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) / 2;
  2485. var absDistance = distance$1(r, r, position.x, position.y);
  2486. var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
  2487. hasFill = _isFillOrStrokeAffect[0],
  2488. hasStroke = _isFillOrStrokeAffect[1];
  2489. if (hasFill && hasStroke || isClipPath) {
  2490. return absDistance <= r + halfLineWidth;
  2491. }
  2492. if (hasFill) {
  2493. return absDistance <= r;
  2494. }
  2495. if (hasStroke) {
  2496. return absDistance >= r - halfLineWidth && absDistance <= r + halfLineWidth;
  2497. }
  2498. return false;
  2499. }
  2500. function ellipseDistance(squareX, squareY, rx, ry) {
  2501. return squareX / (rx * rx) + squareY / (ry * ry);
  2502. }
  2503. function isPointInPath$1(displayObject, position, isClipPath) {
  2504. var _displayObject$parsed = displayObject.parsedStyle,
  2505. rx = _displayObject$parsed.rx,
  2506. ry = _displayObject$parsed.ry,
  2507. fill = _displayObject$parsed.fill,
  2508. stroke = _displayObject$parsed.stroke,
  2509. lineWidth = _displayObject$parsed.lineWidth,
  2510. increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
  2511. pointerEvents = _displayObject$parsed.pointerEvents;
  2512. var x = position.x,
  2513. y = position.y;
  2514. var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
  2515. hasFill = _isFillOrStrokeAffect[0],
  2516. hasStroke = _isFillOrStrokeAffect[1];
  2517. var halfLineWith = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) / 2;
  2518. var squareX = (x - rx) * (x - rx);
  2519. var squareY = (y - ry) * (y - ry);
  2520. // 使用椭圆的公式: x*x/rx*rx + y*y/ry*ry = 1;
  2521. if (hasFill && hasStroke || isClipPath) {
  2522. return ellipseDistance(squareX, squareY, rx + halfLineWith, ry + halfLineWith) <= 1;
  2523. }
  2524. if (hasFill) {
  2525. return ellipseDistance(squareX, squareY, rx, ry) <= 1;
  2526. }
  2527. if (hasStroke) {
  2528. return ellipseDistance(squareX, squareY, rx - halfLineWith, ry - halfLineWith) >= 1 && ellipseDistance(squareX, squareY, rx + halfLineWith, ry + halfLineWith) <= 1;
  2529. }
  2530. return false;
  2531. }
  2532. function isPointInPath$2(displayObject, position, isClipPath) {
  2533. var _displayObject$parsed = displayObject.parsedStyle,
  2534. x1 = _displayObject$parsed.x1,
  2535. y1 = _displayObject$parsed.y1,
  2536. x2 = _displayObject$parsed.x2,
  2537. y2 = _displayObject$parsed.y2,
  2538. lineWidth = _displayObject$parsed.lineWidth,
  2539. increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
  2540. _displayObject$parsed2 = _displayObject$parsed.defX,
  2541. x = _displayObject$parsed2 === void 0 ? 0 : _displayObject$parsed2,
  2542. _displayObject$parsed3 = _displayObject$parsed.defY,
  2543. y = _displayObject$parsed3 === void 0 ? 0 : _displayObject$parsed3,
  2544. pointerEvents = _displayObject$parsed.pointerEvents,
  2545. fill = _displayObject$parsed.fill,
  2546. stroke = _displayObject$parsed.stroke;
  2547. var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
  2548. hasStroke = _isFillOrStrokeAffect[1];
  2549. if (!hasStroke && !isClipPath || !lineWidth) {
  2550. return false;
  2551. }
  2552. return inLine(x1, y1, x2, y2, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y);
  2553. }
  2554. // TODO: replace it with method in @antv/util
  2555. function isPointInStroke(segments, lineWidth, px, py, length) {
  2556. var isHit = false;
  2557. var halfWidth = lineWidth / 2;
  2558. for (var i = 0; i < segments.length; i++) {
  2559. var segment = segments[i];
  2560. var currentPoint = segment.currentPoint,
  2561. params = segment.params,
  2562. prePoint = segment.prePoint,
  2563. box = segment.box;
  2564. // 如果在前面已经生成过包围盒,直接按照包围盒计算
  2565. if (box && !inBox(box.x - halfWidth, box.y - halfWidth, box.width + lineWidth, box.height + lineWidth, px, py)) {
  2566. continue;
  2567. }
  2568. switch (segment.command) {
  2569. // L 和 Z 都是直线, M 不进行拾取
  2570. case 'L':
  2571. case 'Z':
  2572. isHit = inLine(prePoint[0], prePoint[1], currentPoint[0], currentPoint[1], lineWidth, px, py);
  2573. if (isHit) {
  2574. return true;
  2575. }
  2576. break;
  2577. case 'Q':
  2578. var qDistance = quadratic.pointDistance(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4], px, py);
  2579. isHit = qDistance <= lineWidth / 2;
  2580. if (isHit) {
  2581. return true;
  2582. }
  2583. break;
  2584. case 'C':
  2585. var cDistance = cubic.pointDistance(prePoint[0],
  2586. // 上一段结束位置, 即 C 的起始点
  2587. prePoint[1], params[1],
  2588. // 'C' 的参数,1、2 为第一个控制点,3、4 为第二个控制点,5、6 为结束点
  2589. params[2], params[3], params[4], params[5], params[6], px, py, length);
  2590. isHit = cDistance <= lineWidth / 2;
  2591. if (isHit) {
  2592. return true;
  2593. }
  2594. break;
  2595. case 'A':
  2596. // cache conversion result
  2597. if (!segment.cubicParams) {
  2598. segment.cubicParams = arcToCubic(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4], params[5], params[6], params[7], undefined);
  2599. }
  2600. var args = segment.cubicParams;
  2601. // fixArc
  2602. var prePointInCubic = prePoint;
  2603. for (var _i = 0; _i < args.length; _i += 6) {
  2604. var _cDistance = cubic.pointDistance(prePointInCubic[0],
  2605. // 上一段结束位置, 即 C 的起始点
  2606. prePointInCubic[1], args[_i], args[_i + 1], args[_i + 2], args[_i + 3], args[_i + 4], args[_i + 5], px, py, length);
  2607. prePointInCubic = [args[_i + 4], args[_i + 5]];
  2608. isHit = _cDistance <= lineWidth / 2;
  2609. if (isHit) {
  2610. return true;
  2611. }
  2612. }
  2613. break;
  2614. }
  2615. }
  2616. return isHit;
  2617. }
  2618. function isPointInPath$3(displayObject, position, isClipPath, isPointInPath, renderingPluginContext, runtime) {
  2619. var _displayObject$parsed = displayObject.parsedStyle,
  2620. lineWidth = _displayObject$parsed.lineWidth,
  2621. increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
  2622. stroke = _displayObject$parsed.stroke,
  2623. fill = _displayObject$parsed.fill,
  2624. _displayObject$parsed2 = _displayObject$parsed.defX,
  2625. x = _displayObject$parsed2 === void 0 ? 0 : _displayObject$parsed2,
  2626. _displayObject$parsed3 = _displayObject$parsed.defY,
  2627. y = _displayObject$parsed3 === void 0 ? 0 : _displayObject$parsed3,
  2628. path = _displayObject$parsed.path,
  2629. pointerEvents = _displayObject$parsed.pointerEvents;
  2630. var segments = path.segments,
  2631. hasArc = path.hasArc,
  2632. polylines = path.polylines,
  2633. polygons = path.polygons;
  2634. var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents,
  2635. // Only a closed path can be filled.
  2636. (polygons === null || polygons === void 0 ? void 0 : polygons.length) && fill, stroke),
  2637. hasFill = _isFillOrStrokeAffect[0],
  2638. hasStroke = _isFillOrStrokeAffect[1];
  2639. var totalLength = gLite.getOrCalculatePathTotalLength(displayObject);
  2640. var isHit = false;
  2641. if (hasFill || isClipPath) {
  2642. if (hasArc) {
  2643. // 存在曲线时,暂时使用 canvas 的 api 计算,后续可以进行多边形切割
  2644. isHit = isPointInPath(displayObject, position);
  2645. } else {
  2646. // 提取出来的多边形包含闭合的和非闭合的,在这里统一按照多边形处理
  2647. isHit = inPolygons(polygons, position.x + x, position.y + y) || inPolygons(polylines, position.x + x, position.y + y);
  2648. }
  2649. return isHit;
  2650. } else if (hasStroke || isClipPath) {
  2651. isHit = isPointInStroke(segments, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y, totalLength);
  2652. }
  2653. return isHit;
  2654. }
  2655. function isPointInPath$4(displayObject, position, isClipPath) {
  2656. var _displayObject$parsed = displayObject.parsedStyle,
  2657. stroke = _displayObject$parsed.stroke,
  2658. fill = _displayObject$parsed.fill,
  2659. lineWidth = _displayObject$parsed.lineWidth,
  2660. increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
  2661. points = _displayObject$parsed.points,
  2662. _displayObject$parsed2 = _displayObject$parsed.defX,
  2663. x = _displayObject$parsed2 === void 0 ? 0 : _displayObject$parsed2,
  2664. _displayObject$parsed3 = _displayObject$parsed.defY,
  2665. y = _displayObject$parsed3 === void 0 ? 0 : _displayObject$parsed3,
  2666. pointerEvents = _displayObject$parsed.pointerEvents;
  2667. var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
  2668. hasFill = _isFillOrStrokeAffect[0],
  2669. hasStroke = _isFillOrStrokeAffect[1];
  2670. var isHit = false;
  2671. if (hasStroke || isClipPath) {
  2672. isHit = inPolyline(points.points, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y, true);
  2673. }
  2674. if (!isHit && (hasFill || isClipPath)) {
  2675. isHit = inPolygon(points.points, position.x + x, position.y + y);
  2676. }
  2677. return isHit;
  2678. }
  2679. function isPointInPath$5(displayObject, position, isClipPath) {
  2680. var _displayObject$parsed = displayObject.parsedStyle,
  2681. lineWidth = _displayObject$parsed.lineWidth,
  2682. increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
  2683. points = _displayObject$parsed.points,
  2684. _displayObject$parsed2 = _displayObject$parsed.defX,
  2685. x = _displayObject$parsed2 === void 0 ? 0 : _displayObject$parsed2,
  2686. _displayObject$parsed3 = _displayObject$parsed.defY,
  2687. y = _displayObject$parsed3 === void 0 ? 0 : _displayObject$parsed3,
  2688. pointerEvents = _displayObject$parsed.pointerEvents,
  2689. fill = _displayObject$parsed.fill,
  2690. stroke = _displayObject$parsed.stroke;
  2691. var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
  2692. hasStroke = _isFillOrStrokeAffect[1];
  2693. if (!hasStroke && !isClipPath || !lineWidth) {
  2694. return false;
  2695. }
  2696. return inPolyline(points.points, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y, false);
  2697. }
  2698. function isPointInPath$6(displayObject, position, isClipPath, isPointInPath, runtime) {
  2699. var _displayObject$parsed = displayObject.parsedStyle,
  2700. radius = _displayObject$parsed.radius,
  2701. fill = _displayObject$parsed.fill,
  2702. stroke = _displayObject$parsed.stroke,
  2703. lineWidth = _displayObject$parsed.lineWidth,
  2704. increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
  2705. width = _displayObject$parsed.width,
  2706. height = _displayObject$parsed.height,
  2707. pointerEvents = _displayObject$parsed.pointerEvents;
  2708. var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
  2709. hasFill = _isFillOrStrokeAffect[0],
  2710. hasStroke = _isFillOrStrokeAffect[1];
  2711. var hasRadius = radius && radius.some(function (r) {
  2712. return r !== 0;
  2713. });
  2714. var lineWidthForHitTesting = (lineWidth || 0) + (increasedLineWidthForHitTesting || 0);
  2715. // 无圆角时的策略
  2716. if (!hasRadius) {
  2717. var halfWidth = lineWidthForHitTesting / 2;
  2718. // 同时填充和带有边框
  2719. if (hasFill && hasStroke || isClipPath) {
  2720. return inBox(0 - halfWidth, 0 - halfWidth, width + halfWidth, height + halfWidth, position.x, position.y);
  2721. }
  2722. // 仅填充
  2723. if (hasFill) {
  2724. return inBox(0, 0, width, height, position.x, position.y);
  2725. }
  2726. if (hasStroke) {
  2727. return inRect(0, 0, width, height, lineWidthForHitTesting, position.x, position.y);
  2728. }
  2729. } else {
  2730. var isHit = false;
  2731. if (hasStroke || isClipPath) {
  2732. isHit = inRectWithRadius(0, 0, width, height, radius.map(function (r) {
  2733. return clamp(r, 0, Math.min(Math.abs(width) / 2, Math.abs(height) / 2));
  2734. }), lineWidthForHitTesting, position.x, position.y);
  2735. }
  2736. // 仅填充时带有圆角的矩形直接通过图形拾取
  2737. // 以后可以改成纯数学的近似拾取,将圆弧切割成多边形
  2738. if (!isHit && (hasFill || isClipPath)) {
  2739. isHit = isPointInPath(displayObject, position);
  2740. }
  2741. return isHit;
  2742. }
  2743. return false;
  2744. }
  2745. function inRectWithRadius(minX, minY, width, height, radiusArray, lineWidth, x, y) {
  2746. var tlr = radiusArray[0],
  2747. trr = radiusArray[1],
  2748. brr = radiusArray[2],
  2749. blr = radiusArray[3];
  2750. return inLine(minX + tlr, minY, minX + width - trr, minY, lineWidth, x, y) || inLine(minX + width, minY + trr, minX + width, minY + height - brr, lineWidth, x, y) || inLine(minX + width - brr, minY + height, minX + blr, minY + height, lineWidth, x, y) || inLine(minX, minY + height - blr, minX, minY + tlr, lineWidth, x, y) || inArc(minX + width - trr, minY + trr, trr, 1.5 * Math.PI, 2 * Math.PI, lineWidth, x, y) || inArc(minX + width - brr, minY + height - brr, brr, 0, 0.5 * Math.PI, lineWidth, x, y) || inArc(minX + blr, minY + height - blr, blr, 0.5 * Math.PI, Math.PI, lineWidth, x, y) || inArc(minX + tlr, minY + tlr, tlr, Math.PI, 1.5 * Math.PI, lineWidth, x, y);
  2751. }
  2752. function isPointInPath$7(displayObject, position, isClipPath, isPointInPath, renderingPluginContext, runtime) {
  2753. var _displayObject$parsed = displayObject.parsedStyle,
  2754. pointerEvents = _displayObject$parsed.pointerEvents,
  2755. width = _displayObject$parsed.width,
  2756. height = _displayObject$parsed.height;
  2757. if (pointerEvents === 'non-transparent-pixel') {
  2758. var offscreenCanvas = renderingPluginContext.config.offscreenCanvas;
  2759. var canvas = runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
  2760. var context = runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas, {
  2761. willReadFrequently: true
  2762. });
  2763. canvas.width = width;
  2764. canvas.height = height;
  2765. renderingPluginContext.defaultStyleRendererFactory[gLite.Shape.IMAGE].render(context, displayObject.parsedStyle, displayObject, undefined, undefined, undefined);
  2766. var imagedata = context.getImageData(position.x, position.y, 1, 1).data;
  2767. return imagedata.every(function (component) {
  2768. return component !== 0;
  2769. });
  2770. }
  2771. return true;
  2772. }
  2773. var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
  2774. _inheritsLoose$2(Plugin, _AbstractRendererPlug);
  2775. function Plugin() {
  2776. var _this;
  2777. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2778. args[_key] = arguments[_key];
  2779. }
  2780. _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
  2781. _this.name = 'canvas-picker';
  2782. return _this;
  2783. }
  2784. var _proto = Plugin.prototype;
  2785. _proto.init = function init() {
  2786. var _pointInPathPickerFac;
  2787. var trueFunc = function trueFunc() {
  2788. return true;
  2789. };
  2790. var pointInPathPickerFactory = (_pointInPathPickerFac = {}, _pointInPathPickerFac[gLite.Shape.CIRCLE] = isPointInPath, _pointInPathPickerFac[gLite.Shape.ELLIPSE] = isPointInPath$1, _pointInPathPickerFac[gLite.Shape.RECT] = isPointInPath$6, _pointInPathPickerFac[gLite.Shape.LINE] = isPointInPath$2, _pointInPathPickerFac[gLite.Shape.POLYLINE] = isPointInPath$5, _pointInPathPickerFac[gLite.Shape.POLYGON] = isPointInPath$4, _pointInPathPickerFac[gLite.Shape.PATH] = isPointInPath$3, _pointInPathPickerFac[gLite.Shape.TEXT] = trueFunc, _pointInPathPickerFac[gLite.Shape.GROUP] = null, _pointInPathPickerFac[gLite.Shape.IMAGE] = isPointInPath$7, _pointInPathPickerFac[gLite.Shape.HTML] = null, _pointInPathPickerFac[gLite.Shape.MESH] = null, _pointInPathPickerFac);
  2791. // @ts-ignore
  2792. this.context.pointInPathPickerFactory = pointInPathPickerFactory;
  2793. this.addRenderingPlugin(new CanvasPickerPlugin());
  2794. };
  2795. _proto.destroy = function destroy() {
  2796. // @ts-ignore
  2797. delete this.context.pointInPathPickerFactory;
  2798. this.removeAllRenderingPlugins();
  2799. };
  2800. return Plugin;
  2801. }(gLite.AbstractRendererPlugin);
  2802. var index_esm$1 = /*#__PURE__*/Object.freeze({
  2803. __proto__: null,
  2804. Plugin: Plugin$1
  2805. });
  2806. function _extends() {
  2807. _extends = Object.assign ? Object.assign.bind() : function (target) {
  2808. for (var i = 1; i < arguments.length; i++) {
  2809. var source = arguments[i];
  2810. for (var key in source) {
  2811. if (Object.prototype.hasOwnProperty.call(source, key)) {
  2812. target[key] = source[key];
  2813. }
  2814. }
  2815. }
  2816. return target;
  2817. };
  2818. return _extends.apply(this, arguments);
  2819. }
  2820. function _inheritsLoose$3(subClass, superClass) {
  2821. subClass.prototype = Object.create(superClass.prototype);
  2822. subClass.prototype.constructor = subClass;
  2823. _setPrototypeOf$3(subClass, superClass);
  2824. }
  2825. function _setPrototypeOf$3(o, p) {
  2826. _setPrototypeOf$3 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  2827. o.__proto__ = p;
  2828. return o;
  2829. };
  2830. return _setPrototypeOf$3(o, p);
  2831. }
  2832. /**
  2833. * support 2 modes in rendering:
  2834. * * immediate
  2835. * * delayed: render at the end of frame with dirty-rectangle
  2836. */
  2837. var CanvasRendererPlugin = /*#__PURE__*/function () {
  2838. function CanvasRendererPlugin(canvasRendererPluginOptions) {
  2839. this.canvasRendererPluginOptions = void 0;
  2840. this.context = void 0;
  2841. this.pathGeneratorFactory = void 0;
  2842. /**
  2843. * RBush used in dirty rectangle rendering
  2844. */
  2845. this.rBush = void 0;
  2846. this.removedRBushNodeAABBs = [];
  2847. this.renderQueue = [];
  2848. /**
  2849. * This stack is only used by clipPath for now.
  2850. */
  2851. this.restoreStack = [];
  2852. this.clearFullScreen = false;
  2853. /**
  2854. * view projection matrix
  2855. */
  2856. this.vpMatrix = create();
  2857. this.dprMatrix = create();
  2858. this.tmpMat4 = create();
  2859. this.vec3a = create$1();
  2860. this.vec3b = create$1();
  2861. this.vec3c = create$1();
  2862. this.vec3d = create$1();
  2863. this.canvasRendererPluginOptions = canvasRendererPluginOptions;
  2864. }
  2865. var _proto = CanvasRendererPlugin.prototype;
  2866. _proto.apply = function apply(context, runtime) {
  2867. var _this = this;
  2868. this.context = context;
  2869. var config = context.config,
  2870. camera = context.camera,
  2871. renderingService = context.renderingService,
  2872. renderingContext = context.renderingContext,
  2873. rBushRoot = context.rBushRoot,
  2874. pathGeneratorFactory = context.pathGeneratorFactory;
  2875. this.rBush = rBushRoot;
  2876. this.pathGeneratorFactory = pathGeneratorFactory;
  2877. var contextService = context.contextService;
  2878. var canvas = renderingContext.root.ownerDocument.defaultView;
  2879. var handleUnmounted = function handleUnmounted(e) {
  2880. var object = e.target;
  2881. // remove r-bush node
  2882. // @ts-ignore
  2883. var rBushNode = object.rBushNode;
  2884. if (rBushNode.aabb) {
  2885. // save removed aabbs for dirty-rectangle rendering later
  2886. _this.removedRBushNodeAABBs.push(rBushNode.aabb);
  2887. }
  2888. };
  2889. var handleCulled = function handleCulled(e) {
  2890. var object = e.target;
  2891. // @ts-ignore
  2892. var rBushNode = object.rBushNode;
  2893. if (rBushNode.aabb) {
  2894. // save removed aabbs for dirty-rectangle rendering later
  2895. _this.removedRBushNodeAABBs.push(rBushNode.aabb);
  2896. }
  2897. };
  2898. renderingService.hooks.init.tap(CanvasRendererPlugin.tag, function () {
  2899. canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
  2900. canvas.addEventListener(gLite.ElementEvent.CULLED, handleCulled);
  2901. // clear fullscreen
  2902. var dpr = contextService.getDPR();
  2903. var width = config.width,
  2904. height = config.height;
  2905. var context = contextService.getContext();
  2906. _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
  2907. });
  2908. renderingService.hooks.destroy.tap(CanvasRendererPlugin.tag, function () {
  2909. canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
  2910. canvas.removeEventListener(gLite.ElementEvent.CULLED, handleCulled);
  2911. // this.renderQueue = [];
  2912. // this.removedRBushNodeAABBs = [];
  2913. // this.restoreStack = [];
  2914. });
  2915. renderingService.hooks.beginFrame.tap(CanvasRendererPlugin.tag, function () {
  2916. var context = contextService.getContext();
  2917. var dpr = contextService.getDPR();
  2918. var width = config.width,
  2919. height = config.height;
  2920. var _this$canvasRendererP = _this.canvasRendererPluginOptions,
  2921. dirtyObjectNumThreshold = _this$canvasRendererP.dirtyObjectNumThreshold,
  2922. dirtyObjectRatioThreshold = _this$canvasRendererP.dirtyObjectRatioThreshold;
  2923. // some heuristic conditions such as 80% object changed
  2924. var _renderingService$get = renderingService.getStats(),
  2925. total = _renderingService$get.total,
  2926. rendered = _renderingService$get.rendered;
  2927. var ratio = rendered / total;
  2928. _this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > dirtyObjectNumThreshold && ratio > dirtyObjectRatioThreshold;
  2929. if (context) {
  2930. context.resetTransform ? context.resetTransform() : context.setTransform(1, 0, 0, 1, 0, 0);
  2931. if (_this.clearFullScreen) {
  2932. _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
  2933. }
  2934. }
  2935. });
  2936. var renderByZIndex = function renderByZIndex(object, context) {
  2937. if (object.isVisible() && !object.isCulled()) {
  2938. _this.renderDisplayObject(object, context, _this.context, _this.restoreStack, runtime);
  2939. // if (object.renderable.) {
  2940. // if we did a full screen rendering last frame
  2941. _this.saveDirtyAABB(object);
  2942. // }
  2943. }
  2944. var sorted = object.sortable.sorted || object.childNodes;
  2945. // should account for z-index
  2946. sorted.forEach(function (child) {
  2947. renderByZIndex(child, context);
  2948. });
  2949. };
  2950. // render at the end of frame
  2951. renderingService.hooks.endFrame.tap(CanvasRendererPlugin.tag, function () {
  2952. var context = contextService.getContext();
  2953. // clear & clip dirty rectangle
  2954. var dpr = contextService.getDPR();
  2955. fromScaling(_this.dprMatrix, [dpr, dpr, 1]);
  2956. multiply(_this.vpMatrix, _this.dprMatrix, camera.getOrthoMatrix());
  2957. // if (this.clearFullScreen) {
  2958. if (_this.clearFullScreen) {
  2959. // console.log('canvas renderer fcp...');
  2960. renderByZIndex(renderingContext.root, context);
  2961. } else {
  2962. // console.log('canvas renderer next...');
  2963. // merge removed AABB
  2964. var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(_this.renderQueue)].concat(_this.removedRBushNodeAABBs.map(function (_ref) {
  2965. var minX = _ref.minX,
  2966. minY = _ref.minY,
  2967. maxX = _ref.maxX,
  2968. maxY = _ref.maxY;
  2969. var aabb = new gLite.AABB();
  2970. aabb.setMinMax(
  2971. // vec3.fromValues(minX, minY, 0),
  2972. // vec3.fromValues(maxX, maxY, 0),
  2973. [minX, minY, 0], [maxX, maxY, 0]);
  2974. return aabb;
  2975. })));
  2976. _this.removedRBushNodeAABBs = [];
  2977. if (gLite.AABB.isEmpty(dirtyRenderBounds)) {
  2978. _this.renderQueue = [];
  2979. return;
  2980. }
  2981. var dirtyRect = _this.convertAABB2Rect(dirtyRenderBounds);
  2982. var x = dirtyRect.x,
  2983. y = dirtyRect.y,
  2984. width = dirtyRect.width,
  2985. height = dirtyRect.height;
  2986. var tl = transformMat4(_this.vec3a, [x, y, 0], _this.vpMatrix);
  2987. var tr = transformMat4(_this.vec3b, [x + width, y, 0], _this.vpMatrix);
  2988. var bl = transformMat4(_this.vec3c, [x, y + height, 0], _this.vpMatrix);
  2989. var br = transformMat4(_this.vec3d, [x + width, y + height, 0], _this.vpMatrix);
  2990. var minx = Math.min(tl[0], tr[0], br[0], bl[0]);
  2991. var miny = Math.min(tl[1], tr[1], br[1], bl[1]);
  2992. var maxx = Math.max(tl[0], tr[0], br[0], bl[0]);
  2993. var maxy = Math.max(tl[1], tr[1], br[1], bl[1]);
  2994. var ix = Math.floor(minx);
  2995. var iy = Math.floor(miny);
  2996. var iwidth = Math.ceil(maxx - minx);
  2997. var iheight = Math.ceil(maxy - miny);
  2998. context.save();
  2999. _this.clearRect(context, ix, iy, iwidth, iheight, config.background);
  3000. context.beginPath();
  3001. context.rect(ix, iy, iwidth, iheight);
  3002. context.clip();
  3003. // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
  3004. context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]);
  3005. // draw dirty rectangle
  3006. var _config$renderer$getC = config.renderer.getConfig(),
  3007. enableDirtyRectangleRenderingDebug = _config$renderer$getC.enableDirtyRectangleRenderingDebug;
  3008. if (enableDirtyRectangleRenderingDebug) {
  3009. canvas.dispatchEvent(new gLite.CustomEvent(gLite.CanvasEvent.DIRTY_RECTANGLE, {
  3010. dirtyRect: {
  3011. x: ix,
  3012. y: iy,
  3013. width: iwidth,
  3014. height: iheight
  3015. }
  3016. }));
  3017. }
  3018. // search objects intersect with dirty rectangle
  3019. var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds);
  3020. // do rendering
  3021. dirtyObjects
  3022. // sort by z-index
  3023. .sort(function (a, b) {
  3024. return a.sortable.renderOrder - b.sortable.renderOrder;
  3025. }).forEach(function (object) {
  3026. // culled object should not be rendered
  3027. if (object && object.isVisible() && !object.isCulled()) {
  3028. _this.renderDisplayObject(object, context, _this.context, _this.restoreStack, runtime);
  3029. }
  3030. });
  3031. context.restore();
  3032. // save dirty AABBs in last frame
  3033. _this.renderQueue.forEach(function (object) {
  3034. _this.saveDirtyAABB(object);
  3035. });
  3036. // clear queue
  3037. _this.renderQueue = [];
  3038. }
  3039. // pop restore stack, eg. root -> parent -> child
  3040. _this.restoreStack.forEach(function () {
  3041. context.restore();
  3042. });
  3043. // clear restore stack
  3044. _this.restoreStack = [];
  3045. });
  3046. renderingService.hooks.render.tap(CanvasRendererPlugin.tag, function (object) {
  3047. if (!_this.clearFullScreen) {
  3048. // render at the end of frame
  3049. _this.renderQueue.push(object);
  3050. }
  3051. });
  3052. };
  3053. _proto.clearRect = function clearRect(context, x, y, width, height, background) {
  3054. // clearRect is faster than fillRect @see https://stackoverflow.com/a/30830253
  3055. context.clearRect(x, y, width, height);
  3056. if (background) {
  3057. context.fillStyle = background;
  3058. context.fillRect(x, y, width, height);
  3059. }
  3060. };
  3061. _proto.renderDisplayObject = function renderDisplayObject(object, context, canvasContext, restoreStack, runtime) {
  3062. var nodeName = object.nodeName;
  3063. // console.log('canvas render:', object);
  3064. // restore to its ancestor
  3065. var parent = restoreStack[restoreStack.length - 1];
  3066. if (parent && !(object.compareDocumentPosition(parent) & Node.DOCUMENT_POSITION_CONTAINS)) {
  3067. context.restore();
  3068. restoreStack.pop();
  3069. }
  3070. // @ts-ignore
  3071. var styleRenderer = this.context.styleRendererFactory[nodeName];
  3072. var generatePath = this.pathGeneratorFactory[nodeName];
  3073. // clip path
  3074. var clipPath = object.parsedStyle.clipPath;
  3075. if (clipPath) {
  3076. this.applyWorldTransform(context, clipPath);
  3077. // generate path in local space
  3078. var _generatePath = this.pathGeneratorFactory[clipPath.nodeName];
  3079. if (_generatePath) {
  3080. context.save();
  3081. // save clip
  3082. restoreStack.push(object);
  3083. context.beginPath();
  3084. _generatePath(context, clipPath.parsedStyle);
  3085. context.closePath();
  3086. context.clip();
  3087. }
  3088. }
  3089. // fill & stroke
  3090. if (styleRenderer) {
  3091. this.applyWorldTransform(context, object);
  3092. context.save();
  3093. // apply attributes to context
  3094. this.applyAttributesToContext(context, object);
  3095. }
  3096. if (generatePath) {
  3097. context.beginPath();
  3098. generatePath(context, object.parsedStyle);
  3099. if (object.nodeName !== gLite.Shape.LINE && object.nodeName !== gLite.Shape.PATH && object.nodeName !== gLite.Shape.POLYLINE) {
  3100. context.closePath();
  3101. }
  3102. }
  3103. // fill & stroke
  3104. if (styleRenderer) {
  3105. styleRenderer.render(context, object.parsedStyle, object, canvasContext, this, runtime);
  3106. // restore applied attributes, eg. shadowBlur shadowColor...
  3107. context.restore();
  3108. }
  3109. // finish rendering, clear dirty flag
  3110. object.renderable.dirty = false;
  3111. };
  3112. _proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
  3113. var min = aabb.getMin();
  3114. var max = aabb.getMax();
  3115. // expand the rectangle a bit to avoid artifacts
  3116. // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
  3117. var minX = Math.floor(min[0]);
  3118. var minY = Math.floor(min[1]);
  3119. var maxX = Math.ceil(max[0]);
  3120. var maxY = Math.ceil(max[1]);
  3121. var width = maxX - minX;
  3122. var height = maxY - minY;
  3123. return {
  3124. x: minX,
  3125. y: minY,
  3126. width: width,
  3127. height: height
  3128. };
  3129. }
  3130. /**
  3131. * TODO: merge dirty rectangles with some strategies.
  3132. * For now, we just simply merge all the rectangles into one.
  3133. * @see https://idom.me/articles/841.html
  3134. */;
  3135. _proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
  3136. // merge into a big AABB
  3137. // TODO: skip descendant if ancestor is caculated, but compareNodePosition is really slow
  3138. var aabb = new gLite.AABB();
  3139. dirtyObjects.forEach(function (object) {
  3140. var renderBounds = object.getRenderBounds();
  3141. aabb.add(renderBounds);
  3142. var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
  3143. if (dirtyRenderBounds) {
  3144. aabb.add(dirtyRenderBounds);
  3145. }
  3146. });
  3147. return aabb;
  3148. };
  3149. _proto.searchDirtyObjects = function searchDirtyObjects(dirtyRectangle) {
  3150. // search in r-tree, get all affected nodes
  3151. var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
  3152. minX = _dirtyRectangle$getMi[0],
  3153. minY = _dirtyRectangle$getMi[1];
  3154. var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
  3155. maxX = _dirtyRectangle$getMa[0],
  3156. maxY = _dirtyRectangle$getMa[1];
  3157. var rBushNodes = this.rBush.search({
  3158. minX: minX,
  3159. minY: minY,
  3160. maxX: maxX,
  3161. maxY: maxY
  3162. });
  3163. return rBushNodes.map(function (_ref2) {
  3164. var displayObject = _ref2.displayObject;
  3165. return displayObject;
  3166. });
  3167. };
  3168. _proto.saveDirtyAABB = function saveDirtyAABB(object) {
  3169. var renderable = object.renderable;
  3170. if (!renderable.dirtyRenderBounds) {
  3171. renderable.dirtyRenderBounds = new gLite.AABB();
  3172. }
  3173. var renderBounds = object.getRenderBounds();
  3174. if (renderBounds) {
  3175. // save last dirty aabb
  3176. renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
  3177. }
  3178. }
  3179. /**
  3180. * TODO: batch the same global attributes
  3181. */;
  3182. _proto.applyAttributesToContext = function applyAttributesToContext(context, object) {
  3183. var _object$parsedStyle = object.parsedStyle,
  3184. stroke = _object$parsedStyle.stroke,
  3185. fill = _object$parsedStyle.fill,
  3186. opacity = _object$parsedStyle.opacity,
  3187. lineDash = _object$parsedStyle.lineDash,
  3188. lineDashOffset = _object$parsedStyle.lineDashOffset;
  3189. // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
  3190. if (lineDash) {
  3191. context.setLineDash(lineDash);
  3192. }
  3193. // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
  3194. if (!isNil(lineDashOffset)) {
  3195. context.lineDashOffset = lineDashOffset;
  3196. }
  3197. if (!isNil(opacity)) {
  3198. context.globalAlpha *= opacity;
  3199. }
  3200. if (!isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
  3201. context.strokeStyle = object.attributes.stroke;
  3202. }
  3203. if (!isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
  3204. context.fillStyle = object.attributes.fill;
  3205. }
  3206. };
  3207. _proto.applyWorldTransform = function applyWorldTransform(context, object, matrix) {
  3208. var tx = 0;
  3209. var ty = 0;
  3210. var _ref3 = object.parsedStyle || {},
  3211. anchor = _ref3.anchor;
  3212. var anchorX = anchor && anchor[0] || 0;
  3213. var anchorY = anchor && anchor[1] || 0;
  3214. if (anchorX !== 0 || anchorY !== 0) {
  3215. // const bounds = object.getGeometryBounds();
  3216. var bounds = object.geometry.contentBounds;
  3217. var width = bounds && bounds.halfExtents[0] * 2 || 0;
  3218. var height = bounds && bounds.halfExtents[1] * 2 || 0;
  3219. tx = -(anchorX * width);
  3220. ty = -(anchorY * height);
  3221. }
  3222. // apply clip shape's RTS
  3223. if (matrix) {
  3224. copy(this.tmpMat4, object.getLocalTransform());
  3225. this.vec3a[0] = tx;
  3226. this.vec3a[1] = ty;
  3227. this.vec3a[2] = 0;
  3228. translate(this.tmpMat4, this.tmpMat4, this.vec3a);
  3229. multiply(this.tmpMat4, matrix, this.tmpMat4);
  3230. multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
  3231. } else {
  3232. // apply RTS transformation in world space
  3233. copy(this.tmpMat4, object.getWorldTransform());
  3234. this.vec3a[0] = tx;
  3235. this.vec3a[1] = ty;
  3236. this.vec3a[2] = 0;
  3237. translate(this.tmpMat4, this.tmpMat4, this.vec3a);
  3238. multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
  3239. }
  3240. // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
  3241. context.setTransform(this.tmpMat4[0], this.tmpMat4[1], this.tmpMat4[4], this.tmpMat4[5], this.tmpMat4[12], this.tmpMat4[13]);
  3242. };
  3243. _proto.safeMergeAABB = function safeMergeAABB() {
  3244. var merged = new gLite.AABB();
  3245. for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
  3246. aabbs[_key] = arguments[_key];
  3247. }
  3248. aabbs.forEach(function (aabb) {
  3249. merged.add(aabb);
  3250. });
  3251. return merged;
  3252. };
  3253. return CanvasRendererPlugin;
  3254. }();
  3255. CanvasRendererPlugin.tag = 'CanvasRenderer';
  3256. var DefaultRenderer = /*#__PURE__*/function () {
  3257. function DefaultRenderer(imagePool) {
  3258. this.imagePool = void 0;
  3259. this.imagePool = imagePool;
  3260. }
  3261. var _proto = DefaultRenderer.prototype;
  3262. _proto.render = function render(context, parsedStyle, object, canvasContext, plugin, runtime) {
  3263. var fill = parsedStyle.fill,
  3264. fillRule = parsedStyle.fillRule,
  3265. opacity = parsedStyle.opacity,
  3266. fillOpacity = parsedStyle.fillOpacity,
  3267. stroke = parsedStyle.stroke,
  3268. strokeOpacity = parsedStyle.strokeOpacity,
  3269. lineWidth = parsedStyle.lineWidth,
  3270. lineCap = parsedStyle.lineCap,
  3271. lineJoin = parsedStyle.lineJoin,
  3272. shadowType = parsedStyle.shadowType,
  3273. shadowColor = parsedStyle.shadowColor,
  3274. shadowBlur = parsedStyle.shadowBlur,
  3275. filter = parsedStyle.filter,
  3276. miterLimit = parsedStyle.miterLimit;
  3277. var hasFill = !isNil(fill) && !fill.isNone;
  3278. var hasStroke = !isNil(stroke) && !stroke.isNone && lineWidth > 0;
  3279. var isFillTransparent = fill.alpha === 0;
  3280. var hasFilter = !!(filter && filter.length);
  3281. var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
  3282. var nodeName = object.nodeName;
  3283. var isInnerShadow = shadowType === 'inner';
  3284. var shouldDrawShadowWithStroke = hasStroke && hasShadow && (nodeName === gLite.Shape.PATH || nodeName === gLite.Shape.LINE || nodeName === gLite.Shape.POLYLINE || isFillTransparent || isInnerShadow);
  3285. if (hasFill) {
  3286. context.globalAlpha = opacity * fillOpacity;
  3287. if (!shouldDrawShadowWithStroke) {
  3288. setShadowAndFilter(object, context, hasShadow);
  3289. }
  3290. this.fill(context, object, fill, fillRule, canvasContext, plugin, runtime);
  3291. if (!shouldDrawShadowWithStroke) {
  3292. this.clearShadowAndFilter(context, hasFilter, hasShadow);
  3293. }
  3294. }
  3295. if (hasStroke) {
  3296. context.globalAlpha = opacity * strokeOpacity;
  3297. context.lineWidth = lineWidth;
  3298. if (!isNil(miterLimit)) {
  3299. context.miterLimit = miterLimit;
  3300. }
  3301. if (!isNil(lineCap)) {
  3302. context.lineCap = lineCap;
  3303. }
  3304. if (!isNil(lineJoin)) {
  3305. context.lineJoin = lineJoin;
  3306. }
  3307. if (shouldDrawShadowWithStroke) {
  3308. if (isInnerShadow) {
  3309. context.globalCompositeOperation = 'source-atop';
  3310. }
  3311. setShadowAndFilter(object, context, true);
  3312. if (isInnerShadow) {
  3313. this.stroke(context, object, stroke, canvasContext, plugin, runtime);
  3314. context.globalCompositeOperation = 'source-over';
  3315. this.clearShadowAndFilter(context, hasFilter, true);
  3316. }
  3317. }
  3318. this.stroke(context, object, stroke, canvasContext, plugin, runtime);
  3319. }
  3320. };
  3321. _proto.clearShadowAndFilter = function clearShadowAndFilter(context, hasFilter, hasShadow) {
  3322. if (hasShadow) {
  3323. context.shadowColor = 'transparent';
  3324. context.shadowBlur = 0;
  3325. }
  3326. if (hasFilter) {
  3327. // save drop-shadow filter
  3328. var oldFilter = context.filter;
  3329. if (!isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
  3330. context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
  3331. }
  3332. }
  3333. };
  3334. _proto.fill = function fill(context, object, _fill, fillRule, canvasContext, plugin, runtime) {
  3335. var _this = this;
  3336. if (Array.isArray(_fill)) {
  3337. _fill.forEach(function (gradient) {
  3338. context.fillStyle = _this.getColor(gradient, object, context);
  3339. fillRule ? context.fill(fillRule) : context.fill();
  3340. });
  3341. } else {
  3342. if (gLite.isPattern(_fill)) {
  3343. context.fillStyle = this.getPattern(_fill, object, context, canvasContext, plugin, runtime);
  3344. }
  3345. fillRule ? context.fill(fillRule) : context.fill();
  3346. }
  3347. };
  3348. _proto.stroke = function stroke(context, object, _stroke, canvasContext, plugin, runtime) {
  3349. var _this2 = this;
  3350. if (Array.isArray(_stroke)) {
  3351. _stroke.forEach(function (gradient) {
  3352. context.strokeStyle = _this2.getColor(gradient, object, context);
  3353. context.stroke();
  3354. });
  3355. } else {
  3356. if (gLite.isPattern(_stroke)) {
  3357. context.strokeStyle = this.getPattern(_stroke, object, context, canvasContext, plugin, runtime);
  3358. }
  3359. context.stroke();
  3360. }
  3361. };
  3362. _proto.getPattern = function getPattern(pattern, object, context, canvasContext, plugin, runtime) {
  3363. var $offscreenCanvas;
  3364. var dpr;
  3365. if (pattern.image.nodeName === 'rect') {
  3366. var _pattern$image$parsed = pattern.image.parsedStyle,
  3367. width = _pattern$image$parsed.width,
  3368. height = _pattern$image$parsed.height;
  3369. dpr = canvasContext.contextService.getDPR();
  3370. var offscreenCanvas = canvasContext.config.offscreenCanvas;
  3371. $offscreenCanvas = runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
  3372. $offscreenCanvas.width = width * dpr;
  3373. $offscreenCanvas.height = height * dpr;
  3374. var offscreenCanvasContext = runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
  3375. var restoreStack = [];
  3376. // offscreenCanvasContext.scale(1 / dpr, 1 / dpr);
  3377. pattern.image.forEach(function (object) {
  3378. plugin.renderDisplayObject(object, offscreenCanvasContext, canvasContext, restoreStack, runtime);
  3379. });
  3380. restoreStack.forEach(function () {
  3381. offscreenCanvasContext.restore();
  3382. });
  3383. }
  3384. var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, $offscreenCanvas, dpr, function () {
  3385. // set dirty rectangle flag
  3386. object.renderable.dirty = true;
  3387. canvasContext.renderingService.dirtify();
  3388. });
  3389. return canvasPattern;
  3390. };
  3391. _proto.getColor = function getColor(parsedColor, object, context) {
  3392. var color;
  3393. if (parsedColor.type === gLite.GradientType.LinearGradient || parsedColor.type === gLite.GradientType.RadialGradient) {
  3394. var bounds = object.getGeometryBounds();
  3395. var width = bounds && bounds.halfExtents[0] * 2 || 1;
  3396. var height = bounds && bounds.halfExtents[1] * 2 || 1;
  3397. color = this.imagePool.getOrCreateGradient(_extends({
  3398. type: parsedColor.type
  3399. }, parsedColor.value, {
  3400. width: width,
  3401. height: height
  3402. }), context);
  3403. }
  3404. return color;
  3405. };
  3406. return DefaultRenderer;
  3407. }();
  3408. /**
  3409. * apply before fill and stroke but only once
  3410. */
  3411. function setShadowAndFilter(object, context, hasShadow) {
  3412. var _object$parsedStyle = object.parsedStyle,
  3413. filter = _object$parsedStyle.filter,
  3414. shadowColor = _object$parsedStyle.shadowColor,
  3415. shadowBlur = _object$parsedStyle.shadowBlur,
  3416. shadowOffsetX = _object$parsedStyle.shadowOffsetX,
  3417. shadowOffsetY = _object$parsedStyle.shadowOffsetY;
  3418. if (filter && filter.length) {
  3419. // use raw filter string
  3420. context.filter = object.style.filter;
  3421. }
  3422. if (hasShadow) {
  3423. context.shadowColor = shadowColor.toString();
  3424. context.shadowBlur = shadowBlur || 0;
  3425. context.shadowOffsetX = shadowOffsetX || 0;
  3426. context.shadowOffsetY = shadowOffsetY || 0;
  3427. }
  3428. }
  3429. var ImageRenderer = /*#__PURE__*/function () {
  3430. function ImageRenderer(imagePool) {
  3431. this.imagePool = void 0;
  3432. this.imagePool = imagePool;
  3433. }
  3434. var _proto = ImageRenderer.prototype;
  3435. _proto.render = function render(context, parsedStyle, object) {
  3436. var width = parsedStyle.width,
  3437. height = parsedStyle.height,
  3438. img = parsedStyle.img,
  3439. shadowColor = parsedStyle.shadowColor,
  3440. shadowBlur = parsedStyle.shadowBlur;
  3441. var image;
  3442. var iw = width;
  3443. var ih = height;
  3444. if (isString(img)) {
  3445. // image has been loaded in `mounted` hook
  3446. image = this.imagePool.getImageSync(img);
  3447. } else {
  3448. iw || (iw = img.width);
  3449. ih || (ih = img.height);
  3450. image = img;
  3451. }
  3452. if (image) {
  3453. var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
  3454. setShadowAndFilter(object, context, hasShadow);
  3455. // node-canvas will throw the following err:
  3456. // Error: Image given has not completed loading
  3457. try {
  3458. context.drawImage(image, 0, 0, iw, ih);
  3459. } catch (e) {}
  3460. }
  3461. };
  3462. return ImageRenderer;
  3463. }();
  3464. var TextRenderer = /*#__PURE__*/function () {
  3465. function TextRenderer() {}
  3466. var _proto = TextRenderer.prototype;
  3467. _proto.render = function render(context, parsedStyle, object) {
  3468. var lineWidth = parsedStyle.lineWidth,
  3469. textAlign = parsedStyle.textAlign,
  3470. textBaseline = parsedStyle.textBaseline,
  3471. lineJoin = parsedStyle.lineJoin,
  3472. miterLimit = parsedStyle.miterLimit,
  3473. letterSpacing = parsedStyle.letterSpacing,
  3474. stroke = parsedStyle.stroke,
  3475. fill = parsedStyle.fill,
  3476. fillOpacity = parsedStyle.fillOpacity,
  3477. strokeOpacity = parsedStyle.strokeOpacity,
  3478. opacity = parsedStyle.opacity,
  3479. metrics = parsedStyle.metrics,
  3480. dx = parsedStyle.dx,
  3481. dy = parsedStyle.dy,
  3482. shadowColor = parsedStyle.shadowColor,
  3483. shadowBlur = parsedStyle.shadowBlur;
  3484. var font = metrics.font,
  3485. lines = metrics.lines,
  3486. height = metrics.height,
  3487. lineHeight = metrics.lineHeight,
  3488. lineMetrics = metrics.lineMetrics;
  3489. context.font = font;
  3490. context.lineWidth = lineWidth;
  3491. context.textAlign = textAlign === 'middle' ? 'center' : textAlign;
  3492. var formattedTextBaseline = textBaseline;
  3493. if (
  3494. // formattedTextBaseline === 'bottom' ||
  3495. !gLite.runtime.enableCSSParsing && formattedTextBaseline === 'alphabetic') {
  3496. formattedTextBaseline = 'bottom';
  3497. }
  3498. context.lineJoin = lineJoin;
  3499. if (!isNil(miterLimit)) {
  3500. context.miterLimit = miterLimit;
  3501. }
  3502. var linePositionY = 0;
  3503. // handle vertical text baseline
  3504. if (textBaseline === 'middle') {
  3505. linePositionY = -height / 2 - lineHeight / 2;
  3506. } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
  3507. linePositionY = -height;
  3508. } else if (textBaseline === 'top' || textBaseline === 'hanging') {
  3509. linePositionY = -lineHeight;
  3510. }
  3511. // account for dx & dy
  3512. var offsetX = dx || 0;
  3513. linePositionY += dy || 0;
  3514. if (lines.length === 1) {
  3515. if (formattedTextBaseline === 'bottom') {
  3516. formattedTextBaseline = 'middle';
  3517. linePositionY -= 0.5 * height;
  3518. } else if (formattedTextBaseline === 'top') {
  3519. formattedTextBaseline = 'middle';
  3520. linePositionY += 0.5 * height;
  3521. }
  3522. }
  3523. context.textBaseline = formattedTextBaseline;
  3524. var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
  3525. setShadowAndFilter(object, context, hasShadow);
  3526. // draw lines line by line
  3527. for (var i = 0; i < lines.length; i++) {
  3528. var linePositionX = lineWidth / 2 + offsetX;
  3529. linePositionY += lineHeight;
  3530. // no need to re-position X, cause we already set text align
  3531. // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
  3532. if (!isNil(stroke) && !stroke.isNone && lineWidth) {
  3533. this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity, true);
  3534. }
  3535. if (!isNil(fill)) {
  3536. this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity);
  3537. }
  3538. }
  3539. };
  3540. _proto.drawLetterSpacing = function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity, isStroke) {
  3541. if (isStroke === void 0) {
  3542. isStroke = false;
  3543. }
  3544. // letterSpacing of 0 means normal, render all texts directly
  3545. if (letterSpacing === 0) {
  3546. if (isStroke) {
  3547. this.strokeText(context, text, x, y, strokeOpacity);
  3548. } else {
  3549. this.fillText(context, text, x, y, fillOpacity, opacity);
  3550. }
  3551. return;
  3552. }
  3553. // draw text using left align
  3554. var currentTextAlign = context.textAlign;
  3555. context.textAlign = 'left';
  3556. var currentPosition = x;
  3557. if (textAlign === 'center' || textAlign === 'middle') {
  3558. currentPosition = x - lineMetrics.width / 2;
  3559. } else if (textAlign === 'right' || textAlign === 'end') {
  3560. currentPosition = x - lineMetrics.width;
  3561. }
  3562. var stringArray = Array.from(text);
  3563. var previousWidth = context.measureText(text).width;
  3564. var currentWidth = 0;
  3565. for (var i = 0; i < stringArray.length; ++i) {
  3566. var currentChar = stringArray[i];
  3567. if (isStroke) {
  3568. this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
  3569. } else {
  3570. this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
  3571. }
  3572. currentWidth = context.measureText(text.substring(i + 1)).width;
  3573. currentPosition += previousWidth - currentWidth + letterSpacing;
  3574. previousWidth = currentWidth;
  3575. }
  3576. context.textAlign = currentTextAlign;
  3577. };
  3578. _proto.fillText = function fillText(context, text, x, y, fillOpacity, opacity) {
  3579. var currentGlobalAlpha;
  3580. var applyOpacity = !isNil(fillOpacity) && fillOpacity !== 1;
  3581. if (applyOpacity) {
  3582. currentGlobalAlpha = context.globalAlpha;
  3583. context.globalAlpha = fillOpacity * opacity;
  3584. }
  3585. context.fillText(text, x, y);
  3586. if (applyOpacity) {
  3587. context.globalAlpha = currentGlobalAlpha;
  3588. }
  3589. };
  3590. _proto.strokeText = function strokeText(context, text, x, y, strokeOpacity) {
  3591. var currentGlobalAlpha;
  3592. var applyOpacity = !isNil(strokeOpacity) && strokeOpacity !== 1;
  3593. if (applyOpacity) {
  3594. currentGlobalAlpha = context.globalAlpha;
  3595. context.globalAlpha = strokeOpacity;
  3596. }
  3597. context.strokeText(text, x, y);
  3598. if (applyOpacity) {
  3599. context.globalAlpha = currentGlobalAlpha;
  3600. }
  3601. };
  3602. return TextRenderer;
  3603. }();
  3604. var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
  3605. _inheritsLoose$3(RectRenderer, _DefaultRenderer);
  3606. function RectRenderer() {
  3607. return _DefaultRenderer.apply(this, arguments) || this;
  3608. }
  3609. return RectRenderer;
  3610. }(DefaultRenderer);
  3611. var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
  3612. _inheritsLoose$3(CircleRenderer, _DefaultRenderer);
  3613. function CircleRenderer() {
  3614. return _DefaultRenderer.apply(this, arguments) || this;
  3615. }
  3616. return CircleRenderer;
  3617. }(DefaultRenderer);
  3618. var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
  3619. _inheritsLoose$3(EllipseRenderer, _DefaultRenderer);
  3620. function EllipseRenderer() {
  3621. return _DefaultRenderer.apply(this, arguments) || this;
  3622. }
  3623. return EllipseRenderer;
  3624. }(DefaultRenderer);
  3625. var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
  3626. _inheritsLoose$3(LineRenderer, _DefaultRenderer);
  3627. function LineRenderer() {
  3628. return _DefaultRenderer.apply(this, arguments) || this;
  3629. }
  3630. return LineRenderer;
  3631. }(DefaultRenderer);
  3632. var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
  3633. _inheritsLoose$3(PolylineRenderer, _DefaultRenderer);
  3634. function PolylineRenderer() {
  3635. return _DefaultRenderer.apply(this, arguments) || this;
  3636. }
  3637. return PolylineRenderer;
  3638. }(DefaultRenderer);
  3639. var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
  3640. _inheritsLoose$3(PolygonRenderer, _DefaultRenderer);
  3641. function PolygonRenderer() {
  3642. return _DefaultRenderer.apply(this, arguments) || this;
  3643. }
  3644. return PolygonRenderer;
  3645. }(DefaultRenderer);
  3646. var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
  3647. _inheritsLoose$3(PathRenderer, _DefaultRenderer);
  3648. function PathRenderer() {
  3649. return _DefaultRenderer.apply(this, arguments) || this;
  3650. }
  3651. return PathRenderer;
  3652. }(DefaultRenderer);
  3653. var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
  3654. _inheritsLoose$3(Plugin, _AbstractRendererPlug);
  3655. function Plugin(options) {
  3656. var _this;
  3657. if (options === void 0) {
  3658. options = {};
  3659. }
  3660. _this = _AbstractRendererPlug.call(this) || this;
  3661. _this.options = void 0;
  3662. _this.name = 'canvas-renderer';
  3663. _this.options = options;
  3664. return _this;
  3665. }
  3666. var _proto = Plugin.prototype;
  3667. _proto.init = function init() {
  3668. var _defaultStyleRenderer;
  3669. var canvasRendererPluginOptions = _extends({
  3670. dirtyObjectNumThreshold: 500,
  3671. dirtyObjectRatioThreshold: 0.8
  3672. }, this.options);
  3673. // @ts-ignore
  3674. var imagePool = this.context.imagePool;
  3675. var defaultRenderer = new DefaultRenderer(imagePool);
  3676. var defaultStyleRendererFactory = (_defaultStyleRenderer = {}, _defaultStyleRenderer[gLite.Shape.CIRCLE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.ELLIPSE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.RECT] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.IMAGE] = new ImageRenderer(imagePool), _defaultStyleRenderer[gLite.Shape.TEXT] = new TextRenderer(), _defaultStyleRenderer[gLite.Shape.LINE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.POLYLINE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.POLYGON] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.PATH] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.GROUP] = undefined, _defaultStyleRenderer[gLite.Shape.HTML] = undefined, _defaultStyleRenderer[gLite.Shape.MESH] = undefined, _defaultStyleRenderer);
  3677. this.context.defaultStyleRendererFactory = defaultStyleRendererFactory;
  3678. this.context.styleRendererFactory = defaultStyleRendererFactory;
  3679. this.addRenderingPlugin(new CanvasRendererPlugin(canvasRendererPluginOptions));
  3680. };
  3681. _proto.destroy = function destroy() {
  3682. this.removeAllRenderingPlugins();
  3683. delete this.context.defaultStyleRendererFactory;
  3684. delete this.context.styleRendererFactory;
  3685. };
  3686. return Plugin;
  3687. }(gLite.AbstractRendererPlugin);
  3688. var index_esm$2 = /*#__PURE__*/Object.freeze({
  3689. __proto__: null,
  3690. CircleRenderer: CircleRenderer,
  3691. EllipseRenderer: EllipseRenderer,
  3692. ImageRenderer: ImageRenderer,
  3693. LineRenderer: LineRenderer,
  3694. PathRenderer: PathRenderer,
  3695. Plugin: Plugin$2,
  3696. PolygonRenderer: PolygonRenderer,
  3697. PolylineRenderer: PolylineRenderer,
  3698. RectRenderer: RectRenderer,
  3699. TextRenderer: TextRenderer
  3700. });
  3701. function _inheritsLoose$4(subClass, superClass) {
  3702. subClass.prototype = Object.create(superClass.prototype);
  3703. subClass.prototype.constructor = subClass;
  3704. _setPrototypeOf$4(subClass, superClass);
  3705. }
  3706. function _setPrototypeOf$4(o, p) {
  3707. _setPrototypeOf$4 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  3708. o.__proto__ = p;
  3709. return o;
  3710. };
  3711. return _setPrototypeOf$4(o, p);
  3712. }
  3713. // const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
  3714. /**
  3715. * listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
  3716. */
  3717. var DOMInteractionPlugin = /*#__PURE__*/function () {
  3718. function DOMInteractionPlugin() {
  3719. this.context = void 0;
  3720. }
  3721. var _proto = DOMInteractionPlugin.prototype;
  3722. _proto.apply = function apply(context, runtime) {
  3723. var _this = this;
  3724. var renderingService = context.renderingService,
  3725. renderingContext = context.renderingContext,
  3726. config = context.config;
  3727. this.context = context;
  3728. var canvas = renderingContext.root.ownerDocument.defaultView;
  3729. // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
  3730. var onPointerMove = function onPointerMove(ev) {
  3731. renderingService.hooks.pointerMove.call(ev);
  3732. };
  3733. var onPointerUp = function onPointerUp(ev) {
  3734. renderingService.hooks.pointerUp.call(ev);
  3735. };
  3736. var onPointerDown = function onPointerDown(ev) {
  3737. renderingService.hooks.pointerDown.call(ev);
  3738. };
  3739. var onPointerOver = function onPointerOver(ev) {
  3740. renderingService.hooks.pointerOver.call(ev);
  3741. };
  3742. var onPointerOut = function onPointerOut(ev) {
  3743. renderingService.hooks.pointerOut.call(ev);
  3744. };
  3745. var onPointerCancel = function onPointerCancel(ev) {
  3746. renderingService.hooks.pointerCancel.call(ev);
  3747. };
  3748. var onPointerWheel = function onPointerWheel(ev) {
  3749. renderingService.hooks.pointerWheel.call(ev);
  3750. };
  3751. var onClick = function onClick(ev) {
  3752. renderingService.hooks.click.call(ev);
  3753. };
  3754. var addPointerEventListener = function addPointerEventListener($el) {
  3755. runtime.globalThis.document.addEventListener('pointermove', onPointerMove, true);
  3756. $el.addEventListener('pointerdown', onPointerDown, true);
  3757. $el.addEventListener('pointerleave', onPointerOut, true);
  3758. $el.addEventListener('pointerover', onPointerOver, true);
  3759. runtime.globalThis.addEventListener('pointerup', onPointerUp, true);
  3760. runtime.globalThis.addEventListener('pointercancel', onPointerCancel, true);
  3761. };
  3762. var addTouchEventListener = function addTouchEventListener($el) {
  3763. $el.addEventListener('touchstart', onPointerDown, true);
  3764. $el.addEventListener('touchend', onPointerUp, true);
  3765. $el.addEventListener('touchmove', onPointerMove, true);
  3766. $el.addEventListener('touchcancel', onPointerCancel, true);
  3767. };
  3768. var addMouseEventListener = function addMouseEventListener($el) {
  3769. runtime.globalThis.document.addEventListener('mousemove', onPointerMove, true);
  3770. $el.addEventListener('mousedown', onPointerDown, true);
  3771. $el.addEventListener('mouseout', onPointerOut, true);
  3772. $el.addEventListener('mouseover', onPointerOver, true);
  3773. runtime.globalThis.addEventListener('mouseup', onPointerUp, true);
  3774. };
  3775. var removePointerEventListener = function removePointerEventListener($el) {
  3776. runtime.globalThis.document.removeEventListener('pointermove', onPointerMove, true);
  3777. $el.removeEventListener('pointerdown', onPointerDown, true);
  3778. $el.removeEventListener('pointerleave', onPointerOut, true);
  3779. $el.removeEventListener('pointerover', onPointerOver, true);
  3780. runtime.globalThis.removeEventListener('pointerup', onPointerUp, true);
  3781. };
  3782. var removeTouchEventListener = function removeTouchEventListener($el) {
  3783. $el.removeEventListener('touchstart', onPointerDown, true);
  3784. $el.removeEventListener('touchend', onPointerUp, true);
  3785. $el.removeEventListener('touchmove', onPointerMove, true);
  3786. $el.removeEventListener('touchcancel', onPointerCancel, true);
  3787. };
  3788. var removeMouseEventListener = function removeMouseEventListener($el) {
  3789. runtime.globalThis.document.removeEventListener('mousemove', onPointerMove, true);
  3790. $el.removeEventListener('mousedown', onPointerDown, true);
  3791. $el.removeEventListener('mouseout', onPointerOut, true);
  3792. $el.removeEventListener('mouseover', onPointerOver, true);
  3793. runtime.globalThis.removeEventListener('mouseup', onPointerUp, true);
  3794. };
  3795. renderingService.hooks.init.tap(DOMInteractionPlugin.tag, function () {
  3796. var $el = _this.context.contextService.getDomElement();
  3797. // @ts-ignore
  3798. if (runtime.globalThis.navigator.msPointerEnabled) {
  3799. // @ts-ignore
  3800. $el.style.msContentZooming = 'none';
  3801. // @ts-ignore
  3802. $el.style.msTouchAction = 'none';
  3803. } else if (canvas.supportsPointerEvents) {
  3804. $el.style.touchAction = 'none';
  3805. }
  3806. if (canvas.supportsPointerEvents) {
  3807. addPointerEventListener($el);
  3808. } else {
  3809. addMouseEventListener($el);
  3810. }
  3811. if (canvas.supportsTouchEvents) {
  3812. addTouchEventListener($el);
  3813. }
  3814. if (config.useNativeClickEvent) {
  3815. $el.addEventListener('click', onClick, true);
  3816. }
  3817. // use passive event listeners
  3818. // @see https://zhuanlan.zhihu.com/p/24555031
  3819. $el.addEventListener('wheel', onPointerWheel, {
  3820. passive: true,
  3821. capture: true
  3822. });
  3823. });
  3824. renderingService.hooks.destroy.tap(DOMInteractionPlugin.tag, function () {
  3825. var $el = _this.context.contextService.getDomElement();
  3826. // @ts-ignore
  3827. if (runtime.globalThis.navigator.msPointerEnabled) {
  3828. // @ts-ignore
  3829. $el.style.msContentZooming = '';
  3830. // @ts-ignore
  3831. $el.style.msTouchAction = '';
  3832. } else if (canvas.supportsPointerEvents) {
  3833. $el.style.touchAction = '';
  3834. }
  3835. if (canvas.supportsPointerEvents) {
  3836. removePointerEventListener($el);
  3837. } else {
  3838. removeMouseEventListener($el);
  3839. }
  3840. if (canvas.supportsTouchEvents) {
  3841. removeTouchEventListener($el);
  3842. }
  3843. if (config.useNativeClickEvent) {
  3844. $el.removeEventListener('click', onClick, true);
  3845. }
  3846. $el.removeEventListener('wheel', onPointerWheel, true);
  3847. });
  3848. };
  3849. return DOMInteractionPlugin;
  3850. }();
  3851. DOMInteractionPlugin.tag = 'DOMInteraction';
  3852. var Plugin$3 = /*#__PURE__*/function (_AbstractRendererPlug) {
  3853. _inheritsLoose$4(Plugin, _AbstractRendererPlug);
  3854. function Plugin() {
  3855. var _this;
  3856. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  3857. args[_key] = arguments[_key];
  3858. }
  3859. _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
  3860. _this.name = 'dom-interaction';
  3861. return _this;
  3862. }
  3863. var _proto = Plugin.prototype;
  3864. _proto.init = function init() {
  3865. this.addRenderingPlugin(new DOMInteractionPlugin());
  3866. };
  3867. _proto.destroy = function destroy() {
  3868. this.removeAllRenderingPlugins();
  3869. };
  3870. return Plugin;
  3871. }(gLite.AbstractRendererPlugin);
  3872. var index_esm$3 = /*#__PURE__*/Object.freeze({
  3873. __proto__: null,
  3874. Plugin: Plugin$3
  3875. });
  3876. function _inheritsLoose$5(subClass, superClass) {
  3877. subClass.prototype = Object.create(superClass.prototype);
  3878. subClass.prototype.constructor = subClass;
  3879. _setPrototypeOf$5(subClass, superClass);
  3880. }
  3881. function _setPrototypeOf$5(o, p) {
  3882. _setPrototypeOf$5 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  3883. o.__proto__ = p;
  3884. return o;
  3885. };
  3886. return _setPrototypeOf$5(o, p);
  3887. }
  3888. var HTML_PREFIX = 'g-html-';
  3889. var CANVAS_CAMERA_ID = 'g-canvas-camera';
  3890. var HTMLRenderingPlugin = /*#__PURE__*/function () {
  3891. function HTMLRenderingPlugin() {
  3892. this.context = void 0;
  3893. /**
  3894. * wrapper for camera
  3895. */
  3896. this.$camera = void 0;
  3897. }
  3898. var _proto = HTMLRenderingPlugin.prototype;
  3899. _proto.joinTransformMatrix = function joinTransformMatrix(matrix) {
  3900. return "matrix(" + [matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]].join(',') + ")";
  3901. };
  3902. _proto.apply = function apply(context) {
  3903. var _this = this;
  3904. var camera = context.camera,
  3905. renderingContext = context.renderingContext,
  3906. renderingService = context.renderingService;
  3907. this.context = context;
  3908. var canvas = renderingContext.root.ownerDocument.defaultView;
  3909. var setTransform = function setTransform(object, $el) {
  3910. $el.style.transform = _this.joinTransformMatrix(object.getWorldTransform());
  3911. };
  3912. var handleMounted = function handleMounted(e) {
  3913. var object = e.target;
  3914. if (object.nodeName === gLite.Shape.HTML) {
  3915. if (!_this.$camera) {
  3916. _this.$camera = _this.createCamera(camera);
  3917. }
  3918. // create DOM element
  3919. var $el = _this.getOrCreateEl(object);
  3920. _this.$camera.appendChild($el);
  3921. // apply documentElement's style
  3922. var attributes = object.ownerDocument.documentElement.attributes;
  3923. Object.keys(attributes).forEach(function (name) {
  3924. $el.style[name] = attributes[name];
  3925. });
  3926. Object.keys(object.attributes).forEach(function (name) {
  3927. _this.updateAttribute(name, object);
  3928. });
  3929. setTransform(object, $el);
  3930. gLite.runtime.nativeHTMLMap.set($el, object);
  3931. }
  3932. };
  3933. var handleUnmounted = function handleUnmounted(e) {
  3934. var object = e.target;
  3935. if (object.nodeName === gLite.Shape.HTML && _this.$camera) {
  3936. var $el = _this.getOrCreateEl(object);
  3937. if ($el) {
  3938. $el.remove();
  3939. gLite.runtime.nativeHTMLMap.delete($el);
  3940. }
  3941. // const existedId = this.getId(object);
  3942. // const $existedElement: HTMLElement | null = this.$camera.querySelector('#' + existedId);
  3943. // if ($existedElement) {
  3944. // this.$camera.removeChild($existedElement);
  3945. // }
  3946. }
  3947. };
  3948. var handleAttributeChanged = function handleAttributeChanged(e) {
  3949. var object = e.target;
  3950. if (object.nodeName === gLite.Shape.HTML) {
  3951. var attrName = e.attrName;
  3952. _this.updateAttribute(attrName, object);
  3953. }
  3954. };
  3955. var handleBoundsChanged = function handleBoundsChanged(e) {
  3956. var object = e.target;
  3957. if (object.nodeName === gLite.Shape.HTML) {
  3958. var $el = _this.getOrCreateEl(object);
  3959. setTransform(object, $el);
  3960. }
  3961. };
  3962. var handleCanvasResize = function handleCanvasResize() {
  3963. if (_this.$camera) {
  3964. var _this$context$config = _this.context.config,
  3965. width = _this$context$config.width,
  3966. height = _this$context$config.height;
  3967. _this.$camera.style.width = (width || 0) + "px";
  3968. _this.$camera.style.height = (height || 0) + "px";
  3969. }
  3970. };
  3971. renderingService.hooks.init.tap(HTMLRenderingPlugin.tag, function () {
  3972. canvas.addEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
  3973. canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
  3974. canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
  3975. canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
  3976. canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
  3977. });
  3978. renderingService.hooks.endFrame.tap(HTMLRenderingPlugin.tag, function () {
  3979. if (_this.$camera && renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
  3980. _this.$camera.style.transform = _this.joinTransformMatrix(camera.getOrthoMatrix());
  3981. }
  3982. });
  3983. renderingService.hooks.destroy.tap(HTMLRenderingPlugin.tag, function () {
  3984. // remove camera
  3985. if (_this.$camera) {
  3986. _this.$camera.remove();
  3987. }
  3988. canvas.removeEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
  3989. canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
  3990. canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
  3991. canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
  3992. canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
  3993. });
  3994. };
  3995. _proto.getId = function getId(object) {
  3996. return object.id || HTML_PREFIX + object.entity;
  3997. };
  3998. _proto.createCamera = function createCamera(camera) {
  3999. var _this$context$config2 = this.context.config,
  4000. doc = _this$context$config2.document,
  4001. width = _this$context$config2.width,
  4002. height = _this$context$config2.height;
  4003. var $canvas = this.context.contextService.getDomElement();
  4004. var $container = $canvas.parentNode;
  4005. if ($container) {
  4006. var cameraId = CANVAS_CAMERA_ID;
  4007. var $existedCamera = $container.querySelector('#' + cameraId);
  4008. if (!$existedCamera) {
  4009. var $camera = (doc || document).createElement('div');
  4010. $existedCamera = $camera;
  4011. $camera.id = cameraId;
  4012. // use absolute position
  4013. $camera.style.position = 'absolute';
  4014. // account for DOM element's offset @see https://github.com/antvis/G/issues/1150
  4015. $camera.style.left = ($canvas.offsetLeft || 0) + "px";
  4016. $camera.style.top = ($canvas.offsetTop || 0) + "px";
  4017. $camera.style.transformOrigin = 'left top';
  4018. $camera.style.transform = this.joinTransformMatrix(camera.getOrthoMatrix());
  4019. // HTML elements should not overflow with canvas @see https://github.com/antvis/G/issues/1163
  4020. $camera.style.overflow = 'hidden';
  4021. $camera.style.pointerEvents = 'none';
  4022. $camera.style.width = (width || 0) + "px";
  4023. $camera.style.height = (height || 0) + "px";
  4024. $container.appendChild($camera);
  4025. }
  4026. return $existedCamera;
  4027. }
  4028. return null;
  4029. };
  4030. _proto.getOrCreateEl = function getOrCreateEl(object) {
  4031. var doc = this.context.config.document;
  4032. var existedId = this.getId(object);
  4033. var $existedElement = this.$camera.querySelector('#' + existedId);
  4034. if (!$existedElement) {
  4035. $existedElement = (doc || document).createElement('div');
  4036. object.parsedStyle.$el = $existedElement;
  4037. $existedElement.id = existedId;
  4038. if (object.name) {
  4039. $existedElement.setAttribute('name', object.name);
  4040. }
  4041. if (object.className) {
  4042. $existedElement.className = object.className;
  4043. }
  4044. // use absolute position
  4045. $existedElement.style.position = 'absolute';
  4046. // @see https://github.com/antvis/G/issues/1150
  4047. $existedElement.style.left = "0px";
  4048. $existedElement.style.top = "0px";
  4049. $existedElement.style['will-change'] = 'transform';
  4050. $existedElement.style.transform = this.joinTransformMatrix(object.getWorldTransform());
  4051. }
  4052. return $existedElement;
  4053. };
  4054. _proto.updateAttribute = function updateAttribute(name, object) {
  4055. var $el = this.getOrCreateEl(object);
  4056. switch (name) {
  4057. case 'innerHTML':
  4058. var innerHTML = object.parsedStyle.innerHTML;
  4059. if (isString(innerHTML)) {
  4060. $el.innerHTML = innerHTML;
  4061. } else {
  4062. $el.innerHTML = '';
  4063. $el.appendChild(innerHTML);
  4064. }
  4065. break;
  4066. case 'transformOrigin':
  4067. var transformOrigin = object.parsedStyle.transformOrigin;
  4068. $el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
  4069. break;
  4070. case 'width':
  4071. if (gLite.runtime.enableCSSParsing) {
  4072. var width = object.computedStyleMap().get('width');
  4073. $el.style.width = width.toString();
  4074. } else {
  4075. var _width = object.parsedStyle.width;
  4076. $el.style.width = isNumber(_width) ? _width + "px" : _width.toString();
  4077. }
  4078. break;
  4079. case 'height':
  4080. if (gLite.runtime.enableCSSParsing) {
  4081. var height = object.computedStyleMap().get('height');
  4082. $el.style.height = height.toString();
  4083. } else {
  4084. var _height = object.parsedStyle.height;
  4085. $el.style.height = isNumber(_height) ? _height + "px" : _height.toString();
  4086. }
  4087. break;
  4088. case 'zIndex':
  4089. var zIndex = object.parsedStyle.zIndex;
  4090. $el.style['z-index'] = "" + zIndex;
  4091. break;
  4092. case 'visibility':
  4093. var visibility = object.parsedStyle.visibility;
  4094. $el.style.visibility = visibility;
  4095. break;
  4096. case 'pointerEvents':
  4097. var pointerEvents = object.parsedStyle.pointerEvents;
  4098. $el.style.pointerEvents = pointerEvents;
  4099. break;
  4100. case 'opacity':
  4101. var opacity = object.parsedStyle.opacity;
  4102. $el.style.opacity = "" + opacity;
  4103. break;
  4104. case 'fill':
  4105. var fill = object.parsedStyle.fill;
  4106. var color = '';
  4107. if (gLite.isCSSRGB(fill)) {
  4108. if (fill.isNone) {
  4109. color = 'transparent';
  4110. } else {
  4111. color = object.getAttribute('fill');
  4112. }
  4113. } else if (Array.isArray(fill)) {
  4114. color = object.getAttribute('fill');
  4115. } else if (gLite.isPattern(fill)) ;
  4116. $el.style.background = color;
  4117. break;
  4118. case 'stroke':
  4119. var stroke = object.parsedStyle.stroke;
  4120. var borderColor = '';
  4121. if (gLite.isCSSRGB(stroke)) {
  4122. if (stroke.isNone) {
  4123. borderColor = 'transparent';
  4124. } else {
  4125. borderColor = object.getAttribute('stroke');
  4126. }
  4127. } else if (Array.isArray(stroke)) {
  4128. borderColor = object.getAttribute('stroke');
  4129. } else if (gLite.isPattern(stroke)) ;
  4130. $el.style['border-color'] = borderColor;
  4131. $el.style['border-style'] = 'solid';
  4132. break;
  4133. case 'lineWidth':
  4134. var lineWidth = object.parsedStyle.lineWidth;
  4135. $el.style['border-width'] = (lineWidth || 0) + "px";
  4136. break;
  4137. case 'lineDash':
  4138. $el.style['border-style'] = 'dashed';
  4139. break;
  4140. case 'filter':
  4141. var filter = object.style.filter;
  4142. $el.style.filter = filter;
  4143. break;
  4144. }
  4145. };
  4146. return HTMLRenderingPlugin;
  4147. }();
  4148. HTMLRenderingPlugin.tag = 'HTMLRendering';
  4149. var Plugin$4 = /*#__PURE__*/function (_AbstractRendererPlug) {
  4150. _inheritsLoose$5(Plugin, _AbstractRendererPlug);
  4151. function Plugin() {
  4152. var _this;
  4153. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  4154. args[_key] = arguments[_key];
  4155. }
  4156. _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
  4157. _this.name = 'html-renderer';
  4158. return _this;
  4159. }
  4160. var _proto = Plugin.prototype;
  4161. _proto.init = function init() {
  4162. this.addRenderingPlugin(new HTMLRenderingPlugin());
  4163. };
  4164. _proto.destroy = function destroy() {
  4165. this.removeAllRenderingPlugins();
  4166. };
  4167. return Plugin;
  4168. }(gLite.AbstractRendererPlugin);
  4169. var index_esm$4 = /*#__PURE__*/Object.freeze({
  4170. __proto__: null,
  4171. Plugin: Plugin$4
  4172. });
  4173. function _inheritsLoose$6(subClass, superClass) {
  4174. subClass.prototype = Object.create(superClass.prototype);
  4175. subClass.prototype.constructor = subClass;
  4176. _setPrototypeOf$6(subClass, superClass);
  4177. }
  4178. function _setPrototypeOf$6(o, p) {
  4179. _setPrototypeOf$6 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  4180. o.__proto__ = p;
  4181. return o;
  4182. };
  4183. return _setPrototypeOf$6(o, p);
  4184. }
  4185. /**
  4186. * Common utilities
  4187. * @module glMatrix
  4188. */
  4189. var ARRAY_TYPE$1 = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  4190. if (!Math.hypot) Math.hypot = function () {
  4191. var y = 0,
  4192. i = arguments.length;
  4193. while (i--) {
  4194. y += arguments[i] * arguments[i];
  4195. }
  4196. return Math.sqrt(y);
  4197. };
  4198. /**
  4199. * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
  4200. * @module mat4
  4201. */
  4202. /**
  4203. * Creates a new identity mat4
  4204. *
  4205. * @returns {mat4} a new 4x4 matrix
  4206. */
  4207. function create$3() {
  4208. var out = new ARRAY_TYPE$1(16);
  4209. if (ARRAY_TYPE$1 != Float32Array) {
  4210. out[1] = 0;
  4211. out[2] = 0;
  4212. out[3] = 0;
  4213. out[4] = 0;
  4214. out[6] = 0;
  4215. out[7] = 0;
  4216. out[8] = 0;
  4217. out[9] = 0;
  4218. out[11] = 0;
  4219. out[12] = 0;
  4220. out[13] = 0;
  4221. out[14] = 0;
  4222. }
  4223. out[0] = 1;
  4224. out[5] = 1;
  4225. out[10] = 1;
  4226. out[15] = 1;
  4227. return out;
  4228. }
  4229. /**
  4230. * Set a mat4 to the identity matrix
  4231. *
  4232. * @param {mat4} out the receiving matrix
  4233. * @returns {mat4} out
  4234. */
  4235. function identity(out) {
  4236. out[0] = 1;
  4237. out[1] = 0;
  4238. out[2] = 0;
  4239. out[3] = 0;
  4240. out[4] = 0;
  4241. out[5] = 1;
  4242. out[6] = 0;
  4243. out[7] = 0;
  4244. out[8] = 0;
  4245. out[9] = 0;
  4246. out[10] = 1;
  4247. out[11] = 0;
  4248. out[12] = 0;
  4249. out[13] = 0;
  4250. out[14] = 0;
  4251. out[15] = 1;
  4252. return out;
  4253. }
  4254. /**
  4255. * Scales the mat4 by the dimensions in the given vec3 not using vectorization
  4256. *
  4257. * @param {mat4} out the receiving matrix
  4258. * @param {ReadonlyMat4} a the matrix to scale
  4259. * @param {ReadonlyVec3} v the vec3 to scale the matrix by
  4260. * @returns {mat4} out
  4261. **/
  4262. function scale(out, a, v) {
  4263. var x = v[0],
  4264. y = v[1],
  4265. z = v[2];
  4266. out[0] = a[0] * x;
  4267. out[1] = a[1] * x;
  4268. out[2] = a[2] * x;
  4269. out[3] = a[3] * x;
  4270. out[4] = a[4] * y;
  4271. out[5] = a[5] * y;
  4272. out[6] = a[6] * y;
  4273. out[7] = a[7] * y;
  4274. out[8] = a[8] * z;
  4275. out[9] = a[9] * z;
  4276. out[10] = a[10] * z;
  4277. out[11] = a[11] * z;
  4278. out[12] = a[12];
  4279. out[13] = a[13];
  4280. out[14] = a[14];
  4281. out[15] = a[15];
  4282. return out;
  4283. }
  4284. var ImagePool = /*#__PURE__*/function () {
  4285. function ImagePool(canvasConfig) {
  4286. this.canvasConfig = void 0;
  4287. this.imageCache = {};
  4288. this.gradientCache = {};
  4289. this.patternCache = {};
  4290. this.canvasConfig = canvasConfig;
  4291. }
  4292. var _proto = ImagePool.prototype;
  4293. _proto.getImageSync = function getImageSync(src, callback) {
  4294. if (!this.imageCache[src]) {
  4295. this.getOrCreateImage(src).then(function () {
  4296. if (callback) {
  4297. callback();
  4298. }
  4299. });
  4300. } else {
  4301. if (callback) {
  4302. callback();
  4303. }
  4304. }
  4305. return this.imageCache[src];
  4306. };
  4307. _proto.getOrCreateImage = function getOrCreateImage(src) {
  4308. var _this = this;
  4309. if (this.imageCache[src]) {
  4310. return Promise.resolve(this.imageCache[src]);
  4311. }
  4312. // @see https://github.com/antvis/g/issues/938
  4313. var createImage = this.canvasConfig.createImage;
  4314. return new Promise(function (resolve, reject) {
  4315. var image;
  4316. if (createImage) {
  4317. image = createImage(src);
  4318. } else if (gLite.isBrowser) {
  4319. image = new window.Image();
  4320. }
  4321. if (image) {
  4322. image.onload = function () {
  4323. _this.imageCache[src] = image;
  4324. resolve(image);
  4325. };
  4326. image.onerror = function (ev) {
  4327. reject(ev);
  4328. };
  4329. image.crossOrigin = 'Anonymous';
  4330. image.src = src;
  4331. }
  4332. });
  4333. };
  4334. _proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, $offscreenCanvas, dpr, callback) {
  4335. var patternKey = this.generatePatternKey(pattern);
  4336. if (patternKey && this.patternCache[patternKey]) {
  4337. return this.patternCache[patternKey];
  4338. }
  4339. var image = pattern.image,
  4340. repetition = pattern.repetition,
  4341. transform = pattern.transform;
  4342. var src;
  4343. var needScaleWithDPR = false;
  4344. // Image URL
  4345. if (isString(image)) {
  4346. src = this.getImageSync(image, callback);
  4347. } else if ($offscreenCanvas) {
  4348. src = $offscreenCanvas;
  4349. needScaleWithDPR = true;
  4350. } else {
  4351. src = image;
  4352. }
  4353. // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
  4354. var canvasPattern = src && context.createPattern(src, repetition);
  4355. if (canvasPattern) {
  4356. var mat;
  4357. // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern/setTransform
  4358. if (transform) {
  4359. mat = gLite.parsedTransformToMat4(gLite.parseTransform(transform));
  4360. } else {
  4361. mat = identity(create$3());
  4362. }
  4363. if (needScaleWithDPR) {
  4364. scale(mat, mat, [1 / dpr, 1 / dpr, 1]);
  4365. }
  4366. canvasPattern.setTransform({
  4367. a: mat[0],
  4368. b: mat[1],
  4369. c: mat[4],
  4370. d: mat[5],
  4371. e: mat[12],
  4372. f: mat[13]
  4373. });
  4374. }
  4375. if (patternKey && canvasPattern) {
  4376. this.patternCache[patternKey] = canvasPattern;
  4377. }
  4378. return canvasPattern;
  4379. };
  4380. _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
  4381. var key = this.generateGradientKey(params);
  4382. var type = params.type,
  4383. steps = params.steps,
  4384. width = params.width,
  4385. height = params.height,
  4386. angle = params.angle,
  4387. cx = params.cx,
  4388. cy = params.cy,
  4389. size = params.size;
  4390. if (this.gradientCache[key]) {
  4391. return this.gradientCache[key];
  4392. }
  4393. var gradient = null;
  4394. if (type === gLite.GradientType.LinearGradient) {
  4395. var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
  4396. x1 = _computeLinearGradien.x1,
  4397. y1 = _computeLinearGradien.y1,
  4398. x2 = _computeLinearGradien.x2,
  4399. y2 = _computeLinearGradien.y2;
  4400. // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
  4401. gradient = context.createLinearGradient(x1, y1, x2, y2);
  4402. } else if (type === gLite.GradientType.RadialGradient) {
  4403. var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
  4404. x = _computeRadialGradien.x,
  4405. y = _computeRadialGradien.y,
  4406. r = _computeRadialGradien.r;
  4407. // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
  4408. gradient = context.createRadialGradient(x, y, 0, x, y, r);
  4409. }
  4410. if (gradient) {
  4411. steps.forEach(function (_ref) {
  4412. var offset = _ref.offset,
  4413. color = _ref.color;
  4414. if (offset.unit === gLite.UnitType.kPercentage) {
  4415. var _gradient;
  4416. (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset.value / 100, color.toString());
  4417. }
  4418. });
  4419. this.gradientCache[key] = gradient;
  4420. }
  4421. return this.gradientCache[key];
  4422. };
  4423. _proto.generateGradientKey = function generateGradientKey(params) {
  4424. var type = params.type,
  4425. width = params.width,
  4426. height = params.height,
  4427. steps = params.steps,
  4428. angle = params.angle,
  4429. cx = params.cx,
  4430. cy = params.cy,
  4431. size = params.size;
  4432. return "gradient-" + type + "-" + ((angle === null || angle === void 0 ? void 0 : angle.toString()) || 0) + "-" + ((cx === null || cx === void 0 ? void 0 : cx.toString()) || 0) + "-" + ((cy === null || cy === void 0 ? void 0 : cy.toString()) || 0) + "-" + ((size === null || size === void 0 ? void 0 : size.toString()) || 0) + "-" + width + "-" + height + "-" + steps.map(function (_ref2) {
  4433. var offset = _ref2.offset,
  4434. color = _ref2.color;
  4435. return "" + offset + color;
  4436. }).join('-');
  4437. };
  4438. _proto.generatePatternKey = function generatePatternKey(pattern) {
  4439. var image = pattern.image,
  4440. repetition = pattern.repetition;
  4441. // only generate cache for Image
  4442. if (isString(image)) {
  4443. return "pattern-" + image + "-" + repetition;
  4444. } else if (image.nodeName === 'rect') {
  4445. return "pattern-" + image.entity + "-" + repetition;
  4446. }
  4447. };
  4448. return ImagePool;
  4449. }();
  4450. var LoadImagePlugin = /*#__PURE__*/function () {
  4451. function LoadImagePlugin() {}
  4452. var _proto = LoadImagePlugin.prototype;
  4453. _proto.apply = function apply(context) {
  4454. // @ts-ignore
  4455. var renderingService = context.renderingService,
  4456. renderingContext = context.renderingContext,
  4457. imagePool = context.imagePool;
  4458. var canvas = renderingContext.root.ownerDocument.defaultView;
  4459. var handleMounted = function handleMounted(e) {
  4460. var object = e.target;
  4461. var nodeName = object.nodeName,
  4462. attributes = object.attributes;
  4463. if (nodeName === gLite.Shape.IMAGE) {
  4464. var img = attributes.img;
  4465. if (isString(img)) {
  4466. imagePool.getImageSync(img, function () {
  4467. // set dirty rectangle flag
  4468. object.renderable.dirty = true;
  4469. renderingService.dirtify();
  4470. });
  4471. }
  4472. }
  4473. };
  4474. var handleAttributeChanged = function handleAttributeChanged(e) {
  4475. var object = e.target;
  4476. var attrName = e.attrName,
  4477. newValue = e.newValue;
  4478. if (object.nodeName === gLite.Shape.IMAGE) {
  4479. if (attrName === 'img') {
  4480. if (isString(newValue)) {
  4481. imagePool.getOrCreateImage(newValue).then(function () {
  4482. // set dirty rectangle flag
  4483. object.renderable.dirty = true;
  4484. renderingService.dirtify();
  4485. });
  4486. }
  4487. }
  4488. }
  4489. };
  4490. renderingService.hooks.init.tap(LoadImagePlugin.tag, function () {
  4491. canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
  4492. canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
  4493. });
  4494. renderingService.hooks.destroy.tap(LoadImagePlugin.tag, function () {
  4495. canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
  4496. canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
  4497. });
  4498. };
  4499. return LoadImagePlugin;
  4500. }();
  4501. LoadImagePlugin.tag = 'LoadImage';
  4502. var Plugin$5 = /*#__PURE__*/function (_AbstractRendererPlug) {
  4503. _inheritsLoose$6(Plugin, _AbstractRendererPlug);
  4504. function Plugin() {
  4505. var _this;
  4506. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  4507. args[_key] = arguments[_key];
  4508. }
  4509. _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
  4510. _this.name = 'image-loader';
  4511. return _this;
  4512. }
  4513. var _proto = Plugin.prototype;
  4514. _proto.init = function init() {
  4515. // @ts-ignore
  4516. this.context.imagePool = new ImagePool(this.context.config);
  4517. this.addRenderingPlugin(new LoadImagePlugin());
  4518. };
  4519. _proto.destroy = function destroy() {
  4520. this.removeAllRenderingPlugins();
  4521. };
  4522. return Plugin;
  4523. }(gLite.AbstractRendererPlugin);
  4524. var index_esm$5 = /*#__PURE__*/Object.freeze({
  4525. __proto__: null,
  4526. ImagePool: ImagePool,
  4527. Plugin: Plugin$5
  4528. });
  4529. var Canvas2DContextService = /*#__PURE__*/function () {
  4530. function Canvas2DContextService(context) {
  4531. this.$container = void 0;
  4532. this.$canvas = void 0;
  4533. this.dpr = void 0;
  4534. this.context = void 0;
  4535. this.canvasConfig = void 0;
  4536. this.renderingContext = void 0;
  4537. this.renderingContext = context.renderingContext;
  4538. this.canvasConfig = context.config;
  4539. }
  4540. var _proto = Canvas2DContextService.prototype;
  4541. _proto.init = function init() {
  4542. var _this$canvasConfig = this.canvasConfig,
  4543. container = _this$canvasConfig.container,
  4544. canvas = _this$canvasConfig.canvas;
  4545. if (canvas) {
  4546. this.$canvas = canvas;
  4547. if (container && canvas.parentElement !== container) {
  4548. container.appendChild(canvas);
  4549. }
  4550. this.$container = canvas.parentElement;
  4551. this.canvasConfig.container = this.$container;
  4552. } else if (container) {
  4553. // create container
  4554. this.$container = isString(container) ? document.getElementById(container) : container;
  4555. if (this.$container) {
  4556. // create canvas
  4557. var $canvas = document.createElement('canvas');
  4558. this.$container.appendChild($canvas);
  4559. if (!this.$container.style.position) {
  4560. this.$container.style.position = 'relative';
  4561. }
  4562. this.$canvas = $canvas;
  4563. }
  4564. }
  4565. this.context = this.$canvas.getContext('2d');
  4566. this.resize(this.canvasConfig.width, this.canvasConfig.height);
  4567. };
  4568. _proto.getContext = function getContext() {
  4569. return this.context;
  4570. };
  4571. _proto.getDomElement = function getDomElement() {
  4572. return this.$canvas;
  4573. };
  4574. _proto.getDPR = function getDPR() {
  4575. return this.dpr;
  4576. };
  4577. _proto.getBoundingClientRect = function getBoundingClientRect() {
  4578. if (this.$canvas.getBoundingClientRect) {
  4579. return this.$canvas.getBoundingClientRect();
  4580. }
  4581. };
  4582. _proto.destroy = function destroy() {
  4583. // @ts-ignore
  4584. if (this.$container && this.$canvas && this.$canvas.parentNode) {
  4585. // destroy context
  4586. // @ts-ignore
  4587. this.$container.removeChild(this.$canvas);
  4588. }
  4589. };
  4590. _proto.resize = function resize(width, height) {
  4591. var devicePixelRatio = this.canvasConfig.devicePixelRatio;
  4592. // use user-defined dpr first
  4593. var dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
  4594. dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
  4595. this.dpr = dpr;
  4596. if (this.$canvas) {
  4597. // set canvas width & height
  4598. this.$canvas.width = this.dpr * width;
  4599. this.$canvas.height = this.dpr * height;
  4600. // set CSS style width & height
  4601. gLite.setDOMSize(this.$canvas, width, height);
  4602. // const dpr = this.getDPR();
  4603. // scale all drawing operations by the dpr
  4604. // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
  4605. // this.context.scale(dpr, dpr);
  4606. }
  4607. this.renderingContext.renderReasons.add(gLite.RenderReason.CAMERA_CHANGED);
  4608. };
  4609. _proto.applyCursorStyle = function applyCursorStyle(cursor) {
  4610. if (this.$container && this.$container.style) {
  4611. this.$container.style.cursor = cursor;
  4612. }
  4613. };
  4614. _proto.toDataURL = /*#__PURE__*/function () {
  4615. var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
  4616. var _options, type, encoderOptions;
  4617. return _regeneratorRuntime().wrap(function _callee$(_context) {
  4618. while (1) switch (_context.prev = _context.next) {
  4619. case 0:
  4620. if (options === void 0) {
  4621. options = {};
  4622. }
  4623. _options = options, type = _options.type, encoderOptions = _options.encoderOptions;
  4624. return _context.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
  4625. case 3:
  4626. case "end":
  4627. return _context.stop();
  4628. }
  4629. }, _callee, this);
  4630. }));
  4631. function toDataURL(_x) {
  4632. return _toDataURL.apply(this, arguments);
  4633. }
  4634. return toDataURL;
  4635. }();
  4636. return Canvas2DContextService;
  4637. }();
  4638. var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
  4639. _inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
  4640. function ContextRegisterPlugin() {
  4641. var _this;
  4642. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  4643. args[_key] = arguments[_key];
  4644. }
  4645. _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
  4646. _this.name = 'canvas-context-register';
  4647. return _this;
  4648. }
  4649. var _proto = ContextRegisterPlugin.prototype;
  4650. _proto.init = function init() {
  4651. this.context.ContextService = Canvas2DContextService;
  4652. };
  4653. _proto.destroy = function destroy() {
  4654. delete this.context.ContextService;
  4655. };
  4656. return ContextRegisterPlugin;
  4657. }(gLite.AbstractRendererPlugin);
  4658. var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
  4659. _inheritsLoose(Renderer, _AbstractRenderer);
  4660. function Renderer(config) {
  4661. var _this;
  4662. _this = _AbstractRenderer.call(this, config) || this;
  4663. // register Canvas2DContext
  4664. _this.registerPlugin(new ContextRegisterPlugin());
  4665. _this.registerPlugin(new Plugin$5());
  4666. _this.registerPlugin(new Plugin());
  4667. // enable rendering with Canvas2D API
  4668. _this.registerPlugin(new Plugin$2());
  4669. _this.registerPlugin(new Plugin$3());
  4670. // enable picking with Canvas2D API
  4671. _this.registerPlugin(new Plugin$1());
  4672. // render HTML component
  4673. _this.registerPlugin(new Plugin$4());
  4674. return _this;
  4675. }
  4676. return Renderer;
  4677. }(gLite.AbstractRenderer);
  4678. exports.CanvasPathGenerator = index_esm;
  4679. exports.CanvasPicker = index_esm$1;
  4680. exports.CanvasRenderer = index_esm$2;
  4681. exports.DomInteraction = index_esm$3;
  4682. exports.HTMLRenderer = index_esm$4;
  4683. exports.ImageLoader = index_esm$5;
  4684. exports.Renderer = Renderer;
  4685. Object.defineProperty(exports, '__esModule', { value: true });
  4686. })));