@frameright/image-display-control-metadata-parser
Advanced tools
Comparing version 1.2.0 to 2.0.0
@@ -8,3 +8,3 @@ 'use strict'; | ||
var ExifReader = _interopDefault(require('exifreader')); | ||
var sizeOf = _interopDefault(require('image-size')); | ||
var imageSize = require('image-size'); | ||
@@ -198,3 +198,4 @@ function _unsupportedIterableToArray(o, minLen) { | ||
} | ||
var size = sizeOf(this._buffer); | ||
var array = new Uint8Array(this._buffer); | ||
var size = imageSize.imageSize(array); | ||
this._size = { | ||
@@ -201,0 +202,0 @@ width: size.width || 0, |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("exifreader")),t=e(require("image-size"));function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,i=new Array(r);t<r;t++)i[t]=e[t];return i}var n=function(){function e(){this.id="",this.names=[],this.shape="",this.unit=""}var r=e.prototype;return r.matches=function(e,r){return this._matchesShapeFilter(e)&&this._matchesRoleFilter(r)},r._matchesShapeFilter=function(e){return"any"===e||this.shape===e},r._matchesRoleFilter=function(r){if("any"===r)return!0;if("crop"===r)for(var t,n=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return i(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,void 0):void 0}}(e))){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this.roles||[]);!(t=n()).done;)if(e._CROP_XML_ROLES.includes(t.value))return!0;return!1},e}();n._CROP_XML_ROLES=["cropping","recommended cropping","landscape format cropping","portrait format cropping","square format cropping","http://cv.iptc.org/newscodes/imageregionrole/cropping","http://cv.iptc.org/newscodes/imageregionrole/recomCropping","http://cv.iptc.org/newscodes/imageregionrole/landscapeCropping","http://cv.iptc.org/newscodes/imageregionrole/portraitCropping","http://cv.iptc.org/newscodes/imageregionrole/squareCropping"];var a=function(){function e(e){this._size=null,this._buffer=e;try{var t=r.load(this._buffer,{expanded:!0});this._xmpMetadata=t.xmp||{}}catch(e){this._xmpMetadata={}}}var i=e.prototype;return i.getIdcMetadata=function(e,r,t){var i,n=this;void 0===e&&(e="any"),void 0===r&&(r="any"),void 0===t&&(t=!0);var a=[];return Array.isArray(null==(i=this._xmpMetadata.ImageRegion)?void 0:i.value)?(this._xmpMetadata.ImageRegion.value.forEach((function(i){var o=n._xmpRegionToImageRegion(i);if(o.matches(e,r)){if(t)switch(delete o.types,delete o.roles,"relative"===o.unit&&(delete o.imageWidth,delete o.imageHeight),o.shape){case"rectangle":delete o.radius,delete o.vertices;break;case"circle":delete o.width,delete o.height,delete o.vertices;break;case"polygon":delete o.x,delete o.y,delete o.width,delete o.height,delete o.radius}a.push(o)}})),a):a},i.getXmpMetadata=function(){return this._xmpMetadata},i.getSize=function(){if(this._size)return this._size;var e=t(this._buffer);return this._size={width:e.width||0,height:e.height||0},this._size},e._xmpEntityOrConceptsToStringArray=function(r){var t=[],i=r.value;return Array.isArray(i)?i.forEach((function(r){t.push.apply(t,e._xmpEntityOrConceptToStringArray(r))})):"Bag"in i&&t.push.apply(t,e._xmpEntityOrConceptToStringArray(i.Bag.value)),t},e._xmpEntityOrConceptToStringArray=function(r){var t=[];return"Name"in r&&t.push.apply(t,e._xmpAltOrBagToStringArray(r.Name)),"Identifier"in r&&t.push.apply(t,e._xmpAltOrBagToStringArray(r.Identifier)),t},e._xmpAltOrBagToStringArray=function(e){var r=[];return Array.isArray(e.value)&&e.value.forEach((function(e){"string"==typeof e.value&&r.push(e.value)})),r},e._xmpStringToNumber=function(e){if("string"==typeof e.value)return parseFloat(e.value)},i._xmpRegionToImageRegion=function(r){var t=new n,i="rId"in r?r.rId.value:"";if("string"==typeof i&&(t.id=i),"Name"in r&&(t.names=e._xmpAltOrBagToStringArray(r.Name)),"rCtype"in r&&(t.types=e._xmpEntityOrConceptsToStringArray(r.rCtype)),"rRole"in r&&(t.roles=e._xmpEntityOrConceptsToStringArray(r.rRole)),"RegionBoundary"in r){var a=r.RegionBoundary.value;if("rbShape"in a){var o=a.rbShape.value;"string"==typeof o&&(t.shape=o)}if("rbUnit"in a){var p=a.rbUnit.value;"string"==typeof p&&(t.unit=p)}if("rbX"in a&&(t.x=e._xmpStringToNumber(a.rbX)),"rbY"in a&&(t.y=e._xmpStringToNumber(a.rbY)),"rbW"in a&&(t.width=e._xmpStringToNumber(a.rbW)),"rbH"in a&&(t.height=e._xmpStringToNumber(a.rbH)),"rbRx"in a&&(t.radius=e._xmpStringToNumber(a.rbRx)),"rbVertices"in a){var s=a.rbVertices.value;Array.isArray(s)&&s.forEach((function(r){var i,n;"rbX"in r&&(i=e._xmpStringToNumber(r.rbX)),"rbY"in r&&(n=e._xmpStringToNumber(r.rbY)),void 0!==i&&void 0!==n&&(Array.isArray(t.vertices)||(t.vertices=[]),t.vertices.push({x:i,y:n}))}))}}if("RegionDefinitionId"in r){var u=r.RegionDefinitionId.value;"string"==typeof u&&(t.idcRegionDefinitionId=u)}if("RegionName"in r){var g=r.RegionName.value;"string"==typeof g&&(t.idcRegionDefinitionName=g)}var c=this.getSize();return t.imageWidth=c.width,t.imageHeight=c.height,t},e}();exports.ImageRegion=n,exports.Parser=a; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=(e=require("exifreader"))&&"object"==typeof e&&"default"in e?e.default:e,t=require("image-size");function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,i=new Array(r);t<r;t++)i[t]=e[t];return i}var n=function(){function e(){this.id="",this.names=[],this.shape="",this.unit=""}var r=e.prototype;return r.matches=function(e,r){return this._matchesShapeFilter(e)&&this._matchesRoleFilter(r)},r._matchesShapeFilter=function(e){return"any"===e||this.shape===e},r._matchesRoleFilter=function(r){if("any"===r)return!0;if("crop"===r)for(var t,n=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return i(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,void 0):void 0}}(e))){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this.roles||[]);!(t=n()).done;)if(e._CROP_XML_ROLES.includes(t.value))return!0;return!1},e}();n._CROP_XML_ROLES=["cropping","recommended cropping","landscape format cropping","portrait format cropping","square format cropping","http://cv.iptc.org/newscodes/imageregionrole/cropping","http://cv.iptc.org/newscodes/imageregionrole/recomCropping","http://cv.iptc.org/newscodes/imageregionrole/landscapeCropping","http://cv.iptc.org/newscodes/imageregionrole/portraitCropping","http://cv.iptc.org/newscodes/imageregionrole/squareCropping"];var a=function(){function e(e){this._size=null,this._buffer=e;try{var t=r.load(this._buffer,{expanded:!0});this._xmpMetadata=t.xmp||{}}catch(e){this._xmpMetadata={}}}var i=e.prototype;return i.getIdcMetadata=function(e,r,t){var i,n=this;void 0===e&&(e="any"),void 0===r&&(r="any"),void 0===t&&(t=!0);var a=[];return Array.isArray(null==(i=this._xmpMetadata.ImageRegion)?void 0:i.value)?(this._xmpMetadata.ImageRegion.value.forEach((function(i){var o=n._xmpRegionToImageRegion(i);if(o.matches(e,r)){if(t)switch(delete o.types,delete o.roles,"relative"===o.unit&&(delete o.imageWidth,delete o.imageHeight),o.shape){case"rectangle":delete o.radius,delete o.vertices;break;case"circle":delete o.width,delete o.height,delete o.vertices;break;case"polygon":delete o.x,delete o.y,delete o.width,delete o.height,delete o.radius}a.push(o)}})),a):a},i.getXmpMetadata=function(){return this._xmpMetadata},i.getSize=function(){if(this._size)return this._size;var e=new Uint8Array(this._buffer),r=t.imageSize(e);return this._size={width:r.width||0,height:r.height||0},this._size},e._xmpEntityOrConceptsToStringArray=function(r){var t=[],i=r.value;return Array.isArray(i)?i.forEach((function(r){t.push.apply(t,e._xmpEntityOrConceptToStringArray(r))})):"Bag"in i&&t.push.apply(t,e._xmpEntityOrConceptToStringArray(i.Bag.value)),t},e._xmpEntityOrConceptToStringArray=function(r){var t=[];return"Name"in r&&t.push.apply(t,e._xmpAltOrBagToStringArray(r.Name)),"Identifier"in r&&t.push.apply(t,e._xmpAltOrBagToStringArray(r.Identifier)),t},e._xmpAltOrBagToStringArray=function(e){var r=[];return Array.isArray(e.value)&&e.value.forEach((function(e){"string"==typeof e.value&&r.push(e.value)})),r},e._xmpStringToNumber=function(e){if("string"==typeof e.value)return parseFloat(e.value)},i._xmpRegionToImageRegion=function(r){var t=new n,i="rId"in r?r.rId.value:"";if("string"==typeof i&&(t.id=i),"Name"in r&&(t.names=e._xmpAltOrBagToStringArray(r.Name)),"rCtype"in r&&(t.types=e._xmpEntityOrConceptsToStringArray(r.rCtype)),"rRole"in r&&(t.roles=e._xmpEntityOrConceptsToStringArray(r.rRole)),"RegionBoundary"in r){var a=r.RegionBoundary.value;if("rbShape"in a){var o=a.rbShape.value;"string"==typeof o&&(t.shape=o)}if("rbUnit"in a){var p=a.rbUnit.value;"string"==typeof p&&(t.unit=p)}if("rbX"in a&&(t.x=e._xmpStringToNumber(a.rbX)),"rbY"in a&&(t.y=e._xmpStringToNumber(a.rbY)),"rbW"in a&&(t.width=e._xmpStringToNumber(a.rbW)),"rbH"in a&&(t.height=e._xmpStringToNumber(a.rbH)),"rbRx"in a&&(t.radius=e._xmpStringToNumber(a.rbRx)),"rbVertices"in a){var s=a.rbVertices.value;Array.isArray(s)&&s.forEach((function(r){var i,n;"rbX"in r&&(i=e._xmpStringToNumber(r.rbX)),"rbY"in r&&(n=e._xmpStringToNumber(r.rbY)),void 0!==i&&void 0!==n&&(Array.isArray(t.vertices)||(t.vertices=[]),t.vertices.push({x:i,y:n}))}))}}if("RegionDefinitionId"in r){var u=r.RegionDefinitionId.value;"string"==typeof u&&(t.idcRegionDefinitionId=u)}if("RegionName"in r){var g=r.RegionName.value;"string"==typeof g&&(t.idcRegionDefinitionName=g)}var c=this.getSize();return t.imageWidth=c.width,t.imageHeight=c.height,t},e}();exports.ImageRegion=n,exports.Parser=a; | ||
//# sourceMappingURL=image-display-control-metadata-parser.cjs.production.min.js.map |
import ExifReader from 'exifreader'; | ||
import sizeOf from 'image-size'; | ||
import { imageSize } from 'image-size'; | ||
@@ -191,3 +191,4 @@ function _unsupportedIterableToArray(o, minLen) { | ||
} | ||
var size = sizeOf(this._buffer); | ||
var array = new Uint8Array(this._buffer); | ||
var size = imageSize(array); | ||
this._size = { | ||
@@ -194,0 +195,0 @@ width: size.width || 0, |
@@ -27,3 +27,3 @@ /// <reference types="node" /> | ||
*/ | ||
constructor(buffer: Buffer); | ||
constructor(buffer: Buffer | ArrayBuffer); | ||
/** | ||
@@ -30,0 +30,0 @@ * Returns XMP IDC metadata in a format similar to what this web-component |
@@ -18,3 +18,3 @@ { | ||
], | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"license": "MIT", | ||
@@ -62,7 +62,6 @@ "repository": "https://github.com/Frameright/image-display-control-metadata-parser", | ||
"@web/rollup-plugin-copy": "^0.5.0", | ||
"husky": "^8.0.3", | ||
"husky": "^9.0.6", | ||
"markdown-toc": "^1.2.0", | ||
"prettier": "^3.0.0", | ||
"rollup": "^3.20.7", | ||
"rollup-plugin-polyfill-node": "^0.13.0", | ||
"rollup": "^4.16.2", | ||
"rollup-plugin-summary": "^2.0.0", | ||
@@ -76,12 +75,19 @@ "tsdx": "^0.14.1", | ||
"dependencies": { | ||
"buffer": "^6.0.3", | ||
"exifreader": "^4.12.0", | ||
"image-size": "^1.0.2" | ||
"exifreader": "4.19.1", | ||
"image-size": "2.0.0-beta.2" | ||
}, | ||
"_FIXME": "most overrides are caused by tsdx not being maintained anymore. See https://github.com/Frameright/image-display-control-metadata-parser/issues/5", | ||
"overrides": { | ||
"eslint": "^8.46.0", | ||
"eslint-config-react-app": "^7.0.1", | ||
"eslint-plugin-prettier": "^5.0.0" | ||
"rollup-plugin-summary": { | ||
"rollup": "^4.16.2" | ||
}, | ||
"tsdx": { | ||
"eslint": "^8.46.0", | ||
"eslint-config-react-app": "^7.0.1", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"jsdom": "^24.0.0", | ||
"ts-jest": "^29.1.2" | ||
} | ||
} | ||
} |
@@ -143,3 +143,3 @@ [<img src="https://avatars.githubusercontent.com/u/35964478?s=200&v=4" align="right" width="64" height="64">](https://frameright.io) | ||
type="module" | ||
src="https://cdn.jsdelivr.net/npm/@frameright/image-display-control-metadata-parser@1.2.0/dist/image-display-control-metadata-parser-standalone.min.js" | ||
src="https://cdn.jsdelivr.net/npm/@frameright/image-display-control-metadata-parser@2.0.0/dist/image-display-control-metadata-parser-standalone.min.js" | ||
></script> | ||
@@ -152,4 +152,3 @@ | ||
); | ||
const arrayBuffer = await image.arrayBuffer(); | ||
const buffer = Buffer.Buffer.from(arrayBuffer); | ||
const buffer = await image.arrayBuffer(); | ||
const parser = new ImageDisplayControl.Parser(buffer); | ||
@@ -156,0 +155,0 @@ const regions = parser.getIdcMetadata(); |
import ExifReader from 'exifreader'; | ||
import sizeOf from 'image-size'; | ||
import { imageSize } from 'image-size'; | ||
import { ImageRegion, RoleFilter, ShapeFilter, Vertex } from './ImageRegion'; | ||
@@ -30,3 +30,3 @@ export { ImageRegion, RoleFilter, ShapeFilter, Vertex }; | ||
*/ | ||
constructor(buffer: Buffer) { | ||
constructor(buffer: Buffer | ArrayBuffer) { | ||
this._buffer = buffer; | ||
@@ -123,3 +123,4 @@ try { | ||
const size = sizeOf(this._buffer); | ||
const array = new Uint8Array(this._buffer); | ||
const size = imageSize(array); | ||
this._size = { | ||
@@ -331,5 +332,5 @@ width: size.width || 0, | ||
private _buffer: Buffer; | ||
private _buffer: Buffer | ArrayBuffer; | ||
private _xmpMetadata: ExifReader.XmpTags; | ||
private _size: Size | null = null; | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2
14
203850
1613
179
+ Added@xmldom/xmldom@0.8.10(transitive)
+ Addedexifreader@4.19.1(transitive)
+ Addedimage-size@2.0.0-beta.2(transitive)
- Removedbuffer@^6.0.3
- Removed@xmldom/xmldom@0.9.7(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@6.0.3(transitive)
- Removedexifreader@4.26.0(transitive)
- Removedieee754@1.2.1(transitive)
- Removedimage-size@1.2.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedqueue@6.0.2(transitive)
Updatedexifreader@4.19.1
Updatedimage-size@2.0.0-beta.2