@etu-wiki/sharp-iiif-shims 0.0.54 → 0.0.56

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.d.ts CHANGED
@@ -5,7 +5,6 @@ type Dims = {
5
5
  height: number;
6
6
  };
7
7
  export default class SharpIiifImageShims extends IiifImageShims {
8
- pipeline: sharp.Sharp;
9
8
  version: string;
10
9
  level: string;
11
10
  tileWidth: number;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var lt=Object.create;var B=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var pt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,ct=Object.prototype.hasOwnProperty;var ut=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),mt=(i,e)=>{for(var t in e)B(i,t,{get:e[t],enumerable:!0})},G=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of pt(e))!ct.call(i,s)&&s!==t&&B(i,s,{get:()=>e[s],enumerable:!(r=ht(e,s))||r.enumerable});return i};var K=(i,e,t)=>(t=i!=null?lt(gt(i)):{},G(e||!i||!i.__esModule?B(t,"default",{value:i,enumerable:!0}):t,i)),dt=i=>G(B({},"__esModule",{value:!0}),i);var it=ut((Bt,E)=>{"use strict";var L=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,yt=Object.getOwnPropertyNames,zt=Object.prototype.hasOwnProperty,wt=(i,e)=>{for(var t in e)L(i,t,{get:e[t],enumerable:!0})},vt=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of yt(e))!zt.call(i,s)&&s!==t&&L(i,s,{get:()=>e[s],enumerable:!(r=ft(e,s))||r.enumerable});return i},$t=i=>vt(L({},"__esModule",{value:!0}),i),Z={};wt(Z,{default:()=>tt});E.exports=$t(Z);var o="[1-9][0-9]*",V="[0-9]*",m="(?=.*[1-9])\\d+(\\.\\d+)?",O="\\d+(\\.\\d+)?",j=(i=>(i.jpg="image/jpeg",i.jpeg="image/jpeg",i.png="image/png",i.webp="image/webp",i.tif="image/tiff",i.tiff="image/tiff",i.gif="image/gif",i.jp2="image/jp2",i.pdf="application/pdf",i))(j||{}),z={version:["1.0","1.1","2.0","2.1","3.0"],level:["0","1","2"],region:["full","square",`${V},${V},${o},${o}`,`pct:${O},${O},${m},${m}`],rotation:`!?${O}`,quality:["color","gray","bitonal","default","native","grey"],format:["jpg","png","webp","tif","gif","jp2","pdf"],size:[""]},bt={1:["full",`${o},`,`,${o}`,`pct:${m}`,`${o},${o}`,`!${o},${o}`],1.1:["full",`${o},`,`,${o}`,`pct:${m}`,`${o},${o}`,`!${o},${o}`],2:["full",`${o},`,`,${o}`,`pct:${m}`,`${o},${o}`,`!${o},${o}`],2.1:["full","max",`${o},`,`,${o}`,`pct:${m}`,`${o},${o}`,`!${o},${o}`],3:["max",`${o},`,`,${o}`,`pct:${m}`,`${o},${o}`,`!${o},${o}`,"\\^max",`\\^${o},`,`\\^,${o}`,`\\^pct:${m}`,`\\^${o},${o}`,`\\^!${o},${o}`]},_=/^pct:([\d,]+)/,tt=class{constructor(i,e,t,r,s,a,n){this.version=i,this.level=e,this.maxArea=t,this.maxWidth=r,this.maxHeight=s,this.tileWidth=a,this.tileHeight=n,this.validate("version",i),this.validate("level",e),z.size=bt[Number(i)]}validator(i){var e=z[i];return e instanceof Array&&(e=e.join("|")),new RegExp("^("+e+")$")}validate(i,e){if(!this.validator(i).test(e))throw Error(`invalid IIIF url ${i}: ${e}`);return!0}normalizeRegionParams(i,e){if(this.validate("region",i),i==="full")return null;if(i==="square")return this._regionSquare(e);if(_.test(i))return this._regionPct(i.match(_)[1],e);{let t=i.split(",").map(r=>Number(r));return this._regionXYWH(t,e)}}_regionSquare(i){let e,t,r=i.width,s=i.height;if(r!==s){let a=Math.min(r,s),n=Math.abs(Math.floor((r-s)/2));return r>s?(e=n,t=0):(e=0,t=n),this._regionXYWH([e,t,a,a],i)}return null}_regionPct(i,e){let t=i.split(",").map((r,s)=>{let a=Number(r)/100;return s===0||s===2?Math.round(e.width*a):s===1||s===3?Math.round(e.height*a):null});return this._regionXYWH(t,e)}_regionXYWH(i,e){let t=e.width,r=e.height,[s,a,n,l]=i;return s+n>t&&(n=t-s),a+l>r&&(l=r-a),{x:s,y:a,w:n,h:l}}normalizeSizeParams(i,e){let t=i,r=e.width,s=e.height;this.validate("size",t);let a=!1;t.charAt(0)==="^"&&(a=!0,t=t.substring(1));let n=null;if(t==="full"||(t==="max"?n=this._sizeMaxScale(e):_.test(t)?n=this._sizePctScale(t.match(_)[1]):t.charAt(0)==="!"&&(t=t.substring(1),n=this._sizeBangScale(t,a,e)),n===1))return null;if(n){let l=Math.round(r*n),h=Math.round(s*n);return this._sizeWH(`${l},${h}`,a,e)}else return this._sizeWH(t,a,e)}_sizeBangScale(i,e,t){let r=t.width,s=t.height,[a,n]=i.split(",").map(h=>h===""?null:Number(h)),l=Math.min(a/r,n/s);if(a>r&&n>s&&!e)throw Error("should not upscale without ^");return l}_sizeMaxScale(i){let e=i.width,t=i.height,r=1;return this.maxArea&&this.maxArea<e*t&&(r=Math.sqrt(this.maxArea/(e*t))),this.maxWidth&&this.maxWidth<e&&(r=Math.min(r,this.maxWidth/e)),this.maxHeight&&this.maxHeight<t&&(r=Math.min(r,this.maxHeight/t)),r}_sizePctScale(i){return Number(i)/100}_sizeWH(i,e,t){let r=t.width,s=t.height,[a,n]=i.split(",").map(l=>l===""?null:Number(l));if(a?n||(n=Math.round(s*a/r)):a=Math.round(r*n/s),(a>r||n>s)&&!e)throw Error("should not upscale without ^");return{width:a,height:n}}normalizeRotationParams(i){this.validate("rotation",i);let e=!1;if(i==="0")return null;i[0]==="!"&&(e=!0);let t=Number(i.replace(/^!/,""));return{isMirror:e,degree:t}}normalizeQualityParams(i){return this.validate("quality",i),i==="native"||i==="default"?null:i}normalizeFormatParams(i,e){if((this.version==="1.0"||this.version==="1.1"||this.version==="2.0"||this.version==="2.1")&&!i)return"png";this.validate("format",i);let t=j[i],r=j[e];return t===r?null:i}getContentType(i){return j[i]}generateImageInfoTemp(i,e){let t={},r={};t.info=r;let s=this.version;return s==="1.0"?(r.identifier=i,r.width=e.width,r.height=e.height,r.scale_factors=this.factors(e),r.tile_width=this.tileWidth,r.tile_height=this.tileHeight,r.formats=z.format,r.qualities=z.quality,r.profile=this.uriPattern("compliance"),t.contentType="application/json",t.body=JSON.stringify(r)):(s==="1.1"?(r["@context"]=this.uriPattern("context"),r["@id"]=i,r.width=e.width,r.height=e.height,r.scale_factors=this.factors(e),r.tile_width=this.tileWidth,r.tile_height=this.tileHeight,r.formats=z.format,r.qualities=z.quality,r.profile=this.uriPattern("compliance")):s==="2.0"||s==="2.1"?(r["@context"]=this.uriPattern("context"),r["@id"]=i,r.protocol="http://iiif.io/api/image",r.width=e.width,r.height=e.height,this.level==="0"?r.sizes=this.sizes(e):r.tiles=[{scaleFactors:this.factors(e),width:this.tileWidth,height:this.tileHeight}],r.profile=[this.uriPattern("compliance")]):s==="3.0"&&(r["@context"]=[this.uriPattern("context")],r.id=i,r.type="ImageService3",r.protocol="http://iiif.io/api/image",r.width=e.width,r.height=e.height,this.level==="0"?r.sizes=this.sizes(e):r.tiles=[{scaleFactors:this.factors(e),width:this.tileWidth,height:this.tileHeight}],r.profile=this.uriPattern("compliance")),t.contentType="application/ld+json"),t}factors(i){let e=1,t=[1],r=i.width,s=i.height;for(;!(this.tileWidth*e>r&&this.tileHeight*e>s);)e*=2,t.push(e);return t}uriPattern(i){let e="",t="";return this.version==="1.0"?e=`http://library.stanford.edu/iiif/image-api/compliance.html#level${this.level}`:this.version==="1.1"?(e=`http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level${this.level}`,t="http://library.stanford.edu/iiif/image-api/1.1/context.json"):this.version==="2.0"||this.version==="2.1"?(e=`http://iiif.io/api/image/2/level${this.level}.json`,t="http://iiif.io/api/image/2/context.json"):this.version==="3.0"&&(e=`level${this.level}`,t="http://iiif.io/api/image/3/context.json"),i==="compliance"?e:i==="context"?t:""}sizes(i){return[{width:i.width,height:i.height}]}};E.exports=tt});var Wt={};mt(Wt,{default:()=>b});module.exports=dt(Wt);var w=K(require("sharp")),st=K(it()),xt=1e8,et=1e4,rt=1e4,Pt=512,It=512,Ht={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"]},b=class extends st.default{constructor(t,r,s=xt,a=et,n=rt,l=Pt,h=It){super(t,r,s,a,n,l,h)}regionImpl(t){console.log("region: "+JSON.stringify(t)),t&&(this.pipeline=this.pipeline.extract({left:t.x,top:t.y,width:t.w,height:t.h}))}sizeImpl(t){console.log("size: "+JSON.stringify(t)),t&&(this.pipeline=this.pipeline.resize({...t,fit:"fill"}))}rotationImpl(t){console.log("rotation: "+JSON.stringify(t)),t&&(t.isMirror&&(this.pipeline=this.pipeline.flop()),this.pipeline=this.pipeline.rotate(t.degree))}qualityImpl(t){console.log("quality: "+JSON.stringify(t)),t&&(t==="color"?this.pipeline=this.pipeline.toColorspace("srgb"):t==="gray"||t==="grey"?this.pipeline=this.pipeline.grayscale():t==="bitonal"&&(this.pipeline=this.pipeline.threshold()))}formatImpl(t){console.log("format: "+JSON.stringify(t)),t&&(this.pipeline=this.pipeline.toFormat(t))}iiifTransform(t,r){let s={width:r.width,height:r.height},a=(0,w.default)(),n=t.split("/"),l=n.pop(),h=l.split(".")[0],S=l.split(".")[1],q=n.pop(),R=n.pop(),x=n.pop();this.pipeline=a;let p=super.normalizeRegionParams(x,s);this.regionImpl(p);let g=super.normalizeSizeParams(R,{width:p?p.w:s.width,height:p?p.h:s.height});this.sizeImpl(g);let f=super.normalizeRotationParams(q);this.rotationImpl(f);let c=super.normalizeQualityParams(h);this.qualityImpl(c);let u=super.normalizeFormatParams(S,r.format);return this.formatImpl(u),p||g||f||c||u?this.pipeline:null}async generateIiifImage(t,r,s=256){let a=(0,w.default)(r,{limitInputPixels:!1,sequentialRead:!0}),n=t.split("/"),l=n.pop(),h=l.split(".")[0],S=l.split(".")[1],q=n.pop(),R=n.pop(),x=n.pop(),p=await a.metadata(),g={width:p.width,height:p.height},f={};this.pipeline=a;let c=super.normalizeRegionParams(x,g);this.regionImpl(c);let u=super.normalizeSizeParams(R,{width:c?c.w:g.width,height:c?c.h:g.height});this.sizeImpl(u);let{x:D,y:k,w:P,h:I}=c||{x:0,y:0,w:g.width,h:g.height},{width:T,height:A}=u||{width:g.width,height:g.height};if(P*I>T*A*s&&T<et&&A<rt&&p.pages&&p.pages>1){console.log("thumbnail"),console.log(D,k,P,I);let y=Math.max(T/P,A/I),[H,W,v,$]=[Math.round(D*y),Math.round(k*y),Math.round(P*y),Math.round(I*y)],[J,C]=[Math.round(g.width*y),Math.round(g.height*y)];console.log(H,W,v,$),console.log(p.pages);let M=p.pages-1,N=await(0,w.default)(r,{limitInputPixels:!1,page:M,sequentialRead:!0}).metadata();console.log(N);let Q=N.width,U=N.height;for(;U<C||Q<J;)U*=2,Q*=2,M--;console.log("selectedPage: "+M);let F={width:J,height:C,fastShrinkOnLoad:!1},at=await(0,w.default)(r,{limitInputPixels:!1,page:M,sequentialRead:!0}).resize(F).toBuffer();this.pipeline=(0,w.default)(at,{sequentialRead:!0});let d=await this.pipeline.metadata();console.log(d),W+$>d.height&&($=d.height-W,console.log("adjested sh: "+$)),H+v>d.width&&(v=d.width-H,console.log("adjusted sw: "+v));let Y=x==="full"?null:{x:H,y:W,w:v,h:$};this.regionImpl(Y),this.sizeImpl(u),console.log(d.width,d.height,F.width,F.height,Y,u)}let nt=super.normalizeRotationParams(q);this.rotationImpl(nt);let ot=super.normalizeQualityParams(h);this.qualityImpl(ot);let X=super.normalizeFormatParams(S,p.format);return this.formatImpl(X),f.body=this.pipeline,f.contentType=super.getContentType(X),f}generateImageInfo(t,r){let s=this.version,a=this.level,n=super.generateImageInfoTemp(t,r),l=n.info;if((s==="2.0"||s==="2.1")&&(l.profile=[super.uriPattern("compliance")],a==="2")){let h={};h.formats=["jpg","png","webp","tif","jp2","pdf"],h.qualities=["color","gray","bitonal","default","native","grey"],h.supports=Ht[Number(s)],l.profile.push(h)}return s==="3.0"&&(l.extraFormats=["webp"],l.preferredFormats=["webp"]),n}};module.exports=b;
1
+ "use strict";var lt=Object.create;var H=Object.defineProperty;var gt=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var mt=Object.getPrototypeOf,pt=Object.prototype.hasOwnProperty;var ut=(i,r)=>()=>(r||i((r={exports:{}}).exports,r),r.exports),dt=(i,r)=>{for(var e in r)H(i,e,{get:r[e],enumerable:!0})},Y=(i,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of ct(r))!pt.call(i,o)&&o!==e&&H(i,o,{get:()=>r[o],enumerable:!(t=gt(r,o))||t.enumerable});return i};var G=(i,r,e)=>(e=i!=null?lt(mt(i)):{},Y(r||!i||!i.__esModule?H(e,"default",{value:i,enumerable:!0}):e,i)),ft=i=>Y(H({},"__esModule",{value:!0}),i);var tt=ut((_t,E)=>{"use strict";var L=Object.defineProperty,yt=Object.getOwnPropertyDescriptor,zt=Object.getOwnPropertyNames,wt=Object.prototype.hasOwnProperty,vt=(i,r)=>{for(var e in r)L(i,e,{get:r[e],enumerable:!0})},$t=(i,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of zt(r))!wt.call(i,o)&&o!==e&&L(i,o,{get:()=>r[o],enumerable:!(t=yt(r,o))||t.enumerable});return i},bt=i=>$t(L({},"__esModule",{value:!0}),i),V={};vt(V,{default:()=>Z});E.exports=bt(V);var a="[1-9][0-9]*",K="[0-9]*",d="(?=.*[1-9])\\d+(\\.\\d+)?",O="\\d+(\\.\\d+)?",M=(i=>(i.jpg="image/jpeg",i.jpeg="image/jpeg",i.png="image/png",i.webp="image/webp",i.tif="image/tiff",i.tiff="image/tiff",i.gif="image/gif",i.jp2="image/jp2",i.pdf="application/pdf",i))(M||{}),w={version:["1.0","1.1","2.0","2.1","3.0"],level:["0","1","2"],region:["full","square",`${K},${K},${a},${a}`,`pct:${O},${O},${d},${d}`],rotation:`!?${O}`,quality:["color","gray","bitonal","default","native","grey"],format:["jpg","png","webp","tif","gif","jp2","pdf"],size:[""]},xt={1:["full",`${a},`,`,${a}`,`pct:${d}`,`${a},${a}`,`!${a},${a}`],1.1:["full",`${a},`,`,${a}`,`pct:${d}`,`${a},${a}`,`!${a},${a}`],2:["full",`${a},`,`,${a}`,`pct:${d}`,`${a},${a}`,`!${a},${a}`],2.1:["full","max",`${a},`,`,${a}`,`pct:${d}`,`${a},${a}`,`!${a},${a}`],3:["max",`${a},`,`,${a}`,`pct:${d}`,`${a},${a}`,`!${a},${a}`,"\\^max",`\\^${a},`,`\\^,${a}`,`\\^pct:${d}`,`\\^${a},${a}`,`\\^!${a},${a}`]},W=/^pct:([\d,]+)/,Z=class{constructor(i,r,e,t,o,n,s){this.version=i,this.level=r,this.maxArea=e,this.maxWidth=t,this.maxHeight=o,this.tileWidth=n,this.tileHeight=s,this.validate("version",i),this.validate("level",r),w.size=xt[Number(i)]}validator(i){var r=w[i];return r instanceof Array&&(r=r.join("|")),new RegExp("^("+r+")$")}validate(i,r){if(!this.validator(i).test(r))throw Error(`invalid IIIF url ${i}: ${r}`);return!0}normalizeRegionParams(i,r){if(this.validate("region",i),i==="full")return null;if(i==="square")return this._regionSquare(r);if(W.test(i))return this._regionPct(i.match(W)[1],r);{let e=i.split(",").map(t=>Number(t));return this._regionXYWH(e,r)}}_regionSquare(i){let r,e,t=i.width,o=i.height;if(t!==o){let n=Math.min(t,o),s=Math.abs(Math.floor((t-o)/2));return t>o?(r=s,e=0):(r=0,e=s),this._regionXYWH([r,e,n,n],i)}return null}_regionPct(i,r){let e=i.split(",").map((t,o)=>{let n=Number(t)/100;return o===0||o===2?Math.round(r.width*n):o===1||o===3?Math.round(r.height*n):null});return this._regionXYWH(e,r)}_regionXYWH(i,r){let e=r.width,t=r.height,[o,n,s,h]=i;return o+s>e&&(s=e-o),n+h>t&&(h=t-n),{x:o,y:n,w:s,h}}normalizeSizeParams(i,r){let e=i,t=r.width,o=r.height;this.validate("size",e);let n=!1;e.charAt(0)==="^"&&(n=!0,e=e.substring(1));let s=null;if(e==="full"||(e==="max"?s=this._sizeMaxScale(r):W.test(e)?s=this._sizePctScale(e.match(W)[1]):e.charAt(0)==="!"&&(e=e.substring(1),s=this._sizeBangScale(e,n,r)),s===1))return null;if(s){let h=Math.round(t*s),g=Math.round(o*s);return this._sizeWH(`${h},${g}`,n,r)}else return this._sizeWH(e,n,r)}_sizeBangScale(i,r,e){let t=e.width,o=e.height,[n,s]=i.split(",").map(g=>g===""?null:Number(g)),h=Math.min(n/t,s/o);if(n>t&&s>o&&!r)throw Error("should not upscale without ^");return h}_sizeMaxScale(i){let r=i.width,e=i.height,t=1;return this.maxArea&&this.maxArea<r*e&&(t=Math.sqrt(this.maxArea/(r*e))),this.maxWidth&&this.maxWidth<r&&(t=Math.min(t,this.maxWidth/r)),this.maxHeight&&this.maxHeight<e&&(t=Math.min(t,this.maxHeight/e)),t}_sizePctScale(i){return Number(i)/100}_sizeWH(i,r,e){let t=e.width,o=e.height,[n,s]=i.split(",").map(h=>h===""?null:Number(h));if(n?s||(s=Math.round(o*n/t)):n=Math.round(t*s/o),(n>t||s>o)&&!r)throw Error("should not upscale without ^");return{width:n,height:s}}normalizeRotationParams(i){this.validate("rotation",i);let r=!1;if(i==="0")return null;i[0]==="!"&&(r=!0);let e=Number(i.replace(/^!/,""));return{isMirror:r,degree:e}}normalizeQualityParams(i){return this.validate("quality",i),i==="native"||i==="default"?null:i}normalizeFormatParams(i,r){if((this.version==="1.0"||this.version==="1.1"||this.version==="2.0"||this.version==="2.1")&&!i)return"png";this.validate("format",i);let e=M[i],t=M[r];return e===t?null:i}getContentType(i){return M[i]}generateImageInfoTemp(i,r){let e={},t={};e.info=t;let o=this.version;return o==="1.0"?(t.identifier=i,t.width=r.width,t.height=r.height,t.scale_factors=this.factors(r),t.tile_width=this.tileWidth,t.tile_height=this.tileHeight,t.formats=w.format,t.qualities=w.quality,t.profile=this.uriPattern("compliance"),e.contentType="application/json",e.body=JSON.stringify(t)):(o==="1.1"?(t["@context"]=this.uriPattern("context"),t["@id"]=i,t.width=r.width,t.height=r.height,t.scale_factors=this.factors(r),t.tile_width=this.tileWidth,t.tile_height=this.tileHeight,t.formats=w.format,t.qualities=w.quality,t.profile=this.uriPattern("compliance")):o==="2.0"||o==="2.1"?(t["@context"]=this.uriPattern("context"),t["@id"]=i,t.protocol="http://iiif.io/api/image",t.width=r.width,t.height=r.height,this.level==="0"?t.sizes=this.sizes(r):t.tiles=[{scaleFactors:this.factors(r),width:this.tileWidth,height:this.tileHeight}],t.profile=[this.uriPattern("compliance")]):o==="3.0"&&(t["@context"]=[this.uriPattern("context")],t.id=i,t.type="ImageService3",t.protocol="http://iiif.io/api/image",t.width=r.width,t.height=r.height,this.level==="0"?t.sizes=this.sizes(r):t.tiles=[{scaleFactors:this.factors(r),width:this.tileWidth,height:this.tileHeight}],t.profile=this.uriPattern("compliance")),e.contentType="application/ld+json"),e}factors(i){let r=1,e=[1],t=i.width,o=i.height;for(;!(this.tileWidth*r>t&&this.tileHeight*r>o);)r*=2,e.push(r);return e}uriPattern(i){let r="",e="";return this.version==="1.0"?r=`http://library.stanford.edu/iiif/image-api/compliance.html#level${this.level}`:this.version==="1.1"?(r=`http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level${this.level}`,e="http://library.stanford.edu/iiif/image-api/1.1/context.json"):this.version==="2.0"||this.version==="2.1"?(r=`http://iiif.io/api/image/2/level${this.level}.json`,e="http://iiif.io/api/image/2/context.json"):this.version==="3.0"&&(r=`level${this.level}`,e="http://iiif.io/api/image/3/context.json"),i==="compliance"?r:i==="context"?e:""}sizes(i){return[{width:i.width,height:i.height}]}};E.exports=Z});var Mt={};dt(Mt,{default:()=>$});module.exports=ft(Mt);var v=G(require("sharp")),rt=G(tt()),Pt=1e8,et=1e4,it=1e4,It=512,Ht=512,Wt={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"]},$=class extends rt.default{constructor(e,t,o=Pt,n=et,s=it,h=It,g=Ht){super(e,t,o,n,s,h,g)}regionImpl(e,t){console.log("region: "+JSON.stringify(e)),e&&(t=t.extract({left:e.x,top:e.y,width:e.w,height:e.h}))}sizeImpl(e,t){console.log("size: "+JSON.stringify(e)),e&&(t=t.resize({...e,fit:"fill"}))}rotationImpl(e,t){console.log("rotation: "+JSON.stringify(e)),e&&(e.isMirror&&(t=t.flop()),t=t.rotate(e.degree))}qualityImpl(e,t){console.log("quality: "+JSON.stringify(e)),e&&(e==="color"?t=t.toColorspace("srgb"):e==="gray"||e==="grey"?t=t.grayscale():e==="bitonal"&&(t=t.threshold()))}formatImpl(e,t){console.log("format: "+JSON.stringify(e)),e&&(t=t.toFormat(e))}iiifTransform(e,t){let o={width:t.width,height:t.height},n=(0,v.default)(),s=e.split("/"),h=s.pop(),g=h.split(".")[0],b=h.split(".")[1],B=s.pop(),_=s.pop(),S=s.pop(),c=n,l=super.normalizeRegionParams(S,o);this.regionImpl(l,c);let f=super.normalizeSizeParams(_,{width:l?l.w:o.width,height:l?l.h:o.height});this.sizeImpl(f,c);let m=super.normalizeRotationParams(B);this.rotationImpl(m,c);let p=super.normalizeQualityParams(g);this.qualityImpl(p,c);let u=super.normalizeFormatParams(b,t.format);return this.formatImpl(u,c),l||f||m||p||u?c:(console.log("skip iiif transform"),null)}async generateIiifImage(e,t,o=256){let n=(0,v.default)(t,{limitInputPixels:!1,sequentialRead:!0}),s=e.split("/"),h=s.pop(),g=h.split(".")[0],b=h.split(".")[1],B=s.pop(),_=s.pop(),S=s.pop(),c=await n.metadata(),l={width:c.width,height:c.height},f={},m=n,p=super.normalizeRegionParams(S,l);this.regionImpl(p,m);let u=super.normalizeSizeParams(_,{width:p?p.w:l.width,height:p?p.h:l.height});this.sizeImpl(u,m);let{x:ot,y:st,w:j,h:q}=p||{x:0,y:0,w:l.width,h:l.height},{width:R,height:T}=u||{width:l.width,height:l.height};if(j*q>R*T*o&&R<et&&T<it&&c.pages&&c.pages>1){console.log("thumbnail");let y=Math.max(R/j,T/q),[A,F,x,P]=[Math.round(ot*y),Math.round(st*y),Math.round(j*y),Math.round(q*y)],[D,X]=[Math.round(l.width*y),Math.round(l.height*y)],I=c.pages-1,J=await(0,v.default)(t,{limitInputPixels:!1,page:I,sequentialRead:!0}).metadata(),C=J.width,Q=J.height;for(;Q<X||C<D;)Q*=2,C*=2,I--;console.log("selectedPage: "+I);let N={width:D,height:X,fastShrinkOnLoad:!1},ht=await(0,v.default)(t,{limitInputPixels:!1,page:I,sequentialRead:!0}).resize(N).toBuffer();m=(0,v.default)(ht);let z=await m.metadata();F+P>z.height&&(P=z.height-F,console.log("adjested sh: "+P)),A+x>z.width&&(x=z.width-A,console.log("adjusted sw: "+x));let U={x:A,y:F,w:x,h:P};this.regionImpl(U,m),this.sizeImpl(u,m),console.log(z.width,z.height,N.width,N.height,U,u)}let at=super.normalizeRotationParams(B);this.rotationImpl(at,m);let nt=super.normalizeQualityParams(g);this.qualityImpl(nt,m),console.log(b,c.format);let k=super.normalizeFormatParams(b,c.format);return this.formatImpl(k,m),f.body=m,f.contentType=super.getContentType(k),f}generateImageInfo(e,t){let o=this.version,n=this.level,s=super.generateImageInfoTemp(e,t),h=s.info;if((o==="2.0"||o==="2.1")&&(h.profile=[super.uriPattern("compliance")],n==="2")){let g={};g.formats=["jpg","png","webp","tif","jp2","pdf"],g.qualities=["color","gray","bitonal","default","native","grey"],g.supports=Wt[Number(o)],h.profile.push(g)}return o==="3.0"&&(h.extraFormats=["webp"],h.preferredFormats=["webp"]),s}};module.exports=$;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etu-wiki/sharp-iiif-shims",
3
- "version": "0.0.54",
3
+ "version": "0.0.56",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {