@weasel-js/routing 1.5.0 → 1.5.2

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.
@@ -136,7 +136,6 @@ function liveScope(id, eligibility, state) {
136
136
  const tags = eligibility.capabilities;
137
137
  if (tags && tags.length > 0 && state.allows && !state.allows(tags)) return null;
138
138
  if (state.engagedIds?.has(id)) return "hotkey";
139
- if (eligibility.offhand && state.heldTriggers.has(eligibility.offhand)) return "hotkey";
140
139
  if (eligibility.focus && state.focusedId === id) return "active";
141
140
  if (eligibility.always || eligibility.claimed) return "ambient";
142
141
  return null;
@@ -481,11 +480,22 @@ function filterEligible(matches, actionLookup, ruleCtx) {
481
480
  return isEligible(action, ruleCtx);
482
481
  });
483
482
  }
484
- var EMPTY_TRIGGERS = /* @__PURE__ */ new Set();
485
483
  var EMPTY_ENGAGED2 = /* @__PURE__ */ new Set();
486
484
  function modifiersOf(e) {
487
485
  return { alt: e.altKey, ctrl: e.ctrlKey, meta: e.metaKey, shift: e.shiftKey };
488
486
  }
487
+ function worldPointOf(event) {
488
+ switch (event.kind) {
489
+ case "pointerdown":
490
+ case "longpress":
491
+ case "click":
492
+ case "doubleclick":
493
+ case "contextmenu":
494
+ return event.x !== void 0 && event.y !== void 0 ? { x: event.x, y: event.y } : void 0;
495
+ default:
496
+ return void 0;
497
+ }
498
+ }
489
499
  function createDispatcher(opts) {
490
500
  const inFlightHandles = /* @__PURE__ */ new Map();
491
501
  const inFlightOwners = /* @__PURE__ */ new Map();
@@ -537,9 +547,9 @@ function createDispatcher(opts) {
537
547
  base.key = { key: event.key, repeat: false };
538
548
  } else if (event.kind === "wheel") {
539
549
  base.wheel = { deltaX: event.deltaX, deltaY: event.deltaY, deltaZ: 0 };
540
- } else if (event.kind === "pointerdown" || event.kind === "click") {
541
- const sx = event.kind === "pointerdown" ? event.x ?? 0 : event.worldX ?? event.pressX ?? 0;
542
- const sy = event.kind === "pointerdown" ? event.y ?? 0 : event.worldY ?? event.pressY ?? 0;
550
+ } else if (event.kind === "pointerdown" || event.kind === "click" || event.kind === "doubleclick" || event.kind === "contextmenu") {
551
+ const sx = event.x ?? (event.kind === "click" ? event.pressX : void 0) ?? 0;
552
+ const sy = event.y ?? (event.kind === "click" ? event.pressY : void 0) ?? 0;
543
553
  base.world = { x: sx, y: sy };
544
554
  const affordance = event.kind === "pointerdown" ? event.affordance : void 0;
545
555
  base.drag = {
@@ -555,7 +565,8 @@ function createDispatcher(opts) {
555
565
  const origin = gestureId ? dragOrigins.get(gestureId) : void 0;
556
566
  const ox = origin?.x ?? cx;
557
567
  const oy = origin?.y ?? cy;
558
- const points = gestureId ? dragPoints.get(gestureId) : void 0;
568
+ const live = gestureId ? dragPoints.get(gestureId) : void 0;
569
+ const points = live && event.kind === "pointerup" ? [...live] : live;
559
570
  const eventClientX = event.clientX;
560
571
  const eventClientY = event.clientY;
561
572
  const hasClient = eventClientX !== void 0 && eventClientY !== void 0 && origin?.clientX !== void 0 && origin?.clientY !== void 0;
@@ -605,7 +616,6 @@ function createDispatcher(opts) {
605
616
  const allows = capsCtx ? (tags) => tags.every((tag) => capsCtx.allowedCapabilities.has(tag)) : void 0;
606
617
  const result = scopeBindings(ordered, {
607
618
  focusedId: ctx.activeToolId,
608
- heldTriggers: EMPTY_TRIGGERS,
609
619
  engagedIds: new Set(ctx.hotkeyStack),
610
620
  ...allows ? { allows } : {}
611
621
  });
@@ -759,7 +769,7 @@ function createDispatcher(opts) {
759
769
  }
760
770
  const deps = buildDepsFromRequires(action, ctx.depRegistry);
761
771
  if (action.enabled) {
762
- const result = action.enabled(deps);
772
+ const result = action.enabled(deps, worldPointOf(event));
763
773
  if (result !== true) {
764
774
  traceCandidates.push({ actionId: action.id, scope: match.scope, enabledResult: String(result) });
765
775
  continue;
@@ -781,8 +791,8 @@ function createDispatcher(opts) {
781
791
  };
782
792
  } else if (event.kind === "click" || event.kind === "doubleclick") {
783
793
  params = {
784
- worldX: event.worldX,
785
- worldY: event.worldY,
794
+ worldX: event.x,
795
+ worldY: event.y,
786
796
  affordance: event.affordance,
787
797
  // Press point as well as release point — an action that places
788
798
  // geometry at the click wants the former. See `ClickEvent`.
@@ -792,8 +802,8 @@ function createDispatcher(opts) {
792
802
  };
793
803
  } else if (event.kind === "contextmenu" || event.kind === "longpress") {
794
804
  params = {
795
- worldX: event.kind === "contextmenu" ? event.worldX : event.x,
796
- worldY: event.kind === "contextmenu" ? event.worldY : event.y,
805
+ worldX: event.x,
806
+ worldY: event.y,
797
807
  affordance: event.affordance,
798
808
  bodyTarget: event.bodyTarget,
799
809
  mods: modifiersOf(event),
@@ -898,7 +908,7 @@ function createDispatcher(opts) {
898
908
  } else if (ruleCtx && action.eligible && !isEligible(action, ruleCtx)) {
899
909
  verdict = { kind: "ineligible", reason: describeEligible(action.eligible) };
900
910
  } else {
901
- const disabled = action.enabled ? action.enabled(buildDepsFromRequires(action, ctx.depRegistry)) : true;
911
+ const disabled = action.enabled ? action.enabled(buildDepsFromRequires(action, ctx.depRegistry), worldPointOf(event)) : true;
902
912
  if (disabled !== true) {
903
913
  verdict = { kind: "disabled", reason: String(disabled) };
904
914
  } else if (fired) {
@@ -1500,5 +1510,5 @@ function dlog(namespace, ...args) {
1500
1510
  }
1501
1511
 
1502
1512
  export { ALWAYS, COARSE_TARGET_SCALE, DEFAULT_ALLOWED_CAPABILITIES, DEFAULT_DEVICE_PROFILE, INGEST_STRING_MIMES, NEVER, PREDICATE_TARGET, TOOL_OFFHAND_ID, actionBindings, buildDepsFromRequires, buildRouteRegistry, buildRuleCtx, buildToolOffhandBindings, clientToCanvas, clientToCanvasRect, createDispatcher, describeRule, dlog, evaluate, filterEligible, findConflicts, isDev, isEditableTarget, itemsFromClipboardData, itemsFromDataTransfer, itemsFromFiles, liveScope, makeToolOffhandAction, matchBest, matchSorted, matchesKeyBinding, offhandKeyFor, openPointerSession, pointerGestureId, recordModeSwitch, reportRouteConflicts, resolveDeviceProfile, resolveParams, routeGestureForSpecKind, routesForSpec, scopeBindings, specificity, targetConsultsAffordance, validateActionDefaultBinding, validateActionId };
1503
- //# sourceMappingURL=chunk-Y5FHAA4U.js.map
1504
- //# sourceMappingURL=chunk-Y5FHAA4U.js.map
1513
+ //# sourceMappingURL=chunk-H5AGTB2J.js.map
1514
+ //# sourceMappingURL=chunk-H5AGTB2J.js.map