@snaptrude/plugin-core 0.6.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.
- package/CHANGELOG.md +21 -0
- package/api-manifest.full.json +511 -10
- package/api-manifest.json +529 -4
- package/dist/api/core/index.d.ts +5 -0
- package/dist/api/core/index.d.ts.map +1 -1
- package/dist/api/core/proposals/index.d.ts +475 -0
- package/dist/api/core/proposals/index.d.ts.map +1 -0
- package/dist/api/design/create/index.d.ts +209 -0
- package/dist/api/design/create/index.d.ts.map +1 -1
- package/dist/api/design/doors/index.d.ts +159 -0
- package/dist/api/design/doors/index.d.ts.map +1 -1
- package/dist/api/design/furniture/index.d.ts +34 -5
- package/dist/api/design/furniture/index.d.ts.map +1 -1
- package/dist/api/design/index.d.ts +83 -0
- package/dist/api/design/index.d.ts.map +1 -1
- package/dist/api/design/lock.d.ts +26 -0
- package/dist/api/design/lock.d.ts.map +1 -1
- package/dist/api/design/materials/index.d.ts +159 -2
- package/dist/api/design/materials/index.d.ts.map +1 -1
- package/dist/api/design/query/index.d.ts +115 -5
- package/dist/api/design/query/index.d.ts.map +1 -1
- package/dist/api/design/selection/index.d.ts +2 -2
- package/dist/api/design/transform/index.d.ts +83 -2
- package/dist/api/design/transform/index.d.ts.map +1 -1
- package/dist/api/design/update/index.d.ts +168 -0
- package/dist/api/design/update/index.d.ts.map +1 -1
- package/dist/api/design/windows/index.d.ts +113 -2
- package/dist/api/design/windows/index.d.ts.map +1 -1
- package/dist/api/entity/story.d.ts +101 -7
- package/dist/api/entity/story.d.ts.map +1 -1
- package/dist/api/presentation/import.d.ts +49 -4
- package/dist/api/presentation/import.d.ts.map +1 -1
- package/dist/api/presentation/views.d.ts +210 -5
- package/dist/api/presentation/views.d.ts.map +1 -1
- package/dist/api/program/areas.d.ts +42 -12
- package/dist/api/program/areas.d.ts.map +1 -1
- package/dist/api/program/index.d.ts +3 -11
- package/dist/api/program/index.d.ts.map +1 -1
- package/dist/api/program/layout.d.ts +186 -11
- package/dist/api/program/layout.d.ts.map +1 -1
- package/dist/errors/codes.d.ts +34 -0
- package/dist/errors/codes.d.ts.map +1 -0
- package/dist/errors/envelope.d.ts +56 -0
- package/dist/errors/envelope.d.ts.map +1 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/plugin-error.d.ts +69 -0
- package/dist/errors/plugin-error.d.ts.map +1 -0
- package/dist/host-utils.d.ts +4 -0
- package/dist/host-utils.d.ts.map +1 -1
- package/dist/index.cjs +1624 -1028
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1546 -1025
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/scripts/generate-manifest.test.mjs +77 -0
- package/src/api/core/index.ts +5 -0
- package/src/api/core/proposals/index.ts +509 -0
- package/src/api/design/create/index.ts +249 -0
- package/src/api/design/doors/index.ts +168 -0
- package/src/api/design/furniture/index.ts +36 -5
- package/src/api/design/index.ts +87 -0
- package/src/api/design/lock.ts +27 -0
- package/src/api/design/materials/index.ts +182 -2
- package/src/api/design/query/index.ts +81 -0
- package/src/api/design/transform/index.ts +74 -2
- package/src/api/design/update/index.ts +167 -0
- package/src/api/design/windows/index.ts +128 -2
- package/src/api/entity/story.ts +105 -7
- package/src/api/presentation/import.ts +45 -4
- package/src/api/presentation/views.ts +221 -5
- package/src/api/program/areas.ts +34 -12
- package/src/api/program/index.ts +3 -11
- package/src/api/program/layout.ts +195 -11
- package/src/errors/codes.ts +136 -0
- package/src/errors/envelope.ts +75 -0
- package/src/errors/index.ts +21 -0
- package/src/errors/plugin-error.ts +134 -0
- package/src/host-utils.ts +4 -0
- package/src/index.ts +1 -0
- package/test/errors.test.mjs +184 -0
|
@@ -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
|
-
*
|
|
12
|
-
*
|
|
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>
|
package/src/api/entity/story.ts
CHANGED
|
@@ -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
|
-
*
|
|
107
|
-
*
|
|
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
|
|
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
|
|
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
|
+
>
|
|
@@ -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
|
|
8
|
-
* page vectorized to SVG)
|
|
9
|
-
*
|
|
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}
|
|
119
|
+
* {@linkcode PluginPresentationImportApi.pdf} /
|
|
120
|
+
* {@linkcode PluginPresentationImportApi.svg}. Provide exactly one source.
|
|
80
121
|
*
|
|
81
122
|
* | Property | Type | Description |
|
|
82
123
|
* |---|---|---|
|
|
@@ -6,12 +6,12 @@ import { PluginApiReturn } from "../../types"
|
|
|
6
6
|
*
|
|
7
7
|
* A **view** is a saved camera/plan: a sheet-ready 2D plan or a saved 3D view.
|
|
8
8
|
* A plugin can list and read views, capture them to images, activate one (move
|
|
9
|
-
* the camera to it),
|
|
9
|
+
* the camera to it), save the current camera as a new view, and read/update a
|
|
10
|
+
* view's display settings (background, color mode, axis, edges, labels).
|
|
10
11
|
*
|
|
11
|
-
* `list`/`get`/`getActive`/`capture` are reads;
|
|
12
|
-
* (a view is a camera bookmark
|
|
13
|
-
*
|
|
14
|
-
* live discovery surface until the host lands them.
|
|
12
|
+
* `list`/`get`/`getActive`/`capture`/`getSettings` are reads;
|
|
13
|
+
* `setActive`/`create`/`updateSettings` are writes (a view is a camera bookmark
|
|
14
|
+
* — not geometry).
|
|
15
15
|
*
|
|
16
16
|
* Accessed via `snaptrude.presentation.views`.
|
|
17
17
|
*/
|
|
@@ -153,6 +153,85 @@ export abstract class PluginPresentationViewsApi {
|
|
|
153
153
|
name?: string,
|
|
154
154
|
options?: { kind?: "view" | "sitePlan" },
|
|
155
155
|
): PluginApiReturn<PluginPresentationViewsCreateResult>
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Read a saved view's display settings (background, color mode, axis, edges,
|
|
159
|
+
* labels).
|
|
160
|
+
*
|
|
161
|
+
* @param viewId - The id of the view to read settings for.
|
|
162
|
+
* @returns The view's {@linkcode PluginPresentationViewSettings}, or `null` if
|
|
163
|
+
* no view has that id.
|
|
164
|
+
*
|
|
165
|
+
* @examplePrompt What color mode is the Ground Floor view using?
|
|
166
|
+
* @examplePrompt Get the display settings for this view
|
|
167
|
+
* @examplePrompt Does the site plan view show axes and labels?
|
|
168
|
+
* @examplePrompt Read the background color of the active view
|
|
169
|
+
*
|
|
170
|
+
* # Example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const settings = await snaptrude.presentation.views.getSettings("view_123")
|
|
173
|
+
* if (settings) console.log(settings.colorMode, settings.backgroundColor)
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
public abstract getSettings(
|
|
177
|
+
viewId: string,
|
|
178
|
+
): PluginApiReturn<PluginPresentationViewsGetSettingsResult>
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Update a saved view's display settings (partial patch — only the fields you
|
|
182
|
+
* pass change).
|
|
183
|
+
*
|
|
184
|
+
* Persists and broadcasts the change; if the view is currently active, the
|
|
185
|
+
* scene updates live. **Not Ctrl+Z-undoable** — view-metadata edits publish
|
|
186
|
+
* directly and do not land on the local undo stack; this matches how the
|
|
187
|
+
* product's own view-settings UI behaves.
|
|
188
|
+
*
|
|
189
|
+
* Label patch semantics (mirroring the product, which stores no label
|
|
190
|
+
* selection while labels are off):
|
|
191
|
+
*
|
|
192
|
+
* - `{ showLabels: true }` alone turns labels on; if the view has no stored
|
|
193
|
+
* selection, the product defaults (`objectLabels`, `areas`) are applied —
|
|
194
|
+
* labels are never "on" with an empty selection (the product has no such
|
|
195
|
+
* state; labels render only while the selection is non-empty).
|
|
196
|
+
* - `{ labels: [...] }` alone sets the selection **and turns labels on**.
|
|
197
|
+
* - `{ showLabels: false }` turns labels off and **clears the stored
|
|
198
|
+
* selection** — a later read returns `labels: []`.
|
|
199
|
+
* - `{ showLabels: false, labels: [...] }` with a non-empty list is
|
|
200
|
+
* contradictory and **rejected** (nothing is silently discarded).
|
|
201
|
+
* - `{ showLabels: true, labels: [] }` is likewise contradictory and
|
|
202
|
+
* **rejected** — pass a non-empty list, or omit `labels` to get the
|
|
203
|
+
* defaults.
|
|
204
|
+
*
|
|
205
|
+
* `colorMode` accepts the `tag:<categoryId>` scheme strings returned by
|
|
206
|
+
* {@linkcode PluginPresentationViewsApi.getSettings}, so read-then-write
|
|
207
|
+
* round-trips a tag-based color scheme unchanged.
|
|
208
|
+
*
|
|
209
|
+
* @param viewId - The id of the view to update.
|
|
210
|
+
* @param settings - A partial {@linkcode PluginPresentationViewSettings}; any
|
|
211
|
+
* omitted field is left unchanged.
|
|
212
|
+
* @returns The updated view's `id`.
|
|
213
|
+
* @throws If writes are disabled, no view has the given id, or the patch is
|
|
214
|
+
* contradictory (`showLabels: false` with a non-empty `labels`, or
|
|
215
|
+
* `showLabels: true` with an explicitly empty `labels` list).
|
|
216
|
+
*
|
|
217
|
+
* @examplePrompt Switch this view to monochrome color mode
|
|
218
|
+
* @examplePrompt Turn off the axis in the Ground Floor view
|
|
219
|
+
* @examplePrompt Set the background of the active view to white
|
|
220
|
+
* @examplePrompt Show area labels on this view
|
|
221
|
+
* @examplePrompt Enable hidden-line mode for the section view
|
|
222
|
+
*
|
|
223
|
+
* # Example
|
|
224
|
+
* ```ts
|
|
225
|
+
* await snaptrude.presentation.views.updateSettings("view_123", {
|
|
226
|
+
* colorMode: "monochrome",
|
|
227
|
+
* showAxis: false,
|
|
228
|
+
* })
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
public abstract updateSettings(
|
|
232
|
+
viewId: string,
|
|
233
|
+
settings: Partial<PluginPresentationViewSettings>,
|
|
234
|
+
): PluginApiReturn<PluginPresentationViewsUpdateSettingsResult>
|
|
156
235
|
}
|
|
157
236
|
|
|
158
237
|
/**
|
|
@@ -301,3 +380,140 @@ export const PluginPresentationViewsCreateResult = PluginPresentationView
|
|
|
301
380
|
export type PluginPresentationViewsCreateResult = z.infer<
|
|
302
381
|
typeof PluginPresentationViewsCreateResult
|
|
303
382
|
>
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* How the scene is colored in a view.
|
|
386
|
+
*
|
|
387
|
+
* | Value | Meaning |
|
|
388
|
+
* |---|---|
|
|
389
|
+
* | `monochrome` | Flat single-tone shading |
|
|
390
|
+
* | `texture` | Material textures/colors |
|
|
391
|
+
* | `department` | Colored by department |
|
|
392
|
+
* | `tag:<categoryId>` | Colored by a project tag category (e.g. `tag:ZONE`) |
|
|
393
|
+
*
|
|
394
|
+
* The `tag:<categoryId>` form carries the product's tag-based color schemes
|
|
395
|
+
* losslessly — reading a view that uses one returns the `tag:` string as-is,
|
|
396
|
+
* and writing it back preserves the scheme (read-then-write is safe).
|
|
397
|
+
*/
|
|
398
|
+
export const PluginPresentationViewColorMode = z.union([
|
|
399
|
+
z.enum(["monochrome", "texture", "department"]),
|
|
400
|
+
z.templateLiteral(["tag:", z.string()]),
|
|
401
|
+
])
|
|
402
|
+
export type PluginPresentationViewColorMode = z.infer<
|
|
403
|
+
typeof PluginPresentationViewColorMode
|
|
404
|
+
>
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* A category of on-canvas labels a view can show.
|
|
408
|
+
*
|
|
409
|
+
* | Value | Meaning |
|
|
410
|
+
* |---|---|
|
|
411
|
+
* | `objectLabels` | Per-object name labels |
|
|
412
|
+
* | `areas` | Area/room labels |
|
|
413
|
+
* | `department` | Department labels |
|
|
414
|
+
*/
|
|
415
|
+
export const PluginPresentationViewLabel = z.enum([
|
|
416
|
+
"objectLabels",
|
|
417
|
+
"areas",
|
|
418
|
+
"department",
|
|
419
|
+
])
|
|
420
|
+
export type PluginPresentationViewLabel = z.infer<
|
|
421
|
+
typeof PluginPresentationViewLabel
|
|
422
|
+
>
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* A view's display settings.
|
|
426
|
+
*
|
|
427
|
+
* | Property | Type | Description |
|
|
428
|
+
* |---|---|---|
|
|
429
|
+
* | `backgroundColor` | `string` | Canvas background as a hex color (e.g. `#ffffff`) |
|
|
430
|
+
* | `colorMode` | {@linkcode PluginPresentationViewColorMode} | How the scene is colored (including `tag:<categoryId>` schemes) |
|
|
431
|
+
* | `showAxis` | `boolean` | Whether the X/Y/Z axes are shown |
|
|
432
|
+
* | `showEdges` | `boolean` | Whether edges are shown; `false` = hidden-line rendering |
|
|
433
|
+
* | `showLabels` | `boolean` | Master label switch — whether on-canvas labels are shown at all. `true` always pairs with a non-empty `labels` selection (labels render only while the selection is non-empty; there is no labels-on-with-empty-selection state) |
|
|
434
|
+
* | `labels` | {@linkcode PluginPresentationViewLabel}`[]` | Which label categories are selected. When `showLabels` is `false` the view stores no selection and this reads `[]` |
|
|
435
|
+
*/
|
|
436
|
+
export const PluginPresentationViewSettings = z.object({
|
|
437
|
+
backgroundColor: z.string(),
|
|
438
|
+
colorMode: PluginPresentationViewColorMode,
|
|
439
|
+
showAxis: z.boolean(),
|
|
440
|
+
showEdges: z.boolean(),
|
|
441
|
+
showLabels: z.boolean(),
|
|
442
|
+
labels: z.array(PluginPresentationViewLabel),
|
|
443
|
+
})
|
|
444
|
+
export type PluginPresentationViewSettings = z.infer<
|
|
445
|
+
typeof PluginPresentationViewSettings
|
|
446
|
+
>
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Arguments for {@linkcode PluginPresentationViewsApi.getSettings}.
|
|
450
|
+
*
|
|
451
|
+
* | Property | Type | Description |
|
|
452
|
+
* |---|---|---|
|
|
453
|
+
* | `id` | `string` | The id of the view to read settings for |
|
|
454
|
+
*/
|
|
455
|
+
export const PluginPresentationViewsGetSettingsArgs = z.object({
|
|
456
|
+
id: z.string(),
|
|
457
|
+
})
|
|
458
|
+
export type PluginPresentationViewsGetSettingsArgs = z.infer<
|
|
459
|
+
typeof PluginPresentationViewsGetSettingsArgs
|
|
460
|
+
>
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Result of {@linkcode PluginPresentationViewsApi.getSettings} — the settings,
|
|
464
|
+
* or `null` when no view has that id.
|
|
465
|
+
*/
|
|
466
|
+
export const PluginPresentationViewsGetSettingsResult =
|
|
467
|
+
PluginPresentationViewSettings.nullable()
|
|
468
|
+
export type PluginPresentationViewsGetSettingsResult = z.infer<
|
|
469
|
+
typeof PluginPresentationViewsGetSettingsResult
|
|
470
|
+
>
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Arguments for {@linkcode PluginPresentationViewsApi.updateSettings}. The
|
|
474
|
+
* `settings` patch is partial — any omitted field is left unchanged. A patch
|
|
475
|
+
* pairing `showLabels: false` with a non-empty `labels` list, or
|
|
476
|
+
* `showLabels: true` with an explicitly empty `labels` list, is rejected as
|
|
477
|
+
* contradictory (see the method JSDoc for the full label patch semantics).
|
|
478
|
+
*
|
|
479
|
+
* | Property | Type | Description |
|
|
480
|
+
* |---|---|---|
|
|
481
|
+
* | `id` | `string` | The id of the view to update |
|
|
482
|
+
* | `settings` | `Partial<`{@linkcode PluginPresentationViewSettings}`>` | The fields to change |
|
|
483
|
+
*/
|
|
484
|
+
export const PluginPresentationViewsUpdateSettingsArgs = z
|
|
485
|
+
.object({
|
|
486
|
+
id: z.string(),
|
|
487
|
+
settings: PluginPresentationViewSettings.partial(),
|
|
488
|
+
})
|
|
489
|
+
.refine(
|
|
490
|
+
(v) =>
|
|
491
|
+
!(v.settings.showLabels === false && (v.settings.labels?.length ?? 0) > 0),
|
|
492
|
+
{
|
|
493
|
+
message:
|
|
494
|
+
"Contradictory patch: labels cannot be set while showLabels is false",
|
|
495
|
+
},
|
|
496
|
+
)
|
|
497
|
+
.refine(
|
|
498
|
+
(v) =>
|
|
499
|
+
!(
|
|
500
|
+
v.settings.showLabels === true &&
|
|
501
|
+
v.settings.labels !== undefined &&
|
|
502
|
+
v.settings.labels.length === 0
|
|
503
|
+
),
|
|
504
|
+
{
|
|
505
|
+
message:
|
|
506
|
+
"Contradictory patch: showLabels cannot be true with an explicitly empty labels list — pass a non-empty list, or omit labels to apply the defaults",
|
|
507
|
+
},
|
|
508
|
+
)
|
|
509
|
+
export type PluginPresentationViewsUpdateSettingsArgs = z.infer<
|
|
510
|
+
typeof PluginPresentationViewsUpdateSettingsArgs
|
|
511
|
+
>
|
|
512
|
+
|
|
513
|
+
/** Result of {@linkcode PluginPresentationViewsApi.updateSettings} — the updated view's id. */
|
|
514
|
+
export const PluginPresentationViewsUpdateSettingsResult = z.object({
|
|
515
|
+
id: z.string(),
|
|
516
|
+
})
|
|
517
|
+
export type PluginPresentationViewsUpdateSettingsResult = z.infer<
|
|
518
|
+
typeof PluginPresentationViewsUpdateSettingsResult
|
|
519
|
+
>
|