GM dat.GUI

dat.GUI modified to prioritize GM_getValue/GM_setValue over localStorage among other things.

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/429537/964426/GM%20datGUI.js

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址