@weasel-js/guides 1.15.0 → 1.15.1

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useState, useRef, useCallback, useEffect } from 'react';
2
- import { sceneBoxFrames, scenePoseFrame, useLatest, viewportWorldRect, tickedSegment, measuredSegmentCommands, AUTO_POSE_DESCRIPTOR, visualBoundsViaDescriptor, rectFromPlane, unionAABB, createTransformOp, asNodeId, sceneUnitScopes, screenToWorld, nodeGates, resolveStrokeWidth, resolveUnit, axisUnits, resolveScoped } from '@weasel-js/core';
2
+ import { sceneBoxFrames, scenePoseFrame, useLatest, viewportWorldRect, tickedSegment, measuredSegmentCommands, AUTO_POSE_DESCRIPTOR, visualBoundsViaDescriptor, rectFromPlane, unionAABB, sceneMagnification, asNodeId, createTransformOp, sceneUnitScopes, screenToWorld, nodeGates, resolveStrokeWidth, resolveUnit, axisUnits, resolveScoped } from '@weasel-js/core';
3
3
  import { pointInPolygon, invert, mat3, applyToPoint, pxExtent, PATH_M, PATH_L, PATH_Z, pxExtentInFrame } from '@weasel-js/geom';
4
4
 
5
5
  // src/grid/roundToCell.ts
@@ -942,8 +942,6 @@ function extentAcross(q, p, axis, delta) {
942
942
  const lo3 = c === "x" ? landed.x : landed.y;
943
943
  return [lo3, lo3 + (c === "x" ? landed.width : landed.height)];
944
944
  }
945
-
946
- // src/sources/spacing.ts
947
945
  var TRANSLATE = [
948
946
  { axis: "x", edge: "both", rate: { x: 1, y: 0 } },
949
947
  { axis: "y", edge: "both", rate: { x: 0, y: 1 } }
@@ -952,9 +950,9 @@ function movingSides(q) {
952
950
  return q.sides ? q.sides.map((s) => ({ axis: s.axis, edge: s.side, rate: s.rate })) : TRANSLATE;
953
951
  }
954
952
  var measureAll = (boxes) => ({ boxes, x: measureGapSpans(boxes, "x"), y: measureGapSpans(boxes, "y") });
955
- function gapMark(g, color) {
953
+ function gapMark(g, color, magnification) {
956
954
  const ends = g.axis === "x" ? { from: { x: g.min, y: g.at }, to: { x: g.max, y: g.at } } : { from: { x: g.at, y: g.min }, to: { x: g.at, y: g.max } };
957
- return { kind: "gap", ...ends, value: g.max - g.min, ...color === void 0 ? {} : { color } };
955
+ return { kind: "gap", ...ends, value: (g.max - g.min) / magnification, ...color === void 0 ? {} : { color } };
958
956
  }
959
957
  function spacingSnapSource(opts = {}) {
960
958
  const fromScene = cachedPerScene(measureAll, opts.filter);
@@ -971,6 +969,7 @@ function spacingSnapSource(opts = {}) {
971
969
  const reach = q.reachWorld(q.reachPx);
972
970
  const refs = { x: referenceGaps(box, measured.x), y: referenceGaps(box, measured.y) };
973
971
  const seen = /* @__PURE__ */ new Set();
972
+ const magnification = q.scene && q.ids?.length ? sceneMagnification(q.scene, q.ids.map(asNodeId)) : 1;
974
973
  for (const { axis, edge, rate } of movingSides(q)) {
975
974
  const speed = Math.hypot(rate.x, rate.y);
976
975
  for (const o of spacingOffers(box, axis, edge, measured.boxes, refs[axis])) {
@@ -982,7 +981,7 @@ function spacingSnapSource(opts = {}) {
982
981
  locus: sideLine(probe.at, rate, o.delta),
983
982
  mark: (delta) => {
984
983
  const landed = landedBox(q, delta) ?? box;
985
- return equalGaps(landed, axis, o.size, measured.boxes, refs[axis]).map((g) => gapMark(g, opts.color));
984
+ return equalGaps(landed, axis, o.size, measured.boxes, refs[axis]).map((g) => gapMark(g, opts.color, magnification));
986
985
  }
987
986
  };
988
987
  }
@@ -1033,10 +1032,13 @@ function measureAxis(from, to, axis, out) {
1033
1032
  }
1034
1033
 
1035
1034
  // src/spacingHints/distanceReadout.ts
1036
- function marksOf(r, color) {
1035
+ function marksOf(r, color, magnification) {
1037
1036
  const c = color === void 0 ? {} : { color };
1038
1037
  return [
1039
- ...r.gaps.map((g) => g.axis === "x" ? { kind: "distance", from: { x: g.min, y: g.at }, to: { x: g.max, y: g.at }, value: g.max - g.min, ...c } : { kind: "distance", from: { x: g.at, y: g.min }, to: { x: g.at, y: g.max }, value: g.max - g.min, ...c }),
1038
+ ...r.gaps.map((g) => {
1039
+ const value = (g.max - g.min) / magnification;
1040
+ return g.axis === "x" ? { kind: "distance", from: { x: g.min, y: g.at }, to: { x: g.max, y: g.at }, value, ...c } : { kind: "distance", from: { x: g.at, y: g.min }, to: { x: g.at, y: g.max }, value, ...c };
1041
+ }),
1040
1042
  ...r.leaders.flatMap((l) => {
1041
1043
  if (l.span === void 0) return [];
1042
1044
  return [l.axis === "x" ? { kind: "line", from: { x: l.offset, y: l.span.min }, to: { x: l.offset, y: l.span.max }, ...c } : { kind: "line", from: { x: l.span.min, y: l.offset }, to: { x: l.span.max, y: l.offset }, ...c }];
@@ -1061,10 +1063,10 @@ function distanceReadout(opts = {}) {
1061
1063
  const modifier = opts.modifier ?? "alt";
1062
1064
  let shown = EMPTY;
1063
1065
  let store = null;
1064
- const show = (next) => {
1066
+ const show = (next, magnification = 1) => {
1065
1067
  if (next === shown || next.gaps.length === 0 && shown.gaps.length === 0) return;
1066
1068
  shown = next;
1067
- store?.set(marksOf(next, opts.color));
1069
+ store?.set(marksOf(next, opts.color, magnification));
1068
1070
  };
1069
1071
  const action = {
1070
1072
  id: `${id}.measure`,
@@ -1084,7 +1086,8 @@ function distanceReadout(opts = {}) {
1084
1086
  const hit = nodeAtPoint(p.world, subtreeOf(scene, ids));
1085
1087
  const from = worldUnionOf(scene, ids, { poseDescriptor });
1086
1088
  const [to] = hit === null ? [] : worldBoundsOf(scene, [hit], { poseDescriptor });
1087
- show(from === null || to === void 0 ? EMPTY : measureDistances(from, to));
1089
+ if (from === null || to === void 0) show(EMPTY);
1090
+ else show(measureDistances(from, to), sceneMagnification(scene, [...ids, hit]));
1088
1091
  }
1089
1092
  }
1090
1093
  };