2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
/*! For license information please see index.js.LICENSE.txt */
|
|
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("blockly/core"));else if("function"==typeof define&&define.amd)define(["blockly/core"],t);else{var i="object"==typeof exports?t(require("blockly/core")):t(e.Blockly);for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(this,(e=>(()=>{"use strict";var t={573:t=>{t.exports=e}},i={};function n(e){var r=i[e];if(void 0!==r)return r.exports;var o=i[e]={exports:{}};return t[e](o,o.exports,n),o.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{n.r(r);var e=n(573),t=n.n(e);function i(e){return i="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},i(e)}function o(e,t){var i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!i){if(Array.isArray(e)||(i=function(e,t){if(e){if("string"==typeof e)return l(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?l(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){i&&(e=i);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,u=!1;return{s:function(){i=i.call(e)},n:function(){var e=i.next();return a=e.done,e},e:function(e){u=!0,o=e},f:function(){try{a||null==i.return||i.return()}finally{if(u)throw o}}}}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i<t;i++)n[i]=e[i];return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function s(){return s="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,i){var n=c(e,t);if(n){var r=Object.getOwnPropertyDescriptor(n,t);return r.get?r.get.call(arguments.length<3?e:i):r.value}},s.apply(this,arguments)}function c(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=d(e)););return e}function f(e,t){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},f(e,t)}function h(e,t){if(t&&("object"===i(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function d(e){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},d(e)}var p=15,y="#363d80",v="white",_="#e5e7f1",g=function(e){!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}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&f(e,t)}(b,e);var i,n,r,l,c,g=(l=b,c=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=d(l);if(c){var i=d(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return h(this,e)});function b(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return a(this,b),(e=g.call(this,t,i,n)).SERIALIZABLE=!0,null!==e.getValue()?(e.imgHeight_=e.getValue().length,e.imgWidth_=e.getValue()[0].length||0):(e.imgHeight_=n&&n.height||5,e.imgWidth_=n&&n.width||5),e.filledPixelColor_=n&&n.filledColor||y,e.emptyPixelColor_=n&&n.emptyColor||v,e.bgColor_=n&&n.bgColor||_,null===e.getValue()&&e.setValue(e.getEmptyArray_()),e.boundEvents_=[],e.editorPixels_=null,e.fieldGroup_=null,e.blockDisplayPixels_=null,e.mouseIsDown_=!1,e.valToPaintWith_=void 0,e}return i=b,n=[{key:"getImageWidth",value:function(){return this.imgWidth_}},{key:"getImageHeight",value:function(){return this.imgHeight_}},{key:"toXml",value:function(e){return e.textContent=JSON.stringify(this.getValue()),e}},{key:"saveState",value:function(e){var t=this.saveLegacyState(b);return null!==t?t:JSON.stringify(this.getValue())}},{key:"doClassValidation_",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(!t)return null;if("string"==typeof t)try{e=JSON.parse(t)}catch(e){return null}else{if(!Array.isArray(t))return null;e=t}var i=e.length;if(0==i)return null;var n,r=e[0].length,l=o(e);try{for(l.s();!(n=l.n()).done;){var a=n.value;if(!Array.isArray(a))return null;if(a.length!==r)return null}}catch(e){l.e(e)}finally{l.f()}var u,s=o(e);try{for(s.s();!(u=s.n()).done;){var c,f=u.value,h=o(f);try{for(h.s();!(c=h.n()).done;){var d=c.value;if(0!==d&&1!==d)return null}}catch(e){h.e(e)}finally{h.f()}}}catch(e){s.e(e)}finally{s.f()}return e}},{key:"doValueUpdate_",value:function(e){if(s(d(b.prototype),"doValueUpdate_",this).call(this,e),e){var t=e.length,i=e[0]?e[0].length:0;this.imgHeight_===t&&this.imgWidth_===i||(this.imgHeight_=t,this.imgWidth_=i),this.imgHeight_=e.length,this.imgWidth_=e[0]?e[0].length:0}}},{key:"showEditor_",value:function(){var e=this.dropdownCreate_();t().DropDownDiv.getContentDiv().appendChild(e),t().DropDownDiv.setColour(this.sourceBlock_.style.colourPrimary,this.sourceBlock_.style.colourTertiary),t().DropDownDiv.showPositionedByField(this,this.dropdownDispose_.bind(this))}},{key:"render_",value:function(){var e=this;s(d(b.prototype),"render_",this).call(this),this.getValue()&&this.blockDisplayPixels_&&this.forAllCells_((function(t,i){var n=e.getValue()[t][i];e.blockDisplayPixels_&&(e.blockDisplayPixels_[t][i].style.fill=n?e.filledPixelColor_:e.emptyPixelColor_),e.editorPixels_&&(e.editorPixels_[t][i].style.background=n?e.filledPixelColor_:e.emptyPixelColor_)}))}},{key:"updateEditable",value:function(){return!0}},{key:"dropdownCreate_",value:function(){var e,i,n,r,o=this,l=this.createElementWithClassname_("div","dropdownEditor"),a=this.createElementWithClassname_("div","pixelContainer");l.appendChild(a),this.bindEvent_(l,"mouseup",this.onMouseUp_),this.bindEvent_(l,"mouseleave",this.onMouseUp_),this.bindEvent_(l,"dragstart",(function(e){e.preventDefault()})),this.editorPixels_=[];for(var u=function(e){o.editorPixels_.push([]);for(var t=o.createElementWithClassname_("div","pixelRow"),i=function(i){var n=o.createElementWithClassname_("div","pixelButton");o.editorPixels_[e].push(n),t.appendChild(n);var r=o.getValue()[e][i];n.style.background=r?o.filledPixelColor_:o.emptyPixelColor_,o.bindEvent_(n,"mousedown",(function(){return o.onMouseDownInPixel_(e,i),!0})),o.bindEvent_(n,"mouseenter",(function(){o.onMouseEnterPixel_(e,i)}))},n=0;n<o.imgWidth_;n++)i(n);a.appendChild(t)},s=0;s<this.imgHeight_;s++)u(s);var c=this.createElementWithClassname_("div","btnContainer");return this.addControlButton_(c,null!==(e=null===t()||void 0===t()||null===(i=t().Msg)||void 0===i?void 0:i.RANDOM)&&void 0!==e?e:"随机",this.randomizePixels_),this.addControlButton_(c,null!==(n=null===t()||void 0===t()||null===(r=t().Msg)||void 0===r?void 0:r.CLEAR)&&void 0!==n?n:"清空",this.clearPixels_),l.appendChild(c),this.blockDisplayPixels_&&this.forAllCells_((function(e,t){var i=o.getValue()[e][t];o.editorPixels_&&(o.editorPixels_[e][t].style.background=i?o.filledPixelColor_:o.emptyPixelColor_)})),l}},{key:"initView",value:function(){this.createBorderRect_(),this.borderRect_&&(this.borderRect_.setAttribute("fill",this.bgColor_),this.borderRect_.setAttribute("rx","0"),this.borderRect_.setAttribute("ry","0")),this.blockDisplayPixels_=[];for(var e=0;e<this.imgHeight_;e++){for(var i=[],n=0;n<this.imgWidth_;n++){var r=t().utils.dom.createSvgElement("rect",{x:n*p+.5,y:e*p+.5,width:14,height:14,fill:this.emptyPixelColor_,fill_opacity:1},this.fieldGroup_);i.push(r)}this.blockDisplayPixels_.push(i)}}},{key:"updateSize_",value:function(){var e=p*this.imgWidth_,t=p*this.imgHeight_;this.borderRect_&&(this.borderRect_.setAttribute("width",String(e)),this.borderRect_.setAttribute("height",String(t))),this.size_.width=e,this.size_.height=t}},{key:"addControlButton_",value:function(e,t,i){var n=this.createElementWithClassname_("button","controlButton layui-btn layui-btn-normal layui-btn-sm");n.innerHTML=t,e.appendChild(n),this.bindEvent_(n,"click",i)}},{key:"dropdownDispose_",value:function(){var e,i=o(this.boundEvents_);try{for(i.s();!(e=i.n()).done;){var n=e.value;n.length&&t().browserEvents.unbind(n)}}catch(e){i.e(e)}finally{i.f()}this.editorPixels_=null}},{key:"getEmptyArray_",value:function(){for(var e=[],t=0;t<this.imgHeight_;t++){e.push([]);for(var i=0;i<this.imgWidth_;i++)e[t].push(0)}return e}},{key:"onMouseDownInPixel_",value:function(e,t){var i=1-this.getValue()[e][t];this.setPixel_(e,t,i),this.mouseIsDown_=!0,this.valToPaintWith_=i}},{key:"onMouseEnterPixel_",value:function(e,t){this.mouseIsDown_&&this.getValue()[e][t]!==this.valToPaintWith_&&this.setPixel_(e,t,this.valToPaintWith_)}},{key:"onMouseUp_",value:function(){this.mouseIsDown_=!1,this.valToPaintWith_=void 0}},{key:"randomizePixels_",value:function(){var e=this.getEmptyArray_();this.forAllCells_((function(t,i){e[t][i]=Math.floor(2*Math.random())})),this.setValue(e)}},{key:"clearPixels_",value:function(){var e=this.getEmptyArray_();this.forAllCells_((function(t,i){e[t][i]=0})),this.setValue(e)}},{key:"setPixel_",value:function(e,t,i){var n=JSON.parse(JSON.stringify(this.getValue()));n[e][t]=i,this.setValue(n)}},{key:"forAllCells_",value:function(e){for(var t=0;t<this.imgHeight_;t++)for(var i=0;i<this.imgWidth_;i++)e(t,i)}},{key:"createElementWithClassname_",value:function(e,t){var i=document.createElement(e);return i.className=t,i}},{key:"bindEvent_",value:function(e,i,n){this.boundEvents_.push(t().browserEvents.conditionalBind(e,i,this,n))}}],r=[{key:"fromJson",value:function(e){var i;return new b(null!==(i=e.value)&&void 0!==i?i:t().Field.SKIP_SETUP,void 0,e)}}],n&&u(i.prototype,n),r&&u(i,r),Object.defineProperty(i,"prototype",{writable:!1}),b}(t().Field);g.prototype.SERIALIZABLE=!0,Object.defineProperty(t(),"FieldBitmap",{value:g,writable:!0,enumerable:!0,configurable:!0}),t().fieldRegistry.register("field_bitmap",t().FieldBitmap),t().Css.register([".dropdownEditor {\n align-items: center;\n flex-direction: column;\n display: flex;\n justify-content: center;\n }\n .pixelContainer {\n margin: 5px;\n }\n .pixelRow {\n display: flex;\n flex-direction: row;\n padding: 0;\n margin: 0;\n height: ".concat(p,"\n }\n .pixelButton {\n width: ").concat(p,"px;\n height: ").concat(p,"px;\n border: 1px solid ").concat(_,";\n }\n .pixelDisplay {\n white-space:pre-wrap;\n }\n .controlButton {\n margin: 5px 0;\n }\n .btnContainer {\n display: flex;\n flex-direction: row;\n align-items: center;\n }\n ")])})(),r})())); |