dat.gui.js 86 KB

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