暫無描述

holder.js 135KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612
  1. /*!
  2. Holder - client side image placeholders
  3. Version 2.9.9+jl7z
  4. © 2021 Ivan Malopinsky - https://imsky.co
  5. Site: http://holderjs.com
  6. Issues: https://github.com/imsky/holder/issues
  7. License: MIT
  8. */
  9. (function (window) {
  10. if (!window.document) return;
  11. var document = window.document;
  12. //https://github.com/inexorabletash/polyfill/blob/master/web.js
  13. if (!document.querySelectorAll) {
  14. document.querySelectorAll = function (selectors) {
  15. var style = document.createElement('style'), elements = [], element;
  16. document.documentElement.firstChild.appendChild(style);
  17. document._qsa = [];
  18. style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';
  19. window.scrollBy(0, 0);
  20. style.parentNode.removeChild(style);
  21. while (document._qsa.length) {
  22. element = document._qsa.shift();
  23. element.style.removeAttribute('x-qsa');
  24. elements.push(element);
  25. }
  26. document._qsa = null;
  27. return elements;
  28. };
  29. }
  30. if (!document.querySelector) {
  31. document.querySelector = function (selectors) {
  32. var elements = document.querySelectorAll(selectors);
  33. return (elements.length) ? elements[0] : null;
  34. };
  35. }
  36. if (!document.getElementsByClassName) {
  37. document.getElementsByClassName = function (classNames) {
  38. classNames = String(classNames).replace(/^|\s+/g, '.');
  39. return document.querySelectorAll(classNames);
  40. };
  41. }
  42. //https://github.com/inexorabletash/polyfill
  43. // ES5 15.2.3.14 Object.keys ( O )
  44. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys
  45. if (!Object.keys) {
  46. Object.keys = function (o) {
  47. if (o !== Object(o)) { throw TypeError('Object.keys called on non-object'); }
  48. var ret = [], p;
  49. for (p in o) {
  50. if (Object.prototype.hasOwnProperty.call(o, p)) {
  51. ret.push(p);
  52. }
  53. }
  54. return ret;
  55. };
  56. }
  57. // ES5 15.4.4.18 Array.prototype.forEach ( callbackfn [ , thisArg ] )
  58. // From https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
  59. if (!Array.prototype.forEach) {
  60. Array.prototype.forEach = function (fun /*, thisp */) {
  61. if (this === void 0 || this === null) { throw TypeError(); }
  62. var t = Object(this);
  63. var len = t.length >>> 0;
  64. if (typeof fun !== "function") { throw TypeError(); }
  65. var thisp = arguments[1], i;
  66. for (i = 0; i < len; i++) {
  67. if (i in t) {
  68. fun.call(thisp, t[i], i, t);
  69. }
  70. }
  71. };
  72. }
  73. //https://github.com/inexorabletash/polyfill/blob/master/web.js
  74. (function (global) {
  75. var B64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  76. global.atob = global.atob || function (input) {
  77. input = String(input);
  78. var position = 0,
  79. output = [],
  80. buffer = 0, bits = 0, n;
  81. input = input.replace(/\s/g, '');
  82. if ((input.length % 4) === 0) { input = input.replace(/=+$/, ''); }
  83. if ((input.length % 4) === 1) { throw Error('InvalidCharacterError'); }
  84. if (/[^+/0-9A-Za-z]/.test(input)) { throw Error('InvalidCharacterError'); }
  85. while (position < input.length) {
  86. n = B64_ALPHABET.indexOf(input.charAt(position));
  87. buffer = (buffer << 6) | n;
  88. bits += 6;
  89. if (bits === 24) {
  90. output.push(String.fromCharCode((buffer >> 16) & 0xFF));
  91. output.push(String.fromCharCode((buffer >> 8) & 0xFF));
  92. output.push(String.fromCharCode(buffer & 0xFF));
  93. bits = 0;
  94. buffer = 0;
  95. }
  96. position += 1;
  97. }
  98. if (bits === 12) {
  99. buffer = buffer >> 4;
  100. output.push(String.fromCharCode(buffer & 0xFF));
  101. } else if (bits === 18) {
  102. buffer = buffer >> 2;
  103. output.push(String.fromCharCode((buffer >> 8) & 0xFF));
  104. output.push(String.fromCharCode(buffer & 0xFF));
  105. }
  106. return output.join('');
  107. };
  108. global.btoa = global.btoa || function (input) {
  109. input = String(input);
  110. var position = 0,
  111. out = [],
  112. o1, o2, o3,
  113. e1, e2, e3, e4;
  114. if (/[^\x00-\xFF]/.test(input)) { throw Error('InvalidCharacterError'); }
  115. while (position < input.length) {
  116. o1 = input.charCodeAt(position++);
  117. o2 = input.charCodeAt(position++);
  118. o3 = input.charCodeAt(position++);
  119. // 111111 112222 222233 333333
  120. e1 = o1 >> 2;
  121. e2 = ((o1 & 0x3) << 4) | (o2 >> 4);
  122. e3 = ((o2 & 0xf) << 2) | (o3 >> 6);
  123. e4 = o3 & 0x3f;
  124. if (position === input.length + 2) {
  125. e3 = 64; e4 = 64;
  126. }
  127. else if (position === input.length + 1) {
  128. e4 = 64;
  129. }
  130. out.push(B64_ALPHABET.charAt(e1),
  131. B64_ALPHABET.charAt(e2),
  132. B64_ALPHABET.charAt(e3),
  133. B64_ALPHABET.charAt(e4));
  134. }
  135. return out.join('');
  136. };
  137. }(window));
  138. //https://gist.github.com/jimeh/332357
  139. if (!Object.prototype.hasOwnProperty){
  140. /*jshint -W001, -W103 */
  141. Object.prototype.hasOwnProperty = function(prop) {
  142. var proto = this.__proto__ || this.constructor.prototype;
  143. return (prop in this) && (!(prop in proto) || proto[prop] !== this[prop]);
  144. };
  145. /*jshint +W001, +W103 */
  146. }
  147. // @license http://opensource.org/licenses/MIT
  148. // copyright Paul Irish 2015
  149. // Date.now() is supported everywhere except IE8. For IE8 we use the Date.now polyfill
  150. // github.com/Financial-Times/polyfill-service/blob/master/polyfills/Date.now/polyfill.js
  151. // as Safari 6 doesn't have support for NavigationTiming, we use a Date.now() timestamp for relative values
  152. // if you want values similar to what you'd get with real perf.now, place this towards the head of the page
  153. // but in reality, you're just getting the delta between now() calls, so it's not terribly important where it's placed
  154. (function(){
  155. if ('performance' in window === false) {
  156. window.performance = {};
  157. }
  158. Date.now = (Date.now || function () { // thanks IE8
  159. return new Date().getTime();
  160. });
  161. if ('now' in window.performance === false){
  162. var nowOffset = Date.now();
  163. if (performance.timing && performance.timing.navigationStart){
  164. nowOffset = performance.timing.navigationStart;
  165. }
  166. window.performance.now = function now(){
  167. return Date.now() - nowOffset;
  168. };
  169. }
  170. })();
  171. //requestAnimationFrame polyfill for older Firefox/Chrome versions
  172. if (!window.requestAnimationFrame) {
  173. if (window.webkitRequestAnimationFrame && window.webkitCancelAnimationFrame) {
  174. //https://github.com/Financial-Times/polyfill-service/blob/master/polyfills/requestAnimationFrame/polyfill-webkit.js
  175. (function (global) {
  176. global.requestAnimationFrame = function (callback) {
  177. return webkitRequestAnimationFrame(function () {
  178. callback(global.performance.now());
  179. });
  180. };
  181. global.cancelAnimationFrame = global.webkitCancelAnimationFrame;
  182. }(window));
  183. } else if (window.mozRequestAnimationFrame && window.mozCancelAnimationFrame) {
  184. //https://github.com/Financial-Times/polyfill-service/blob/master/polyfills/requestAnimationFrame/polyfill-moz.js
  185. (function (global) {
  186. global.requestAnimationFrame = function (callback) {
  187. return mozRequestAnimationFrame(function () {
  188. callback(global.performance.now());
  189. });
  190. };
  191. global.cancelAnimationFrame = global.mozCancelAnimationFrame;
  192. }(window));
  193. } else {
  194. (function (global) {
  195. global.requestAnimationFrame = function (callback) {
  196. return global.setTimeout(callback, 1000 / 60);
  197. };
  198. global.cancelAnimationFrame = global.clearTimeout;
  199. })(window);
  200. }
  201. }
  202. })(this);
  203. (function webpackUniversalModuleDefinition(root, factory) {
  204. if(typeof exports === 'object' && typeof module === 'object')
  205. module.exports = factory();
  206. else if(typeof define === 'function' && define.amd)
  207. define([], factory);
  208. else if(typeof exports === 'object')
  209. exports["Holder"] = factory();
  210. else
  211. root["Holder"] = factory();
  212. })(this, function() {
  213. return /******/ (function(modules) { // webpackBootstrap
  214. /******/ // The module cache
  215. /******/ var installedModules = {};
  216. /******/ // The require function
  217. /******/ function __webpack_require__(moduleId) {
  218. /******/ // Check if module is in cache
  219. /******/ if(installedModules[moduleId])
  220. /******/ return installedModules[moduleId].exports;
  221. /******/ // Create a new module (and put it into the cache)
  222. /******/ var module = installedModules[moduleId] = {
  223. /******/ exports: {},
  224. /******/ id: moduleId,
  225. /******/ loaded: false
  226. /******/ };
  227. /******/ // Execute the module function
  228. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  229. /******/ // Flag the module as loaded
  230. /******/ module.loaded = true;
  231. /******/ // Return the exports of the module
  232. /******/ return module.exports;
  233. /******/ }
  234. /******/ // expose the modules object (__webpack_modules__)
  235. /******/ __webpack_require__.m = modules;
  236. /******/ // expose the module cache
  237. /******/ __webpack_require__.c = installedModules;
  238. /******/ // __webpack_public_path__
  239. /******/ __webpack_require__.p = "";
  240. /******/ // Load entry module and return exports
  241. /******/ return __webpack_require__(0);
  242. /******/ })
  243. /************************************************************************/
  244. /******/ ([
  245. /* 0 */
  246. /***/ (function(module, exports, __webpack_require__) {
  247. /*
  248. Holder.js - client side image placeholders
  249. (c) 2012-2020 Ivan Malopinsky - https://imsky.co
  250. */
  251. module.exports = __webpack_require__(1);
  252. /***/ }),
  253. /* 1 */
  254. /***/ (function(module, exports, __webpack_require__) {
  255. /* WEBPACK VAR INJECTION */(function(global) {/*
  256. Holder.js - client side image placeholders
  257. (c) 2012-2020 Ivan Malopinsky - http://imsky.co
  258. */
  259. //Libraries and functions
  260. var onDomReady = __webpack_require__(2);
  261. var querystring = __webpack_require__(3);
  262. var SceneGraph = __webpack_require__(6);
  263. var utils = __webpack_require__(7);
  264. var SVG = __webpack_require__(8);
  265. var DOM = __webpack_require__(9);
  266. var Color = __webpack_require__(10);
  267. var constants = __webpack_require__(11);
  268. var svgRenderer = __webpack_require__(12);
  269. var sgCanvasRenderer = __webpack_require__(27);
  270. var extend = utils.extend;
  271. var dimensionCheck = utils.dimensionCheck;
  272. //Constants and definitions
  273. var SVG_NS = constants.svg_ns;
  274. var Holder = {
  275. version: constants.version,
  276. /**
  277. * Adds a theme to default settings
  278. *
  279. * @param {string} name Theme name
  280. * @param {Object} theme Theme object, with foreground, background, size, font, and fontweight properties.
  281. */
  282. addTheme: function(name, theme) {
  283. name != null && theme != null && (App.settings.themes[name] = theme);
  284. delete App.vars.cache.themeKeys;
  285. return this;
  286. },
  287. /**
  288. * Appends a placeholder to an element
  289. *
  290. * @param {string} src Placeholder URL string
  291. * @param el A selector or a reference to a DOM node
  292. */
  293. addImage: function(src, el) {
  294. //todo: use jquery fallback if available for all QSA references
  295. var nodes = DOM.getNodeArray(el);
  296. nodes.forEach(function (node) {
  297. var img = DOM.newEl('img');
  298. var domProps = {};
  299. domProps[App.setup.dataAttr] = src;
  300. DOM.setAttr(img, domProps);
  301. node.appendChild(img);
  302. });
  303. return this;
  304. },
  305. /**
  306. * Sets whether or not an image is updated on resize.
  307. * If an image is set to be updated, it is immediately rendered.
  308. *
  309. * @param {Object} el Image DOM element
  310. * @param {Boolean} value Resizable update flag value
  311. */
  312. setResizeUpdate: function(el, value) {
  313. if (el.holderData) {
  314. el.holderData.resizeUpdate = !!value;
  315. if (el.holderData.resizeUpdate) {
  316. updateResizableElements(el);
  317. }
  318. }
  319. },
  320. /**
  321. * Runs Holder with options. By default runs Holder on all images with "holder.js" in their source attributes.
  322. *
  323. * @param {Object} userOptions Options object, can contain domain, themes, images, and bgnodes properties
  324. */
  325. run: function(userOptions) {
  326. //todo: split processing into separate queues
  327. userOptions = userOptions || {};
  328. var engineSettings = {};
  329. var options = extend(App.settings, userOptions);
  330. App.vars.preempted = true;
  331. App.vars.dataAttr = options.dataAttr || App.setup.dataAttr;
  332. engineSettings.renderer = options.renderer ? options.renderer : App.setup.renderer;
  333. if (App.setup.renderers.join(',').indexOf(engineSettings.renderer) === -1) {
  334. engineSettings.renderer = App.setup.supportsSVG ? 'svg' : (App.setup.supportsCanvas ? 'canvas' : 'html');
  335. }
  336. var images = DOM.getNodeArray(options.images);
  337. var bgnodes = DOM.getNodeArray(options.bgnodes);
  338. var stylenodes = DOM.getNodeArray(options.stylenodes);
  339. var objects = DOM.getNodeArray(options.objects);
  340. engineSettings.stylesheets = [];
  341. engineSettings.svgXMLStylesheet = true;
  342. engineSettings.noFontFallback = !!options.noFontFallback;
  343. engineSettings.noBackgroundSize = !!options.noBackgroundSize;
  344. stylenodes.forEach(function (styleNode) {
  345. if (styleNode.attributes.rel && styleNode.attributes.href && styleNode.attributes.rel.value == 'stylesheet') {
  346. var href = styleNode.attributes.href.value;
  347. //todo: write isomorphic relative-to-absolute URL function
  348. var proxyLink = DOM.newEl('a');
  349. proxyLink.href = href;
  350. var stylesheetURL = proxyLink.protocol + '//' + proxyLink.host + proxyLink.pathname + proxyLink.search;
  351. engineSettings.stylesheets.push(stylesheetURL);
  352. }
  353. });
  354. bgnodes.forEach(function (bgNode) {
  355. //Skip processing background nodes if getComputedStyle is unavailable, since only modern browsers would be able to use canvas or SVG to render to background
  356. if (!global.getComputedStyle) return;
  357. var backgroundImage = global.getComputedStyle(bgNode, null).getPropertyValue('background-image');
  358. var dataBackgroundImage = bgNode.getAttribute('data-background-src');
  359. var rawURL = dataBackgroundImage || backgroundImage;
  360. var holderURL = null;
  361. var holderString = options.domain + '/';
  362. var holderStringIndex = rawURL.indexOf(holderString);
  363. if (holderStringIndex === 0) {
  364. holderURL = rawURL;
  365. } else if (holderStringIndex === 1 && rawURL[0] === '?') {
  366. holderURL = rawURL.slice(1);
  367. } else {
  368. var fragment = rawURL.substr(holderStringIndex).match(/([^"]*)"?\)/);
  369. if (fragment !== null) {
  370. holderURL = fragment[1];
  371. } else if (rawURL.indexOf('url(') === 0) {
  372. throw 'Holder: unable to parse background URL: ' + rawURL;
  373. }
  374. }
  375. if (holderURL) {
  376. var holderFlags = parseURL(holderURL, options);
  377. if (holderFlags) {
  378. prepareDOMElement({
  379. mode: 'background',
  380. el: bgNode,
  381. flags: holderFlags,
  382. engineSettings: engineSettings
  383. });
  384. }
  385. }
  386. });
  387. objects.forEach(function (object) {
  388. var objectAttr = {};
  389. try {
  390. objectAttr.data = object.getAttribute('data');
  391. objectAttr.dataSrc = object.getAttribute(App.vars.dataAttr);
  392. } catch (e) {
  393. objectAttr.error = e;
  394. }
  395. var objectHasSrcURL = objectAttr.data != null && objectAttr.data.indexOf(options.domain) === 0;
  396. var objectHasDataSrcURL = objectAttr.dataSrc != null && objectAttr.dataSrc.indexOf(options.domain) === 0;
  397. if (objectHasSrcURL) {
  398. prepareImageElement(options, engineSettings, objectAttr.data, object);
  399. } else if (objectHasDataSrcURL) {
  400. prepareImageElement(options, engineSettings, objectAttr.dataSrc, object);
  401. }
  402. });
  403. images.forEach(function (image) {
  404. var imageAttr = {};
  405. try {
  406. imageAttr.src = image.getAttribute('src');
  407. imageAttr.dataSrc = image.getAttribute(App.vars.dataAttr);
  408. imageAttr.rendered = image.getAttribute('data-holder-rendered');
  409. } catch (e) {
  410. imageAttr.error = e;
  411. }
  412. var imageHasSrc = imageAttr.src != null;
  413. var imageHasDataSrcURL = imageAttr.dataSrc != null && imageAttr.dataSrc.indexOf(options.domain) === 0;
  414. var imageRendered = imageAttr.rendered != null && imageAttr.rendered == 'true';
  415. if (imageHasSrc) {
  416. if (imageAttr.src.indexOf(options.domain) === 0) {
  417. prepareImageElement(options, engineSettings, imageAttr.src, image);
  418. } else if (imageHasDataSrcURL) {
  419. //Image has a valid data-src and an invalid src
  420. if (imageRendered) {
  421. //If the placeholder has already been render, re-render it
  422. prepareImageElement(options, engineSettings, imageAttr.dataSrc, image);
  423. } else {
  424. //If the placeholder has not been rendered, check if the image exists and render a fallback if it doesn't
  425. (function(src, options, engineSettings, dataSrc, image) {
  426. utils.imageExists(src, function(exists) {
  427. if (!exists) {
  428. prepareImageElement(options, engineSettings, dataSrc, image);
  429. }
  430. });
  431. })(imageAttr.src, options, engineSettings, imageAttr.dataSrc, image);
  432. }
  433. }
  434. } else if (imageHasDataSrcURL) {
  435. prepareImageElement(options, engineSettings, imageAttr.dataSrc, image);
  436. }
  437. });
  438. return this;
  439. }
  440. };
  441. var App = {
  442. settings: {
  443. domain: 'holder.js',
  444. images: 'img',
  445. objects: 'object',
  446. bgnodes: 'body .holderjs',
  447. stylenodes: 'head link.holderjs',
  448. themes: {
  449. 'gray': {
  450. bg: '#EEEEEE',
  451. fg: '#AAAAAA'
  452. },
  453. 'social': {
  454. bg: '#3a5a97',
  455. fg: '#FFFFFF'
  456. },
  457. 'industrial': {
  458. bg: '#434A52',
  459. fg: '#C2F200'
  460. },
  461. 'sky': {
  462. bg: '#0D8FDB',
  463. fg: '#FFFFFF'
  464. },
  465. 'vine': {
  466. bg: '#39DBAC',
  467. fg: '#1E292C'
  468. },
  469. 'lava': {
  470. bg: '#F8591A',
  471. fg: '#1C2846'
  472. }
  473. }
  474. },
  475. defaults: {
  476. size: 10,
  477. units: 'pt',
  478. scale: 1 / 16
  479. }
  480. };
  481. /**
  482. * Processes provided source attribute and sets up the appropriate rendering workflow
  483. *
  484. * @private
  485. * @param options Instance options from Holder.run
  486. * @param renderSettings Instance configuration
  487. * @param src Image URL
  488. * @param el Image DOM element
  489. */
  490. function prepareImageElement(options, engineSettings, src, el) {
  491. var holderFlags = parseURL(src.substr(src.lastIndexOf(options.domain)), options);
  492. if (holderFlags) {
  493. prepareDOMElement({
  494. mode: null,
  495. el: el,
  496. flags: holderFlags,
  497. engineSettings: engineSettings
  498. });
  499. }
  500. }
  501. /**
  502. * Processes a Holder URL and extracts configuration from query string
  503. *
  504. * @private
  505. * @param url URL
  506. * @param instanceOptions Instance options from Holder.run
  507. */
  508. function parseURL(url, instanceOptions) {
  509. var holder = {
  510. theme: extend(App.settings.themes.gray, null),
  511. stylesheets: instanceOptions.stylesheets,
  512. instanceOptions: instanceOptions
  513. };
  514. var firstQuestionMark = url.indexOf('?');
  515. var parts = [url];
  516. if (firstQuestionMark !== -1) {
  517. parts = [url.slice(0, firstQuestionMark), url.slice(firstQuestionMark + 1)];
  518. }
  519. var basics = parts[0].split('/');
  520. holder.holderURL = url;
  521. var dimensions = basics[1];
  522. var dimensionData = dimensions.match(/([\d]+p?)x([\d]+p?)/);
  523. if (!dimensionData) return false;
  524. holder.fluid = dimensions.indexOf('p') !== -1;
  525. holder.dimensions = {
  526. width: dimensionData[1].replace('p', '%'),
  527. height: dimensionData[2].replace('p', '%')
  528. };
  529. if (parts.length === 2) {
  530. var options = querystring.parse(parts[1]);
  531. // Dimensions
  532. if (utils.truthy(options.ratio)) {
  533. holder.fluid = true;
  534. var ratioWidth = parseFloat(holder.dimensions.width.replace('%', ''));
  535. var ratioHeight = parseFloat(holder.dimensions.height.replace('%', ''));
  536. ratioHeight = Math.floor(100 * (ratioHeight / ratioWidth));
  537. ratioWidth = 100;
  538. holder.dimensions.width = ratioWidth + '%';
  539. holder.dimensions.height = ratioHeight + '%';
  540. }
  541. holder.auto = utils.truthy(options.auto);
  542. // Colors
  543. if (options.bg) {
  544. holder.theme.bg = utils.parseColor(options.bg);
  545. }
  546. if (options.fg) {
  547. holder.theme.fg = utils.parseColor(options.fg);
  548. }
  549. //todo: add automatic foreground to themes without foreground
  550. if (options.bg && !options.fg) {
  551. holder.autoFg = true;
  552. }
  553. if (options.theme && Object.prototype.hasOwnProperty.call(holder.instanceOptions.themes, options.theme)) {
  554. holder.theme = extend(holder.instanceOptions.themes[options.theme], null);
  555. }
  556. // Text
  557. if (options.text) {
  558. holder.text = options.text;
  559. }
  560. if (options.textmode) {
  561. holder.textmode = options.textmode;
  562. }
  563. if (options.size && parseFloat(options.size)) {
  564. holder.size = parseFloat(options.size);
  565. }
  566. if (options.fixedSize != null) {
  567. holder.fixedSize = utils.truthy(options.fixedSize);
  568. }
  569. if (options.font) {
  570. holder.font = options.font;
  571. }
  572. if (options.align) {
  573. holder.align = options.align;
  574. }
  575. if (options.lineWrap) {
  576. holder.lineWrap = options.lineWrap;
  577. }
  578. holder.nowrap = utils.truthy(options.nowrap);
  579. // Miscellaneous
  580. holder.outline = utils.truthy(options.outline);
  581. if (utils.truthy(options.random)) {
  582. App.vars.cache.themeKeys = App.vars.cache.themeKeys || Object.keys(holder.instanceOptions.themes);
  583. var _theme = App.vars.cache.themeKeys[0 | Math.random() * App.vars.cache.themeKeys.length];
  584. holder.theme = extend(holder.instanceOptions.themes[_theme], null);
  585. }
  586. }
  587. return holder;
  588. }
  589. /**
  590. * Modifies the DOM to fit placeholders and sets up resizable image callbacks (for fluid and automatically sized placeholders)
  591. *
  592. * @private
  593. * @param settings DOM prep settings
  594. */
  595. function prepareDOMElement(prepSettings) {
  596. var mode = prepSettings.mode;
  597. var el = prepSettings.el;
  598. var flags = prepSettings.flags;
  599. var _engineSettings = prepSettings.engineSettings;
  600. var dimensions = flags.dimensions,
  601. theme = flags.theme;
  602. var dimensionsCaption = dimensions.width + 'x' + dimensions.height;
  603. mode = mode == null ? (flags.fluid ? 'fluid' : 'image') : mode;
  604. var holderTemplateRe = /holder_([a-z]+)/g;
  605. var dimensionsInText = false;
  606. if (flags.text != null) {
  607. theme.text = flags.text;
  608. //<object> SVG embedding doesn't parse Unicode properly
  609. if (el.nodeName.toLowerCase() === 'object') {
  610. var textLines = theme.text.split('\\n');
  611. for (var k = 0; k < textLines.length; k++) {
  612. textLines[k] = utils.encodeHtmlEntity(textLines[k]);
  613. }
  614. theme.text = textLines.join('\\n');
  615. }
  616. }
  617. if (theme.text) {
  618. var holderTemplateMatches = theme.text.match(holderTemplateRe);
  619. if (holderTemplateMatches !== null) {
  620. //todo: optimize template replacement
  621. holderTemplateMatches.forEach(function (match) {
  622. if (match === 'holder_dimensions') {
  623. theme.text = theme.text.replace(match, dimensionsCaption);
  624. }
  625. });
  626. }
  627. }
  628. var holderURL = flags.holderURL;
  629. var engineSettings = extend(_engineSettings, null);
  630. if (flags.font) {
  631. /*
  632. If external fonts are used in a <img> placeholder rendered with SVG, Holder falls back to canvas.
  633. This is done because Firefox and Chrome disallow embedded SVGs from referencing external assets.
  634. The workaround is either to change the placeholder tag from <img> to <object> or to use the canvas renderer.
  635. */
  636. theme.font = flags.font;
  637. if (!engineSettings.noFontFallback && el.nodeName.toLowerCase() === 'img' && App.setup.supportsCanvas && engineSettings.renderer === 'svg') {
  638. engineSettings = extend(engineSettings, {
  639. renderer: 'canvas'
  640. });
  641. }
  642. }
  643. //Chrome and Opera require a quick 10ms re-render if web fonts are used with canvas
  644. if (flags.font && engineSettings.renderer == 'canvas') {
  645. engineSettings.reRender = true;
  646. }
  647. if (mode == 'background') {
  648. if (el.getAttribute('data-background-src') == null) {
  649. DOM.setAttr(el, {
  650. 'data-background-src': holderURL
  651. });
  652. }
  653. } else {
  654. var domProps = {};
  655. domProps[App.vars.dataAttr] = holderURL;
  656. DOM.setAttr(el, domProps);
  657. }
  658. flags.theme = theme;
  659. //todo consider using all renderSettings in holderData
  660. el.holderData = {
  661. flags: flags,
  662. engineSettings: engineSettings
  663. };
  664. if (mode == 'image' || mode == 'fluid') {
  665. DOM.setAttr(el, {
  666. 'alt': theme.text ? (dimensionsInText ? theme.text : theme.text + ' [' + dimensionsCaption + ']') : dimensionsCaption
  667. });
  668. }
  669. var renderSettings = {
  670. mode: mode,
  671. el: el,
  672. holderSettings: {
  673. dimensions: dimensions,
  674. theme: theme,
  675. flags: flags
  676. },
  677. engineSettings: engineSettings
  678. };
  679. if (mode == 'image') {
  680. if (!flags.auto) {
  681. el.style.width = dimensions.width + 'px';
  682. el.style.height = dimensions.height + 'px';
  683. }
  684. if (engineSettings.renderer == 'html') {
  685. el.style.backgroundColor = theme.bg;
  686. } else {
  687. render(renderSettings);
  688. if (flags.textmode == 'exact') {
  689. el.holderData.resizeUpdate = true;
  690. App.vars.resizableImages.push(el);
  691. updateResizableElements(el);
  692. }
  693. }
  694. } else if (mode == 'background' && engineSettings.renderer != 'html') {
  695. render(renderSettings);
  696. } else if (mode == 'fluid') {
  697. el.holderData.resizeUpdate = true;
  698. if (dimensions.height.slice(-1) == '%') {
  699. el.style.height = dimensions.height;
  700. } else if (flags.auto == null || !flags.auto) {
  701. el.style.height = dimensions.height + 'px';
  702. }
  703. if (dimensions.width.slice(-1) == '%') {
  704. el.style.width = dimensions.width;
  705. } else if (flags.auto == null || !flags.auto) {
  706. el.style.width = dimensions.width + 'px';
  707. }
  708. if (el.style.display == 'inline' || el.style.display === '' || el.style.display == 'none') {
  709. el.style.display = 'block';
  710. }
  711. setInitialDimensions(el);
  712. if (engineSettings.renderer == 'html') {
  713. el.style.backgroundColor = theme.bg;
  714. } else {
  715. App.vars.resizableImages.push(el);
  716. updateResizableElements(el);
  717. }
  718. }
  719. }
  720. /**
  721. * Core function that takes output from renderers and sets it as the source or background-image of the target element
  722. *
  723. * @private
  724. * @param renderSettings Renderer settings
  725. */
  726. function render(renderSettings) {
  727. var image = null;
  728. var mode = renderSettings.mode;
  729. var el = renderSettings.el;
  730. var holderSettings = renderSettings.holderSettings;
  731. var engineSettings = renderSettings.engineSettings;
  732. switch (engineSettings.renderer) {
  733. case 'svg':
  734. if (!App.setup.supportsSVG) return;
  735. break;
  736. case 'canvas':
  737. if (!App.setup.supportsCanvas) return;
  738. break;
  739. default:
  740. return;
  741. }
  742. //todo: move generation of scene up to flag generation to reduce extra object creation
  743. var scene = {
  744. width: holderSettings.dimensions.width,
  745. height: holderSettings.dimensions.height,
  746. theme: holderSettings.theme,
  747. flags: holderSettings.flags
  748. };
  749. var sceneGraph = buildSceneGraph(scene);
  750. function getRenderedImage() {
  751. var image = null;
  752. switch (engineSettings.renderer) {
  753. case 'canvas':
  754. image = sgCanvasRenderer(sceneGraph, renderSettings);
  755. break;
  756. case 'svg':
  757. image = svgRenderer(sceneGraph, renderSettings);
  758. break;
  759. default:
  760. throw 'Holder: invalid renderer: ' + engineSettings.renderer;
  761. }
  762. return image;
  763. }
  764. image = getRenderedImage();
  765. if (image == null) {
  766. throw 'Holder: couldn\'t render placeholder';
  767. }
  768. //todo: add <object> canvas rendering
  769. if (mode == 'background') {
  770. el.style.backgroundImage = 'url(' + image + ')';
  771. if (!engineSettings.noBackgroundSize) {
  772. el.style.backgroundSize = scene.width + 'px ' + scene.height + 'px';
  773. }
  774. } else {
  775. if (el.nodeName.toLowerCase() === 'img') {
  776. DOM.setAttr(el, {
  777. 'src': image
  778. });
  779. } else if (el.nodeName.toLowerCase() === 'object') {
  780. DOM.setAttr(el, {
  781. 'data': image,
  782. 'type': 'image/svg+xml'
  783. });
  784. }
  785. if (engineSettings.reRender) {
  786. global.setTimeout(function () {
  787. var image = getRenderedImage();
  788. if (image == null) {
  789. throw 'Holder: couldn\'t render placeholder';
  790. }
  791. //todo: refactor this code into a function
  792. if (el.nodeName.toLowerCase() === 'img') {
  793. DOM.setAttr(el, {
  794. 'src': image
  795. });
  796. } else if (el.nodeName.toLowerCase() === 'object') {
  797. DOM.setAttr(el, {
  798. 'data': image,
  799. 'type': 'image/svg+xml'
  800. });
  801. }
  802. }, 150);
  803. }
  804. }
  805. //todo: account for re-rendering
  806. DOM.setAttr(el, {
  807. 'data-holder-rendered': true
  808. });
  809. }
  810. /**
  811. * Core function that takes a Holder scene description and builds a scene graph
  812. *
  813. * @private
  814. * @param scene Holder scene object
  815. */
  816. //todo: make this function reusable
  817. //todo: merge app defaults and setup properties into the scene argument
  818. function buildSceneGraph(scene) {
  819. var fontSize = App.defaults.size;
  820. var fixedSize = scene.flags.fixedSize != null ? scene.flags.fixedSize : scene.theme.fixedSize;
  821. if (parseFloat(scene.theme.size)) {
  822. fontSize = scene.theme.size;
  823. } else if (parseFloat(scene.flags.size)) {
  824. fontSize = scene.flags.size;
  825. }
  826. scene.font = {
  827. family: scene.theme.font ? scene.theme.font : 'Arial, Helvetica, Open Sans, sans-serif',
  828. size: fixedSize ? fontSize : textSize(scene.width, scene.height, fontSize, App.defaults.scale),
  829. units: scene.theme.units ? scene.theme.units : App.defaults.units,
  830. weight: scene.theme.fontweight ? scene.theme.fontweight : 'bold'
  831. };
  832. scene.text = scene.theme.text || Math.floor(scene.width) + 'x' + Math.floor(scene.height);
  833. scene.noWrap = scene.theme.nowrap || scene.flags.nowrap;
  834. scene.align = scene.theme.align || scene.flags.align || 'center';
  835. switch (scene.flags.textmode) {
  836. case 'literal':
  837. scene.text = scene.flags.dimensions.width + 'x' + scene.flags.dimensions.height;
  838. break;
  839. case 'exact':
  840. if (!scene.flags.exactDimensions) break;
  841. scene.text = Math.floor(scene.flags.exactDimensions.width) + 'x' + Math.floor(scene.flags.exactDimensions.height);
  842. break;
  843. }
  844. var lineWrap = scene.flags.lineWrap || App.setup.lineWrapRatio;
  845. var sceneMargin = scene.width * lineWrap;
  846. var maxLineWidth = sceneMargin;
  847. var sceneGraph = new SceneGraph({
  848. width: scene.width,
  849. height: scene.height
  850. });
  851. var Shape = sceneGraph.Shape;
  852. var holderBg = new Shape.Rect('holderBg', {
  853. fill: scene.theme.bg
  854. });
  855. holderBg.resize(scene.width, scene.height);
  856. sceneGraph.root.add(holderBg);
  857. if (scene.flags.outline) {
  858. var outlineColor = new Color(holderBg.properties.fill);
  859. outlineColor = outlineColor.lighten(outlineColor.lighterThan('7f7f7f') ? -0.1 : 0.1);
  860. holderBg.properties.outline = {
  861. fill: outlineColor.toHex(true),
  862. width: 2
  863. };
  864. }
  865. var holderTextColor = scene.theme.fg;
  866. if (scene.flags.autoFg) {
  867. var holderBgColor = new Color(holderBg.properties.fill);
  868. var lightColor = new Color('fff');
  869. var darkColor = new Color('000', {
  870. 'alpha': 0.285714
  871. });
  872. holderTextColor = holderBgColor.blendAlpha(holderBgColor.lighterThan('7f7f7f') ? darkColor : lightColor).toHex(true);
  873. }
  874. var holderTextGroup = new Shape.Group('holderTextGroup', {
  875. text: scene.text,
  876. align: scene.align,
  877. font: scene.font,
  878. fill: holderTextColor
  879. });
  880. holderTextGroup.moveTo(null, null, 1);
  881. sceneGraph.root.add(holderTextGroup);
  882. var tpdata = holderTextGroup.textPositionData = stagingRenderer(sceneGraph);
  883. if (!tpdata) {
  884. throw 'Holder: staging fallback not supported yet.';
  885. }
  886. holderTextGroup.properties.leading = tpdata.boundingBox.height;
  887. var textNode = null;
  888. var line = null;
  889. function finalizeLine(parent, line, width, height) {
  890. line.width = width;
  891. line.height = height;
  892. parent.width = Math.max(parent.width, line.width);
  893. parent.height += line.height;
  894. }
  895. if (tpdata.lineCount > 1) {
  896. var offsetX = 0;
  897. var offsetY = 0;
  898. var lineIndex = 0;
  899. var lineKey;
  900. line = new Shape.Group('line' + lineIndex);
  901. //Double margin so that left/right-aligned next is not flush with edge of image
  902. if (scene.align === 'left' || scene.align === 'right') {
  903. maxLineWidth = scene.width * (1 - (1 - lineWrap) * 2);
  904. }
  905. for (var i = 0; i < tpdata.words.length; i++) {
  906. var word = tpdata.words[i];
  907. textNode = new Shape.Text(word.text);
  908. var newline = word.text == '\\n';
  909. if (!scene.noWrap && (offsetX + word.width >= maxLineWidth || newline === true)) {
  910. finalizeLine(holderTextGroup, line, offsetX, holderTextGroup.properties.leading);
  911. holderTextGroup.add(line);
  912. offsetX = 0;
  913. offsetY += holderTextGroup.properties.leading;
  914. lineIndex += 1;
  915. line = new Shape.Group('line' + lineIndex);
  916. line.y = offsetY;
  917. }
  918. if (newline === true) {
  919. continue;
  920. }
  921. textNode.moveTo(offsetX, 0);
  922. offsetX += tpdata.spaceWidth + word.width;
  923. line.add(textNode);
  924. }
  925. finalizeLine(holderTextGroup, line, offsetX, holderTextGroup.properties.leading);
  926. holderTextGroup.add(line);
  927. if (scene.align === 'left') {
  928. holderTextGroup.moveTo(scene.width - sceneMargin, null, null);
  929. } else if (scene.align === 'right') {
  930. for (lineKey in holderTextGroup.children) {
  931. line = holderTextGroup.children[lineKey];
  932. line.moveTo(scene.width - line.width, null, null);
  933. }
  934. holderTextGroup.moveTo(0 - (scene.width - sceneMargin), null, null);
  935. } else {
  936. for (lineKey in holderTextGroup.children) {
  937. line = holderTextGroup.children[lineKey];
  938. line.moveTo((holderTextGroup.width - line.width) / 2, null, null);
  939. }
  940. holderTextGroup.moveTo((scene.width - holderTextGroup.width) / 2, null, null);
  941. }
  942. holderTextGroup.moveTo(null, (scene.height - holderTextGroup.height) / 2, null);
  943. //If the text exceeds vertical space, move it down so the first line is visible
  944. if ((scene.height - holderTextGroup.height) / 2 < 0) {
  945. holderTextGroup.moveTo(null, 0, null);
  946. }
  947. } else {
  948. textNode = new Shape.Text(scene.text);
  949. line = new Shape.Group('line0');
  950. line.add(textNode);
  951. holderTextGroup.add(line);
  952. if (scene.align === 'left') {
  953. holderTextGroup.moveTo(scene.width - sceneMargin, null, null);
  954. } else if (scene.align === 'right') {
  955. holderTextGroup.moveTo(0 - (scene.width - sceneMargin), null, null);
  956. } else {
  957. holderTextGroup.moveTo((scene.width - tpdata.boundingBox.width) / 2, null, null);
  958. }
  959. holderTextGroup.moveTo(null, (scene.height - tpdata.boundingBox.height) / 2, null);
  960. }
  961. //todo: renderlist
  962. return sceneGraph;
  963. }
  964. /**
  965. * Adaptive text sizing function
  966. *
  967. * @private
  968. * @param width Parent width
  969. * @param height Parent height
  970. * @param fontSize Requested text size
  971. * @param scale Proportional scale of text
  972. */
  973. function textSize(width, height, fontSize, scale) {
  974. var stageWidth = parseInt(width, 10);
  975. var stageHeight = parseInt(height, 10);
  976. var bigSide = Math.max(stageWidth, stageHeight);
  977. var smallSide = Math.min(stageWidth, stageHeight);
  978. var newHeight = 0.8 * Math.min(smallSide, bigSide * scale);
  979. return Math.round(Math.max(fontSize, newHeight));
  980. }
  981. /**
  982. * Iterates over resizable (fluid or auto) placeholders and renders them
  983. *
  984. * @private
  985. * @param element Optional element selector, specified only if a specific element needs to be re-rendered
  986. */
  987. function updateResizableElements(element) {
  988. var images;
  989. if (element == null || element.nodeType == null) {
  990. images = App.vars.resizableImages;
  991. } else {
  992. images = [element];
  993. }
  994. for (var i = 0, l = images.length; i < l; i++) {
  995. var el = images[i];
  996. if (el.holderData) {
  997. var flags = el.holderData.flags;
  998. var dimensions = dimensionCheck(el);
  999. if (dimensions) {
  1000. if (!el.holderData.resizeUpdate) {
  1001. continue;
  1002. }
  1003. if (flags.fluid && flags.auto) {
  1004. var fluidConfig = el.holderData.fluidConfig;
  1005. switch (fluidConfig.mode) {
  1006. case 'width':
  1007. dimensions.height = dimensions.width / fluidConfig.ratio;
  1008. break;
  1009. case 'height':
  1010. dimensions.width = dimensions.height * fluidConfig.ratio;
  1011. break;
  1012. }
  1013. }
  1014. var settings = {
  1015. mode: 'image',
  1016. holderSettings: {
  1017. dimensions: dimensions,
  1018. theme: flags.theme,
  1019. flags: flags
  1020. },
  1021. el: el,
  1022. engineSettings: el.holderData.engineSettings
  1023. };
  1024. if (flags.textmode == 'exact') {
  1025. flags.exactDimensions = dimensions;
  1026. settings.holderSettings.dimensions = flags.dimensions;
  1027. }
  1028. render(settings);
  1029. } else {
  1030. setInvisible(el);
  1031. }
  1032. }
  1033. }
  1034. }
  1035. /**
  1036. * Sets up aspect ratio metadata for fluid placeholders, in order to preserve proportions when resizing
  1037. *
  1038. * @private
  1039. * @param el Image DOM element
  1040. */
  1041. function setInitialDimensions(el) {
  1042. if (el.holderData) {
  1043. var dimensions = dimensionCheck(el);
  1044. if (dimensions) {
  1045. var flags = el.holderData.flags;
  1046. var fluidConfig = {
  1047. fluidHeight: flags.dimensions.height.slice(-1) == '%',
  1048. fluidWidth: flags.dimensions.width.slice(-1) == '%',
  1049. mode: null,
  1050. initialDimensions: dimensions
  1051. };
  1052. if (fluidConfig.fluidWidth && !fluidConfig.fluidHeight) {
  1053. fluidConfig.mode = 'width';
  1054. fluidConfig.ratio = fluidConfig.initialDimensions.width / parseFloat(flags.dimensions.height);
  1055. } else if (!fluidConfig.fluidWidth && fluidConfig.fluidHeight) {
  1056. fluidConfig.mode = 'height';
  1057. fluidConfig.ratio = parseFloat(flags.dimensions.width) / fluidConfig.initialDimensions.height;
  1058. }
  1059. el.holderData.fluidConfig = fluidConfig;
  1060. } else {
  1061. setInvisible(el);
  1062. }
  1063. }
  1064. }
  1065. /**
  1066. * Iterates through all current invisible images, and if they're visible, renders them and removes them from further checks. Runs every animation frame.
  1067. *
  1068. * @private
  1069. */
  1070. function visibilityCheck() {
  1071. var renderableImages = [];
  1072. var keys = Object.keys(App.vars.invisibleImages);
  1073. var el;
  1074. keys.forEach(function (key) {
  1075. el = App.vars.invisibleImages[key];
  1076. if (dimensionCheck(el) && el.nodeName.toLowerCase() == 'img') {
  1077. renderableImages.push(el);
  1078. delete App.vars.invisibleImages[key];
  1079. }
  1080. });
  1081. if (renderableImages.length) {
  1082. Holder.run({
  1083. images: renderableImages
  1084. });
  1085. }
  1086. // Done to prevent 100% CPU usage via aggressive calling of requestAnimationFrame
  1087. setTimeout(function () {
  1088. global.requestAnimationFrame(visibilityCheck);
  1089. }, 10);
  1090. }
  1091. /**
  1092. * Starts checking for invisible placeholders if not doing so yet. Does nothing otherwise.
  1093. *
  1094. * @private
  1095. */
  1096. function startVisibilityCheck() {
  1097. if (!App.vars.visibilityCheckStarted) {
  1098. global.requestAnimationFrame(visibilityCheck);
  1099. App.vars.visibilityCheckStarted = true;
  1100. }
  1101. }
  1102. /**
  1103. * Sets a unique ID for an image detected to be invisible and adds it to the map of invisible images checked by visibilityCheck
  1104. *
  1105. * @private
  1106. * @param el Invisible DOM element
  1107. */
  1108. function setInvisible(el) {
  1109. if (!el.holderData.invisibleId) {
  1110. App.vars.invisibleId += 1;
  1111. App.vars.invisibleImages['i' + App.vars.invisibleId] = el;
  1112. el.holderData.invisibleId = App.vars.invisibleId;
  1113. }
  1114. }
  1115. //todo: see if possible to convert stagingRenderer to use HTML only
  1116. var stagingRenderer = (function() {
  1117. var svg = null,
  1118. stagingText = null,
  1119. stagingTextNode = null;
  1120. return function(graph) {
  1121. var rootNode = graph.root;
  1122. if (App.setup.supportsSVG) {
  1123. var firstTimeSetup = false;
  1124. var tnode = function(text) {
  1125. return document.createTextNode(text);
  1126. };
  1127. if (svg == null || svg.parentNode !== document.body) {
  1128. firstTimeSetup = true;
  1129. }
  1130. svg = SVG.initSVG(svg, rootNode.properties.width, rootNode.properties.height);
  1131. //Show staging element before staging
  1132. svg.style.display = 'block';
  1133. if (firstTimeSetup) {
  1134. stagingText = DOM.newEl('text', SVG_NS);
  1135. stagingTextNode = tnode(null);
  1136. DOM.setAttr(stagingText, {
  1137. x: 0
  1138. });
  1139. stagingText.appendChild(stagingTextNode);
  1140. svg.appendChild(stagingText);
  1141. document.body.appendChild(svg);
  1142. svg.style.visibility = 'hidden';
  1143. svg.style.position = 'absolute';
  1144. svg.style.top = '-100%';
  1145. svg.style.left = '-100%';
  1146. //todo: workaround for zero-dimension <svg> tag in Opera 12
  1147. //svg.setAttribute('width', 0);
  1148. //svg.setAttribute('height', 0);
  1149. }
  1150. var holderTextGroup = rootNode.children.holderTextGroup;
  1151. var htgProps = holderTextGroup.properties;
  1152. DOM.setAttr(stagingText, {
  1153. 'y': htgProps.font.size,
  1154. 'style': utils.cssProps({
  1155. 'font-weight': htgProps.font.weight,
  1156. 'font-size': htgProps.font.size + htgProps.font.units,
  1157. 'font-family': htgProps.font.family
  1158. })
  1159. });
  1160. //Unescape HTML entities to get approximately the right width
  1161. var txt = DOM.newEl('textarea');
  1162. txt.innerHTML = htgProps.text;
  1163. stagingTextNode.nodeValue = txt.value;
  1164. //Get bounding box for the whole string (total width and height)
  1165. var stagingTextBBox = stagingText.getBBox();
  1166. //Get line count and split the string into words
  1167. var lineCount = Math.ceil(stagingTextBBox.width / rootNode.properties.width);
  1168. var words = htgProps.text.split(' ');
  1169. var newlines = htgProps.text.match(/\\n/g);
  1170. lineCount += newlines == null ? 0 : newlines.length;
  1171. //Get bounding box for the string with spaces removed
  1172. stagingTextNode.nodeValue = htgProps.text.replace(/[ ]+/g, '');
  1173. var computedNoSpaceLength = stagingText.getComputedTextLength();
  1174. //Compute average space width
  1175. var diffLength = stagingTextBBox.width - computedNoSpaceLength;
  1176. var spaceWidth = Math.round(diffLength / Math.max(1, words.length - 1));
  1177. //Get widths for every word with space only if there is more than one line
  1178. var wordWidths = [];
  1179. if (lineCount > 1) {
  1180. stagingTextNode.nodeValue = '';
  1181. for (var i = 0; i < words.length; i++) {
  1182. if (words[i].length === 0) continue;
  1183. stagingTextNode.nodeValue = utils.decodeHtmlEntity(words[i]);
  1184. var bbox = stagingText.getBBox();
  1185. wordWidths.push({
  1186. text: words[i],
  1187. width: bbox.width
  1188. });
  1189. }
  1190. }
  1191. //Hide staging element after staging
  1192. svg.style.display = 'none';
  1193. return {
  1194. spaceWidth: spaceWidth,
  1195. lineCount: lineCount,
  1196. boundingBox: stagingTextBBox,
  1197. words: wordWidths
  1198. };
  1199. } else {
  1200. //todo: canvas fallback for measuring text on android 2.3
  1201. return false;
  1202. }
  1203. };
  1204. })();
  1205. //Helpers
  1206. /**
  1207. * Prevents a function from being called too often, waits until a timer elapses to call it again
  1208. *
  1209. * @param fn Function to call
  1210. */
  1211. function debounce(fn) {
  1212. if (!App.vars.debounceTimer) fn.call(this);
  1213. if (App.vars.debounceTimer) global.clearTimeout(App.vars.debounceTimer);
  1214. App.vars.debounceTimer = global.setTimeout(function() {
  1215. App.vars.debounceTimer = null;
  1216. fn.call(this);
  1217. }, App.setup.debounce);
  1218. }
  1219. /**
  1220. * Holder-specific resize/orientation change callback, debounced to prevent excessive execution
  1221. */
  1222. function resizeEvent() {
  1223. debounce(function() {
  1224. updateResizableElements(null);
  1225. });
  1226. }
  1227. //Set up flags
  1228. for (var flag in App.flags) {
  1229. if (!Object.prototype.hasOwnProperty.call(App.flags, flag)) continue;
  1230. App.flags[flag].match = function(val) {
  1231. return val.match(this.regex);
  1232. };
  1233. }
  1234. //Properties set once on setup
  1235. App.setup = {
  1236. renderer: 'html',
  1237. debounce: 100,
  1238. ratio: 1,
  1239. supportsCanvas: false,
  1240. supportsSVG: false,
  1241. lineWrapRatio: 0.9,
  1242. dataAttr: 'data-src',
  1243. renderers: ['html', 'canvas', 'svg']
  1244. };
  1245. //Properties modified during runtime
  1246. App.vars = {
  1247. preempted: false,
  1248. resizableImages: [],
  1249. invisibleImages: {},
  1250. invisibleId: 0,
  1251. visibilityCheckStarted: false,
  1252. debounceTimer: null,
  1253. cache: {}
  1254. };
  1255. //Pre-flight
  1256. (function() {
  1257. var canvas = DOM.newEl('canvas');
  1258. if (canvas.getContext) {
  1259. if (canvas.toDataURL('image/png').indexOf('data:image/png') != -1) {
  1260. App.setup.renderer = 'canvas';
  1261. App.setup.supportsCanvas = true;
  1262. }
  1263. }
  1264. if (!!document.createElementNS && !!document.createElementNS(SVG_NS, 'svg').createSVGRect) {
  1265. App.setup.renderer = 'svg';
  1266. App.setup.supportsSVG = true;
  1267. }
  1268. })();
  1269. //Starts checking for invisible placeholders
  1270. startVisibilityCheck();
  1271. if (onDomReady) {
  1272. onDomReady(function() {
  1273. if (!App.vars.preempted) {
  1274. Holder.run();
  1275. }
  1276. if (global.addEventListener) {
  1277. global.addEventListener('resize', resizeEvent, false);
  1278. global.addEventListener('orientationchange', resizeEvent, false);
  1279. } else {
  1280. global.attachEvent('onresize', resizeEvent);
  1281. }
  1282. if (typeof global.Turbolinks == 'object') {
  1283. global.document.addEventListener('page:change', function() {
  1284. Holder.run();
  1285. });
  1286. }
  1287. });
  1288. }
  1289. module.exports = Holder;
  1290. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  1291. /***/ }),
  1292. /* 2 */
  1293. /***/ (function(module, exports) {
  1294. /*!
  1295. * onDomReady.js 1.4.0 (c) 2013 Tubal Martin - MIT license
  1296. *
  1297. * Specially modified to work with Holder.js
  1298. */
  1299. function _onDomReady(win) {
  1300. //Lazy loading fix for Firefox < 3.6
  1301. //http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
  1302. if (document.readyState == null && document.addEventListener) {
  1303. document.addEventListener("DOMContentLoaded", function DOMContentLoaded() {
  1304. document.removeEventListener("DOMContentLoaded", DOMContentLoaded, false);
  1305. document.readyState = "complete";
  1306. }, false);
  1307. document.readyState = "loading";
  1308. }
  1309. var doc = win.document,
  1310. docElem = doc.documentElement,
  1311. LOAD = "load",
  1312. FALSE = false,
  1313. ONLOAD = "on"+LOAD,
  1314. COMPLETE = "complete",
  1315. READYSTATE = "readyState",
  1316. ATTACHEVENT = "attachEvent",
  1317. DETACHEVENT = "detachEvent",
  1318. ADDEVENTLISTENER = "addEventListener",
  1319. DOMCONTENTLOADED = "DOMContentLoaded",
  1320. ONREADYSTATECHANGE = "onreadystatechange",
  1321. REMOVEEVENTLISTENER = "removeEventListener",
  1322. // W3C Event model
  1323. w3c = ADDEVENTLISTENER in doc,
  1324. _top = FALSE,
  1325. // isReady: Is the DOM ready to be used? Set to true once it occurs.
  1326. isReady = FALSE,
  1327. // Callbacks pending execution until DOM is ready
  1328. callbacks = [];
  1329. // Handle when the DOM is ready
  1330. function ready( fn ) {
  1331. if ( !isReady ) {
  1332. // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
  1333. if ( !doc.body ) {
  1334. return defer( ready );
  1335. }
  1336. // Remember that the DOM is ready
  1337. isReady = true;
  1338. // Execute all callbacks
  1339. while ( fn = callbacks.shift() ) {
  1340. defer( fn );
  1341. }
  1342. }
  1343. }
  1344. // The ready event handler
  1345. function completed( event ) {
  1346. // readyState === "complete" is good enough for us to call the dom ready in oldIE
  1347. if ( w3c || event.type === LOAD || doc[READYSTATE] === COMPLETE ) {
  1348. detach();
  1349. ready();
  1350. }
  1351. }
  1352. // Clean-up method for dom ready events
  1353. function detach() {
  1354. if ( w3c ) {
  1355. doc[REMOVEEVENTLISTENER]( DOMCONTENTLOADED, completed, FALSE );
  1356. win[REMOVEEVENTLISTENER]( LOAD, completed, FALSE );
  1357. } else {
  1358. doc[DETACHEVENT]( ONREADYSTATECHANGE, completed );
  1359. win[DETACHEVENT]( ONLOAD, completed );
  1360. }
  1361. }
  1362. // Defers a function, scheduling it to run after the current call stack has cleared.
  1363. function defer( fn, wait ) {
  1364. // Allow 0 to be passed
  1365. setTimeout( fn, +wait >= 0 ? wait : 1 );
  1366. }
  1367. // Attach the listeners:
  1368. // Catch cases where onDomReady is called after the browser event has already occurred.
  1369. // we once tried to use readyState "interactive" here, but it caused issues like the one
  1370. // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
  1371. if ( doc[READYSTATE] === COMPLETE ) {
  1372. // Handle it asynchronously to allow scripts the opportunity to delay ready
  1373. defer( ready );
  1374. // Standards-based browsers support DOMContentLoaded
  1375. } else if ( w3c ) {
  1376. // Use the handy event callback
  1377. doc[ADDEVENTLISTENER]( DOMCONTENTLOADED, completed, FALSE );
  1378. // A fallback to window.onload, that will always work
  1379. win[ADDEVENTLISTENER]( LOAD, completed, FALSE );
  1380. // If IE event model is used
  1381. } else {
  1382. // Ensure firing before onload, maybe late but safe also for iframes
  1383. doc[ATTACHEVENT]( ONREADYSTATECHANGE, completed );
  1384. // A fallback to window.onload, that will always work
  1385. win[ATTACHEVENT]( ONLOAD, completed );
  1386. // If IE and not a frame
  1387. // continually check to see if the document is ready
  1388. try {
  1389. _top = win.frameElement == null && docElem;
  1390. } catch(e) {}
  1391. if ( _top && _top.doScroll ) {
  1392. (function doScrollCheck() {
  1393. if ( !isReady ) {
  1394. try {
  1395. // Use the trick by Diego Perini
  1396. // http://javascript.nwbox.com/IEContentLoaded/
  1397. _top.doScroll("left");
  1398. } catch(e) {
  1399. return defer( doScrollCheck, 50 );
  1400. }
  1401. // detach all dom ready events
  1402. detach();
  1403. // and execute any waiting functions
  1404. ready();
  1405. }
  1406. })();
  1407. }
  1408. }
  1409. function onDomReady( fn ) {
  1410. // If DOM is ready, execute the function (async), otherwise wait
  1411. isReady ? defer( fn ) : callbacks.push( fn );
  1412. }
  1413. // Add version
  1414. onDomReady.version = "1.4.0";
  1415. // Add method to check if DOM is ready
  1416. onDomReady.isReady = function(){
  1417. return isReady;
  1418. };
  1419. return onDomReady;
  1420. }
  1421. module.exports = typeof window !== "undefined" && _onDomReady(window);
  1422. /***/ }),
  1423. /* 3 */
  1424. /***/ (function(module, exports, __webpack_require__) {
  1425. //Modified version of component/querystring
  1426. //Changes: updated dependencies, dot notation parsing, JSHint fixes
  1427. //Fork at https://github.com/imsky/querystring
  1428. /**
  1429. * Module dependencies.
  1430. */
  1431. var encode = encodeURIComponent;
  1432. var decode = decodeURIComponent;
  1433. var trim = __webpack_require__(4);
  1434. var type = __webpack_require__(5);
  1435. var arrayRegex = /(\w+)\[(\d+)\]/;
  1436. var objectRegex = /\w+\.\w+/;
  1437. /**
  1438. * Parse the given query `str`.
  1439. *
  1440. * @param {String} str
  1441. * @return {Object}
  1442. * @api public
  1443. */
  1444. exports.parse = function(str){
  1445. if ('string' !== typeof str) return {};
  1446. str = trim(str);
  1447. if ('' === str) return {};
  1448. if ('?' === str.charAt(0)) str = str.slice(1);
  1449. var obj = {};
  1450. var pairs = str.split('&');
  1451. for (var i = 0; i < pairs.length; i++) {
  1452. var parts = pairs[i].split('=');
  1453. var key = decode(parts[0]);
  1454. var m, ctx, prop;
  1455. if (m = arrayRegex.exec(key)) {
  1456. obj[m[1]] = obj[m[1]] || [];
  1457. obj[m[1]][m[2]] = decode(parts[1]);
  1458. continue;
  1459. }
  1460. if (m = objectRegex.test(key)) {
  1461. m = key.split('.');
  1462. ctx = obj;
  1463. while (m.length) {
  1464. prop = m.shift();
  1465. if (!prop.length) continue;
  1466. if (!ctx[prop]) {
  1467. ctx[prop] = {};
  1468. } else if (ctx[prop] && typeof ctx[prop] !== 'object') {
  1469. break;
  1470. }
  1471. if (!m.length) {
  1472. ctx[prop] = decode(parts[1]);
  1473. }
  1474. ctx = ctx[prop];
  1475. }
  1476. continue;
  1477. }
  1478. obj[parts[0]] = null == parts[1] ? '' : decode(parts[1]);
  1479. }
  1480. return obj;
  1481. };
  1482. /**
  1483. * Stringify the given `obj`.
  1484. *
  1485. * @param {Object} obj
  1486. * @return {String}
  1487. * @api public
  1488. */
  1489. exports.stringify = function(obj){
  1490. if (!obj) return '';
  1491. var pairs = [];
  1492. for (var key in obj) {
  1493. var value = obj[key];
  1494. if ('array' == type(value)) {
  1495. for (var i = 0; i < value.length; ++i) {
  1496. pairs.push(encode(key + '[' + i + ']') + '=' + encode(value[i]));
  1497. }
  1498. continue;
  1499. }
  1500. pairs.push(encode(key) + '=' + encode(obj[key]));
  1501. }
  1502. return pairs.join('&');
  1503. };
  1504. /***/ }),
  1505. /* 4 */
  1506. /***/ (function(module, exports) {
  1507. exports = module.exports = trim;
  1508. function trim(str){
  1509. return str.replace(/^\s*|\s*$/g, '');
  1510. }
  1511. exports.left = function(str){
  1512. return str.replace(/^\s*/, '');
  1513. };
  1514. exports.right = function(str){
  1515. return str.replace(/\s*$/, '');
  1516. };
  1517. /***/ }),
  1518. /* 5 */
  1519. /***/ (function(module, exports) {
  1520. /**
  1521. * toString ref.
  1522. */
  1523. var toString = Object.prototype.toString;
  1524. /**
  1525. * Return the type of `val`.
  1526. *
  1527. * @param {Mixed} val
  1528. * @return {String}
  1529. * @api public
  1530. */
  1531. module.exports = function(val){
  1532. switch (toString.call(val)) {
  1533. case '[object Date]': return 'date';
  1534. case '[object RegExp]': return 'regexp';
  1535. case '[object Arguments]': return 'arguments';
  1536. case '[object Array]': return 'array';
  1537. case '[object Error]': return 'error';
  1538. }
  1539. if (val === null) return 'null';
  1540. if (val === undefined) return 'undefined';
  1541. if (val !== val) return 'nan';
  1542. if (val && val.nodeType === 1) return 'element';
  1543. val = val.valueOf
  1544. ? val.valueOf()
  1545. : Object.prototype.valueOf.apply(val)
  1546. return typeof val;
  1547. };
  1548. /***/ }),
  1549. /* 6 */
  1550. /***/ (function(module, exports) {
  1551. var SceneGraph = function(sceneProperties) {
  1552. var nodeCount = 1;
  1553. //todo: move merge to helpers section
  1554. function merge(parent, child) {
  1555. for (var prop in child) {
  1556. parent[prop] = child[prop];
  1557. }
  1558. return parent;
  1559. }
  1560. var SceneNode = function(name) {
  1561. nodeCount++;
  1562. this.parent = null;
  1563. this.children = {};
  1564. this.id = nodeCount;
  1565. this.name = 'n' + nodeCount;
  1566. if (typeof name !== 'undefined') {
  1567. this.name = name;
  1568. }
  1569. this.x = this.y = this.z = 0;
  1570. this.width = this.height = 0;
  1571. };
  1572. SceneNode.prototype.resize = function(width, height) {
  1573. if (width != null) {
  1574. this.width = width;
  1575. }
  1576. if (height != null) {
  1577. this.height = height;
  1578. }
  1579. };
  1580. SceneNode.prototype.moveTo = function(x, y, z) {
  1581. this.x = x != null ? x : this.x;
  1582. this.y = y != null ? y : this.y;
  1583. this.z = z != null ? z : this.z;
  1584. };
  1585. SceneNode.prototype.add = function(child) {
  1586. var name = child.name;
  1587. if (typeof this.children[name] === 'undefined') {
  1588. this.children[name] = child;
  1589. child.parent = this;
  1590. } else {
  1591. throw 'SceneGraph: child already exists: ' + name;
  1592. }
  1593. };
  1594. var RootNode = function() {
  1595. SceneNode.call(this, 'root');
  1596. this.properties = sceneProperties;
  1597. };
  1598. RootNode.prototype = new SceneNode();
  1599. var Shape = function(name, props) {
  1600. SceneNode.call(this, name);
  1601. this.properties = {
  1602. 'fill': '#000000'
  1603. };
  1604. if (typeof props !== 'undefined') {
  1605. merge(this.properties, props);
  1606. } else if (typeof name !== 'undefined' && typeof name !== 'string') {
  1607. throw 'SceneGraph: invalid node name';
  1608. }
  1609. };
  1610. Shape.prototype = new SceneNode();
  1611. var Group = function() {
  1612. Shape.apply(this, arguments);
  1613. this.type = 'group';
  1614. };
  1615. Group.prototype = new Shape();
  1616. var Rect = function() {
  1617. Shape.apply(this, arguments);
  1618. this.type = 'rect';
  1619. };
  1620. Rect.prototype = new Shape();
  1621. var Text = function(text) {
  1622. Shape.call(this);
  1623. this.type = 'text';
  1624. this.properties.text = text;
  1625. };
  1626. Text.prototype = new Shape();
  1627. var root = new RootNode();
  1628. this.Shape = {
  1629. 'Rect': Rect,
  1630. 'Text': Text,
  1631. 'Group': Group
  1632. };
  1633. this.root = root;
  1634. return this;
  1635. };
  1636. module.exports = SceneGraph;
  1637. /***/ }),
  1638. /* 7 */
  1639. /***/ (function(module, exports) {
  1640. /* WEBPACK VAR INJECTION */(function(global) {/**
  1641. * Shallow object clone and merge
  1642. *
  1643. * @param a Object A
  1644. * @param b Object B
  1645. * @returns {Object} New object with all of A's properties, and all of B's properties, overwriting A's properties
  1646. */
  1647. exports.extend = function(a, b) {
  1648. var c = {};
  1649. for (var x in a) {
  1650. if (Object.prototype.hasOwnProperty.call(a,x)) {
  1651. c[x] = a[x];
  1652. }
  1653. }
  1654. if (b != null) {
  1655. for (var y in b) {
  1656. if (Object.prototype.hasOwnProperty.call(b, y)) {
  1657. c[y] = b[y];
  1658. }
  1659. }
  1660. }
  1661. return c;
  1662. };
  1663. /**
  1664. * Takes a k/v list of CSS properties and returns a rule
  1665. *
  1666. * @param props CSS properties object
  1667. */
  1668. exports.cssProps = function(props) {
  1669. var ret = [];
  1670. for (var p in props) {
  1671. if (Object.prototype.hasOwnProperty.call(props, p)) {
  1672. ret.push(p + ':' + props[p]);
  1673. }
  1674. }
  1675. return ret.join(';');
  1676. };
  1677. /**
  1678. * Encodes HTML entities in a string
  1679. *
  1680. * @param str Input string
  1681. */
  1682. exports.encodeHtmlEntity = function(str) {
  1683. var buf = [];
  1684. var charCode = 0;
  1685. for (var i = str.length - 1; i >= 0; i--) {
  1686. charCode = str.charCodeAt(i);
  1687. if (charCode > 128) {
  1688. buf.unshift(['&#', charCode, ';'].join(''));
  1689. } else {
  1690. buf.unshift(str[i]);
  1691. }
  1692. }
  1693. return buf.join('');
  1694. };
  1695. /**
  1696. * Checks if an image exists
  1697. *
  1698. * @param src URL of image
  1699. * @param callback Callback to call once image status has been found
  1700. */
  1701. exports.imageExists = function(src, callback) {
  1702. var image = new Image();
  1703. image.onerror = function() {
  1704. callback.call(this, false);
  1705. };
  1706. image.onload = function() {
  1707. callback.call(this, true);
  1708. };
  1709. image.src = src;
  1710. };
  1711. /**
  1712. * Decodes HTML entities in a string
  1713. *
  1714. * @param str Input string
  1715. */
  1716. exports.decodeHtmlEntity = function(str) {
  1717. return str.replace(/&#(\d+);/g, function(match, dec) {
  1718. return String.fromCharCode(dec);
  1719. });
  1720. };
  1721. /**
  1722. * Returns an element's dimensions if it's visible, `false` otherwise.
  1723. *
  1724. * @param el DOM element
  1725. */
  1726. exports.dimensionCheck = function(el) {
  1727. var dimensions = {
  1728. height: el.clientHeight,
  1729. width: el.clientWidth
  1730. };
  1731. if (dimensions.height && dimensions.width) {
  1732. return dimensions;
  1733. } else {
  1734. return false;
  1735. }
  1736. };
  1737. /**
  1738. * Returns true if value is truthy or if it is "semantically truthy"
  1739. * @param val
  1740. */
  1741. exports.truthy = function(val) {
  1742. if (typeof val === 'string') {
  1743. return val === 'true' || val === 'yes' || val === '1' || val === 'on' || val === '✓';
  1744. }
  1745. return !!val;
  1746. };
  1747. /**
  1748. * Parses input into a well-formed CSS color
  1749. * @param val
  1750. */
  1751. exports.parseColor = function(val) {
  1752. var hexre = /(^(?:#?)[0-9a-f]{6}$)|(^(?:#?)[0-9a-f]{3}$)/i;
  1753. var rgbre = /^rgb\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/;
  1754. var rgbare = /^rgba\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0*\.\d{1,}|1)\)$/;
  1755. var match = val.match(hexre);
  1756. var retval;
  1757. if (match !== null) {
  1758. retval = match[1] || match[2];
  1759. if (retval[0] !== '#') {
  1760. return '#' + retval;
  1761. } else {
  1762. return retval;
  1763. }
  1764. }
  1765. match = val.match(rgbre);
  1766. if (match !== null) {
  1767. retval = 'rgb(' + match.slice(1).join(',') + ')';
  1768. return retval;
  1769. }
  1770. match = val.match(rgbare);
  1771. if (match !== null) {
  1772. var normalizeAlpha = function (a) { return '0.' + a.split('.')[1]; };
  1773. var fixedMatch = match.slice(1).map(function (e, i) {
  1774. return (i === 3) ? normalizeAlpha(e) : e;
  1775. });
  1776. retval = 'rgba(' + fixedMatch.join(',') + ')';
  1777. return retval;
  1778. }
  1779. return null;
  1780. };
  1781. /**
  1782. * Provides the correct scaling ratio for canvas drawing operations on HiDPI screens (e.g. Retina displays)
  1783. */
  1784. exports.canvasRatio = function () {
  1785. var devicePixelRatio = 1;
  1786. var backingStoreRatio = 1;
  1787. if (global.document) {
  1788. var canvas = global.document.createElement('canvas');
  1789. if (canvas.getContext) {
  1790. var ctx = canvas.getContext('2d');
  1791. devicePixelRatio = global.devicePixelRatio || 1;
  1792. backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  1793. }
  1794. }
  1795. return devicePixelRatio / backingStoreRatio;
  1796. };
  1797. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  1798. /***/ }),
  1799. /* 8 */
  1800. /***/ (function(module, exports, __webpack_require__) {
  1801. /* WEBPACK VAR INJECTION */(function(global) {var DOM = __webpack_require__(9);
  1802. var SVG_NS = 'http://www.w3.org/2000/svg';
  1803. var NODE_TYPE_COMMENT = 8;
  1804. /**
  1805. * Generic SVG element creation function
  1806. *
  1807. * @param svg SVG context, set to null if new
  1808. * @param width Document width
  1809. * @param height Document height
  1810. */
  1811. exports.initSVG = function(svg, width, height) {
  1812. var defs, style, initialize = false;
  1813. if (svg && svg.querySelector) {
  1814. style = svg.querySelector('style');
  1815. if (style === null) {
  1816. initialize = true;
  1817. }
  1818. } else {
  1819. svg = DOM.newEl('svg', SVG_NS);
  1820. initialize = true;
  1821. }
  1822. if (initialize) {
  1823. defs = DOM.newEl('defs', SVG_NS);
  1824. style = DOM.newEl('style', SVG_NS);
  1825. DOM.setAttr(style, {
  1826. 'type': 'text/css'
  1827. });
  1828. defs.appendChild(style);
  1829. svg.appendChild(defs);
  1830. }
  1831. //IE throws an exception if this is set and Chrome requires it to be set
  1832. if (svg.webkitMatchesSelector) {
  1833. svg.setAttribute('xmlns', SVG_NS);
  1834. }
  1835. //Remove comment nodes
  1836. for (var i = 0; i < svg.childNodes.length; i++) {
  1837. if (svg.childNodes[i].nodeType === NODE_TYPE_COMMENT) {
  1838. svg.removeChild(svg.childNodes[i]);
  1839. }
  1840. }
  1841. //Remove CSS
  1842. while (style.childNodes.length) {
  1843. style.removeChild(style.childNodes[0]);
  1844. }
  1845. DOM.setAttr(svg, {
  1846. 'width': width,
  1847. 'height': height,
  1848. 'viewBox': '0 0 ' + width + ' ' + height,
  1849. 'preserveAspectRatio': 'none'
  1850. });
  1851. return svg;
  1852. };
  1853. /**
  1854. * Converts serialized SVG to a string suitable for data URI use
  1855. * @param svgString Serialized SVG string
  1856. * @param [base64] Use base64 encoding for data URI
  1857. */
  1858. exports.svgStringToDataURI = function() {
  1859. var rawPrefix = 'data:image/svg+xml;charset=UTF-8,';
  1860. var base64Prefix = 'data:image/svg+xml;charset=UTF-8;base64,';
  1861. return function(svgString, base64) {
  1862. if (base64) {
  1863. return base64Prefix + btoa(global.unescape(encodeURIComponent(svgString)));
  1864. } else {
  1865. return rawPrefix + encodeURIComponent(svgString);
  1866. }
  1867. };
  1868. }();
  1869. /**
  1870. * Returns serialized SVG with XML processing instructions
  1871. *
  1872. * @param svg SVG context
  1873. * @param stylesheets CSS stylesheets to include
  1874. */
  1875. exports.serializeSVG = function(svg, engineSettings) {
  1876. if (!global.XMLSerializer) return;
  1877. var serializer = new XMLSerializer();
  1878. var svgCSS = '';
  1879. var stylesheets = engineSettings.stylesheets;
  1880. //External stylesheets: Processing Instruction method
  1881. if (engineSettings.svgXMLStylesheet) {
  1882. var xml = DOM.createXML();
  1883. //Add <?xml-stylesheet ?> directives
  1884. for (var i = stylesheets.length - 1; i >= 0; i--) {
  1885. var csspi = xml.createProcessingInstruction('xml-stylesheet', 'href="' + stylesheets[i] + '" rel="stylesheet"');
  1886. xml.insertBefore(csspi, xml.firstChild);
  1887. }
  1888. xml.removeChild(xml.documentElement);
  1889. svgCSS = serializer.serializeToString(xml);
  1890. }
  1891. var svgText = serializer.serializeToString(svg);
  1892. svgText = svgText.replace(/&amp;(#[0-9]{2,};)/g, '&$1');
  1893. return svgCSS + svgText;
  1894. };
  1895. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  1896. /***/ }),
  1897. /* 9 */
  1898. /***/ (function(module, exports) {
  1899. /* WEBPACK VAR INJECTION */(function(global) {/**
  1900. * Generic new DOM element function
  1901. *
  1902. * @param tag Tag to create
  1903. * @param namespace Optional namespace value
  1904. */
  1905. exports.newEl = function(tag, namespace) {
  1906. if (!global.document) return;
  1907. if (namespace == null) {
  1908. return global.document.createElement(tag);
  1909. } else {
  1910. return global.document.createElementNS(namespace, tag);
  1911. }
  1912. };
  1913. /**
  1914. * Generic setAttribute function
  1915. *
  1916. * @param el Reference to DOM element
  1917. * @param attrs Object with attribute keys and values
  1918. */
  1919. exports.setAttr = function (el, attrs) {
  1920. for (var a in attrs) {
  1921. el.setAttribute(a, attrs[a]);
  1922. }
  1923. };
  1924. /**
  1925. * Creates a XML document
  1926. * @private
  1927. */
  1928. exports.createXML = function() {
  1929. if (!global.DOMParser) return;
  1930. return new DOMParser().parseFromString('<xml />', 'application/xml');
  1931. };
  1932. /**
  1933. * Converts a value into an array of DOM nodes
  1934. *
  1935. * @param val A string, a NodeList, a Node, or an HTMLCollection
  1936. */
  1937. exports.getNodeArray = function(val) {
  1938. var retval = null;
  1939. if (typeof(val) == 'string') {
  1940. retval = document.querySelectorAll(val);
  1941. } else if (global.NodeList && val instanceof global.NodeList) {
  1942. retval = val;
  1943. } else if (global.Node && val instanceof global.Node) {
  1944. retval = [val];
  1945. } else if (global.HTMLCollection && val instanceof global.HTMLCollection) {
  1946. retval = val;
  1947. } else if (val instanceof Array) {
  1948. retval = val;
  1949. } else if (val === null) {
  1950. retval = [];
  1951. }
  1952. retval = Array.prototype.slice.call(retval);
  1953. return retval;
  1954. };
  1955. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  1956. /***/ }),
  1957. /* 10 */
  1958. /***/ (function(module, exports) {
  1959. var Color = function(color, options) {
  1960. //todo: support rgba, hsla, and rrggbbaa notation
  1961. //todo: use CIELAB internally
  1962. //todo: add clamp function (with sign)
  1963. if (typeof color !== 'string') return;
  1964. this.original = color;
  1965. if (color.charAt(0) === '#') {
  1966. color = color.slice(1);
  1967. }
  1968. if (/[^a-f0-9]+/i.test(color)) return;
  1969. if (color.length === 3) {
  1970. color = color.replace(/./g, '$&$&');
  1971. }
  1972. if (color.length !== 6) return;
  1973. this.alpha = 1;
  1974. if (options && options.alpha) {
  1975. this.alpha = options.alpha;
  1976. }
  1977. this.set(parseInt(color, 16));
  1978. };
  1979. //todo: jsdocs
  1980. Color.rgb2hex = function(r, g, b) {
  1981. function format (decimal) {
  1982. var hex = (decimal | 0).toString(16);
  1983. if (decimal < 16) {
  1984. hex = '0' + hex;
  1985. }
  1986. return hex;
  1987. }
  1988. return [r, g, b].map(format).join('');
  1989. };
  1990. //todo: jsdocs
  1991. Color.hsl2rgb = function (h, s, l) {
  1992. var H = h / 60;
  1993. var C = (1 - Math.abs(2 * l - 1)) * s;
  1994. var X = C * (1 - Math.abs(parseInt(H) % 2 - 1));
  1995. var m = l - (C / 2);
  1996. var r = 0, g = 0, b = 0;
  1997. if (H >= 0 && H < 1) {
  1998. r = C;
  1999. g = X;
  2000. } else if (H >= 1 && H < 2) {
  2001. r = X;
  2002. g = C;
  2003. } else if (H >= 2 && H < 3) {
  2004. g = C;
  2005. b = X;
  2006. } else if (H >= 3 && H < 4) {
  2007. g = X;
  2008. b = C;
  2009. } else if (H >= 4 && H < 5) {
  2010. r = X;
  2011. b = C;
  2012. } else if (H >= 5 && H < 6) {
  2013. r = C;
  2014. b = X;
  2015. }
  2016. r += m;
  2017. g += m;
  2018. b += m;
  2019. r = parseInt(r * 255);
  2020. g = parseInt(g * 255);
  2021. b = parseInt(b * 255);
  2022. return [r, g, b];
  2023. };
  2024. /**
  2025. * Sets the color from a raw RGB888 integer
  2026. * @param raw RGB888 representation of color
  2027. */
  2028. //todo: refactor into a static method
  2029. //todo: factor out individual color spaces
  2030. //todo: add HSL, CIELAB, and CIELUV
  2031. Color.prototype.set = function (val) {
  2032. this.raw = val;
  2033. var r = (this.raw & 0xFF0000) >> 16;
  2034. var g = (this.raw & 0x00FF00) >> 8;
  2035. var b = (this.raw & 0x0000FF);
  2036. // BT.709
  2037. var y = 0.2126 * r + 0.7152 * g + 0.0722 * b;
  2038. var u = -0.09991 * r - 0.33609 * g + 0.436 * b;
  2039. var v = 0.615 * r - 0.55861 * g - 0.05639 * b;
  2040. this.rgb = {
  2041. r: r,
  2042. g: g,
  2043. b: b
  2044. };
  2045. this.yuv = {
  2046. y: y,
  2047. u: u,
  2048. v: v
  2049. };
  2050. return this;
  2051. };
  2052. /**
  2053. * Lighten or darken a color
  2054. * @param multiplier Amount to lighten or darken (-1 to 1)
  2055. */
  2056. Color.prototype.lighten = function(multiplier) {
  2057. var cm = Math.min(1, Math.max(0, Math.abs(multiplier))) * (multiplier < 0 ? -1 : 1);
  2058. var bm = (255 * cm) | 0;
  2059. var cr = Math.min(255, Math.max(0, this.rgb.r + bm));
  2060. var cg = Math.min(255, Math.max(0, this.rgb.g + bm));
  2061. var cb = Math.min(255, Math.max(0, this.rgb.b + bm));
  2062. var hex = Color.rgb2hex(cr, cg, cb);
  2063. return new Color(hex);
  2064. };
  2065. /**
  2066. * Output color in hex format
  2067. * @param addHash Add a hash character to the beginning of the output
  2068. */
  2069. Color.prototype.toHex = function(addHash) {
  2070. return (addHash ? '#' : '') + this.raw.toString(16);
  2071. };
  2072. /**
  2073. * Returns whether or not current color is lighter than another color
  2074. * @param color Color to compare against
  2075. */
  2076. Color.prototype.lighterThan = function(color) {
  2077. if (!(color instanceof Color)) {
  2078. color = new Color(color);
  2079. }
  2080. return this.yuv.y > color.yuv.y;
  2081. };
  2082. /**
  2083. * Returns the result of mixing current color with another color
  2084. * @param color Color to mix with
  2085. * @param multiplier How much to mix with the other color
  2086. */
  2087. /*
  2088. Color.prototype.mix = function (color, multiplier) {
  2089. if (!(color instanceof Color)) {
  2090. color = new Color(color);
  2091. }
  2092. var r = this.rgb.r;
  2093. var g = this.rgb.g;
  2094. var b = this.rgb.b;
  2095. var a = this.alpha;
  2096. var m = typeof multiplier !== 'undefined' ? multiplier : 0.5;
  2097. //todo: write a lerp function
  2098. r = r + m * (color.rgb.r - r);
  2099. g = g + m * (color.rgb.g - g);
  2100. b = b + m * (color.rgb.b - b);
  2101. a = a + m * (color.alpha - a);
  2102. return new Color(Color.rgbToHex(r, g, b), {
  2103. 'alpha': a
  2104. });
  2105. };
  2106. */
  2107. /**
  2108. * Returns the result of blending another color on top of current color with alpha
  2109. * @param color Color to blend on top of current color, i.e. "Ca"
  2110. */
  2111. //todo: see if .blendAlpha can be merged into .mix
  2112. Color.prototype.blendAlpha = function(color) {
  2113. if (!(color instanceof Color)) {
  2114. color = new Color(color);
  2115. }
  2116. var Ca = color;
  2117. var Cb = this;
  2118. //todo: write alpha blending function
  2119. var r = Ca.alpha * Ca.rgb.r + (1 - Ca.alpha) * Cb.rgb.r;
  2120. var g = Ca.alpha * Ca.rgb.g + (1 - Ca.alpha) * Cb.rgb.g;
  2121. var b = Ca.alpha * Ca.rgb.b + (1 - Ca.alpha) * Cb.rgb.b;
  2122. return new Color(Color.rgb2hex(r, g, b));
  2123. };
  2124. module.exports = Color;
  2125. /***/ }),
  2126. /* 11 */
  2127. /***/ (function(module, exports) {
  2128. module.exports = {
  2129. 'version': '2.9.9',
  2130. 'svg_ns': 'http://www.w3.org/2000/svg'
  2131. };
  2132. /***/ }),
  2133. /* 12 */
  2134. /***/ (function(module, exports, __webpack_require__) {
  2135. var shaven = __webpack_require__(13).default;
  2136. var SVG = __webpack_require__(8);
  2137. var constants = __webpack_require__(11);
  2138. var utils = __webpack_require__(7);
  2139. var SVG_NS = constants.svg_ns;
  2140. var templates = {
  2141. 'element': function (options) {
  2142. var tag = options.tag;
  2143. var content = options.content || '';
  2144. delete options.tag;
  2145. delete options.content;
  2146. return [tag, content, options];
  2147. }
  2148. };
  2149. //todo: deprecate tag arg, infer tag from shape object
  2150. function convertShape (shape, tag) {
  2151. return templates.element({
  2152. 'tag': tag,
  2153. 'width': shape.width,
  2154. 'height': shape.height,
  2155. 'fill': shape.properties.fill
  2156. });
  2157. }
  2158. function textCss (properties) {
  2159. return utils.cssProps({
  2160. 'fill': properties.fill,
  2161. 'font-weight': properties.font.weight,
  2162. 'font-family': properties.font.family + ', monospace',
  2163. 'font-size': properties.font.size + properties.font.units
  2164. });
  2165. }
  2166. function outlinePath (bgWidth, bgHeight, outlineWidth) {
  2167. var outlineOffsetWidth = outlineWidth / 2;
  2168. return [
  2169. 'M', outlineOffsetWidth, outlineOffsetWidth,
  2170. 'H', bgWidth - outlineOffsetWidth,
  2171. 'V', bgHeight - outlineOffsetWidth,
  2172. 'H', outlineOffsetWidth,
  2173. 'V', 0,
  2174. 'M', 0, outlineOffsetWidth,
  2175. 'L', bgWidth, bgHeight - outlineOffsetWidth,
  2176. 'M', 0, bgHeight - outlineOffsetWidth,
  2177. 'L', bgWidth, outlineOffsetWidth
  2178. ].join(' ');
  2179. }
  2180. module.exports = function (sceneGraph, renderSettings) {
  2181. var engineSettings = renderSettings.engineSettings;
  2182. var stylesheets = engineSettings.stylesheets;
  2183. var stylesheetXml = stylesheets.map(function (stylesheet) {
  2184. return '<?xml-stylesheet rel="stylesheet" href="' + stylesheet + '"?>';
  2185. }).join('\n');
  2186. var holderId = 'holder_' + Number(new Date()).toString(16);
  2187. var root = sceneGraph.root;
  2188. var textGroup = root.children.holderTextGroup;
  2189. var css = '#' + holderId + ' text { ' + textCss(textGroup.properties) + ' } ';
  2190. // push text down to be equally vertically aligned with canvas renderer
  2191. textGroup.y += textGroup.textPositionData.boundingBox.height * 0.8;
  2192. var wordTags = [];
  2193. Object.keys(textGroup.children).forEach(function (lineKey) {
  2194. var line = textGroup.children[lineKey];
  2195. Object.keys(line.children).forEach(function (wordKey) {
  2196. var word = line.children[wordKey];
  2197. var x = textGroup.x + line.x + word.x;
  2198. var y = textGroup.y + line.y + word.y;
  2199. var wordTag = templates.element({
  2200. 'tag': 'text',
  2201. 'content': word.properties.text,
  2202. 'x': x,
  2203. 'y': y
  2204. });
  2205. wordTags.push(wordTag);
  2206. });
  2207. });
  2208. var text = templates.element({
  2209. 'tag': 'g',
  2210. 'content': wordTags
  2211. });
  2212. var outline = null;
  2213. if (root.children.holderBg.properties.outline) {
  2214. var outlineProperties = root.children.holderBg.properties.outline;
  2215. outline = templates.element({
  2216. 'tag': 'path',
  2217. 'd': outlinePath(root.children.holderBg.width, root.children.holderBg.height, outlineProperties.width),
  2218. 'stroke-width': outlineProperties.width,
  2219. 'stroke': outlineProperties.fill,
  2220. 'fill': 'none'
  2221. });
  2222. }
  2223. var bg = convertShape(root.children.holderBg, 'rect');
  2224. var sceneContent = [];
  2225. sceneContent.push(bg);
  2226. if (outlineProperties) {
  2227. sceneContent.push(outline);
  2228. }
  2229. sceneContent.push(text);
  2230. var scene = templates.element({
  2231. 'tag': 'g',
  2232. 'id': holderId,
  2233. 'content': sceneContent
  2234. });
  2235. var style = templates.element({
  2236. 'tag': 'style',
  2237. //todo: figure out how to add CDATA directive
  2238. 'content': css,
  2239. 'type': 'text/css'
  2240. });
  2241. var defs = templates.element({
  2242. 'tag': 'defs',
  2243. 'content': style
  2244. });
  2245. var svg = templates.element({
  2246. 'tag': 'svg',
  2247. 'content': [defs, scene],
  2248. 'width': root.properties.width,
  2249. 'height': root.properties.height,
  2250. 'xmlns': SVG_NS,
  2251. 'viewBox': [0, 0, root.properties.width, root.properties.height].join(' '),
  2252. 'preserveAspectRatio': 'none'
  2253. });
  2254. var output = String(shaven(svg));
  2255. if (/&amp;(x)?#[0-9A-Fa-f]/.test(output[0])) {
  2256. output = output.replace(/&amp;#/gm, '&#');
  2257. }
  2258. output = stylesheetXml + output;
  2259. var svgString = SVG.svgStringToDataURI(output, renderSettings.mode === 'background');
  2260. return svgString;
  2261. };
  2262. /***/ }),
  2263. /* 13 */
  2264. /***/ (function(module, exports, __webpack_require__) {
  2265. // vendored shaven 1.3.0 due to published package.json including an outdated node engine
  2266. module.exports = __webpack_require__(14);
  2267. /***/ }),
  2268. /* 14 */
  2269. /***/ (function(module, exports, __webpack_require__) {
  2270. 'use strict';
  2271. Object.defineProperty(exports, "__esModule", {
  2272. value: true
  2273. });
  2274. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2275. exports.default = shaven;
  2276. var _parseSugarString = __webpack_require__(15);
  2277. var _parseSugarString2 = _interopRequireDefault(_parseSugarString);
  2278. var _escape = __webpack_require__(16);
  2279. var escape = _interopRequireWildcard(_escape);
  2280. var _defaults = __webpack_require__(17);
  2281. var _defaults2 = _interopRequireDefault(_defaults);
  2282. var _mapAttributeValue = __webpack_require__(18);
  2283. var _mapAttributeValue2 = _interopRequireDefault(_mapAttributeValue);
  2284. var _assert = __webpack_require__(21);
  2285. var _assert2 = _interopRequireDefault(_assert);
  2286. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  2287. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  2288. function shaven(arrayOrObject) {
  2289. var isArray = Array.isArray(arrayOrObject);
  2290. var objType = typeof arrayOrObject === 'undefined' ? 'undefined' : _typeof(arrayOrObject);
  2291. if (!isArray && objType !== 'object') {
  2292. throw new Error('Argument must be either an array or an object ' + 'and not ' + JSON.stringify(arrayOrObject));
  2293. }
  2294. if (isArray && arrayOrObject.length === 0) {
  2295. // Ignore empty arrays
  2296. return {};
  2297. }
  2298. var config = {};
  2299. var elementArray = [];
  2300. if (Array.isArray(arrayOrObject)) {
  2301. elementArray = arrayOrObject.slice(0);
  2302. } else {
  2303. elementArray = arrayOrObject.elementArray.slice(0);
  2304. config = Object.assign(config, arrayOrObject);
  2305. delete config.elementArray;
  2306. }
  2307. config = Object.assign({}, _defaults2.default, config, {
  2308. returnObject: { // Shaven object to return at last
  2309. ids: {},
  2310. references: {}
  2311. }
  2312. });
  2313. function createElement(sugarString) {
  2314. var properties = (0, _parseSugarString2.default)(sugarString);
  2315. var element = {
  2316. tag: properties.tag,
  2317. attr: {},
  2318. children: []
  2319. };
  2320. if (properties.id) {
  2321. element.attr.id = properties.id;
  2322. (0, _assert2.default)(!config.returnObject.ids.hasOwnProperty(properties.id), 'Ids must be unique and "' + properties.id + '" is already assigned');
  2323. config.returnObject.ids[properties.id] = element;
  2324. }
  2325. if (properties.class) {
  2326. element.attr.class = properties.class;
  2327. }
  2328. if (properties.reference) {
  2329. (0, _assert2.default)(!config.returnObject.ids.hasOwnProperty(properties.reference), 'References must be unique and "' + properties.id + '" is already assigned');
  2330. config.returnObject.references[properties.reference] = element;
  2331. }
  2332. config.escapeHTML = properties.escapeHTML != null ? properties.escapeHTML : config.escapeHTML;
  2333. return element;
  2334. }
  2335. function buildDom(elemArray) {
  2336. if (Array.isArray(elemArray) && elemArray.length === 0) {
  2337. // Ignore empty arrays
  2338. return {};
  2339. }
  2340. var index = 1;
  2341. var createdCallback = void 0;
  2342. var selfClosingHTMLTags = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'];
  2343. // Clone to avoid mutation problems
  2344. var array = elemArray.slice(0);
  2345. if (typeof array[0] === 'string') {
  2346. array[0] = createElement(array[0]);
  2347. } else if (Array.isArray(array[0])) {
  2348. index = 0;
  2349. } else {
  2350. throw new Error('First element of array must be a string, ' + 'or an array and not ' + JSON.stringify(array[0]));
  2351. }
  2352. for (; index < array.length; index++) {
  2353. // Don't render element if value is false or null
  2354. if (array[index] === false || array[index] === null) {
  2355. array[0] = false;
  2356. break;
  2357. }
  2358. // Continue with next array value if current value is undefined or true
  2359. else if (array[index] === undefined || array[index] === true) {
  2360. continue;
  2361. } else if (typeof array[index] === 'string') {
  2362. if (config.escapeHTML) {
  2363. // eslint-disable-next-line new-cap
  2364. array[index] = escape.HTML(array[index]);
  2365. }
  2366. array[0].children.push(array[index]);
  2367. } else if (typeof array[index] === 'number') {
  2368. array[0].children.push(array[index]);
  2369. } else if (Array.isArray(array[index])) {
  2370. if (Array.isArray(array[index][0])) {
  2371. array[index].reverse().forEach(function (subArray) {
  2372. // eslint-disable-line no-loop-func
  2373. array.splice(index + 1, 0, subArray);
  2374. });
  2375. if (index !== 0) continue;
  2376. index++;
  2377. }
  2378. array[index] = buildDom(array[index]);
  2379. if (array[index][0]) {
  2380. array[0].children.push(array[index][0]);
  2381. }
  2382. } else if (typeof array[index] === 'function') {
  2383. createdCallback = array[index];
  2384. } else if (_typeof(array[index]) === 'object') {
  2385. for (var attributeKey in array[index]) {
  2386. if (!array[index].hasOwnProperty(attributeKey)) continue;
  2387. var attributeValue = array[index][attributeKey];
  2388. if (array[index].hasOwnProperty(attributeKey) && attributeValue !== null && attributeValue !== false) {
  2389. array[0].attr[attributeKey] = (0, _mapAttributeValue2.default)(attributeKey, attributeValue);
  2390. }
  2391. }
  2392. } else {
  2393. throw new TypeError('"' + array[index] + '" is not allowed as a value');
  2394. }
  2395. }
  2396. if (array[0] !== false) {
  2397. var HTMLString = '<' + array[0].tag;
  2398. for (var key in array[0].attr) {
  2399. if (array[0].attr.hasOwnProperty(key)) {
  2400. var _attributeValue = escape.attribute(array[0].attr[key]);
  2401. var value = _attributeValue;
  2402. if (config.quoteAttributes || /[ "'=<>]/.test(_attributeValue)) {
  2403. value = config.quotationMark + _attributeValue + config.quotationMark;
  2404. }
  2405. HTMLString += ' ' + key + '=' + value;
  2406. }
  2407. }
  2408. HTMLString += '>';
  2409. if (!(selfClosingHTMLTags.indexOf(array[0].tag) !== -1)) {
  2410. array[0].children.forEach(function (child) {
  2411. return HTMLString += child;
  2412. });
  2413. HTMLString += '</' + array[0].tag + '>';
  2414. }
  2415. array[0] = HTMLString;
  2416. }
  2417. // Return root element on index 0
  2418. config.returnObject[0] = array[0];
  2419. config.returnObject.rootElement = array[0];
  2420. config.returnObject.toString = function () {
  2421. return array[0];
  2422. };
  2423. if (createdCallback) createdCallback(array[0]);
  2424. return config.returnObject;
  2425. }
  2426. return buildDom(elementArray);
  2427. }
  2428. shaven.setDefaults = function (object) {
  2429. Object.assign(_defaults2.default, object);
  2430. return shaven;
  2431. };
  2432. /***/ }),
  2433. /* 15 */
  2434. /***/ (function(module, exports) {
  2435. 'use strict';
  2436. Object.defineProperty(exports, "__esModule", {
  2437. value: true
  2438. });
  2439. exports.default = function (sugarString) {
  2440. var tags = sugarString.match(/^[\w-]+/);
  2441. var properties = {
  2442. tag: tags ? tags[0] : 'div'
  2443. };
  2444. var ids = sugarString.match(/#([\w-]+)/);
  2445. var classes = sugarString.match(/\.[\w-]+/g);
  2446. var references = sugarString.match(/\$([\w-]+)/);
  2447. if (ids) properties.id = ids[1];
  2448. if (classes) {
  2449. properties.class = classes.join(' ').replace(/\./g, '');
  2450. }
  2451. if (references) properties.reference = references[1];
  2452. if (sugarString.endsWith('&') || sugarString.endsWith('!')) {
  2453. properties.escapeHTML = false;
  2454. }
  2455. return properties;
  2456. };
  2457. /***/ }),
  2458. /* 16 */
  2459. /***/ (function(module, exports) {
  2460. 'use strict';
  2461. Object.defineProperty(exports, "__esModule", {
  2462. value: true
  2463. });
  2464. exports.attribute = attribute;
  2465. exports.HTML = HTML;
  2466. function attribute(string) {
  2467. return string || string === 0 ? String(string).replace(/&/g, '&amp;').replace(/"/g, '&quot;') : '';
  2468. }
  2469. function HTML(string) {
  2470. return String(string).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&apos;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  2471. }
  2472. /***/ }),
  2473. /* 17 */
  2474. /***/ (function(module, exports) {
  2475. 'use strict';
  2476. Object.defineProperty(exports, "__esModule", {
  2477. value: true
  2478. });
  2479. exports.default = {
  2480. namespace: 'xhtml',
  2481. autoNamespacing: true,
  2482. escapeHTML: true,
  2483. quotationMark: '"',
  2484. quoteAttributes: true,
  2485. convertTransformArray: true
  2486. };
  2487. /***/ }),
  2488. /* 18 */
  2489. /***/ (function(module, exports, __webpack_require__) {
  2490. 'use strict';
  2491. Object.defineProperty(exports, "__esModule", {
  2492. value: true
  2493. });
  2494. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2495. var _buildTransformString = __webpack_require__(19);
  2496. var _buildTransformString2 = _interopRequireDefault(_buildTransformString);
  2497. var _stringifyStyleObject = __webpack_require__(20);
  2498. var _stringifyStyleObject2 = _interopRequireDefault(_stringifyStyleObject);
  2499. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  2500. exports.default = function (key, value) {
  2501. if (value === undefined) {
  2502. return '';
  2503. }
  2504. if (key === 'style' && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
  2505. return (0, _stringifyStyleObject2.default)(value);
  2506. }
  2507. if (key === 'transform' && Array.isArray(value)) {
  2508. return (0, _buildTransformString2.default)(value);
  2509. }
  2510. return value;
  2511. };
  2512. /***/ }),
  2513. /* 19 */
  2514. /***/ (function(module, exports) {
  2515. 'use strict';
  2516. Object.defineProperty(exports, "__esModule", {
  2517. value: true
  2518. });
  2519. // Create transform string from list transform objects
  2520. exports.default = function (transformObjects) {
  2521. return transformObjects.map(function (transformation) {
  2522. var values = [];
  2523. if (transformation.type === 'rotate' && transformation.degrees) {
  2524. values.push(transformation.degrees);
  2525. }
  2526. if (transformation.x) values.push(transformation.x);
  2527. if (transformation.y) values.push(transformation.y);
  2528. return transformation.type + '(' + values + ')';
  2529. }).join(' ');
  2530. };
  2531. /***/ }),
  2532. /* 20 */
  2533. /***/ (function(module, exports) {
  2534. 'use strict';
  2535. Object.defineProperty(exports, "__esModule", {
  2536. value: true
  2537. });
  2538. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2539. function sanitizeProperties(key, value) {
  2540. if (value === null || value === false || value === undefined) return;
  2541. if (typeof value === 'string' || (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') return value;
  2542. return String(value);
  2543. }
  2544. exports.default = function (styleObject) {
  2545. return JSON.stringify(styleObject, sanitizeProperties).slice(2, -2).replace(/","/g, ';').replace(/":"/g, ':').replace(/\\"/g, '\'');
  2546. };
  2547. /***/ }),
  2548. /* 21 */
  2549. /***/ (function(module, exports, __webpack_require__) {
  2550. /* WEBPACK VAR INJECTION */(function(global) {'use strict';
  2551. var objectAssign = __webpack_require__(22);
  2552. // compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js
  2553. // original notice:
  2554. /*!
  2555. * The buffer module from node.js, for the browser.
  2556. *
  2557. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  2558. * @license MIT
  2559. */
  2560. function compare(a, b) {
  2561. if (a === b) {
  2562. return 0;
  2563. }
  2564. var x = a.length;
  2565. var y = b.length;
  2566. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  2567. if (a[i] !== b[i]) {
  2568. x = a[i];
  2569. y = b[i];
  2570. break;
  2571. }
  2572. }
  2573. if (x < y) {
  2574. return -1;
  2575. }
  2576. if (y < x) {
  2577. return 1;
  2578. }
  2579. return 0;
  2580. }
  2581. function isBuffer(b) {
  2582. if (global.Buffer && typeof global.Buffer.isBuffer === 'function') {
  2583. return global.Buffer.isBuffer(b);
  2584. }
  2585. return !!(b != null && b._isBuffer);
  2586. }
  2587. // based on node assert, original notice:
  2588. // NB: The URL to the CommonJS spec is kept just for tradition.
  2589. // node-assert has evolved a lot since then, both in API and behavior.
  2590. // http://wiki.commonjs.org/wiki/Unit_Testing/1.0
  2591. //
  2592. // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
  2593. //
  2594. // Originally from narwhal.js (http://narwhaljs.org)
  2595. // Copyright (c) 2009 Thomas Robinson <280north.com>
  2596. //
  2597. // Permission is hereby granted, free of charge, to any person obtaining a copy
  2598. // of this software and associated documentation files (the 'Software'), to
  2599. // deal in the Software without restriction, including without limitation the
  2600. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  2601. // sell copies of the Software, and to permit persons to whom the Software is
  2602. // furnished to do so, subject to the following conditions:
  2603. //
  2604. // The above copyright notice and this permission notice shall be included in
  2605. // all copies or substantial portions of the Software.
  2606. //
  2607. // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2608. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2609. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  2610. // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2611. // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  2612. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  2613. var util = __webpack_require__(23);
  2614. var hasOwn = Object.prototype.hasOwnProperty;
  2615. var pSlice = Array.prototype.slice;
  2616. var functionsHaveNames = (function () {
  2617. return function foo() {}.name === 'foo';
  2618. }());
  2619. function pToString (obj) {
  2620. return Object.prototype.toString.call(obj);
  2621. }
  2622. function isView(arrbuf) {
  2623. if (isBuffer(arrbuf)) {
  2624. return false;
  2625. }
  2626. if (typeof global.ArrayBuffer !== 'function') {
  2627. return false;
  2628. }
  2629. if (typeof ArrayBuffer.isView === 'function') {
  2630. return ArrayBuffer.isView(arrbuf);
  2631. }
  2632. if (!arrbuf) {
  2633. return false;
  2634. }
  2635. if (arrbuf instanceof DataView) {
  2636. return true;
  2637. }
  2638. if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
  2639. return true;
  2640. }
  2641. return false;
  2642. }
  2643. // 1. The assert module provides functions that throw
  2644. // AssertionError's when particular conditions are not met. The
  2645. // assert module must conform to the following interface.
  2646. var assert = module.exports = ok;
  2647. // 2. The AssertionError is defined in assert.
  2648. // new assert.AssertionError({ message: message,
  2649. // actual: actual,
  2650. // expected: expected })
  2651. var regex = /\s*function\s+([^\(\s]*)\s*/;
  2652. // based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js
  2653. function getName(func) {
  2654. if (!util.isFunction(func)) {
  2655. return;
  2656. }
  2657. if (functionsHaveNames) {
  2658. return func.name;
  2659. }
  2660. var str = func.toString();
  2661. var match = str.match(regex);
  2662. return match && match[1];
  2663. }
  2664. assert.AssertionError = function AssertionError(options) {
  2665. this.name = 'AssertionError';
  2666. this.actual = options.actual;
  2667. this.expected = options.expected;
  2668. this.operator = options.operator;
  2669. if (options.message) {
  2670. this.message = options.message;
  2671. this.generatedMessage = false;
  2672. } else {
  2673. this.message = getMessage(this);
  2674. this.generatedMessage = true;
  2675. }
  2676. var stackStartFunction = options.stackStartFunction || fail;
  2677. if (Error.captureStackTrace) {
  2678. Error.captureStackTrace(this, stackStartFunction);
  2679. } else {
  2680. // non v8 browsers so we can have a stacktrace
  2681. var err = new Error();
  2682. if (err.stack) {
  2683. var out = err.stack;
  2684. // try to strip useless frames
  2685. var fn_name = getName(stackStartFunction);
  2686. var idx = out.indexOf('\n' + fn_name);
  2687. if (idx >= 0) {
  2688. // once we have located the function frame
  2689. // we need to strip out everything before it (and its line)
  2690. var next_line = out.indexOf('\n', idx + 1);
  2691. out = out.substring(next_line + 1);
  2692. }
  2693. this.stack = out;
  2694. }
  2695. }
  2696. };
  2697. // assert.AssertionError instanceof Error
  2698. util.inherits(assert.AssertionError, Error);
  2699. function truncate(s, n) {
  2700. if (typeof s === 'string') {
  2701. return s.length < n ? s : s.slice(0, n);
  2702. } else {
  2703. return s;
  2704. }
  2705. }
  2706. function inspect(something) {
  2707. if (functionsHaveNames || !util.isFunction(something)) {
  2708. return util.inspect(something);
  2709. }
  2710. var rawname = getName(something);
  2711. var name = rawname ? ': ' + rawname : '';
  2712. return '[Function' + name + ']';
  2713. }
  2714. function getMessage(self) {
  2715. return truncate(inspect(self.actual), 128) + ' ' +
  2716. self.operator + ' ' +
  2717. truncate(inspect(self.expected), 128);
  2718. }
  2719. // At present only the three keys mentioned above are used and
  2720. // understood by the spec. Implementations or sub modules can pass
  2721. // other keys to the AssertionError's constructor - they will be
  2722. // ignored.
  2723. // 3. All of the following functions must throw an AssertionError
  2724. // when a corresponding condition is not met, with a message that
  2725. // may be undefined if not provided. All assertion methods provide
  2726. // both the actual and expected values to the assertion error for
  2727. // display purposes.
  2728. function fail(actual, expected, message, operator, stackStartFunction) {
  2729. throw new assert.AssertionError({
  2730. message: message,
  2731. actual: actual,
  2732. expected: expected,
  2733. operator: operator,
  2734. stackStartFunction: stackStartFunction
  2735. });
  2736. }
  2737. // EXTENSION! allows for well behaved errors defined elsewhere.
  2738. assert.fail = fail;
  2739. // 4. Pure assertion tests whether a value is truthy, as determined
  2740. // by !!guard.
  2741. // assert.ok(guard, message_opt);
  2742. // This statement is equivalent to assert.equal(true, !!guard,
  2743. // message_opt);. To test strictly for the value true, use
  2744. // assert.strictEqual(true, guard, message_opt);.
  2745. function ok(value, message) {
  2746. if (!value) fail(value, true, message, '==', assert.ok);
  2747. }
  2748. assert.ok = ok;
  2749. // 5. The equality assertion tests shallow, coercive equality with
  2750. // ==.
  2751. // assert.equal(actual, expected, message_opt);
  2752. assert.equal = function equal(actual, expected, message) {
  2753. if (actual != expected) fail(actual, expected, message, '==', assert.equal);
  2754. };
  2755. // 6. The non-equality assertion tests for whether two objects are not equal
  2756. // with != assert.notEqual(actual, expected, message_opt);
  2757. assert.notEqual = function notEqual(actual, expected, message) {
  2758. if (actual == expected) {
  2759. fail(actual, expected, message, '!=', assert.notEqual);
  2760. }
  2761. };
  2762. // 7. The equivalence assertion tests a deep equality relation.
  2763. // assert.deepEqual(actual, expected, message_opt);
  2764. assert.deepEqual = function deepEqual(actual, expected, message) {
  2765. if (!_deepEqual(actual, expected, false)) {
  2766. fail(actual, expected, message, 'deepEqual', assert.deepEqual);
  2767. }
  2768. };
  2769. assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
  2770. if (!_deepEqual(actual, expected, true)) {
  2771. fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual);
  2772. }
  2773. };
  2774. function _deepEqual(actual, expected, strict, memos) {
  2775. // 7.1. All identical values are equivalent, as determined by ===.
  2776. if (actual === expected) {
  2777. return true;
  2778. } else if (isBuffer(actual) && isBuffer(expected)) {
  2779. return compare(actual, expected) === 0;
  2780. // 7.2. If the expected value is a Date object, the actual value is
  2781. // equivalent if it is also a Date object that refers to the same time.
  2782. } else if (util.isDate(actual) && util.isDate(expected)) {
  2783. return actual.getTime() === expected.getTime();
  2784. // 7.3 If the expected value is a RegExp object, the actual value is
  2785. // equivalent if it is also a RegExp object with the same source and
  2786. // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
  2787. } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
  2788. return actual.source === expected.source &&
  2789. actual.global === expected.global &&
  2790. actual.multiline === expected.multiline &&
  2791. actual.lastIndex === expected.lastIndex &&
  2792. actual.ignoreCase === expected.ignoreCase;
  2793. // 7.4. Other pairs that do not both pass typeof value == 'object',
  2794. // equivalence is determined by ==.
  2795. } else if ((actual === null || typeof actual !== 'object') &&
  2796. (expected === null || typeof expected !== 'object')) {
  2797. return strict ? actual === expected : actual == expected;
  2798. // If both values are instances of typed arrays, wrap their underlying
  2799. // ArrayBuffers in a Buffer each to increase performance
  2800. // This optimization requires the arrays to have the same type as checked by
  2801. // Object.prototype.toString (aka pToString). Never perform binary
  2802. // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
  2803. // bit patterns are not identical.
  2804. } else if (isView(actual) && isView(expected) &&
  2805. pToString(actual) === pToString(expected) &&
  2806. !(actual instanceof Float32Array ||
  2807. actual instanceof Float64Array)) {
  2808. return compare(new Uint8Array(actual.buffer),
  2809. new Uint8Array(expected.buffer)) === 0;
  2810. // 7.5 For all other Object pairs, including Array objects, equivalence is
  2811. // determined by having the same number of owned properties (as verified
  2812. // with Object.prototype.hasOwnProperty.call), the same set of keys
  2813. // (although not necessarily the same order), equivalent values for every
  2814. // corresponding key, and an identical 'prototype' property. Note: this
  2815. // accounts for both named and indexed properties on Arrays.
  2816. } else if (isBuffer(actual) !== isBuffer(expected)) {
  2817. return false;
  2818. } else {
  2819. memos = memos || {actual: [], expected: []};
  2820. var actualIndex = memos.actual.indexOf(actual);
  2821. if (actualIndex !== -1) {
  2822. if (actualIndex === memos.expected.indexOf(expected)) {
  2823. return true;
  2824. }
  2825. }
  2826. memos.actual.push(actual);
  2827. memos.expected.push(expected);
  2828. return objEquiv(actual, expected, strict, memos);
  2829. }
  2830. }
  2831. function isArguments(object) {
  2832. return Object.prototype.toString.call(object) == '[object Arguments]';
  2833. }
  2834. function objEquiv(a, b, strict, actualVisitedObjects) {
  2835. if (a === null || a === undefined || b === null || b === undefined)
  2836. return false;
  2837. // if one is a primitive, the other must be same
  2838. if (util.isPrimitive(a) || util.isPrimitive(b))
  2839. return a === b;
  2840. if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
  2841. return false;
  2842. var aIsArgs = isArguments(a);
  2843. var bIsArgs = isArguments(b);
  2844. if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
  2845. return false;
  2846. if (aIsArgs) {
  2847. a = pSlice.call(a);
  2848. b = pSlice.call(b);
  2849. return _deepEqual(a, b, strict);
  2850. }
  2851. var ka = objectKeys(a);
  2852. var kb = objectKeys(b);
  2853. var key, i;
  2854. // having the same number of owned properties (keys incorporates
  2855. // hasOwnProperty)
  2856. if (ka.length !== kb.length)
  2857. return false;
  2858. //the same set of keys (although not necessarily the same order),
  2859. ka.sort();
  2860. kb.sort();
  2861. //~~~cheap key test
  2862. for (i = ka.length - 1; i >= 0; i--) {
  2863. if (ka[i] !== kb[i])
  2864. return false;
  2865. }
  2866. //equivalent values for every corresponding key, and
  2867. //~~~possibly expensive deep test
  2868. for (i = ka.length - 1; i >= 0; i--) {
  2869. key = ka[i];
  2870. if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
  2871. return false;
  2872. }
  2873. return true;
  2874. }
  2875. // 8. The non-equivalence assertion tests for any deep inequality.
  2876. // assert.notDeepEqual(actual, expected, message_opt);
  2877. assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
  2878. if (_deepEqual(actual, expected, false)) {
  2879. fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
  2880. }
  2881. };
  2882. assert.notDeepStrictEqual = notDeepStrictEqual;
  2883. function notDeepStrictEqual(actual, expected, message) {
  2884. if (_deepEqual(actual, expected, true)) {
  2885. fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
  2886. }
  2887. }
  2888. // 9. The strict equality assertion tests strict equality, as determined by ===.
  2889. // assert.strictEqual(actual, expected, message_opt);
  2890. assert.strictEqual = function strictEqual(actual, expected, message) {
  2891. if (actual !== expected) {
  2892. fail(actual, expected, message, '===', assert.strictEqual);
  2893. }
  2894. };
  2895. // 10. The strict non-equality assertion tests for strict inequality, as
  2896. // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
  2897. assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
  2898. if (actual === expected) {
  2899. fail(actual, expected, message, '!==', assert.notStrictEqual);
  2900. }
  2901. };
  2902. function expectedException(actual, expected) {
  2903. if (!actual || !expected) {
  2904. return false;
  2905. }
  2906. if (Object.prototype.toString.call(expected) == '[object RegExp]') {
  2907. return expected.test(actual);
  2908. }
  2909. try {
  2910. if (actual instanceof expected) {
  2911. return true;
  2912. }
  2913. } catch (e) {
  2914. // Ignore. The instanceof check doesn't work for arrow functions.
  2915. }
  2916. if (Error.isPrototypeOf(expected)) {
  2917. return false;
  2918. }
  2919. return expected.call({}, actual) === true;
  2920. }
  2921. function _tryBlock(block) {
  2922. var error;
  2923. try {
  2924. block();
  2925. } catch (e) {
  2926. error = e;
  2927. }
  2928. return error;
  2929. }
  2930. function _throws(shouldThrow, block, expected, message) {
  2931. var actual;
  2932. if (typeof block !== 'function') {
  2933. throw new TypeError('"block" argument must be a function');
  2934. }
  2935. if (typeof expected === 'string') {
  2936. message = expected;
  2937. expected = null;
  2938. }
  2939. actual = _tryBlock(block);
  2940. message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
  2941. (message ? ' ' + message : '.');
  2942. if (shouldThrow && !actual) {
  2943. fail(actual, expected, 'Missing expected exception' + message);
  2944. }
  2945. var userProvidedMessage = typeof message === 'string';
  2946. var isUnwantedException = !shouldThrow && util.isError(actual);
  2947. var isUnexpectedException = !shouldThrow && actual && !expected;
  2948. if ((isUnwantedException &&
  2949. userProvidedMessage &&
  2950. expectedException(actual, expected)) ||
  2951. isUnexpectedException) {
  2952. fail(actual, expected, 'Got unwanted exception' + message);
  2953. }
  2954. if ((shouldThrow && actual && expected &&
  2955. !expectedException(actual, expected)) || (!shouldThrow && actual)) {
  2956. throw actual;
  2957. }
  2958. }
  2959. // 11. Expected to throw an error:
  2960. // assert.throws(block, Error_opt, message_opt);
  2961. assert.throws = function(block, /*optional*/error, /*optional*/message) {
  2962. _throws(true, block, error, message);
  2963. };
  2964. // EXTENSION! This is annoying to write outside this module.
  2965. assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
  2966. _throws(false, block, error, message);
  2967. };
  2968. assert.ifError = function(err) { if (err) throw err; };
  2969. // Expose a strict only variant of assert
  2970. function strict(value, message) {
  2971. if (!value) fail(value, true, message, '==', strict);
  2972. }
  2973. assert.strict = objectAssign(strict, assert, {
  2974. equal: assert.strictEqual,
  2975. deepEqual: assert.deepStrictEqual,
  2976. notEqual: assert.notStrictEqual,
  2977. notDeepEqual: assert.notDeepStrictEqual
  2978. });
  2979. assert.strict.strict = assert.strict;
  2980. var objectKeys = Object.keys || function (obj) {
  2981. var keys = [];
  2982. for (var key in obj) {
  2983. if (hasOwn.call(obj, key)) keys.push(key);
  2984. }
  2985. return keys;
  2986. };
  2987. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  2988. /***/ }),
  2989. /* 22 */
  2990. /***/ (function(module, exports) {
  2991. /*
  2992. object-assign
  2993. (c) Sindre Sorhus
  2994. @license MIT
  2995. */
  2996. 'use strict';
  2997. /* eslint-disable no-unused-vars */
  2998. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  2999. var hasOwnProperty = Object.prototype.hasOwnProperty;
  3000. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  3001. function toObject(val) {
  3002. if (val === null || val === undefined) {
  3003. throw new TypeError('Object.assign cannot be called with null or undefined');
  3004. }
  3005. return Object(val);
  3006. }
  3007. function shouldUseNative() {
  3008. try {
  3009. if (!Object.assign) {
  3010. return false;
  3011. }
  3012. // Detect buggy property enumeration order in older V8 versions.
  3013. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  3014. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  3015. test1[5] = 'de';
  3016. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  3017. return false;
  3018. }
  3019. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  3020. var test2 = {};
  3021. for (var i = 0; i < 10; i++) {
  3022. test2['_' + String.fromCharCode(i)] = i;
  3023. }
  3024. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  3025. return test2[n];
  3026. });
  3027. if (order2.join('') !== '0123456789') {
  3028. return false;
  3029. }
  3030. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  3031. var test3 = {};
  3032. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  3033. test3[letter] = letter;
  3034. });
  3035. if (Object.keys(Object.assign({}, test3)).join('') !==
  3036. 'abcdefghijklmnopqrst') {
  3037. return false;
  3038. }
  3039. return true;
  3040. } catch (err) {
  3041. // We don't expect any of the above to throw, but better to be safe.
  3042. return false;
  3043. }
  3044. }
  3045. module.exports = shouldUseNative() ? Object.assign : function (target, source) {
  3046. var from;
  3047. var to = toObject(target);
  3048. var symbols;
  3049. for (var s = 1; s < arguments.length; s++) {
  3050. from = Object(arguments[s]);
  3051. for (var key in from) {
  3052. if (hasOwnProperty.call(from, key)) {
  3053. to[key] = from[key];
  3054. }
  3055. }
  3056. if (getOwnPropertySymbols) {
  3057. symbols = getOwnPropertySymbols(from);
  3058. for (var i = 0; i < symbols.length; i++) {
  3059. if (propIsEnumerable.call(from, symbols[i])) {
  3060. to[symbols[i]] = from[symbols[i]];
  3061. }
  3062. }
  3063. }
  3064. }
  3065. return to;
  3066. };
  3067. /***/ }),
  3068. /* 23 */
  3069. /***/ (function(module, exports, __webpack_require__) {
  3070. /* WEBPACK VAR INJECTION */(function(global, process) {// Copyright Joyent, Inc. and other Node contributors.
  3071. //
  3072. // Permission is hereby granted, free of charge, to any person obtaining a
  3073. // copy of this software and associated documentation files (the
  3074. // "Software"), to deal in the Software without restriction, including
  3075. // without limitation the rights to use, copy, modify, merge, publish,
  3076. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3077. // persons to whom the Software is furnished to do so, subject to the
  3078. // following conditions:
  3079. //
  3080. // The above copyright notice and this permission notice shall be included
  3081. // in all copies or substantial portions of the Software.
  3082. //
  3083. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3084. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3085. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3086. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3087. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3088. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3089. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3090. var formatRegExp = /%[sdj%]/g;
  3091. exports.format = function(f) {
  3092. if (!isString(f)) {
  3093. var objects = [];
  3094. for (var i = 0; i < arguments.length; i++) {
  3095. objects.push(inspect(arguments[i]));
  3096. }
  3097. return objects.join(' ');
  3098. }
  3099. var i = 1;
  3100. var args = arguments;
  3101. var len = args.length;
  3102. var str = String(f).replace(formatRegExp, function(x) {
  3103. if (x === '%%') return '%';
  3104. if (i >= len) return x;
  3105. switch (x) {
  3106. case '%s': return String(args[i++]);
  3107. case '%d': return Number(args[i++]);
  3108. case '%j':
  3109. try {
  3110. return JSON.stringify(args[i++]);
  3111. } catch (_) {
  3112. return '[Circular]';
  3113. }
  3114. default:
  3115. return x;
  3116. }
  3117. });
  3118. for (var x = args[i]; i < len; x = args[++i]) {
  3119. if (isNull(x) || !isObject(x)) {
  3120. str += ' ' + x;
  3121. } else {
  3122. str += ' ' + inspect(x);
  3123. }
  3124. }
  3125. return str;
  3126. };
  3127. // Mark that a method should not be used.
  3128. // Returns a modified function which warns once by default.
  3129. // If --no-deprecation is set, then it is a no-op.
  3130. exports.deprecate = function(fn, msg) {
  3131. // Allow for deprecating things in the process of starting up.
  3132. if (isUndefined(global.process)) {
  3133. return function() {
  3134. return exports.deprecate(fn, msg).apply(this, arguments);
  3135. };
  3136. }
  3137. if (process.noDeprecation === true) {
  3138. return fn;
  3139. }
  3140. var warned = false;
  3141. function deprecated() {
  3142. if (!warned) {
  3143. if (process.throwDeprecation) {
  3144. throw new Error(msg);
  3145. } else if (process.traceDeprecation) {
  3146. console.trace(msg);
  3147. } else {
  3148. console.error(msg);
  3149. }
  3150. warned = true;
  3151. }
  3152. return fn.apply(this, arguments);
  3153. }
  3154. return deprecated;
  3155. };
  3156. var debugs = {};
  3157. var debugEnviron;
  3158. exports.debuglog = function(set) {
  3159. if (isUndefined(debugEnviron))
  3160. debugEnviron = process.env.NODE_DEBUG || '';
  3161. set = set.toUpperCase();
  3162. if (!debugs[set]) {
  3163. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  3164. var pid = process.pid;
  3165. debugs[set] = function() {
  3166. var msg = exports.format.apply(exports, arguments);
  3167. console.error('%s %d: %s', set, pid, msg);
  3168. };
  3169. } else {
  3170. debugs[set] = function() {};
  3171. }
  3172. }
  3173. return debugs[set];
  3174. };
  3175. /**
  3176. * Echos the value of a value. Trys to print the value out
  3177. * in the best way possible given the different types.
  3178. *
  3179. * @param {Object} obj The object to print out.
  3180. * @param {Object} opts Optional options object that alters the output.
  3181. */
  3182. /* legacy: obj, showHidden, depth, colors*/
  3183. function inspect(obj, opts) {
  3184. // default options
  3185. var ctx = {
  3186. seen: [],
  3187. stylize: stylizeNoColor
  3188. };
  3189. // legacy...
  3190. if (arguments.length >= 3) ctx.depth = arguments[2];
  3191. if (arguments.length >= 4) ctx.colors = arguments[3];
  3192. if (isBoolean(opts)) {
  3193. // legacy...
  3194. ctx.showHidden = opts;
  3195. } else if (opts) {
  3196. // got an "options" object
  3197. exports._extend(ctx, opts);
  3198. }
  3199. // set default options
  3200. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  3201. if (isUndefined(ctx.depth)) ctx.depth = 2;
  3202. if (isUndefined(ctx.colors)) ctx.colors = false;
  3203. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  3204. if (ctx.colors) ctx.stylize = stylizeWithColor;
  3205. return formatValue(ctx, obj, ctx.depth);
  3206. }
  3207. exports.inspect = inspect;
  3208. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  3209. inspect.colors = {
  3210. 'bold' : [1, 22],
  3211. 'italic' : [3, 23],
  3212. 'underline' : [4, 24],
  3213. 'inverse' : [7, 27],
  3214. 'white' : [37, 39],
  3215. 'grey' : [90, 39],
  3216. 'black' : [30, 39],
  3217. 'blue' : [34, 39],
  3218. 'cyan' : [36, 39],
  3219. 'green' : [32, 39],
  3220. 'magenta' : [35, 39],
  3221. 'red' : [31, 39],
  3222. 'yellow' : [33, 39]
  3223. };
  3224. // Don't use 'blue' not visible on cmd.exe
  3225. inspect.styles = {
  3226. 'special': 'cyan',
  3227. 'number': 'yellow',
  3228. 'boolean': 'yellow',
  3229. 'undefined': 'grey',
  3230. 'null': 'bold',
  3231. 'string': 'green',
  3232. 'date': 'magenta',
  3233. // "name": intentionally not styling
  3234. 'regexp': 'red'
  3235. };
  3236. function stylizeWithColor(str, styleType) {
  3237. var style = inspect.styles[styleType];
  3238. if (style) {
  3239. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  3240. '\u001b[' + inspect.colors[style][1] + 'm';
  3241. } else {
  3242. return str;
  3243. }
  3244. }
  3245. function stylizeNoColor(str, styleType) {
  3246. return str;
  3247. }
  3248. function arrayToHash(array) {
  3249. var hash = {};
  3250. array.forEach(function(val, idx) {
  3251. hash[val] = true;
  3252. });
  3253. return hash;
  3254. }
  3255. function formatValue(ctx, value, recurseTimes) {
  3256. // Provide a hook for user-specified inspect functions.
  3257. // Check that value is an object with an inspect function on it
  3258. if (ctx.customInspect &&
  3259. value &&
  3260. isFunction(value.inspect) &&
  3261. // Filter out the util module, it's inspect function is special
  3262. value.inspect !== exports.inspect &&
  3263. // Also filter out any prototype objects using the circular check.
  3264. !(value.constructor && value.constructor.prototype === value)) {
  3265. var ret = value.inspect(recurseTimes, ctx);
  3266. if (!isString(ret)) {
  3267. ret = formatValue(ctx, ret, recurseTimes);
  3268. }
  3269. return ret;
  3270. }
  3271. // Primitive types cannot have properties
  3272. var primitive = formatPrimitive(ctx, value);
  3273. if (primitive) {
  3274. return primitive;
  3275. }
  3276. // Look up the keys of the object.
  3277. var keys = Object.keys(value);
  3278. var visibleKeys = arrayToHash(keys);
  3279. if (ctx.showHidden) {
  3280. keys = Object.getOwnPropertyNames(value);
  3281. }
  3282. // IE doesn't make error fields non-enumerable
  3283. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  3284. if (isError(value)
  3285. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  3286. return formatError(value);
  3287. }
  3288. // Some type of object without properties can be shortcutted.
  3289. if (keys.length === 0) {
  3290. if (isFunction(value)) {
  3291. var name = value.name ? ': ' + value.name : '';
  3292. return ctx.stylize('[Function' + name + ']', 'special');
  3293. }
  3294. if (isRegExp(value)) {
  3295. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  3296. }
  3297. if (isDate(value)) {
  3298. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  3299. }
  3300. if (isError(value)) {
  3301. return formatError(value);
  3302. }
  3303. }
  3304. var base = '', array = false, braces = ['{', '}'];
  3305. // Make Array say that they are Array
  3306. if (isArray(value)) {
  3307. array = true;
  3308. braces = ['[', ']'];
  3309. }
  3310. // Make functions say that they are functions
  3311. if (isFunction(value)) {
  3312. var n = value.name ? ': ' + value.name : '';
  3313. base = ' [Function' + n + ']';
  3314. }
  3315. // Make RegExps say that they are RegExps
  3316. if (isRegExp(value)) {
  3317. base = ' ' + RegExp.prototype.toString.call(value);
  3318. }
  3319. // Make dates with properties first say the date
  3320. if (isDate(value)) {
  3321. base = ' ' + Date.prototype.toUTCString.call(value);
  3322. }
  3323. // Make error with message first say the error
  3324. if (isError(value)) {
  3325. base = ' ' + formatError(value);
  3326. }
  3327. if (keys.length === 0 && (!array || value.length == 0)) {
  3328. return braces[0] + base + braces[1];
  3329. }
  3330. if (recurseTimes < 0) {
  3331. if (isRegExp(value)) {
  3332. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  3333. } else {
  3334. return ctx.stylize('[Object]', 'special');
  3335. }
  3336. }
  3337. ctx.seen.push(value);
  3338. var output;
  3339. if (array) {
  3340. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  3341. } else {
  3342. output = keys.map(function(key) {
  3343. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  3344. });
  3345. }
  3346. ctx.seen.pop();
  3347. return reduceToSingleString(output, base, braces);
  3348. }
  3349. function formatPrimitive(ctx, value) {
  3350. if (isUndefined(value))
  3351. return ctx.stylize('undefined', 'undefined');
  3352. if (isString(value)) {
  3353. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  3354. .replace(/'/g, "\\'")
  3355. .replace(/\\"/g, '"') + '\'';
  3356. return ctx.stylize(simple, 'string');
  3357. }
  3358. if (isNumber(value))
  3359. return ctx.stylize('' + value, 'number');
  3360. if (isBoolean(value))
  3361. return ctx.stylize('' + value, 'boolean');
  3362. // For some reason typeof null is "object", so special case here.
  3363. if (isNull(value))
  3364. return ctx.stylize('null', 'null');
  3365. }
  3366. function formatError(value) {
  3367. return '[' + Error.prototype.toString.call(value) + ']';
  3368. }
  3369. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  3370. var output = [];
  3371. for (var i = 0, l = value.length; i < l; ++i) {
  3372. if (hasOwnProperty(value, String(i))) {
  3373. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  3374. String(i), true));
  3375. } else {
  3376. output.push('');
  3377. }
  3378. }
  3379. keys.forEach(function(key) {
  3380. if (!key.match(/^\d+$/)) {
  3381. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  3382. key, true));
  3383. }
  3384. });
  3385. return output;
  3386. }
  3387. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  3388. var name, str, desc;
  3389. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  3390. if (desc.get) {
  3391. if (desc.set) {
  3392. str = ctx.stylize('[Getter/Setter]', 'special');
  3393. } else {
  3394. str = ctx.stylize('[Getter]', 'special');
  3395. }
  3396. } else {
  3397. if (desc.set) {
  3398. str = ctx.stylize('[Setter]', 'special');
  3399. }
  3400. }
  3401. if (!hasOwnProperty(visibleKeys, key)) {
  3402. name = '[' + key + ']';
  3403. }
  3404. if (!str) {
  3405. if (ctx.seen.indexOf(desc.value) < 0) {
  3406. if (isNull(recurseTimes)) {
  3407. str = formatValue(ctx, desc.value, null);
  3408. } else {
  3409. str = formatValue(ctx, desc.value, recurseTimes - 1);
  3410. }
  3411. if (str.indexOf('\n') > -1) {
  3412. if (array) {
  3413. str = str.split('\n').map(function(line) {
  3414. return ' ' + line;
  3415. }).join('\n').substr(2);
  3416. } else {
  3417. str = '\n' + str.split('\n').map(function(line) {
  3418. return ' ' + line;
  3419. }).join('\n');
  3420. }
  3421. }
  3422. } else {
  3423. str = ctx.stylize('[Circular]', 'special');
  3424. }
  3425. }
  3426. if (isUndefined(name)) {
  3427. if (array && key.match(/^\d+$/)) {
  3428. return str;
  3429. }
  3430. name = JSON.stringify('' + key);
  3431. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  3432. name = name.substr(1, name.length - 2);
  3433. name = ctx.stylize(name, 'name');
  3434. } else {
  3435. name = name.replace(/'/g, "\\'")
  3436. .replace(/\\"/g, '"')
  3437. .replace(/(^"|"$)/g, "'");
  3438. name = ctx.stylize(name, 'string');
  3439. }
  3440. }
  3441. return name + ': ' + str;
  3442. }
  3443. function reduceToSingleString(output, base, braces) {
  3444. var numLinesEst = 0;
  3445. var length = output.reduce(function(prev, cur) {
  3446. numLinesEst++;
  3447. if (cur.indexOf('\n') >= 0) numLinesEst++;
  3448. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  3449. }, 0);
  3450. if (length > 60) {
  3451. return braces[0] +
  3452. (base === '' ? '' : base + '\n ') +
  3453. ' ' +
  3454. output.join(',\n ') +
  3455. ' ' +
  3456. braces[1];
  3457. }
  3458. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  3459. }
  3460. // NOTE: These type checking functions intentionally don't use `instanceof`
  3461. // because it is fragile and can be easily faked with `Object.create()`.
  3462. function isArray(ar) {
  3463. return Array.isArray(ar);
  3464. }
  3465. exports.isArray = isArray;
  3466. function isBoolean(arg) {
  3467. return typeof arg === 'boolean';
  3468. }
  3469. exports.isBoolean = isBoolean;
  3470. function isNull(arg) {
  3471. return arg === null;
  3472. }
  3473. exports.isNull = isNull;
  3474. function isNullOrUndefined(arg) {
  3475. return arg == null;
  3476. }
  3477. exports.isNullOrUndefined = isNullOrUndefined;
  3478. function isNumber(arg) {
  3479. return typeof arg === 'number';
  3480. }
  3481. exports.isNumber = isNumber;
  3482. function isString(arg) {
  3483. return typeof arg === 'string';
  3484. }
  3485. exports.isString = isString;
  3486. function isSymbol(arg) {
  3487. return typeof arg === 'symbol';
  3488. }
  3489. exports.isSymbol = isSymbol;
  3490. function isUndefined(arg) {
  3491. return arg === void 0;
  3492. }
  3493. exports.isUndefined = isUndefined;
  3494. function isRegExp(re) {
  3495. return isObject(re) && objectToString(re) === '[object RegExp]';
  3496. }
  3497. exports.isRegExp = isRegExp;
  3498. function isObject(arg) {
  3499. return typeof arg === 'object' && arg !== null;
  3500. }
  3501. exports.isObject = isObject;
  3502. function isDate(d) {
  3503. return isObject(d) && objectToString(d) === '[object Date]';
  3504. }
  3505. exports.isDate = isDate;
  3506. function isError(e) {
  3507. return isObject(e) &&
  3508. (objectToString(e) === '[object Error]' || e instanceof Error);
  3509. }
  3510. exports.isError = isError;
  3511. function isFunction(arg) {
  3512. return typeof arg === 'function';
  3513. }
  3514. exports.isFunction = isFunction;
  3515. function isPrimitive(arg) {
  3516. return arg === null ||
  3517. typeof arg === 'boolean' ||
  3518. typeof arg === 'number' ||
  3519. typeof arg === 'string' ||
  3520. typeof arg === 'symbol' || // ES6 symbol
  3521. typeof arg === 'undefined';
  3522. }
  3523. exports.isPrimitive = isPrimitive;
  3524. exports.isBuffer = __webpack_require__(25);
  3525. function objectToString(o) {
  3526. return Object.prototype.toString.call(o);
  3527. }
  3528. function pad(n) {
  3529. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  3530. }
  3531. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  3532. 'Oct', 'Nov', 'Dec'];
  3533. // 26 Feb 16:19:34
  3534. function timestamp() {
  3535. var d = new Date();
  3536. var time = [pad(d.getHours()),
  3537. pad(d.getMinutes()),
  3538. pad(d.getSeconds())].join(':');
  3539. return [d.getDate(), months[d.getMonth()], time].join(' ');
  3540. }
  3541. // log is just a thin wrapper to console.log that prepends a timestamp
  3542. exports.log = function() {
  3543. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  3544. };
  3545. /**
  3546. * Inherit the prototype methods from one constructor into another.
  3547. *
  3548. * The Function.prototype.inherits from lang.js rewritten as a standalone
  3549. * function (not on Function.prototype). NOTE: If this file is to be loaded
  3550. * during bootstrapping this function needs to be rewritten using some native
  3551. * functions as prototype setup using normal JavaScript does not work as
  3552. * expected during bootstrapping (see mirror.js in r114903).
  3553. *
  3554. * @param {function} ctor Constructor function which needs to inherit the
  3555. * prototype.
  3556. * @param {function} superCtor Constructor function to inherit prototype from.
  3557. */
  3558. exports.inherits = __webpack_require__(26);
  3559. exports._extend = function(origin, add) {
  3560. // Don't do anything if add isn't an object
  3561. if (!add || !isObject(add)) return origin;
  3562. var keys = Object.keys(add);
  3563. var i = keys.length;
  3564. while (i--) {
  3565. origin[keys[i]] = add[keys[i]];
  3566. }
  3567. return origin;
  3568. };
  3569. function hasOwnProperty(obj, prop) {
  3570. return Object.prototype.hasOwnProperty.call(obj, prop);
  3571. }
  3572. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()), __webpack_require__(24)))
  3573. /***/ }),
  3574. /* 24 */
  3575. /***/ (function(module, exports) {
  3576. // shim for using process in browser
  3577. var process = module.exports = {};
  3578. // cached from whatever global is present so that test runners that stub it
  3579. // don't break things. But we need to wrap it in a try catch in case it is
  3580. // wrapped in strict mode code which doesn't define any globals. It's inside a
  3581. // function because try/catches deoptimize in certain engines.
  3582. var cachedSetTimeout;
  3583. var cachedClearTimeout;
  3584. function defaultSetTimout() {
  3585. throw new Error('setTimeout has not been defined');
  3586. }
  3587. function defaultClearTimeout () {
  3588. throw new Error('clearTimeout has not been defined');
  3589. }
  3590. (function () {
  3591. try {
  3592. if (typeof setTimeout === 'function') {
  3593. cachedSetTimeout = setTimeout;
  3594. } else {
  3595. cachedSetTimeout = defaultSetTimout;
  3596. }
  3597. } catch (e) {
  3598. cachedSetTimeout = defaultSetTimout;
  3599. }
  3600. try {
  3601. if (typeof clearTimeout === 'function') {
  3602. cachedClearTimeout = clearTimeout;
  3603. } else {
  3604. cachedClearTimeout = defaultClearTimeout;
  3605. }
  3606. } catch (e) {
  3607. cachedClearTimeout = defaultClearTimeout;
  3608. }
  3609. } ())
  3610. function runTimeout(fun) {
  3611. if (cachedSetTimeout === setTimeout) {
  3612. //normal enviroments in sane situations
  3613. return setTimeout(fun, 0);
  3614. }
  3615. // if setTimeout wasn't available but was latter defined
  3616. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  3617. cachedSetTimeout = setTimeout;
  3618. return setTimeout(fun, 0);
  3619. }
  3620. try {
  3621. // when when somebody has screwed with setTimeout but no I.E. maddness
  3622. return cachedSetTimeout(fun, 0);
  3623. } catch(e){
  3624. try {
  3625. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  3626. return cachedSetTimeout.call(null, fun, 0);
  3627. } catch(e){
  3628. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  3629. return cachedSetTimeout.call(this, fun, 0);
  3630. }
  3631. }
  3632. }
  3633. function runClearTimeout(marker) {
  3634. if (cachedClearTimeout === clearTimeout) {
  3635. //normal enviroments in sane situations
  3636. return clearTimeout(marker);
  3637. }
  3638. // if clearTimeout wasn't available but was latter defined
  3639. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  3640. cachedClearTimeout = clearTimeout;
  3641. return clearTimeout(marker);
  3642. }
  3643. try {
  3644. // when when somebody has screwed with setTimeout but no I.E. maddness
  3645. return cachedClearTimeout(marker);
  3646. } catch (e){
  3647. try {
  3648. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  3649. return cachedClearTimeout.call(null, marker);
  3650. } catch (e){
  3651. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  3652. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  3653. return cachedClearTimeout.call(this, marker);
  3654. }
  3655. }
  3656. }
  3657. var queue = [];
  3658. var draining = false;
  3659. var currentQueue;
  3660. var queueIndex = -1;
  3661. function cleanUpNextTick() {
  3662. if (!draining || !currentQueue) {
  3663. return;
  3664. }
  3665. draining = false;
  3666. if (currentQueue.length) {
  3667. queue = currentQueue.concat(queue);
  3668. } else {
  3669. queueIndex = -1;
  3670. }
  3671. if (queue.length) {
  3672. drainQueue();
  3673. }
  3674. }
  3675. function drainQueue() {
  3676. if (draining) {
  3677. return;
  3678. }
  3679. var timeout = runTimeout(cleanUpNextTick);
  3680. draining = true;
  3681. var len = queue.length;
  3682. while(len) {
  3683. currentQueue = queue;
  3684. queue = [];
  3685. while (++queueIndex < len) {
  3686. if (currentQueue) {
  3687. currentQueue[queueIndex].run();
  3688. }
  3689. }
  3690. queueIndex = -1;
  3691. len = queue.length;
  3692. }
  3693. currentQueue = null;
  3694. draining = false;
  3695. runClearTimeout(timeout);
  3696. }
  3697. process.nextTick = function (fun) {
  3698. var args = new Array(arguments.length - 1);
  3699. if (arguments.length > 1) {
  3700. for (var i = 1; i < arguments.length; i++) {
  3701. args[i - 1] = arguments[i];
  3702. }
  3703. }
  3704. queue.push(new Item(fun, args));
  3705. if (queue.length === 1 && !draining) {
  3706. runTimeout(drainQueue);
  3707. }
  3708. };
  3709. // v8 likes predictible objects
  3710. function Item(fun, array) {
  3711. this.fun = fun;
  3712. this.array = array;
  3713. }
  3714. Item.prototype.run = function () {
  3715. this.fun.apply(null, this.array);
  3716. };
  3717. process.title = 'browser';
  3718. process.browser = true;
  3719. process.env = {};
  3720. process.argv = [];
  3721. process.version = ''; // empty string to avoid regexp issues
  3722. process.versions = {};
  3723. function noop() {}
  3724. process.on = noop;
  3725. process.addListener = noop;
  3726. process.once = noop;
  3727. process.off = noop;
  3728. process.removeListener = noop;
  3729. process.removeAllListeners = noop;
  3730. process.emit = noop;
  3731. process.prependListener = noop;
  3732. process.prependOnceListener = noop;
  3733. process.listeners = function (name) { return [] }
  3734. process.binding = function (name) {
  3735. throw new Error('process.binding is not supported');
  3736. };
  3737. process.cwd = function () { return '/' };
  3738. process.chdir = function (dir) {
  3739. throw new Error('process.chdir is not supported');
  3740. };
  3741. process.umask = function() { return 0; };
  3742. /***/ }),
  3743. /* 25 */
  3744. /***/ (function(module, exports) {
  3745. module.exports = function isBuffer(arg) {
  3746. return arg && typeof arg === 'object'
  3747. && typeof arg.copy === 'function'
  3748. && typeof arg.fill === 'function'
  3749. && typeof arg.readUInt8 === 'function';
  3750. }
  3751. /***/ }),
  3752. /* 26 */
  3753. /***/ (function(module, exports) {
  3754. if (typeof Object.create === 'function') {
  3755. // implementation from standard node.js 'util' module
  3756. module.exports = function inherits(ctor, superCtor) {
  3757. ctor.super_ = superCtor
  3758. ctor.prototype = Object.create(superCtor.prototype, {
  3759. constructor: {
  3760. value: ctor,
  3761. enumerable: false,
  3762. writable: true,
  3763. configurable: true
  3764. }
  3765. });
  3766. };
  3767. } else {
  3768. // old school shim for old browsers
  3769. module.exports = function inherits(ctor, superCtor) {
  3770. ctor.super_ = superCtor
  3771. var TempCtor = function () {}
  3772. TempCtor.prototype = superCtor.prototype
  3773. ctor.prototype = new TempCtor()
  3774. ctor.prototype.constructor = ctor
  3775. }
  3776. }
  3777. /***/ }),
  3778. /* 27 */
  3779. /***/ (function(module, exports, __webpack_require__) {
  3780. var DOM = __webpack_require__(9);
  3781. var utils = __webpack_require__(7);
  3782. module.exports = (function() {
  3783. var canvas = DOM.newEl('canvas');
  3784. var ctx = null;
  3785. return function(sceneGraph) {
  3786. if (ctx == null) {
  3787. ctx = canvas.getContext('2d');
  3788. }
  3789. var dpr = utils.canvasRatio();
  3790. var root = sceneGraph.root;
  3791. canvas.width = dpr * root.properties.width;
  3792. canvas.height = dpr * root.properties.height ;
  3793. ctx.textBaseline = 'middle';
  3794. var bg = root.children.holderBg;
  3795. var bgWidth = dpr * bg.width;
  3796. var bgHeight = dpr * bg.height;
  3797. //todo: parametrize outline width (e.g. in scene object)
  3798. var outlineWidth = 2;
  3799. var outlineOffsetWidth = outlineWidth / 2;
  3800. ctx.fillStyle = bg.properties.fill;
  3801. ctx.fillRect(0, 0, bgWidth, bgHeight);
  3802. if (bg.properties.outline) {
  3803. //todo: abstract this into a method
  3804. ctx.strokeStyle = bg.properties.outline.fill;
  3805. ctx.lineWidth = bg.properties.outline.width;
  3806. ctx.moveTo(outlineOffsetWidth, outlineOffsetWidth);
  3807. // TL, TR, BR, BL
  3808. ctx.lineTo(bgWidth - outlineOffsetWidth, outlineOffsetWidth);
  3809. ctx.lineTo(bgWidth - outlineOffsetWidth, bgHeight - outlineOffsetWidth);
  3810. ctx.lineTo(outlineOffsetWidth, bgHeight - outlineOffsetWidth);
  3811. ctx.lineTo(outlineOffsetWidth, outlineOffsetWidth);
  3812. // Diagonals
  3813. ctx.moveTo(0, outlineOffsetWidth);
  3814. ctx.lineTo(bgWidth, bgHeight - outlineOffsetWidth);
  3815. ctx.moveTo(0, bgHeight - outlineOffsetWidth);
  3816. ctx.lineTo(bgWidth, outlineOffsetWidth);
  3817. ctx.stroke();
  3818. }
  3819. var textGroup = root.children.holderTextGroup;
  3820. ctx.font = textGroup.properties.font.weight + ' ' + (dpr * textGroup.properties.font.size) + textGroup.properties.font.units + ' ' + textGroup.properties.font.family + ', monospace';
  3821. ctx.fillStyle = textGroup.properties.fill;
  3822. for (var lineKey in textGroup.children) {
  3823. var line = textGroup.children[lineKey];
  3824. for (var wordKey in line.children) {
  3825. var word = line.children[wordKey];
  3826. var x = dpr * (textGroup.x + line.x + word.x);
  3827. var y = dpr * (textGroup.y + line.y + word.y + (textGroup.properties.leading / 2));
  3828. ctx.fillText(word.properties.text, x, y);
  3829. }
  3830. }
  3831. return canvas.toDataURL('image/png');
  3832. };
  3833. })();
  3834. /***/ })
  3835. /******/ ])
  3836. });
  3837. ;
  3838. (function(ctx, isMeteorPackage) {
  3839. if (isMeteorPackage) {
  3840. Holder = ctx.Holder;
  3841. }
  3842. })(this, typeof Meteor !== 'undefined' && typeof Package !== 'undefined');