@ibodr/draw 0.2.7 → 0.2.9

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/index.d.ts CHANGED
@@ -2353,6 +2353,11 @@ declare class ArrowShapeUtil extends ShapeUtil<DrArrowShape> {
2353
2353
  canBeLaidOut(shape: DrArrowShape, info: DrShapeUtilCanBeLaidOutOpts): boolean;
2354
2354
  getFontFaces(shape: DrArrowShape): _ibodr_schema.DrFontFace[];
2355
2355
  getDefaultProps(): DrArrowShape['props'];
2356
+ getLodStyle(shape: DrArrowShape): {
2357
+ fill: null;
2358
+ stroke: string;
2359
+ strokeWidth: number;
2360
+ };
2356
2361
  getGeometry(shape: DrArrowShape): Group2d;
2357
2362
  getHandles(shape: DrArrowShape): DrHandle[];
2358
2363
  getText(shape: DrArrowShape): string;
@@ -2472,6 +2477,11 @@ declare class DrawShapeUtil extends ShapeUtil<DrDrawShape> {
2472
2477
  hideRotateHandle(shape: DrDrawShape): boolean;
2473
2478
  hideSelectionBoundsFg(shape: DrDrawShape): boolean;
2474
2479
  getDefaultProps(): DrDrawShape['props'];
2480
+ getLodStyle(shape: DrDrawShape): {
2481
+ fill: string | null;
2482
+ stroke: string;
2483
+ strokeWidth: number;
2484
+ } | null;
2475
2485
  getGeometry(shape: DrDrawShape): Polyline2d | Circle2d;
2476
2486
  component(shape: DrDrawShape): react_jsx_runtime.JSX.Element;
2477
2487
  getIndicatorPath(shape: DrDrawShape): Path2D;
@@ -2607,6 +2617,11 @@ declare class FrameShapeUtil extends BaseFrameLikeShapeUtil<DrFrameShape> {
2607
2617
  isExportBoundsContainer(): boolean;
2608
2618
  getDefaultProps(): DrFrameShape['props'];
2609
2619
  getAriaDescriptor(shape: DrFrameShape): string;
2620
+ getLodStyle(shape: DrFrameShape): {
2621
+ fill: string;
2622
+ stroke: string;
2623
+ strokeWidth: number;
2624
+ };
2610
2625
  getGeometry(shape: DrFrameShape): Geometry2d;
2611
2626
  getText(shape: DrFrameShape): string | undefined;
2612
2627
  component(shape: DrFrameShape): react_jsx_runtime.JSX.Element;
@@ -2852,6 +2867,11 @@ declare class GeoShapeUtil extends BaseBoxShapeUtil<DrGeoShape> {
2852
2867
  options: GeoShapeOptions;
2853
2868
  canEdit(shape: DrGeoShape): boolean;
2854
2869
  getDefaultProps(): DrGeoShape['props'];
2870
+ getLodStyle(shape: DrGeoShape): {
2871
+ fill: string | null;
2872
+ stroke: string;
2873
+ strokeWidth: number;
2874
+ };
2855
2875
  getGeometry(shape: DrGeoShape): Group2d;
2856
2876
  getHandleSnapGeometry(shape: DrGeoShape): HandleSnapGeometry;
2857
2877
  getText(shape: DrGeoShape): string;
@@ -3040,6 +3060,12 @@ declare class HighlightShapeUtil extends ShapeUtil<DrHighlightShape> {
3040
3060
  hideRotateHandle(shape: DrHighlightShape): boolean;
3041
3061
  hideSelectionBoundsFg(shape: DrHighlightShape): boolean;
3042
3062
  getDefaultProps(): DrHighlightShape['props'];
3063
+ getLodStyle(shape: DrHighlightShape): {
3064
+ fill: null;
3065
+ stroke: string;
3066
+ strokeWidth: number;
3067
+ opacity: number;
3068
+ } | null;
3043
3069
  getGeometry(shape: DrHighlightShape): Polygon2d | Circle2d;
3044
3070
  component(shape: DrHighlightShape): react_jsx_runtime.JSX.Element;
3045
3071
  backgroundComponent(shape: DrHighlightShape): react_jsx_runtime.JSX.Element;
@@ -3071,6 +3097,12 @@ declare class ImageShapeUtil extends BaseBoxShapeUtil<DrImageShape> {
3071
3097
  isAspectRatioLocked(shape: DrImageShape): boolean;
3072
3098
  canCrop(shape: DrImageShape): boolean;
3073
3099
  isExportBoundsContainer(): boolean;
3100
+ getLodStyle(_shape: DrImageShape): {
3101
+ fill: null;
3102
+ stroke: null;
3103
+ strokeWidth: number;
3104
+ unmountWhenCulled: boolean;
3105
+ };
3074
3106
  getDefaultProps(): DrImageShape['props'];
3075
3107
  createShapeForAsset(asset: DrAsset, position: VecModel): DrShapePartial | null;
3076
3108
  getGeometry(shape: DrImageShape): Geometry2d;
@@ -3103,6 +3135,11 @@ declare class LineShapeUtil extends ShapeUtil<DrLineShape> {
3103
3135
  hideSelectionBoundsBg(shape: DrLineShape): boolean;
3104
3136
  hideInMinimap(): boolean;
3105
3137
  getDefaultProps(): DrLineShape['props'];
3138
+ getLodStyle(shape: DrLineShape): {
3139
+ fill: null;
3140
+ stroke: string;
3141
+ strokeWidth: number;
3142
+ };
3106
3143
  getGeometry(shape: DrLineShape): PathBuilderGeometry2d;
3107
3144
  getHandles(shape: DrLineShape): DrHandle[];
3108
3145
  onResize(shape: DrLineShape, info: DrResizeInfo<DrLineShape>): {
@@ -3276,6 +3313,11 @@ declare class NoteShapeUtil extends ShapeUtil<DrNoteShape> {
3276
3313
  isAspectRatioLocked(shape: DrNoteShape): boolean;
3277
3314
  hideSelectionBoundsFg(shape: DrNoteShape): boolean;
3278
3315
  getDefaultProps(): DrNoteShape['props'];
3316
+ getLodStyle(shape: DrNoteShape): {
3317
+ fill: string;
3318
+ stroke: null;
3319
+ strokeWidth: number;
3320
+ };
3279
3321
  getGeometry(shape: DrNoteShape): Group2d;
3280
3322
  getHandles(shape: DrNoteShape): DrHandle[];
3281
3323
  onResize(shape: any, info: DrResizeInfo<any>): {
@@ -3366,6 +3408,12 @@ declare class TextShapeUtil extends ShapeUtil<DrTextShape> {
3366
3408
  width: number;
3367
3409
  height: number;
3368
3410
  };
3411
+ getLodStyle(shape: DrTextShape): {
3412
+ fill: null;
3413
+ stroke: string;
3414
+ strokeWidth: number;
3415
+ opacity: number;
3416
+ };
3369
3417
  getGeometry(shape: DrTextShape, opts: DrGeometryOpts): Rectangle2d;
3370
3418
  getFontFaces(shape: DrTextShape): _ibodr_schema.DrFontFace[];
3371
3419
  getText(shape: DrTextShape): string;
package/dist/index.mjs CHANGED
@@ -27391,6 +27391,10 @@ var ArrowShapeUtil = class extends ShapeUtil {
27391
27391
  scale: 1
27392
27392
  };
27393
27393
  }
27394
+ getLodStyle(shape) {
27395
+ const dv = getDisplayValues(this, shape);
27396
+ return { fill: null, stroke: dv.strokeColor, strokeWidth: dv.strokeWidth };
27397
+ }
27394
27398
  getGeometry(shape) {
27395
27399
  const isEditing = this.editor.getEditingShapeId() === shape.id;
27396
27400
  const info = getArrowInfo(this.editor, shape);
@@ -28850,6 +28854,17 @@ var DrawShapeUtil = class extends ShapeUtil {
28850
28854
  scaleY: 1
28851
28855
  };
28852
28856
  }
28857
+ getLodStyle(shape) {
28858
+ if (!shape.props.isComplete || shape.props.segments.length === 0) return null;
28859
+ const dv = getDisplayValues(this, shape);
28860
+ const sw = (dv.strokeWidth + 1) * shape.props.scale;
28861
+ const filled = shape.props.isClosed && shape.props.fill !== "none";
28862
+ return {
28863
+ fill: filled ? dv.fillColor : null,
28864
+ stroke: dv.strokeColor,
28865
+ strokeWidth: sw
28866
+ };
28867
+ }
28853
28868
  getGeometry(shape) {
28854
28869
  const points = getPointsFromDrawSegments(
28855
28870
  shape.props.segments,
@@ -28974,6 +28989,45 @@ function getIsDot(shape) {
28974
28989
  const segment = shape.props.segments[0];
28975
28990
  return shape.props.segments.length === 1 && b64Vecs.isSinglePoint(segment.path, segment.dim);
28976
28991
  }
28992
+ var drawSvgCache = /* @__PURE__ */ new WeakMap();
28993
+ function getDrawSvgPaths(shape, baseStrokeWidth, forceSolid) {
28994
+ const cached = drawSvgCache.get(shape);
28995
+ if (cached && cached.forceSolid === forceSolid && cached.baseStrokeWidth === baseStrokeWidth) {
28996
+ return cached;
28997
+ }
28998
+ const allPointsFromSegments = getPointsFromDrawSegments(
28999
+ shape.props.segments,
29000
+ shape.props.scaleX,
29001
+ shape.props.scaleY
29002
+ );
29003
+ const showAsComplete = shape.props.isComplete || last(shape.props.segments)?.type === "straight";
29004
+ let sw = (baseStrokeWidth + 1) * shape.props.scale;
29005
+ if (!forceSolid && !shape.props.isPen && shape.props.dash === "draw" && allPointsFromSegments.length === 1) {
29006
+ sw += rng(shape.id)() * (sw / 6);
29007
+ }
29008
+ const options = getFreehandOptions(shape.props, sw, showAsComplete, forceSolid);
29009
+ let ink = null;
29010
+ let inkFill = null;
29011
+ let solid = null;
29012
+ let isDot = false;
29013
+ if (!forceSolid && shape.props.dash === "draw") {
29014
+ if (shape.props.isClosed && shape.props.fill !== "none" && allPointsFromSegments.length > 1) {
29015
+ inkFill = getSvgPathFromStrokePoints(
29016
+ getStrokePoints(allPointsFromSegments, options),
29017
+ shape.props.isClosed
29018
+ );
29019
+ }
29020
+ ink = svgInk(allPointsFromSegments, options);
29021
+ } else {
29022
+ const strokePoints = getStrokePoints(allPointsFromSegments, options);
29023
+ isDot = strokePoints.length < 2;
29024
+ const fill = isDot || shape.props.isClosed ? shape.props.fill : "none";
29025
+ solid = isDot ? getDot(allPointsFromSegments[0] ?? { x: 0, y: 0 }, 0) : getSvgPathFromStrokePoints(strokePoints, shape.props.isClosed && fill !== "none");
29026
+ }
29027
+ const paths = { forceSolid, baseStrokeWidth, sw, ink, inkFill, solid, isDot };
29028
+ drawSvgCache.set(shape, paths);
29029
+ return paths;
29030
+ }
28977
29031
  function DrawShapeSvg({
28978
29032
  shape,
28979
29033
  zoomOverride,
@@ -28983,20 +29037,14 @@ function DrawShapeSvg({
28983
29037
  patternFillFallbackColor
28984
29038
  }) {
28985
29039
  const editor = useEditor();
28986
- const allPointsFromSegments = getPointsFromDrawSegments(
28987
- shape.props.segments,
28988
- shape.props.scaleX,
28989
- shape.props.scaleY
28990
- );
28991
- const showAsComplete = shape.props.isComplete || last(shape.props.segments)?.type === "straight";
28992
- let sw = (baseStrokeWidth + 1) * shape.props.scale;
29040
+ const strokeWidthForZoom = (baseStrokeWidth + 1) * shape.props.scale;
28993
29041
  const forceSolid = useValue(
28994
29042
  "force solid",
28995
29043
  () => {
28996
29044
  const zoomLevel = zoomOverride ?? editor.getEfficientZoomLevel();
28997
- return zoomLevel < 0.5 && zoomLevel < 1.5 / sw;
29045
+ return zoomLevel < 0.5 && zoomLevel < 1.5 / strokeWidthForZoom;
28998
29046
  },
28999
- [editor, sw, zoomOverride]
29047
+ [editor, strokeWidthForZoom, zoomOverride]
29000
29048
  );
29001
29049
  const dotAdjustment = useValue(
29002
29050
  "dot adjustment",
@@ -29006,40 +29054,25 @@ function DrawShapeSvg({
29006
29054
  },
29007
29055
  [editor, zoomOverride]
29008
29056
  );
29009
- if (!forceSolid && !shape.props.isPen && shape.props.dash === "draw" && allPointsFromSegments.length === 1) {
29010
- sw += rng(shape.id)() * (sw / 6);
29011
- }
29012
- const options = getFreehandOptions(shape.props, sw, showAsComplete, forceSolid);
29013
- if (!forceSolid && shape.props.dash === "draw") {
29057
+ const paths = getDrawSvgPaths(shape, baseStrokeWidth, forceSolid);
29058
+ const sw = paths.sw;
29059
+ if (!forceSolid && shape.props.dash === "draw" && paths.ink) {
29014
29060
  return /* @__PURE__ */ jsxs(Fragment, { children: [
29015
- shape.props.isClosed && shape.props.fill !== "none" && allPointsFromSegments.length > 1 && (shape.props.fill === "pattern" ? /* @__PURE__ */ jsx(
29061
+ paths.inkFill && (shape.props.fill === "pattern" ? /* @__PURE__ */ jsx(
29016
29062
  PatternFill,
29017
29063
  {
29018
- d: getSvgPathFromStrokePoints(
29019
- getStrokePoints(allPointsFromSegments, options),
29020
- shape.props.isClosed
29021
- ),
29064
+ d: paths.inkFill,
29022
29065
  fillColor,
29023
29066
  patternFillFallbackColor,
29024
29067
  scale: shape.props.scale
29025
29068
  }
29026
- ) : /* @__PURE__ */ jsx(
29027
- "path",
29028
- {
29029
- fill: fillColor,
29030
- d: getSvgPathFromStrokePoints(
29031
- getStrokePoints(allPointsFromSegments, options),
29032
- shape.props.isClosed
29033
- )
29034
- }
29035
- )),
29036
- /* @__PURE__ */ jsx("path", { d: svgInk(allPointsFromSegments, options), strokeLinecap: "round", fill: strokeColor })
29069
+ ) : /* @__PURE__ */ jsx("path", { fill: fillColor, d: paths.inkFill })),
29070
+ /* @__PURE__ */ jsx("path", { d: paths.ink, strokeLinecap: "round", fill: strokeColor })
29037
29071
  ] });
29038
29072
  }
29039
- const strokePoints = getStrokePoints(allPointsFromSegments, options);
29040
- const isDot = strokePoints.length < 2;
29073
+ const solidStrokePath = paths.solid ?? "";
29074
+ const isDot = paths.isDot;
29041
29075
  const fill = isDot || shape.props.isClosed ? shape.props.fill : "none";
29042
- const solidStrokePath = isDot ? getDot(allPointsFromSegments[0] ?? { x: 0, y: 0 }, 0) : getSvgPathFromStrokePoints(strokePoints, shape.props.isClosed && fill !== "none");
29043
29076
  return /* @__PURE__ */ jsxs(Fragment, { children: [
29044
29077
  isDot || !shape.props.isClosed || fill === "none" ? null : fill === "pattern" ? /* @__PURE__ */ jsx(
29045
29078
  PatternFill,
@@ -29799,6 +29832,14 @@ var FrameShapeUtil = class extends BaseFrameLikeShapeUtil {
29799
29832
  getAriaDescriptor(shape) {
29800
29833
  return shape.props.name;
29801
29834
  }
29835
+ getLodStyle(shape) {
29836
+ const dv = getDisplayValues(this, shape);
29837
+ return {
29838
+ fill: this.options.showColors ? dv.showColorsFillColor : dv.fillColor,
29839
+ stroke: this.options.showColors ? dv.showColorsStrokeColor : dv.strokeColor,
29840
+ strokeWidth: 2
29841
+ };
29842
+ }
29802
29843
  getGeometry(shape) {
29803
29844
  const { editor } = this;
29804
29845
  const z = editor.getEfficientZoomLevel();
@@ -30152,6 +30193,15 @@ var GeoShapeUtil = class extends BaseBoxShapeUtil {
30152
30193
  richText: toRichText("")
30153
30194
  };
30154
30195
  }
30196
+ getLodStyle(shape) {
30197
+ const dv = getDisplayValues(this, shape);
30198
+ const filled = shape.props.fill !== "none" && dv.fillColor !== "transparent";
30199
+ return {
30200
+ fill: filled ? dv.fillColor : null,
30201
+ stroke: dv.strokeColor,
30202
+ strokeWidth: dv.strokeWidth
30203
+ };
30204
+ }
30155
30205
  getGeometry(shape) {
30156
30206
  const { props } = shape;
30157
30207
  const { scale } = props;
@@ -30741,6 +30791,16 @@ var HighlightShapeUtil = class extends ShapeUtil {
30741
30791
  scaleY: 1
30742
30792
  };
30743
30793
  }
30794
+ getLodStyle(shape) {
30795
+ if (!shape.props.isComplete || shape.props.segments.length === 0) return null;
30796
+ const dv = getDisplayValues(this, shape);
30797
+ return {
30798
+ fill: null,
30799
+ stroke: dv.strokeColor,
30800
+ strokeWidth: dv.strokeWidth,
30801
+ opacity: dv.underlayOpacity
30802
+ };
30803
+ }
30744
30804
  getGeometry(shape) {
30745
30805
  const dv = getDisplayValues(this, shape);
30746
30806
  const strokeWidth = dv.strokeWidth * shape.props.scale;
@@ -30895,6 +30955,7 @@ function getIsDot2(shape) {
30895
30955
  const segment = shape.props.segments[0];
30896
30956
  return shape.props.segments.length === 1 && b64Vecs.isSinglePoint(segment.path, segment.dim);
30897
30957
  }
30958
+ var highlightPathCache = /* @__PURE__ */ new WeakMap();
30898
30959
  function HighlightRenderer({
30899
30960
  strokeWidth,
30900
30961
  forceSolid,
@@ -30902,6 +30963,21 @@ function HighlightRenderer({
30902
30963
  opacity,
30903
30964
  strokeColor
30904
30965
  }) {
30966
+ const cached = highlightPathCache.get(shape);
30967
+ if (cached && cached.forceSolid === forceSolid && cached.strokeWidth === strokeWidth) {
30968
+ return /* @__PURE__ */ jsx(
30969
+ "path",
30970
+ {
30971
+ d: cached.d,
30972
+ strokeLinecap: "round",
30973
+ fill: "none",
30974
+ pointerEvents: "all",
30975
+ stroke: strokeColor,
30976
+ strokeWidth: cached.sw,
30977
+ opacity
30978
+ }
30979
+ );
30980
+ }
30905
30981
  const allPointsFromSegments = getPointsFromDrawSegments(
30906
30982
  shape.props.segments,
30907
30983
  shape.props.scaleX,
@@ -30917,6 +30993,7 @@ function HighlightRenderer({
30917
30993
  });
30918
30994
  const strokePoints = getStrokePoints(allPointsFromSegments, options);
30919
30995
  const solidStrokePath = strokePoints.length > 1 ? getSvgPathFromStrokePoints(strokePoints, false) : getShapeDot(allPointsFromSegments[0] ?? { x: 0, y: 0 });
30996
+ highlightPathCache.set(shape, { forceSolid, strokeWidth, d: solidStrokePath, sw });
30920
30997
  return /* @__PURE__ */ jsx(
30921
30998
  "path",
30922
30999
  {
@@ -31221,6 +31298,9 @@ var ImageShapeUtil = class extends BaseBoxShapeUtil {
31221
31298
  isExportBoundsContainer() {
31222
31299
  return true;
31223
31300
  }
31301
+ getLodStyle(_shape) {
31302
+ return { fill: null, stroke: null, strokeWidth: 0, unmountWhenCulled: true };
31303
+ }
31224
31304
  getDefaultProps() {
31225
31305
  return {
31226
31306
  w: 100,
@@ -31708,6 +31788,10 @@ var LineShapeUtil = class extends ShapeUtil {
31708
31788
  scale: 1
31709
31789
  };
31710
31790
  }
31791
+ getLodStyle(shape) {
31792
+ const dv = getDisplayValues(this, shape);
31793
+ return { fill: null, stroke: dv.strokeColor, strokeWidth: dv.strokeWidth };
31794
+ }
31711
31795
  getGeometry(shape) {
31712
31796
  const geometry = getPathForLineShape(shape).toGeometry();
31713
31797
  assert(geometry instanceof PathBuilderGeometry2d);
@@ -32080,6 +32164,10 @@ var NoteShapeUtil = class extends ShapeUtil {
32080
32164
  textLastEditedBy: null
32081
32165
  };
32082
32166
  }
32167
+ getLodStyle(shape) {
32168
+ const dv = getDisplayValues(this, shape);
32169
+ return { fill: dv.noteBackgroundColor, stroke: null, strokeWidth: 0 };
32170
+ }
32083
32171
  getGeometry(shape) {
32084
32172
  const { labelHeight, labelWidth } = this.getLabelSize(shape);
32085
32173
  const { scale } = shape.props;
@@ -32581,6 +32669,10 @@ var TextShapeUtil = class extends ShapeUtil {
32581
32669
  getMinDimensions(shape) {
32582
32670
  return sizeCache.get(this.editor, shape.id);
32583
32671
  }
32672
+ getLodStyle(shape) {
32673
+ const dv = getDisplayValues(this, shape);
32674
+ return { fill: null, stroke: dv.color, strokeWidth: 1, opacity: 0.85 };
32675
+ }
32584
32676
  getGeometry(shape, opts) {
32585
32677
  const { scale } = shape.props;
32586
32678
  const { width, height } = this.getMinDimensions(shape);
@@ -40181,7 +40273,7 @@ init_sanitizeSvg();
40181
40273
  // src/index.ts
40182
40274
  registerDrawLibraryVersion(
40183
40275
  "@ibodr/draw",
40184
- "0.2.7",
40276
+ "0.2.9",
40185
40277
  "esm"
40186
40278
  );
40187
40279
  /*!