@snaptrude/plugin-core 0.9.5 → 0.9.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/api-manifest.full.json +8442 -0
  3. package/api-manifest.json +221 -7
  4. package/dist/api/core/camera/index.d.ts +16 -0
  5. package/dist/api/core/camera/index.d.ts.map +1 -1
  6. package/dist/api/core/io/import/index.d.ts +3 -1
  7. package/dist/api/core/io/import/index.d.ts.map +1 -1
  8. package/dist/api/core/project/index.d.ts +68 -1
  9. package/dist/api/core/project/index.d.ts.map +1 -1
  10. package/dist/api/core/storeys/index.d.ts +14 -0
  11. package/dist/api/core/storeys/index.d.ts.map +1 -1
  12. package/dist/api/design/create/bulk-items.d.ts +177 -0
  13. package/dist/api/design/create/bulk-items.d.ts.map +1 -0
  14. package/dist/api/design/create/index.d.ts +273 -8
  15. package/dist/api/design/create/index.d.ts.map +1 -1
  16. package/dist/api/design/create/opening-fields.d.ts +29 -0
  17. package/dist/api/design/create/opening-fields.d.ts.map +1 -0
  18. package/dist/api/design/delete/index.d.ts +4 -0
  19. package/dist/api/design/delete/index.d.ts.map +1 -1
  20. package/dist/api/design/dimensions.d.ts +427 -0
  21. package/dist/api/design/dimensions.d.ts.map +1 -0
  22. package/dist/api/design/furniture/index.d.ts +33 -0
  23. package/dist/api/design/furniture/index.d.ts.map +1 -1
  24. package/dist/api/design/index.d.ts +5 -0
  25. package/dist/api/design/index.d.ts.map +1 -1
  26. package/dist/api/design/visibility.d.ts +28 -0
  27. package/dist/api/design/visibility.d.ts.map +1 -1
  28. package/dist/api/presentation/annotate.d.ts +2 -2
  29. package/dist/api/presentation/shapes.d.ts +2 -2
  30. package/dist/handles.d.ts +19 -0
  31. package/dist/handles.d.ts.map +1 -1
  32. package/dist/index.cjs +2019 -1865
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.js +1994 -1865
  35. package/dist/index.js.map +1 -1
  36. package/package.json +13 -13
  37. package/src/api/core/camera/index.ts +17 -0
  38. package/src/api/core/io/import/index.ts +11 -3
  39. package/src/api/core/project/index.ts +62 -1
  40. package/src/api/core/storeys/index.ts +15 -0
  41. package/src/api/design/create/bulk-items.ts +182 -0
  42. package/src/api/design/create/index.ts +296 -18
  43. package/src/api/design/create/opening-fields.ts +29 -0
  44. package/src/api/design/delete/index.ts +4 -0
  45. package/src/api/design/dimensions.ts +453 -0
  46. package/src/api/design/furniture/index.ts +34 -0
  47. package/src/api/design/index.ts +5 -0
  48. package/src/api/design/visibility.ts +34 -0
  49. package/src/handles.ts +24 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snaptrude/plugin-core",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -16,17 +16,6 @@
16
16
  "publishConfig": {
17
17
  "access": "public"
18
18
  },
19
- "scripts": {
20
- "check-types": "tsc --noEmit",
21
- "build": "tsup --clean",
22
- "dev": "tsup --watch",
23
- "clean-dist": "rm -rf dist",
24
- "test": "node --test test/*.test.mjs",
25
- "generate:manifest": "node scripts/generate-manifest.mjs",
26
- "generate:manifest:check": "node scripts/generate-manifest.mjs --check",
27
- "generate:manifest:all": "node scripts/generate-manifest.mjs --all",
28
- "generate:manifest:all:check": "node scripts/generate-manifest.mjs --all --check"
29
- },
30
19
  "devDependencies": {
31
20
  "ts-morph": "^28.0.0",
32
21
  "tsup": "^8.5.1",
@@ -37,5 +26,16 @@
37
26
  },
38
27
  "peerDependencies": {
39
28
  "zod": "^3.25.0 || ^4.0.0"
29
+ },
30
+ "scripts": {
31
+ "check-types": "tsc --noEmit",
32
+ "build": "tsup --clean",
33
+ "dev": "tsup --watch",
34
+ "clean-dist": "rm -rf dist",
35
+ "test": "node --test test/*.test.mjs",
36
+ "generate:manifest": "node scripts/generate-manifest.mjs",
37
+ "generate:manifest:check": "node scripts/generate-manifest.mjs --check",
38
+ "generate:manifest:all": "node scripts/generate-manifest.mjs --all",
39
+ "generate:manifest:all:check": "node scripts/generate-manifest.mjs --all --check"
40
40
  }
41
- }
41
+ }
@@ -62,6 +62,23 @@ export abstract class PluginCameraApi {
62
62
  view: PluginStandardView,
63
63
  ): PluginApiReturn<boolean>
64
64
 
65
+ /**
66
+ * Get the current camera mode. Paired with {@linkcode PluginCameraApi.setMode}.
67
+ *
68
+ * @returns `"2d"` when the editor is in plan view, `"3d"` otherwise.
69
+ *
70
+ * @examplePrompt Am I in 2D or 3D?
71
+ * @examplePrompt What view mode is the editor in?
72
+ *
73
+ * # Example
74
+ * ```ts
75
+ * if ((await snaptrude.core.camera.getMode()) === "2d") {
76
+ * await snaptrude.core.camera.setMode("3d")
77
+ * }
78
+ * ```
79
+ */
80
+ public abstract getMode(): PluginApiReturn<PluginCameraMode>
81
+
65
82
  /**
66
83
  * Toggle the modelling mode between `2d` (plan) and `3d`. Mirrors the canvas
67
84
  * 2D/3D toggle: `3d` enters the isometric perspective view, `2d` drops to the
@@ -183,7 +183,10 @@ export abstract class PluginCoreIoImportApi {
183
183
  * if (cad) console.log("DWG imported as CAD underlay:", cad)
184
184
  * ```
185
185
  */
186
- public abstract dwg(source: string, storey?: number): PluginApiReturn<ImportJobHandle>
186
+ public abstract dwg(
187
+ source: string,
188
+ storey?: number,
189
+ ): PluginApiReturn<ImportJobHandle>
187
190
 
188
191
  /**
189
192
  * Sketch a CAD underlay from **already-parsed CAD JSON** — synchronous, with no
@@ -214,7 +217,10 @@ export abstract class PluginCoreIoImportApi {
214
217
  * )
215
218
  * ```
216
219
  */
217
- public abstract cadJson(cad: CadJsonInput, storey?: number): PluginApiReturn<UnderlayHandle>
220
+ public abstract cadJson(
221
+ cad: CadJsonInput,
222
+ storey?: number,
223
+ ): PluginApiReturn<UnderlayHandle>
218
224
 
219
225
  /**
220
226
  * Import a **3D model** file and place it in the scene as a component.
@@ -239,7 +245,9 @@ export abstract class PluginCoreIoImportApi {
239
245
  * @returns the placed {@linkcode ComponentHandle}.
240
246
  * @throws if writes are disabled, the source can't be loaded, the format is
241
247
  * unsupported, conversion/placement fails, or the converted model cannot be
242
- * found in the library after upload.
248
+ * found in the library after upload; `PRECONDITION_FAILED`
249
+ * (`details.engineCode: "TOOL_ACTIVE"`) while the interactive furniture tool is
250
+ * active — finish or cancel it first.
243
251
  *
244
252
  * @examplePrompt Import this SketchUp model onto storey 1
245
253
  * @examplePrompt Bring in this OBJ file and place it at the origin
@@ -1,15 +1,47 @@
1
1
  import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../../types"
3
+ import { PUnitType } from "../units"
3
4
 
4
5
  /**
5
6
  * Project-level settings and info.
6
7
  *
7
- * Accessed via `snaptrude.core.project`. Currently exposes
8
+ * Accessed via `snaptrude.core.project`. Exposes
9
+ * {@linkcode PluginProjectApi.getInfo} (project identity) and
8
10
  * {@linkcode PluginProjectApi.settings} (snap + grid controls).
9
11
  */
10
12
  export abstract class PluginProjectApi {
11
13
  constructor() {}
12
14
 
15
+ /**
16
+ * Read identity and headline facts about the currently open project — id,
17
+ * display name, unit type, storey count, active storey, and site location
18
+ * when the project is geo-located.
19
+ *
20
+ * `activeStorey` and `storeyCount` are both scoped to the ACTIVE BUILDING, so
21
+ * they always describe the same building. In a multi-building project
22
+ * `storeyCount` is therefore NOT the total across every building — use
23
+ * `core.storeys.list()`, which spans all buildings, for that.
24
+ *
25
+ * @returns A {@linkcode PluginProjectInfo}. `name` is `null` only when the
26
+ * project genuinely has no title; `location` is `null` only when the project
27
+ * is not geo-located. Neither is used to signal a failure.
28
+ * @throws PRECONDITION_FAILED when no project is open.
29
+ * @throws OPERATION_FAILED when the project lookup or the site-location read
30
+ * fails. A failed read is never reported as `null`.
31
+ *
32
+ * @examplePrompt What is this project called?
33
+ * @examplePrompt Where is this project located?
34
+ * @examplePrompt Give me a summary of this project
35
+ * @examplePrompt How many storeys does this project have?
36
+ *
37
+ * # Example
38
+ * ```ts
39
+ * const info = await snaptrude.core.project.getInfo()
40
+ * console.log(info.name, info.units, info.storeyCount)
41
+ * ```
42
+ */
43
+ public abstract getInfo(): PluginApiReturn<PluginProjectInfo>
44
+
13
45
  /** Project settings — snaps and grid. See {@linkcode PluginProjectSettingsApi}. */
14
46
  public abstract settings: PluginProjectSettingsApi
15
47
  }
@@ -416,3 +448,32 @@ export const PluginToleranceArgs = z.object({
416
448
  })
417
449
 
418
450
  export type PluginToleranceArgs = z.infer<typeof PluginToleranceArgs>
451
+
452
+ /**
453
+ * Identity and headline facts about the currently open project.
454
+ *
455
+ * `location` is a read-only projection of {@linkcode PluginProgramSiteApi.getLocation}
456
+ * — `program.site.*` remains the full site surface (context, weather, polygons).
457
+ * It is mirrored here because "what and where is this project" is one question.
458
+ *
459
+ * | Property | Type | Description |
460
+ * |---|---|---|
461
+ * | `projectId` | `string` | The open project's id (floorkey) |
462
+ * | `name` | `string \| null` | Display name; `null` only when the project has no title (a failed lookup throws) |
463
+ * | `units` | {@linkcode PUnitType} | The project's unit type |
464
+ * | `activeStorey` | `number` | The active storey value, in the active building |
465
+ * | `storeyCount` | `number` | How many storeys the ACTIVE BUILDING has (not the project-wide total — `core.storeys.list()` spans all buildings) |
466
+ * | `location` | `{ latitude, longitude } \| null` | Site location; `null` only when not geo-located (a failed read throws) |
467
+ */
468
+ export const PluginProjectInfo = z.object({
469
+ projectId: z.string(),
470
+ name: z.string().nullable(),
471
+ units: PUnitType,
472
+ activeStorey: z.number(),
473
+ storeyCount: z.number(),
474
+ location: z
475
+ .object({ latitude: z.number(), longitude: z.number() })
476
+ .nullable(),
477
+ })
478
+
479
+ export type PluginProjectInfo = z.infer<typeof PluginProjectInfo>
@@ -160,6 +160,21 @@ export abstract class PluginCoreStoreysApi {
160
160
  options?: { name?: string },
161
161
  ): PluginApiReturn<PluginStoryUpdateResult>
162
162
 
163
+ /**
164
+ * Get the active storey's value. Paired with {@linkcode PluginCoreStoreysApi.setActive}.
165
+ *
166
+ * @returns The active storey value, in the same numbering `list` and `get` use.
167
+ *
168
+ * @examplePrompt Which storey am I on?
169
+ * @examplePrompt What is the current storey?
170
+ *
171
+ * # Example
172
+ * ```ts
173
+ * const storey = await snaptrude.core.storeys.getActive()
174
+ * ```
175
+ */
176
+ public abstract getActive(): PluginApiReturn<number>
177
+
163
178
  /**
164
179
  * Make a storey the active storey — the same as clicking it in the storey/layer
165
180
  * panel. Subsequent draws and creates target this storey, and in 2D the
@@ -0,0 +1,182 @@
1
+ import * as z from "zod"
2
+ import { ContourHandle, ProfileHandle, Vec3Handle } from "../../../handles"
3
+ import { PluginOpeningBaseOptions } from "./opening-fields"
4
+
5
+ /**
6
+ * Maximum items per bulk `design.create.*` call. A bounded request keeps
7
+ * validation, command capture and rollback work finite; split a larger import
8
+ * into separate awaited batches, each with its own undo entry.
9
+ */
10
+ export const PLUGIN_CREATE_BATCH_LIMIT = 1000
11
+
12
+ // ---------------------------------------------------------------------------
13
+ // wallRuns
14
+ // ---------------------------------------------------------------------------
15
+
16
+ /**
17
+ * One wall run to create via {@linkcode PluginDesignCreateApi.wallRuns} — the
18
+ * same inputs as {@linkcode PluginDesignCreateApi.walls}, one run per item.
19
+ *
20
+ * | Property | Type | Description |
21
+ * |---|---|---|
22
+ * | `profile` | {@linkcode ProfileHandle} | Ordered curve chain (wall centerlines) |
23
+ * | `height` | `number`? | Wall height (Snaptrude units, > 0; default engine default) |
24
+ * | `thickness` | `number`? | Wall thickness (Snaptrude units, > 0; default: `wallType`'s total layer thickness when given, else engine default) |
25
+ * | `wallType` | `string`? | Wall type name from `design.types.list("wall")` — layers/material/thickness defaults (default generic) |
26
+ * | `storey` | `number`? (int) | Target storey (must exist) — the run's walls are assigned + lifted to its base in the same undo entry (default: geometry-derived) |
27
+ */
28
+ export const PluginCreateWallRunItem = z.object({
29
+ profile: ProfileHandle,
30
+ height: z.number().optional(),
31
+ thickness: z.number().optional(),
32
+ wallType: z.string().min(1).optional(),
33
+ storey: z.number().int().optional(),
34
+ })
35
+ export type PluginCreateWallRunItem = z.infer<typeof PluginCreateWallRunItem>
36
+
37
+ /** The `items` array of {@linkcode PluginDesignCreateApi.wallRuns} (1…1000). */
38
+ export const PluginCreateWallRunItems = z
39
+ .array(PluginCreateWallRunItem)
40
+ .min(1)
41
+ .max(PLUGIN_CREATE_BATCH_LIMIT)
42
+ export type PluginCreateWallRunItems = z.infer<typeof PluginCreateWallRunItems>
43
+
44
+ // ---------------------------------------------------------------------------
45
+ // floors
46
+ // ---------------------------------------------------------------------------
47
+
48
+ /**
49
+ * One floor to create via {@linkcode PluginDesignCreateApi.floors} — the same
50
+ * footprint-extrude inputs as {@linkcode PluginDesignCreateApi.floor}.
51
+ *
52
+ * | Property | Type | Description |
53
+ * |---|---|---|
54
+ * | `contour` | {@linkcode ContourHandle} | Footprint (outer profile + holes) |
55
+ * | `thickness` | `number` | Floor thickness (Snaptrude units, > 0) |
56
+ * | `position` | {@linkcode Vec3Handle}? | Offset from origin (default origin) |
57
+ */
58
+ export const PluginCreateFloorItem = z.object({
59
+ contour: ContourHandle,
60
+ thickness: z.number(),
61
+ position: Vec3Handle.optional(),
62
+ })
63
+ export type PluginCreateFloorItem = z.infer<typeof PluginCreateFloorItem>
64
+
65
+ /** The `items` array of {@linkcode PluginDesignCreateApi.floors} (1…1000). */
66
+ export const PluginCreateFloorItems = z
67
+ .array(PluginCreateFloorItem)
68
+ .min(1)
69
+ .max(PLUGIN_CREATE_BATCH_LIMIT)
70
+ export type PluginCreateFloorItems = z.infer<typeof PluginCreateFloorItems>
71
+
72
+ // ---------------------------------------------------------------------------
73
+ // doors / windows
74
+ // ---------------------------------------------------------------------------
75
+
76
+ /**
77
+ * One door to place via {@linkcode PluginDesignCreateApi.doors} — the same
78
+ * fields as a `"door"` {@linkcode PluginDesignCreateOpeningOptions}, so the
79
+ * size overrides singular {@linkcode PluginDesignCreateApi.door} lacks are
80
+ * available per item. `facing` is a WORLD POINT on the side of the wall the
81
+ * door opens into, not a direction. Rejects unknown fields.
82
+ *
83
+ * | Property | Type | Description |
84
+ * |---|---|---|
85
+ * | `catalogId` | `string` | Library id: team `_id` or general `fullName` |
86
+ * | `hostWall` | {@linkcode ComponentHandle} | The wall to host the door |
87
+ * | `position` | {@linkcode Vec3Handle} | World point projected onto the wall |
88
+ * | `facing` | {@linkcode Vec3Handle}? | World point on the side the door faces (default engine-chosen) |
89
+ * | `label` | `string`? | Instance name (optional) |
90
+ * | `width` | `number`? | Width override (Snaptrude units, > 0; default the catalog item's) |
91
+ * | `height` | `number`? | Height override (Snaptrude units, > 0; default the catalog item's) |
92
+ */
93
+ export const PluginCreateDoorItem = z
94
+ .object({ ...PluginOpeningBaseOptions })
95
+ .strict()
96
+ export type PluginCreateDoorItem = z.infer<typeof PluginCreateDoorItem>
97
+
98
+ /** The `items` array of {@linkcode PluginDesignCreateApi.doors} (1…1000). */
99
+ export const PluginCreateDoorItems = z
100
+ .array(PluginCreateDoorItem)
101
+ .min(1)
102
+ .max(PLUGIN_CREATE_BATCH_LIMIT)
103
+ export type PluginCreateDoorItems = z.infer<typeof PluginCreateDoorItems>
104
+
105
+ /**
106
+ * One window to place via {@linkcode PluginDesignCreateApi.windows} — the same
107
+ * fields as a `"window"` {@linkcode PluginDesignCreateOpeningOptions}.
108
+ * `sillHeight` is a nonnegative Snaptrude-unit distance from the host wall's
109
+ * base to the BOTTOM of the window, not to its center. `facing` is a WORLD
110
+ * POINT on the desired side of the wall, not a direction. Rejects unknown
111
+ * fields.
112
+ *
113
+ * | Property | Type | Description |
114
+ * |---|---|---|
115
+ * | `catalogId` | `string` | Library id: team `_id` or general `fullName` |
116
+ * | `hostWall` | {@linkcode ComponentHandle} | The wall to host the window |
117
+ * | `position` | {@linkcode Vec3Handle} | World point projected onto the wall |
118
+ * | `facing` | {@linkcode Vec3Handle}? | World point on the side the window faces (default engine-chosen) |
119
+ * | `label` | `string`? | Instance name (optional) |
120
+ * | `width` | `number`? | Width override (Snaptrude units, > 0; default the catalog item's) |
121
+ * | `height` | `number`? | Height override (Snaptrude units, > 0; default the catalog item's) |
122
+ * | `sillHeight` | `number`? | Wall base to window bottom (Snaptrude units, ≥ 0; default the catalog item's) |
123
+ */
124
+ export const PluginCreateWindowItem = z
125
+ .object({
126
+ ...PluginOpeningBaseOptions,
127
+ sillHeight: z.number().finite().nonnegative().optional(),
128
+ })
129
+ .strict()
130
+ export type PluginCreateWindowItem = z.infer<typeof PluginCreateWindowItem>
131
+
132
+ /** The `items` array of {@linkcode PluginDesignCreateApi.windows} (1…1000). */
133
+ export const PluginCreateWindowItems = z
134
+ .array(PluginCreateWindowItem)
135
+ .min(1)
136
+ .max(PLUGIN_CREATE_BATCH_LIMIT)
137
+ export type PluginCreateWindowItems = z.infer<typeof PluginCreateWindowItems>
138
+
139
+ // ---------------------------------------------------------------------------
140
+ // furnitureItems
141
+ // ---------------------------------------------------------------------------
142
+
143
+ /**
144
+ * One furniture instance to place via
145
+ * {@linkcode PluginDesignCreateApi.furnitureItems} — the same inputs as
146
+ * {@linkcode PluginDesignCreateApi.furniture} minus `createNewSourceMesh`: in a
147
+ * batch the host owns source-mesh persistence (a source is recorded once per
148
+ * call, however many items reuse it).
149
+ *
150
+ * `position.y` is the REST elevation: the item is grounded so its bounding-box
151
+ * base sits exactly at `position.y` (the same surface-flush contract as
152
+ * interactive drag-drop) — pass the floor/storey elevation to stand furniture
153
+ * on it; never add half the item's height yourself.
154
+ *
155
+ * | Property | Type | Description |
156
+ * |---|---|---|
157
+ * | `catalogId` | `string` | Library id: team `_id` or general `fullName` |
158
+ * | `position` | {@linkcode Vec3Handle} | Absolute world placement point (`y` = rest elevation) |
159
+ * | `label` | `string`? | Instance name and readable label (default auto `${name}Ins${n}`) |
160
+ * | `angleInDegrees` | `number`? | Rotation about the vertical axis, in degrees (default unrotated) |
161
+ */
162
+ export const PluginCreateFurnitureItem = z.object({
163
+ catalogId: z.string().min(1),
164
+ position: Vec3Handle,
165
+ label: z.string().optional(),
166
+ angleInDegrees: z.number().optional(),
167
+ })
168
+ export type PluginCreateFurnitureItem = z.infer<
169
+ typeof PluginCreateFurnitureItem
170
+ >
171
+
172
+ /**
173
+ * The `items` array of {@linkcode PluginDesignCreateApi.furnitureItems}
174
+ * (1…1000).
175
+ */
176
+ export const PluginCreateFurnitureItems = z
177
+ .array(PluginCreateFurnitureItem)
178
+ .min(1)
179
+ .max(PLUGIN_CREATE_BATCH_LIMIT)
180
+ export type PluginCreateFurnitureItems = z.infer<
181
+ typeof PluginCreateFurnitureItems
182
+ >