@stemy/backend 2.9.3 → 2.9.6

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,35 @@
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
+ if (!isNaN(metadata.width) && !isNaN(metadata.height)) {
1293
+ metadata.svgSize = { x: metadata.width, y: metadata.height };
1294
+ }
1295
+ }
1296
+ return [2 /*return*/, buffer];
1297
+ }
1298
+ return [4 /*yield*/, sharp$3(buffer).rotate().toBuffer({ resolveWithObject: true })];
1276
1299
  case 1:
1277
1300
  output = _b.sent();
1278
1301
  Object.assign(metadata, output.info);
@@ -1297,7 +1320,7 @@
1297
1320
  switch (_b.label) {
1298
1321
  case 0:
1299
1322
  if (!AssetProcessor_1.isImage(fileType.mime)) return [3 /*break*/, 2];
1300
- return [4 /*yield*/, AssetProcessor_1.copyImageMeta(buffer, metadata)];
1323
+ return [4 /*yield*/, AssetProcessor_1.copyImageMeta(buffer, metadata, fileType)];
1301
1324
  case 1:
1302
1325
  buffer = _b.sent();
1303
1326
  _b.label = 2;
@@ -2889,7 +2912,7 @@
2889
2912
  }
2890
2913
  isFinished = progress.percent == 100;
2891
2914
  if (!!isFinished) return [3 /*break*/, 4];
2892
- return [4 /*yield*/, promiseTimeout(150)];
2915
+ return [4 /*yield*/, promiseTimeout(50)];
2893
2916
  case 3:
2894
2917
  _a.sent();
2895
2918
  _a.label = 4;