instagram-api-media
Advanced tools
Comparing version 1.0.0 to 1.0.1
import { BaseOptions } from './BaseOptions'; | ||
import { PhotoDetails } from './MediaDetails'; | ||
import { PhotoDetails, VideoDetails } from './MediaDetails'; | ||
import { CalculatedValue } from './Types'; | ||
export declare const instagramApiMediaLib: { | ||
calculate(inputMedia: PhotoDetails, options?: BaseOptions | undefined): CalculatedValue; | ||
calculatePhoto(inputMedia: PhotoDetails, options?: BaseOptions | undefined): CalculatedValue; | ||
calculateVideo(inputMedia: VideoDetails, options?: BaseOptions | undefined): CalculatedValue; | ||
}; |
@@ -6,5 +6,7 @@ "use strict"; | ||
const InstagramPhotoCalculator_1 = require("./InstagramPhotoCalculator"); | ||
const InstagramVideo_1 = require("./InstagramVideo"); | ||
const InstagramVideoCalculator_1 = require("./InstagramVideoCalculator"); | ||
const Types_1 = require("./Types"); | ||
exports.instagramApiMediaLib = { | ||
calculate(inputMedia, options) { | ||
calculatePhoto(inputMedia, options) { | ||
const instagramPhoto = new InstagramPhoto_1.InstagramPhoto(inputMedia, { operation: Types_1.OperationEnum.EXPAND }); | ||
@@ -14,3 +16,8 @@ const instagramPhotoCalculator = new InstagramPhotoCalculator_1.InstagramPhotoCalculator(instagramPhoto); | ||
}, | ||
calculateVideo(inputMedia, options) { | ||
const instagramPhoto = new InstagramVideo_1.InstagramVideo(inputMedia, { operation: Types_1.OperationEnum.EXPAND }); | ||
const instagramPhotoCalculator = new InstagramVideoCalculator_1.InstagramVideoCalculator(instagramPhoto); | ||
return instagramPhotoCalculator.calculate(); | ||
}, | ||
}; | ||
//# sourceMappingURL=instagram-api-media.js.map |
@@ -1,1 +0,1 @@ | ||
!function(t){var e={};function i(s){if(e[s])return e[s].exports;var r=e[s]={i:s,l:!1,exports:{}};return t[s].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=t,i.c=e,i.d=function(t,e,s){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:s})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(s,r,function(e){return t[e]}.bind(null,r));return s},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=3)}([function(t,e,i){"use strict";var s;Object.defineProperty(e,"__esModule",{value:!0}),function(t){t[t.FEED_TIMELINE=1]="FEED_TIMELINE",t[t.FEED_TIMELINE_ALBUM=2]="FEED_TIMELINE_ALBUM",t[t.FEED_STORY=3]="FEED_STORY",t[t.FEED_DIRECT=4]="FEED_DIRECT",t[t.FEED_DIRECT_STORY=5]="FEED_DIRECT_STORY",t[t.FEED_TV=6]="FEED_TV"}(e.FeedTypeEnum||(e.FeedTypeEnum={})),function(t){t.CROP="CROP",t.EXPAND="EXPAND"}(e.OperationEnum||(e.OperationEnum={})),function(t){t.round="round",t.floor="floor",t.ceil="ceil"}(s=e.RoundingFunc||(e.RoundingFunc={})),e.RoundingFunctions=new Map([[s.round,{name:s.round,roundingFunc:Math.round}],[s.floor,{name:s.floor,roundingFunc:Math.floor}],[s.ceil,{name:s.ceil,roundingFunc:Math.ceil}]]),function(t){t.IMAGETYPE_JPEG="IMAGETYPE_JPEG",t.IMAGETYPE_PNG="IMAGETYPE_PNG"}(e.ImageType||(e.ImageType={}));class r{constructor(t){this.rawValue=t,this.min=Number.MIN_SAFE_INTEGER,this.max=Number.MAX_SAFE_INTEGER}valueOf(){return this.value}get value(){return this.clamp(Math.trunc(this.rawValue))}clamp(t){return t<this.min?this.min:t>this.max?this.max:t}}e.ClampedInteger=r;e.CropFocus=class extends r{constructor(){super(...arguments),this.min=-50,this.max=50}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(0);class r{constructor(t,e){this.width=t,this.height=e,this.aspectRatio=this.width/this.height}getWidth(){return this.width}getHeight(){return this.height}getAspectRatio(){return this.aspectRatio}withSwappedAxes(){return new r(this.height,this.width)}withRescaling(t=1,e){const i=s.RoundingFunctions.get(e);if(i){const e=i.roundingFunc,s=e(t*this.width),n=e(t*this.height);return new r(s,n)}return new r(this.width,this.height)}}e.Dimensions=r},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(0);class r{constructor(t,e,i,s){this.x=t,this.y=e,this.width=i,this.height=s,this.aspectRatio=this.width/this.height}getX(){return this.x}getY(){return this.y}getX1(){return this.x}getY1(){return this.y}getX2(){return this.x+this.width}getY2(){return this.y+this.height}getWidth(){return this.width}getHeight(){return this.height}getAspectRatio(){return this.aspectRatio}withSwappedAxes(){return new r(this.y,this.x,this.height,this.width)}withRescaling(t=1,e){const i=s.RoundingFunctions.get(e);if(i){const e=i.roundingFunc,s=e(t*this.width),n=e(t*this.height);return new r(this.x,this.y,s,n)}return new r(this.x,this.y,this.width,this.height)}}e.Rectangle=r},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(4),r=i(9),n=i(0);e.instagramApiMediaLib={calculate(t,e){const i=new s.InstagramPhoto(t,{operation:n.OperationEnum.EXPAND});return new r.InstagramPhotoCalculator(i).calculate()}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(5);e.InstagramPhoto=class extends s.InstagramMedia{constructor(t,e){super(e),this.details=t}getMediaDetails(){return this.details}isMod2CanvasRequired(){return!1}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(6),r=i(7),n=i(1),o=i(2),a=i(0);e.InstagramMedia=class{constructor(t){if(t?(this.operation=void 0!==t.operation?t.operation:a.OperationEnum.CROP,this.targetFeed=void 0!==t.targetFeed?t.targetFeed:a.FeedTypeEnum.FEED_TIMELINE,this.allowNewAspectDeviation=t.allowNewAspectDeviation,this.bgColor=t.bgColor,this.blurredBorder=t.blurredBorder,this.horCropFocus=t.horCropFocus,this.maxAspectRatio=t.maxAspectRatio,this.minAspectRatio=t.minAspectRatio,this.useRecommendedRatio=t.useRecommendedRatio,this.userForceTargetAspectRatio=t.userForceTargetAspectRatio,this.verCropFocus=t.verCropFocus):(this.operation=a.OperationEnum.CROP,this.targetFeed=a.FeedTypeEnum.FEED_TIMELINE),this.hasUserForceTargetAspectRatio=!1,void 0!==this.userForceTargetAspectRatio&&(this.hasUserForceTargetAspectRatio=!0,this.useRecommendedRatio=!1),this.constraints=r.ConstraintsFactory.createFor(this.targetFeed),this.hasUserForceTargetAspectRatio&&void 0===this.useRecommendedRatio&&(void 0!==this.minAspectRatio||void 0!==this.maxAspectRatio?this.useRecommendedRatio=!1:this.useRecommendedRatio=this.constraints.useRecommendedRatioByDefault()),!this.hasUserForceTargetAspectRatio&&this.useRecommendedRatio){this.forceTargetAspectRatio=this.constraints.getRecommendedRatio();const t=this.constraints.getRecommendedRatioDeviation();this.minAspectRatio=this.forceTargetAspectRatio-t,this.maxAspectRatio=this.forceTargetAspectRatio+t}else{const t=this.constraints.getMinAspectRatio(),e=this.constraints.getMaxAspectRatio();if(void 0!==this.minAspectRatio&&(this.minAspectRatio<t||this.minAspectRatio>e))throw new Error(s.sprintf("Minimum aspect ratio must be between %1.3f and %2.3f.",t,e));if(void 0===this.minAspectRatio&&(this.minAspectRatio=t),void 0!==this.maxAspectRatio&&(this.maxAspectRatio<t||this.maxAspectRatio>e))throw new Error(s.sprintf("Maximum aspect ratio must be between %1.3f and %2.3f.",t,e));if(void 0===this.maxAspectRatio&&(this.maxAspectRatio=e),this.minAspectRatio>this.maxAspectRatio)throw new Error("Maximum aspect ratio must be greater than or equal to minimum.");if(this.hasUserForceTargetAspectRatio){if(this.forceTargetAspectRatio=this.userForceTargetAspectRatio,void 0===this.forceTargetAspectRatio)throw new Error("Force target aspect ratio undefined");if(this.forceTargetAspectRatio<this.minAspectRatio)throw new Error(s.sprintf("Custom target aspect ratio (%1.5f) must be greater than or equal to the minimum aspect ratio (%2.5f).",this.forceTargetAspectRatio,this.minAspectRatio));if(this.forceTargetAspectRatio>this.maxAspectRatio)throw new Error(s.sprintf("Custom target aspect ratio (%.5f) must be lesser than or equal to the maximum aspect ratio (%.5f).",this.forceTargetAspectRatio,this.maxAspectRatio))}}void 0===this.allowNewAspectDeviation&&(this.allowNewAspectDeviation=!1),void 0===this.bgColor&&(this.bgColor={red:255,green:255,blue:255}),void 0===this.blurredBorder&&(this.blurredBorder=!1)}shouldProcess(){const t=this.getMediaDetails().getAspectRatio();if(void 0!==this.minAspectRatio&&t<this.minAspectRatio)return!0;if(void 0!==this.maxAspectRatio&&t>this.maxAspectRatio)return!0;if(this.hasUserForceTargetAspectRatio&&this.forceTargetAspectRatio)if(1===this.forceTargetAspectRatio){if(1!==t)return!0}else{const e=.003,i=this.forceTargetAspectRatio-e,s=this.forceTargetAspectRatio+e;if(t<i||t>s)return!0}try{return this.getMediaDetails().validate(this.constraints),!1}catch(t){return!0}}calculate(){const t=this.getMediaDetails(),e=new n.Dimensions(t.getWidth(),t.getHeight()),i=this.calculateNewCanvas(this.operation,e.getWidth(),e.getHeight(),this.isMod2CanvasRequired(),t.getMinAllowedWidth(),t.getMaxAllowedWidth(),this.allowNewAspectDeviation,this.minAspectRatio,this.maxAspectRatio,this.forceTargetAspectRatio),s=i.canvas;if(this.operation===a.OperationEnum.CROP){let r=0;const c=new n.Dimensions(s.getWidth()-i.mod2WidthDiff,s.getHeight()-i.mod2HeightDiff),h=c.getWidth()/e.getWidth(),u=c.getHeight()/e.getHeight();r=Math.abs(c.getAspectRatio()-e.getAspectRatio())<1e-4?h:c.getAspectRatio()<e.getAspectRatio()?u:h;let d=c.withRescaling(1/r,a.RoundingFunc.round);const l=Math.round(i.mod2WidthDiff*(1/r)),g=Math.round(i.mod2HeightDiff*(1/r)),p=(d=new n.Dimensions(d.getWidth()+l,d.getHeight()+g)).getWidth()<=e.getWidth()?d.getWidth():e.getWidth(),f=d.getHeight()<=e.getHeight()?d.getHeight():e.getHeight();d=new n.Dimensions(p,f);let m=0,R=0,E=e.getWidth(),A=e.getHeight();const M=d.getWidth()-e.getWidth(),T=d.getHeight()-e.getHeight();if(M<0){let e=void 0!==this.horCropFocus?this.horCropFocus.value:0;t.isHorizontallyFlipped()&&(e=-e);const i=Math.abs(M);E-=i-(m=Math.floor(i*(50+e)/100))}if(T<0){let e=void 0!==this.verCropFocus?this.verCropFocus.value:-50;t.isVerticallyFlipped()&&(e=-e);const i=Math.abs(T);A-=i-(R=Math.floor(i*(50+e)/100))}return{src:new o.Rectangle(m,R,E-m,A-R),dst:new o.Rectangle(0,0,s.getWidth(),s.getHeight()),canvas:s}}{const t=new o.Rectangle(0,0,e.getWidth(),e.getHeight()),i=s.getWidth()/e.getWidth(),r=s.getHeight()/e.getHeight(),n=Math.min(i,r),c=t.withRescaling(n,a.RoundingFunc.ceil),h=Math.floor((s.getWidth()-c.getWidth())/2),u=Math.floor((s.getHeight()-c.getHeight())/2);return{src:t,dst:new o.Rectangle(h,u,c.getWidth(),c.getHeight()),canvas:s}}}calculateNewCanvas(t,e,i,r,o=1,c=99999,h=!1,u,d,l){let g=e,p=i,f=e/i;void 0!==u&&f<u||void 0!==l&&f<l?(f=void 0!==l?l:void 0!==u?u:0,t===a.OperationEnum.CROP?p=Math.floor(g/f):g=Math.ceil(p*f)):(void 0!==d&&f>d||void 0!==l&&f>l)&&(f=void 0!==l?l:void 0!==d?d:0,t===a.OperationEnum.CROP?g=Math.floor(p*f):p=Math.ceil(g/f));const m=Math.abs((void 0!==u?u:0)-f)<=Math.abs((void 0!==d?d:9999999)-f);1===f&&g!==p&&(g=p=t===a.OperationEnum.CROP?Math.min(g,p):Math.max(g,p)),g>c?(g=c,p=this.accurateHeightRecalc(m,f,g)):g<o&&(g=o,p=this.accurateHeightRecalc(m,f,g));r&&(this.isNumberMod2(g)||this.isNumberMod2(p));const R=new n.Dimensions(g,p),E=void 0!==u&&R.getAspectRatio()<u||void 0!==d&&R.getAspectRatio()>d;if(R.getWidth()<1||R.getHeight()<1)throw new Error(s.sprintf("Canvas calculation failed. Target width (%1s) or height (%2s) less than one pixel.",R.getWidth(),R.getHeight()));if(R.getWidth()<o)throw new Error(s.sprintf("Canvas calculation failed. Target width (%1s) less than minimum allowed (%2s).",R.getWidth(),o));if(R.getWidth()>c)throw new Error(s.sprintf("Canvas calculation failed. Target width (%1s) greater than maximum allowed (%2s).",R.getWidth(),c));if(E&&!h)throw new Error(s.sprintf("Canvas calculation failed. Unable to reach target aspect ratio range during output canvas generation. The range of allowed aspect ratios is too narrow (%1.8f - %2.8f). We achieved a ratio of %3.8f.",null!==u?u:0,null!==d?d:Number.MAX_VALUE,R.getAspectRatio()));return{canvas:R,mod2WidthDiff:0,mod2HeightDiff:0}}accurateHeightRecalc(t,e,i){return t?Math.floor(i/e):Math.ceil(i/e)}isNumberMod2(t){return Math.round(t)%2==0}}},function(t,e,i){!function(t){var i={not_string:/[^s]/,number:/[diefg]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijosuxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[\+\-]/};function s(){var t=arguments[0],e=s.cache;return e[t]&&e.hasOwnProperty(t)||(e[t]=s.parse(t)),s.format.call(null,e[t],arguments)}s.format=function(t,e){var n,o,a,c,h,u,d,l,g=1,p=t.length,f="",m=[],R=!0,E="";for(o=0;o<p;o++)if("string"===(f=r(t[o])))m[m.length]=t[o];else if("array"===f){if((c=t[o])[2])for(n=e[g],a=0;a<c[2].length;a++){if(!n.hasOwnProperty(c[2][a]))throw new Error(s("[sprintf] property '%s' does not exist",c[2][a]));n=n[c[2][a]]}else n=c[1]?e[c[1]]:e[g++];if("function"==r(n)&&(n=n()),i.not_string.test(c[8])&&i.not_json.test(c[8])&&"number"!=r(n)&&isNaN(n))throw new TypeError(s("[sprintf] expecting number but found %s",r(n)));switch(i.number.test(c[8])&&(R=n>=0),c[8]){case"b":n=n.toString(2);break;case"c":n=String.fromCharCode(n);break;case"d":case"i":n=parseInt(n,10);break;case"j":n=JSON.stringify(n,null,c[6]?parseInt(c[6]):0);break;case"e":n=c[7]?n.toExponential(c[7]):n.toExponential();break;case"f":n=c[7]?parseFloat(n).toFixed(c[7]):parseFloat(n);break;case"g":n=c[7]?parseFloat(n).toPrecision(c[7]):parseFloat(n);break;case"o":n=n.toString(8);break;case"s":n=(n=String(n))&&c[7]?n.substring(0,c[7]):n;break;case"u":n>>>=0;break;case"x":n=n.toString(16);break;case"X":n=n.toString(16).toUpperCase()}i.json.test(c[8])?m[m.length]=n:(!i.number.test(c[8])||R&&!c[3]?E="":(E=R?"+":"-",n=n.toString().replace(i.sign,"")),u=c[4]?"0"===c[4]?"0":c[4].charAt(1):" ",d=c[6]-(E+n).length,h=c[6]&&d>0?(l=u,Array(d+1).join(l)):"",m[m.length]=c[5]?E+n+h:"0"===u?E+h+n:h+E+n)}return m.join("")},s.cache={},s.parse=function(t){for(var e=t,s=[],r=[],n=0;e;){if(null!==(s=i.text.exec(e)))r[r.length]=s[0];else if(null!==(s=i.modulo.exec(e)))r[r.length]="%";else{if(null===(s=i.placeholder.exec(e)))throw new SyntaxError("[sprintf] unexpected placeholder");if(s[2]){n|=1;var o=[],a=s[2],c=[];if(null===(c=i.key.exec(a)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(o[o.length]=c[1];""!==(a=a.substring(c[0].length));)if(null!==(c=i.key_access.exec(a)))o[o.length]=c[1];else{if(null===(c=i.index_access.exec(a)))throw new SyntaxError("[sprintf] failed to parse named argument key");o[o.length]=c[1]}s[2]=o}else n|=2;if(3===n)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");r[r.length]=s}e=e.substring(s[0].length)}return r};function r(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()}e.sprintf=s,e.vsprintf=function(t,e,i){return(i=(e||[]).slice(0)).splice(0,0,t),s.apply(null,i)}}("undefined"==typeof window||window)},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(8),r=i(0);e.ConstraintsFactory=class{static createFor(t){switch(t){case r.FeedTypeEnum.FEED_STORY:return new s.StoryConstraints;case r.FeedTypeEnum.FEED_DIRECT:return new s.DirectConstraints;case r.FeedTypeEnum.FEED_DIRECT_STORY:return new s.DirectStoryConstraints;case r.FeedTypeEnum.FEED_TV:return new s.TvConstraints;case r.FeedTypeEnum.FEED_TIMELINE_ALBUM:return new s.AlbumConstraints;case r.FeedTypeEnum.FEED_TIMELINE:default:return new s.TimelineConstraints}}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});class s{constructor(){this.MIN_RATIO=.8,this.MAX_RATIO=1.91,this.RECOMMENDED_RATIO=1,this.RECOMMENDED_RATIO_DEVIATION=0,this.MIN_DURATION=3,this.MAX_DURATION=60,this.TITLE=""}getMaxAspectRatio(){return this.MAX_RATIO}getMaxDuration(){return this.MAX_DURATION}getMinAspectRatio(){return this.MIN_RATIO}getMinDuration(){return this.MIN_DURATION}getRecommendedRatio(){return this.RECOMMENDED_RATIO}getRecommendedRatioDeviation(){return this.RECOMMENDED_RATIO_DEVIATION}getTitle(){return this.TITLE}useRecommendedRatioByDefault(){return!1}}e.BaseConstraints=s;e.TimelineConstraints=class extends s{constructor(){super(...arguments),this.TITLE="timeline"}};e.AlbumConstraints=class extends s{constructor(){super(...arguments),this.TITLE="album"}};e.DirectConstraints=class extends s{constructor(){super(...arguments),this.TITLE="direct",this.MIN_DURATION=1,this.MAX_DURATION=15}};e.StoryConstraints=class extends s{constructor(){super(...arguments),this.TITLE="story",this.MIN_RATIO=.56,this.MAX_RATIO=.67,this.RECOMMENDED_RATIO=.5625,this.RECOMMENDED_RATIO_DEVIATION=.0025,this.MIN_DURATION=1,this.MAX_DURATION=15}useRecommendedRatioByDefault(){return!0}};e.DirectStoryConstraints=class extends s{constructor(){super(...arguments),this.TITLE="direct story"}};e.TvConstraints=class extends s{constructor(){super(...arguments),this.TITLE="tv",this.MIN_RATIO=.5,this.MAX_RATIO=.8,this.MIN_DURATION=15,this.MAX_DURATION=600}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(10);e.InstagramPhotoCalculator=class extends s.InstagramMediaCalculator{constructor(t){super(),this.instagramPhoto=t}getInstagramMedia(){return this.instagramPhoto}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(1),r=i(2);e.InstagramMediaCalculator=class{calculate(){const t=this.getInstagramMedia();return t.shouldProcess()?t.calculate():{dst:new r.Rectangle(0,0,t.getMediaDetails().getWidth(),t.getMediaDetails().getHeight()),src:new r.Rectangle(0,0,t.getMediaDetails().getWidth(),t.getMediaDetails().getHeight()),canvas:new s.Dimensions(t.getMediaDetails().getWidth(),t.getMediaDetails().getHeight())}}}}]); | ||
!function(t){var e={};function i(s){if(e[s])return e[s].exports;var r=e[s]={i:s,l:!1,exports:{}};return t[s].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=t,i.c=e,i.d=function(t,e,s){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:s})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(s,r,function(e){return t[e]}.bind(null,r));return s},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=5)}([function(t,e,i){"use strict";var s;Object.defineProperty(e,"__esModule",{value:!0}),function(t){t[t.FEED_TIMELINE=1]="FEED_TIMELINE",t[t.FEED_TIMELINE_ALBUM=2]="FEED_TIMELINE_ALBUM",t[t.FEED_STORY=3]="FEED_STORY",t[t.FEED_DIRECT=4]="FEED_DIRECT",t[t.FEED_DIRECT_STORY=5]="FEED_DIRECT_STORY",t[t.FEED_TV=6]="FEED_TV"}(e.FeedTypeEnum||(e.FeedTypeEnum={})),function(t){t.CROP="CROP",t.EXPAND="EXPAND"}(e.OperationEnum||(e.OperationEnum={})),function(t){t.round="round",t.floor="floor",t.ceil="ceil"}(s=e.RoundingFunc||(e.RoundingFunc={})),e.RoundingFunctions=new Map([[s.round,{name:s.round,roundingFunc:Math.round}],[s.floor,{name:s.floor,roundingFunc:Math.floor}],[s.ceil,{name:s.ceil,roundingFunc:Math.ceil}]]),function(t){t.IMAGETYPE_JPEG="IMAGETYPE_JPEG",t.IMAGETYPE_PNG="IMAGETYPE_PNG"}(e.ImageType||(e.ImageType={}));class r{constructor(t){this.rawValue=t,this.min=Number.MIN_SAFE_INTEGER,this.max=Number.MAX_SAFE_INTEGER}valueOf(){return this.value}get value(){return this.clamp(Math.trunc(this.rawValue))}clamp(t){return t<this.min?this.min:t>this.max?this.max:t}}e.ClampedInteger=r;e.CropFocus=class extends r{constructor(){super(...arguments),this.min=-50,this.max=50}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(7),r=i(8),n=i(2),o=i(3),a=i(0);e.InstagramMedia=class{constructor(t){if(t?(this.operation=void 0!==t.operation?t.operation:a.OperationEnum.CROP,this.targetFeed=void 0!==t.targetFeed?t.targetFeed:a.FeedTypeEnum.FEED_TIMELINE,this.allowNewAspectDeviation=t.allowNewAspectDeviation,this.bgColor=t.bgColor,this.blurredBorder=t.blurredBorder,this.horCropFocus=t.horCropFocus,this.maxAspectRatio=t.maxAspectRatio,this.minAspectRatio=t.minAspectRatio,this.useRecommendedRatio=t.useRecommendedRatio,this.userForceTargetAspectRatio=t.userForceTargetAspectRatio,this.verCropFocus=t.verCropFocus):(this.operation=a.OperationEnum.CROP,this.targetFeed=a.FeedTypeEnum.FEED_TIMELINE),this.hasUserForceTargetAspectRatio=!1,void 0!==this.userForceTargetAspectRatio&&(this.hasUserForceTargetAspectRatio=!0,this.useRecommendedRatio=!1),this.constraints=r.ConstraintsFactory.createFor(this.targetFeed),this.hasUserForceTargetAspectRatio&&void 0===this.useRecommendedRatio&&(void 0!==this.minAspectRatio||void 0!==this.maxAspectRatio?this.useRecommendedRatio=!1:this.useRecommendedRatio=this.constraints.useRecommendedRatioByDefault()),!this.hasUserForceTargetAspectRatio&&this.useRecommendedRatio){this.forceTargetAspectRatio=this.constraints.getRecommendedRatio();const t=this.constraints.getRecommendedRatioDeviation();this.minAspectRatio=this.forceTargetAspectRatio-t,this.maxAspectRatio=this.forceTargetAspectRatio+t}else{const t=this.constraints.getMinAspectRatio(),e=this.constraints.getMaxAspectRatio();if(void 0!==this.minAspectRatio&&(this.minAspectRatio<t||this.minAspectRatio>e))throw new Error(s.sprintf("Minimum aspect ratio must be between %1.3f and %2.3f.",t,e));if(void 0===this.minAspectRatio&&(this.minAspectRatio=t),void 0!==this.maxAspectRatio&&(this.maxAspectRatio<t||this.maxAspectRatio>e))throw new Error(s.sprintf("Maximum aspect ratio must be between %1.3f and %2.3f.",t,e));if(void 0===this.maxAspectRatio&&(this.maxAspectRatio=e),this.minAspectRatio>this.maxAspectRatio)throw new Error("Maximum aspect ratio must be greater than or equal to minimum.");if(this.hasUserForceTargetAspectRatio){if(this.forceTargetAspectRatio=this.userForceTargetAspectRatio,void 0===this.forceTargetAspectRatio)throw new Error("Force target aspect ratio undefined");if(this.forceTargetAspectRatio<this.minAspectRatio)throw new Error(s.sprintf("Custom target aspect ratio (%1.5f) must be greater than or equal to the minimum aspect ratio (%2.5f).",this.forceTargetAspectRatio,this.minAspectRatio));if(this.forceTargetAspectRatio>this.maxAspectRatio)throw new Error(s.sprintf("Custom target aspect ratio (%.5f) must be lesser than or equal to the maximum aspect ratio (%.5f).",this.forceTargetAspectRatio,this.maxAspectRatio))}}void 0===this.allowNewAspectDeviation&&(this.allowNewAspectDeviation=!1),void 0===this.bgColor&&(this.bgColor={red:255,green:255,blue:255}),void 0===this.blurredBorder&&(this.blurredBorder=!1)}shouldProcess(){const t=this.getMediaDetails().getAspectRatio();if(void 0!==this.minAspectRatio&&t<this.minAspectRatio)return!0;if(void 0!==this.maxAspectRatio&&t>this.maxAspectRatio)return!0;if(this.hasUserForceTargetAspectRatio&&this.forceTargetAspectRatio)if(1===this.forceTargetAspectRatio){if(1!==t)return!0}else{const e=.003,i=this.forceTargetAspectRatio-e,s=this.forceTargetAspectRatio+e;if(t<i||t>s)return!0}try{return this.getMediaDetails().validate(this.constraints),!1}catch(t){return!0}}calculate(){const t=this.getMediaDetails(),e=new n.Dimensions(t.getWidth(),t.getHeight()),i=this.calculateNewCanvas(this.operation,e.getWidth(),e.getHeight(),this.isMod2CanvasRequired(),t.getMinAllowedWidth(),t.getMaxAllowedWidth(),this.allowNewAspectDeviation,this.minAspectRatio,this.maxAspectRatio,this.forceTargetAspectRatio),s=i.canvas;if(this.operation===a.OperationEnum.CROP){let r=0;const c=new n.Dimensions(s.getWidth()-i.mod2WidthDiff,s.getHeight()-i.mod2HeightDiff),h=c.getWidth()/e.getWidth(),u=c.getHeight()/e.getHeight();r=Math.abs(c.getAspectRatio()-e.getAspectRatio())<1e-4?h:c.getAspectRatio()<e.getAspectRatio()?u:h;let d=c.withRescaling(1/r,a.RoundingFunc.round);const l=Math.round(i.mod2WidthDiff*(1/r)),g=Math.round(i.mod2HeightDiff*(1/r)),p=(d=new n.Dimensions(d.getWidth()+l,d.getHeight()+g)).getWidth()<=e.getWidth()?d.getWidth():e.getWidth(),m=d.getHeight()<=e.getHeight()?d.getHeight():e.getHeight();d=new n.Dimensions(p,m);let f=0,R=0,E=e.getWidth(),A=e.getHeight();const M=d.getWidth()-e.getWidth(),T=d.getHeight()-e.getHeight();if(M<0){let e=void 0!==this.horCropFocus?this.horCropFocus.value:0;t.isHorizontallyFlipped()&&(e=-e);const i=Math.abs(M);E-=i-(f=Math.floor(i*(50+e)/100))}if(T<0){let e=void 0!==this.verCropFocus?this.verCropFocus.value:-50;t.isVerticallyFlipped()&&(e=-e);const i=Math.abs(T);A-=i-(R=Math.floor(i*(50+e)/100))}return{src:new o.Rectangle(f,R,E-f,A-R),dst:new o.Rectangle(0,0,s.getWidth(),s.getHeight()),canvas:s}}{const t=new o.Rectangle(0,0,e.getWidth(),e.getHeight()),i=s.getWidth()/e.getWidth(),r=s.getHeight()/e.getHeight(),n=Math.min(i,r),c=t.withRescaling(n,a.RoundingFunc.ceil),h=Math.floor((s.getWidth()-c.getWidth())/2),u=Math.floor((s.getHeight()-c.getHeight())/2);return{src:t,dst:new o.Rectangle(h,u,c.getWidth(),c.getHeight()),canvas:s}}}calculateNewCanvas(t,e,i,r,o=1,c=99999,h=!1,u,d,l){let g=e,p=i,m=e/i;void 0!==u&&m<u||void 0!==l&&m<l?(m=void 0!==l?l:void 0!==u?u:0,t===a.OperationEnum.CROP?p=Math.floor(g/m):g=Math.ceil(p*m)):(void 0!==d&&m>d||void 0!==l&&m>l)&&(m=void 0!==l?l:void 0!==d?d:0,t===a.OperationEnum.CROP?g=Math.floor(p*m):p=Math.ceil(g/m));const f=Math.abs((void 0!==u?u:0)-m)<=Math.abs((void 0!==d?d:9999999)-m);1===m&&g!==p&&(g=p=t===a.OperationEnum.CROP?Math.min(g,p):Math.max(g,p)),g>c?(g=c,p=this.accurateHeightRecalc(f,m,g)):g<o&&(g=o,p=this.accurateHeightRecalc(f,m,g));r&&(this.isNumberMod2(g)||this.isNumberMod2(p));const R=new n.Dimensions(g,p),E=void 0!==u&&R.getAspectRatio()<u||void 0!==d&&R.getAspectRatio()>d;if(R.getWidth()<1||R.getHeight()<1)throw new Error(s.sprintf("Canvas calculation failed. Target width (%1s) or height (%2s) less than one pixel.",R.getWidth(),R.getHeight()));if(R.getWidth()<o)throw new Error(s.sprintf("Canvas calculation failed. Target width (%1s) less than minimum allowed (%2s).",R.getWidth(),o));if(R.getWidth()>c)throw new Error(s.sprintf("Canvas calculation failed. Target width (%1s) greater than maximum allowed (%2s).",R.getWidth(),c));if(E&&!h)throw new Error(s.sprintf("Canvas calculation failed. Unable to reach target aspect ratio range during output canvas generation. The range of allowed aspect ratios is too narrow (%1.8f - %2.8f). We achieved a ratio of %3.8f.",null!==u?u:0,null!==d?d:Number.MAX_VALUE,R.getAspectRatio()));return{canvas:R,mod2WidthDiff:0,mod2HeightDiff:0}}accurateHeightRecalc(t,e,i){return t?Math.floor(i/e):Math.ceil(i/e)}isNumberMod2(t){return Math.round(t)%2==0}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(0);class r{constructor(t,e){this.width=t,this.height=e,this.aspectRatio=this.width/this.height}getWidth(){return this.width}getHeight(){return this.height}getAspectRatio(){return this.aspectRatio}withSwappedAxes(){return new r(this.height,this.width)}withRescaling(t=1,e){const i=s.RoundingFunctions.get(e);if(i){const e=i.roundingFunc,s=e(t*this.width),n=e(t*this.height);return new r(s,n)}return new r(this.width,this.height)}}e.Dimensions=r},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(0);class r{constructor(t,e,i,s){this.x=t,this.y=e,this.width=i,this.height=s,this.aspectRatio=this.width/this.height}getX(){return this.x}getY(){return this.y}getX1(){return this.x}getY1(){return this.y}getX2(){return this.x+this.width}getY2(){return this.y+this.height}getWidth(){return this.width}getHeight(){return this.height}getAspectRatio(){return this.aspectRatio}withSwappedAxes(){return new r(this.y,this.x,this.height,this.width)}withRescaling(t=1,e){const i=s.RoundingFunctions.get(e);if(i){const e=i.roundingFunc,s=e(t*this.width),n=e(t*this.height);return new r(this.x,this.y,s,n)}return new r(this.x,this.y,this.width,this.height)}}e.Rectangle=r},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(2),r=i(3);e.InstagramMediaCalculator=class{calculate(){const t=this.getInstagramMedia();return t.shouldProcess()?t.calculate():{dst:new r.Rectangle(0,0,t.getMediaDetails().getWidth(),t.getMediaDetails().getHeight()),src:new r.Rectangle(0,0,t.getMediaDetails().getWidth(),t.getMediaDetails().getHeight()),canvas:new s.Dimensions(t.getMediaDetails().getWidth(),t.getMediaDetails().getHeight())}}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(6),r=i(10),n=i(11),o=i(12),a=i(0);e.instagramApiMediaLib={calculatePhoto(t,e){const i=new s.InstagramPhoto(t,{operation:a.OperationEnum.EXPAND});return new r.InstagramPhotoCalculator(i).calculate()},calculateVideo(t,e){const i=new n.InstagramVideo(t,{operation:a.OperationEnum.EXPAND});return new o.InstagramVideoCalculator(i).calculate()}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(1);e.InstagramPhoto=class extends s.InstagramMedia{constructor(t,e){super(e),this.details=t}getMediaDetails(){return this.details}isMod2CanvasRequired(){return!1}}},function(t,e,i){!function(t){var i={not_string:/[^s]/,number:/[diefg]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijosuxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[\+\-]/};function s(){var t=arguments[0],e=s.cache;return e[t]&&e.hasOwnProperty(t)||(e[t]=s.parse(t)),s.format.call(null,e[t],arguments)}s.format=function(t,e){var n,o,a,c,h,u,d,l,g=1,p=t.length,m="",f=[],R=!0,E="";for(o=0;o<p;o++)if("string"===(m=r(t[o])))f[f.length]=t[o];else if("array"===m){if((c=t[o])[2])for(n=e[g],a=0;a<c[2].length;a++){if(!n.hasOwnProperty(c[2][a]))throw new Error(s("[sprintf] property '%s' does not exist",c[2][a]));n=n[c[2][a]]}else n=c[1]?e[c[1]]:e[g++];if("function"==r(n)&&(n=n()),i.not_string.test(c[8])&&i.not_json.test(c[8])&&"number"!=r(n)&&isNaN(n))throw new TypeError(s("[sprintf] expecting number but found %s",r(n)));switch(i.number.test(c[8])&&(R=n>=0),c[8]){case"b":n=n.toString(2);break;case"c":n=String.fromCharCode(n);break;case"d":case"i":n=parseInt(n,10);break;case"j":n=JSON.stringify(n,null,c[6]?parseInt(c[6]):0);break;case"e":n=c[7]?n.toExponential(c[7]):n.toExponential();break;case"f":n=c[7]?parseFloat(n).toFixed(c[7]):parseFloat(n);break;case"g":n=c[7]?parseFloat(n).toPrecision(c[7]):parseFloat(n);break;case"o":n=n.toString(8);break;case"s":n=(n=String(n))&&c[7]?n.substring(0,c[7]):n;break;case"u":n>>>=0;break;case"x":n=n.toString(16);break;case"X":n=n.toString(16).toUpperCase()}i.json.test(c[8])?f[f.length]=n:(!i.number.test(c[8])||R&&!c[3]?E="":(E=R?"+":"-",n=n.toString().replace(i.sign,"")),u=c[4]?"0"===c[4]?"0":c[4].charAt(1):" ",d=c[6]-(E+n).length,h=c[6]&&d>0?(l=u,Array(d+1).join(l)):"",f[f.length]=c[5]?E+n+h:"0"===u?E+h+n:h+E+n)}return f.join("")},s.cache={},s.parse=function(t){for(var e=t,s=[],r=[],n=0;e;){if(null!==(s=i.text.exec(e)))r[r.length]=s[0];else if(null!==(s=i.modulo.exec(e)))r[r.length]="%";else{if(null===(s=i.placeholder.exec(e)))throw new SyntaxError("[sprintf] unexpected placeholder");if(s[2]){n|=1;var o=[],a=s[2],c=[];if(null===(c=i.key.exec(a)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(o[o.length]=c[1];""!==(a=a.substring(c[0].length));)if(null!==(c=i.key_access.exec(a)))o[o.length]=c[1];else{if(null===(c=i.index_access.exec(a)))throw new SyntaxError("[sprintf] failed to parse named argument key");o[o.length]=c[1]}s[2]=o}else n|=2;if(3===n)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");r[r.length]=s}e=e.substring(s[0].length)}return r};function r(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()}e.sprintf=s,e.vsprintf=function(t,e,i){return(i=(e||[]).slice(0)).splice(0,0,t),s.apply(null,i)}}("undefined"==typeof window||window)},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(9),r=i(0);e.ConstraintsFactory=class{static createFor(t){switch(t){case r.FeedTypeEnum.FEED_STORY:return new s.StoryConstraints;case r.FeedTypeEnum.FEED_DIRECT:return new s.DirectConstraints;case r.FeedTypeEnum.FEED_DIRECT_STORY:return new s.DirectStoryConstraints;case r.FeedTypeEnum.FEED_TV:return new s.TvConstraints;case r.FeedTypeEnum.FEED_TIMELINE_ALBUM:return new s.AlbumConstraints;case r.FeedTypeEnum.FEED_TIMELINE:default:return new s.TimelineConstraints}}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});class s{constructor(){this.MIN_RATIO=.8,this.MAX_RATIO=1.91,this.RECOMMENDED_RATIO=1,this.RECOMMENDED_RATIO_DEVIATION=0,this.MIN_DURATION=3,this.MAX_DURATION=60,this.TITLE=""}getMaxAspectRatio(){return this.MAX_RATIO}getMaxDuration(){return this.MAX_DURATION}getMinAspectRatio(){return this.MIN_RATIO}getMinDuration(){return this.MIN_DURATION}getRecommendedRatio(){return this.RECOMMENDED_RATIO}getRecommendedRatioDeviation(){return this.RECOMMENDED_RATIO_DEVIATION}getTitle(){return this.TITLE}useRecommendedRatioByDefault(){return!1}}e.BaseConstraints=s;e.TimelineConstraints=class extends s{constructor(){super(...arguments),this.TITLE="timeline"}};e.AlbumConstraints=class extends s{constructor(){super(...arguments),this.TITLE="album"}};e.DirectConstraints=class extends s{constructor(){super(...arguments),this.TITLE="direct",this.MIN_DURATION=1,this.MAX_DURATION=15}};e.StoryConstraints=class extends s{constructor(){super(...arguments),this.TITLE="story",this.MIN_RATIO=.56,this.MAX_RATIO=.67,this.RECOMMENDED_RATIO=.5625,this.RECOMMENDED_RATIO_DEVIATION=.0025,this.MIN_DURATION=1,this.MAX_DURATION=15}useRecommendedRatioByDefault(){return!0}};e.DirectStoryConstraints=class extends s{constructor(){super(...arguments),this.TITLE="direct story"}};e.TvConstraints=class extends s{constructor(){super(...arguments),this.TITLE="tv",this.MIN_RATIO=.5,this.MAX_RATIO=.8,this.MIN_DURATION=15,this.MAX_DURATION=600}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(4);e.InstagramPhotoCalculator=class extends s.InstagramMediaCalculator{constructor(t){super(),this.instagramPhoto=t}getInstagramMedia(){return this.instagramPhoto}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(1);e.InstagramVideo=class extends s.InstagramMedia{constructor(t,e){super(e),this.details=t}getMediaDetails(){return this.details}isMod2CanvasRequired(){return!0}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=i(4);e.InstagramVideoCalculator=class extends s.InstagramMediaCalculator{constructor(t){super(),this.instagramVideo=t}getInstagramMedia(){return this.instagramVideo}}}]); |
{ | ||
"name": "instagram-api-media", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Automatically calculates a media file data according to Instagram's rules.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/instagram-api-media.min.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97066
48
1186