canvu-react 0.4.44 → 0.4.45

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/native.cjs CHANGED
@@ -963,6 +963,9 @@ function rebuildItemSvg(item) {
963
963
  }
964
964
  return item;
965
965
  }
966
+ function applyStrokeToItem(item, patch) {
967
+ return rebuildItemSvg({ ...item, ...patch });
968
+ }
966
969
  function createRectangleItem(id, bounds, style) {
967
970
  const r = normalizeRect(bounds);
968
971
  const s = { ...DEFAULT_STROKE_STYLE, ...style };
@@ -5197,6 +5200,14 @@ function isPlacementTool(toolId) {
5197
5200
  function isDefaultMarkerToolStyle(style) {
5198
5201
  return style.stroke === MARKER_TOOL_STYLE.stroke && style.strokeWidth === MARKER_TOOL_STYLE.strokeWidth && style.strokeOpacity === MARKER_TOOL_STYLE.strokeOpacity;
5199
5202
  }
5203
+ function getNativeStyleInspectorToolId(item) {
5204
+ const kind = item.toolKind;
5205
+ if (kind === "marker") return "marker";
5206
+ if (kind === "draw" || kind === "pencil" || kind === "brush" || kind === "rect" || kind === "ellipse" || kind === "architectural-cloud" || kind === "line" || kind === "arrow") {
5207
+ return "draw";
5208
+ }
5209
+ return null;
5210
+ }
5200
5211
  function placementPreviewForTool(toolId, start, end) {
5201
5212
  if (toolId === "rect" || toolId === "ellipse" || toolId === "architectural-cloud") {
5202
5213
  return { kind: toolId, rect: rectFromCorners(start, end) };
@@ -5460,12 +5471,45 @@ var NativeVectorViewport = react.forwardRef(function NativeVectorViewport2({
5460
5471
  () => items.filter((it) => selectedIds.includes(it.id)),
5461
5472
  [items, selectedIds]
5462
5473
  );
5474
+ const selectedStyleInspectorState = react.useMemo(() => {
5475
+ const styleableItems = selectedItems.filter(
5476
+ (item) => !item.locked && getNativeStyleInspectorToolId(item) !== null
5477
+ );
5478
+ if (styleableItems.length === 0) return null;
5479
+ const toolId2 = styleableItems.every((item) => item.toolKind === "marker") ? "marker" : "draw";
5480
+ const primaryItem = toolId2 === "marker" ? styleableItems[0] : styleableItems.find((item) => item.toolKind !== "marker") ?? styleableItems[0];
5481
+ if (!primaryItem) return null;
5482
+ return {
5483
+ toolId: toolId2,
5484
+ value: resolveStrokeStyle(primaryItem)
5485
+ };
5486
+ }, [selectedItems]);
5463
5487
  const sceneItems = react.useMemo(() => {
5464
5488
  if (eraserPreviewIds.length === 0) return items;
5465
5489
  const hidden = new Set(eraserPreviewIds);
5466
5490
  return items.filter((it) => !hidden.has(it.id));
5467
5491
  }, [items, eraserPreviewIds]);
5468
5492
  const showResizeHandles = interactive && selectedItems.length === 1 && !selectedItems[0]?.locked && supportsNativeResizeHandles(selectedItems[0]);
5493
+ const patchSelectedItemsStrokeStyle = react.useCallback(
5494
+ (patch) => {
5495
+ const change = onItemsChangeRef.current;
5496
+ if (!change) return;
5497
+ const selectedIdSet = new Set(selectedIdsRef.current);
5498
+ if (selectedIdSet.size === 0) return;
5499
+ let changed = false;
5500
+ const nextItems = itemsRef.current.map((item) => {
5501
+ if (!selectedIdSet.has(item.id) || item.locked || getNativeStyleInspectorToolId(item) === null) {
5502
+ return item;
5503
+ }
5504
+ changed = true;
5505
+ return applyStrokeToItem(item, patch);
5506
+ });
5507
+ if (!changed) return;
5508
+ change(nextItems);
5509
+ patchCurrentStrokeStyle(patch);
5510
+ },
5511
+ [patchCurrentStrokeStyle]
5512
+ );
5469
5513
  const lastPinchDist = react.useRef(null);
5470
5514
  const lastPanPoint = react.useRef(null);
5471
5515
  const beginDragAtScreenPoint = react.useCallback(
@@ -6211,6 +6255,9 @@ var NativeVectorViewport = react.forwardRef(function NativeVectorViewport2({
6211
6255
  [requestRender, size]
6212
6256
  );
6213
6257
  const activeStyleToolId = toolId === "draw" || toolId === "marker" ? toolId : null;
6258
+ const styleInspectorToolId = selectedStyleInspectorState?.toolId ?? activeStyleToolId;
6259
+ const styleInspectorValue = selectedStyleInspectorState?.value ?? strokeStyleState;
6260
+ const styleInspectorChange = selectedStyleInspectorState ? patchSelectedItemsStrokeStyle : patchCurrentStrokeStyle;
6214
6261
  const nativeLinkDialogLabels = {
6215
6262
  ...DEFAULT_NATIVE_LINK_TOOL_DIALOG_LABELS,
6216
6263
  ...linkToolDialogLabels ?? {}
@@ -6277,7 +6324,7 @@ var NativeVectorViewport = react.forwardRef(function NativeVectorViewport2({
6277
6324
  children: overlay
6278
6325
  }
6279
6326
  ) : null,
6280
- interactive && showStyleInspector && activeStyleToolId ? /* @__PURE__ */ jsxRuntime.jsx(
6327
+ interactive && showStyleInspector && styleInspectorToolId ? /* @__PURE__ */ jsxRuntime.jsx(
6281
6328
  reactNative.View,
6282
6329
  {
6283
6330
  pointerEvents: "box-none",
@@ -6300,9 +6347,9 @@ var NativeVectorViewport = react.forwardRef(function NativeVectorViewport2({
6300
6347
  children: /* @__PURE__ */ jsxRuntime.jsx(
6301
6348
  NativeVectorStyleInspector,
6302
6349
  {
6303
- toolId: activeStyleToolId,
6304
- value: strokeStyleState,
6305
- onChange: patchCurrentStrokeStyle
6350
+ toolId: styleInspectorToolId,
6351
+ value: styleInspectorValue,
6352
+ onChange: styleInspectorChange
6306
6353
  }
6307
6354
  )
6308
6355
  }