canvu-react 0.3.14 → 0.3.16
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/README.md +5 -0
- package/dist/react.cjs +16 -37
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +16 -37
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.d.cts
CHANGED
package/dist/react.d.ts
CHANGED
package/dist/react.js
CHANGED
|
@@ -1358,12 +1358,12 @@ async function uploadAssetIfNeeded(assetStore, file, kind) {
|
|
|
1358
1358
|
async function ingestAssetFilesToSceneItems(options) {
|
|
1359
1359
|
const {
|
|
1360
1360
|
files,
|
|
1361
|
+
existingItems = [],
|
|
1361
1362
|
worldCenter,
|
|
1362
1363
|
assetStore,
|
|
1363
1364
|
imageStore = new IndexedDbImageStore(),
|
|
1364
1365
|
createId = createShapeId,
|
|
1365
1366
|
gapWorld = 16,
|
|
1366
|
-
stepWorld = 48,
|
|
1367
1367
|
pdfScale = 1.15,
|
|
1368
1368
|
pdfPageConcurrency = 2,
|
|
1369
1369
|
decorateItem,
|
|
@@ -1372,10 +1372,7 @@ async function ingestAssetFilesToSceneItems(options) {
|
|
|
1372
1372
|
} = options;
|
|
1373
1373
|
const items = [];
|
|
1374
1374
|
const errors = [];
|
|
1375
|
-
let
|
|
1376
|
-
let occupiedBottomY = null;
|
|
1377
|
-
let imageYOffsetAdjustment = 0;
|
|
1378
|
-
let hasImagePlacementBase = false;
|
|
1375
|
+
let occupiedBottomY = existingItems.length > 0 ? Math.max(...existingItems.map((item) => item.bounds.y + item.bounds.height)) : null;
|
|
1379
1376
|
for (const file of files) {
|
|
1380
1377
|
const kind = getAssetKindForFile(file);
|
|
1381
1378
|
if (!kind) {
|
|
@@ -1398,10 +1395,10 @@ async function ingestAssetFilesToSceneItems(options) {
|
|
|
1398
1395
|
const uploadResult2 = await uploadResultPromise;
|
|
1399
1396
|
const fullUrl2 = await createBlobUrlFromStore(imageStore, page.blobId);
|
|
1400
1397
|
const naturalTopY2 = worldCenter.y - page.height / 2;
|
|
1401
|
-
const
|
|
1398
|
+
const stackedTopY2 = occupiedBottomY == null ? naturalTopY2 : occupiedBottomY + gapWorld;
|
|
1402
1399
|
const bounds2 = {
|
|
1403
1400
|
x: worldCenter.x - page.width / 2,
|
|
1404
|
-
y: Math.max(naturalTopY2,
|
|
1401
|
+
y: Math.max(naturalTopY2, stackedTopY2),
|
|
1405
1402
|
width: page.width,
|
|
1406
1403
|
height: page.height
|
|
1407
1404
|
};
|
|
@@ -1439,9 +1436,6 @@ async function ingestAssetFilesToSceneItems(options) {
|
|
|
1439
1436
|
onItemsReady?.([item2], { file, kind });
|
|
1440
1437
|
}
|
|
1441
1438
|
});
|
|
1442
|
-
hasImagePlacementBase = false;
|
|
1443
|
-
imagePlacementIndex = 0;
|
|
1444
|
-
imageYOffsetAdjustment = 0;
|
|
1445
1439
|
continue;
|
|
1446
1440
|
}
|
|
1447
1441
|
const [uploadResult, storedImage] = await Promise.all([
|
|
@@ -1452,17 +1446,11 @@ async function ingestAssetFilesToSceneItems(options) {
|
|
|
1452
1446
|
const fullUrl = await createBlobUrlFromStore(imageStore, blobId);
|
|
1453
1447
|
const thumbBlob = await imageStore.getThumbnail(thumbnailBlobId);
|
|
1454
1448
|
const thumbnailHref = thumbBlob ? URL.createObjectURL(thumbBlob) : null;
|
|
1455
|
-
const
|
|
1456
|
-
const
|
|
1457
|
-
const naturalTopY = worldCenter.y - height / 2 + oy;
|
|
1458
|
-
if (!hasImagePlacementBase) {
|
|
1459
|
-
const minimumTopY = occupiedBottomY == null ? naturalTopY : occupiedBottomY + gapWorld;
|
|
1460
|
-
imageYOffsetAdjustment = Math.max(0, minimumTopY - naturalTopY);
|
|
1461
|
-
hasImagePlacementBase = true;
|
|
1462
|
-
}
|
|
1449
|
+
const naturalTopY = worldCenter.y - height / 2;
|
|
1450
|
+
const stackedTopY = occupiedBottomY == null ? naturalTopY : occupiedBottomY + gapWorld;
|
|
1463
1451
|
const bounds = {
|
|
1464
|
-
x: worldCenter.x - width / 2
|
|
1465
|
-
y: naturalTopY
|
|
1452
|
+
x: worldCenter.x - width / 2,
|
|
1453
|
+
y: Math.max(naturalTopY, stackedTopY),
|
|
1466
1454
|
width,
|
|
1467
1455
|
height
|
|
1468
1456
|
};
|
|
@@ -1492,7 +1480,6 @@ async function ingestAssetFilesToSceneItems(options) {
|
|
|
1492
1480
|
);
|
|
1493
1481
|
items.push(item);
|
|
1494
1482
|
onItemsReady?.([item], { file, kind });
|
|
1495
|
-
imagePlacementIndex++;
|
|
1496
1483
|
occupiedBottomY = occupiedBottomY == null ? bounds.y + height : Math.max(occupiedBottomY, bounds.y + height);
|
|
1497
1484
|
} catch (error) {
|
|
1498
1485
|
const fileError = {
|
|
@@ -6003,7 +5990,7 @@ body[data-canvu-pen-active="true"] [data-slot="shape-context-menu"] * {
|
|
|
6003
5990
|
}
|
|
6004
5991
|
`;
|
|
6005
5992
|
function debugApplePencilPointer(phase, detail) {
|
|
6006
|
-
|
|
5993
|
+
return;
|
|
6007
5994
|
}
|
|
6008
5995
|
var MARKER_TOOL_STYLE = {
|
|
6009
5996
|
stroke: "#fde047",
|
|
@@ -6603,7 +6590,6 @@ var VectorViewport = forwardRef(
|
|
|
6603
6590
|
const captureInteractionPointer = useCallback(
|
|
6604
6591
|
(target, pointerId, options) => {
|
|
6605
6592
|
const captureNativePointer = options?.captureNativePointer ?? true;
|
|
6606
|
-
debugApplePencilPointer("capture", { pointerId, captureNativePointer });
|
|
6607
6593
|
activeInteractionPointerIdRef.current = pointerId;
|
|
6608
6594
|
activeInteractionPointerTargetRef.current = captureNativePointer ? target : null;
|
|
6609
6595
|
if (captureNativePointer) {
|
|
@@ -6615,7 +6601,6 @@ var VectorViewport = forwardRef(
|
|
|
6615
6601
|
const releaseInteractionPointer = useCallback(() => {
|
|
6616
6602
|
const pointerId = activeInteractionPointerIdRef.current;
|
|
6617
6603
|
const target = activeInteractionPointerTargetRef.current;
|
|
6618
|
-
debugApplePencilPointer("release", { pointerId });
|
|
6619
6604
|
if (pointerId != null && target) {
|
|
6620
6605
|
try {
|
|
6621
6606
|
if (target.hasPointerCapture(pointerId)) {
|
|
@@ -6648,8 +6633,6 @@ var VectorViewport = forwardRef(
|
|
|
6648
6633
|
const itemId = strokeState.itemId;
|
|
6649
6634
|
const style = { ...strokeStyleRef.current };
|
|
6650
6635
|
debugApplePencilPointer("finalize-stroke", {
|
|
6651
|
-
pointerType,
|
|
6652
|
-
tool,
|
|
6653
6636
|
points: pts.length
|
|
6654
6637
|
});
|
|
6655
6638
|
dragStateRef.current = { kind: "idle" };
|
|
@@ -7399,6 +7382,7 @@ var VectorViewport = forwardRef(
|
|
|
7399
7382
|
}
|
|
7400
7383
|
const result = await ingestAssetFilesToSceneItems({
|
|
7401
7384
|
files,
|
|
7385
|
+
existingItems: itemsRef.current,
|
|
7402
7386
|
worldCenter: {
|
|
7403
7387
|
x: worldX,
|
|
7404
7388
|
y: worldY
|
|
@@ -7426,12 +7410,12 @@ var VectorViewport = forwardRef(
|
|
|
7426
7410
|
);
|
|
7427
7411
|
const handleImageFileChange = useCallback(
|
|
7428
7412
|
async (e) => {
|
|
7429
|
-
const
|
|
7413
|
+
const files = e.target.files ? Array.from(e.target.files) : [];
|
|
7430
7414
|
e.target.value = "";
|
|
7431
7415
|
const pending = pendingImagePlacementRef.current;
|
|
7432
7416
|
pendingImagePlacementRef.current = null;
|
|
7433
|
-
if (
|
|
7434
|
-
await placeImageFilesAtWorld(
|
|
7417
|
+
if (files.length === 0 || !pending) return;
|
|
7418
|
+
await placeImageFilesAtWorld(files, pending.worldX, pending.worldY);
|
|
7435
7419
|
},
|
|
7436
7420
|
[placeImageFilesAtWorld]
|
|
7437
7421
|
);
|
|
@@ -7527,14 +7511,12 @@ var VectorViewport = forwardRef(
|
|
|
7527
7511
|
pointerType: e.pointerType,
|
|
7528
7512
|
pointerId: e.pointerId,
|
|
7529
7513
|
pressure: e.pointerType === "pen" ? e.pressure : void 0,
|
|
7530
|
-
activePointerId,
|
|
7531
7514
|
dragKind: currentDragState.kind
|
|
7532
7515
|
});
|
|
7533
7516
|
}
|
|
7534
7517
|
if (e.pointerType === "pen" && currentDragState.kind === "stroke" && currentDragState.pointerType === "pen") {
|
|
7535
7518
|
debugApplePencilPointer("pen-reentry", {
|
|
7536
7519
|
pointerId: e.pointerId,
|
|
7537
|
-
previousPointerId: activePointerId,
|
|
7538
7520
|
previousPoints: currentDragState.points.length
|
|
7539
7521
|
});
|
|
7540
7522
|
finalizeStrokeDragState(currentDragState);
|
|
@@ -7880,9 +7862,7 @@ var VectorViewport = forwardRef(
|
|
|
7880
7862
|
debugApplePencilPointer("native-pointerdown", {
|
|
7881
7863
|
pointerType: e.pointerType,
|
|
7882
7864
|
pointerId: e.pointerId,
|
|
7883
|
-
pressure: e.pressure
|
|
7884
|
-
tool
|
|
7885
|
-
});
|
|
7865
|
+
pressure: e.pressure});
|
|
7886
7866
|
e.preventDefault();
|
|
7887
7867
|
e.stopImmediatePropagation();
|
|
7888
7868
|
};
|
|
@@ -7982,9 +7962,7 @@ var VectorViewport = forwardRef(
|
|
|
7982
7962
|
debugApplePencilPointer("touchstart-stroke", {
|
|
7983
7963
|
touchId: touch.identifier,
|
|
7984
7964
|
touchType: touchKind(touch),
|
|
7985
|
-
force: touchPressure(touch)
|
|
7986
|
-
tool
|
|
7987
|
-
});
|
|
7965
|
+
force: touchPressure(touch)});
|
|
7988
7966
|
stopTouchEvent(ev);
|
|
7989
7967
|
};
|
|
7990
7968
|
const onTouchMove = (ev) => {
|
|
@@ -8706,6 +8684,7 @@ var VectorViewport = forwardRef(
|
|
|
8706
8684
|
{
|
|
8707
8685
|
ref: imageInputRef,
|
|
8708
8686
|
type: "file",
|
|
8687
|
+
multiple: true,
|
|
8709
8688
|
accept: "image/*,application/pdf",
|
|
8710
8689
|
style: { display: "none" },
|
|
8711
8690
|
"aria-label": "Select image or PDF to place on canvas",
|