@embedpdf/plugin-annotation 3.0.0-next.6 → 3.0.0-next.7

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.
@@ -10,7 +10,7 @@ let _embedpdf_core_geometry = require("@embedpdf/core-geometry");
10
10
  * here (the package internals + the `/internal` entry use this view). The package
11
11
  * root re-exports the SAME token narrowed to {@link AnnotationCapability}.
12
12
  */
13
- const AnnotationToken = (0, _embedpdf_core.createCapabilityToken)("annotation");
13
+ const AnnotationToken = (0, _embedpdf_core.createCapabilityToken)("annotation", { hint: `add annotationPlugin() from '@embedpdf/plugin-annotation' to your plugins list` });
14
14
  //#endregion
15
15
  //#region src/repository/seam.ts
16
16
  function refKey(ref) {
@@ -1126,6 +1126,17 @@ const TOOL_DEFAULT_KEYS = {
1126
1126
  const DRAW_TAGS = ["annotation-draw", "annotation-edit"];
1127
1127
  const MARKUP_TAGS = ["text-select", "annotation-edit"];
1128
1128
  /**
1129
+ * Whether arming this ANNOTATION tool is touch consent (`Tool.touchDirect`):
1130
+ * drag-CREATE tools — shape/ink draw and text-markup select — take
1131
+ * single-finger touch wholesale (finger draws/marks, two fingers navigate:
1132
+ * the drawing-app convention). Click-to-PLACE tools (stamp, note) do not: a
1133
+ * tap places without any claim, and drags keep scrolling. Derived from the
1134
+ * gesture tags, so custom registered tools inherit the right behavior. Only
1135
+ * annotation-owned tools run through this — the built-in `pointer` tool also
1136
+ * enables `text-select`, but it is registered by the hub, not here.
1137
+ */
1138
+ const isTouchDirect = (enables) => enables.has("annotation-draw") || enables.has("text-select");
1139
+ /**
1129
1140
  * The built-in tools — a data mirror of v2's registrations (shapes + lines + ink
1130
1141
  * + free text in the draw channel, text markup + caret behind text selection, and
1131
1142
  * the click-to-place stamp). Order is display-neutral; the toolbar owns layout.
@@ -1560,16 +1571,23 @@ function createAnnotationCapability(ctx, config = {}) {
1560
1571
  };
1561
1572
  /** The CSS-px chrome settings converted to CONTENT units by the page's view
1562
1573
  * scale (px per content unit) — screen-constant grab zones + stalk at every
1563
- * zoom. No scale → the values are read as content units (headless callers). */
1564
- const chromeGeomAt = (scale) => {
1574
+ * zoom. No scale → the values are read as content units (headless callers).
1575
+ * `boost` widens the GRAB tolerances only (never the drawn chrome or the
1576
+ * knob's position) — the touch path passes {@link TOUCH_GRAB_BOOST} so
1577
+ * handles present finger-sized targets. */
1578
+ const chromeGeomAt = (scale, boost = 1) => {
1565
1579
  const cs = chromeSettings();
1566
1580
  const s = scale || 1;
1567
1581
  return {
1568
- handleTol: cs.handles.hitSize / 2 / s,
1569
- knobTol: cs.knob.hitSize / 2 / s,
1582
+ handleTol: cs.handles.hitSize / 2 / s * boost,
1583
+ knobTol: cs.knob.hitSize / 2 / s * boost,
1570
1584
  knobOffset: cs.knob.offset / s
1571
1585
  };
1572
1586
  };
1587
+ /** Finger-sized grab zones: 2× the mouse tolerances lands a ~24px handle hit
1588
+ * box in Apple's ~44pt-target territory without moving any visuals. */
1589
+ const TOUCH_GRAB_BOOST = 2;
1590
+ const grabBoost = (touch) => touch ? TOUCH_GRAB_BOOST : 1;
1573
1591
  const itemsCache = /* @__PURE__ */ new Map();
1574
1592
  const chromeCache = /* @__PURE__ */ new Map();
1575
1593
  const memoItems = (pon, view) => {
@@ -2340,7 +2358,8 @@ function createAnnotationCapability(ctx, config = {}) {
2340
2358
  const un = ctx.tryGet(_embedpdf_plugin_interaction.InteractionToken)?.registerTool({
2341
2359
  id: resolved.id,
2342
2360
  cursor: resolved.cursor,
2343
- enables: resolved.enables
2361
+ enables: resolved.enables,
2362
+ touchDirect: isTouchDirect(resolved.enables)
2344
2363
  });
2345
2364
  if (resolved.defaults) apply({
2346
2365
  t: "setDefaults",
@@ -2396,7 +2415,14 @@ function createAnnotationCapability(ctx, config = {}) {
2396
2415
  selectionAnchor: (scale, rotation, zoom) => memoAnchor(scale, rotation, zoom),
2397
2416
  creationDraftAnchor: () => memoDraftAnchor(),
2398
2417
  selection: () => model().selected,
2399
- hitKind: (pon, point, scale, rotation, zoom) => (0, _embedpdf_core_annotation.hitTest)(model(), pon, point, chromeGeomAt(scale), model().hitMargin, pageBoxOf(pon), inertIdsAt(pon), viewEnv(zoom, rotation)).t,
2418
+ hitKind: (pon, point, scale, rotation, zoom, touch) => (0, _embedpdf_core_annotation.hitTest)(model(), pon, point, chromeGeomAt(scale, grabBoost(touch)), model().hitMargin, pageBoxOf(pon), inertIdsAt(pon), viewEnv(zoom, rotation)).t,
2419
+ claimsTouchAt: (pon, point, scale, rotation, zoom) => {
2420
+ const m = model();
2421
+ const t = (0, _embedpdf_core_annotation.hitTest)(m, pon, point, chromeGeomAt(scale, TOUCH_GRAB_BOOST), m.hitMargin, pageBoxOf(pon), inertIdsAt(pon), viewEnv(zoom, rotation));
2422
+ if (t.t === "handle" || t.t === "rotate" || t.t === "group-handle") return true;
2423
+ if (t.t === "annot") return m.selected.includes(t.id) && m.selected.every((id) => (0, _embedpdf_core_annotation.canMove)(m, id));
2424
+ return false;
2425
+ },
2400
2426
  cursorAt: (pon, point, scale, rotation, zoom) => (0, _embedpdf_core_annotation.cursorAt)(model(), pon, point, chromeGeomAt(scale), model().hitMargin, pageBoxOf(pon), inertIdsAt(pon), viewEnv(zoom, rotation)),
2401
2427
  hoverAt: (at) => {
2402
2428
  const m = model();
@@ -2435,7 +2461,7 @@ function createAnnotationCapability(ctx, config = {}) {
2435
2461
  const crop = cropOf(pon);
2436
2462
  return crop ? (0, _embedpdf_core_annotation.pdfToContentRect)(rect, crop) : null;
2437
2463
  },
2438
- editPointer: (phase, pon, point, shift, scale, rotation, zoom) => apply({
2464
+ editPointer: (phase, pon, point, shift, scale, rotation, zoom, touch) => apply({
2439
2465
  t: "editPointer",
2440
2466
  phase,
2441
2467
  in: {
@@ -2443,7 +2469,7 @@ function createAnnotationCapability(ctx, config = {}) {
2443
2469
  point,
2444
2470
  shift,
2445
2471
  pageBox: pageBoxOf(pon),
2446
- chrome: chromeGeomAt(scale),
2472
+ chrome: chromeGeomAt(scale, grabBoost(touch)),
2447
2473
  inert: inertIdsAt(pon),
2448
2474
  ...zoom != null ? { zoom } : {},
2449
2475
  ...rotation != null ? { displayRotation: rotation } : {}
@@ -2659,10 +2685,14 @@ function createAnnotationCapability(ctx, config = {}) {
2659
2685
  const m = model();
2660
2686
  const h = (0, _embedpdf_core_annotation.hitTest)(m, pon, point, chromeGeomAt(scale), m.hitMargin, pageBoxOf(pon), void 0, viewEnv(zoom, rotation));
2661
2687
  const id = h.t === "annot" || h.t === "handle" ? h.id : null;
2662
- if (id != null && m.byId[id]?.geom.t === "text") apply({
2663
- t: "beginTextEdit",
2664
- id
2665
- });
2688
+ if (id != null && m.byId[id]?.geom.t === "text") {
2689
+ apply({
2690
+ t: "beginTextEdit",
2691
+ id
2692
+ });
2693
+ return true;
2694
+ }
2695
+ return false;
2666
2696
  },
2667
2697
  setContents: (ref, text) => {
2668
2698
  apply({
@@ -2736,6 +2766,12 @@ Object.defineProperty(exports, "fromDTO", {
2736
2766
  return fromDTO;
2737
2767
  }
2738
2768
  });
2769
+ Object.defineProperty(exports, "isTouchDirect", {
2770
+ enumerable: true,
2771
+ get: function() {
2772
+ return isTouchDirect;
2773
+ }
2774
+ });
2739
2775
  Object.defineProperty(exports, "refKey", {
2740
2776
  enumerable: true,
2741
2777
  get: function() {
@@ -2767,4 +2803,4 @@ Object.defineProperty(exports, "widgetAppearanceFromProps", {
2767
2803
  }
2768
2804
  });
2769
2805
 
2770
- //# sourceMappingURL=capability-BMBwSdaY.cjs.map
2806
+ //# sourceMappingURL=capability-2FkTVblD.cjs.map