UNPKG

@googleforcreators/units

Version:

A collection of utility functions as well as a React context provider for dealing with "data" and "editor" pixels in the Web Stories editor.

3 lines (2 loc) 1.22 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./calcRotatedResizeOffset.js"),e=require("./constants.js");function o(t){return Number(t.toFixed(0))}function r(t){return Number(t.toFixed(5))}function n(t,o){return r(t*o/e.PAGE_WIDTH)}function i(t,o){return r(t*o/e.PAGE_HEIGHT)}function u({x:t,y:o,width:r,height:u,rotationAngle:s,isBackground:d},a,x){return{x:n(d?0:t,a),y:i(d?-e.DANGER_ZONE_HEIGHT:o,x),width:n(d?e.PAGE_WIDTH:r,a),height:i(d?e.FULLBLEED_HEIGHT:u,x),rotationAngle:d?0:s}}exports.dataFontEm=function(t){return Number((t*e.DEFAULT_EM).toFixed(1))},exports.dataPixels=o,exports.dataToEditorX=n,exports.dataToEditorY=i,exports.dataToFontSizeY=function(t,e){return(i(t,e)/10).toFixed(6)},exports.editorPixels=r,exports.editorToDataX=function(t,r,n=!0){const i=t*e.PAGE_WIDTH/r;return n?o(i):i},exports.editorToDataY=function(t,r,n=!0){const i=t*e.PAGE_HEIGHT/r;return n?o(i):i},exports.getBox=u,exports.getBoxWithBorder=function(e,o,r){const{rotationAngle:n,border:i}=e,s=u(e,o,r);if(!i)return s;const{left:d=0,right:a=0,top:x=0,bottom:c=0}=i,[E,f]=t(n,d,a,x,c);return{...s,x:s.x+E,y:s.y+f,width:s.width+d+a,height:s.height+x+c}}; //# sourceMappingURL=dimensions.js.map