@etu-wiki/sharp-iiif-shims 0.0.34 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var o in i)("object"==typeof exports?exports:t)[o]=i[o]}}(global,(()=>{return t={958:t=>{var e;global,e=()=>(()=>{"use strict";var t={607:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var i="[1-9][0-9]*",o="[0-9]*",r="(?=.*[1-9])\\d+(\\.\\d+)?",n="\\d+(\\.\\d+)?",a={jpg:"image/jpeg",png:"image/png",webp:"image/webp",tif:"image/tiff",gif:"image/gif",jp2:"image/jp2",pdf:"application/pdf"},s={version:["1.0","1.1","2.0","2.1","3.0"],level:["0","1","2"],region:["full","square","".concat(o,",").concat(o,",").concat(i,",").concat(i),"pct:".concat(n,",").concat(n,",").concat(r,",").concat(r)],rotation:"!?".concat(n),quality:["color","gray","bitonal","default","native","grey"],format:["jpg","png","webp","tif","gif"],size:[]},h={1:["full","".concat(i,","),",".concat(i),"pct:".concat(r),"".concat(i,",").concat(i),"!".concat(i,",").concat(i)],1.1:["full","".concat(i,","),",".concat(i),"pct:".concat(r),"".concat(i,",").concat(i),"!".concat(i,",").concat(i)],2:["full","".concat(i,","),",".concat(i),"pct:".concat(r),"".concat(i,",").concat(i),"!".concat(i,",").concat(i)],2.1:["full","max","".concat(i,","),",".concat(i),"pct:".concat(r),"".concat(i,",").concat(i),"!".concat(i,",").concat(i)],3:["max","".concat(i,","),",".concat(i),"pct:".concat(r),"".concat(i,",").concat(i),"!".concat(i,",").concat(i),"\\^max","\\^".concat(i,","),"\\^,".concat(i),"\\^pct:".concat(r),"\\^".concat(i,",").concat(i),"\\^!".concat(i,",").concat(i)]},c=function(){function t(t,e,i,o,r,n,a,c){void 0===o&&(o=4e6),void 0===r&&(r=2e3),void 0===n&&(n=2e3),void 0===a&&(a=512),void 0===c&&(c=512),this.version=t,this.level=e,this.maxArea=o,this.maxWidth=r,this.maxHeight=n,this.tileWidth=a,this.tileHeight=c,this.normalImageType=i,this.validate("version",t),this.validate("level",e),s.size=h[Number(t)]}return t.prototype.validator=function(t){var e=s[t];return e instanceof Array&&(e=e.join("|")),new RegExp("^("+e+")$")},t.prototype.validate=function(t,e){if(!this.validator(t).test(e))throw Error("invalid IIIF url ".concat(t,": ").concat(e));return!0},t.prototype.normalizeRegionParams=function(t,e){if(this.validate("region",t),"full"===t)return null;if("square"===t)return this._regionSquare(e);if(t.match(/^pct:([\d,]+)/))return this._regionPct(RegExp.$1,e);var i=t.split(",").map((function(t){return Number(t)}));return this._regionXYWH(i,e)},t.prototype._regionSquare=function(t){var e,i,o=t.width,r=t.height;if(o!==r){var n=Math.min(o,r),a=Math.abs(Math.floor((o-r)/2));return o>r?(e=a,i=0):(e=0,i=a),this._regionXYWH([e,i,n,n],t)}},t.prototype._regionPct=function(t,e){var i=t.split(",").map((function(t,i){var o=Number(t)/100;return 0===i||2===i?Math.round(e.width*o):1===i||3===i?Math.round(e.height*o):void 0}));return this._regionXYWH(i,e)},t.prototype._regionXYWH=function(t,e){var i=e.width,o=e.height,r=t[0],n=t[1],a=t[2],s=t[3];return r+a>i&&(a=i-r),n+s>o&&(s=o-n),{x:r,y:n,w:a,h:s}},t.prototype.normalizeSizeParams=function(t,e){var i=t,o=e.width,r=e.height;this.validate("size",i);var n,a=!1;if("^"===i.charAt(0)&&(a=!0,i=i.substring(1)),"full"===i)return null;if("max"===i?n=this._sizeMaxScale(e):i.match(/^pct:([\d]+)/)?n=this._sizePctScale(RegExp.$1):"!"===i.charAt(0)&&(i=i.substring(1),n=this._sizeBangScale(i,e)),1===n)return null;if(n){var s=Math.round(o*n),h=Math.round(r*n);return this._sizeWH("".concat(s,",").concat(h),a,e)}return this._sizeWH(i,a,e)},t.prototype._sizeBangScale=function(t,e){var i=e.width,o=e.height,r=t.split(",").map((function(t){return""===t?null:Number(t)})),n=r[0],a=r[1],s=Math.min(n/i,a/o);return n>=i&&a>=o?1:s},t.prototype._sizeMaxScale=function(t){var e=t.width,i=t.height,o=1;return this.maxArea&&this.maxArea<e*i&&(o=Math.sqrt(this.maxArea/(e*i))),this.maxWidth&&this.maxWidth<e&&(o=Math.min(o,this.maxWidth/e)),this.maxHeight&&this.maxHeight<i&&(o=Math.min(o,this.maxHeight/i)),o},t.prototype._sizePctScale=function(t){return Number(t)/100},t.prototype._sizeWH=function(t,e,i){var o=i.width,r=i.height,n=t.split(",").map((function(t){return""===t?null:Number(t)})),a=n[0],s=n[1];if(a?s||(s=Math.round(r*a/o)):a=Math.round(o*s/r),(a>o||s>r)&&!e)throw Error("should not upscale without ^");return{width:a,height:s}},t.prototype.normalizeRotationParams=function(t){this.validate("rotation",t);var e=!1;return"0"===t?null:("!"===t[0]&&(e=!0),{isMirror:e,degree:Number(t.replace(/^!/,""))})},t.prototype.normalizeQualityParams=function(t){return this.validate("quality",t),t},t.prototype.normalizeFormatParams=function(t){return"1.0"!==this.version&&"1.1"!==this.version&&"2.0"!==this.version&&"2.1"!==this.version||t?(this.validate("format",t),t):"png"},t.prototype.getContentType=function(t){return a[t]},t.prototype.generateImageInfoTemp=function(t,e){var i={},o={};i.info=o;var r=this.version;return"1.0"===r?(o.identifier=t,o.width=e.width,o.height=e.height,o.scale_factors=this.factors(e),o.tile_width=this.tileWidth,o.tile_height=this.tileHeight,o.formats=s.format,o.qualities=s.quality,o.profile=this.uriPattern("compliance"),i.contentType="application/json",i.body=JSON.stringify(o)):("1.1"===r?(o["@context"]=this.uriPattern("context"),o["@id"]=t,o.width=e.width,o.height=e.height,o.scale_factors=this.factors(e),o.tile_width=this.tileWidth,o.tile_height=this.tileHeight,o.formats=s.format,o.qualities=s.quality,o.profile=this.uriPattern("compliance")):"2.0"===r||"2.1"===r?(o["@context"]=this.uriPattern("context"),o["@id"]=t,o.protocol="http://iiif.io/api/image",o.width=e.width,o.height=e.height,"0"===this.level?o.sizes=this.sizes(e):o.tiles=[{scaleFactors:this.factors(e),width:this.tileWidth,height:this.tileHeight}],o.profile=[this.uriPattern("compliance")]):"3.0"===r&&(o["@context"]=[this.uriPattern("context")],o.id=t,o.type="ImageService3",o.protocol="http://iiif.io/api/image",o.width=e.width,o.height=e.height,"0"===this.level?o.sizes=this.sizes(e):o.tiles=[{scaleFactors:this.factors(e),width:this.tileWidth,height:this.tileHeight}],o.profile=this.uriPattern("compliance")),i.contentType="application/ld+json"),i},t.prototype.factors=function(t){for(var e=1,i=[1],o=t.width,r=t.height;!(this.tileWidth*e>o&&this.tileHeight*e>r);)e*=2,i.push(e);return i},t.prototype.uriPattern=function(t){var e,i;return"1.0"===this.version?e="http://library.stanford.edu/iiif/image-api/compliance.html#level".concat(this.level):"1.1"===this.version?(e="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level".concat(this.level),i="http://library.stanford.edu/iiif/image-api/1.1/context.json"):"2.0"===this.version||"2.1"===this.version?(e="http://iiif.io/api/image/2/level".concat(this.level,".json"),i="http://iiif.io/api/image/2/context.json"):"3.0"===this.version&&(e="level".concat(this.level),i="http://iiif.io/api/image/3/context.json"),"compliance"===t?e:"context"===t?i:void 0},t.prototype.sizes=function(t){return this.normalizeSizeParams("!200,200",{width:t.width,height:t.height}),this.normalizeSizeParams("!50,50",{width:t.width,height:t.height}),[{width:t.width,height:t.height}]},t}();e.default=c,t.exports=c}},e={};return function i(o){var r=e[o];if(void 0!==r)return r.exports;var n=e[o]={exports:{}};return t[o](n,n.exports,i),n.exports}(607)})(),t.exports=e()},607:function(t,e,i){"use strict";var o,r=this&&this.__extends||(o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},o(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}),n=this&&this.__assign||function(){return n=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},n.apply(this,arguments)},a=this&&this.__awaiter||function(t,e,i,o){return new(i||(i=Promise))((function(r,n){function a(t){try{h(o.next(t))}catch(t){n(t)}}function s(t){try{h(o.throw(t))}catch(t){n(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}h((o=o.apply(t,e||[])).next())}))},s=this&&this.__generator||function(t,e){var i,o,r,n,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return n={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function s(s){return function(h){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;n&&(n=0,s[0]&&(a=0)),a;)try{if(i=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,o=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((r=(r=a.trys).length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){a.label=s[1];break}if(6===s[0]&&a.label<r[1]){a.label=r[1],r=s;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(s);break}r[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],o=0}finally{i=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,h])}}},h=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var c=h(i(441)),l=h(i(958)),p={2:["baseUriRedirect","canonicalLinkHeader","cors","jsonldMediaType","mirroring","profileLinkHeader","regionByPct","regionByPx","rotationArbitrary","rotationBy90s","sizeAboveFull","sizeByWhListed","sizeByForcedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"],2.1:["baseUriRedirect","canonicalLinkHeader","cors","jsonldMediaType","mirroring","profileLinkHeader","regionByPct","regionByPx","regionSquare","rotationArbitrary","rotationBy90s","sizeAboveFull","sizeByConfinedWh","sizeByDistortedWh","sizeByH","sizeByPct","sizeByW","sizeByWh","sizeByWhListed","sizeByForcedWh"],3:["baseUriRedirect","canonicalLinkHeader","cors","jsonldMediaType","mirroring","profileLinkHeader","regionByPct","regionByPx","regionSquare","rotationArbitrary","rotationBy90s","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh","sizeUpscaling"]},u=function(t){function e(e,i,o,r,n,a,s,h){return void 0===r&&(r=4e6),void 0===n&&(n=2e3),void 0===a&&(a=2e3),void 0===s&&(s=512),void 0===h&&(h=512),t.call(this,e,i,o,r,n,a,s,h)||this}return r(e,t),e.prototype.regionImpl=function(t){t&&(this.pipeline=this.pipeline.extract({left:t.x,top:t.y,width:t.w,height:t.h}))},e.prototype.sizeImpl=function(t){t&&(this.pipeline=this.pipeline.resize(n(n({},t),{fit:"fill"})))},e.prototype.rotationImpl=function(t){t&&(t.isMirror&&(this.pipeline=this.pipeline.flop()),this.pipeline=this.pipeline.rotate(t.degree))},e.prototype.qualityImpl=function(t){"native"===t||"default"===t||("color"===t?this.pipeline=this.pipeline.toColorspace("srgb"):"gray"===t||"grey"===t?this.pipeline=this.pipeline.grayscale():"bitonal"===t&&(this.pipeline=this.pipeline.threshold()))},e.prototype.formatImpl=function(t){t="tif"===t?"tiff":t,this.pipeline=this.pipeline.toFormat(t)},e.prototype.generateIiifImage=function(e,i){return a(this,void 0,void 0,(function(){var o,r,n,a,h,l,p,u,f,d,g,m,y,v,w,x,b,z,P,_,B,M,I,W,j,H,q,S,R,A,F,T,O,k,L,N,E,C;return s(this,(function(s){switch(s.label){case 0:return o=(0,c.default)(i,{limitInputPixels:!1,sequentialRead:!0}),r=e.split("/"),n=r.pop(),a=n.split(".")[0],h=n.split(".")[1],l=r.pop(),p=r.pop(),u=r.pop(),[4,this.getMetadata(i)];case 1:return f=s.sent(),d={width:f.width,height:f.height},g={},this.pipeline=o,m=t.prototype.normalizeRegionParams.call(this,u,d),this.regionImpl(m),y=t.prototype.normalizeSizeParams.call(this,p,{width:m?m.w:d.width,height:m?m.h:d.height}),this.sizeImpl(y),v=m||{x:0,y:0,w:d.width,h:d.height},w=v.x,x=v.y,b=v.w,z=v.h,P=y||{width:d.width,height:d.height},_=P.width,B=P.height,b*z>_*B*256&&_<1e4&&B<1e4?(console.log("thumbnail"),M=Math.max(_/b,B/z),I=[Math.round(w*M),Math.round(x*M),Math.round(b*M),Math.round(z*M)],W=I[0],j=I[1],H=I[2],q=I[3],console.log(f.pages),S=f.pages-1,[4,(0,c.default)(i,{limitInputPixels:!1,page:S,sequentialRead:!0}).metadata()]):[3,5];case 2:for(R=s.sent(),A=R.width,F=R.height;F<q||A<H;)F*=2,A*=2,S--;return console.log("selectedPage: "+S),T={width:Math.round(d.width*M),height:Math.round(d.height*M),fastShrinkOnLoad:!1},[4,(0,c.default)(i,{limitInputPixels:!1,page:S,sequentialRead:!0}).resize(T).toBuffer()];case 3:return O=s.sent(),this.pipeline=(0,c.default)(O),[4,this.pipeline.metadata()];case 4:k=s.sent(),j+q>k.height&&(q=k.height-j,console.log("adjested sh: "+q)),W+H>k.width&&(H=k.width-W,console.log("adjusted sw: "+H)),L={x:W,y:j,w:H,h:q},this.regionImpl(L),this.sizeImpl(y),console.log(k.width,k.height,T.width,T.height,L,y),s.label=5;case 5:return N=t.prototype.normalizeRotationParams.call(this,l),this.rotationImpl(N),E=t.prototype.normalizeQualityParams.call(this,a),this.qualityImpl(E),C=t.prototype.normalizeFormatParams.call(this,h),this.formatImpl(C),g.body=this.pipeline,g.contentType=t.prototype.getContentType.call(this,C),[2,g]}}))}))},e.prototype.generateImageInfo=function(e,i){var o=this.version,r=this.level,n=t.prototype.generateImageInfoTemp.call(this,e,i),a=n.info;if(("2.0"===o||"2.1"===o)&&(a.profile=[t.prototype.uriPattern.call(this,"compliance")],"2"===r)){var s={formats:["jpg","png","webp","tif"],qualities:["color","gray","bitonal","default","native","grey"]};s.supports=p[Number(o)],a.profile.push(s)}return"3.0"===o&&(a.extraFormats=["webp"],a.preferredFormats=["webp"]),n},e.prototype.getMetadata=function(t){return a(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,(0,c.default)(t,{limitInputPixels:!1,sequentialRead:!0}).metadata()];case 1:return[2,e.sent()]}}))}))},e.prototype.normalize=function(t){return a(this,void 0,void 0,(function(){var e,i,o,r,n;return s(this,(function(a){switch(a.label){case 0:return[4,(e=(0,c.default)(t,{limitInputPixels:!1,sequentialRead:!0})).metadata()];case 1:return i=a.sent(),o=i.width.toString(),r=i.height.toString(),i&&i.orientation&&(e=e.rotate(),i.orientation>=5&&(n=o,o=r,r=n)),[4,e.tiff({pyramid:!0,tile:!0}).toBuffer()];case 2:return[2,{buffer:a.sent(),width:o,height:r}]}}))}))},e.prototype.derive=function(t,e){return a(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,(0,c.default)(t,{limitInputPixels:!1,sequentialRead:!0}).tile({size:512,layout:"iiif"}).toFile("/tmp/".concat(e))];case 1:return i.sent(),[2]}}))}))},e}(l.default);e.default=u,t.exports=u},441:t=>{"use strict";t.exports=require("sharp")}},e={},function i(o){var r=e[o];if(void 0!==r)return r.exports;var n=e[o]={exports:{}};return t[o].call(n.exports,n,n.exports,i),n.exports}(607);var t,e}));
1
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var o in i)("object"==typeof exports?exports:t)[o]=i[o]}}(global,(()=>{return t={958:t=>{var e;global,e=()=>(()=>{"use strict";var t={607:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var i="[1-9][0-9]*",o="[0-9]*",r="(?=.*[1-9])\\d+(\\.\\d+)?",n="\\d+(\\.\\d+)?",a={jpg:"image/jpeg",png:"image/png",webp:"image/webp",tif:"image/tiff",gif:"image/gif",jp2:"image/jp2",pdf:"application/pdf"},s={version:["1.0","1.1","2.0","2.1","3.0"],level:["0","1","2"],region:["full","square","".concat(o,",").concat(o,",").concat(i,",").concat(i),"pct:".concat(n,",").concat(n,",").concat(r,",").concat(r)],rotation:"!?".concat(n),quality:["color","gray","bitonal","default","native","grey"],format:["jpg","png","webp","tif","gif"],size:[]},h={1:["full","".concat(i,","),",".concat(i),"pct:".concat(r),"".concat(i,",").concat(i),"!".concat(i,",").concat(i)],1.1:["full","".concat(i,","),",".concat(i),"pct:".concat(r),"".concat(i,",").concat(i),"!".concat(i,",").concat(i)],2:["full","".concat(i,","),",".concat(i),"pct:".concat(r),"".concat(i,",").concat(i),"!".concat(i,",").concat(i)],2.1:["full","max","".concat(i,","),",".concat(i),"pct:".concat(r),"".concat(i,",").concat(i),"!".concat(i,",").concat(i)],3:["max","".concat(i,","),",".concat(i),"pct:".concat(r),"".concat(i,",").concat(i),"!".concat(i,",").concat(i),"\\^max","\\^".concat(i,","),"\\^,".concat(i),"\\^pct:".concat(r),"\\^".concat(i,",").concat(i),"\\^!".concat(i,",").concat(i)]},c=function(){function t(t,e,i,o,r,n,a,c){void 0===o&&(o=4e6),void 0===r&&(r=2e3),void 0===n&&(n=2e3),void 0===a&&(a=512),void 0===c&&(c=512),this.version=t,this.level=e,this.maxArea=o,this.maxWidth=r,this.maxHeight=n,this.tileWidth=a,this.tileHeight=c,this.normalImageType=i,this.validate("version",t),this.validate("level",e),s.size=h[Number(t)]}return t.prototype.validator=function(t){var e=s[t];return e instanceof Array&&(e=e.join("|")),new RegExp("^("+e+")$")},t.prototype.validate=function(t,e){if(!this.validator(t).test(e))throw Error("invalid IIIF url ".concat(t,": ").concat(e));return!0},t.prototype.normalizeRegionParams=function(t,e){if(this.validate("region",t),"full"===t)return null;if("square"===t)return this._regionSquare(e);if(t.match(/^pct:([\d,]+)/))return this._regionPct(RegExp.$1,e);var i=t.split(",").map((function(t){return Number(t)}));return this._regionXYWH(i,e)},t.prototype._regionSquare=function(t){var e,i,o=t.width,r=t.height;if(o!==r){var n=Math.min(o,r),a=Math.abs(Math.floor((o-r)/2));return o>r?(e=a,i=0):(e=0,i=a),this._regionXYWH([e,i,n,n],t)}},t.prototype._regionPct=function(t,e){var i=t.split(",").map((function(t,i){var o=Number(t)/100;return 0===i||2===i?Math.round(e.width*o):1===i||3===i?Math.round(e.height*o):void 0}));return this._regionXYWH(i,e)},t.prototype._regionXYWH=function(t,e){var i=e.width,o=e.height,r=t[0],n=t[1],a=t[2],s=t[3];return r+a>i&&(a=i-r),n+s>o&&(s=o-n),{x:r,y:n,w:a,h:s}},t.prototype.normalizeSizeParams=function(t,e){var i=t,o=e.width,r=e.height;this.validate("size",i);var n,a=!1;if("^"===i.charAt(0)&&(a=!0,i=i.substring(1)),"full"===i)return null;if("max"===i?n=this._sizeMaxScale(e):i.match(/^pct:([\d]+)/)?n=this._sizePctScale(RegExp.$1):"!"===i.charAt(0)&&(i=i.substring(1),n=this._sizeBangScale(i,a,e)),1===n)return null;if(n){var s=Math.round(o*n),h=Math.round(r*n);return this._sizeWH("".concat(s,",").concat(h),a,e)}return this._sizeWH(i,a,e)},t.prototype._sizeBangScale=function(t,e,i){var o=i.width,r=i.height,n=t.split(",").map((function(t){return""===t?null:Number(t)})),a=n[0],s=n[1],h=Math.min(a/o,s/r);if(a>o&&s>r&&!e)throw Error("should not upscale without ^");return h},t.prototype._sizeMaxScale=function(t){var e=t.width,i=t.height,o=1;return this.maxArea&&this.maxArea<e*i&&(o=Math.sqrt(this.maxArea/(e*i))),this.maxWidth&&this.maxWidth<e&&(o=Math.min(o,this.maxWidth/e)),this.maxHeight&&this.maxHeight<i&&(o=Math.min(o,this.maxHeight/i)),o},t.prototype._sizePctScale=function(t){return Number(t)/100},t.prototype._sizeWH=function(t,e,i){var o=i.width,r=i.height,n=t.split(",").map((function(t){return""===t?null:Number(t)})),a=n[0],s=n[1];if(a?s||(s=Math.round(r*a/o)):a=Math.round(o*s/r),(a>o||s>r)&&!e)throw Error("should not upscale without ^");return{width:a,height:s}},t.prototype.normalizeRotationParams=function(t){this.validate("rotation",t);var e=!1;return"0"===t?null:("!"===t[0]&&(e=!0),{isMirror:e,degree:Number(t.replace(/^!/,""))})},t.prototype.normalizeQualityParams=function(t){return this.validate("quality",t),t},t.prototype.normalizeFormatParams=function(t){return"1.0"!==this.version&&"1.1"!==this.version&&"2.0"!==this.version&&"2.1"!==this.version||t?(this.validate("format",t),t):"png"},t.prototype.getContentType=function(t){return a[t]},t.prototype.generateImageInfoTemp=function(t,e){var i={},o={};i.info=o;var r=this.version;return"1.0"===r?(o.identifier=t,o.width=e.width,o.height=e.height,o.scale_factors=this.factors(e),o.tile_width=this.tileWidth,o.tile_height=this.tileHeight,o.formats=s.format,o.qualities=s.quality,o.profile=this.uriPattern("compliance"),i.contentType="application/json",i.body=JSON.stringify(o)):("1.1"===r?(o["@context"]=this.uriPattern("context"),o["@id"]=t,o.width=e.width,o.height=e.height,o.scale_factors=this.factors(e),o.tile_width=this.tileWidth,o.tile_height=this.tileHeight,o.formats=s.format,o.qualities=s.quality,o.profile=this.uriPattern("compliance")):"2.0"===r||"2.1"===r?(o["@context"]=this.uriPattern("context"),o["@id"]=t,o.protocol="http://iiif.io/api/image",o.width=e.width,o.height=e.height,"0"===this.level?o.sizes=this.sizes(e):o.tiles=[{scaleFactors:this.factors(e),width:this.tileWidth,height:this.tileHeight}],o.profile=[this.uriPattern("compliance")]):"3.0"===r&&(o["@context"]=[this.uriPattern("context")],o.id=t,o.type="ImageService3",o.protocol="http://iiif.io/api/image",o.width=e.width,o.height=e.height,"0"===this.level?o.sizes=this.sizes(e):o.tiles=[{scaleFactors:this.factors(e),width:this.tileWidth,height:this.tileHeight}],o.profile=this.uriPattern("compliance")),i.contentType="application/ld+json"),i},t.prototype.factors=function(t){for(var e=1,i=[1],o=t.width,r=t.height;!(this.tileWidth*e>o&&this.tileHeight*e>r);)e*=2,i.push(e);return i},t.prototype.uriPattern=function(t){var e,i;return"1.0"===this.version?e="http://library.stanford.edu/iiif/image-api/compliance.html#level".concat(this.level):"1.1"===this.version?(e="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level".concat(this.level),i="http://library.stanford.edu/iiif/image-api/1.1/context.json"):"2.0"===this.version||"2.1"===this.version?(e="http://iiif.io/api/image/2/level".concat(this.level,".json"),i="http://iiif.io/api/image/2/context.json"):"3.0"===this.version&&(e="level".concat(this.level),i="http://iiif.io/api/image/3/context.json"),"compliance"===t?e:"context"===t?i:void 0},t.prototype.sizes=function(t){return this.normalizeSizeParams("!200,200",{width:t.width,height:t.height}),this.normalizeSizeParams("!50,50",{width:t.width,height:t.height}),[{width:t.width,height:t.height}]},t}();e.default=c,t.exports=c}},e={};return function i(o){var r=e[o];if(void 0!==r)return r.exports;var n=e[o]={exports:{}};return t[o](n,n.exports,i),n.exports}(607)})(),t.exports=e()},607:function(t,e,i){"use strict";var o,r=this&&this.__extends||(o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},o(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}),n=this&&this.__assign||function(){return n=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},n.apply(this,arguments)},a=this&&this.__awaiter||function(t,e,i,o){return new(i||(i=Promise))((function(r,n){function a(t){try{h(o.next(t))}catch(t){n(t)}}function s(t){try{h(o.throw(t))}catch(t){n(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}h((o=o.apply(t,e||[])).next())}))},s=this&&this.__generator||function(t,e){var i,o,r,n,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return n={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function s(s){return function(h){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;n&&(n=0,s[0]&&(a=0)),a;)try{if(i=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,o=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((r=(r=a.trys).length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){a.label=s[1];break}if(6===s[0]&&a.label<r[1]){a.label=r[1],r=s;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(s);break}r[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],o=0}finally{i=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,h])}}},h=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var c=h(i(441)),l=h(i(958)),p={2:["baseUriRedirect","canonicalLinkHeader","cors","jsonldMediaType","mirroring","profileLinkHeader","regionByPct","regionByPx","rotationArbitrary","rotationBy90s","sizeAboveFull","sizeByWhListed","sizeByForcedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"],2.1:["baseUriRedirect","canonicalLinkHeader","cors","jsonldMediaType","mirroring","profileLinkHeader","regionByPct","regionByPx","regionSquare","rotationArbitrary","rotationBy90s","sizeAboveFull","sizeByConfinedWh","sizeByDistortedWh","sizeByH","sizeByPct","sizeByW","sizeByWh","sizeByWhListed","sizeByForcedWh"],3:["baseUriRedirect","canonicalLinkHeader","cors","jsonldMediaType","mirroring","profileLinkHeader","regionByPct","regionByPx","regionSquare","rotationArbitrary","rotationBy90s","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh","sizeUpscaling"]},u=function(t){function e(e,i,o,r,n,a,s,h){return void 0===r&&(r=4e6),void 0===n&&(n=2e3),void 0===a&&(a=2e3),void 0===s&&(s=512),void 0===h&&(h=512),t.call(this,e,i,o,r,n,a,s,h)||this}return r(e,t),e.prototype.regionImpl=function(t){t&&(this.pipeline=this.pipeline.extract({left:t.x,top:t.y,width:t.w,height:t.h}))},e.prototype.sizeImpl=function(t){t&&(this.pipeline=this.pipeline.resize(n(n({},t),{fit:"fill"})))},e.prototype.rotationImpl=function(t){t&&(t.isMirror&&(this.pipeline=this.pipeline.flop()),this.pipeline=this.pipeline.rotate(t.degree))},e.prototype.qualityImpl=function(t){"native"===t||"default"===t||("color"===t?this.pipeline=this.pipeline.toColorspace("srgb"):"gray"===t||"grey"===t?this.pipeline=this.pipeline.grayscale():"bitonal"===t&&(this.pipeline=this.pipeline.threshold()))},e.prototype.formatImpl=function(t){t="tif"===t?"tiff":t,this.pipeline=this.pipeline.toFormat(t)},e.prototype.generateIiifImage=function(e,i){return a(this,void 0,void 0,(function(){var o,r,n,a,h,l,p,u,f,d,g,m,y,v,w,x,b,z,P,_,B,M,I,W,j,H,q,S,R,F,A,T,k,O,L,N,E,C,U,X,Y;return s(this,(function(s){switch(s.label){case 0:return console.log("hello"),o=(0,c.default)(i,{limitInputPixels:!1,sequentialRead:!0}),r=e.split("/"),n=r.pop(),a=n.split(".")[0],h=n.split(".")[1],l=r.pop(),p=r.pop(),u=r.pop(),o.tiff({compression:"jp2k",tile:!0}).toFile("test.tif"),[4,this.getMetadata(i)];case 1:return f=s.sent(),console.log("world"),d={width:f.width,height:f.height},g={},this.pipeline=o,m=t.prototype.normalizeRegionParams.call(this,u,d),this.regionImpl(m),y=t.prototype.normalizeSizeParams.call(this,p,{width:m?m.w:d.width,height:m?m.h:d.height}),this.sizeImpl(y),w=(v=m||{x:0,y:0,w:d.width,h:d.height}).x,x=v.y,b=v.w,z=v.h,_=(P=y||{width:d.width,height:d.height}).width,B=P.height,b*z>_*B*256&&_<1e4&&B<1e4?(console.log("thumbnail"),M=Math.max(_/b,B/z),I=[Math.round(w*M),Math.round(x*M),Math.round(b*M),Math.round(z*M)],W=I[0],j=I[1],H=I[2],q=I[3],S=[Math.round(d.width*M),Math.round(d.height*M)],R=S[0],F=S[1],A=f.pages-1,[4,(0,c.default)(i,{limitInputPixels:!1,page:A,sequentialRead:!0}).metadata()]):[3,5];case 2:for(T=s.sent(),k=T.width,O=T.height;O<F||k<R;)O*=2,k*=2,A--;return console.log("selectedPage: "+A),L={width:R,height:F,fastShrinkOnLoad:!1},[4,(0,c.default)(i,{limitInputPixels:!1,page:A,sequentialRead:!0}).resize(L).toBuffer()];case 3:return N=s.sent(),this.pipeline=(0,c.default)(N),[4,this.pipeline.metadata()];case 4:E=s.sent(),j+q>E.height&&(q=E.height-j,console.log("adjested sh: "+q)),W+H>E.width&&(H=E.width-W,console.log("adjusted sw: "+H)),C={x:W,y:j,w:H,h:q},this.regionImpl(C),this.sizeImpl(y),console.log(E.width,E.height,L.width,L.height,C,y),s.label=5;case 5:return U=t.prototype.normalizeRotationParams.call(this,l),this.rotationImpl(U),X=t.prototype.normalizeQualityParams.call(this,a),this.qualityImpl(X),Y=t.prototype.normalizeFormatParams.call(this,h),this.formatImpl(Y),g.body=this.pipeline,g.contentType=t.prototype.getContentType.call(this,Y),[2,g]}}))}))},e.prototype.generateImageInfo=function(e,i){var o=this.version,r=this.level,n=t.prototype.generateImageInfoTemp.call(this,e,i),a=n.info;if(("2.0"===o||"2.1"===o)&&(a.profile=[t.prototype.uriPattern.call(this,"compliance")],"2"===r)){var s={formats:["jpg","png","webp","tif"],qualities:["color","gray","bitonal","default","native","grey"]};s.supports=p[Number(o)],a.profile.push(s)}return"3.0"===o&&(a.extraFormats=["webp"],a.preferredFormats=["webp"]),n},e.prototype.getMetadata=function(t){return a(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,(0,c.default)(t,{limitInputPixels:!1,sequentialRead:!0}).metadata()];case 1:return[2,e.sent()]}}))}))},e.prototype.normalize=function(t){return a(this,void 0,void 0,(function(){var e,i,o,r,n;return s(this,(function(a){switch(a.label){case 0:return[4,(e=(0,c.default)(t,{limitInputPixels:!1,sequentialRead:!0})).metadata()];case 1:return i=a.sent(),o=i.width.toString(),r=i.height.toString(),i&&i.orientation&&(e=e.rotate(),i.orientation>=5&&(n=o,o=r,r=n)),[4,e.tiff({pyramid:!0,tile:!0}).toBuffer()];case 2:return[2,{buffer:a.sent(),width:o,height:r}]}}))}))},e.prototype.derive=function(t,e){return a(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,(0,c.default)(t,{limitInputPixels:!1,sequentialRead:!0}).tile({size:512,layout:"iiif"}).toFile("/tmp/".concat(e))];case 1:return i.sent(),[2]}}))}))},e}(l.default);e.default=u,t.exports=u},441:t=>{"use strict";t.exports=require("sharp")}},e={},function i(o){var r=e[o];if(void 0!==r)return r.exports;var n=e[o]={exports:{}};return t[o].call(n.exports,n,n.exports,i),n.exports}(607);var t,e}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etu-wiki/sharp-iiif-shims",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -28,7 +28,7 @@
28
28
  "webpack-cli": "^4.9.2"
29
29
  },
30
30
  "dependencies": {
31
- "@etu-wiki/iiif-image-shims": "^0.0.3",
31
+ "@etu-wiki/iiif-image-shims": "^0.0.4",
32
32
  "sharp": "^0.32.0"
33
33
  },
34
34
  "files": [