dat.gui.module.js 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575
  1. /**
  2. * dat-gui JavaScript Controller Library
  3. * http://code.google.com/p/dat-gui
  4. *
  5. * Copyright 2011 Data Arts Team, Google Creative Lab
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. */
  13. function ___$insertStyle( css ) {
  14. if ( ! css ) {
  15. return;
  16. }
  17. if ( typeof window === 'undefined' ) {
  18. return;
  19. }
  20. var style = document.createElement( 'style' );
  21. style.setAttribute( 'type', 'text/css' );
  22. style.innerHTML = css;
  23. document.head.appendChild( style );
  24. return css;
  25. }
  26. function colorToString( color, forceCSSHex ) {
  27. var colorFormat = color.__state.conversionName.toString();
  28. var r = Math.round( color.r );
  29. var g = Math.round( color.g );
  30. var b = Math.round( color.b );
  31. var a = color.a;
  32. var h = Math.round( color.h );
  33. var s = color.s.toFixed( 1 );
  34. var v = color.v.toFixed( 1 );
  35. if ( forceCSSHex || colorFormat === 'THREE_CHAR_HEX' || colorFormat === 'SIX_CHAR_HEX' ) {
  36. var str = color.hex.toString( 16 );
  37. while ( str.length < 6 ) {
  38. str = '0' + str;
  39. }
  40. return '#' + str;
  41. } else if ( colorFormat === 'CSS_RGB' ) {
  42. return 'rgb(' + r + ',' + g + ',' + b + ')';
  43. } else if ( colorFormat === 'CSS_RGBA' ) {
  44. return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
  45. } else if ( colorFormat === 'HEX' ) {
  46. return '0x' + color.hex.toString( 16 );
  47. } else if ( colorFormat === 'RGB_ARRAY' ) {
  48. return '[' + r + ',' + g + ',' + b + ']';
  49. } else if ( colorFormat === 'RGBA_ARRAY' ) {
  50. return '[' + r + ',' + g + ',' + b + ',' + a + ']';
  51. } else if ( colorFormat === 'RGB_OBJ' ) {
  52. return '{r:' + r + ',g:' + g + ',b:' + b + '}';
  53. } else if ( colorFormat === 'RGBA_OBJ' ) {
  54. return '{r:' + r + ',g:' + g + ',b:' + b + ',a:' + a + '}';
  55. } else if ( colorFormat === 'HSV_OBJ' ) {
  56. return '{h:' + h + ',s:' + s + ',v:' + v + '}';
  57. } else if ( colorFormat === 'HSVA_OBJ' ) {
  58. return '{h:' + h + ',s:' + s + ',v:' + v + ',a:' + a + '}';
  59. }
  60. return 'unknown format';
  61. }
  62. var ARR_EACH = Array.prototype.forEach;
  63. var ARR_SLICE = Array.prototype.slice;
  64. var Common = {
  65. BREAK: {},
  66. extend: function extend( target ) {
  67. this.each( ARR_SLICE.call( arguments, 1 ), function ( obj ) {
  68. var keys = this.isObject( obj ) ? Object.keys( obj ) : [];
  69. keys.forEach( function ( key ) {
  70. if ( ! this.isUndefined( obj[ key ] ) ) {
  71. target[ key ] = obj[ key ];
  72. }
  73. }.bind( this ) );
  74. }, this );
  75. return target;
  76. },
  77. defaults: function defaults( target ) {
  78. this.each( ARR_SLICE.call( arguments, 1 ), function ( obj ) {
  79. var keys = this.isObject( obj ) ? Object.keys( obj ) : [];
  80. keys.forEach( function ( key ) {
  81. if ( this.isUndefined( target[ key ] ) ) {
  82. target[ key ] = obj[ key ];
  83. }
  84. }.bind( this ) );
  85. }, this );
  86. return target;
  87. },
  88. compose: function compose() {
  89. var toCall = ARR_SLICE.call( arguments );
  90. return function () {
  91. var args = ARR_SLICE.call( arguments );
  92. for ( var i = toCall.length - 1; i >= 0; i -- ) {
  93. args = [ toCall[ i ].apply( this, args ) ];
  94. }
  95. return args[ 0 ];
  96. };
  97. },
  98. each: function each( obj, itr, scope ) {
  99. if ( ! obj ) {
  100. return;
  101. }
  102. if ( ARR_EACH && obj.forEach && obj.forEach === ARR_EACH ) {
  103. obj.forEach( itr, scope );
  104. } else if ( obj.length === obj.length + 0 ) {
  105. var key = void 0;
  106. var l = void 0;
  107. for ( key = 0, l = obj.length; key < l; key ++ ) {
  108. if ( key in obj && itr.call( scope, obj[ key ], key ) === this.BREAK ) {
  109. return;
  110. }
  111. }
  112. } else {
  113. for ( var _key in obj ) {
  114. if ( itr.call( scope, obj[ _key ], _key ) === this.BREAK ) {
  115. return;
  116. }
  117. }
  118. }
  119. },
  120. defer: function defer( fnc ) {
  121. setTimeout( fnc, 0 );
  122. },
  123. debounce: function debounce( func, threshold, callImmediately ) {
  124. var timeout = void 0;
  125. return function () {
  126. var obj = this;
  127. var args = arguments;
  128. function delayed() {
  129. timeout = null;
  130. if ( ! callImmediately ) func.apply( obj, args );
  131. }
  132. var callNow = callImmediately || ! timeout;
  133. clearTimeout( timeout );
  134. timeout = setTimeout( delayed, threshold );
  135. if ( callNow ) {
  136. func.apply( obj, args );
  137. }
  138. };
  139. },
  140. toArray: function toArray( obj ) {
  141. if ( obj.toArray ) return obj.toArray();
  142. return ARR_SLICE.call( obj );
  143. },
  144. isUndefined: function isUndefined( obj ) {
  145. return obj === undefined;
  146. },
  147. isNull: function isNull( obj ) {
  148. return obj === null;
  149. },
  150. isNaN: function ( _isNaN ) {
  151. function isNaN() {
  152. return _isNaN.apply( this, arguments );
  153. }
  154. isNaN.toString = function () {
  155. return _isNaN.toString();
  156. };
  157. return isNaN;
  158. }( function ( obj ) {
  159. return isNaN( obj );
  160. } ),
  161. isArray: Array.isArray || function ( obj ) {
  162. return obj.constructor === Array;
  163. },
  164. isObject: function isObject( obj ) {
  165. return obj === Object( obj );
  166. },
  167. isNumber: function isNumber( obj ) {
  168. return obj === obj + 0;
  169. },
  170. isString: function isString( obj ) {
  171. return obj === obj + '';
  172. },
  173. isBoolean: function isBoolean( obj ) {
  174. return obj === false || obj === true;
  175. },
  176. isFunction: function isFunction( obj ) {
  177. return Object.prototype.toString.call( obj ) === '[object Function]';
  178. }
  179. };
  180. var INTERPRETATIONS = [
  181. {
  182. litmus: Common.isString,
  183. conversions: {
  184. THREE_CHAR_HEX: {
  185. read: function read( original ) {
  186. var test = original.match( /^#([A-F0-9])([A-F0-9])([A-F0-9])$/i );
  187. if ( test === null ) {
  188. return false;
  189. }
  190. return {
  191. space: 'HEX',
  192. hex: parseInt( '0x' + test[ 1 ].toString() + test[ 1 ].toString() + test[ 2 ].toString() + test[ 2 ].toString() + test[ 3 ].toString() + test[ 3 ].toString(), 0 )
  193. };
  194. },
  195. write: colorToString
  196. },
  197. SIX_CHAR_HEX: {
  198. read: function read( original ) {
  199. var test = original.match( /^#([A-F0-9]{6})$/i );
  200. if ( test === null ) {
  201. return false;
  202. }
  203. return {
  204. space: 'HEX',
  205. hex: parseInt( '0x' + test[ 1 ].toString(), 0 )
  206. };
  207. },
  208. write: colorToString
  209. },
  210. CSS_RGB: {
  211. read: function read( original ) {
  212. var test = original.match( /^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/ );
  213. if ( test === null ) {
  214. return false;
  215. }
  216. return {
  217. space: 'RGB',
  218. r: parseFloat( test[ 1 ] ),
  219. g: parseFloat( test[ 2 ] ),
  220. b: parseFloat( test[ 3 ] )
  221. };
  222. },
  223. write: colorToString
  224. },
  225. CSS_RGBA: {
  226. read: function read( original ) {
  227. var test = original.match( /^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/ );
  228. if ( test === null ) {
  229. return false;
  230. }
  231. return {
  232. space: 'RGB',
  233. r: parseFloat( test[ 1 ] ),
  234. g: parseFloat( test[ 2 ] ),
  235. b: parseFloat( test[ 3 ] ),
  236. a: parseFloat( test[ 4 ] )
  237. };
  238. },
  239. write: colorToString
  240. }
  241. }
  242. },
  243. {
  244. litmus: Common.isNumber,
  245. conversions: {
  246. HEX: {
  247. read: function read( original ) {
  248. return {
  249. space: 'HEX',
  250. hex: original,
  251. conversionName: 'HEX'
  252. };
  253. },
  254. write: function write( color ) {
  255. return color.hex;
  256. }
  257. }
  258. }
  259. },
  260. {
  261. litmus: Common.isArray,
  262. conversions: {
  263. RGB_ARRAY: {
  264. read: function read( original ) {
  265. if ( original.length !== 3 ) {
  266. return false;
  267. }
  268. return {
  269. space: 'RGB',
  270. r: original[ 0 ],
  271. g: original[ 1 ],
  272. b: original[ 2 ]
  273. };
  274. },
  275. write: function write( color ) {
  276. return [ color.r, color.g, color.b ];
  277. }
  278. },
  279. RGBA_ARRAY: {
  280. read: function read( original ) {
  281. if ( original.length !== 4 ) return false;
  282. return {
  283. space: 'RGB',
  284. r: original[ 0 ],
  285. g: original[ 1 ],
  286. b: original[ 2 ],
  287. a: original[ 3 ]
  288. };
  289. },
  290. write: function write( color ) {
  291. return [ color.r, color.g, color.b, color.a ];
  292. }
  293. }
  294. }
  295. },
  296. {
  297. litmus: Common.isObject,
  298. conversions: {
  299. RGBA_OBJ: {
  300. read: function read( original ) {
  301. if ( Common.isNumber( original.r ) && Common.isNumber( original.g ) && Common.isNumber( original.b ) && Common.isNumber( original.a ) ) {
  302. return {
  303. space: 'RGB',
  304. r: original.r,
  305. g: original.g,
  306. b: original.b,
  307. a: original.a
  308. };
  309. }
  310. return false;
  311. },
  312. write: function write( color ) {
  313. return {
  314. r: color.r,
  315. g: color.g,
  316. b: color.b,
  317. a: color.a
  318. };
  319. }
  320. },
  321. RGB_OBJ: {
  322. read: function read( original ) {
  323. if ( Common.isNumber( original.r ) && Common.isNumber( original.g ) && Common.isNumber( original.b ) ) {
  324. return {
  325. space: 'RGB',
  326. r: original.r,
  327. g: original.g,
  328. b: original.b
  329. };
  330. }
  331. return false;
  332. },
  333. write: function write( color ) {
  334. return {
  335. r: color.r,
  336. g: color.g,
  337. b: color.b
  338. };
  339. }
  340. },
  341. HSVA_OBJ: {
  342. read: function read( original ) {
  343. if ( Common.isNumber( original.h ) && Common.isNumber( original.s ) && Common.isNumber( original.v ) && Common.isNumber( original.a ) ) {
  344. return {
  345. space: 'HSV',
  346. h: original.h,
  347. s: original.s,
  348. v: original.v,
  349. a: original.a
  350. };
  351. }
  352. return false;
  353. },
  354. write: function write( color ) {
  355. return {
  356. h: color.h,
  357. s: color.s,
  358. v: color.v,
  359. a: color.a
  360. };
  361. }
  362. },
  363. HSV_OBJ: {
  364. read: function read( original ) {
  365. if ( Common.isNumber( original.h ) && Common.isNumber( original.s ) && Common.isNumber( original.v ) ) {
  366. return {
  367. space: 'HSV',
  368. h: original.h,
  369. s: original.s,
  370. v: original.v
  371. };
  372. }
  373. return false;
  374. },
  375. write: function write( color ) {
  376. return {
  377. h: color.h,
  378. s: color.s,
  379. v: color.v
  380. };
  381. }
  382. }
  383. }
  384. } ];
  385. var result = void 0;
  386. var toReturn = void 0;
  387. var interpret = function interpret() {
  388. toReturn = false;
  389. var original = arguments.length > 1 ? Common.toArray( arguments ) : arguments[ 0 ];
  390. Common.each( INTERPRETATIONS, function ( family ) {
  391. if ( family.litmus( original ) ) {
  392. Common.each( family.conversions, function ( conversion, conversionName ) {
  393. result = conversion.read( original );
  394. if ( toReturn === false && result !== false ) {
  395. toReturn = result;
  396. result.conversionName = conversionName;
  397. result.conversion = conversion;
  398. return Common.BREAK;
  399. }
  400. } );
  401. return Common.BREAK;
  402. }
  403. } );
  404. return toReturn;
  405. };
  406. var tmpComponent = void 0;
  407. var ColorMath = {
  408. hsv_to_rgb: function hsv_to_rgb( h, s, v ) {
  409. var hi = Math.floor( h / 60 ) % 6;
  410. var f = h / 60 - Math.floor( h / 60 );
  411. var p = v * ( 1.0 - s );
  412. var q = v * ( 1.0 - f * s );
  413. var t = v * ( 1.0 - ( 1.0 - f ) * s );
  414. var c = [[ v, t, p ], [ q, v, p ], [ p, v, t ], [ p, q, v ], [ t, p, v ], [ v, p, q ]][ hi ];
  415. return {
  416. r: c[ 0 ] * 255,
  417. g: c[ 1 ] * 255,
  418. b: c[ 2 ] * 255
  419. };
  420. },
  421. rgb_to_hsv: function rgb_to_hsv( r, g, b ) {
  422. var min = Math.min( r, g, b );
  423. var max = Math.max( r, g, b );
  424. var delta = max - min;
  425. var h = void 0;
  426. var s = void 0;
  427. if ( max !== 0 ) {
  428. s = delta / max;
  429. } else {
  430. return {
  431. h: NaN,
  432. s: 0,
  433. v: 0
  434. };
  435. }
  436. if ( r === max ) {
  437. h = ( g - b ) / delta;
  438. } else if ( g === max ) {
  439. h = 2 + ( b - r ) / delta;
  440. } else {
  441. h = 4 + ( r - g ) / delta;
  442. }
  443. h /= 6;
  444. if ( h < 0 ) {
  445. h += 1;
  446. }
  447. return {
  448. h: h * 360,
  449. s: s,
  450. v: max / 255
  451. };
  452. },
  453. rgb_to_hex: function rgb_to_hex( r, g, b ) {
  454. var hex = this.hex_with_component( 0, 2, r );
  455. hex = this.hex_with_component( hex, 1, g );
  456. hex = this.hex_with_component( hex, 0, b );
  457. return hex;
  458. },
  459. component_from_hex: function component_from_hex( hex, componentIndex ) {
  460. return hex >> componentIndex * 8 & 0xFF;
  461. },
  462. hex_with_component: function hex_with_component( hex, componentIndex, value ) {
  463. return value << ( tmpComponent = componentIndex * 8 ) | hex & ~ ( 0xFF << tmpComponent );
  464. }
  465. };
  466. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function ( obj ) {
  467. return typeof obj;
  468. } : function ( obj ) {
  469. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  470. };
  471. var classCallCheck = function ( instance, Constructor ) {
  472. if ( ! ( instance instanceof Constructor ) ) {
  473. throw new TypeError( "Cannot call a class as a function" );
  474. }
  475. };
  476. var createClass = function () {
  477. function defineProperties( target, props ) {
  478. for ( var i = 0; i < props.length; i ++ ) {
  479. var descriptor = props[ i ];
  480. descriptor.enumerable = descriptor.enumerable || false;
  481. descriptor.configurable = true;
  482. if ( "value" in descriptor ) descriptor.writable = true;
  483. Object.defineProperty( target, descriptor.key, descriptor );
  484. }
  485. }
  486. return function ( Constructor, protoProps, staticProps ) {
  487. if ( protoProps ) defineProperties( Constructor.prototype, protoProps );
  488. if ( staticProps ) defineProperties( Constructor, staticProps );
  489. return Constructor;
  490. };
  491. }();
  492. var get = function get( object, property, receiver ) {
  493. if ( object === null ) object = Function.prototype;
  494. var desc = Object.getOwnPropertyDescriptor( object, property );
  495. if ( desc === undefined ) {
  496. var parent = Object.getPrototypeOf( object );
  497. if ( parent === null ) {
  498. return undefined;
  499. } else {
  500. return get( parent, property, receiver );
  501. }
  502. } else if ( "value" in desc ) {
  503. return desc.value;
  504. } else {
  505. var getter = desc.get;
  506. if ( getter === undefined ) {
  507. return undefined;
  508. }
  509. return getter.call( receiver );
  510. }
  511. };
  512. var inherits = function ( subClass, superClass ) {
  513. if ( typeof superClass !== "function" && superClass !== null ) {
  514. throw new TypeError( "Super expression must either be null or a function, not " + typeof superClass );
  515. }
  516. subClass.prototype = Object.create( superClass && superClass.prototype, {
  517. constructor: {
  518. value: subClass,
  519. enumerable: false,
  520. writable: true,
  521. configurable: true
  522. }
  523. } );
  524. if ( superClass ) Object.setPrototypeOf ? Object.setPrototypeOf( subClass, superClass ) : subClass.__proto__ = superClass;
  525. };
  526. var possibleConstructorReturn = function ( self, call ) {
  527. if ( ! self ) {
  528. throw new ReferenceError( "this hasn't been initialised - super() hasn't been called" );
  529. }
  530. return call && ( typeof call === "object" || typeof call === "function" ) ? call : self;
  531. };
  532. var Color = function () {
  533. function Color() {
  534. classCallCheck( this, Color );
  535. this.__state = interpret.apply( this, arguments );
  536. if ( this.__state === false ) {
  537. throw new Error( 'Failed to interpret color arguments' );
  538. }
  539. this.__state.a = this.__state.a || 1;
  540. }
  541. createClass( Color, [ {
  542. key: 'toString',
  543. value: function toString() {
  544. return colorToString( this );
  545. }
  546. }, {
  547. key: 'toHexString',
  548. value: function toHexString() {
  549. return colorToString( this, true );
  550. }
  551. }, {
  552. key: 'toOriginal',
  553. value: function toOriginal() {
  554. return this.__state.conversion.write( this );
  555. }
  556. } ] );
  557. return Color;
  558. }();
  559. function defineRGBComponent( target, component, componentHexIndex ) {
  560. Object.defineProperty( target, component, {
  561. get: function get$$1() {
  562. if ( this.__state.space === 'RGB' ) {
  563. return this.__state[ component ];
  564. }
  565. Color.recalculateRGB( this, component, componentHexIndex );
  566. return this.__state[ component ];
  567. },
  568. set: function set$$1( v ) {
  569. if ( this.__state.space !== 'RGB' ) {
  570. Color.recalculateRGB( this, component, componentHexIndex );
  571. this.__state.space = 'RGB';
  572. }
  573. this.__state[ component ] = v;
  574. }
  575. } );
  576. }
  577. function defineHSVComponent( target, component ) {
  578. Object.defineProperty( target, component, {
  579. get: function get$$1() {
  580. if ( this.__state.space === 'HSV' ) {
  581. return this.__state[ component ];
  582. }
  583. Color.recalculateHSV( this );
  584. return this.__state[ component ];
  585. },
  586. set: function set$$1( v ) {
  587. if ( this.__state.space !== 'HSV' ) {
  588. Color.recalculateHSV( this );
  589. this.__state.space = 'HSV';
  590. }
  591. this.__state[ component ] = v;
  592. }
  593. } );
  594. }
  595. Color.recalculateRGB = function ( color, component, componentHexIndex ) {
  596. if ( color.__state.space === 'HEX' ) {
  597. color.__state[ component ] = ColorMath.component_from_hex( color.__state.hex, componentHexIndex );
  598. } else if ( color.__state.space === 'HSV' ) {
  599. Common.extend( color.__state, ColorMath.hsv_to_rgb( color.__state.h, color.__state.s, color.__state.v ) );
  600. } else {
  601. throw new Error( 'Corrupted color state' );
  602. }
  603. };
  604. Color.recalculateHSV = function ( color ) {
  605. var result = ColorMath.rgb_to_hsv( color.r, color.g, color.b );
  606. Common.extend( color.__state, {
  607. s: result.s,
  608. v: result.v
  609. } );
  610. if ( ! Common.isNaN( result.h ) ) {
  611. color.__state.h = result.h;
  612. } else if ( Common.isUndefined( color.__state.h ) ) {
  613. color.__state.h = 0;
  614. }
  615. };
  616. Color.COMPONENTS = [ 'r', 'g', 'b', 'h', 's', 'v', 'hex', 'a' ];
  617. defineRGBComponent( Color.prototype, 'r', 2 );
  618. defineRGBComponent( Color.prototype, 'g', 1 );
  619. defineRGBComponent( Color.prototype, 'b', 0 );
  620. defineHSVComponent( Color.prototype, 'h' );
  621. defineHSVComponent( Color.prototype, 's' );
  622. defineHSVComponent( Color.prototype, 'v' );
  623. Object.defineProperty( Color.prototype, 'a', {
  624. get: function get$$1() {
  625. return this.__state.a;
  626. },
  627. set: function set$$1( v ) {
  628. this.__state.a = v;
  629. }
  630. } );
  631. Object.defineProperty( Color.prototype, 'hex', {
  632. get: function get$$1() {
  633. if ( ! this.__state.space !== 'HEX' ) {
  634. this.__state.hex = ColorMath.rgb_to_hex( this.r, this.g, this.b );
  635. }
  636. return this.__state.hex;
  637. },
  638. set: function set$$1( v ) {
  639. this.__state.space = 'HEX';
  640. this.__state.hex = v;
  641. }
  642. } );
  643. var Controller = function () {
  644. function Controller( object, property ) {
  645. classCallCheck( this, Controller );
  646. this.initialValue = object[ property ];
  647. this.domElement = document.createElement( 'div' );
  648. this.object = object;
  649. this.property = property;
  650. this.__onChange = undefined;
  651. this.__onFinishChange = undefined;
  652. }
  653. createClass( Controller, [ {
  654. key: 'onChange',
  655. value: function onChange( fnc ) {
  656. this.__onChange = fnc;
  657. return this;
  658. }
  659. }, {
  660. key: 'onFinishChange',
  661. value: function onFinishChange( fnc ) {
  662. this.__onFinishChange = fnc;
  663. return this;
  664. }
  665. }, {
  666. key: 'setValue',
  667. value: function setValue( newValue ) {
  668. this.object[ this.property ] = newValue;
  669. if ( this.__onChange ) {
  670. this.__onChange.call( this, newValue );
  671. }
  672. this.updateDisplay();
  673. return this;
  674. }
  675. }, {
  676. key: 'getValue',
  677. value: function getValue() {
  678. return this.object[ this.property ];
  679. }
  680. }, {
  681. key: 'updateDisplay',
  682. value: function updateDisplay() {
  683. return this;
  684. }
  685. }, {
  686. key: 'isModified',
  687. value: function isModified() {
  688. return this.initialValue !== this.getValue();
  689. }
  690. } ] );
  691. return Controller;
  692. }();
  693. var EVENT_MAP = {
  694. HTMLEvents: [ 'change' ],
  695. MouseEvents: [ 'click', 'mousemove', 'mousedown', 'mouseup', 'mouseover' ],
  696. KeyboardEvents: [ 'keydown' ]
  697. };
  698. var EVENT_MAP_INV = {};
  699. Common.each( EVENT_MAP, function ( v, k ) {
  700. Common.each( v, function ( e ) {
  701. EVENT_MAP_INV[ e ] = k;
  702. } );
  703. } );
  704. var CSS_VALUE_PIXELS = /(\d+(\.\d+)?)px/;
  705. function cssValueToPixels( val ) {
  706. if ( val === '0' || Common.isUndefined( val ) ) {
  707. return 0;
  708. }
  709. var match = val.match( CSS_VALUE_PIXELS );
  710. if ( ! Common.isNull( match ) ) {
  711. return parseFloat( match[ 1 ] );
  712. }
  713. return 0;
  714. }
  715. var dom = {
  716. makeSelectable: function makeSelectable( elem, selectable ) {
  717. if ( elem === undefined || elem.style === undefined ) return;
  718. elem.onselectstart = selectable ? function () {
  719. return false;
  720. } : function () {};
  721. elem.style.MozUserSelect = selectable ? 'auto' : 'none';
  722. elem.style.KhtmlUserSelect = selectable ? 'auto' : 'none';
  723. elem.unselectable = selectable ? 'on' : 'off';
  724. },
  725. makeFullscreen: function makeFullscreen( elem, hor, vert ) {
  726. var vertical = vert;
  727. var horizontal = hor;
  728. if ( Common.isUndefined( horizontal ) ) {
  729. horizontal = true;
  730. }
  731. if ( Common.isUndefined( vertical ) ) {
  732. vertical = true;
  733. }
  734. elem.style.position = 'absolute';
  735. if ( horizontal ) {
  736. elem.style.left = 0;
  737. elem.style.right = 0;
  738. }
  739. if ( vertical ) {
  740. elem.style.top = 0;
  741. elem.style.bottom = 0;
  742. }
  743. },
  744. fakeEvent: function fakeEvent( elem, eventType, pars, aux ) {
  745. var params = pars || {};
  746. var className = EVENT_MAP_INV[ eventType ];
  747. if ( ! className ) {
  748. throw new Error( 'Event type ' + eventType + ' not supported.' );
  749. }
  750. var evt = document.createEvent( className );
  751. switch ( className ) {
  752. case 'MouseEvents':
  753. {
  754. var clientX = params.x || params.clientX || 0;
  755. var clientY = params.y || params.clientY || 0;
  756. evt.initMouseEvent( eventType, params.bubbles || false, params.cancelable || true, window, params.clickCount || 1, 0,
  757. 0,
  758. clientX,
  759. clientY,
  760. false, false, false, false, 0, null );
  761. break;
  762. }
  763. case 'KeyboardEvents':
  764. {
  765. var init = evt.initKeyboardEvent || evt.initKeyEvent;
  766. Common.defaults( params, {
  767. cancelable: true,
  768. ctrlKey: false,
  769. altKey: false,
  770. shiftKey: false,
  771. metaKey: false,
  772. keyCode: undefined,
  773. charCode: undefined
  774. } );
  775. init( eventType, params.bubbles || false, params.cancelable, window, params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.keyCode, params.charCode );
  776. break;
  777. }
  778. default:
  779. {
  780. evt.initEvent( eventType, params.bubbles || false, params.cancelable || true );
  781. break;
  782. }
  783. }
  784. Common.defaults( evt, aux );
  785. elem.dispatchEvent( evt );
  786. },
  787. bind: function bind( elem, event, func, newBool ) {
  788. var bool = newBool || false;
  789. if ( elem.addEventListener ) {
  790. elem.addEventListener( event, func, bool );
  791. } else if ( elem.attachEvent ) {
  792. elem.attachEvent( 'on' + event, func );
  793. }
  794. return dom;
  795. },
  796. unbind: function unbind( elem, event, func, newBool ) {
  797. var bool = newBool || false;
  798. if ( elem.removeEventListener ) {
  799. elem.removeEventListener( event, func, bool );
  800. } else if ( elem.detachEvent ) {
  801. elem.detachEvent( 'on' + event, func );
  802. }
  803. return dom;
  804. },
  805. addClass: function addClass( elem, className ) {
  806. if ( elem.className === undefined ) {
  807. elem.className = className;
  808. } else if ( elem.className !== className ) {
  809. var classes = elem.className.split( / +/ );
  810. if ( classes.indexOf( className ) === - 1 ) {
  811. classes.push( className );
  812. elem.className = classes.join( ' ' ).replace( /^\s+/, '' ).replace( /\s+$/, '' );
  813. }
  814. }
  815. return dom;
  816. },
  817. removeClass: function removeClass( elem, className ) {
  818. if ( className ) {
  819. if ( elem.className === className ) {
  820. elem.removeAttribute( 'class' );
  821. } else {
  822. var classes = elem.className.split( / +/ );
  823. var index = classes.indexOf( className );
  824. if ( index !== - 1 ) {
  825. classes.splice( index, 1 );
  826. elem.className = classes.join( ' ' );
  827. }
  828. }
  829. } else {
  830. elem.className = undefined;
  831. }
  832. return dom;
  833. },
  834. hasClass: function hasClass( elem, className ) {
  835. return new RegExp( '(?:^|\\s+)' + className + '(?:\\s+|$)' ).test( elem.className ) || false;
  836. },
  837. getWidth: function getWidth( elem ) {
  838. var style = getComputedStyle( elem );
  839. return cssValueToPixels( style[ 'border-left-width' ] ) + cssValueToPixels( style[ 'border-right-width' ] ) + cssValueToPixels( style[ 'padding-left' ] ) + cssValueToPixels( style[ 'padding-right' ] ) + cssValueToPixels( style.width );
  840. },
  841. getHeight: function getHeight( elem ) {
  842. var style = getComputedStyle( elem );
  843. return cssValueToPixels( style[ 'border-top-width' ] ) + cssValueToPixels( style[ 'border-bottom-width' ] ) + cssValueToPixels( style[ 'padding-top' ] ) + cssValueToPixels( style[ 'padding-bottom' ] ) + cssValueToPixels( style.height );
  844. },
  845. getOffset: function getOffset( el ) {
  846. var elem = el;
  847. var offset = { left: 0, top: 0 };
  848. if ( elem.offsetParent ) {
  849. do {
  850. offset.left += elem.offsetLeft;
  851. offset.top += elem.offsetTop;
  852. elem = elem.offsetParent;
  853. } while ( elem );
  854. }
  855. return offset;
  856. },
  857. isActive: function isActive( elem ) {
  858. return elem === document.activeElement && ( elem.type || elem.href );
  859. }
  860. };
  861. var BooleanController = function ( _Controller ) {
  862. inherits( BooleanController, _Controller );
  863. function BooleanController( object, property ) {
  864. classCallCheck( this, BooleanController );
  865. var _this2 = possibleConstructorReturn( this, ( BooleanController.__proto__ || Object.getPrototypeOf( BooleanController ) ).call( this, object, property ) );
  866. var _this = _this2;
  867. _this2.__prev = _this2.getValue();
  868. _this2.__checkbox = document.createElement( 'input' );
  869. _this2.__checkbox.setAttribute( 'type', 'checkbox' );
  870. function onChange() {
  871. _this.setValue( ! _this.__prev );
  872. }
  873. dom.bind( _this2.__checkbox, 'change', onChange, false );
  874. _this2.domElement.appendChild( _this2.__checkbox );
  875. _this2.updateDisplay();
  876. return _this2;
  877. }
  878. createClass( BooleanController, [ {
  879. key: 'setValue',
  880. value: function setValue( v ) {
  881. var toReturn = get( BooleanController.prototype.__proto__ || Object.getPrototypeOf( BooleanController.prototype ), 'setValue', this ).call( this, v );
  882. if ( this.__onFinishChange ) {
  883. this.__onFinishChange.call( this, this.getValue() );
  884. }
  885. this.__prev = this.getValue();
  886. return toReturn;
  887. }
  888. }, {
  889. key: 'updateDisplay',
  890. value: function updateDisplay() {
  891. if ( this.getValue() === true ) {
  892. this.__checkbox.setAttribute( 'checked', 'checked' );
  893. this.__checkbox.checked = true;
  894. this.__prev = true;
  895. } else {
  896. this.__checkbox.checked = false;
  897. this.__prev = false;
  898. }
  899. return get( BooleanController.prototype.__proto__ || Object.getPrototypeOf( BooleanController.prototype ), 'updateDisplay', this ).call( this );
  900. }
  901. } ] );
  902. return BooleanController;
  903. }( Controller );
  904. var OptionController = function ( _Controller ) {
  905. inherits( OptionController, _Controller );
  906. function OptionController( object, property, opts ) {
  907. classCallCheck( this, OptionController );
  908. var _this2 = possibleConstructorReturn( this, ( OptionController.__proto__ || Object.getPrototypeOf( OptionController ) ).call( this, object, property ) );
  909. var options = opts;
  910. var _this = _this2;
  911. _this2.__select = document.createElement( 'select' );
  912. if ( Common.isArray( options ) ) {
  913. var map = {};
  914. Common.each( options, function ( element ) {
  915. map[ element ] = element;
  916. } );
  917. options = map;
  918. }
  919. Common.each( options, function ( value, key ) {
  920. var opt = document.createElement( 'option' );
  921. opt.innerHTML = key;
  922. opt.setAttribute( 'value', value );
  923. _this.__select.appendChild( opt );
  924. } );
  925. _this2.updateDisplay();
  926. dom.bind( _this2.__select, 'change', function () {
  927. var desiredValue = this.options[ this.selectedIndex ].value;
  928. _this.setValue( desiredValue );
  929. } );
  930. _this2.domElement.appendChild( _this2.__select );
  931. return _this2;
  932. }
  933. createClass( OptionController, [ {
  934. key: 'setValue',
  935. value: function setValue( v ) {
  936. var toReturn = get( OptionController.prototype.__proto__ || Object.getPrototypeOf( OptionController.prototype ), 'setValue', this ).call( this, v );
  937. if ( this.__onFinishChange ) {
  938. this.__onFinishChange.call( this, this.getValue() );
  939. }
  940. return toReturn;
  941. }
  942. }, {
  943. key: 'updateDisplay',
  944. value: function updateDisplay() {
  945. if ( dom.isActive( this.__select ) ) return this;
  946. this.__select.value = this.getValue();
  947. return get( OptionController.prototype.__proto__ || Object.getPrototypeOf( OptionController.prototype ), 'updateDisplay', this ).call( this );
  948. }
  949. } ] );
  950. return OptionController;
  951. }( Controller );
  952. var StringController = function ( _Controller ) {
  953. inherits( StringController, _Controller );
  954. function StringController( object, property ) {
  955. classCallCheck( this, StringController );
  956. var _this2 = possibleConstructorReturn( this, ( StringController.__proto__ || Object.getPrototypeOf( StringController ) ).call( this, object, property ) );
  957. var _this = _this2;
  958. function onChange() {
  959. _this.setValue( _this.__input.value );
  960. }
  961. function onBlur() {
  962. if ( _this.__onFinishChange ) {
  963. _this.__onFinishChange.call( _this, _this.getValue() );
  964. }
  965. }
  966. _this2.__input = document.createElement( 'input' );
  967. _this2.__input.setAttribute( 'type', 'text' );
  968. dom.bind( _this2.__input, 'keyup', onChange );
  969. dom.bind( _this2.__input, 'change', onChange );
  970. dom.bind( _this2.__input, 'blur', onBlur );
  971. dom.bind( _this2.__input, 'keydown', function ( e ) {
  972. if ( e.keyCode === 13 ) {
  973. this.blur();
  974. }
  975. } );
  976. _this2.updateDisplay();
  977. _this2.domElement.appendChild( _this2.__input );
  978. return _this2;
  979. }
  980. createClass( StringController, [ {
  981. key: 'updateDisplay',
  982. value: function updateDisplay() {
  983. if ( ! dom.isActive( this.__input ) ) {
  984. this.__input.value = this.getValue();
  985. }
  986. return get( StringController.prototype.__proto__ || Object.getPrototypeOf( StringController.prototype ), 'updateDisplay', this ).call( this );
  987. }
  988. } ] );
  989. return StringController;
  990. }( Controller );
  991. function numDecimals( x ) {
  992. var _x = x.toString();
  993. if ( _x.indexOf( '.' ) > - 1 ) {
  994. return _x.length - _x.indexOf( '.' ) - 1;
  995. }
  996. return 0;
  997. }
  998. var NumberController = function ( _Controller ) {
  999. inherits( NumberController, _Controller );
  1000. function NumberController( object, property, params ) {
  1001. classCallCheck( this, NumberController );
  1002. var _this = possibleConstructorReturn( this, ( NumberController.__proto__ || Object.getPrototypeOf( NumberController ) ).call( this, object, property ) );
  1003. var _params = params || {};
  1004. _this.__min = _params.min;
  1005. _this.__max = _params.max;
  1006. _this.__step = _params.step;
  1007. if ( Common.isUndefined( _this.__step ) ) {
  1008. if ( _this.initialValue === 0 ) {
  1009. _this.__impliedStep = 1;
  1010. } else {
  1011. _this.__impliedStep = Math.pow( 10, Math.floor( Math.log( Math.abs( _this.initialValue ) ) / Math.LN10 ) ) / 10;
  1012. }
  1013. } else {
  1014. _this.__impliedStep = _this.__step;
  1015. }
  1016. _this.__precision = numDecimals( _this.__impliedStep );
  1017. return _this;
  1018. }
  1019. createClass( NumberController, [ {
  1020. key: 'setValue',
  1021. value: function setValue( v ) {
  1022. var _v = v;
  1023. if ( this.__min !== undefined && _v < this.__min ) {
  1024. _v = this.__min;
  1025. } else if ( this.__max !== undefined && _v > this.__max ) {
  1026. _v = this.__max;
  1027. }
  1028. if ( this.__step !== undefined && _v % this.__step !== 0 ) {
  1029. _v = Math.round( _v / this.__step ) * this.__step;
  1030. }
  1031. return get( NumberController.prototype.__proto__ || Object.getPrototypeOf( NumberController.prototype ), 'setValue', this ).call( this, _v );
  1032. }
  1033. }, {
  1034. key: 'min',
  1035. value: function min( minValue ) {
  1036. this.__min = minValue;
  1037. return this;
  1038. }
  1039. }, {
  1040. key: 'max',
  1041. value: function max( maxValue ) {
  1042. this.__max = maxValue;
  1043. return this;
  1044. }
  1045. }, {
  1046. key: 'step',
  1047. value: function step( stepValue ) {
  1048. this.__step = stepValue;
  1049. this.__impliedStep = stepValue;
  1050. this.__precision = numDecimals( stepValue );
  1051. return this;
  1052. }
  1053. } ] );
  1054. return NumberController;
  1055. }( Controller );
  1056. function roundToDecimal( value, decimals ) {
  1057. var tenTo = Math.pow( 10, decimals );
  1058. return Math.round( value * tenTo ) / tenTo;
  1059. }
  1060. var NumberControllerBox = function ( _NumberController ) {
  1061. inherits( NumberControllerBox, _NumberController );
  1062. function NumberControllerBox( object, property, params ) {
  1063. classCallCheck( this, NumberControllerBox );
  1064. var _this2 = possibleConstructorReturn( this, ( NumberControllerBox.__proto__ || Object.getPrototypeOf( NumberControllerBox ) ).call( this, object, property, params ) );
  1065. _this2.__truncationSuspended = false;
  1066. var _this = _this2;
  1067. var prevY = void 0;
  1068. function onChange() {
  1069. var attempted = parseFloat( _this.__input.value );
  1070. if ( ! Common.isNaN( attempted ) ) {
  1071. _this.setValue( attempted );
  1072. }
  1073. }
  1074. function onFinish() {
  1075. if ( _this.__onFinishChange ) {
  1076. _this.__onFinishChange.call( _this, _this.getValue() );
  1077. }
  1078. }
  1079. function onBlur() {
  1080. onFinish();
  1081. }
  1082. function onMouseDrag( e ) {
  1083. var diff = prevY - e.clientY;
  1084. _this.setValue( _this.getValue() + diff * _this.__impliedStep );
  1085. prevY = e.clientY;
  1086. }
  1087. function onMouseUp() {
  1088. dom.unbind( window, 'mousemove', onMouseDrag );
  1089. dom.unbind( window, 'mouseup', onMouseUp );
  1090. onFinish();
  1091. }
  1092. function onMouseDown( e ) {
  1093. dom.bind( window, 'mousemove', onMouseDrag );
  1094. dom.bind( window, 'mouseup', onMouseUp );
  1095. prevY = e.clientY;
  1096. }
  1097. _this2.__input = document.createElement( 'input' );
  1098. _this2.__input.setAttribute( 'type', 'text' );
  1099. dom.bind( _this2.__input, 'change', onChange );
  1100. dom.bind( _this2.__input, 'blur', onBlur );
  1101. dom.bind( _this2.__input, 'mousedown', onMouseDown );
  1102. dom.bind( _this2.__input, 'keydown', function ( e ) {
  1103. if ( e.keyCode === 13 ) {
  1104. _this.__truncationSuspended = true;
  1105. this.blur();
  1106. _this.__truncationSuspended = false;
  1107. onFinish();
  1108. }
  1109. } );
  1110. _this2.updateDisplay();
  1111. _this2.domElement.appendChild( _this2.__input );
  1112. return _this2;
  1113. }
  1114. createClass( NumberControllerBox, [ {
  1115. key: 'updateDisplay',
  1116. value: function updateDisplay() {
  1117. this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal( this.getValue(), this.__precision );
  1118. return get( NumberControllerBox.prototype.__proto__ || Object.getPrototypeOf( NumberControllerBox.prototype ), 'updateDisplay', this ).call( this );
  1119. }
  1120. } ] );
  1121. return NumberControllerBox;
  1122. }( NumberController );
  1123. function map( v, i1, i2, o1, o2 ) {
  1124. return o1 + ( o2 - o1 ) * ( ( v - i1 ) / ( i2 - i1 ) );
  1125. }
  1126. var NumberControllerSlider = function ( _NumberController ) {
  1127. inherits( NumberControllerSlider, _NumberController );
  1128. function NumberControllerSlider( object, property, min, max, step ) {
  1129. classCallCheck( this, NumberControllerSlider );
  1130. var _this2 = possibleConstructorReturn( this, ( NumberControllerSlider.__proto__ || Object.getPrototypeOf( NumberControllerSlider ) ).call( this, object, property, { min: min, max: max, step: step } ) );
  1131. var _this = _this2;
  1132. _this2.__background = document.createElement( 'div' );
  1133. _this2.__foreground = document.createElement( 'div' );
  1134. dom.bind( _this2.__background, 'mousedown', onMouseDown );
  1135. dom.bind( _this2.__background, 'touchstart', onTouchStart );
  1136. dom.addClass( _this2.__background, 'slider' );
  1137. dom.addClass( _this2.__foreground, 'slider-fg' );
  1138. function onMouseDown( e ) {
  1139. document.activeElement.blur();
  1140. dom.bind( window, 'mousemove', onMouseDrag );
  1141. dom.bind( window, 'mouseup', onMouseUp );
  1142. onMouseDrag( e );
  1143. }
  1144. function onMouseDrag( e ) {
  1145. e.preventDefault();
  1146. var bgRect = _this.__background.getBoundingClientRect();
  1147. _this.setValue( map( e.clientX, bgRect.left, bgRect.right, _this.__min, _this.__max ) );
  1148. return false;
  1149. }
  1150. function onMouseUp() {
  1151. dom.unbind( window, 'mousemove', onMouseDrag );
  1152. dom.unbind( window, 'mouseup', onMouseUp );
  1153. if ( _this.__onFinishChange ) {
  1154. _this.__onFinishChange.call( _this, _this.getValue() );
  1155. }
  1156. }
  1157. function onTouchStart( e ) {
  1158. if ( e.touches.length !== 1 ) {
  1159. return;
  1160. }
  1161. dom.bind( window, 'touchmove', onTouchMove );
  1162. dom.bind( window, 'touchend', onTouchEnd );
  1163. onTouchMove( e );
  1164. }
  1165. function onTouchMove( e ) {
  1166. var clientX = e.touches[ 0 ].clientX;
  1167. var bgRect = _this.__background.getBoundingClientRect();
  1168. _this.setValue( map( clientX, bgRect.left, bgRect.right, _this.__min, _this.__max ) );
  1169. }
  1170. function onTouchEnd() {
  1171. dom.unbind( window, 'touchmove', onTouchMove );
  1172. dom.unbind( window, 'touchend', onTouchEnd );
  1173. if ( _this.__onFinishChange ) {
  1174. _this.__onFinishChange.call( _this, _this.getValue() );
  1175. }
  1176. }
  1177. _this2.updateDisplay();
  1178. _this2.__background.appendChild( _this2.__foreground );
  1179. _this2.domElement.appendChild( _this2.__background );
  1180. return _this2;
  1181. }
  1182. createClass( NumberControllerSlider, [ {
  1183. key: 'updateDisplay',
  1184. value: function updateDisplay() {
  1185. var pct = ( this.getValue() - this.__min ) / ( this.__max - this.__min );
  1186. this.__foreground.style.width = pct * 100 + '%';
  1187. return get( NumberControllerSlider.prototype.__proto__ || Object.getPrototypeOf( NumberControllerSlider.prototype ), 'updateDisplay', this ).call( this );
  1188. }
  1189. } ] );
  1190. return NumberControllerSlider;
  1191. }( NumberController );
  1192. var FunctionController = function ( _Controller ) {
  1193. inherits( FunctionController, _Controller );
  1194. function FunctionController( object, property, text ) {
  1195. classCallCheck( this, FunctionController );
  1196. var _this2 = possibleConstructorReturn( this, ( FunctionController.__proto__ || Object.getPrototypeOf( FunctionController ) ).call( this, object, property ) );
  1197. var _this = _this2;
  1198. _this2.__button = document.createElement( 'div' );
  1199. _this2.__button.innerHTML = text === undefined ? 'Fire' : text;
  1200. dom.bind( _this2.__button, 'click', function ( e ) {
  1201. e.preventDefault();
  1202. _this.fire();
  1203. return false;
  1204. } );
  1205. dom.addClass( _this2.__button, 'button' );
  1206. _this2.domElement.appendChild( _this2.__button );
  1207. return _this2;
  1208. }
  1209. createClass( FunctionController, [ {
  1210. key: 'fire',
  1211. value: function fire() {
  1212. if ( this.__onChange ) {
  1213. this.__onChange.call( this );
  1214. }
  1215. this.getValue().call( this.object );
  1216. if ( this.__onFinishChange ) {
  1217. this.__onFinishChange.call( this, this.getValue() );
  1218. }
  1219. }
  1220. } ] );
  1221. return FunctionController;
  1222. }( Controller );
  1223. var ColorController = function ( _Controller ) {
  1224. inherits( ColorController, _Controller );
  1225. function ColorController( object, property ) {
  1226. classCallCheck( this, ColorController );
  1227. var _this2 = possibleConstructorReturn( this, ( ColorController.__proto__ || Object.getPrototypeOf( ColorController ) ).call( this, object, property ) );
  1228. _this2.__color = new Color( _this2.getValue() );
  1229. _this2.__temp = new Color( 0 );
  1230. var _this = _this2;
  1231. _this2.domElement = document.createElement( 'div' );
  1232. dom.makeSelectable( _this2.domElement, false );
  1233. _this2.__selector = document.createElement( 'div' );
  1234. _this2.__selector.className = 'selector';
  1235. _this2.__saturation_field = document.createElement( 'div' );
  1236. _this2.__saturation_field.className = 'saturation-field';
  1237. _this2.__field_knob = document.createElement( 'div' );
  1238. _this2.__field_knob.className = 'field-knob';
  1239. _this2.__field_knob_border = '2px solid ';
  1240. _this2.__hue_knob = document.createElement( 'div' );
  1241. _this2.__hue_knob.className = 'hue-knob';
  1242. _this2.__hue_field = document.createElement( 'div' );
  1243. _this2.__hue_field.className = 'hue-field';
  1244. _this2.__input = document.createElement( 'input' );
  1245. _this2.__input.type = 'text';
  1246. _this2.__input_textShadow = '0 1px 1px ';
  1247. dom.bind( _this2.__input, 'keydown', function ( e ) {
  1248. if ( e.keyCode === 13 ) {
  1249. onBlur.call( this );
  1250. }
  1251. } );
  1252. dom.bind( _this2.__input, 'blur', onBlur );
  1253. dom.bind( _this2.__selector, 'mousedown', function () {
  1254. dom.addClass( this, 'drag' ).bind( window, 'mouseup', function () {
  1255. dom.removeClass( _this.__selector, 'drag' );
  1256. } );
  1257. } );
  1258. dom.bind( _this2.__selector, 'touchstart', function () {
  1259. dom.addClass( this, 'drag' ).bind( window, 'touchend', function () {
  1260. dom.removeClass( _this.__selector, 'drag' );
  1261. } );
  1262. } );
  1263. var valueField = document.createElement( 'div' );
  1264. Common.extend( _this2.__selector.style, {
  1265. width: '122px',
  1266. height: '102px',
  1267. padding: '3px',
  1268. backgroundColor: '#222',
  1269. boxShadow: '0px 1px 3px rgba(0,0,0,0.3)'
  1270. } );
  1271. Common.extend( _this2.__field_knob.style, {
  1272. position: 'absolute',
  1273. width: '12px',
  1274. height: '12px',
  1275. border: _this2.__field_knob_border + ( _this2.__color.v < 0.5 ? '#fff' : '#000' ),
  1276. boxShadow: '0px 1px 3px rgba(0,0,0,0.5)',
  1277. borderRadius: '12px',
  1278. zIndex: 1
  1279. } );
  1280. Common.extend( _this2.__hue_knob.style, {
  1281. position: 'absolute',
  1282. width: '15px',
  1283. height: '2px',
  1284. borderRight: '4px solid #fff',
  1285. zIndex: 1
  1286. } );
  1287. Common.extend( _this2.__saturation_field.style, {
  1288. width: '100px',
  1289. height: '100px',
  1290. border: '1px solid #555',
  1291. marginRight: '3px',
  1292. display: 'inline-block',
  1293. cursor: 'pointer'
  1294. } );
  1295. Common.extend( valueField.style, {
  1296. width: '100%',
  1297. height: '100%',
  1298. background: 'none'
  1299. } );
  1300. linearGradient( valueField, 'top', 'rgba(0,0,0,0)', '#000' );
  1301. Common.extend( _this2.__hue_field.style, {
  1302. width: '15px',
  1303. height: '100px',
  1304. border: '1px solid #555',
  1305. cursor: 'ns-resize',
  1306. position: 'absolute',
  1307. top: '3px',
  1308. right: '3px'
  1309. } );
  1310. hueGradient( _this2.__hue_field );
  1311. Common.extend( _this2.__input.style, {
  1312. outline: 'none',
  1313. textAlign: 'center',
  1314. color: '#fff',
  1315. border: 0,
  1316. fontWeight: 'bold',
  1317. textShadow: _this2.__input_textShadow + 'rgba(0,0,0,0.7)'
  1318. } );
  1319. dom.bind( _this2.__saturation_field, 'mousedown', fieldDown );
  1320. dom.bind( _this2.__saturation_field, 'touchstart', fieldDown );
  1321. dom.bind( _this2.__field_knob, 'mousedown', fieldDown );
  1322. dom.bind( _this2.__field_knob, 'touchstart', fieldDown );
  1323. dom.bind( _this2.__hue_field, 'mousedown', fieldDownH );
  1324. dom.bind( _this2.__hue_field, 'touchstart', fieldDownH );
  1325. function fieldDown( e ) {
  1326. setSV( e );
  1327. dom.bind( window, 'mousemove', setSV );
  1328. dom.bind( window, 'touchmove', setSV );
  1329. dom.bind( window, 'mouseup', fieldUpSV );
  1330. dom.bind( window, 'touchend', fieldUpSV );
  1331. }
  1332. function fieldDownH( e ) {
  1333. setH( e );
  1334. dom.bind( window, 'mousemove', setH );
  1335. dom.bind( window, 'touchmove', setH );
  1336. dom.bind( window, 'mouseup', fieldUpH );
  1337. dom.bind( window, 'touchend', fieldUpH );
  1338. }
  1339. function fieldUpSV() {
  1340. dom.unbind( window, 'mousemove', setSV );
  1341. dom.unbind( window, 'touchmove', setSV );
  1342. dom.unbind( window, 'mouseup', fieldUpSV );
  1343. dom.unbind( window, 'touchend', fieldUpSV );
  1344. onFinish();
  1345. }
  1346. function fieldUpH() {
  1347. dom.unbind( window, 'mousemove', setH );
  1348. dom.unbind( window, 'touchmove', setH );
  1349. dom.unbind( window, 'mouseup', fieldUpH );
  1350. dom.unbind( window, 'touchend', fieldUpH );
  1351. onFinish();
  1352. }
  1353. function onBlur() {
  1354. var i = interpret( this.value );
  1355. if ( i !== false ) {
  1356. _this.__color.__state = i;
  1357. _this.setValue( _this.__color.toOriginal() );
  1358. } else {
  1359. this.value = _this.__color.toString();
  1360. }
  1361. }
  1362. function onFinish() {
  1363. if ( _this.__onFinishChange ) {
  1364. _this.__onFinishChange.call( _this, _this.__color.toOriginal() );
  1365. }
  1366. }
  1367. _this2.__saturation_field.appendChild( valueField );
  1368. _this2.__selector.appendChild( _this2.__field_knob );
  1369. _this2.__selector.appendChild( _this2.__saturation_field );
  1370. _this2.__selector.appendChild( _this2.__hue_field );
  1371. _this2.__hue_field.appendChild( _this2.__hue_knob );
  1372. _this2.domElement.appendChild( _this2.__input );
  1373. _this2.domElement.appendChild( _this2.__selector );
  1374. _this2.updateDisplay();
  1375. function setSV( e ) {
  1376. if ( e.type.indexOf( 'touch' ) === - 1 ) {
  1377. e.preventDefault();
  1378. }
  1379. var fieldRect = _this.__saturation_field.getBoundingClientRect();
  1380. var _ref = e.touches && e.touches[ 0 ] || e,
  1381. clientX = _ref.clientX,
  1382. clientY = _ref.clientY;
  1383. var s = ( clientX - fieldRect.left ) / ( fieldRect.right - fieldRect.left );
  1384. var v = 1 - ( clientY - fieldRect.top ) / ( fieldRect.bottom - fieldRect.top );
  1385. if ( v > 1 ) {
  1386. v = 1;
  1387. } else if ( v < 0 ) {
  1388. v = 0;
  1389. }
  1390. if ( s > 1 ) {
  1391. s = 1;
  1392. } else if ( s < 0 ) {
  1393. s = 0;
  1394. }
  1395. _this.__color.v = v;
  1396. _this.__color.s = s;
  1397. _this.setValue( _this.__color.toOriginal() );
  1398. return false;
  1399. }
  1400. function setH( e ) {
  1401. if ( e.type.indexOf( 'touch' ) === - 1 ) {
  1402. e.preventDefault();
  1403. }
  1404. var fieldRect = _this.__hue_field.getBoundingClientRect();
  1405. var _ref2 = e.touches && e.touches[ 0 ] || e,
  1406. clientY = _ref2.clientY;
  1407. var h = 1 - ( clientY - fieldRect.top ) / ( fieldRect.bottom - fieldRect.top );
  1408. if ( h > 1 ) {
  1409. h = 1;
  1410. } else if ( h < 0 ) {
  1411. h = 0;
  1412. }
  1413. _this.__color.h = h * 360;
  1414. _this.setValue( _this.__color.toOriginal() );
  1415. return false;
  1416. }
  1417. return _this2;
  1418. }
  1419. createClass( ColorController, [ {
  1420. key: 'updateDisplay',
  1421. value: function updateDisplay() {
  1422. var i = interpret( this.getValue() );
  1423. if ( i !== false ) {
  1424. var mismatch = false;
  1425. Common.each( Color.COMPONENTS, function ( component ) {
  1426. if ( ! Common.isUndefined( i[ component ] ) && ! Common.isUndefined( this.__color.__state[ component ] ) && i[ component ] !== this.__color.__state[ component ] ) {
  1427. mismatch = true;
  1428. return {};
  1429. }
  1430. }, this );
  1431. if ( mismatch ) {
  1432. Common.extend( this.__color.__state, i );
  1433. }
  1434. }
  1435. Common.extend( this.__temp.__state, this.__color.__state );
  1436. this.__temp.a = 1;
  1437. var flip = this.__color.v < 0.5 || this.__color.s > 0.5 ? 255 : 0;
  1438. var _flip = 255 - flip;
  1439. Common.extend( this.__field_knob.style, {
  1440. marginLeft: 100 * this.__color.s - 7 + 'px',
  1441. marginTop: 100 * ( 1 - this.__color.v ) - 7 + 'px',
  1442. backgroundColor: this.__temp.toHexString(),
  1443. border: this.__field_knob_border + 'rgb(' + flip + ',' + flip + ',' + flip + ')'
  1444. } );
  1445. this.__hue_knob.style.marginTop = ( 1 - this.__color.h / 360 ) * 100 + 'px';
  1446. this.__temp.s = 1;
  1447. this.__temp.v = 1;
  1448. linearGradient( this.__saturation_field, 'left', '#fff', this.__temp.toHexString() );
  1449. this.__input.value = this.__color.toString();
  1450. Common.extend( this.__input.style, {
  1451. backgroundColor: this.__color.toHexString(),
  1452. color: 'rgb(' + flip + ',' + flip + ',' + flip + ')',
  1453. textShadow: this.__input_textShadow + 'rgba(' + _flip + ',' + _flip + ',' + _flip + ',.7)'
  1454. } );
  1455. }
  1456. } ] );
  1457. return ColorController;
  1458. }( Controller );
  1459. var vendors = [ '-moz-', '-o-', '-webkit-', '-ms-', '' ];
  1460. function linearGradient( elem, x, a, b ) {
  1461. elem.style.background = '';
  1462. Common.each( vendors, function ( vendor ) {
  1463. elem.style.cssText += 'background: ' + vendor + 'linear-gradient(' + x + ', ' + a + ' 0%, ' + b + ' 100%); ';
  1464. } );
  1465. }
  1466. function hueGradient( elem ) {
  1467. elem.style.background = '';
  1468. elem.style.cssText += 'background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);';
  1469. elem.style.cssText += 'background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
  1470. elem.style.cssText += 'background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
  1471. elem.style.cssText += 'background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
  1472. elem.style.cssText += 'background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
  1473. }
  1474. var css = {
  1475. load: function load( url, indoc ) {
  1476. var doc = indoc || document;
  1477. var link = doc.createElement( 'link' );
  1478. link.type = 'text/css';
  1479. link.rel = 'stylesheet';
  1480. link.href = url;
  1481. doc.getElementsByTagName( 'head' )[ 0 ].appendChild( link );
  1482. },
  1483. inject: function inject( cssContent, indoc ) {
  1484. var doc = indoc || document;
  1485. var injected = document.createElement( 'style' );
  1486. injected.type = 'text/css';
  1487. injected.innerHTML = cssContent;
  1488. var head = doc.getElementsByTagName( 'head' )[ 0 ];
  1489. try {
  1490. head.appendChild( injected );
  1491. } catch ( e ) {
  1492. }
  1493. }
  1494. };
  1495. var saveDialogContents = "<div id=\"dg-save\" class=\"dg dialogue\">\n\n Here's the new load parameter for your <code>GUI</code>'s constructor:\n\n <textarea id=\"dg-new-constructor\"></textarea>\n\n <div id=\"dg-save-locally\">\n\n <input id=\"dg-local-storage\" type=\"checkbox\"/> Automatically save\n values to <code>localStorage</code> on exit.\n\n <div id=\"dg-local-explain\">The values saved to <code>localStorage</code> will\n override those passed to <code>dat.GUI</code>'s constructor. This makes it\n easier to work incrementally, but <code>localStorage</code> is fragile,\n and your friends may not see the same values you do.\n\n </div>\n\n </div>\n\n</div>";
  1496. var ControllerFactory = function ControllerFactory( object, property ) {
  1497. var initialValue = object[ property ];
  1498. if ( Common.isArray( arguments[ 2 ] ) || Common.isObject( arguments[ 2 ] ) ) {
  1499. return new OptionController( object, property, arguments[ 2 ] );
  1500. }
  1501. if ( Common.isNumber( initialValue ) ) {
  1502. if ( Common.isNumber( arguments[ 2 ] ) && Common.isNumber( arguments[ 3 ] ) ) {
  1503. if ( Common.isNumber( arguments[ 4 ] ) ) {
  1504. return new NumberControllerSlider( object, property, arguments[ 2 ], arguments[ 3 ], arguments[ 4 ] );
  1505. }
  1506. return new NumberControllerSlider( object, property, arguments[ 2 ], arguments[ 3 ] );
  1507. }
  1508. if ( Common.isNumber( arguments[ 4 ] ) ) {
  1509. return new NumberControllerBox( object, property, { min: arguments[ 2 ], max: arguments[ 3 ], step: arguments[ 4 ] } );
  1510. }
  1511. return new NumberControllerBox( object, property, { min: arguments[ 2 ], max: arguments[ 3 ] } );
  1512. }
  1513. if ( Common.isString( initialValue ) ) {
  1514. return new StringController( object, property );
  1515. }
  1516. if ( Common.isFunction( initialValue ) ) {
  1517. return new FunctionController( object, property, '' );
  1518. }
  1519. if ( Common.isBoolean( initialValue ) ) {
  1520. return new BooleanController( object, property );
  1521. }
  1522. return null;
  1523. };
  1524. function requestAnimationFrame( callback ) {
  1525. setTimeout( callback, 1000 / 60 );
  1526. }
  1527. var requestAnimationFrame$1 = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || requestAnimationFrame;
  1528. var CenteredDiv = function () {
  1529. function CenteredDiv() {
  1530. classCallCheck( this, CenteredDiv );
  1531. this.backgroundElement = document.createElement( 'div' );
  1532. Common.extend( this.backgroundElement.style, {
  1533. backgroundColor: 'rgba(0,0,0,0.8)',
  1534. top: 0,
  1535. left: 0,
  1536. display: 'none',
  1537. zIndex: '1000',
  1538. opacity: 0,
  1539. WebkitTransition: 'opacity 0.2s linear',
  1540. transition: 'opacity 0.2s linear'
  1541. } );
  1542. dom.makeFullscreen( this.backgroundElement );
  1543. this.backgroundElement.style.position = 'fixed';
  1544. this.domElement = document.createElement( 'div' );
  1545. Common.extend( this.domElement.style, {
  1546. position: 'fixed',
  1547. display: 'none',
  1548. zIndex: '1001',
  1549. opacity: 0,
  1550. WebkitTransition: '-webkit-transform 0.2s ease-out, opacity 0.2s linear',
  1551. transition: 'transform 0.2s ease-out, opacity 0.2s linear'
  1552. } );
  1553. document.body.appendChild( this.backgroundElement );
  1554. document.body.appendChild( this.domElement );
  1555. var _this = this;
  1556. dom.bind( this.backgroundElement, 'click', function () {
  1557. _this.hide();
  1558. } );
  1559. }
  1560. createClass( CenteredDiv, [ {
  1561. key: 'show',
  1562. value: function show() {
  1563. var _this = this;
  1564. this.backgroundElement.style.display = 'block';
  1565. this.domElement.style.display = 'block';
  1566. this.domElement.style.opacity = 0;
  1567. this.domElement.style.webkitTransform = 'scale(1.1)';
  1568. this.layout();
  1569. Common.defer( function () {
  1570. _this.backgroundElement.style.opacity = 1;
  1571. _this.domElement.style.opacity = 1;
  1572. _this.domElement.style.webkitTransform = 'scale(1)';
  1573. } );
  1574. }
  1575. }, {
  1576. key: 'hide',
  1577. value: function hide() {
  1578. var _this = this;
  1579. var hide = function hide() {
  1580. _this.domElement.style.display = 'none';
  1581. _this.backgroundElement.style.display = 'none';
  1582. dom.unbind( _this.domElement, 'webkitTransitionEnd', hide );
  1583. dom.unbind( _this.domElement, 'transitionend', hide );
  1584. dom.unbind( _this.domElement, 'oTransitionEnd', hide );
  1585. };
  1586. dom.bind( this.domElement, 'webkitTransitionEnd', hide );
  1587. dom.bind( this.domElement, 'transitionend', hide );
  1588. dom.bind( this.domElement, 'oTransitionEnd', hide );
  1589. this.backgroundElement.style.opacity = 0;
  1590. this.domElement.style.opacity = 0;
  1591. this.domElement.style.webkitTransform = 'scale(1.1)';
  1592. }
  1593. }, {
  1594. key: 'layout',
  1595. value: function layout() {
  1596. this.domElement.style.left = window.innerWidth / 2 - dom.getWidth( this.domElement ) / 2 + 'px';
  1597. this.domElement.style.top = window.innerHeight / 2 - dom.getHeight( this.domElement ) / 2 + 'px';
  1598. }
  1599. } ] );
  1600. return CenteredDiv;
  1601. }();
  1602. var styleSheet = ___$insertStyle( ".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear;border:0;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button.close-top{position:relative}.dg.main .close-button.close-bottom{position:absolute}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-y:visible}.dg.a.has-save>ul.close-top{margin-top:0}.dg.a.has-save>ul.close-bottom{margin-top:27px}.dg.a.has-save>ul.closed{margin-top:0}.dg.a .save-row{top:0;z-index:1002}.dg.a .save-row.close-top{position:relative}.dg.a .save-row.close-bottom{position:fixed}.dg li{-webkit-transition:height .1s ease-out;-o-transition:height .1s ease-out;-moz-transition:height .1s ease-out;transition:height .1s ease-out;-webkit-transition:overflow .1s linear;-o-transition:overflow .1s linear;-moz-transition:overflow .1s linear;transition:overflow .1s linear}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li>*{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px;overflow:hidden}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%;position:relative}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:7px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .cr.color{overflow:visible}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.color{border-left:3px solid}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2FA1D6}.dg .cr.number input[type=text]{color:#2FA1D6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2FA1D6;max-width:100%}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n" );
  1603. css.inject( styleSheet );
  1604. var CSS_NAMESPACE = 'dg';
  1605. var HIDE_KEY_CODE = 72;
  1606. var CLOSE_BUTTON_HEIGHT = 20;
  1607. var DEFAULT_DEFAULT_PRESET_NAME = 'Default';
  1608. var SUPPORTS_LOCAL_STORAGE = function () {
  1609. try {
  1610. return !! window.localStorage;
  1611. } catch ( e ) {
  1612. return false;
  1613. }
  1614. }();
  1615. var SAVE_DIALOGUE = void 0;
  1616. var autoPlaceVirgin = true;
  1617. var autoPlaceContainer = void 0;
  1618. var hide = false;
  1619. var hideableGuis = [];
  1620. var GUI = function GUI( pars ) {
  1621. var _this = this;
  1622. var params = pars || {};
  1623. this.domElement = document.createElement( 'div' );
  1624. this.__ul = document.createElement( 'ul' );
  1625. this.domElement.appendChild( this.__ul );
  1626. dom.addClass( this.domElement, CSS_NAMESPACE );
  1627. this.__folders = {};
  1628. this.__controllers = [];
  1629. this.__rememberedObjects = [];
  1630. this.__rememberedObjectIndecesToControllers = [];
  1631. this.__listening = [];
  1632. params = Common.defaults( params, {
  1633. closeOnTop: false,
  1634. autoPlace: true,
  1635. width: GUI.DEFAULT_WIDTH
  1636. } );
  1637. params = Common.defaults( params, {
  1638. resizable: params.autoPlace,
  1639. hideable: params.autoPlace
  1640. } );
  1641. if ( ! Common.isUndefined( params.load ) ) {
  1642. if ( params.preset ) {
  1643. params.load.preset = params.preset;
  1644. }
  1645. } else {
  1646. params.load = { preset: DEFAULT_DEFAULT_PRESET_NAME };
  1647. }
  1648. if ( Common.isUndefined( params.parent ) && params.hideable ) {
  1649. hideableGuis.push( this );
  1650. }
  1651. params.resizable = Common.isUndefined( params.parent ) && params.resizable;
  1652. if ( params.autoPlace && Common.isUndefined( params.scrollable ) ) {
  1653. params.scrollable = true;
  1654. }
  1655. var useLocalStorage = SUPPORTS_LOCAL_STORAGE && localStorage.getItem( getLocalStorageHash( this, 'isLocal' ) ) === 'true';
  1656. var saveToLocalStorage = void 0;
  1657. var titleRow = void 0;
  1658. Object.defineProperties( this,
  1659. {
  1660. parent: {
  1661. get: function get$$1() {
  1662. return params.parent;
  1663. }
  1664. },
  1665. scrollable: {
  1666. get: function get$$1() {
  1667. return params.scrollable;
  1668. }
  1669. },
  1670. autoPlace: {
  1671. get: function get$$1() {
  1672. return params.autoPlace;
  1673. }
  1674. },
  1675. closeOnTop: {
  1676. get: function get$$1() {
  1677. return params.closeOnTop;
  1678. }
  1679. },
  1680. preset: {
  1681. get: function get$$1() {
  1682. if ( _this.parent ) {
  1683. return _this.getRoot().preset;
  1684. }
  1685. return params.load.preset;
  1686. },
  1687. set: function set$$1( v ) {
  1688. if ( _this.parent ) {
  1689. _this.getRoot().preset = v;
  1690. } else {
  1691. params.load.preset = v;
  1692. }
  1693. setPresetSelectIndex( this );
  1694. _this.revert();
  1695. }
  1696. },
  1697. width: {
  1698. get: function get$$1() {
  1699. return params.width;
  1700. },
  1701. set: function set$$1( v ) {
  1702. params.width = v;
  1703. setWidth( _this, v );
  1704. }
  1705. },
  1706. name: {
  1707. get: function get$$1() {
  1708. return params.name;
  1709. },
  1710. set: function set$$1( v ) {
  1711. params.name = v;
  1712. if ( titleRow ) {
  1713. titleRow.innerHTML = params.name;
  1714. }
  1715. }
  1716. },
  1717. closed: {
  1718. get: function get$$1() {
  1719. return params.closed;
  1720. },
  1721. set: function set$$1( v ) {
  1722. params.closed = v;
  1723. if ( params.closed ) {
  1724. dom.addClass( _this.__ul, GUI.CLASS_CLOSED );
  1725. } else {
  1726. dom.removeClass( _this.__ul, GUI.CLASS_CLOSED );
  1727. }
  1728. this.onResize();
  1729. if ( _this.__closeButton ) {
  1730. _this.__closeButton.innerHTML = v ? GUI.TEXT_OPEN : GUI.TEXT_CLOSED;
  1731. }
  1732. }
  1733. },
  1734. load: {
  1735. get: function get$$1() {
  1736. return params.load;
  1737. }
  1738. },
  1739. useLocalStorage: {
  1740. get: function get$$1() {
  1741. return useLocalStorage;
  1742. },
  1743. set: function set$$1( bool ) {
  1744. if ( SUPPORTS_LOCAL_STORAGE ) {
  1745. useLocalStorage = bool;
  1746. if ( bool ) {
  1747. dom.bind( window, 'unload', saveToLocalStorage );
  1748. } else {
  1749. dom.unbind( window, 'unload', saveToLocalStorage );
  1750. }
  1751. localStorage.setItem( getLocalStorageHash( _this, 'isLocal' ), bool );
  1752. }
  1753. }
  1754. }
  1755. } );
  1756. if ( Common.isUndefined( params.parent ) ) {
  1757. this.closed = params.closed || false;
  1758. dom.addClass( this.domElement, GUI.CLASS_MAIN );
  1759. dom.makeSelectable( this.domElement, false );
  1760. if ( SUPPORTS_LOCAL_STORAGE ) {
  1761. if ( useLocalStorage ) {
  1762. _this.useLocalStorage = true;
  1763. var savedGui = localStorage.getItem( getLocalStorageHash( this, 'gui' ) );
  1764. if ( savedGui ) {
  1765. params.load = JSON.parse( savedGui );
  1766. }
  1767. }
  1768. }
  1769. this.__closeButton = document.createElement( 'div' );
  1770. this.__closeButton.innerHTML = GUI.TEXT_CLOSED;
  1771. dom.addClass( this.__closeButton, GUI.CLASS_CLOSE_BUTTON );
  1772. if ( params.closeOnTop ) {
  1773. dom.addClass( this.__closeButton, GUI.CLASS_CLOSE_TOP );
  1774. this.domElement.insertBefore( this.__closeButton, this.domElement.childNodes[ 0 ] );
  1775. } else {
  1776. dom.addClass( this.__closeButton, GUI.CLASS_CLOSE_BOTTOM );
  1777. this.domElement.appendChild( this.__closeButton );
  1778. }
  1779. dom.bind( this.__closeButton, 'click', function () {
  1780. _this.closed = ! _this.closed;
  1781. } );
  1782. } else {
  1783. if ( params.closed === undefined ) {
  1784. params.closed = true;
  1785. }
  1786. var titleRowName = document.createTextNode( params.name );
  1787. dom.addClass( titleRowName, 'controller-name' );
  1788. titleRow = addRow( _this, titleRowName );
  1789. var onClickTitle = function onClickTitle( e ) {
  1790. e.preventDefault();
  1791. _this.closed = ! _this.closed;
  1792. return false;
  1793. };
  1794. dom.addClass( this.__ul, GUI.CLASS_CLOSED );
  1795. dom.addClass( titleRow, 'title' );
  1796. dom.bind( titleRow, 'click', onClickTitle );
  1797. if ( ! params.closed ) {
  1798. this.closed = false;
  1799. }
  1800. }
  1801. if ( params.autoPlace ) {
  1802. if ( Common.isUndefined( params.parent ) ) {
  1803. if ( autoPlaceVirgin ) {
  1804. autoPlaceContainer = document.createElement( 'div' );
  1805. dom.addClass( autoPlaceContainer, CSS_NAMESPACE );
  1806. dom.addClass( autoPlaceContainer, GUI.CLASS_AUTO_PLACE_CONTAINER );
  1807. document.body.appendChild( autoPlaceContainer );
  1808. autoPlaceVirgin = false;
  1809. }
  1810. autoPlaceContainer.appendChild( this.domElement );
  1811. dom.addClass( this.domElement, GUI.CLASS_AUTO_PLACE );
  1812. }
  1813. if ( ! this.parent ) {
  1814. setWidth( _this, params.width );
  1815. }
  1816. }
  1817. this.__resizeHandler = function () {
  1818. _this.onResizeDebounced();
  1819. };
  1820. dom.bind( window, 'resize', this.__resizeHandler );
  1821. dom.bind( this.__ul, 'webkitTransitionEnd', this.__resizeHandler );
  1822. dom.bind( this.__ul, 'transitionend', this.__resizeHandler );
  1823. dom.bind( this.__ul, 'oTransitionEnd', this.__resizeHandler );
  1824. this.onResize();
  1825. if ( params.resizable ) {
  1826. addResizeHandle( this );
  1827. }
  1828. saveToLocalStorage = function saveToLocalStorage() {
  1829. if ( SUPPORTS_LOCAL_STORAGE && localStorage.getItem( getLocalStorageHash( _this, 'isLocal' ) ) === 'true' ) {
  1830. localStorage.setItem( getLocalStorageHash( _this, 'gui' ), JSON.stringify( _this.getSaveObject() ) );
  1831. }
  1832. };
  1833. this.saveToLocalStorageIfPossible = saveToLocalStorage;
  1834. function resetWidth() {
  1835. var root = _this.getRoot();
  1836. root.width += 1;
  1837. Common.defer( function () {
  1838. root.width -= 1;
  1839. } );
  1840. }
  1841. if ( ! params.parent ) {
  1842. resetWidth();
  1843. }
  1844. };
  1845. GUI.toggleHide = function () {
  1846. hide = ! hide;
  1847. Common.each( hideableGuis, function ( gui ) {
  1848. gui.domElement.style.display = hide ? 'none' : '';
  1849. } );
  1850. };
  1851. GUI.CLASS_AUTO_PLACE = 'a';
  1852. GUI.CLASS_AUTO_PLACE_CONTAINER = 'ac';
  1853. GUI.CLASS_MAIN = 'main';
  1854. GUI.CLASS_CONTROLLER_ROW = 'cr';
  1855. GUI.CLASS_TOO_TALL = 'taller-than-window';
  1856. GUI.CLASS_CLOSED = 'closed';
  1857. GUI.CLASS_CLOSE_BUTTON = 'close-button';
  1858. GUI.CLASS_CLOSE_TOP = 'close-top';
  1859. GUI.CLASS_CLOSE_BOTTOM = 'close-bottom';
  1860. GUI.CLASS_DRAG = 'drag';
  1861. GUI.DEFAULT_WIDTH = 245;
  1862. GUI.TEXT_CLOSED = 'Close Controls';
  1863. GUI.TEXT_OPEN = 'Open Controls';
  1864. GUI._keydownHandler = function ( e ) {
  1865. if ( document.activeElement.type !== 'text' && ( e.which === HIDE_KEY_CODE || e.keyCode === HIDE_KEY_CODE ) ) {
  1866. GUI.toggleHide();
  1867. }
  1868. };
  1869. dom.bind( window, 'keydown', GUI._keydownHandler, false );
  1870. Common.extend( GUI.prototype,
  1871. {
  1872. add: function add( object, property ) {
  1873. return _add( this, object, property, {
  1874. factoryArgs: Array.prototype.slice.call( arguments, 2 )
  1875. } );
  1876. },
  1877. addColor: function addColor( object, property ) {
  1878. return _add( this, object, property, {
  1879. color: true
  1880. } );
  1881. },
  1882. remove: function remove( controller ) {
  1883. this.__ul.removeChild( controller.__li );
  1884. this.__controllers.splice( this.__controllers.indexOf( controller ), 1 );
  1885. var _this = this;
  1886. Common.defer( function () {
  1887. _this.onResize();
  1888. } );
  1889. },
  1890. destroy: function destroy() {
  1891. if ( this.parent ) {
  1892. throw new Error( 'Only the root GUI should be removed with .destroy(). ' + 'For subfolders, use gui.removeFolder(folder) instead.' );
  1893. }
  1894. if ( this.autoPlace ) {
  1895. autoPlaceContainer.removeChild( this.domElement );
  1896. }
  1897. var _this = this;
  1898. Common.each( this.__folders, function ( subfolder ) {
  1899. _this.removeFolder( subfolder );
  1900. } );
  1901. dom.unbind( window, 'keydown', GUI._keydownHandler, false );
  1902. removeListeners( this );
  1903. },
  1904. addFolder: function addFolder( name ) {
  1905. if ( this.__folders[ name ] !== undefined ) {
  1906. throw new Error( 'You already have a folder in this GUI by the' + ' name "' + name + '"' );
  1907. }
  1908. var newGuiParams = { name: name, parent: this };
  1909. newGuiParams.autoPlace = this.autoPlace;
  1910. if ( this.load &&
  1911. this.load.folders &&
  1912. this.load.folders[ name ] ) {
  1913. newGuiParams.closed = this.load.folders[ name ].closed;
  1914. newGuiParams.load = this.load.folders[ name ];
  1915. }
  1916. var gui = new GUI( newGuiParams );
  1917. this.__folders[ name ] = gui;
  1918. var li = addRow( this, gui.domElement );
  1919. dom.addClass( li, 'folder' );
  1920. return gui;
  1921. },
  1922. removeFolder: function removeFolder( folder ) {
  1923. this.__ul.removeChild( folder.domElement.parentElement );
  1924. delete this.__folders[ folder.name ];
  1925. if ( this.load &&
  1926. this.load.folders &&
  1927. this.load.folders[ folder.name ] ) {
  1928. delete this.load.folders[ folder.name ];
  1929. }
  1930. removeListeners( folder );
  1931. var _this = this;
  1932. Common.each( folder.__folders, function ( subfolder ) {
  1933. folder.removeFolder( subfolder );
  1934. } );
  1935. Common.defer( function () {
  1936. _this.onResize();
  1937. } );
  1938. },
  1939. open: function open() {
  1940. this.closed = false;
  1941. },
  1942. close: function close() {
  1943. this.closed = true;
  1944. },
  1945. hide: function hide() {
  1946. this.domElement.style.display = 'none';
  1947. },
  1948. show: function show() {
  1949. this.domElement.style.display = '';
  1950. },
  1951. onResize: function onResize() {
  1952. var root = this.getRoot();
  1953. if ( root.scrollable ) {
  1954. var top = dom.getOffset( root.__ul ).top;
  1955. var h = 0;
  1956. Common.each( root.__ul.childNodes, function ( node ) {
  1957. if ( ! ( root.autoPlace && node === root.__save_row ) ) {
  1958. h += dom.getHeight( node );
  1959. }
  1960. } );
  1961. if ( window.innerHeight - top - CLOSE_BUTTON_HEIGHT < h ) {
  1962. dom.addClass( root.domElement, GUI.CLASS_TOO_TALL );
  1963. root.__ul.style.height = window.innerHeight - top - CLOSE_BUTTON_HEIGHT + 'px';
  1964. } else {
  1965. dom.removeClass( root.domElement, GUI.CLASS_TOO_TALL );
  1966. root.__ul.style.height = 'auto';
  1967. }
  1968. }
  1969. if ( root.__resize_handle ) {
  1970. Common.defer( function () {
  1971. root.__resize_handle.style.height = root.__ul.offsetHeight + 'px';
  1972. } );
  1973. }
  1974. if ( root.__closeButton ) {
  1975. root.__closeButton.style.width = root.width + 'px';
  1976. }
  1977. },
  1978. onResizeDebounced: Common.debounce( function () {
  1979. this.onResize();
  1980. }, 50 ),
  1981. remember: function remember() {
  1982. if ( Common.isUndefined( SAVE_DIALOGUE ) ) {
  1983. SAVE_DIALOGUE = new CenteredDiv();
  1984. SAVE_DIALOGUE.domElement.innerHTML = saveDialogContents;
  1985. }
  1986. if ( this.parent ) {
  1987. throw new Error( 'You can only call remember on a top level GUI.' );
  1988. }
  1989. var _this = this;
  1990. Common.each( Array.prototype.slice.call( arguments ), function ( object ) {
  1991. if ( _this.__rememberedObjects.length === 0 ) {
  1992. addSaveMenu( _this );
  1993. }
  1994. if ( _this.__rememberedObjects.indexOf( object ) === - 1 ) {
  1995. _this.__rememberedObjects.push( object );
  1996. }
  1997. } );
  1998. if ( this.autoPlace ) {
  1999. setWidth( this, this.width );
  2000. }
  2001. },
  2002. getRoot: function getRoot() {
  2003. var gui = this;
  2004. while ( gui.parent ) {
  2005. gui = gui.parent;
  2006. }
  2007. return gui;
  2008. },
  2009. getSaveObject: function getSaveObject() {
  2010. var toReturn = this.load;
  2011. toReturn.closed = this.closed;
  2012. if ( this.__rememberedObjects.length > 0 ) {
  2013. toReturn.preset = this.preset;
  2014. if ( ! toReturn.remembered ) {
  2015. toReturn.remembered = {};
  2016. }
  2017. toReturn.remembered[ this.preset ] = getCurrentPreset( this );
  2018. }
  2019. toReturn.folders = {};
  2020. Common.each( this.__folders, function ( element, key ) {
  2021. toReturn.folders[ key ] = element.getSaveObject();
  2022. } );
  2023. return toReturn;
  2024. },
  2025. save: function save() {
  2026. if ( ! this.load.remembered ) {
  2027. this.load.remembered = {};
  2028. }
  2029. this.load.remembered[ this.preset ] = getCurrentPreset( this );
  2030. markPresetModified( this, false );
  2031. this.saveToLocalStorageIfPossible();
  2032. },
  2033. saveAs: function saveAs( presetName ) {
  2034. if ( ! this.load.remembered ) {
  2035. this.load.remembered = {};
  2036. this.load.remembered[ DEFAULT_DEFAULT_PRESET_NAME ] = getCurrentPreset( this, true );
  2037. }
  2038. this.load.remembered[ presetName ] = getCurrentPreset( this );
  2039. this.preset = presetName;
  2040. addPresetOption( this, presetName, true );
  2041. this.saveToLocalStorageIfPossible();
  2042. },
  2043. revert: function revert( gui ) {
  2044. Common.each( this.__controllers, function ( controller ) {
  2045. if ( ! this.getRoot().load.remembered ) {
  2046. controller.setValue( controller.initialValue );
  2047. } else {
  2048. recallSavedValue( gui || this.getRoot(), controller );
  2049. }
  2050. if ( controller.__onFinishChange ) {
  2051. controller.__onFinishChange.call( controller, controller.getValue() );
  2052. }
  2053. }, this );
  2054. Common.each( this.__folders, function ( folder ) {
  2055. folder.revert( folder );
  2056. } );
  2057. if ( ! gui ) {
  2058. markPresetModified( this.getRoot(), false );
  2059. }
  2060. },
  2061. listen: function listen( controller ) {
  2062. var init = this.__listening.length === 0;
  2063. this.__listening.push( controller );
  2064. if ( init ) {
  2065. updateDisplays( this.__listening );
  2066. }
  2067. },
  2068. updateDisplay: function updateDisplay() {
  2069. Common.each( this.__controllers, function ( controller ) {
  2070. controller.updateDisplay();
  2071. } );
  2072. Common.each( this.__folders, function ( folder ) {
  2073. folder.updateDisplay();
  2074. } );
  2075. }
  2076. } );
  2077. function addRow( gui, newDom, liBefore ) {
  2078. var li = document.createElement( 'li' );
  2079. if ( newDom ) {
  2080. li.appendChild( newDom );
  2081. }
  2082. if ( liBefore ) {
  2083. gui.__ul.insertBefore( li, liBefore );
  2084. } else {
  2085. gui.__ul.appendChild( li );
  2086. }
  2087. gui.onResize();
  2088. return li;
  2089. }
  2090. function removeListeners( gui ) {
  2091. dom.unbind( window, 'resize', gui.__resizeHandler );
  2092. if ( gui.saveToLocalStorageIfPossible ) {
  2093. dom.unbind( window, 'unload', gui.saveToLocalStorageIfPossible );
  2094. }
  2095. }
  2096. function markPresetModified( gui, modified ) {
  2097. var opt = gui.__preset_select[ gui.__preset_select.selectedIndex ];
  2098. if ( modified ) {
  2099. opt.innerHTML = opt.value + '*';
  2100. } else {
  2101. opt.innerHTML = opt.value;
  2102. }
  2103. }
  2104. function augmentController( gui, li, controller ) {
  2105. controller.__li = li;
  2106. controller.__gui = gui;
  2107. Common.extend( controller, {
  2108. options: function options( _options ) {
  2109. if ( arguments.length > 1 ) {
  2110. var nextSibling = controller.__li.nextElementSibling;
  2111. controller.remove();
  2112. return _add( gui, controller.object, controller.property, {
  2113. before: nextSibling,
  2114. factoryArgs: [ Common.toArray( arguments ) ]
  2115. } );
  2116. }
  2117. if ( Common.isArray( _options ) || Common.isObject( _options ) ) {
  2118. var _nextSibling = controller.__li.nextElementSibling;
  2119. controller.remove();
  2120. return _add( gui, controller.object, controller.property, {
  2121. before: _nextSibling,
  2122. factoryArgs: [ _options ]
  2123. } );
  2124. }
  2125. },
  2126. name: function name( _name ) {
  2127. controller.__li.firstElementChild.firstElementChild.innerHTML = _name;
  2128. return controller;
  2129. },
  2130. listen: function listen() {
  2131. controller.__gui.listen( controller );
  2132. return controller;
  2133. },
  2134. remove: function remove() {
  2135. controller.__gui.remove( controller );
  2136. return controller;
  2137. }
  2138. } );
  2139. if ( controller instanceof NumberControllerSlider ) {
  2140. var box = new NumberControllerBox( controller.object, controller.property, { min: controller.__min, max: controller.__max, step: controller.__step } );
  2141. Common.each( [ 'updateDisplay', 'onChange', 'onFinishChange', 'step', 'min', 'max' ], function ( method ) {
  2142. var pc = controller[ method ];
  2143. var pb = box[ method ];
  2144. controller[ method ] = box[ method ] = function () {
  2145. var args = Array.prototype.slice.call( arguments );
  2146. pb.apply( box, args );
  2147. return pc.apply( controller, args );
  2148. };
  2149. } );
  2150. dom.addClass( li, 'has-slider' );
  2151. controller.domElement.insertBefore( box.domElement, controller.domElement.firstElementChild );
  2152. } else if ( controller instanceof NumberControllerBox ) {
  2153. var r = function r( returned ) {
  2154. if ( Common.isNumber( controller.__min ) && Common.isNumber( controller.__max ) ) {
  2155. var oldName = controller.__li.firstElementChild.firstElementChild.innerHTML;
  2156. var wasListening = controller.__gui.__listening.indexOf( controller ) > - 1;
  2157. controller.remove();
  2158. var newController = _add( gui, controller.object, controller.property, {
  2159. before: controller.__li.nextElementSibling,
  2160. factoryArgs: [ controller.__min, controller.__max, controller.__step ]
  2161. } );
  2162. newController.name( oldName );
  2163. if ( wasListening ) newController.listen();
  2164. return newController;
  2165. }
  2166. return returned;
  2167. };
  2168. controller.min = Common.compose( r, controller.min );
  2169. controller.max = Common.compose( r, controller.max );
  2170. } else if ( controller instanceof BooleanController ) {
  2171. dom.bind( li, 'click', function () {
  2172. dom.fakeEvent( controller.__checkbox, 'click' );
  2173. } );
  2174. dom.bind( controller.__checkbox, 'click', function ( e ) {
  2175. e.stopPropagation();
  2176. } );
  2177. } else if ( controller instanceof FunctionController ) {
  2178. dom.bind( li, 'click', function () {
  2179. dom.fakeEvent( controller.__button, 'click' );
  2180. } );
  2181. dom.bind( li, 'mouseover', function () {
  2182. dom.addClass( controller.__button, 'hover' );
  2183. } );
  2184. dom.bind( li, 'mouseout', function () {
  2185. dom.removeClass( controller.__button, 'hover' );
  2186. } );
  2187. } else if ( controller instanceof ColorController ) {
  2188. dom.addClass( li, 'color' );
  2189. controller.updateDisplay = Common.compose( function ( val ) {
  2190. li.style.borderLeftColor = controller.__color.toString();
  2191. return val;
  2192. }, controller.updateDisplay );
  2193. controller.updateDisplay();
  2194. }
  2195. controller.setValue = Common.compose( function ( val ) {
  2196. if ( gui.getRoot().__preset_select && controller.isModified() ) {
  2197. markPresetModified( gui.getRoot(), true );
  2198. }
  2199. return val;
  2200. }, controller.setValue );
  2201. }
  2202. function recallSavedValue( gui, controller ) {
  2203. var root = gui.getRoot();
  2204. var matchedIndex = root.__rememberedObjects.indexOf( controller.object );
  2205. if ( matchedIndex !== - 1 ) {
  2206. var controllerMap = root.__rememberedObjectIndecesToControllers[ matchedIndex ];
  2207. if ( controllerMap === undefined ) {
  2208. controllerMap = {};
  2209. root.__rememberedObjectIndecesToControllers[ matchedIndex ] = controllerMap;
  2210. }
  2211. controllerMap[ controller.property ] = controller;
  2212. if ( root.load && root.load.remembered ) {
  2213. var presetMap = root.load.remembered;
  2214. var preset = void 0;
  2215. if ( presetMap[ gui.preset ] ) {
  2216. preset = presetMap[ gui.preset ];
  2217. } else if ( presetMap[ DEFAULT_DEFAULT_PRESET_NAME ] ) {
  2218. preset = presetMap[ DEFAULT_DEFAULT_PRESET_NAME ];
  2219. } else {
  2220. return;
  2221. }
  2222. if ( preset[ matchedIndex ] && preset[ matchedIndex ][ controller.property ] !== undefined ) {
  2223. var value = preset[ matchedIndex ][ controller.property ];
  2224. controller.initialValue = value;
  2225. controller.setValue( value );
  2226. }
  2227. }
  2228. }
  2229. }
  2230. function _add( gui, object, property, params ) {
  2231. if ( object[ property ] === undefined ) {
  2232. throw new Error( 'Object "' + object + '" has no property "' + property + '"' );
  2233. }
  2234. var controller = void 0;
  2235. if ( params.color ) {
  2236. controller = new ColorController( object, property );
  2237. } else {
  2238. var factoryArgs = [ object, property ].concat( params.factoryArgs );
  2239. controller = ControllerFactory.apply( gui, factoryArgs );
  2240. }
  2241. if ( params.before instanceof Controller ) {
  2242. params.before = params.before.__li;
  2243. }
  2244. recallSavedValue( gui, controller );
  2245. dom.addClass( controller.domElement, 'c' );
  2246. var name = document.createElement( 'span' );
  2247. dom.addClass( name, 'property-name' );
  2248. name.innerHTML = controller.property;
  2249. var container = document.createElement( 'div' );
  2250. container.appendChild( name );
  2251. container.appendChild( controller.domElement );
  2252. var li = addRow( gui, container, params.before );
  2253. dom.addClass( li, GUI.CLASS_CONTROLLER_ROW );
  2254. if ( controller instanceof ColorController ) {
  2255. dom.addClass( li, 'color' );
  2256. } else {
  2257. dom.addClass( li, _typeof( controller.getValue() ) );
  2258. }
  2259. augmentController( gui, li, controller );
  2260. gui.__controllers.push( controller );
  2261. return controller;
  2262. }
  2263. function getLocalStorageHash( gui, key ) {
  2264. return document.location.href + '.' + key;
  2265. }
  2266. function addPresetOption( gui, name, setSelected ) {
  2267. var opt = document.createElement( 'option' );
  2268. opt.innerHTML = name;
  2269. opt.value = name;
  2270. gui.__preset_select.appendChild( opt );
  2271. if ( setSelected ) {
  2272. gui.__preset_select.selectedIndex = gui.__preset_select.length - 1;
  2273. }
  2274. }
  2275. function showHideExplain( gui, explain ) {
  2276. explain.style.display = gui.useLocalStorage ? 'block' : 'none';
  2277. }
  2278. function addSaveMenu( gui ) {
  2279. var div = gui.__save_row = document.createElement( 'li' );
  2280. dom.addClass( gui.domElement, 'has-save' );
  2281. gui.__ul.insertBefore( div, gui.__ul.firstChild );
  2282. dom.addClass( div, 'save-row' );
  2283. var gears = document.createElement( 'span' );
  2284. gears.innerHTML = '&nbsp;';
  2285. dom.addClass( gears, 'button gears' );
  2286. var button = document.createElement( 'span' );
  2287. button.innerHTML = 'Save';
  2288. dom.addClass( button, 'button' );
  2289. dom.addClass( button, 'save' );
  2290. var button2 = document.createElement( 'span' );
  2291. button2.innerHTML = 'New';
  2292. dom.addClass( button2, 'button' );
  2293. dom.addClass( button2, 'save-as' );
  2294. var button3 = document.createElement( 'span' );
  2295. button3.innerHTML = 'Revert';
  2296. dom.addClass( button3, 'button' );
  2297. dom.addClass( button3, 'revert' );
  2298. var select = gui.__preset_select = document.createElement( 'select' );
  2299. if ( gui.load && gui.load.remembered ) {
  2300. Common.each( gui.load.remembered, function ( value, key ) {
  2301. addPresetOption( gui, key, key === gui.preset );
  2302. } );
  2303. } else {
  2304. addPresetOption( gui, DEFAULT_DEFAULT_PRESET_NAME, false );
  2305. }
  2306. dom.bind( select, 'change', function () {
  2307. for ( var index = 0; index < gui.__preset_select.length; index ++ ) {
  2308. gui.__preset_select[ index ].innerHTML = gui.__preset_select[ index ].value;
  2309. }
  2310. gui.preset = this.value;
  2311. } );
  2312. div.appendChild( select );
  2313. div.appendChild( gears );
  2314. div.appendChild( button );
  2315. div.appendChild( button2 );
  2316. div.appendChild( button3 );
  2317. if ( SUPPORTS_LOCAL_STORAGE ) {
  2318. var explain = document.getElementById( 'dg-local-explain' );
  2319. var localStorageCheckBox = document.getElementById( 'dg-local-storage' );
  2320. var saveLocally = document.getElementById( 'dg-save-locally' );
  2321. saveLocally.style.display = 'block';
  2322. if ( localStorage.getItem( getLocalStorageHash( gui, 'isLocal' ) ) === 'true' ) {
  2323. localStorageCheckBox.setAttribute( 'checked', 'checked' );
  2324. }
  2325. showHideExplain( gui, explain );
  2326. dom.bind( localStorageCheckBox, 'change', function () {
  2327. gui.useLocalStorage = ! gui.useLocalStorage;
  2328. showHideExplain( gui, explain );
  2329. } );
  2330. }
  2331. var newConstructorTextArea = document.getElementById( 'dg-new-constructor' );
  2332. dom.bind( newConstructorTextArea, 'keydown', function ( e ) {
  2333. if ( e.metaKey && ( e.which === 67 || e.keyCode === 67 ) ) {
  2334. SAVE_DIALOGUE.hide();
  2335. }
  2336. } );
  2337. dom.bind( gears, 'click', function () {
  2338. newConstructorTextArea.innerHTML = JSON.stringify( gui.getSaveObject(), undefined, 2 );
  2339. SAVE_DIALOGUE.show();
  2340. newConstructorTextArea.focus();
  2341. newConstructorTextArea.select();
  2342. } );
  2343. dom.bind( button, 'click', function () {
  2344. gui.save();
  2345. } );
  2346. dom.bind( button2, 'click', function () {
  2347. var presetName = prompt( 'Enter a new preset name.' );
  2348. if ( presetName ) {
  2349. gui.saveAs( presetName );
  2350. }
  2351. } );
  2352. dom.bind( button3, 'click', function () {
  2353. gui.revert();
  2354. } );
  2355. }
  2356. function addResizeHandle( gui ) {
  2357. var pmouseX = void 0;
  2358. gui.__resize_handle = document.createElement( 'div' );
  2359. Common.extend( gui.__resize_handle.style, {
  2360. width: '6px',
  2361. marginLeft: '-3px',
  2362. height: '200px',
  2363. cursor: 'ew-resize',
  2364. position: 'absolute'
  2365. } );
  2366. function drag( e ) {
  2367. e.preventDefault();
  2368. gui.width += pmouseX - e.clientX;
  2369. gui.onResize();
  2370. pmouseX = e.clientX;
  2371. return false;
  2372. }
  2373. function dragStop() {
  2374. dom.removeClass( gui.__closeButton, GUI.CLASS_DRAG );
  2375. dom.unbind( window, 'mousemove', drag );
  2376. dom.unbind( window, 'mouseup', dragStop );
  2377. }
  2378. function dragStart( e ) {
  2379. e.preventDefault();
  2380. pmouseX = e.clientX;
  2381. dom.addClass( gui.__closeButton, GUI.CLASS_DRAG );
  2382. dom.bind( window, 'mousemove', drag );
  2383. dom.bind( window, 'mouseup', dragStop );
  2384. return false;
  2385. }
  2386. dom.bind( gui.__resize_handle, 'mousedown', dragStart );
  2387. dom.bind( gui.__closeButton, 'mousedown', dragStart );
  2388. gui.domElement.insertBefore( gui.__resize_handle, gui.domElement.firstElementChild );
  2389. }
  2390. function setWidth( gui, w ) {
  2391. gui.domElement.style.width = w + 'px';
  2392. if ( gui.__save_row && gui.autoPlace ) {
  2393. gui.__save_row.style.width = w + 'px';
  2394. }
  2395. if ( gui.__closeButton ) {
  2396. gui.__closeButton.style.width = w + 'px';
  2397. }
  2398. }
  2399. function getCurrentPreset( gui, useInitialValues ) {
  2400. var toReturn = {};
  2401. Common.each( gui.__rememberedObjects, function ( val, index ) {
  2402. var savedValues = {};
  2403. var controllerMap = gui.__rememberedObjectIndecesToControllers[ index ];
  2404. Common.each( controllerMap, function ( controller, property ) {
  2405. savedValues[ property ] = useInitialValues ? controller.initialValue : controller.getValue();
  2406. } );
  2407. toReturn[ index ] = savedValues;
  2408. } );
  2409. return toReturn;
  2410. }
  2411. function setPresetSelectIndex( gui ) {
  2412. for ( var index = 0; index < gui.__preset_select.length; index ++ ) {
  2413. if ( gui.__preset_select[ index ].value === gui.preset ) {
  2414. gui.__preset_select.selectedIndex = index;
  2415. }
  2416. }
  2417. }
  2418. function updateDisplays( controllerArray ) {
  2419. if ( controllerArray.length !== 0 ) {
  2420. requestAnimationFrame$1.call( window, function () {
  2421. updateDisplays( controllerArray );
  2422. } );
  2423. }
  2424. Common.each( controllerArray, function ( c ) {
  2425. c.updateDisplay();
  2426. } );
  2427. }
  2428. var color = {
  2429. Color: Color,
  2430. math: ColorMath,
  2431. interpret: interpret
  2432. };
  2433. var controllers = {
  2434. Controller: Controller,
  2435. BooleanController: BooleanController,
  2436. OptionController: OptionController,
  2437. StringController: StringController,
  2438. NumberController: NumberController,
  2439. NumberControllerBox: NumberControllerBox,
  2440. NumberControllerSlider: NumberControllerSlider,
  2441. FunctionController: FunctionController,
  2442. ColorController: ColorController
  2443. };
  2444. var dom$1 = { dom: dom };
  2445. var gui = { GUI: GUI };
  2446. var GUI$1 = GUI;
  2447. var index = {
  2448. color: color,
  2449. controllers: controllers,
  2450. dom: dom$1,
  2451. gui: gui,
  2452. GUI: GUI$1
  2453. };
  2454. export { color, controllers, dom$1 as dom, gui, GUI$1 as GUI };
  2455. export default index;
  2456. //# sourceMappingURL=dat.gui.module.js.map