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