How to use svValues method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

DAT.GUI.js

Source:DAT.GUI.js Github

copy

Full Screen

1/**2 * dat-gui JavaScript Controller Library3 * http://code.google.com/p/dat-gui4 *5 * Copyright 2011 Data Arts Team, Google Creative Lab6 * Copyright 2013 Mariusz Zieliński7 *8 * Licensed under the Apache License, Version 2.0 (the "License");9 * you may not use this file except in compliance with the License.10 * You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 */14/** @namespace */15var dat = dat || {};16/** @namespace */17dat.gui = dat.gui || {};18/** @namespace */19dat.utils = dat.utils || {};20/** @namespace */21dat.controllers = dat.controllers || {};22/** @namespace */23dat.dom = dat.dom || {};24/** @namespace */25dat.color = dat.color || {};26dat.utils.css = (function () {27 return {28 load: function (url, doc) {29 doc = doc || document;30 var link = doc.createElement('link');31 link.type = 'text/css';32 link.rel = 'stylesheet';33 link.href = url;34 doc.getElementsByTagName('head')[0].appendChild(link);35 },36 inject: function(css, doc) {37 doc = doc || document;38 var injected = document.createElement('style');39 injected.type = 'text/css';40 injected.innerHTML = css;41 doc.getElementsByTagName('head')[0].appendChild(injected);42 }43 }44})();45dat.utils.common = (function () {46 var ARR_EACH = Array.prototype.forEach;47 var ARR_SLICE = Array.prototype.slice;48 /**49 * Band-aid methods for things that should be a lot easier in JavaScript.50 * Implementation and structure inspired by underscore.js51 * http://documentcloud.github.com/underscore/52 */53 return {54 BREAK: {},55 extend: function(target) {56 this.each(ARR_SLICE.call(arguments, 1), function(obj) {57 for (var key in obj)58 if (!this.isUndefined(obj[key]))59 target[key] = obj[key];60 }, this);61 return target;62 },63 defaults: function(target) {64 this.each(ARR_SLICE.call(arguments, 1), function(obj) {65 for (var key in obj)66 if (this.isUndefined(target[key]))67 target[key] = obj[key];68 }, this);69 return target;70 },71 compose: function() {72 var toCall = ARR_SLICE.call(arguments);73 return function() {74 var args = ARR_SLICE.call(arguments);75 for (var i = toCall.length -1; i >= 0; i--) {76 args = [toCall[i].apply(this, args)];77 }78 return args[0];79 }80 },81 each: function(obj, itr, scope) {82 if (ARR_EACH && obj.forEach === ARR_EACH) {83 obj.forEach(itr, scope);84 } else if (obj.length === obj.length + 0) { // Is number but not NaN85 for (var key = 0, l = obj.length; key < l; key++)86 if (key in obj && itr.call(scope, obj[key], key) === this.BREAK)87 return;88 } else {89 for (var key in obj)90 if (itr.call(scope, obj[key], key) === this.BREAK)91 return;92 }93 },94 defer: function(fnc) {95 setTimeout(fnc, 0);96 },97 toArray: function(obj) {98 if (obj.toArray) return obj.toArray();99 return ARR_SLICE.call(obj);100 },101 isUndefined: function(obj) {102 return obj === undefined;103 },104 isNull: function(obj) {105 return obj === null;106 },107 isNaN: function(obj) {108 return obj !== obj;109 },110 isArray: Array.isArray || function(obj) {111 return obj.constructor === Array;112 },113 isObject: function(obj) {114 return obj === Object(obj);115 },116 isNumber: function(obj) {117 return obj === obj+0;118 },119 isString: function(obj) {120 return obj === obj+'';121 },122 isBoolean: function(obj) {123 return obj === false || obj === true;124 },125 isFunction: function(obj) {126 return Object.prototype.toString.call(obj) === '[object Function]';127 }128 };129})();130dat.controllers.Controller = (function (common) {131 /**132 * @class An "abstract" class that represents a given property of an object.133 *134 * @param {Object} object The object to be manipulated135 * @param {string} property The name of the property to be manipulated136 *137 * @member dat.controllers138 */139 var Controller = function(object, property) {140 this.initialValue = object[property];141 /**142 * Those who extend this class will put their DOM elements in here.143 * @type {DOMElement}144 */145 this.domElement = document.createElement('div');146 /**147 * The object to manipulate148 * @type {Object}149 */150 this.object = object;151 /**152 * The name of the property to manipulate153 * @type {String}154 */155 this.property = property;156 /**157 * The function to be called on change.158 * @type {Function}159 * @ignore160 */161 this.__onChange = undefined;162 /**163 * The function to be called on finishing change.164 * @type {Function}165 * @ignore166 */167 this.__onFinishChange = undefined;168 };169 common.extend(170 Controller.prototype,171 /** @lends dat.controllers.Controller.prototype */172 {173 /**174 * Specify that a function fire every time someone changes the value with175 * this Controller.176 *177 * @param {Function} fnc This function will be called whenever the value178 * is modified via this Controller.179 * @returns {dat.controllers.Controller} this180 */181 onChange: function(fnc) {182 this.__onChange = fnc;183 return this;184 },185 /**186 * Specify that a function fire every time someone "finishes" changing187 * the value wih this Controller. Useful for values that change188 * incrementally like numbers or strings.189 *190 * @param {Function} fnc This function will be called whenever191 * someone "finishes" changing the value via this Controller.192 * @returns {dat.controllers.Controller} this193 */194 onFinishChange: function(fnc) {195 this.__onFinishChange = fnc;196 return this;197 },198 /**199 * Change the value of <code>object[property]</code>200 *201 * @param {Object} newValue The new value of <code>object[property]</code>202 */203 setValue: function(newValue) {204 this.object[this.property] = newValue;205 if (this.__onChange) {206 this.__onChange.call(this, newValue);207 }208 this.updateDisplay();209 return this;210 },211 /**212 * Gets the value of <code>object[property]</code>213 *214 * @returns {Object} The current value of <code>object[property]</code>215 */216 getValue: function() {217 return this.object[this.property];218 },219 /**220 * Refreshes the visual display of a Controller in order to keep sync221 * with the object's current value.222 * @returns {dat.controllers.Controller} this223 */224 updateDisplay: function() {225 return this;226 },227 /**228 * @returns {Boolean} true if the value has deviated from initialValue229 */230 isModified: function() {231 return this.initialValue !== this.getValue()232 }233 }234 );235 return Controller;236})(dat.utils.common);237dat.dom.dom = (function (common) {238 var EVENT_MAP = {239 'HTMLEvents': ['change'],240 'MouseEvents': ['click','mousemove','mousedown','mouseup', 'mouseover'],241 'KeyboardEvents': ['keydown']242 };243 var EVENT_MAP_INV = {};244 common.each(EVENT_MAP, function(v, k) {245 common.each(v, function(e) {246 EVENT_MAP_INV[e] = k;247 });248 });249 var CSS_VALUE_PIXELS = /(\d+(\.\d+)?)px/;250 function cssValueToPixels(val) {251 if (val === '0' || common.isUndefined(val)) return 0;252 var match = val.match(CSS_VALUE_PIXELS);253 if (!common.isNull(match)) {254 return parseFloat(match[1]);255 }256 // TODO ...ems? %?257 return 0;258 }259 /**260 * @namespace261 * @member dat.dom262 */263 var dom = {264 /**265 *266 * @param elem267 * @param selectable268 */269 makeSelectable: function(elem, selectable) {270 if (elem === undefined || elem.style === undefined) return;271 elem.onselectstart = selectable ? function() {272 return false;273 } : function() {274 };275 elem.style.MozUserSelect = selectable ? 'auto' : 'none';276 elem.style.KhtmlUserSelect = selectable ? 'auto' : 'none';277 elem.unselectable = selectable ? 'on' : 'off';278 },279 /**280 *281 * @param elem282 * @param horizontal283 * @param vertical284 */285 makeFullscreen: function(elem, horizontal, vertical) {286 if (common.isUndefined(horizontal)) horizontal = true;287 if (common.isUndefined(vertical)) vertical = true;288 elem.style.position = 'absolute';289 if (horizontal) {290 elem.style.left = 0;291 elem.style.right = 0;292 }293 if (vertical) {294 elem.style.top = 0;295 elem.style.bottom = 0;296 }297 },298 /**299 *300 * @param elem301 * @param eventType302 * @param params303 */304 fakeEvent: function(elem, eventType, params, aux) {305 params = params || {};306 var className = EVENT_MAP_INV[eventType];307 if (!className) {308 throw new Error('Event type ' + eventType + ' not supported.');309 }310 var evt = document.createEvent(className);311 switch (className) {312 case 'MouseEvents':313 var clientX = params.x || params.clientX || 0;314 var clientY = params.y || params.clientY || 0;315 evt.initMouseEvent(eventType, params.bubbles || false,316 params.cancelable || true, window, params.clickCount || 1,317 0, //screen X318 0, //screen Y319 clientX, //client X320 clientY, //client Y321 false, false, false, false, 0, null);322 break;323 case 'KeyboardEvents':324 var init = evt.initKeyboardEvent || evt.initKeyEvent; // webkit || moz325 common.defaults(params, {326 cancelable: true,327 ctrlKey: false,328 altKey: false,329 shiftKey: false,330 metaKey: false,331 keyCode: undefined,332 charCode: undefined333 });334 init(eventType, params.bubbles || false,335 params.cancelable, window,336 params.ctrlKey, params.altKey,337 params.shiftKey, params.metaKey,338 params.keyCode, params.charCode);339 break;340 default:341 evt.initEvent(eventType, params.bubbles || false,342 params.cancelable || true);343 break;344 }345 common.defaults(evt, aux);346 elem.dispatchEvent(evt);347 },348 /**349 *350 * @param elem351 * @param event352 * @param func353 * @param bool354 */355 bind: function(elem, event, func, bool) {356 bool = bool || false;357 if (elem.addEventListener)358 elem.addEventListener(event, func, bool);359 else if (elem.attachEvent)360 elem.attachEvent('on' + event, func);361 return dom;362 },363 /**364 *365 * @param elem366 * @param event367 * @param func368 * @param bool369 */370 unbind: function(elem, event, func, bool) {371 bool = bool || false;372 if (elem.removeEventListener)373 elem.removeEventListener(event, func, bool);374 else if (elem.detachEvent)375 elem.detachEvent('on' + event, func);376 return dom;377 },378 /**379 *380 * @param elem381 * @param className382 */383 addClass: function(elem, className) {384 if (elem.className === undefined) {385 elem.className = className;386 } else if (elem.className !== className) {387 var classes = elem.className.split(/ +/);388 if (classes.indexOf(className) == -1) {389 classes.push(className);390 elem.className = classes.join(' ').replace(/^\s+/, '').replace(/\s+$/, '');391 }392 }393 return dom;394 },395 /**396 *397 * @param elem398 * @param className399 */400 removeClass: function(elem, className) {401 if (className) {402 if (elem.className === undefined) {403 // elem.className = className;404 } else if (elem.className === className) {405 elem.removeAttribute('class');406 } else {407 var classes = elem.className.split(/ +/);408 var index = classes.indexOf(className);409 if (index != -1) {410 classes.splice(index, 1);411 elem.className = classes.join(' ');412 }413 }414 } else {415 elem.className = undefined;416 }417 return dom;418 },419 hasClass: function(elem, className) {420 return new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)').test(elem.className) || false;421 },422 /**423 *424 * @param elem425 */426 getWidth: function(elem) {427 var style = getComputedStyle(elem);428 return cssValueToPixels(style['border-left-width']) +429 cssValueToPixels(style['border-right-width']) +430 cssValueToPixels(style['padding-left']) +431 cssValueToPixels(style['padding-right']) +432 cssValueToPixels(style['width']);433 },434 /**435 *436 * @param elem437 */438 getHeight: function(elem) {439 var style = getComputedStyle(elem);440 return cssValueToPixels(style['border-top-width']) +441 cssValueToPixels(style['border-bottom-width']) +442 cssValueToPixels(style['padding-top']) +443 cssValueToPixels(style['padding-bottom']) +444 cssValueToPixels(style['height']);445 },446 /**447 *448 * @param elem449 */450 getOffset: function(elem) {451 var offset = {left: 0, top:0};452 if (elem.offsetParent) {453 do {454 offset.left += elem.offsetLeft;455 offset.top += elem.offsetTop;456 } while (elem = elem.offsetParent);457 }458 return offset;459 },460 // http://stackoverflow.com/posts/2684561/revisions461 /**462 *463 * @param elem464 */465 isActive: function(elem) {466 return elem === document.activeElement && ( elem.type || elem.href );467 }468 };469 return dom;470})(dat.utils.common);471dat.controllers.OptionController = (function (Controller, dom, common) {472 /**473 * @class Provides a select input to alter the property of an object, using a474 * list of accepted values.475 *476 * @extends dat.controllers.Controller477 *478 * @param {Object} object The object to be manipulated479 * @param {string} property The name of the property to be manipulated480 * @param {Object|string[]} options A map of labels to acceptable values, or481 * a list of acceptable string values.482 *483 * @member dat.controllers484 */485 var OptionController = function(object, property, options) {486 OptionController.superclass.call(this, object, property);487 var _this = this;488 /**489 * The drop down menu490 * @ignore491 */492 this.__select = document.createElement('select');493 if (common.isArray(options)) {494 var map = {};495 common.each(options, function(element) {496 map[element] = element;497 });498 options = map;499 }500 common.each(options, function(value, key) {501 var opt = document.createElement('option');502 opt.innerHTML = key;503 opt.setAttribute('value', value);504 _this.__select.appendChild(opt);505 });506 // Acknowledge original value507 this.updateDisplay();508 dom.bind(this.__select, 'change', function() {509 var desiredValue = this.options[this.selectedIndex].value;510 _this.setValue(desiredValue);511 });512 this.domElement.appendChild(this.__select);513 };514 OptionController.superclass = Controller;515 common.extend(516 OptionController.prototype,517 Controller.prototype,518 {519 setValue: function(v) {520 var toReturn = OptionController.superclass.prototype.setValue.call(this, v);521 if (this.__onFinishChange) {522 this.__onFinishChange.call(this, this.getValue());523 }524 return toReturn;525 },526 updateDisplay: function() {527 this.__select.value = this.getValue();528 return OptionController.superclass.prototype.updateDisplay.call(this);529 }530 }531 );532 return OptionController;533})(dat.controllers.Controller,534 dat.dom.dom,535 dat.utils.common);536dat.controllers.NumberController = (function (Controller, common) {537 /**538 * @class Represents a given property of an object that is a number.539 *540 * @extends dat.controllers.Controller541 *542 * @param {Object} object The object to be manipulated543 * @param {string} property The name of the property to be manipulated544 * @param {Object} [params] Optional parameters545 * @param {Number} [params.min] Minimum allowed value546 * @param {Number} [params.max] Maximum allowed value547 * @param {Number} [params.step] Increment by which to change value548 *549 * @member dat.controllers550 */551 var NumberController = function(object, property, params) {552 NumberController.superclass.call(this, object, property);553 params = params || {};554 this.__min = params.min;555 this.__max = params.max;556 this.__step = params.step;557 if (common.isUndefined(this.__step)) {558 if (this.initialValue == 0) {559 this.__impliedStep = 1; // What are we, psychics?560 } else {561 // Hey Doug, check this out.562 this.__impliedStep = Math.pow(10, Math.floor(Math.log(this.initialValue)/Math.LN10))/10;563 }564 } else {565 this.__impliedStep = this.__step;566 }567 this.__precision = numDecimals(this.__impliedStep);568 };569 NumberController.superclass = Controller;570 common.extend(571 NumberController.prototype,572 Controller.prototype,573 /** @lends dat.controllers.NumberController.prototype */574 {575 setValue: function(v) {576 if (this.__min !== undefined && v < this.__min) {577 v = this.__min;578 } else if (this.__max !== undefined && v > this.__max) {579 v = this.__max;580 }581 if (this.__step !== undefined && v % this.__step != 0) {582 v = Math.round(v / this.__step) * this.__step;583 }584 return NumberController.superclass.prototype.setValue.call(this, v);585 },586 /**587 * Specify a minimum value for <code>object[property]</code>.588 *589 * @param {Number} minValue The minimum value for590 * <code>object[property]</code>591 * @returns {dat.controllers.NumberController} this592 */593 min: function(v) {594 this.__min = v;595 return this;596 },597 /**598 * Specify a maximum value for <code>object[property]</code>.599 *600 * @param {Number} maxValue The maximum value for601 * <code>object[property]</code>602 * @returns {dat.controllers.NumberController} this603 */604 max: function(v) {605 this.__max = v;606 return this;607 },608 /**609 * Specify a step value that dat.controllers.NumberController610 * increments by.611 *612 * @param {Number} stepValue The step value for613 * dat.controllers.NumberController614 * @default if minimum and maximum specified increment is 1% of the615 * difference otherwise stepValue is 1616 * @returns {dat.controllers.NumberController} this617 */618 step: function(v) {619 this.__step = v;620 return this;621 }622 }623 );624 function numDecimals(x) {625 x = x.toString();626 if (x.indexOf('.') > -1) {627 return x.length - x.indexOf('.') - 1;628 } else {629 return 0;630 }631 }632 return NumberController;633})(dat.controllers.Controller,634 dat.utils.common);635dat.controllers.NumberControllerBox = (function (NumberController, dom, common) {636 /**637 * @class Represents a given property of an object that is a number and638 * provides an input element with which to manipulate it.639 *640 * @extends dat.controllers.Controller641 * @extends dat.controllers.NumberController642 *643 * @param {Object} object The object to be manipulated644 * @param {string} property The name of the property to be manipulated645 * @param {Object} [params] Optional parameters646 * @param {Number} [params.min] Minimum allowed value647 * @param {Number} [params.max] Maximum allowed value648 * @param {Number} [params.step] Increment by which to change value649 *650 * @member dat.controllers651 */652 var NumberControllerBox = function(object, property, params) {653 this.__truncationSuspended = false;654 NumberControllerBox.superclass.call(this, object, property, params);655 var _this = this;656 /**657 * {Number} Previous mouse y position658 * @ignore659 */660 var prev_y;661 this.__input = document.createElement('input');662 this.__input.setAttribute('type', 'text');663 // Makes it so manually specified values are not truncated.664 dom.bind(this.__input, 'change', onChange);665 dom.bind(this.__input, 'blur', onBlur);666 dom.bind(this.__input, 'mousedown', onMouseDown);667 dom.bind(this.__input, 'keydown', function(e) {668 // When pressing entire, you can be as precise as you want.669 if (e.keyCode === 13) {670 _this.__truncationSuspended = true;671 this.blur();672 _this.__truncationSuspended = false;673 }674 });675 function onChange() {676 var attempted = parseFloat(_this.__input.value);677 if (!common.isNaN(attempted)) _this.setValue(attempted);678 }679 function onBlur() {680 onChange();681 if (_this.__onFinishChange) {682 _this.__onFinishChange.call(_this, _this.getValue());683 }684 }685 function onMouseDown(e) {686 dom.bind(window, 'mousemove', onMouseDrag);687 dom.bind(window, 'mouseup', onMouseUp);688 prev_y = e.clientY;689 }690 function onMouseDrag(e) {691 var diff = prev_y - e.clientY;692 _this.setValue(_this.getValue() + diff * _this.__impliedStep);693 prev_y = e.clientY;694 }695 function onMouseUp() {696 dom.unbind(window, 'mousemove', onMouseDrag);697 dom.unbind(window, 'mouseup', onMouseUp);698 }699 this.updateDisplay();700 this.domElement.appendChild(this.__input);701 };702 NumberControllerBox.superclass = NumberController;703 common.extend(704 NumberControllerBox.prototype,705 NumberController.prototype,706 {707 updateDisplay: function() {708 this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal(this.getValue(), this.__precision);709 return NumberControllerBox.superclass.prototype.updateDisplay.call(this);710 }711 }712 );713 function roundToDecimal(value, decimals) {714 var tenTo = Math.pow(10, decimals);715 return Math.round(value * tenTo) / tenTo;716 }717 return NumberControllerBox;718})(dat.controllers.NumberController,719 dat.dom.dom,720 dat.utils.common);721dat.controllers.NumberControllerSlider = (function (NumberController, dom, css, common, styleSheet) {722 /**723 * @class Represents a given property of an object that is a number, contains724 * a minimum and maximum, and provides a slider element with which to725 * manipulate it. It should be noted that the slider element is made up of726 * <code>&lt;div&gt;</code> tags, <strong>not</strong> the html5727 * <code>&lt;slider&gt;</code> element.728 *729 * @extends dat.controllers.Controller730 * @extends dat.controllers.NumberController731 *732 * @param {Object} object The object to be manipulated733 * @param {string} property The name of the property to be manipulated734 * @param {Number} minValue Minimum allowed value735 * @param {Number} maxValue Maximum allowed value736 * @param {Number} stepValue Increment by which to change value737 *738 * @member dat.controllers739 */740 var NumberControllerSlider = function(object, property, min, max, step) {741 NumberControllerSlider.superclass.call(this, object, property, { min: min, max: max, step: step });742 var _this = this;743 this.__background = document.createElement('div');744 this.__foreground = document.createElement('div');745 dom.bind(this.__background, 'mousedown', onMouseDown);746 dom.addClass(this.__background, 'slider');747 dom.addClass(this.__foreground, 'slider-fg');748 function onMouseDown(e) {749 dom.bind(window, 'mousemove', onMouseDrag);750 dom.bind(window, 'mouseup', onMouseUp);751 onMouseDrag(e);752 }753 function onMouseDrag(e) {754 e.preventDefault();755 var offset = dom.getOffset(_this.__background);756 var width = dom.getWidth(_this.__background);757 _this.setValue(758 map(e.clientX, offset.left, offset.left + width, _this.__min, _this.__max)759 );760 return false;761 }762 function onMouseUp() {763 dom.unbind(window, 'mousemove', onMouseDrag);764 dom.unbind(window, 'mouseup', onMouseUp);765 if (_this.__onFinishChange) {766 _this.__onFinishChange.call(_this, _this.getValue());767 }768 }769 this.updateDisplay();770 this.__background.appendChild(this.__foreground);771 this.domElement.appendChild(this.__background);772 };773 NumberControllerSlider.superclass = NumberController;774 /**775 * Injects default stylesheet for slider elements.776 */777 NumberControllerSlider.useDefaultStyles = function() {778 css.inject(styleSheet);779 };780 common.extend(781 NumberControllerSlider.prototype,782 NumberController.prototype,783 {784 updateDisplay: function() {785 var pct = (this.getValue() - this.__min)/(this.__max - this.__min);786 this.__foreground.style.width = pct*100+'%';787 return NumberControllerSlider.superclass.prototype.updateDisplay.call(this);788 }789 }790 );791 function map(v, i1, i2, o1, o2) {792 return o1 + (o2 - o1) * ((v - i1) / (i2 - i1));793 }794 return NumberControllerSlider;795})(dat.controllers.NumberController,796 dat.dom.dom,797 dat.utils.css,798 dat.utils.common,799 ".slider {\n box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);\n height: 1em;\n border-radius: 1em;\n background-color: #eee;\n padding: 0 0.5em;\n overflow: hidden;\n}\n\n.slider-fg {\n padding: 1px 0 2px 0;\n background-color: #aaa;\n height: 1em;\n margin-left: -0.5em;\n padding-right: 0.5em;\n border-radius: 1em 0 0 1em;\n}\n\n.slider-fg:after {\n display: inline-block;\n border-radius: 1em;\n background-color: #fff;\n border: 1px solid #aaa;\n content: '';\n float: right;\n margin-right: -1em;\n margin-top: -1px;\n height: 0.9em;\n width: 0.9em;\n}");800dat.controllers.FunctionController = (function (Controller, dom, common) {801 /**802 * @class Provides a GUI interface to fire a specified method, a property of an object.803 *804 * @extends dat.controllers.Controller805 *806 * @param {Object} object The object to be manipulated807 * @param {string} property The name of the property to be manipulated808 *809 * @member dat.controllers810 */811 var FunctionController = function(object, property, text) {812 FunctionController.superclass.call(this, object, property);813 var _this = this;814 this.__button = document.createElement('div');815 this.__button.innerHTML = text === undefined ? 'Fire' : text;816 dom.bind(this.__button, 'click', function(e) {817 e.preventDefault();818 _this.fire();819 return false;820 });821 dom.addClass(this.__button, 'button');822 this.domElement.appendChild(this.__button);823 };824 FunctionController.superclass = Controller;825 common.extend(826 FunctionController.prototype,827 Controller.prototype,828 {829 fire: function() {830 if (this.__onChange) {831 this.__onChange.call(this);832 }833 if (this.__onFinishChange) {834 this.__onFinishChange.call(this, this.getValue());835 }836 this.getValue().call(this.object);837 }838 }839 );840 return FunctionController;841})(dat.controllers.Controller,842 dat.dom.dom,843 dat.utils.common);844dat.controllers.BooleanController = (function (Controller, dom, common) {845 /**846 * @class Provides a checkbox input to alter the boolean property of an object.847 * @extends dat.controllers.Controller848 *849 * @param {Object} object The object to be manipulated850 * @param {string} property The name of the property to be manipulated851 *852 * @member dat.controllers853 */854 var BooleanController = function(object, property) {855 BooleanController.superclass.call(this, object, property);856 var _this = this;857 this.__prev = this.getValue();858 this.__checkbox = document.createElement('input');859 this.__checkbox.setAttribute('type', 'checkbox');860 dom.bind(this.__checkbox, 'change', onChange, false);861 this.domElement.appendChild(this.__checkbox);862 // Match original value863 this.updateDisplay();864 function onChange() {865 _this.setValue(!_this.__prev);866 }867 };868 BooleanController.superclass = Controller;869 common.extend(870 BooleanController.prototype,871 Controller.prototype,872 {873 setValue: function(v) {874 var toReturn = BooleanController.superclass.prototype.setValue.call(this, v);875 if (this.__onFinishChange) {876 this.__onFinishChange.call(this, this.getValue());877 }878 this.__prev = this.getValue();879 return toReturn;880 },881 updateDisplay: function() {882 if (this.getValue() === true) {883 this.__checkbox.setAttribute('checked', 'checked');884 this.__checkbox.checked = true;885 } else {886 this.__checkbox.checked = false;887 }888 return BooleanController.superclass.prototype.updateDisplay.call(this);889 }890 }891 );892 return BooleanController;893})(dat.controllers.Controller,894 dat.dom.dom,895 dat.utils.common);896dat.color.toString = (function (common) {897 return function(color) {898 if (color.a == 1 || common.isUndefined(color.a)) {899 var s = color.hex.toString(16);900 while (s.length < 6) {901 s = '0' + s;902 }903 return '#' + s;904 } else {905 return 'rgba(' + Math.round(color.r) + ',' + Math.round(color.g) + ',' + Math.round(color.b) + ',' + color.a + ')';906 }907 }908})(dat.utils.common);909dat.color.interpret = (function (toString, common) {910 var result, toReturn;911 var interpret = function() {912 toReturn = false;913 var original = arguments.length > 1 ? common.toArray(arguments) : arguments[0];914 common.each(INTERPRETATIONS, function(family) {915 if (family.litmus(original)) {916 common.each(family.conversions, function(conversion, conversionName) {917 result = conversion.read(original);918 if (toReturn === false && result !== false) {919 toReturn = result;920 result.conversionName = conversionName;921 result.conversion = conversion;922 return common.BREAK;923 }924 });925 return common.BREAK;926 }927 });928 return toReturn;929 };930 var INTERPRETATIONS = [931 // Strings932 {933 litmus: common.isString,934 conversions: {935 THREE_CHAR_HEX: {936 read: function(original) {937 var test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i);938 if (test === null) return false;939 return {940 space: 'HEX',941 hex: parseInt(942 '0x' +943 test[1].toString() + test[1].toString() +944 test[2].toString() + test[2].toString() +945 test[3].toString() + test[3].toString())946 };947 },948 write: toString949 },950 SIX_CHAR_HEX: {951 read: function(original) {952 var test = original.match(/^#([A-F0-9]{6})$/i);953 if (test === null) return false;954 return {955 space: 'HEX',956 hex: parseInt('0x' + test[1].toString())957 };958 },959 write: toString960 },961 CSS_RGB: {962 read: function(original) {963 var test = original.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);964 if (test === null) return false;965 return {966 space: 'RGB',967 r: parseFloat(test[1]),968 g: parseFloat(test[2]),969 b: parseFloat(test[3])970 };971 },972 write: toString973 },974 CSS_RGBA: {975 read: function(original) {976 var test = original.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\,\s*(.+)\s*\)/);977 if (test === null) return false;978 return {979 space: 'RGB',980 r: parseFloat(test[1]),981 g: parseFloat(test[2]),982 b: parseFloat(test[3]),983 a: parseFloat(test[4])984 };985 },986 write: toString987 }988 }989 },990 // Numbers991 {992 litmus: common.isNumber,993 conversions: {994 HEX: {995 read: function(original) {996 return {997 space: 'HEX',998 hex: original,999 conversionName: 'HEX'1000 }1001 },1002 write: function(color) {1003 return color.hex;1004 }1005 }1006 }1007 },1008 // Arrays1009 {1010 litmus: common.isArray,1011 conversions: {1012 RGB_ARRAY: {1013 read: function(original) {1014 if (original.length != 3) return false;1015 return {1016 space: 'RGB',1017 r: original[0],1018 g: original[1],1019 b: original[2]1020 };1021 },1022 write: function(color) {1023 return [color.r, color.g, color.b];1024 }1025 },1026 RGBA_ARRAY: {1027 read: function(original) {1028 if (original.length != 4) return false;1029 return {1030 space: 'RGB',1031 r: original[0],1032 g: original[1],1033 b: original[2],1034 a: original[3]1035 };1036 },1037 write: function(color) {1038 return [color.r, color.g, color.b, color.a];1039 }1040 }1041 }1042 },1043 // Objects1044 {1045 litmus: common.isObject,1046 conversions: {1047 RGBA_OBJ: {1048 read: function(original) {1049 if (common.isNumber(original.r) &&1050 common.isNumber(original.g) &&1051 common.isNumber(original.b) &&1052 common.isNumber(original.a)) {1053 return {1054 space: 'RGB',1055 r: original.r,1056 g: original.g,1057 b: original.b,1058 a: original.a1059 }1060 }1061 return false;1062 },1063 write: function(color) {1064 return {1065 r: color.r,1066 g: color.g,1067 b: color.b,1068 a: color.a1069 }1070 }1071 },1072 RGB_OBJ: {1073 read: function(original) {1074 if (common.isNumber(original.r) &&1075 common.isNumber(original.g) &&1076 common.isNumber(original.b)) {1077 return {1078 space: 'RGB',1079 r: original.r,1080 g: original.g,1081 b: original.b1082 }1083 }1084 return false;1085 },1086 write: function(color) {1087 return {1088 r: color.r,1089 g: color.g,1090 b: color.b1091 }1092 }1093 },1094 HSVA_OBJ: {1095 read: function(original) {1096 if (common.isNumber(original.h) &&1097 common.isNumber(original.s) &&1098 common.isNumber(original.v) &&1099 common.isNumber(original.a)) {1100 return {1101 space: 'HSV',1102 h: original.h,1103 s: original.s,1104 v: original.v,1105 a: original.a1106 }1107 }1108 return false;1109 },1110 write: function(color) {1111 return {1112 h: color.h,1113 s: color.s,1114 v: color.v,1115 a: color.a1116 }1117 }1118 },1119 HSV_OBJ: {1120 read: function(original) {1121 if (common.isNumber(original.h) &&1122 common.isNumber(original.s) &&1123 common.isNumber(original.v)) {1124 return {1125 space: 'HSV',1126 h: original.h,1127 s: original.s,1128 v: original.v1129 }1130 }1131 return false;1132 },1133 write: function(color) {1134 return {1135 h: color.h,1136 s: color.s,1137 v: color.v1138 }1139 }1140 }1141 }1142 }1143 ];1144 return interpret;1145})(dat.color.toString,1146 dat.utils.common);1147dat.GUI = dat.gui.GUI = (function (css, saveDialogueContents, styleSheet, controllerFactory, Controller, BooleanController, FunctionController, NumberControllerBox, NumberControllerSlider, OptionController, ColorController, requestAnimationFrame, CenteredDiv, dom, common) {1148 css.inject(styleSheet);1149 /** Outer-most className for GUI's */1150 var CSS_NAMESPACE = 'dg';1151 var HIDE_KEY_CODE = 72;1152 /** The only value shared between the JS and SCSS. Use caution. */1153 var CLOSE_BUTTON_HEIGHT = 20;1154 var DEFAULT_DEFAULT_PRESET_NAME = 'Default';1155 var SUPPORTS_LOCAL_STORAGE = (function() {1156 try {1157 return 'localStorage' in window && window['localStorage'] !== null;1158 } catch (e) {1159 return false;1160 }1161 })();1162 var SAVE_DIALOGUE;1163 /** Have we yet to create an autoPlace GUI? */1164 var auto_place_virgin = true;1165 /** Fixed position div that auto place GUI's go inside */1166 var auto_place_container;1167 /** Are we hiding the GUI's ? */1168 var hide = false;1169 /** GUI's which should be hidden */1170 var hideable_guis = [];1171 /**1172 * A lightweight controller library for JavaScript. It allows you to easily1173 * manipulate variables and fire functions on the fly.1174 * @class1175 *1176 * @member dat.gui1177 *1178 * @param {Object} [params]1179 * @param {String} [params.name] The name of this GUI.1180 * @param {Object} [params.load] JSON object representing the saved state of1181 * this GUI.1182 * @param {Boolean} [params.auto=true]1183 * @param {dat.gui.GUI} [params.parent] The GUI I'm nested in.1184 * @param {Boolean} [params.closed] If true, starts closed1185 */1186 var GUI = function(params) {1187 var _this = this;1188 /**1189 * Outermost DOM Element1190 * @type DOMElement1191 */1192 this.domElement = document.createElement('div');1193 this.__ul = document.createElement('ul');1194 this.domElement.appendChild(this.__ul);1195 dom.addClass(this.domElement, CSS_NAMESPACE);1196 /**1197 * Nested GUI's by name1198 * @ignore1199 */1200 this.__folders = {};1201 this.__controllers = [];1202 /**1203 * List of objects I'm remembering for save, only used in top level GUI1204 * @ignore1205 */1206 this.__rememberedObjects = [];1207 /**1208 * Maps the index of remembered objects to a map of controllers, only used1209 * in top level GUI.1210 *1211 * @private1212 * @ignore1213 *1214 * @example1215 * [1216 * {1217 * propertyName: Controller,1218 * anotherPropertyName: Controller1219 * },1220 * {1221 * propertyName: Controller1222 * }1223 * ]1224 */1225 this.__rememberedObjectIndecesToControllers = [];1226 this.__listening = [];1227 params = params || {};1228 // Default parameters1229 params = common.defaults(params, {1230 autoPlace: true,1231 width: GUI.DEFAULT_WIDTH1232 });1233 params = common.defaults(params, {1234 resizable: params.autoPlace,1235 hideable: params.autoPlace1236 });1237 if (!common.isUndefined(params.load)) {1238 // Explicit preset1239 if (params.preset) params.load.preset = params.preset;1240 } else {1241 params.load = { preset: DEFAULT_DEFAULT_PRESET_NAME };1242 }1243 if (common.isUndefined(params.parent) && params.hideable) {1244 hideable_guis.push(this);1245 }1246 // Only root level GUI's are resizable.1247 params.resizable = common.isUndefined(params.parent) && params.resizable;1248 if (params.autoPlace && common.isUndefined(params.scrollable)) {1249 params.scrollable = true;1250 }1251// params.scrollable = common.isUndefined(params.parent) && params.scrollable === true;1252 // Not part of params because I don't want people passing this in via1253 // constructor. Should be a 'remembered' value.1254 var use_local_storage =1255 SUPPORTS_LOCAL_STORAGE &&1256 localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true';1257 Object.defineProperties(this,1258 /** @lends dat.gui.GUI.prototype */1259 {1260 /**1261 * The parent <code>GUI</code>1262 * @type dat.gui.GUI1263 */1264 parent: {1265 get: function() {1266 return params.parent;1267 }1268 },1269 scrollable: {1270 get: function() {1271 return params.scrollable;1272 }1273 },1274 /**1275 * Handles <code>GUI</code>'s element placement for you1276 * @type Boolean1277 */1278 autoPlace: {1279 get: function() {1280 return params.autoPlace;1281 }1282 },1283 /**1284 * The identifier for a set of saved values1285 * @type String1286 */1287 preset: {1288 get: function() {1289 if (_this.parent) {1290 return _this.getRoot().preset;1291 } else {1292 return params.load.preset;1293 }1294 },1295 set: function(v) {1296 if (_this.parent) {1297 _this.getRoot().preset = v;1298 } else {1299 params.load.preset = v;1300 }1301 setPresetSelectIndex(this);1302 _this.revert();1303 }1304 },1305 /**1306 * The width of <code>GUI</code> element1307 * @type Number1308 */1309 width: {1310 get: function() {1311 return params.width;1312 },1313 set: function(v) {1314 params.width = v;1315 setWidth(_this, v);1316 }1317 },1318 /**1319 * The name of <code>GUI</code>. Used for folders. i.e1320 * a folder's name1321 * @type String1322 */1323 name: {1324 get: function() {1325 return params.name;1326 },1327 set: function(v) {1328 // TODO Check for collisions among sibling folders1329 params.name = v;1330 if (title_row_name) {1331 title_row_name.innerHTML = params.name;1332 }1333 }1334 },1335 /**1336 * Whether the <code>GUI</code> is collapsed or not1337 * @type Boolean1338 */1339 closed: {1340 get: function() {1341 return params.closed;1342 },1343 set: function(v) {1344 params.closed = v;1345 if (params.closed) {1346 dom.addClass(_this.__ul, GUI.CLASS_CLOSED);1347 } else {1348 dom.removeClass(_this.__ul, GUI.CLASS_CLOSED);1349 }1350 // For browsers that aren't going to respect the CSS transition,1351 // Lets just check our height against the window height right off1352 // the bat.1353 this.onResize();1354 if (_this.__closeButton) {1355 _this.__closeButton.innerHTML = v ? GUI.TEXT_OPEN : GUI.TEXT_CLOSED;1356 }1357 }1358 },1359 /**1360 * Contains all presets1361 * @type Object1362 */1363 load: {1364 get: function() {1365 return params.load;1366 }1367 },1368 /**1369 * Determines whether or not to use <a href="https://developer.mozilla.org/en/DOM/Storage#localStorage">localStorage</a> as the means for1370 * <code>remember</code>ing1371 * @type Boolean1372 */1373 useLocalStorage: {1374 get: function() {1375 return use_local_storage;1376 },1377 set: function(bool) {1378 if (SUPPORTS_LOCAL_STORAGE) {1379 use_local_storage = bool;1380 if (bool) {1381 dom.bind(window, 'unload', saveToLocalStorage);1382 } else {1383 dom.unbind(window, 'unload', saveToLocalStorage);1384 }1385 localStorage.setItem(getLocalStorageHash(_this, 'isLocal'), bool);1386 }1387 }1388 }1389 });1390 // Are we a root level GUI?1391 if (common.isUndefined(params.parent)) {1392 params.closed = false;1393 dom.addClass(this.domElement, GUI.CLASS_MAIN);1394 dom.makeSelectable(this.domElement, false);1395 // Are we supposed to be loading locally?1396 if (SUPPORTS_LOCAL_STORAGE) {1397 if (use_local_storage) {1398 _this.useLocalStorage = true;1399 var saved_gui = localStorage.getItem(getLocalStorageHash(this, 'gui'));1400 if (saved_gui) {1401 params.load = JSON.parse(saved_gui);1402 }1403 }1404 }1405 this.__closeButton = document.createElement('div');1406 this.__closeButton.innerHTML = GUI.TEXT_CLOSED;1407 dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BUTTON);1408 this.domElement.appendChild(this.__closeButton);1409 dom.bind(this.__closeButton, 'click', function() {1410 _this.closed = !_this.closed;1411 });1412 // Oh, you're a nested GUI!1413 } else {1414 if (params.closed === undefined) {1415 params.closed = true;1416 }1417 var title_row_name = document.createTextNode(params.name);1418 dom.addClass(title_row_name, 'controller-name');1419 var title_row = addRow(_this, title_row_name);1420 var on_click_title = function(e) {1421 e.preventDefault();1422 _this.closed = !_this.closed;1423 return false;1424 };1425 dom.addClass(this.__ul, GUI.CLASS_CLOSED);1426 dom.addClass(title_row, 'title');1427 dom.bind(title_row, 'click', on_click_title);1428 if (!params.closed) {1429 this.closed = false;1430 }1431 }1432 if (params.autoPlace) {1433 if (common.isUndefined(params.parent)) {1434 if (auto_place_virgin) {1435 auto_place_container = document.createElement('div');1436 dom.addClass(auto_place_container, CSS_NAMESPACE);1437 dom.addClass(auto_place_container, GUI.CLASS_AUTO_PLACE_CONTAINER);1438 document.body.appendChild(auto_place_container);1439 auto_place_virgin = false;1440 }1441 // Put it in the dom for you.1442 auto_place_container.appendChild(this.domElement);1443 // Apply the auto styles1444 dom.addClass(this.domElement, GUI.CLASS_AUTO_PLACE);1445 }1446 // Make it not elastic.1447 if (!this.parent) setWidth(_this, params.width);1448 }1449 dom.bind(window, 'resize', function() { _this.onResize() });1450 dom.bind(this.__ul, 'webkitTransitionEnd', function() { _this.onResize(); });1451 dom.bind(this.__ul, 'transitionend', function() { _this.onResize() });1452 dom.bind(this.__ul, 'oTransitionEnd', function() { _this.onResize() });1453 this.onResize();1454 if (params.resizable) {1455 addResizeHandle(this);1456 }1457 function saveToLocalStorage() {1458 localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject()));1459 }1460 var root = _this.getRoot();1461 function resetWidth() {1462 var root = _this.getRoot();1463 root.width += 1;1464 common.defer(function() {1465 root.width -= 1;1466 });1467 }1468 if (!params.parent) {1469 resetWidth();1470 }1471 };1472 GUI.toggleHide = function() {1473 hide = !hide;1474 common.each(hideable_guis, function(gui) {1475 gui.domElement.style.zIndex = hide ? -999 : 999;1476 gui.domElement.style.opacity = hide ? 0 : 1;1477 });1478 };1479 GUI.CLASS_AUTO_PLACE = 'a';1480 GUI.CLASS_AUTO_PLACE_CONTAINER = 'ac';1481 GUI.CLASS_MAIN = 'main';1482 GUI.CLASS_CONTROLLER_ROW = 'cr';1483 GUI.CLASS_TOO_TALL = 'taller-than-window';1484 GUI.CLASS_CLOSED = 'closed';1485 GUI.CLASS_CLOSE_BUTTON = 'close-button';1486 GUI.CLASS_DRAG = 'drag';1487 GUI.DEFAULT_WIDTH = 310;1488 GUI.TEXT_CLOSED = 'Close Controls';1489 GUI.TEXT_OPEN = 'Open Controls';1490 dom.bind(window, 'keydown', function(e) {1491 if (document.activeElement.type !== 'text' &&1492 (e.which === HIDE_KEY_CODE || e.keyCode == HIDE_KEY_CODE)) {1493 GUI.toggleHide();1494 }1495 }, false);1496 common.extend(1497 GUI.prototype,1498 /** @lends dat.gui.GUI */1499 {1500 /**1501 * @param object1502 * @param property1503 * @returns {dat.controllers.Controller} The new controller that was added.1504 * @instance1505 */1506 add: function(object, property) {1507 return add(1508 this,1509 object,1510 property,1511 {1512 factoryArgs: Array.prototype.slice.call(arguments, 2)1513 }1514 );1515 },1516 /**1517 * @param object1518 * @param property1519 * @returns {dat.controllers.ColorController} The new controller that was added.1520 * @instance1521 */1522 addColor: function(object, property) {1523 return add(1524 this,1525 object,1526 property,1527 {1528 color: true1529 }1530 );1531 },1532 /**1533 * @param controller1534 * @instance1535 */1536 remove: function(controller) {1537 // TODO listening?1538 this.__ul.removeChild(controller.__li);1539 this.__controllers.slice(this.__controllers.indexOf(controller), 1);1540 var _this = this;1541 common.defer(function() {1542 _this.onResize();1543 });1544 },1545 destroy: function() {1546 if (this.autoPlace) {1547 auto_place_container.removeChild(this.domElement);1548 }1549 },1550 /**1551 * @param name1552 * @returns {dat.gui.GUI} The new folder.1553 * @throws {Error} if this GUI already has a folder by the specified1554 * name1555 * @instance1556 */1557 addFolder: function(name) {1558 // We have to prevent collisions on names in order to have a key1559 // by which to remember saved values1560 if (this.__folders[name] !== undefined) {1561 throw new Error('You already have a folder in this GUI by the' +1562 ' name "' + name + '"');1563 }1564 var new_gui_params = { name: name, parent: this };1565 // We need to pass down the autoPlace trait so that we can1566 // attach event listeners to open/close folder actions to1567 // ensure that a scrollbar appears if the window is too short.1568 new_gui_params.autoPlace = this.autoPlace;1569 // Do we have saved appearance data for this folder?1570 if (this.load && // Anything loaded?1571 this.load.folders && // Was my parent a dead-end?1572 this.load.folders[name]) { // Did daddy remember me?1573 // Start me closed if I was closed1574 new_gui_params.closed = this.load.folders[name].closed;1575 // Pass down the loaded data1576 new_gui_params.load = this.load.folders[name];1577 }1578 var gui = new GUI(new_gui_params);1579 this.__folders[name] = gui;1580 var li = addRow(this, gui.domElement);1581 dom.addClass(li, 'folder');1582 return gui;1583 },1584 open: function() {1585 this.closed = false;1586 },1587 close: function() {1588 this.closed = true;1589 },1590 onResize: function() {1591 var root = this.getRoot();1592 if (root.scrollable) {1593 var top = dom.getOffset(root.__ul).top;1594 var h = 0;1595 common.each(root.__ul.childNodes, function(node) {1596 if (! (root.autoPlace && node === root.__save_row))1597 h += dom.getHeight(node);1598 });1599 if (window.innerHeight - top - CLOSE_BUTTON_HEIGHT < h) {1600 dom.addClass(root.domElement, GUI.CLASS_TOO_TALL);1601 root.__ul.style.height = window.innerHeight - top - CLOSE_BUTTON_HEIGHT + 'px';1602 } else {1603 dom.removeClass(root.domElement, GUI.CLASS_TOO_TALL);1604 root.__ul.style.height = 'auto';1605 }1606 }1607 if (root.__resize_handle) {1608 common.defer(function() {1609 root.__resize_handle.style.height = root.__ul.offsetHeight + 'px';1610 });1611 }1612 if (root.__closeButton) {1613 root.__closeButton.style.width = root.width + 'px';1614 }1615 },1616 /**1617 * Mark objects for saving. The order of these objects cannot change as1618 * the GUI grows. When remembering new objects, append them to the end1619 * of the list.1620 *1621 * @param {Object...} objects1622 * @throws {Error} if not called on a top level GUI.1623 * @instance1624 */1625 remember: function() {1626 if (common.isUndefined(SAVE_DIALOGUE)) {1627 SAVE_DIALOGUE = new CenteredDiv();1628 SAVE_DIALOGUE.domElement.innerHTML = saveDialogueContents;1629 }1630 if (this.parent) {1631 throw new Error("You can only call remember on a top level GUI.");1632 }1633 var _this = this;1634 common.each(Array.prototype.slice.call(arguments), function(object) {1635 if (_this.__rememberedObjects.length == 0) {1636 addSaveMenu(_this);1637 }1638 if (_this.__rememberedObjects.indexOf(object) == -1) {1639 _this.__rememberedObjects.push(object);1640 }1641 });1642 if (this.autoPlace) {1643 // Set save row width1644 setWidth(this, this.width);1645 }1646 },1647 /**1648 * @returns {dat.gui.GUI} the topmost parent GUI of a nested GUI.1649 * @instance1650 */1651 getRoot: function() {1652 var gui = this;1653 while (gui.parent) {1654 gui = gui.parent;1655 }1656 return gui;1657 },1658 /**1659 * @returns {Object} a JSON object representing the current state of1660 * this GUI as well as its remembered properties.1661 * @instance1662 */1663 getSaveObject: function() {1664 var toReturn = this.load;1665 toReturn.closed = this.closed;1666 // Am I remembering any values?1667 if (this.__rememberedObjects.length > 0) {1668 toReturn.preset = this.preset;1669 if (!toReturn.remembered) {1670 toReturn.remembered = {};1671 }1672 toReturn.remembered[this.preset] = getCurrentPreset(this);1673 }1674 toReturn.folders = {};1675 common.each(this.__folders, function(element, key) {1676 toReturn.folders[key] = element.getSaveObject();1677 });1678 return toReturn;1679 },1680 save: function() {1681 if (!this.load.remembered) {1682 this.load.remembered = {};1683 }1684 this.load.remembered[this.preset] = getCurrentPreset(this);1685 markPresetModified(this, false);1686 },1687 saveAs: function(presetName) {1688 if (!this.load.remembered) {1689 // Retain default values upon first save1690 this.load.remembered = {};1691 this.load.remembered[DEFAULT_DEFAULT_PRESET_NAME] = getCurrentPreset(this, true);1692 }1693 this.load.remembered[presetName] = getCurrentPreset(this);1694 this.preset = presetName;1695 addPresetOption(this, presetName, true);1696 },1697 revert: function(gui) {1698 common.each(this.__controllers, function(controller) {1699 // Make revert work on Default.1700 if (!this.getRoot().load.remembered) {1701 controller.setValue(controller.initialValue);1702 } else {1703 recallSavedValue(gui || this.getRoot(), controller);1704 }1705 }, this);1706 common.each(this.__folders, function(folder) {1707 folder.revert(folder);1708 });1709 if (!gui) {1710 markPresetModified(this.getRoot(), false);1711 }1712 },1713 listen: function(controller) {1714 var init = this.__listening.length == 0;1715 this.__listening.push(controller);1716 if (init) updateDisplays(this.__listening);1717 }1718 }1719 );1720 function add(gui, object, property, params) {1721 if (object[property] === undefined) {1722 throw new Error("Object " + object + " has no property \"" + property + "\"");1723 }1724 var controller;1725 if (params.color) {1726 controller = new ColorController(object, property);1727 } else {1728 var factoryArgs = [object,property].concat(params.factoryArgs);1729 controller = controllerFactory.apply(gui, factoryArgs);1730 }1731 if (params.before instanceof Controller) {1732 params.before = params.before.__li;1733 }1734 recallSavedValue(gui, controller);1735 dom.addClass(controller.domElement, 'c');1736 var name = document.createElement('span');1737 dom.addClass(name, 'property-name');1738 name.innerHTML = controller.property;1739 var container = document.createElement('div');1740 container.appendChild(name);1741 container.appendChild(controller.domElement);1742 var li = addRow(gui, container, params.before);1743 dom.addClass(li, GUI.CLASS_CONTROLLER_ROW);1744 dom.addClass(li, typeof controller.getValue());1745 augmentController(gui, li, controller);1746 gui.__controllers.push(controller);1747 return controller;1748 }1749 /**1750 * Add a row to the end of the GUI or before another row.1751 *1752 * @param gui1753 * @param [dom] If specified, inserts the dom content in the new row1754 * @param [liBefore] If specified, places the new row before another row1755 */1756 function addRow(gui, dom, liBefore) {1757 var li = document.createElement('li');1758 if (dom) li.appendChild(dom);1759 if (liBefore) {1760 gui.__ul.insertBefore(li, params.before);1761 } else {1762 gui.__ul.appendChild(li);1763 }1764 gui.onResize();1765 return li;1766 }1767 function augmentController(gui, li, controller) {1768 controller.__li = li;1769 controller.__gui = gui;1770 common.extend(controller, {1771 options: function(options) {1772 if (arguments.length > 1) {1773 controller.remove();1774 return add(1775 gui,1776 controller.object,1777 controller.property,1778 {1779 before: controller.__li.nextElementSibling,1780 factoryArgs: [common.toArray(arguments)]1781 }1782 );1783 }1784 if (common.isArray(options) || common.isObject(options)) {1785 controller.remove();1786 return add(1787 gui,1788 controller.object,1789 controller.property,1790 {1791 before: controller.__li.nextElementSibling,1792 factoryArgs: [options]1793 }1794 );1795 }1796 },1797 name: function(v) {1798 controller.__li.firstElementChild.firstElementChild.innerHTML = v;1799 return controller;1800 },1801 listen: function() {1802 controller.__gui.listen(controller);1803 return controller;1804 },1805 remove: function() {1806 controller.__gui.remove(controller);1807 return controller;1808 }1809 });1810 // All sliders should be accompanied by a box.1811 if (controller instanceof NumberControllerSlider) {1812 var box = new NumberControllerBox(controller.object, controller.property,1813 { min: controller.__min, max: controller.__max, step: controller.__step });1814 common.each(['updateDisplay', 'onChange', 'onFinishChange'], function(method) {1815 var pc = controller[method];1816 var pb = box[method];1817 controller[method] = box[method] = function() {1818 var args = Array.prototype.slice.call(arguments);1819 pc.apply(controller, args);1820 return pb.apply(box, args);1821 }1822 });1823 dom.addClass(li, 'has-slider');1824 controller.domElement.insertBefore(box.domElement, controller.domElement.firstElementChild);1825 }1826 else if (controller instanceof NumberControllerBox) {1827 var r = function(returned) {1828 // Have we defined both boundaries?1829 if (common.isNumber(controller.__min) && common.isNumber(controller.__max)) {1830 // Well, then lets just replace this with a slider.1831 controller.remove();1832 return add(1833 gui,1834 controller.object,1835 controller.property,1836 {1837 before: controller.__li.nextElementSibling,1838 factoryArgs: [controller.__min, controller.__max, controller.__step]1839 });1840 }1841 return returned;1842 };1843 controller.min = common.compose(r, controller.min);1844 controller.max = common.compose(r, controller.max);1845 }1846 else if (controller instanceof BooleanController) {1847 dom.bind(li, 'click', function() {1848 dom.fakeEvent(controller.__checkbox, 'click');1849 });1850 dom.bind(controller.__checkbox, 'click', function(e) {1851 e.stopPropagation(); // Prevents double-toggle1852 })1853 }1854 else if (controller instanceof FunctionController) {1855 dom.bind(li, 'click', function() {1856 dom.fakeEvent(controller.__button, 'click');1857 });1858 dom.bind(li, 'mouseover', function() {1859 dom.addClass(controller.__button, 'hover');1860 });1861 dom.bind(li, 'mouseout', function() {1862 dom.removeClass(controller.__button, 'hover');1863 });1864 }1865 else if (controller instanceof ColorController) {1866 dom.addClass(li, 'color');1867 controller.updateDisplay = common.compose(function(r) {1868 li.style.borderLeftColor = controller.__color.toString();1869 return r;1870 }, controller.updateDisplay);1871 controller.updateDisplay();1872 }1873 controller.setValue = common.compose(function(r) {1874 if (gui.getRoot().__preset_select && controller.isModified()) {1875 markPresetModified(gui.getRoot(), true);1876 }1877 return r;1878 }, controller.setValue);1879 }1880 function recallSavedValue(gui, controller) {1881 // Find the topmost GUI, that's where remembered objects live.1882 var root = gui.getRoot();1883 // Does the object we're controlling match anything we've been told to1884 // remember?1885 var matched_index = root.__rememberedObjects.indexOf(controller.object);1886 // Why yes, it does!1887 if (matched_index != -1) {1888 // Let me fetch a map of controllers for thcommon.isObject.1889 var controller_map =1890 root.__rememberedObjectIndecesToControllers[matched_index];1891 // Ohp, I believe this is the first controller we've created for this1892 // object. Lets make the map fresh.1893 if (controller_map === undefined) {1894 controller_map = {};1895 root.__rememberedObjectIndecesToControllers[matched_index] =1896 controller_map;1897 }1898 // Keep track of this controller1899 controller_map[controller.property] = controller;1900 // Okay, now have we saved any values for this controller?1901 if (root.load && root.load.remembered) {1902 var preset_map = root.load.remembered;1903 // Which preset are we trying to load?1904 var preset;1905 if (preset_map[gui.preset]) {1906 preset = preset_map[gui.preset];1907 } else if (preset_map[DEFAULT_DEFAULT_PRESET_NAME]) {1908 // Uhh, you can have the default instead?1909 preset = preset_map[DEFAULT_DEFAULT_PRESET_NAME];1910 } else {1911 // Nada.1912 return;1913 }1914 // Did the loaded object remember thcommon.isObject?1915 if (preset[matched_index] &&1916 // Did we remember this particular property?1917 preset[matched_index][controller.property] !== undefined) {1918 // We did remember something for this guy ...1919 var value = preset[matched_index][controller.property];1920 // And that's what it is.1921 controller.initialValue = value;1922 controller.setValue(value);1923 }1924 }1925 }1926 }1927 function getLocalStorageHash(gui, key) {1928 // TODO how does this deal with multiple GUI's?1929 return document.location.href + '.' + key;1930 }1931 function addSaveMenu(gui) {1932 var div = gui.__save_row = document.createElement('li');1933 dom.addClass(gui.domElement, 'has-save');1934 gui.__ul.insertBefore(div, gui.__ul.firstChild);1935 dom.addClass(div, 'save-row');1936 var gears = document.createElement('span');1937 gears.innerHTML = '&nbsp;';1938 dom.addClass(gears, 'button gears');1939 // TODO replace with FunctionController1940 var button = document.createElement('span');1941 button.innerHTML = 'Save';1942 dom.addClass(button, 'button');1943 dom.addClass(button, 'save');1944 var button2 = document.createElement('span');1945 button2.innerHTML = 'New';1946 dom.addClass(button2, 'button');1947 dom.addClass(button2, 'save-as');1948 var button3 = document.createElement('span');1949 button3.innerHTML = 'Revert';1950 dom.addClass(button3, 'button');1951 dom.addClass(button3, 'revert');1952 var select = gui.__preset_select = document.createElement('select');1953 if (gui.load && gui.load.remembered) {1954 common.each(gui.load.remembered, function(value, key) {1955 addPresetOption(gui, key, key == gui.preset);1956 });1957 } else {1958 addPresetOption(gui, DEFAULT_DEFAULT_PRESET_NAME, false);1959 }1960 dom.bind(select, 'change', function() {1961 for (var index = 0; index < gui.__preset_select.length; index++) {1962 gui.__preset_select[index].innerHTML = gui.__preset_select[index].value;1963 }1964 gui.preset = this.value;1965 });1966 div.appendChild(select);1967 div.appendChild(gears);1968 div.appendChild(button);1969 div.appendChild(button2);1970 div.appendChild(button3);1971 if (SUPPORTS_LOCAL_STORAGE) {1972 var saveLocally = document.getElementById('dg-save-locally');1973 var explain = document.getElementById('dg-local-explain');1974 saveLocally.style.display = 'block';1975 var localStorageCheckBox = document.getElementById('dg-local-storage');1976 if (localStorage.getItem(getLocalStorageHash(gui, 'isLocal')) === 'true') {1977 localStorageCheckBox.setAttribute('checked', 'checked');1978 }1979 function showHideExplain() {1980 explain.style.display = gui.useLocalStorage ? 'block' : 'none';1981 }1982 showHideExplain();1983 // TODO: Use a boolean controller, fool!1984 dom.bind(localStorageCheckBox, 'change', function() {1985 gui.useLocalStorage = !gui.useLocalStorage;1986 showHideExplain();1987 });1988 }1989 var newConstructorTextArea = document.getElementById('dg-new-constructor');1990 dom.bind(newConstructorTextArea, 'keydown', function(e) {1991 if (e.metaKey && (e.which === 67 || e.keyCode == 67)) {1992 SAVE_DIALOGUE.hide();1993 }1994 });1995 dom.bind(gears, 'click', function() {1996 newConstructorTextArea.innerHTML = JSON.stringify(gui.getSaveObject(), undefined, 2);1997 SAVE_DIALOGUE.show();1998 newConstructorTextArea.focus();1999 newConstructorTextArea.select();2000 });2001 dom.bind(button, 'click', function() {2002 gui.save();2003 });2004 dom.bind(button2, 'click', function() {2005 var presetName = prompt('Enter a new preset name.');2006 if (presetName) gui.saveAs(presetName);2007 });2008 dom.bind(button3, 'click', function() {2009 gui.revert();2010 });2011// div.appendChild(button2);2012 }2013 function addResizeHandle(gui) {2014 gui.__resize_handle = document.createElement('div');2015 common.extend(gui.__resize_handle.style, {2016 width: '6px',2017 marginLeft: '-3px',2018 height: '200px',2019 cursor: 'ew-resize',2020 position: 'absolute'2021// border: '1px solid blue'2022 });2023 var pmouseX;2024 dom.bind(gui.__resize_handle, 'mousedown', dragStart);2025 dom.bind(gui.__closeButton, 'mousedown', dragStart);2026 gui.domElement.insertBefore(gui.__resize_handle, gui.domElement.firstElementChild);2027 function dragStart(e) {2028 e.preventDefault();2029 pmouseX = e.clientX;2030 dom.addClass(gui.__closeButton, GUI.CLASS_DRAG);2031 dom.bind(window, 'mousemove', drag);2032 dom.bind(window, 'mouseup', dragStop);2033 return false;2034 }2035 function drag(e) {2036 e.preventDefault();2037 gui.width += pmouseX - e.clientX;2038 gui.onResize();2039 pmouseX = e.clientX;2040 return false;2041 }2042 function dragStop() {2043 dom.removeClass(gui.__closeButton, GUI.CLASS_DRAG);2044 dom.unbind(window, 'mousemove', drag);2045 dom.unbind(window, 'mouseup', dragStop);2046 }2047 }2048 function setWidth(gui, w) {2049 gui.domElement.style.width = w + 'px';2050 // Auto placed save-rows are position fixed, so we have to2051 // set the width manually if we want it to bleed to the edge2052 if (gui.__save_row && gui.autoPlace) {2053 gui.__save_row.style.width = w + 'px';2054 }if (gui.__closeButton) {2055 gui.__closeButton.style.width = w + 'px';2056 }2057 }2058 function getCurrentPreset(gui, useInitialValues) {2059 var toReturn = {};2060 // For each object I'm remembering2061 common.each(gui.__rememberedObjects, function(val, index) {2062 var saved_values = {};2063 // The controllers I've made for thcommon.isObject by property2064 var controller_map =2065 gui.__rememberedObjectIndecesToControllers[index];2066 // Remember each value for each property2067 common.each(controller_map, function(controller, property) {2068 saved_values[property] = useInitialValues ? controller.initialValue : controller.getValue();2069 });2070 // Save the values for thcommon.isObject2071 toReturn[index] = saved_values;2072 });2073 return toReturn;2074 }2075 function addPresetOption(gui, name, setSelected) {2076 var opt = document.createElement('option');2077 opt.innerHTML = name;2078 opt.value = name;2079 gui.__preset_select.appendChild(opt);2080 if (setSelected) {2081 gui.__preset_select.selectedIndex = gui.__preset_select.length - 1;2082 }2083 }2084 function setPresetSelectIndex(gui) {2085 for (var index = 0; index < gui.__preset_select.length; index++) {2086 if (gui.__preset_select[index].value == gui.preset) {2087 gui.__preset_select.selectedIndex = index;2088 }2089 }2090 }2091 function markPresetModified(gui, modified) {2092 var opt = gui.__preset_select[gui.__preset_select.selectedIndex];2093// console.log('mark', modified, opt);2094 if (modified) {2095 opt.innerHTML = opt.value + "*";2096 } else {2097 opt.innerHTML = opt.value;2098 }2099 }2100 function updateDisplays(controllerArray) {2101 if (controllerArray.length != 0) {2102 requestAnimationFrame(function() {2103 updateDisplays(controllerArray);2104 });2105 }2106 common.each(controllerArray, function(c) {2107 c.updateDisplay();2108 });2109 }2110 return GUI;2111})(dat.utils.css,2112 "<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>",2113 ".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 0.1s linear;-o-transition:opacity 0.1s linear;-moz-transition:opacity 0.1s linear;transition:opacity 0.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 0.1s linear;-o-transition:opacity 0.1s linear;-moz-transition:opacity 0.1s linear;transition:opacity 0.1s linear;border:0;position:absolute;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-x:hidden}.dg.a.has-save ul{margin-top:27px}.dg.a.has-save ul.closed{margin-top:0}.dg.a .save-row{position:fixed;top:0;z-index:1002}.dg li{-webkit-transition:height 0.1s ease-out;-o-transition:height 0.1s ease-out;-moz-transition:height 0.1s ease-out;transition:height 0.1s ease-out}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;overflow:hidden;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}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%}.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:9px}.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 .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.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}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n",2114 dat.controllers.factory = (function (OptionController, NumberControllerBox, NumberControllerSlider, StringController, FunctionController, BooleanController, common) {2115 return function(object, property) {2116 var initialValue = object[property];2117 // Providing options?2118 if (common.isArray(arguments[2]) || common.isObject(arguments[2])) {2119 return new OptionController(object, property, arguments[2]);2120 }2121 // Providing a map?2122 if (common.isNumber(initialValue)) {2123 if (common.isNumber(arguments[2]) && common.isNumber(arguments[3])) {2124 // Has min and max.2125 return new NumberControllerSlider(object, property, arguments[2], arguments[3]);2126 } else {2127 return new NumberControllerBox(object, property, { min: arguments[2], max: arguments[3] });2128 }2129 }2130 if (common.isString(initialValue)) {2131 return new StringController(object, property);2132 }2133 if (common.isFunction(initialValue)) {2134 return new FunctionController(object, property, '');2135 }2136 if (common.isBoolean(initialValue)) {2137 return new BooleanController(object, property);2138 }2139 }2140 })(dat.controllers.OptionController,2141 dat.controllers.NumberControllerBox,2142 dat.controllers.NumberControllerSlider,2143 dat.controllers.StringController = (function (Controller, dom, common) {2144 /**2145 * @class Provides a text input to alter the string property of an object.2146 *2147 * @extends dat.controllers.Controller2148 *2149 * @param {Object} object The object to be manipulated2150 * @param {string} property The name of the property to be manipulated2151 *2152 * @member dat.controllers2153 */2154 var StringController = function(object, property) {2155 StringController.superclass.call(this, object, property);2156 var _this = this;2157 this.__input = document.createElement('input');2158 this.__input.setAttribute('type', 'text');2159 dom.bind(this.__input, 'keyup', onChange);2160 dom.bind(this.__input, 'change', onChange);2161 dom.bind(this.__input, 'blur', onBlur);2162 dom.bind(this.__input, 'keydown', function(e) {2163 if (e.keyCode === 13) {2164 this.blur();2165 }2166 });2167 function onChange() {2168 _this.setValue(_this.__input.value);2169 }2170 function onBlur() {2171 if (_this.__onFinishChange) {2172 _this.__onFinishChange.call(_this, _this.getValue());2173 }2174 }2175 this.updateDisplay();2176 this.domElement.appendChild(this.__input);2177 };2178 StringController.superclass = Controller;2179 common.extend(2180 StringController.prototype,2181 Controller.prototype,2182 {2183 updateDisplay: function() {2184 // Stops the caret from moving on account of:2185 // keyup -> setValue -> updateDisplay2186 if (!dom.isActive(this.__input)) {2187 this.__input.value = this.getValue();2188 }2189 return StringController.superclass.prototype.updateDisplay.call(this);2190 }2191 }2192 );2193 return StringController;2194 })(dat.controllers.Controller,2195 dat.dom.dom,2196 dat.utils.common),2197 dat.controllers.FunctionController,2198 dat.controllers.BooleanController,2199 dat.utils.common),2200 dat.controllers.Controller,2201 dat.controllers.BooleanController,2202 dat.controllers.FunctionController,2203 dat.controllers.NumberControllerBox,2204 dat.controllers.NumberControllerSlider,2205 dat.controllers.OptionController,2206 dat.controllers.ColorController = (function (Controller, dom, Color, interpret, common) {2207 var ColorController = function(object, property) {2208 ColorController.superclass.call(this, object, property);2209 this.__color = new Color(this.getValue());2210 this.__temp = new Color(0);2211 var _this = this;2212 this.domElement = document.createElement('div');2213 dom.makeSelectable(this.domElement, false);2214 this.__selector = document.createElement('div');2215 this.__selector.className = 'selector';2216 this.__saturation_field = document.createElement('div');2217 this.__saturation_field.className = 'saturation-field';2218 this.__field_knob = document.createElement('div');2219 this.__field_knob.className = 'field-knob';2220 this.__field_knob_border = '2px solid ';2221 this.__hue_knob = document.createElement('div');2222 this.__hue_knob.className = 'hue-knob';2223 this.__hue_field = document.createElement('div');2224 this.__hue_field.className = 'hue-field';2225 this.__alpha_knob = document.createElement('div');2226 this.__alpha_knob.className = 'alpha-knob';2227 this.__alpha_field = document.createElement('div');2228 this.__alpha_field.className = 'alpha-field';2229 this.__input = document.createElement('input');2230 this.__input.type = 'text';2231 this.__input_textShadow = '0 1px 1px ';2232 dom.bind(this.__input, 'keydown', function(e) {2233 if (e.keyCode === 13) { // on enter2234 onBlur.call(this);2235 }2236 });2237 dom.bind(this.__input, 'blur', onBlur);2238 dom.bind(this.__selector, 'mousedown', function(e) {2239 dom2240 .addClass(this, 'drag')2241 .bind(window, 'mouseup', function(e) {2242 dom.removeClass(_this.__selector, 'drag');2243 });2244 });2245 var value_field = document.createElement('div');2246 common.extend(this.__selector.style, {2247 width: '144px',2248 height: '102px',2249 padding: '3px',2250 backgroundColor: '#222',2251 boxShadow: '0px 1px 3px rgba(0,0,0,0.3)'2252 });2253 common.extend(this.__field_knob.style, {2254 position: 'absolute',2255 width: '12px',2256 height: '12px',2257 border: this.__field_knob_border + (this.__color.v < .5 ? '#fff' : '#000'),2258 boxShadow: '0px 1px 3px rgba(0,0,0,0.5)',2259 borderRadius: '12px',2260 zIndex: 12261 });2262 common.extend(this.__hue_knob.style, {2263 position: 'absolute',2264 width: '15px',2265 height: '2px',2266 borderRight: '4px solid #fff',2267 zIndex: 12268 });2269 common.extend(this.__alpha_knob.style, {2270 position: 'absolute',2271 width: '15px',2272 height: '2px',2273 borderRight: '4px solid #fff',2274 zIndex: 12275 });2276 common.extend(this.__saturation_field.style, {2277 width: '100px',2278 height: '100px',2279 border: '1px solid #555',2280 marginRight: '3px',2281 display: 'inline-block',2282 cursor: 'pointer'2283 });2284 common.extend(value_field.style, {2285 width: '100%',2286 height: '100%',2287 background: 'none'2288 });2289 linearGradient(value_field, 'top', 'rgba(0,0,0,0)', '#000');2290 common.extend(this.__hue_field.style, {2291 width: '15px',2292 height: '100px',2293 display: 'inline-block',2294 border: '1px solid #555',2295 cursor: 'ns-resize'2296 });2297 hueGradient(this.__hue_field);2298 common.extend(this.__input.style, {2299 outline: 'none',2300// width: '120px',2301 textAlign: 'center',2302// padding: '4px',2303// marginBottom: '6px',2304 color: '#fff',2305 border: 0,2306 fontWeight: 'bold',2307 textShadow: this.__input_textShadow + 'rgba(0,0,0,0.7)'2308 });2309 common.extend(this.__alpha_field.style , {2310 width: '15px',2311 height: '100px',2312 marginLeft: '3px',2313 display: 'inline-block',2314 border: '1px solid #555',2315 cursor: 'ns-resize'2316 });2317 alphaGradient(this.__alpha_field, _this.__color);2318 dom.bind(this.__saturation_field, 'mousedown', fieldDown);2319 dom.bind(this.__field_knob, 'mousedown', fieldDown);2320 dom.bind(this.__alpha_field, 'mousedown', function (e) {2321 setA(e);2322 dom.bind(window, 'mousemove', setA);2323 dom.bind(window, 'mouseup', unbindA);2324 });2325 var setHValues = function (e) {2326 setH(e);2327 alphaGradient(_this.__alpha_field, _this.__color);2328 };2329 var setSVValues = function (e) {2330 setSV(e);2331 alphaGradient(_this.__alpha_field, _this.__color);2332 };2333 dom.bind(this.__hue_field, 'mousedown', function(e) {2334 setHValues(e);2335 dom.bind(window, 'mousemove', setHValues);2336 dom.bind(window, 'mouseup', unbindH);2337 });2338 function fieldDown(e) {2339 setSVValues(e);2340 // document.body.style.cursor = 'none';2341 dom.bind(window, 'mousemove', setSVValues);2342 dom.bind(window, 'mouseup', unbindSV);2343 }2344 function unbindSV() {2345 dom.unbind(window, 'mousemove', setSVValues);2346 dom.unbind(window, 'mouseup', unbindSV);2347 }2348 function onBlur() {2349 var i = interpret(this.value);2350 if (i !== false) {2351 _this.__color.__state = i;2352 _this.setValue(_this.__color.toOriginal());2353 } else {2354 this.value = _this.__color.toString();2355 }2356 }2357 function unbindA() {2358 dom.unbind(window, 'mousemove', setA);2359 dom.unbind(window, 'mouseup', unbindA);2360 }2361 function unbindH() {2362 dom.unbind(window, 'mousemove', setHValues);2363 dom.unbind(window, 'mouseup', unbindH);2364 }2365 this.__saturation_field.appendChild(value_field);2366 this.__selector.appendChild(this.__field_knob);2367 this.__selector.appendChild(this.__saturation_field);2368 this.__selector.appendChild(this.__hue_field);2369 this.__selector.appendChild(this.__alpha_field);2370 this.__hue_field.appendChild(this.__hue_knob);2371 this.__alpha_field.appendChild(this.__alpha_knob);2372 this.domElement.appendChild(this.__input);2373 this.domElement.appendChild(this.__selector);2374 this.updateDisplay();2375 function setSV(e) {2376 e.preventDefault();2377 var w = dom.getWidth(_this.__saturation_field);2378 var o = dom.getOffset(_this.__saturation_field);2379 var s = (e.clientX - o.left + document.body.scrollLeft) / w;2380 var v = 1 - (e.clientY - o.top + document.body.scrollTop) / w;2381 if (v > 1) v = 1;2382 else if (v < 0) v = 0;2383 if (s > 1) s = 1;2384 else if (s < 0) s = 0;2385 _this.__color.v = v;2386 _this.__color.s = s;2387 _this.setValue(_this.__color.toOriginal());2388 return false;2389 }2390 function setH(e) {2391 e.preventDefault();2392 var s = dom.getHeight(_this.__hue_field);2393 var o = dom.getOffset(_this.__hue_field);2394 var h = 1 - (e.clientY - o.top + document.body.scrollTop) / s;2395 if (h > 1) h = 1;2396 else if (h < 0) h = 0;2397 _this.__color.h = h * 360;2398 _this.setValue(_this.__color.toOriginal());2399 return false;2400 }2401 function setA(e) {2402 e.preventDefault();2403 var s = dom.getHeight(_this.__alpha_field);2404 var o = dom.getOffset(_this.__alpha_field);2405 var a = 1 - (e.clientY - o.top + document.body.scrollTop) / s;2406 if (a > 1) a = 1;2407 else if (a < 0) a = 0;2408 _this.__color.a = a.toFixed(2);2409 _this.setValue(_this.__color.toOriginal());2410 return false;2411 }2412 };2413 ColorController.superclass = Controller;2414 common.extend(2415 ColorController.prototype,2416 Controller.prototype,2417 {2418 updateDisplay: function() {2419 var i = interpret(this.getValue());2420 if (i !== false) {2421 var mismatch = false;2422 // Check for mismatch on the interpreted value.2423 common.each(Color.COMPONENTS, function(component) {2424 if (!common.isUndefined(i[component]) &&2425 !common.isUndefined(this.__color.__state[component]) &&2426 i[component] !== this.__color.__state[component]) {2427 mismatch = true;2428 return {}; // break2429 }2430 }, this);2431 // If nothing diverges, we keep our previous values2432 // for statefulness, otherwise we recalculate fresh2433 if (mismatch) {2434 common.extend(this.__color.__state, i);2435 }2436 }2437 common.extend(this.__temp.__state, this.__color.__state);2438 this.__temp.a = 1;2439 var flip = (this.__color.v < .5 || this.__color.s > .5) ? 255 : 0;2440 var _flip = 255 - flip;2441 common.extend(this.__field_knob.style, {2442 marginLeft: 100 * this.__color.s - 7 + 'px',2443 marginTop: 100 * (1 - this.__color.v) - 7 + 'px',2444 backgroundColor: this.__temp.toString(),2445 border: this.__field_knob_border + 'rgb(' + flip + ',' + flip + ',' + flip +')'2446 });2447 this.__alpha_knob.style.marginTop = (1 - this.__color.a) * 100 + 'px';2448 this.__hue_knob.style.marginTop = (1 - this.__color.h / 360) * 100 + 'px';2449 this.__temp.s = 1;2450 this.__temp.v = 1;2451 linearGradient(this.__saturation_field, 'left', '#fff', this.__temp.toString());2452 common.extend(this.__input.style, {2453 backgroundColor: this.__input.value = this.__color.toString(),2454 color: 'rgb(' + flip + ',' + flip + ',' + flip +')',2455 textShadow: this.__input_textShadow + 'rgba(' + _flip + ',' + _flip + ',' + _flip +',.7)'2456 });2457 }2458 }2459 );2460 var vendors = ['-moz-','-o-','-webkit-','-ms-',''];2461 function linearGradient(elem, x, a, b) {2462 elem.style.background = '';2463 common.each(vendors, function(vendor) {2464 elem.style.cssText += 'background: ' + vendor + 'linear-gradient('+x+', '+a+' 0%, ' + b + ' 100%); ';2465 });2466 }2467 function hueGradient(elem) {2468 elem.style.background = '';2469 elem.style.cssText += 'background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);'2470 elem.style.cssText += 'background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'2471 elem.style.cssText += 'background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'2472 elem.style.cssText += 'background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'2473 elem.style.cssText += 'background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'2474 }2475 function alphaGradient(elem, color) {2476 elem.style.background = '';2477 var rgb = color.rgb,2478 r = Math.floor(color.r),2479 g = Math.floor(color.g),2480 b = Math.floor(color.b),2481 rgbaStart = 'rgba('+r+','+g+','+b+',1)',2482 rgbaEnd = 'rgba('+r+','+g+','+b+',0)';2483 common.each(vendors, function(vendor) {2484 elem.style.cssText += 'background: ' + vendor + 'linear-gradient(top, '+rgbaStart+ ' , '+rgbaEnd+'); ';2485 });2486 }2487 return ColorController;2488 })(dat.controllers.Controller,2489 dat.dom.dom,2490 dat.color.Color = (function (interpret, math, toString, common) {2491 var Color = function() {2492 this.__state = interpret.apply(this, arguments);2493 if (this.__state === false) {2494 throw 'Failed to interpret color arguments';2495 }2496 this.__state.a = this.__state.a || 1;2497 };2498 Color.COMPONENTS = ['r','g','b','h','s','v','hex','a'];2499 common.extend(Color.prototype, {2500 toString: function() {2501 return toString(this);2502 },2503 toOriginal: function() {2504 return this.__state.conversion.write(this);2505 }2506 });2507 defineRGBComponent(Color.prototype, 'r', 2);2508 defineRGBComponent(Color.prototype, 'g', 1);2509 defineRGBComponent(Color.prototype, 'b', 0);2510 defineHSVComponent(Color.prototype, 'h');2511 defineHSVComponent(Color.prototype, 's');2512 defineHSVComponent(Color.prototype, 'v');2513 Object.defineProperty(Color.prototype, 'a', {2514 get: function() {2515 return this.__state.a;2516 },2517 set: function(v) {2518 this.__state.a = v;2519 }2520 });2521 Object.defineProperty(Color.prototype, 'rgb', {2522 get: function() {2523 return math.hsv_to_rgb(this.__state.h, 1, 1);2524 },2525 set: function(v) {2526 }2527 });2528 Object.defineProperty(Color.prototype, 'hex', {2529 get: function() {2530 if (!this.__state.space !== 'HEX') {2531 this.__state.hex = math.rgb_to_hex(this.r, this.g, this.b);2532 }2533 return this.__state.hex;2534 },2535 set: function(v) {2536 this.__state.space = 'HEX';2537 this.__state.hex = v;2538 }2539 });2540 function defineRGBComponent(target, component, componentHexIndex) {2541 Object.defineProperty(target, component, {2542 get: function() {2543 if (this.__state.space === 'RGB') {2544 return this.__state[component];2545 }2546 recalculateRGB(this, component, componentHexIndex);2547 return this.__state[component];2548 },2549 set: function(v) {2550 if (this.__state.space !== 'RGB') {2551 recalculateRGB(this, component, componentHexIndex);2552 this.__state.space = 'RGB';2553 }2554 this.__state[component] = v;2555 }2556 });2557 }2558 function defineHSVComponent(target, component) {2559 Object.defineProperty(target, component, {2560 get: function() {2561 if (this.__state.space === 'HSV')2562 return this.__state[component];2563 recalculateHSV(this);2564 return this.__state[component];2565 },2566 set: function(v) {2567 if (this.__state.space !== 'HSV') {2568 recalculateHSV(this);2569 this.__state.space = 'HSV';2570 }2571 this.__state[component] = v;2572 }2573 });2574 }2575 function recalculateRGB(color, component, componentHexIndex) {2576 if (color.__state.space === 'HEX') {2577 color.__state[component] = math.component_from_hex(color.__state.hex, componentHexIndex);2578 } else if (color.__state.space === 'HSV') {2579 common.extend(color.__state, math.hsv_to_rgb(color.__state.h, color.__state.s, color.__state.v));2580 } else {2581 throw 'Corrupted color state';2582 }2583 }2584 function recalculateHSV(color) {2585 var result = math.rgb_to_hsv(color.r, color.g, color.b);2586 common.extend(color.__state,2587 {2588 s: result.s,2589 v: result.v2590 }2591 );2592 if (!common.isNaN(result.h)) {2593 color.__state.h = result.h;2594 } else if (common.isUndefined(color.__state.h)) {2595 color.__state.h = 0;2596 }2597 }2598 return Color;2599 })(dat.color.interpret,2600 dat.color.math = (function () {2601 var tmpComponent;2602 return {2603 hsv_to_rgb: function(h, s, v) {2604 var hi = Math.floor(h / 60) % 6;2605 var f = h / 60 - Math.floor(h / 60);2606 var p = v * (1.0 - s);2607 var q = v * (1.0 - (f * s));2608 var t = v * (1.0 - ((1.0 - f) * s));2609 var c = [2610 [v, t, p],2611 [q, v, p],2612 [p, v, t],2613 [p, q, v],2614 [t, p, v],2615 [v, p, q]2616 ][hi];2617 return {2618 r: c[0] * 255,2619 g: c[1] * 255,2620 b: c[2] * 2552621 };2622 },2623 rgb_to_hsv: function(r, g, b) {2624 var min = Math.min(r, g, b),2625 max = Math.max(r, g, b),2626 delta = max - min,2627 h, s;2628 if (max != 0) {2629 s = delta / max;2630 } else {2631 return {2632 h: NaN,2633 s: 0,2634 v: 02635 };2636 }2637 if (r == max) {2638 h = (g - b) / delta;2639 } else if (g == max) {2640 h = 2 + (b - r) / delta;2641 } else {2642 h = 4 + (r - g) / delta;2643 }2644 h /= 6;2645 if (h < 0) {2646 h += 1;2647 }2648 return {2649 h: h * 360,2650 s: s,2651 v: max / 2552652 };2653 },2654 rgb_to_hex: function(r, g, b) {2655 var hex = this.hex_with_component(0, 2, r);2656 hex = this.hex_with_component(hex, 1, g);2657 hex = this.hex_with_component(hex, 0, b);2658 return hex;2659 },2660 component_from_hex: function(hex, componentIndex) {2661 return (hex >> (componentIndex * 8)) & 0xFF;2662 },2663 hex_with_component: function(hex, componentIndex, value) {2664 return value << (tmpComponent = componentIndex * 8) | (hex & ~ (0xFF << tmpComponent));2665 }2666 }2667 })(),2668 dat.color.toString,2669 dat.utils.common),2670 dat.color.interpret,2671 dat.utils.common),2672 dat.utils.requestAnimationFrame = (function () {2673 /**2674 * requirejs version of Paul Irish's RequestAnimationFrame2675 * http://paulirish.com/2011/requestanimationframe-for-smart-animating/2676 */2677 return window.webkitRequestAnimationFrame ||2678 window.mozRequestAnimationFrame ||2679 window.oRequestAnimationFrame ||2680 window.msRequestAnimationFrame ||2681 function(callback, element) {2682 window.setTimeout(callback, 1000 / 60);2683 };2684 })(),2685 dat.dom.CenteredDiv = (function (dom, common) {2686 var CenteredDiv = function() {2687 this.backgroundElement = document.createElement('div');2688 common.extend(this.backgroundElement.style, {2689 backgroundColor: 'rgba(0,0,0,0.8)',2690 top: 0,2691 left: 0,2692 display: 'none',2693 zIndex: '1000',2694 opacity: 0,2695 WebkitTransition: 'opacity 0.2s linear'2696 });2697 dom.makeFullscreen(this.backgroundElement);2698 this.backgroundElement.style.position = 'fixed';2699 this.domElement = document.createElement('div');2700 common.extend(this.domElement.style, {2701 position: 'fixed',2702 display: 'none',2703 zIndex: '1001',2704 opacity: 0,2705 WebkitTransition: '-webkit-transform 0.2s ease-out, opacity 0.2s linear'2706 });2707 document.body.appendChild(this.backgroundElement);2708 document.body.appendChild(this.domElement);2709 var _this = this;2710 dom.bind(this.backgroundElement, 'click', function() {2711 _this.hide();2712 });2713 };2714 CenteredDiv.prototype.show = function() {2715 var _this = this;2716 this.backgroundElement.style.display = 'block';2717 this.domElement.style.display = 'block';2718 this.domElement.style.opacity = 0;2719// this.domElement.style.top = '52%';2720 this.domElement.style.webkitTransform = 'scale(1.1)';2721 this.layout();2722 common.defer(function() {2723 _this.backgroundElement.style.opacity = 1;2724 _this.domElement.style.opacity = 1;2725 _this.domElement.style.webkitTransform = 'scale(1)';2726 });2727 };2728 CenteredDiv.prototype.hide = function() {2729 var _this = this;2730 var hide = function() {2731 _this.domElement.style.display = 'none';2732 _this.backgroundElement.style.display = 'none';2733 dom.unbind(_this.domElement, 'webkitTransitionEnd', hide);2734 dom.unbind(_this.domElement, 'transitionend', hide);2735 dom.unbind(_this.domElement, 'oTransitionEnd', hide);2736 };2737 dom.bind(this.domElement, 'webkitTransitionEnd', hide);2738 dom.bind(this.domElement, 'transitionend', hide);2739 dom.bind(this.domElement, 'oTransitionEnd', hide);2740 this.backgroundElement.style.opacity = 0;2741// this.domElement.style.top = '48%';2742 this.domElement.style.opacity = 0;2743 this.domElement.style.webkitTransform = 'scale(1.1)';2744 };2745 CenteredDiv.prototype.layout = function() {2746 this.domElement.style.left = window.innerWidth/2 - dom.getWidth(this.domElement) / 2 + 'px';2747 this.domElement.style.top = window.innerHeight/2 - dom.getHeight(this.domElement) / 2 + 'px';2748 };2749 function lockScroll(e) {2750 console.log(e);2751 }2752 return CenteredDiv;2753 })(dat.dom.dom,2754 dat.utils.common),2755 dat.dom.dom,...

Full Screen

Full Screen

SourceValuesIterator.spec.ts

Source:SourceValuesIterator.spec.ts Github

copy

Full Screen

1import * as fc from 'fast-check';2import { SourceValuesIterator } from '../../../../src/check/runner/SourceValuesIterator';3function iota() {4 function* g() {5 let idx = 0;6 while (true) yield idx++;7 }8 return new fc.Stream(g());9}10function iotaN(n: number) {11 return iota().take(n);12}13function source() {14 return iota()15 .map((v) => () => v)16 [Symbol.iterator]();17}18function sourceN(n: number) {19 return iotaN(n)20 .map((v) => () => v)21 [Symbol.iterator]();22}23function simulateSkips(svIt: SourceValuesIterator<number>, skippedValues: number[]) {24 const svValues = [];25 for (const v of svIt) {26 if (skippedValues.includes(v)) svIt.skippedOne();27 else svValues.push(v);28 }29 return svValues;30}31describe('SourceValuesIterator', () => {32 it('Should only call the produce method when iterating on the value', () =>33 fc.assert(34 fc.property(fc.nat(100), (askedValues) => {35 const generatedValues: number[] = [];36 const initialValues = iota()37 .map((v) => () => {38 generatedValues.push(v);39 return v;40 })41 [Symbol.iterator]();42 const svIt = new SourceValuesIterator(initialValues, askedValues, 0);43 const svValues = [...svIt];44 expect(generatedValues).toHaveLength(askedValues);45 expect(generatedValues).toEqual(svValues);46 })47 ));48 describe('Not enough skipped values', () => {49 it('Should return the first eligible askedValues values if infinite source', () =>50 fc.assert(51 fc.property(fc.nat(100), fc.uniqueArray(fc.nat(100)), (askedValues, skippedValues) => {52 const svIt = new SourceValuesIterator(source(), askedValues, skippedValues.length);53 const svValues = simulateSkips(svIt, skippedValues);54 const expectedValues = [55 ...iota()56 .filter((v) => !skippedValues.includes(v))57 .take(askedValues),58 ];59 expect(svValues).toHaveLength(askedValues);60 expect(svValues).toEqual(expectedValues);61 })62 ));63 it('Should return the first eligible askedValues values if larger source', () =>64 fc.assert(65 fc.property(66 fc.nat(100),67 fc.nat(100),68 fc.uniqueArray(fc.nat(100)),69 (askedValues, additionalValuesInSource, skippedValues) => {70 const initialValues = sourceN(askedValues + additionalValuesInSource + skippedValues.length);71 const svIt = new SourceValuesIterator(initialValues, askedValues, skippedValues.length);72 const svValues = simulateSkips(svIt, skippedValues);73 const expectedValues = [74 ...iota()75 .filter((v) => !skippedValues.includes(v))76 .take(askedValues),77 ];78 expect(svValues).toHaveLength(askedValues);79 expect(svValues).toEqual(expectedValues);80 }81 )82 ));83 it('Should return the first eligible values among sourceValues values if smaller source', () =>84 fc.assert(85 fc.property(86 fc.nat(100),87 fc.nat(100),88 fc.uniqueArray(fc.nat(100)),89 (sourceValues, additionalAskedValues, skippedValues) => {90 const askedValues = sourceValues + additionalAskedValues;91 const svIt = new SourceValuesIterator(sourceN(sourceValues), askedValues, skippedValues.length);92 const svValues = simulateSkips(svIt, skippedValues);93 const numSkippedValues = skippedValues.filter((v) => v < sourceValues).length;94 const expectedValues = [95 ...iota()96 .take(sourceValues)97 .filter((v) => !skippedValues.includes(v)),98 ];99 expect(svValues).toHaveLength(sourceValues - numSkippedValues);100 expect(svValues).toEqual(expectedValues);101 }102 )103 ));104 });105 describe('Too many skipped values', () => {106 it('Should stop as soon as it passes maxSkips skipped values', () =>107 fc.assert(108 fc.property(109 fc.uniqueArray(fc.nat(100), { minLength: 1, maxLength: 20 }),110 fc.integer({ min: 1, max: 100 }),111 (skippedValues, missingValues) => {112 const lastSkip = skippedValues.reduce((prev, cur) => (prev > cur ? prev : cur), 0);113 const askedValues = lastSkip + 1 - skippedValues.length + missingValues;114 const svIt = new SourceValuesIterator(source(), askedValues, skippedValues.length - 1);115 const svValues = simulateSkips(svIt, skippedValues);116 const expectedValues = [...iotaN(lastSkip).filter((v) => !skippedValues.includes(v))];117 expect(svValues).toEqual(expectedValues);118 }119 )120 ));121 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import {svValues} from 'fast-check-monorepo';2const values = svValues();3console.log(values);4{5 "scripts": {6 },7 "dependencies": {8 }9}10The fast-check-monorepo package is a simple package that exports a single function svValues() . It is used to return a list of values that are used by the SV project. The SV project is a project that is used to test the functionality of the SV tool. The SV tool is a tool that is used to test the functionality of the SV project. The SV project is a project that is used to test the functionality of the SV tool. The SV tool is a tool that is used to test the functionality of the SV project. The SV project is a project that is used to test the functionality of the SV tool. The SV tool is a tool that is used to test the functionality of the SV project. The SV project is a project that is used to test the functionality of the SV tool. The SV tool is a tool that is used to test the functionality of the SV project. The SV project is a project that is used to test the functionality of the SV tool. The SV tool is a tool that is used to test the functionality of the SV project. The SV project is a project that is used to test the functionality of the SV tool. The SV tool is a tool that is used to test the functionality of the SV project. The SV project is a project that is used to test the functionality of the SV tool. The SV tool is a tool that is used to test the functionality of the SV project. The SV project is a project that is used to test the functionality of the SV tool. The SV tool is a tool that is used to test the functionality of the SV project. The SV project is a project that is used to test the functionality of the SV tool. The SV tool is a tool that is used to test the functionality of the SV project. The SV project is a project that is used to test the functionality of the SV tool. The SV tool is a tool that

Full Screen

Using AI Code Generation

copy

Full Screen

1const {svValues} = require('fast-check-monorepo');2const {svValues} = require('fast-check-monorepo');3const svValues = require('fast-check-monorepo').svValues;4const svValues = require('fast-check-monorepo').svValues;5const {svValues} = require('fast-check-monorepo');6const {svValues} = require('fast-check-monorepo');7const svValues = require('fast-check-monorepo').svValues;8const svValues = require('fast-check-monorepo').svValues;9const {svValues} = require('fast-check-monorepo');10const {svValues} = require('fast-check-monorepo');11const svValues = require('fast-check-monorepo').svValues;12const svValues = require('fast-check-monorepo').svValues;13const {svValues} = require('fast-check-monorepo');14const {svValues} = require('fast-check-monorepo');15const svValues = require('fast-check-monorepo').svValues;16const svValues = require('fast-check-monorepo').svValues;17const {svValues} = require('fast-check-monorepo');18const {svValues} = require('fast-check-monorepo');19const svValues = require('fast-check-monorepo').svValues;20const svValues = require('fast-check-monorepo').svValues;21const {svValues} = require('fast-check-monorepo');22const {svValues} = require('fast-check-monorepo');23const svValues = require('fast-check-monorepo').svValues;24const svValues = require('fast-check-monorepo').svValues;25const {svValues} = require('fast-check-monorepo');26const {svValues} = require('fast-check-monorepo');27const svValues = require('fast-check-monorepo').svValues;28const svValues = require('fast-check-monorepo').svValues;29const {svValues} = require('fast-check-monorepo');30const {svValues} = require('fast-check-monorepo');

Full Screen

Using AI Code Generation

copy

Full Screen

1const {svValues} = require('fast-check-monorepo');2const sv = svValues;3const sv1 = sv(1, 2, 3);4console.log(sv1);5const sv2 = sv(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);6console.log(sv2);7const sv3 = sv(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);8console.log(sv3);9const sv4 = sv(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);10console.log(sv4);11const sv5 = sv(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);12console.log(sv5);13const sv6 = sv(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);14console.log(sv6);15const sv7 = sv(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { svValues } = require('fast-check');2const { svInteger } = require('fast-check');3const { svTuple } = require('fast-check');4const { svFrequency } = require('fast-check');5const { svObject } = require('fast-check');6const { svRecord } = require('fast-check');7const { svString } = require('fast-check');8const { svOneOf } = require('fast-check');9const { svBoolean } = require('fast-check');10const { svMap } = require('fast-check');11const { svSet } = require('fast-check');12const { svArray } = require('fast-check');13const { svDate } = require('fast-check');14const { svDateFromInterval } = require('fast-check');15const { svDateMax } = require('fast-check');16const { svDateMin } = require('fast-check');17const { svDateWithin } = require('fast-check');18const { svDateWithinNext } = require('fast-check');19const { svDateWithinPast } = require('fast-check');20const { svObjectWith } = require('fast-check');21const { svObjectWithKeys } = require('fast-check');22const { svObjectWithKeysOf } = require('fast-check');23const { svObjectWithKeysOfAtLeast } = require('fast-check');24const { svObjectWithKeysOfAtMost } = require('fast-check');25const { svObjectWithKeysOfBetween } = require('fast-check');26const { svObjectWithKeysOfLength } = require('fast-check');27const { svObjectWithKeysOfMaxLength } = require('fast-check');28const { svObjectWithKeysOfMinLength } = require('fast-check');29const { svObjectWithKeysOfSubset } = require('fast-check');30const { svObjectWithKeysOfSuperset } = require('fast-check');31const { svObjectWithKeysOfUnique } = require('fast-check');32const { svObjectWithKeysOfUniqueValues } = require('fast-check');33const { svObjectWithKeysOfValues } = require('fast-check');34const { svObjectWithKeysOfValuesOf } = require('fast-check');35const { svObjectWithKeysOfValuesOfAtLeast } = require('fast-check');36const { svObjectWithKeysOfValuesOfAtMost } = require('fast-check');37const { svObjectWithKeysOfValuesOfBetween } = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1let fc = require('fast-check');2let svValues = require('fast-check-monorepo/svValues');3let arbs = svValues(fc);4let arb = arbs.svArray(arbs.svString);5fc.assert(fc.property(arb, (arr) => {6 return arr.length > 0;7}));8{9 "dependencies": {10 }11}12let fc = require('fast-check');13let svValues = require('fast-check-monorepo/svValues');14let arbs = svValues(fc);15let arb = arbs.svArray(arbs.svString);16fc.assert(fc.property(arb, (arr) => {17 return arr.length > 0;18}));19{20 "dependencies": {21 }22}23let fc = require('fast-check');24let svValues = require('fast-check-monorepo/svValues');25let arbs = svValues(fc);26let arb = arbs.svArray(arbs.svString);27fc.assert(fc.property(arb, (arr) => {28 return arr.length > 0;29}));30{31 "dependencies": {32 }33}34let fc = require('fast-check');35let svValues = require('fast-check-monorepo/svValues');36let arbs = svValues(fc);37let arb = arbs.svArray(arbs.svString);38fc.assert(fc.property(arb, (arr) => {39 return arr.length > 0;40}));41{42 "dependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const {svValues} = require("@fast-check/sv-values");2const {fc} = require("fast-check");3const {sv} = require("@fast-check/sv");4const myFunction = (a, b, c) => {5 return a + b + c;6};7const inputGenerator = svValues({8 a: sv.integer({min: 0, max: 100}),9 b: sv.integer({min: 0, max: 100}),10 c: sv.integer({min: 0, max: 100})11});12const myFunctionCheck = (a, b, c, output) => {13 return myFunction(a, b, c) === output;14};15const outputGenerator = svValues({16 output: sv.integer({min: 0, max: 100})17});18const inputOutputGenerator = svValues({19 a: sv.integer({min: 0, max: 100}),20 b: sv.integer({min: 0, max: 100}),21 c: sv.integer({min: 0, max: 100}),22 output: sv.integer({min: 0, max: 100})23});24const myFunctionCheck2 = (a, b, c, output) => {25 return myFunction(a, b, c) === output;26};27const inputOutputGenerator2 = svValues({28 a: sv.integer({min: 0, max: 100}),29 b: sv.integer({min: 0, max: 100}),30 c: sv.integer({min: 0, max: 100}),31 output: sv.integer({min: 0, max: 100})32});33const myFunctionCheck3 = (a, b, c, output) => {34 return myFunction(a, b, c) === output;35};36const inputOutputGenerator3 = svValues({37 a: sv.integer({min: 0, max: 100}),

Full Screen

Using AI Code Generation

copy

Full Screen

1import { NextArbitrary, svValues } from 'fast-check'2const arb = new NextArbitrary<T>()3const values = svValues(arb, 42)4for (const value of values) {5 console.log(value)6}7import * as fc from 'fast-check'8const values = fc.svValues(fc.integer(0, 10), 10)9for (const value of values) {10 console.log(value)11}12import * as fc from 'fast-check'13const values = fc.svValues(fc.integer(0, 10), 42, 10)14for (const value of values) {15 console.log(value)16}17import * as fc from 'fast-check'18const values = fc.svValues(fc.integer(0, 10), 42, 10)19for (const value of values) {20 console.log(value)21}22import * as fc from 'fast-check'23const values = fc.svValues(fc.integer(0, 10), 42, 10)24for (const value of values) {25 console.log(value)26}27import * as fc from 'fast-check'28const values = fc.svValues(fc.integer(0, 10), 42, 10)29for (const value of values) {30 console.log(value)31}32import * as fc from 'fast-check'

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful