UNPKG

@blockly/field-colour

Version:
3 lines 27 kB
/*! For license information please see index.js.LICENSE.txt */ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("blockly/core"),require("blockly/javascript"),require("blockly/dart"),require("blockly/lua"),require("blockly/php"),require("blockly/python"));else if("function"==typeof define&&define.amd)define(["blockly/core","blockly/javascript","blockly/dart","blockly/lua","blockly/php","blockly/python"],e);else{var r="object"==typeof exports?e(require("blockly/core"),require("blockly/javascript"),require("blockly/dart"),require("blockly/lua"),require("blockly/php"),require("blockly/python")):e(t.Blockly,t["Blockly.JavaScript"],t["Blockly.Dart"],t["Blockly.Lua"],t["Blockly.PHP"],t["Blockly.Python"]);for(var o in r)("object"==typeof exports?exports:t)[o]=r[o]}}(this,((t,e,r,o,n,i)=>(()=>{var l={127:t=>{"use strict";t.exports=e},157:t=>{"use strict";t.exports=o},370:e=>{"use strict";e.exports=t},379:t=>{"use strict";t.exports=r},462:function(t,e,r){var o;o=t=>(()=>{"use strict";var e={370:e=>{e.exports=t}},r={};function o(t){var n=r[t];if(void 0!==n)return n.exports;var i=r[t]={exports:{}};return e[t](i,i.exports,o),i.exports}o.d=(t,e)=>{for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};o.r(n),o.d(n,{FieldGridDropdown:()=>c});var i=o(370);class l{constructor(t,e,r,o){this.value=r,this.selected=!1,this.selectionCallback=o,this.element=document.createElement("button"),this.element.id=i.utils.idGenerator.getNextUniqueId(),this.element.className="blocklyFieldGridItem",this.clickHandler=i.browserEvents.conditionalBind(this.element,"click",this,this.onClick,!0),t.appendChild(this.element);const n="string"==typeof e?document.createTextNode(e):e;this.element.appendChild(n),i.utils.aria.setRole(this.element,i.utils.aria.Role.GRIDCELL)}dispose(){this.selectionCallback=null,this.element.remove(),this.clickHandler&&(i.browserEvents.unbind(this.clickHandler),this.clickHandler=null)}getId(){return this.element.id}getValue(){return this.value}isSelected(){return this.selected}setSelected(t){this.selected=t,i.utils.aria.setState(this.element,i.utils.aria.State.SELECTED,this.selected),this.element.classList.toggle("blocklyFieldGridItemSelected",this.selected),this.isSelected()&&this.focus()}onClick(){var t;this.setSelected(!0),null===(t=this.selectionCallback)||void 0===t||t.call(this,this)}focus(){this.element.focus({preventScroll:!0});const t=this.element.offsetParent;if(!t)return;const e=this.element.offsetTop,r=t.scrollTop,o=this.getInterItemSpacing();e<r?t.scrollTo(0,e-o):e+this.element.offsetHeight>r+t.clientHeight&&t.scrollBy(0,e+this.element.clientHeight-(r+t.clientHeight)+o)}getInterItemSpacing(){const t=this.element.closest(".blocklyFieldGrid");if(!t)return 0;const e=[...t.querySelectorAll(".blocklyFieldGridItem")];if(!e.length)return 0;const r=e[0].offsetTop,o=e[0].offsetHeight;for(const t of e)if(t.offsetTop!==r)return t.offsetTop-o-r;return 0}}class s{constructor(t,e,r,o,n){if(this.columns=r,this.rtl=o,this.itemIndices=new Map,this.items=new Array,this.keyDownHandler=null,this.pointerMoveHandler=null,this.selectionCallback=n,this.root=document.createElement("div"),this.root.className="blocklyFieldGrid",this.root.tabIndex=0,i.utils.aria.setRole(this.root,i.utils.aria.Role.GRID),t.appendChild(this.root),this.populateItems(e),this.keyDownHandler=i.browserEvents.conditionalBind(this.root,"keydown",this,this.onKeyDown),this.pointerMoveHandler=i.browserEvents.conditionalBind(this.root,"pointermove",this,this.onPointerMove,!0),!(r>=1))throw new Error(`Number of columns must be >= 1; got ${r}`);this.columns=r,this.root.style.setProperty("--grid-columns",`${this.columns}`)}populateItems(t){let e=document.createElement("div");for(const[r,o]of t.entries()){if(o===i.FieldDropdown.SEPARATOR)continue;r%this.columns===0&&(e=document.createElement("div"),e.className="blocklyFieldGridRow",i.utils.aria.setRole(e,i.utils.aria.Role.ROW),this.root.appendChild(e));const[t,n]=o,s=(()=>{if((e=t)&&"object"==typeof e&&"src"in e&&"string"==typeof e.src&&"alt"in e&&"string"==typeof e.alt&&"width"in e&&"number"==typeof e.width&&"height"in e&&"number"==typeof e.height){const e=new Image(t.width,t.height);return e.src=t.src,e.alt=t.alt||"",e}var e;return t})(),c=new l(e,s,n,(t=>{var e;this.setSelectedValue(t.getValue()),null===(e=this.selectionCallback)||void 0===e||e.call(this,t)}));this.itemIndices.set(c.getId(),this.itemIndices.size),this.items.push(c)}}dispose(){this.selectionCallback=void 0;for(const t of this.items)t.dispose();this.itemIndices.clear(),this.items.length=0,this.keyDownHandler&&(i.browserEvents.unbind(this.keyDownHandler),this.keyDownHandler=null),this.pointerMoveHandler&&(i.browserEvents.unbind(this.pointerMoveHandler),this.pointerMoveHandler=null),this.root.remove()}onKeyDown(t){if(!(!this.items.length||t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)){switch(t.key){case"ArrowUp":this.moveFocus(-1*this.columns,!0);break;case"ArrowDown":this.moveFocus(this.columns,!0);break;case"ArrowLeft":this.moveFocus(-1*(this.rtl?-1:1),!0);break;case"ArrowRight":this.moveFocus(1*(this.rtl?-1:1),!0);break;case"PageUp":case"Home":this.moveFocus(0,!1);break;case"PageDown":case"End":this.moveFocus(this.items.length-1,!1);break;default:return}t.preventDefault(),t.stopPropagation()}}onPointerMove(t){if(!t.movementX&&!t.movementY||!(t.target instanceof Element))return;const e=t.target.closest(".blocklyFieldGridItem");if(!e)return;const r=e.id,o=this.itemIndices.get(r);void 0!==o&&this.moveFocus(o,!1)}setSelectedValue(t){for(const[e,r]of this.items.entries()){const o=r.getValue()===t;r.setSelected(o),o&&this.moveFocus(e,!1)}}moveFocus(t,e){let r=t;if(e){const t=this.getFocusedItem();if(!t)return;r+=this.indexOfItem(t)}const o=this.itemAtIndex(r);o&&(o.focus(),i.utils.aria.setState(this.root,i.utils.aria.State.ACTIVEDESCENDANT,o.getId()))}indexOfItem(t){var e;return null!==(e=this.itemIndices.get(t.getId()))&&void 0!==e?e:-1}itemAtIndex(t){return this.items[t]}getFocusedItem(){var t;const e=null!==(t=this.root.querySelector(".blocklyFieldGridItem:focus"))&&void 0!==t?t:this.root.querySelector(".blocklyFieldGridItem");if(!e||!e.id)return;const r=this.itemIndices.get(e.id);return void 0!==r?this.itemAtIndex(r):void 0}}class c extends i.FieldDropdown{constructor(t,e,r){super(t,e,r),this.columns=3,(null==r?void 0:r.columns)&&this.setColumns(parseInt(`${r.columns}`)),r&&r.primaryColour&&(this.primaryColour=r.primaryColour),r&&r.borderColour&&(this.borderColour=r.borderColour)}static fromJson(t){if(!t.options)throw new Error("options are required for the dropdown field. The options property must be assigned an array of [humanReadableValue, languageNeutralValue] tuples.");return new this(t.options,void 0,t)}setColumns(t){var e;!isNaN(t)&&t>=1&&(this.columns=t,i.DropDownDiv.getOwner()===this&&i.DropDownDiv.isVisible()&&(null===(e=this.grid)||void 0===e||e.dispose(),this.showEditor_()))}showEditor_(t){var e;i.DropDownDiv.clearContent();const r=!!(null===(e=this.getSourceBlock())||void 0===e?void 0:e.workspace.RTL);this.grid=new s(i.DropDownDiv.getContentDiv(),this.getOptions(!1),this.columns,r,(t=>{i.DropDownDiv.hideIfOwner(this),this.setValue(t.getValue())})),i.DropDownDiv.getContentDiv().classList.add("blocklyFieldGridContainer");const o=this.getColours();o&&o.border&&i.DropDownDiv.setColour(o.primary,o.border),i.DropDownDiv.showPositionedByField(this,this.dropdownDispose_.bind(this));const n=this.getValue();n&&this.grid.setSelectedValue(n)}doValueUpdate_(t){var e;super.doValueUpdate_(t),null===(e=this.grid)||void 0===e||e.setSelectedValue(t)}getColours(){var t,e;if(this.primaryColour&&this.borderColour)return{primary:this.primaryColour,border:this.borderColour};const r=this.getSourceBlock();if(!(r instanceof i.BlockSvg))return;const o=r.isShadow()?r.getParent():r;return o?{primary:null!==(t=this.primaryColour)&&void 0!==t?t:o.getColour(),border:null!==(e=this.borderColour)&&void 0!==e?e:o.getColourTertiary()}:void 0}}return i.fieldRegistry.register("field_grid_dropdown",c),i.Css.register("\n .blocklyFieldGridContainer {\n padding: 7px;\n overflow: auto;\n }\n \n .blocklyFieldGrid {\n display: grid;\n grid-gap: 7px;\n grid-template-columns: repeat(var(--grid-columns), min-content);\n }\n\n .blocklyFieldGrid .blocklyFieldGridItem {\n border: 1px solid rgba(1, 1, 1, 0.5);\n border-radius: 4px;\n color: white;\n min-width: auto;\n background: none;\n white-space: nowrap;\n cursor: pointer;\n padding: 6px 15px;\n }\n \n .blocklyFieldGrid .blocklyFieldGridRow {\n display: contents;\n }\n \n .blocklyFieldGrid .blocklyFieldGridItem.blocklyFieldGridItemSelected {\n background-color: rgba(1, 1, 1, 0.25);\n }\n\n .blocklyFieldGrid .blocklyFieldGridItem:focus {\n box-shadow: 0 0 0 4px hsla(0, 0%, 100%, .2);\n outline: none;\n }\n "),n})(),t.exports=o(r(370))},537:t=>{"use strict";t.exports=n},557:t=>{"use strict";t.exports=i}},s={};function c(t){var e=s[t];if(void 0!==e)return e.exports;var r=s[t]={exports:{}};return l[t].call(r.exports,r,r.exports,c),r.exports}c.d=(t,e)=>{for(var r in e)c.o(e,r)&&!c.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},c.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),c.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var a={};return(()=>{"use strict";c.r(a),c.d(a,{FieldColour:()=>s,colourBlend:()=>o,colourPicker:()=>t,colourRandom:()=>e,colourRgb:()=>r,installAllBlocks:()=>ot,registerFieldColour:()=>d});var t={};c.r(t),c.d(t,{BLOCK_NAME:()=>g,blockDefinition:()=>N,installBlock:()=>L,toDart:()=>C,toJavascript:()=>_,toLua:()=>v,toPhp:()=>y,toPython:()=>E});var e={};c.r(e),c.d(e,{BLOCK_NAME:()=>R,blockDefinition:()=>U,installBlock:()=>w,toDart:()=>T,toJavascript:()=>x,toLua:()=>I,toPhp:()=>$,toPython:()=>D});var r={};c.r(r),c.d(r,{BLOCK_NAME:()=>S,blockDefinition:()=>V,installBlock:()=>q,toDart:()=>P,toJavascript:()=>M,toLua:()=>G,toPhp:()=>H,toPython:()=>K});var o={};c.r(o),c.d(o,{BLOCK_NAME:()=>Y,blockDefinition:()=>et,installBlock:()=>rt,toDart:()=>W,toJavascript:()=>J,toLua:()=>X,toPhp:()=>Q,toPython:()=>Z});var n=c(370),i=c(462);const l=["#ffffff","#cccccc","#c0c0c0","#999999","#666666","#333333","#000000","#ffcccc","#ff6666","#ff0000","#cc0000","#990000","#660000","#330000","#ffcc99","#ff9966","#ff9900","#ff6600","#cc6600","#993300","#663300","#ffff99","#ffff66","#ffcc66","#ffcc33","#cc9933","#996633","#663333","#ffffcc","#ffff33","#ffff00","#ffcc00","#999900","#666600","#333300","#99ff99","#66ff99","#33ff33","#33cc00","#009900","#006600","#003300","#99ffff","#33ffff","#66cccc","#00cccc","#339999","#336666","#003333","#ccffff","#66ffff","#33ccff","#3366ff","#3333ff","#000099","#000066","#ccccff","#9999ff","#6666cc","#6633ff","#6600cc","#333399","#330099","#ffccff","#ff99ff","#cc66cc","#cc33cc","#993399","#663366","#330033"];class s extends i.FieldGridDropdown{constructor(t,e,r){var o,i;super(u(null!==(o=null==r?void 0:r.colourOptions)&&void 0!==o?o:l),e,Object.assign(Object.assign({},r),{columns:null!==(i=null==r?void 0:r.columns)&&void 0!==i?i:7})),this.isDirty_=!1,t!==n.Field.SKIP_SETUP&&this.setValue(t)}trimOptions(t){return{options:t}}configure_(t){super.configure_(t),t.colourOptions&&this.setColours(t.colourOptions,t.colourTitles)}initView(){const t=this.getConstants();if(!t)throw Error("Constants not found");this.size_=new n.utils.Size(t.FIELD_COLOUR_DEFAULT_WIDTH,t.FIELD_COLOUR_DEFAULT_HEIGHT),this.createBorderRect_(),this.getBorderRect().style.fillOpacity="1",this.getBorderRect().setAttribute("stroke","#fff"),this.isFullBlockField()&&(this.clickTarget_=this.sourceBlock_.getSvgRoot())}showEditor_(t){super.showEditor_(t),n.DropDownDiv.getContentDiv().classList.add("blocklyFieldColour"),n.DropDownDiv.repositionForWindowResize()}isFullBlockField(){if(!this.getSourceBlock())throw new n.UnattachedFieldError;const t=this.getConstants();return this.blockIsSimpleReporter()&&Boolean(null==t?void 0:t.FIELD_COLOUR_FULL_BLOCK)}blockIsSimpleReporter(){const t=this.getSourceBlock();if(!t)throw new n.UnattachedFieldError;if(!t.outputConnection)return!1;for(const e of t.inputList)if(e.connection||e.fieldRow.length>1)return!1;return!0}applyColour(){const t=this.getSourceBlock();if(!t)throw new n.UnattachedFieldError;if(!this.fieldGroup_)return;const e=this.borderRect_;if(!e)throw new Error("The border rect has not been initialized");this.isFullBlockField()?(e.style.display="none",t.pathObject.svgPath.setAttribute("fill",this.getValue()),t.pathObject.svgPath.setAttribute("stroke","#fff")):(e.style.display="block",e.style.fill=this.getValue())}getSize(){var t;return(null===(t=this.getConstants())||void 0===t?void 0:t.FIELD_COLOUR_FULL_BLOCK)&&(this.render_(),this.isDirty_=!1),super.getSize()}render_(){this.updateSize_();const t=this.getSourceBlock();if(!t)throw new n.UnattachedFieldError;t.applyColour()}updateSize_(t){const e=this.getConstants();if(!e)return;let r,o;this.isFullBlockField()?(r=2*(null!=t?t:0),o=e.FIELD_TEXT_HEIGHT):(r=e.FIELD_COLOUR_DEFAULT_WIDTH,o=e.FIELD_COLOUR_DEFAULT_HEIGHT),this.size_.height=o,this.size_.width=r,this.positionBorderRect_()}doClassValidation_(t){return"string"!=typeof t?null:n.utils.colour.parse(t)}getText(){let t=this.value_;return/^#(.)\1(.)\2(.)\3$/.test(t)&&(t="#"+t[1]+t[3]+t[5]),t}setColours(t,e){const r=u(t,e);return this.setOptions(r),this}static fromJson(t){return new this(t.colour,void 0,t)}}function u(t,e){return t.map(((t,r)=>{const o=document.createElement("div");return o.className="blocklyColourSwatch",o.style.backgroundColor=t,e&&r<e.length&&(o.title=e[r]),[o,t]}))}function d(){n.fieldRegistry.register("field_colour",s)}s.prototype.DEFAULT_VALUE="#ffffff",n.Css.register("\n.blocklyFieldColour .blocklyFieldGridItemSelected,\n.blocklyFieldGridItemSelected:hover {\n border-color: #eee !important;\n outline: 1px solid #333;\n position: relative;\n}\n\n.blocklyColourSwatch {\n width: 20px;\n height: 20px;\n}\n\n.blocklyGridContainer {\n padding: 0px;\n}\n\n.blocklyFieldColour .blocklyFieldGrid {\n grid-gap: 0px;\n row-gap: 4px;\n}\n\n.blocklyFieldColour .blocklyFieldGrid .blocklyGridItem {\n border-radius: 0;\n padding: 0;\n border: 0.5px solid #888;\n cursor: pointer;\n}\n\n.blocklyFieldColour .blocklyFieldGrid .blocklyFieldGridItem {\n border: 0.5px solid #888;\n padding: 0;\n margin: 0;\n border-radius: 0;\n}\n\n.blocklyFieldColour .blocklyFieldGrid .blocklyFieldGridItem:focus {\n border-color: #eee;\n box-shadow: 2px 2px 7px 2px rgba(0, 0, 0, 0.3);\n position: relative;\n border-radius: 0;\n outline: none;\n}\n");var h=c(127),p=c(379),f=c(157),m=c(537),b=c(557);const g="colour_picker",O={type:g,message0:"%1",args0:[{type:"field_colour",name:"COLOUR",colour:"#ff0000"}],output:"Colour",helpUrl:"%{BKY_COLOUR_PICKER_HELPURL}",style:"colour_blocks",tooltip:"%{BKY_COLOUR_PICKER_TOOLTIP}",extensions:["parent_tooltip_when_inline"]};function _(t,e){return[e.quote_(t.getFieldValue("COLOUR")),h.Order.ATOMIC]}function C(t,e){return[e.quote_(t.getFieldValue("COLOUR")),p.Order.ATOMIC]}function v(t,e){return[e.quote_(t.getFieldValue("COLOUR")),f.Order.ATOMIC]}function y(t,e){return[e.quote_(t.getFieldValue("COLOUR")),m.Order.ATOMIC]}function E(t,e){return[e.quote_(t.getFieldValue("COLOUR")),b.Order.ATOMIC]}const k=n.common.createBlockDefinitionsFromJsonArray([O]),N=k[g];function L(t={}){d(),n.common.defineBlocks(k),t.javascript&&(t.javascript.forBlock[g]=_),t.dart&&(t.dart.forBlock[g]=C),t.lua&&(t.lua.forBlock[g]=v),t.php&&(t.php.forBlock[g]=y),t.python&&(t.python.forBlock[g]=E)}const R="colour_random",F={type:R,message0:"%{BKY_COLOUR_RANDOM_TITLE}",output:"Colour",helpUrl:"%{BKY_COLOUR_RANDOM_HELPURL}",style:"colour_blocks",tooltip:"%{BKY_COLOUR_RANDOM_TOOLTIP}"};function x(t,e){return[e.provideFunction_("colourRandom",`\nfunction ${e.FUNCTION_NAME_PLACEHOLDER_}() {\n var num = Math.floor(Math.random() * 0x1000000);\n return '#' + ('00000' + num.toString(16)).substr(-6);\n}\n`)+"()",h.Order.FUNCTION_CALL]}function T(t,e){return e.definitions_.import_dart_math="import 'dart:math' as Math;",[e.provideFunction_("colour_random",`\nString ${e.FUNCTION_NAME_PLACEHOLDER_}() {\n String hex = '0123456789abcdef';\n var rnd = new Math.Random();\n return '#\${hex[rnd.nextInt(16)]}\${hex[rnd.nextInt(16)]}'\n '\${hex[rnd.nextInt(16)]}\${hex[rnd.nextInt(16)]}'\n '\${hex[rnd.nextInt(16)]}\${hex[rnd.nextInt(16)]}';\n}\n`)+"()",p.Order.UNARY_POSTFIX]}function I(t,e){return['string.format("#%06x", math.random(0, 2^24 - 1))',f.Order.HIGH]}function $(t,e){return[e.provideFunction_("colour_random",`\nfunction ${e.FUNCTION_NAME_PLACEHOLDER_}() {\n return '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);\n}\n`)+"()",m.Order.FUNCTION_CALL]}function D(t,e){return e.definitions_.import_random="import random",["'#%06x' % random.randint(0, 2**24 - 1)",b.Order.FUNCTION_CALL]}const B=n.common.createBlockDefinitionsFromJsonArray([F]),U=B[R];function w(t={}){d(),n.common.defineBlocks(B),t.javascript&&(t.javascript.forBlock[R]=x),t.dart&&(t.dart.forBlock[R]=T),t.lua&&(t.lua.forBlock[R]=I),t.php&&(t.php.forBlock[R]=$),t.python&&(t.python.forBlock[R]=D)}const S="colour_rgb",A={type:S,message0:"%{BKY_COLOUR_RGB_TITLE} %{BKY_COLOUR_RGB_RED} %1 %{BKY_COLOUR_RGB_GREEN} %2 %{BKY_COLOUR_RGB_BLUE} %3",args0:[{type:"input_value",name:"RED",check:"Number",align:"RIGHT"},{type:"input_value",name:"GREEN",check:"Number",align:"RIGHT"},{type:"input_value",name:"BLUE",check:"Number",align:"RIGHT"}],output:"Colour",helpUrl:"%{BKY_COLOUR_RGB_HELPURL}",style:"colour_blocks",tooltip:"%{BKY_COLOUR_RGB_TOOLTIP}"};function M(t,e){const r=e.valueToCode(t,"RED",h.Order.NONE)||0,o=e.valueToCode(t,"GREEN",h.Order.NONE)||0,n=e.valueToCode(t,"BLUE",h.Order.NONE)||0;return[`${e.provideFunction_("colourRgb",`\nfunction ${e.FUNCTION_NAME_PLACEHOLDER_}(r, g, b) {\n r = Math.max(Math.min(Number(r), 100), 0) * 2.55;\n g = Math.max(Math.min(Number(g), 100), 0) * 2.55;\n b = Math.max(Math.min(Number(b), 100), 0) * 2.55;\n r = ('0' + (Math.round(r) || 0).toString(16)).slice(-2);\n g = ('0' + (Math.round(g) || 0).toString(16)).slice(-2);\n b = ('0' + (Math.round(b) || 0).toString(16)).slice(-2);\n return '#' + r + g + b;\n}\n`)}(${r}, ${o}, ${n})`,h.Order.FUNCTION_CALL]}function P(t,e){const r=e.valueToCode(t,"RED",p.Order.NONE)||0,o=e.valueToCode(t,"GREEN",p.Order.NONE)||0,n=e.valueToCode(t,"BLUE",p.Order.NONE)||0;return e.definitions_.import_dart_math="import 'dart:math' as Math;",[`${e.provideFunction_("colour_rgb",`\nString ${e.FUNCTION_NAME_PLACEHOLDER_}(num r, num g, num b) {\n num rn = (Math.max(Math.min(r, 100), 0) * 2.55).round();\n String rs = rn.toInt().toRadixString(16);\n rs = '0$rs';\n rs = rs.substring(rs.length - 2);\n num gn = (Math.max(Math.min(g, 100), 0) * 2.55).round();\n String gs = gn.toInt().toRadixString(16);\n gs = '0$gs';\n gs = gs.substring(gs.length - 2);\n num bn = (Math.max(Math.min(b, 100), 0) * 2.55).round();\n String bs = bn.toInt().toRadixString(16);\n bs = '0$bs';\n bs = bs.substring(bs.length - 2);\n return '#$rs$gs$bs';\n}\n`)}(${r}, ${o}, ${n})`,p.Order.UNARY_POSTFIX]}function G(t,e){return[`${e.provideFunction_("colour_rgb",`\nfunction ${e.FUNCTION_NAME_PLACEHOLDER_}(r, g, b)\n r = math.floor(math.min(100, math.max(0, r)) * 2.55 + .5)\n g = math.floor(math.min(100, math.max(0, g)) * 2.55 + .5)\n b = math.floor(math.min(100, math.max(0, b)) * 2.55 + .5)\n return string.format("#%02x%02x%02x", r, g, b)\nend\n`)}(${e.valueToCode(t,"RED",f.Order.NONE)||0}, ${e.valueToCode(t,"GREEN",f.Order.NONE)||0}, ${e.valueToCode(t,"BLUE",f.Order.NONE)||0})`,f.Order.HIGH]}function H(t,e){const r=e.valueToCode(t,"RED",m.Order.NONE)||0,o=e.valueToCode(t,"GREEN",m.Order.NONE)||0,n=e.valueToCode(t,"BLUE",m.Order.NONE)||0;return[`${e.provideFunction_("colour_rgb",`\nfunction ${e.FUNCTION_NAME_PLACEHOLDER_}($r, $g, $b) {\n $r = round(max(min($r, 100), 0) * 2.55);\n $g = round(max(min($g, 100), 0) * 2.55);\n $b = round(max(min($b, 100), 0) * 2.55);\n $hex = '#';\n $hex .= str_pad(dechex($r), 2, '0', STR_PAD_LEFT);\n $hex .= str_pad(dechex($g), 2, '0', STR_PAD_LEFT);\n $hex .= str_pad(dechex($b), 2, '0', STR_PAD_LEFT);\n return $hex;\n}\n`)}(${r}, ${o}, ${n})`,m.Order.FUNCTION_CALL]}function K(t,e){return[e.provideFunction_("colour_rgb",`\ndef ${e.FUNCTION_NAME_PLACEHOLDER_}(r, g, b):\n r = round(min(100, max(0, r)) * 2.55)\n g = round(min(100, max(0, g)) * 2.55)\n b = round(min(100, max(0, b)) * 2.55)\n return '#%02x%02x%02x' % (r, g, b)\n`)+"("+(e.valueToCode(t,"RED",b.Order.NONE)||0)+", "+(e.valueToCode(t,"GREEN",b.Order.NONE)||0)+", "+(e.valueToCode(t,"BLUE",b.Order.NONE)||0)+")",b.Order.FUNCTION_CALL]}const j=n.common.createBlockDefinitionsFromJsonArray([A]),V=j[S];function q(t={}){d(),n.common.defineBlocks(j),t.javascript&&(t.javascript.forBlock[S]=M),t.dart&&(t.dart.forBlock[S]=P,t.dart.addReservedWords("Math")),t.lua&&(t.lua.forBlock[S]=G),t.php&&(t.php.forBlock[S]=H),t.python&&(t.python.forBlock[S]=K)}const Y="colour_blend",z={type:Y,message0:"%{BKY_COLOUR_BLEND_TITLE} %{BKY_COLOUR_BLEND_COLOUR1} %1 %{BKY_COLOUR_BLEND_COLOUR2} %2 %{BKY_COLOUR_BLEND_RATIO} %3",args0:[{type:"input_value",name:"COLOUR1",check:"Colour",align:"RIGHT"},{type:"input_value",name:"COLOUR2",check:"Colour",align:"RIGHT"},{type:"input_value",name:"RATIO",check:"Number",align:"RIGHT"}],output:"Colour",helpUrl:"%{BKY_COLOUR_BLEND_HELPURL}",style:"colour_blocks",tooltip:"%{BKY_COLOUR_BLEND_TOOLTIP}"};function J(t,e){const r=e.valueToCode(t,"COLOUR1",h.Order.NONE)||"'#000000'",o=e.valueToCode(t,"COLOUR2",h.Order.NONE)||"'#000000'",n=e.valueToCode(t,"RATIO",h.Order.NONE)||.5;return[`${e.provideFunction_("colourBlend",`\nfunction ${e.FUNCTION_NAME_PLACEHOLDER_}(c1, c2, ratio) {\n ratio = Math.max(Math.min(Number(ratio), 1), 0);\n var r1 = parseInt(c1.substring(1, 3), 16);\n var g1 = parseInt(c1.substring(3, 5), 16);\n var b1 = parseInt(c1.substring(5, 7), 16);\n var r2 = parseInt(c2.substring(1, 3), 16);\n var g2 = parseInt(c2.substring(3, 5), 16);\n var b2 = parseInt(c2.substring(5, 7), 16);\n var r = Math.round(r1 * (1 - ratio) + r2 * ratio);\n var g = Math.round(g1 * (1 - ratio) + g2 * ratio);\n var b = Math.round(b1 * (1 - ratio) + b2 * ratio);\n r = ('0' + (r || 0).toString(16)).slice(-2);\n g = ('0' + (g || 0).toString(16)).slice(-2);\n b = ('0' + (b || 0).toString(16)).slice(-2);\n return '#' + r + g + b;\n}\n`)}(${r}, ${o}, ${n})`,h.Order.FUNCTION_CALL]}function W(t,e){const r=e.valueToCode(t,"COLOUR1",p.Order.NONE)||"'#000000'",o=e.valueToCode(t,"COLOUR2",p.Order.NONE)||"'#000000'",n=e.valueToCode(t,"RATIO",p.Order.NONE)||.5;return e.definitions_.import_dart_math="import 'dart:math' as Math;",[`${e.provideFunction_("colour_blend",`\nString ${e.FUNCTION_NAME_PLACEHOLDER_}(String c1, String c2, num ratio) {\n ratio = Math.max(Math.min(ratio, 1), 0);\n int r1 = int.parse('0x\${c1.substring(1, 3)}');\n int g1 = int.parse('0x\${c1.substring(3, 5)}');\n int b1 = int.parse('0x\${c1.substring(5, 7)}');\n int r2 = int.parse('0x\${c2.substring(1, 3)}');\n int g2 = int.parse('0x\${c2.substring(3, 5)}');\n int b2 = int.parse('0x\${c2.substring(5, 7)}');\n num rn = (r1 * (1 - ratio) + r2 * ratio).round();\n String rs = rn.toInt().toRadixString(16);\n num gn = (g1 * (1 - ratio) + g2 * ratio).round();\n String gs = gn.toInt().toRadixString(16);\n num bn = (b1 * (1 - ratio) + b2 * ratio).round();\n String bs = bn.toInt().toRadixString(16);\n rs = '0$rs';\n rs = rs.substring(rs.length - 2);\n gs = '0$gs';\n gs = gs.substring(gs.length - 2);\n bs = '0$bs';\n bs = bs.substring(bs.length - 2);\n return '#$rs$gs$bs';\n}\n`)}(${r}, ${o}, ${n})`,p.Order.UNARY_POSTFIX]}function X(t,e){return[`${e.provideFunction_("colour_blend",`\nfunction ${e.FUNCTION_NAME_PLACEHOLDER_}(colour1, colour2, ratio)\n local r1 = tonumber(string.sub(colour1, 2, 3), 16)\n local r2 = tonumber(string.sub(colour2, 2, 3), 16)\n local g1 = tonumber(string.sub(colour1, 4, 5), 16)\n local g2 = tonumber(string.sub(colour2, 4, 5), 16)\n local b1 = tonumber(string.sub(colour1, 6, 7), 16)\n local b2 = tonumber(string.sub(colour2, 6, 7), 16)\n local ratio = math.min(1, math.max(0, ratio))\n local r = math.floor(r1 * (1 - ratio) + r2 * ratio + .5)\n local g = math.floor(g1 * (1 - ratio) + g2 * ratio + .5)\n local b = math.floor(b1 * (1 - ratio) + b2 * ratio + .5)\n return string.format("#%02x%02x%02x", r, g, b)\nend\n`)}(${e.valueToCode(t,"COLOUR1",f.Order.NONE)||"'#000000'"}, ${e.valueToCode(t,"COLOUR2",f.Order.NONE)||"'#000000'"}, ${e.valueToCode(t,"RATIO",f.Order.NONE)||0})`,f.Order.HIGH]}function Q(t,e){const r=e.valueToCode(t,"COLOUR1",m.Order.NONE)||"'#000000'",o=e.valueToCode(t,"COLOUR2",m.Order.NONE)||"'#000000'",n=e.valueToCode(t,"RATIO",m.Order.NONE)||.5;return[`${e.provideFunction_("colour_blend",`\nfunction ${e.FUNCTION_NAME_PLACEHOLDER_}($c1, $c2, $ratio) {\n $ratio = max(min($ratio, 1), 0);\n $r1 = hexdec(substr($c1, 1, 2));\n $g1 = hexdec(substr($c1, 3, 2));\n $b1 = hexdec(substr($c1, 5, 2));\n $r2 = hexdec(substr($c2, 1, 2));\n $g2 = hexdec(substr($c2, 3, 2));\n $b2 = hexdec(substr($c2, 5, 2));\n $r = round($r1 * (1 - $ratio) + $r2 * $ratio);\n $g = round($g1 * (1 - $ratio) + $g2 * $ratio);\n $b = round($b1 * (1 - $ratio) + $b2 * $ratio);\n $hex = '#';\n $hex .= str_pad(dechex($r), 2, '0', STR_PAD_LEFT);\n $hex .= str_pad(dechex($g), 2, '0', STR_PAD_LEFT);\n $hex .= str_pad(dechex($b), 2, '0', STR_PAD_LEFT);\n return $hex;\n}\n`)}(${r}, ${o}, ${n})`,m.Order.FUNCTION_CALL]}function Z(t,e){return[`${e.provideFunction_("colour_blend",`\ndef ${e.FUNCTION_NAME_PLACEHOLDER_}(colour1, colour2, ratio):\n r1, r2 = int(colour1[1:3], 16), int(colour2[1:3], 16)\n g1, g2 = int(colour1[3:5], 16), int(colour2[3:5], 16)\n b1, b2 = int(colour1[5:7], 16), int(colour2[5:7], 16)\n ratio = min(1, max(0, ratio))\n r = round(r1 * (1 - ratio) + r2 * ratio)\n g = round(g1 * (1 - ratio) + g2 * ratio)\n b = round(b1 * (1 - ratio) + b2 * ratio)\n return '#%02x%02x%02x' % (r, g, b)\n`)}(${e.valueToCode(t,"COLOUR1",b.Order.NONE)||"'#000000'"}, ${e.valueToCode(t,"COLOUR2",b.Order.NONE)||"'#000000'"}, ${e.valueToCode(t,"RATIO",b.Order.NONE)||0})`,b.Order.FUNCTION_CALL]}const tt=n.common.createBlockDefinitionsFromJsonArray([z]),et=tt[Y];function rt(t={}){d(),n.common.defineBlocks(tt),t.javascript&&(t.javascript.forBlock[Y]=J),t.dart&&(t.dart.forBlock[Y]=W,t.dart.addReservedWords("Math")),t.lua&&(t.lua.forBlock[Y]=X),t.php&&(t.php.forBlock[Y]=Q),t.python&&(t.python.forBlock[Y]=Z)}function ot(t={}){L(t),q(t),w(t),rt(t)}})(),a})())); //# sourceMappingURL=index.js.map