@snaptrude/plugin-core 1.0.2 → 1.0.4

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 (106) hide show
  1. package/AGENTS.md +17 -0
  2. package/CHANGELOG.md +12 -0
  3. package/api-manifest.json +130 -2098
  4. package/dist/api/core/camera/index.d.ts +16 -6
  5. package/dist/api/core/camera/index.d.ts.map +1 -1
  6. package/dist/api/core/comment/index.d.ts +7 -3
  7. package/dist/api/core/comment/index.d.ts.map +1 -1
  8. package/dist/api/core/geom/create/index.d.ts +69 -21
  9. package/dist/api/core/geom/create/index.d.ts.map +1 -1
  10. package/dist/api/core/geom/query/circle.d.ts +31 -11
  11. package/dist/api/core/geom/query/circle.d.ts.map +1 -1
  12. package/dist/api/core/geom/query/contour.d.ts +19 -7
  13. package/dist/api/core/geom/query/contour.d.ts.map +1 -1
  14. package/dist/api/core/geom/query/curve.d.ts +72 -24
  15. package/dist/api/core/geom/query/curve.d.ts.map +1 -1
  16. package/dist/api/core/geom/query/profile.d.ts +19 -7
  17. package/dist/api/core/geom/query/profile.d.ts.map +1 -1
  18. package/dist/api/core/geom/update/contour.d.ts +36 -12
  19. package/dist/api/core/geom/update/contour.d.ts.map +1 -1
  20. package/dist/api/core/geom/update/curve.d.ts +13 -5
  21. package/dist/api/core/geom/update/curve.d.ts.map +1 -1
  22. package/dist/api/core/geom/update/profile.d.ts +36 -12
  23. package/dist/api/core/geom/update/profile.d.ts.map +1 -1
  24. package/dist/api/core/io/import/index.d.ts +7 -3
  25. package/dist/api/core/io/import/index.d.ts.map +1 -1
  26. package/dist/api/core/math/quat.d.ts +2 -2
  27. package/dist/api/core/math/quat.d.ts.map +1 -1
  28. package/dist/api/core/math/vec3.d.ts +15 -15
  29. package/dist/api/core/math/vec3.d.ts.map +1 -1
  30. package/dist/api/core/storeys/index.d.ts +5 -0
  31. package/dist/api/core/storeys/index.d.ts.map +1 -1
  32. package/dist/api/design/boolean/index.d.ts +20 -4
  33. package/dist/api/design/boolean/index.d.ts.map +1 -1
  34. package/dist/api/design/create/bulk-items.d.ts +88 -17
  35. package/dist/api/design/create/bulk-items.d.ts.map +1 -1
  36. package/dist/api/design/create/index.d.ts +146 -59
  37. package/dist/api/design/create/index.d.ts.map +1 -1
  38. package/dist/api/design/create/opening-fields.d.ts +18 -6
  39. package/dist/api/design/create/opening-fields.d.ts.map +1 -1
  40. package/dist/api/design/delete/index.d.ts +14 -7
  41. package/dist/api/design/delete/index.d.ts.map +1 -1
  42. package/dist/api/design/dimensions.d.ts +12 -4
  43. package/dist/api/design/dimensions.d.ts.map +1 -1
  44. package/dist/api/design/doors/index.d.ts +37 -0
  45. package/dist/api/design/doors/index.d.ts.map +1 -1
  46. package/dist/api/design/edit/index.d.ts +7 -3
  47. package/dist/api/design/edit/index.d.ts.map +1 -1
  48. package/dist/api/design/family.d.ts +5 -1
  49. package/dist/api/design/family.d.ts.map +1 -1
  50. package/dist/api/design/index.d.ts +1 -0
  51. package/dist/api/design/index.d.ts.map +1 -1
  52. package/dist/api/design/lock.d.ts +3 -0
  53. package/dist/api/design/lock.d.ts.map +1 -1
  54. package/dist/api/design/opening-placement.d.ts +135 -0
  55. package/dist/api/design/opening-placement.d.ts.map +1 -0
  56. package/dist/api/design/transform/index.d.ts +28 -8
  57. package/dist/api/design/transform/index.d.ts.map +1 -1
  58. package/dist/api/design/windows/index.d.ts +23 -0
  59. package/dist/api/design/windows/index.d.ts.map +1 -1
  60. package/dist/api/entity/space.d.ts +30 -6
  61. package/dist/api/entity/space.d.ts.map +1 -1
  62. package/dist/api/entity/story.d.ts +4 -0
  63. package/dist/api/entity/story.d.ts.map +1 -1
  64. package/dist/api/presentation/drawings.d.ts +1 -1
  65. package/dist/api/presentation/views.d.ts +5 -1
  66. package/dist/api/presentation/views.d.ts.map +1 -1
  67. package/dist/handles.d.ts +8 -0
  68. package/dist/handles.d.ts.map +1 -1
  69. package/dist/index.cjs +2510 -2427
  70. package/dist/index.cjs.map +1 -1
  71. package/dist/index.js +2506 -2427
  72. package/dist/index.js.map +1 -1
  73. package/package.json +13 -13
  74. package/src/api/core/camera/index.ts +9 -7
  75. package/src/api/core/comment/index.ts +3 -3
  76. package/src/api/core/geom/create/index.ts +25 -25
  77. package/src/api/core/geom/query/circle.ts +11 -11
  78. package/src/api/core/geom/query/contour.ts +7 -6
  79. package/src/api/core/geom/query/curve.ts +25 -25
  80. package/src/api/core/geom/query/profile.ts +7 -6
  81. package/src/api/core/geom/update/contour.ts +12 -11
  82. package/src/api/core/geom/update/curve.ts +5 -5
  83. package/src/api/core/geom/update/profile.ts +12 -11
  84. package/src/api/core/io/import/index.ts +3 -2
  85. package/src/api/core/math/quat.ts +2 -2
  86. package/src/api/core/math/vec3.ts +16 -16
  87. package/src/api/core/storeys/index.ts +5 -0
  88. package/src/api/design/boolean/index.ts +2 -2
  89. package/src/api/design/create/bulk-items.ts +11 -3
  90. package/src/api/design/create/index.ts +46 -46
  91. package/src/api/design/create/opening-fields.ts +7 -7
  92. package/src/api/design/delete/index.ts +14 -7
  93. package/src/api/design/dimensions.ts +5 -4
  94. package/src/api/design/doors/index.ts +43 -0
  95. package/src/api/design/edit/index.ts +3 -3
  96. package/src/api/design/family.ts +2 -1
  97. package/src/api/design/index.ts +1 -0
  98. package/src/api/design/lock.ts +6 -0
  99. package/src/api/design/opening-placement.ts +79 -0
  100. package/src/api/design/transform/index.ts +15 -7
  101. package/src/api/design/windows/index.ts +29 -0
  102. package/src/api/entity/space.ts +5 -4
  103. package/src/api/entity/story.ts +4 -0
  104. package/src/api/presentation/views.ts +7 -2
  105. package/src/handles.ts +11 -0
  106. package/test/handles.test.mjs +36 -0
@@ -1,6 +1,6 @@
1
1
  import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../../types"
3
- import { ComponentHandle, Vec3Handle } from "../../../handles"
3
+ import { ComponentHandle, Vec3Handle, Vec3Input } from "../../../handles"
4
4
  import { PluginDesignChangeResult } from "../lock"
5
5
 
6
6
  /**
@@ -22,9 +22,17 @@ export abstract class PluginDesignTransformApi {
22
22
  * component's absolute position as the anchor). Undoable.
23
23
  *
24
24
  * @param components - Entities to move
25
- * @param displacement - Relative translation as a {@linkcode Vec3Handle}
25
+ * @param displacement - Relative translation as a {@linkcode Vec3Handle}. A displacement
26
+ * shorter than 1e-6 is a no-op that succeeds (hosts before Oct 2026 throw
27
+ * `OPERATION_FAILED` "No movement occurred" instead, so skip the call when nothing moves).
26
28
  * @param options - `is2D`, `trackParentChange`
27
29
  * @returns {@linkcode PluginDesignChangeResult}
30
+ * @throws `OPERATION_FAILED` when the engine drops the whole move. A single connected
31
+ * parametric wall moves only across its own line: the vertical part and the part along
32
+ * the line are dropped. Move the whole connected run in one call to lift walls; to slide
33
+ * or lengthen one wall, delete it and create it again on the new line. Graph-bound walls
34
+ * made by Sketch-to-BIM refuse `move` outright (`TOPOLOGY_ERROR` / `ZERO_MOVEMENT`):
35
+ * adjust the room boundary that owns the wall instead.
28
36
  *
29
37
  * @examplePrompt Move the selected room 5 metres to the right
30
38
  * @examplePrompt Shift these walls 3m along the x axis
@@ -43,7 +51,7 @@ export abstract class PluginDesignTransformApi {
43
51
  */
44
52
  public abstract move(
45
53
  components: ComponentHandle[],
46
- displacement: Vec3Handle,
54
+ displacement: Vec3Input,
47
55
  options?: { is2D?: boolean; trackParentChange?: boolean },
48
56
  ): PluginApiReturn<PluginDesignChangeResult>
49
57
 
@@ -81,7 +89,7 @@ export abstract class PluginDesignTransformApi {
81
89
  public abstract rotate(
82
90
  components: ComponentHandle[],
83
91
  angleInDegrees: number,
84
- options?: { axis?: Vec3Handle; pivot?: Vec3Handle; is2D?: boolean },
92
+ options?: { axis?: Vec3Input; pivot?: Vec3Input; is2D?: boolean },
85
93
  ): PluginApiReturn<PluginDesignChangeResult>
86
94
 
87
95
  /**
@@ -205,7 +213,7 @@ export type PluginAlignEdge = z.infer<typeof PluginAlignEdge>
205
213
  */
206
214
  export const PluginDesignMoveArgs = z.object({
207
215
  components: z.array(ComponentHandle).min(1),
208
- displacement: Vec3Handle,
216
+ displacement: Vec3Input,
209
217
  is2D: z.boolean().optional(),
210
218
  trackParentChange: z.boolean().optional(),
211
219
  })
@@ -217,9 +225,9 @@ export type PluginDesignMoveArgs = z.infer<typeof PluginDesignMoveArgs>
217
225
  export const PluginDesignRotateArgs = z.object({
218
226
  components: z.array(ComponentHandle).min(1),
219
227
  angleInDegrees: z.number(),
220
- axis: Vec3Handle.optional(),
228
+ axis: Vec3Input.optional(),
221
229
  is2D: z.boolean().optional(),
222
- pivot: Vec3Handle.optional(),
230
+ pivot: Vec3Input.optional(),
223
231
  })
224
232
  export type PluginDesignRotateArgs = z.infer<typeof PluginDesignRotateArgs>
225
233
 
@@ -3,6 +3,10 @@ import { PluginApiReturn } from "../../../types"
3
3
  import { ComponentHandle } from "../../../handles"
4
4
  import { PluginDesignChangeResult } from "../lock"
5
5
  import { PluginObjectCatalogGroup, PluginObjectCatalogItem } from "../doors"
6
+ import type {
7
+ PluginOpeningPlacementArgs,
8
+ PluginOpeningPlacementResult,
9
+ } from "../opening-placement"
6
10
 
7
11
  /**
8
12
  * `snaptrude.design.windows` — window-specific reads. Creation lives at
@@ -22,6 +26,31 @@ import { PluginObjectCatalogGroup, PluginObjectCatalogItem } from "../doors"
22
26
  export abstract class PluginDesignWindowsApi {
23
27
  constructor() {}
24
28
 
29
+ /**
30
+ * Trial the native host fit and geometry rebuild, then restore the model without publishing commands.
31
+ * The first result uses the creation options; subsequent results use candidateWidths in input order.
32
+ * Widths are authored parameters, not physical envelopes or a guaranteed maximum width.
33
+ * No catalog save, history entry or model persistence occurs. Rerun after model edits.
34
+ * A failed fit leaves cut unverified. Family-host cuts are also unverified: their rebuild
35
+ * cannot supply a reversible, authoritative trial result. Material clearance checks evaluated
36
+ * parts against physical neighbours across hosts. The intended host uses native fit/cut checks.
37
+ * Creation repeats clearance immediately before placement; this report grants no later approval.
38
+ * Editing permission is required; locked hosts and an active opening tool reject.
39
+ * A requested width/height on a family sized by its Type (Custom Sizes off) picks the Type
40
+ * within 25 mm, else turns Custom Sizes on; each result's `sizing` says which. Creation
41
+ * (`design.create.window(s)`) applies the same rule, so the size you pass is the size built.
42
+ * @param options Window creation options and up to 12 alternative widths; numeric lengths use SU.
43
+ * @returns Separate fit/cut/clearance evidence, evaluated bounds and explicit limitations.
44
+ * @examplePrompt Check whether this window fits and its host can be cut
45
+ * @example
46
+ * const result = await snaptrude.design.windows.checkPlacement({
47
+ * familyId, version, hostWall, position, width: 4, sillHeight: 3,
48
+ * })
49
+ */
50
+ public abstract checkPlacement(
51
+ options: PluginOpeningPlacementArgs,
52
+ ): PluginApiReturn<PluginOpeningPlacementResult>
53
+
25
54
  /**
26
55
  * Get the type name of a window — the label that identifies which kind of
27
56
  * window the instance is, as shown in its properties.
@@ -6,6 +6,7 @@ import * as z from "zod"
6
6
  import {
7
7
  ProfileHandle,
8
8
  Vec3Handle,
9
+ Vec3Input,
9
10
  Vec3Components,
10
11
  QuatComponents,
11
12
  CurveHandle,
@@ -21,7 +22,7 @@ import {
21
22
  * | `dimensions` | `{ width, height, depth }` | Box dimensions in Babylon units |
22
23
  */
23
24
  export const PluginSpaceCreateRectangularArgs = z.object({
24
- position: Vec3Handle,
25
+ position: Vec3Input,
25
26
  dimensions: z.object({
26
27
  width: z.number(),
27
28
  height: z.number(),
@@ -62,7 +63,7 @@ export const PluginSpaceCreateFromProfileArgs = z.object({
62
63
  profile: ProfileHandle,
63
64
  innerProfiles: z.array(ProfileHandle).optional(),
64
65
  extrudeHeight: z.number(),
65
- position: Vec3Handle,
66
+ position: Vec3Input,
66
67
  })
67
68
 
68
69
  export type PluginSpaceCreateFromProfileArgs = z.infer<
@@ -466,7 +467,7 @@ export type PluginSpaceUpdateResult = z.infer<typeof PluginSpaceUpdateResult>
466
467
  export const PluginSpaceBulkCreateItem = z.discriminatedUnion("kind", [
467
468
  z.object({
468
469
  kind: z.literal("rectangular"),
469
- position: Vec3Handle,
470
+ position: Vec3Input,
470
471
  dimensions: z.object({
471
472
  width: z.number(),
472
473
  height: z.number(),
@@ -482,7 +483,7 @@ export const PluginSpaceBulkCreateItem = z.discriminatedUnion("kind", [
482
483
  profile: ProfileHandle,
483
484
  innerProfiles: z.array(ProfileHandle).optional(),
484
485
  extrudeHeight: z.number(),
485
- position: Vec3Handle,
486
+ position: Vec3Input,
486
487
  room_type: z.string().optional(),
487
488
  spaceType: PluginSpaceType.optional(),
488
489
  massType: PluginMassType.optional(),
@@ -88,6 +88,10 @@ export abstract class PluginStoryApi {
88
88
  * @returns A {@linkcode PluginStoryCreateResult} with `storyId` and `storyValue`
89
89
  * @throws If a story with the given value already exists or creation fails
90
90
  *
91
+ * Storeys are added at the ends of the stack only: a value above the top also creates
92
+ * every storey in between (returning only the requested one), and a value inside a gap
93
+ * is refused.
94
+ *
91
95
  * @examplePrompt Add a third floor to the building
92
96
  * @examplePrompt Create a new storey above the second floor
93
97
  * @examplePrompt Add a basement level to this project
@@ -522,8 +522,13 @@ export type PluginPresentationViewsCreateArgs = z.infer<
522
522
  typeof PluginPresentationViewsCreateArgs
523
523
  >
524
524
 
525
- /** Result of {@linkcode PluginPresentationViewsApi.create} — the saved view. */
526
- export const PluginPresentationViewsCreateResult = PluginPresentationView
525
+ /**
526
+ * Result of {@linkcode PluginPresentationViewsApi.create} — the saved view, plus `framed`:
527
+ * whether the view was framed on the given elements or bounds (always `false` without `frame`).
528
+ */
529
+ export const PluginPresentationViewsCreateResult = PluginPresentationView.extend({
530
+ framed: z.boolean().optional(),
531
+ })
527
532
  export type PluginPresentationViewsCreateResult = z.infer<
528
533
  typeof PluginPresentationViewsCreateResult
529
534
  >
package/src/handles.ts CHANGED
@@ -288,6 +288,17 @@ export const EdgeHandle = handleSchema("edge")
288
288
  export const HalfEdgeHandle = handleSchema("halfedge")
289
289
  export const VertexHandle = handleSchema("vertex")
290
290
  export const Vec3Components = z.object({ x: z.number(), y: z.number(), z: z.number() })
291
+ /**
292
+ * A vec3 ARGUMENT: a {@linkcode Vec3Handle} in any inbound form, or a plain finite
293
+ * `{ x, y, z }` point. Geometry reads return plain points, and callers pass them straight
294
+ * back where a vec3 is expected; the host resolves the point as a vector. Returns stay
295
+ * {@linkcode Vec3Handle}. Explicitly typed to keep handles.d.ts inside its size budget.
296
+ */
297
+ export type Vec3Input = Handle<"vec3"> | Vec3Components
298
+ export const Vec3Input: z.ZodUnion<readonly [typeof Vec3Handle, typeof Vec3Components]> = z.union(
299
+ [Vec3Handle, Vec3Components],
300
+ { error: 'expected a "vec3" handle or a plain { x, y, z } point' }
301
+ )
291
302
  export const QuatComponents = z.object({
292
303
  x: z.number(),
293
304
  y: z.number(),
@@ -0,0 +1,36 @@
1
+ // Node built-in test runner suite for the handle schemas.
2
+ // Imports the BUILT package (dist) — run `pnpm build` first.
3
+ import test from "node:test"
4
+ import assert from "node:assert/strict"
5
+ import { Vec3Handle, Vec3Input, Handle, PluginDesignMoveArgs } from "../dist/index.js"
6
+
7
+ test("a vec3 handle parses in every inbound form, and only as a handle", () => {
8
+ for (const v of ["vec3_abc", new Handle("vec3_abc"), { __h: "vec3_abc" }, { id: "vec3_abc" }]) {
9
+ const out = Vec3Handle.parse(v)
10
+ assert.ok(out instanceof Handle)
11
+ assert.equal(out.id, "vec3_abc")
12
+ }
13
+ assert.equal(Vec3Handle.safeParse({ x: 1, y: 2, z: 3 }).success, false)
14
+ const bad = Vec3Handle.safeParse("profile_1")
15
+ assert.equal(bad.success, false)
16
+ assert.match(bad.error.issues[0].message, /expected a "vec3" handle/)
17
+ })
18
+
19
+ test("Vec3Input takes a handle or a plain { x, y, z } point", () => {
20
+ // Geometry reads return plain points; agents pass them back where a vec3 belongs.
21
+ const point = { x: 1, y: 2.5, z: -3 }
22
+ assert.deepEqual(Vec3Input.parse(point), point)
23
+ assert.ok(Vec3Input.parse("vec3_abc") instanceof Handle)
24
+ const args = PluginDesignMoveArgs.parse({ components: ["wl_1"], displacement: { x: 0, y: 0, z: 10 } })
25
+ assert.deepEqual(args.displacement, { x: 0, y: 0, z: 10 })
26
+ const handled = PluginDesignMoveArgs.parse({ components: ["wl_1"], displacement: "vec3_d" })
27
+ assert.equal(handled.displacement.id, "vec3_d")
28
+ })
29
+
30
+ test("Vec3Input still rejects non-points and wrong handles, with one message", () => {
31
+ for (const v of [{ x: 1, y: 2 }, { x: 1, y: Number.NaN, z: 3 }, { x: "1", y: 2, z: 3 }, "profile_1", null, 42]) {
32
+ const r = Vec3Input.safeParse(v)
33
+ assert.equal(r.success, false, JSON.stringify(v))
34
+ assert.equal(r.error.issues[0].message, 'expected a "vec3" handle or a plain { x, y, z } point')
35
+ }
36
+ })