canvu-react 0.3.14 → 0.3.17

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/dist/react.d.cts CHANGED
@@ -68,6 +68,7 @@ type IngestAssetFileError = {
68
68
  */
69
69
  type IngestAssetFilesToSceneItemsOptions = {
70
70
  files: readonly File[];
71
+ existingItems?: readonly VectorSceneItem[];
71
72
  worldCenter: {
72
73
  x: number;
73
74
  y: number;
package/dist/react.d.ts CHANGED
@@ -68,6 +68,7 @@ type IngestAssetFileError = {
68
68
  */
69
69
  type IngestAssetFilesToSceneItemsOptions = {
70
70
  files: readonly File[];
71
+ existingItems?: readonly VectorSceneItem[];
71
72
  worldCenter: {
72
73
  x: number;
73
74
  y: number;
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 imagePlacementIndex = 0;
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 stackedTopY = occupiedBottomY == null ? naturalTopY2 : occupiedBottomY + gapWorld;
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, stackedTopY),
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 ox = imagePlacementIndex % 8 * stepWorld;
1456
- const oy = Math.floor(imagePlacementIndex / 8) * stepWorld;
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 + ox,
1465
- y: naturalTopY + imageYOffsetAdjustment,
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 = {
@@ -1679,11 +1666,7 @@ function VectorSelectionInspector({
1679
1666
  ...activeToolStyle.strokeOpacity != null ? { strokeOpacity: activeToolStyle.strokeOpacity } : {}
1680
1667
  })
1681
1668
  }
1682
- ),
1683
- /* @__PURE__ */ jsxs("span", { style: { fontWeight: 500, color: "#71717a" }, children: [
1684
- strokeWidth2,
1685
- "px"
1686
- ] })
1669
+ )
1687
1670
  ] }),
1688
1671
  showMarkerOpacity2 && /* @__PURE__ */ jsxs("label", { style: labelStyle, children: [
1689
1672
  "Opacidade (marcador)",
@@ -1789,11 +1772,7 @@ function VectorSelectionInspector({
1789
1772
  strokeWidth: Number(e.target.value)
1790
1773
  })
1791
1774
  }
1792
- ),
1793
- /* @__PURE__ */ jsxs("span", { style: { fontWeight: 500, color: "#71717a" }, children: [
1794
- strokeWidth,
1795
- "px"
1796
- ] })
1775
+ )
1797
1776
  ] }),
1798
1777
  showMarkerOpacity && firstMarker && /* @__PURE__ */ jsxs("label", { style: labelStyle, children: [
1799
1778
  "Opacidade (marcador)",
@@ -6003,7 +5982,7 @@ body[data-canvu-pen-active="true"] [data-slot="shape-context-menu"] * {
6003
5982
  }
6004
5983
  `;
6005
5984
  function debugApplePencilPointer(phase, detail) {
6006
- console.debug(`[canvu][apple-pencil] ${phase}`, detail);
5985
+ return;
6007
5986
  }
6008
5987
  var MARKER_TOOL_STYLE = {
6009
5988
  stroke: "#fde047",
@@ -6603,7 +6582,6 @@ var VectorViewport = forwardRef(
6603
6582
  const captureInteractionPointer = useCallback(
6604
6583
  (target, pointerId, options) => {
6605
6584
  const captureNativePointer = options?.captureNativePointer ?? true;
6606
- debugApplePencilPointer("capture", { pointerId, captureNativePointer });
6607
6585
  activeInteractionPointerIdRef.current = pointerId;
6608
6586
  activeInteractionPointerTargetRef.current = captureNativePointer ? target : null;
6609
6587
  if (captureNativePointer) {
@@ -6615,7 +6593,6 @@ var VectorViewport = forwardRef(
6615
6593
  const releaseInteractionPointer = useCallback(() => {
6616
6594
  const pointerId = activeInteractionPointerIdRef.current;
6617
6595
  const target = activeInteractionPointerTargetRef.current;
6618
- debugApplePencilPointer("release", { pointerId });
6619
6596
  if (pointerId != null && target) {
6620
6597
  try {
6621
6598
  if (target.hasPointerCapture(pointerId)) {
@@ -6648,8 +6625,6 @@ var VectorViewport = forwardRef(
6648
6625
  const itemId = strokeState.itemId;
6649
6626
  const style = { ...strokeStyleRef.current };
6650
6627
  debugApplePencilPointer("finalize-stroke", {
6651
- pointerType,
6652
- tool,
6653
6628
  points: pts.length
6654
6629
  });
6655
6630
  dragStateRef.current = { kind: "idle" };
@@ -7399,6 +7374,7 @@ var VectorViewport = forwardRef(
7399
7374
  }
7400
7375
  const result = await ingestAssetFilesToSceneItems({
7401
7376
  files,
7377
+ existingItems: itemsRef.current,
7402
7378
  worldCenter: {
7403
7379
  x: worldX,
7404
7380
  y: worldY
@@ -7426,12 +7402,12 @@ var VectorViewport = forwardRef(
7426
7402
  );
7427
7403
  const handleImageFileChange = useCallback(
7428
7404
  async (e) => {
7429
- const file = e.target.files?.[0];
7405
+ const files = e.target.files ? Array.from(e.target.files) : [];
7430
7406
  e.target.value = "";
7431
7407
  const pending = pendingImagePlacementRef.current;
7432
7408
  pendingImagePlacementRef.current = null;
7433
- if (!file || !pending) return;
7434
- await placeImageFilesAtWorld([file], pending.worldX, pending.worldY);
7409
+ if (files.length === 0 || !pending) return;
7410
+ await placeImageFilesAtWorld(files, pending.worldX, pending.worldY);
7435
7411
  },
7436
7412
  [placeImageFilesAtWorld]
7437
7413
  );
@@ -7527,14 +7503,12 @@ var VectorViewport = forwardRef(
7527
7503
  pointerType: e.pointerType,
7528
7504
  pointerId: e.pointerId,
7529
7505
  pressure: e.pointerType === "pen" ? e.pressure : void 0,
7530
- activePointerId,
7531
7506
  dragKind: currentDragState.kind
7532
7507
  });
7533
7508
  }
7534
7509
  if (e.pointerType === "pen" && currentDragState.kind === "stroke" && currentDragState.pointerType === "pen") {
7535
7510
  debugApplePencilPointer("pen-reentry", {
7536
7511
  pointerId: e.pointerId,
7537
- previousPointerId: activePointerId,
7538
7512
  previousPoints: currentDragState.points.length
7539
7513
  });
7540
7514
  finalizeStrokeDragState(currentDragState);
@@ -7699,10 +7673,10 @@ var VectorViewport = forwardRef(
7699
7673
  return;
7700
7674
  }
7701
7675
  if (!e.shiftKey && cur.length > 0) {
7702
- const selectedArrowOrLine = cur.map((id) => resolved.find((it) => it.id === id)).filter(
7703
- (it) => it != null && !it.locked && (it.toolKind === "line" || it.toolKind === "arrow")
7676
+ const selectedUnlockedItems = cur.map((id) => resolved.find((it) => it.id === id)).filter(
7677
+ (it) => it != null && !it.locked
7704
7678
  );
7705
- if (selectedArrowOrLine.some(
7679
+ if (selectedUnlockedItems.some(
7706
7680
  (it) => pointInSelectedItemBounds(it, worldX, worldY)
7707
7681
  )) {
7708
7682
  const snapshots = {};
@@ -7880,9 +7854,7 @@ var VectorViewport = forwardRef(
7880
7854
  debugApplePencilPointer("native-pointerdown", {
7881
7855
  pointerType: e.pointerType,
7882
7856
  pointerId: e.pointerId,
7883
- pressure: e.pressure,
7884
- tool
7885
- });
7857
+ pressure: e.pressure});
7886
7858
  e.preventDefault();
7887
7859
  e.stopImmediatePropagation();
7888
7860
  };
@@ -7982,9 +7954,7 @@ var VectorViewport = forwardRef(
7982
7954
  debugApplePencilPointer("touchstart-stroke", {
7983
7955
  touchId: touch.identifier,
7984
7956
  touchType: touchKind(touch),
7985
- force: touchPressure(touch),
7986
- tool
7987
- });
7957
+ force: touchPressure(touch)});
7988
7958
  stopTouchEvent(ev);
7989
7959
  };
7990
7960
  const onTouchMove = (ev) => {
@@ -8706,6 +8676,7 @@ var VectorViewport = forwardRef(
8706
8676
  {
8707
8677
  ref: imageInputRef,
8708
8678
  type: "file",
8679
+ multiple: true,
8709
8680
  accept: "image/*,application/pdf",
8710
8681
  style: { display: "none" },
8711
8682
  "aria-label": "Select image or PDF to place on canvas",