Socket
Socket
Sign inDemoInstall

sbweb-scalegorithm

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sbweb-scalegorithm - npm Package Compare versions

Comparing version 0.1.7 to 1.0.0

13

build/scalegorithm.js

@@ -136,3 +136,14 @@ "use strict";

}();
/* istanbul ignore else */
module.exports = Scalegorithm;
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = Scalegorithm;
} else {
/* istanbul ignore else */
if (typeof define === 'function' && define.amd) {
define([], function () {
return Scalegorithm;
});
}
}

2

build/scalegorithm.min.js

@@ -7,2 +7,2 @@ "use strict";

* @license MIT
*/var Scalegorithm=function(){var o={mode:"fit",parentSize:null,childSize:null,padding:[0,0],upscaleLimit:0,verbose:!0},r=function(e){if("fit"!=(e=Object.assign(o,e)).mode)throw new Error("scalegorithm invalid mode: currently only 'fit' is supported");if(e.verbose){if(!e.parentSize||2!=e.parentSize.length)throw new Error("scalegorithm parameter invalid: parentSize must be of array[2]");if(e.parentSize[0]<=0||e.parentSize[1]<=0)throw new Error("scalegorithm parameter invalid: parentSize dimensions must both be > 0");if(!e.childSize||2!=e.childSize.length)throw new Error("scalegorithm parameter invalid: childSize must be of array[2]");if(e.childSize[0]<=0||e.childSize[1]<=0)throw new Error("scalegorithm parameter invalid: childSize dimensions must both be > 0");if(!e.padding||2!=e.padding.length)throw new Error("scalegorithm parameter invalid: padding must be of array[2]");if(e.padding[0]<0||e.padding[1]<0)throw new Error("scalegorithm parameter invalid: padding dimensions must both be >= 0")}var i={childTop:null,childLeft:null,scale:1},l=e.parentSize[0]-2*e.padding[0],t=e.parentSize[1]-2*e.padding[1],r=e.childSize[0]/l,a=e.childSize[1]/t;return e.verbose&&(console.log("calc scale with parms",e),console.log("targetscale W H",[1/r,1/a])),i.childTop=1<a?(e.verbose&&console.log("childScale_H > 1"),-e.childSize[1]/2+e.parentSize[1]/2):(e.verbose&&console.log("childScale_H < 1"),null),i.childLeft=1<r?(e.verbose&&console.log("\tchildScale_W > 1"),-e.childSize[0]/2+e.parentSize[0]/2):(e.verbose&&console.log("\tchildScale_W < 1"),null),r<a?(i.scale=1/a,e.verbose&&console.log("\t\tSelected childscale_H",i.scale)):(i.scale=1/r,e.verbose&&console.log("\t\tSelected childScale_W",i.scale)),0<e.upscaleLimit&&i.scale>e.upscaleLimit&&(e.verbose&&console.log("preventing large upscale. new targetscale",e.upscaleLimit),i.scale=e.upscaleLimit),i};return{calc:r,scaleChild:function(e,i,l){(l=Object.assign(o,l)).parentSize=[e.offsetWidth,e.clientHeight],l.childSize=[i.offsetWidth,i.clientHeight];var t=r(l);i.style.position="relative",i.style.top=t.childTop?t.childTop+"px":"",i.style.left=t.childLeft?t.childLeft+"px":"",i.style.transform="scale("+t.scale+")"}}}();module.exports=Scalegorithm;
*/var Scalegorithm=function(){var a={mode:"fit",parentSize:null,childSize:null,padding:[0,0],upscaleLimit:0,verbose:!0},r=function(e){if("fit"!=(e=Object.assign(a,e)).mode)throw new Error("scalegorithm invalid mode: currently only 'fit' is supported");if(e.verbose){if(!e.parentSize||2!=e.parentSize.length)throw new Error("scalegorithm parameter invalid: parentSize must be of array[2]");if(e.parentSize[0]<=0||e.parentSize[1]<=0)throw new Error("scalegorithm parameter invalid: parentSize dimensions must both be > 0");if(!e.childSize||2!=e.childSize.length)throw new Error("scalegorithm parameter invalid: childSize must be of array[2]");if(e.childSize[0]<=0||e.childSize[1]<=0)throw new Error("scalegorithm parameter invalid: childSize dimensions must both be > 0");if(!e.padding||2!=e.padding.length)throw new Error("scalegorithm parameter invalid: padding must be of array[2]");if(e.padding[0]<0||e.padding[1]<0)throw new Error("scalegorithm parameter invalid: padding dimensions must both be >= 0")}var i={childTop:null,childLeft:null,scale:1},l=e.parentSize[0]-2*e.padding[0],t=e.parentSize[1]-2*e.padding[1],r=e.childSize[0]/l,o=e.childSize[1]/t;return e.verbose&&(console.log("calc scale with parms",e),console.log("targetscale W H",[1/r,1/o])),i.childTop=1<o?(e.verbose&&console.log("childScale_H > 1"),-e.childSize[1]/2+e.parentSize[1]/2):(e.verbose&&console.log("childScale_H < 1"),null),i.childLeft=1<r?(e.verbose&&console.log("\tchildScale_W > 1"),-e.childSize[0]/2+e.parentSize[0]/2):(e.verbose&&console.log("\tchildScale_W < 1"),null),r<o?(i.scale=1/o,e.verbose&&console.log("\t\tSelected childscale_H",i.scale)):(i.scale=1/r,e.verbose&&console.log("\t\tSelected childScale_W",i.scale)),0<e.upscaleLimit&&i.scale>e.upscaleLimit&&(e.verbose&&console.log("preventing large upscale. new targetscale",e.upscaleLimit),i.scale=e.upscaleLimit),i};return{calc:r,scaleChild:function(e,i,l){(l=Object.assign(a,l)).parentSize=[e.offsetWidth,e.clientHeight],l.childSize=[i.offsetWidth,i.clientHeight];var t=r(l);i.style.position="relative",i.style.top=t.childTop?t.childTop+"px":"",i.style.left=t.childLeft?t.childLeft+"px":"",i.style.transform="scale("+t.scale+")"}}}();"undefined"!=typeof module&&void 0!==module.exports?module.exports=Scalegorithm:"function"==typeof define&&define.amd&&define([],function(){return Scalegorithm});
{
"name": "sbweb-scalegorithm",
"version": "0.1.7",
"version": "1.0.0",
"author": "S. Derdeyn <sigged@users.noreply.github.com>",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -133,2 +133,12 @@ /**

module.exports = Scalegorithm;
/* istanbul ignore else */
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = Scalegorithm;
} else {
/* istanbul ignore else */
if (typeof define === 'function' && define.amd) {
define([], function() {
return Scalegorithm;
});
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc