@snaptrude/plugin-core 0.7.1 → 0.9.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 (193) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/api-manifest.full.json +7703 -0
  3. package/api-manifest.json +2946 -259
  4. package/dist/api/analysis/daylight.d.ts +603 -0
  5. package/dist/api/analysis/daylight.d.ts.map +1 -0
  6. package/dist/api/analysis/heatmaps.d.ts +438 -14
  7. package/dist/api/analysis/heatmaps.d.ts.map +1 -1
  8. package/dist/api/analysis/index.d.ts +15 -0
  9. package/dist/api/analysis/index.d.ts.map +1 -1
  10. package/dist/api/analysis/solar.d.ts +249 -0
  11. package/dist/api/analysis/solar.d.ts.map +1 -0
  12. package/dist/api/analysis/weather.d.ts +193 -0
  13. package/dist/api/analysis/weather.d.ts.map +1 -0
  14. package/dist/api/core/camera/index.d.ts +245 -0
  15. package/dist/api/core/camera/index.d.ts.map +1 -0
  16. package/dist/api/core/comment/index.d.ts +105 -2
  17. package/dist/api/core/comment/index.d.ts.map +1 -1
  18. package/dist/api/core/geom/create/index.d.ts +331 -14
  19. package/dist/api/core/geom/create/index.d.ts.map +1 -1
  20. package/dist/api/core/geom/delete/index.d.ts +8 -2
  21. package/dist/api/core/geom/delete/index.d.ts.map +1 -1
  22. package/dist/api/core/geom/query/arc.d.ts +5 -5
  23. package/dist/api/core/geom/query/brep.d.ts +18 -18
  24. package/dist/api/core/geom/query/circle.d.ts +18 -18
  25. package/dist/api/core/geom/query/contour.d.ts +20 -20
  26. package/dist/api/core/geom/query/curve.d.ts +49 -49
  27. package/dist/api/core/geom/query/edge.d.ts +5 -5
  28. package/dist/api/core/geom/query/face.d.ts +16 -16
  29. package/dist/api/core/geom/query/halfedge.d.ts +8 -8
  30. package/dist/api/core/geom/query/profile.d.ts +19 -19
  31. package/dist/api/core/geom/query/vertex.d.ts +8 -8
  32. package/dist/api/core/geom/update/contour.d.ts +14 -14
  33. package/dist/api/core/geom/update/curve.d.ts +7 -7
  34. package/dist/api/core/geom/update/profile.d.ts +16 -16
  35. package/dist/api/core/handles/index.d.ts +210 -0
  36. package/dist/api/core/handles/index.d.ts.map +1 -0
  37. package/dist/api/core/index.d.ts +24 -0
  38. package/dist/api/core/index.d.ts.map +1 -1
  39. package/dist/api/core/io/export/index.d.ts +134 -0
  40. package/dist/api/core/io/export/index.d.ts.map +1 -0
  41. package/dist/api/core/io/import/index.d.ts +62 -1
  42. package/dist/api/core/io/import/index.d.ts.map +1 -1
  43. package/dist/api/core/io/index.d.ts +5 -0
  44. package/dist/api/core/io/index.d.ts.map +1 -1
  45. package/dist/api/core/layers.d.ts +7 -7
  46. package/dist/api/core/mode/index.d.ts +99 -0
  47. package/dist/api/core/mode/index.d.ts.map +1 -0
  48. package/dist/api/core/proposals/index.d.ts +65 -9
  49. package/dist/api/core/proposals/index.d.ts.map +1 -1
  50. package/dist/api/core/storeys/index.d.ts +251 -0
  51. package/dist/api/core/storeys/index.d.ts.map +1 -0
  52. package/dist/api/core/tags.d.ts +24 -0
  53. package/dist/api/core/tags.d.ts.map +1 -1
  54. package/dist/api/core/user.d.ts +44 -0
  55. package/dist/api/core/user.d.ts.map +1 -0
  56. package/dist/api/core/zoom/index.d.ts +4 -0
  57. package/dist/api/core/zoom/index.d.ts.map +1 -1
  58. package/dist/api/design/boolean/index.d.ts +4 -4
  59. package/dist/api/design/create/index.d.ts +253 -47
  60. package/dist/api/design/create/index.d.ts.map +1 -1
  61. package/dist/api/design/delete/index.d.ts +3 -0
  62. package/dist/api/design/delete/index.d.ts.map +1 -1
  63. package/dist/api/design/doors/index.d.ts +36 -0
  64. package/dist/api/design/doors/index.d.ts.map +1 -1
  65. package/dist/api/design/edit/index.d.ts +1 -1
  66. package/dist/api/design/erase/index.d.ts +2 -2
  67. package/dist/api/design/furniture/index.d.ts +114 -3
  68. package/dist/api/design/furniture/index.d.ts.map +1 -1
  69. package/dist/api/design/index.d.ts +10 -0
  70. package/dist/api/design/index.d.ts.map +1 -1
  71. package/dist/api/design/materials/index.d.ts +111 -14
  72. package/dist/api/design/materials/index.d.ts.map +1 -1
  73. package/dist/api/design/query/geometry/index.d.ts +112 -0
  74. package/dist/api/design/query/geometry/index.d.ts.map +1 -1
  75. package/dist/api/design/query/index.d.ts +35 -1
  76. package/dist/api/design/query/index.d.ts.map +1 -1
  77. package/dist/api/design/query/referenceLines.d.ts +45 -0
  78. package/dist/api/design/query/referenceLines.d.ts.map +1 -0
  79. package/dist/api/design/query/spaces.d.ts +178 -5
  80. package/dist/api/design/query/spaces.d.ts.map +1 -1
  81. package/dist/api/design/transform/index.d.ts +95 -14
  82. package/dist/api/design/transform/index.d.ts.map +1 -1
  83. package/dist/api/design/types/index.d.ts +181 -0
  84. package/dist/api/design/types/index.d.ts.map +1 -0
  85. package/dist/api/design/update/index.d.ts +385 -2
  86. package/dist/api/design/update/index.d.ts.map +1 -1
  87. package/dist/api/design/visibility.d.ts +98 -0
  88. package/dist/api/design/visibility.d.ts.map +1 -0
  89. package/dist/api/entity/buildableEnvelope.d.ts +4 -0
  90. package/dist/api/entity/buildableEnvelope.d.ts.map +1 -1
  91. package/dist/api/entity/referenceLine.d.ts +10 -2
  92. package/dist/api/entity/referenceLine.d.ts.map +1 -1
  93. package/dist/api/entity/space.d.ts +19 -19
  94. package/dist/api/entity/story.d.ts +148 -15
  95. package/dist/api/entity/story.d.ts.map +1 -1
  96. package/dist/api/index.d.ts +5 -0
  97. package/dist/api/index.d.ts.map +1 -1
  98. package/dist/api/presentation/annotate.d.ts +448 -0
  99. package/dist/api/presentation/annotate.d.ts.map +1 -0
  100. package/dist/api/presentation/diagrams.d.ts +49 -8
  101. package/dist/api/presentation/diagrams.d.ts.map +1 -1
  102. package/dist/api/presentation/export.d.ts +108 -0
  103. package/dist/api/presentation/export.d.ts.map +1 -0
  104. package/dist/api/presentation/import.d.ts +6 -0
  105. package/dist/api/presentation/import.d.ts.map +1 -1
  106. package/dist/api/presentation/index.d.ts +47 -0
  107. package/dist/api/presentation/index.d.ts.map +1 -1
  108. package/dist/api/presentation/placedViews.d.ts +370 -0
  109. package/dist/api/presentation/placedViews.d.ts.map +1 -0
  110. package/dist/api/presentation/shapes.d.ts +481 -0
  111. package/dist/api/presentation/shapes.d.ts.map +1 -0
  112. package/dist/api/presentation/sheets.d.ts +410 -13
  113. package/dist/api/presentation/sheets.d.ts.map +1 -1
  114. package/dist/api/presentation/views.d.ts +165 -10
  115. package/dist/api/presentation/views.d.ts.map +1 -1
  116. package/dist/api/program/areas.d.ts +63 -3
  117. package/dist/api/program/areas.d.ts.map +1 -1
  118. package/dist/api/program/cores.d.ts +3 -99
  119. package/dist/api/program/cores.d.ts.map +1 -1
  120. package/dist/api/program/index.d.ts +2 -2
  121. package/dist/api/program/index.d.ts.map +1 -1
  122. package/dist/api/program/layout.d.ts +172 -12
  123. package/dist/api/program/layout.d.ts.map +1 -1
  124. package/dist/api/program/site.d.ts +105 -8
  125. package/dist/api/program/site.d.ts.map +1 -1
  126. package/dist/api/program/spreadsheet.d.ts +365 -41
  127. package/dist/api/program/spreadsheet.d.ts.map +1 -1
  128. package/dist/api/workspace/index.d.ts +460 -0
  129. package/dist/api/workspace/index.d.ts.map +1 -0
  130. package/dist/handles.d.ts +64 -25
  131. package/dist/handles.d.ts.map +1 -1
  132. package/dist/index.cjs +3210 -1671
  133. package/dist/index.cjs.map +1 -1
  134. package/dist/index.js +3008 -1666
  135. package/dist/index.js.map +1 -1
  136. package/package.json +3 -2
  137. package/scripts/generate-manifest.mjs +45 -0
  138. package/src/api/analysis/daylight.ts +470 -0
  139. package/src/api/analysis/heatmaps.ts +444 -17
  140. package/src/api/analysis/index.ts +15 -0
  141. package/src/api/analysis/solar.ts +237 -0
  142. package/src/api/analysis/weather.ts +179 -0
  143. package/src/api/core/camera/index.ts +251 -0
  144. package/src/api/core/comment/index.ts +120 -2
  145. package/src/api/core/geom/create/index.ts +344 -1
  146. package/src/api/core/geom/delete/index.ts +6 -0
  147. package/src/api/core/handles/index.ts +233 -0
  148. package/src/api/core/index.ts +24 -0
  149. package/src/api/core/io/export/index.ts +126 -0
  150. package/src/api/core/io/import/index.ts +64 -0
  151. package/src/api/core/io/index.ts +5 -0
  152. package/src/api/core/mode/index.ts +96 -0
  153. package/src/api/core/proposals/index.ts +71 -11
  154. package/src/api/core/storeys/index.ts +279 -0
  155. package/src/api/core/tags.ts +27 -0
  156. package/src/api/core/user.ts +46 -0
  157. package/src/api/core/zoom/index.ts +4 -0
  158. package/src/api/design/create/index.ts +303 -36
  159. package/src/api/design/delete/index.ts +3 -0
  160. package/src/api/design/doors/index.ts +40 -0
  161. package/src/api/design/furniture/index.ts +127 -3
  162. package/src/api/design/index.ts +10 -0
  163. package/src/api/design/materials/index.ts +157 -30
  164. package/src/api/design/query/geometry/index.ts +125 -3
  165. package/src/api/design/query/index.ts +37 -7
  166. package/src/api/design/query/referenceLines.ts +52 -0
  167. package/src/api/design/query/spaces.ts +143 -0
  168. package/src/api/design/transform/index.ts +101 -12
  169. package/src/api/design/types/index.ts +156 -0
  170. package/src/api/design/update/index.ts +467 -6
  171. package/src/api/design/visibility.ts +109 -0
  172. package/src/api/entity/buildableEnvelope.ts +4 -0
  173. package/src/api/entity/referenceLine.ts +8 -0
  174. package/src/api/entity/story.ts +161 -15
  175. package/src/api/index.ts +5 -0
  176. package/src/api/presentation/annotate.ts +360 -0
  177. package/src/api/presentation/diagrams.ts +53 -8
  178. package/src/api/presentation/export.ts +108 -0
  179. package/src/api/presentation/import.ts +6 -0
  180. package/src/api/presentation/index.ts +55 -0
  181. package/src/api/presentation/placedViews.ts +363 -0
  182. package/src/api/presentation/shapes.ts +274 -0
  183. package/src/api/presentation/sheets.ts +346 -13
  184. package/src/api/presentation/views.ts +164 -12
  185. package/src/api/program/areas.ts +57 -6
  186. package/src/api/program/cores.ts +3 -91
  187. package/src/api/program/index.ts +2 -2
  188. package/src/api/program/layout.ts +182 -12
  189. package/src/api/program/site.ts +106 -8
  190. package/src/api/program/spreadsheet.ts +376 -35
  191. package/src/api/workspace/index.ts +516 -0
  192. package/src/handles.ts +77 -13
  193. package/tsconfig.json +7 -2
@@ -0,0 +1,233 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../../types"
3
+ // Type-only: src/handles.ts type-only-imports ArenaKind from this file, so the
4
+ // cycle stays purely type-level and is erased at emit.
5
+ import type { AnyArenaHandle } from "../../../handles"
6
+ import { Handle } from "../../../handles"
7
+
8
+ /**
9
+ * The 12 registry-arena handle kinds — the releasable families. Entity-style
10
+ * handles (component / material / underlay / terrain / importJob / comment) are
11
+ * raw engine ids with no arena entry and therefore no lifecycle: passing one to
12
+ * `release` is a silent no-op like any other unknown id.
13
+ */
14
+ export const ArenaKind = z.enum([
15
+ "vec3",
16
+ "quat",
17
+ "line",
18
+ "arc",
19
+ "circle",
20
+ "profile",
21
+ "contour",
22
+ "brep",
23
+ "face",
24
+ "edge",
25
+ "halfedge",
26
+ "vertex",
27
+ ])
28
+ export type ArenaKind = z.infer<typeof ArenaKind>
29
+
30
+ /** Max handles accepted by a single `release` / `endScope(retain)` call. */
31
+ export const RELEASE_BATCH_MAX = 10_000
32
+
33
+ /**
34
+ * An opaque token identifying a handle scope opened by
35
+ * {@linkcode PluginCoreHandlesApi.beginScope}. It is NOT an arena handle —
36
+ * it pins no memory, and `release(token)` is a silent no-op; only
37
+ * {@linkcode PluginCoreHandlesApi.endScope} consumes it.
38
+ */
39
+ export type ScopeToken = string
40
+
41
+ /**
42
+ * Handle lifecycle — free host-side handle registry entries the plugin no
43
+ * longer needs, individually ({@linkcode release}), by kind
44
+ * ({@linkcode releaseAll}), or as a mint-recording region
45
+ * ({@linkcode beginScope} / {@linkcode endScope}).
46
+ *
47
+ * Releasing is a handle-lifecycle operation only: it frees the registry entry
48
+ * (host memory + quota room) and makes the handle unresolvable. It never
49
+ * deletes engine-side geometry or scene entities.
50
+ *
51
+ * Accessed via `snaptrude.core.handles`.
52
+ */
53
+ export abstract class PluginCoreHandlesApi {
54
+ constructor() {}
55
+
56
+ /**
57
+ * Free arena handles in bulk. Unknown, foreign, or already-released ids are
58
+ * silent no-ops — there is no per-id result and no count, so responses can
59
+ * never be used as an existence oracle.
60
+ *
61
+ * @param handles The handles to release (max {@linkcode RELEASE_BATCH_MAX} per call)
62
+ * @returns Nothing
63
+ *
64
+ * # Example
65
+ * ```ts
66
+ * const faces = await snaptrude.core.geom.query.brep.listFaces(brep)
67
+ * // ... read what you need ...
68
+ * await snaptrude.core.handles.release(faces)
69
+ * ```
70
+ */
71
+ public abstract release(handles: ReadonlyArray<AnyArenaHandle>): PluginApiReturn<void>
72
+
73
+ /**
74
+ * Free every live arena handle of one kind, or ALL arena handles when the
75
+ * kind is omitted. Useful at batch boundaries — e.g. a poll loop that mints
76
+ * a fresh footprint contour per tick.
77
+ *
78
+ * @param kind Optional arena kind to restrict the sweep to
79
+ * @returns Nothing
80
+ *
81
+ * # Example
82
+ * ```ts
83
+ * const footprint = await snaptrude.design.query.spaces.getFootprint(space)
84
+ * // ... measure ...
85
+ * await snaptrude.core.handles.releaseAll("contour")
86
+ * ```
87
+ */
88
+ public abstract releaseAll(kind?: ArenaKind): PluginApiReturn<void>
89
+
90
+ /**
91
+ * Open a mint-recording scope: every arena handle MINTED after this call
92
+ * (fresh mints only — identity-deduped re-registrations of pre-existing
93
+ * objects are not captured) is freed when the matching
94
+ * {@linkcode endScope} runs. Scopes nest, up to 64 deep — always pair
95
+ * begin/end in try/finally.
96
+ *
97
+ * @returns The scope token to pass to {@linkcode endScope}
98
+ *
99
+ * # Example
100
+ * ```ts
101
+ * for (const space of spaces) {
102
+ * const scope = await snaptrude.core.handles.beginScope()
103
+ * try {
104
+ * const footprint = await snaptrude.design.query.spaces.getFootprint(space)
105
+ * const area = await snaptrude.core.geom.query.contour.getArea(footprint)
106
+ * } finally {
107
+ * await snaptrude.core.handles.endScope(scope) // footprint (and intermediates) freed
108
+ * }
109
+ * }
110
+ * ```
111
+ */
112
+ public abstract beginScope(): PluginApiReturn<ScopeToken>
113
+
114
+ /**
115
+ * Close a scope by its token and free every handle it recorded, except those
116
+ * listed in `retain`. Retained handles are promoted to the enclosing scope
117
+ * (if any), so nesting composes like block scopes. Closing is
118
+ * token-addressed: an out-of-order close (interleaved async tasks) frees
119
+ * only that scope's mints and leaves other open scopes intact. Always pair
120
+ * begin/end in try/finally so a thrown body cannot leak the scope.
121
+ *
122
+ * @param scope The token returned by the matching {@linkcode beginScope}
123
+ * @param retain Handles minted inside the scope that must survive it
124
+ * @returns Nothing
125
+ *
126
+ * # Example
127
+ * ```ts
128
+ * const scope = await snaptrude.core.handles.beginScope()
129
+ * const outline = await snaptrude.design.query.spaces.getFootprint(space)
130
+ * const outer = await snaptrude.core.geom.query.contour.getOuterProfile(outline)
131
+ * await snaptrude.core.handles.endScope(scope, [outer]) // outline freed, outer survives
132
+ * ```
133
+ */
134
+ public abstract endScope(
135
+ scope: ScopeToken,
136
+ retain?: ReadonlyArray<AnyArenaHandle>
137
+ ): PluginApiReturn<void>
138
+
139
+ /**
140
+ * Live handle-registry statistics for the calling plugin, plus the host
141
+ * page's JS heap usage (when the browser exposes it). Diagnostic surface for
142
+ * verifying that releases actually shrink host memory.
143
+ *
144
+ * @returns Arena entry counts, open scope depth, and host heap bytes
145
+ *
146
+ * # Example
147
+ * ```ts
148
+ * const before = await snaptrude.core.handles.stats()
149
+ * await snaptrude.core.handles.releaseAll("vec3")
150
+ * const after = await snaptrude.core.handles.stats()
151
+ * console.log(`freed ${before.values - after.values} value entries`)
152
+ * ```
153
+ */
154
+ public abstract stats(): PluginApiReturn<PluginHandlesStatsResult>
155
+ }
156
+
157
+ /**
158
+ * Wire-normalize one handle argument: a raw id string passes through; a live
159
+ * `Handle` instance (direct host callers — console harness, host-internal) or a
160
+ * structured-clone-stripped `{id}` / tagged `{__h}` shape collapses to its id.
161
+ * Deliberately shape-lax beyond that (non-empty string) — a malformed id is
162
+ * just an id that resolves nowhere (anti-oracle).
163
+ */
164
+ const handleIdWire = z.preprocess((v) => {
165
+ if (typeof v === "string") return v
166
+ if (v instanceof Handle) return v.id
167
+ if (v && typeof v === "object") {
168
+ const o = v as Record<string, unknown>
169
+ if (typeof o.__h === "string") return o.__h
170
+ if (typeof o.id === "string") return o.id
171
+ }
172
+ return v
173
+ }, z.string().min(1))
174
+
175
+ /**
176
+ * Arguments for {@linkcode PluginCoreHandlesApi.release}.
177
+ *
178
+ * | Property | Type | Description |
179
+ * |---|---|---|
180
+ * | `handles` | `string[]` | Handles to release (≤ {@linkcode RELEASE_BATCH_MAX}) |
181
+ */
182
+ export const PluginHandlesReleaseArgs = z.object({
183
+ handles: z.array(handleIdWire).max(RELEASE_BATCH_MAX),
184
+ })
185
+ export type PluginHandlesReleaseArgs = z.infer<typeof PluginHandlesReleaseArgs>
186
+
187
+ /**
188
+ * Arguments for {@linkcode PluginCoreHandlesApi.releaseAll}.
189
+ *
190
+ * | Property | Type | Description |
191
+ * |---|---|---|
192
+ * | `kind` | {@linkcode ArenaKind} (optional) | Restrict the sweep to one kind |
193
+ */
194
+ export const PluginHandlesReleaseAllArgs = z.object({
195
+ kind: ArenaKind.optional(),
196
+ })
197
+ export type PluginHandlesReleaseAllArgs = z.infer<typeof PluginHandlesReleaseAllArgs>
198
+
199
+ /**
200
+ * Arguments for {@linkcode PluginCoreHandlesApi.endScope}.
201
+ *
202
+ * | Property | Type | Description |
203
+ * |---|---|---|
204
+ * | `scope` | {@linkcode ScopeToken} | Token from the matching `beginScope` |
205
+ * | `retain` | `string[]` (optional) | Scope-minted handles that must survive |
206
+ */
207
+ export const PluginHandlesEndScopeArgs = z.object({
208
+ scope: z.string().regex(/^scope_[A-Za-z0-9_-]+$/, 'expected a "scope" token'),
209
+ retain: z.array(handleIdWire).max(RELEASE_BATCH_MAX).optional(),
210
+ })
211
+ export type PluginHandlesEndScopeArgs = z.infer<typeof PluginHandlesEndScopeArgs>
212
+
213
+ /**
214
+ * Result of {@linkcode PluginCoreHandlesApi.stats}.
215
+ *
216
+ * | Property | Type | Description |
217
+ * |---|---|---|
218
+ * | `resources` | `number` | Live resource-arena entries (profile/contour) |
219
+ * | `values` | `number` | Live value-arena entries (vec3/quat/line/arc/circle) |
220
+ * | `topology` | `number` | Live topology-arena entries (brep/face/edge/halfedge/vertex) |
221
+ * | `scopes` | `number` | Currently open handle scopes |
222
+ * | `hostHeapUsedBytes` | `number \| null` | Host page `usedJSHeapSize` (null where unsupported) |
223
+ * | `hostHeapTotalBytes` | `number \| null` | Host page `totalJSHeapSize` (null where unsupported) |
224
+ */
225
+ export const PluginHandlesStatsResult = z.object({
226
+ resources: z.number().int().nonnegative(),
227
+ values: z.number().int().nonnegative(),
228
+ topology: z.number().int().nonnegative(),
229
+ scopes: z.number().int().nonnegative(),
230
+ hostHeapUsedBytes: z.number().nullable(),
231
+ hostHeapTotalBytes: z.number().nullable(),
232
+ })
233
+ export type PluginHandlesStatsResult = z.infer<typeof PluginHandlesStatsResult>
@@ -10,7 +10,12 @@ import { PluginCoreBuildingsApi } from "./buildings"
10
10
  import { PluginCoreLayersApi } from "./layers"
11
11
  import { PluginCoreTagsApi } from "./tags"
12
12
  import { PluginCoreIoApi } from "./io"
13
+ import { PluginCoreHandlesApi } from "./handles"
13
14
  import { PluginCoreProposalsApi } from "./proposals"
15
+ import { PluginCameraApi } from "./camera"
16
+ import { PluginCoreStoreysApi } from "./storeys"
17
+ import { PluginCoreModeApi } from "./mode"
18
+ import { PluginUserApi } from "./user"
14
19
 
15
20
  /**
16
21
  * Core primitives and infrastructure used across the plugin API.
@@ -20,13 +25,17 @@ import { PluginCoreProposalsApi } from "./proposals"
20
25
  * - {@linkcode PluginCoreApi.history} — Undo / redo of committed history entries
21
26
  * - {@linkcode PluginCoreApi.units} — Unit-type queries and conversion
22
27
  * - {@linkcode PluginCoreApi.zoom} — Camera zoom controls (extents / selection)
28
+ * - {@linkcode PluginCoreApi.camera} — Camera controls — position, standard views, 2D/3D mode
29
+ * - {@linkcode PluginCoreApi.user} — User locale — timezone & language
23
30
  * - {@linkcode PluginCoreApi.project} — Project-level settings and info
24
31
  * - {@linkcode PluginCoreApi.comment} — Comments: create, edit, resolve, tag, list
25
32
  * - {@linkcode PluginCoreApi.groups} — Read & edit the group hierarchy
26
33
  * - {@linkcode PluginCoreApi.buildings} — Read & edit buildings and their storeys
34
+ * - {@linkcode PluginCoreApi.storeys} — Create, read & edit storeys (floors)
27
35
  * - {@linkcode PluginCoreApi.layers} — Read & toggle storey drawing/reference layers
28
36
  * - {@linkcode PluginCoreApi.tags} — Tag catalog + assignment
29
37
  * - {@linkcode PluginCoreApi.io} — Import files (image/pdf/cad/model/terrain), poll jobs, manage underlays
38
+ * - {@linkcode PluginCoreApi.handles} — Handle lifecycle: release, releaseAll, scopes
30
39
  * - {@linkcode PluginCoreApi.proposals} — Design options: read, create, rename, switch, delete
31
40
  */
32
41
  export abstract class PluginCoreApi {
@@ -40,6 +49,10 @@ export abstract class PluginCoreApi {
40
49
  public abstract units: PluginUnitsApi
41
50
  /** Camera zoom controls. See {@linkcode PluginZoomApi}. */
42
51
  public abstract zoom: PluginZoomApi
52
+ /** Camera controls — position, standard views, 2D/3D mode. See {@linkcode PluginCameraApi}. */
53
+ public abstract camera: PluginCameraApi
54
+ /** User locale — timezone & language. See {@linkcode PluginUserApi}. */
55
+ public abstract user: PluginUserApi
43
56
  /** Project-level settings and info. See {@linkcode PluginProjectApi}. */
44
57
  public abstract project: PluginProjectApi
45
58
  /** Comments — create, edit, resolve, tag, list. See {@linkcode PluginCommentApi}. */
@@ -48,12 +61,18 @@ export abstract class PluginCoreApi {
48
61
  public abstract groups: PluginCoreGroupsApi
49
62
  /** Buildings — read & edit buildings and their storeys. See {@linkcode PluginCoreBuildingsApi}. */
50
63
  public abstract buildings: PluginCoreBuildingsApi
64
+ /** Storeys — create, read & edit storeys (floors). See {@linkcode PluginCoreStoreysApi}. */
65
+ public abstract storeys: PluginCoreStoreysApi
66
+ /** Application mode — read & switch the editor's top-bar mode. See {@linkcode PluginCoreModeApi}. */
67
+ public abstract mode: PluginCoreModeApi
51
68
  /** Layers — read & toggle storey drawing/reference layers. See {@linkcode PluginCoreLayersApi}. */
52
69
  public abstract layers: PluginCoreLayersApi
53
70
  /** Tags — tag catalog + assignment. See {@linkcode PluginCoreTagsApi}. */
54
71
  public abstract tags: PluginCoreTagsApi
55
72
  /** I/O — file import, import jobs, and underlay management. See {@linkcode PluginCoreIoApi}. */
56
73
  public abstract io: PluginCoreIoApi
74
+ /** Handle lifecycle — release, releaseAll, and mint-recording scopes. See {@linkcode PluginCoreHandlesApi}. */
75
+ public abstract handles: PluginCoreHandlesApi
57
76
  /** Proposals — design options: read, create, rename, switch, delete. See {@linkcode PluginCoreProposalsApi}. */
58
77
  public abstract proposals: PluginCoreProposalsApi
59
78
 
@@ -65,11 +84,16 @@ export * from "./geom"
65
84
  export * from "./history"
66
85
  export * from "./units"
67
86
  export * from "./zoom"
87
+ export * from "./camera"
88
+ export * from "./user"
68
89
  export * from "./project"
69
90
  export * from "./comment"
70
91
  export * from "./groups"
71
92
  export * from "./buildings"
93
+ export * from "./storeys"
94
+ export * from "./mode"
72
95
  export * from "./layers"
73
96
  export * from "./tags"
74
97
  export * from "./io"
98
+ export * from "./handles"
75
99
  export * from "./proposals"
@@ -0,0 +1,126 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../../../types"
3
+
4
+ /**
5
+ * Serialization format for {@link PluginCoreIoExportApi.model}.
6
+ *
7
+ * `glb` / `obj` serialize in the browser; `fbx` / `3ds` run the same server
8
+ * conversion the app's Export dialog uses and return a **zip** containing the
9
+ * converted file.
10
+ */
11
+ export const ExportModelFormat = z.enum(["glb", "obj", "fbx", "3ds"])
12
+ export type ExportModelFormat = z.infer<typeof ExportModelFormat>
13
+
14
+ /**
15
+ * What to export: the whole model (`"scene"`, default) or only the current
16
+ * selection (`"selection"`).
17
+ */
18
+ export const ExportScope = z.enum(["scene", "selection"])
19
+ export type ExportScope = z.infer<typeof ExportScope>
20
+
21
+ /**
22
+ * A serialized model file returned by {@link PluginCoreIoExportApi.model}.
23
+ *
24
+ * | Property | Type | Description |
25
+ * |---|---|---|
26
+ * | `fileName` | `string` | Suggested file name incl. extension (e.g. `"model.glb"`) |
27
+ * | `mimeType` | `string` | MIME type (`"model/gltf-binary"` for glb, `"text/plain"` for obj) |
28
+ * | `dataBase64` | `string` | The file's bytes, base64-encoded (decode to save/download) |
29
+ */
30
+ export const ExportedFile = z.object({
31
+ fileName: z.string(),
32
+ mimeType: z.string(),
33
+ dataBase64: z.string(),
34
+ })
35
+ export type ExportedFile = z.infer<typeof ExportedFile>
36
+
37
+ /**
38
+ * Model export — serialize the scene (or selection) to a downloadable 3D file.
39
+ *
40
+ * `core.io.export.model` hands you the file bytes as base64 — no download
41
+ * dialog opens; the plugin decides what to do with the result (save it, POST
42
+ * it, diff it). For a different export intent, see `presentation.export`
43
+ * (Present-mode layout sheets to PDF/PNG/JPG) and `program.spreadsheet.export`
44
+ * (the area-program / takeoff workbook). Four formats:
45
+ *
46
+ * - `"glb"` — binary glTF (`model/gltf-binary`); geometry + materials,
47
+ * serialized in the browser (nothing is uploaded).
48
+ * - `"obj"` — Wavefront OBJ text (`text/plain`); geometry only, serialized in
49
+ * the browser.
50
+ * - `"fbx"` / `"3ds"` — Autodesk FBX / 3D Studio; the scene is uploaded to the
51
+ * same `/exportmodel/` conversion service the app's Export dialog uses, and
52
+ * the call resolves once the converted artifact is fetched back — a **zip**
53
+ * (`application/zip`) containing the `.fbx`/`.3ds` file. Whole-scene only
54
+ * (`scope: "selection"` is rejected). Conversion runs on the server and is
55
+ * bounded by the per-call plugin timeout (60 s) — very large models may
56
+ * exceed it and reject with `TIMEOUT`.
57
+ *
58
+ * For the browser formats, only real model geometry is exported (walls, slabs,
59
+ * roofs, floors, doors, windows, furniture, staircases, masses, ceilings,
60
+ * mullions, beams, columns, terrain); UI helpers, hidden objects, and
61
+ * hidden-bucket objects are excluded — matching the app's GLB export. The
62
+ * server formats convert the full serialized scene (hidden-bucket objects
63
+ * excluded), exactly like the Export dialog. This is a **read**: it never
64
+ * mutates the model.
65
+ *
66
+ * > Server-backed BIM exports (RVT / IFC / DWG) are **not** exposed here — those
67
+ * > run as fire-and-forget Forge jobs that stream a browser download and return
68
+ * > no retrievable bytes. Use the app's Export menu for those.
69
+ *
70
+ * Accessed via `snaptrude.core.io.export`.
71
+ */
72
+ export abstract class PluginCoreIoExportApi {
73
+ constructor() {}
74
+
75
+ /**
76
+ * Export the model to a 3D file and return its bytes as base64.
77
+ *
78
+ * @param format - `"glb"` (binary glTF, geometry + materials), `"obj"`
79
+ * (Wavefront OBJ text, geometry only) — both serialized in the browser —
80
+ * or `"fbx"` / `"3ds"`, converted by the app's export service and returned
81
+ * as a zip containing the converted file.
82
+ * @param scope - `"scene"` (default) for the whole model, or `"selection"` for
83
+ * only the currently selected objects (browser formats only — `"fbx"`/`"3ds"`
84
+ * reject it). An empty selection yields an empty file.
85
+ * @returns an {@linkcode ExportedFile} — `{ fileName, mimeType, dataBase64 }`.
86
+ * @throws if the format is unsupported, `scope: "selection"` is combined with a
87
+ * server format, or the serialization/conversion fails.
88
+ *
89
+ * @examplePrompt Export the model as a GLB
90
+ * @examplePrompt Give me the whole scene as an OBJ file
91
+ * @examplePrompt Export just my selection to GLB
92
+ * @examplePrompt Download the model as an FBX file
93
+ * @examplePrompt Export the scene to 3DS for 3ds Max
94
+ *
95
+ * # Example
96
+ * ```ts
97
+ * const file = await snaptrude.core.io.export.model("glb")
98
+ * // decode base64 → bytes and save/download in the plugin UI
99
+ * const bytes = Uint8Array.from(atob(file.dataBase64), (c) => c.charCodeAt(0))
100
+ * const blob = new Blob([bytes], { type: file.mimeType })
101
+ * // ...offer blob for download as file.fileName
102
+ *
103
+ * // Only the current selection, as OBJ text:
104
+ * const obj = await snaptrude.core.io.export.model("obj", "selection")
105
+ * const text = atob(obj.dataBase64)
106
+ * ```
107
+ */
108
+ public abstract model(
109
+ format: ExportModelFormat,
110
+ scope?: ExportScope,
111
+ ): PluginApiReturn<ExportedFile>
112
+ }
113
+
114
+ /**
115
+ * Arguments for {@link PluginCoreIoExportApi.model}.
116
+ *
117
+ * | Property | Type | Description |
118
+ * |---|---|---|
119
+ * | `format` | {@link ExportModelFormat} | `"glb"`, `"obj"`, `"fbx"`, or `"3ds"` |
120
+ * | `scope` | {@link ExportScope} | `"scene"` (default) or `"selection"` (browser formats only) |
121
+ */
122
+ export const PluginExportModelArgs = z.object({
123
+ format: ExportModelFormat,
124
+ scope: ExportScope.optional(),
125
+ })
126
+ export type PluginExportModelArgs = z.infer<typeof PluginExportModelArgs>
@@ -55,6 +55,9 @@ export abstract class PluginCoreIoImportApi {
55
55
  * Supported formats: PNG, JPG/JPEG, BMP. The image is placed on the target
56
56
  * storey's "Image" layer at ~50% opacity by default.
57
57
  *
58
+ * To place the image on a **Present-mode sheet** instead of the scene, use
59
+ * `presentation.import.image`.
60
+ *
58
61
  * The plane is placed at the storey origin (the engine's import placement);
59
62
  * there is no placement parameter — calibrate size with
60
63
  * {@link PluginCoreIoUnderlayApi.setScale} after import.
@@ -308,6 +311,40 @@ export abstract class PluginCoreIoImportApi {
308
311
  neighborhood?: boolean,
309
312
  parcels?: boolean,
310
313
  ): PluginApiReturn<TerrainHandle>
314
+
315
+ /**
316
+ * Import an **EPW weather file** into the project's weather catalog.
317
+ *
318
+ * Uploads an EnergyPlus Weather (`.epw`) file and registers it as the
319
+ * project's site weather, returning its catalog `weatherFileId` — the same id
320
+ * {@link PluginAnalysisWeatherApi.getSeries}, `program.site.getWeather`, and a
321
+ * daylight run's provenance report. Uploading a user file makes the site's
322
+ * `selectionMethod` `"user-upload"`, overriding nearest-station resolution.
323
+ *
324
+ * **Mutating**: this writes project state and is subject to the plugin
325
+ * write-gate — it throws when plugin writes are disabled. Unlike the file
326
+ * underlay/model importers it returns no scene handle (a weather file is not
327
+ * a scene object), only the catalog `{ weatherFileId, label }`.
328
+ *
329
+ * @param source - The `.epw` file to import: an `https://` URL or a `data:` URL.
330
+ * @returns A {@linkcode PluginImportEpwResult} — the catalog `weatherFileId`
331
+ * and a human-readable `label` (the station/file name).
332
+ * @throws if writes are disabled, the source can't be loaded, or the file is
333
+ * not a valid EPW.
334
+ *
335
+ * @examplePrompt Import this EPW weather file for the site
336
+ * @examplePrompt Upload a custom weather file for the daylight analysis
337
+ * @examplePrompt Use this .epw as the project's weather source
338
+ *
339
+ * # Example
340
+ * ```ts
341
+ * const { weatherFileId, label } = await snaptrude.core.io.import.epw(
342
+ * "https://example.com/Chicago-OHare.epw",
343
+ * )
344
+ * console.log(`Weather set to ${label} (${weatherFileId})`)
345
+ * ```
346
+ */
347
+ public abstract epw(source: string): PluginApiReturn<PluginImportEpwResult>
311
348
  }
312
349
 
313
350
  /**
@@ -430,3 +467,30 @@ export const PluginImportTerrainArgs = z.object({
430
467
  parcels: z.boolean().optional(),
431
468
  })
432
469
  export type PluginImportTerrainArgs = z.infer<typeof PluginImportTerrainArgs>
470
+
471
+ /**
472
+ * Arguments for {@link PluginCoreIoImportApi.epw}.
473
+ *
474
+ * | Property | Type | Description |
475
+ * |---|---|---|
476
+ * | `source` | `string` | EPW `https://` URL or `data:` URL |
477
+ */
478
+ export const PluginImportEpwArgs = z.object({
479
+ source: ImportSource,
480
+ })
481
+ export type PluginImportEpwArgs = z.infer<typeof PluginImportEpwArgs>
482
+
483
+ /**
484
+ * Result of {@link PluginCoreIoImportApi.epw} — the imported weather file's
485
+ * catalog entry.
486
+ *
487
+ * | Property | Type | Description |
488
+ * |---|---|---|
489
+ * | `weatherFileId` | `string` | Catalog id (same key as `analysis.weather`'s `weatherFileId`) |
490
+ * | `label` | `string` | Human-readable name (station / file name) |
491
+ */
492
+ export const PluginImportEpwResult = z.object({
493
+ weatherFileId: z.string(),
494
+ label: z.string(),
495
+ })
496
+ export type PluginImportEpwResult = z.infer<typeof PluginImportEpwResult>
@@ -3,6 +3,7 @@ import { PluginCoreIoJobApi } from "./job"
3
3
  import { PluginCoreIoUnderlayApi } from "./underlay"
4
4
  import { PluginCoreIoTerrainApi } from "./terrain"
5
5
  import { PluginCoreIoQueryApi } from "./query"
6
+ import { PluginCoreIoExportApi } from "./export"
6
7
 
7
8
  /**
8
9
  * I/O — bring external files into the project and manage what was imported.
@@ -12,6 +13,7 @@ import { PluginCoreIoQueryApi } from "./query"
12
13
  * - {@linkcode PluginCoreIoApi.job} — poll long-running async imports (e.g. DWG)
13
14
  * - {@linkcode PluginCoreIoApi.underlay} — inspect/scale/opacity/delete placed underlays
14
15
  * - {@linkcode PluginCoreIoApi.terrain} — inspect/edit the site terrain (datum, layers, delete)
16
+ * - {@linkcode PluginCoreIoApi.export} — serialize the model to glb/obj (base64 bytes)
15
17
  *
16
18
  * Accessed via `snaptrude.core.io`.
17
19
  */
@@ -26,6 +28,8 @@ export abstract class PluginCoreIoApi {
26
28
  public abstract underlay: PluginCoreIoUnderlayApi
27
29
  /** Inspect and manage the site terrain. See {@linkcode PluginCoreIoTerrainApi}. */
28
30
  public abstract terrain: PluginCoreIoTerrainApi
31
+ /** Serialize the model to a downloadable 3D file. See {@linkcode PluginCoreIoExportApi}. */
32
+ public abstract export: PluginCoreIoExportApi
29
33
 
30
34
  constructor() {}
31
35
  }
@@ -35,3 +39,4 @@ export * from "./job"
35
39
  export * from "./underlay"
36
40
  export * from "./terrain"
37
41
  export * from "./query"
42
+ export * from "./export"
@@ -0,0 +1,96 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../../types"
3
+
4
+ /**
5
+ * The editor's top-bar application modes — the tabs a user switches between
6
+ * while working on a project.
7
+ */
8
+ export const PluginAppMode = z.enum(["design", "bim", "present", "program"])
9
+ export type PluginAppMode = z.infer<typeof PluginAppMode>
10
+
11
+ export const PluginCoreModeSetArgs = z.object({
12
+ mode: PluginAppMode,
13
+ })
14
+ export type PluginCoreModeSetArgs = z.infer<typeof PluginCoreModeSetArgs>
15
+
16
+ export interface PluginCoreModeListResult {
17
+ modes: PluginAppMode[]
18
+ }
19
+
20
+ export interface PluginCoreModeSetResult {
21
+ mode: PluginAppMode
22
+ }
23
+
24
+ /**
25
+ * Application-mode control — read and switch the editor's top-bar mode
26
+ * (Design, BIM, Present, Program), the same tabs a user clicks in the
27
+ * top menu bar. Accessed via `snaptrude.core.mode`.
28
+ *
29
+ * Not to be confused with the viewport's 2D/3D camera mode
30
+ * (`core.camera.setMode`) or saved presentation views (`presentation.views`).
31
+ *
32
+ * `set` covers `design`, `bim`, and `present` — in-page switches.
33
+ * `program` opens in its own browser tab in the product, which a plugin worker
34
+ * cannot do, so `set("program")` fails with `PRECONDITION_FAILED`; `get()`
35
+ * still reports `"program"` for code running in the Program tab.
36
+ */
37
+ export abstract class PluginCoreModeApi {
38
+ constructor() {}
39
+
40
+ /**
41
+ * List every application mode the editor has.
42
+ *
43
+ * @returns The full set of mode tokens accepted by {@linkcode get} / {@linkcode set}.
44
+ *
45
+ * @examplePrompt What modes does Snaptrude have?
46
+ * @examplePrompt List the editor modes I can switch to
47
+ *
48
+ * # Example
49
+ * ```ts
50
+ * const { modes } = await snaptrude.core.mode.list()
51
+ * // ["design", "bim", "present", "program"]
52
+ * ```
53
+ */
54
+ public abstract list(): PluginApiReturn<PluginCoreModeListResult>
55
+
56
+ /**
57
+ * Get the currently active application mode.
58
+ *
59
+ * @returns The active mode token (e.g. `"design"`).
60
+ *
61
+ * @examplePrompt Which mode am I in right now?
62
+ * @examplePrompt Am I in present mode?
63
+ * @examplePrompt Check whether the editor is in BIM mode
64
+ *
65
+ * # Example
66
+ * ```ts
67
+ * const mode = await snaptrude.core.mode.get()
68
+ * if (mode !== "present") await snaptrude.core.mode.set("present")
69
+ * ```
70
+ */
71
+ public abstract get(): PluginApiReturn<PluginAppMode>
72
+
73
+ /**
74
+ * Switch the editor to another application mode — the same action as
75
+ * clicking that tab in the top menu bar.
76
+ *
77
+ * Supported: `"design"`, `"bim"`, `"present"`. Switching to
78
+ * `"program"` is rejected with `PRECONDITION_FAILED` (the Program surface
79
+ * opens in its own browser tab in the product; a plugin cannot open one).
80
+ *
81
+ * @param mode - Target mode token from {@linkcode PluginAppMode}
82
+ * @returns The committed `{ mode }` after the switch.
83
+ *
84
+ * @examplePrompt Switch to present mode
85
+ * @examplePrompt Open BIM mode
86
+ * @examplePrompt Go back to design mode
87
+ *
88
+ * # Example
89
+ * ```ts
90
+ * await snaptrude.core.mode.set("present")
91
+ * // ... presentation work ...
92
+ * await snaptrude.core.mode.set("design")
93
+ * ```
94
+ */
95
+ public abstract set(mode: PluginAppMode): PluginApiReturn<PluginCoreModeSetResult>
96
+ }