@snaptrude/plugin-core 0.5.0 → 0.6.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 (67) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/api-manifest.full.json +2044 -443
  3. package/api-manifest.json +2051 -394
  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 +5 -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/design/create/index.d.ts +9 -0
  32. package/dist/api/design/create/index.d.ts.map +1 -1
  33. package/dist/api/design/query/spaces.d.ts +3 -3
  34. package/dist/api/design/selection/index.d.ts +144 -0
  35. package/dist/api/design/selection/index.d.ts.map +1 -1
  36. package/dist/api/entity/space.d.ts +2 -2
  37. package/dist/api/index.d.ts +5 -0
  38. package/dist/api/index.d.ts.map +1 -1
  39. package/dist/api/program/site.d.ts +84 -0
  40. package/dist/api/program/site.d.ts.map +1 -1
  41. package/dist/handles.d.ts +33 -0
  42. package/dist/handles.d.ts.map +1 -1
  43. package/dist/index.cjs +1335 -987
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.js +1278 -983
  46. package/dist/index.js.map +1 -1
  47. package/package.json +1 -1
  48. package/scripts/generate-manifest.test.mjs +26 -4
  49. package/src/api/analysis/heatmaps.ts +256 -0
  50. package/src/api/analysis/illuminance.ts +155 -0
  51. package/src/api/analysis/index.ts +46 -0
  52. package/src/api/analysis/shadows.ts +183 -0
  53. package/src/api/analysis/sunlightHours.ts +211 -0
  54. package/src/api/analysis/sunpath.ts +83 -0
  55. package/src/api/core/index.ts +5 -0
  56. package/src/api/core/io/import/index.ts +432 -0
  57. package/src/api/core/io/index.ts +37 -0
  58. package/src/api/core/io/job/index.ts +140 -0
  59. package/src/api/core/io/query/index.ts +71 -0
  60. package/src/api/core/io/terrain/index.ts +214 -0
  61. package/src/api/core/io/underlay/index.ts +295 -0
  62. package/src/api/design/create/index.ts +9 -0
  63. package/src/api/design/erase/index.ts +1 -1
  64. package/src/api/design/selection/index.ts +129 -0
  65. package/src/api/index.ts +5 -0
  66. package/src/api/program/site.ts +93 -0
  67. package/src/handles.ts +46 -0
@@ -0,0 +1,211 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../types"
3
+
4
+ /**
5
+ * Analysis sunlightHours — the direct-sunlight-hours heatmap study.
6
+ *
7
+ * Computes, for every space surface (Room or Department Mass — generic
8
+ * Masses are not enough), how many hours of direct sunlight
9
+ * it receives over a date range, and renders the result as a heatmap on the
10
+ * scene. The computation is an **asynchronous backend job**:
11
+ *
12
+ * 1. {@linkcode PluginAnalysisSunlightHoursApi.compute} starts the job and
13
+ * returns immediately.
14
+ * 2. Poll {@linkcode PluginAnalysisSunlightHoursApi.get} until `status` is
15
+ * `"active"` (heatmap rendered) — a run typically takes minutes. There is
16
+ * no completion event; polling is the pattern.
17
+ * 3. {@linkcode PluginAnalysisSunlightHoursApi.cancel} aborts an in-flight
18
+ * run; {@linkcode PluginAnalysisSunlightHoursApi.reset} clears a rendered
19
+ * heatmap.
20
+ *
21
+ * Heatmaps are invalidated by scene-mutating edits — re-run the study after
22
+ * changing the model. Dates cross as ISO 8601 date strings (`"YYYY-MM-DD"`).
23
+ *
24
+ * Accessed via `snaptrude.analysis.sunlightHours`.
25
+ */
26
+ export abstract class PluginAnalysisSunlightHoursApi {
27
+ constructor() {}
28
+
29
+ /**
30
+ * Start a direct-sunlight-hours run for a date range.
31
+ *
32
+ * Starts the backend job and **returns immediately** — it does not wait
33
+ * for the heatmap. Poll {@linkcode PluginAnalysisSunlightHoursApi.get}
34
+ * until `status` is `"active"`. Starting a new run while one is in flight
35
+ * replaces it. Shadows and the heatmap analyses are mutually exclusive in
36
+ * the product: starting a run disables real-time shadows and resets/cancels
37
+ * any {@linkcode PluginAnalysisIlluminanceApi} (`analysis.illuminance`)
38
+ * study.
39
+ *
40
+ * @param startDate - Start of the study range, ISO date `"YYYY-MM-DD"`.
41
+ * @param endDate - End of the study range, ISO date `"YYYY-MM-DD"` (on or
42
+ * after `startDate`).
43
+ * @returns A {@linkcode PluginAnalysisComputeResult} — `{ success: true }`
44
+ * when the job was started. The `{ success: false, error }` arm is
45
+ * reserved — not yet emitted (start failures currently throw).
46
+ * @throws When the project has no geo-located site/terrain (no location to
47
+ * compute sun exposure for — there is no fallback location).
48
+ * @throws When the scene has no space (Room or Department Mass) to analyse
49
+ * or the editor is not in the 3D view.
50
+ * @throws When a date is not a parseable ISO date or the range is inverted.
51
+ * @throws When plugin writes are disabled.
52
+ *
53
+ * @examplePrompt Run a sunlight hours analysis for June
54
+ * @examplePrompt Compute direct sunlight hours between March and September
55
+ * @examplePrompt How much sun does my building get over the summer?
56
+ *
57
+ * # Example
58
+ * ```ts
59
+ * const { success } = await snaptrude.analysis.sunlightHours.compute(
60
+ * "2026-06-01",
61
+ * "2026-06-30",
62
+ * )
63
+ * // poll until the heatmap is rendered
64
+ * let job = await snaptrude.analysis.sunlightHours.get()
65
+ * while (job?.status === "running") {
66
+ * await new Promise((r) => setTimeout(r, 5000))
67
+ * job = await snaptrude.analysis.sunlightHours.get()
68
+ * }
69
+ * ```
70
+ */
71
+ public abstract compute(
72
+ startDate: string,
73
+ endDate: string,
74
+ ): PluginApiReturn<PluginAnalysisComputeResult>
75
+
76
+ /**
77
+ * Get the state of the sunlight-hours study.
78
+ *
79
+ * The polling read for the async job started by
80
+ * {@linkcode PluginAnalysisSunlightHoursApi.compute}. `status` values:
81
+ *
82
+ * | Status | Meaning |
83
+ * |---|---|
84
+ * | `"running"` | A run is in flight — keep polling |
85
+ * | `"active"` | The heatmap is rendered on the scene |
86
+ * | `"inactive"` | A previous run exists but its heatmap is not showing |
87
+ *
88
+ * @returns A {@linkcode PluginAnalysisJobStateResult} with the `status` and
89
+ * the run's ISO `startDate`/`endDate`, or `null` when no run result is
90
+ * available (the study never ran, was cancelled, or the last run failed).
91
+ *
92
+ * @examplePrompt Is the sunlight analysis done?
93
+ * @examplePrompt Check the status of the sunlight hours run
94
+ * @examplePrompt What date range was the sunlight heatmap computed for?
95
+ *
96
+ * # Example
97
+ * ```ts
98
+ * const job = await snaptrude.analysis.sunlightHours.get()
99
+ * if (job?.status === "active") console.log(job.startDate, job.endDate)
100
+ * ```
101
+ */
102
+ public abstract get(): PluginApiReturn<PluginAnalysisJobStateResult>
103
+
104
+ /**
105
+ * Cancel the in-flight sunlight-hours run.
106
+ *
107
+ * Aborts the backend job. A no-op (returns `false`) when nothing is
108
+ * running.
109
+ *
110
+ * @returns `true` when a run was cancelled, `false` when nothing was
111
+ * running.
112
+ * @throws When plugin writes are disabled.
113
+ *
114
+ * @examplePrompt Cancel the sunlight analysis
115
+ * @examplePrompt Stop the running sunlight hours computation
116
+ * @examplePrompt Abort the sun study
117
+ *
118
+ * # Example
119
+ * ```ts
120
+ * await snaptrude.analysis.sunlightHours.cancel()
121
+ * ```
122
+ */
123
+ public abstract cancel(): PluginApiReturn<boolean>
124
+
125
+ /**
126
+ * Clear the sunlight-hours heatmap from the scene.
127
+ *
128
+ * Un-applies the rendered heatmap and restores the normal material view.
129
+ * A no-op (returns `false`) when no heatmap is showing. Does not cancel an
130
+ * in-flight run — use {@linkcode PluginAnalysisSunlightHoursApi.cancel}.
131
+ *
132
+ * @returns `true` when a heatmap was cleared, `false` when none was
133
+ * showing.
134
+ * @throws When plugin writes are disabled.
135
+ *
136
+ * @examplePrompt Clear the sunlight heatmap
137
+ * @examplePrompt Remove the sun hours colours from the model
138
+ * @examplePrompt Reset the sunlight analysis view
139
+ *
140
+ * # Example
141
+ * ```ts
142
+ * await snaptrude.analysis.sunlightHours.reset()
143
+ * ```
144
+ */
145
+ public abstract reset(): PluginApiReturn<boolean>
146
+ }
147
+
148
+ /**
149
+ * Result of starting an analysis job
150
+ * ({@linkcode PluginAnalysisSunlightHoursApi.compute} /
151
+ * {@linkcode PluginAnalysisIlluminanceApi.compute}).
152
+ *
153
+ * The `success: false` arm is **reserved — not yet emitted**: the current
154
+ * host always returns `{ success: true }` (start failures throw instead); a
155
+ * failure indicator may be added additively later.
156
+ *
157
+ * | Property | Type | Description |
158
+ * |---|---|---|
159
+ * | `success` | `boolean` | `true` when the backend job was started |
160
+ * | `error` | `string \| undefined` | Failure reason when `success` is `false` (reserved — not yet emitted) |
161
+ */
162
+ export const PluginAnalysisComputeResult = z.object({
163
+ success: z.boolean(),
164
+ error: z.string().optional(),
165
+ })
166
+ export type PluginAnalysisComputeResult = z.infer<
167
+ typeof PluginAnalysisComputeResult
168
+ >
169
+
170
+ /**
171
+ * The status of an analysis heatmap job.
172
+ *
173
+ * | Value | Meaning |
174
+ * |---|---|
175
+ * | `"running"` | A run is in flight — keep polling |
176
+ * | `"active"` | The heatmap is rendered on the scene |
177
+ * | `"inactive"` | A previous run exists but its heatmap is not showing |
178
+ */
179
+ export const PluginAnalysisJobStatus = z.enum([
180
+ "running",
181
+ "active",
182
+ "inactive",
183
+ ])
184
+ export type PluginAnalysisJobStatus = z.infer<typeof PluginAnalysisJobStatus>
185
+
186
+ /**
187
+ * The state of an analysis heatmap job.
188
+ *
189
+ * | Property | Type | Description |
190
+ * |---|---|---|
191
+ * | `status` | {@linkcode PluginAnalysisJobStatus} | `"running"` \| `"active"` \| `"inactive"` |
192
+ * | `startDate` | `string` | ISO date (`"YYYY-MM-DD"`) the run was computed from |
193
+ * | `endDate` | `string` | ISO date (`"YYYY-MM-DD"`) the run was computed to |
194
+ */
195
+ export const PluginAnalysisJobState = z.object({
196
+ status: PluginAnalysisJobStatus,
197
+ startDate: z.string(),
198
+ endDate: z.string(),
199
+ })
200
+ export type PluginAnalysisJobState = z.infer<typeof PluginAnalysisJobState>
201
+
202
+ /**
203
+ * Result of {@linkcode PluginAnalysisSunlightHoursApi.get} /
204
+ * {@linkcode PluginAnalysisIlluminanceApi.get} — the job state, or `null`
205
+ * when no run result is available (the study never ran, was cancelled, or
206
+ * the last run failed).
207
+ */
208
+ export const PluginAnalysisJobStateResult = PluginAnalysisJobState.nullable()
209
+ export type PluginAnalysisJobStateResult = z.infer<
210
+ typeof PluginAnalysisJobStateResult
211
+ >
@@ -0,0 +1,83 @@
1
+ import { PluginApiReturn } from "../../types"
2
+
3
+ /**
4
+ * Analysis sunpath — the sun-path diagram overlay.
5
+ *
6
+ * The sun-path diagram draws the sun's annual/daily trajectory arcs over the
7
+ * scene for the project's geographic location, so daylight behaviour can be
8
+ * read directly off the model. Toggling it is an **undoable** action (it goes
9
+ * through the command stack, so `core.history.undo` reverts it).
10
+ *
11
+ * The overlay is computed for the project's geo-location. Enabling **throws**
12
+ * when the project has no geo-located site/terrain — there is no fallback
13
+ * location. Set the site location first (Import terrain / site context);
14
+ * read it via `program.site.getLocation`.
15
+ *
16
+ * Accessed via `snaptrude.analysis.sunpath`.
17
+ */
18
+ export abstract class PluginAnalysisSunpathApi {
19
+ constructor() {}
20
+
21
+ /**
22
+ * Turn the sun-path diagram overlay ON.
23
+ *
24
+ * Undoable: the toggle is committed through the command stack. A no-op
25
+ * (returns `true`) when the overlay is already active.
26
+ *
27
+ * @returns `true` — the overlay is active after the call.
28
+ * @throws When the project has no geo-located site/terrain (no location to
29
+ * compute the sun trajectory for).
30
+ * @throws When plugin writes are disabled.
31
+ *
32
+ * @examplePrompt Show the sun path diagram
33
+ * @examplePrompt Turn on the sunpath overlay
34
+ * @examplePrompt Visualize the sun's trajectory over my building
35
+ *
36
+ * # Example
37
+ * ```ts
38
+ * await snaptrude.analysis.sunpath.enable()
39
+ * const active = await snaptrude.analysis.sunpath.isActive() // true
40
+ * ```
41
+ */
42
+ public abstract enable(): PluginApiReturn<boolean>
43
+
44
+ /**
45
+ * Turn the sun-path diagram overlay OFF.
46
+ *
47
+ * Undoable: the toggle is committed through the command stack. A no-op
48
+ * (returns `false`) when the overlay is already off.
49
+ *
50
+ * @returns `false` — the overlay is inactive after the call.
51
+ * @throws When plugin writes are disabled.
52
+ *
53
+ * @examplePrompt Hide the sun path diagram
54
+ * @examplePrompt Turn off the sunpath overlay
55
+ * @examplePrompt Remove the sun trajectory arcs from the scene
56
+ *
57
+ * # Example
58
+ * ```ts
59
+ * await snaptrude.analysis.sunpath.disable()
60
+ * ```
61
+ */
62
+ public abstract disable(): PluginApiReturn<boolean>
63
+
64
+ /**
65
+ * Whether the sun-path diagram overlay is currently active.
66
+ *
67
+ * A pure read — never mutates, never throws.
68
+ *
69
+ * @returns `true` when the overlay is showing.
70
+ *
71
+ * @examplePrompt Is the sun path diagram on?
72
+ * @examplePrompt Check whether the sunpath overlay is active
73
+ * @examplePrompt Am I looking at the sun trajectory right now?
74
+ *
75
+ * # Example
76
+ * ```ts
77
+ * if (!(await snaptrude.analysis.sunpath.isActive())) {
78
+ * await snaptrude.analysis.sunpath.enable()
79
+ * }
80
+ * ```
81
+ */
82
+ public abstract isActive(): PluginApiReturn<boolean>
83
+ }
@@ -9,6 +9,7 @@ import { PluginCoreGroupsApi } from "./groups"
9
9
  import { PluginCoreBuildingsApi } from "./buildings"
10
10
  import { PluginCoreLayersApi } from "./layers"
11
11
  import { PluginCoreTagsApi } from "./tags"
12
+ import { PluginCoreIoApi } from "./io"
12
13
 
13
14
  /**
14
15
  * Core primitives and infrastructure used across the plugin API.
@@ -24,6 +25,7 @@ import { PluginCoreTagsApi } from "./tags"
24
25
  * - {@linkcode PluginCoreApi.buildings} — Read & edit buildings and their storeys
25
26
  * - {@linkcode PluginCoreApi.layers} — Read & toggle storey drawing/reference layers
26
27
  * - {@linkcode PluginCoreApi.tags} — Tag catalog + assignment
28
+ * - {@linkcode PluginCoreApi.io} — Import files (image/pdf/cad/model/terrain), poll jobs, manage underlays
27
29
  */
28
30
  export abstract class PluginCoreApi {
29
31
  /** Vector and quaternion math utilities. See {@linkcode PluginMathApi}. */
@@ -48,6 +50,8 @@ export abstract class PluginCoreApi {
48
50
  public abstract layers: PluginCoreLayersApi
49
51
  /** Tags — tag catalog + assignment. See {@linkcode PluginCoreTagsApi}. */
50
52
  public abstract tags: PluginCoreTagsApi
53
+ /** I/O — file import, import jobs, and underlay management. See {@linkcode PluginCoreIoApi}. */
54
+ public abstract io: PluginCoreIoApi
51
55
 
52
56
  constructor() {}
53
57
  }
@@ -63,3 +67,4 @@ export * from "./groups"
63
67
  export * from "./buildings"
64
68
  export * from "./layers"
65
69
  export * from "./tags"
70
+ export * from "./io"