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