@pixerate/editor-react 0.87.0 → 0.89.0

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.
@@ -97,6 +97,7 @@ __export(canvas_exports, {
97
97
  blendLayout: () => import_canvas30.blendLayout,
98
98
  boundsOf: () => import_canvas30.boundsOf,
99
99
  brushstrokeScaleBucket: () => import_canvas34.brushstrokeScaleBucket,
100
+ brushstrokeSeed: () => import_canvas34.brushstrokeSeed,
100
101
  calculateDagreReflowDisplacement: () => import_canvas30.calculateDagreReflowDisplacement,
101
102
  calculateDirectionalDisplacement: () => import_canvas30.calculateDirectionalDisplacement,
102
103
  canCombineShapeNodes: () => import_canvas28.canCombineShapeNodes,
@@ -301,6 +302,7 @@ __export(canvas_exports, {
301
302
  removeTrack: () => import_canvas33.removeTrack,
302
303
  renameCanvasVariantProperty: () => import_canvas34.renameCanvasVariantProperty,
303
304
  renameCanvasVariantValue: () => import_canvas34.renameCanvasVariantValue,
305
+ renderCanvasBrushSwatch: () => import_canvas34.renderCanvasBrushSwatch,
304
306
  renderShapeBrushstroke: () => import_canvas34.renderShapeBrushstroke,
305
307
  reorderNodes: () => import_canvas27.reorderNodes,
306
308
  repositionNodesTo: () => import_canvas30.repositionNodesTo,
@@ -1660,13 +1662,16 @@ function ShapeNodeZoomProvider({ zoom, children }) {
1660
1662
  const bucket = (0, import_canvas12.brushstrokeScaleBucket)(zoom);
1661
1663
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ShapeNodeZoomContext.Provider, { value: bucket, children });
1662
1664
  }
1663
- function useShapeBrushstroke(shape, width, height) {
1665
+ function useShapeBrushstroke(shape, width, height, position) {
1664
1666
  const zoom = (0, import_react14.useContext)(ShapeNodeZoomContext);
1665
1667
  const brushed = (0, import_canvas12.isBrushedShape)(shape) ? shape : null;
1666
1668
  const vb = brushed?.viewBox;
1667
1669
  const nodeScale = vb && width && height && vb[2] > 0 && vb[3] > 0 ? Math.max(width / vb[2], height / vb[3]) : 1;
1668
1670
  const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
1669
1671
  const scale = (0, import_canvas12.brushstrokeScaleBucket)(zoom * nodeScale, dpr);
1672
+ const unit = vb && width && vb[2] > 0 ? width / vb[2] : 1;
1673
+ const ox = Math.round((position?.x ?? 0) - (vb?.[0] ?? 0) * unit);
1674
+ const oy = Math.round((position?.y ?? 0) - (vb?.[1] ?? 0) * unit);
1670
1675
  const [image, setImage] = (0, import_react14.useState)(null);
1671
1676
  (0, import_react14.useEffect)(() => {
1672
1677
  if (!brushed) {
@@ -1674,7 +1679,7 @@ function useShapeBrushstroke(shape, width, height) {
1674
1679
  return;
1675
1680
  }
1676
1681
  let live = true;
1677
- (0, import_canvas12.renderShapeBrushstroke)(brushed, { scale }).then(
1682
+ (0, import_canvas12.renderShapeBrushstroke)(brushed, { scale, origin: { x: ox, y: oy }, unit }).then(
1678
1683
  (img) => live && setImage(img),
1679
1684
  (error) => {
1680
1685
  if (!live) return;
@@ -1685,21 +1690,23 @@ function useShapeBrushstroke(shape, width, height) {
1685
1690
  return () => {
1686
1691
  live = false;
1687
1692
  };
1688
- }, [brushed, scale]);
1693
+ }, [brushed, scale, ox, oy, unit]);
1689
1694
  return image;
1690
1695
  }
1691
- function useCanvasBrushes() {
1696
+ function useCanvasBrushes(options = {}) {
1692
1697
  const [state, setState] = (0, import_react14.useState)({ brushes: [], loading: true, error: null });
1698
+ const swatches = options.swatches ? JSON.stringify(options.swatches) : "";
1693
1699
  (0, import_react14.useEffect)(() => {
1694
1700
  let live = true;
1695
- (0, import_canvas12.listCanvasBrushes)().then(
1701
+ const opts = swatches ? JSON.parse(swatches) : null;
1702
+ (0, import_canvas12.listCanvasBrushes)().then(async (list) => opts ? Promise.all(list.map(async (b) => ({ ...b, swatch: await (0, import_canvas12.renderCanvasBrushSwatch)(b.id, opts) }))) : list).then(
1696
1703
  (brushes) => live && setState({ brushes, loading: false, error: null }),
1697
1704
  (error) => live && setState({ brushes: [], loading: false, error: error instanceof Error ? error.message : String(error) })
1698
1705
  );
1699
1706
  return () => {
1700
1707
  live = false;
1701
1708
  };
1702
- }, []);
1709
+ }, [swatches]);
1703
1710
  return (0, import_react14.useMemo)(() => state, [state]);
1704
1711
  }
1705
1712
 
@@ -2399,9 +2406,9 @@ function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = ""
2399
2406
 
2400
2407
  // src/canvas/ShapeNode.tsx
2401
2408
  var import_jsx_runtime10 = require("react/jsx-runtime");
2402
- function ShapeNode({ id, data, width, height, selected, className = "", children }) {
2409
+ function ShapeNode({ id, data, width, height, selected, className = "", children, positionAbsoluteX, positionAbsoluteY }) {
2403
2410
  const shape = data?.shape;
2404
- const brushImage = useShapeBrushstroke((0, import_canvas14.isShapeDescription)(shape) ? shape : null, width, height);
2411
+ const brushImage = useShapeBrushstroke((0, import_canvas14.isShapeDescription)(shape) ? shape : null, width, height, { x: positionAbsoluteX ?? 0, y: positionAbsoluteY ?? 0 });
2405
2412
  if (!(0, import_canvas14.isShapeDescription)(shape)) return null;
2406
2413
  const render = (0, import_canvas14.getShapeRenderData)(shape, { width, height }, { id: id || data?.id });
2407
2414
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
@@ -3758,6 +3765,7 @@ function DiagramPresenceLayer({ presence, viewport, className = "" }) {
3758
3765
  blendLayout,
3759
3766
  boundsOf,
3760
3767
  brushstrokeScaleBucket,
3768
+ brushstrokeSeed,
3761
3769
  calculateDagreReflowDisplacement,
3762
3770
  calculateDirectionalDisplacement,
3763
3771
  canCombineShapeNodes,
@@ -3962,6 +3970,7 @@ function DiagramPresenceLayer({ presence, viewport, className = "" }) {
3962
3970
  removeTrack,
3963
3971
  renameCanvasVariantProperty,
3964
3972
  renameCanvasVariantValue,
3973
+ renderCanvasBrushSwatch,
3965
3974
  renderShapeBrushstroke,
3966
3975
  reorderNodes,
3967
3976
  repositionNodesTo,