UNPKG

@blockly/zoom-to-fit

Version:
3 lines 4.09 kB
/*! For license information please see index.js.LICENSE.txt */ !function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("blockly/core"));else if("function"==typeof define&&define.amd)define(["blockly/core"],i);else{var o="object"==typeof exports?i(require("blockly/core")):i(t.Blockly);for(var e in o)("object"==typeof exports?exports:t)[e]=o[e]}}(this,t=>(()=>{"use strict";var i={370:i=>{i.exports=t}},o={};function e(t){var s=o[t];if(void 0!==s)return s.exports;var r=o[t]={exports:{}};return i[t](r,r.exports,e),r.exports}e.n=t=>{var i=t&&t.__esModule?()=>t.default:()=>t;return e.d(i,{a:i}),i},e.d=(t,i)=>{for(var o in i)e.o(i,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:i[o]})},e.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i),e.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};e.r(s),e.d(s,{ZoomToFitControl:()=>n});var r=e(370);class n{constructor(t){this.workspace=t,this.id="zoomToFit",this.svgGroup=null,this.left=0,this.top=0,this.width=32,this.height=32,this.marginVertical=20,this.marginHorizontal=20,this.initialized=!1,this.onZoomToFitWrapper=null}init(){this.workspace.getComponentManager().addComponent({component:this,weight:2,capabilities:[r.ComponentManager.Capability.POSITIONABLE]}),this.createDom(),this.initialized=!0,this.workspace.resize()}dispose(){this.svgGroup&&r.utils.dom.removeNode(this.svgGroup),this.onZoomToFitWrapper&&(r.browserEvents.unbind(this.onZoomToFitWrapper),this.onZoomToFitWrapper=null)}createDom(){this.svgGroup=r.utils.dom.createSvgElement(r.utils.Svg.IMAGE,{height:`${this.height}px`,width:`${this.width}px`,class:"zoomToFit"}),this.svgGroup.setAttributeNS(r.utils.dom.XLINK_NS,"xlink:href",l),r.utils.dom.insertAfter(this.svgGroup,this.workspace.getBubbleCanvas()),this.onZoomToFitWrapper=r.browserEvents.conditionalBind(this.svgGroup,"pointerdown",null,this.onClick.bind(this))}onClick(t){this.workspace.zoomToFit();const i=new(r.Events.get(r.Events.CLICK))(null,this.workspace.id,"zoom_reset_control");r.Events.fire(i),t.stopPropagation(),t.preventDefault()}getBoundingRectangle(){return new r.utils.Rect(this.top,this.top+this.height,this.left,this.left+this.width)}position(t,i){var o;if(!this.initialized)return;const e=this.workspace.scrollbar&&this.workspace.scrollbar.canScrollHorizontally(),s=this.workspace.scrollbar&&this.workspace.scrollbar.canScrollVertically();t.toolboxMetrics.position===r.TOOLBOX_AT_LEFT||this.workspace.horizontalLayout&&!this.workspace.RTL?(this.left=t.absoluteMetrics.left+t.viewMetrics.width-this.width-this.marginHorizontal,e&&!this.workspace.RTL&&(this.left-=r.Scrollbar.scrollbarThickness)):(this.left=this.marginHorizontal,e&&this.workspace.RTL&&(this.left+=r.Scrollbar.scrollbarThickness));const n=t.toolboxMetrics.position!==r.TOOLBOX_AT_BOTTOM;n?(this.top=t.absoluteMetrics.top+t.viewMetrics.height-this.height-this.marginVertical,s&&(this.top-=r.Scrollbar.scrollbarThickness)):this.top=t.absoluteMetrics.top+this.marginVertical;let l=this.getBoundingRectangle();for(let t,o=0;t=i[o];o++)l.intersects(t)&&(this.top=n?t.top-this.height-this.marginVertical:t.bottom+this.marginVertical,l=this.getBoundingRectangle(),o=-1);null===(o=this.svgGroup)||void 0===o||o.setAttribute("transform",`translate(${this.left}, ${this.top})`)}}const l="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iIzU0NkU3QSI+PHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+PHBhdGggZD0iTTUgNi40Mkw4LjA5IDkuNSA5LjUgOC4wOSA2LjQxIDVIOVYzSDN2Nmgyem0xMC0zLjQxdjJoMi41N0wxNC41IDguMDlsMS40MSAxLjQxTDE5IDYuNDFWOWgyVjMuMDF6bTQgMTQuNTdsLTMuMDktMy4wOC0xLjQxIDEuNDFMMTcuNTkgMTlIMTV2Mmg2di02aC0yek04LjA5IDE0LjVMNSAxNy41OVYxNUgzdjZoNnYtMkg2LjQybDMuMDgtMy4wOXoiLz48L3N2Zz4=";return r.Css.register("\n.zoomToFit {\n opacity: 0.4;\n}\n.zoomToFit:hover {\n opacity: 0.6;\n}\n.zoomToFit:active {\n opacity: 0.8;\n}\n"),s})()); //# sourceMappingURL=index.js.map