engine.js 164 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 0);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ([
  89. /* 0 */
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. __webpack_require__.r(__webpack_exports__);
  93. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EE", function() { return EE; });
  94. /* harmony import */ var _env_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
  95. /* harmony import */ var _env_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_env_js__WEBPACK_IMPORTED_MODULE_0__);
  96. /* harmony import */ var _components_elements_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
  97. /* harmony import */ var _common_pool_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5);
  98. /* harmony import */ var tiny_emitter__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
  99. /* harmony import */ var tiny_emitter__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(tiny_emitter__WEBPACK_IMPORTED_MODULE_3__);
  100. /* harmony import */ var css_layout__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6);
  101. /* harmony import */ var css_layout__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(css_layout__WEBPACK_IMPORTED_MODULE_4__);
  102. /* harmony import */ var _common_util_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(7);
  103. /* harmony import */ var _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(8);
  104. /* harmony import */ var _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__);
  105. /* harmony import */ var _common_bitMapFont__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(14);
  106. /* harmony import */ var _components_index_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(16);
  107. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  108. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  109. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  110. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  111. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  112. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  113. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  114. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  115. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  116. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  117. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  118. // components
  119. // 全局事件管道
  120. var EE = new tiny_emitter__WEBPACK_IMPORTED_MODULE_3___default.a();
  121. var imgPool = new _common_pool_js__WEBPACK_IMPORTED_MODULE_2__["default"]('imgPool');
  122. var canvasPool = new _common_pool_js__WEBPACK_IMPORTED_MODULE_2__["default"]('canvasPool');
  123. var constructorMap = {
  124. view: _components_index_js__WEBPACK_IMPORTED_MODULE_8__["View"],
  125. text: _components_index_js__WEBPACK_IMPORTED_MODULE_8__["Text"],
  126. image: _components_index_js__WEBPACK_IMPORTED_MODULE_8__["Image"],
  127. scrollview: _components_index_js__WEBPACK_IMPORTED_MODULE_8__["ScrollView"],
  128. bitmaptext: _components_index_js__WEBPACK_IMPORTED_MODULE_8__["BitMapText"]
  129. };
  130. function isPercent(data) {
  131. return typeof data === 'string' && /\d+(?:\.\d+)?%/.test(data);
  132. }
  133. function convertPercent(data, parentData) {
  134. if (typeof data === 'number') {
  135. return data;
  136. }
  137. var matchData = data.match(/(\d+(?:\.\d+)?)%/)[1];
  138. if (matchData) {
  139. return parentData * matchData * 0.01;
  140. }
  141. }
  142. var create = function create(node, style, parent) {
  143. var _this = this;
  144. var _constructor = constructorMap[node.name];
  145. var children = node.children || [];
  146. var attr = node.attr || {};
  147. var id = attr.id || '';
  148. var args = Object.keys(attr).reduce(function (obj, key) {
  149. var value = attr[key];
  150. var attribute = key;
  151. if (key === 'id') {
  152. obj.style = Object.assign(obj.style || {}, style[id] || {});
  153. return obj;
  154. }
  155. if (key === 'class') {
  156. obj.style = value.split(/\s+/).reduce(function (res, oneClass) {
  157. return Object.assign(res, style[oneClass]);
  158. }, obj.style || {});
  159. return obj;
  160. } // if (/\{\{.+\}\}/.test(value)) {
  161. // }
  162. if (value === 'true') {
  163. obj[attribute] = true;
  164. } else if (value === 'false') {
  165. obj[attribute] = false;
  166. } else {
  167. obj[attribute] = value;
  168. }
  169. return obj;
  170. }, {}); // 用于后续元素查询
  171. args.idName = id;
  172. args.className = attr["class"] || '';
  173. var thisStyle = args.style;
  174. if (thisStyle) {
  175. var parentStyle;
  176. if (parent) {
  177. parentStyle = parent.style;
  178. } else if (typeof sharedCanvas !== 'undefined') {
  179. parentStyle = sharedCanvas;
  180. } else {
  181. parentStyle = __env.getSharedCanvas();
  182. }
  183. if (isPercent(thisStyle.width)) {
  184. thisStyle.width = parentStyle.width ? convertPercent(thisStyle.width, parentStyle.width) : 0;
  185. }
  186. if (isPercent(thisStyle.height)) {
  187. thisStyle.height = parentStyle.height ? convertPercent(thisStyle.height, parentStyle.height) : 0;
  188. }
  189. }
  190. var element = new _constructor(args);
  191. element.root = this;
  192. children.forEach(function (childNode) {
  193. var childElement = create.call(_this, childNode, style, args);
  194. element.add(childElement);
  195. });
  196. return element;
  197. };
  198. var getChildren = function getChildren(element) {
  199. return Object.keys(element.children).map(function (id) {
  200. return element.children[id];
  201. }).map(function (child) {
  202. return {
  203. id: child.id,
  204. name: child.name,
  205. style: child.style,
  206. children: getChildren(child)
  207. };
  208. });
  209. };
  210. var renderChildren = function renderChildren(children, context) {
  211. children.forEach(function (child) {
  212. if (child.type === 'ScrollView') {
  213. // ScrollView的子节点渲染交给ScrollView自己,不支持嵌套ScrollView
  214. child.insertScrollView(context);
  215. } else {
  216. child.insert(context);
  217. return renderChildren(child.children, context);
  218. }
  219. });
  220. };
  221. function layoutChildren(dataArray, children) {
  222. var _this2 = this;
  223. dataArray.forEach(function (data) {
  224. var child = children.find(function (item) {
  225. return item.id === data.id;
  226. });
  227. child.layoutBox = child.layoutBox || {};
  228. ['left', 'top', 'width', 'height'].forEach(function (prop) {
  229. child.layoutBox[prop] = data.layout[prop];
  230. });
  231. if (child.parent) {
  232. child.layoutBox.absoluteX = (child.parent.layoutBox.absoluteX || 0) + child.layoutBox.left;
  233. child.layoutBox.absoluteY = (child.parent.layoutBox.absoluteY || 0) + child.layoutBox.top;
  234. } else {
  235. child.layoutBox.absoluteX = child.layoutBox.left;
  236. child.layoutBox.absoluteY = child.layoutBox.top;
  237. }
  238. child.layoutBox.originalAbsoluteY = child.layoutBox.absoluteY; // 滚动列表的画板尺寸和主画板保持一致
  239. if (child.type === 'ScrollView') {
  240. child.updateRenderPort(_this2.renderport);
  241. }
  242. layoutChildren.call(_this2, data.children, child.children);
  243. });
  244. }
  245. var updateRealLayout = function updateRealLayout(dataArray, children, scale) {
  246. dataArray.forEach(function (data) {
  247. var child = children.find(function (item) {
  248. return item.id === data.id;
  249. });
  250. child.realLayoutBox = child.realLayoutBox || {};
  251. ['left', 'top', 'width', 'height'].forEach(function (prop) {
  252. child.realLayoutBox[prop] = data.layout[prop] * scale;
  253. });
  254. if (child.parent) {
  255. child.realLayoutBox.realX = (child.parent.realLayoutBox.realX || 0) + child.realLayoutBox.left;
  256. Object.defineProperty(child.realLayoutBox, 'realY', {
  257. configurable: true,
  258. enumerable: true,
  259. get: function get() {
  260. var res = (child.parent.realLayoutBox.realY || 0) + child.realLayoutBox.top;
  261. /**
  262. * 滚动列表事件处理
  263. */
  264. if (child.parent && child.parent.type === 'ScrollView') {
  265. res -= child.parent.top * scale;
  266. }
  267. return res;
  268. }
  269. });
  270. } else {
  271. child.realLayoutBox.realX = child.realLayoutBox.left;
  272. child.realLayoutBox.realY = child.realLayoutBox.top;
  273. }
  274. updateRealLayout(data.children, child.children, scale);
  275. });
  276. };
  277. function _getElementsById(tree) {
  278. var list = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  279. var id = arguments.length > 2 ? arguments[2] : undefined;
  280. Object.keys(tree.children).forEach(function (key) {
  281. var child = tree.children[key];
  282. if (child.idName === id) {
  283. list.push(child);
  284. }
  285. if (Object.keys(child.children).length) {
  286. _getElementsById(child, list, id);
  287. }
  288. });
  289. return list;
  290. }
  291. function _getElementsByClassName(tree) {
  292. var list = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  293. var className = arguments.length > 2 ? arguments[2] : undefined;
  294. Object.keys(tree.children).forEach(function (key) {
  295. var child = tree.children[key];
  296. if (child.className.split(/\s+/).indexOf(className) > -1) {
  297. list.push(child);
  298. }
  299. if (Object.keys(child.children).length) {
  300. _getElementsByClassName(child, list, className);
  301. }
  302. });
  303. return list;
  304. }
  305. var _Layout = /*#__PURE__*/function (_Element) {
  306. _inherits(_Layout, _Element);
  307. var _super = _createSuper(_Layout);
  308. function _Layout() {
  309. var _this3;
  310. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  311. style = _ref.style,
  312. name = _ref.name;
  313. _classCallCheck(this, _Layout);
  314. _this3 = _super.call(this, {
  315. style: style,
  316. id: 0,
  317. name: name
  318. });
  319. _this3.hasEventHandler = false;
  320. _this3.elementTree = null;
  321. _this3.renderContext = null;
  322. _this3.debugInfo = {};
  323. _this3.renderport = {};
  324. _this3.viewport = {};
  325. _this3.touchStart = _this3.eventHandler('touchstart').bind(_assertThisInitialized(_this3));
  326. _this3.touchMove = _this3.eventHandler('touchmove').bind(_assertThisInitialized(_this3));
  327. _this3.touchEnd = _this3.eventHandler('touchend').bind(_assertThisInitialized(_this3));
  328. _this3.touchCancel = _this3.eventHandler('touchcancel').bind(_assertThisInitialized(_this3));
  329. _this3.version = '0.0.1';
  330. _this3.touchMsg = {};
  331. _this3.hasViewPortSet = false;
  332. _this3.realLayoutBox = {
  333. realX: 0,
  334. realY: 0
  335. };
  336. _this3.state = _common_util_js__WEBPACK_IMPORTED_MODULE_5__["STATE"].UNINIT;
  337. _this3.bitMapFonts = [];
  338. return _this3;
  339. }
  340. /**
  341. * 更新被绘制canvas的窗口信息,本渲染引擎并不关心是否会和其他游戏引擎共同使用
  342. * 而本身又需要支持事件处理,因此,如果被渲染内容是绘制到离屏canvas,需要将最终绘制在屏幕上
  343. * 的绝对尺寸和位置信息更新到本渲染引擎。
  344. * 其中,width为物理像素宽度,height为物理像素高度,x为距离屏幕左上角的物理像素x坐标,y为距离屏幕左上角的物理像素
  345. * y坐标
  346. */
  347. _createClass(_Layout, [{
  348. key: "updateViewPort",
  349. value: function updateViewPort(box) {
  350. this.viewport.width = box.width || 0;
  351. this.viewport.height = box.height || 0;
  352. this.viewport.x = box.x || 0;
  353. this.viewport.y = box.y || 0;
  354. this.realLayoutBox = {
  355. realX: this.viewport.x,
  356. realY: this.viewport.y
  357. };
  358. this.hasViewPortSet = true;
  359. }
  360. }, {
  361. key: "init",
  362. value: function init(template, style, attrValueProcessor) {
  363. var start = new Date();
  364. /*if( parser.validate(template) === true) { //optional (it'll return an object in case it's not valid)*/
  365. /*}*/
  366. var parseConfig = {
  367. attributeNamePrefix: "",
  368. attrNodeName: "attr",
  369. //default is 'false'
  370. textNodeName: "#text",
  371. ignoreAttributes: false,
  372. ignoreNameSpace: true,
  373. allowBooleanAttributes: true,
  374. parseNodeValue: false,
  375. parseAttributeValue: false,
  376. trimValues: true,
  377. parseTrueNumberOnly: false
  378. };
  379. if (attrValueProcessor && typeof attrValueProcessor === "function") {
  380. parseConfig.attrValueProcessor = attrValueProcessor;
  381. }
  382. var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6___default.a.parse(template, parseConfig, true);
  383. var xmlTree = jsonObj.children[0];
  384. this.debugInfo.xmlTree = new Date() - start; // XML树生成渲染树
  385. this.layoutTree = create.call(this, xmlTree, style);
  386. this.debugInfo.layoutTree = new Date() - start;
  387. this.add(this.layoutTree);
  388. var elementTree = {
  389. id: this.id,
  390. style: {
  391. width: this.style.width,
  392. height: this.style.height,
  393. flexDirection: 'row'
  394. },
  395. children: getChildren(this)
  396. }; // 计算布局树
  397. css_layout__WEBPACK_IMPORTED_MODULE_4___default()(elementTree);
  398. this.elementTree = elementTree;
  399. this.debugInfo.renderTree = new Date() - start;
  400. var rootEle = this.children[0];
  401. if (rootEle.style.width === undefined || rootEle.style.height === undefined) {
  402. console.error('Please set width and height property for root element');
  403. } else {
  404. this.renderport.width = rootEle.style.width;
  405. this.renderport.height = rootEle.style.height;
  406. }
  407. this.state = _common_util_js__WEBPACK_IMPORTED_MODULE_5__["STATE"].INITED;
  408. }
  409. }, {
  410. key: "layout",
  411. value: function layout(context) {
  412. var start = new Date();
  413. this.renderContext = context;
  414. if (this.renderContext) {
  415. this.renderContext.clearRect(0, 0, this.renderport.width, this.renderport.height);
  416. }
  417. if (!this.hasViewPortSet) {
  418. console.error('Please invoke method `updateViewPort` before method `layout`');
  419. }
  420. layoutChildren.call(this, this.elementTree.children, this.children);
  421. this.debugInfo.layoutChildren = new Date() - start; // 计算真实的物理像素位置,用于事件处理
  422. updateRealLayout(this.elementTree.children, this.children, this.viewport.width / this.renderport.width);
  423. this.debugInfo.updateRealLayout = new Date() - start;
  424. renderChildren(this.children, context);
  425. this.debugInfo.renderChildren = new Date() - start;
  426. this.bindEvents();
  427. this.state = _common_util_js__WEBPACK_IMPORTED_MODULE_5__["STATE"].RENDERED;
  428. }
  429. }, {
  430. key: "initRepaint",
  431. value: function initRepaint() {
  432. var _this4 = this;
  433. this.on('repaint', function () {
  434. _this4.repaint();
  435. });
  436. this.EE.on('one__image__render__done', function (img) {
  437. _this4.repaint();
  438. });
  439. }
  440. }, {
  441. key: "repaint",
  442. value: function repaint() {
  443. var start = new Date();
  444. Object(_common_util_js__WEBPACK_IMPORTED_MODULE_5__["repaintChildren"])(this.children);
  445. this.emit('repaint__done');
  446. }
  447. }, {
  448. key: "getChildByPos",
  449. value: function getChildByPos(tree, x, y) {
  450. var list = Object.keys(tree.children);
  451. for (var i = 0; i < list.length; i++) {
  452. var child = tree.children[list[i]];
  453. var box = child.realLayoutBox;
  454. if (box.realX <= x && x <= box.realX + box.width && box.realY <= y && y <= box.realY + box.height) {
  455. if (Object.keys(child.children).length) {
  456. return this.getChildByPos(child, x, y);
  457. } else {
  458. return child;
  459. }
  460. }
  461. }
  462. return tree;
  463. }
  464. }, {
  465. key: "eventHandler",
  466. value: function eventHandler(eventName) {
  467. return function touchEventHandler(e) {
  468. if (!this.elementTree) {
  469. return;
  470. }
  471. var touch = e.touches && e.touches[0] || e.changedTouches && e.changedTouches[0] || e;
  472. if (!touch || !touch.pageX || !touch.pageY) {
  473. return;
  474. }
  475. if (!touch.timeStamp) {
  476. touch.timeStamp = e.timeStamp;
  477. }
  478. var item = touch && this.getChildByPos(this, touch.pageX, touch.pageY);
  479. item && item.emit(eventName, e);
  480. if (eventName === 'touchstart' || eventName === 'touchend') {
  481. this.touchMsg[eventName] = touch;
  482. }
  483. if (eventName === 'touchend' && Object(_common_util_js__WEBPACK_IMPORTED_MODULE_5__["isClick"])(this.touchMsg)) {
  484. item && item.emit('click', e);
  485. }
  486. };
  487. }
  488. }, {
  489. key: "bindEvents",
  490. value: function bindEvents() {
  491. if (this.hasEventHandler) {
  492. return;
  493. }
  494. this.hasEventHandler = true;
  495. if (typeof __env !== 'undefined') {
  496. __env.onTouchStart(this.touchStart);
  497. __env.onTouchMove(this.touchMove);
  498. __env.onTouchEnd(this.touchEnd);
  499. __env.onTouchCancel(this.touchCancel);
  500. } else {
  501. document.onmousedown = this.touchStart;
  502. document.onmousemove = this.touchMove;
  503. document.onmouseup = this.touchEnd;
  504. document.onmouseleave = this.touchEnd;
  505. }
  506. }
  507. }, {
  508. key: "emit",
  509. value: function emit(event, data) {
  510. EE.emit(event, data);
  511. }
  512. }, {
  513. key: "on",
  514. value: function on(event, callback) {
  515. EE.on(event, callback);
  516. }
  517. }, {
  518. key: "once",
  519. value: function once(event, callback) {
  520. EE.once(event, callback);
  521. }
  522. }, {
  523. key: "off",
  524. value: function off(event, callback) {
  525. EE.off(event, callback);
  526. }
  527. }, {
  528. key: "getElementsById",
  529. value: function getElementsById(id) {
  530. return _getElementsById(this, [], id);
  531. }
  532. }, {
  533. key: "getElementsByClassName",
  534. value: function getElementsByClassName(className) {
  535. return _getElementsByClassName(this, [], className);
  536. }
  537. }, {
  538. key: "destroyAll",
  539. value: function destroyAll(tree) {
  540. var _this5 = this;
  541. if (!tree) {
  542. tree = this;
  543. }
  544. var children = tree.children;
  545. children.forEach(function (child) {
  546. child.destroy();
  547. _this5.destroyAll(child);
  548. child.destroySelf && child.destroySelf();
  549. });
  550. }
  551. }, {
  552. key: "clear",
  553. value: function clear() {
  554. this.destroyAll();
  555. this.elementTree = null;
  556. this.children = [];
  557. this.layoutTree = {};
  558. this.state = _common_util_js__WEBPACK_IMPORTED_MODULE_5__["STATE"].CLEAR;
  559. canvasPool.getList().forEach(function (item) {
  560. item.context && item.context.clearRect(0, 0, item.canvas.width, item.canvas.height);
  561. item.elements = [];
  562. item.canvas = null;
  563. item.context = null;
  564. });
  565. if (this.renderContext) {
  566. this.renderContext.clearRect(0, 0, this.renderContext.canvas.width, this.renderContext.canvas.height);
  567. }
  568. /*['touchstart', 'touchmove', 'touchcancel', 'touchend', 'click', 'repaint'].forEach(eventName => {
  569. this.off(eventName);
  570. });*/
  571. this.EE.off('image__render__done');
  572. }
  573. }, {
  574. key: "clearPool",
  575. value: function clearPool() {
  576. imgPool.clear();
  577. canvasPool.clear();
  578. }
  579. }, {
  580. key: "clearAll",
  581. value: function clearAll() {
  582. this.clear();
  583. this.clearPool();
  584. }
  585. }, {
  586. key: "loadImgs",
  587. value: function loadImgs(arr) {
  588. arr.forEach(function (src) {
  589. var img = Object(_common_util_js__WEBPACK_IMPORTED_MODULE_5__["createImage"])();
  590. imgPool.set(src, img);
  591. img.onload = function () {
  592. img.loadDone = true;
  593. };
  594. img.onloadcbks = [];
  595. img.src = src;
  596. });
  597. }
  598. }, {
  599. key: "registBitMapFont",
  600. value: function registBitMapFont(name, src, config) {
  601. var font = new _common_bitMapFont__WEBPACK_IMPORTED_MODULE_7__["default"](name, src, config);
  602. this.bitMapFonts.push(font);
  603. }
  604. }]);
  605. return _Layout;
  606. }(_components_elements_js__WEBPACK_IMPORTED_MODULE_1__["default"]);
  607. var Layout = new _Layout({
  608. style: {
  609. width: 0,
  610. height: 0
  611. },
  612. name: 'layout'
  613. });
  614. /* harmony default export */ __webpack_exports__["default"] = (Layout);
  615. /***/ }),
  616. /* 1 */
  617. /***/ (function(module, exports) {
  618. GameGlobal.__env = GameGlobal.wx || GameGlobal.tt || GameGlobal.swan;
  619. /***/ }),
  620. /* 2 */
  621. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  622. "use strict";
  623. __webpack_require__.r(__webpack_exports__);
  624. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Element; });
  625. /* harmony import */ var _style_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
  626. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  627. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  628. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  629. var Emitter = __webpack_require__(4); // 全局事件管道
  630. var EE = new Emitter();
  631. var uuid = 0;
  632. var dpr = 1;
  633. function hexToRgb(hex) {
  634. var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  635. return result ? {
  636. r: parseInt(result[1], 16),
  637. g: parseInt(result[2], 16),
  638. b: parseInt(result[3], 16)
  639. } : null;
  640. }
  641. function getRgba(hex, opacity) {
  642. var rgbObj = hexToRgb(hex);
  643. if (opacity == undefined) {
  644. opacity = 1;
  645. }
  646. return "rgba(".concat(rgbObj.r, ", ").concat(rgbObj.g, ", ").concat(rgbObj.b, ", ").concat(opacity, ")");
  647. }
  648. var toEventName = function toEventName(event, id) {
  649. var elementEvent = ['click', 'touchstart', 'touchmove', 'touchend', 'touchcancel'];
  650. if (elementEvent.indexOf(event) !== -1) {
  651. return "element-".concat(id, "-").concat(event);
  652. }
  653. return "element-".concat(id, "-").concat(event);
  654. };
  655. var Element = /*#__PURE__*/function () {
  656. function Element(_ref) {
  657. var _this = this;
  658. var _ref$style = _ref.style,
  659. style = _ref$style === void 0 ? {} : _ref$style,
  660. _ref$props = _ref.props,
  661. props = _ref$props === void 0 ? {} : _ref$props,
  662. _ref$idName = _ref.idName,
  663. idName = _ref$idName === void 0 ? '' : _ref$idName,
  664. _ref$className = _ref.className,
  665. className = _ref$className === void 0 ? '' : _ref$className,
  666. _ref$id = _ref.id,
  667. id = _ref$id === void 0 ? ++uuid : _ref$id;
  668. _classCallCheck(this, Element);
  669. this.children = [];
  670. this.childMap = {};
  671. this.parent = null;
  672. this.parentId = 0;
  673. this.id = id;
  674. this.props = props;
  675. this.idName = idName;
  676. this.className = className;
  677. this.style = style;
  678. this.EE = EE;
  679. this.root = null;
  680. this.isDestroyed = false;
  681. this.layoutBox = {};
  682. if (style.opacity !== undefined && style.color && style.color.indexOf('#') > -1) {
  683. style.color = getRgba(style.color, style.opacity);
  684. }
  685. if (style.opacity !== undefined && style.backgroundColor && style.backgroundColor.indexOf('#') > -1) {
  686. style.backgroundColor = getRgba(style.backgroundColor, style.opacity);
  687. }
  688. for (var key in this.style) {
  689. if (_style_js__WEBPACK_IMPORTED_MODULE_0__["scalableStyles"].indexOf(key) > -1) {
  690. this.style[key] *= dpr;
  691. }
  692. } // 事件冒泡逻辑
  693. ['touchstart', 'touchmove', 'touchcancel', 'touchend', 'click'].forEach(function (eventName) {
  694. _this.on(eventName, function (e, touchMsg) {
  695. _this.parent && _this.parent.emit(eventName, e, touchMsg);
  696. });
  697. });
  698. this.initRepaint();
  699. }
  700. _createClass(Element, [{
  701. key: "initRepaint",
  702. value: function initRepaint() {
  703. var _this2 = this;
  704. this.on('repaint', function (e) {
  705. _this2.parent && _this2.parent.emit('repaint', e);
  706. });
  707. } // 子类填充实现
  708. }, {
  709. key: "repaint",
  710. value: function repaint() {} // 子类填充实现
  711. }, {
  712. key: "insert",
  713. value: function insert() {}
  714. }, {
  715. key: "checkNeedRender",
  716. value: function checkNeedRender() {
  717. return true;
  718. } // 子类填充实现
  719. }, {
  720. key: "destroy",
  721. value: function destroy() {
  722. var _this3 = this;
  723. ['touchstart', 'touchmove', 'touchcancel', 'touchend', 'click', 'repaint'].forEach(function (eventName) {
  724. _this3.off(eventName);
  725. });
  726. this.EE.off('image__render__done');
  727. this.isDestroyed = true;
  728. this.EE = null;
  729. /*this.root = null;*/
  730. this.parent = null;
  731. this.ctx = null;
  732. this.realLayoutBox = null;
  733. this.layoutBox = null;
  734. this.props = null;
  735. this.style = null;
  736. if (this.renderBoxes) {
  737. this.renderBoxes = null;
  738. }
  739. }
  740. }, {
  741. key: "add",
  742. value: function add(element) {
  743. element.parent = this;
  744. element.parentId = this.id;
  745. this.children.push(element);
  746. }
  747. }, {
  748. key: "emit",
  749. value: function emit(event) {
  750. for (var _len = arguments.length, theArgs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  751. theArgs[_key - 1] = arguments[_key];
  752. }
  753. EE.emit.apply(EE, [toEventName(event, this.id)].concat(theArgs));
  754. }
  755. }, {
  756. key: "on",
  757. value: function on(event, callback) {
  758. EE.on(toEventName(event, this.id), callback);
  759. }
  760. }, {
  761. key: "once",
  762. value: function once(event, callback) {
  763. EE.once(toEventName(event, this.id), callback);
  764. }
  765. }, {
  766. key: "off",
  767. value: function off(event, callback) {
  768. EE.off(toEventName(event, this.id), callback);
  769. } // 方便子类实现borderRadius
  770. }, {
  771. key: "roundRect",
  772. value: function roundRect(ctx, layoutBox) {
  773. var style = this.style || {};
  774. var box = layoutBox || this.layoutBox;
  775. var w = box.width;
  776. var h = box.height;
  777. var r = style.borderRadius;
  778. var x = box.absoluteX;
  779. var y = box.absoluteY;
  780. ctx.moveTo(x + r, y);
  781. ctx.arcTo(x + w, y, x + w, y + h, r);
  782. ctx.arcTo(x + w, y + h, x, y + h, r);
  783. ctx.arcTo(x, y + h, x, y, r);
  784. ctx.arcTo(x, y, x + w, y, r);
  785. ctx.clip();
  786. }
  787. }, {
  788. key: "renderBorder",
  789. value: function renderBorder(ctx, layoutBox) {
  790. var style = this.style || {};
  791. if (style.borderRadius) {
  792. this.roundRect(ctx, layoutBox);
  793. }
  794. ctx.save();
  795. var box = layoutBox || this.layoutBox;
  796. var borderWidth = style.borderWidth || 0;
  797. var borderLeftWidth = style.borderLeftWidth || 0;
  798. var borderRightWidth = style.borderRightWidth || 0;
  799. var borderTopWidth = style.borderTopWidth || 0;
  800. var borderBottomWidth = style.borderBottomWidth || 0;
  801. var radius = style.borderRadius || 0;
  802. var borderColor = style.borderColor;
  803. var drawX = box.absoluteX;
  804. var drawY = box.absoluteY;
  805. ctx.beginPath();
  806. if (borderWidth && borderColor) {
  807. ctx.lineWidth = borderWidth;
  808. ctx.strokeStyle = borderColor;
  809. ctx.strokeRect(drawX, drawY, box.width, box.height);
  810. }
  811. if (borderTopWidth && (borderColor || style.borderTopColor)) {
  812. ctx.lineWidth = borderTopWidth;
  813. ctx.strokeStyle = style.borderTopColor || borderColor;
  814. ctx.moveTo(radius ? drawX + radius : drawX, drawY + borderTopWidth / 2);
  815. ctx.lineTo(radius ? drawX + box.width - radius : drawX + box.width, drawY + borderTopWidth / 2);
  816. }
  817. if (borderBottomWidth && (borderColor || style.borderBottomColor)) {
  818. ctx.lineWidth = borderBottomWidth;
  819. ctx.strokeStyle = style.borderBottomColor || borderColor;
  820. ctx.moveTo(radius ? drawX + radius : drawX, drawY + box.height - borderBottomWidth / 2);
  821. ctx.lineTo(radius ? drawX + box.width - radius : drawX + box.width, drawY + box.height - borderBottomWidth / 2);
  822. }
  823. if (borderLeftWidth && (borderColor || style.borderLeftColor)) {
  824. ctx.lineWidth = borderLeftWidth;
  825. ctx.strokeStyle = style.borderLeftColor || borderColor;
  826. ctx.moveTo(drawX + borderLeftWidth / 2, radius ? drawY + radius : drawY);
  827. ctx.lineTo(drawX + borderLeftWidth / 2, radius ? drawY + box.height - radius : drawY + box.height);
  828. }
  829. if (borderRightWidth && (borderColor || style.borderRightColor)) {
  830. ctx.lineWidth = borderRightWidth;
  831. ctx.strokeStyle = style.borderRightColor || borderColor;
  832. ctx.moveTo(drawX + box.width - borderRightWidth / 2, radius ? drawY + radius : drawY);
  833. ctx.lineTo(drawX + box.width - borderRightWidth / 2, radius ? drawY + box.height - radius : drawY + box.height);
  834. }
  835. ctx.closePath();
  836. ctx.stroke();
  837. ctx.restore();
  838. }
  839. }]);
  840. return Element;
  841. }();
  842. /***/ }),
  843. /* 3 */
  844. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  845. "use strict";
  846. __webpack_require__.r(__webpack_exports__);
  847. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "scalableStyles", function() { return scalableStyles; });
  848. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "textStyles", function() { return textStyles; });
  849. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "layoutAffectedStyles", function() { return layoutAffectedStyles; });
  850. var textStyles = ['color', 'fontSize', 'textAlign', 'fontWeight', 'lineHeight', 'lineBreak'];
  851. var scalableStyles = ['left', 'top', 'right', 'bottom', 'width', 'height', 'margin', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom', 'padding', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'fontSize', 'lineHeight', 'borderRadius', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight'];
  852. var layoutAffectedStyles = ['margin', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight', 'padding', 'paddingTop', 'paddingBottom', 'paddingLeft', 'paddingRight', 'width', 'height'];
  853. /***/ }),
  854. /* 4 */
  855. /***/ (function(module, exports) {
  856. function E () {
  857. // Keep this empty so it's easier to inherit from
  858. // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
  859. }
  860. E.prototype = {
  861. on: function (name, callback, ctx) {
  862. var e = this.e || (this.e = {});
  863. (e[name] || (e[name] = [])).push({
  864. fn: callback,
  865. ctx: ctx
  866. });
  867. return this;
  868. },
  869. once: function (name, callback, ctx) {
  870. var self = this;
  871. function listener () {
  872. self.off(name, listener);
  873. callback.apply(ctx, arguments);
  874. };
  875. listener._ = callback
  876. return this.on(name, listener, ctx);
  877. },
  878. emit: function (name) {
  879. var data = [].slice.call(arguments, 1);
  880. var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
  881. var i = 0;
  882. var len = evtArr.length;
  883. for (i; i < len; i++) {
  884. evtArr[i].fn.apply(evtArr[i].ctx, data);
  885. }
  886. return this;
  887. },
  888. off: function (name, callback) {
  889. var e = this.e || (this.e = {});
  890. var evts = e[name];
  891. var liveEvents = [];
  892. if (evts && callback) {
  893. for (var i = 0, len = evts.length; i < len; i++) {
  894. if (evts[i].fn !== callback && evts[i].fn._ !== callback)
  895. liveEvents.push(evts[i]);
  896. }
  897. }
  898. // Remove event from queue to prevent memory leak
  899. // Suggested by https://github.com/lazd
  900. // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
  901. (liveEvents.length)
  902. ? e[name] = liveEvents
  903. : delete e[name];
  904. return this;
  905. }
  906. };
  907. module.exports = E;
  908. module.exports.TinyEmitter = E;
  909. /***/ }),
  910. /* 5 */
  911. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  912. "use strict";
  913. __webpack_require__.r(__webpack_exports__);
  914. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Pool; });
  915. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  916. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  917. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  918. var pools = [];
  919. var Pool = /*#__PURE__*/function () {
  920. function Pool() {
  921. var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'pool';
  922. _classCallCheck(this, Pool);
  923. var curr = pools.find(function (item) {
  924. return item.name === name;
  925. });
  926. if (curr) {
  927. return curr;
  928. }
  929. this.name = name;
  930. this.pool = {};
  931. pools.push(this);
  932. }
  933. _createClass(Pool, [{
  934. key: "get",
  935. value: function get(key) {
  936. return this.pool[key];
  937. }
  938. }, {
  939. key: "set",
  940. value: function set(key, value) {
  941. this.pool[key] = value;
  942. }
  943. }, {
  944. key: "clear",
  945. value: function clear() {
  946. this.pool = {};
  947. }
  948. }, {
  949. key: "getList",
  950. value: function getList() {
  951. return Object.values(this.pool);
  952. }
  953. }]);
  954. return Pool;
  955. }();
  956. /***/ }),
  957. /* 6 */
  958. /***/ (function(module, exports, __webpack_require__) {
  959. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// UMD (Universal Module Definition)
  960. // See https://github.com/umdjs/umd for reference
  961. //
  962. // This file uses the following specific UMD implementation:
  963. // https://github.com/umdjs/umd/blob/master/returnExports.js
  964. (function(root, factory) {
  965. if (true) {
  966. // AMD. Register as an anonymous module.
  967. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
  968. __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  969. (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
  970. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  971. } else {}
  972. }(this, function() {
  973. /**
  974. * Copyright (c) 2014, Facebook, Inc.
  975. * All rights reserved.
  976. *
  977. * This source code is licensed under the BSD-style license found in the
  978. * LICENSE file in the root directory of this source tree. An additional grant
  979. * of patent rights can be found in the PATENTS file in the same directory.
  980. */
  981. var computeLayout = (function() {
  982. var CSS_UNDEFINED;
  983. var CSS_DIRECTION_INHERIT = 'inherit';
  984. var CSS_DIRECTION_LTR = 'ltr';
  985. var CSS_DIRECTION_RTL = 'rtl';
  986. var CSS_FLEX_DIRECTION_ROW = 'row';
  987. var CSS_FLEX_DIRECTION_ROW_REVERSE = 'row-reverse';
  988. var CSS_FLEX_DIRECTION_COLUMN = 'column';
  989. var CSS_FLEX_DIRECTION_COLUMN_REVERSE = 'column-reverse';
  990. var CSS_JUSTIFY_FLEX_START = 'flex-start';
  991. var CSS_JUSTIFY_CENTER = 'center';
  992. var CSS_JUSTIFY_FLEX_END = 'flex-end';
  993. var CSS_JUSTIFY_SPACE_BETWEEN = 'space-between';
  994. var CSS_JUSTIFY_SPACE_AROUND = 'space-around';
  995. var CSS_ALIGN_FLEX_START = 'flex-start';
  996. var CSS_ALIGN_CENTER = 'center';
  997. var CSS_ALIGN_FLEX_END = 'flex-end';
  998. var CSS_ALIGN_STRETCH = 'stretch';
  999. var CSS_POSITION_RELATIVE = 'relative';
  1000. var CSS_POSITION_ABSOLUTE = 'absolute';
  1001. var leading = {
  1002. 'row': 'left',
  1003. 'row-reverse': 'right',
  1004. 'column': 'top',
  1005. 'column-reverse': 'bottom'
  1006. };
  1007. var trailing = {
  1008. 'row': 'right',
  1009. 'row-reverse': 'left',
  1010. 'column': 'bottom',
  1011. 'column-reverse': 'top'
  1012. };
  1013. var pos = {
  1014. 'row': 'left',
  1015. 'row-reverse': 'right',
  1016. 'column': 'top',
  1017. 'column-reverse': 'bottom'
  1018. };
  1019. var dim = {
  1020. 'row': 'width',
  1021. 'row-reverse': 'width',
  1022. 'column': 'height',
  1023. 'column-reverse': 'height'
  1024. };
  1025. // When transpiled to Java / C the node type has layout, children and style
  1026. // properties. For the JavaScript version this function adds these properties
  1027. // if they don't already exist.
  1028. function fillNodes(node) {
  1029. if (!node.layout || node.isDirty) {
  1030. node.layout = {
  1031. width: undefined,
  1032. height: undefined,
  1033. top: 0,
  1034. left: 0,
  1035. right: 0,
  1036. bottom: 0
  1037. };
  1038. }
  1039. if (!node.style) {
  1040. node.style = {};
  1041. }
  1042. if (!node.children) {
  1043. node.children = [];
  1044. }
  1045. node.children.forEach(fillNodes);
  1046. return node;
  1047. }
  1048. function isUndefined(value) {
  1049. return value === undefined;
  1050. }
  1051. function isRowDirection(flexDirection) {
  1052. return flexDirection === CSS_FLEX_DIRECTION_ROW ||
  1053. flexDirection === CSS_FLEX_DIRECTION_ROW_REVERSE;
  1054. }
  1055. function isColumnDirection(flexDirection) {
  1056. return flexDirection === CSS_FLEX_DIRECTION_COLUMN ||
  1057. flexDirection === CSS_FLEX_DIRECTION_COLUMN_REVERSE;
  1058. }
  1059. function getLeadingMargin(node, axis) {
  1060. if (node.style.marginStart !== undefined && isRowDirection(axis)) {
  1061. return node.style.marginStart;
  1062. }
  1063. var value = null;
  1064. switch (axis) {
  1065. case 'row': value = node.style.marginLeft; break;
  1066. case 'row-reverse': value = node.style.marginRight; break;
  1067. case 'column': value = node.style.marginTop; break;
  1068. case 'column-reverse': value = node.style.marginBottom; break;
  1069. }
  1070. if (value !== undefined) {
  1071. return value;
  1072. }
  1073. if (node.style.margin !== undefined) {
  1074. return node.style.margin;
  1075. }
  1076. return 0;
  1077. }
  1078. function getTrailingMargin(node, axis) {
  1079. if (node.style.marginEnd !== undefined && isRowDirection(axis)) {
  1080. return node.style.marginEnd;
  1081. }
  1082. var value = null;
  1083. switch (axis) {
  1084. case 'row': value = node.style.marginRight; break;
  1085. case 'row-reverse': value = node.style.marginLeft; break;
  1086. case 'column': value = node.style.marginBottom; break;
  1087. case 'column-reverse': value = node.style.marginTop; break;
  1088. }
  1089. if (value != null) {
  1090. return value;
  1091. }
  1092. if (node.style.margin !== undefined) {
  1093. return node.style.margin;
  1094. }
  1095. return 0;
  1096. }
  1097. function getLeadingPadding(node, axis) {
  1098. if (node.style.paddingStart !== undefined && node.style.paddingStart >= 0
  1099. && isRowDirection(axis)) {
  1100. return node.style.paddingStart;
  1101. }
  1102. var value = null;
  1103. switch (axis) {
  1104. case 'row': value = node.style.paddingLeft; break;
  1105. case 'row-reverse': value = node.style.paddingRight; break;
  1106. case 'column': value = node.style.paddingTop; break;
  1107. case 'column-reverse': value = node.style.paddingBottom; break;
  1108. }
  1109. if (value != null && value >= 0) {
  1110. return value;
  1111. }
  1112. if (node.style.padding !== undefined && node.style.padding >= 0) {
  1113. return node.style.padding;
  1114. }
  1115. return 0;
  1116. }
  1117. function getTrailingPadding(node, axis) {
  1118. if (node.style.paddingEnd !== undefined && node.style.paddingEnd >= 0
  1119. && isRowDirection(axis)) {
  1120. return node.style.paddingEnd;
  1121. }
  1122. var value = null;
  1123. switch (axis) {
  1124. case 'row': value = node.style.paddingRight; break;
  1125. case 'row-reverse': value = node.style.paddingLeft; break;
  1126. case 'column': value = node.style.paddingBottom; break;
  1127. case 'column-reverse': value = node.style.paddingTop; break;
  1128. }
  1129. if (value != null && value >= 0) {
  1130. return value;
  1131. }
  1132. if (node.style.padding !== undefined && node.style.padding >= 0) {
  1133. return node.style.padding;
  1134. }
  1135. return 0;
  1136. }
  1137. function getLeadingBorder(node, axis) {
  1138. if (node.style.borderStartWidth !== undefined && node.style.borderStartWidth >= 0
  1139. && isRowDirection(axis)) {
  1140. return node.style.borderStartWidth;
  1141. }
  1142. var value = null;
  1143. switch (axis) {
  1144. case 'row': value = node.style.borderLeftWidth; break;
  1145. case 'row-reverse': value = node.style.borderRightWidth; break;
  1146. case 'column': value = node.style.borderTopWidth; break;
  1147. case 'column-reverse': value = node.style.borderBottomWidth; break;
  1148. }
  1149. if (value != null && value >= 0) {
  1150. return value;
  1151. }
  1152. if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
  1153. return node.style.borderWidth;
  1154. }
  1155. return 0;
  1156. }
  1157. function getTrailingBorder(node, axis) {
  1158. if (node.style.borderEndWidth !== undefined && node.style.borderEndWidth >= 0
  1159. && isRowDirection(axis)) {
  1160. return node.style.borderEndWidth;
  1161. }
  1162. var value = null;
  1163. switch (axis) {
  1164. case 'row': value = node.style.borderRightWidth; break;
  1165. case 'row-reverse': value = node.style.borderLeftWidth; break;
  1166. case 'column': value = node.style.borderBottomWidth; break;
  1167. case 'column-reverse': value = node.style.borderTopWidth; break;
  1168. }
  1169. if (value != null && value >= 0) {
  1170. return value;
  1171. }
  1172. if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
  1173. return node.style.borderWidth;
  1174. }
  1175. return 0;
  1176. }
  1177. function getLeadingPaddingAndBorder(node, axis) {
  1178. return getLeadingPadding(node, axis) + getLeadingBorder(node, axis);
  1179. }
  1180. function getTrailingPaddingAndBorder(node, axis) {
  1181. return getTrailingPadding(node, axis) + getTrailingBorder(node, axis);
  1182. }
  1183. function getBorderAxis(node, axis) {
  1184. return getLeadingBorder(node, axis) + getTrailingBorder(node, axis);
  1185. }
  1186. function getMarginAxis(node, axis) {
  1187. return getLeadingMargin(node, axis) + getTrailingMargin(node, axis);
  1188. }
  1189. function getPaddingAndBorderAxis(node, axis) {
  1190. return getLeadingPaddingAndBorder(node, axis) +
  1191. getTrailingPaddingAndBorder(node, axis);
  1192. }
  1193. function getJustifyContent(node) {
  1194. if (node.style.justifyContent) {
  1195. return node.style.justifyContent;
  1196. }
  1197. return 'flex-start';
  1198. }
  1199. function getAlignContent(node) {
  1200. if (node.style.alignContent) {
  1201. return node.style.alignContent;
  1202. }
  1203. return 'flex-start';
  1204. }
  1205. function getAlignItem(node, child) {
  1206. if (child.style.alignSelf) {
  1207. return child.style.alignSelf;
  1208. }
  1209. if (node.style.alignItems) {
  1210. return node.style.alignItems;
  1211. }
  1212. return 'stretch';
  1213. }
  1214. function resolveAxis(axis, direction) {
  1215. if (direction === CSS_DIRECTION_RTL) {
  1216. if (axis === CSS_FLEX_DIRECTION_ROW) {
  1217. return CSS_FLEX_DIRECTION_ROW_REVERSE;
  1218. } else if (axis === CSS_FLEX_DIRECTION_ROW_REVERSE) {
  1219. return CSS_FLEX_DIRECTION_ROW;
  1220. }
  1221. }
  1222. return axis;
  1223. }
  1224. function resolveDirection(node, parentDirection) {
  1225. var direction;
  1226. if (node.style.direction) {
  1227. direction = node.style.direction;
  1228. } else {
  1229. direction = CSS_DIRECTION_INHERIT;
  1230. }
  1231. if (direction === CSS_DIRECTION_INHERIT) {
  1232. direction = (parentDirection === undefined ? CSS_DIRECTION_LTR : parentDirection);
  1233. }
  1234. return direction;
  1235. }
  1236. function getFlexDirection(node) {
  1237. if (node.style.flexDirection) {
  1238. return node.style.flexDirection;
  1239. }
  1240. return CSS_FLEX_DIRECTION_COLUMN;
  1241. }
  1242. function getCrossFlexDirection(flexDirection, direction) {
  1243. if (isColumnDirection(flexDirection)) {
  1244. return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
  1245. } else {
  1246. return CSS_FLEX_DIRECTION_COLUMN;
  1247. }
  1248. }
  1249. function getPositionType(node) {
  1250. if (node.style.position) {
  1251. return node.style.position;
  1252. }
  1253. return 'relative';
  1254. }
  1255. function isFlex(node) {
  1256. return (
  1257. getPositionType(node) === CSS_POSITION_RELATIVE &&
  1258. node.style.flex > 0
  1259. );
  1260. }
  1261. function isFlexWrap(node) {
  1262. return node.style.flexWrap === 'wrap';
  1263. }
  1264. function getDimWithMargin(node, axis) {
  1265. return node.layout[dim[axis]] + getMarginAxis(node, axis);
  1266. }
  1267. function isDimDefined(node, axis) {
  1268. return node.style[dim[axis]] !== undefined && node.style[dim[axis]] >= 0;
  1269. }
  1270. function isPosDefined(node, pos) {
  1271. return node.style[pos] !== undefined;
  1272. }
  1273. function isMeasureDefined(node) {
  1274. return node.style.measure !== undefined;
  1275. }
  1276. function getPosition(node, pos) {
  1277. if (node.style[pos] !== undefined) {
  1278. return node.style[pos];
  1279. }
  1280. return 0;
  1281. }
  1282. function boundAxis(node, axis, value) {
  1283. var min = {
  1284. 'row': node.style.minWidth,
  1285. 'row-reverse': node.style.minWidth,
  1286. 'column': node.style.minHeight,
  1287. 'column-reverse': node.style.minHeight
  1288. }[axis];
  1289. var max = {
  1290. 'row': node.style.maxWidth,
  1291. 'row-reverse': node.style.maxWidth,
  1292. 'column': node.style.maxHeight,
  1293. 'column-reverse': node.style.maxHeight
  1294. }[axis];
  1295. var boundValue = value;
  1296. if (max !== undefined && max >= 0 && boundValue > max) {
  1297. boundValue = max;
  1298. }
  1299. if (min !== undefined && min >= 0 && boundValue < min) {
  1300. boundValue = min;
  1301. }
  1302. return boundValue;
  1303. }
  1304. function fmaxf(a, b) {
  1305. if (a > b) {
  1306. return a;
  1307. }
  1308. return b;
  1309. }
  1310. // When the user specifically sets a value for width or height
  1311. function setDimensionFromStyle(node, axis) {
  1312. // The parent already computed us a width or height. We just skip it
  1313. if (node.layout[dim[axis]] !== undefined) {
  1314. return;
  1315. }
  1316. // We only run if there's a width or height defined
  1317. if (!isDimDefined(node, axis)) {
  1318. return;
  1319. }
  1320. // The dimensions can never be smaller than the padding and border
  1321. node.layout[dim[axis]] = fmaxf(
  1322. boundAxis(node, axis, node.style[dim[axis]]),
  1323. getPaddingAndBorderAxis(node, axis)
  1324. );
  1325. }
  1326. function setTrailingPosition(node, child, axis) {
  1327. child.layout[trailing[axis]] = node.layout[dim[axis]] -
  1328. child.layout[dim[axis]] - child.layout[pos[axis]];
  1329. }
  1330. // If both left and right are defined, then use left. Otherwise return
  1331. // +left or -right depending on which is defined.
  1332. function getRelativePosition(node, axis) {
  1333. if (node.style[leading[axis]] !== undefined) {
  1334. return getPosition(node, leading[axis]);
  1335. }
  1336. return -getPosition(node, trailing[axis]);
  1337. }
  1338. function layoutNodeImpl(node, parentMaxWidth, /*css_direction_t*/parentDirection) {
  1339. var/*css_direction_t*/ direction = resolveDirection(node, parentDirection);
  1340. var/*(c)!css_flex_direction_t*//*(java)!int*/ mainAxis = resolveAxis(getFlexDirection(node), direction);
  1341. var/*(c)!css_flex_direction_t*//*(java)!int*/ crossAxis = getCrossFlexDirection(mainAxis, direction);
  1342. var/*(c)!css_flex_direction_t*//*(java)!int*/ resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
  1343. // Handle width and height style attributes
  1344. setDimensionFromStyle(node, mainAxis);
  1345. setDimensionFromStyle(node, crossAxis);
  1346. // Set the resolved resolution in the node's layout
  1347. node.layout.direction = direction;
  1348. // The position is set by the parent, but we need to complete it with a
  1349. // delta composed of the margin and left/top/right/bottom
  1350. node.layout[leading[mainAxis]] += getLeadingMargin(node, mainAxis) +
  1351. getRelativePosition(node, mainAxis);
  1352. node.layout[trailing[mainAxis]] += getTrailingMargin(node, mainAxis) +
  1353. getRelativePosition(node, mainAxis);
  1354. node.layout[leading[crossAxis]] += getLeadingMargin(node, crossAxis) +
  1355. getRelativePosition(node, crossAxis);
  1356. node.layout[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) +
  1357. getRelativePosition(node, crossAxis);
  1358. // Inline immutable values from the target node to avoid excessive method
  1359. // invocations during the layout calculation.
  1360. var/*int*/ childCount = node.children.length;
  1361. var/*float*/ paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis);
  1362. if (isMeasureDefined(node)) {
  1363. var/*bool*/ isResolvedRowDimDefined = !isUndefined(node.layout[dim[resolvedRowAxis]]);
  1364. var/*float*/ width = CSS_UNDEFINED;
  1365. if (isDimDefined(node, resolvedRowAxis)) {
  1366. width = node.style.width;
  1367. } else if (isResolvedRowDimDefined) {
  1368. width = node.layout[dim[resolvedRowAxis]];
  1369. } else {
  1370. width = parentMaxWidth -
  1371. getMarginAxis(node, resolvedRowAxis);
  1372. }
  1373. width -= paddingAndBorderAxisResolvedRow;
  1374. // We only need to give a dimension for the text if we haven't got any
  1375. // for it computed yet. It can either be from the style attribute or because
  1376. // the element is flexible.
  1377. var/*bool*/ isRowUndefined = !isDimDefined(node, resolvedRowAxis) && !isResolvedRowDimDefined;
  1378. var/*bool*/ isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) &&
  1379. isUndefined(node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]]);
  1380. // Let's not measure the text if we already know both dimensions
  1381. if (isRowUndefined || isColumnUndefined) {
  1382. var/*css_dim_t*/ measureDim = node.style.measure(
  1383. /*(c)!node->context,*/
  1384. /*(java)!layoutContext.measureOutput,*/
  1385. width
  1386. );
  1387. if (isRowUndefined) {
  1388. node.layout.width = measureDim.width +
  1389. paddingAndBorderAxisResolvedRow;
  1390. }
  1391. if (isColumnUndefined) {
  1392. node.layout.height = measureDim.height +
  1393. getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
  1394. }
  1395. }
  1396. if (childCount === 0) {
  1397. return;
  1398. }
  1399. }
  1400. var/*bool*/ isNodeFlexWrap = isFlexWrap(node);
  1401. var/*css_justify_t*/ justifyContent = getJustifyContent(node);
  1402. var/*float*/ leadingPaddingAndBorderMain = getLeadingPaddingAndBorder(node, mainAxis);
  1403. var/*float*/ leadingPaddingAndBorderCross = getLeadingPaddingAndBorder(node, crossAxis);
  1404. var/*float*/ paddingAndBorderAxisMain = getPaddingAndBorderAxis(node, mainAxis);
  1405. var/*float*/ paddingAndBorderAxisCross = getPaddingAndBorderAxis(node, crossAxis);
  1406. var/*bool*/ isMainDimDefined = !isUndefined(node.layout[dim[mainAxis]]);
  1407. var/*bool*/ isCrossDimDefined = !isUndefined(node.layout[dim[crossAxis]]);
  1408. var/*bool*/ isMainRowDirection = isRowDirection(mainAxis);
  1409. var/*int*/ i;
  1410. var/*int*/ ii;
  1411. var/*css_node_t**/ child;
  1412. var/*(c)!css_flex_direction_t*//*(java)!int*/ axis;
  1413. var/*css_node_t**/ firstAbsoluteChild = null;
  1414. var/*css_node_t**/ currentAbsoluteChild = null;
  1415. var/*float*/ definedMainDim = CSS_UNDEFINED;
  1416. if (isMainDimDefined) {
  1417. definedMainDim = node.layout[dim[mainAxis]] - paddingAndBorderAxisMain;
  1418. }
  1419. // We want to execute the next two loops one per line with flex-wrap
  1420. var/*int*/ startLine = 0;
  1421. var/*int*/ endLine = 0;
  1422. // var/*int*/ nextOffset = 0;
  1423. var/*int*/ alreadyComputedNextLayout = 0;
  1424. // We aggregate the total dimensions of the container in those two variables
  1425. var/*float*/ linesCrossDim = 0;
  1426. var/*float*/ linesMainDim = 0;
  1427. var/*int*/ linesCount = 0;
  1428. while (endLine < childCount) {
  1429. // <Loop A> Layout non flexible children and count children by type
  1430. // mainContentDim is accumulation of the dimensions and margin of all the
  1431. // non flexible children. This will be used in order to either set the
  1432. // dimensions of the node if none already exist, or to compute the
  1433. // remaining space left for the flexible children.
  1434. var/*float*/ mainContentDim = 0;
  1435. // There are three kind of children, non flexible, flexible and absolute.
  1436. // We need to know how many there are in order to distribute the space.
  1437. var/*int*/ flexibleChildrenCount = 0;
  1438. var/*float*/ totalFlexible = 0;
  1439. var/*int*/ nonFlexibleChildrenCount = 0;
  1440. // Use the line loop to position children in the main axis for as long
  1441. // as they are using a simple stacking behaviour. Children that are
  1442. // immediately stacked in the initial loop will not be touched again
  1443. // in <Loop C>.
  1444. var/*bool*/ isSimpleStackMain =
  1445. (isMainDimDefined && justifyContent === CSS_JUSTIFY_FLEX_START) ||
  1446. (!isMainDimDefined && justifyContent !== CSS_JUSTIFY_CENTER);
  1447. var/*int*/ firstComplexMain = (isSimpleStackMain ? childCount : startLine);
  1448. // Use the initial line loop to position children in the cross axis for
  1449. // as long as they are relatively positioned with alignment STRETCH or
  1450. // FLEX_START. Children that are immediately stacked in the initial loop
  1451. // will not be touched again in <Loop D>.
  1452. var/*bool*/ isSimpleStackCross = true;
  1453. var/*int*/ firstComplexCross = childCount;
  1454. var/*css_node_t**/ firstFlexChild = null;
  1455. var/*css_node_t**/ currentFlexChild = null;
  1456. var/*float*/ mainDim = leadingPaddingAndBorderMain;
  1457. var/*float*/ crossDim = 0;
  1458. var/*float*/ maxWidth;
  1459. for (i = startLine; i < childCount; ++i) {
  1460. child = node.children[i];
  1461. child.lineIndex = linesCount;
  1462. child.nextAbsoluteChild = null;
  1463. child.nextFlexChild = null;
  1464. var/*css_align_t*/ alignItem = getAlignItem(node, child);
  1465. // Pre-fill cross axis dimensions when the child is using stretch before
  1466. // we call the recursive layout pass
  1467. if (alignItem === CSS_ALIGN_STRETCH &&
  1468. getPositionType(child) === CSS_POSITION_RELATIVE &&
  1469. isCrossDimDefined &&
  1470. !isDimDefined(child, crossAxis)) {
  1471. child.layout[dim[crossAxis]] = fmaxf(
  1472. boundAxis(child, crossAxis, node.layout[dim[crossAxis]] -
  1473. paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),
  1474. // You never want to go smaller than padding
  1475. getPaddingAndBorderAxis(child, crossAxis)
  1476. );
  1477. } else if (getPositionType(child) === CSS_POSITION_ABSOLUTE) {
  1478. // Store a private linked list of absolutely positioned children
  1479. // so that we can efficiently traverse them later.
  1480. if (firstAbsoluteChild === null) {
  1481. firstAbsoluteChild = child;
  1482. }
  1483. if (currentAbsoluteChild !== null) {
  1484. currentAbsoluteChild.nextAbsoluteChild = child;
  1485. }
  1486. currentAbsoluteChild = child;
  1487. // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both
  1488. // left and right or top and bottom).
  1489. for (ii = 0; ii < 2; ii++) {
  1490. axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
  1491. if (!isUndefined(node.layout[dim[axis]]) &&
  1492. !isDimDefined(child, axis) &&
  1493. isPosDefined(child, leading[axis]) &&
  1494. isPosDefined(child, trailing[axis])) {
  1495. child.layout[dim[axis]] = fmaxf(
  1496. boundAxis(child, axis, node.layout[dim[axis]] -
  1497. getPaddingAndBorderAxis(node, axis) -
  1498. getMarginAxis(child, axis) -
  1499. getPosition(child, leading[axis]) -
  1500. getPosition(child, trailing[axis])),
  1501. // You never want to go smaller than padding
  1502. getPaddingAndBorderAxis(child, axis)
  1503. );
  1504. }
  1505. }
  1506. }
  1507. var/*float*/ nextContentDim = 0;
  1508. // It only makes sense to consider a child flexible if we have a computed
  1509. // dimension for the node.
  1510. if (isMainDimDefined && isFlex(child)) {
  1511. flexibleChildrenCount++;
  1512. totalFlexible += child.style.flex;
  1513. // Store a private linked list of flexible children so that we can
  1514. // efficiently traverse them later.
  1515. if (firstFlexChild === null) {
  1516. firstFlexChild = child;
  1517. }
  1518. if (currentFlexChild !== null) {
  1519. currentFlexChild.nextFlexChild = child;
  1520. }
  1521. currentFlexChild = child;
  1522. // Even if we don't know its exact size yet, we already know the padding,
  1523. // border and margin. We'll use this partial information, which represents
  1524. // the smallest possible size for the child, to compute the remaining
  1525. // available space.
  1526. nextContentDim = getPaddingAndBorderAxis(child, mainAxis) +
  1527. getMarginAxis(child, mainAxis);
  1528. } else {
  1529. maxWidth = CSS_UNDEFINED;
  1530. if (!isMainRowDirection) {
  1531. if (isDimDefined(node, resolvedRowAxis)) {
  1532. maxWidth = node.layout[dim[resolvedRowAxis]] -
  1533. paddingAndBorderAxisResolvedRow;
  1534. } else {
  1535. maxWidth = parentMaxWidth -
  1536. getMarginAxis(node, resolvedRowAxis) -
  1537. paddingAndBorderAxisResolvedRow;
  1538. }
  1539. }
  1540. // This is the main recursive call. We layout non flexible children.
  1541. if (alreadyComputedNextLayout === 0) {
  1542. layoutNode(/*(java)!layoutContext, */child, maxWidth, direction);
  1543. }
  1544. // Absolute positioned elements do not take part of the layout, so we
  1545. // don't use them to compute mainContentDim
  1546. if (getPositionType(child) === CSS_POSITION_RELATIVE) {
  1547. nonFlexibleChildrenCount++;
  1548. // At this point we know the final size and margin of the element.
  1549. nextContentDim = getDimWithMargin(child, mainAxis);
  1550. }
  1551. }
  1552. // The element we are about to add would make us go to the next line
  1553. if (isNodeFlexWrap &&
  1554. isMainDimDefined &&
  1555. mainContentDim + nextContentDim > definedMainDim &&
  1556. // If there's only one element, then it's bigger than the content
  1557. // and needs its own line
  1558. i !== startLine) {
  1559. nonFlexibleChildrenCount--;
  1560. alreadyComputedNextLayout = 1;
  1561. break;
  1562. }
  1563. // Disable simple stacking in the main axis for the current line as
  1564. // we found a non-trivial child. The remaining children will be laid out
  1565. // in <Loop C>.
  1566. if (isSimpleStackMain &&
  1567. (getPositionType(child) !== CSS_POSITION_RELATIVE || isFlex(child))) {
  1568. isSimpleStackMain = false;
  1569. firstComplexMain = i;
  1570. }
  1571. // Disable simple stacking in the cross axis for the current line as
  1572. // we found a non-trivial child. The remaining children will be laid out
  1573. // in <Loop D>.
  1574. if (isSimpleStackCross &&
  1575. (getPositionType(child) !== CSS_POSITION_RELATIVE ||
  1576. (alignItem !== CSS_ALIGN_STRETCH && alignItem !== CSS_ALIGN_FLEX_START) ||
  1577. isUndefined(child.layout[dim[crossAxis]]))) {
  1578. isSimpleStackCross = false;
  1579. firstComplexCross = i;
  1580. }
  1581. if (isSimpleStackMain) {
  1582. child.layout[pos[mainAxis]] += mainDim;
  1583. if (isMainDimDefined) {
  1584. setTrailingPosition(node, child, mainAxis);
  1585. }
  1586. mainDim += getDimWithMargin(child, mainAxis);
  1587. crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));
  1588. }
  1589. if (isSimpleStackCross) {
  1590. child.layout[pos[crossAxis]] += linesCrossDim + leadingPaddingAndBorderCross;
  1591. if (isCrossDimDefined) {
  1592. setTrailingPosition(node, child, crossAxis);
  1593. }
  1594. }
  1595. alreadyComputedNextLayout = 0;
  1596. mainContentDim += nextContentDim;
  1597. endLine = i + 1;
  1598. }
  1599. // <Loop B> Layout flexible children and allocate empty space
  1600. // In order to position the elements in the main axis, we have two
  1601. // controls. The space between the beginning and the first element
  1602. // and the space between each two elements.
  1603. var/*float*/ leadingMainDim = 0;
  1604. var/*float*/ betweenMainDim = 0;
  1605. // The remaining available space that needs to be allocated
  1606. var/*float*/ remainingMainDim = 0;
  1607. if (isMainDimDefined) {
  1608. remainingMainDim = definedMainDim - mainContentDim;
  1609. } else {
  1610. remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim;
  1611. }
  1612. // If there are flexible children in the mix, they are going to fill the
  1613. // remaining space
  1614. if (flexibleChildrenCount !== 0) {
  1615. var/*float*/ flexibleMainDim = remainingMainDim / totalFlexible;
  1616. var/*float*/ baseMainDim;
  1617. var/*float*/ boundMainDim;
  1618. // If the flex share of remaining space doesn't meet min/max bounds,
  1619. // remove this child from flex calculations.
  1620. currentFlexChild = firstFlexChild;
  1621. while (currentFlexChild !== null) {
  1622. baseMainDim = flexibleMainDim * currentFlexChild.style.flex +
  1623. getPaddingAndBorderAxis(currentFlexChild, mainAxis);
  1624. boundMainDim = boundAxis(currentFlexChild, mainAxis, baseMainDim);
  1625. if (baseMainDim !== boundMainDim) {
  1626. remainingMainDim -= boundMainDim;
  1627. totalFlexible -= currentFlexChild.style.flex;
  1628. }
  1629. currentFlexChild = currentFlexChild.nextFlexChild;
  1630. }
  1631. flexibleMainDim = remainingMainDim / totalFlexible;
  1632. // The non flexible children can overflow the container, in this case
  1633. // we should just assume that there is no space available.
  1634. if (flexibleMainDim < 0) {
  1635. flexibleMainDim = 0;
  1636. }
  1637. currentFlexChild = firstFlexChild;
  1638. while (currentFlexChild !== null) {
  1639. // At this point we know the final size of the element in the main
  1640. // dimension
  1641. currentFlexChild.layout[dim[mainAxis]] = boundAxis(currentFlexChild, mainAxis,
  1642. flexibleMainDim * currentFlexChild.style.flex +
  1643. getPaddingAndBorderAxis(currentFlexChild, mainAxis)
  1644. );
  1645. maxWidth = CSS_UNDEFINED;
  1646. if (isDimDefined(node, resolvedRowAxis)) {
  1647. maxWidth = node.layout[dim[resolvedRowAxis]] -
  1648. paddingAndBorderAxisResolvedRow;
  1649. } else if (!isMainRowDirection) {
  1650. maxWidth = parentMaxWidth -
  1651. getMarginAxis(node, resolvedRowAxis) -
  1652. paddingAndBorderAxisResolvedRow;
  1653. }
  1654. // And we recursively call the layout algorithm for this child
  1655. layoutNode(/*(java)!layoutContext, */currentFlexChild, maxWidth, direction);
  1656. child = currentFlexChild;
  1657. currentFlexChild = currentFlexChild.nextFlexChild;
  1658. child.nextFlexChild = null;
  1659. }
  1660. // We use justifyContent to figure out how to allocate the remaining
  1661. // space available
  1662. } else if (justifyContent !== CSS_JUSTIFY_FLEX_START) {
  1663. if (justifyContent === CSS_JUSTIFY_CENTER) {
  1664. leadingMainDim = remainingMainDim / 2;
  1665. } else if (justifyContent === CSS_JUSTIFY_FLEX_END) {
  1666. leadingMainDim = remainingMainDim;
  1667. } else if (justifyContent === CSS_JUSTIFY_SPACE_BETWEEN) {
  1668. remainingMainDim = fmaxf(remainingMainDim, 0);
  1669. if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 !== 0) {
  1670. betweenMainDim = remainingMainDim /
  1671. (flexibleChildrenCount + nonFlexibleChildrenCount - 1);
  1672. } else {
  1673. betweenMainDim = 0;
  1674. }
  1675. } else if (justifyContent === CSS_JUSTIFY_SPACE_AROUND) {
  1676. // Space on the edges is half of the space between elements
  1677. betweenMainDim = remainingMainDim /
  1678. (flexibleChildrenCount + nonFlexibleChildrenCount);
  1679. leadingMainDim = betweenMainDim / 2;
  1680. }
  1681. }
  1682. // <Loop C> Position elements in the main axis and compute dimensions
  1683. // At this point, all the children have their dimensions set. We need to
  1684. // find their position. In order to do that, we accumulate data in
  1685. // variables that are also useful to compute the total dimensions of the
  1686. // container!
  1687. mainDim += leadingMainDim;
  1688. for (i = firstComplexMain; i < endLine; ++i) {
  1689. child = node.children[i];
  1690. if (getPositionType(child) === CSS_POSITION_ABSOLUTE &&
  1691. isPosDefined(child, leading[mainAxis])) {
  1692. // In case the child is position absolute and has left/top being
  1693. // defined, we override the position to whatever the user said
  1694. // (and margin/border).
  1695. child.layout[pos[mainAxis]] = getPosition(child, leading[mainAxis]) +
  1696. getLeadingBorder(node, mainAxis) +
  1697. getLeadingMargin(child, mainAxis);
  1698. } else {
  1699. // If the child is position absolute (without top/left) or relative,
  1700. // we put it at the current accumulated offset.
  1701. child.layout[pos[mainAxis]] += mainDim;
  1702. // Define the trailing position accordingly.
  1703. if (isMainDimDefined) {
  1704. setTrailingPosition(node, child, mainAxis);
  1705. }
  1706. // Now that we placed the element, we need to update the variables
  1707. // We only need to do that for relative elements. Absolute elements
  1708. // do not take part in that phase.
  1709. if (getPositionType(child) === CSS_POSITION_RELATIVE) {
  1710. // The main dimension is the sum of all the elements dimension plus
  1711. // the spacing.
  1712. mainDim += betweenMainDim + getDimWithMargin(child, mainAxis);
  1713. // The cross dimension is the max of the elements dimension since there
  1714. // can only be one element in that cross dimension.
  1715. crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));
  1716. }
  1717. }
  1718. }
  1719. var/*float*/ containerCrossAxis = node.layout[dim[crossAxis]];
  1720. if (!isCrossDimDefined) {
  1721. containerCrossAxis = fmaxf(
  1722. // For the cross dim, we add both sides at the end because the value
  1723. // is aggregate via a max function. Intermediate negative values
  1724. // can mess this computation otherwise
  1725. boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross),
  1726. paddingAndBorderAxisCross
  1727. );
  1728. }
  1729. // <Loop D> Position elements in the cross axis
  1730. for (i = firstComplexCross; i < endLine; ++i) {
  1731. child = node.children[i];
  1732. if (getPositionType(child) === CSS_POSITION_ABSOLUTE &&
  1733. isPosDefined(child, leading[crossAxis])) {
  1734. // In case the child is absolutely positionned and has a
  1735. // top/left/bottom/right being set, we override all the previously
  1736. // computed positions to set it correctly.
  1737. child.layout[pos[crossAxis]] = getPosition(child, leading[crossAxis]) +
  1738. getLeadingBorder(node, crossAxis) +
  1739. getLeadingMargin(child, crossAxis);
  1740. } else {
  1741. var/*float*/ leadingCrossDim = leadingPaddingAndBorderCross;
  1742. // For a relative children, we're either using alignItems (parent) or
  1743. // alignSelf (child) in order to determine the position in the cross axis
  1744. if (getPositionType(child) === CSS_POSITION_RELATIVE) {
  1745. /*eslint-disable */
  1746. // This variable is intentionally re-defined as the code is transpiled to a block scope language
  1747. var/*css_align_t*/ alignItem = getAlignItem(node, child);
  1748. /*eslint-enable */
  1749. if (alignItem === CSS_ALIGN_STRETCH) {
  1750. // You can only stretch if the dimension has not already been set
  1751. // previously.
  1752. if (isUndefined(child.layout[dim[crossAxis]])) {
  1753. child.layout[dim[crossAxis]] = fmaxf(
  1754. boundAxis(child, crossAxis, containerCrossAxis -
  1755. paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),
  1756. // You never want to go smaller than padding
  1757. getPaddingAndBorderAxis(child, crossAxis)
  1758. );
  1759. }
  1760. } else if (alignItem !== CSS_ALIGN_FLEX_START) {
  1761. // The remaining space between the parent dimensions+padding and child
  1762. // dimensions+margin.
  1763. var/*float*/ remainingCrossDim = containerCrossAxis -
  1764. paddingAndBorderAxisCross - getDimWithMargin(child, crossAxis);
  1765. if (alignItem === CSS_ALIGN_CENTER) {
  1766. leadingCrossDim += remainingCrossDim / 2;
  1767. } else { // CSS_ALIGN_FLEX_END
  1768. leadingCrossDim += remainingCrossDim;
  1769. }
  1770. }
  1771. }
  1772. // And we apply the position
  1773. child.layout[pos[crossAxis]] += linesCrossDim + leadingCrossDim;
  1774. // Define the trailing position accordingly.
  1775. if (isCrossDimDefined) {
  1776. setTrailingPosition(node, child, crossAxis);
  1777. }
  1778. }
  1779. }
  1780. linesCrossDim += crossDim;
  1781. linesMainDim = fmaxf(linesMainDim, mainDim);
  1782. linesCount += 1;
  1783. startLine = endLine;
  1784. }
  1785. // <Loop E>
  1786. //
  1787. // Note(prenaux): More than one line, we need to layout the crossAxis
  1788. // according to alignContent.
  1789. //
  1790. // Note that we could probably remove <Loop D> and handle the one line case
  1791. // here too, but for the moment this is safer since it won't interfere with
  1792. // previously working code.
  1793. //
  1794. // See specs:
  1795. // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm
  1796. // section 9.4
  1797. //
  1798. if (linesCount > 1 && isCrossDimDefined) {
  1799. var/*float*/ nodeCrossAxisInnerSize = node.layout[dim[crossAxis]] -
  1800. paddingAndBorderAxisCross;
  1801. var/*float*/ remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim;
  1802. var/*float*/ crossDimLead = 0;
  1803. var/*float*/ currentLead = leadingPaddingAndBorderCross;
  1804. var/*css_align_t*/ alignContent = getAlignContent(node);
  1805. if (alignContent === CSS_ALIGN_FLEX_END) {
  1806. currentLead += remainingAlignContentDim;
  1807. } else if (alignContent === CSS_ALIGN_CENTER) {
  1808. currentLead += remainingAlignContentDim / 2;
  1809. } else if (alignContent === CSS_ALIGN_STRETCH) {
  1810. if (nodeCrossAxisInnerSize > linesCrossDim) {
  1811. crossDimLead = (remainingAlignContentDim / linesCount);
  1812. }
  1813. }
  1814. var/*int*/ endIndex = 0;
  1815. for (i = 0; i < linesCount; ++i) {
  1816. var/*int*/ startIndex = endIndex;
  1817. // compute the line's height and find the endIndex
  1818. var/*float*/ lineHeight = 0;
  1819. for (ii = startIndex; ii < childCount; ++ii) {
  1820. child = node.children[ii];
  1821. if (getPositionType(child) !== CSS_POSITION_RELATIVE) {
  1822. continue;
  1823. }
  1824. if (child.lineIndex !== i) {
  1825. break;
  1826. }
  1827. if (!isUndefined(child.layout[dim[crossAxis]])) {
  1828. lineHeight = fmaxf(
  1829. lineHeight,
  1830. child.layout[dim[crossAxis]] + getMarginAxis(child, crossAxis)
  1831. );
  1832. }
  1833. }
  1834. endIndex = ii;
  1835. lineHeight += crossDimLead;
  1836. for (ii = startIndex; ii < endIndex; ++ii) {
  1837. child = node.children[ii];
  1838. if (getPositionType(child) !== CSS_POSITION_RELATIVE) {
  1839. continue;
  1840. }
  1841. var/*css_align_t*/ alignContentAlignItem = getAlignItem(node, child);
  1842. if (alignContentAlignItem === CSS_ALIGN_FLEX_START) {
  1843. child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);
  1844. } else if (alignContentAlignItem === CSS_ALIGN_FLEX_END) {
  1845. child.layout[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child.layout[dim[crossAxis]];
  1846. } else if (alignContentAlignItem === CSS_ALIGN_CENTER) {
  1847. var/*float*/ childHeight = child.layout[dim[crossAxis]];
  1848. child.layout[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2;
  1849. } else if (alignContentAlignItem === CSS_ALIGN_STRETCH) {
  1850. child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);
  1851. // TODO(prenaux): Correctly set the height of items with undefined
  1852. // (auto) crossAxis dimension.
  1853. }
  1854. }
  1855. currentLead += lineHeight;
  1856. }
  1857. }
  1858. var/*bool*/ needsMainTrailingPos = false;
  1859. var/*bool*/ needsCrossTrailingPos = false;
  1860. // If the user didn't specify a width or height, and it has not been set
  1861. // by the container, then we set it via the children.
  1862. if (!isMainDimDefined) {
  1863. node.layout[dim[mainAxis]] = fmaxf(
  1864. // We're missing the last padding at this point to get the final
  1865. // dimension
  1866. boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)),
  1867. // We can never assign a width smaller than the padding and borders
  1868. paddingAndBorderAxisMain
  1869. );
  1870. if (mainAxis === CSS_FLEX_DIRECTION_ROW_REVERSE ||
  1871. mainAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
  1872. needsMainTrailingPos = true;
  1873. }
  1874. }
  1875. if (!isCrossDimDefined) {
  1876. node.layout[dim[crossAxis]] = fmaxf(
  1877. // For the cross dim, we add both sides at the end because the value
  1878. // is aggregate via a max function. Intermediate negative values
  1879. // can mess this computation otherwise
  1880. boundAxis(node, crossAxis, linesCrossDim + paddingAndBorderAxisCross),
  1881. paddingAndBorderAxisCross
  1882. );
  1883. if (crossAxis === CSS_FLEX_DIRECTION_ROW_REVERSE ||
  1884. crossAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
  1885. needsCrossTrailingPos = true;
  1886. }
  1887. }
  1888. // <Loop F> Set trailing position if necessary
  1889. if (needsMainTrailingPos || needsCrossTrailingPos) {
  1890. for (i = 0; i < childCount; ++i) {
  1891. child = node.children[i];
  1892. if (needsMainTrailingPos) {
  1893. setTrailingPosition(node, child, mainAxis);
  1894. }
  1895. if (needsCrossTrailingPos) {
  1896. setTrailingPosition(node, child, crossAxis);
  1897. }
  1898. }
  1899. }
  1900. // <Loop G> Calculate dimensions for absolutely positioned elements
  1901. currentAbsoluteChild = firstAbsoluteChild;
  1902. while (currentAbsoluteChild !== null) {
  1903. // Pre-fill dimensions when using absolute position and both offsets for
  1904. // the axis are defined (either both left and right or top and bottom).
  1905. for (ii = 0; ii < 2; ii++) {
  1906. axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
  1907. if (!isUndefined(node.layout[dim[axis]]) &&
  1908. !isDimDefined(currentAbsoluteChild, axis) &&
  1909. isPosDefined(currentAbsoluteChild, leading[axis]) &&
  1910. isPosDefined(currentAbsoluteChild, trailing[axis])) {
  1911. currentAbsoluteChild.layout[dim[axis]] = fmaxf(
  1912. boundAxis(currentAbsoluteChild, axis, node.layout[dim[axis]] -
  1913. getBorderAxis(node, axis) -
  1914. getMarginAxis(currentAbsoluteChild, axis) -
  1915. getPosition(currentAbsoluteChild, leading[axis]) -
  1916. getPosition(currentAbsoluteChild, trailing[axis])
  1917. ),
  1918. // You never want to go smaller than padding
  1919. getPaddingAndBorderAxis(currentAbsoluteChild, axis)
  1920. );
  1921. }
  1922. if (isPosDefined(currentAbsoluteChild, trailing[axis]) &&
  1923. !isPosDefined(currentAbsoluteChild, leading[axis])) {
  1924. currentAbsoluteChild.layout[leading[axis]] =
  1925. node.layout[dim[axis]] -
  1926. currentAbsoluteChild.layout[dim[axis]] -
  1927. getPosition(currentAbsoluteChild, trailing[axis]);
  1928. }
  1929. }
  1930. child = currentAbsoluteChild;
  1931. currentAbsoluteChild = currentAbsoluteChild.nextAbsoluteChild;
  1932. child.nextAbsoluteChild = null;
  1933. }
  1934. }
  1935. function layoutNode(node, parentMaxWidth, parentDirection) {
  1936. node.shouldUpdate = true;
  1937. var direction = node.style.direction || CSS_DIRECTION_LTR;
  1938. var skipLayout =
  1939. !node.isDirty &&
  1940. node.lastLayout &&
  1941. node.lastLayout.requestedHeight === node.layout.height &&
  1942. node.lastLayout.requestedWidth === node.layout.width &&
  1943. node.lastLayout.parentMaxWidth === parentMaxWidth &&
  1944. node.lastLayout.direction === direction;
  1945. if (skipLayout) {
  1946. node.layout.width = node.lastLayout.width;
  1947. node.layout.height = node.lastLayout.height;
  1948. node.layout.top = node.lastLayout.top;
  1949. node.layout.left = node.lastLayout.left;
  1950. } else {
  1951. if (!node.lastLayout) {
  1952. node.lastLayout = {};
  1953. }
  1954. node.lastLayout.requestedWidth = node.layout.width;
  1955. node.lastLayout.requestedHeight = node.layout.height;
  1956. node.lastLayout.parentMaxWidth = parentMaxWidth;
  1957. node.lastLayout.direction = direction;
  1958. // Reset child layouts
  1959. node.children.forEach(function(child) {
  1960. child.layout.width = undefined;
  1961. child.layout.height = undefined;
  1962. child.layout.top = 0;
  1963. child.layout.left = 0;
  1964. });
  1965. layoutNodeImpl(node, parentMaxWidth, parentDirection);
  1966. node.lastLayout.width = node.layout.width;
  1967. node.lastLayout.height = node.layout.height;
  1968. node.lastLayout.top = node.layout.top;
  1969. node.lastLayout.left = node.layout.left;
  1970. }
  1971. }
  1972. return {
  1973. layoutNodeImpl: layoutNodeImpl,
  1974. computeLayout: layoutNode,
  1975. fillNodes: fillNodes
  1976. };
  1977. })();
  1978. // This module export is only used for the purposes of unit testing this file. When
  1979. // the library is packaged this file is included within css-layout.js which forms
  1980. // the public API.
  1981. if (true) {
  1982. module.exports = computeLayout;
  1983. }
  1984. return function(node) {
  1985. /*eslint-disable */
  1986. // disabling ESLint because this code relies on the above include
  1987. computeLayout.fillNodes(node);
  1988. computeLayout.computeLayout(node);
  1989. /*eslint-enable */
  1990. };
  1991. }));
  1992. /***/ }),
  1993. /* 7 */
  1994. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1995. "use strict";
  1996. __webpack_require__.r(__webpack_exports__);
  1997. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "throttle", function() { return throttle; });
  1998. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "none", function() { return none; });
  1999. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isClick", function() { return isClick; });
  2000. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createCanvas", function() { return createCanvas; });
  2001. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createImage", function() { return createImage; });
  2002. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDpr", function() { return getDpr; });
  2003. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "STATE", function() { return STATE; });
  2004. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "repaintChildren", function() { return repaintChildren; });
  2005. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "repaintTree", function() { return repaintTree; });
  2006. function throttle(fn, threshhold, scope) {
  2007. threshhold || (threshhold = 250);
  2008. var last, deferTimer;
  2009. return function () {
  2010. var context = scope || this;
  2011. var now = +new Date(),
  2012. args = arguments;
  2013. if (last && now < last + threshhold) {
  2014. // hold on to it
  2015. clearTimeout(deferTimer);
  2016. deferTimer = setTimeout(function () {
  2017. last = now;
  2018. fn.apply(context, args);
  2019. }, threshhold);
  2020. } else {
  2021. last = now;
  2022. fn.apply(context, args);
  2023. }
  2024. };
  2025. }
  2026. /* istanbul ignore next */
  2027. function none() {}
  2028. /**
  2029. * 根据触摸时长和触摸位置变化来判断是否属于点击事件
  2030. */
  2031. function isClick(touchMsg) {
  2032. var start = touchMsg.touchstart;
  2033. var end = touchMsg.touchend;
  2034. if (!start || !end || !start.timeStamp || !end.timeStamp || start.pageX === undefined || start.pageY === undefined || end.pageX === undefined || end.pageY === undefined) {
  2035. return false;
  2036. }
  2037. var startPosX = start.pageX;
  2038. var startPosY = start.pageY;
  2039. var endPosX = end.pageX;
  2040. var endPosY = end.pageY;
  2041. var touchTimes = end.timeStamp - start.timeStamp;
  2042. return !!(Math.abs(endPosY - startPosY) < 30 && Math.abs(endPosX - startPosX) < 30 && touchTimes < 300);
  2043. }
  2044. function createCanvas() {
  2045. /* istanbul ignore if*/
  2046. if (typeof __env !== "undefined") {
  2047. return __env.createCanvas();
  2048. } else {
  2049. return document.createElement('canvas');
  2050. }
  2051. }
  2052. function createImage() {
  2053. /* istanbul ignore if*/
  2054. if (typeof __env !== "undefined") {
  2055. return __env.createImage();
  2056. } else {
  2057. return document.createElement('img');
  2058. }
  2059. }
  2060. var _dpr; // only Baidu platform need to recieve system info from main context
  2061. if (typeof swan !== 'undefined') {
  2062. __env.onMessage(function (res) {
  2063. if (res && res.type === 'engine') {
  2064. if (res.event === 'systemInfo') {
  2065. _dpr = res.systemInfo.devicePixelRatio;
  2066. }
  2067. }
  2068. });
  2069. }
  2070. function getDpr() {
  2071. if (typeof _dpr !== 'undefined') {
  2072. return _dpr;
  2073. }
  2074. if (typeof __env !== "undefined" && __env.getSystemInfoSync) {
  2075. _dpr = __env.getSystemInfoSync().devicePixelRatio;
  2076. } else {
  2077. console.warn('failed to access device pixel ratio, fallback to 1');
  2078. _dpr = 1;
  2079. }
  2080. return _dpr;
  2081. }
  2082. var STATE = {
  2083. "UNINIT": "UNINIT",
  2084. "INITED": "INITED",
  2085. "RENDERED": "RENDERED",
  2086. "CLEAR": "CLEAR"
  2087. };
  2088. var repaintChildren = function repaintChildren(children) {
  2089. children.forEach(function (child) {
  2090. child.repaint();
  2091. repaintChildren(child.children);
  2092. });
  2093. };
  2094. var repaintTree = function repaintTree(tree) {
  2095. tree.repaint();
  2096. tree.children.forEach(function (child) {
  2097. child.repaint();
  2098. repaintTree(child);
  2099. });
  2100. };
  2101. /***/ }),
  2102. /* 8 */
  2103. /***/ (function(module, exports, __webpack_require__) {
  2104. "use strict";
  2105. var nodeToJson = __webpack_require__(9);
  2106. var xmlToNodeobj = __webpack_require__(11);
  2107. var x2xmlnode = __webpack_require__(11);
  2108. var buildOptions = __webpack_require__(10).buildOptions;
  2109. var validator = __webpack_require__(13);
  2110. exports.parse = function (xmlData, options, validationOption) {
  2111. if (validationOption) {
  2112. if (validationOption === true) validationOption = {};
  2113. var result = validator.validate(xmlData, validationOption);
  2114. if (result !== true) {
  2115. throw Error(result.err.msg);
  2116. }
  2117. }
  2118. options = buildOptions(options, x2xmlnode.defaultOptions, x2xmlnode.props);
  2119. return nodeToJson.convertToJson(xmlToNodeobj.getTraversalObj(xmlData, options), options);
  2120. };
  2121. /***/ }),
  2122. /* 9 */
  2123. /***/ (function(module, exports, __webpack_require__) {
  2124. "use strict";
  2125. var util = __webpack_require__(10);
  2126. var convertToJson = function convertToJson(node, options) {
  2127. var jObj = {
  2128. name: node.tagname
  2129. }; //when no child node or attr is present
  2130. if ((!node.child || util.isEmptyObject(node.child)) && (!node.attrsMap || util.isEmptyObject(node.attrsMap))) {
  2131. return util.isExist(node.val) && !!node.val ? node.val : jObj;
  2132. } else {
  2133. //otherwise create a textnode if node has some text
  2134. if (util.isExist(node.val)) {
  2135. if (!(typeof node.val === 'string' && (node.val === '' || node.val === options.cdataPositionChar))) {
  2136. if (options.arrayMode === "strict") {
  2137. jObj[options.textNodeName] = [node.val];
  2138. } else {
  2139. jObj[options.textNodeName] = node.val;
  2140. }
  2141. }
  2142. }
  2143. }
  2144. util.merge(jObj, node.attrsMap, options.arrayMode);
  2145. jObj.children = [];
  2146. node.children.forEach(function (child) {
  2147. jObj.children.push(convertToJson(child, options));
  2148. }); // const keys = Object.keys(node.child);
  2149. // for (let index = 0; index < keys.length; index++) {
  2150. // var tagname = keys[index];
  2151. // if (node.child[tagname] && node.child[tagname].length > 1) {
  2152. // jObj[tagname] = [];
  2153. // for (var tag in node.child[tagname]) {
  2154. // jObj[tagname].push(convertToJson(node.child[tagname][tag], options));
  2155. // }
  2156. // } else {
  2157. // if(options.arrayMode === true){
  2158. // const result = convertToJson(node.child[tagname][0], options)
  2159. // if(typeof result === 'object')
  2160. // jObj[tagname] = [ result ];
  2161. // else
  2162. // jObj[tagname] = result;
  2163. // }else if(options.arrayMode === "strict"){
  2164. // jObj[tagname] = [convertToJson(node.child[tagname][0], options) ];
  2165. // }else{
  2166. // jObj[tagname] = convertToJson(node.child[tagname][0], options);
  2167. // }
  2168. // }
  2169. // }
  2170. //add value
  2171. return jObj;
  2172. };
  2173. exports.convertToJson = convertToJson;
  2174. /***/ }),
  2175. /* 10 */
  2176. /***/ (function(module, exports, __webpack_require__) {
  2177. "use strict";
  2178. var getAllMatches = function getAllMatches(string, regex) {
  2179. var matches = [];
  2180. var match = regex.exec(string);
  2181. while (match) {
  2182. var allmatches = [];
  2183. var len = match.length;
  2184. for (var index = 0; index < len; index++) {
  2185. allmatches.push(match[index]);
  2186. }
  2187. matches.push(allmatches);
  2188. match = regex.exec(string);
  2189. }
  2190. return matches;
  2191. };
  2192. var doesMatch = function doesMatch(string, regex) {
  2193. var match = regex.exec(string);
  2194. return !(match === null || typeof match === 'undefined');
  2195. };
  2196. var doesNotMatch = function doesNotMatch(string, regex) {
  2197. return !doesMatch(string, regex);
  2198. };
  2199. exports.isExist = function (v) {
  2200. return typeof v !== 'undefined';
  2201. };
  2202. exports.isEmptyObject = function (obj) {
  2203. return Object.keys(obj).length === 0;
  2204. };
  2205. /**
  2206. * Copy all the properties of a into b.
  2207. * @param {*} target
  2208. * @param {*} a
  2209. */
  2210. exports.merge = function (target, a, arrayMode) {
  2211. if (a) {
  2212. var keys = Object.keys(a); // will return an array of own properties
  2213. var len = keys.length; //don't make it inline
  2214. for (var i = 0; i < len; i++) {
  2215. if (arrayMode === 'strict') {
  2216. target[keys[i]] = [a[keys[i]]];
  2217. } else {
  2218. target[keys[i]] = a[keys[i]];
  2219. }
  2220. }
  2221. }
  2222. };
  2223. /* exports.merge =function (b,a){
  2224. return Object.assign(b,a);
  2225. } */
  2226. exports.getValue = function (v) {
  2227. if (exports.isExist(v)) {
  2228. return v;
  2229. } else {
  2230. return '';
  2231. }
  2232. }; // const fakeCall = function(a) {return a;};
  2233. // const fakeCallNoReturn = function() {};
  2234. exports.buildOptions = function (options, defaultOptions, props) {
  2235. var newOptions = {};
  2236. if (!options) {
  2237. return defaultOptions; //if there are not options
  2238. }
  2239. for (var i = 0; i < props.length; i++) {
  2240. if (options[props[i]] !== undefined) {
  2241. newOptions[props[i]] = options[props[i]];
  2242. } else {
  2243. newOptions[props[i]] = defaultOptions[props[i]];
  2244. }
  2245. }
  2246. return newOptions;
  2247. };
  2248. exports.doesMatch = doesMatch;
  2249. exports.doesNotMatch = doesNotMatch;
  2250. exports.getAllMatches = getAllMatches;
  2251. /***/ }),
  2252. /* 11 */
  2253. /***/ (function(module, exports, __webpack_require__) {
  2254. "use strict";
  2255. var util = __webpack_require__(10);
  2256. var buildOptions = __webpack_require__(10).buildOptions;
  2257. var xmlNode = __webpack_require__(12);
  2258. var TagType = {
  2259. OPENING: 1,
  2260. CLOSING: 2,
  2261. SELF: 3,
  2262. CDATA: 4
  2263. };
  2264. var regx = '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|(([\\w:\\-._]*:)?([\\w:\\-._]+))([^>]*)>|((\\/)(([\\w:\\-._]*:)?([\\w:\\-._]+))\\s*>))([^<]*)'; //const tagsRegx = new RegExp("<(\\/?[\\w:\\-\._]+)([^>]*)>(\\s*"+cdataRegx+")*([^<]+)?","g");
  2265. //const tagsRegx = new RegExp("<(\\/?)((\\w*:)?([\\w:\\-\._]+))([^>]*)>([^<]*)("+cdataRegx+"([^<]*))*([^<]+)?","g");
  2266. //polyfill
  2267. if (!Number.parseInt && window.parseInt) {
  2268. Number.parseInt = window.parseInt;
  2269. }
  2270. if (!Number.parseFloat && window.parseFloat) {
  2271. Number.parseFloat = window.parseFloat;
  2272. }
  2273. var defaultOptions = {
  2274. attributeNamePrefix: '@_',
  2275. attrNodeName: false,
  2276. textNodeName: '#text',
  2277. ignoreAttributes: true,
  2278. ignoreNameSpace: false,
  2279. allowBooleanAttributes: false,
  2280. //a tag can have attributes without any value
  2281. //ignoreRootElement : false,
  2282. parseNodeValue: true,
  2283. parseAttributeValue: false,
  2284. arrayMode: false,
  2285. trimValues: true,
  2286. //Trim string values of tag and attributes
  2287. cdataTagName: false,
  2288. cdataPositionChar: '\\c',
  2289. localeRange: '',
  2290. tagValueProcessor: function tagValueProcessor(a) {
  2291. return a;
  2292. },
  2293. attrValueProcessor: function attrValueProcessor(a) {
  2294. return a;
  2295. },
  2296. stopNodes: [] //decodeStrict: false,
  2297. };
  2298. exports.defaultOptions = defaultOptions;
  2299. var props = ['attributeNamePrefix', 'attrNodeName', 'textNodeName', 'ignoreAttributes', 'ignoreNameSpace', 'allowBooleanAttributes', 'parseNodeValue', 'parseAttributeValue', 'arrayMode', 'trimValues', 'cdataTagName', 'cdataPositionChar', 'localeRange', 'tagValueProcessor', 'attrValueProcessor', 'parseTrueNumberOnly', 'stopNodes'];
  2300. exports.props = props;
  2301. var getTraversalObj = function getTraversalObj(xmlData, options) {
  2302. options = buildOptions(options, defaultOptions, props); //xmlData = xmlData.replace(/\r?\n/g, " ");//make it single line
  2303. xmlData = xmlData.replace(/<!--[\s\S]*?-->/g, ''); //Remove comments
  2304. var xmlObj = new xmlNode('!xml');
  2305. var currentNode = xmlObj;
  2306. regx = regx.replace(/\[\\w/g, '[' + options.localeRange + '\\w');
  2307. var tagsRegx = new RegExp(regx, 'g');
  2308. var tag = tagsRegx.exec(xmlData);
  2309. var nextTag = tagsRegx.exec(xmlData);
  2310. while (tag) {
  2311. var tagType = checkForTagType(tag);
  2312. if (tagType === TagType.CLOSING) {
  2313. //add parsed data to parent node
  2314. if (currentNode.parent && tag[14]) {
  2315. currentNode.parent.val = util.getValue(currentNode.parent.val) + '' + processTagValue(tag, options, currentNode.parent.tagname);
  2316. }
  2317. if (options.stopNodes.length && options.stopNodes.includes(currentNode.tagname)) {
  2318. currentNode.child = [];
  2319. if (currentNode.attrsMap == undefined) {
  2320. currentNode.attrsMap = {};
  2321. }
  2322. currentNode.val = xmlData.substr(currentNode.startIndex + 1, tag.index - currentNode.startIndex - 1);
  2323. }
  2324. currentNode = currentNode.parent;
  2325. } else if (tagType === TagType.CDATA) {
  2326. if (options.cdataTagName) {
  2327. //add cdata node
  2328. var childNode = new xmlNode(options.cdataTagName, currentNode, tag[3]);
  2329. childNode.attrsMap = buildAttributesMap(tag[8], options);
  2330. currentNode.addChild(childNode); //for backtracking
  2331. currentNode.val = util.getValue(currentNode.val) + options.cdataPositionChar; //add rest value to parent node
  2332. if (tag[14]) {
  2333. currentNode.val += processTagValue(tag, options);
  2334. }
  2335. } else {
  2336. currentNode.val = (currentNode.val || '') + (tag[3] || '') + processTagValue(tag, options);
  2337. }
  2338. } else if (tagType === TagType.SELF) {
  2339. if (currentNode && tag[14]) {
  2340. currentNode.val = util.getValue(currentNode.val) + '' + processTagValue(tag, options);
  2341. }
  2342. var _childNode = new xmlNode(options.ignoreNameSpace ? tag[7] : tag[5], currentNode, '');
  2343. if (tag[8] && tag[8].length > 0) {
  2344. tag[8] = tag[8].substr(0, tag[8].length - 1);
  2345. }
  2346. _childNode.attrsMap = buildAttributesMap(tag[8], options);
  2347. currentNode.addChild(_childNode);
  2348. } else {
  2349. //TagType.OPENING
  2350. var _childNode2 = new xmlNode(options.ignoreNameSpace ? tag[7] : tag[5], currentNode, processTagValue(tag, options));
  2351. if (options.stopNodes.length && options.stopNodes.includes(_childNode2.tagname)) {
  2352. _childNode2.startIndex = tag.index + tag[1].length;
  2353. }
  2354. _childNode2.attrsMap = buildAttributesMap(tag[8], options);
  2355. currentNode.addChild(_childNode2);
  2356. currentNode = _childNode2;
  2357. }
  2358. tag = nextTag;
  2359. nextTag = tagsRegx.exec(xmlData);
  2360. }
  2361. return xmlObj;
  2362. };
  2363. function processTagValue(parsedTags, options, parentTagName) {
  2364. var tagName = parsedTags[7] || parentTagName;
  2365. var val = parsedTags[14];
  2366. if (val) {
  2367. if (options.trimValues) {
  2368. val = val.trim();
  2369. }
  2370. val = options.tagValueProcessor(val, tagName);
  2371. val = parseValue(val, options.parseNodeValue, options.parseTrueNumberOnly);
  2372. }
  2373. return val;
  2374. }
  2375. function checkForTagType(match) {
  2376. if (match[4] === ']]>') {
  2377. return TagType.CDATA;
  2378. } else if (match[10] === '/') {
  2379. return TagType.CLOSING;
  2380. } else if (typeof match[8] !== 'undefined' && match[8].substr(match[8].length - 1) === '/') {
  2381. return TagType.SELF;
  2382. } else {
  2383. return TagType.OPENING;
  2384. }
  2385. }
  2386. function resolveNameSpace(tagname, options) {
  2387. if (options.ignoreNameSpace) {
  2388. var tags = tagname.split(':');
  2389. var prefix = tagname.charAt(0) === '/' ? '/' : '';
  2390. if (tags[0] === 'xmlns') {
  2391. return '';
  2392. }
  2393. if (tags.length === 2) {
  2394. tagname = prefix + tags[1];
  2395. }
  2396. }
  2397. return tagname;
  2398. }
  2399. function parseValue(val, shouldParse, parseTrueNumberOnly) {
  2400. if (shouldParse && typeof val === 'string') {
  2401. var parsed;
  2402. if (val.trim() === '' || isNaN(val)) {
  2403. parsed = val === 'true' ? true : val === 'false' ? false : val;
  2404. } else {
  2405. if (val.indexOf('0x') !== -1) {
  2406. //support hexa decimal
  2407. parsed = Number.parseInt(val, 16);
  2408. } else if (val.indexOf('.') !== -1) {
  2409. parsed = Number.parseFloat(val);
  2410. } else {
  2411. parsed = Number.parseInt(val, 10);
  2412. }
  2413. if (parseTrueNumberOnly) {
  2414. parsed = String(parsed) === val ? parsed : val;
  2415. }
  2416. }
  2417. return parsed;
  2418. } else {
  2419. if (util.isExist(val)) {
  2420. return val;
  2421. } else {
  2422. return '';
  2423. }
  2424. }
  2425. } //TODO: change regex to capture NS
  2426. //const attrsRegx = new RegExp("([\\w\\-\\.\\:]+)\\s*=\\s*(['\"])((.|\n)*?)\\2","gm");
  2427. var attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])(.*?)\\3)?', 'g');
  2428. function buildAttributesMap(attrStr, options) {
  2429. if (!options.ignoreAttributes && typeof attrStr === 'string') {
  2430. attrStr = attrStr.replace(/\r?\n/g, ' '); //attrStr = attrStr || attrStr.trim();
  2431. var matches = util.getAllMatches(attrStr, attrsRegx);
  2432. var len = matches.length; //don't make it inline
  2433. var attrs = {};
  2434. for (var i = 0; i < len; i++) {
  2435. var attrName = resolveNameSpace(matches[i][1], options);
  2436. if (attrName.length) {
  2437. if (matches[i][4] !== undefined) {
  2438. if (options.trimValues) {
  2439. matches[i][4] = matches[i][4].trim();
  2440. }
  2441. matches[i][4] = options.attrValueProcessor(matches[i][4], attrName);
  2442. attrs[options.attributeNamePrefix + attrName] = parseValue(matches[i][4], options.parseAttributeValue, options.parseTrueNumberOnly);
  2443. } else if (options.allowBooleanAttributes) {
  2444. attrs[options.attributeNamePrefix + attrName] = true;
  2445. }
  2446. }
  2447. }
  2448. if (!Object.keys(attrs).length) {
  2449. return;
  2450. }
  2451. if (options.attrNodeName) {
  2452. var attrCollection = {};
  2453. attrCollection[options.attrNodeName] = attrs;
  2454. return attrCollection;
  2455. }
  2456. return attrs;
  2457. }
  2458. }
  2459. exports.getTraversalObj = getTraversalObj;
  2460. /***/ }),
  2461. /* 12 */
  2462. /***/ (function(module, exports, __webpack_require__) {
  2463. "use strict";
  2464. module.exports = function (tagname, parent, val) {
  2465. this.tagname = tagname;
  2466. this.parent = parent;
  2467. this.child = {}; //child tags
  2468. this.attrsMap = {}; //attributes map
  2469. this.children = [];
  2470. this.val = val; //text only
  2471. this.addChild = function (child) {
  2472. this.children.push(child);
  2473. if (Array.isArray(this.child[child.tagname])) {
  2474. //already presents
  2475. this.child[child.tagname].push(child);
  2476. } else {
  2477. this.child[child.tagname] = [child];
  2478. }
  2479. };
  2480. };
  2481. /***/ }),
  2482. /* 13 */
  2483. /***/ (function(module, exports, __webpack_require__) {
  2484. "use strict";
  2485. var util = __webpack_require__(10);
  2486. var defaultOptions = {
  2487. allowBooleanAttributes: false,
  2488. //A tag can have attributes without any value
  2489. localeRange: 'a-zA-Z'
  2490. };
  2491. var props = ['allowBooleanAttributes', 'localeRange']; //const tagsPattern = new RegExp("<\\/?([\\w:\\-_\.]+)\\s*\/?>","g");
  2492. exports.validate = function (xmlData, options) {
  2493. options = util.buildOptions(options, defaultOptions, props); //xmlData = xmlData.replace(/(\r\n|\n|\r)/gm,"");//make it single line
  2494. //xmlData = xmlData.replace(/(^\s*<\?xml.*?\?>)/g,"");//Remove XML starting tag
  2495. //xmlData = xmlData.replace(/(<!DOCTYPE[\s\w\"\.\/\-\:]+(\[.*\])*\s*>)/g,"");//Remove DOCTYPE
  2496. var tags = [];
  2497. var tagFound = false;
  2498. if (xmlData[0] === "\uFEFF") {
  2499. // check for byte order mark (BOM)
  2500. xmlData = xmlData.substr(1);
  2501. }
  2502. var regxAttrName = new RegExp('^[_w][\\w\\-.:]*$'.replace('_w', '_' + options.localeRange));
  2503. var regxTagName = new RegExp('^([w]|_)[\\w.\\-_:]*'.replace('([w', '([' + options.localeRange));
  2504. for (var i = 0; i < xmlData.length; i++) {
  2505. if (xmlData[i] === '<') {
  2506. //starting of tag
  2507. //read until you reach to '>' avoiding any '>' in attribute value
  2508. i++;
  2509. if (xmlData[i] === '?') {
  2510. i = readPI(xmlData, ++i);
  2511. if (i.err) {
  2512. return i;
  2513. }
  2514. } else if (xmlData[i] === '!') {
  2515. i = readCommentAndCDATA(xmlData, i);
  2516. continue;
  2517. } else {
  2518. var closingTag = false;
  2519. if (xmlData[i] === '/') {
  2520. //closing tag
  2521. closingTag = true;
  2522. i++;
  2523. } //read tagname
  2524. var tagName = '';
  2525. for (; i < xmlData.length && xmlData[i] !== '>' && xmlData[i] !== ' ' && xmlData[i] !== '\t' && xmlData[i] !== '\n' && xmlData[i] !== '\r'; i++) {
  2526. tagName += xmlData[i];
  2527. }
  2528. tagName = tagName.trim(); //console.log(tagName);
  2529. if (tagName[tagName.length - 1] === '/') {
  2530. //self closing tag without attributes
  2531. tagName = tagName.substring(0, tagName.length - 1);
  2532. continue;
  2533. }
  2534. if (!validateTagName(tagName, regxTagName)) {
  2535. return {
  2536. err: {
  2537. code: 'InvalidTag',
  2538. msg: 'Tag ' + tagName + ' is an invalid name.'
  2539. }
  2540. };
  2541. }
  2542. var result = readAttributeStr(xmlData, i);
  2543. if (result === false) {
  2544. return {
  2545. err: {
  2546. code: 'InvalidAttr',
  2547. msg: 'Attributes for "' + tagName + '" have open quote.'
  2548. }
  2549. };
  2550. }
  2551. var attrStr = result.value;
  2552. i = result.index;
  2553. if (attrStr[attrStr.length - 1] === '/') {
  2554. //self closing tag
  2555. attrStr = attrStr.substring(0, attrStr.length - 1);
  2556. var isValid = validateAttributeString(attrStr, options, regxAttrName);
  2557. if (isValid === true) {
  2558. tagFound = true; //continue; //text may presents after self closing tag
  2559. } else {
  2560. return isValid;
  2561. }
  2562. } else if (closingTag) {
  2563. if (!result.tagClosed) {
  2564. return {
  2565. err: {
  2566. code: 'InvalidTag',
  2567. msg: 'closing tag "' + tagName + "\" don't have proper closing."
  2568. }
  2569. };
  2570. } else if (attrStr.trim().length > 0) {
  2571. return {
  2572. err: {
  2573. code: 'InvalidTag',
  2574. msg: 'closing tag "' + tagName + "\" can't have attributes or invalid starting."
  2575. }
  2576. };
  2577. } else {
  2578. var otg = tags.pop();
  2579. if (tagName !== otg) {
  2580. return {
  2581. err: {
  2582. code: 'InvalidTag',
  2583. msg: 'closing tag ' + otg + ' is expected inplace of ' + tagName + '.'
  2584. }
  2585. };
  2586. }
  2587. }
  2588. } else {
  2589. var _isValid = validateAttributeString(attrStr, options, regxAttrName);
  2590. if (_isValid !== true) {
  2591. return _isValid;
  2592. }
  2593. tags.push(tagName);
  2594. tagFound = true;
  2595. } //skip tag text value
  2596. //It may include comments and CDATA value
  2597. for (i++; i < xmlData.length; i++) {
  2598. if (xmlData[i] === '<') {
  2599. if (xmlData[i + 1] === '!') {
  2600. //comment or CADATA
  2601. i++;
  2602. i = readCommentAndCDATA(xmlData, i);
  2603. continue;
  2604. } else {
  2605. break;
  2606. }
  2607. }
  2608. } //end of reading tag text value
  2609. if (xmlData[i] === '<') {
  2610. i--;
  2611. }
  2612. }
  2613. } else {
  2614. if (xmlData[i] === ' ' || xmlData[i] === '\t' || xmlData[i] === '\n' || xmlData[i] === '\r') {
  2615. continue;
  2616. }
  2617. return {
  2618. err: {
  2619. code: 'InvalidChar',
  2620. msg: 'char ' + xmlData[i] + ' is not expected .'
  2621. }
  2622. };
  2623. }
  2624. }
  2625. if (!tagFound) {
  2626. return {
  2627. err: {
  2628. code: 'InvalidXml',
  2629. msg: 'Start tag expected.'
  2630. }
  2631. };
  2632. } else if (tags.length > 0) {
  2633. return {
  2634. err: {
  2635. code: 'InvalidXml',
  2636. msg: 'Invalid ' + JSON.stringify(tags, null, 4).replace(/\r?\n/g, '') + ' found.'
  2637. }
  2638. };
  2639. }
  2640. return true;
  2641. };
  2642. /**
  2643. * Read Processing insstructions and skip
  2644. * @param {*} xmlData
  2645. * @param {*} i
  2646. */
  2647. function readPI(xmlData, i) {
  2648. var start = i;
  2649. for (; i < xmlData.length; i++) {
  2650. if (xmlData[i] == '?' || xmlData[i] == ' ') {
  2651. //tagname
  2652. var tagname = xmlData.substr(start, i - start);
  2653. if (i > 5 && tagname === 'xml') {
  2654. return {
  2655. err: {
  2656. code: 'InvalidXml',
  2657. msg: 'XML declaration allowed only at the start of the document.'
  2658. }
  2659. };
  2660. } else if (xmlData[i] == '?' && xmlData[i + 1] == '>') {
  2661. //check if valid attribut string
  2662. i++;
  2663. break;
  2664. } else {
  2665. continue;
  2666. }
  2667. }
  2668. }
  2669. return i;
  2670. }
  2671. function readCommentAndCDATA(xmlData, i) {
  2672. if (xmlData.length > i + 5 && xmlData[i + 1] === '-' && xmlData[i + 2] === '-') {
  2673. //comment
  2674. for (i += 3; i < xmlData.length; i++) {
  2675. if (xmlData[i] === '-' && xmlData[i + 1] === '-' && xmlData[i + 2] === '>') {
  2676. i += 2;
  2677. break;
  2678. }
  2679. }
  2680. } else if (xmlData.length > i + 8 && xmlData[i + 1] === 'D' && xmlData[i + 2] === 'O' && xmlData[i + 3] === 'C' && xmlData[i + 4] === 'T' && xmlData[i + 5] === 'Y' && xmlData[i + 6] === 'P' && xmlData[i + 7] === 'E') {
  2681. var angleBracketsCount = 1;
  2682. for (i += 8; i < xmlData.length; i++) {
  2683. if (xmlData[i] === '<') {
  2684. angleBracketsCount++;
  2685. } else if (xmlData[i] === '>') {
  2686. angleBracketsCount--;
  2687. if (angleBracketsCount === 0) {
  2688. break;
  2689. }
  2690. }
  2691. }
  2692. } else if (xmlData.length > i + 9 && xmlData[i + 1] === '[' && xmlData[i + 2] === 'C' && xmlData[i + 3] === 'D' && xmlData[i + 4] === 'A' && xmlData[i + 5] === 'T' && xmlData[i + 6] === 'A' && xmlData[i + 7] === '[') {
  2693. for (i += 8; i < xmlData.length; i++) {
  2694. if (xmlData[i] === ']' && xmlData[i + 1] === ']' && xmlData[i + 2] === '>') {
  2695. i += 2;
  2696. break;
  2697. }
  2698. }
  2699. }
  2700. return i;
  2701. }
  2702. var doubleQuote = '"';
  2703. var singleQuote = "'";
  2704. /**
  2705. * Keep reading xmlData until '<' is found outside the attribute value.
  2706. * @param {string} xmlData
  2707. * @param {number} i
  2708. */
  2709. function readAttributeStr(xmlData, i) {
  2710. var attrStr = '';
  2711. var startChar = '';
  2712. var tagClosed = false;
  2713. for (; i < xmlData.length; i++) {
  2714. if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
  2715. if (startChar === '') {
  2716. startChar = xmlData[i];
  2717. } else if (startChar !== xmlData[i]) {
  2718. //if vaue is enclosed with double quote then single quotes are allowed inside the value and vice versa
  2719. continue;
  2720. } else {
  2721. startChar = '';
  2722. }
  2723. } else if (xmlData[i] === '>') {
  2724. if (startChar === '') {
  2725. tagClosed = true;
  2726. break;
  2727. }
  2728. }
  2729. attrStr += xmlData[i];
  2730. }
  2731. if (startChar !== '') {
  2732. return false;
  2733. }
  2734. return {
  2735. value: attrStr,
  2736. index: i,
  2737. tagClosed: tagClosed
  2738. };
  2739. }
  2740. /**
  2741. * Select all the attributes whether valid or invalid.
  2742. */
  2743. var validAttrStrRegxp = new RegExp('(\\s*)([^\\s=]+)(\\s*=)?(\\s*([\'"])(([\\s\\S])*?)\\5)?', 'g'); //attr, ="sd", a="amit's", a="sd"b="saf", ab cd=""
  2744. function validateAttributeString(attrStr, options, regxAttrName) {
  2745. //console.log("start:"+attrStr+":end");
  2746. //if(attrStr.trim().length === 0) return true; //empty string
  2747. var matches = util.getAllMatches(attrStr, validAttrStrRegxp);
  2748. var attrNames = {};
  2749. for (var i = 0; i < matches.length; i++) {
  2750. //console.log(matches[i]);
  2751. if (matches[i][1].length === 0) {
  2752. //nospace before attribute name: a="sd"b="saf"
  2753. return {
  2754. err: {
  2755. code: 'InvalidAttr',
  2756. msg: 'attribute ' + matches[i][2] + ' has no space in starting.'
  2757. }
  2758. };
  2759. } else if (matches[i][3] === undefined && !options.allowBooleanAttributes) {
  2760. //independent attribute: ab
  2761. return {
  2762. err: {
  2763. code: 'InvalidAttr',
  2764. msg: 'boolean attribute ' + matches[i][2] + ' is not allowed.'
  2765. }
  2766. };
  2767. }
  2768. /* else if(matches[i][6] === undefined){//attribute without value: ab=
  2769. return { err: { code:"InvalidAttr",msg:"attribute " + matches[i][2] + " has no value assigned."}};
  2770. } */
  2771. var attrName = matches[i][2];
  2772. if (!validateAttrName(attrName, regxAttrName)) {
  2773. return {
  2774. err: {
  2775. code: 'InvalidAttr',
  2776. msg: 'attribute ' + attrName + ' is an invalid name.'
  2777. }
  2778. };
  2779. }
  2780. /*if (!attrNames.hasOwnProperty(attrName)) {*/
  2781. if (!Object.prototype.hasOwnProperty.call(attrNames, attrName)) {
  2782. //check for duplicate attribute.
  2783. attrNames[attrName] = 1;
  2784. } else {
  2785. return {
  2786. err: {
  2787. code: 'InvalidAttr',
  2788. msg: 'attribute ' + attrName + ' is repeated.'
  2789. }
  2790. };
  2791. }
  2792. }
  2793. return true;
  2794. } // const validAttrRegxp = /^[_a-zA-Z][\w\-.:]*$/;
  2795. function validateAttrName(attrName, regxAttrName) {
  2796. // const validAttrRegxp = new RegExp(regxAttrName);
  2797. return util.doesMatch(attrName, regxAttrName);
  2798. } //const startsWithXML = new RegExp("^[Xx][Mm][Ll]");
  2799. // startsWith = /^([a-zA-Z]|_)[\w.\-_:]*/;
  2800. function validateTagName(tagname, regxTagName) {
  2801. /*if(util.doesMatch(tagname,startsWithXML)) return false;
  2802. else*/
  2803. return !util.doesNotMatch(tagname, regxTagName);
  2804. }
  2805. /***/ }),
  2806. /* 14 */
  2807. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2808. "use strict";
  2809. __webpack_require__.r(__webpack_exports__);
  2810. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return BitMapFont; });
  2811. /* harmony import */ var _imageManager__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(15);
  2812. /* harmony import */ var _pool__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
  2813. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2814. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  2815. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  2816. var bitMapPool = new _pool__WEBPACK_IMPORTED_MODULE_1__["default"]('bitMapPool');
  2817. var Emitter = __webpack_require__(4);
  2818. /**
  2819. * http://www.angelcode.com/products/bmfont/doc/file_format.html
  2820. */
  2821. var BitMapFont = /*#__PURE__*/function () {
  2822. function BitMapFont(name, src, config) {
  2823. var _this = this;
  2824. _classCallCheck(this, BitMapFont);
  2825. var cache = bitMapPool.get(name);
  2826. if (cache) {
  2827. return cache;
  2828. }
  2829. this.config = config;
  2830. this.chars = this.parseConfig(config);
  2831. this.ready = false;
  2832. this.event = new Emitter();
  2833. this.texture = _imageManager__WEBPACK_IMPORTED_MODULE_0__["default"].loadImage(src, function (texture, fromCache) {
  2834. if (fromCache) {
  2835. _this.texture = texture;
  2836. }
  2837. _this.ready = true;
  2838. _this.event.emit('text__load__done');
  2839. });
  2840. bitMapPool.set(name, this);
  2841. }
  2842. _createClass(BitMapFont, [{
  2843. key: "parseConfig",
  2844. value: function parseConfig(fntText) {
  2845. fntText = fntText.split("\r\n").join("\n");
  2846. var lines = fntText.split("\n");
  2847. var charsCount = this.getConfigByKey(lines[3], "count");
  2848. this.lineHeight = this.getConfigByKey(lines[1], 'lineHeight');
  2849. this.fontSize = this.getConfigByKey(lines[0], 'size');
  2850. var chars = {};
  2851. for (var i = 4; i < 4 + charsCount; i++) {
  2852. var charText = lines[i];
  2853. var letter = String.fromCharCode(this.getConfigByKey(charText, "id"));
  2854. var c = {};
  2855. chars[letter] = c;
  2856. c["x"] = this.getConfigByKey(charText, "x");
  2857. c["y"] = this.getConfigByKey(charText, "y");
  2858. c["w"] = this.getConfigByKey(charText, "width");
  2859. c["h"] = this.getConfigByKey(charText, "height");
  2860. c["offX"] = this.getConfigByKey(charText, "xoffset");
  2861. c["offY"] = this.getConfigByKey(charText, "yoffset");
  2862. c["xadvance"] = this.getConfigByKey(charText, "xadvance");
  2863. }
  2864. return chars;
  2865. }
  2866. }, {
  2867. key: "getConfigByKey",
  2868. value: function getConfigByKey(configText, key) {
  2869. var itemConfigTextList = configText.split(" ");
  2870. for (var i = 0, length = itemConfigTextList.length; i < length; i++) {
  2871. var itemConfigText = itemConfigTextList[i];
  2872. if (key === itemConfigText.substring(0, key.length)) {
  2873. var value = itemConfigText.substring(key.length + 1);
  2874. return parseInt(value);
  2875. }
  2876. }
  2877. return 0;
  2878. }
  2879. }]);
  2880. return BitMapFont;
  2881. }();
  2882. /***/ }),
  2883. /* 15 */
  2884. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2885. "use strict";
  2886. __webpack_require__.r(__webpack_exports__);
  2887. /* harmony import */ var _pool__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
  2888. /* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7);
  2889. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2890. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  2891. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  2892. var imgPool = new _pool__WEBPACK_IMPORTED_MODULE_0__["default"]('imgPool');
  2893. var ImageManager = /*#__PURE__*/function () {
  2894. function ImageManager() {
  2895. _classCallCheck(this, ImageManager);
  2896. }
  2897. _createClass(ImageManager, [{
  2898. key: "getRes",
  2899. value: function getRes(src) {
  2900. return imgPool.get(src);
  2901. }
  2902. }, {
  2903. key: "loadImage",
  2904. value: function loadImage(src) {
  2905. var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _util__WEBPACK_IMPORTED_MODULE_1__["none"];
  2906. var img = null;
  2907. var cache = this.getRes(src);
  2908. if (!src) {
  2909. return img;
  2910. } // 图片已经被加载过,直接返回图片并且执行回调
  2911. if (cache && cache.loadDone) {
  2912. img = cache;
  2913. callback(img, true);
  2914. } else if (cache && !cache.loadDone) {
  2915. // 图片正在加载过程中,返回图片并且等待图片加载完成执行回调
  2916. img = cache;
  2917. cache.onloadcbks.push(callback);
  2918. } else {
  2919. // 创建图片,将回调函数推入回调函数栈
  2920. img = Object(_util__WEBPACK_IMPORTED_MODULE_1__["createImage"])();
  2921. img.onloadcbks = [callback];
  2922. imgPool.set(src, img);
  2923. img.onload = function () {
  2924. img.onloadcbks.forEach(function (fn) {
  2925. return fn(img, false);
  2926. });
  2927. img.onloadcbks = [];
  2928. img.loadDone = true;
  2929. };
  2930. img.onerror = function (e) {
  2931. console.log('img load error', e);
  2932. };
  2933. img.src = src;
  2934. }
  2935. return img;
  2936. }
  2937. }]);
  2938. return ImageManager;
  2939. }();
  2940. /* harmony default export */ __webpack_exports__["default"] = (new ImageManager());
  2941. /***/ }),
  2942. /* 16 */
  2943. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2944. "use strict";
  2945. __webpack_require__.r(__webpack_exports__);
  2946. /* harmony import */ var _view_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(17);
  2947. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "View", function() { return _view_js__WEBPACK_IMPORTED_MODULE_0__["default"]; });
  2948. /* harmony import */ var _image_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(18);
  2949. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Image", function() { return _image_js__WEBPACK_IMPORTED_MODULE_1__["default"]; });
  2950. /* harmony import */ var _text_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(19);
  2951. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Text", function() { return _text_js__WEBPACK_IMPORTED_MODULE_2__["default"]; });
  2952. /* harmony import */ var _scrollview_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(20);
  2953. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ScrollView", function() { return _scrollview_js__WEBPACK_IMPORTED_MODULE_3__["default"]; });
  2954. /* harmony import */ var _bitmaptext_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(22);
  2955. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BitMapText", function() { return _bitmaptext_js__WEBPACK_IMPORTED_MODULE_4__["default"]; });
  2956. /***/ }),
  2957. /* 17 */
  2958. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2959. "use strict";
  2960. __webpack_require__.r(__webpack_exports__);
  2961. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return View; });
  2962. /* harmony import */ var _elements_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
  2963. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  2964. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2965. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  2966. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  2967. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  2968. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  2969. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  2970. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  2971. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  2972. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  2973. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  2974. var View = /*#__PURE__*/function (_Element) {
  2975. _inherits(View, _Element);
  2976. var _super = _createSuper(View);
  2977. function View(_ref) {
  2978. var _this;
  2979. var _ref$style = _ref.style,
  2980. style = _ref$style === void 0 ? {} : _ref$style,
  2981. _ref$props = _ref.props,
  2982. props = _ref$props === void 0 ? {} : _ref$props,
  2983. _ref$idName = _ref.idName,
  2984. idName = _ref$idName === void 0 ? '' : _ref$idName,
  2985. _ref$className = _ref.className,
  2986. className = _ref$className === void 0 ? '' : _ref$className;
  2987. _classCallCheck(this, View);
  2988. _this = _super.call(this, {
  2989. props: props,
  2990. idName: idName,
  2991. className: className,
  2992. style: style
  2993. });
  2994. _this.type = 'View';
  2995. _this.ctx = null;
  2996. _this.renderBoxes = [];
  2997. return _this;
  2998. }
  2999. _createClass(View, [{
  3000. key: "destroySelf",
  3001. value: function destroySelf() {
  3002. this.isDestroyed = true;
  3003. this.children = null;
  3004. this.root = null;
  3005. } // 有些节点仅仅作为容器,实际上不需要任何渲染逻辑,这里加个判断可以提高性能
  3006. }, {
  3007. key: "checkNeedRender",
  3008. value: function checkNeedRender() {
  3009. var style = this.style || {};
  3010. var borderColor = style.borderColor;
  3011. return !!(style.backgroundColor || style.borderWidth && borderColor || style.borderTopWidth && (borderColor || style.borderTopColor) || style.borderBottomWidth && (borderColor || style.borderBottomColor) || style.borderLeftWidth && (borderColor || style.borderLeftColor) || style.borderRightWidth && (borderColor || style.borderRightColor));
  3012. }
  3013. }, {
  3014. key: "render",
  3015. value: function render(ctx, layoutBox) {
  3016. var style = this.style || {};
  3017. var box = layoutBox || this.layoutBox;
  3018. ctx.save();
  3019. var borderWidth = style.borderWidth || 0;
  3020. var drawX = box.absoluteX;
  3021. var drawY = box.absoluteY;
  3022. var borderLeftWidth = style.borderLeftWidth || borderWidth;
  3023. var borderRightWidth = style.borderRightWidth || borderWidth;
  3024. var borderTopWidth = style.borderTopWidth || borderWidth;
  3025. var borderBottomWidth = style.borderBottomWidth || borderWidth;
  3026. this.renderBorder(ctx, layoutBox);
  3027. if (style.backgroundColor) {
  3028. ctx.fillStyle = style.backgroundColor;
  3029. ctx.fillRect(drawX + borderLeftWidth, drawY + borderRightWidth, box.width - (borderLeftWidth + borderRightWidth), box.height - (borderTopWidth + borderBottomWidth));
  3030. }
  3031. ctx.restore();
  3032. }
  3033. }, {
  3034. key: "insert",
  3035. value: function insert(ctx, box) {
  3036. this.ctx = ctx;
  3037. if (!box) {
  3038. box = this.layoutBox;
  3039. }
  3040. this.renderBoxes.push({
  3041. ctx: ctx,
  3042. box: box
  3043. });
  3044. this.render(ctx, box);
  3045. }
  3046. }, {
  3047. key: "repaint",
  3048. value: function repaint() {
  3049. var _this2 = this;
  3050. this.renderBoxes.forEach(function (item) {
  3051. _this2.render(item.ctx, item.box);
  3052. });
  3053. }
  3054. }]);
  3055. return View;
  3056. }(_elements_js__WEBPACK_IMPORTED_MODULE_0__["default"]);
  3057. /***/ }),
  3058. /* 18 */
  3059. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3060. "use strict";
  3061. __webpack_require__.r(__webpack_exports__);
  3062. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Image; });
  3063. /* harmony import */ var _elements_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
  3064. /* harmony import */ var _common_imageManager__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(15);
  3065. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3066. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3067. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3068. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  3069. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  3070. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  3071. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  3072. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  3073. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  3074. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  3075. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  3076. var Image = /*#__PURE__*/function (_Element) {
  3077. _inherits(Image, _Element);
  3078. var _super = _createSuper(Image);
  3079. function Image(opts) {
  3080. var _this;
  3081. _classCallCheck(this, Image);
  3082. var _opts$style = opts.style,
  3083. style = _opts$style === void 0 ? {} : _opts$style,
  3084. _opts$props = opts.props,
  3085. props = _opts$props === void 0 ? {} : _opts$props,
  3086. _opts$idName = opts.idName,
  3087. idName = _opts$idName === void 0 ? '' : _opts$idName,
  3088. _opts$className = opts.className,
  3089. className = _opts$className === void 0 ? '' : _opts$className,
  3090. _opts$src = opts.src,
  3091. src = _opts$src === void 0 ? '' : _opts$src;
  3092. _this = _super.call(this, {
  3093. props: props,
  3094. idName: idName,
  3095. className: className,
  3096. style: style
  3097. });
  3098. _this.imgsrc = src;
  3099. Object.defineProperty(_assertThisInitialized(_this), "src", {
  3100. get: function get() {
  3101. return this.imgsrc;
  3102. },
  3103. set: function set(newValue) {
  3104. var _this2 = this;
  3105. if (newValue !== this.imgsrc) {
  3106. this.imgsrc = newValue;
  3107. _common_imageManager__WEBPACK_IMPORTED_MODULE_1__["default"].loadImage(this.src, function (img) {
  3108. _this2.img = img;
  3109. /*this.repaint();*/
  3110. _this2.emit('repaint');
  3111. });
  3112. }
  3113. },
  3114. enumerable: true,
  3115. configurable: true
  3116. });
  3117. _this.type = 'Image';
  3118. _this.renderBoxes = [];
  3119. return _this;
  3120. }
  3121. _createClass(Image, [{
  3122. key: "repaint",
  3123. value: function repaint() {
  3124. var _this3 = this;
  3125. this.renderBoxes.forEach(function (item) {
  3126. _this3.renderImg(item.ctx, item.box, false);
  3127. });
  3128. } // 子类填充实现
  3129. }, {
  3130. key: "destroySelf",
  3131. value: function destroySelf() {
  3132. this.isDestroyed = true;
  3133. this.img = null;
  3134. delete this.src;
  3135. this.root = null;
  3136. }
  3137. }, {
  3138. key: "renderImg",
  3139. value: function renderImg(ctx, layoutBox) {
  3140. var needEmitEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  3141. if (!this.img) {
  3142. return;
  3143. }
  3144. var style = this.style || {};
  3145. var box = layoutBox || this.layoutBox;
  3146. ctx.save();
  3147. if (style.borderColor) {
  3148. ctx.strokeStyle = style.borderColor;
  3149. }
  3150. ctx.lineWidth = style.borderWidth || 0;
  3151. var drawX = box.absoluteX;
  3152. var drawY = box.absoluteY;
  3153. this.renderBorder(ctx, layoutBox);
  3154. ctx.drawImage(this.img, drawX, drawY, box.width, box.height);
  3155. ctx.restore();
  3156. }
  3157. }, {
  3158. key: "insert",
  3159. value: function insert(ctx, box) {
  3160. var _this4 = this;
  3161. this.renderBoxes.push({
  3162. ctx: ctx,
  3163. box: box
  3164. });
  3165. this.img = _common_imageManager__WEBPACK_IMPORTED_MODULE_1__["default"].loadImage(this.src, function (img, fromCache) {
  3166. // 来自缓存的,还没返回img就会执行回调函数
  3167. if (fromCache) {
  3168. _this4.img = img;
  3169. _this4.renderImg(ctx, box, false);
  3170. } else {
  3171. // 当图片加载完成,实例可能已经被销毁了
  3172. if (_this4.img) {
  3173. var eventName = _this4.isScrollViewChild ? 'image__render__done' : 'one__image__render__done';
  3174. _this4.EE.emit(eventName, _this4);
  3175. }
  3176. }
  3177. });
  3178. }
  3179. }, {
  3180. key: "isScrollViewChild",
  3181. get: function get() {
  3182. var flag = false;
  3183. var parent = this.parent;
  3184. while (parent && !flag) {
  3185. if (parent.type === 'ScrollView') {
  3186. flag = true;
  3187. } else {
  3188. parent = parent.parent;
  3189. }
  3190. }
  3191. return flag;
  3192. }
  3193. }]);
  3194. return Image;
  3195. }(_elements_js__WEBPACK_IMPORTED_MODULE_0__["default"]);
  3196. /***/ }),
  3197. /* 19 */
  3198. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3199. "use strict";
  3200. __webpack_require__.r(__webpack_exports__);
  3201. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Text; });
  3202. /* harmony import */ var _elements_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
  3203. /* harmony import */ var _common_util_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7);
  3204. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3205. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3206. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3207. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  3208. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  3209. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  3210. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  3211. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  3212. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  3213. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  3214. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  3215. var DEFAULT_FONT_FAMILY = 'PingFangSC-Regular, sans-serif';
  3216. var context = null;
  3217. var getContext = function getContext() {
  3218. if (context) {
  3219. return context;
  3220. }
  3221. var canvas = Object(_common_util_js__WEBPACK_IMPORTED_MODULE_1__["createCanvas"])();
  3222. canvas.width = 1;
  3223. canvas.height = 1;
  3224. context = canvas.getContext('2d');
  3225. return context;
  3226. };
  3227. function getTextWidth(style, value) {
  3228. var context = getContext();
  3229. context.font = "".concat(style.fontWeight || 'normal', " ").concat(style.fontSize || 12, "px ").concat(style.fontFamily || DEFAULT_FONT_FAMILY);
  3230. return context.measureText(value).width || 0;
  3231. }
  3232. function getTextWidthWithoutSetFont(value) {
  3233. return getContext().measureText(value).width || 0;
  3234. }
  3235. function parseText(style, value) {
  3236. value = String(value);
  3237. var maxWidth = style.width;
  3238. var wordWidth = getTextWidth(style, value); // 对文字溢出的处理,默认用...
  3239. var textOverflow = style.textOverflow || 'ellipsis'; // 文字最大长度不超限制
  3240. if (wordWidth <= maxWidth) {
  3241. return value;
  3242. } // 对于用点点点处理的情况,先将最大宽度减去...的宽度
  3243. if (textOverflow === 'ellipsis') {
  3244. maxWidth -= getTextWidthWithoutSetFont('...');
  3245. }
  3246. var length = value.length - 1;
  3247. var str = value.substring(0, length);
  3248. while (getTextWidthWithoutSetFont(str) > maxWidth && length > 0) {
  3249. length--;
  3250. str = value.substring(0, length);
  3251. }
  3252. return length && textOverflow === 'ellipsis' ? str + '...' : str;
  3253. }
  3254. var Text = /*#__PURE__*/function (_Element) {
  3255. _inherits(Text, _Element);
  3256. var _super = _createSuper(Text);
  3257. function Text(_ref) {
  3258. var _this;
  3259. var _ref$style = _ref.style,
  3260. style = _ref$style === void 0 ? {} : _ref$style,
  3261. _ref$props = _ref.props,
  3262. props = _ref$props === void 0 ? {} : _ref$props,
  3263. _ref$idName = _ref.idName,
  3264. idName = _ref$idName === void 0 ? '' : _ref$idName,
  3265. _ref$className = _ref.className,
  3266. className = _ref$className === void 0 ? '' : _ref$className,
  3267. _ref$value = _ref.value,
  3268. value = _ref$value === void 0 ? '' : _ref$value;
  3269. _classCallCheck(this, Text);
  3270. // 没有设置宽度的时候通过canvas计算出文字宽度
  3271. if (style.width === undefined) {
  3272. style.width = getTextWidth(style, value);
  3273. } else if (style.textOverflow === 'ellipsis') {
  3274. value = parseText(style, value);
  3275. }
  3276. _this = _super.call(this, {
  3277. props: props,
  3278. idName: idName,
  3279. className: className,
  3280. style: style
  3281. });
  3282. _this.type = 'Text';
  3283. _this.ctx = null;
  3284. _this.valuesrc = value;
  3285. _this.renderBoxes = [];
  3286. Object.defineProperty(_assertThisInitialized(_this), "value", {
  3287. get: function get() {
  3288. return this.valuesrc;
  3289. },
  3290. set: function set(newValue) {
  3291. if (newValue !== this.valuesrc) {
  3292. this.valuesrc = newValue;
  3293. this.emit('repaint');
  3294. }
  3295. },
  3296. enumerable: true,
  3297. configurable: true
  3298. });
  3299. return _this;
  3300. }
  3301. _createClass(Text, [{
  3302. key: "toCanvasData",
  3303. value: function toCanvasData() {
  3304. var style = this.style || {};
  3305. this.fontSize = style.fontSize || 12;
  3306. this.textBaseline = 'top';
  3307. this.font = "".concat(style.fontWeight || '', " ").concat(style.fontSize || 12, "px ").concat(DEFAULT_FONT_FAMILY);
  3308. this.textAlign = style.textAlign || 'left';
  3309. this.fillStyle = style.color || '#000';
  3310. }
  3311. }, {
  3312. key: "insert",
  3313. value: function insert(ctx, box) {
  3314. this.renderBoxes.push({
  3315. ctx: ctx,
  3316. box: box
  3317. });
  3318. this.render(ctx, box);
  3319. }
  3320. }, {
  3321. key: "repaint",
  3322. value: function repaint() {
  3323. var _this2 = this;
  3324. this.renderBoxes.forEach(function (item) {
  3325. _this2.render(item.ctx, item.box);
  3326. });
  3327. }
  3328. }, {
  3329. key: "destroySelf",
  3330. value: function destroySelf() {
  3331. this.root = null;
  3332. }
  3333. }, {
  3334. key: "render",
  3335. value: function render(ctx, layoutBox) {
  3336. this.toCanvasData();
  3337. ctx.save();
  3338. var box = layoutBox || this.layoutBox;
  3339. var style = this.style;
  3340. ctx.textBaseline = this.textBaseline;
  3341. ctx.font = this.font;
  3342. ctx.textAlign = this.textAlign;
  3343. var drawX = box.absoluteX;
  3344. var drawY = box.absoluteY;
  3345. this.renderBorder(ctx, layoutBox);
  3346. if (style.backgroundColor) {
  3347. ctx.fillStyle = style.backgroundColor;
  3348. ctx.fillRect(drawX, drawY, box.width, box.height);
  3349. }
  3350. ctx.fillStyle = this.fillStyle;
  3351. if (this.textAlign === 'center') {
  3352. drawX += box.width / 2;
  3353. } else if (this.textAlign === 'right') {
  3354. drawX += box.width;
  3355. }
  3356. if (style.lineHeight) {
  3357. ctx.textBaseline = 'middle';
  3358. drawY += style.lineHeight / 2;
  3359. }
  3360. ctx.fillText(this.value, drawX, drawY);
  3361. ctx.restore();
  3362. }
  3363. }]);
  3364. return Text;
  3365. }(_elements_js__WEBPACK_IMPORTED_MODULE_0__["default"]);
  3366. /***/ }),
  3367. /* 20 */
  3368. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3369. "use strict";
  3370. __webpack_require__.r(__webpack_exports__);
  3371. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return ScrollView; });
  3372. /* harmony import */ var _view_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(17);
  3373. /* harmony import */ var _common_pool_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
  3374. /* harmony import */ var _common_touch_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(21);
  3375. /* harmony import */ var _common_util_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(7);
  3376. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3377. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3378. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3379. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  3380. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  3381. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  3382. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  3383. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  3384. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  3385. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  3386. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  3387. var id = 0;
  3388. var canvasPool = new _common_pool_js__WEBPACK_IMPORTED_MODULE_1__["default"]('canvasPool');
  3389. var ScrollView = /*#__PURE__*/function (_View) {
  3390. _inherits(ScrollView, _View);
  3391. var _super = _createSuper(ScrollView);
  3392. function ScrollView(_ref) {
  3393. var _this;
  3394. var _ref$style = _ref.style,
  3395. style = _ref$style === void 0 ? {} : _ref$style,
  3396. _ref$props = _ref.props,
  3397. props = _ref$props === void 0 ? {} : _ref$props,
  3398. _ref$name = _ref.name,
  3399. name = _ref$name === void 0 ? '' : _ref$name;
  3400. _classCallCheck(this, ScrollView);
  3401. _this = _super.call(this, {
  3402. props: props,
  3403. name: name,
  3404. style: style
  3405. });
  3406. _this.type = 'ScrollView'; // 当前列表滚动的值
  3407. _this.top = 0; // 滚动处理器
  3408. _this.touch = new _common_touch_js__WEBPACK_IMPORTED_MODULE_2__["default"](); // canvas高度不能过高,在小游戏里面,对canvas尺寸是有限制的
  3409. _this.pageHeight = 2000; // 根据列表总高度和单页高度计算的分页数量
  3410. _this.pageCount = 1;
  3411. _this.canvasMap = {}; // 图片加载完成之后会触发scrollView的重绘函数,当图片过多的时候用节流提升性能
  3412. _this.throttleRepaint = Object(_common_util_js__WEBPACK_IMPORTED_MODULE_3__["throttle"])(_this.clipRepaint, 16, _assertThisInitialized(_this));
  3413. _this.throttleImageLoadDone = Object(_common_util_js__WEBPACK_IMPORTED_MODULE_3__["throttle"])(_this.childImageLoadDoneCbk, 32, _assertThisInitialized(_this));
  3414. _this.renderTimers = [];
  3415. _this.requestID = null;
  3416. return _this;
  3417. }
  3418. /**
  3419. * 获取滚动列表内所有元素的高度和
  3420. * 这里不能简单将所有子元素的高度累加,因为每个元素之间可能是有空隙的
  3421. */
  3422. _createClass(ScrollView, [{
  3423. key: "repaint",
  3424. value: function repaint() {
  3425. var _this2 = this;
  3426. this.clear();
  3427. this.renderBoxes.forEach(function (item) {
  3428. _this2.render(item.ctx, item.box);
  3429. });
  3430. }
  3431. /**
  3432. * 列表子元素重绘之前先将所有的canvas擦除
  3433. */
  3434. }, {
  3435. key: "clear",
  3436. value: function clear() {
  3437. var _this3 = this;
  3438. Object.keys(this.canvasMap).forEach(function (key) {
  3439. var item = _this3.canvasMap[key];
  3440. item.context && item.context.clearRect(0, 0, item.canvas.width, item.canvas.height);
  3441. });
  3442. } // 与主canvas的尺寸保持一致
  3443. }, {
  3444. key: "updateRenderPort",
  3445. value: function updateRenderPort(renderport) {
  3446. this.renderport = renderport;
  3447. }
  3448. /**
  3449. * 计算分页数据
  3450. * 小游戏的canvas对尺寸有要求,如果如果高度过高,可能出现渲染不出来的情况
  3451. * 因此需要手动分页,列表过长的时候将数据绘制到几个canvas上面,这里预创建几个canvas
  3452. */
  3453. }, {
  3454. key: "calPageData",
  3455. value: function calPageData() {
  3456. this.pageCount = Math.ceil((this.scrollHeight + this.layoutBox.absoluteY) / this.pageHeight);
  3457. for (var i = 0; i < this.pageCount; i++) {
  3458. var cache = canvasPool.get(i);
  3459. if (cache) {
  3460. cache.context && cache.context.clearRect(0, 0, cache.canvas.width, cache.canvas.height);
  3461. cache.elements = [];
  3462. this.canvasMap[i] = cache;
  3463. } else {
  3464. this.canvasMap[i] = {
  3465. elements: []
  3466. };
  3467. canvasPool.set(i, this.canvasMap[i]);
  3468. }
  3469. }
  3470. }
  3471. }, {
  3472. key: "destroySelf",
  3473. value: function destroySelf() {
  3474. this.touch = null;
  3475. this.isDestroyed = true;
  3476. this.throttleRepaint = null;
  3477. this.renderTimers.forEach(function (timer) {
  3478. clearTimeout(timer);
  3479. });
  3480. this.root.off('repaint__done');
  3481. this.renderTimers = [];
  3482. this.canvasMap = {};
  3483. this.ctx = null;
  3484. this.children = null;
  3485. this.requestID && cancelAnimationFrame(this.requestID);
  3486. this.root = null;
  3487. }
  3488. /**
  3489. * 滚动列表重绘逻辑
  3490. * 将分页canvas按照滚动裁剪绘制到主canvas上面
  3491. */
  3492. }, {
  3493. key: "clipRepaint",
  3494. value: function clipRepaint(top) {
  3495. var _this4 = this;
  3496. if (this.isDestroyed) {
  3497. return;
  3498. }
  3499. this.requestID = requestAnimationFrame(function () {
  3500. top = -top;
  3501. _this4.top = top;
  3502. var box = _this4.layoutBox;
  3503. var abY = box.absoluteY;
  3504. if (_this4.isDestroyed || _this4.root.state === _common_util_js__WEBPACK_IMPORTED_MODULE_3__["STATE"].CLEAR) {
  3505. return;
  3506. } // 在主canvas上面将滚动列表区域擦除
  3507. _this4.ctx.clearRect(box.absoluteX, abY, box.width, box.height); // 背景填充
  3508. _this4.ctx.fillStyle = _this4.parent.style.backgroundColor || '#ffffff';
  3509. _this4.ctx.fillRect(box.absoluteX, abY, box.width, box.height);
  3510. for (var i = 0; i < _this4.pageCount; i++) {
  3511. var canvas = _this4.canvasMap[i].canvas; // 根据滚动值获取裁剪区域
  3512. var startY = abY + top;
  3513. var endY = abY + top + box.height; // 计算在裁剪区域内的canvas
  3514. if (startY < _this4.pageHeight * (i + 1) && endY > _this4.pageHeight * i) {
  3515. /**
  3516. * 这里不能按照box.width * box.height的区域去裁剪
  3517. * 在浏览器里面正常,但是在小游戏里面会出现诡异的渲染出错,所以裁剪canvas真实有效的区域
  3518. */
  3519. var clipY = abY + top - _this4.pageHeight * i;
  3520. var clipH = box.height;
  3521. var renderY = abY;
  3522. if (clipY > 0 && _this4.pageHeight - clipY < box.height) {
  3523. clipH = _this4.pageHeight - clipY;
  3524. } else if (clipY < 0) {
  3525. clipH = clipY + box.height;
  3526. renderY = renderY - clipY;
  3527. clipY = 0;
  3528. }
  3529. _this4.ctx.drawImage(canvas, box.absoluteX, clipY, box.width, clipH, box.absoluteX, renderY, box.width, clipH);
  3530. }
  3531. }
  3532. });
  3533. }
  3534. }, {
  3535. key: "renderChildren",
  3536. value: function renderChildren(tree) {
  3537. var _this5 = this;
  3538. var children = tree.children;
  3539. var height = this.pageHeight;
  3540. Object.keys(children).forEach(function (id) {
  3541. var child = children[id];
  3542. var originY = child.layoutBox.originalAbsoluteY;
  3543. var pageIndex = Math.floor(originY / height);
  3544. var nextPage = pageIndex + 1;
  3545. child.layoutBox.absoluteY -= _this5.pageHeight * pageIndex;
  3546. if (child.checkNeedRender()) {
  3547. _this5.canvasMap[pageIndex].elements.push({
  3548. element: child,
  3549. box: child.layoutBox
  3550. });
  3551. } // 对于跨界的元素,两边都绘制下
  3552. if (originY + child.layoutBox.height > height * nextPage) {
  3553. var tmpBox = Object.assign({}, child.layoutBox);
  3554. tmpBox.absoluteY = originY - _this5.pageHeight * nextPage;
  3555. if (child.checkNeedRender()) {
  3556. _this5.canvasMap[nextPage].elements.push({
  3557. element: child,
  3558. box: tmpBox
  3559. });
  3560. }
  3561. }
  3562. _this5.renderChildren(child);
  3563. });
  3564. }
  3565. }, {
  3566. key: "insertElements",
  3567. value: function insertElements(pageIndex) {
  3568. var _this6 = this;
  3569. var can = Object(_common_util_js__WEBPACK_IMPORTED_MODULE_3__["createCanvas"])();
  3570. var ctx = can.getContext('2d');
  3571. can.width = this.renderport.width;
  3572. can.height = this.pageHeight;
  3573. ctx.id = ++id;
  3574. this.canvasMap[pageIndex].canvas = can;
  3575. this.canvasMap[pageIndex].context = ctx;
  3576. this.canvasMap[pageIndex].elements.forEach(function (ele) {
  3577. ele.element.insert(ctx, ele.box);
  3578. });
  3579. if (pageIndex < this.pageCount - 1) {
  3580. var timer = setTimeout(function () {
  3581. _this6.insertElements(++pageIndex);
  3582. }, 250);
  3583. this.renderTimers.push(timer);
  3584. }
  3585. }
  3586. }, {
  3587. key: "childImageLoadDoneCbk",
  3588. value: function childImageLoadDoneCbk(img) {
  3589. var start = new Date();
  3590. var list = Object.values(this.canvasMap);
  3591. var pageIndex = -1;
  3592. for (var i = 0; i < list.length; i++) {
  3593. if (list[i].elements.find(function (item) {
  3594. return item.element === img;
  3595. })) {
  3596. pageIndex = i;
  3597. break;
  3598. }
  3599. }
  3600. if (pageIndex > -1) {
  3601. var _start = new Date();
  3602. var canItem = this.canvasMap[pageIndex];
  3603. var canvas = canItem.canvas;
  3604. var ctx = canItem.context;
  3605. ctx.clearRect(0, 0, canvas.width, canvas.height);
  3606. this.canvasMap[pageIndex].elements.forEach(function (ele) {
  3607. Object(_common_util_js__WEBPACK_IMPORTED_MODULE_3__["repaintTree"])(ele.element);
  3608. });
  3609. }
  3610. /*this.throttleRepaint(-this.top || 0);*/
  3611. this.clipRepaint(-this.top);
  3612. }
  3613. }, {
  3614. key: "insertScrollView",
  3615. value: function insertScrollView(context) {
  3616. var _this7 = this;
  3617. // 绘制容器
  3618. this.insert(context);
  3619. this.root.on('repaint__done', function () {
  3620. _this7.clipRepaint(-_this7.top);
  3621. }); // 计算列表应该分割成几页
  3622. this.calPageData(); // 计算分页数据:每个元素应该坐落在哪个canvas
  3623. this.renderChildren(this);
  3624. this.insertElements(0);
  3625. this.clipRepaint(-this.top); // 图片加载可能是异步的,监听图片加载完成事件完成列表重绘逻辑
  3626. this.EE.on('image__render__done', function (img) {
  3627. _this7.throttleImageLoadDone(img);
  3628. });
  3629. if (this.scrollHeight > this.layoutBox.height) {
  3630. this.touch.setTouchRange(-(this.scrollHeight - this.layoutBox.height), 0, this.clipRepaint.bind(this)); // 监听触摸相关事件,将滚动处理逻辑交给相应的处理器处理
  3631. this.on('touchstart', this.touch.startFunc);
  3632. this.on('touchmove', this.touch.moveFunc);
  3633. this.on('touchend', this.touch.endFunc);
  3634. }
  3635. }
  3636. }, {
  3637. key: "scrollHeight",
  3638. get: function get() {
  3639. // scrollview为空的情况
  3640. if (!this.children.length) {
  3641. return 0;
  3642. }
  3643. var last = this.children[this.children.length - 1];
  3644. return last.layoutBox.top + last.layoutBox.height;
  3645. }
  3646. }]);
  3647. return ScrollView;
  3648. }(_view_js__WEBPACK_IMPORTED_MODULE_0__["default"]);
  3649. /***/ }),
  3650. /* 21 */
  3651. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3652. "use strict";
  3653. __webpack_require__.r(__webpack_exports__);
  3654. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Touch; });
  3655. /* harmony import */ var _util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
  3656. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3657. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3658. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  3659. var Touch = /*#__PURE__*/function () {
  3660. function Touch() {
  3661. _classCallCheck(this, Touch);
  3662. this.needProcess = false;
  3663. this.startFunc = this.touchStartHandler.bind(this);
  3664. this.endFunc = this.touchEndHandler.bind(this);
  3665. this.moveFunc = this.touchMoveHandler.bind(this);
  3666. }
  3667. _createClass(Touch, [{
  3668. key: "reset",
  3669. value: function reset() {
  3670. this.touchTime = new Date();
  3671. this.touchStartX = 0;
  3672. this.touchStartY = 0; // 滚动区间
  3673. this.start = 0;
  3674. this.end = 0; // 当前位置
  3675. this.move = 0; // 目标位置
  3676. this.target = 0; // 滚动回调函数
  3677. this.scroll = null; // for istanbul
  3678. /* istanbul ignore if*/
  3679. if (typeof cancelAnimationFrame !== 'undefined') {
  3680. cancelAnimationFrame(this.animate);
  3681. }
  3682. }
  3683. }, {
  3684. key: "enable",
  3685. value: function enable() {
  3686. this.reset();
  3687. this.needProcess = true;
  3688. }
  3689. }, {
  3690. key: "disable",
  3691. value: function disable() {
  3692. this.needProcess = false;
  3693. } // 设置滚动区间,比如一个排行榜的滚动区间可能是[-300, 0]
  3694. }, {
  3695. key: "setTouchRange",
  3696. value: function setTouchRange(start, end, scroll) {
  3697. // 考虑到切换游戏的场景,每次设置的时候重置所有变量
  3698. this.enable();
  3699. this.start = start;
  3700. this.end = end;
  3701. if (start === 0 && end === 0) {
  3702. return;
  3703. }
  3704. this.scroll = scroll; // this.animate = requestAnimationFrame(this.loop.bind(this));
  3705. } // 保证滚动目标位置在滚动区间内
  3706. }, {
  3707. key: "limitTarget",
  3708. value: function limitTarget(target) {
  3709. var result = target;
  3710. if (target > this.end) {
  3711. result = this.end;
  3712. } else if (target < this.start) {
  3713. result = this.start;
  3714. }
  3715. return result;
  3716. }
  3717. }, {
  3718. key: "touchStartHandler",
  3719. value: function touchStartHandler(e) {
  3720. var touch = e.touches && e.touches[0] || e.changedTouches && e.changedTouches[0] || e;
  3721. if (!touch || !touch.pageX || !touch.pageY) {
  3722. return;
  3723. }
  3724. var dpr = Object(_util_js__WEBPACK_IMPORTED_MODULE_0__["getDpr"])();
  3725. this.touchStartX = touch.clientX * dpr;
  3726. this.touchStartY = touch.clientY * dpr;
  3727. this.touchTime = new Date();
  3728. this.isMoving = true;
  3729. this.needProcess = true;
  3730. this.animate = requestAnimationFrame(this.loop.bind(this));
  3731. }
  3732. }, {
  3733. key: "touchMoveHandler",
  3734. value: function touchMoveHandler(e) {
  3735. if (!this.isMoving) {
  3736. return;
  3737. }
  3738. var touch = e.touches && e.touches[0] || e.changedTouches && e.changedTouches[0] || e;
  3739. if (!touch || !touch.pageX || !touch.pageY) {
  3740. return;
  3741. }
  3742. var dpr = Object(_util_js__WEBPACK_IMPORTED_MODULE_0__["getDpr"])();
  3743. var currY = touch.clientY * dpr;
  3744. if (this.touchStartY - currY > 2 || this.touchStartY - currY < -2) {
  3745. this.target -= this.touchStartY - currY;
  3746. }
  3747. this.target = this.limitTarget(this.target);
  3748. this.touchStartY = currY;
  3749. }
  3750. }, {
  3751. key: "touchEndHandler",
  3752. value: function touchEndHandler() {
  3753. this.isMoving = false;
  3754. var timeInS = (Date.now() - this.touchTime) / 1000;
  3755. /*console.log(Date.now(), this.touchTime.getTime(), Date.now() - this.touchTime);*/
  3756. if (timeInS < 0.9) {
  3757. /*console.log(1, timeInS, this.target, this.move);*/
  3758. this.target += (this.target - this.move) * 0.6 / (timeInS * 5);
  3759. /*console.log(2, this.target)*/
  3760. this.target = this.limitTarget(this.target);
  3761. /*console.log(3, this.target)*/
  3762. }
  3763. }
  3764. }, {
  3765. key: "loop",
  3766. value: function loop() {
  3767. if (this.needProcess) {
  3768. if (this.isMoving) {
  3769. if (this.move !== this.target) {
  3770. // 手指移动可能过快,切片以使得滑动流畅
  3771. if (Math.abs(this.target - this.move) > 1) {
  3772. this.move += (this.target - this.move) * 0.4;
  3773. } else {
  3774. this.move = this.target;
  3775. }
  3776. this.scroll && this.scroll(this.move);
  3777. }
  3778. } else {
  3779. if (this.move !== this.target) {
  3780. /**
  3781. * 如果滑动很快,为了滚动流畅,需要将滑动过程切片
  3782. */
  3783. if (Math.abs(this.target - this.move) > 1) {
  3784. this.move += (this.target - this.move) * 0.3;
  3785. } else {
  3786. this.move = this.target;
  3787. }
  3788. this.scroll && this.scroll(this.move);
  3789. } else {
  3790. // 滑动结束,停止动画
  3791. this.needProcess = false;
  3792. }
  3793. }
  3794. this.animate = requestAnimationFrame(this.loop.bind(this));
  3795. } else if (typeof cancelAnimationFrame !== 'undefined') {
  3796. cancelAnimationFrame(this.animate);
  3797. }
  3798. }
  3799. }]);
  3800. return Touch;
  3801. }();
  3802. /***/ }),
  3803. /* 22 */
  3804. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3805. "use strict";
  3806. __webpack_require__.r(__webpack_exports__);
  3807. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return BitMapText; });
  3808. /* harmony import */ var _elements_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
  3809. /* harmony import */ var _common_pool_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
  3810. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3811. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3812. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3813. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  3814. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  3815. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  3816. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  3817. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  3818. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  3819. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  3820. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  3821. var bitMapPool = new _common_pool_js__WEBPACK_IMPORTED_MODULE_1__["default"]('bitMapPool');
  3822. var BitMapText = /*#__PURE__*/function (_Element) {
  3823. _inherits(BitMapText, _Element);
  3824. var _super = _createSuper(BitMapText);
  3825. function BitMapText(opts) {
  3826. var _this;
  3827. _classCallCheck(this, BitMapText);
  3828. var _opts$style = opts.style,
  3829. style = _opts$style === void 0 ? {} : _opts$style,
  3830. _opts$props = opts.props,
  3831. props = _opts$props === void 0 ? {} : _opts$props,
  3832. _opts$idName = opts.idName,
  3833. idName = _opts$idName === void 0 ? '' : _opts$idName,
  3834. _opts$className = opts.className,
  3835. className = _opts$className === void 0 ? '' : _opts$className,
  3836. _opts$value = opts.value,
  3837. value = _opts$value === void 0 ? '' : _opts$value,
  3838. _opts$font = opts.font,
  3839. font = _opts$font === void 0 ? '' : _opts$font;
  3840. _this = _super.call(this, {
  3841. props: props,
  3842. idName: idName,
  3843. className: className,
  3844. style: style
  3845. });
  3846. _this.type = "BitMapText";
  3847. _this.ctx = null;
  3848. _this.valuesrc = value;
  3849. _this.renderBoxes = [];
  3850. Object.defineProperty(_assertThisInitialized(_this), "value", {
  3851. get: function get() {
  3852. return this.valuesrc;
  3853. },
  3854. set: function set(newValue) {
  3855. if (newValue !== this.valuesrc) {
  3856. this.valuesrc = newValue;
  3857. this.emit('repaint');
  3858. }
  3859. },
  3860. enumerable: true,
  3861. configurable: true
  3862. });
  3863. _this.font = bitMapPool.get(font);
  3864. if (!_this.font) {
  3865. console.error('Please invoke API `registBitMapFont` before using `BitMapText`');
  3866. }
  3867. return _this;
  3868. }
  3869. _createClass(BitMapText, [{
  3870. key: "insert",
  3871. value: function insert(ctx, box) {
  3872. this.renderBoxes.push({
  3873. ctx: ctx,
  3874. box: box
  3875. });
  3876. this.render(ctx, box);
  3877. }
  3878. }, {
  3879. key: "repaint",
  3880. value: function repaint() {
  3881. var _this2 = this;
  3882. this.renderBoxes.forEach(function (item) {
  3883. _this2.render(item.ctx, item.box);
  3884. });
  3885. }
  3886. }, {
  3887. key: "destroySelf",
  3888. value: function destroySelf() {
  3889. this.root = null;
  3890. }
  3891. }, {
  3892. key: "render",
  3893. value: function render(ctx, layoutBox) {
  3894. var _this3 = this;
  3895. if (!this.font) {
  3896. return;
  3897. }
  3898. if (this.font.ready) {
  3899. this.renderText(ctx, layoutBox);
  3900. } else {
  3901. this.font.event.on('text__load__done', function () {
  3902. if (!_this3.isDestroyed) {
  3903. _this3.renderText(ctx, layoutBox);
  3904. }
  3905. });
  3906. }
  3907. }
  3908. }, {
  3909. key: "getTextBounds",
  3910. value: function getTextBounds() {
  3911. var style = this.style;
  3912. var _style$letterSpacing = style.letterSpacing,
  3913. letterSpacing = _style$letterSpacing === void 0 ? 0 : _style$letterSpacing;
  3914. var width = 0;
  3915. for (var i = 0, len = this.value.length; i < len; i++) {
  3916. var _char = this.value[i];
  3917. var cfg = this.font.chars[_char];
  3918. if (cfg) {
  3919. width += cfg.w;
  3920. if (i < len - 1) {
  3921. width += letterSpacing;
  3922. }
  3923. }
  3924. }
  3925. return {
  3926. width: width,
  3927. height: this.font.lineHeight
  3928. };
  3929. }
  3930. }, {
  3931. key: "renderText",
  3932. value: function renderText(ctx, layoutBox) {
  3933. var bounds = this.getTextBounds();
  3934. var defaultLineHeight = this.font.lineHeight;
  3935. ctx.save();
  3936. this.renderBorder(ctx, layoutBox);
  3937. var box = layoutBox || this.layoutBox;
  3938. var style = this.style;
  3939. var width = style.width,
  3940. height = style.height,
  3941. _style$lineHeight = style.lineHeight,
  3942. lineHeight = _style$lineHeight === void 0 ? defaultLineHeight : _style$lineHeight,
  3943. textAlign = style.textAlign,
  3944. verticalAlign = style.verticalAlign; // 元素包围盒的左上角坐标
  3945. var x = box.absoluteX;
  3946. var y = box.absoluteY;
  3947. var scaleY = lineHeight / defaultLineHeight;
  3948. var realWidth = scaleY * bounds.width; // 如果文字的渲染区域高度小于盒子高度,采用对齐方式
  3949. if (lineHeight < height) {
  3950. if (verticalAlign === 'middle') {
  3951. y += (height - lineHeight) / 2;
  3952. } else if (verticalAlign === 'bottom') {
  3953. y = y + height - lineHeight;
  3954. }
  3955. }
  3956. if (width > realWidth) {
  3957. if (textAlign === 'center') {
  3958. x += (width - realWidth) / 2;
  3959. } else if (textAlign === 'right') {
  3960. x += width - realWidth;
  3961. }
  3962. }
  3963. for (var i = 0; i < this.value.length; i++) {
  3964. var _char2 = this.value[i];
  3965. var cfg = this.font.chars[_char2];
  3966. if (cfg) {
  3967. ctx.drawImage(this.font.texture, cfg.x, cfg.y, cfg.w, cfg.h, x + cfg.offX * scaleY, y + cfg.offY * scaleY, cfg.w * scaleY, cfg.h * scaleY);
  3968. x += cfg.w * scaleY;
  3969. }
  3970. }
  3971. }
  3972. }]);
  3973. return BitMapText;
  3974. }(_elements_js__WEBPACK_IMPORTED_MODULE_0__["default"]);
  3975. /***/ })
  3976. /******/ ]);