@unicitylabs/sphere-ui 0.1.23 → 0.1.24

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.
Files changed (2) hide show
  1. package/dist/index.js +35 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1411,6 +1411,17 @@ import { Fragment as Fragment4, jsx as jsx23, jsxs as jsxs18 } from "react/jsx-r
1411
1411
  function formatExtensions(mimes) {
1412
1412
  return mimes.map((m) => m.split("/")[1].toUpperCase()).join(", ");
1413
1413
  }
1414
+ async function readImageSize(file) {
1415
+ if (typeof createImageBitmap !== "function") return null;
1416
+ try {
1417
+ const bitmap = await createImageBitmap(file);
1418
+ const size = { width: bitmap.width, height: bitmap.height };
1419
+ bitmap.close?.();
1420
+ return size;
1421
+ } catch {
1422
+ return null;
1423
+ }
1424
+ }
1414
1425
  function MediaUploader({
1415
1426
  kind,
1416
1427
  ownerType,
@@ -1453,6 +1464,30 @@ function MediaUploader({
1453
1464
  });
1454
1465
  return;
1455
1466
  }
1467
+ if (file.type !== "image/svg+xml") {
1468
+ const size = await readImageSize(file);
1469
+ if (size) {
1470
+ const { width, height } = size;
1471
+ if (limit.maxWidth && width > limit.maxWidth || limit.maxHeight && height > limit.maxHeight) {
1472
+ setState({
1473
+ phase: "error",
1474
+ message: `Image too large (max ${limit.maxWidth}\xD7${limit.maxHeight}px \u2014 this is ${width}\xD7${height})`
1475
+ });
1476
+ return;
1477
+ }
1478
+ if (limit.aspectRatio) {
1479
+ const ratio = width / height;
1480
+ const tolerance = limit.aspectTolerance ?? 0;
1481
+ if (Math.abs(ratio - limit.aspectRatio) > limit.aspectRatio * tolerance) {
1482
+ setState({
1483
+ phase: "error",
1484
+ message: `Wrong aspect ratio (need ~${limit.aspectRatio}:1 \u2014 this is ${ratio.toFixed(2)}:1)`
1485
+ });
1486
+ return;
1487
+ }
1488
+ }
1489
+ }
1490
+ }
1456
1491
  if (deferUpload) {
1457
1492
  if (previewRef.current) URL.revokeObjectURL(previewRef.current);
1458
1493
  previewRef.current = URL.createObjectURL(file);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unicitylabs/sphere-ui",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",