UNPKG

dat.gui.image

Version:

Plugin to give you another GUI function called

1 lines 9.13 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["dat.gui.image"]=t():e["dat.gui.image"]=t()}(window,function(){return r={},i.m=n=[function(e,t,n){"use strict";n.r(t);n(1);function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function l(e,t,n){return(l="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=d(e)););return e}(e,t);if(r){var i=Object.getOwnPropertyDescriptor(r,t);return i.get?i.get.call(n):i.value}})(e,t,n||e)}function s(o){return function(){var e,t,n,r=d(o);if(function(){if("undefined"==typeof Reflect||!Reflect.construct)return;if(Reflect.construct.sham)return;if("function"==typeof Proxy)return 1;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),1}catch(e){return}}()){var i=d(this).constructor;e=Reflect.construct(r,arguments,i)}else e=r.apply(this,arguments);return t=this,!(n=e)||"object"!==a(n)&&"function"!=typeof n?f(t):n}}function f(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function p(e,t){return(p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}t.default=function(a){var c=a.dom.dom,u=function(){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&p(e,t)}(i,a.controllers.Controller);var e,t,n,r=s(i);function i(e,t){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,i),(n=r.call(this,e,t)).__onChangeFirstTime=!0,n.__fileReader=new FileReader,n.__image=document.createElement("img"),n.__imagePreview=document.createElement("img"),n.__input=document.createElement("input"),n.__image.src=e[t],n.__imagePreview.src=e[t],n.__input.type="file",c.bind(n.__image,"load",n.handleImageLoaded.bind(f(n))),c.bind(n.__input,"change",n.handleFileUpload.bind(f(n))),c.bind(n.__fileReader,"loadend",n.handleFileLoaded.bind(f(n))),c.addClass(n.__imagePreview,"preview"),n.domElement.appendChild(n.__imagePreview),n.domElement.appendChild(n.__input),n}return e=i,(t=[{key:"handleFileUpload",value:function(){var e=this.__input.files[0];e&&(this.__input.value="",this.__fileReader.readAsDataURL(e))}},{key:"handleFileLoaded",value:function(){this.handleFilePath(this.__fileReader.result)}},{key:"handleFilePath",value:function(e){e&&(this.__image.src=e)}},{key:"handleImageLoaded",value:function(){this.__imagePreview.src=this.__image.src,this.__onChange&&(this.__onChange.call(this,this.__image,this.__onChangeFirstTime),this.__onChangeFirstTime=!1)}},{key:"updateDisplay",value:function(){if(this.isModified()){var e=this.getValue();this.handleFilePath(e),this.initialValue=e}return l(d(i.prototype),"updateDisplay",this).call(this)}}])&&o(e.prototype,t),n&&o(e,n),i}();a.GUI.prototype.addImage=function(e,t){if(void 0===e[t])throw new Error('Object "'+e+'" has no property "'+t+'"');var n=new u(e,t);c.addClass(n.domElement,"c");var r=document.createElement("span");c.addClass(r,"property-name"),r.innerHTML=n.property;var i=document.createElement("div");i.appendChild(r),i.appendChild(n.domElement);var o=document.createElement("li");return i&&o.appendChild(i),this.__ul.appendChild(o),this.onResize(),c.addClass(o,a.GUI.CLASS_CONTROLLER_ROW),c.addClass(o,"image"),n.__li=o,n.__gui=this,n.name=function(e){return this.__li.firstElementChild.firstElementChild.innerHTML=e,this},n.listen=function(){return this.__gui.listen(this),this},n.remove=function(){return this.__gui.remove(this),this},this.__controllers.push(n),n}}},function(e,t,n){var r=n(2),i=n(3);"string"==typeof(i=i.__esModule?i.default:i)&&(i=[[e.i,i,""]]);var o={insert:"head",singleton:!1},a=(r(i,o),i.locals?i.locals:{});e.exports=a},function(e,t,o){"use strict";var n,r,i=function(){return void 0===n&&(n=Boolean(window&&document&&document.all&&!window.atob)),n},a=(r={},function(e){if(void 0===r[e]){var t=document.querySelector(e);if(window.HTMLIFrameElement&&t instanceof window.HTMLIFrameElement)try{t=t.contentDocument.head}catch(e){t=null}r[e]=t}return r[e]}),f=[];function d(e){for(var t=-1,n=0;n<f.length;n++)if(f[n].identifier===e){t=n;break}return t}function u(e,t){for(var n={},r=[],i=0;i<e.length;i++){var o=e[i],a=t.base?o[0]+t.base:o[0],c=n[a]||0,u="".concat(a," ").concat(c);n[a]=c+1;var l=d(u),s={css:o[1],media:o[2],sourceMap:o[3]};-1!==l?(f[l].references++,f[l].updater(s)):f.push({identifier:u,updater:v(s,t),references:1}),r.push(u)}return r}function c(e){var t=document.createElement("style"),n=e.attributes||{};if(void 0===n.nonce){var r=o.nc;r&&(n.nonce=r)}if(Object.keys(n).forEach(function(e){t.setAttribute(e,n[e])}),"function"==typeof e.insert)e.insert(t);else{var i=a(e.insert||"head");if(!i)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");i.appendChild(t)}return t}var l,s=(l=[],function(e,t){return l[e]=t,l.filter(Boolean).join("\n")});function p(e,t,n,r){var i=n?"":r.media?"@media ".concat(r.media," {").concat(r.css,"}"):r.css;if(e.styleSheet)e.styleSheet.cssText=s(t,i);else{var o=document.createTextNode(i),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(o,a[t]):e.appendChild(o)}}var h=null,m=0;function v(t,e){var n,r,i;if(e.singleton){var o=m++;n=h=h||c(e),r=p.bind(null,n,o,!1),i=p.bind(null,n,o,!0)}else n=c(e),r=function(e,t,n){var r=n.css,i=n.media,o=n.sourceMap;if(i?e.setAttribute("media",i):e.removeAttribute("media"),o&&btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(o))))," */")),e.styleSheet)e.styleSheet.cssText=r;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(r))}}.bind(null,n,e),i=function(){var e;null!==(e=n).parentNode&&e.parentNode.removeChild(e)};return r(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;r(t=e)}else i()}}e.exports=function(e,a){(a=a||{}).singleton||"boolean"==typeof a.singleton||(a.singleton=i());var c=u(e=e||[],a);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var t=0;t<c.length;t++){var n=d(c[t]);f[n].references--}for(var r=u(e,a),i=0;i<c.length;i++){var o=d(c[i]);0===f[o].references&&(f[o].updater(),f.splice(o,1))}c=r}}}},function(e,t,n){(t=n(4)(!1)).push([e.i,".dg .cr.image{position:relative;height:auto;border-left:3px solid #2fa1d6}.dg .cr.image .preview{display:block;width:calc(100% + 5px);padding:4px 0;margin-left:-5px}.dg .cr.image input{position:absolute;top:0;left:0;width:100%;height:100%;opacity:0;cursor:pointer}\n",""]),e.exports=t},function(e,t,n){"use strict";e.exports=function(n){var u=[];return u.toString=function(){return this.map(function(e){var t=function(e,t){var n=e[1]||"",r=e[3];if(!r)return n;if(t&&"function"==typeof btoa){var i=function(e){var t=btoa(unescape(encodeURIComponent(JSON.stringify(e)))),n="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(t);return"/*# ".concat(n," */")}(r),o=r.sources.map(function(e){return"/*# sourceURL=".concat(r.sourceRoot||"").concat(e," */")});return[n].concat(o).concat([i]).join("\n")}return[n].join("\n")}(e,n);return e[2]?"@media ".concat(e[2]," {").concat(t,"}"):t}).join("")},u.i=function(e,t,n){"string"==typeof e&&(e=[[null,e,""]]);var r={};if(n)for(var i=0;i<this.length;i++){var o=this[i][0];null!=o&&(r[o]=!0)}for(var a=0;a<e.length;a++){var c=[].concat(e[a]);n&&r[c[0]]||(t&&(c[2]?c[2]="".concat(t," and ").concat(c[2]):c[2]=t),u.push(c))}},u}}],i.c=r,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0);function i(e){if(r[e])return r[e].exports;var t=r[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,i),t.l=!0,t.exports}var n,r});