@dicebear/converter 9.2.1 → 9.2.3

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/lib/node/core.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { promises as fs } from 'node:fs';
2
2
  import { getMimeType } from '../utils/mime-type.js';
3
- import { ensureSize } from '../utils/svg.js';
3
+ import { ensureSize, getMetadata } from '../utils/svg.js';
4
4
  import * as tmp from 'tmp-promise';
5
5
  import { renderAsync } from '@resvg/resvg-js';
6
6
  import sharp from 'sharp';
@@ -65,31 +65,27 @@ async function toBuffer(rawSvg, format, exif, options) {
65
65
  // https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata
66
66
  // https://developers.google.com/search/docs/appearance/structured-data/image-license-metadata
67
67
  function getExif(svg) {
68
+ const metadata = getMetadata(svg);
68
69
  const exif = {};
69
- const sourceName = svg.match(/<dc:title[^>]*>(.*?)<\/dc:title>/s);
70
- const sourceUrl = svg.match(/<dc:source[^>]*>(.*?)<\/dc:source>/s);
71
- const creatorName = svg.match(/<dc:creator[^>]*>(.*?)<\/dc:creator>/s);
72
- const licenseUrl = svg.match(/<dcterms:license[^>]*>(.*?)<\/dcterms:license>/s);
73
- const copyright = svg.match(/<dc:rights[^>]*>(.*?)<\/dc:rights>/s);
74
- if (sourceName) {
75
- exif['IPTC:ObjectName'] = sourceName[1];
76
- exif['XMP-dc:Title'] = sourceName[1];
70
+ if (metadata.title) {
71
+ exif['IPTC:ObjectName'] = metadata.title;
72
+ exif['XMP-dc:Title'] = metadata.title;
77
73
  }
78
- if (sourceUrl) {
79
- exif['XMP-plus:LicensorURL'] = sourceUrl[1];
74
+ if (metadata.source) {
75
+ exif['XMP-plus:LicensorURL'] = metadata.source;
80
76
  }
81
- if (creatorName) {
82
- exif['IPTC:By-line'] = creatorName[1];
83
- exif['XMP-dc:Creator'] = creatorName[1];
84
- exif['IPTC:Credit'] = creatorName[1];
85
- exif['XMP-photoshop:Credit'] = creatorName[1];
77
+ if (metadata.creator) {
78
+ exif['IPTC:By-line'] = metadata.creator;
79
+ exif['XMP-dc:Creator'] = metadata.creator;
80
+ exif['IPTC:Credit'] = metadata.creator;
81
+ exif['XMP-photoshop:Credit'] = metadata.creator;
86
82
  }
87
- if (licenseUrl) {
88
- exif['XMP-xmpRights:WebStatement'] = licenseUrl[1];
83
+ if (metadata.license) {
84
+ exif['XMP-xmpRights:WebStatement'] = metadata.license;
89
85
  }
90
- if (copyright) {
91
- exif['IPTC:CopyrightNotice'] = copyright[1];
92
- exif['XMP-dc:Rights'] = copyright[1];
86
+ if (metadata.copyright) {
87
+ exif['IPTC:CopyrightNotice'] = metadata.copyright;
88
+ exif['XMP-dc:Rights'] = metadata.copyright;
93
89
  }
94
90
  return exif;
95
91
  }
package/lib/types.d.ts CHANGED
@@ -16,3 +16,10 @@ export interface Options {
16
16
  fonts?: string[];
17
17
  includeExif?: boolean;
18
18
  }
19
+ export interface Metadata {
20
+ title?: string;
21
+ source?: string;
22
+ creator?: string;
23
+ license?: string;
24
+ copyright?: string;
25
+ }
@@ -1,4 +1,6 @@
1
+ import { Metadata } from '../types';
1
2
  export declare function ensureSize(svg: string, defaultSize?: number): {
2
3
  svg: string;
3
4
  size: number;
4
5
  };
6
+ export declare function getMetadata(svg: string): Metadata;
package/lib/utils/svg.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { XMLParser } from 'fast-xml-parser';
1
2
  export function ensureSize(svg, defaultSize = 512) {
2
3
  let size = defaultSize;
3
4
  svg = svg.replace(/<svg([^>]*)/, (match, g1) => {
@@ -21,3 +22,16 @@ export function ensureSize(svg, defaultSize = 512) {
21
22
  });
22
23
  return { svg, size };
23
24
  }
25
+ export function getMetadata(svg) {
26
+ var _a, _b;
27
+ const parser = new XMLParser();
28
+ const xml = parser.parse(svg);
29
+ const rdfDescription = (_b = (_a = xml.svg.metadata) === null || _a === void 0 ? void 0 : _a['rdf:RDF']) === null || _b === void 0 ? void 0 : _b['rdf:Description'];
30
+ return {
31
+ title: rdfDescription === null || rdfDescription === void 0 ? void 0 : rdfDescription['dc:title'],
32
+ source: rdfDescription === null || rdfDescription === void 0 ? void 0 : rdfDescription['dc:source'],
33
+ creator: rdfDescription === null || rdfDescription === void 0 ? void 0 : rdfDescription['dc:creator'],
34
+ license: rdfDescription === null || rdfDescription === void 0 ? void 0 : rdfDescription['dcterms:license'],
35
+ copyright: rdfDescription === null || rdfDescription === void 0 ? void 0 : rdfDescription['dc:rights'],
36
+ };
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dicebear/converter",
3
- "version": "9.2.1",
3
+ "version": "9.2.3",
4
4
  "description": "SVG Converter for DiceBear",
5
5
  "keywords": [
6
6
  "dicebear"
@@ -37,15 +37,15 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@resvg/resvg-js": "^2.6.2",
40
- "exiftool-vendored": "^27.0.0",
41
- "sharp": "^0.33.4",
40
+ "exiftool-vendored": "^30.2.0",
41
+ "fast-xml-parser": "^5.2.5",
42
+ "sharp": "^0.34.2",
42
43
  "tmp-promise": "^3.0.3"
43
44
  },
44
45
  "devDependencies": {
45
- "@tsconfig/recommended": "^1.0.2",
46
- "@types/sharp": "^0.32.0",
47
- "del-cli": "^5.0.0",
48
- "typescript": "^5.1.6",
46
+ "@tsconfig/recommended": "^1.0.10",
47
+ "del-cli": "^6.0.0",
48
+ "typescript": "^5.8.3",
49
49
  "uvu": "^0.5.6"
50
50
  },
51
51
  "engines": {
@@ -54,5 +54,5 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  },
57
- "gitHead": "49137b3469a8b831a296c61a69169f0005879508"
57
+ "gitHead": "8cfdc4d029c9de6a82fef4e27ed67b5e2cd14a30"
58
58
  }