New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@frameright/image-display-control-metadata-parser

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@frameright/image-display-control-metadata-parser - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

23

dist/image-display-control-metadata-parser.cjs.development.js

@@ -212,12 +212,23 @@ 'use strict';

bag.forEach(function (xmpEntityOrConcept) {
if ('Name' in xmpEntityOrConcept) {
result.push.apply(result, Parser._xmpAltOrBagToStringArray(xmpEntityOrConcept['Name']));
}
if ('Identifier' in xmpEntityOrConcept) {
result.push.apply(result, Parser._xmpAltOrBagToStringArray(xmpEntityOrConcept['Identifier']));
}
result.push.apply(result, Parser._xmpEntityOrConceptToStringArray(xmpEntityOrConcept));
});
} else if ('Bag' in bag) {
// happens when there is only one element in the bag
result.push.apply(result, Parser._xmpEntityOrConceptToStringArray(bag['Bag'].value));
}
return result;
}
// Converts an entity or concept to an array of strings. See
// https://iptc.org/std/photometadata/specification/IPTC-PhotoMetadata#entity-or-concept-structure
;
Parser._xmpEntityOrConceptToStringArray = function _xmpEntityOrConceptToStringArray(xmpEntityOrConcept) {
var result = [];
if ('Name' in xmpEntityOrConcept) {
result.push.apply(result, Parser._xmpAltOrBagToStringArray(xmpEntityOrConcept['Name']));
}
if ('Identifier' in xmpEntityOrConcept) {
result.push.apply(result, Parser._xmpAltOrBagToStringArray(xmpEntityOrConcept['Identifier']));
}
return result;
}
// Converts an XMP rdf:Alt or rdf:Bag tag to an array of strings.

@@ -224,0 +235,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){"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 s=a.rbUnit.value;"string"==typeof s&&(t.unit=s)}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 p=a.rbVertices.value;Array.isArray(p)&&p.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}))}))}}var u=this.getSize();return t.imageWidth=u.width,t.imageHeight=u.height,t},e}();exports.ImageRegion=n,exports.Parser=a;
"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}))}))}}var u=this.getSize();return t.imageWidth=u.width,t.imageHeight=u.height,t},e}();exports.ImageRegion=n,exports.Parser=a;
//# sourceMappingURL=image-display-control-metadata-parser.cjs.production.min.js.map

@@ -206,12 +206,23 @@ import ExifReader from 'exifreader';

bag.forEach(function (xmpEntityOrConcept) {
if ('Name' in xmpEntityOrConcept) {
result.push.apply(result, Parser._xmpAltOrBagToStringArray(xmpEntityOrConcept['Name']));
}
if ('Identifier' in xmpEntityOrConcept) {
result.push.apply(result, Parser._xmpAltOrBagToStringArray(xmpEntityOrConcept['Identifier']));
}
result.push.apply(result, Parser._xmpEntityOrConceptToStringArray(xmpEntityOrConcept));
});
} else if ('Bag' in bag) {
// happens when there is only one element in the bag
result.push.apply(result, Parser._xmpEntityOrConceptToStringArray(bag['Bag'].value));
}
return result;
}
// Converts an entity or concept to an array of strings. See
// https://iptc.org/std/photometadata/specification/IPTC-PhotoMetadata#entity-or-concept-structure
;
Parser._xmpEntityOrConceptToStringArray = function _xmpEntityOrConceptToStringArray(xmpEntityOrConcept) {
var result = [];
if ('Name' in xmpEntityOrConcept) {
result.push.apply(result, Parser._xmpAltOrBagToStringArray(xmpEntityOrConcept['Name']));
}
if ('Identifier' in xmpEntityOrConcept) {
result.push.apply(result, Parser._xmpAltOrBagToStringArray(xmpEntityOrConcept['Identifier']));
}
return result;
}
// Converts an XMP rdf:Alt or rdf:Bag tag to an array of strings.

@@ -218,0 +229,0 @@ ;

@@ -55,2 +55,3 @@ /// <reference types="node" />

private static _xmpEntityOrConceptsToStringArray;
private static _xmpEntityOrConceptToStringArray;
private static _xmpAltOrBagToStringArray;

@@ -57,0 +58,0 @@ private static _xmpStringToNumber;

@@ -18,3 +18,3 @@ {

],
"version": "1.0.3",
"version": "1.0.4",
"license": "MIT",

@@ -21,0 +21,0 @@ "author": {

@@ -81,2 +81,5 @@ [<img src="https://avatars.githubusercontent.com/u/35964478?s=200&v=4" align="right" width="64" height="64">](https://frameright.io)

> **NOTE**: a PHP equivalent of this library is available
> [here](https://github.com/Frameright/php-image-metadata-parser).
## Usage

@@ -119,3 +122,3 @@

type="module"
src="https://cdn.jsdelivr.net/npm/@frameright/image-display-control-metadata-parser@1.0.3/dist/image-display-control-metadata-parser-standalone.min.js"
src="https://cdn.jsdelivr.net/npm/@frameright/image-display-control-metadata-parser@1.0.4/dist/image-display-control-metadata-parser-standalone.min.js"
></script>

@@ -155,2 +158,5 @@

**1.0.4** (2023-05-12):
* Fixed parsing bug for image regions having only one role.
**1.0.3** (2023-04-22):

@@ -157,0 +163,0 @@ * Document how to use the browser build.

@@ -140,17 +140,14 @@ import ExifReader from 'exifreader';

bag.forEach((xmpEntityOrConcept) => {
if ('Name' in xmpEntityOrConcept) {
result.push(
...Parser._xmpAltOrBagToStringArray(
xmpEntityOrConcept['Name'] as ExifReader.XmpTag
)
);
}
if ('Identifier' in xmpEntityOrConcept) {
result.push(
...Parser._xmpAltOrBagToStringArray(
xmpEntityOrConcept['Identifier'] as ExifReader.XmpTag
)
);
}
result.push(
...Parser._xmpEntityOrConceptToStringArray(xmpEntityOrConcept)
);
});
} else if ('Bag' in bag) {
// happens when there is only one element in the bag
result.push(
...Parser._xmpEntityOrConceptToStringArray(
(bag['Bag'] as ExifReader.XmpTag).value as ExifReader.XmpTags
)
);
}

@@ -161,2 +158,27 @@

// Converts an entity or concept to an array of strings. See
// https://iptc.org/std/photometadata/specification/IPTC-PhotoMetadata#entity-or-concept-structure
private static _xmpEntityOrConceptToStringArray(
xmpEntityOrConcept: ExifReader.XmpTags
): string[] {
const result: string[] = [];
if ('Name' in xmpEntityOrConcept) {
result.push(
...Parser._xmpAltOrBagToStringArray(
xmpEntityOrConcept['Name'] as ExifReader.XmpTag
)
);
}
if ('Identifier' in xmpEntityOrConcept) {
result.push(
...Parser._xmpAltOrBagToStringArray(
xmpEntityOrConcept['Identifier'] as ExifReader.XmpTag
)
);
}
return result;
}
// Converts an XMP rdf:Alt or rdf:Bag tag to an array of strings.

@@ -163,0 +185,0 @@ private static _xmpAltOrBagToStringArray(

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc