@etu-wiki/sharp-iiif-shims 0.0.28 → 0.0.29
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.
- package/dist/index.js +1 -1
- package/package.json +37 -38
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i();else if("function"==typeof define&&define.amd)define([],i);else{var e=i();for(var o in e)("object"==typeof exports?exports:t)[o]=e[o]}}(global,(()=>{return t={958:t=>{var i;global,i=()=>(()=>{"use strict";var t={607:(t,i)=>{Object.defineProperty(i,"__esModule",{value:!0});var e="[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(e,",").concat(e),"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(e,","),",".concat(e),"pct:".concat(r),"".concat(e,",").concat(e),"!".concat(e,",").concat(e)],1.1:["full","".concat(e,","),",".concat(e),"pct:".concat(r),"".concat(e,",").concat(e),"!".concat(e,",").concat(e)],2:["full","".concat(e,","),",".concat(e),"pct:".concat(r),"".concat(e,",").concat(e),"!".concat(e,",").concat(e)],2.1:["full","max","".concat(e,","),",".concat(e),"pct:".concat(r),"".concat(e,",").concat(e),"!".concat(e,",").concat(e)],3:["max","".concat(e,","),",".concat(e),"pct:".concat(r),"".concat(e,",").concat(e),"!".concat(e,",").concat(e),"\\^max","\\^".concat(e,","),"\\^,".concat(e),"\\^pct:".concat(r),"\\^".concat(e,",").concat(e),"\\^!".concat(e,",").concat(e)]},c=function(){function t(t,i,e,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=i,this.maxArea=o,this.maxWidth=r,this.maxHeight=n,this.tileWidth=a,this.tileHeight=c,this.normalImageType=e,this.validate("version",t),this.validate("level",i),s.size=h[Number(t)]}return t.prototype.validator=function(t){var i=s[t];return i instanceof Array&&(i=i.join("|")),new RegExp("^("+i+")$")},t.prototype.validate=function(t,i){if(!this.validator(t).test(i))throw Error("invalid IIIF url ".concat(t,": ").concat(i));return!0},t.prototype.normalizeRegionParams=function(t,i){if(this.validate("region",t),"full"===t)return null;if("square"===t)return this._regionSquare(i);if(t.match(/^pct:([\d,]+)/))return this._regionPct(RegExp.$1,i);var e=t.split(",").map((function(t){return Number(t)}));return this._regionXYWH(e,i)},t.prototype._regionSquare=function(t){var i,e,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?(i=a,e=0):(i=0,e=a),this._regionXYWH([i,e,n,n],t)}},t.prototype._regionPct=function(t,i){var e=t.split(",").map((function(t,e){var o=Number(t)/100;return 0===e||2===e?Math.round(i.width*o):1===e||3===e?Math.round(i.height*o):void 0}));return this._regionXYWH(e,i)},t.prototype._regionXYWH=function(t,i){var e=i.width,o=i.height,r=t[0],n=t[1],a=t[2],s=t[3];return r+a>e&&(a=e-r),n+s>o&&(s=o-n),{x:r,y:n,w:a,h:s}},t.prototype.normalizeSizeParams=function(t,i){var e=t,o=i.width,r=i.height;this.validate("size",e);var n,a=!1;if("^"===e.charAt(0)&&(a=!0,e=e.substring(1)),"full"===e)return null;if("max"===e?n=this._sizeMaxScale(i):e.match(/^pct:([\d]+)/)?n=this._sizePctScale(RegExp.$1):"!"===e.charAt(0)&&(e=e.substring(1),n=this._sizeBangScale(e,i)),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,i)}return this._sizeWH(e,a,i)},t.prototype._sizeBangScale=function(t,i){var e=i.width,o=i.height,r=t.split(",").map((function(t){return""===t?null:Number(t)})),n=r[0],a=r[1],s=Math.min(n/e,a/o);return n>=e&&a>=o?1:s},t.prototype._sizeMaxScale=function(t){var i=t.width,e=t.height,o=1;return this.maxArea&&this.maxArea<i*e&&(o=Math.sqrt(this.maxArea/(i*e))),this.maxWidth&&this.maxWidth<i&&(o=Math.min(o,this.maxWidth/i)),this.maxHeight&&this.maxHeight<e&&(o=Math.min(o,this.maxHeight/e)),o},t.prototype._sizePctScale=function(t){return Number(t)/100},t.prototype._sizeWH=function(t,i,e){var o=e.width,r=e.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)&&!i)throw Error("should not upscale without ^");return{width:a,height:s}},t.prototype.normalizeRotationParams=function(t){this.validate("rotation",t);var i=!1;return"0"===t?null:("!"===t[0]&&(i=!0),{isMirror:i,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,i){var e={},o={};e.info=o;var r=this.version;return"1.0"===r?(o.identifier=t,o.width=i.width,o.height=i.height,o.scale_factors=this.factors(i),o.tile_width=this.tileWidth,o.tile_height=this.tileHeight,o.formats=s.format,o.qualities=s.quality,o.profile=this.uriPattern("compliance"),e.contentType="application/json",e.body=JSON.stringify(o)):("1.1"===r?(o["@context"]=this.uriPattern("context"),o["@id"]=t,o.width=i.width,o.height=i.height,o.scale_factors=this.factors(i),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=i.width,o.height=i.height,"0"===this.level?o.sizes=this.sizes(i):o.tiles=[{scaleFactors:this.factors(i),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=i.width,o.height=i.height,"0"===this.level?o.sizes=this.sizes(i):o.tiles=[{scaleFactors:this.factors(i),width:this.tileWidth,height:this.tileHeight}],o.profile=this.uriPattern("compliance")),e.contentType="application/ld+json"),e},t.prototype.factors=function(t){for(var i=1,e=[1],o=t.width,r=t.height;!(this.tileWidth*i>o&&this.tileHeight*i>r);)i*=2,e.push(i);return e},t.prototype.uriPattern=function(t){var i,e;return"1.0"===this.version?i="http://library.stanford.edu/iiif/image-api/compliance.html#level".concat(this.level):"1.1"===this.version?(i="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level".concat(this.level),e="http://library.stanford.edu/iiif/image-api/1.1/context.json"):"2.0"===this.version||"2.1"===this.version?(i="http://iiif.io/api/image/2/level".concat(this.level,".json"),e="http://iiif.io/api/image/2/context.json"):"3.0"===this.version&&(i="level".concat(this.level),e="http://iiif.io/api/image/3/context.json"),"compliance"===t?i:"context"===t?e: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}();i.default=c,t.exports=c}},i={};return function e(o){var r=i[o];if(void 0!==r)return r.exports;var n=i[o]={exports:{}};return t[o](n,n.exports,e),n.exports}(607)})(),t.exports=i()},607:function(t,i,e){"use strict";var o,r=this&&this.__extends||(o=function(t,i){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])},o(t,i)},function(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function e(){this.constructor=t}o(t,i),t.prototype=null===i?Object.create(i):(e.prototype=i.prototype,new e)}),n=this&&this.__assign||function(){return n=Object.assign||function(t){for(var i,e=1,o=arguments.length;e<o;e++)for(var r in i=arguments[e])Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r]);return t},n.apply(this,arguments)},a=this&&this.__awaiter||function(t,i,e,o){return new(e||(e=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 i;t.done?r(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(a,s)}h((o=o.apply(t,i||[])).next())}))},s=this&&this.__generator||function(t,i){var e,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(n){return function(s){return function(n){if(e)throw new TypeError("Generator is already executing.");for(;a;)try{if(e=1,o&&(r=2&n[0]?o.return:n[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,n[1])).done)return r;switch(o=0,r&&(n=[2&n[0],r.value]),n[0]){case 0:case 1:r=n;break;case 4:return a.label++,{value:n[1],done:!1};case 5:a.label++,o=n[1],n=[0];continue;case 7:n=a.ops.pop(),a.trys.pop();continue;default:if(!((r=(r=a.trys).length>0&&r[r.length-1])||6!==n[0]&&2!==n[0])){a=0;continue}if(3===n[0]&&(!r||n[1]>r[0]&&n[1]<r[3])){a.label=n[1];break}if(6===n[0]&&a.label<r[1]){a.label=r[1],r=n;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(n);break}r[2]&&a.ops.pop(),a.trys.pop();continue}n=i.call(t,a)}catch(t){n=[6,t],o=0}finally{e=r=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,s])}}},h=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(i,"__esModule",{value:!0});var c=h(e(441)),l=h(e(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 i(i,e,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,i,e,o,r,n,a,s,h)||this}return r(i,t),i.prototype.regionImpl=function(t){t&&(this.pipeline=this.pipeline.extract({left:t.x,top:t.y,width:t.w,height:t.h}))},i.prototype.sizeImpl=function(t){t&&(this.pipeline=this.pipeline.resize(n(n({},t),{fit:"fill"})))},i.prototype.rotationImpl=function(t){t&&(t.isMirror&&(this.pipeline=this.pipeline.flop()),this.pipeline=this.pipeline.rotate(t.degree))},i.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()))},i.prototype.formatImpl=function(t){t="tif"===t?"tiff":t,this.pipeline=this.pipeline.toFormat(t)},i.prototype.generateIiifImage=function(i,e){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,N;return s(this,(function(s){switch(s.label){case 0:return o=(0,c.default)(e,{limitInputPixels:!1,sequentialRead:!0}),r=i.split("/"),n=r.pop(),a=n.split(".")[0],h=n.split(".")[1],l=r.pop(),p=r.pop(),u=r.pop(),[4,this.getMetadata(e)];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),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=_.height,b*z>P*B*256&&P<1e4&&B<1e4?(console.log("thumbnail"),M=Math.max(P/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=0,f.pages-2>=0&&(S=f.pages-2),console.log("selectPage: "+S),R={width:Math.round(d.width*M),height:Math.round(d.height*M)},[4,(0,c.default)(e,{limitInputPixels:!1,page:S,sequentialRead:!0}).resize(R).toBuffer()]):[3,4];case 2:return A=s.sent(),this.pipeline=(0,c.default)(A),[4,this.pipeline.metadata()];case 3:F=s.sent(),j+q>F.height&&(q=F.height-j,console.log("sh: "+q)),W+H>F.width&&(H=F.width-W,console.log("sw: "+H)),T={x:W,y:j,w:H,h:q},this.regionImpl(T),this.sizeImpl(y),console.log(F.width,F.height,R.width,R.height,T,y),s.label=4;case 4:return O=t.prototype.normalizeRotationParams.call(this,l),this.rotationImpl(O),k=t.prototype.normalizeQualityParams.call(this,a),this.qualityImpl(k),N=t.prototype.normalizeFormatParams.call(this,h),this.formatImpl(N),g.body=this.pipeline,g.contentType=t.prototype.getContentType.call(this,N),[2,g]}}))}))},i.prototype.generateImageInfo=function(i,e){var o=this.version,r=this.level,n=t.prototype.generateImageInfoTemp.call(this,i,e),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},i.prototype.getMetadata=function(t){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}).metadata()];case 1:return[2,i.sent()]}}))}))},i.prototype.normalize=function(t){return a(this,void 0,void 0,(function(){var i,e,o,r,n;return s(this,(function(a){switch(a.label){case 0:return[4,(i=(0,c.default)(t,{limitInputPixels:!1,sequentialRead:!0})).metadata()];case 1:return e=a.sent(),o=e.width.toString(),r=e.height.toString(),e&&e.orientation&&(i=i.rotate(),e.orientation>=5&&(n=o,o=r,r=n)),[4,i.tiff({pyramid:!0,tile:!0}).toBuffer()];case 2:return[2,{buffer:a.sent(),width:o,height:r}]}}))}))},i.prototype.derive=function(t,i){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}).tile({size:512,layout:"iiif"}).toFile("/tmp/".concat(i))];case 1:return e.sent(),[2]}}))}))},i}(l.default);i.default=u,t.exports=u},441:t=>{"use strict";t.exports=require("sharp")}},i={},function e(o){var r=i[o];if(void 0!==r)return r.exports;var n=i[o]={exports:{}};return t[o].call(n.exports,n,n.exports,e),n.exports}(607);var t,i}));
|
|
1
|
+
!function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i();else if("function"==typeof define&&define.amd)define([],i);else{var e=i();for(var r in e)("object"==typeof exports?exports:t)[r]=e[r]}}(global,(()=>{return t={958:t=>{var i;global,i=()=>(()=>{"use strict";var t={607:(t,i)=>{Object.defineProperty(i,"__esModule",{value:!0});var e="[1-9][0-9]*",r="[0-9]*",o="(?=.*[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(r,",").concat(r,",").concat(e,",").concat(e),"pct:".concat(n,",").concat(n,",").concat(o,",").concat(o)],rotation:"!?".concat(n),quality:["color","gray","bitonal","default","native","grey"],format:["jpg","png","webp","tif","gif"],size:[]},c={1:["full","".concat(e,","),",".concat(e),"pct:".concat(o),"".concat(e,",").concat(e),"!".concat(e,",").concat(e)],1.1:["full","".concat(e,","),",".concat(e),"pct:".concat(o),"".concat(e,",").concat(e),"!".concat(e,",").concat(e)],2:["full","".concat(e,","),",".concat(e),"pct:".concat(o),"".concat(e,",").concat(e),"!".concat(e,",").concat(e)],2.1:["full","max","".concat(e,","),",".concat(e),"pct:".concat(o),"".concat(e,",").concat(e),"!".concat(e,",").concat(e)],3:["max","".concat(e,","),",".concat(e),"pct:".concat(o),"".concat(e,",").concat(e),"!".concat(e,",").concat(e),"\\^max","\\^".concat(e,","),"\\^,".concat(e),"\\^pct:".concat(o),"\\^".concat(e,",").concat(e),"\\^!".concat(e,",").concat(e)]},l=function(){function t(t,i,e,r,o,n,a,l){void 0===r&&(r=4e6),void 0===o&&(o=2e3),void 0===n&&(n=2e3),void 0===a&&(a=512),void 0===l&&(l=512),this.version=t,this.level=i,this.maxArea=r,this.maxWidth=o,this.maxHeight=n,this.tileWidth=a,this.tileHeight=l,this.normalImageType=e,this.validate("version",t),this.validate("level",i),s.size=c[Number(t)]}return t.prototype.validator=function(t){var i=s[t];return i instanceof Array&&(i=i.join("|")),new RegExp("^("+i+")$")},t.prototype.validate=function(t,i){if(!this.validator(t).test(i))throw Error("invalid IIIF url ".concat(t,": ").concat(i));return!0},t.prototype.normalizeRegionParams=function(t,i){if(this.validate("region",t),"full"===t)return null;if("square"===t)return this._regionSquare(i);if(t.match(/^pct:([\d,]+)/))return this._regionPct(RegExp.$1,i);var e=t.split(",").map((function(t){return Number(t)}));return this._regionXYWH(e,i)},t.prototype._regionSquare=function(t){var i,e,r=t.width,o=t.height;if(r!==o){var n=Math.min(r,o),a=Math.abs(Math.floor((r-o)/2));return r>o?(i=a,e=0):(i=0,e=a),this._regionXYWH([i,e,n,n],t)}},t.prototype._regionPct=function(t,i){var e=t.split(",").map((function(t,e){var r=Number(t)/100;return 0===e||2===e?Math.round(i.width*r):1===e||3===e?Math.round(i.height*r):void 0}));return this._regionXYWH(e,i)},t.prototype._regionXYWH=function(t,i){var e=i.width,r=i.height,o=t[0],n=t[1],a=t[2],s=t[3];return o+a>e&&(a=e-o),n+s>r&&(s=r-n),{x:o,y:n,w:a,h:s}},t.prototype.normalizeSizeParams=function(t,i){var e=t,r=i.width,o=i.height;this.validate("size",e);var n,a=!1;if("^"===e.charAt(0)&&(a=!0,e=e.substring(1)),"full"===e)return null;if("max"===e?n=this._sizeMaxScale(i):e.match(/^pct:([\d]+)/)?n=this._sizePctScale(RegExp.$1):"!"===e.charAt(0)&&(e=e.substring(1),n=this._sizeBangScale(e,i)),1===n)return null;if(n){var s=Math.round(r*n),c=Math.round(o*n);return this._sizeWH("".concat(s,",").concat(c),a,i)}return this._sizeWH(e,a,i)},t.prototype._sizeBangScale=function(t,i){var e=i.width,r=i.height,o=t.split(",").map((function(t){return""===t?null:Number(t)})),n=o[0],a=o[1],s=Math.min(n/e,a/r);return n>=e&&a>=r?1:s},t.prototype._sizeMaxScale=function(t){var i=t.width,e=t.height,r=1;return this.maxArea&&this.maxArea<i*e&&(r=Math.sqrt(this.maxArea/(i*e))),this.maxWidth&&this.maxWidth<i&&(r=Math.min(r,this.maxWidth/i)),this.maxHeight&&this.maxHeight<e&&(r=Math.min(r,this.maxHeight/e)),r},t.prototype._sizePctScale=function(t){return Number(t)/100},t.prototype._sizeWH=function(t,i,e){var r=e.width,o=e.height,n=t.split(",").map((function(t){return""===t?null:Number(t)})),a=n[0],s=n[1];if(a?s||(s=Math.round(o*a/r)):a=Math.round(r*s/o),(a>r||s>o)&&!i)throw Error("should not upscale without ^");return{width:a,height:s}},t.prototype.normalizeRotationParams=function(t){this.validate("rotation",t);var i=!1;return"0"===t?null:("!"===t[0]&&(i=!0),{isMirror:i,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,i){var e={},r={};e.info=r;var o=this.version;return"1.0"===o?(r.identifier=t,r.width=i.width,r.height=i.height,r.scale_factors=this.factors(i),r.tile_width=this.tileWidth,r.tile_height=this.tileHeight,r.formats=s.format,r.qualities=s.quality,r.profile=this.uriPattern("compliance"),e.contentType="application/json",e.body=JSON.stringify(r)):("1.1"===o?(r["@context"]=this.uriPattern("context"),r["@id"]=t,r.width=i.width,r.height=i.height,r.scale_factors=this.factors(i),r.tile_width=this.tileWidth,r.tile_height=this.tileHeight,r.formats=s.format,r.qualities=s.quality,r.profile=this.uriPattern("compliance")):"2.0"===o||"2.1"===o?(r["@context"]=this.uriPattern("context"),r["@id"]=t,r.protocol="http://iiif.io/api/image",r.width=i.width,r.height=i.height,"0"===this.level?r.sizes=this.sizes(i):r.tiles=[{scaleFactors:this.factors(i),width:this.tileWidth,height:this.tileHeight}],r.profile=[this.uriPattern("compliance")]):"3.0"===o&&(r["@context"]=[this.uriPattern("context")],r.id=t,r.type="ImageService3",r.protocol="http://iiif.io/api/image",r.width=i.width,r.height=i.height,"0"===this.level?r.sizes=this.sizes(i):r.tiles=[{scaleFactors:this.factors(i),width:this.tileWidth,height:this.tileHeight}],r.profile=this.uriPattern("compliance")),e.contentType="application/ld+json"),e},t.prototype.factors=function(t){for(var i=1,e=[1],r=t.width,o=t.height;!(this.tileWidth*i>r&&this.tileHeight*i>o);)i*=2,e.push(i);return e},t.prototype.uriPattern=function(t){var i,e;return"1.0"===this.version?i="http://library.stanford.edu/iiif/image-api/compliance.html#level".concat(this.level):"1.1"===this.version?(i="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level".concat(this.level),e="http://library.stanford.edu/iiif/image-api/1.1/context.json"):"2.0"===this.version||"2.1"===this.version?(i="http://iiif.io/api/image/2/level".concat(this.level,".json"),e="http://iiif.io/api/image/2/context.json"):"3.0"===this.version&&(i="level".concat(this.level),e="http://iiif.io/api/image/3/context.json"),"compliance"===t?i:"context"===t?e: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}();i.default=l,t.exports=l}},i={};return function e(r){var o=i[r];if(void 0!==o)return o.exports;var n=i[r]={exports:{}};return t[r](n,n.exports,e),n.exports}(607)})(),t.exports=i()},607:function(t,i,e){"use strict";var r,o=this&&this.__extends||(r=function(t,i){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])},r(t,i)},function(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function e(){this.constructor=t}r(t,i),t.prototype=null===i?Object.create(i):(e.prototype=i.prototype,new e)}),n=this&&this.__assign||function(){return n=Object.assign||function(t){for(var i,e=1,r=arguments.length;e<r;e++)for(var o in i=arguments[e])Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o]);return t},n.apply(this,arguments)},a=this&&this.__awaiter||function(t,i,e,r){return new(e||(e=Promise))((function(o,n){function a(t){try{c(r.next(t))}catch(t){n(t)}}function s(t){try{c(r.throw(t))}catch(t){n(t)}}function c(t){var i;t.done?o(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(a,s)}c((r=r.apply(t,i||[])).next())}))},s=this&&this.__generator||function(t,i){var e,r,o,n,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(c){return function(s){if(e)throw new TypeError("Generator is already executing.");for(;n&&(n=0,s[0]&&(a=0)),a;)try{if(e=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=i.call(t,a)}catch(t){s=[6,t],r=0}finally{e=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},c=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(i,"__esModule",{value:!0});var l=c(e(441)),h=c(e(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 i(i,e,r,o,n,a,s,c){return void 0===o&&(o=4e6),void 0===n&&(n=2e3),void 0===a&&(a=2e3),void 0===s&&(s=512),void 0===c&&(c=512),t.call(this,i,e,r,o,n,a,s,c)||this}return o(i,t),i.prototype.regionImpl=function(t){t&&(this.pipeline=this.pipeline.extract({left:t.x,top:t.y,width:t.w,height:t.h}))},i.prototype.sizeImpl=function(t){t&&(this.pipeline=this.pipeline.resize(n(n({},t),{fit:"fill"})))},i.prototype.rotationImpl=function(t){t&&(t.isMirror&&(this.pipeline=this.pipeline.flop()),this.pipeline=this.pipeline.rotate(t.degree))},i.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()))},i.prototype.formatImpl=function(t){t="tif"===t?"tiff":t,this.pipeline=this.pipeline.toFormat(t)},i.prototype.generateIiifImage=function(i,e){return a(this,void 0,void 0,(function(){var r,o,n,a,c,h,p,u,f,d,g,y,m,v,w,x;return s(this,(function(s){switch(s.label){case 0:return r=(0,l.default)(e,{limitInputPixels:!1,sequentialRead:!0}),o=i.split("/"),n=o.pop(),a=n.split(".")[0],c=n.split(".")[1],h=o.pop(),p=o.pop(),u=o.pop(),[4,this.getMetadata(e)];case 1:return f=s.sent(),d={width:f.width,height:f.height},g={},this.pipeline=r,y=t.prototype.normalizeRegionParams.call(this,u,d),this.regionImpl(y),m=t.prototype.normalizeSizeParams.call(this,p,{width:y?y.w:d.width,height:y?y.h:d.height}),this.sizeImpl(m),v=t.prototype.normalizeRotationParams.call(this,h),this.rotationImpl(v),w=t.prototype.normalizeQualityParams.call(this,a),this.qualityImpl(w),x=t.prototype.normalizeFormatParams.call(this,c),this.formatImpl(x),g.body=this.pipeline,g.contentType=t.prototype.getContentType.call(this,x),[2,g]}}))}))},i.prototype.generateImageInfo=function(i,e){var r=this.version,o=this.level,n=t.prototype.generateImageInfoTemp.call(this,i,e),a=n.info;if(("2.0"===r||"2.1"===r)&&(a.profile=[t.prototype.uriPattern.call(this,"compliance")],"2"===o)){var s={formats:["jpg","png","webp","tif"],qualities:["color","gray","bitonal","default","native","grey"]};s.supports=p[Number(r)],a.profile.push(s)}return"3.0"===r&&(a.extraFormats=["webp"],a.preferredFormats=["webp"]),n},i.prototype.getMetadata=function(t){return a(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,(0,l.default)(t,{limitInputPixels:!1,sequentialRead:!0}).metadata()];case 1:return[2,i.sent()]}}))}))},i.prototype.normalize=function(t){return a(this,void 0,void 0,(function(){var i,e,r,o,n;return s(this,(function(a){switch(a.label){case 0:return[4,(i=(0,l.default)(t,{limitInputPixels:!1,sequentialRead:!0})).metadata()];case 1:return e=a.sent(),r=e.width.toString(),o=e.height.toString(),e&&e.orientation&&(i=i.rotate(),e.orientation>=5&&(n=r,r=o,o=n)),[4,i.tiff({pyramid:!0,tile:!0}).toBuffer()];case 2:return[2,{buffer:a.sent(),width:r,height:o}]}}))}))},i.prototype.derive=function(t,i){return a(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,(0,l.default)(t,{limitInputPixels:!1,sequentialRead:!0}).tile({size:512,layout:"iiif"}).toFile("/tmp/".concat(i))];case 1:return e.sent(),[2]}}))}))},i}(h.default);i.default=u,t.exports=u},441:t=>{"use strict";t.exports=require("sharp")}},i={},function e(r){var o=i[r];if(void 0!==o)return o.exports;var n=i[r]={exports:{}};return t[r].call(n.exports,n,n.exports,e),n.exports}(607);var t,i}));
|
package/package.json
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@etu-wiki/sharp-iiif-shims",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"clean": "rm -rf ./dist",
|
|
8
|
-
"test": "jest",
|
|
9
|
-
"build": "webpack --mode production",
|
|
10
|
-
"watch": "tsc -w",
|
|
11
|
-
"prepublishOnly": "npm run build"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"iiif",
|
|
15
|
-
"sharp"
|
|
16
|
-
],
|
|
17
|
-
"author": "Joe Song",
|
|
18
|
-
"license": "ISC",
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"@babel/core": "^7.17.10",
|
|
21
|
-
"@babel/preset-env": "^7.17.10",
|
|
22
|
-
"@babel/preset-typescript": "^7.16.7",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"webpack": "^
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@etu-wiki/sharp-iiif-shims",
|
|
3
|
+
"version": "0.0.29",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"clean": "rm -rf ./dist",
|
|
8
|
+
"test": "jest",
|
|
9
|
+
"build": "webpack --mode production",
|
|
10
|
+
"watch": "tsc -w",
|
|
11
|
+
"prepublishOnly": "npm run build"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"iiif",
|
|
15
|
+
"sharp"
|
|
16
|
+
],
|
|
17
|
+
"author": "Joe Song",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@babel/core": "^7.17.10",
|
|
21
|
+
"@babel/preset-env": "^7.17.10",
|
|
22
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
23
|
+
"babel-jest": "^28.1.0",
|
|
24
|
+
"jest": "^27.5.1",
|
|
25
|
+
"ts-loader": "^9.2.8",
|
|
26
|
+
"typescript": "^4.6.3",
|
|
27
|
+
"webpack": "^5.72.0",
|
|
28
|
+
"webpack-cli": "^4.9.2"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@etu-wiki/iiif-image-shims": "^0.0.3",
|
|
32
|
+
"sharp": "^0.32.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/index.js"
|
|
36
|
+
]
|
|
37
|
+
}
|