12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657 |
- (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
- 'use strict'
- exports.byteLength = byteLength
- exports.toByteArray = toByteArray
- exports.fromByteArray = fromByteArray
- var lookup = []
- var revLookup = []
- var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
- var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
- for (var i = 0, len = code.length; i < len; ++i) {
- lookup[i] = code[i]
- revLookup[code.charCodeAt(i)] = i
- }
- revLookup['-'.charCodeAt(0)] = 62
- revLookup['_'.charCodeAt(0)] = 63
- function getLens (b64) {
- var len = b64.length
- if (len % 4 > 0) {
- throw new Error('Invalid string. Length must be a multiple of 4')
- }
-
-
- var validLen = b64.indexOf('=')
- if (validLen === -1) validLen = len
- var placeHoldersLen = validLen === len
- ? 0
- : 4 - (validLen % 4)
- return [validLen, placeHoldersLen]
- }
- function byteLength (b64) {
- var lens = getLens(b64)
- var validLen = lens[0]
- var placeHoldersLen = lens[1]
- return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
- }
- function _byteLength (b64, validLen, placeHoldersLen) {
- return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
- }
- function toByteArray (b64) {
- var tmp
- var lens = getLens(b64)
- var validLen = lens[0]
- var placeHoldersLen = lens[1]
- var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
- var curByte = 0
-
- var len = placeHoldersLen > 0
- ? validLen - 4
- : validLen
- var i
- for (i = 0; i < len; i += 4) {
- tmp =
- (revLookup[b64.charCodeAt(i)] << 18) |
- (revLookup[b64.charCodeAt(i + 1)] << 12) |
- (revLookup[b64.charCodeAt(i + 2)] << 6) |
- revLookup[b64.charCodeAt(i + 3)]
- arr[curByte++] = (tmp >> 16) & 0xFF
- arr[curByte++] = (tmp >> 8) & 0xFF
- arr[curByte++] = tmp & 0xFF
- }
- if (placeHoldersLen === 2) {
- tmp =
- (revLookup[b64.charCodeAt(i)] << 2) |
- (revLookup[b64.charCodeAt(i + 1)] >> 4)
- arr[curByte++] = tmp & 0xFF
- }
- if (placeHoldersLen === 1) {
- tmp =
- (revLookup[b64.charCodeAt(i)] << 10) |
- (revLookup[b64.charCodeAt(i + 1)] << 4) |
- (revLookup[b64.charCodeAt(i + 2)] >> 2)
- arr[curByte++] = (tmp >> 8) & 0xFF
- arr[curByte++] = tmp & 0xFF
- }
- return arr
- }
- function tripletToBase64 (num) {
- return lookup[num >> 18 & 0x3F] +
- lookup[num >> 12 & 0x3F] +
- lookup[num >> 6 & 0x3F] +
- lookup[num & 0x3F]
- }
- function encodeChunk (uint8, start, end) {
- var tmp
- var output = []
- for (var i = start; i < end; i += 3) {
- tmp =
- ((uint8[i] << 16) & 0xFF0000) +
- ((uint8[i + 1] << 8) & 0xFF00) +
- (uint8[i + 2] & 0xFF)
- output.push(tripletToBase64(tmp))
- }
- return output.join('')
- }
- function fromByteArray (uint8) {
- var tmp
- var len = uint8.length
- var extraBytes = len % 3
- var parts = []
- var maxChunkLength = 16383
-
- for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
- parts.push(encodeChunk(
- uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
- ))
- }
-
- if (extraBytes === 1) {
- tmp = uint8[len - 1]
- parts.push(
- lookup[tmp >> 2] +
- lookup[(tmp << 4) & 0x3F] +
- '=='
- )
- } else if (extraBytes === 2) {
- tmp = (uint8[len - 2] << 8) + uint8[len - 1]
- parts.push(
- lookup[tmp >> 10] +
- lookup[(tmp >> 4) & 0x3F] +
- lookup[(tmp << 2) & 0x3F] +
- '='
- )
- }
- return parts.join('')
- }
- },{}],2:[function(require,module,exports){
- (function (Buffer){
- 'use strict'
- var base64 = require('base64-js')
- var ieee754 = require('ieee754')
- exports.Buffer = Buffer
- exports.SlowBuffer = SlowBuffer
- exports.INSPECT_MAX_BYTES = 50
- var K_MAX_LENGTH = 0x7fffffff
- exports.kMaxLength = K_MAX_LENGTH
- Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
- if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
- typeof console.error === 'function') {
- console.error(
- 'This browser lacks typed array (Uint8Array) support which is required by ' +
- '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
- )
- }
- function typedArraySupport () {
-
- try {
- var arr = new Uint8Array(1)
- arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
- return arr.foo() === 42
- } catch (e) {
- return false
- }
- }
- Object.defineProperty(Buffer.prototype, 'parent', {
- enumerable: true,
- get: function () {
- if (!Buffer.isBuffer(this)) return undefined
- return this.buffer
- }
- })
- Object.defineProperty(Buffer.prototype, 'offset', {
- enumerable: true,
- get: function () {
- if (!Buffer.isBuffer(this)) return undefined
- return this.byteOffset
- }
- })
- function createBuffer (length) {
- if (length > K_MAX_LENGTH) {
- throw new RangeError('The value "' + length + '" is invalid for option "size"')
- }
-
- var buf = new Uint8Array(length)
- buf.__proto__ = Buffer.prototype
- return buf
- }
- function Buffer (arg, encodingOrOffset, length) {
-
- if (typeof arg === 'number') {
- if (typeof encodingOrOffset === 'string') {
- throw new TypeError(
- 'The "string" argument must be of type string. Received type number'
- )
- }
- return allocUnsafe(arg)
- }
- return from(arg, encodingOrOffset, length)
- }
- if (typeof Symbol !== 'undefined' && Symbol.species != null &&
- Buffer[Symbol.species] === Buffer) {
- Object.defineProperty(Buffer, Symbol.species, {
- value: null,
- configurable: true,
- enumerable: false,
- writable: false
- })
- }
- Buffer.poolSize = 8192
- function from (value, encodingOrOffset, length) {
- if (typeof value === 'string') {
- return fromString(value, encodingOrOffset)
- }
- if (ArrayBuffer.isView(value)) {
- return fromArrayLike(value)
- }
- if (value == null) {
- throw TypeError(
- 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
- 'or Array-like Object. Received type ' + (typeof value)
- )
- }
- if (isInstance(value, ArrayBuffer) ||
- (value && isInstance(value.buffer, ArrayBuffer))) {
- return fromArrayBuffer(value, encodingOrOffset, length)
- }
- if (typeof value === 'number') {
- throw new TypeError(
- 'The "value" argument must not be of type number. Received type number'
- )
- }
- var valueOf = value.valueOf && value.valueOf()
- if (valueOf != null && valueOf !== value) {
- return Buffer.from(valueOf, encodingOrOffset, length)
- }
- var b = fromObject(value)
- if (b) return b
- if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
- typeof value[Symbol.toPrimitive] === 'function') {
- return Buffer.from(
- value[Symbol.toPrimitive]('string'), encodingOrOffset, length
- )
- }
- throw new TypeError(
- 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
- 'or Array-like Object. Received type ' + (typeof value)
- )
- }
- Buffer.from = function (value, encodingOrOffset, length) {
- return from(value, encodingOrOffset, length)
- }
- Buffer.prototype.__proto__ = Uint8Array.prototype
- Buffer.__proto__ = Uint8Array
- function assertSize (size) {
- if (typeof size !== 'number') {
- throw new TypeError('"size" argument must be of type number')
- } else if (size < 0) {
- throw new RangeError('The value "' + size + '" is invalid for option "size"')
- }
- }
- function alloc (size, fill, encoding) {
- assertSize(size)
- if (size <= 0) {
- return createBuffer(size)
- }
- if (fill !== undefined) {
-
-
-
- return typeof encoding === 'string'
- ? createBuffer(size).fill(fill, encoding)
- : createBuffer(size).fill(fill)
- }
- return createBuffer(size)
- }
- Buffer.alloc = function (size, fill, encoding) {
- return alloc(size, fill, encoding)
- }
- function allocUnsafe (size) {
- assertSize(size)
- return createBuffer(size < 0 ? 0 : checked(size) | 0)
- }
- Buffer.allocUnsafe = function (size) {
- return allocUnsafe(size)
- }
- Buffer.allocUnsafeSlow = function (size) {
- return allocUnsafe(size)
- }
- function fromString (string, encoding) {
- if (typeof encoding !== 'string' || encoding === '') {
- encoding = 'utf8'
- }
- if (!Buffer.isEncoding(encoding)) {
- throw new TypeError('Unknown encoding: ' + encoding)
- }
- var length = byteLength(string, encoding) | 0
- var buf = createBuffer(length)
- var actual = buf.write(string, encoding)
- if (actual !== length) {
-
-
-
- buf = buf.slice(0, actual)
- }
- return buf
- }
- function fromArrayLike (array) {
- var length = array.length < 0 ? 0 : checked(array.length) | 0
- var buf = createBuffer(length)
- for (var i = 0; i < length; i += 1) {
- buf[i] = array[i] & 255
- }
- return buf
- }
- function fromArrayBuffer (array, byteOffset, length) {
- if (byteOffset < 0 || array.byteLength < byteOffset) {
- throw new RangeError('"offset" is outside of buffer bounds')
- }
- if (array.byteLength < byteOffset + (length || 0)) {
- throw new RangeError('"length" is outside of buffer bounds')
- }
- var buf
- if (byteOffset === undefined && length === undefined) {
- buf = new Uint8Array(array)
- } else if (length === undefined) {
- buf = new Uint8Array(array, byteOffset)
- } else {
- buf = new Uint8Array(array, byteOffset, length)
- }
-
- buf.__proto__ = Buffer.prototype
- return buf
- }
- function fromObject (obj) {
- if (Buffer.isBuffer(obj)) {
- var len = checked(obj.length) | 0
- var buf = createBuffer(len)
- if (buf.length === 0) {
- return buf
- }
- obj.copy(buf, 0, 0, len)
- return buf
- }
- if (obj.length !== undefined) {
- if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
- return createBuffer(0)
- }
- return fromArrayLike(obj)
- }
- if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
- return fromArrayLike(obj.data)
- }
- }
- function checked (length) {
-
-
- if (length >= K_MAX_LENGTH) {
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
- 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
- }
- return length | 0
- }
- function SlowBuffer (length) {
- if (+length != length) {
- length = 0
- }
- return Buffer.alloc(+length)
- }
- Buffer.isBuffer = function isBuffer (b) {
- return b != null && b._isBuffer === true &&
- b !== Buffer.prototype
- }
- Buffer.compare = function compare (a, b) {
- if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
- if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
- if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
- throw new TypeError(
- 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
- )
- }
- if (a === b) return 0
- var x = a.length
- var y = b.length
- for (var i = 0, len = Math.min(x, y); i < len; ++i) {
- if (a[i] !== b[i]) {
- x = a[i]
- y = b[i]
- break
- }
- }
- if (x < y) return -1
- if (y < x) return 1
- return 0
- }
- Buffer.isEncoding = function isEncoding (encoding) {
- switch (String(encoding).toLowerCase()) {
- case 'hex':
- case 'utf8':
- case 'utf-8':
- case 'ascii':
- case 'latin1':
- case 'binary':
- case 'base64':
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return true
- default:
- return false
- }
- }
- Buffer.concat = function concat (list, length) {
- if (!Array.isArray(list)) {
- throw new TypeError('"list" argument must be an Array of Buffers')
- }
- if (list.length === 0) {
- return Buffer.alloc(0)
- }
- var i
- if (length === undefined) {
- length = 0
- for (i = 0; i < list.length; ++i) {
- length += list[i].length
- }
- }
- var buffer = Buffer.allocUnsafe(length)
- var pos = 0
- for (i = 0; i < list.length; ++i) {
- var buf = list[i]
- if (isInstance(buf, Uint8Array)) {
- buf = Buffer.from(buf)
- }
- if (!Buffer.isBuffer(buf)) {
- throw new TypeError('"list" argument must be an Array of Buffers')
- }
- buf.copy(buffer, pos)
- pos += buf.length
- }
- return buffer
- }
- function byteLength (string, encoding) {
- if (Buffer.isBuffer(string)) {
- return string.length
- }
- if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
- return string.byteLength
- }
- if (typeof string !== 'string') {
- throw new TypeError(
- 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
- 'Received type ' + typeof string
- )
- }
- var len = string.length
- var mustMatch = (arguments.length > 2 && arguments[2] === true)
- if (!mustMatch && len === 0) return 0
-
- var loweredCase = false
- for (;;) {
- switch (encoding) {
- case 'ascii':
- case 'latin1':
- case 'binary':
- return len
- case 'utf8':
- case 'utf-8':
- return utf8ToBytes(string).length
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return len * 2
- case 'hex':
- return len >>> 1
- case 'base64':
- return base64ToBytes(string).length
- default:
- if (loweredCase) {
- return mustMatch ? -1 : utf8ToBytes(string).length
- }
- encoding = ('' + encoding).toLowerCase()
- loweredCase = true
- }
- }
- }
- Buffer.byteLength = byteLength
- function slowToString (encoding, start, end) {
- var loweredCase = false
-
-
-
-
-
-
- if (start === undefined || start < 0) {
- start = 0
- }
-
-
- if (start > this.length) {
- return ''
- }
- if (end === undefined || end > this.length) {
- end = this.length
- }
- if (end <= 0) {
- return ''
- }
-
- end >>>= 0
- start >>>= 0
- if (end <= start) {
- return ''
- }
- if (!encoding) encoding = 'utf8'
- while (true) {
- switch (encoding) {
- case 'hex':
- return hexSlice(this, start, end)
- case 'utf8':
- case 'utf-8':
- return utf8Slice(this, start, end)
- case 'ascii':
- return asciiSlice(this, start, end)
- case 'latin1':
- case 'binary':
- return latin1Slice(this, start, end)
- case 'base64':
- return base64Slice(this, start, end)
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return utf16leSlice(this, start, end)
- default:
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
- encoding = (encoding + '').toLowerCase()
- loweredCase = true
- }
- }
- }
- Buffer.prototype._isBuffer = true
- function swap (b, n, m) {
- var i = b[n]
- b[n] = b[m]
- b[m] = i
- }
- Buffer.prototype.swap16 = function swap16 () {
- var len = this.length
- if (len % 2 !== 0) {
- throw new RangeError('Buffer size must be a multiple of 16-bits')
- }
- for (var i = 0; i < len; i += 2) {
- swap(this, i, i + 1)
- }
- return this
- }
- Buffer.prototype.swap32 = function swap32 () {
- var len = this.length
- if (len % 4 !== 0) {
- throw new RangeError('Buffer size must be a multiple of 32-bits')
- }
- for (var i = 0; i < len; i += 4) {
- swap(this, i, i + 3)
- swap(this, i + 1, i + 2)
- }
- return this
- }
- Buffer.prototype.swap64 = function swap64 () {
- var len = this.length
- if (len % 8 !== 0) {
- throw new RangeError('Buffer size must be a multiple of 64-bits')
- }
- for (var i = 0; i < len; i += 8) {
- swap(this, i, i + 7)
- swap(this, i + 1, i + 6)
- swap(this, i + 2, i + 5)
- swap(this, i + 3, i + 4)
- }
- return this
- }
- Buffer.prototype.toString = function toString () {
- var length = this.length
- if (length === 0) return ''
- if (arguments.length === 0) return utf8Slice(this, 0, length)
- return slowToString.apply(this, arguments)
- }
- Buffer.prototype.toLocaleString = Buffer.prototype.toString
- Buffer.prototype.equals = function equals (b) {
- if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
- if (this === b) return true
- return Buffer.compare(this, b) === 0
- }
- Buffer.prototype.inspect = function inspect () {
- var str = ''
- var max = exports.INSPECT_MAX_BYTES
- str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
- if (this.length > max) str += ' ... '
- return '<Buffer ' + str + '>'
- }
- Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
- if (isInstance(target, Uint8Array)) {
- target = Buffer.from(target, target.offset, target.byteLength)
- }
- if (!Buffer.isBuffer(target)) {
- throw new TypeError(
- 'The "target" argument must be one of type Buffer or Uint8Array. ' +
- 'Received type ' + (typeof target)
- )
- }
- if (start === undefined) {
- start = 0
- }
- if (end === undefined) {
- end = target ? target.length : 0
- }
- if (thisStart === undefined) {
- thisStart = 0
- }
- if (thisEnd === undefined) {
- thisEnd = this.length
- }
- if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
- throw new RangeError('out of range index')
- }
- if (thisStart >= thisEnd && start >= end) {
- return 0
- }
- if (thisStart >= thisEnd) {
- return -1
- }
- if (start >= end) {
- return 1
- }
- start >>>= 0
- end >>>= 0
- thisStart >>>= 0
- thisEnd >>>= 0
- if (this === target) return 0
- var x = thisEnd - thisStart
- var y = end - start
- var len = Math.min(x, y)
- var thisCopy = this.slice(thisStart, thisEnd)
- var targetCopy = target.slice(start, end)
- for (var i = 0; i < len; ++i) {
- if (thisCopy[i] !== targetCopy[i]) {
- x = thisCopy[i]
- y = targetCopy[i]
- break
- }
- }
- if (x < y) return -1
- if (y < x) return 1
- return 0
- }
- function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
-
- if (buffer.length === 0) return -1
-
- if (typeof byteOffset === 'string') {
- encoding = byteOffset
- byteOffset = 0
- } else if (byteOffset > 0x7fffffff) {
- byteOffset = 0x7fffffff
- } else if (byteOffset < -0x80000000) {
- byteOffset = -0x80000000
- }
- byteOffset = +byteOffset
- if (numberIsNaN(byteOffset)) {
-
- byteOffset = dir ? 0 : (buffer.length - 1)
- }
-
- if (byteOffset < 0) byteOffset = buffer.length + byteOffset
- if (byteOffset >= buffer.length) {
- if (dir) return -1
- else byteOffset = buffer.length - 1
- } else if (byteOffset < 0) {
- if (dir) byteOffset = 0
- else return -1
- }
-
- if (typeof val === 'string') {
- val = Buffer.from(val, encoding)
- }
-
- if (Buffer.isBuffer(val)) {
-
- if (val.length === 0) {
- return -1
- }
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
- } else if (typeof val === 'number') {
- val = val & 0xFF
- if (typeof Uint8Array.prototype.indexOf === 'function') {
- if (dir) {
- return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
- } else {
- return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
- }
- }
- return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
- }
- throw new TypeError('val must be string, number or Buffer')
- }
- function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
- var indexSize = 1
- var arrLength = arr.length
- var valLength = val.length
- if (encoding !== undefined) {
- encoding = String(encoding).toLowerCase()
- if (encoding === 'ucs2' || encoding === 'ucs-2' ||
- encoding === 'utf16le' || encoding === 'utf-16le') {
- if (arr.length < 2 || val.length < 2) {
- return -1
- }
- indexSize = 2
- arrLength /= 2
- valLength /= 2
- byteOffset /= 2
- }
- }
- function read (buf, i) {
- if (indexSize === 1) {
- return buf[i]
- } else {
- return buf.readUInt16BE(i * indexSize)
- }
- }
- var i
- if (dir) {
- var foundIndex = -1
- for (i = byteOffset; i < arrLength; i++) {
- if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
- if (foundIndex === -1) foundIndex = i
- if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
- } else {
- if (foundIndex !== -1) i -= i - foundIndex
- foundIndex = -1
- }
- }
- } else {
- if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
- for (i = byteOffset; i >= 0; i--) {
- var found = true
- for (var j = 0; j < valLength; j++) {
- if (read(arr, i + j) !== read(val, j)) {
- found = false
- break
- }
- }
- if (found) return i
- }
- }
- return -1
- }
- Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
- return this.indexOf(val, byteOffset, encoding) !== -1
- }
- Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
- }
- Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
- }
- function hexWrite (buf, string, offset, length) {
- offset = Number(offset) || 0
- var remaining = buf.length - offset
- if (!length) {
- length = remaining
- } else {
- length = Number(length)
- if (length > remaining) {
- length = remaining
- }
- }
- var strLen = string.length
- if (length > strLen / 2) {
- length = strLen / 2
- }
- for (var i = 0; i < length; ++i) {
- var parsed = parseInt(string.substr(i * 2, 2), 16)
- if (numberIsNaN(parsed)) return i
- buf[offset + i] = parsed
- }
- return i
- }
- function utf8Write (buf, string, offset, length) {
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
- }
- function asciiWrite (buf, string, offset, length) {
- return blitBuffer(asciiToBytes(string), buf, offset, length)
- }
- function latin1Write (buf, string, offset, length) {
- return asciiWrite(buf, string, offset, length)
- }
- function base64Write (buf, string, offset, length) {
- return blitBuffer(base64ToBytes(string), buf, offset, length)
- }
- function ucs2Write (buf, string, offset, length) {
- return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
- }
- Buffer.prototype.write = function write (string, offset, length, encoding) {
-
- if (offset === undefined) {
- encoding = 'utf8'
- length = this.length
- offset = 0
-
- } else if (length === undefined && typeof offset === 'string') {
- encoding = offset
- length = this.length
- offset = 0
-
- } else if (isFinite(offset)) {
- offset = offset >>> 0
- if (isFinite(length)) {
- length = length >>> 0
- if (encoding === undefined) encoding = 'utf8'
- } else {
- encoding = length
- length = undefined
- }
- } else {
- throw new Error(
- 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
- )
- }
- var remaining = this.length - offset
- if (length === undefined || length > remaining) length = remaining
- if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
- throw new RangeError('Attempt to write outside buffer bounds')
- }
- if (!encoding) encoding = 'utf8'
- var loweredCase = false
- for (;;) {
- switch (encoding) {
- case 'hex':
- return hexWrite(this, string, offset, length)
- case 'utf8':
- case 'utf-8':
- return utf8Write(this, string, offset, length)
- case 'ascii':
- return asciiWrite(this, string, offset, length)
- case 'latin1':
- case 'binary':
- return latin1Write(this, string, offset, length)
- case 'base64':
-
- return base64Write(this, string, offset, length)
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return ucs2Write(this, string, offset, length)
- default:
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
- encoding = ('' + encoding).toLowerCase()
- loweredCase = true
- }
- }
- }
- Buffer.prototype.toJSON = function toJSON () {
- return {
- type: 'Buffer',
- data: Array.prototype.slice.call(this._arr || this, 0)
- }
- }
- function base64Slice (buf, start, end) {
- if (start === 0 && end === buf.length) {
- return base64.fromByteArray(buf)
- } else {
- return base64.fromByteArray(buf.slice(start, end))
- }
- }
- function utf8Slice (buf, start, end) {
- end = Math.min(buf.length, end)
- var res = []
- var i = start
- while (i < end) {
- var firstByte = buf[i]
- var codePoint = null
- var bytesPerSequence = (firstByte > 0xEF) ? 4
- : (firstByte > 0xDF) ? 3
- : (firstByte > 0xBF) ? 2
- : 1
- if (i + bytesPerSequence <= end) {
- var secondByte, thirdByte, fourthByte, tempCodePoint
- switch (bytesPerSequence) {
- case 1:
- if (firstByte < 0x80) {
- codePoint = firstByte
- }
- break
- case 2:
- secondByte = buf[i + 1]
- if ((secondByte & 0xC0) === 0x80) {
- tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
- if (tempCodePoint > 0x7F) {
- codePoint = tempCodePoint
- }
- }
- break
- case 3:
- secondByte = buf[i + 1]
- thirdByte = buf[i + 2]
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
- tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
- if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
- codePoint = tempCodePoint
- }
- }
- break
- case 4:
- secondByte = buf[i + 1]
- thirdByte = buf[i + 2]
- fourthByte = buf[i + 3]
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
- tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
- if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
- codePoint = tempCodePoint
- }
- }
- }
- }
- if (codePoint === null) {
-
-
- codePoint = 0xFFFD
- bytesPerSequence = 1
- } else if (codePoint > 0xFFFF) {
-
- codePoint -= 0x10000
- res.push(codePoint >>> 10 & 0x3FF | 0xD800)
- codePoint = 0xDC00 | codePoint & 0x3FF
- }
- res.push(codePoint)
- i += bytesPerSequence
- }
- return decodeCodePointsArray(res)
- }
- var MAX_ARGUMENTS_LENGTH = 0x1000
- function decodeCodePointsArray (codePoints) {
- var len = codePoints.length
- if (len <= MAX_ARGUMENTS_LENGTH) {
- return String.fromCharCode.apply(String, codePoints)
- }
-
- var res = ''
- var i = 0
- while (i < len) {
- res += String.fromCharCode.apply(
- String,
- codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
- )
- }
- return res
- }
- function asciiSlice (buf, start, end) {
- var ret = ''
- end = Math.min(buf.length, end)
- for (var i = start; i < end; ++i) {
- ret += String.fromCharCode(buf[i] & 0x7F)
- }
- return ret
- }
- function latin1Slice (buf, start, end) {
- var ret = ''
- end = Math.min(buf.length, end)
- for (var i = start; i < end; ++i) {
- ret += String.fromCharCode(buf[i])
- }
- return ret
- }
- function hexSlice (buf, start, end) {
- var len = buf.length
- if (!start || start < 0) start = 0
- if (!end || end < 0 || end > len) end = len
- var out = ''
- for (var i = start; i < end; ++i) {
- out += toHex(buf[i])
- }
- return out
- }
- function utf16leSlice (buf, start, end) {
- var bytes = buf.slice(start, end)
- var res = ''
- for (var i = 0; i < bytes.length; i += 2) {
- res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
- }
- return res
- }
- Buffer.prototype.slice = function slice (start, end) {
- var len = this.length
- start = ~~start
- end = end === undefined ? len : ~~end
- if (start < 0) {
- start += len
- if (start < 0) start = 0
- } else if (start > len) {
- start = len
- }
- if (end < 0) {
- end += len
- if (end < 0) end = 0
- } else if (end > len) {
- end = len
- }
- if (end < start) end = start
- var newBuf = this.subarray(start, end)
-
- newBuf.__proto__ = Buffer.prototype
- return newBuf
- }
- function checkOffset (offset, ext, length) {
- if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
- if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
- }
- Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
- offset = offset >>> 0
- byteLength = byteLength >>> 0
- if (!noAssert) checkOffset(offset, byteLength, this.length)
- var val = this[offset]
- var mul = 1
- var i = 0
- while (++i < byteLength && (mul *= 0x100)) {
- val += this[offset + i] * mul
- }
- return val
- }
- Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
- offset = offset >>> 0
- byteLength = byteLength >>> 0
- if (!noAssert) {
- checkOffset(offset, byteLength, this.length)
- }
- var val = this[offset + --byteLength]
- var mul = 1
- while (byteLength > 0 && (mul *= 0x100)) {
- val += this[offset + --byteLength] * mul
- }
- return val
- }
- Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 1, this.length)
- return this[offset]
- }
- Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 2, this.length)
- return this[offset] | (this[offset + 1] << 8)
- }
- Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 2, this.length)
- return (this[offset] << 8) | this[offset + 1]
- }
- Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 4, this.length)
- return ((this[offset]) |
- (this[offset + 1] << 8) |
- (this[offset + 2] << 16)) +
- (this[offset + 3] * 0x1000000)
- }
- Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 4, this.length)
- return (this[offset] * 0x1000000) +
- ((this[offset + 1] << 16) |
- (this[offset + 2] << 8) |
- this[offset + 3])
- }
- Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
- offset = offset >>> 0
- byteLength = byteLength >>> 0
- if (!noAssert) checkOffset(offset, byteLength, this.length)
- var val = this[offset]
- var mul = 1
- var i = 0
- while (++i < byteLength && (mul *= 0x100)) {
- val += this[offset + i] * mul
- }
- mul *= 0x80
- if (val >= mul) val -= Math.pow(2, 8 * byteLength)
- return val
- }
- Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
- offset = offset >>> 0
- byteLength = byteLength >>> 0
- if (!noAssert) checkOffset(offset, byteLength, this.length)
- var i = byteLength
- var mul = 1
- var val = this[offset + --i]
- while (i > 0 && (mul *= 0x100)) {
- val += this[offset + --i] * mul
- }
- mul *= 0x80
- if (val >= mul) val -= Math.pow(2, 8 * byteLength)
- return val
- }
- Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 1, this.length)
- if (!(this[offset] & 0x80)) return (this[offset])
- return ((0xff - this[offset] + 1) * -1)
- }
- Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 2, this.length)
- var val = this[offset] | (this[offset + 1] << 8)
- return (val & 0x8000) ? val | 0xFFFF0000 : val
- }
- Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 2, this.length)
- var val = this[offset + 1] | (this[offset] << 8)
- return (val & 0x8000) ? val | 0xFFFF0000 : val
- }
- Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 4, this.length)
- return (this[offset]) |
- (this[offset + 1] << 8) |
- (this[offset + 2] << 16) |
- (this[offset + 3] << 24)
- }
- Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 4, this.length)
- return (this[offset] << 24) |
- (this[offset + 1] << 16) |
- (this[offset + 2] << 8) |
- (this[offset + 3])
- }
- Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 4, this.length)
- return ieee754.read(this, offset, true, 23, 4)
- }
- Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 4, this.length)
- return ieee754.read(this, offset, false, 23, 4)
- }
- Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 8, this.length)
- return ieee754.read(this, offset, true, 52, 8)
- }
- Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
- offset = offset >>> 0
- if (!noAssert) checkOffset(offset, 8, this.length)
- return ieee754.read(this, offset, false, 52, 8)
- }
- function checkInt (buf, value, offset, ext, max, min) {
- if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
- if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
- }
- Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
- value = +value
- offset = offset >>> 0
- byteLength = byteLength >>> 0
- if (!noAssert) {
- var maxBytes = Math.pow(2, 8 * byteLength) - 1
- checkInt(this, value, offset, byteLength, maxBytes, 0)
- }
- var mul = 1
- var i = 0
- this[offset] = value & 0xFF
- while (++i < byteLength && (mul *= 0x100)) {
- this[offset + i] = (value / mul) & 0xFF
- }
- return offset + byteLength
- }
- Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
- value = +value
- offset = offset >>> 0
- byteLength = byteLength >>> 0
- if (!noAssert) {
- var maxBytes = Math.pow(2, 8 * byteLength) - 1
- checkInt(this, value, offset, byteLength, maxBytes, 0)
- }
- var i = byteLength - 1
- var mul = 1
- this[offset + i] = value & 0xFF
- while (--i >= 0 && (mul *= 0x100)) {
- this[offset + i] = (value / mul) & 0xFF
- }
- return offset + byteLength
- }
- Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
- this[offset] = (value & 0xff)
- return offset + 1
- }
- Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
- this[offset] = (value & 0xff)
- this[offset + 1] = (value >>> 8)
- return offset + 2
- }
- Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
- this[offset] = (value >>> 8)
- this[offset + 1] = (value & 0xff)
- return offset + 2
- }
- Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
- this[offset + 3] = (value >>> 24)
- this[offset + 2] = (value >>> 16)
- this[offset + 1] = (value >>> 8)
- this[offset] = (value & 0xff)
- return offset + 4
- }
- Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
- this[offset] = (value >>> 24)
- this[offset + 1] = (value >>> 16)
- this[offset + 2] = (value >>> 8)
- this[offset + 3] = (value & 0xff)
- return offset + 4
- }
- Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) {
- var limit = Math.pow(2, (8 * byteLength) - 1)
- checkInt(this, value, offset, byteLength, limit - 1, -limit)
- }
- var i = 0
- var mul = 1
- var sub = 0
- this[offset] = value & 0xFF
- while (++i < byteLength && (mul *= 0x100)) {
- if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
- sub = 1
- }
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
- }
- return offset + byteLength
- }
- Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) {
- var limit = Math.pow(2, (8 * byteLength) - 1)
- checkInt(this, value, offset, byteLength, limit - 1, -limit)
- }
- var i = byteLength - 1
- var mul = 1
- var sub = 0
- this[offset + i] = value & 0xFF
- while (--i >= 0 && (mul *= 0x100)) {
- if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
- sub = 1
- }
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
- }
- return offset + byteLength
- }
- Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
- if (value < 0) value = 0xff + value + 1
- this[offset] = (value & 0xff)
- return offset + 1
- }
- Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
- this[offset] = (value & 0xff)
- this[offset + 1] = (value >>> 8)
- return offset + 2
- }
- Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
- this[offset] = (value >>> 8)
- this[offset + 1] = (value & 0xff)
- return offset + 2
- }
- Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
- this[offset] = (value & 0xff)
- this[offset + 1] = (value >>> 8)
- this[offset + 2] = (value >>> 16)
- this[offset + 3] = (value >>> 24)
- return offset + 4
- }
- Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
- if (value < 0) value = 0xffffffff + value + 1
- this[offset] = (value >>> 24)
- this[offset + 1] = (value >>> 16)
- this[offset + 2] = (value >>> 8)
- this[offset + 3] = (value & 0xff)
- return offset + 4
- }
- function checkIEEE754 (buf, value, offset, ext, max, min) {
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
- if (offset < 0) throw new RangeError('Index out of range')
- }
- function writeFloat (buf, value, offset, littleEndian, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) {
- checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
- }
- ieee754.write(buf, value, offset, littleEndian, 23, 4)
- return offset + 4
- }
- Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
- return writeFloat(this, value, offset, true, noAssert)
- }
- Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
- return writeFloat(this, value, offset, false, noAssert)
- }
- function writeDouble (buf, value, offset, littleEndian, noAssert) {
- value = +value
- offset = offset >>> 0
- if (!noAssert) {
- checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
- }
- ieee754.write(buf, value, offset, littleEndian, 52, 8)
- return offset + 8
- }
- Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
- return writeDouble(this, value, offset, true, noAssert)
- }
- Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
- return writeDouble(this, value, offset, false, noAssert)
- }
- Buffer.prototype.copy = function copy (target, targetStart, start, end) {
- if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
- if (!start) start = 0
- if (!end && end !== 0) end = this.length
- if (targetStart >= target.length) targetStart = target.length
- if (!targetStart) targetStart = 0
- if (end > 0 && end < start) end = start
-
- if (end === start) return 0
- if (target.length === 0 || this.length === 0) return 0
-
- if (targetStart < 0) {
- throw new RangeError('targetStart out of bounds')
- }
- if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
- if (end < 0) throw new RangeError('sourceEnd out of bounds')
-
- if (end > this.length) end = this.length
- if (target.length - targetStart < end - start) {
- end = target.length - targetStart + start
- }
- var len = end - start
- if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
-
- this.copyWithin(targetStart, start, end)
- } else if (this === target && start < targetStart && targetStart < end) {
-
- for (var i = len - 1; i >= 0; --i) {
- target[i + targetStart] = this[i + start]
- }
- } else {
- Uint8Array.prototype.set.call(
- target,
- this.subarray(start, end),
- targetStart
- )
- }
- return len
- }
- Buffer.prototype.fill = function fill (val, start, end, encoding) {
-
- if (typeof val === 'string') {
- if (typeof start === 'string') {
- encoding = start
- start = 0
- end = this.length
- } else if (typeof end === 'string') {
- encoding = end
- end = this.length
- }
- if (encoding !== undefined && typeof encoding !== 'string') {
- throw new TypeError('encoding must be a string')
- }
- if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
- throw new TypeError('Unknown encoding: ' + encoding)
- }
- if (val.length === 1) {
- var code = val.charCodeAt(0)
- if ((encoding === 'utf8' && code < 128) ||
- encoding === 'latin1') {
-
- val = code
- }
- }
- } else if (typeof val === 'number') {
- val = val & 255
- }
-
- if (start < 0 || this.length < start || this.length < end) {
- throw new RangeError('Out of range index')
- }
- if (end <= start) {
- return this
- }
- start = start >>> 0
- end = end === undefined ? this.length : end >>> 0
- if (!val) val = 0
- var i
- if (typeof val === 'number') {
- for (i = start; i < end; ++i) {
- this[i] = val
- }
- } else {
- var bytes = Buffer.isBuffer(val)
- ? val
- : Buffer.from(val, encoding)
- var len = bytes.length
- if (len === 0) {
- throw new TypeError('The value "' + val +
- '" is invalid for argument "value"')
- }
- for (i = 0; i < end - start; ++i) {
- this[i + start] = bytes[i % len]
- }
- }
- return this
- }
- var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
- function base64clean (str) {
-
- str = str.split('=')[0]
-
- str = str.trim().replace(INVALID_BASE64_RE, '')
-
- if (str.length < 2) return ''
-
- while (str.length % 4 !== 0) {
- str = str + '='
- }
- return str
- }
- function toHex (n) {
- if (n < 16) return '0' + n.toString(16)
- return n.toString(16)
- }
- function utf8ToBytes (string, units) {
- units = units || Infinity
- var codePoint
- var length = string.length
- var leadSurrogate = null
- var bytes = []
- for (var i = 0; i < length; ++i) {
- codePoint = string.charCodeAt(i)
-
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
-
- if (!leadSurrogate) {
-
- if (codePoint > 0xDBFF) {
-
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
- continue
- } else if (i + 1 === length) {
-
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
- continue
- }
-
- leadSurrogate = codePoint
- continue
- }
-
- if (codePoint < 0xDC00) {
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
- leadSurrogate = codePoint
- continue
- }
-
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
- } else if (leadSurrogate) {
-
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
- }
- leadSurrogate = null
-
- if (codePoint < 0x80) {
- if ((units -= 1) < 0) break
- bytes.push(codePoint)
- } else if (codePoint < 0x800) {
- if ((units -= 2) < 0) break
- bytes.push(
- codePoint >> 0x6 | 0xC0,
- codePoint & 0x3F | 0x80
- )
- } else if (codePoint < 0x10000) {
- if ((units -= 3) < 0) break
- bytes.push(
- codePoint >> 0xC | 0xE0,
- codePoint >> 0x6 & 0x3F | 0x80,
- codePoint & 0x3F | 0x80
- )
- } else if (codePoint < 0x110000) {
- if ((units -= 4) < 0) break
- bytes.push(
- codePoint >> 0x12 | 0xF0,
- codePoint >> 0xC & 0x3F | 0x80,
- codePoint >> 0x6 & 0x3F | 0x80,
- codePoint & 0x3F | 0x80
- )
- } else {
- throw new Error('Invalid code point')
- }
- }
- return bytes
- }
- function asciiToBytes (str) {
- var byteArray = []
- for (var i = 0; i < str.length; ++i) {
-
- byteArray.push(str.charCodeAt(i) & 0xFF)
- }
- return byteArray
- }
- function utf16leToBytes (str, units) {
- var c, hi, lo
- var byteArray = []
- for (var i = 0; i < str.length; ++i) {
- if ((units -= 2) < 0) break
- c = str.charCodeAt(i)
- hi = c >> 8
- lo = c % 256
- byteArray.push(lo)
- byteArray.push(hi)
- }
- return byteArray
- }
- function base64ToBytes (str) {
- return base64.toByteArray(base64clean(str))
- }
- function blitBuffer (src, dst, offset, length) {
- for (var i = 0; i < length; ++i) {
- if ((i + offset >= dst.length) || (i >= src.length)) break
- dst[i + offset] = src[i]
- }
- return i
- }
- function isInstance (obj, type) {
- return obj instanceof type ||
- (obj != null && obj.constructor != null && obj.constructor.name != null &&
- obj.constructor.name === type.name)
- }
- function numberIsNaN (obj) {
-
- return obj !== obj
- }
- }).call(this,require("buffer").Buffer)
- },{"base64-js":1,"buffer":2,"ieee754":3}],3:[function(require,module,exports){
- exports.read = function (buffer, offset, isLE, mLen, nBytes) {
- var e, m
- var eLen = (nBytes * 8) - mLen - 1
- var eMax = (1 << eLen) - 1
- var eBias = eMax >> 1
- var nBits = -7
- var i = isLE ? (nBytes - 1) : 0
- var d = isLE ? -1 : 1
- var s = buffer[offset + i]
- i += d
- e = s & ((1 << (-nBits)) - 1)
- s >>= (-nBits)
- nBits += eLen
- for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
- m = e & ((1 << (-nBits)) - 1)
- e >>= (-nBits)
- nBits += mLen
- for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
- if (e === 0) {
- e = 1 - eBias
- } else if (e === eMax) {
- return m ? NaN : ((s ? -1 : 1) * Infinity)
- } else {
- m = m + Math.pow(2, mLen)
- e = e - eBias
- }
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
- }
- exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
- var e, m, c
- var eLen = (nBytes * 8) - mLen - 1
- var eMax = (1 << eLen) - 1
- var eBias = eMax >> 1
- var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
- var i = isLE ? 0 : (nBytes - 1)
- var d = isLE ? 1 : -1
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
- value = Math.abs(value)
- if (isNaN(value) || value === Infinity) {
- m = isNaN(value) ? 1 : 0
- e = eMax
- } else {
- e = Math.floor(Math.log(value) / Math.LN2)
- if (value * (c = Math.pow(2, -e)) < 1) {
- e--
- c *= 2
- }
- if (e + eBias >= 1) {
- value += rt / c
- } else {
- value += rt * Math.pow(2, 1 - eBias)
- }
- if (value * c >= 2) {
- e++
- c /= 2
- }
- if (e + eBias >= eMax) {
- m = 0
- e = eMax
- } else if (e + eBias >= 1) {
- m = ((value * c) - 1) * Math.pow(2, mLen)
- e = e + eBias
- } else {
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
- e = 0
- }
- }
- for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
- e = (e << mLen) | m
- eLen += mLen
- for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
- buffer[offset + i - d] |= s * 128
- }
- },{}],4:[function(require,module,exports){
- "use strict";
- var __assign = (this && this.__assign) || function () {
- __assign = Object.assign || function(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
- t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [op[0] & 2, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.HubControl = void 0;
- var manual_1 = require("./states/manual");
- var ai_1 = require("./states/ai");
- var HubControl = (function () {
- function HubControl(deviceInfo, controlData, configuration) {
- this.hub = null;
- this.device = deviceInfo;
- this.control = controlData;
- this.configuration = configuration;
- this.prevControl = __assign({}, this.control);
- this.states = {
- Turn: ai_1.turn,
- Drive: ai_1.drive,
- Stop: ai_1.stop,
- Back: ai_1.back,
- Manual: manual_1.manual,
- Seek: ai_1.seek,
- };
- this.currentState = this.states['Manual'];
- }
- HubControl.prototype.updateConfiguration = function (configuration) {
- this.configuration = configuration;
- };
- HubControl.prototype.start = function (hub) {
- return __awaiter(this, void 0, void 0, function () {
- var _this = this;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- this.hub = hub;
- this.device.connected = true;
- this.hub.emitter.on('error', function (err) {
- _this.device.err = err;
- });
- this.hub.emitter.on('disconnect', function () {
- _this.device.connected = false;
- });
- this.hub.emitter.on('distance', function (distance) {
- _this.device.distance = distance;
- });
- this.hub.emitter.on('rssi', function (rssi) {
- _this.device.rssi = rssi;
- });
- this.hub.emitter.on('port', function (portObject) {
- var port = portObject.port, action = portObject.action;
- _this.device.ports[port].action = action;
- });
- this.hub.emitter.on('color', function (color) {
- _this.device.color = color;
- });
- this.hub.emitter.on('tilt', function (tilt) {
- var roll = tilt.roll, pitch = tilt.pitch;
- _this.device.tilt.roll = roll;
- _this.device.tilt.pitch = pitch;
- });
- this.hub.emitter.on('rotation', function (rotation) {
- var port = rotation.port, angle = rotation.angle;
- _this.device.ports[port].angle = angle;
- });
- return [4 , this.hub.ledAsync('red')];
- case 1:
- _a.sent();
- return [4 , this.hub.ledAsync('yellow')];
- case 2:
- _a.sent();
- return [4 , this.hub.ledAsync('green')];
- case 3:
- _a.sent();
- return [2 ];
- }
- });
- });
- };
- HubControl.prototype.disconnect = function () {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.device.connected) return [3 , 2];
- return [4 , this.hub.disconnectAsync()];
- case 1:
- _a.sent();
- _a.label = 2;
- case 2: return [2 ];
- }
- });
- });
- };
- HubControl.prototype.setNextState = function (state) {
- this.control.controlUpdateTime = undefined;
- this.control.state = state;
- this.currentState = this.states[state];
- };
- HubControl.prototype.update = function () {
-
- this.currentState(this);
-
- this.prevControl = __assign({}, this.control);
- this.prevControl.tilt = __assign({}, this.control.tilt);
- this.prevDevice = __assign({}, this.device);
- };
- return HubControl;
- }());
- exports.HubControl = HubControl;
- },{"./states/ai":5,"./states/manual":6}],5:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.seek = exports.turn = exports.drive = exports.back = exports.stop = void 0;
- var MIN_DISTANCE = 75;
- var OK_DISTANCE = 100;
- var EXECUTE_TIME_SEC = 60;
- var CHECK_TIME_MS = 59000;
- var TURN_SPEED = 30;
- var TURN_SPEED_OPPOSITE = -10;
- var DRIVE_SPEED = 30;
- var REVERSE_SPEED = -15;
- var seek = function (hubControl) {
- if (!hubControl.control.controlUpdateTime || Date.now() - hubControl.control.controlUpdateTime > CHECK_TIME_MS) {
- hubControl.control.controlUpdateTime = Date.now();
- hubControl.hub.motorTimeMulti(EXECUTE_TIME_SEC, TURN_SPEED, TURN_SPEED_OPPOSITE);
- }
- if (Date.now() - hubControl.control.controlUpdateTime < 250)
- return;
- if (hubControl.device.distance > hubControl.prevDevice.distance) {
- hubControl.control.turnDirection = 'right';
- hubControl.setNextState('Turn');
- }
- else {
- hubControl.control.turnDirection = 'left';
- hubControl.setNextState('Turn');
- }
- };
- exports.seek = seek;
- var turn = function (hubControl) {
- if (hubControl.device.distance < MIN_DISTANCE) {
- hubControl.control.turnDirection = null;
- hubControl.setNextState('Back');
- return;
- }
- else if (hubControl.device.distance > OK_DISTANCE) {
- hubControl.control.turnDirection = null;
- hubControl.setNextState('Drive');
- return;
- }
- if (!hubControl.control.controlUpdateTime || Date.now() - hubControl.control.controlUpdateTime > CHECK_TIME_MS) {
- var motorA = hubControl.control.turnDirection === 'right' ? TURN_SPEED : TURN_SPEED_OPPOSITE;
- var motorB = hubControl.control.turnDirection === 'right' ? TURN_SPEED_OPPOSITE : TURN_SPEED;
- hubControl.control.controlUpdateTime = Date.now();
- hubControl.hub.motorTimeMulti(EXECUTE_TIME_SEC, motorA, motorB);
- }
- };
- exports.turn = turn;
- var drive = function (hubControl) {
- if (hubControl.device.distance < MIN_DISTANCE) {
- hubControl.setNextState('Back');
- return;
- }
- else if (hubControl.device.distance < OK_DISTANCE) {
- hubControl.setNextState('Seek');
- return;
- }
- if (!hubControl.control.controlUpdateTime || Date.now() - hubControl.control.controlUpdateTime > CHECK_TIME_MS) {
- hubControl.control.controlUpdateTime = Date.now();
- var speed = hubControl.configuration.leftMotor === 'A' ? DRIVE_SPEED : DRIVE_SPEED * -1;
- hubControl.hub.motorTimeMulti(EXECUTE_TIME_SEC, speed, speed);
- }
- };
- exports.drive = drive;
- var back = function (hubControl) {
- if (hubControl.device.distance > OK_DISTANCE) {
- hubControl.setNextState('Seek');
- return;
- }
- if (!hubControl.control.controlUpdateTime || Date.now() - hubControl.control.controlUpdateTime > CHECK_TIME_MS) {
- hubControl.control.controlUpdateTime = Date.now();
- var speed = hubControl.configuration.leftMotor === 'A' ? REVERSE_SPEED : REVERSE_SPEED * -1;
- hubControl.hub.motorTimeMulti(EXECUTE_TIME_SEC, speed, speed);
- }
- };
- exports.back = back;
- var stop = function (hubControl) {
- hubControl.control.speed = 0;
- hubControl.control.turnAngle = 0;
- if (!hubControl.control.controlUpdateTime || Date.now() - hubControl.control.controlUpdateTime > CHECK_TIME_MS) {
- hubControl.control.controlUpdateTime = Date.now();
- hubControl.hub.motorTimeMulti(EXECUTE_TIME_SEC, 0, 0);
- }
- };
- exports.stop = stop;
- },{}],6:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.manual = void 0;
- function manual(hubControl) {
- if (hubControl.control.speed !== hubControl.prevControl.speed || hubControl.control.turnAngle !== hubControl.prevControl.turnAngle) {
- var motorA = hubControl.control.speed + (hubControl.control.turnAngle > 0 ? Math.abs(hubControl.control.turnAngle) : 0);
- var motorB = hubControl.control.speed + (hubControl.control.turnAngle < 0 ? Math.abs(hubControl.control.turnAngle) : 0);
- if (motorA > 100) {
- motorB -= motorA - 100;
- motorA = 100;
- }
- if (motorB > 100) {
- motorA -= motorB - 100;
- motorB = 100;
- }
- hubControl.control.motorA = motorA;
- hubControl.control.motorB = motorB;
- hubControl.hub.motorTimeMulti(60, motorA, motorB);
- }
- if (hubControl.control.tilt.pitch !== hubControl.prevControl.tilt.pitch) {
- hubControl.hub.motorTime('C', 60, hubControl.control.tilt.pitch);
- }
- if (hubControl.control.tilt.roll !== hubControl.prevControl.tilt.roll) {
- hubControl.hub.motorTime('D', 60, hubControl.control.tilt.roll);
- }
- }
- exports.manual = manual;
- },{}],7:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [op[0] & 2, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.BoostConnector = void 0;
- var BOOST_HUB_SERVICE_UUID = '00001623-1212-efde-1623-785feabcd123';
- var BOOST_CHARACTERISTIC_UUID = '00001624-1212-efde-1623-785feabcd123';
- var BoostConnector = (function () {
- function BoostConnector() {
- }
- BoostConnector.connect = function (disconnectCallback) {
- return __awaiter(this, void 0, void 0, function () {
- var options, _a;
- var _this = this;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- options = {
- acceptAllDevices: false,
- filters: [{ services: [BOOST_HUB_SERVICE_UUID] }],
- optionalServices: [BOOST_HUB_SERVICE_UUID],
- };
- _a = this;
- return [4 , navigator.bluetooth.requestDevice(options)];
- case 1:
- _a.device = _b.sent();
- this.device.addEventListener('gattserverdisconnected', function (event) { return __awaiter(_this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0: return [4 , disconnectCallback()];
- case 1:
- _a.sent();
- return [2 ];
- }
- });
- }); });
-
-
-
-
-
- return [2 , BoostConnector.getCharacteristic(this.device)];
- }
- });
- });
- };
- BoostConnector.getCharacteristic = function (device) {
- return __awaiter(this, void 0, void 0, function () {
- var server, service;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0: return [4 , device.gatt.connect()];
- case 1:
- server = _a.sent();
- return [4 , server.getPrimaryService(BOOST_HUB_SERVICE_UUID)];
- case 2:
- service = _a.sent();
- return [4 , service.getCharacteristic(BOOST_CHARACTERISTIC_UUID)];
- case 3: return [2 , _a.sent()];
- }
- });
- });
- };
- BoostConnector.reconnect = function () {
- return __awaiter(this, void 0, void 0, function () {
- var bluetooth;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.device) return [3 , 2];
- return [4 , BoostConnector.getCharacteristic(this.device)];
- case 1:
- bluetooth = _a.sent();
- return [2 , [true, bluetooth]];
- case 2: return [2 , [false, null]];
- }
- });
- });
- };
- BoostConnector.disconnect = function () {
- if (this.device) {
- this.device.gatt.disconnect();
- return true;
- }
- return false;
- };
- BoostConnector.isWebBluetoothSupported = navigator.bluetooth ? true : false;
- return BoostConnector;
- }());
- exports.BoostConnector = BoostConnector;
- },{}],8:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var legoBoost_1 = require("./legoBoost");
- var boostConnector_1 = require("./boostConnector");
- var boost = new legoBoost_1.default();
- boost.logDebug = console.log;
- window.isWebBluetoothSupported = boostConnector_1.BoostConnector.isWebBluetoothSupported;
- window._LegoBoost = boost
- window.connect = boost.connect.bind(boost);
- window.led = boost.changeLed.bind(boost);
- window.drive = boost.drive.bind(boost, 50);
- window.disconnect = boost.disconnect.bind(boost);
- window.ai = boost.ai.bind(boost);
- window.stop = boost.stop.bind(boost);
- window.turnLeft = boost.turn.bind(boost, 90 * 400);
- window.turnRight = boost.turn.bind(boost, 90 * 400 * -1);
- window.driveForward = boost.driveToDirection.bind(boost);
- window.driveBackward = boost.driveToDirection.bind(boost, -1);
- window.turnAPositive = boost.motorAngle.bind(boost, 'A', 3600, 10);
- window.turnANegative = boost.motorAngle.bind(boost, 'A', 3600, -10);
- window.rawCommand = boost.rawCommand.bind(boost, {
- 0: 0x08,
- 1: 0x00,
- 2: 0x81,
- 3: 0x32,
- 4: 0x11,
- 5: 0x51,
- 6: 0x00,
- 7: 0x02,
- 8: 0x00,
- 9: 0x00,
- 10: 0x00,
- 11: 0x00,
- 12: 0x00,
- 13: 0x00,
- 14: 0x00,
- });
- },{"./boostConnector":7,"./legoBoost":13}],9:[function(require,module,exports){
- (function (Buffer){
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.kMaxLength = exports.INSPECT_MAX_BYTES = exports.SlowBuffer = exports.Buffer = void 0;
- var base64 = Promise.resolve().then(function () { return require('base64-js'); });
- var ieee754 = Promise.resolve().then(function () { return require('ieee754'); });
- var INSPECT_MAX_BYTES = 50;
- exports.INSPECT_MAX_BYTES = INSPECT_MAX_BYTES;
- var K_MAX_LENGTH = 0x7fffffff;
- var kMaxLength = K_MAX_LENGTH;
- exports.kMaxLength = kMaxLength;
- Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
- if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
- typeof console.error === 'function') {
- console.error('This browser lacks typed array (Uint8Array) support which is required by ' +
- '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.');
- }
- function typedArraySupport() {
-
- try {
- var arr = new Uint8Array(1);
-
- arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42; } };
-
- return arr.foo() === 42;
- }
- catch (e) {
- return false;
- }
- }
- Object.defineProperty(Buffer.prototype, 'parent', {
- enumerable: true,
- get: function () {
- if (!Buffer.isBuffer(this))
- return undefined;
- return this.buffer;
- }
- });
- Object.defineProperty(Buffer.prototype, 'offset', {
- enumerable: true,
- get: function () {
- if (!Buffer.isBuffer(this))
- return undefined;
- return this.byteOffset;
- }
- });
- function createBuffer(length) {
- if (length > K_MAX_LENGTH) {
- throw new RangeError('The value "' + length + '" is invalid for option "size"');
- }
-
- var buf = new Uint8Array(length);
-
- buf.__proto__ = Buffer.prototype;
- return buf;
- }
- function Buffer(arg, encodingOrOffset, length) {
-
- if (typeof arg === 'number') {
- if (typeof encodingOrOffset === 'string') {
- throw new TypeError('The "string" argument must be of type string. Received type number');
- }
- return allocUnsafe(arg);
- }
- return from(arg, encodingOrOffset, length);
- }
- exports.Buffer = Buffer;
- if (typeof Symbol !== 'undefined' && Symbol.species != null &&
- Buffer[Symbol.species] === Buffer) {
- Object.defineProperty(Buffer, Symbol.species, {
- value: null,
- configurable: true,
- enumerable: false,
- writable: false
- });
- }
- Buffer.poolSize = 8192;
- function from(value, encodingOrOffset, length) {
- if (typeof value === 'string') {
- return fromString(value, encodingOrOffset);
- }
- if (ArrayBuffer.isView(value)) {
- return fromArrayLike(value);
- }
- if (value == null) {
- throw TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
- 'or Array-like Object. Received type ' + (typeof value));
- }
- if (isInstance(value, ArrayBuffer) ||
- (value && isInstance(value.buffer, ArrayBuffer))) {
- return fromArrayBuffer(value, encodingOrOffset, length);
- }
- if (typeof value === 'number') {
- throw new TypeError('The "value" argument must not be of type number. Received type number');
- }
- var valueOf = value.valueOf && value.valueOf();
- if (valueOf != null && valueOf !== value) {
- return Buffer.from(valueOf, encodingOrOffset, length);
- }
- var b = fromObject(value);
- if (b)
- return b;
- if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
- typeof value[Symbol.toPrimitive] === 'function') {
- return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length);
- }
- throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
- 'or Array-like Object. Received type ' + (typeof value));
- }
- Buffer.from = function (value, encodingOrOffset, length) {
- return from(value, encodingOrOffset, length);
- };
- Buffer.prototype.__proto__ = Uint8Array.prototype;
- Buffer.__proto__ = Uint8Array;
- function assertSize(size) {
- if (typeof size !== 'number') {
- throw new TypeError('"size" argument must be of type number');
- }
- else if (size < 0) {
- throw new RangeError('The value "' + size + '" is invalid for option "size"');
- }
- }
- function alloc(size, fill, encoding) {
- assertSize(size);
- if (size <= 0) {
- return createBuffer(size);
- }
- if (fill !== undefined) {
-
-
-
- return typeof encoding === 'string'
-
- ? createBuffer(size).fill(fill, encoding)
- : createBuffer(size).fill(fill);
- }
- return createBuffer(size);
- }
- Buffer.alloc = function (size, fill, encoding) {
- return alloc(size, fill, encoding);
- };
- function allocUnsafe(size) {
- assertSize(size);
- return createBuffer(size < 0 ? 0 : checked(size) | 0);
- }
- Buffer.allocUnsafe = function (size) {
- return allocUnsafe(size);
- };
- Buffer.allocUnsafeSlow = function (size) {
- return allocUnsafe(size);
- };
- function fromString(string, encoding) {
- if (typeof encoding !== 'string' || encoding === '') {
- encoding = 'utf8';
- }
- if (!Buffer.isEncoding(encoding)) {
- throw new TypeError('Unknown encoding: ' + encoding);
- }
- var length = byteLength(string, encoding) | 0;
- var buf = createBuffer(length);
-
- var actual = buf.write(string, encoding);
- if (actual !== length) {
-
-
-
- buf = buf.slice(0, actual);
- }
- return buf;
- }
- function fromArrayLike(array) {
- var length = array.length < 0 ? 0 : checked(array.length) | 0;
- var buf = createBuffer(length);
- for (var i = 0; i < length; i += 1) {
- buf[i] = array[i] & 255;
- }
- return buf;
- }
- function fromArrayBuffer(array, byteOffset, length) {
- if (byteOffset < 0 || array.byteLength < byteOffset) {
- throw new RangeError('"offset" is outside of buffer bounds');
- }
- if (array.byteLength < byteOffset + (length || 0)) {
- throw new RangeError('"length" is outside of buffer bounds');
- }
- var buf;
- if (byteOffset === undefined && length === undefined) {
- buf = new Uint8Array(array);
- }
- else if (length === undefined) {
- buf = new Uint8Array(array, byteOffset);
- }
- else {
- buf = new Uint8Array(array, byteOffset, length);
- }
-
- buf.__proto__ = Buffer.prototype;
- return buf;
- }
- function fromObject(obj) {
- if (Buffer.isBuffer(obj)) {
- var len = checked(obj.length) | 0;
- var buf = createBuffer(len);
- if (buf.length === 0) {
- return buf;
- }
- obj.copy(buf, 0, 0, len);
- return buf;
- }
- if (obj.length !== undefined) {
- if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
- return createBuffer(0);
- }
- return fromArrayLike(obj);
- }
- if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
- return fromArrayLike(obj.data);
- }
- }
- function checked(length) {
-
-
- if (length >= K_MAX_LENGTH) {
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
- 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes');
- }
- return length | 0;
- }
- function SlowBuffer(length) {
- if (+length != length) {
- length = 0;
- }
-
- return Buffer.alloc(+length);
- }
- exports.SlowBuffer = SlowBuffer;
- Buffer.isBuffer = function isBuffer(b) {
- return b != null && b._isBuffer === true &&
- b !== Buffer.prototype;
- };
- Buffer.compare = function compare(a, b) {
- if (isInstance(a, Uint8Array))
- a = Buffer.from(a, a.offset, a.byteLength);
- if (isInstance(b, Uint8Array))
- b = Buffer.from(b, b.offset, b.byteLength);
- if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
- throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
- }
- if (a === b)
- return 0;
- var x = a.length;
- var y = b.length;
- for (var i = 0, len = Math.min(x, y); i < len; ++i) {
- if (a[i] !== b[i]) {
- x = a[i];
- y = b[i];
- break;
- }
- }
- if (x < y)
- return -1;
- if (y < x)
- return 1;
- return 0;
- };
- Buffer.isEncoding = function isEncoding(encoding) {
- switch (String(encoding).toLowerCase()) {
- case 'hex':
- case 'utf8':
- case 'utf-8':
- case 'ascii':
- case 'latin1':
- case 'binary':
- case 'base64':
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return true;
- default:
- return false;
- }
- };
- Buffer.concat = function concat(list, length) {
- if (!Array.isArray(list)) {
- throw new TypeError('"list" argument must be an Array of Buffers');
- }
- if (list.length === 0) {
-
- return Buffer.alloc(0);
- }
- var i;
- if (length === undefined) {
- length = 0;
- for (i = 0; i < list.length; ++i) {
- length += list[i].length;
- }
- }
- var buffer = Buffer.allocUnsafe(length);
- var pos = 0;
- for (i = 0; i < list.length; ++i) {
- var buf = list[i];
- if (isInstance(buf, Uint8Array)) {
-
- buf = Buffer.from(buf);
- }
- if (!Buffer.isBuffer(buf)) {
- throw new TypeError('"list" argument must be an Array of Buffers');
- }
- buf.copy(buffer, pos);
- pos += buf.length;
- }
- return buffer;
- };
- function byteLength(string, encoding) {
- if (Buffer.isBuffer(string)) {
- return string.length;
- }
- if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
- return string.byteLength;
- }
- if (typeof string !== 'string') {
- throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
- 'Received type ' + typeof string);
- }
- var len = string.length;
- var mustMatch = (arguments.length > 2 && arguments[2] === true);
- if (!mustMatch && len === 0)
- return 0;
-
- var loweredCase = false;
- for (;;) {
- switch (encoding) {
- case 'ascii':
- case 'latin1':
- case 'binary':
- return len;
- case 'utf8':
- case 'utf-8':
-
- return utf8ToBytes(string).length;
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return len * 2;
- case 'hex':
- return len >>> 1;
- case 'base64':
- return base64ToBytes(string).length;
- default:
- if (loweredCase) {
-
- return mustMatch ? -1 : utf8ToBytes(string).length;
- }
- encoding = ('' + encoding).toLowerCase();
- loweredCase = true;
- }
- }
- }
- Buffer.byteLength = byteLength;
- function slowToString(encoding, start, end) {
- var loweredCase = false;
-
-
-
-
-
-
- if (start === undefined || start < 0) {
- start = 0;
- }
-
-
- if (start > this.length) {
- return '';
- }
- if (end === undefined || end > this.length) {
- end = this.length;
- }
- if (end <= 0) {
- return '';
- }
-
- end >>>= 0;
- start >>>= 0;
- if (end <= start) {
- return '';
- }
- if (!encoding)
- encoding = 'utf8';
- while (true) {
- switch (encoding) {
- case 'hex':
- return hexSlice(this, start, end);
- case 'utf8':
- case 'utf-8':
- return utf8Slice(this, start, end);
- case 'ascii':
- return asciiSlice(this, start, end);
- case 'latin1':
- case 'binary':
- return latin1Slice(this, start, end);
- case 'base64':
- return base64Slice(this, start, end);
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return utf16leSlice(this, start, end);
- default:
- if (loweredCase)
- throw new TypeError('Unknown encoding: ' + encoding);
- encoding = (encoding + '').toLowerCase();
- loweredCase = true;
- }
- }
- }
- Buffer.prototype._isBuffer = true;
- function swap(b, n, m) {
- var i = b[n];
- b[n] = b[m];
- b[m] = i;
- }
- Buffer.prototype.swap16 = function swap16() {
- var len = this.length;
- if (len % 2 !== 0) {
- throw new RangeError('Buffer size must be a multiple of 16-bits');
- }
- for (var i = 0; i < len; i += 2) {
- swap(this, i, i + 1);
- }
- return this;
- };
- Buffer.prototype.swap32 = function swap32() {
- var len = this.length;
- if (len % 4 !== 0) {
- throw new RangeError('Buffer size must be a multiple of 32-bits');
- }
- for (var i = 0; i < len; i += 4) {
- swap(this, i, i + 3);
- swap(this, i + 1, i + 2);
- }
- return this;
- };
- Buffer.prototype.swap64 = function swap64() {
- var len = this.length;
- if (len % 8 !== 0) {
- throw new RangeError('Buffer size must be a multiple of 64-bits');
- }
- for (var i = 0; i < len; i += 8) {
- swap(this, i, i + 7);
- swap(this, i + 1, i + 6);
- swap(this, i + 2, i + 5);
- swap(this, i + 3, i + 4);
- }
- return this;
- };
- Buffer.prototype.toString = function toString() {
- var length = this.length;
- if (length === 0)
- return '';
- if (arguments.length === 0)
- return utf8Slice(this, 0, length);
- return slowToString.apply(this, arguments);
- };
- Buffer.prototype.toLocaleString = Buffer.prototype.toString;
- Buffer.prototype.equals = function equals(b) {
- if (!Buffer.isBuffer(b))
- throw new TypeError('Argument must be a Buffer');
- if (this === b)
- return true;
- return Buffer.compare(this, b) === 0;
- };
- Buffer.prototype.inspect = function inspect() {
- var str = '';
- var max = INSPECT_MAX_BYTES;
- str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
- if (this.length > max)
- str += ' ... ';
- return '<Buffer ' + str + '>';
- };
- Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
- if (isInstance(target, Uint8Array)) {
- target = Buffer.from(target, target.offset, target.byteLength);
- }
- if (!Buffer.isBuffer(target)) {
- throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. ' +
- 'Received type ' + (typeof target));
- }
- if (start === undefined) {
- start = 0;
- }
- if (end === undefined) {
- end = target ? target.length : 0;
- }
- if (thisStart === undefined) {
- thisStart = 0;
- }
- if (thisEnd === undefined) {
- thisEnd = this.length;
- }
- if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
- throw new RangeError('out of range index');
- }
- if (thisStart >= thisEnd && start >= end) {
- return 0;
- }
- if (thisStart >= thisEnd) {
- return -1;
- }
- if (start >= end) {
- return 1;
- }
- start >>>= 0;
- end >>>= 0;
- thisStart >>>= 0;
- thisEnd >>>= 0;
- if (this === target)
- return 0;
- var x = thisEnd - thisStart;
- var y = end - start;
- var len = Math.min(x, y);
- var thisCopy = this.slice(thisStart, thisEnd);
- var targetCopy = target.slice(start, end);
- for (var i = 0; i < len; ++i) {
- if (thisCopy[i] !== targetCopy[i]) {
- x = thisCopy[i];
- y = targetCopy[i];
- break;
- }
- }
- if (x < y)
- return -1;
- if (y < x)
- return 1;
- return 0;
- };
- function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
-
- if (buffer.length === 0)
- return -1;
-
- if (typeof byteOffset === 'string') {
- encoding = byteOffset;
- byteOffset = 0;
- }
- else if (byteOffset > 0x7fffffff) {
- byteOffset = 0x7fffffff;
- }
- else if (byteOffset < -0x80000000) {
- byteOffset = -0x80000000;
- }
- byteOffset = +byteOffset;
- if (numberIsNaN(byteOffset)) {
-
- byteOffset = dir ? 0 : (buffer.length - 1);
- }
-
- if (byteOffset < 0)
- byteOffset = buffer.length + byteOffset;
- if (byteOffset >= buffer.length) {
- if (dir)
- return -1;
- else
- byteOffset = buffer.length - 1;
- }
- else if (byteOffset < 0) {
- if (dir)
- byteOffset = 0;
- else
- return -1;
- }
-
- if (typeof val === 'string') {
-
- val = Buffer.from(val, encoding);
- }
-
- if (Buffer.isBuffer(val)) {
-
- if (val.length === 0) {
- return -1;
- }
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
- }
- else if (typeof val === 'number') {
- val = val & 0xFF;
- if (typeof Uint8Array.prototype.indexOf === 'function') {
- if (dir) {
- return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
- }
- else {
- return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
- }
- }
- return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
- }
- throw new TypeError('val must be string, number or Buffer');
- }
- function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
- var indexSize = 1;
- var arrLength = arr.length;
- var valLength = val.length;
- if (encoding !== undefined) {
- encoding = String(encoding).toLowerCase();
- if (encoding === 'ucs2' || encoding === 'ucs-2' ||
- encoding === 'utf16le' || encoding === 'utf-16le') {
- if (arr.length < 2 || val.length < 2) {
- return -1;
- }
- indexSize = 2;
- arrLength /= 2;
- valLength /= 2;
- byteOffset /= 2;
- }
- }
- function read(buf, i) {
- if (indexSize === 1) {
- return buf[i];
- }
- else {
- return buf.readUInt16BE(i * indexSize);
- }
- }
- var i;
- if (dir) {
- var foundIndex = -1;
- for (i = byteOffset; i < arrLength; i++) {
- if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
- if (foundIndex === -1)
- foundIndex = i;
- if (i - foundIndex + 1 === valLength)
- return foundIndex * indexSize;
- }
- else {
- if (foundIndex !== -1)
- i -= i - foundIndex;
- foundIndex = -1;
- }
- }
- }
- else {
- if (byteOffset + valLength > arrLength)
- byteOffset = arrLength - valLength;
- for (i = byteOffset; i >= 0; i--) {
- var found = true;
- for (var j = 0; j < valLength; j++) {
- if (read(arr, i + j) !== read(val, j)) {
- found = false;
- break;
- }
- }
- if (found)
- return i;
- }
- }
- return -1;
- }
- Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
- return this.indexOf(val, byteOffset, encoding) !== -1;
- };
- Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
- };
- Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
- };
- function hexWrite(buf, string, offset, length) {
- offset = Number(offset) || 0;
- var remaining = buf.length - offset;
- if (!length) {
- length = remaining;
- }
- else {
- length = Number(length);
- if (length > remaining) {
- length = remaining;
- }
- }
- var strLen = string.length;
- if (length > strLen / 2) {
- length = strLen / 2;
- }
- for (var i = 0; i < length; ++i) {
- var parsed = parseInt(string.substr(i * 2, 2), 16);
- if (numberIsNaN(parsed))
- return i;
- buf[offset + i] = parsed;
- }
- return i;
- }
- function utf8Write(buf, string, offset, length) {
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
- }
- function asciiWrite(buf, string, offset, length) {
- return blitBuffer(asciiToBytes(string), buf, offset, length);
- }
- function latin1Write(buf, string, offset, length) {
- return asciiWrite(buf, string, offset, length);
- }
- function base64Write(buf, string, offset, length) {
- return blitBuffer(base64ToBytes(string), buf, offset, length);
- }
- function ucs2Write(buf, string, offset, length) {
- return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
- }
- Buffer.prototype.write = function write(string, offset, length, encoding) {
-
- if (offset === undefined) {
- encoding = 'utf8';
- length = this.length;
- offset = 0;
-
- }
- else if (length === undefined && typeof offset === 'string') {
- encoding = offset;
- length = this.length;
- offset = 0;
-
- }
- else if (isFinite(offset)) {
- offset = offset >>> 0;
- if (isFinite(length)) {
- length = length >>> 0;
- if (encoding === undefined)
- encoding = 'utf8';
- }
- else {
- encoding = length;
- length = undefined;
- }
- }
- else {
- throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');
- }
- var remaining = this.length - offset;
- if (length === undefined || length > remaining)
- length = remaining;
- if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
- throw new RangeError('Attempt to write outside buffer bounds');
- }
- if (!encoding)
- encoding = 'utf8';
- var loweredCase = false;
- for (;;) {
- switch (encoding) {
- case 'hex':
- return hexWrite(this, string, offset, length);
- case 'utf8':
- case 'utf-8':
- return utf8Write(this, string, offset, length);
- case 'ascii':
- return asciiWrite(this, string, offset, length);
- case 'latin1':
- case 'binary':
- return latin1Write(this, string, offset, length);
- case 'base64':
-
- return base64Write(this, string, offset, length);
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return ucs2Write(this, string, offset, length);
- default:
- if (loweredCase)
- throw new TypeError('Unknown encoding: ' + encoding);
- encoding = ('' + encoding).toLowerCase();
- loweredCase = true;
- }
- }
- };
- Buffer.prototype.toJSON = function toJSON() {
- return {
- type: 'Buffer',
- data: Array.prototype.slice.call(this._arr || this, 0)
- };
- };
- function base64Slice(buf, start, end) {
- if (start === 0 && end === buf.length) {
-
- return base64.fromByteArray(buf);
- }
- else {
-
- return base64.fromByteArray(buf.slice(start, end));
- }
- }
- function utf8Slice(buf, start, end) {
- end = Math.min(buf.length, end);
- var res = [];
- var i = start;
- while (i < end) {
- var firstByte = buf[i];
- var codePoint = null;
- var bytesPerSequence = (firstByte > 0xEF) ? 4
- : (firstByte > 0xDF) ? 3
- : (firstByte > 0xBF) ? 2
- : 1;
- if (i + bytesPerSequence <= end) {
- var secondByte, thirdByte, fourthByte, tempCodePoint;
- switch (bytesPerSequence) {
- case 1:
- if (firstByte < 0x80) {
- codePoint = firstByte;
- }
- break;
- case 2:
- secondByte = buf[i + 1];
- if ((secondByte & 0xC0) === 0x80) {
- tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
- if (tempCodePoint > 0x7F) {
- codePoint = tempCodePoint;
- }
- }
- break;
- case 3:
- secondByte = buf[i + 1];
- thirdByte = buf[i + 2];
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
- tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
- if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
- codePoint = tempCodePoint;
- }
- }
- break;
- case 4:
- secondByte = buf[i + 1];
- thirdByte = buf[i + 2];
- fourthByte = buf[i + 3];
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
- tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
- if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
- codePoint = tempCodePoint;
- }
- }
- }
- }
- if (codePoint === null) {
-
-
- codePoint = 0xFFFD;
- bytesPerSequence = 1;
- }
- else if (codePoint > 0xFFFF) {
-
- codePoint -= 0x10000;
- res.push(codePoint >>> 10 & 0x3FF | 0xD800);
- codePoint = 0xDC00 | codePoint & 0x3FF;
- }
- res.push(codePoint);
- i += bytesPerSequence;
- }
- return decodeCodePointsArray(res);
- }
- var MAX_ARGUMENTS_LENGTH = 0x1000;
- function decodeCodePointsArray(codePoints) {
- var len = codePoints.length;
- if (len <= MAX_ARGUMENTS_LENGTH) {
- return String.fromCharCode.apply(String, codePoints);
- }
-
- var res = '';
- var i = 0;
- while (i < len) {
- res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
- }
- return res;
- }
- function asciiSlice(buf, start, end) {
- var ret = '';
- end = Math.min(buf.length, end);
- for (var i = start; i < end; ++i) {
- ret += String.fromCharCode(buf[i] & 0x7F);
- }
- return ret;
- }
- function latin1Slice(buf, start, end) {
- var ret = '';
- end = Math.min(buf.length, end);
- for (var i = start; i < end; ++i) {
- ret += String.fromCharCode(buf[i]);
- }
- return ret;
- }
- function hexSlice(buf, start, end) {
- var len = buf.length;
- if (!start || start < 0)
- start = 0;
- if (!end || end < 0 || end > len)
- end = len;
- var out = '';
- for (var i = start; i < end; ++i) {
- out += toHex(buf[i]);
- }
- return out;
- }
- function utf16leSlice(buf, start, end) {
- var bytes = buf.slice(start, end);
- var res = '';
- for (var i = 0; i < bytes.length; i += 2) {
- res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
- }
- return res;
- }
- Buffer.prototype.slice = function slice(start, end) {
- var len = this.length;
- start = ~~start;
- end = end === undefined ? len : ~~end;
- if (start < 0) {
- start += len;
- if (start < 0)
- start = 0;
- }
- else if (start > len) {
- start = len;
- }
- if (end < 0) {
- end += len;
- if (end < 0)
- end = 0;
- }
- else if (end > len) {
- end = len;
- }
- if (end < start)
- end = start;
- var newBuf = this.subarray(start, end);
-
- newBuf.__proto__ = Buffer.prototype;
- return newBuf;
- };
- function checkOffset(offset, ext, length) {
- if ((offset % 1) !== 0 || offset < 0)
- throw new RangeError('offset is not uint');
- if (offset + ext > length)
- throw new RangeError('Trying to access beyond buffer length');
- }
- Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
- offset = offset >>> 0;
- byteLength = byteLength >>> 0;
- if (!noAssert)
- checkOffset(offset, byteLength, this.length);
- var val = this[offset];
- var mul = 1;
- var i = 0;
- while (++i < byteLength && (mul *= 0x100)) {
- val += this[offset + i] * mul;
- }
- return val;
- };
- Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
- offset = offset >>> 0;
- byteLength = byteLength >>> 0;
- if (!noAssert) {
- checkOffset(offset, byteLength, this.length);
- }
- var val = this[offset + --byteLength];
- var mul = 1;
- while (byteLength > 0 && (mul *= 0x100)) {
- val += this[offset + --byteLength] * mul;
- }
- return val;
- };
- Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 1, this.length);
- return this[offset];
- };
- Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 2, this.length);
- return this[offset] | (this[offset + 1] << 8);
- };
- Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 2, this.length);
- return (this[offset] << 8) | this[offset + 1];
- };
- Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 4, this.length);
- return ((this[offset]) |
- (this[offset + 1] << 8) |
- (this[offset + 2] << 16)) +
- (this[offset + 3] * 0x1000000);
- };
- Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 4, this.length);
- return (this[offset] * 0x1000000) +
- ((this[offset + 1] << 16) |
- (this[offset + 2] << 8) |
- this[offset + 3]);
- };
- Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
- offset = offset >>> 0;
- byteLength = byteLength >>> 0;
- if (!noAssert)
- checkOffset(offset, byteLength, this.length);
- var val = this[offset];
- var mul = 1;
- var i = 0;
- while (++i < byteLength && (mul *= 0x100)) {
- val += this[offset + i] * mul;
- }
- mul *= 0x80;
- if (val >= mul)
- val -= Math.pow(2, 8 * byteLength);
- return val;
- };
- Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
- offset = offset >>> 0;
- byteLength = byteLength >>> 0;
- if (!noAssert)
- checkOffset(offset, byteLength, this.length);
- var i = byteLength;
- var mul = 1;
- var val = this[offset + --i];
- while (i > 0 && (mul *= 0x100)) {
- val += this[offset + --i] * mul;
- }
- mul *= 0x80;
- if (val >= mul)
- val -= Math.pow(2, 8 * byteLength);
- return val;
- };
- Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 1, this.length);
- if (!(this[offset] & 0x80))
- return (this[offset]);
- return ((0xff - this[offset] + 1) * -1);
- };
- Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 2, this.length);
- var val = this[offset] | (this[offset + 1] << 8);
- return (val & 0x8000) ? val | 0xFFFF0000 : val;
- };
- Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 2, this.length);
- var val = this[offset + 1] | (this[offset] << 8);
- return (val & 0x8000) ? val | 0xFFFF0000 : val;
- };
- Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 4, this.length);
- return (this[offset]) |
- (this[offset + 1] << 8) |
- (this[offset + 2] << 16) |
- (this[offset + 3] << 24);
- };
- Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 4, this.length);
- return (this[offset] << 24) |
- (this[offset + 1] << 16) |
- (this[offset + 2] << 8) |
- (this[offset + 3]);
- };
- Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 4, this.length);
-
- return ieee754.read(this, offset, true, 23, 4);
- };
- Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 4, this.length);
-
- return ieee754.read(this, offset, false, 23, 4);
- };
- Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 8, this.length);
-
- return ieee754.read(this, offset, true, 52, 8);
- };
- Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
- offset = offset >>> 0;
- if (!noAssert)
- checkOffset(offset, 8, this.length);
-
- return ieee754.read(this, offset, false, 52, 8);
- };
- function checkInt(buf, value, offset, ext, max, min) {
- if (!Buffer.isBuffer(buf))
- throw new TypeError('"buffer" argument must be a Buffer instance');
- if (value > max || value < min)
- throw new RangeError('"value" argument is out of bounds');
- if (offset + ext > buf.length)
- throw new RangeError('Index out of range');
- }
- Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
- value = +value;
- offset = offset >>> 0;
- byteLength = byteLength >>> 0;
- if (!noAssert) {
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
- checkInt(this, value, offset, byteLength, maxBytes, 0);
- }
- var mul = 1;
- var i = 0;
- this[offset] = value & 0xFF;
- while (++i < byteLength && (mul *= 0x100)) {
- this[offset + i] = (value / mul) & 0xFF;
- }
- return offset + byteLength;
- };
- Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
- value = +value;
- offset = offset >>> 0;
- byteLength = byteLength >>> 0;
- if (!noAssert) {
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
- checkInt(this, value, offset, byteLength, maxBytes, 0);
- }
- var i = byteLength - 1;
- var mul = 1;
- this[offset + i] = value & 0xFF;
- while (--i >= 0 && (mul *= 0x100)) {
- this[offset + i] = (value / mul) & 0xFF;
- }
- return offset + byteLength;
- };
- Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert)
- checkInt(this, value, offset, 1, 0xff, 0);
- this[offset] = (value & 0xff);
- return offset + 1;
- };
- Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert)
- checkInt(this, value, offset, 2, 0xffff, 0);
- this[offset] = (value & 0xff);
- this[offset + 1] = (value >>> 8);
- return offset + 2;
- };
- Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert)
- checkInt(this, value, offset, 2, 0xffff, 0);
- this[offset] = (value >>> 8);
- this[offset + 1] = (value & 0xff);
- return offset + 2;
- };
- Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert)
- checkInt(this, value, offset, 4, 0xffffffff, 0);
- this[offset + 3] = (value >>> 24);
- this[offset + 2] = (value >>> 16);
- this[offset + 1] = (value >>> 8);
- this[offset] = (value & 0xff);
- return offset + 4;
- };
- Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert)
- checkInt(this, value, offset, 4, 0xffffffff, 0);
- this[offset] = (value >>> 24);
- this[offset + 1] = (value >>> 16);
- this[offset + 2] = (value >>> 8);
- this[offset + 3] = (value & 0xff);
- return offset + 4;
- };
- Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert) {
- var limit = Math.pow(2, (8 * byteLength) - 1);
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
- }
- var i = 0;
- var mul = 1;
- var sub = 0;
- this[offset] = value & 0xFF;
- while (++i < byteLength && (mul *= 0x100)) {
- if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
- sub = 1;
- }
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
- }
- return offset + byteLength;
- };
- Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert) {
- var limit = Math.pow(2, (8 * byteLength) - 1);
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
- }
- var i = byteLength - 1;
- var mul = 1;
- var sub = 0;
- this[offset + i] = value & 0xFF;
- while (--i >= 0 && (mul *= 0x100)) {
- if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
- sub = 1;
- }
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
- }
- return offset + byteLength;
- };
- Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert)
- checkInt(this, value, offset, 1, 0x7f, -0x80);
- if (value < 0)
- value = 0xff + value + 1;
- this[offset] = (value & 0xff);
- return offset + 1;
- };
- Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert)
- checkInt(this, value, offset, 2, 0x7fff, -0x8000);
- this[offset] = (value & 0xff);
- this[offset + 1] = (value >>> 8);
- return offset + 2;
- };
- Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert)
- checkInt(this, value, offset, 2, 0x7fff, -0x8000);
- this[offset] = (value >>> 8);
- this[offset + 1] = (value & 0xff);
- return offset + 2;
- };
- Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert)
- checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
- this[offset] = (value & 0xff);
- this[offset + 1] = (value >>> 8);
- this[offset + 2] = (value >>> 16);
- this[offset + 3] = (value >>> 24);
- return offset + 4;
- };
- Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert)
- checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
- if (value < 0)
- value = 0xffffffff + value + 1;
- this[offset] = (value >>> 24);
- this[offset + 1] = (value >>> 16);
- this[offset + 2] = (value >>> 8);
- this[offset + 3] = (value & 0xff);
- return offset + 4;
- };
- function checkIEEE754(buf, value, offset, ext, max, min) {
- if (offset + ext > buf.length)
- throw new RangeError('Index out of range');
- if (offset < 0)
- throw new RangeError('Index out of range');
- }
- function writeFloat(buf, value, offset, littleEndian, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert) {
- checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38);
- }
-
- ieee754.write(buf, value, offset, littleEndian, 23, 4);
- return offset + 4;
- }
- Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
- return writeFloat(this, value, offset, true, noAssert);
- };
- Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
- return writeFloat(this, value, offset, false, noAssert);
- };
- function writeDouble(buf, value, offset, littleEndian, noAssert) {
- value = +value;
- offset = offset >>> 0;
- if (!noAssert) {
- checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308);
- }
-
- ieee754.write(buf, value, offset, littleEndian, 52, 8);
- return offset + 8;
- }
- Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
- return writeDouble(this, value, offset, true, noAssert);
- };
- Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
- return writeDouble(this, value, offset, false, noAssert);
- };
- Buffer.prototype.copy = function copy(target, targetStart, start, end) {
- if (!Buffer.isBuffer(target))
- throw new TypeError('argument should be a Buffer');
- if (!start)
- start = 0;
- if (!end && end !== 0)
- end = this.length;
- if (targetStart >= target.length)
- targetStart = target.length;
- if (!targetStart)
- targetStart = 0;
- if (end > 0 && end < start)
- end = start;
-
- if (end === start)
- return 0;
- if (target.length === 0 || this.length === 0)
- return 0;
-
- if (targetStart < 0) {
- throw new RangeError('targetStart out of bounds');
- }
- if (start < 0 || start >= this.length)
- throw new RangeError('Index out of range');
- if (end < 0)
- throw new RangeError('sourceEnd out of bounds');
-
- if (end > this.length)
- end = this.length;
- if (target.length - targetStart < end - start) {
- end = target.length - targetStart + start;
- }
- var len = end - start;
- if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
-
- this.copyWithin(targetStart, start, end);
- }
- else if (this === target && start < targetStart && targetStart < end) {
-
- for (var i = len - 1; i >= 0; --i) {
- target[i + targetStart] = this[i + start];
- }
- }
- else {
- Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
- }
- return len;
- };
- Buffer.prototype.fill = function fill(val, start, end, encoding) {
-
- if (typeof val === 'string') {
- if (typeof start === 'string') {
- encoding = start;
- start = 0;
- end = this.length;
- }
- else if (typeof end === 'string') {
- encoding = end;
- end = this.length;
- }
- if (encoding !== undefined && typeof encoding !== 'string') {
- throw new TypeError('encoding must be a string');
- }
- if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
- throw new TypeError('Unknown encoding: ' + encoding);
- }
- if (val.length === 1) {
- var code = val.charCodeAt(0);
- if ((encoding === 'utf8' && code < 128) ||
- encoding === 'latin1') {
-
- val = code;
- }
- }
- }
- else if (typeof val === 'number') {
- val = val & 255;
- }
-
- if (start < 0 || this.length < start || this.length < end) {
- throw new RangeError('Out of range index');
- }
- if (end <= start) {
- return this;
- }
- start = start >>> 0;
- end = end === undefined ? this.length : end >>> 0;
- if (!val)
- val = 0;
- var i;
- if (typeof val === 'number') {
- for (i = start; i < end; ++i) {
- this[i] = val;
- }
- }
- else {
- var bytes = Buffer.isBuffer(val)
- ? val
-
- : Buffer.from(val, encoding);
- var len = bytes.length;
- if (len === 0) {
- throw new TypeError('The value "' + val +
- '" is invalid for argument "value"');
- }
- for (i = 0; i < end - start; ++i) {
- this[i + start] = bytes[i % len];
- }
- }
- return this;
- };
- var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
- function base64clean(str) {
-
- str = str.split('=')[0];
-
- str = str.trim().replace(INVALID_BASE64_RE, '');
-
- if (str.length < 2)
- return '';
-
- while (str.length % 4 !== 0) {
- str = str + '=';
- }
- return str;
- }
- function toHex(n) {
- if (n < 16)
- return '0' + n.toString(16);
- return n.toString(16);
- }
- function utf8ToBytes(string, units) {
- units = units || Infinity;
- var codePoint;
- var length = string.length;
- var leadSurrogate = null;
- var bytes = [];
- for (var i = 0; i < length; ++i) {
- codePoint = string.charCodeAt(i);
-
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
-
- if (!leadSurrogate) {
-
- if (codePoint > 0xDBFF) {
-
- if ((units -= 3) > -1)
- bytes.push(0xEF, 0xBF, 0xBD);
- continue;
- }
- else if (i + 1 === length) {
-
- if ((units -= 3) > -1)
- bytes.push(0xEF, 0xBF, 0xBD);
- continue;
- }
-
- leadSurrogate = codePoint;
- continue;
- }
-
- if (codePoint < 0xDC00) {
- if ((units -= 3) > -1)
- bytes.push(0xEF, 0xBF, 0xBD);
- leadSurrogate = codePoint;
- continue;
- }
-
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
- }
- else if (leadSurrogate) {
-
- if ((units -= 3) > -1)
- bytes.push(0xEF, 0xBF, 0xBD);
- }
- leadSurrogate = null;
-
- if (codePoint < 0x80) {
- if ((units -= 1) < 0)
- break;
- bytes.push(codePoint);
- }
- else if (codePoint < 0x800) {
- if ((units -= 2) < 0)
- break;
- bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80);
- }
- else if (codePoint < 0x10000) {
- if ((units -= 3) < 0)
- break;
- bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
- }
- else if (codePoint < 0x110000) {
- if ((units -= 4) < 0)
- break;
- bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
- }
- else {
- throw new Error('Invalid code point');
- }
- }
- return bytes;
- }
- function asciiToBytes(str) {
- var byteArray = [];
- for (var i = 0; i < str.length; ++i) {
-
- byteArray.push(str.charCodeAt(i) & 0xFF);
- }
- return byteArray;
- }
- function utf16leToBytes(str, units) {
- var c, hi, lo;
- var byteArray = [];
- for (var i = 0; i < str.length; ++i) {
- if ((units -= 2) < 0)
- break;
- c = str.charCodeAt(i);
- hi = c >> 8;
- lo = c % 256;
- byteArray.push(lo);
- byteArray.push(hi);
- }
- return byteArray;
- }
- function base64ToBytes(str) {
-
- return base64.toByteArray(base64clean(str));
- }
- function blitBuffer(src, dst, offset, length) {
- for (var i = 0; i < length; ++i) {
- if ((i + offset >= dst.length) || (i >= src.length))
- break;
- dst[i + offset] = src[i];
- }
- return i;
- }
- function isInstance(obj, type) {
- return obj instanceof type ||
- (obj != null && obj.constructor != null && obj.constructor.name != null &&
- obj.constructor.name === type.name);
- }
- function numberIsNaN(obj) {
-
- return obj !== obj;
- }
- }).call(this,require("buffer").Buffer)
- },{"base64-js":1,"buffer":2,"ieee754":3}],10:[function(require,module,exports){
- "use strict";
- var __spreadArrays = (this && this.__spreadArrays) || function () {
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
- r[k] = a[j];
- return r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.EventEmitter = void 0;
- var EventEmitter = (function () {
- function EventEmitter() {
- this.events = {};
- }
- EventEmitter.prototype.on = function (event, listener) {
- var _this = this;
- if (typeof this.events[event] !== 'object') {
- this.events[event] = [];
- }
- this.events[event].push(listener);
- return function () { return _this.removeListener(event, listener); };
- };
- EventEmitter.prototype.removeListener = function (event, listener) {
- if (typeof this.events[event] !== 'object') {
- return;
- }
- var idx = this.events[event].indexOf(listener);
- if (idx > -1) {
- this.events[event].splice(idx, 1);
- }
- };
- EventEmitter.prototype.removeAllListeners = function () {
- var _this = this;
- Object.keys(this.events).forEach(function (event) { return _this.events[event].splice(0, _this.events[event].length); });
- };
- EventEmitter.prototype.emit = function (event) {
- var _this = this;
- var args = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- args[_i - 1] = arguments[_i];
- }
- if (typeof this.events[event] !== 'object') {
- return;
- }
- __spreadArrays(this.events[event]).forEach(function (listener) { return listener.apply(_this, args); });
- };
- EventEmitter.prototype.once = function (event, listener) {
- var _this = this;
- var remove = this.on(event, function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- remove();
- listener.apply(_this, args);
- });
- return remove;
- };
- return EventEmitter;
- }());
- exports.EventEmitter = EventEmitter;
- },{}],11:[function(require,module,exports){
- (function (global){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.Hub = void 0;
- var eventEmitter_1 = require("../helpers/eventEmitter");
- var buffer_1 = require("../helpers/buffer");
- var Hub = (function () {
- function Hub(bluetooth) {
- this.emitter = new eventEmitter_1.EventEmitter();
- this.autoSubscribe = true;
- this.writeCue = [];
- this.isWriting = false;
- this.bluetooth = bluetooth;
- this.log = console.log;
- this.autoSubscribe = true;
- this.ports = {};
- this.num2type = {
- 23: 'LED',
- 37: 'DISTANCE',
- 38: 'IMOTOR',
- 39: 'MOTOR',
- 40: 'TILT',
- };
- this.port2num = {
- A: 0x00,
- B: 0x01,
- C: 0x02,
- D: 0x03,
- AB: 0x10,
- LED: 0x32,
- TILT: 0x3a,
- };
- this.num2port = Object.entries(this.port2num).reduce(function (acc, _a) {
- var port = _a[0], portNum = _a[1];
- acc[portNum] = port;
- return acc;
- }, {});
- this.num2action = {
- 1: 'start',
- 5: 'conflict',
- 10: 'stop',
- };
- this.num2color = {
- 0: 'black',
- 3: 'blue',
- 5: 'green',
- 7: 'yellow',
- 9: 'red',
- 10: 'white',
- };
- this.ledColors = [
- 'off',
- 'pink',
- 'purple',
- 'blue',
- 'lightblue',
- 'cyan',
- 'green',
- 'yellow',
- 'orange',
- 'red',
- 'white',
- ];
- this.addListeners();
- }
- Hub.prototype.emit = function (type, data) {
- if (data === void 0) { data = null; }
- this.emitter.emit(type, data);
- };
- Hub.prototype.addListeners = function () {
- var _this = this;
- this.bluetooth.addEventListener('characteristicvaluechanged', function (event) {
-
-
- var data = buffer_1.Buffer.from(event.target.value.buffer);
- _this.parseMessage(data);
- });
- global.setTimeout(function () {
-
- _this.bluetooth.startNotifications();
- }, 1000);
- };
- Hub.prototype.parseMessage = function (data) {
- var _this = this;
- switch (data[2]) {
- case 0x04: {
- global.clearTimeout(this.portInfoTimeout);
- this.portInfoTimeout = global.setTimeout(function () {
-
- if (_this.autoSubscribe) {
- _this.subscribeAll();
- }
- if (!_this.connected) {
- _this.connected = true;
- _this.emit('connect');
- }
- }, 1000);
- this.log('Found: ' + this.num2type[data[5]]);
- this.logDebug('Found', data);
- if (data[4] === 0x01) {
- this.ports[data[3]] = {
- type: 'port',
- deviceType: this.num2type[data[5]],
- deviceTypeNum: data[5],
- };
- }
- else if (data[4] === 0x02) {
- this.ports[data[3]] = {
- type: 'group',
- deviceType: this.num2type[data[5]],
- deviceTypeNum: data[5],
- members: [data[7], data[8]],
- };
- }
- break;
- }
- case 0x05: {
- this.log('Malformed message');
- this.log('<', data);
- break;
- }
- case 0x45: {
- this.parseSensor(data);
- break;
- }
- case 0x47: {
-
-
- break;
- }
- case 0x82: {
-
- this.emit('port', {
- port: this.num2port[data[3]],
- action: this.num2action[data[4]],
- });
- break;
- }
- default:
- this.log('unknown message type 0x' + data[2].toString(16));
- this.log('<', data);
- }
- };
- Hub.prototype.parseSensor = function (data) {
- if (!this.ports[data[3]]) {
- this.log('parseSensor unknown port 0x' + data[3].toString(16));
- return;
- }
- switch (this.ports[data[3]].deviceType) {
- case 'DISTANCE': {
-
- this.emit('color', this.num2color[data[4]]);
-
- var distance = void 0;
- if (data[7] > 0 && data[5] < 2) {
- distance = Math.floor(20 - data[7] * 2.85);
- }
- else if (data[5] > 9) {
- distance = Infinity;
- }
- else {
- distance = Math.floor(20 + data[5] * 18);
- }
-
- this.emit('distance', distance);
- break;
- }
- case 'TILT': {
- var roll = data.readInt8(4);
- var pitch = data.readInt8(5);
-
- this.emit('tilt', { roll: roll, pitch: pitch });
- break;
- }
- case 'MOTOR':
- case 'IMOTOR': {
- var angle = data.readInt32LE(4);
-
- this.emit('rotation', {
- port: this.num2port[data[3]],
- angle: angle,
- });
- break;
- }
- default:
- this.log('unknown sensor type 0x' + data[3].toString(16), data[3], this.ports[data[3]].deviceType);
- }
- };
-
- Hub.prototype.setDisconnected = function () {
-
- this.connected = false;
- this.noReconnect = true;
- this.writeCue = [];
- };
-
- Hub.prototype.motorTime = function (port, seconds, dutyCycle, callback) {
- if (typeof dutyCycle === 'function') {
- callback = dutyCycle;
- dutyCycle = 100;
- }
- var portNum = typeof port === 'string' ? this.port2num[port] : port;
- this.write(this.encodeMotorTime(portNum, seconds, dutyCycle), callback);
- };
-
- Hub.prototype.motorTimeMulti = function (seconds, dutyCycleA, dutyCycleB, callback) {
- this.write(this.encodeMotorTimeMulti(this.port2num['AB'], seconds, dutyCycleA, dutyCycleB), callback);
- };
-
- Hub.prototype.motorAngle = function (port, angle, dutyCycle, callback) {
- if (typeof dutyCycle === 'function') {
- callback = dutyCycle;
- dutyCycle = 100;
- }
- var portNum = typeof port === 'string' ? this.port2num[port] : port;
- this.write(this.encodeMotorAngle(portNum, angle, dutyCycle), callback);
- };
-
- Hub.prototype.motorAngleMulti = function (angle, dutyCycleA, dutyCycleB, callback) {
- this.write(this.encodeMotorAngleMulti(this.port2num['AB'], angle, dutyCycleA, dutyCycleB), callback);
- };
-
- Hub.prototype.rawCommand = function (raw, callback) {
-
- var buf = buffer_1.Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
- for (var idx in raw) {
- buf.writeIntLE(raw[idx], idx);
- }
- this.write(buf, callback);
- };
- Hub.prototype.motorPowerCommand = function (port, power) {
- this.write(this.encodeMotorPower(port, power));
- };
-
- Hub.prototype.encodeMotorPower = function (port, dutyCycle) {
- if (dutyCycle === void 0) { dutyCycle = 100; }
- var portNum = typeof port === 'string' ? this.port2num[port] : port;
-
- var buf = buffer_1.Buffer.from([0x09, 0x00, 0x81, portNum, 0x11, 0x07, 0x00, 0x64, 0x03]);
-
- buf.writeInt8(dutyCycle, 6);
- return buf;
- };
-
-
- Hub.prototype.led = function (color, callback) {
- this.write(this.encodeLed(color), callback);
- };
-
- Hub.prototype.subscribe = function (port, option, callback) {
- if (option === void 0) { option = 0; }
- if (typeof option === 'function') {
-
- callback = option;
- option = 0x00;
- }
- var portNum = typeof port === 'string' ? this.port2num[port] : port;
- this.write(
-
- buffer_1.Buffer.from([0x0a, 0x00, 0x41, portNum, option, 0x01, 0x00, 0x00, 0x00, 0x01]), callback);
- };
-
- Hub.prototype.unsubscribe = function (port, option, callback) {
- if (option === void 0) { option = 0; }
- if (typeof option === 'function') {
- callback = option;
- option = 0x00;
- }
- var portNum = typeof port === 'string' ? this.port2num[port] : port;
- this.write(
-
- buffer_1.Buffer.from([0x0a, 0x00, 0x41, portNum, option, 0x01, 0x00, 0x00, 0x00, 0x00]), callback);
- };
- Hub.prototype.subscribeAll = function () {
- var _this = this;
- Object.entries(this.ports).forEach(function (_a) {
- var port = _a[0], data = _a[1];
- if (data.deviceType === 'DISTANCE') {
- _this.subscribe(parseInt(port, 10), 8);
- }
- else if (data.deviceType === 'TILT') {
- _this.subscribe(parseInt(port, 10), 0);
- }
- else if (data.deviceType === 'IMOTOR') {
- _this.subscribe(parseInt(port, 10), 2);
- }
- else if (data.deviceType === 'MOTOR') {
- _this.subscribe(parseInt(port, 10), 2);
- }
- else {
- _this.logDebug("Port subscribtion not sent: " + port);
- }
- });
- };
-
- Hub.prototype.write = function (data, callback) {
- if (typeof data === 'string') {
- var arr_1 = [];
- data.split(' ').forEach(function (c) {
- arr_1.push(parseInt(c, 16));
- });
-
- data = buffer_1.Buffer.from(arr_1);
- }
-
- this.writeCue.push({
- data: data,
- secondArg: true,
- callback: callback,
- });
- this.writeFromCue();
- };
- Hub.prototype.writeFromCue = function () {
- var _this = this;
- if (this.writeCue.length === 0 || this.isWriting)
- return;
- var el = this.writeCue.shift();
- this.logDebug('Writing to device', el);
- this.isWriting = true;
- this.bluetooth
- .writeValue(el.data)
- .then(function () {
- _this.isWriting = false;
- if (typeof el.callback === 'function')
- el.callback();
- })
- .catch(function (err) {
- _this.isWriting = false;
- _this.log("Error while writing: " + el.data + " - Error " + err.toString());
-
- })
- .finally(function () {
- _this.writeFromCue();
- });
- };
- Hub.prototype.encodeMotorTimeMulti = function (port, seconds, dutyCycleA, dutyCycleB) {
- if (dutyCycleA === void 0) { dutyCycleA = 100; }
- if (dutyCycleB === void 0) { dutyCycleB = -100; }
-
- var buf = buffer_1.Buffer.from([0x0d, 0x00, 0x81, port, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x64, 0x7f, 0x03]);
- buf.writeUInt16LE(seconds * 1000, 6);
- buf.writeInt8(dutyCycleA, 8);
- buf.writeInt8(dutyCycleB, 9);
- return buf;
- };
- Hub.prototype.encodeMotorTime = function (port, seconds, dutyCycle) {
- if (dutyCycle === void 0) { dutyCycle = 100; }
-
- var buf = buffer_1.Buffer.from([0x0c, 0x00, 0x81, port, 0x11, 0x09, 0x00, 0x00, 0x00, 0x64, 0x7f, 0x03]);
- buf.writeUInt16LE(seconds * 1000, 6);
- buf.writeInt8(dutyCycle, 8);
- return buf;
- };
- Hub.prototype.encodeMotorAngleMulti = function (port, angle, dutyCycleA, dutyCycleB) {
- if (dutyCycleA === void 0) { dutyCycleA = 100; }
- if (dutyCycleB === void 0) { dutyCycleB = -100; }
-
- var buf = buffer_1.Buffer.from([0x0f, 0x00, 0x81, port, 0x11, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x7f, 0x03]);
- buf.writeUInt32LE(angle, 6);
- buf.writeInt8(dutyCycleA, 10);
- buf.writeInt8(dutyCycleB, 11);
- return buf;
- };
- Hub.prototype.encodeMotorAngle = function (port, angle, dutyCycle) {
- if (dutyCycle === void 0) { dutyCycle = 100; }
-
- var buf = buffer_1.Buffer.from([0x0e, 0x00, 0x81, port, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x7f, 0x03]);
- buf.writeUInt32LE(angle, 6);
- buf.writeInt8(dutyCycle, 10);
- return buf;
- };
- Hub.prototype.encodeLed = function (color) {
- if (typeof color === 'boolean') {
- color = color ? 'white' : 'off';
- }
- var colorNum = typeof color === 'string' ? this.ledColors.indexOf(color) : color;
-
- return buffer_1.Buffer.from([0x08, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, colorNum]);
- };
- return Hub;
- }());
- exports.Hub = Hub;
- }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
- },{"../helpers/buffer":9,"../helpers/eventEmitter":10}],12:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = function (d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [op[0] & 2, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.HubAsync = exports.DEFAULT_CONFIG = void 0;
- var hub_1 = require("./hub");
- var CALLBACK_TIMEOUT_MS = 1000 / 3;
- exports.DEFAULT_CONFIG = {
- METRIC_MODIFIER: 28.5,
- TURN_MODIFIER: 2.56,
- DRIVE_SPEED: 25,
- TURN_SPEED: 20,
- DEFAULT_STOP_DISTANCE: 105,
- DEFAULT_CLEAR_DISTANCE: 120,
- LEFT_MOTOR: 'A',
- RIGHT_MOTOR: 'B',
- VALID_MOTORS: ['A', 'B'],
- };
- var validateConfiguration = function (configuration) {
- configuration.leftMotor = configuration.leftMotor || exports.DEFAULT_CONFIG.LEFT_MOTOR;
- configuration.rightMotor = configuration.rightMotor || exports.DEFAULT_CONFIG.RIGHT_MOTOR;
-
- if (!exports.DEFAULT_CONFIG.VALID_MOTORS.includes(configuration.leftMotor))
- throw Error('Define left port port correctly');
-
- if (!exports.DEFAULT_CONFIG.VALID_MOTORS.includes(configuration.rightMotor))
- throw Error('Define right port port correctly');
- if (configuration.leftMotor === configuration.rightMotor)
- throw Error('Left and right motor can not be same');
- configuration.distanceModifier = configuration.distanceModifier || exports.DEFAULT_CONFIG.METRIC_MODIFIER;
- configuration.turnModifier = configuration.turnModifier || exports.DEFAULT_CONFIG.TURN_MODIFIER;
- configuration.driveSpeed = configuration.driveSpeed || exports.DEFAULT_CONFIG.DRIVE_SPEED;
- configuration.turnSpeed = configuration.turnSpeed || exports.DEFAULT_CONFIG.TURN_SPEED;
- configuration.defaultStopDistance = configuration.defaultStopDistance || exports.DEFAULT_CONFIG.DEFAULT_STOP_DISTANCE;
- configuration.defaultClearDistance = configuration.defaultClearDistance || exports.DEFAULT_CONFIG.DEFAULT_CLEAR_DISTANCE;
- };
- var waitForValueToSet = function (valueName, compareFunc, timeoutMs) {
- var _this = this;
- if (compareFunc === void 0) { compareFunc = function (valueNameToCompare) { return _this[valueNameToCompare]; }; }
- if (timeoutMs === void 0) { timeoutMs = 0; }
- if (compareFunc.bind(this)(valueName))
- return Promise.resolve(this[valueName]);
- return new Promise(function (resolve, reject) {
- setTimeout(function () { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- _a = resolve;
- return [4 , waitForValueToSet.bind(this)(valueName, compareFunc, timeoutMs)];
- case 1: return [2 , _a.apply(void 0, [_b.sent()])];
- }
- }); }); }, timeoutMs + 100);
- });
- };
- var HubAsync = (function (_super) {
- __extends(HubAsync, _super);
- function HubAsync(bluetooth, configuration) {
- var _this = _super.call(this, bluetooth) || this;
- validateConfiguration(configuration);
- _this.configuration = configuration;
- return _this;
- }
-
- HubAsync.prototype.disconnectAsync = function () {
- this.setDisconnected();
- return waitForValueToSet.bind(this)('hubDisconnected');
- };
-
- HubAsync.prototype.afterInitialization = function () {
- var _this = this;
- this.hubDisconnected = null;
- this.portData = {
- A: { angle: 0 },
- B: { angle: 0 },
- AB: { angle: 0 },
- C: { angle: 0 },
- D: { angle: 0 },
- LED: { angle: 0 },
- };
- this.useMetric = true;
- this.modifier = 1;
- this.emitter.on('rotation', function (rotation) { return (_this.portData[rotation.port].angle = rotation.angle); });
- this.emitter.on('disconnect', function () { return (_this.hubDisconnected = true); });
- this.emitter.on('distance', function (distance) { return (_this.distance = distance); });
- };
-
- HubAsync.prototype.ledAsync = function (color) {
- var _this = this;
- return new Promise(function (resolve, reject) {
- _this.led(color, function () {
-
- setTimeout(resolve, CALLBACK_TIMEOUT_MS);
- });
- });
- };
-
- HubAsync.prototype.motorTimeAsync = function (port, seconds, dutyCycle, wait) {
- var _this = this;
- if (dutyCycle === void 0) { dutyCycle = 100; }
- if (wait === void 0) { wait = false; }
- return new Promise(function (resolve, _) {
- _this.motorTime(port, seconds, dutyCycle, function () {
- setTimeout(resolve, wait ? CALLBACK_TIMEOUT_MS + seconds * 1000 : CALLBACK_TIMEOUT_MS);
- });
- });
- };
-
- HubAsync.prototype.motorTimeMultiAsync = function (seconds, dutyCycleA, dutyCycleB, wait) {
- var _this = this;
- if (dutyCycleA === void 0) { dutyCycleA = 100; }
- if (dutyCycleB === void 0) { dutyCycleB = 100; }
- if (wait === void 0) { wait = false; }
- return new Promise(function (resolve, _) {
- _this.motorTimeMulti(seconds, dutyCycleA, dutyCycleB, function () {
- setTimeout(resolve, wait ? CALLBACK_TIMEOUT_MS + seconds * 1000 : CALLBACK_TIMEOUT_MS);
- });
- });
- };
-
- HubAsync.prototype.motorAngleAsync = function (port, angle, dutyCycle, wait) {
- var _this = this;
- if (dutyCycle === void 0) { dutyCycle = 100; }
- if (wait === void 0) { wait = false; }
- return new Promise(function (resolve, _) {
- _this.motorAngle(port, angle, dutyCycle, function () { return __awaiter(_this, void 0, void 0, function () {
- var beforeTurn;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!wait) return [3 , 5];
- beforeTurn = void 0;
- _a.label = 1;
- case 1:
- beforeTurn = this.portData[port].angle;
- return [4 , new Promise(function (res) { return setTimeout(res, CALLBACK_TIMEOUT_MS); })];
- case 2:
- _a.sent();
- _a.label = 3;
- case 3:
- if (this.portData[port].angle !== beforeTurn) return [3 , 1];
- _a.label = 4;
- case 4:
- resolve();
- return [3 , 6];
- case 5:
- setTimeout(resolve, CALLBACK_TIMEOUT_MS);
- _a.label = 6;
- case 6: return [2 ];
- }
- });
- }); });
- });
- };
-
- HubAsync.prototype.motorAngleMultiAsync = function (angle, dutyCycleA, dutyCycleB, wait) {
- var _this = this;
- if (dutyCycleA === void 0) { dutyCycleA = 100; }
- if (dutyCycleB === void 0) { dutyCycleB = 100; }
- if (wait === void 0) { wait = false; }
- return new Promise(function (resolve, _) {
- _this.motorAngleMulti(angle, dutyCycleA, dutyCycleB, function () { return __awaiter(_this, void 0, void 0, function () {
- var beforeTurn;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!wait) return [3 , 5];
- beforeTurn = void 0;
- _a.label = 1;
- case 1:
- beforeTurn = this.portData['AB'].angle;
- return [4 , new Promise(function (res) { return setTimeout(res, CALLBACK_TIMEOUT_MS); })];
- case 2:
- _a.sent();
- _a.label = 3;
- case 3:
- if (this.portData['AB'].angle !== beforeTurn) return [3 , 1];
- _a.label = 4;
- case 4:
- resolve();
- return [3 , 6];
- case 5:
- setTimeout(resolve, CALLBACK_TIMEOUT_MS);
- _a.label = 6;
- case 6: return [2 ];
- }
- });
- }); });
- });
- };
-
- HubAsync.prototype.useMetricUnits = function () {
- this.useMetric = true;
- };
-
- HubAsync.prototype.useImperialUnits = function () {
- this.useMetric = false;
- };
-
- HubAsync.prototype.setFrictionModifier = function (modifier) {
- this.modifier = modifier;
- };
-
- HubAsync.prototype.drive = function (distance, wait) {
- if (wait === void 0) { wait = true; }
- var angle = Math.abs(distance) *
- ((this.useMetric ? this.configuration.distanceModifier : this.configuration.distanceModifier / 4) *
- this.modifier);
- var dutyCycleA = this.configuration.driveSpeed * (distance > 0 ? 1 : -1) * (this.configuration.leftMotor === 'A' ? 1 : -1);
- var dutyCycleB = this.configuration.driveSpeed * (distance > 0 ? 1 : -1) * (this.configuration.leftMotor === 'A' ? 1 : -1);
- return this.motorAngleMultiAsync(angle, dutyCycleA, dutyCycleB, wait);
- };
-
- HubAsync.prototype.turn = function (degrees, wait) {
- if (wait === void 0) { wait = true; }
- var angle = Math.abs(degrees) * this.configuration.turnModifier;
- var turnMotorModifier = this.configuration.leftMotor === 'A' ? 1 : -1;
- var leftTurn = this.configuration.turnSpeed * (degrees > 0 ? 1 : -1) * turnMotorModifier;
- var rightTurn = this.configuration.turnSpeed * (degrees > 0 ? -1 : 1) * turnMotorModifier;
- var dutyCycleA = this.configuration.leftMotor === 'A' ? leftTurn : rightTurn;
- var dutyCycleB = this.configuration.leftMotor === 'A' ? rightTurn : leftTurn;
- return this.motorAngleMultiAsync(angle, dutyCycleA, dutyCycleB, wait);
- };
-
- HubAsync.prototype.driveUntil = function (distance, wait) {
- if (distance === void 0) { distance = 0; }
- if (wait === void 0) { wait = true; }
- return __awaiter(this, void 0, void 0, function () {
- var distanceCheck, direction, compareFunc;
- var _this = this;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- distanceCheck = distance !== 0 ? (this.useMetric ? distance : distance * 2.54) : this.configuration.defaultStopDistance;
- direction = this.configuration.leftMotor === 'A' ? 1 : -1;
- compareFunc = direction === 1 ? function () { return distanceCheck >= _this.distance; } : function () { return distanceCheck <= _this.distance; };
- this.motorTimeMulti(60, this.configuration.driveSpeed * direction, this.configuration.driveSpeed * direction);
- if (!wait) return [3 , 3];
- return [4 , waitForValueToSet.bind(this)('distance', compareFunc)];
- case 1:
- _a.sent();
- return [4 , this.motorAngleMultiAsync(0)];
- case 2:
- _a.sent();
- return [3 , 4];
- case 3: return [2 , waitForValueToSet
- .bind(this)('distance', compareFunc)
- .then(function (_) { return _this.motorAngleMulti(0, 0, 0); })];
- case 4: return [2 ];
- }
- });
- });
- };
-
- HubAsync.prototype.turnUntil = function (direction, wait) {
- if (direction === void 0) { direction = 1; }
- if (wait === void 0) { wait = true; }
- return __awaiter(this, void 0, void 0, function () {
- var directionModifier;
- var _this = this;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- directionModifier = direction > 0 ? 1 : -1;
- this.turn(360 * directionModifier, false);
- if (!wait) return [3 , 3];
- return [4 , waitForValueToSet.bind(this)('distance', function () { return _this.distance >= _this.configuration.defaultClearDistance; })];
- case 1:
- _a.sent();
- return [4 , this.turn(0, false)];
- case 2:
- _a.sent();
- return [3 , 4];
- case 3: return [2 , waitForValueToSet
- .bind(this)('distance', function () { return _this.distance >= _this.configuration.defaultClearDistance; })
- .then(function (_) { return _this.turn(0, false); })];
- case 4: return [2 ];
- }
- });
- });
- };
- HubAsync.prototype.updateConfiguration = function (configuration) {
- validateConfiguration(configuration);
- this.configuration = configuration;
- };
- return HubAsync;
- }(hub_1.Hub));
- exports.HubAsync = HubAsync;
- },{"./hub":11}],13:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [op[0] & 2, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var boostConnector_1 = require("./boostConnector");
- var hubAsync_1 = require("./hub/hubAsync");
- var hub_control_1 = require("./ai/hub-control");
- var LegoBoost = (function () {
- function LegoBoost() {
- this.logDebug = function (s) { };
-
- this.deviceInfo = {
- ports: {
- A: { action: '', angle: 0 },
- B: { action: '', angle: 0 },
- AB: { action: '', angle: 0 },
- C: { action: '', angle: 0 },
- D: { action: '', angle: 0 },
- LED: { action: '', angle: 0 },
- },
- tilt: { roll: 0, pitch: 0 },
- distance: Number.MAX_SAFE_INTEGER,
- rssi: 0,
- color: '',
- error: '',
- connected: false,
- };
-
- this.controlData = {
- input: null,
- speed: 0,
- turnAngle: 0,
- tilt: { roll: 0, pitch: 0 },
- forceState: null,
- updateInputMode: null,
- controlUpdateTime: undefined,
- state: undefined,
- };
- }
-
- LegoBoost.prototype.connect = function (configuration) {
- if (configuration === void 0) { configuration = {}; }
- return __awaiter(this, void 0, void 0, function () {
- var bluetooth, e_1;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- _a.trys.push([0, 2, , 3]);
- this.configuration = configuration;
- return [4 , boostConnector_1.BoostConnector.connect(this.handleGattDisconnect.bind(this))];
- case 1:
- bluetooth = _a.sent();
- this.initHub(bluetooth, this.configuration);
- return [3 , 3];
- case 2:
- e_1 = _a.sent();
- console.log('Error from connect: ' + e_1);
- return [3 , 3];
- case 3: return [2 ];
- }
- });
- });
- };
- LegoBoost.prototype.initHub = function (bluetooth, configuration) {
- return __awaiter(this, void 0, void 0, function () {
- var _this = this;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- this.hub = new hubAsync_1.HubAsync(bluetooth, configuration);
- this.hub.logDebug = this.logDebug;
- this.hub.emitter.on('disconnect', function (evt) { return __awaiter(_this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- return [2 ];
- });
- }); });
- this.hub.emitter.on('connect', function (evt) { return __awaiter(_this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- this.hub.afterInitialization();
- return [4 , this.hub.ledAsync('white')];
- case 1:
- _a.sent();
- this.logDebug('Connected');
- return [2 ];
- }
- });
- }); });
- this.hubControl = new hub_control_1.HubControl(this.deviceInfo, this.controlData, configuration);
- return [4 , this.hubControl.start(this.hub)];
- case 1:
- _a.sent();
- this.updateTimer = setInterval(function () {
- _this.hubControl.update();
- }, 100);
- return [2 ];
- }
- });
- });
- };
- LegoBoost.prototype.handleGattDisconnect = function () {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- this.logDebug('handleGattDisconnect');
- if (this.deviceInfo.connected === false)
- return [2 ];
- this.hub.setDisconnected();
- this.deviceInfo.connected = false;
- clearInterval(this.updateTimer);
- this.logDebug('Disconnected');
- return [2 ];
- });
- });
- };
-
- LegoBoost.prototype.changeLed = function () {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.hub || this.hub.connected === false)
- return [2 ];
- this.color = this.color === 'pink' ? 'orange' : 'pink';
- return [4 , this.hub.ledAsync(this.color)];
- case 1:
- _a.sent();
- return [2 ];
- }
- });
- });
- };
-
- LegoBoost.prototype.driveToDirection = function (direction) {
- if (direction === void 0) { direction = 1; }
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.preCheck())
- return [2 ];
- if (!(direction > 0)) return [3 , 2];
- return [4 , this.hub.driveUntil()];
- case 1: return [2 , _a.sent()];
- case 2: return [4 , this.hub.drive(-10000)];
- case 3: return [2 , _a.sent()];
- }
- });
- });
- };
-
- LegoBoost.prototype.disconnect = function () {
- if (!this.hub || this.hub.connected === false)
- return;
- this.hub.setDisconnected();
- var success = boostConnector_1.BoostConnector.disconnect();
- return success;
- };
-
- LegoBoost.prototype.ai = function () {
- if (!this.hub || this.hub.connected === false)
- return;
- this.hubControl.setNextState('Drive');
- };
-
- LegoBoost.prototype.stop = function () {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.preCheck())
- return [2 ];
- this.controlData.speed = 0;
- this.controlData.turnAngle = 0;
- return [4 , this.hub.motorTimeMultiAsync(1, 0, 0)];
- case 1:
-
- return [2 , _a.sent()];
- }
- });
- });
- };
-
- LegoBoost.prototype.updateConfiguration = function (configuration) {
- if (!this.hub)
- return;
- this.hub.updateConfiguration(configuration);
- this.hubControl.updateConfiguration(configuration);
- };
-
-
- LegoBoost.prototype.led = function (color) {
- if (!this.preCheck())
- return;
- this.hub.led(color);
- };
-
- LegoBoost.prototype.ledAsync = function (color) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.preCheck())
- return [2 ];
- this.color = color;
- return [4 , this.hub.ledAsync(color)];
- case 1: return [2 , _a.sent()];
- }
- });
- });
- };
-
- LegoBoost.prototype.motorTime = function (port, seconds, dutyCycle) {
- if (dutyCycle === void 0) { dutyCycle = 100; }
- if (!this.preCheck())
- return;
- this.hub.motorTime(port, seconds, dutyCycle);
- };
-
- LegoBoost.prototype.motorTimeAsync = function (port, seconds, dutyCycle, wait) {
- if (dutyCycle === void 0) { dutyCycle = 100; }
- if (wait === void 0) { wait = true; }
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.preCheck())
- return [2 ];
- return [4 , this.hub.motorTimeAsync(port, seconds, dutyCycle, wait)];
- case 1:
- _a.sent();
- return [2 ];
- }
- });
- });
- };
-
- LegoBoost.prototype.motorTimeMulti = function (seconds, dutyCycleA, dutyCycleB) {
- if (dutyCycleA === void 0) { dutyCycleA = 100; }
- if (dutyCycleB === void 0) { dutyCycleB = 100; }
- if (!this.preCheck())
- return;
- this.hub.motorTimeMulti(seconds, dutyCycleA, dutyCycleB);
- };
-
- LegoBoost.prototype.motorTimeMultiAsync = function (seconds, dutyCycleA, dutyCycleB, wait) {
- if (dutyCycleA === void 0) { dutyCycleA = 100; }
- if (dutyCycleB === void 0) { dutyCycleB = 100; }
- if (wait === void 0) { wait = true; }
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.preCheck())
- return [2 ];
- return [4 , this.hub.motorTimeMultiAsync(seconds, dutyCycleA, dutyCycleB, wait)];
- case 1:
- _a.sent();
- return [2 ];
- }
- });
- });
- };
-
- LegoBoost.prototype.motorAngle = function (port, angle, dutyCycle) {
- if (dutyCycle === void 0) { dutyCycle = 100; }
- if (!this.preCheck())
- return;
- this.hub.motorAngle(port, angle, dutyCycle);
- };
-
- LegoBoost.prototype.motorAngleAsync = function (port, angle, dutyCycle, wait) {
- if (dutyCycle === void 0) { dutyCycle = 100; }
- if (wait === void 0) { wait = true; }
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.preCheck())
- return [2 ];
- return [4 , this.hub.motorAngleAsync(port, angle, dutyCycle, wait)];
- case 1:
- _a.sent();
- return [2 ];
- }
- });
- });
- };
-
- LegoBoost.prototype.motorAngleMulti = function (angle, dutyCycleA, dutyCycleB) {
- if (dutyCycleA === void 0) { dutyCycleA = 100; }
- if (dutyCycleB === void 0) { dutyCycleB = 100; }
- if (!this.preCheck())
- return;
- this.hub.motorAngleMulti(angle, dutyCycleA, dutyCycleB);
- };
-
- LegoBoost.prototype.motorAngleMultiAsync = function (angle, dutyCycleA, dutyCycleB, wait) {
- if (dutyCycleA === void 0) { dutyCycleA = 100; }
- if (dutyCycleB === void 0) { dutyCycleB = 100; }
- if (wait === void 0) { wait = true; }
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.preCheck())
- return [2 ];
- return [4 , this.hub.motorAngleMultiAsync(angle, dutyCycleA, dutyCycleB, wait)];
- case 1:
- _a.sent();
- return [2 ];
- }
- });
- });
- };
-
- LegoBoost.prototype.drive = function (distance, wait) {
- if (wait === void 0) { wait = true; }
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.preCheck())
- return [2 ];
- return [4 , this.hub.drive(distance, wait)];
- case 1: return [2 , _a.sent()];
- }
- });
- });
- };
-
- LegoBoost.prototype.turn = function (degrees, wait) {
- if (wait === void 0) { wait = true; }
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.preCheck())
- return [2 ];
- return [4 , this.hub.turn(degrees, wait)];
- case 1: return [2 , _a.sent()];
- }
- });
- });
- };
-
- LegoBoost.prototype.driveUntil = function (distance, wait) {
- if (distance === void 0) { distance = 0; }
- if (wait === void 0) { wait = true; }
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.preCheck())
- return [2 ];
- return [4 , this.hub.driveUntil(distance, wait)];
- case 1: return [2 , _a.sent()];
- }
- });
- });
- };
-
- LegoBoost.prototype.turnUntil = function (direction, wait) {
- if (direction === void 0) { direction = 1; }
- if (wait === void 0) { wait = true; }
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.preCheck())
- return [2 ];
- return [4 , this.hub.turnUntil(direction, wait)];
- case 1: return [2 , _a.sent()];
- }
- });
- });
- };
-
- LegoBoost.prototype.rawCommand = function (raw) {
- if (!this.preCheck())
- return;
- return this.hub.rawCommand(raw);
- };
- LegoBoost.prototype.preCheck = function () {
- if (!this.hub || this.hub.connected === false)
- return false;
- this.hubControl.setNextState('Manual');
- return true;
- };
- return LegoBoost;
- }());
- exports.default = LegoBoost;
- },{"./ai/hub-control":4,"./boostConnector":7,"./hub/hubAsync":12}]},{},[8])
|