opencalque 1.10.2 → 1.11.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.
Files changed (2) hide show
  1. package/dist/cli.js +83 -33
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -20278,7 +20278,8 @@ var NodeSchema = discriminatedUnion("type", [
20278
20278
  flipX: boolean2().optional(),
20279
20279
  scale: number2().positive().optional().describe("Size multiplier of this placement. Defaults to 1."),
20280
20280
  scaleX: number2().positive().optional().describe(`Stretch of this placement along the component's own X axis, on top of "scale": wider than it is drawn. Defaults to 1.`),
20281
- scaleY: number2().positive().optional().describe(`Stretch of this placement along the component's own Y axis, on top of "scale": taller than it is drawn. Defaults to 1.`)
20281
+ scaleY: number2().positive().optional().describe(`Stretch of this placement along the component's own Y axis, on top of "scale": taller than it is drawn. Defaults to 1.`),
20282
+ z: number2().nonnegative().optional().describe("How high above the floor its underside is, in mm, as elevations draw it: a mirror, a shelf. Left out, it stands on the floor.")
20282
20283
  }).describe("A placement of a component. Editing the component updates every instance."),
20283
20284
  object({
20284
20285
  ...base,
@@ -20289,7 +20290,7 @@ var NodeSchema = discriminatedUnion("type", [
20289
20290
  y: number2(),
20290
20291
  rotation,
20291
20292
  flipX: boolean2().optional(),
20292
- z: number2().nonnegative().optional().describe("How high above the floor it is, in mm, to its centre: a socket's or a switch's height. Left out, its kind's usual height for an object fixed on a wall, else none. The plan writes it only with showHeight."),
20293
+ z: number2().nonnegative().optional().describe("How high above the floor it is, in mm: for an object fixed on a wall, to its centre (a socket's or a switch's height) unless its kind measures it to its underside; for anything else, to its underside (a raised unit, a shelf). Left out, its kind's usual height for an object fixed on a wall, else on the floor. The plan writes it only with showHeight."),
20293
20294
  showHeight: boolean2().optional().describe("For an object fixed on a wall: its height above the floor is written beside it on the plan, as electrical plans do.")
20294
20295
  }).describe("An object generated from parameters by an extension. Unknown kinds are preserved and drawn as a placeholder.")
20295
20296
  ]).describe("All coordinates and lengths are millimetres. X grows to the right, Y grows downward.");
@@ -20745,26 +20746,45 @@ function meet(p, a, b, style = "auto") {
20745
20746
  if (!crossing) return square;
20746
20747
  c = crossing;
20747
20748
  } else if (s > a.length || u > b.length) return square;
20748
- if (s < 0 && style === "round") {
20749
- const from = Math.atan2(qa.y - p.y, qa.x - p.x);
20750
- let sweep2 = Math.atan2(qb.y - p.y, qb.x - p.x) - from;
20751
- if (sweep2 > Math.PI) sweep2 -= 2 * Math.PI;
20752
- if (sweep2 < -Math.PI) sweep2 += 2 * Math.PI;
20753
- const steps = Math.max(2, Math.ceil(Math.abs(sweep2) / (Math.PI / 16)));
20754
- const at2 = (t) => {
20755
- const r = a.plus + (b.minus - a.plus) * t;
20756
- return { x: tidy(p.x + r * Math.cos(from + sweep2 * t)), y: tidy(p.y + r * Math.sin(from + sweep2 * t)) };
20757
- };
20758
- const half = Array.from({ length: steps + 1 }, (_, i) => i / (2 * steps));
20759
- return { a: half.map((t) => at2(t)), b: half.map((t) => at2(1 - t)) };
20749
+ if (style === "round" || style === "bevel") {
20750
+ const o = middlesCross(p, a, b);
20751
+ const ga = add(o, scale(perp(a.d), (a.plus + a.minus) / 2));
20752
+ const gb = sub(o, scale(perp(b.d), (b.plus + b.minus) / 2));
20753
+ if (cross(sub(gb, ga), b.d) / denom < 0) {
20754
+ const r = Math.min(a.plus + a.minus, b.plus + b.minus) / 2;
20755
+ const ia = sub(qa, scale(perp(a.d), r));
20756
+ const ib = add(qb, scale(perp(b.d), r));
20757
+ const centre = add(ia, scale(a.d, cross(sub(ib, ia), b.d) / denom));
20758
+ const ta = add(centre, scale(perp(a.d), r));
20759
+ const tb = sub(centre, scale(perp(b.d), r));
20760
+ if (style === "bevel") {
20761
+ const m = mid(ta, tb);
20762
+ return { a: [ta, m], b: [tb, m], at: centre };
20763
+ }
20764
+ const from = Math.atan2(ta.y - centre.y, ta.x - centre.x);
20765
+ let sweep2 = Math.atan2(tb.y - centre.y, tb.x - centre.x) - from;
20766
+ if (sweep2 > Math.PI) sweep2 -= 2 * Math.PI;
20767
+ if (sweep2 < -Math.PI) sweep2 += 2 * Math.PI;
20768
+ const steps = Math.max(2, Math.ceil(Math.abs(sweep2) / (Math.PI / 16)));
20769
+ const point2 = (t) => ({ x: tidy(centre.x + r * Math.cos(from + sweep2 * t)), y: tidy(centre.y + r * Math.sin(from + sweep2 * t)) });
20770
+ const half = Array.from({ length: steps + 1 }, (_, i) => i / (2 * steps));
20771
+ return { a: half.map((t) => point2(t)), b: half.map((t) => point2(1 - t)), at: centre };
20772
+ }
20760
20773
  }
20761
20774
  const tip2 = dist(c, p) / Math.max(a.plus, b.minus, 1e-9);
20762
- if (s < 0 && (style === "bevel" || style === "auto" && tip2 > MITER_LIMIT || tip2 > FORCED_MITER_LIMIT)) {
20775
+ if (s < 0 && (style === "auto" && tip2 > MITER_LIMIT || tip2 > FORCED_MITER_LIMIT)) {
20763
20776
  const m = mid(qa, qb);
20764
20777
  return { a: [qa, m], b: [qb, m] };
20765
20778
  }
20766
20779
  return { a: [c], b: [c] };
20767
20780
  }
20781
+ function middlesCross(p, a, b) {
20782
+ const ma = add(p, scale(perp(a.d), (a.plus - a.minus) / 2));
20783
+ const mb = add(p, scale(perp(b.d), (b.plus - b.minus) / 2));
20784
+ const denom = cross(a.d, b.d);
20785
+ if (Math.abs(denom) < 1e-9) return p;
20786
+ return add(ma, scale(a.d, cross(sub(mb, ma), b.d) / denom));
20787
+ }
20768
20788
  var STOP_TOLERANCE = 1;
20769
20789
  var STOP_LIMIT = 0.25;
20770
20790
  function stopAgainst(doc, wall, p, away, own2) {
@@ -20833,10 +20853,12 @@ function cap(p, wall, away, doc, seams, stopped) {
20833
20853
  const lineShown = (usual) => rays.length !== 2 ? false : me.line === true || next.line === true ? true : me.line === false || next.line === false ? false : usual;
20834
20854
  const drawsLine = (usual) => me.look === next.look ? usual : !!me.look;
20835
20855
  const joined3 = (shape, draws) => {
20836
- const before = meet(p, prev, me, shape).b;
20837
- const after = meet(p, me, next, shape).a;
20856
+ const back = meet(p, prev, me, shape);
20857
+ const ahead = meet(p, me, next, shape);
20858
+ const before = back.b;
20859
+ const after = ahead.a;
20838
20860
  if (draws) seams?.push([before[before.length - 1], after[after.length - 1]]);
20839
- return [...before, p, ...after.reverse()];
20861
+ return [...before, back.at ?? ahead.at ?? p, ...after.reverse()];
20840
20862
  };
20841
20863
  if (style === "butt") {
20842
20864
  const other = next;
@@ -21100,7 +21122,8 @@ function fillFields(text2, doc, parentId, sheet) {
21100
21122
  // packages/core/src/imperial.ts
21101
21123
  var MM_PER_INCH = 25.4;
21102
21124
  function formatFeetInches(mm2, denominator = 16) {
21103
- const parts = Math.round(Math.abs(mm2) / MM_PER_INCH * denominator);
21125
+ const units = Math.abs(mm2) / MM_PER_INCH * denominator;
21126
+ const parts = Math.round(Math.round(units * 1e6) / 1e6);
21104
21127
  if (parts === 0) return '0"';
21105
21128
  const feet2 = Math.floor(parts / (12 * denominator));
21106
21129
  const rest = parts - feet2 * 12 * denominator;
@@ -21389,13 +21412,27 @@ var turned = (degrees) => tidy2((degrees % 360 + 360) % 360);
21389
21412
  var sheetContentOf = (doc) => componentsOf(doc).find((component) => component.sheet !== void 0);
21390
21413
 
21391
21414
  // packages/core/src/papers.ts
21415
+ var INCH = 25.4;
21392
21416
  var PAPER_FORMATS = [
21393
- { name: "A5", short: 148, long: 210 },
21394
- { name: "A4", short: 210, long: 297 },
21395
- { name: "A3", short: 297, long: 420 },
21396
- { name: "A2", short: 420, long: 594 },
21397
- { name: "A1", short: 594, long: 841 },
21398
- { name: "A0", short: 841, long: 1189 }
21417
+ { name: "A5", series: "ISO", short: 148, long: 210 },
21418
+ { name: "A4", series: "ISO", short: 210, long: 297 },
21419
+ { name: "A3", series: "ISO", short: 297, long: 420 },
21420
+ { name: "A2", series: "ISO", short: 420, long: 594 },
21421
+ { name: "A1", series: "ISO", short: 594, long: 841 },
21422
+ { name: "A0", series: "ISO", short: 841, long: 1189 },
21423
+ // The sizes US plan sets are printed on, 9 × 12 to 36 × 48 inches; E1, 30 × 42, comes between D and E.
21424
+ { name: "ARCH A", series: "ARCH", short: 9 * INCH, long: 12 * INCH },
21425
+ { name: "ARCH B", series: "ARCH", short: 12 * INCH, long: 18 * INCH },
21426
+ { name: "ARCH C", series: "ARCH", short: 18 * INCH, long: 24 * INCH },
21427
+ { name: "ARCH D", series: "ARCH", short: 24 * INCH, long: 36 * INCH },
21428
+ { name: "ARCH E1", series: "ARCH", short: 30 * INCH, long: 42 * INCH },
21429
+ { name: "ARCH E", series: "ARCH", short: 36 * INCH, long: 48 * INCH },
21430
+ // The engineering sizes of ASME Y14.1: A is US Letter, B is Tabloid (11 × 17), each next one twice the one before.
21431
+ { name: "ANSI A", series: "ANSI", short: 8.5 * INCH, long: 11 * INCH },
21432
+ { name: "ANSI B", series: "ANSI", short: 11 * INCH, long: 17 * INCH },
21433
+ { name: "ANSI C", series: "ANSI", short: 17 * INCH, long: 22 * INCH },
21434
+ { name: "ANSI D", series: "ANSI", short: 22 * INCH, long: 34 * INCH },
21435
+ { name: "ANSI E", series: "ANSI", short: 34 * INCH, long: 44 * INCH }
21399
21436
  ];
21400
21437
  var DEFAULT_PAPER_SCALE = 100;
21401
21438
  function paperFormat(paper) {
@@ -21926,6 +21963,12 @@ function seenFrom(facing, viewer2) {
21926
21963
  return c >= Math.SQRT1_2 - 1e-9 ? "front" : c <= -Math.SQRT1_2 + 1e-9 ? "back" : "side";
21927
21964
  }
21928
21965
  var standingWeight = (p) => (p.kind === "path" || p.kind === "ellipse") && p.strokeWidth === void 0 ? { ...p, strokeWidth: STANDING_WEIGHT } : p;
21966
+ function shownOnPlan(doc, node2) {
21967
+ for (let at2 = node2, depth = 0; at2 && at2.type !== "page" && depth < 64; at2 = at2.parent ? doc.nodes[at2.parent] : void 0, depth++) {
21968
+ if (!isVisible(doc, at2)) return false;
21969
+ }
21970
+ return true;
21971
+ }
21929
21972
  function layout(view, doc, registry3, measure = () => []) {
21930
21973
  const line2 = lineOf(doc, view);
21931
21974
  if (!line2) return { prims: [], items: [] };
@@ -21962,7 +22005,7 @@ function layout(view, doc, registry3, measure = () => []) {
21962
22005
  const box2 = prims.map(primitiveBounds).reduce((all, one) => one ? all ? unionBounds(all, one) : one : all, null);
21963
22006
  const kind = object3.type === "parametric" ? registry3.parametric.get(object3.kind) : void 0;
21964
22007
  if (box2) {
21965
- const item = { node: object3, role, box: box2, raises: role === "fixed" || !!kind?.sill };
22008
+ const item = { node: object3, role, box: box2, raises: role !== "opening" || !!kind?.sill };
21966
22009
  items.push(item);
21967
22010
  if (prims[0]) drawnFirst.set(item, prims[0]);
21968
22011
  }
@@ -21971,7 +22014,7 @@ function layout(view, doc, registry3, measure = () => []) {
21971
22014
  const deep = depthOf(node2);
21972
22015
  const front = viewer(node2.a, node2.b);
21973
22016
  const off = (p) => dot(sub(p, node2.a), front);
21974
- const walls = wallsIn(doc, node2.parent);
22017
+ const walls = wallsIn(doc, node2.parent).filter((wall) => shownOnPlan(doc, wall));
21975
22018
  const layers = [];
21976
22019
  const depthOn = (outline2) => (s) => sightDepth(outline2, s, along2, off);
21977
22020
  const seenOf = (points) => clipConvex(convexHull(points), seenArea(node2));
@@ -22010,6 +22053,7 @@ function layout(view, doc, registry3, measure = () => []) {
22010
22053
  layers.push({ from, to, depth: depthOn(ends2), prims: faces });
22011
22054
  faces.push({ kind: "path", points: box(from, to, 0, height), closed: true, fill: WALL_SEEN, own: true });
22012
22055
  for (const { node: opening } of wallOpenings(doc, wall, registry3)) {
22056
+ if (!shownOnPlan(doc, opening)) continue;
22013
22057
  const kind = registry3.parametric.get(opening.kind);
22014
22058
  if (!kind) continue;
22015
22059
  const props = registry3.resolveProps(kind, opening.props);
@@ -22021,6 +22065,7 @@ function layout(view, doc, registry3, measure = () => []) {
22021
22065
  faces.push(...shown(opening, "opening", own2 ? placed(opening, own2, 0) : [{ kind: "path", points: box(Math.min(s0, s1), Math.max(s0, s1), bottom, top), closed: true }]));
22022
22066
  }
22023
22067
  for (const object3 of wallMounted(doc, wall, registry3)) {
22068
+ if (!shownOnPlan(doc, object3)) continue;
22024
22069
  const origin = applyTransform({ x: 0, y: 0 }, object3);
22025
22070
  if (mountOf(object3, registry3)?.on !== "wall" || mountedOn(doc, object3, registry3)?.face !== face || !within(along2(origin)) || !between(origin)) continue;
22026
22071
  const kind = registry3.parametric.get(object3.kind);
@@ -22074,15 +22119,16 @@ function layout(view, doc, registry3, measure = () => []) {
22074
22119
  layers.push({ from: run.from, to: run.to, depth: run.depth, prims: [{ kind: "path", points: box(run.from, run.to, 0, run.height), closed: true, fill: WALL_GREY, own: true }] });
22075
22120
  }
22076
22121
  for (const leaf of drawnBy ? leavesOf(doc, rootOf(doc, node2.parent)?.id ?? "") : []) {
22077
- if (leaf.type !== "instance" && leaf.type !== "parametric") continue;
22122
+ if (leaf.type !== "instance" && leaf.type !== "parametric" || !shownOnPlan(doc, leaf)) continue;
22078
22123
  if (leaf.type === "parametric" && (mountOf(leaf, registry3)?.on === "wall" || openingSpan(leaf, registry3))) continue;
22079
22124
  let tall;
22080
22125
  let looks = null;
22126
+ const raised = heightAboveFloor(leaf, registry3) ?? 0;
22081
22127
  if (leaf.type === "parametric") {
22082
22128
  const kind = registry3.parametric.get(leaf.kind);
22083
22129
  const props = kind ? registry3.resolveProps(kind, leaf.props) : {};
22084
22130
  tall = kind?.height?.(props);
22085
- looks = kind ? seenAs(leaf, props, 0) : null;
22131
+ looks = kind ? seenAs(leaf, props, raised) : null;
22086
22132
  } else {
22087
22133
  const component = doc.nodes[leaf.component];
22088
22134
  tall = component?.type === "component" && component.height ? component.height * (leaf.scale ?? 1) : void 0;
@@ -22097,12 +22143,12 @@ function layout(view, doc, registry3, measure = () => []) {
22097
22143
  const from = Math.max(0, Math.min(...ss));
22098
22144
  const to = Math.min(length, Math.max(...ss));
22099
22145
  if (to - from < 1) continue;
22100
- const drawn = looks ? looks.map(standingWeight) : [{ kind: "path", points: box(from, to, 0, tall), closed: true, strokeWidth: STANDING_WEIGHT, own: true }];
22146
+ const drawn = looks ? looks.map(standingWeight) : [{ kind: "path", points: box(from, to, raised, raised + tall), closed: true, strokeWidth: STANDING_WEIGHT, own: true }];
22101
22147
  layers.push({ from, to, depth: depthOn(seenOf(points)), prims: shown(leaf, "standing", drawn) });
22102
22148
  }
22103
22149
  const onFaces = new Set(items.filter((item) => item.role === "fixed").map((item) => item.node.id));
22104
22150
  for (const leaf of drawnBy ? leavesOf(doc, rootOf(doc, node2.parent)?.id ?? "") : []) {
22105
- if (leaf.type !== "parametric" || onFaces.has(leaf.id) || mountOf(leaf, registry3)?.on !== "wall") continue;
22151
+ if (leaf.type !== "parametric" || onFaces.has(leaf.id) || mountOf(leaf, registry3)?.on !== "wall" || !shownOnPlan(doc, leaf)) continue;
22106
22152
  const points = drawnBy(leaf, doc, registry3).flatMap(outlineOf);
22107
22153
  if (points.length === 0) continue;
22108
22154
  const offs = points.map(off);
@@ -23811,6 +23857,7 @@ function mountOf(node2, registry3) {
23811
23857
  return mount?.on === "wall" || mount?.on === "floor" ? mount : null;
23812
23858
  }
23813
23859
  function heightAboveFloor(node2, registry3) {
23860
+ if (node2.type === "instance") return node2.z ?? null;
23814
23861
  if (node2.type !== "parametric") return null;
23815
23862
  const mount = mountOf(node2, registry3);
23816
23863
  return node2.z ?? (mount?.on === "wall" ? mount.height ?? null : null);
@@ -25970,7 +26017,7 @@ ${JSON.stringify(kinds)}
25970
26017
 
25971
26018
  Kinds with "cutsWalls" are doors and windows. One cuts an opening when it lies on a wall: put its insertion point (x, y) in the middle of the wall's thickness (on its line for a wall without "justify", half its thickness off it towards the wall otherwise) and set its rotation to the wall's direction, the angle from the wall's "a" to "b". The opening then runs along the wall from the insertion point for its width. It adapts to the wall's thickness by itself, and moves with the wall only by being on it.
25972
26019
 
25973
- Kinds with "fixedOnWall" (sockets, switches, wall lights) are fixed on a face of a wall, and follow the wall when it changes only while they are exactly on it. Their own point (0, back) lies on the face, their own X along it, and they stand out of the wall into the room towards their own +Y, or -Y when "out" is "up". For a wall whose direction from "a" to "b" is the angle \u03B8, that is rotation \u03B8 on its right face (the face to the right as it runs from a to b, at +90\xB0 from its direction since Y grows downward) and \u03B8 + 180 on its left face, adding 180 to either when "out" is "up"; then place the insertion point so that (0, back) turned by that rotation lands on the face. "z" on such an object is its height above the floor in mm, to its centre; left out, it is the "height" given. Kinds with "againstWall" (kitchen units, a fridge, a washbasin) stand on the floor with their back against a face, placed by the same rule, and have no height above the floor.
26020
+ Kinds with "fixedOnWall" (sockets, switches, wall lights) are fixed on a face of a wall, and follow the wall when it changes only while they are exactly on it. Their own point (0, back) lies on the face, their own X along it, and they stand out of the wall into the room towards their own +Y, or -Y when "out" is "up". For a wall whose direction from "a" to "b" is the angle \u03B8, that is rotation \u03B8 on its right face (the face to the right as it runs from a to b, at +90\xB0 from its direction since Y grows downward) and \u03B8 + 180 on its left face, adding 180 to either when "out" is "up"; then place the insertion point so that (0, back) turned by that rotation lands on the face. "z" on such an object is its height above the floor in mm, to its centre; left out, it is the "height" given. Kinds with "againstWall" (kitchen units, a fridge, a washbasin) stand on the floor with their back against a face, placed by the same rule. Anything else, and a placement of a component, stands on the floor too unless given "z", the height of its underside above the floor in mm (a raised unit, a shelf, a mirror), which elevations draw it at.
25974
26021
 
25975
26022
  A "group" holds several nodes so they are selected, moved and stacked as one. It has no coordinates of its own: to group nodes, add a group and set their "parent" to its id; to move a group, move the nodes inside it. Its "opacity" (0 to 1, 1 when left out) makes everything inside it see-through.
25976
26023
 
@@ -25986,7 +26033,7 @@ A "link" joins two objects of the same page by their ids, "from" and "to", throu
25986
26033
 
25987
26034
  An elevation or a section is two nodes: a "viewline" on the plan (a to b, and depth), which says what is seen, and an "elevation" that refers to it by "line" and says where its view is drawn (x, y, on any page). For an elevation of a wall's face, put the viewline 1000 in front of the face, with depth 1000, running so that the face is on its left (seen from its right); add the viewline before its view. Removing a viewline removes its views.
25988
26035
 
25989
- A "paper" is a sheet laid over the drawing that frames what goes on one printed page. Its width and height are in drawing millimetres: the sheet's real size times its "scale" (an A3 lying at 1:100 is 42000 \xD7 29700). It has no children; whatever lies inside its rectangle is on it. Give it "titleBlock": {} (optionally with "project", "author", "date", "number") for a border and a title block; the person exports papers to PDF at their true scale from the File menu.
26036
+ A "paper" is a sheet laid over the drawing that frames what goes on one printed page. Its width and height are in drawing millimetres: the sheet's real size times its "scale" (an A3 lying at 1:100 is 42000 \xD7 29700; an ARCH D, 24 \xD7 36 inches, lying at 1:48 is 43891.2 \xD7 29260.8). It has no children; whatever lies inside its rectangle is on it. Give it "titleBlock": {} (optionally with "project", "author", "date", "number") for a border and a title block; the person exports papers to PDF at their true scale from the File menu.
25990
26037
 
25991
26038
  A "dimension" shows the distance between "a" and "b"; "offset" is how far its line stands off them. An "annotation" is a note with a leader from the tip "a" to the text at "b". Texts may hold fields that are filled in when drawn: {date}, {page}, {page-number}, {pages}, {document}.
25992
26039
 
@@ -27271,6 +27318,9 @@ async function runDrawingTool(name, given, host2) {
27271
27318
  }
27272
27319
  }
27273
27320
 
27321
+ // packages/core/src/elevation-grips.ts
27322
+ var ALONG = Math.SQRT1_2 - 1e-9;
27323
+
27274
27324
  // packages/ext-architecture/src/shared.ts
27275
27325
  var THIN2 = { strokeWidth: 0.5 };
27276
27326
  var HEAVY = { strokeWidth: 2 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencalque",
3
- "version": "1.10.2",
3
+ "version": "1.11.0",
4
4
  "description": "Draw 2D floor plans as JSON: walls, doors, rooms, furniture. Check, measure, export PDF, DXF, SVG.",
5
5
  "keywords": [
6
6
  "floor plan",