@ibodr/draw 0.2.7 → 0.2.10

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,14 @@ 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
+ label: string;
2875
+ labelColor: string;
2876
+ labelSize: number;
2877
+ };
2855
2878
  getGeometry(shape: DrGeoShape): Group2d;
2856
2879
  getHandleSnapGeometry(shape: DrGeoShape): HandleSnapGeometry;
2857
2880
  getText(shape: DrGeoShape): string;
@@ -3040,6 +3063,12 @@ declare class HighlightShapeUtil extends ShapeUtil<DrHighlightShape> {
3040
3063
  hideRotateHandle(shape: DrHighlightShape): boolean;
3041
3064
  hideSelectionBoundsFg(shape: DrHighlightShape): boolean;
3042
3065
  getDefaultProps(): DrHighlightShape['props'];
3066
+ getLodStyle(shape: DrHighlightShape): {
3067
+ fill: null;
3068
+ stroke: string;
3069
+ strokeWidth: number;
3070
+ opacity: number;
3071
+ } | null;
3043
3072
  getGeometry(shape: DrHighlightShape): Polygon2d | Circle2d;
3044
3073
  component(shape: DrHighlightShape): react_jsx_runtime.JSX.Element;
3045
3074
  backgroundComponent(shape: DrHighlightShape): react_jsx_runtime.JSX.Element;
@@ -3071,6 +3100,12 @@ declare class ImageShapeUtil extends BaseBoxShapeUtil<DrImageShape> {
3071
3100
  isAspectRatioLocked(shape: DrImageShape): boolean;
3072
3101
  canCrop(shape: DrImageShape): boolean;
3073
3102
  isExportBoundsContainer(): boolean;
3103
+ getLodStyle(_shape: DrImageShape): {
3104
+ fill: null;
3105
+ stroke: null;
3106
+ strokeWidth: number;
3107
+ unmountWhenCulled: boolean;
3108
+ };
3074
3109
  getDefaultProps(): DrImageShape['props'];
3075
3110
  createShapeForAsset(asset: DrAsset, position: VecModel): DrShapePartial | null;
3076
3111
  getGeometry(shape: DrImageShape): Geometry2d;
@@ -3103,6 +3138,11 @@ declare class LineShapeUtil extends ShapeUtil<DrLineShape> {
3103
3138
  hideSelectionBoundsBg(shape: DrLineShape): boolean;
3104
3139
  hideInMinimap(): boolean;
3105
3140
  getDefaultProps(): DrLineShape['props'];
3141
+ getLodStyle(shape: DrLineShape): {
3142
+ fill: null;
3143
+ stroke: string;
3144
+ strokeWidth: number;
3145
+ };
3106
3146
  getGeometry(shape: DrLineShape): PathBuilderGeometry2d;
3107
3147
  getHandles(shape: DrLineShape): DrHandle[];
3108
3148
  onResize(shape: DrLineShape, info: DrResizeInfo<DrLineShape>): {
@@ -3276,6 +3316,14 @@ declare class NoteShapeUtil extends ShapeUtil<DrNoteShape> {
3276
3316
  isAspectRatioLocked(shape: DrNoteShape): boolean;
3277
3317
  hideSelectionBoundsFg(shape: DrNoteShape): boolean;
3278
3318
  getDefaultProps(): DrNoteShape['props'];
3319
+ getLodStyle(shape: DrNoteShape): {
3320
+ fill: string;
3321
+ stroke: null;
3322
+ strokeWidth: number;
3323
+ label: string;
3324
+ labelColor: string;
3325
+ labelSize: number;
3326
+ };
3279
3327
  getGeometry(shape: DrNoteShape): Group2d;
3280
3328
  getHandles(shape: DrNoteShape): DrHandle[];
3281
3329
  onResize(shape: any, info: DrResizeInfo<any>): {
@@ -3366,6 +3414,15 @@ declare class TextShapeUtil extends ShapeUtil<DrTextShape> {
3366
3414
  width: number;
3367
3415
  height: number;
3368
3416
  };
3417
+ getLodStyle(shape: DrTextShape): {
3418
+ fill: null;
3419
+ stroke: string;
3420
+ strokeWidth: number;
3421
+ opacity: number;
3422
+ label: string;
3423
+ labelColor: string;
3424
+ labelSize: number;
3425
+ };
3369
3426
  getGeometry(shape: DrTextShape, opts: DrGeometryOpts): Rectangle2d;
3370
3427
  getFontFaces(shape: DrTextShape): _ibodr_schema.DrFontFace[];
3371
3428
  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,19 @@ 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
+ const text = renderPlaintextFromRichText(this.editor, shape.props.richText).trim();
30200
+ return {
30201
+ fill: filled ? dv.fillColor : null,
30202
+ stroke: dv.strokeColor,
30203
+ strokeWidth: dv.strokeWidth,
30204
+ label: text,
30205
+ labelColor: dv.labelColor,
30206
+ labelSize: dv.labelFontSize * shape.props.scale
30207
+ };
30208
+ }
30155
30209
  getGeometry(shape) {
30156
30210
  const { props } = shape;
30157
30211
  const { scale } = props;
@@ -30741,6 +30795,16 @@ var HighlightShapeUtil = class extends ShapeUtil {
30741
30795
  scaleY: 1
30742
30796
  };
30743
30797
  }
30798
+ getLodStyle(shape) {
30799
+ if (!shape.props.isComplete || shape.props.segments.length === 0) return null;
30800
+ const dv = getDisplayValues(this, shape);
30801
+ return {
30802
+ fill: null,
30803
+ stroke: dv.strokeColor,
30804
+ strokeWidth: dv.strokeWidth,
30805
+ opacity: dv.underlayOpacity
30806
+ };
30807
+ }
30744
30808
  getGeometry(shape) {
30745
30809
  const dv = getDisplayValues(this, shape);
30746
30810
  const strokeWidth = dv.strokeWidth * shape.props.scale;
@@ -30895,6 +30959,7 @@ function getIsDot2(shape) {
30895
30959
  const segment = shape.props.segments[0];
30896
30960
  return shape.props.segments.length === 1 && b64Vecs.isSinglePoint(segment.path, segment.dim);
30897
30961
  }
30962
+ var highlightPathCache = /* @__PURE__ */ new WeakMap();
30898
30963
  function HighlightRenderer({
30899
30964
  strokeWidth,
30900
30965
  forceSolid,
@@ -30902,6 +30967,21 @@ function HighlightRenderer({
30902
30967
  opacity,
30903
30968
  strokeColor
30904
30969
  }) {
30970
+ const cached = highlightPathCache.get(shape);
30971
+ if (cached && cached.forceSolid === forceSolid && cached.strokeWidth === strokeWidth) {
30972
+ return /* @__PURE__ */ jsx(
30973
+ "path",
30974
+ {
30975
+ d: cached.d,
30976
+ strokeLinecap: "round",
30977
+ fill: "none",
30978
+ pointerEvents: "all",
30979
+ stroke: strokeColor,
30980
+ strokeWidth: cached.sw,
30981
+ opacity
30982
+ }
30983
+ );
30984
+ }
30905
30985
  const allPointsFromSegments = getPointsFromDrawSegments(
30906
30986
  shape.props.segments,
30907
30987
  shape.props.scaleX,
@@ -30917,6 +30997,7 @@ function HighlightRenderer({
30917
30997
  });
30918
30998
  const strokePoints = getStrokePoints(allPointsFromSegments, options);
30919
30999
  const solidStrokePath = strokePoints.length > 1 ? getSvgPathFromStrokePoints(strokePoints, false) : getShapeDot(allPointsFromSegments[0] ?? { x: 0, y: 0 });
31000
+ highlightPathCache.set(shape, { forceSolid, strokeWidth, d: solidStrokePath, sw });
30920
31001
  return /* @__PURE__ */ jsx(
30921
31002
  "path",
30922
31003
  {
@@ -31221,6 +31302,9 @@ var ImageShapeUtil = class extends BaseBoxShapeUtil {
31221
31302
  isExportBoundsContainer() {
31222
31303
  return true;
31223
31304
  }
31305
+ getLodStyle(_shape) {
31306
+ return { fill: null, stroke: null, strokeWidth: 0, unmountWhenCulled: true };
31307
+ }
31224
31308
  getDefaultProps() {
31225
31309
  return {
31226
31310
  w: 100,
@@ -31708,6 +31792,10 @@ var LineShapeUtil = class extends ShapeUtil {
31708
31792
  scale: 1
31709
31793
  };
31710
31794
  }
31795
+ getLodStyle(shape) {
31796
+ const dv = getDisplayValues(this, shape);
31797
+ return { fill: null, stroke: dv.strokeColor, strokeWidth: dv.strokeWidth };
31798
+ }
31711
31799
  getGeometry(shape) {
31712
31800
  const geometry = getPathForLineShape(shape).toGeometry();
31713
31801
  assert(geometry instanceof PathBuilderGeometry2d);
@@ -32080,6 +32168,18 @@ var NoteShapeUtil = class extends ShapeUtil {
32080
32168
  textLastEditedBy: null
32081
32169
  };
32082
32170
  }
32171
+ getLodStyle(shape) {
32172
+ const dv = getDisplayValues(this, shape);
32173
+ const text = renderPlaintextFromRichText(this.editor, shape.props.richText).trim();
32174
+ return {
32175
+ fill: dv.noteBackgroundColor,
32176
+ stroke: null,
32177
+ strokeWidth: 0,
32178
+ label: text,
32179
+ labelColor: dv.labelColor,
32180
+ labelSize: dv.labelFontSize * (shape.props.fontSizeAdjustment ?? 1) * shape.props.scale
32181
+ };
32182
+ }
32083
32183
  getGeometry(shape) {
32084
32184
  const { labelHeight, labelWidth } = this.getLabelSize(shape);
32085
32185
  const { scale } = shape.props;
@@ -32581,6 +32681,19 @@ var TextShapeUtil = class extends ShapeUtil {
32581
32681
  getMinDimensions(shape) {
32582
32682
  return sizeCache.get(this.editor, shape.id);
32583
32683
  }
32684
+ getLodStyle(shape) {
32685
+ const dv = getDisplayValues(this, shape);
32686
+ const text = renderPlaintextFromRichText(this.editor, shape.props.richText).trim();
32687
+ return {
32688
+ fill: null,
32689
+ stroke: dv.color,
32690
+ strokeWidth: 1,
32691
+ opacity: 0.85,
32692
+ label: text,
32693
+ labelColor: dv.color,
32694
+ labelSize: dv.fontSize * shape.props.scale
32695
+ };
32696
+ }
32584
32697
  getGeometry(shape, opts) {
32585
32698
  const { scale } = shape.props;
32586
32699
  const { width, height } = this.getMinDimensions(shape);
@@ -40181,7 +40294,7 @@ init_sanitizeSvg();
40181
40294
  // src/index.ts
40182
40295
  registerDrawLibraryVersion(
40183
40296
  "@ibodr/draw",
40184
- "0.2.7",
40297
+ "0.2.10",
40185
40298
  "esm"
40186
40299
  );
40187
40300
  /*!