@stemy/backend 2.9.4 → 2.9.5

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.
@@ -1212,7 +1212,7 @@
1212
1212
  "application/font-woff", "application/font-woff2", "application/x-font-opentype", "application/x-font-truetype", "application/x-font-datafork",
1213
1213
  "font/woff", "font/woff2", "font/otf", "font/ttf", "font/datafork"
1214
1214
  ];
1215
- var imageTypes = ["image/jpeg", "image/jpg", "image/png"];
1215
+ var imageTypes = ["image/jpeg", "image/jpg", "image/png", "image/svg+xml"];
1216
1216
  var fontProps = [
1217
1217
  "postscriptName", "fullName", "familyName", "subfamilyName",
1218
1218
  "copyright", "version", "unitsPerEm", "ascent", "descent", "lineGap",
@@ -1267,12 +1267,32 @@
1267
1267
  AssetProcessor.isImage = function (contentType) {
1268
1268
  return imageTypes.indexOf(contentType) >= 0;
1269
1269
  };
1270
- AssetProcessor.copyImageMeta = function (buffer, metadata) {
1270
+ AssetProcessor.copyImageMeta = function (buffer, metadata, fileType) {
1271
1271
  return __awaiter$u(this, void 0, void 0, function () {
1272
- var output;
1272
+ var match, attrs, parts, output;
1273
1273
  return __generator(this, function (_b) {
1274
1274
  switch (_b.label) {
1275
- case 0: return [4 /*yield*/, sharp$3(buffer).rotate().toBuffer({ resolveWithObject: true })];
1275
+ case 0:
1276
+ if (fileType.mime === "image/svg+xml") {
1277
+ match = /<svg(.+)>/gi.exec(buffer.toString("utf8"));
1278
+ if (match && match.length > 1) {
1279
+ attrs = match[1].match(/([a-z]+)="([^"]+)"/gi);
1280
+ attrs.forEach(function (attr) {
1281
+ if (attr.length < 5)
1282
+ return;
1283
+ var _b = __read(attr.split("="), 2), name = _b[0], value = _b[1];
1284
+ var val = value.replace(/"/gi, "");
1285
+ metadata[name] = isNaN(val) ? val : Number(val);
1286
+ });
1287
+ if (metadata.viewBox && (isNaN(metadata.width) || isNaN(metadata.height))) {
1288
+ parts = metadata.viewBox.split(" ");
1289
+ metadata.width = Number(parts[0]) + Number(parts[2]);
1290
+ metadata.height = Number(parts[1]) + Number(parts[3]);
1291
+ }
1292
+ }
1293
+ return [2 /*return*/, buffer];
1294
+ }
1295
+ return [4 /*yield*/, sharp$3(buffer).rotate().toBuffer({ resolveWithObject: true })];
1276
1296
  case 1:
1277
1297
  output = _b.sent();
1278
1298
  Object.assign(metadata, output.info);
@@ -1297,7 +1317,7 @@
1297
1317
  switch (_b.label) {
1298
1318
  case 0:
1299
1319
  if (!AssetProcessor_1.isImage(fileType.mime)) return [3 /*break*/, 2];
1300
- return [4 /*yield*/, AssetProcessor_1.copyImageMeta(buffer, metadata)];
1320
+ return [4 /*yield*/, AssetProcessor_1.copyImageMeta(buffer, metadata, fileType)];
1301
1321
  case 1:
1302
1322
  buffer = _b.sent();
1303
1323
  _b.label = 2;