| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509 |
- /*!
- * vue-qrcode v1.0.2
- * https://fengyuanchen.github.io/vue-qrcode
- *
- * Copyright 2018-present Chen Fengyuan
- * Released under the MIT license
- *
- * Date: 2020-01-18T06:04:33.222Z
- */
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
- typeof define === 'function' && define.amd ? define(factory) :
- (global = global || self, global.VueQrcode = factory());
- }(this, (function () { 'use strict';
- function commonjsRequire () {
- throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
- }
- function createCommonjsModule(fn, module) {
- return module = { exports: {} }, fn(module, module.exports), module.exports;
- }
- var qrcode = createCommonjsModule(function (module, exports) {
- (function(f){{module.exports=f();}})(function(){return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof commonjsRequire&&commonjsRequire;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 commonjsRequire&&commonjsRequire,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
- // can-promise has a crash in some versions of react native that dont have
- // standard global objects
- // https://github.com/soldair/node-qrcode/issues/157
- module.exports = function () {
- return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then
- };
- },{}],2:[function(require,module,exports){
- /**
- * Alignment pattern are fixed reference pattern in defined positions
- * in a matrix symbology, which enables the decode software to re-synchronise
- * the coordinate mapping of the image modules in the event of moderate amounts
- * of distortion of the image.
- *
- * Alignment patterns are present only in QR Code symbols of version 2 or larger
- * and their number depends on the symbol version.
- */
- var getSymbolSize = require('./utils').getSymbolSize;
- /**
- * Calculate the row/column coordinates of the center module of each alignment pattern
- * for the specified QR Code version.
- *
- * The alignment patterns are positioned symmetrically on either side of the diagonal
- * running from the top left corner of the symbol to the bottom right corner.
- *
- * Since positions are simmetrical only half of the coordinates are returned.
- * Each item of the array will represent in turn the x and y coordinate.
- * @see {@link getPositions}
- *
- * @param {Number} version QR Code version
- * @return {Array} Array of coordinate
- */
- exports.getRowColCoords = function getRowColCoords (version) {
- if (version === 1) return []
- var posCount = Math.floor(version / 7) + 2;
- var size = getSymbolSize(version);
- var intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
- var positions = [size - 7]; // Last coord is always (size - 7)
- for (var i = 1; i < posCount - 1; i++) {
- positions[i] = positions[i - 1] - intervals;
- }
- positions.push(6); // First coord is always 6
- return positions.reverse()
- };
- /**
- * Returns an array containing the positions of each alignment pattern.
- * Each array's element represent the center point of the pattern as (x, y) coordinates
- *
- * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
- * and filtering out the items that overlaps with finder pattern
- *
- * @example
- * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
- * The alignment patterns, therefore, are to be centered on (row, column)
- * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
- * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
- * and are not therefore used for alignment patterns.
- *
- * var pos = getPositions(7)
- * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
- *
- * @param {Number} version QR Code version
- * @return {Array} Array of coordinates
- */
- exports.getPositions = function getPositions (version) {
- var coords = [];
- var pos = exports.getRowColCoords(version);
- var posLength = pos.length;
- for (var i = 0; i < posLength; i++) {
- for (var j = 0; j < posLength; j++) {
- // Skip if position is occupied by finder patterns
- if ((i === 0 && j === 0) || // top-left
- (i === 0 && j === posLength - 1) || // bottom-left
- (i === posLength - 1 && j === 0)) { // top-right
- continue
- }
- coords.push([pos[i], pos[j]]);
- }
- }
- return coords
- };
- },{"./utils":21}],3:[function(require,module,exports){
- var Mode = require('./mode');
- /**
- * Array of characters available in alphanumeric mode
- *
- * As per QR Code specification, to each character
- * is assigned a value from 0 to 44 which in this case coincides
- * with the array index
- *
- * @type {Array}
- */
- var ALPHA_NUM_CHARS = [
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
- 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- ' ', '$', '%', '*', '+', '-', '.', '/', ':'
- ];
- function AlphanumericData (data) {
- this.mode = Mode.ALPHANUMERIC;
- this.data = data;
- }
- AlphanumericData.getBitsLength = function getBitsLength (length) {
- return 11 * Math.floor(length / 2) + 6 * (length % 2)
- };
- AlphanumericData.prototype.getLength = function getLength () {
- return this.data.length
- };
- AlphanumericData.prototype.getBitsLength = function getBitsLength () {
- return AlphanumericData.getBitsLength(this.data.length)
- };
- AlphanumericData.prototype.write = function write (bitBuffer) {
- var i;
- // Input data characters are divided into groups of two characters
- // and encoded as 11-bit binary codes.
- for (i = 0; i + 2 <= this.data.length; i += 2) {
- // The character value of the first character is multiplied by 45
- var value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
- // The character value of the second digit is added to the product
- value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
- // The sum is then stored as 11-bit binary number
- bitBuffer.put(value, 11);
- }
- // If the number of input data characters is not a multiple of two,
- // the character value of the final character is encoded as a 6-bit binary number.
- if (this.data.length % 2) {
- bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
- }
- };
- module.exports = AlphanumericData;
- },{"./mode":14}],4:[function(require,module,exports){
- function BitBuffer () {
- this.buffer = [];
- this.length = 0;
- }
- BitBuffer.prototype = {
- get: function (index) {
- var bufIndex = Math.floor(index / 8);
- return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
- },
- put: function (num, length) {
- for (var i = 0; i < length; i++) {
- this.putBit(((num >>> (length - i - 1)) & 1) === 1);
- }
- },
- getLengthInBits: function () {
- return this.length
- },
- putBit: function (bit) {
- var bufIndex = Math.floor(this.length / 8);
- if (this.buffer.length <= bufIndex) {
- this.buffer.push(0);
- }
- if (bit) {
- this.buffer[bufIndex] |= (0x80 >>> (this.length % 8));
- }
- this.length++;
- }
- };
- module.exports = BitBuffer;
- },{}],5:[function(require,module,exports){
- var BufferUtil = require('../utils/buffer');
- /**
- * Helper class to handle QR Code symbol modules
- *
- * @param {Number} size Symbol size
- */
- function BitMatrix (size) {
- if (!size || size < 1) {
- throw new Error('BitMatrix size must be defined and greater than 0')
- }
- this.size = size;
- this.data = BufferUtil.alloc(size * size);
- this.reservedBit = BufferUtil.alloc(size * size);
- }
- /**
- * Set bit value at specified location
- * If reserved flag is set, this bit will be ignored during masking process
- *
- * @param {Number} row
- * @param {Number} col
- * @param {Boolean} value
- * @param {Boolean} reserved
- */
- BitMatrix.prototype.set = function (row, col, value, reserved) {
- var index = row * this.size + col;
- this.data[index] = value;
- if (reserved) this.reservedBit[index] = true;
- };
- /**
- * Returns bit value at specified location
- *
- * @param {Number} row
- * @param {Number} col
- * @return {Boolean}
- */
- BitMatrix.prototype.get = function (row, col) {
- return this.data[row * this.size + col]
- };
- /**
- * Applies xor operator at specified location
- * (used during masking process)
- *
- * @param {Number} row
- * @param {Number} col
- * @param {Boolean} value
- */
- BitMatrix.prototype.xor = function (row, col, value) {
- this.data[row * this.size + col] ^= value;
- };
- /**
- * Check if bit at specified location is reserved
- *
- * @param {Number} row
- * @param {Number} col
- * @return {Boolean}
- */
- BitMatrix.prototype.isReserved = function (row, col) {
- return this.reservedBit[row * this.size + col]
- };
- module.exports = BitMatrix;
- },{"../utils/buffer":28}],6:[function(require,module,exports){
- var BufferUtil = require('../utils/buffer');
- var Mode = require('./mode');
- function ByteData (data) {
- this.mode = Mode.BYTE;
- this.data = BufferUtil.from(data);
- }
- ByteData.getBitsLength = function getBitsLength (length) {
- return length * 8
- };
- ByteData.prototype.getLength = function getLength () {
- return this.data.length
- };
- ByteData.prototype.getBitsLength = function getBitsLength () {
- return ByteData.getBitsLength(this.data.length)
- };
- ByteData.prototype.write = function (bitBuffer) {
- for (var i = 0, l = this.data.length; i < l; i++) {
- bitBuffer.put(this.data[i], 8);
- }
- };
- module.exports = ByteData;
- },{"../utils/buffer":28,"./mode":14}],7:[function(require,module,exports){
- var ECLevel = require('./error-correction-level');
- var EC_BLOCKS_TABLE = [
- // L M Q H
- 1, 1, 1, 1,
- 1, 1, 1, 1,
- 1, 1, 2, 2,
- 1, 2, 2, 4,
- 1, 2, 4, 4,
- 2, 4, 4, 4,
- 2, 4, 6, 5,
- 2, 4, 6, 6,
- 2, 5, 8, 8,
- 4, 5, 8, 8,
- 4, 5, 8, 11,
- 4, 8, 10, 11,
- 4, 9, 12, 16,
- 4, 9, 16, 16,
- 6, 10, 12, 18,
- 6, 10, 17, 16,
- 6, 11, 16, 19,
- 6, 13, 18, 21,
- 7, 14, 21, 25,
- 8, 16, 20, 25,
- 8, 17, 23, 25,
- 9, 17, 23, 34,
- 9, 18, 25, 30,
- 10, 20, 27, 32,
- 12, 21, 29, 35,
- 12, 23, 34, 37,
- 12, 25, 34, 40,
- 13, 26, 35, 42,
- 14, 28, 38, 45,
- 15, 29, 40, 48,
- 16, 31, 43, 51,
- 17, 33, 45, 54,
- 18, 35, 48, 57,
- 19, 37, 51, 60,
- 19, 38, 53, 63,
- 20, 40, 56, 66,
- 21, 43, 59, 70,
- 22, 45, 62, 74,
- 24, 47, 65, 77,
- 25, 49, 68, 81
- ];
- var EC_CODEWORDS_TABLE = [
- // L M Q H
- 7, 10, 13, 17,
- 10, 16, 22, 28,
- 15, 26, 36, 44,
- 20, 36, 52, 64,
- 26, 48, 72, 88,
- 36, 64, 96, 112,
- 40, 72, 108, 130,
- 48, 88, 132, 156,
- 60, 110, 160, 192,
- 72, 130, 192, 224,
- 80, 150, 224, 264,
- 96, 176, 260, 308,
- 104, 198, 288, 352,
- 120, 216, 320, 384,
- 132, 240, 360, 432,
- 144, 280, 408, 480,
- 168, 308, 448, 532,
- 180, 338, 504, 588,
- 196, 364, 546, 650,
- 224, 416, 600, 700,
- 224, 442, 644, 750,
- 252, 476, 690, 816,
- 270, 504, 750, 900,
- 300, 560, 810, 960,
- 312, 588, 870, 1050,
- 336, 644, 952, 1110,
- 360, 700, 1020, 1200,
- 390, 728, 1050, 1260,
- 420, 784, 1140, 1350,
- 450, 812, 1200, 1440,
- 480, 868, 1290, 1530,
- 510, 924, 1350, 1620,
- 540, 980, 1440, 1710,
- 570, 1036, 1530, 1800,
- 570, 1064, 1590, 1890,
- 600, 1120, 1680, 1980,
- 630, 1204, 1770, 2100,
- 660, 1260, 1860, 2220,
- 720, 1316, 1950, 2310,
- 750, 1372, 2040, 2430
- ];
- /**
- * Returns the number of error correction block that the QR Code should contain
- * for the specified version and error correction level.
- *
- * @param {Number} version QR Code version
- * @param {Number} errorCorrectionLevel Error correction level
- * @return {Number} Number of error correction blocks
- */
- exports.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {
- switch (errorCorrectionLevel) {
- case ECLevel.L:
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]
- case ECLevel.M:
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]
- case ECLevel.Q:
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]
- case ECLevel.H:
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]
- default:
- return undefined
- }
- };
- /**
- * Returns the number of error correction codewords to use for the specified
- * version and error correction level.
- *
- * @param {Number} version QR Code version
- * @param {Number} errorCorrectionLevel Error correction level
- * @return {Number} Number of error correction codewords
- */
- exports.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {
- switch (errorCorrectionLevel) {
- case ECLevel.L:
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]
- case ECLevel.M:
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]
- case ECLevel.Q:
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]
- case ECLevel.H:
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]
- default:
- return undefined
- }
- };
- },{"./error-correction-level":8}],8:[function(require,module,exports){
- exports.L = { bit: 1 };
- exports.M = { bit: 0 };
- exports.Q = { bit: 3 };
- exports.H = { bit: 2 };
- function fromString (string) {
- if (typeof string !== 'string') {
- throw new Error('Param is not a string')
- }
- var lcStr = string.toLowerCase();
- switch (lcStr) {
- case 'l':
- case 'low':
- return exports.L
- case 'm':
- case 'medium':
- return exports.M
- case 'q':
- case 'quartile':
- return exports.Q
- case 'h':
- case 'high':
- return exports.H
- default:
- throw new Error('Unknown EC Level: ' + string)
- }
- }
- exports.isValid = function isValid (level) {
- return level && typeof level.bit !== 'undefined' &&
- level.bit >= 0 && level.bit < 4
- };
- exports.from = function from (value, defaultValue) {
- if (exports.isValid(value)) {
- return value
- }
- try {
- return fromString(value)
- } catch (e) {
- return defaultValue
- }
- };
- },{}],9:[function(require,module,exports){
- var getSymbolSize = require('./utils').getSymbolSize;
- var FINDER_PATTERN_SIZE = 7;
- /**
- * Returns an array containing the positions of each finder pattern.
- * Each array's element represent the top-left point of the pattern as (x, y) coordinates
- *
- * @param {Number} version QR Code version
- * @return {Array} Array of coordinates
- */
- exports.getPositions = function getPositions (version) {
- var size = getSymbolSize(version);
- return [
- // top-left
- [0, 0],
- // top-right
- [size - FINDER_PATTERN_SIZE, 0],
- // bottom-left
- [0, size - FINDER_PATTERN_SIZE]
- ]
- };
- },{"./utils":21}],10:[function(require,module,exports){
- var Utils = require('./utils');
- var G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
- var G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
- var G15_BCH = Utils.getBCHDigit(G15);
- /**
- * Returns format information with relative error correction bits
- *
- * The format information is a 15-bit sequence containing 5 data bits,
- * with 10 error correction bits calculated using the (15, 5) BCH code.
- *
- * @param {Number} errorCorrectionLevel Error correction level
- * @param {Number} mask Mask pattern
- * @return {Number} Encoded format information bits
- */
- exports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
- var data = ((errorCorrectionLevel.bit << 3) | mask);
- var d = data << 10;
- while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
- d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH));
- }
- // xor final data with mask pattern in order to ensure that
- // no combination of Error Correction Level and data mask pattern
- // will result in an all-zero data string
- return ((data << 10) | d) ^ G15_MASK
- };
- },{"./utils":21}],11:[function(require,module,exports){
- var BufferUtil = require('../utils/buffer');
- var EXP_TABLE = BufferUtil.alloc(512);
- var LOG_TABLE = BufferUtil.alloc(256)
- /**
- * Precompute the log and anti-log tables for faster computation later
- *
- * For each possible value in the galois field 2^8, we will pre-compute
- * the logarithm and anti-logarithm (exponential) of this value
- *
- * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}
- */
- ;(function initTables () {
- var x = 1;
- for (var i = 0; i < 255; i++) {
- EXP_TABLE[i] = x;
- LOG_TABLE[x] = i;
- x <<= 1; // multiply by 2
- // The QR code specification says to use byte-wise modulo 100011101 arithmetic.
- // This means that when a number is 256 or larger, it should be XORed with 0x11D.
- if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)
- x ^= 0x11D;
- }
- }
- // Optimization: double the size of the anti-log table so that we don't need to mod 255 to
- // stay inside the bounds (because we will mainly use this table for the multiplication of
- // two GF numbers, no more).
- // @see {@link mul}
- for (i = 255; i < 512; i++) {
- EXP_TABLE[i] = EXP_TABLE[i - 255];
- }
- }());
- /**
- * Returns log value of n inside Galois Field
- *
- * @param {Number} n
- * @return {Number}
- */
- exports.log = function log (n) {
- if (n < 1) throw new Error('log(' + n + ')')
- return LOG_TABLE[n]
- };
- /**
- * Returns anti-log value of n inside Galois Field
- *
- * @param {Number} n
- * @return {Number}
- */
- exports.exp = function exp (n) {
- return EXP_TABLE[n]
- };
- /**
- * Multiplies two number inside Galois Field
- *
- * @param {Number} x
- * @param {Number} y
- * @return {Number}
- */
- exports.mul = function mul (x, y) {
- if (x === 0 || y === 0) return 0
- // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
- // @see {@link initTables}
- return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]
- };
- },{"../utils/buffer":28}],12:[function(require,module,exports){
- var Mode = require('./mode');
- var Utils = require('./utils');
- function KanjiData (data) {
- this.mode = Mode.KANJI;
- this.data = data;
- }
- KanjiData.getBitsLength = function getBitsLength (length) {
- return length * 13
- };
- KanjiData.prototype.getLength = function getLength () {
- return this.data.length
- };
- KanjiData.prototype.getBitsLength = function getBitsLength () {
- return KanjiData.getBitsLength(this.data.length)
- };
- KanjiData.prototype.write = function (bitBuffer) {
- var i;
- // In the Shift JIS system, Kanji characters are represented by a two byte combination.
- // These byte values are shifted from the JIS X 0208 values.
- // JIS X 0208 gives details of the shift coded representation.
- for (i = 0; i < this.data.length; i++) {
- var value = Utils.toSJIS(this.data[i]);
- // For characters with Shift JIS values from 0x8140 to 0x9FFC:
- if (value >= 0x8140 && value <= 0x9FFC) {
- // Subtract 0x8140 from Shift JIS value
- value -= 0x8140;
- // For characters with Shift JIS values from 0xE040 to 0xEBBF
- } else if (value >= 0xE040 && value <= 0xEBBF) {
- // Subtract 0xC140 from Shift JIS value
- value -= 0xC140;
- } else {
- throw new Error(
- 'Invalid SJIS character: ' + this.data[i] + '\n' +
- 'Make sure your charset is UTF-8')
- }
- // Multiply most significant byte of result by 0xC0
- // and add least significant byte to product
- value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff);
- // Convert result to a 13-bit binary string
- bitBuffer.put(value, 13);
- }
- };
- module.exports = KanjiData;
- },{"./mode":14,"./utils":21}],13:[function(require,module,exports){
- /**
- * Data mask pattern reference
- * @type {Object}
- */
- exports.Patterns = {
- PATTERN000: 0,
- PATTERN001: 1,
- PATTERN010: 2,
- PATTERN011: 3,
- PATTERN100: 4,
- PATTERN101: 5,
- PATTERN110: 6,
- PATTERN111: 7
- };
- /**
- * Weighted penalty scores for the undesirable features
- * @type {Object}
- */
- var PenaltyScores = {
- N1: 3,
- N2: 3,
- N3: 40,
- N4: 10
- };
- /**
- * Check if mask pattern value is valid
- *
- * @param {Number} mask Mask pattern
- * @return {Boolean} true if valid, false otherwise
- */
- exports.isValid = function isValid (mask) {
- return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7
- };
- /**
- * Returns mask pattern from a value.
- * If value is not valid, returns undefined
- *
- * @param {Number|String} value Mask pattern value
- * @return {Number} Valid mask pattern or undefined
- */
- exports.from = function from (value) {
- return exports.isValid(value) ? parseInt(value, 10) : undefined
- };
- /**
- * Find adjacent modules in row/column with the same color
- * and assign a penalty value.
- *
- * Points: N1 + i
- * i is the amount by which the number of adjacent modules of the same color exceeds 5
- */
- exports.getPenaltyN1 = function getPenaltyN1 (data) {
- var size = data.size;
- var points = 0;
- var sameCountCol = 0;
- var sameCountRow = 0;
- var lastCol = null;
- var lastRow = null;
- for (var row = 0; row < size; row++) {
- sameCountCol = sameCountRow = 0;
- lastCol = lastRow = null;
- for (var col = 0; col < size; col++) {
- var module = data.get(row, col);
- if (module === lastCol) {
- sameCountCol++;
- } else {
- if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
- lastCol = module;
- sameCountCol = 1;
- }
- module = data.get(col, row);
- if (module === lastRow) {
- sameCountRow++;
- } else {
- if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
- lastRow = module;
- sameCountRow = 1;
- }
- }
- if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
- if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
- }
- return points
- };
- /**
- * Find 2x2 blocks with the same color and assign a penalty value
- *
- * Points: N2 * (m - 1) * (n - 1)
- */
- exports.getPenaltyN2 = function getPenaltyN2 (data) {
- var size = data.size;
- var points = 0;
- for (var row = 0; row < size - 1; row++) {
- for (var col = 0; col < size - 1; col++) {
- var last = data.get(row, col) +
- data.get(row, col + 1) +
- data.get(row + 1, col) +
- data.get(row + 1, col + 1);
- if (last === 4 || last === 0) points++;
- }
- }
- return points * PenaltyScores.N2
- };
- /**
- * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
- * preceded or followed by light area 4 modules wide
- *
- * Points: N3 * number of pattern found
- */
- exports.getPenaltyN3 = function getPenaltyN3 (data) {
- var size = data.size;
- var points = 0;
- var bitsCol = 0;
- var bitsRow = 0;
- for (var row = 0; row < size; row++) {
- bitsCol = bitsRow = 0;
- for (var col = 0; col < size; col++) {
- bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col);
- if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++;
- bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row);
- if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++;
- }
- }
- return points * PenaltyScores.N3
- };
- /**
- * Calculate proportion of dark modules in entire symbol
- *
- * Points: N4 * k
- *
- * k is the rating of the deviation of the proportion of dark modules
- * in the symbol from 50% in steps of 5%
- */
- exports.getPenaltyN4 = function getPenaltyN4 (data) {
- var darkCount = 0;
- var modulesCount = data.data.length;
- for (var i = 0; i < modulesCount; i++) darkCount += data.data[i];
- var k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10);
- return k * PenaltyScores.N4
- };
- /**
- * Return mask value at given position
- *
- * @param {Number} maskPattern Pattern reference value
- * @param {Number} i Row
- * @param {Number} j Column
- * @return {Boolean} Mask value
- */
- function getMaskAt (maskPattern, i, j) {
- switch (maskPattern) {
- case exports.Patterns.PATTERN000: return (i + j) % 2 === 0
- case exports.Patterns.PATTERN001: return i % 2 === 0
- case exports.Patterns.PATTERN010: return j % 3 === 0
- case exports.Patterns.PATTERN011: return (i + j) % 3 === 0
- case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0
- case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0
- case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0
- case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0
- default: throw new Error('bad maskPattern:' + maskPattern)
- }
- }
- /**
- * Apply a mask pattern to a BitMatrix
- *
- * @param {Number} pattern Pattern reference number
- * @param {BitMatrix} data BitMatrix data
- */
- exports.applyMask = function applyMask (pattern, data) {
- var size = data.size;
- for (var col = 0; col < size; col++) {
- for (var row = 0; row < size; row++) {
- if (data.isReserved(row, col)) continue
- data.xor(row, col, getMaskAt(pattern, row, col));
- }
- }
- };
- /**
- * Returns the best mask pattern for data
- *
- * @param {BitMatrix} data
- * @return {Number} Mask pattern reference number
- */
- exports.getBestMask = function getBestMask (data, setupFormatFunc) {
- var numPatterns = Object.keys(exports.Patterns).length;
- var bestPattern = 0;
- var lowerPenalty = Infinity;
- for (var p = 0; p < numPatterns; p++) {
- setupFormatFunc(p);
- exports.applyMask(p, data);
- // Calculate penalty
- var penalty =
- exports.getPenaltyN1(data) +
- exports.getPenaltyN2(data) +
- exports.getPenaltyN3(data) +
- exports.getPenaltyN4(data);
- // Undo previously applied mask
- exports.applyMask(p, data);
- if (penalty < lowerPenalty) {
- lowerPenalty = penalty;
- bestPattern = p;
- }
- }
- return bestPattern
- };
- },{}],14:[function(require,module,exports){
- var VersionCheck = require('./version-check');
- var Regex = require('./regex');
- /**
- * Numeric mode encodes data from the decimal digit set (0 - 9)
- * (byte values 30HEX to 39HEX).
- * Normally, 3 data characters are represented by 10 bits.
- *
- * @type {Object}
- */
- exports.NUMERIC = {
- id: 'Numeric',
- bit: 1 << 0,
- ccBits: [10, 12, 14]
- };
- /**
- * Alphanumeric mode encodes data from a set of 45 characters,
- * i.e. 10 numeric digits (0 - 9),
- * 26 alphabetic characters (A - Z),
- * and 9 symbols (SP, $, %, *, +, -, ., /, :).
- * Normally, two input characters are represented by 11 bits.
- *
- * @type {Object}
- */
- exports.ALPHANUMERIC = {
- id: 'Alphanumeric',
- bit: 1 << 1,
- ccBits: [9, 11, 13]
- };
- /**
- * In byte mode, data is encoded at 8 bits per character.
- *
- * @type {Object}
- */
- exports.BYTE = {
- id: 'Byte',
- bit: 1 << 2,
- ccBits: [8, 16, 16]
- };
- /**
- * The Kanji mode efficiently encodes Kanji characters in accordance with
- * the Shift JIS system based on JIS X 0208.
- * The Shift JIS values are shifted from the JIS X 0208 values.
- * JIS X 0208 gives details of the shift coded representation.
- * Each two-byte character value is compacted to a 13-bit binary codeword.
- *
- * @type {Object}
- */
- exports.KANJI = {
- id: 'Kanji',
- bit: 1 << 3,
- ccBits: [8, 10, 12]
- };
- /**
- * Mixed mode will contain a sequences of data in a combination of any of
- * the modes described above
- *
- * @type {Object}
- */
- exports.MIXED = {
- bit: -1
- };
- /**
- * Returns the number of bits needed to store the data length
- * according to QR Code specifications.
- *
- * @param {Mode} mode Data mode
- * @param {Number} version QR Code version
- * @return {Number} Number of bits
- */
- exports.getCharCountIndicator = function getCharCountIndicator (mode, version) {
- if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)
- if (!VersionCheck.isValid(version)) {
- throw new Error('Invalid version: ' + version)
- }
- if (version >= 1 && version < 10) return mode.ccBits[0]
- else if (version < 27) return mode.ccBits[1]
- return mode.ccBits[2]
- };
- /**
- * Returns the most efficient mode to store the specified data
- *
- * @param {String} dataStr Input data string
- * @return {Mode} Best mode
- */
- exports.getBestModeForData = function getBestModeForData (dataStr) {
- if (Regex.testNumeric(dataStr)) return exports.NUMERIC
- else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC
- else if (Regex.testKanji(dataStr)) return exports.KANJI
- else return exports.BYTE
- };
- /**
- * Return mode name as string
- *
- * @param {Mode} mode Mode object
- * @returns {String} Mode name
- */
- exports.toString = function toString (mode) {
- if (mode && mode.id) return mode.id
- throw new Error('Invalid mode')
- };
- /**
- * Check if input param is a valid mode object
- *
- * @param {Mode} mode Mode object
- * @returns {Boolean} True if valid mode, false otherwise
- */
- exports.isValid = function isValid (mode) {
- return mode && mode.bit && mode.ccBits
- };
- /**
- * Get mode object from its name
- *
- * @param {String} string Mode name
- * @returns {Mode} Mode object
- */
- function fromString (string) {
- if (typeof string !== 'string') {
- throw new Error('Param is not a string')
- }
- var lcStr = string.toLowerCase();
- switch (lcStr) {
- case 'numeric':
- return exports.NUMERIC
- case 'alphanumeric':
- return exports.ALPHANUMERIC
- case 'kanji':
- return exports.KANJI
- case 'byte':
- return exports.BYTE
- default:
- throw new Error('Unknown mode: ' + string)
- }
- }
- /**
- * Returns mode from a value.
- * If value is not a valid mode, returns defaultValue
- *
- * @param {Mode|String} value Encoding mode
- * @param {Mode} defaultValue Fallback value
- * @return {Mode} Encoding mode
- */
- exports.from = function from (value, defaultValue) {
- if (exports.isValid(value)) {
- return value
- }
- try {
- return fromString(value)
- } catch (e) {
- return defaultValue
- }
- };
- },{"./regex":19,"./version-check":22}],15:[function(require,module,exports){
- var Mode = require('./mode');
- function NumericData (data) {
- this.mode = Mode.NUMERIC;
- this.data = data.toString();
- }
- NumericData.getBitsLength = function getBitsLength (length) {
- return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
- };
- NumericData.prototype.getLength = function getLength () {
- return this.data.length
- };
- NumericData.prototype.getBitsLength = function getBitsLength () {
- return NumericData.getBitsLength(this.data.length)
- };
- NumericData.prototype.write = function write (bitBuffer) {
- var i, group, value;
- // The input data string is divided into groups of three digits,
- // and each group is converted to its 10-bit binary equivalent.
- for (i = 0; i + 3 <= this.data.length; i += 3) {
- group = this.data.substr(i, 3);
- value = parseInt(group, 10);
- bitBuffer.put(value, 10);
- }
- // If the number of input digits is not an exact multiple of three,
- // the final one or two digits are converted to 4 or 7 bits respectively.
- var remainingNum = this.data.length - i;
- if (remainingNum > 0) {
- group = this.data.substr(i);
- value = parseInt(group, 10);
- bitBuffer.put(value, remainingNum * 3 + 1);
- }
- };
- module.exports = NumericData;
- },{"./mode":14}],16:[function(require,module,exports){
- var BufferUtil = require('../utils/buffer');
- var GF = require('./galois-field');
- /**
- * Multiplies two polynomials inside Galois Field
- *
- * @param {Buffer} p1 Polynomial
- * @param {Buffer} p2 Polynomial
- * @return {Buffer} Product of p1 and p2
- */
- exports.mul = function mul (p1, p2) {
- var coeff = BufferUtil.alloc(p1.length + p2.length - 1);
- for (var i = 0; i < p1.length; i++) {
- for (var j = 0; j < p2.length; j++) {
- coeff[i + j] ^= GF.mul(p1[i], p2[j]);
- }
- }
- return coeff
- };
- /**
- * Calculate the remainder of polynomials division
- *
- * @param {Buffer} divident Polynomial
- * @param {Buffer} divisor Polynomial
- * @return {Buffer} Remainder
- */
- exports.mod = function mod (divident, divisor) {
- var result = BufferUtil.from(divident);
- while ((result.length - divisor.length) >= 0) {
- var coeff = result[0];
- for (var i = 0; i < divisor.length; i++) {
- result[i] ^= GF.mul(divisor[i], coeff);
- }
- // remove all zeros from buffer head
- var offset = 0;
- while (offset < result.length && result[offset] === 0) offset++;
- result = result.slice(offset);
- }
- return result
- };
- /**
- * Generate an irreducible generator polynomial of specified degree
- * (used by Reed-Solomon encoder)
- *
- * @param {Number} degree Degree of the generator polynomial
- * @return {Buffer} Buffer containing polynomial coefficients
- */
- exports.generateECPolynomial = function generateECPolynomial (degree) {
- var poly = BufferUtil.from([1]);
- for (var i = 0; i < degree; i++) {
- poly = exports.mul(poly, [1, GF.exp(i)]);
- }
- return poly
- };
- },{"../utils/buffer":28,"./galois-field":11}],17:[function(require,module,exports){
- var BufferUtil = require('../utils/buffer');
- var Utils = require('./utils');
- var ECLevel = require('./error-correction-level');
- var BitBuffer = require('./bit-buffer');
- var BitMatrix = require('./bit-matrix');
- var AlignmentPattern = require('./alignment-pattern');
- var FinderPattern = require('./finder-pattern');
- var MaskPattern = require('./mask-pattern');
- var ECCode = require('./error-correction-code');
- var ReedSolomonEncoder = require('./reed-solomon-encoder');
- var Version = require('./version');
- var FormatInfo = require('./format-info');
- var Mode = require('./mode');
- var Segments = require('./segments');
- var isArray = require('isarray');
- /**
- * QRCode for JavaScript
- *
- * modified by Ryan Day for nodejs support
- * Copyright (c) 2011 Ryan Day
- *
- * Licensed under the MIT license:
- * http://www.opensource.org/licenses/mit-license.php
- *
- //---------------------------------------------------------------------
- // QRCode for JavaScript
- //
- // Copyright (c) 2009 Kazuhiko Arase
- //
- // URL: http://www.d-project.com/
- //
- // Licensed under the MIT license:
- // http://www.opensource.org/licenses/mit-license.php
- //
- // The word "QR Code" is registered trademark of
- // DENSO WAVE INCORPORATED
- // http://www.denso-wave.com/qrcode/faqpatent-e.html
- //
- //---------------------------------------------------------------------
- */
- /**
- * Add finder patterns bits to matrix
- *
- * @param {BitMatrix} matrix Modules matrix
- * @param {Number} version QR Code version
- */
- function setupFinderPattern (matrix, version) {
- var size = matrix.size;
- var pos = FinderPattern.getPositions(version);
- for (var i = 0; i < pos.length; i++) {
- var row = pos[i][0];
- var col = pos[i][1];
- for (var r = -1; r <= 7; r++) {
- if (row + r <= -1 || size <= row + r) continue
- for (var c = -1; c <= 7; c++) {
- if (col + c <= -1 || size <= col + c) continue
- if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||
- (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||
- (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {
- matrix.set(row + r, col + c, true, true);
- } else {
- matrix.set(row + r, col + c, false, true);
- }
- }
- }
- }
- }
- /**
- * Add timing pattern bits to matrix
- *
- * Note: this function must be called before {@link setupAlignmentPattern}
- *
- * @param {BitMatrix} matrix Modules matrix
- */
- function setupTimingPattern (matrix) {
- var size = matrix.size;
- for (var r = 8; r < size - 8; r++) {
- var value = r % 2 === 0;
- matrix.set(r, 6, value, true);
- matrix.set(6, r, value, true);
- }
- }
- /**
- * Add alignment patterns bits to matrix
- *
- * Note: this function must be called after {@link setupTimingPattern}
- *
- * @param {BitMatrix} matrix Modules matrix
- * @param {Number} version QR Code version
- */
- function setupAlignmentPattern (matrix, version) {
- var pos = AlignmentPattern.getPositions(version);
- for (var i = 0; i < pos.length; i++) {
- var row = pos[i][0];
- var col = pos[i][1];
- for (var r = -2; r <= 2; r++) {
- for (var c = -2; c <= 2; c++) {
- if (r === -2 || r === 2 || c === -2 || c === 2 ||
- (r === 0 && c === 0)) {
- matrix.set(row + r, col + c, true, true);
- } else {
- matrix.set(row + r, col + c, false, true);
- }
- }
- }
- }
- }
- /**
- * Add version info bits to matrix
- *
- * @param {BitMatrix} matrix Modules matrix
- * @param {Number} version QR Code version
- */
- function setupVersionInfo (matrix, version) {
- var size = matrix.size;
- var bits = Version.getEncodedBits(version);
- var row, col, mod;
- for (var i = 0; i < 18; i++) {
- row = Math.floor(i / 3);
- col = i % 3 + size - 8 - 3;
- mod = ((bits >> i) & 1) === 1;
- matrix.set(row, col, mod, true);
- matrix.set(col, row, mod, true);
- }
- }
- /**
- * Add format info bits to matrix
- *
- * @param {BitMatrix} matrix Modules matrix
- * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
- * @param {Number} maskPattern Mask pattern reference value
- */
- function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {
- var size = matrix.size;
- var bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
- var i, mod;
- for (i = 0; i < 15; i++) {
- mod = ((bits >> i) & 1) === 1;
- // vertical
- if (i < 6) {
- matrix.set(i, 8, mod, true);
- } else if (i < 8) {
- matrix.set(i + 1, 8, mod, true);
- } else {
- matrix.set(size - 15 + i, 8, mod, true);
- }
- // horizontal
- if (i < 8) {
- matrix.set(8, size - i - 1, mod, true);
- } else if (i < 9) {
- matrix.set(8, 15 - i - 1 + 1, mod, true);
- } else {
- matrix.set(8, 15 - i - 1, mod, true);
- }
- }
- // fixed module
- matrix.set(size - 8, 8, 1, true);
- }
- /**
- * Add encoded data bits to matrix
- *
- * @param {BitMatrix} matrix Modules matrix
- * @param {Buffer} data Data codewords
- */
- function setupData (matrix, data) {
- var size = matrix.size;
- var inc = -1;
- var row = size - 1;
- var bitIndex = 7;
- var byteIndex = 0;
- for (var col = size - 1; col > 0; col -= 2) {
- if (col === 6) col--;
- while (true) {
- for (var c = 0; c < 2; c++) {
- if (!matrix.isReserved(row, col - c)) {
- var dark = false;
- if (byteIndex < data.length) {
- dark = (((data[byteIndex] >>> bitIndex) & 1) === 1);
- }
- matrix.set(row, col - c, dark);
- bitIndex--;
- if (bitIndex === -1) {
- byteIndex++;
- bitIndex = 7;
- }
- }
- }
- row += inc;
- if (row < 0 || size <= row) {
- row -= inc;
- inc = -inc;
- break
- }
- }
- }
- }
- /**
- * Create encoded codewords from data input
- *
- * @param {Number} version QR Code version
- * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
- * @param {ByteData} data Data input
- * @return {Buffer} Buffer containing encoded codewords
- */
- function createData (version, errorCorrectionLevel, segments) {
- // Prepare data buffer
- var buffer = new BitBuffer();
- segments.forEach(function (data) {
- // prefix data with mode indicator (4 bits)
- buffer.put(data.mode.bit, 4);
- // Prefix data with character count indicator.
- // The character count indicator is a string of bits that represents the
- // number of characters that are being encoded.
- // The character count indicator must be placed after the mode indicator
- // and must be a certain number of bits long, depending on the QR version
- // and data mode
- // @see {@link Mode.getCharCountIndicator}.
- buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
- // add binary data sequence to buffer
- data.write(buffer);
- });
- // Calculate required number of bits
- var totalCodewords = Utils.getSymbolTotalCodewords(version);
- var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
- var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
- // Add a terminator.
- // If the bit string is shorter than the total number of required bits,
- // a terminator of up to four 0s must be added to the right side of the string.
- // If the bit string is more than four bits shorter than the required number of bits,
- // add four 0s to the end.
- if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
- buffer.put(0, 4);
- }
- // If the bit string is fewer than four bits shorter, add only the number of 0s that
- // are needed to reach the required number of bits.
- // After adding the terminator, if the number of bits in the string is not a multiple of 8,
- // pad the string on the right with 0s to make the string's length a multiple of 8.
- while (buffer.getLengthInBits() % 8 !== 0) {
- buffer.putBit(0);
- }
- // Add pad bytes if the string is still shorter than the total number of required bits.
- // Extend the buffer to fill the data capacity of the symbol corresponding to
- // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
- // and 00010001 (0x11) alternately.
- var remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
- for (var i = 0; i < remainingByte; i++) {
- buffer.put(i % 2 ? 0x11 : 0xEC, 8);
- }
- return createCodewords(buffer, version, errorCorrectionLevel)
- }
- /**
- * Encode input data with Reed-Solomon and return codewords with
- * relative error correction bits
- *
- * @param {BitBuffer} bitBuffer Data to encode
- * @param {Number} version QR Code version
- * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
- * @return {Buffer} Buffer containing encoded codewords
- */
- function createCodewords (bitBuffer, version, errorCorrectionLevel) {
- // Total codewords for this QR code version (Data + Error correction)
- var totalCodewords = Utils.getSymbolTotalCodewords(version);
- // Total number of error correction codewords
- var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
- // Total number of data codewords
- var dataTotalCodewords = totalCodewords - ecTotalCodewords;
- // Total number of blocks
- var ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
- // Calculate how many blocks each group should contain
- var blocksInGroup2 = totalCodewords % ecTotalBlocks;
- var blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
- var totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
- var dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
- var dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
- // Number of EC codewords is the same for both groups
- var ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
- // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
- var rs = new ReedSolomonEncoder(ecCount);
- var offset = 0;
- var dcData = new Array(ecTotalBlocks);
- var ecData = new Array(ecTotalBlocks);
- var maxDataSize = 0;
- var buffer = BufferUtil.from(bitBuffer.buffer);
- // Divide the buffer into the required number of blocks
- for (var b = 0; b < ecTotalBlocks; b++) {
- var dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
- // extract a block of data from buffer
- dcData[b] = buffer.slice(offset, offset + dataSize);
- // Calculate EC codewords for this data block
- ecData[b] = rs.encode(dcData[b]);
- offset += dataSize;
- maxDataSize = Math.max(maxDataSize, dataSize);
- }
- // Create final data
- // Interleave the data and error correction codewords from each block
- var data = BufferUtil.alloc(totalCodewords);
- var index = 0;
- var i, r;
- // Add data codewords
- for (i = 0; i < maxDataSize; i++) {
- for (r = 0; r < ecTotalBlocks; r++) {
- if (i < dcData[r].length) {
- data[index++] = dcData[r][i];
- }
- }
- }
- // Apped EC codewords
- for (i = 0; i < ecCount; i++) {
- for (r = 0; r < ecTotalBlocks; r++) {
- data[index++] = ecData[r][i];
- }
- }
- return data
- }
- /**
- * Build QR Code symbol
- *
- * @param {String} data Input string
- * @param {Number} version QR Code version
- * @param {ErrorCorretionLevel} errorCorrectionLevel Error level
- * @param {MaskPattern} maskPattern Mask pattern
- * @return {Object} Object containing symbol data
- */
- function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
- var segments;
- if (isArray(data)) {
- segments = Segments.fromArray(data);
- } else if (typeof data === 'string') {
- var estimatedVersion = version;
- if (!estimatedVersion) {
- var rawSegments = Segments.rawSplit(data);
- // Estimate best version that can contain raw splitted segments
- estimatedVersion = Version.getBestVersionForData(rawSegments,
- errorCorrectionLevel);
- }
- // Build optimized segments
- // If estimated version is undefined, try with the highest version
- segments = Segments.fromString(data, estimatedVersion || 40);
- } else {
- throw new Error('Invalid data')
- }
- // Get the min version that can contain data
- var bestVersion = Version.getBestVersionForData(segments,
- errorCorrectionLevel);
- // If no version is found, data cannot be stored
- if (!bestVersion) {
- throw new Error('The amount of data is too big to be stored in a QR Code')
- }
- // If not specified, use min version as default
- if (!version) {
- version = bestVersion;
- // Check if the specified version can contain the data
- } else if (version < bestVersion) {
- throw new Error('\n' +
- 'The chosen QR Code version cannot contain this amount of data.\n' +
- 'Minimum version required to store current data is: ' + bestVersion + '.\n'
- )
- }
- var dataBits = createData(version, errorCorrectionLevel, segments);
- // Allocate matrix buffer
- var moduleCount = Utils.getSymbolSize(version);
- var modules = new BitMatrix(moduleCount);
- // Add function modules
- setupFinderPattern(modules, version);
- setupTimingPattern(modules);
- setupAlignmentPattern(modules, version);
- // Add temporary dummy bits for format info just to set them as reserved.
- // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
- // since the masking operation must be performed only on the encoding region.
- // These blocks will be replaced with correct values later in code.
- setupFormatInfo(modules, errorCorrectionLevel, 0);
- if (version >= 7) {
- setupVersionInfo(modules, version);
- }
- // Add data codewords
- setupData(modules, dataBits);
- if (isNaN(maskPattern)) {
- // Find best mask pattern
- maskPattern = MaskPattern.getBestMask(modules,
- setupFormatInfo.bind(null, modules, errorCorrectionLevel));
- }
- // Apply mask pattern
- MaskPattern.applyMask(maskPattern, modules);
- // Replace format info bits with correct values
- setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
- return {
- modules: modules,
- version: version,
- errorCorrectionLevel: errorCorrectionLevel,
- maskPattern: maskPattern,
- segments: segments
- }
- }
- /**
- * QR Code
- *
- * @param {String | Array} data Input data
- * @param {Object} options Optional configurations
- * @param {Number} options.version QR Code version
- * @param {String} options.errorCorrectionLevel Error correction level
- * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
- */
- exports.create = function create (data, options) {
- if (typeof data === 'undefined' || data === '') {
- throw new Error('No input text')
- }
- var errorCorrectionLevel = ECLevel.M;
- var version;
- var mask;
- if (typeof options !== 'undefined') {
- // Use higher error correction level as default
- errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
- version = Version.from(options.version);
- mask = MaskPattern.from(options.maskPattern);
- if (options.toSJISFunc) {
- Utils.setToSJISFunction(options.toSJISFunc);
- }
- }
- return createSymbol(data, version, errorCorrectionLevel, mask)
- };
- },{"../utils/buffer":28,"./alignment-pattern":2,"./bit-buffer":4,"./bit-matrix":5,"./error-correction-code":7,"./error-correction-level":8,"./finder-pattern":9,"./format-info":10,"./mask-pattern":13,"./mode":14,"./reed-solomon-encoder":18,"./segments":20,"./utils":21,"./version":23,"isarray":33}],18:[function(require,module,exports){
- var BufferUtil = require('../utils/buffer');
- var Polynomial = require('./polynomial');
- var Buffer = require('buffer').Buffer;
- function ReedSolomonEncoder (degree) {
- this.genPoly = undefined;
- this.degree = degree;
- if (this.degree) this.initialize(this.degree);
- }
- /**
- * Initialize the encoder.
- * The input param should correspond to the number of error correction codewords.
- *
- * @param {Number} degree
- */
- ReedSolomonEncoder.prototype.initialize = function initialize (degree) {
- // create an irreducible generator polynomial
- this.degree = degree;
- this.genPoly = Polynomial.generateECPolynomial(this.degree);
- };
- /**
- * Encodes a chunk of data
- *
- * @param {Buffer} data Buffer containing input data
- * @return {Buffer} Buffer containing encoded data
- */
- ReedSolomonEncoder.prototype.encode = function encode (data) {
- if (!this.genPoly) {
- throw new Error('Encoder not initialized')
- }
- // Calculate EC for this data block
- // extends data size to data+genPoly size
- var pad = BufferUtil.alloc(this.degree);
- var paddedData = Buffer.concat([data, pad], data.length + this.degree);
- // The error correction codewords are the remainder after dividing the data codewords
- // by a generator polynomial
- var remainder = Polynomial.mod(paddedData, this.genPoly);
- // return EC data blocks (last n byte, where n is the degree of genPoly)
- // If coefficients number in remainder are less than genPoly degree,
- // pad with 0s to the left to reach the needed number of coefficients
- var start = this.degree - remainder.length;
- if (start > 0) {
- var buff = BufferUtil.alloc(this.degree);
- remainder.copy(buff, start);
- return buff
- }
- return remainder
- };
- module.exports = ReedSolomonEncoder;
- },{"../utils/buffer":28,"./polynomial":16,"buffer":30}],19:[function(require,module,exports){
- var numeric = '[0-9]+';
- var alphanumeric = '[A-Z $%*+\\-./:]+';
- var kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +
- '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +
- '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +
- '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+';
- kanji = kanji.replace(/u/g, '\\u');
- var byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+';
- exports.KANJI = new RegExp(kanji, 'g');
- exports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g');
- exports.BYTE = new RegExp(byte, 'g');
- exports.NUMERIC = new RegExp(numeric, 'g');
- exports.ALPHANUMERIC = new RegExp(alphanumeric, 'g');
- var TEST_KANJI = new RegExp('^' + kanji + '$');
- var TEST_NUMERIC = new RegExp('^' + numeric + '$');
- var TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$');
- exports.testKanji = function testKanji (str) {
- return TEST_KANJI.test(str)
- };
- exports.testNumeric = function testNumeric (str) {
- return TEST_NUMERIC.test(str)
- };
- exports.testAlphanumeric = function testAlphanumeric (str) {
- return TEST_ALPHANUMERIC.test(str)
- };
- },{}],20:[function(require,module,exports){
- var Mode = require('./mode');
- var NumericData = require('./numeric-data');
- var AlphanumericData = require('./alphanumeric-data');
- var ByteData = require('./byte-data');
- var KanjiData = require('./kanji-data');
- var Regex = require('./regex');
- var Utils = require('./utils');
- var dijkstra = require('dijkstrajs');
- /**
- * Returns UTF8 byte length
- *
- * @param {String} str Input string
- * @return {Number} Number of byte
- */
- function getStringByteLength (str) {
- return unescape(encodeURIComponent(str)).length
- }
- /**
- * Get a list of segments of the specified mode
- * from a string
- *
- * @param {Mode} mode Segment mode
- * @param {String} str String to process
- * @return {Array} Array of object with segments data
- */
- function getSegments (regex, mode, str) {
- var segments = [];
- var result;
- while ((result = regex.exec(str)) !== null) {
- segments.push({
- data: result[0],
- index: result.index,
- mode: mode,
- length: result[0].length
- });
- }
- return segments
- }
- /**
- * Extracts a series of segments with the appropriate
- * modes from a string
- *
- * @param {String} dataStr Input string
- * @return {Array} Array of object with segments data
- */
- function getSegmentsFromString (dataStr) {
- var numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
- var alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
- var byteSegs;
- var kanjiSegs;
- if (Utils.isKanjiModeEnabled()) {
- byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
- kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
- } else {
- byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
- kanjiSegs = [];
- }
- var segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
- return segs
- .sort(function (s1, s2) {
- return s1.index - s2.index
- })
- .map(function (obj) {
- return {
- data: obj.data,
- mode: obj.mode,
- length: obj.length
- }
- })
- }
- /**
- * Returns how many bits are needed to encode a string of
- * specified length with the specified mode
- *
- * @param {Number} length String length
- * @param {Mode} mode Segment mode
- * @return {Number} Bit length
- */
- function getSegmentBitsLength (length, mode) {
- switch (mode) {
- case Mode.NUMERIC:
- return NumericData.getBitsLength(length)
- case Mode.ALPHANUMERIC:
- return AlphanumericData.getBitsLength(length)
- case Mode.KANJI:
- return KanjiData.getBitsLength(length)
- case Mode.BYTE:
- return ByteData.getBitsLength(length)
- }
- }
- /**
- * Merges adjacent segments which have the same mode
- *
- * @param {Array} segs Array of object with segments data
- * @return {Array} Array of object with segments data
- */
- function mergeSegments (segs) {
- return segs.reduce(function (acc, curr) {
- var prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
- if (prevSeg && prevSeg.mode === curr.mode) {
- acc[acc.length - 1].data += curr.data;
- return acc
- }
- acc.push(curr);
- return acc
- }, [])
- }
- /**
- * Generates a list of all possible nodes combination which
- * will be used to build a segments graph.
- *
- * Nodes are divided by groups. Each group will contain a list of all the modes
- * in which is possible to encode the given text.
- *
- * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
- * The group for '12345' will contain then 3 objects, one for each
- * possible encoding mode.
- *
- * Each node represents a possible segment.
- *
- * @param {Array} segs Array of object with segments data
- * @return {Array} Array of object with segments data
- */
- function buildNodes (segs) {
- var nodes = [];
- for (var i = 0; i < segs.length; i++) {
- var seg = segs[i];
- switch (seg.mode) {
- case Mode.NUMERIC:
- nodes.push([seg,
- { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
- { data: seg.data, mode: Mode.BYTE, length: seg.length }
- ]);
- break
- case Mode.ALPHANUMERIC:
- nodes.push([seg,
- { data: seg.data, mode: Mode.BYTE, length: seg.length }
- ]);
- break
- case Mode.KANJI:
- nodes.push([seg,
- { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
- ]);
- break
- case Mode.BYTE:
- nodes.push([
- { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
- ]);
- }
- }
- return nodes
- }
- /**
- * Builds a graph from a list of nodes.
- * All segments in each node group will be connected with all the segments of
- * the next group and so on.
- *
- * At each connection will be assigned a weight depending on the
- * segment's byte length.
- *
- * @param {Array} nodes Array of object with segments data
- * @param {Number} version QR Code version
- * @return {Object} Graph of all possible segments
- */
- function buildGraph (nodes, version) {
- var table = {};
- var graph = {'start': {}};
- var prevNodeIds = ['start'];
- for (var i = 0; i < nodes.length; i++) {
- var nodeGroup = nodes[i];
- var currentNodeIds = [];
- for (var j = 0; j < nodeGroup.length; j++) {
- var node = nodeGroup[j];
- var key = '' + i + j;
- currentNodeIds.push(key);
- table[key] = { node: node, lastCount: 0 };
- graph[key] = {};
- for (var n = 0; n < prevNodeIds.length; n++) {
- var prevNodeId = prevNodeIds[n];
- if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
- graph[prevNodeId][key] =
- getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -
- getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
- table[prevNodeId].lastCount += node.length;
- } else {
- if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
- graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +
- 4 + Mode.getCharCountIndicator(node.mode, version); // switch cost
- }
- }
- }
- prevNodeIds = currentNodeIds;
- }
- for (n = 0; n < prevNodeIds.length; n++) {
- graph[prevNodeIds[n]]['end'] = 0;
- }
- return { map: graph, table: table }
- }
- /**
- * Builds a segment from a specified data and mode.
- * If a mode is not specified, the more suitable will be used.
- *
- * @param {String} data Input data
- * @param {Mode | String} modesHint Data mode
- * @return {Segment} Segment
- */
- function buildSingleSegment (data, modesHint) {
- var mode;
- var bestMode = Mode.getBestModeForData(data);
- mode = Mode.from(modesHint, bestMode);
- // Make sure data can be encoded
- if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
- throw new Error('"' + data + '"' +
- ' cannot be encoded with mode ' + Mode.toString(mode) +
- '.\n Suggested mode is: ' + Mode.toString(bestMode))
- }
- // Use Mode.BYTE if Kanji support is disabled
- if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
- mode = Mode.BYTE;
- }
- switch (mode) {
- case Mode.NUMERIC:
- return new NumericData(data)
- case Mode.ALPHANUMERIC:
- return new AlphanumericData(data)
- case Mode.KANJI:
- return new KanjiData(data)
- case Mode.BYTE:
- return new ByteData(data)
- }
- }
- /**
- * Builds a list of segments from an array.
- * Array can contain Strings or Objects with segment's info.
- *
- * For each item which is a string, will be generated a segment with the given
- * string and the more appropriate encoding mode.
- *
- * For each item which is an object, will be generated a segment with the given
- * data and mode.
- * Objects must contain at least the property "data".
- * If property "mode" is not present, the more suitable mode will be used.
- *
- * @param {Array} array Array of objects with segments data
- * @return {Array} Array of Segments
- */
- exports.fromArray = function fromArray (array) {
- return array.reduce(function (acc, seg) {
- if (typeof seg === 'string') {
- acc.push(buildSingleSegment(seg, null));
- } else if (seg.data) {
- acc.push(buildSingleSegment(seg.data, seg.mode));
- }
- return acc
- }, [])
- };
- /**
- * Builds an optimized sequence of segments from a string,
- * which will produce the shortest possible bitstream.
- *
- * @param {String} data Input string
- * @param {Number} version QR Code version
- * @return {Array} Array of segments
- */
- exports.fromString = function fromString (data, version) {
- var segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
- var nodes = buildNodes(segs);
- var graph = buildGraph(nodes, version);
- var path = dijkstra.find_path(graph.map, 'start', 'end');
- var optimizedSegs = [];
- for (var i = 1; i < path.length - 1; i++) {
- optimizedSegs.push(graph.table[path[i]].node);
- }
- return exports.fromArray(mergeSegments(optimizedSegs))
- };
- /**
- * Splits a string in various segments with the modes which
- * best represent their content.
- * The produced segments are far from being optimized.
- * The output of this function is only used to estimate a QR Code version
- * which may contain the data.
- *
- * @param {string} data Input string
- * @return {Array} Array of segments
- */
- exports.rawSplit = function rawSplit (data) {
- return exports.fromArray(
- getSegmentsFromString(data, Utils.isKanjiModeEnabled())
- )
- };
- },{"./alphanumeric-data":3,"./byte-data":6,"./kanji-data":12,"./mode":14,"./numeric-data":15,"./regex":19,"./utils":21,"dijkstrajs":31}],21:[function(require,module,exports){
- var toSJISFunction;
- var CODEWORDS_COUNT = [
- 0, // Not used
- 26, 44, 70, 100, 134, 172, 196, 242, 292, 346,
- 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,
- 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,
- 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
- ];
- /**
- * Returns the QR Code size for the specified version
- *
- * @param {Number} version QR Code version
- * @return {Number} size of QR code
- */
- exports.getSymbolSize = function getSymbolSize (version) {
- if (!version) throw new Error('"version" cannot be null or undefined')
- if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40')
- return version * 4 + 17
- };
- /**
- * Returns the total number of codewords used to store data and EC information.
- *
- * @param {Number} version QR Code version
- * @return {Number} Data length in bits
- */
- exports.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {
- return CODEWORDS_COUNT[version]
- };
- /**
- * Encode data with Bose-Chaudhuri-Hocquenghem
- *
- * @param {Number} data Value to encode
- * @return {Number} Encoded value
- */
- exports.getBCHDigit = function (data) {
- var digit = 0;
- while (data !== 0) {
- digit++;
- data >>>= 1;
- }
- return digit
- };
- exports.setToSJISFunction = function setToSJISFunction (f) {
- if (typeof f !== 'function') {
- throw new Error('"toSJISFunc" is not a valid function.')
- }
- toSJISFunction = f;
- };
- exports.isKanjiModeEnabled = function () {
- return typeof toSJISFunction !== 'undefined'
- };
- exports.toSJIS = function toSJIS (kanji) {
- return toSJISFunction(kanji)
- };
- },{}],22:[function(require,module,exports){
- /**
- * Check if QR Code version is valid
- *
- * @param {Number} version QR Code version
- * @return {Boolean} true if valid version, false otherwise
- */
- exports.isValid = function isValid (version) {
- return !isNaN(version) && version >= 1 && version <= 40
- };
- },{}],23:[function(require,module,exports){
- var Utils = require('./utils');
- var ECCode = require('./error-correction-code');
- var ECLevel = require('./error-correction-level');
- var Mode = require('./mode');
- var VersionCheck = require('./version-check');
- var isArray = require('isarray');
- // Generator polynomial used to encode version information
- var G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
- var G18_BCH = Utils.getBCHDigit(G18);
- function getBestVersionForDataLength (mode, length, errorCorrectionLevel) {
- for (var currentVersion = 1; currentVersion <= 40; currentVersion++) {
- if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
- return currentVersion
- }
- }
- return undefined
- }
- function getReservedBitsCount (mode, version) {
- // Character count indicator + mode indicator bits
- return Mode.getCharCountIndicator(mode, version) + 4
- }
- function getTotalBitsFromDataArray (segments, version) {
- var totalBits = 0;
- segments.forEach(function (data) {
- var reservedBits = getReservedBitsCount(data.mode, version);
- totalBits += reservedBits + data.getBitsLength();
- });
- return totalBits
- }
- function getBestVersionForMixedData (segments, errorCorrectionLevel) {
- for (var currentVersion = 1; currentVersion <= 40; currentVersion++) {
- var length = getTotalBitsFromDataArray(segments, currentVersion);
- if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
- return currentVersion
- }
- }
- return undefined
- }
- /**
- * Returns version number from a value.
- * If value is not a valid version, returns defaultValue
- *
- * @param {Number|String} value QR Code version
- * @param {Number} defaultValue Fallback value
- * @return {Number} QR Code version number
- */
- exports.from = function from (value, defaultValue) {
- if (VersionCheck.isValid(value)) {
- return parseInt(value, 10)
- }
- return defaultValue
- };
- /**
- * Returns how much data can be stored with the specified QR code version
- * and error correction level
- *
- * @param {Number} version QR Code version (1-40)
- * @param {Number} errorCorrectionLevel Error correction level
- * @param {Mode} mode Data mode
- * @return {Number} Quantity of storable data
- */
- exports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {
- if (!VersionCheck.isValid(version)) {
- throw new Error('Invalid QR Code version')
- }
- // Use Byte mode as default
- if (typeof mode === 'undefined') mode = Mode.BYTE;
- // Total codewords for this QR code version (Data + Error correction)
- var totalCodewords = Utils.getSymbolTotalCodewords(version);
- // Total number of error correction codewords
- var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
- // Total number of data codewords
- var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
- if (mode === Mode.MIXED) return dataTotalCodewordsBits
- var usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
- // Return max number of storable codewords
- switch (mode) {
- case Mode.NUMERIC:
- return Math.floor((usableBits / 10) * 3)
- case Mode.ALPHANUMERIC:
- return Math.floor((usableBits / 11) * 2)
- case Mode.KANJI:
- return Math.floor(usableBits / 13)
- case Mode.BYTE:
- default:
- return Math.floor(usableBits / 8)
- }
- };
- /**
- * Returns the minimum version needed to contain the amount of data
- *
- * @param {Segment} data Segment of data
- * @param {Number} [errorCorrectionLevel=H] Error correction level
- * @param {Mode} mode Data mode
- * @return {Number} QR Code version
- */
- exports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {
- var seg;
- var ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
- if (isArray(data)) {
- if (data.length > 1) {
- return getBestVersionForMixedData(data, ecl)
- }
- if (data.length === 0) {
- return 1
- }
- seg = data[0];
- } else {
- seg = data;
- }
- return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)
- };
- /**
- * Returns version information with relative error correction bits
- *
- * The version information is included in QR Code symbols of version 7 or larger.
- * It consists of an 18-bit sequence containing 6 data bits,
- * with 12 error correction bits calculated using the (18, 6) Golay code.
- *
- * @param {Number} version QR Code version
- * @return {Number} Encoded version info bits
- */
- exports.getEncodedBits = function getEncodedBits (version) {
- if (!VersionCheck.isValid(version) || version < 7) {
- throw new Error('Invalid QR Code version')
- }
- var d = version << 12;
- while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
- d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH));
- }
- return (version << 12) | d
- };
- },{"./error-correction-code":7,"./error-correction-level":8,"./mode":14,"./utils":21,"./version-check":22,"isarray":33}],24:[function(require,module,exports){
- var canPromise = require('./can-promise');
- var QRCode = require('./core/qrcode');
- var CanvasRenderer = require('./renderer/canvas');
- var SvgRenderer = require('./renderer/svg-tag.js');
- function renderCanvas (renderFunc, canvas, text, opts, cb) {
- var args = [].slice.call(arguments, 1);
- var argsNum = args.length;
- var isLastArgCb = typeof args[argsNum - 1] === 'function';
- if (!isLastArgCb && !canPromise()) {
- throw new Error('Callback required as last argument')
- }
- if (isLastArgCb) {
- if (argsNum < 2) {
- throw new Error('Too few arguments provided')
- }
- if (argsNum === 2) {
- cb = text;
- text = canvas;
- canvas = opts = undefined;
- } else if (argsNum === 3) {
- if (canvas.getContext && typeof cb === 'undefined') {
- cb = opts;
- opts = undefined;
- } else {
- cb = opts;
- opts = text;
- text = canvas;
- canvas = undefined;
- }
- }
- } else {
- if (argsNum < 1) {
- throw new Error('Too few arguments provided')
- }
- if (argsNum === 1) {
- text = canvas;
- canvas = opts = undefined;
- } else if (argsNum === 2 && !canvas.getContext) {
- opts = text;
- text = canvas;
- canvas = undefined;
- }
- return new Promise(function (resolve, reject) {
- try {
- var data = QRCode.create(text, opts);
- resolve(renderFunc(data, canvas, opts));
- } catch (e) {
- reject(e);
- }
- })
- }
- try {
- var data = QRCode.create(text, opts);
- cb(null, renderFunc(data, canvas, opts));
- } catch (e) {
- cb(e);
- }
- }
- exports.create = QRCode.create;
- exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
- exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
- // only svg for now.
- exports.toString = renderCanvas.bind(null, function (data, _, opts) {
- return SvgRenderer.render(data, opts)
- });
- },{"./can-promise":1,"./core/qrcode":17,"./renderer/canvas":25,"./renderer/svg-tag.js":26}],25:[function(require,module,exports){
- var Utils = require('./utils');
- function clearCanvas (ctx, canvas, size) {
- ctx.clearRect(0, 0, canvas.width, canvas.height);
- if (!canvas.style) canvas.style = {};
- canvas.height = size;
- canvas.width = size;
- canvas.style.height = size + 'px';
- canvas.style.width = size + 'px';
- }
- function getCanvasElement () {
- try {
- return document.createElement('canvas')
- } catch (e) {
- throw new Error('You need to specify a canvas element')
- }
- }
- exports.render = function render (qrData, canvas, options) {
- var opts = options;
- var canvasEl = canvas;
- if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
- opts = canvas;
- canvas = undefined;
- }
- if (!canvas) {
- canvasEl = getCanvasElement();
- }
- opts = Utils.getOptions(opts);
- var size = Utils.getImageWidth(qrData.modules.size, opts);
- var ctx = canvasEl.getContext('2d');
- var image = ctx.createImageData(size, size);
- Utils.qrToImageData(image.data, qrData, opts);
- clearCanvas(ctx, canvasEl, size);
- ctx.putImageData(image, 0, 0);
- return canvasEl
- };
- exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
- var opts = options;
- if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
- opts = canvas;
- canvas = undefined;
- }
- if (!opts) opts = {};
- var canvasEl = exports.render(qrData, canvas, opts);
- var type = opts.type || 'image/png';
- var rendererOpts = opts.rendererOpts || {};
- return canvasEl.toDataURL(type, rendererOpts.quality)
- };
- },{"./utils":27}],26:[function(require,module,exports){
- var Utils = require('./utils');
- function getColorAttrib (color, attrib) {
- var alpha = color.a / 255;
- var str = attrib + '="' + color.hex + '"';
- return alpha < 1
- ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"'
- : str
- }
- function svgCmd (cmd, x, y) {
- var str = cmd + x;
- if (typeof y !== 'undefined') str += ' ' + y;
- return str
- }
- function qrToPath (data, size, margin) {
- var path = '';
- var moveBy = 0;
- var newRow = false;
- var lineLength = 0;
- for (var i = 0; i < data.length; i++) {
- var col = Math.floor(i % size);
- var row = Math.floor(i / size);
- if (!col && !newRow) newRow = true;
- if (data[i]) {
- lineLength++;
- if (!(i > 0 && col > 0 && data[i - 1])) {
- path += newRow
- ? svgCmd('M', col + margin, 0.5 + row + margin)
- : svgCmd('m', moveBy, 0);
- moveBy = 0;
- newRow = false;
- }
- if (!(col + 1 < size && data[i + 1])) {
- path += svgCmd('h', lineLength);
- lineLength = 0;
- }
- } else {
- moveBy++;
- }
- }
- return path
- }
- exports.render = function render (qrData, options, cb) {
- var opts = Utils.getOptions(options);
- var size = qrData.modules.size;
- var data = qrData.modules.data;
- var qrcodesize = size + opts.margin * 2;
- var bg = !opts.color.light.a
- ? ''
- : '<path ' + getColorAttrib(opts.color.light, 'fill') +
- ' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>';
- var path =
- '<path ' + getColorAttrib(opts.color.dark, 'stroke') +
- ' d="' + qrToPath(data, size, opts.margin) + '"/>';
- var viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"';
- var width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" ';
- var svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n';
- if (typeof cb === 'function') {
- cb(null, svgTag);
- }
- return svgTag
- };
- },{"./utils":27}],27:[function(require,module,exports){
- function hex2rgba (hex) {
- if (typeof hex === 'number') {
- hex = hex.toString();
- }
- if (typeof hex !== 'string') {
- throw new Error('Color should be defined as hex string')
- }
- var hexCode = hex.slice().replace('#', '').split('');
- if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
- throw new Error('Invalid hex color: ' + hex)
- }
- // Convert from short to long form (fff -> ffffff)
- if (hexCode.length === 3 || hexCode.length === 4) {
- hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
- return [c, c]
- }));
- }
- // Add default alpha value
- if (hexCode.length === 6) hexCode.push('F', 'F');
- var hexValue = parseInt(hexCode.join(''), 16);
- return {
- r: (hexValue >> 24) & 255,
- g: (hexValue >> 16) & 255,
- b: (hexValue >> 8) & 255,
- a: hexValue & 255,
- hex: '#' + hexCode.slice(0, 6).join('')
- }
- }
- exports.getOptions = function getOptions (options) {
- if (!options) options = {};
- if (!options.color) options.color = {};
- var margin = typeof options.margin === 'undefined' ||
- options.margin === null ||
- options.margin < 0 ? 4 : options.margin;
- var width = options.width && options.width >= 21 ? options.width : undefined;
- var scale = options.scale || 4;
- return {
- width: width,
- scale: width ? 4 : scale,
- margin: margin,
- color: {
- dark: hex2rgba(options.color.dark || '#000000ff'),
- light: hex2rgba(options.color.light || '#ffffffff')
- },
- type: options.type,
- rendererOpts: options.rendererOpts || {}
- }
- };
- exports.getScale = function getScale (qrSize, opts) {
- return opts.width && opts.width >= qrSize + opts.margin * 2
- ? opts.width / (qrSize + opts.margin * 2)
- : opts.scale
- };
- exports.getImageWidth = function getImageWidth (qrSize, opts) {
- var scale = exports.getScale(qrSize, opts);
- return Math.floor((qrSize + opts.margin * 2) * scale)
- };
- exports.qrToImageData = function qrToImageData (imgData, qr, opts) {
- var size = qr.modules.size;
- var data = qr.modules.data;
- var scale = exports.getScale(size, opts);
- var symbolSize = Math.floor((size + opts.margin * 2) * scale);
- var scaledMargin = opts.margin * scale;
- var palette = [opts.color.light, opts.color.dark];
- for (var i = 0; i < symbolSize; i++) {
- for (var j = 0; j < symbolSize; j++) {
- var posDst = (i * symbolSize + j) * 4;
- var pxColor = opts.color.light;
- if (i >= scaledMargin && j >= scaledMargin &&
- i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
- var iSrc = Math.floor((i - scaledMargin) / scale);
- var jSrc = Math.floor((j - scaledMargin) / scale);
- pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
- }
- imgData[posDst++] = pxColor.r;
- imgData[posDst++] = pxColor.g;
- imgData[posDst++] = pxColor.b;
- imgData[posDst] = pxColor.a;
- }
- }
- };
- },{}],28:[function(require,module,exports){
- var isArray = require('isarray');
- function typedArraySupport () {
- // Can typed array instances be augmented?
- try {
- var arr = new Uint8Array(1);
- arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }};
- return arr.foo() === 42
- } catch (e) {
- return false
- }
- }
- Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
- var K_MAX_LENGTH = Buffer.TYPED_ARRAY_SUPPORT
- ? 0x7fffffff
- : 0x3fffffff;
- function Buffer (arg, offset, length) {
- if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
- return new Buffer(arg, offset, length)
- }
- if (typeof arg === 'number') {
- return allocUnsafe(this, arg)
- }
- return from(this, arg, offset, length)
- }
- if (Buffer.TYPED_ARRAY_SUPPORT) {
- Buffer.prototype.__proto__ = Uint8Array.prototype;
- Buffer.__proto__ = Uint8Array;
- // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
- if (typeof Symbol !== 'undefined' && Symbol.species &&
- Buffer[Symbol.species] === Buffer) {
- Object.defineProperty(Buffer, Symbol.species, {
- value: null,
- configurable: true,
- enumerable: false,
- writable: false
- });
- }
- }
- function checked (length) {
- // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
- // length is NaN (which is otherwise coerced to zero.)
- 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 isnan (val) {
- return val !== val // eslint-disable-line no-self-compare
- }
- function createBuffer (that, length) {
- var buf;
- if (Buffer.TYPED_ARRAY_SUPPORT) {
- buf = new Uint8Array(length);
- buf.__proto__ = Buffer.prototype;
- } else {
- // Fallback: Return an object instance of the Buffer class
- buf = that;
- if (buf === null) {
- buf = new Buffer(length);
- }
- buf.length = length;
- }
- return buf
- }
- function allocUnsafe (that, size) {
- var buf = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
- if (!Buffer.TYPED_ARRAY_SUPPORT) {
- for (var i = 0; i < size; ++i) {
- buf[i] = 0;
- }
- }
- return buf
- }
- function fromString (that, string) {
- var length = byteLength(string) | 0;
- var buf = createBuffer(that, length);
- var actual = buf.write(string);
- if (actual !== length) {
- // Writing a hex string, for example, that contains invalid characters will
- // cause everything after the first invalid character to be ignored. (e.g.
- // 'abxxcd' will be treated as 'ab')
- buf = buf.slice(0, actual);
- }
- return buf
- }
- function fromArrayLike (that, array) {
- var length = array.length < 0 ? 0 : checked(array.length) | 0;
- var buf = createBuffer(that, length);
- for (var i = 0; i < length; i += 1) {
- buf[i] = array[i] & 255;
- }
- return buf
- }
- function fromArrayBuffer (that, array, byteOffset, length) {
- if (byteOffset < 0 || array.byteLength < byteOffset) {
- throw new RangeError('\'offset\' is out of bounds')
- }
- if (array.byteLength < byteOffset + (length || 0)) {
- throw new RangeError('\'length\' is out of 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);
- }
- if (Buffer.TYPED_ARRAY_SUPPORT) {
- // Return an augmented `Uint8Array` instance, for best performance
- buf.__proto__ = Buffer.prototype;
- } else {
- // Fallback: Return an object instance of the Buffer class
- buf = fromArrayLike(that, buf);
- }
- return buf
- }
- function fromObject (that, obj) {
- if (Buffer.isBuffer(obj)) {
- var len = checked(obj.length) | 0;
- var buf = createBuffer(that, len);
- if (buf.length === 0) {
- return buf
- }
- obj.copy(buf, 0, 0, len);
- return buf
- }
- if (obj) {
- if ((typeof ArrayBuffer !== 'undefined' &&
- obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
- if (typeof obj.length !== 'number' || isnan(obj.length)) {
- return createBuffer(that, 0)
- }
- return fromArrayLike(that, obj)
- }
- if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
- return fromArrayLike(that, obj.data)
- }
- }
- throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
- }
- 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);
- // is surrogate component
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
- // last char was a lead
- if (!leadSurrogate) {
- // no lead yet
- if (codePoint > 0xDBFF) {
- // unexpected trail
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
- continue
- } else if (i + 1 === length) {
- // unpaired lead
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
- continue
- }
- // valid lead
- leadSurrogate = codePoint;
- continue
- }
- // 2 leads in a row
- if (codePoint < 0xDC00) {
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
- leadSurrogate = codePoint;
- continue
- }
- // valid surrogate pair
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
- } else if (leadSurrogate) {
- // valid bmp char, but last char was a lead
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
- }
- leadSurrogate = null;
- // encode utf8
- 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 byteLength (string) {
- if (Buffer.isBuffer(string)) {
- return string.length
- }
- if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
- (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
- return string.byteLength
- }
- if (typeof string !== 'string') {
- string = '' + string;
- }
- var len = string.length;
- if (len === 0) return 0
- return utf8ToBytes(string).length
- }
- 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 utf8Write (buf, string, offset, length) {
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
- }
- function from (that, value, offset, length) {
- if (typeof value === 'number') {
- throw new TypeError('"value" argument must not be a number')
- }
- if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
- return fromArrayBuffer(that, value, offset, length)
- }
- if (typeof value === 'string') {
- return fromString(that, value)
- }
- return fromObject(that, value)
- }
- Buffer.prototype.write = function write (string, offset, length) {
- // Buffer#write(string)
- if (offset === undefined) {
- length = this.length;
- offset = 0;
- // Buffer#write(string, encoding)
- } else if (length === undefined && typeof offset === 'string') {
- length = this.length;
- offset = 0;
- // Buffer#write(string, offset[, length])
- } else if (isFinite(offset)) {
- offset = offset | 0;
- if (isFinite(length)) {
- length = length | 0;
- } else {
- length = undefined;
- }
- }
- 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')
- }
- return utf8Write(this, string, offset, length)
- };
- 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;
- if (Buffer.TYPED_ARRAY_SUPPORT) {
- newBuf = this.subarray(start, end);
- // Return an augmented `Uint8Array` instance
- newBuf.__proto__ = Buffer.prototype;
- } else {
- var sliceLen = end - start;
- newBuf = new Buffer(sliceLen, undefined);
- for (var i = 0; i < sliceLen; ++i) {
- newBuf[i] = this[i + start];
- }
- }
- return newBuf
- };
- Buffer.prototype.copy = function copy (target, targetStart, start, end) {
- 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;
- // Copy 0 bytes; we're done
- if (end === start) return 0
- if (target.length === 0 || this.length === 0) return 0
- // Fatal error conditions
- if (targetStart < 0) {
- throw new RangeError('targetStart out of bounds')
- }
- if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
- if (end < 0) throw new RangeError('sourceEnd out of bounds')
- // Are we oob?
- if (end > this.length) end = this.length;
- if (target.length - targetStart < end - start) {
- end = target.length - targetStart + start;
- }
- var len = end - start;
- var i;
- if (this === target && start < targetStart && targetStart < end) {
- // descending copy from end
- for (i = len - 1; i >= 0; --i) {
- target[i + targetStart] = this[i + start];
- }
- } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
- // ascending copy from start
- for (i = 0; i < len; ++i) {
- target[i + targetStart] = this[i + start];
- }
- } else {
- Uint8Array.prototype.set.call(
- target,
- this.subarray(start, start + len),
- targetStart
- );
- }
- return len
- };
- Buffer.prototype.fill = function fill (val, start, end) {
- // Handle string cases:
- if (typeof val === 'string') {
- if (typeof start === 'string') {
- start = 0;
- end = this.length;
- } else if (typeof end === 'string') {
- end = this.length;
- }
- if (val.length === 1) {
- var code = val.charCodeAt(0);
- if (code < 256) {
- val = code;
- }
- }
- } else if (typeof val === 'number') {
- val = val & 255;
- }
- // Invalid ranges are not set to a default, so can range check early.
- 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
- : new Buffer(val);
- var len = bytes.length;
- for (i = 0; i < end - start; ++i) {
- this[i + start] = bytes[i % len];
- }
- }
- return this
- };
- Buffer.concat = function concat (list, length) {
- if (!isArray(list)) {
- throw new TypeError('"list" argument must be an Array of Buffers')
- }
- if (list.length === 0) {
- return createBuffer(null, 0)
- }
- var i;
- if (length === undefined) {
- length = 0;
- for (i = 0; i < list.length; ++i) {
- length += list[i].length;
- }
- }
- var buffer = allocUnsafe(null, length);
- var pos = 0;
- for (i = 0; i < list.length; ++i) {
- var buf = list[i];
- if (!Buffer.isBuffer(buf)) {
- throw new TypeError('"list" argument must be an Array of Buffers')
- }
- buf.copy(buffer, pos);
- pos += buf.length;
- }
- return buffer
- };
- Buffer.byteLength = byteLength;
- Buffer.prototype._isBuffer = true;
- Buffer.isBuffer = function isBuffer (b) {
- return !!(b != null && b._isBuffer)
- };
- module.exports.alloc = function (size) {
- var buffer = new Buffer(size);
- buffer.fill(0);
- return buffer
- };
- module.exports.from = function (data) {
- return new Buffer(data)
- };
- },{"isarray":33}],29:[function(require,module,exports){
- 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;
- }
- // Support decoding URL-safe base64 strings, as Node.js does.
- // See: https://en.wikipedia.org/wiki/Base64#URL_applications
- 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')
- }
- // Trim off extra bytes after placeholder bytes are found
- // See: https://github.com/beatgammit/base64-js/issues/42
- var validLen = b64.indexOf('=');
- if (validLen === -1) validLen = len;
- var placeHoldersLen = validLen === len
- ? 0
- : 4 - (validLen % 4);
- return [validLen, placeHoldersLen]
- }
- // base64 is 4/3 + up to two characters of the original data
- 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;
- // if there are placeholders, only get up to the last complete 4 chars
- 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; // if we have 1 byte left, pad 2 bytes
- var parts = [];
- var maxChunkLength = 16383; // must be multiple of 3
- // go through the array every three bytes, we'll deal with trailing stuff later
- for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
- parts.push(encodeChunk(
- uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
- ));
- }
- // pad the end with zeros, but make sure to not forget the extra bytes
- 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('')
- }
- },{}],30:[function(require,module,exports){
- var base64 = require('base64-js');
- var ieee754 = require('ieee754');
- var customInspectSymbol =
- (typeof Symbol === 'function' && typeof Symbol.for === 'function')
- ? Symbol.for('nodejs.util.inspect.custom')
- : null;
- exports.Buffer = Buffer;
- exports.SlowBuffer = SlowBuffer;
- exports.INSPECT_MAX_BYTES = 50;
- var K_MAX_LENGTH = 0x7fffffff;
- exports.kMaxLength = K_MAX_LENGTH;
- /**
- * If `Buffer.TYPED_ARRAY_SUPPORT`:
- * === true Use Uint8Array implementation (fastest)
- * === false Print warning and recommend using `buffer` v4.x which has an Object
- * implementation (most compatible, even IE6)
- *
- * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
- * Opera 11.6+, iOS 4.2+.
- *
- * We report that the browser does not support typed arrays if the are not subclassable
- * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
- * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
- * for __proto__ and has a buggy typed array implementation.
- */
- 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 () {
- // Can typed array instances can be augmented?
- try {
- var arr = new Uint8Array(1);
- var proto = { foo: function () { return 42 } };
- Object.setPrototypeOf(proto, Uint8Array.prototype);
- Object.setPrototypeOf(arr, proto);
- 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"')
- }
- // Return an augmented `Uint8Array` instance
- var buf = new Uint8Array(length);
- Object.setPrototypeOf(buf, Buffer.prototype);
- return buf
- }
- /**
- * The Buffer constructor returns instances of `Uint8Array` that have their
- * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
- * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
- * and the `Uint8Array` methods. Square bracket notation works as expected -- it
- * returns a single octet.
- *
- * The `Uint8Array` prototype remains unmodified.
- */
- function Buffer (arg, encodingOrOffset, length) {
- // Common case.
- 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)
- }
- // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
- 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; // not used by this implementation
- function from (value, encodingOrOffset, length) {
- if (typeof value === 'string') {
- return fromString(value, encodingOrOffset)
- }
- if (ArrayBuffer.isView(value)) {
- return fromArrayLike(value)
- }
- if (value == null) {
- throw new 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)
- )
- }
- /**
- * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
- * if value is a number.
- * Buffer.from(str[, encoding])
- * Buffer.from(array)
- * Buffer.from(buffer)
- * Buffer.from(arrayBuffer[, byteOffset[, length]])
- **/
- Buffer.from = function (value, encodingOrOffset, length) {
- return from(value, encodingOrOffset, length)
- };
- // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
- // https://github.com/feross/buffer/pull/148
- Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
- Object.setPrototypeOf(Buffer, 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) {
- // Only pay attention to encoding if it's a string. This
- // prevents accidentally sending in a number that would
- // be interpretted as a start offset.
- return typeof encoding === 'string'
- ? createBuffer(size).fill(fill, encoding)
- : createBuffer(size).fill(fill)
- }
- return createBuffer(size)
- }
- /**
- * Creates a new filled Buffer instance.
- * alloc(size[, fill[, encoding]])
- **/
- Buffer.alloc = function (size, fill, encoding) {
- return alloc(size, fill, encoding)
- };
- function allocUnsafe (size) {
- assertSize(size);
- return createBuffer(size < 0 ? 0 : checked(size) | 0)
- }
- /**
- * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
- * */
- Buffer.allocUnsafe = function (size) {
- return allocUnsafe(size)
- };
- /**
- * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
- */
- 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) {
- // Writing a hex string, for example, that contains invalid characters will
- // cause everything after the first invalid character to be ignored. (e.g.
- // 'abxxcd' will be treated as 'ab')
- 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);
- }
- // Return an augmented `Uint8Array` instance
- Object.setPrototypeOf(buf, 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) {
- // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
- // length is NaN (which is otherwise coerced to zero.)
- 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) { // eslint-disable-line eqeqeq
- length = 0;
- }
- return Buffer.alloc(+length)
- }
- Buffer.isBuffer = function isBuffer (b) {
- return b != null && b._isBuffer === true &&
- b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
- };
- 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
- // Use a for loop to avoid recursion
- 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 // assume utf8
- }
- encoding = ('' + encoding).toLowerCase();
- loweredCase = true;
- }
- }
- }
- Buffer.byteLength = byteLength;
- function slowToString (encoding, start, end) {
- var loweredCase = false;
- // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
- // property of a typed array.
- // This behaves neither like String nor Uint8Array in that we set start/end
- // to their upper/lower bounds if the value passed is out of range.
- // undefined is handled specially as per ECMA-262 6th Edition,
- // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
- if (start === undefined || start < 0) {
- start = 0;
- }
- // Return early if start > this.length. Done here to prevent potential uint32
- // coercion fail below.
- if (start > this.length) {
- return ''
- }
- if (end === undefined || end > this.length) {
- end = this.length;
- }
- if (end <= 0) {
- return ''
- }
- // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
- 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;
- }
- }
- }
- // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
- // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
- // reliably in a browserify context because there could be multiple different
- // copies of the 'buffer' package in use. This method works even for Buffer
- // instances that were created from another copy of the `buffer` package.
- // See: https://github.com/feross/buffer/issues/154
- 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 + '>'
- };
- if (customInspectSymbol) {
- Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
- }
- 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
- };
- // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
- // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
- //
- // Arguments:
- // - buffer - a Buffer to search
- // - val - a string, Buffer, or number
- // - byteOffset - an index into `buffer`; will be clamped to an int32
- // - encoding - an optional encoding, relevant is val is a string
- // - dir - true for indexOf, false for lastIndexOf
- function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
- // Empty buffer means no match
- if (buffer.length === 0) return -1
- // Normalize byteOffset
- if (typeof byteOffset === 'string') {
- encoding = byteOffset;
- byteOffset = 0;
- } else if (byteOffset > 0x7fffffff) {
- byteOffset = 0x7fffffff;
- } else if (byteOffset < -0x80000000) {
- byteOffset = -0x80000000;
- }
- byteOffset = +byteOffset; // Coerce to Number.
- if (numberIsNaN(byteOffset)) {
- // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
- byteOffset = dir ? 0 : (buffer.length - 1);
- }
- // Normalize byteOffset: negative offsets start from the end of the buffer
- 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
- }
- // Normalize val
- if (typeof val === 'string') {
- val = Buffer.from(val, encoding);
- }
- // Finally, search either indexOf (if dir is true) or lastIndexOf
- if (Buffer.isBuffer(val)) {
- // Special case: looking for empty string/buffer always fails
- if (val.length === 0) {
- return -1
- }
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
- } else if (typeof val === 'number') {
- val = val & 0xFF; // Search for a byte value [0-255]
- 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) {
- // Buffer#write(string)
- if (offset === undefined) {
- encoding = 'utf8';
- length = this.length;
- offset = 0;
- // Buffer#write(string, encoding)
- } else if (length === undefined && typeof offset === 'string') {
- encoding = offset;
- length = this.length;
- offset = 0;
- // Buffer#write(string, offset[, length][, encoding])
- } 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':
- // Warning: maxLength not taken into account in base64Write
- 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) {
- // we did not generate a valid codePoint so insert a
- // replacement char (U+FFFD) and advance only 1 byte
- codePoint = 0xFFFD;
- bytesPerSequence = 1;
- } else if (codePoint > 0xFFFF) {
- // encode to utf16 (surrogate pair dance)
- codePoint -= 0x10000;
- res.push(codePoint >>> 10 & 0x3FF | 0xD800);
- codePoint = 0xDC00 | codePoint & 0x3FF;
- }
- res.push(codePoint);
- i += bytesPerSequence;
- }
- return decodeCodePointsArray(res)
- }
- // Based on http://stackoverflow.com/a/22747272/680742, the browser with
- // the lowest limit is Chrome, with 0x10000 args.
- // We go 1 magnitude less, for safety
- var MAX_ARGUMENTS_LENGTH = 0x1000;
- function decodeCodePointsArray (codePoints) {
- var len = codePoints.length;
- if (len <= MAX_ARGUMENTS_LENGTH) {
- return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
- }
- // Decode in chunks to avoid "call stack size exceeded".
- 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 += hexSliceLookupTable[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);
- // Return an augmented `Uint8Array` instance
- Object.setPrototypeOf(newBuf, Buffer.prototype);
- return newBuf
- };
- /*
- * Need to make sure that buffer isn't trying to write out of bounds.
- */
- 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);
- }
- 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);
- }
- 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)
- };
- // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
- 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;
- // Copy 0 bytes; we're done
- if (end === start) return 0
- if (target.length === 0 || this.length === 0) return 0
- // Fatal error conditions
- 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')
- // Are we oob?
- 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') {
- // Use built-in when available, missing from IE11
- this.copyWithin(targetStart, start, end);
- } else if (this === target && start < targetStart && targetStart < end) {
- // descending copy from 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
- };
- // Usage:
- // buffer.fill(number[, offset[, end]])
- // buffer.fill(buffer[, offset[, end]])
- // buffer.fill(string[, offset[, end]][, encoding])
- Buffer.prototype.fill = function fill (val, start, end, encoding) {
- // Handle string cases:
- 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') {
- // Fast path: If `val` fits into a single byte, use that numeric value.
- val = code;
- }
- }
- } else if (typeof val === 'number') {
- val = val & 255;
- } else if (typeof val === 'boolean') {
- val = Number(val);
- }
- // Invalid ranges are not set to a default, so can range check early.
- 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
- };
- // HELPER FUNCTIONS
- // ================
- var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
- function base64clean (str) {
- // Node takes equal signs as end of the Base64 encoding
- str = str.split('=')[0];
- // Node strips out invalid characters like \n and \t from the string, base64-js does not
- str = str.trim().replace(INVALID_BASE64_RE, '');
- // Node converts strings with length < 2 to ''
- if (str.length < 2) return ''
- // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
- while (str.length % 4 !== 0) {
- str = str + '=';
- }
- return str
- }
- 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);
- // is surrogate component
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
- // last char was a lead
- if (!leadSurrogate) {
- // no lead yet
- if (codePoint > 0xDBFF) {
- // unexpected trail
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
- continue
- } else if (i + 1 === length) {
- // unpaired lead
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
- continue
- }
- // valid lead
- leadSurrogate = codePoint;
- continue
- }
- // 2 leads in a row
- if (codePoint < 0xDC00) {
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
- leadSurrogate = codePoint;
- continue
- }
- // valid surrogate pair
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
- } else if (leadSurrogate) {
- // valid bmp char, but last char was a lead
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
- }
- leadSurrogate = null;
- // encode utf8
- 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) {
- // Node's code seems to be doing this and not & 0x7F..
- 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
- }
- // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
- // the `instanceof` check but they should be treated as of that type.
- // See: https://github.com/feross/buffer/issues/166
- 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) {
- // For IE11 support
- return obj !== obj // eslint-disable-line no-self-compare
- }
- // Create lookup table for `toString('hex')`
- // See: https://github.com/feross/buffer/issues/219
- var hexSliceLookupTable = (function () {
- var alphabet = '0123456789abcdef';
- var table = new Array(256);
- for (var i = 0; i < 16; ++i) {
- var i16 = i * 16;
- for (var j = 0; j < 16; ++j) {
- table[i16 + j] = alphabet[i] + alphabet[j];
- }
- }
- return table
- })();
- },{"base64-js":29,"ieee754":32}],31:[function(require,module,exports){
- /******************************************************************************
- * Created 2008-08-19.
- *
- * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
- *
- * Copyright (C) 2008
- * Wyatt Baldwin <self@wyattbaldwin.com>
- * All rights reserved
- *
- * Licensed under the MIT license.
- *
- * http://www.opensource.org/licenses/mit-license.php
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *****************************************************************************/
- var dijkstra = {
- single_source_shortest_paths: function(graph, s, d) {
- // Predecessor map for each node that has been encountered.
- // node ID => predecessor node ID
- var predecessors = {};
- // Costs of shortest paths from s to all nodes encountered.
- // node ID => cost
- var costs = {};
- costs[s] = 0;
- // Costs of shortest paths from s to all nodes encountered; differs from
- // `costs` in that it provides easy access to the node that currently has
- // the known shortest path from s.
- // XXX: Do we actually need both `costs` and `open`?
- var open = dijkstra.PriorityQueue.make();
- open.push(s, 0);
- var closest,
- u, v,
- cost_of_s_to_u,
- adjacent_nodes,
- cost_of_e,
- cost_of_s_to_u_plus_cost_of_e,
- cost_of_s_to_v,
- first_visit;
- while (!open.empty()) {
- // In the nodes remaining in graph that have a known cost from s,
- // find the node, u, that currently has the shortest path from s.
- closest = open.pop();
- u = closest.value;
- cost_of_s_to_u = closest.cost;
- // Get nodes adjacent to u...
- adjacent_nodes = graph[u] || {};
- // ...and explore the edges that connect u to those nodes, updating
- // the cost of the shortest paths to any or all of those nodes as
- // necessary. v is the node across the current edge from u.
- for (v in adjacent_nodes) {
- if (adjacent_nodes.hasOwnProperty(v)) {
- // Get the cost of the edge running from u to v.
- cost_of_e = adjacent_nodes[v];
- // Cost of s to u plus the cost of u to v across e--this is *a*
- // cost from s to v that may or may not be less than the current
- // known cost to v.
- cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
- // If we haven't visited v yet OR if the current known cost from s to
- // v is greater than the new cost we just found (cost of s to u plus
- // cost of u to v across e), update v's cost in the cost list and
- // update v's predecessor in the predecessor list (it's now u).
- cost_of_s_to_v = costs[v];
- first_visit = (typeof costs[v] === 'undefined');
- if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
- costs[v] = cost_of_s_to_u_plus_cost_of_e;
- open.push(v, cost_of_s_to_u_plus_cost_of_e);
- predecessors[v] = u;
- }
- }
- }
- }
- if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {
- var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');
- throw new Error(msg);
- }
- return predecessors;
- },
- extract_shortest_path_from_predecessor_list: function(predecessors, d) {
- var nodes = [];
- var u = d;
- var predecessor;
- while (u) {
- nodes.push(u);
- predecessor = predecessors[u];
- u = predecessors[u];
- }
- nodes.reverse();
- return nodes;
- },
- find_path: function(graph, s, d) {
- var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
- return dijkstra.extract_shortest_path_from_predecessor_list(
- predecessors, d);
- },
- /**
- * A very naive priority queue implementation.
- */
- PriorityQueue: {
- make: function (opts) {
- var T = dijkstra.PriorityQueue,
- t = {},
- key;
- opts = opts || {};
- for (key in T) {
- if (T.hasOwnProperty(key)) {
- t[key] = T[key];
- }
- }
- t.queue = [];
- t.sorter = opts.sorter || T.default_sorter;
- return t;
- },
- default_sorter: function (a, b) {
- return a.cost - b.cost;
- },
- /**
- * Add a new item to the queue and ensure the highest priority element
- * is at the front of the queue.
- */
- push: function (value, cost) {
- var item = {value: value, cost: cost};
- this.queue.push(item);
- this.queue.sort(this.sorter);
- },
- /**
- * Return the highest priority element in the queue.
- */
- pop: function () {
- return this.queue.shift();
- },
- empty: function () {
- return this.queue.length === 0;
- }
- }
- };
- // node.js module exports
- if (typeof module !== 'undefined') {
- module.exports = dijkstra;
- }
- },{}],32:[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;
- };
- },{}],33:[function(require,module,exports){
- var toString = {}.toString;
- module.exports = Array.isArray || function (arr) {
- return toString.call(arr) == '[object Array]';
- };
- },{}]},{},[24])(24)
- });
- });
- var index = {
- name: 'qrcode',
- props: {
- /**
- * The value of the QR code.
- */
- value: null,
- /**
- * The options for the QR code generator.
- * {@link https://github.com/soldair/node-qrcode#qr-code-options}
- */
- options: Object,
- /**
- * The tag name of the component's root element.
- */
- tag: {
- type: String,
- default: 'canvas'
- }
- },
- render: function render(createElement) {
- return createElement(this.tag, this.$slots.default);
- },
- watch: {
- $props: {
- deep: true,
- immediate: true,
- /**
- * Update the QR code when props changed.
- */
- handler: function handler() {
- if (this.$el) {
- this.generate();
- }
- }
- }
- },
- methods: {
- /**
- * Generate QR code.
- */
- generate: function generate() {
- var _this = this;
- var options = this.options,
- tag = this.tag;
- var value = String(this.value);
- if (tag === 'canvas') {
- qrcode.toCanvas(this.$el, value, options, function (error) {
- /* istanbul ignore if */
- if (error) {
- throw error;
- }
- });
- } else if (tag === 'img') {
- qrcode.toDataURL(value, options, function (error, url) {
- /* istanbul ignore if */
- if (error) {
- throw error;
- }
- _this.$el.src = url;
- });
- } else {
- qrcode.toString(value, options, function (error, string) {
- /* istanbul ignore if */
- if (error) {
- throw error;
- }
- _this.$el.innerHTML = string;
- });
- }
- }
- },
- mounted: function mounted() {
- this.generate();
- }
- };
- return index;
- })));
|