@mocanvas/editor 4.11.1 → 4.12.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.
package/dist/index.d.ts CHANGED
@@ -898,7 +898,6 @@ interface TransformedGeometry2dOptions {
898
898
  debugColor?: string | undefined;
899
899
  excludeFromShapeBounds?: boolean | undefined;
900
900
  }
901
- /** Base class for shape geometry. */
902
901
  declare abstract class Geometry2d {
903
902
  readonly isFilled: boolean;
904
903
  readonly isClosed: boolean;
@@ -8317,6 +8316,12 @@ interface EditorConfig extends TldrawOptions {
8317
8316
  }
8318
8317
  declare const DEFAULT_EDITOR_CONFIG: EditorConfig;
8319
8318
  interface HitTestOptions {
8319
+ /**
8320
+ * Extra tolerance around the shape, in page units — a caller working from a
8321
+ * screen distance divides it by the zoom level itself, as tldraw's callers do.
8322
+ * Defaults to the hit-test margin for the current pointer, which is a screen
8323
+ * distance and is converted here.
8324
+ */
8320
8325
  margin?: number;
8321
8326
  hitInside?: boolean;
8322
8327
  hitLocked?: boolean;
@@ -12786,6 +12791,16 @@ interface CanvasComponents {
12786
12791
  * `TLComponents.Grid`. `null` draws none; omitted uses {@link DefaultGrid}.
12787
12792
  */
12788
12793
  Grid: ((props: TLGridProps) => ReactNode) | null;
12794
+ /**
12795
+ * Drawn over the canvas, in screen space, under whatever chrome the app puts
12796
+ * on top. The layer itself takes no pointer events and its children take
12797
+ * them normally, so a badge pinned to a shape is clickable while the empty
12798
+ * space around it still pans the canvas.
12799
+ *
12800
+ * It belongs to the canvas rather than to the chrome, which is what makes it
12801
+ * survive `hideUi` — an app with no panels still gets its own overlay.
12802
+ */
12803
+ InFrontOfTheCanvas: (() => ReactNode) | null;
12789
12804
  /**
12790
12805
  * Rendered in place of the whole editor once it has thrown. `null` renders
12791
12806
  * nothing — the choice a host with its own error UI outside the canvas
package/dist/index.js CHANGED
@@ -1582,6 +1582,7 @@ var Geometry2dFilters = {
1582
1582
  EXCLUDE_LABELS: { includeInternal: true, includeLabels: false },
1583
1583
  EXCLUDE_NON_STANDARD: { includeInternal: false, includeLabels: false }
1584
1584
  };
1585
+ var HIT_TEST_EPSILON = 1e-9;
1585
1586
  var Geometry2d = class {
1586
1587
  isFilled;
1587
1588
  isClosed;
@@ -1716,7 +1717,7 @@ var Geometry2d = class {
1716
1717
  */
1717
1718
  hitTestPoint(point, margin = 0, hitInside = false, _filters) {
1718
1719
  if ((hitInside || this.isFilled) && this.isClosed && pointInPolygon(point, this.vertices)) return true;
1719
- return Vec.Dist(point, this.nearestPoint(point)) <= margin;
1720
+ return Vec.Dist(point, this.nearestPoint(point)) <= margin + HIT_TEST_EPSILON;
1720
1721
  }
1721
1722
  /** Whether `point` lies within the bounding box, which is the cheap pre-test. */
1722
1723
  isPointInBounds(point, margin = 0) {
@@ -1905,7 +1906,7 @@ var TransformedGeometry2d = class extends Geometry2d {
1905
1906
  }
1906
1907
  hitTestPoint(point, margin = 0, hitInside = false, filters) {
1907
1908
  if ((hitInside || this.isFilled) && this.isClosed && pointInPolygon(point, this.vertices)) return true;
1908
- return Vec.Dist(point, this.nearestPoint(point, filters)) <= margin;
1909
+ return Vec.Dist(point, this.nearestPoint(point, filters)) <= margin + HIT_TEST_EPSILON;
1909
1910
  }
1910
1911
  ignoreHit(point) {
1911
1912
  return this.geometry.ignoreHit(this.toLocal(point));
@@ -5340,7 +5341,7 @@ function faceSet(font) {
5340
5341
  const local = LOCAL_SOURCES[font];
5341
5342
  const face = (style, weight) => ({
5342
5343
  family,
5343
- src: `local("${local}")`,
5344
+ src: weight === "bold" ? `local("${local} Bold"), local("${local}")` : `local("${local}")`,
5344
5345
  style,
5345
5346
  weight,
5346
5347
  display: "swap"
@@ -8731,7 +8732,7 @@ var Editor = class extends EventEmitter {
8731
8732
  }
8732
8733
  getShapeAtPoint(point, opts = {}) {
8733
8734
  this.flushEngine();
8734
- const margin = (opts.margin ?? this.getHitTestMargin()) / this.getZoomLevel();
8735
+ const margin = opts.margin ?? this.getHitTestMargin() / this.getZoomLevel();
8735
8736
  const filter = this.hitFilter(opts);
8736
8737
  if (!filter && !opts.hitInside) {
8737
8738
  const h = this.engine.hitTest(point.x, point.y, margin, this.hitFilterBits(opts));
@@ -8743,7 +8744,7 @@ var Editor = class extends EventEmitter {
8743
8744
  /** Shapes under a point, topmost first. */
8744
8745
  getShapesAtPoint(point, opts = {}) {
8745
8746
  this.flushEngine();
8746
- const margin = (opts.margin ?? this.getHitTestMargin()) / this.getZoomLevel();
8747
+ const margin = opts.margin ?? this.getHitTestMargin() / this.getZoomLevel();
8747
8748
  const filter = this.hitFilter(opts);
8748
8749
  const out = [];
8749
8750
  let candidates;
@@ -15084,6 +15085,7 @@ function CanvasBody({ editor, className, style, children, components, indicatorO
15084
15085
  const Indicators = components?.Indicators ?? DefaultIndicators;
15085
15086
  const Brush = components?.Brush ?? (hasOverlay(editor, "brush") ? null : DefaultBrush);
15086
15087
  const Background = components?.Background;
15088
+ const InFrontOfTheCanvas = components?.InFrontOfTheCanvas;
15087
15089
  return /* @__PURE__ */ jsx(EditorProvider, { editor, children: /* @__PURE__ */ jsxs(
15088
15090
  "div",
15089
15091
  {
@@ -15108,7 +15110,8 @@ function CanvasBody({ editor, className, style, children, components, indicatorO
15108
15110
  hasOverlay(editor, "snapIndicator") ? null : /* @__PURE__ */ jsx(SnapLines, { editor }),
15109
15111
  Brush ? /* @__PURE__ */ jsx(Brush, { editor }) : null
15110
15112
  ] }),
15111
- children
15113
+ children,
15114
+ InFrontOfTheCanvas ? /* @__PURE__ */ jsx("div", { className: "mocanvas-in-front-of-canvas", style: { ...layerStyle, pointerEvents: "none" }, children: /* @__PURE__ */ jsx(InFrontOfTheCanvas, {}) }) : null
15112
15115
  ]
15113
15116
  }
15114
15117
  ) });