@snaptrude/plugin-core 0.5.0 → 0.7.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 (134) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/api-manifest.full.json +2644 -542
  3. package/api-manifest.json +2606 -424
  4. package/dist/api/analysis/heatmaps.d.ts +234 -0
  5. package/dist/api/analysis/heatmaps.d.ts.map +1 -0
  6. package/dist/api/analysis/illuminance.d.ts +145 -0
  7. package/dist/api/analysis/illuminance.d.ts.map +1 -0
  8. package/dist/api/analysis/index.d.ts +44 -0
  9. package/dist/api/analysis/index.d.ts.map +1 -0
  10. package/dist/api/analysis/shadows.d.ts +165 -0
  11. package/dist/api/analysis/shadows.d.ts.map +1 -0
  12. package/dist/api/analysis/sunlightHours.d.ts +208 -0
  13. package/dist/api/analysis/sunlightHours.d.ts.map +1 -0
  14. package/dist/api/analysis/sunpath.d.ts +80 -0
  15. package/dist/api/analysis/sunpath.d.ts.map +1 -0
  16. package/dist/api/core/index.d.ts +10 -0
  17. package/dist/api/core/index.d.ts.map +1 -1
  18. package/dist/api/core/io/import/index.d.ts +392 -0
  19. package/dist/api/core/io/import/index.d.ts.map +1 -0
  20. package/dist/api/core/io/index.d.ts +35 -0
  21. package/dist/api/core/io/index.d.ts.map +1 -0
  22. package/dist/api/core/io/job/index.d.ts +139 -0
  23. package/dist/api/core/io/job/index.d.ts.map +1 -0
  24. package/dist/api/core/io/query/index.d.ts +74 -0
  25. package/dist/api/core/io/query/index.d.ts.map +1 -0
  26. package/dist/api/core/io/terrain/index.d.ts +206 -0
  27. package/dist/api/core/io/terrain/index.d.ts.map +1 -0
  28. package/dist/api/core/io/underlay/index.d.ts +286 -0
  29. package/dist/api/core/io/underlay/index.d.ts.map +1 -0
  30. package/dist/api/core/layers.d.ts +7 -7
  31. package/dist/api/core/proposals/index.d.ts +475 -0
  32. package/dist/api/core/proposals/index.d.ts.map +1 -0
  33. package/dist/api/design/create/index.d.ts +218 -0
  34. package/dist/api/design/create/index.d.ts.map +1 -1
  35. package/dist/api/design/doors/index.d.ts +159 -0
  36. package/dist/api/design/doors/index.d.ts.map +1 -1
  37. package/dist/api/design/furniture/index.d.ts +34 -5
  38. package/dist/api/design/furniture/index.d.ts.map +1 -1
  39. package/dist/api/design/index.d.ts +83 -0
  40. package/dist/api/design/index.d.ts.map +1 -1
  41. package/dist/api/design/lock.d.ts +26 -0
  42. package/dist/api/design/lock.d.ts.map +1 -1
  43. package/dist/api/design/materials/index.d.ts +159 -2
  44. package/dist/api/design/materials/index.d.ts.map +1 -1
  45. package/dist/api/design/query/index.d.ts +115 -5
  46. package/dist/api/design/query/index.d.ts.map +1 -1
  47. package/dist/api/design/query/spaces.d.ts +3 -3
  48. package/dist/api/design/selection/index.d.ts +144 -0
  49. package/dist/api/design/selection/index.d.ts.map +1 -1
  50. package/dist/api/design/transform/index.d.ts +83 -2
  51. package/dist/api/design/transform/index.d.ts.map +1 -1
  52. package/dist/api/design/update/index.d.ts +168 -0
  53. package/dist/api/design/update/index.d.ts.map +1 -1
  54. package/dist/api/design/windows/index.d.ts +113 -2
  55. package/dist/api/design/windows/index.d.ts.map +1 -1
  56. package/dist/api/entity/space.d.ts +2 -2
  57. package/dist/api/entity/story.d.ts +101 -7
  58. package/dist/api/entity/story.d.ts.map +1 -1
  59. package/dist/api/index.d.ts +5 -0
  60. package/dist/api/index.d.ts.map +1 -1
  61. package/dist/api/presentation/import.d.ts +49 -4
  62. package/dist/api/presentation/import.d.ts.map +1 -1
  63. package/dist/api/presentation/views.d.ts +210 -5
  64. package/dist/api/presentation/views.d.ts.map +1 -1
  65. package/dist/api/program/areas.d.ts +42 -12
  66. package/dist/api/program/areas.d.ts.map +1 -1
  67. package/dist/api/program/index.d.ts +3 -11
  68. package/dist/api/program/index.d.ts.map +1 -1
  69. package/dist/api/program/layout.d.ts +186 -11
  70. package/dist/api/program/layout.d.ts.map +1 -1
  71. package/dist/api/program/site.d.ts +84 -0
  72. package/dist/api/program/site.d.ts.map +1 -1
  73. package/dist/errors/codes.d.ts +34 -0
  74. package/dist/errors/codes.d.ts.map +1 -0
  75. package/dist/errors/envelope.d.ts +56 -0
  76. package/dist/errors/envelope.d.ts.map +1 -0
  77. package/dist/errors/index.d.ts +6 -0
  78. package/dist/errors/index.d.ts.map +1 -0
  79. package/dist/errors/plugin-error.d.ts +69 -0
  80. package/dist/errors/plugin-error.d.ts.map +1 -0
  81. package/dist/handles.d.ts +33 -0
  82. package/dist/handles.d.ts.map +1 -1
  83. package/dist/host-utils.d.ts +4 -0
  84. package/dist/host-utils.d.ts.map +1 -1
  85. package/dist/index.cjs +1942 -998
  86. package/dist/index.cjs.map +1 -1
  87. package/dist/index.d.ts +1 -0
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/index.js +1810 -994
  90. package/dist/index.js.map +1 -1
  91. package/package.json +2 -1
  92. package/scripts/generate-manifest.test.mjs +103 -4
  93. package/src/api/analysis/heatmaps.ts +256 -0
  94. package/src/api/analysis/illuminance.ts +155 -0
  95. package/src/api/analysis/index.ts +46 -0
  96. package/src/api/analysis/shadows.ts +183 -0
  97. package/src/api/analysis/sunlightHours.ts +211 -0
  98. package/src/api/analysis/sunpath.ts +83 -0
  99. package/src/api/core/index.ts +10 -0
  100. package/src/api/core/io/import/index.ts +432 -0
  101. package/src/api/core/io/index.ts +37 -0
  102. package/src/api/core/io/job/index.ts +140 -0
  103. package/src/api/core/io/query/index.ts +71 -0
  104. package/src/api/core/io/terrain/index.ts +214 -0
  105. package/src/api/core/io/underlay/index.ts +295 -0
  106. package/src/api/core/proposals/index.ts +509 -0
  107. package/src/api/design/create/index.ts +258 -0
  108. package/src/api/design/doors/index.ts +168 -0
  109. package/src/api/design/erase/index.ts +1 -1
  110. package/src/api/design/furniture/index.ts +36 -5
  111. package/src/api/design/index.ts +87 -0
  112. package/src/api/design/lock.ts +27 -0
  113. package/src/api/design/materials/index.ts +182 -2
  114. package/src/api/design/query/index.ts +81 -0
  115. package/src/api/design/selection/index.ts +129 -0
  116. package/src/api/design/transform/index.ts +74 -2
  117. package/src/api/design/update/index.ts +167 -0
  118. package/src/api/design/windows/index.ts +128 -2
  119. package/src/api/entity/story.ts +105 -7
  120. package/src/api/index.ts +5 -0
  121. package/src/api/presentation/import.ts +45 -4
  122. package/src/api/presentation/views.ts +221 -5
  123. package/src/api/program/areas.ts +34 -12
  124. package/src/api/program/index.ts +3 -11
  125. package/src/api/program/layout.ts +195 -11
  126. package/src/api/program/site.ts +93 -0
  127. package/src/errors/codes.ts +136 -0
  128. package/src/errors/envelope.ts +75 -0
  129. package/src/errors/index.ts +21 -0
  130. package/src/errors/plugin-error.ts +134 -0
  131. package/src/handles.ts +46 -0
  132. package/src/host-utils.ts +4 -0
  133. package/src/index.ts +1 -0
  134. package/test/errors.test.mjs +184 -0
@@ -8,6 +8,7 @@ import {
8
8
  PluginAreaClass,
9
9
  PluginSpaceUpdateResult,
10
10
  } from "../../entity/space"
11
+ import { PluginDesignChangeResult } from "../lock"
11
12
 
12
13
  /**
13
14
  * Sparse property updates for a space. Only provided fields change.
@@ -44,6 +45,83 @@ export const PluginUpdateSpaceItem = z.object({
44
45
  })
45
46
  export type PluginUpdateSpaceItem = z.infer<typeof PluginUpdateSpaceItem>
46
47
 
48
+ /**
49
+ * Wire schema for {@linkcode PluginDesignUpdateApi.setLabel}.
50
+ *
51
+ * | Property | Type | Description |
52
+ * |---|---|---|
53
+ * | `component` | `ComponentHandle` | The component to relabel |
54
+ * | `label` | `string` | New label (non-empty after trimming) |
55
+ */
56
+ export const PluginDesignSetLabelArgs = z.object({
57
+ component: ComponentHandle,
58
+ label: z.string().trim().min(1),
59
+ })
60
+ export type PluginDesignSetLabelArgs = z.infer<typeof PluginDesignSetLabelArgs>
61
+
62
+ /**
63
+ * Sparse parametric updates for a staircase (all fields optional; at least one
64
+ * required). Only the fields you provide change. Consumed by
65
+ * {@linkcode PluginDesignUpdateApi.staircase}; the paired read is
66
+ * `design.query.getStaircaseParams`.
67
+ *
68
+ * All dimensions are in **engine units** (the same convention as
69
+ * `design.doors.setWidth`); `steps` is a unitless integer count. Height, riser,
70
+ * and step count are **coupled** (`staircaseHeight = steps × riser`); the two
71
+ * lock booleans govern which value recomputes — see the method JSDoc.
72
+ *
73
+ * | Property | Type | Description |
74
+ * |---|---|---|
75
+ * | `isStoreyHeightUnlocked` | `boolean`? | Unlock the staircase height from the storey height |
76
+ * | `isStaircaseHeightUnlocked` | `boolean`? | Unlock the height from `steps × riser` |
77
+ * | `storeyHeight` | `number`? | Storey height the stair sits within (engine units) |
78
+ * | `staircaseHeight` | `number`? | Total rise (engine units) |
79
+ * | `steps` | `number`? | Step count (unitless integer) |
80
+ * | `riser` | `number`? | Riser height (engine units) |
81
+ * | `tread` | `number`? | Tread depth (engine units) |
82
+ * | `width` | `number`? | Flight width (engine units) |
83
+ * | `depth` | `number`? | Slab/waist thickness (engine units) |
84
+ * | `wellSize` | `number`? | Stairwell gap (dogLegged / openWell / square) |
85
+ * | `flightStartDistAfterTurn` | `number`? | Flight offset after a turn (dogLegged / lShaped / square) |
86
+ * | `landingWidth` | `number`? | Landing depth (straight / dogLegged) |
87
+ * | `baseOffset` | `number`? | Vertical offset from the storey base (engine units) |
88
+ */
89
+ export const PluginStaircaseParamUpdates = z
90
+ .object({
91
+ isStoreyHeightUnlocked: z.boolean().optional(),
92
+ isStaircaseHeightUnlocked: z.boolean().optional(),
93
+ storeyHeight: z.number().optional(),
94
+ staircaseHeight: z.number().optional(),
95
+ steps: z.number().int().optional(),
96
+ riser: z.number().optional(),
97
+ tread: z.number().optional(),
98
+ width: z.number().optional(),
99
+ depth: z.number().optional(),
100
+ wellSize: z.number().optional(),
101
+ flightStartDistAfterTurn: z.number().optional(),
102
+ landingWidth: z.number().optional(),
103
+ baseOffset: z.number().optional(),
104
+ })
105
+ .refine((p) => Object.keys(p).length > 0, {
106
+ message:
107
+ "PluginStaircaseParamUpdates requires at least one field to change",
108
+ })
109
+ export type PluginStaircaseParamUpdates = z.infer<typeof PluginStaircaseParamUpdates>
110
+
111
+ /**
112
+ * Arguments for {@linkcode PluginDesignUpdateApi.staircase}.
113
+ *
114
+ * | Property | Type | Description |
115
+ * |---|---|---|
116
+ * | `staircases` | {@linkcode ComponentHandle}`[]` | The staircases to update |
117
+ * | `params` | {@linkcode PluginStaircaseParamUpdates} | Sparse parametric changes (≥ 1 field) |
118
+ */
119
+ export const PluginDesignUpdateStaircaseArgs = z.object({
120
+ staircases: z.array(ComponentHandle),
121
+ params: PluginStaircaseParamUpdates,
122
+ })
123
+ export type PluginDesignUpdateStaircaseArgs = z.infer<typeof PluginDesignUpdateStaircaseArgs>
124
+
47
125
  /**
48
126
  * `snaptrude.design.update` — edit existing scene entities (properties + geometry).
49
127
  *
@@ -53,6 +131,46 @@ export type PluginUpdateSpaceItem = z.infer<typeof PluginUpdateSpaceItem>
53
131
  export abstract class PluginDesignUpdateApi {
54
132
  constructor() {}
55
133
 
134
+ /**
135
+ * Set a component's **Label** — the same editable Label field the properties
136
+ * panel shows (doors, windows, furniture, spaces, and every other labelled
137
+ * component). The paired read is `design.query.getLabel`. Undoable; the
138
+ * canvas label text updates immediately.
139
+ *
140
+ * Strictly **per component**: labelling one door of a placed family never
141
+ * touches its sibling doors (the panel's Label edit, by contrast, applies to
142
+ * the whole family). On **legacy masses** without a space type, panel parity
143
+ * applies — a label matching a room-type preset with a height can also
144
+ * adjust the mass's height and material, exactly like typing it in the panel.
145
+ *
146
+ * Throws when the component is locked, the handle is gone/forged, the label
147
+ * is empty, or the component has no mesh to label. Re-applying the current
148
+ * label is a no-op that returns `true` without touching the undo stack.
149
+ *
150
+ * @param component - The component to relabel
151
+ * @param label - New label text (non-empty; leading/trailing whitespace trimmed)
152
+ * @returns `true` once the label is applied
153
+ *
154
+ * @examplePrompt Rename this door to D-101
155
+ * @examplePrompt Number all doors on storey 2 with a D-2-XX tag
156
+ * @examplePrompt Set the selected window's label to W-04
157
+ * @examplePrompt Tag every door with its fire rating
158
+ *
159
+ * # Example
160
+ * ```ts
161
+ * // Door tag numbering: label every door as D-<storey>-<n>, numbered per storey
162
+ * await snaptrude.design.selection.setByFilter({ types: ["door"] })
163
+ * const doors = await snaptrude.design.selection.get()
164
+ * const counts = {}
165
+ * for (const door of doors) {
166
+ * const { storey = 0 } = await snaptrude.design.query.getProperties(door)
167
+ * counts[storey] = (counts[storey] ?? 0) + 1
168
+ * await snaptrude.design.update.setLabel(door, `D-${storey}-${String(counts[storey]).padStart(2, "0")}`)
169
+ * }
170
+ * ```
171
+ */
172
+ public abstract setLabel(component: ComponentHandle, label: string): PluginApiReturn<boolean>
173
+
56
174
  /**
57
175
  * Update a single space (room) — change its properties (room label, space
58
176
  * type, mass type, area class, department) and/or replace its geometry by
@@ -114,4 +232,53 @@ export abstract class PluginDesignUpdateApi {
114
232
  * ```
115
233
  */
116
234
  public abstract spaces(items: PluginUpdateSpaceItem[]): PluginApiReturn<PluginSpaceUpdateResult[]>
235
+
236
+ /**
237
+ * Update the parameters of one or more staircases — riser, tread, width,
238
+ * depth, step count, total height, well size, landing depth, base offset,
239
+ * and the two height locks — in one undoable operation. Sparse: only the
240
+ * fields you provide change. The paired read is
241
+ * `design.query.getStaircaseParams`.
242
+ *
243
+ * All dimensions are in **engine units** (the same convention as
244
+ * `design.doors.setWidth`); `steps` is a unitless integer count. The height,
245
+ * riser, and step count are **coupled** — `staircaseHeight = steps × riser` —
246
+ * and the two lock booleans govern which value recomputes when another
247
+ * changes. With `isStoreyHeightUnlocked` false the staircase height follows
248
+ * the storey height; unlocking it also unlocks the staircase height. Setting
249
+ * `steps` recomputes `riser` (or the height, once the height is unlocked),
250
+ * and setting `riser` recomputes `steps`/height in turn.
251
+ *
252
+ * Presets-only: this edits the parametric fields of a preset staircase; it
253
+ * does not change the staircase's type/preset (there is no in-place re-type).
254
+ * Every edit rebuilds the staircase geometry, so the call is async.
255
+ *
256
+ * Throws when a handle is not a staircase, when a staircase is locked, or
257
+ * when a value falls outside the engine's accepted range (RPC rejects).
258
+ *
259
+ * @param staircases - the staircases to update
260
+ * @param params - sparse {@linkcode PluginStaircaseParamUpdates} (at least one field)
261
+ * @returns the affected staircases
262
+ *
263
+ * @examplePrompt Set the riser of this staircase to 165mm
264
+ * @examplePrompt Change all the stairs to 14 steps
265
+ * @examplePrompt Make the selected staircase 1200 wide with a 280 tread
266
+ * @examplePrompt Widen every staircase on level 1 to 1 metre
267
+ * @examplePrompt Unlock the height and set this stair to 3200 tall
268
+ *
269
+ * # Example
270
+ * ```ts
271
+ * // Give every ground-floor staircase a common riser + tread (engine units)
272
+ * const stairs = await snaptrude.design.query.listStaircases({ storeys: [1] })
273
+ * const { affected } = await snaptrude.design.update.staircase(stairs, {
274
+ * riser: 165,
275
+ * tread: 280,
276
+ * })
277
+ * console.log("updated", affected.length, "staircases")
278
+ * ```
279
+ */
280
+ public abstract staircase(
281
+ staircases: ComponentHandle[],
282
+ params: PluginStaircaseParamUpdates,
283
+ ): PluginApiReturn<PluginDesignChangeResult>
117
284
  }
@@ -2,14 +2,21 @@ import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../../types"
3
3
  import { ComponentHandle } from "../../../handles"
4
4
  import { PluginDesignChangeResult } from "../lock"
5
+ import { PluginObjectCatalogGroup, PluginObjectCatalogItem } from "../doors"
5
6
 
6
7
  /**
7
8
  * `snaptrude.design.windows` — window-specific reads. Creation lives at
8
9
  * `design.create.window`; generic reads (`listWindows`/`getHost`/`getProperties`) live
9
10
  * at `design.query.*`. Window targets are {@linkcode ComponentHandle}s.
10
11
  *
11
- * `listTypes` (UI-const catalog), `getSillHeight` (bounds-derived), and the
12
- * command-wired `mirror` land in a later pass.
12
+ * The **catalog** reads (`listCatalogGroups`/`listCatalog`/`getCatalogItem`/`exists`)
13
+ * browse the placeable window library — plain value records keyed by a library id
14
+ * (team `_id` or general `fullName`), NOT handles — and feed `design.create.window`.
15
+ * They are network-backed but carry no `Async` suffix (§6.6) and never throw
16
+ * (`[]`/`null`). The {@linkcode PluginObjectCatalogGroup} / {@linkcode PluginObjectCatalogItem}
17
+ * DTOs are shared with `design.doors` (defined there, re-exported here).
18
+ *
19
+ * `getSillHeight` (bounds-derived) and the command-wired `mirror` land in a later pass.
13
20
  */
14
21
  export abstract class PluginDesignWindowsApi {
15
22
  constructor() {}
@@ -148,6 +155,91 @@ export abstract class PluginDesignWindowsApi {
148
155
  window: ComponentHandle,
149
156
  height: number
150
157
  ): PluginApiReturn<PluginDesignChangeResult>
158
+
159
+ /**
160
+ * List the window catalog **groups** — the placement families (Fixed,
161
+ * Casement, Sliding, Folding, …), built-in groups merged with any
162
+ * team-custom types.
163
+ *
164
+ * @returns The groups as {@linkcode PluginObjectCatalogGroup}`[]` (`[]` when empty)
165
+ *
166
+ * @examplePrompt What kinds of windows can I place?
167
+ * @examplePrompt List the window groups in the catalog
168
+ * @examplePrompt Show me the window families available in this project
169
+ * @examplePrompt Which window types does this project support?
170
+ *
171
+ * # Example
172
+ * ```ts
173
+ * const groups = await snaptrude.design.windows.listCatalogGroups()
174
+ * for (const g of groups) console.log(g.dbType, g.label, g.source)
175
+ * ```
176
+ */
177
+ public abstract listCatalogGroups(): PluginApiReturn<PluginObjectCatalogGroup[]>
178
+
179
+ /**
180
+ * List the placeable window catalog (team + general libraries), optionally
181
+ * restricted to one group by its `dbType` token.
182
+ *
183
+ * @param group Restrict to one group's `dbType` (optional; e.g. `"casementDouble"`)
184
+ * @returns The catalog as {@linkcode PluginObjectCatalogItem}`[]` (`[]` when empty)
185
+ *
186
+ * @examplePrompt What windows can I place in this project?
187
+ * @examplePrompt List every window in the library
188
+ * @examplePrompt Show me the casement windows I can add
189
+ * @examplePrompt Browse the window catalog
190
+ *
191
+ * # Example
192
+ * ```ts
193
+ * const [group] = await snaptrude.design.windows.listCatalogGroups()
194
+ * const items = await snaptrude.design.windows.listCatalog(group?.dbType)
195
+ * for (const item of items) console.log(item.id, item.name, item.thumbnailUrl)
196
+ * ```
197
+ */
198
+ public abstract listCatalog(
199
+ group?: string
200
+ ): PluginApiReturn<PluginObjectCatalogItem[]>
201
+
202
+ /**
203
+ * Get a single window catalog item by its library id.
204
+ *
205
+ * @param id The catalog library id
206
+ * @returns The item, or `null` if no catalog item matches
207
+ *
208
+ * @examplePrompt Get the details of this window from the library
209
+ * @examplePrompt Look up the catalog entry for this window id
210
+ * @examplePrompt What is the cost of this window item?
211
+ * @examplePrompt Show me the family name of this window in the catalog
212
+ *
213
+ * # Example
214
+ * ```ts
215
+ * const [entry] = await snaptrude.design.windows.listCatalog()
216
+ * const item = await snaptrude.design.windows.getCatalogItem(entry.id)
217
+ * if (item) console.log(item.name, item.source, item.dbType)
218
+ * ```
219
+ */
220
+ public abstract getCatalogItem(
221
+ id: string
222
+ ): PluginApiReturn<PluginObjectCatalogItem | null>
223
+
224
+ /**
225
+ * Test whether a window catalog item exists for the given library id.
226
+ *
227
+ * @param id The catalog library id
228
+ * @returns `true` if it exists, otherwise `false`
229
+ *
230
+ * @examplePrompt Is this window still in the library?
231
+ * @examplePrompt Check whether a window catalog item with this id exists
232
+ * @examplePrompt Does my team library have this window?
233
+ * @examplePrompt Verify the window is available before placing it
234
+ *
235
+ * # Example
236
+ * ```ts
237
+ * const [entry] = await snaptrude.design.windows.listCatalog()
238
+ * const stillAvailable = await snaptrude.design.windows.exists(entry.id)
239
+ * console.log(stillAvailable ? "safe to place" : "removed from library")
240
+ * ```
241
+ */
242
+ public abstract exists(id: string): PluginApiReturn<boolean>
151
243
  }
152
244
 
153
245
  /**
@@ -205,3 +297,37 @@ export const PluginDesignWindowSetHeightArgs = z.object({
205
297
  height: z.number(),
206
298
  })
207
299
  export type PluginDesignWindowSetHeightArgs = z.infer<typeof PluginDesignWindowSetHeightArgs>
300
+
301
+ // ---------------------------------------------------------------------------
302
+ // catalog (shared DTOs defined in ../doors, re-exported here for symmetry)
303
+ // ---------------------------------------------------------------------------
304
+
305
+ // Re-export the shared catalog DTOs imported at the top of this file.
306
+ export { PluginObjectCatalogGroup, PluginObjectCatalogItem }
307
+
308
+ /**
309
+ * Arguments for {@linkcode PluginDesignWindowsApi.listCatalog}.
310
+ *
311
+ * | Property | Type | Description |
312
+ * |---|---|---|
313
+ * | `group` | `string`? | Restrict to one group's `dbType` token (optional) |
314
+ */
315
+ export const PluginDesignWindowListCatalogArgs = z.object({
316
+ group: z.string().optional(),
317
+ })
318
+ export type PluginDesignWindowListCatalogArgs = z.infer<typeof PluginDesignWindowListCatalogArgs>
319
+
320
+ /**
321
+ * Arguments for {@linkcode PluginDesignWindowsApi.getCatalogItem} / {@linkcode PluginDesignWindowsApi.exists}.
322
+ *
323
+ * | Property | Type | Description |
324
+ * |---|---|---|
325
+ * | `id` | `string` | The catalog library id |
326
+ */
327
+ export const PluginDesignWindowGetCatalogItemArgs = z.object({
328
+ id: z.string(),
329
+ })
330
+ export type PluginDesignWindowGetCatalogItemArgs = z.infer<typeof PluginDesignWindowGetCatalogItemArgs>
331
+
332
+ export const PluginDesignWindowExistsArgs = PluginDesignWindowGetCatalogItemArgs
333
+ export type PluginDesignWindowExistsArgs = z.infer<typeof PluginDesignWindowExistsArgs>
@@ -1,5 +1,6 @@
1
1
  import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../types"
3
+ import { ComponentHandle } from "../../handles"
3
4
 
4
5
  /**
5
6
  * Story (floor/storey) management.
@@ -101,17 +102,25 @@ export abstract class PluginStoryApi {
101
102
  ): PluginApiReturn<PluginStoryCreateResult>
102
103
 
103
104
  /**
104
- * Update a story's height.
105
+ * Update a story's floor-to-floor height, cascading the full geometry change.
105
106
  *
106
- * Changes the floor-to-floor height of the specified story. This
107
- * operation is undoable.
107
+ * This is the same operation as editing the height in the Stories panel: the
108
+ * walls, columns, and masses on the story are **stretched** to the new height,
109
+ * every story **above shifts up/down** by the delta so the stack stays
110
+ * contiguous, and coupled elements (staircases, parametric curtain walls,
111
+ * furniture offsets) are re-fitted. The whole cascade is committed as **one
112
+ * undo step**. Height-locked elements are left untouched.
108
113
  *
109
114
  * @param storyValue - Integer storey number
110
115
  * identifying the story to update
111
- * @param height - New height value in Babylon
112
- * units
116
+ * @param height - New floor-to-floor height in
117
+ * Babylon units
113
118
  * @returns A {@linkcode PluginStoryUpdateResult} with the updated `storyValue` and `height`
114
- * @throws If the story does not exist or the update fails
119
+ * @throws `PRECONDITION_FAILED` if no story has the given value;
120
+ * `STORY_HEIGHT_REJECTED` if the engine rejects the height (e.g. out of
121
+ * range — the change silently reverts host-side and is surfaced as this
122
+ * error); `STORY_UPDATE_FAILED` if the story cannot be re-read after the
123
+ * update
115
124
  *
116
125
  * @examplePrompt Change the ground floor height to 3.5 metres
117
126
  * @examplePrompt Make the second storey taller
@@ -120,7 +129,8 @@ export abstract class PluginStoryApi {
120
129
  *
121
130
  * # Example
122
131
  * ```ts
123
- * // Set ground floor height to 5 Babylon units
132
+ * // Set ground floor height to 5 Babylon units — walls stretch and the
133
+ * // floors above move up to match, all in a single undo step.
124
134
  * const result = await snaptrude.entity.story.update(1, 5)
125
135
  * ```
126
136
  */
@@ -128,6 +138,54 @@ export abstract class PluginStoryApi {
128
138
  storyValue: number,
129
139
  height: number,
130
140
  ): PluginApiReturn<PluginStoryUpdateResult>
141
+
142
+ /**
143
+ * Duplicate a story into the adjacent level, up or down.
144
+ *
145
+ * By default the **whole story** is duplicated: every eligible element on the
146
+ * active story (walls, floors, roofs, masses, columns, beams, staircases,
147
+ * ceilings, parametric curtain walls, and furniture) is copied into the story
148
+ * one level `"up"` or `"down"`. Pass `options.components` to duplicate only a
149
+ * subset instead. The target story is **created automatically** if it does not
150
+ * yet exist, inheriting the source story's height.
151
+ *
152
+ * Copies are **instanced** by default (`unique: false`) — they share geometry
153
+ * with the source, so later edits propagate. Set `unique: true` for independent
154
+ * geometry. Doors and windows are never duplicated on their own; they ride along
155
+ * with their host wall. Locked, throw-away, and unsupported elements are skipped
156
+ * and counted in `skipped`. The whole operation is a single undo step.
157
+ *
158
+ * @param direction - `"up"` to duplicate into the story above, `"down"` for below
159
+ * @param options - `components` (restrict to a subset of the story's elements;
160
+ * omit for the whole story) and `unique` (default `false` = instanced copies;
161
+ * `true` = independent geometry)
162
+ * @returns A {@linkcode PluginStoryDuplicateResult} with the `sourceStory`, the
163
+ * `targetStories` the copies landed on, the `created` component handles, the
164
+ * `createdStoryValues` for any stories generated to receive them, and the
165
+ * `skipped` count of ineligible elements
166
+ * @throws `NO_ACTIVE_STRUCTURE` if there is no active structure to duplicate
167
+ * into; `NO_ELIGIBLE_ELEMENTS` if nothing on the source story (or in
168
+ * `options.components`) is duplicable; `HANDLE_INVALID` for a stale or
169
+ * foreign supplied handle; or if plugin writes are disabled
170
+ *
171
+ * @examplePrompt Duplicate this floor to the storey above
172
+ * @examplePrompt Copy the ground floor down into a new basement
173
+ * @examplePrompt Repeat this level upwards with its own independent geometry
174
+ * @examplePrompt Duplicate just the selected walls onto the next floor up
175
+ *
176
+ * # Example
177
+ * ```ts
178
+ * // Duplicate the whole active story one level up (instanced copies).
179
+ * const { targetStories, created, skipped } =
180
+ * await snaptrude.entity.story.duplicate("up")
181
+ * console.log(`Copied ${created.length} elements onto story ${targetStories}`)
182
+ * if (skipped) console.log(`${skipped} elements were skipped`)
183
+ * ```
184
+ */
185
+ public abstract duplicate(
186
+ direction: "up" | "down",
187
+ options?: { components?: ComponentHandle[]; unique?: boolean },
188
+ ): PluginApiReturn<PluginStoryDuplicateResult>
131
189
  }
132
190
 
133
191
  /**
@@ -271,3 +329,43 @@ export const PluginStoryUpdateResult = z.object({
271
329
  })
272
330
 
273
331
  export type PluginStoryUpdateResult = z.infer<typeof PluginStoryUpdateResult>
332
+
333
+ /**
334
+ * Arguments for {@linkcode PluginStoryApi.duplicate} (options flattened).
335
+ *
336
+ * | Property | Type | Description |
337
+ * |---|---|---|
338
+ * | `direction` | `'up' \| 'down'` | Which adjacent story to duplicate into |
339
+ * | `components` | {@linkcode ComponentHandle}`[]?` | Restrict to a subset; omit for the whole story |
340
+ * | `unique` | `boolean?` | `false` (default) = instanced copies; `true` = independent geometry |
341
+ */
342
+ export const PluginStoryDuplicateArgs = z.object({
343
+ direction: z.enum(["up", "down"]),
344
+ components: z.array(ComponentHandle).optional(),
345
+ unique: z.boolean().optional(),
346
+ })
347
+
348
+ export type PluginStoryDuplicateArgs = z.infer<typeof PluginStoryDuplicateArgs>
349
+
350
+ /**
351
+ * Result of {@linkcode PluginStoryApi.duplicate}.
352
+ *
353
+ * | Property | Type | Description |
354
+ * |---|---|---|
355
+ * | `sourceStory` | `number` | Storey value the copies were duplicated from |
356
+ * | `targetStories` | `number[]` | Storey values the copies landed on |
357
+ * | `created` | {@linkcode ComponentHandle}`[]` | Handles of the newly created components |
358
+ * | `createdStoryValues` | `number[]` | Storey values that were generated to receive the copies |
359
+ * | `skipped` | `number` | Count of ineligible elements that were skipped |
360
+ */
361
+ export const PluginStoryDuplicateResult = z.object({
362
+ sourceStory: z.number(),
363
+ targetStories: z.array(z.number()),
364
+ created: z.array(ComponentHandle),
365
+ createdStoryValues: z.array(z.number()),
366
+ skipped: z.number(),
367
+ })
368
+
369
+ export type PluginStoryDuplicateResult = z.infer<
370
+ typeof PluginStoryDuplicateResult
371
+ >
package/src/api/index.ts CHANGED
@@ -3,6 +3,7 @@ import { PluginDesignApi } from "./design"
3
3
  import { PluginEntityApi } from "./entity"
4
4
  import { PluginProgramApi } from "./program"
5
5
  import { PluginPresentationApi } from "./presentation"
6
+ import { PluginAnalysisApi } from "./analysis"
6
7
 
7
8
  /**
8
9
  * Root API surface for Snaptrude plugins.
@@ -14,6 +15,7 @@ import { PluginPresentationApi } from "./presentation"
14
15
  * - {@linkcode PluginApi.entity} — CRUD operations on Snaptrude entities (spaces, stories)
15
16
  * - {@linkcode PluginApi.program} — Program-mode planning reads (departments, metrics)
16
17
  * - {@linkcode PluginApi.presentation} — Presentation preparation (views, AI Inspiration)
18
+ * - {@linkcode PluginApi.analysis} — Sustainability analysis (sunpath, shadows, sunlight/illuminance heatmaps)
17
19
  */
18
20
  export abstract class PluginApi {
19
21
  /** Core math, geometry, history, and units primitives. See {@linkcode PluginCoreApi}. */
@@ -26,6 +28,8 @@ export abstract class PluginApi {
26
28
  public abstract program: PluginProgramApi
27
29
  /** Presentation preparation reads — saved views. See {@linkcode PluginPresentationApi}. */
28
30
  public abstract presentation: PluginPresentationApi
31
+ /** Sustainability analysis — sun & daylight studies. See {@linkcode PluginAnalysisApi}. */
32
+ public abstract analysis: PluginAnalysisApi
29
33
 
30
34
  constructor() {}
31
35
  }
@@ -35,3 +39,4 @@ export * from "./design"
35
39
  export * from "./entity"
36
40
  export * from "./program"
37
41
  export * from "./presentation"
42
+ export * from "./analysis"
@@ -4,9 +4,10 @@ import { PluginApiReturn } from "../../types"
4
4
  /**
5
5
  * Presentation import — bring external reference assets onto the Present canvas.
6
6
  *
7
- * `import.image` places a reference image and `import.pdf` places a PDF (each
8
- * page vectorized to SVG) onto the current Present sheet, returning the created
9
- * canvas shape ids. Requires Present mode to be open.
7
+ * `import.image` places a reference image, `import.pdf` places a PDF (each
8
+ * page vectorized to SVG), and `import.svg` places a validated SVG onto
9
+ * the current Present sheet, returning the created canvas shape ids. Requires
10
+ * Present mode to be open.
10
11
  *
11
12
  * The host engine takes a browser `File`, which a plugin worker cannot supply,
12
13
  * so these accept a `url`/`dataUrl` that the host adapts into a `File`.
@@ -72,11 +73,51 @@ export abstract class PluginPresentationImportApi {
72
73
  source: { url?: string; dataUrl?: string },
73
74
  options?: { position?: { x: number; y: number } },
74
75
  ): PluginApiReturn<PluginPresentationImportResult>
76
+
77
+ /**
78
+ * Import an SVG onto the current Present sheet as a vector asset.
79
+ *
80
+ * An SVG-validating variant of {@linkcode PluginPresentationImportApi.image}:
81
+ * `import.image` already passes SVG sources through, but this method first
82
+ * validates that the source really is an SVG and forces the vector mime
83
+ * type. Throws if the source is not an SVG.
84
+ *
85
+ * **Rendering is vector up to a complexity cap.** Simple SVGs (up to ~1500
86
+ * SVG element nodes and ~2 MB) render true-vector and stay crisp at every
87
+ * zoom. Beyond that cap the shared canvas renderer **intentionally falls
88
+ * back to a 1920px raster** to protect canvas performance, so very complex
89
+ * SVGs can look rasterized when zoomed in. The stored asset is the original
90
+ * SVG either way; only the on-canvas rendering falls back.
91
+ *
92
+ * @param source - The SVG to import: exactly one of `url` or `dataUrl`.
93
+ * @param options - Optional `position` — where to place the SVG on the sheet.
94
+ * @returns A {@linkcode PluginPresentationImportResult} with the created
95
+ * `shapeIds`.
96
+ * @throws If Present mode is not open, the source is not an SVG, or it cannot
97
+ * be loaded.
98
+ *
99
+ * @examplePrompt Import this SVG diagram onto the present canvas
100
+ * @examplePrompt Add a vector logo to my presentation board
101
+ * @examplePrompt Place this SVG floor plan on the current sheet as vectors
102
+ * @examplePrompt Bring a crisp vector graphic into Present mode
103
+ *
104
+ * # Example
105
+ * ```ts
106
+ * const { shapeIds } = await snaptrude.presentation.import.svg({
107
+ * url: "https://example.com/diagram.svg",
108
+ * })
109
+ * ```
110
+ */
111
+ public abstract svg(
112
+ source: { url?: string; dataUrl?: string },
113
+ options?: { position?: { x: number; y: number } },
114
+ ): PluginApiReturn<PluginPresentationImportResult>
75
115
  }
76
116
 
77
117
  /**
78
118
  * Arguments for {@linkcode PluginPresentationImportApi.image} /
79
- * {@linkcode PluginPresentationImportApi.pdf}. Provide exactly one source.
119
+ * {@linkcode PluginPresentationImportApi.pdf} /
120
+ * {@linkcode PluginPresentationImportApi.svg}. Provide exactly one source.
80
121
  *
81
122
  * | Property | Type | Description |
82
123
  * |---|---|---|