@etu-wiki/sharp-iiif-shims 0.0.66 → 0.0.68
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 +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var lt=Object.create;var H=Object.defineProperty;var gt=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var pt=Object.getPrototypeOf,mt=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))!mt.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(pt(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 n="[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||{}),v={version:["1.0","1.1","2.0","2.1","3.0"],level:["0","1","2"],region:["full","square",`${K},${K},${n},${n}`,`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",`${n},`,`,${n}`,`pct:${d}`,`${n},${n}`,`!${n},${n}`],1.1:["full",`${n},`,`,${n}`,`pct:${d}`,`${n},${n}`,`!${n},${n}`],2:["full",`${n},`,`,${n}`,`pct:${d}`,`${n},${n}`,`!${n},${n}`],2.1:["full","max",`${n},`,`,${n}`,`pct:${d}`,`${n},${n}`,`!${n},${n}`],3:["max",`${n},`,`,${n}`,`pct:${d}`,`${n},${n}`,`!${n},${n}`,"\\^max",`\\^${n},`,`\\^,${n}`,`\\^pct:${d}`,`\\^${n},${n}`,`\\^!${n},${n}`]},W=/^pct:([\d,]+)/,Z=class{constructor(i,r,e,t,o,a,s){this.version=i,this.level=r,this.maxArea=e,this.maxWidth=t,this.maxHeight=o,this.tileWidth=a,this.tileHeight=s,this.validate("version",i),this.validate("level",r),v.size=xt[Number(i)]}validator(i){var r=v[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 a=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,a,a],i)}return null}_regionPct(i,r){let e=i.split(",").map((t,o)=>{let a=Number(t)/100;return o===0||o===2?Math.round(r.width*a):o===1||o===3?Math.round(r.height*a):null});return this._regionXYWH(e,r)}_regionXYWH(i,r){let e=r.width,t=r.height,[o,a,s,h]=i;return o+s>e&&(s=e-o),a+h>t&&(h=t-a),{x:o,y:a,w:s,h}}normalizeSizeParams(i,r){let e=i,t=r.width,o=r.height;this.validate("size",e);let a=!1;e.charAt(0)==="^"&&(a=!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,a,r)),s===1))return null;if(s){let h=Math.round(t*s),c=Math.round(o*s);return this._sizeWH(`${h},${c}`,a,r)}else return this._sizeWH(e,a,r)}_sizeBangScale(i,r,e){let t=e.width,o=e.height,[a,s]=i.split(",").map(c=>c===""?null:Number(c)),h=Math.min(a/t,s/o);if(a>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,[a,s]=i.split(",").map(h=>h===""?null:Number(h));if(a?s||(s=Math.round(o*a/t),s=s===0?1:s):(a=Math.round(t*s/o),a=a===0?1:a),(a>t||s>o)&&!r)throw Error("should not upscale without ^");return{width:a,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=v.format,t.qualities=v.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=v.format,t.qualities=v.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:()=>b});module.exports=ft(Mt);var $=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"]},b=class extends rt.default{constructor(e,t,o=Pt,a=et,s=it,h=It,c=Ht){super(e,t,o,a,s,h,c)}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,o){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(),o==="png"&&t.toColorspace("b-w").png({colors:2})))}formatImpl(e,t,o,a){console.log("format: "+JSON.stringify(e)),o==="png"&&a["palette-bit-depth"]===1&&(t=t.png({colors:2})),e&&(t=t.toFormat(e))}iiifTransform(e,t){let o={width:t.width,height:t.height},a=(0,$.default)(),s=e.split("/"),h=s.pop(),c=h.split(".")[0],f=h.split(".")[1],B=s.pop(),_=s.pop(),S=s.pop(),l=a,g=super.normalizeRegionParams(S,o);this.regionImpl(g,l);let y=super.normalizeSizeParams(_,{width:g?g.w:o.width,height:g?g.h:o.height});this.sizeImpl(y,l);let p=super.normalizeRotationParams(B);this.rotationImpl(p,l);let m=super.normalizeQualityParams(c);this.qualityImpl(m,l,t.format);let u=super.normalizeFormatParams(f,t.format);return this.formatImpl(u,l,f,t),g||y||p||m||u?l:(console.log("skip iiif transform"),null)}async generateIiifImage(e,t,o=256){let a=(0,$.default)(t,{limitInputPixels:!1,sequentialRead:!0}),s=e.split("/"),h=s.pop(),c=h.split(".")[0],f=h.split(".")[1],B=s.pop(),_=s.pop(),S=s.pop(),l=await a.metadata(),g={width:l.width,height:l.height},y={},p=a,m=super.normalizeRegionParams(S,g);this.regionImpl(m,p);let u=super.normalizeSizeParams(_,{width:m?m.w:g.width,height:m?m.h:g.height});this.sizeImpl(u,p);let{x:ot,y:st,w:j,h:q}=m||{x:0,y:0,w:g.width,h:g.height},{width:R,height:T}=u||{width:g.width,height:g.height};if(j*q>R*T*o&&R<et&&T<it&&l.pages&&l.pages>1){console.log("thumbnail");let z=Math.max(R/j,T/q),[A,F,x,P]=[Math.round(ot*z),Math.round(st*z),Math.round(j*z),Math.round(q*z)],[D,X]=[Math.round(g.width*z),Math.round(g.height*z)],I=l.pages-1,C=await(0,$.default)(t,{limitInputPixels:!1,page:I,sequentialRead:!0}).metadata(),J=C.width,Q=C.height;for(;Q<X||J<D;)Q*=2,J*=2,I--;console.log("selectedPage: "+I);let N={width:D,height:X,fastShrinkOnLoad:!1},ht=await(0,$.default)(t,{limitInputPixels:!1,page:I,sequentialRead:!0}).resize(N).toBuffer();p=(0,$.default)(ht);let w=await p.metadata();F+P>w.height&&(P=w.height-F,console.log("adjested sh: "+P)),A+x>w.width&&(x=w.width-A,console.log("adjusted sw: "+x));let U={x:A,y:F,w:x,h:P};this.regionImpl(U,p),this.sizeImpl(u,p),console.log(w.width,w.height,N.width,N.height,U,u)}let at=super.normalizeRotationParams(B);this.rotationImpl(at,p);let nt=super.normalizeQualityParams(c);this.qualityImpl(nt,p,l.format),console.log(f,l.format);let k=super.normalizeFormatParams(f,l.format);return this.formatImpl(k,p,f,l),y.body=p,y.contentType=super.getContentType(k),y}generateImageInfo(e,t){let o=this.version,a=this.level,s=super.generateImageInfoTemp(e,t),h=s.info;if((o==="2.0"||o==="2.1")&&(h.profile=[super.uriPattern("compliance")],a==="2")){let c={};c.formats=["jpg","png","webp","jp2","pdf","tif"],c.qualities=["color","gray","bitonal","default","native","grey"],c.supports=Wt[Number(o)],h.profile.push(c)}return o==="3.0"&&(h.extraFormats=["png","webp"],h.preferredFormats=["png","webp"]),s}};module.exports=b;
|
|
1
|
+
"use strict";var lt=Object.create;var H=Object.defineProperty;var gt=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var pt=Object.getPrototypeOf,mt=Object.prototype.hasOwnProperty;var dt=(i,r)=>()=>(r||i((r={exports:{}}).exports,r),r.exports),ut=(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))!mt.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(pt(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=dt((_t,E)=>{"use strict";var L=Object.defineProperty,yt=Object.getOwnPropertyDescriptor,wt=Object.getOwnPropertyNames,zt=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 wt(r))!zt.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 n="[1-9][0-9]*",K="[0-9]*",f="(?=.*[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||{}),v={version:["1.0","1.1","2.0","2.1","3.0"],level:["0","1","2"],region:["full","square",`${K},${K},${n},${n}`,`pct:${O},${O},${f},${f}`],rotation:`!?${O}`,quality:["color","gray","bitonal","default","native","grey"],format:["jpg","png","webp","tif","gif","jp2","pdf"],size:[""]},xt={1:["full",`${n},`,`,${n}`,`pct:${f}`,`${n},${n}`,`!${n},${n}`],1.1:["full",`${n},`,`,${n}`,`pct:${f}`,`${n},${n}`,`!${n},${n}`],2:["full",`${n},`,`,${n}`,`pct:${f}`,`${n},${n}`,`!${n},${n}`],2.1:["full","max",`${n},`,`,${n}`,`pct:${f}`,`${n},${n}`,`!${n},${n}`],3:["max",`${n},`,`,${n}`,`pct:${f}`,`${n},${n}`,`!${n},${n}`,"\\^max",`\\^${n},`,`\\^,${n}`,`\\^pct:${f}`,`\\^${n},${n}`,`\\^!${n},${n}`]},W=/^pct:([\d,]+)/,Z=class{constructor(i,r,e,t,o,a,s){this.version=i,this.level=r,this.maxArea=e,this.maxWidth=t,this.maxHeight=o,this.tileWidth=a,this.tileHeight=s,this.validate("version",i),this.validate("level",r),v.size=xt[Number(i)]}validator(i){var r=v[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 a=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,a,a],i)}return null}_regionPct(i,r){let e=i.split(",").map((t,o)=>{let a=Number(t)/100;return o===0||o===2?Math.round(r.width*a):o===1||o===3?Math.round(r.height*a):null});return this._regionXYWH(e,r)}_regionXYWH(i,r){let e=r.width,t=r.height,[o,a,s,h]=i;return o+s>e&&(s=e-o),a+h>t&&(h=t-a),{x:o,y:a,w:s,h}}normalizeSizeParams(i,r){let e=i,t=r.width,o=r.height;this.validate("size",e);let a=!1;e.charAt(0)==="^"&&(a=!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,a,r)),s===1))return null;if(s){let h=Math.round(t*s),g=Math.round(o*s);return this._sizeWH(`${h},${g}`,a,r)}else return this._sizeWH(e,a,r)}_sizeBangScale(i,r,e){let t=e.width,o=e.height,[a,s]=i.split(",").map(g=>g===""?null:Number(g)),h=Math.min(a/t,s/o);if(a>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,[a,s]=i.split(",").map(h=>h===""?null:Number(h));if(a?s||(s=Math.round(o*a/t),s=s===0?1:s):(a=Math.round(t*s/o),a=a===0?1:a),(a>t||s>o)&&!r)throw Error("should not upscale without ^");return{width:a,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=v.format,t.qualities=v.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=v.format,t.qualities=v.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={};ut(Mt,{default:()=>b});module.exports=ft(Mt);var $=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"]},b=class extends rt.default{constructor(e,t,o=Pt,a=et,s=it,h=It,g=Ht){super(e,t,o,a,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,o){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(),o==="png"&&t.toColorspace("b-w").png({colors:2})))}formatImpl(e,t,o,a){console.log("format: "+JSON.stringify(e)),console.log("targetFormat: "+o),console.log("meta['palette-bit-depth']: "+a["palette-bit-depth"]),e&&(t=t.toFormat(e)),o==="png"&&a["palette-bit-depth"]===1&&(console.log("png && palette-bit-depth"),t=t.toColorspace("b-w").png({colors:2}))}iiifTransform(e,t){let o={width:t.width,height:t.height},a=(0,$.default)(),s=e.split("/"),h=s.pop(),g=h.split(".")[0],d=h.split(".")[1],B=s.pop(),_=s.pop(),S=s.pop(),c=a,l=super.normalizeRegionParams(S,o);this.regionImpl(l,c);let y=super.normalizeSizeParams(_,{width:l?l.w:o.width,height:l?l.h:o.height});this.sizeImpl(y,c);let p=super.normalizeRotationParams(B);this.rotationImpl(p,c);let m=super.normalizeQualityParams(g);this.qualityImpl(m,c,d);let u=super.normalizeFormatParams(d,t.format);return this.formatImpl(u,c,d,t),l||y||p||m||u?c:(console.log("skip iiif transform"),null)}async generateIiifImage(e,t,o=256){let a=(0,$.default)(t,{limitInputPixels:!1,sequentialRead:!0}),s=e.split("/"),h=s.pop(),g=h.split(".")[0],d=h.split(".")[1],B=s.pop(),_=s.pop(),S=s.pop(),c=await a.metadata(),l={width:c.width,height:c.height},y={},p=a,m=super.normalizeRegionParams(S,l);this.regionImpl(m,p);let u=super.normalizeSizeParams(_,{width:m?m.w:l.width,height:m?m.h:l.height});this.sizeImpl(u,p);let{x:ot,y:st,w:j,h:q}=m||{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 w=Math.max(R/j,T/q),[A,F,x,P]=[Math.round(ot*w),Math.round(st*w),Math.round(j*w),Math.round(q*w)],[D,C]=[Math.round(l.width*w),Math.round(l.height*w)],I=c.pages-1,X=await(0,$.default)(t,{limitInputPixels:!1,page:I,sequentialRead:!0}).metadata(),J=X.width,Q=X.height;for(;Q<C||J<D;)Q*=2,J*=2,I--;console.log("selectedPage: "+I);let N={width:D,height:C,fastShrinkOnLoad:!1},ht=await(0,$.default)(t,{limitInputPixels:!1,page:I,sequentialRead:!0}).resize(N).toBuffer();p=(0,$.default)(ht);let z=await p.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,p),this.sizeImpl(u,p),console.log(z.width,z.height,N.width,N.height,U,u)}let at=super.normalizeRotationParams(B);this.rotationImpl(at,p);let nt=super.normalizeQualityParams(g);this.qualityImpl(nt,p,d),console.log(d,c.format);let k=super.normalizeFormatParams(d,c.format);return this.formatImpl(k,p,d,c),y.body=p,y.contentType=super.getContentType(k),y}generateImageInfo(e,t){let o=this.version,a=this.level,s=super.generateImageInfoTemp(e,t),h=s.info;if((o==="2.0"||o==="2.1")&&(h.profile=[super.uriPattern("compliance")],a==="2")){let g={};g.formats=["jpg","png","webp","jp2","pdf","tif"],g.qualities=["color","gray","bitonal","default","native","grey"],g.supports=Wt[Number(o)],h.profile.push(g)}return o==="3.0"&&(h.extraFormats=["png","webp"],h.preferredFormats=["png","webp"]),s}};module.exports=b;
|