@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snaptrude/plugin-core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -48,10 +48,7 @@ test("all 4 Phase-1 slice methods are present with intent + prompts", () => {
48
48
  })
49
49
 
50
50
  test("departments.get carries its args type; list takes no args", () => {
51
- assert.equal(
52
- byPath.get("program.departments.get").argsType,
53
- "PluginProgramDepartmentsGetArgs",
54
- )
51
+ assert.equal(byPath.get("program.departments.get").argsType, "string")
55
52
  assert.equal(byPath.get("program.departments.list").argsType, null)
56
53
  })
57
54
 
@@ -109,6 +106,31 @@ test("promoted methods are present in the manifest", () => {
109
106
  "core.layers.setActive",
110
107
  "core.layers.update",
111
108
  "program.areas.update",
109
+ // 2026-07-06 promotions — analysis namespace + program.site geo reads,
110
+ // react hosts landed:
111
+ "analysis.sunpath.enable",
112
+ "analysis.sunpath.disable",
113
+ "analysis.sunpath.isActive",
114
+ "analysis.shadows.enable",
115
+ "analysis.shadows.disable",
116
+ "analysis.shadows.isEnabled",
117
+ "analysis.shadows.setDateTime",
118
+ "analysis.shadows.getDateTime",
119
+ "analysis.sunlightHours.compute",
120
+ "analysis.sunlightHours.get",
121
+ "analysis.sunlightHours.cancel",
122
+ "analysis.sunlightHours.reset",
123
+ "analysis.illuminance.compute",
124
+ "analysis.illuminance.get",
125
+ "analysis.illuminance.cancel",
126
+ "analysis.illuminance.reset",
127
+ "program.site.getLocation",
128
+ "program.site.getNorthAngle",
129
+ // 2026-07-07 promotion — analysis.heatmaps, react host landed:
130
+ "analysis.heatmaps.renderSpaces",
131
+ "analysis.heatmaps.renderGrid",
132
+ "analysis.heatmaps.reset",
133
+ "analysis.heatmaps.isActive",
112
134
  ]
113
135
  for (const p of promoted) {
114
136
  assert.ok(
@@ -0,0 +1,256 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../types"
3
+ import { ComponentHandle, Vec3Components } from "../../handles"
4
+
5
+ /**
6
+ * Analysis heatmaps — render plugin-computed scalar data as a heatmap.
7
+ *
8
+ * Unlike the built-in studies ({@linkcode PluginAnalysisSunlightHoursApi},
9
+ * {@linkcode PluginAnalysisIlluminanceApi}) where the host computes the
10
+ * values, here the **plugin brings its own numbers** and the host renders
11
+ * them. Two render modes:
12
+ *
13
+ * - {@linkcode PluginAnalysisHeatmapsApi.renderSpaces} — one flat colour per
14
+ * space, painted on the space's top face (occupancy, energy use, any
15
+ * per-room metric).
16
+ * - {@linkcode PluginAnalysisHeatmapsApi.renderGrid} — a coloured grid mesh
17
+ * from point samples in world coordinates (wind, noise, microclimate — any
18
+ * field sampled over an area).
19
+ *
20
+ * Shared semantics:
21
+ *
22
+ * - **Single active heatmap** — a render call **replaces** whatever heatmap
23
+ * is currently showing (from either mode).
24
+ * - **Legend** — the host renders a legend card from
25
+ * {@linkcode PluginAnalysisHeatmapOptions} (title, unit, min/max, colour
26
+ * segments). Values outside `[min, max]` **clamp to the end colours** and
27
+ * the legend shows `<` / `>` markers at the clamped ends.
28
+ * - **Ephemeral** — the heatmap is a transient overlay: never persisted,
29
+ * never saved with views, and auto-cleared when a scene-mutating edit
30
+ * invalidates it. Re-render after changing the model.
31
+ *
32
+ * Accessed via `snaptrude.analysis.heatmaps`.
33
+ */
34
+ export abstract class PluginAnalysisHeatmapsApi {
35
+ constructor() {}
36
+
37
+ /**
38
+ * Render a per-space heatmap — one flat colour per space's top face.
39
+ *
40
+ * Each entry maps a space to a scalar value; the value is mapped through
41
+ * the colour ramp (see {@linkcode PluginAnalysisHeatmapOptions}) and the
42
+ * space's top face is painted that single flat colour. Replaces any
43
+ * heatmap currently showing (single active heatmap). Spaces whose top
44
+ * face is not flat (pitched/sloped tops) are **skipped with a console
45
+ * warning** — the rest of the heatmap still renders.
46
+ *
47
+ * The heatmap is ephemeral: it is auto-cleared by scene-mutating edits
48
+ * and is never persisted or saved with views.
49
+ *
50
+ * @param entries - One {@linkcode PluginAnalysisHeatmapSpaceEntry} per
51
+ * space: the space's handle and its scalar value.
52
+ * @param options - {@linkcode PluginAnalysisHeatmapOptions} — legend
53
+ * title/unit, explicit min/max range (auto-derived from the data when
54
+ * omitted), and the colour ramp.
55
+ * @returns A {@linkcode PluginAnalysisHeatmapsRenderResult} —
56
+ * `{ success: true }` once the heatmap is rendered.
57
+ * @throws When `entries` is empty or a handle does not resolve to a space.
58
+ * @throws When no space had a flat top face to paint (every entry was
59
+ * skipped).
60
+ * @throws When `options.min` is greater than `options.max`.
61
+ * @throws When a colour in `options.colors` is not a 6-digit hex colour.
62
+ * @throws When plugin writes are disabled.
63
+ *
64
+ * @examplePrompt Color each room by its occupancy count
65
+ * @examplePrompt Show my energy simulation results as a heatmap per space
66
+ * @examplePrompt Paint the rooms red to blue by temperature
67
+ *
68
+ * # Example
69
+ * ```ts
70
+ * const spaces = await snaptrude.design.query.listSpaces()
71
+ * await snaptrude.analysis.heatmaps.renderSpaces(
72
+ * spaces.map((space) => ({ space, value: occupancy[space] ?? 0 })),
73
+ * { title: "Occupancy", unit: "people", min: 0, max: 50 },
74
+ * )
75
+ * ```
76
+ */
77
+ public abstract renderSpaces(
78
+ entries: PluginAnalysisHeatmapSpaceEntry[],
79
+ options?: PluginAnalysisHeatmapOptions,
80
+ ): PluginApiReturn<PluginAnalysisHeatmapsRenderResult>
81
+
82
+ /**
83
+ * Render a grid heatmap — a coloured mesh from point samples.
84
+ *
85
+ * Each cell is a scalar sample at a **world-coordinate** position
86
+ * (**y is up** — a ground-level field sits at `y = 0`); the host builds
87
+ * one square cell of edge `cellSize` per sample — in the same Snaptrude
88
+ * internal units as `position` (convert real-world lengths via
89
+ * {@linkcode PluginUnitsApi.convert}) — coloured by mapping the value
90
+ * through the colour ramp
91
+ * (see {@linkcode PluginAnalysisHeatmapOptions}). This is the mode for
92
+ * field data — wind, noise, microclimate — sampled over an area. Replaces
93
+ * any heatmap currently showing (single active heatmap).
94
+ *
95
+ * The heatmap is ephemeral: it is auto-cleared by scene-mutating edits
96
+ * and is never persisted or saved with views.
97
+ *
98
+ * @param cells - One {@linkcode PluginAnalysisHeatmapGridCell} per
99
+ * sample: a world-coordinate `position` (y up) and its scalar `value`.
100
+ * @param cellSize - Edge length of each (square) cell, in the same
101
+ * Snaptrude internal units as `position` (see
102
+ * {@linkcode PluginUnitsApi.convert}). Must be a positive, finite number.
103
+ * @param options - {@linkcode PluginAnalysisHeatmapOptions} — legend
104
+ * title/unit, explicit min/max range (auto-derived from the data when
105
+ * omitted), and the colour ramp.
106
+ * @returns A {@linkcode PluginAnalysisHeatmapsRenderResult} —
107
+ * `{ success: true }` once the heatmap is rendered.
108
+ * @throws When `cells` is empty or `cellSize` is not a positive, finite number.
109
+ * @throws When `options.min` is greater than `options.max`.
110
+ * @throws When a colour in `options.colors` is not a 6-digit hex colour.
111
+ * @throws When plugin writes are disabled.
112
+ *
113
+ * @examplePrompt Overlay my CFD wind simulation results on the site
114
+ * @examplePrompt Render a noise-level grid around the building
115
+ * @examplePrompt Show these sampled microclimate values as a colored grid
116
+ *
117
+ * # Example
118
+ * ```ts
119
+ * // World coordinates are y-up: a ground-level field varies in x/z at y = 0.
120
+ * await snaptrude.analysis.heatmaps.renderGrid(
121
+ * samples.map((s) => ({ position: { x: s.x, y: 0, z: s.z }, value: s.windSpeed })),
122
+ * 2, // 2-unit square cells
123
+ * { title: "Wind speed", unit: "m/s", colors: ["#0000ff", "#00ff00", "#ff0000"] },
124
+ * )
125
+ * ```
126
+ */
127
+ public abstract renderGrid(
128
+ cells: PluginAnalysisHeatmapGridCell[],
129
+ cellSize: number,
130
+ options?: PluginAnalysisHeatmapOptions,
131
+ ): PluginApiReturn<PluginAnalysisHeatmapsRenderResult>
132
+
133
+ /**
134
+ * Clear the plugin heatmap from the scene.
135
+ *
136
+ * Un-applies the rendered heatmap (either mode) and removes its legend.
137
+ * A no-op (returns `false`) when no plugin heatmap is showing. Does not
138
+ * touch the built-in study heatmaps (`sunlightHours` / `illuminance`) —
139
+ * they have their own `reset`.
140
+ *
141
+ * @returns `true` when a heatmap was cleared, `false` when none was
142
+ * showing.
143
+ * @throws When plugin writes are disabled.
144
+ *
145
+ * @examplePrompt Clear my custom heatmap
146
+ * @examplePrompt Remove the wind overlay from the model
147
+ * @examplePrompt Reset the plugin heatmap view
148
+ *
149
+ * # Example
150
+ * ```ts
151
+ * await snaptrude.analysis.heatmaps.reset()
152
+ * ```
153
+ */
154
+ public abstract reset(): PluginApiReturn<boolean>
155
+
156
+ /**
157
+ * Is a plugin heatmap currently showing?
158
+ *
159
+ * `true` between a successful render and the next
160
+ * {@linkcode PluginAnalysisHeatmapsApi.reset} — or the scene-mutating
161
+ * edit that auto-clears it (heatmaps are ephemeral).
162
+ *
163
+ * @returns `true` when a plugin heatmap is rendered on the scene.
164
+ *
165
+ * @examplePrompt Is my heatmap still showing?
166
+ * @examplePrompt Check whether the custom heatmap is active
167
+ * @examplePrompt Do I need to re-render the wind overlay?
168
+ *
169
+ * # Example
170
+ * ```ts
171
+ * if (!(await snaptrude.analysis.heatmaps.isActive())) {
172
+ * await snaptrude.analysis.heatmaps.renderGrid(cells, 2)
173
+ * }
174
+ * ```
175
+ */
176
+ public abstract isActive(): PluginApiReturn<boolean>
177
+ }
178
+
179
+ /**
180
+ * One space's entry in {@linkcode PluginAnalysisHeatmapsApi.renderSpaces}.
181
+ *
182
+ * | Property | Type | Description |
183
+ * |---|---|---|
184
+ * | `space` | {@linkcode ComponentHandle} | Handle of the space to colour |
185
+ * | `value` | `number` | The scalar value mapped to a colour |
186
+ */
187
+ export const PluginAnalysisHeatmapSpaceEntry = z.object({
188
+ space: ComponentHandle,
189
+ value: z.number().finite(),
190
+ })
191
+ export type PluginAnalysisHeatmapSpaceEntry = z.infer<
192
+ typeof PluginAnalysisHeatmapSpaceEntry
193
+ >
194
+
195
+ /**
196
+ * One grid sample in {@linkcode PluginAnalysisHeatmapsApi.renderGrid}.
197
+ *
198
+ * | Property | Type | Description |
199
+ * |---|---|---|
200
+ * | `position` | `{ x, y, z }` | Cell centre in **world coordinates** (y is up) |
201
+ * | `value` | `number` | The scalar value mapped to a colour |
202
+ */
203
+ export const PluginAnalysisHeatmapGridCell = z.object({
204
+ position: Vec3Components,
205
+ value: z.number().finite(),
206
+ })
207
+ export type PluginAnalysisHeatmapGridCell = z.infer<
208
+ typeof PluginAnalysisHeatmapGridCell
209
+ >
210
+
211
+ /**
212
+ * Display options shared by both heatmap render modes.
213
+ *
214
+ * The colour ramp maps values to colours: `colors` is an **ordered list of
215
+ * hex colour stops, low → high** (e.g. `["#0000ff", "#ff0000"]`). When
216
+ * omitted, the host's default blue → cyan → green → yellow → red ramp is used. Values outside
217
+ * `[min, max]` clamp to the end colours; the legend marks the clamped ends
218
+ * with `<` / `>`. `min`/`max` are auto-derived from the data when omitted.
219
+ *
220
+ * | Property | Type | Description |
221
+ * |---|---|---|
222
+ * | `title` | `string \| undefined` | Legend title |
223
+ * | `unit` | `string \| undefined` | Unit label shown on the legend (e.g. `"m/s"`) |
224
+ * | `min` | `number \| undefined` | Value mapped to the first colour stop; data minimum when omitted |
225
+ * | `max` | `number \| undefined` | Value mapped to the last colour stop; data maximum when omitted |
226
+ * | `colors` | `string[] \| undefined` | Ordered 6-digit hex colour stops (e.g. `"#0000ff"`), low → high; host blue → cyan → green → yellow → red default |
227
+ */
228
+ export const PluginAnalysisHeatmapOptions = z.object({
229
+ title: z.string().optional(),
230
+ unit: z.string().optional(),
231
+ min: z.number().finite().optional(),
232
+ max: z.number().finite().optional(),
233
+ colors: z
234
+ .array(z.string().regex(/^#?[0-9a-fA-F]{6}$/, "expected a 6-digit hex colour like \"#0000ff\""))
235
+ .min(1)
236
+ .optional(),
237
+ })
238
+ export type PluginAnalysisHeatmapOptions = z.infer<
239
+ typeof PluginAnalysisHeatmapOptions
240
+ >
241
+
242
+ /**
243
+ * Result of {@linkcode PluginAnalysisHeatmapsApi.renderSpaces} /
244
+ * {@linkcode PluginAnalysisHeatmapsApi.renderGrid} — render failures throw,
245
+ * so a returned value always carries `success: true`.
246
+ *
247
+ * | Property | Type | Description |
248
+ * |---|---|---|
249
+ * | `success` | `true` | The heatmap is rendered on the scene |
250
+ */
251
+ export const PluginAnalysisHeatmapsRenderResult = z.object({
252
+ success: z.literal(true),
253
+ })
254
+ export type PluginAnalysisHeatmapsRenderResult = z.infer<
255
+ typeof PluginAnalysisHeatmapsRenderResult
256
+ >
@@ -0,0 +1,155 @@
1
+ import { PluginApiReturn } from "../../types"
2
+ import {
3
+ PluginAnalysisComputeResult,
4
+ PluginAnalysisJobStateResult,
5
+ } from "./sunlightHours"
6
+
7
+ /**
8
+ * Analysis illuminance — the daylight illuminance (lux) heatmap study.
9
+ *
10
+ * Computes interior daylight illuminance over a date range and renders the
11
+ * result as a heatmap on the scene. **Pro-gated**: every method that starts
12
+ * a run throws when the workspace is not on a Pro plan.
13
+ *
14
+ * Like {@linkcode PluginAnalysisSunlightHoursApi} (`analysis.sunlightHours`),
15
+ * this is an **asynchronous backend job**:
16
+ *
17
+ * 1. {@linkcode PluginAnalysisIlluminanceApi.compute} starts the job and
18
+ * returns immediately.
19
+ * 2. Poll {@linkcode PluginAnalysisIlluminanceApi.get} until `status` is
20
+ * `"active"` (heatmap rendered) — a run typically takes minutes. There is
21
+ * no completion event; polling is the pattern.
22
+ * 3. {@linkcode PluginAnalysisIlluminanceApi.cancel} aborts an in-flight
23
+ * run; {@linkcode PluginAnalysisIlluminanceApi.reset} clears a rendered
24
+ * heatmap.
25
+ *
26
+ * Illuminance analyses BIM slab and roof objects (floors, roofs, …) — walls
27
+ * or bare Masses are not enough — and requires the 3D view. Heatmaps are invalidated by
28
+ * scene-mutating edits. Dates cross as ISO 8601 date strings
29
+ * (`"YYYY-MM-DD"`).
30
+ *
31
+ * Accessed via `snaptrude.analysis.illuminance`.
32
+ */
33
+ export abstract class PluginAnalysisIlluminanceApi {
34
+ constructor() {}
35
+
36
+ /**
37
+ * Start a daylight-illuminance run for a date range.
38
+ *
39
+ * Starts the backend job and **returns immediately** — it does not wait
40
+ * for the heatmap. Poll {@linkcode PluginAnalysisIlluminanceApi.get} until
41
+ * `status` is `"active"`. Starting a new run while one is in flight
42
+ * replaces it. Shadows and the heatmap analyses are mutually exclusive in
43
+ * the product: starting a run disables real-time shadows and resets/cancels
44
+ * any {@linkcode PluginAnalysisSunlightHoursApi}
45
+ * (`analysis.sunlightHours`) study.
46
+ *
47
+ * @param startDate - Start of the study range, ISO date `"YYYY-MM-DD"`.
48
+ * @param endDate - End of the study range, ISO date `"YYYY-MM-DD"` (on or
49
+ * after `startDate`).
50
+ * @returns A {@linkcode PluginAnalysisComputeResult} — `{ success: true }`
51
+ * when the job was started. The `{ success: false, error }` arm is
52
+ * reserved — not yet emitted (start failures currently throw).
53
+ * @throws When the workspace is not on a **Pro** plan (illuminance is a
54
+ * Pro feature).
55
+ * @throws When the project has no geo-located site/terrain (no location to
56
+ * compute daylight for — there is no fallback location).
57
+ * @throws When the scene has no slab or roof BIM object to analyse (walls
58
+ * or bare Masses are not enough) or the editor is not in the 3D view.
59
+ * @throws When a date is not a parseable ISO date or the range is inverted.
60
+ * @throws When plugin writes are disabled.
61
+ *
62
+ * @examplePrompt Run a daylight illuminance analysis for December
63
+ * @examplePrompt Compute the lux levels inside the building for winter
64
+ * @examplePrompt How much daylight do the interior floors get?
65
+ *
66
+ * # Example
67
+ * ```ts
68
+ * const { success } = await snaptrude.analysis.illuminance.compute(
69
+ * "2026-12-01",
70
+ * "2026-12-31",
71
+ * )
72
+ * // poll until the heatmap is rendered
73
+ * let job = await snaptrude.analysis.illuminance.get()
74
+ * while (job?.status === "running") {
75
+ * await new Promise((r) => setTimeout(r, 5000))
76
+ * job = await snaptrude.analysis.illuminance.get()
77
+ * }
78
+ * ```
79
+ */
80
+ public abstract compute(
81
+ startDate: string,
82
+ endDate: string,
83
+ ): PluginApiReturn<PluginAnalysisComputeResult>
84
+
85
+ /**
86
+ * Get the state of the illuminance study.
87
+ *
88
+ * The polling read for the async job started by
89
+ * {@linkcode PluginAnalysisIlluminanceApi.compute}. `status` values:
90
+ *
91
+ * | Status | Meaning |
92
+ * |---|---|
93
+ * | `"running"` | A run is in flight — keep polling |
94
+ * | `"active"` | The heatmap is rendered on the scene |
95
+ * | `"inactive"` | A previous run exists but its heatmap is not showing |
96
+ *
97
+ * @returns A {@linkcode PluginAnalysisJobStateResult} with the `status` and
98
+ * the run's ISO `startDate`/`endDate`, or `null` when no run result is
99
+ * available (the study never ran, was cancelled, or the last run failed).
100
+ *
101
+ * @examplePrompt Is the illuminance analysis done?
102
+ * @examplePrompt Check the status of the daylight lux run
103
+ * @examplePrompt What date range was the illuminance heatmap computed for?
104
+ *
105
+ * # Example
106
+ * ```ts
107
+ * const job = await snaptrude.analysis.illuminance.get()
108
+ * if (job?.status === "active") console.log(job.startDate, job.endDate)
109
+ * ```
110
+ */
111
+ public abstract get(): PluginApiReturn<PluginAnalysisJobStateResult>
112
+
113
+ /**
114
+ * Cancel the in-flight illuminance run.
115
+ *
116
+ * Aborts the backend job. A no-op (returns `false`) when nothing is
117
+ * running.
118
+ *
119
+ * @returns `true` when a run was cancelled, `false` when nothing was
120
+ * running.
121
+ * @throws When plugin writes are disabled.
122
+ *
123
+ * @examplePrompt Cancel the illuminance analysis
124
+ * @examplePrompt Stop the running daylight computation
125
+ * @examplePrompt Abort the lux study
126
+ *
127
+ * # Example
128
+ * ```ts
129
+ * await snaptrude.analysis.illuminance.cancel()
130
+ * ```
131
+ */
132
+ public abstract cancel(): PluginApiReturn<boolean>
133
+
134
+ /**
135
+ * Clear the illuminance heatmap from the scene.
136
+ *
137
+ * Un-applies the rendered heatmap and restores the normal material view.
138
+ * A no-op (returns `false`) when no heatmap is showing. Does not cancel an
139
+ * in-flight run — use {@linkcode PluginAnalysisIlluminanceApi.cancel}.
140
+ *
141
+ * @returns `true` when a heatmap was cleared, `false` when none was
142
+ * showing.
143
+ * @throws When plugin writes are disabled.
144
+ *
145
+ * @examplePrompt Clear the illuminance heatmap
146
+ * @examplePrompt Remove the daylight lux colours from the model
147
+ * @examplePrompt Reset the illuminance analysis view
148
+ *
149
+ * # Example
150
+ * ```ts
151
+ * await snaptrude.analysis.illuminance.reset()
152
+ * ```
153
+ */
154
+ public abstract reset(): PluginApiReturn<boolean>
155
+ }
@@ -0,0 +1,46 @@
1
+ import { PluginAnalysisSunpathApi } from "./sunpath"
2
+ import { PluginAnalysisShadowsApi } from "./shadows"
3
+ import { PluginAnalysisSunlightHoursApi } from "./sunlightHours"
4
+ import { PluginAnalysisIlluminanceApi } from "./illuminance"
5
+ import { PluginAnalysisHeatmapsApi } from "./heatmaps"
6
+
7
+ /**
8
+ * Sustainability-analysis APIs.
9
+ *
10
+ * Analysis is the environmental-performance layer: sun and daylight studies
11
+ * computed for the project's geo-located site. The synchronous visual
12
+ * overlays (sun-path diagram, real-time shadows) toggle instantly; the
13
+ * heatmap studies (direct sunlight hours, daylight illuminance) are
14
+ * asynchronous backend jobs — start them, poll their state, and cancel or
15
+ * clear them. Shadows and the heatmap analyses are **mutually exclusive**
16
+ * (enabling one resets the other), exactly as in the sustainability sidebar.
17
+ * Site inputs (location, true north) are read via `program.site`.
18
+ *
19
+ * - {@linkcode PluginAnalysisApi.sunpath} — Toggle & query the sun-path diagram overlay
20
+ * - {@linkcode PluginAnalysisApi.shadows} — Toggle real-time shadows and scrub the sun's date-time
21
+ * - {@linkcode PluginAnalysisApi.sunlightHours} — Direct-sunlight-hours heatmap job (start / poll / cancel / clear)
22
+ * - {@linkcode PluginAnalysisApi.illuminance} — Daylight-illuminance heatmap job, Pro-gated (start / poll / cancel / clear)
23
+ * - {@linkcode PluginAnalysisApi.heatmaps} — Render plugin-computed scalar data as a heatmap (per-space / grid)
24
+ *
25
+ * Accessed via `snaptrude.analysis`.
26
+ */
27
+ export abstract class PluginAnalysisApi {
28
+ /** Sun-path diagram overlay — enable/disable/isActive. See {@linkcode PluginAnalysisSunpathApi}. */
29
+ public abstract sunpath: PluginAnalysisSunpathApi
30
+ /** Real-time sun shadows + sun date-time. See {@linkcode PluginAnalysisShadowsApi}. */
31
+ public abstract shadows: PluginAnalysisShadowsApi
32
+ /** Direct-sunlight-hours heatmap job. See {@linkcode PluginAnalysisSunlightHoursApi}. */
33
+ public abstract sunlightHours: PluginAnalysisSunlightHoursApi
34
+ /** Daylight-illuminance heatmap job (Pro). See {@linkcode PluginAnalysisIlluminanceApi}. */
35
+ public abstract illuminance: PluginAnalysisIlluminanceApi
36
+ /** Plugin-supplied scalar-data heatmaps. See {@linkcode PluginAnalysisHeatmapsApi}. */
37
+ public abstract heatmaps: PluginAnalysisHeatmapsApi
38
+
39
+ constructor() {}
40
+ }
41
+
42
+ export * from "./sunpath"
43
+ export * from "./shadows"
44
+ export * from "./sunlightHours"
45
+ export * from "./illuminance"
46
+ export * from "./heatmaps"
@@ -0,0 +1,183 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../types"
3
+
4
+ /**
5
+ * Analysis shadows — real-time sun shadows in the scene.
6
+ *
7
+ * Shadows are cast for the sun position at a specific date and time at the
8
+ * project's geographic location. The date-time crosses this API as an **ISO
9
+ * 8601 date-time string** in the project's local time (e.g.
10
+ * `"2026-06-21T14:30"`); the engine snaps the time **down** to its half-hour
11
+ * grid (`14:59` → `14:30`); seconds, if provided, are discarded. The
12
+ * timezone is derived from the site location by the engine — do not append
13
+ * a UTC offset.
14
+ *
15
+ * Methods that position the sun **throw** when the project has no geo-located
16
+ * site/terrain — there is no fallback location. Set the site location first;
17
+ * read it via `program.site.getLocation`.
18
+ *
19
+ * Accessed via `snaptrude.analysis.shadows`.
20
+ */
21
+ export abstract class PluginAnalysisShadowsApi {
22
+ constructor() {}
23
+
24
+ /**
25
+ * Turn real-time sun shadows ON, optionally at a specific date and time.
26
+ *
27
+ * Without `options.dateTime` the shadows use the current stored sun
28
+ * position; with it, the sun is moved first (same as
29
+ * {@linkcode PluginAnalysisShadowsApi.setDateTime}). Enabling shadows
30
+ * resets any active heatmap analysis (`sunlightHours` / `illuminance`) —
31
+ * they are mutually exclusive in the product.
32
+ *
33
+ * @param options - Optional `dateTime`: ISO 8601 local date-time to
34
+ * position the sun at (snapped to the engine's half-hour grid).
35
+ * @returns `true` — shadows are enabled after the call.
36
+ * @throws When the project has no geo-located site/terrain.
37
+ * @throws When `options.dateTime` is not a parseable ISO date-time.
38
+ * @throws When plugin writes are disabled.
39
+ *
40
+ * @examplePrompt Turn on shadows
41
+ * @examplePrompt Show the shadows at 3pm on June 21st
42
+ * @examplePrompt Enable sun shadows for the summer solstice afternoon
43
+ *
44
+ * # Example
45
+ * ```ts
46
+ * await snaptrude.analysis.shadows.enable({ dateTime: "2026-06-21T15:00" })
47
+ * ```
48
+ */
49
+ public abstract enable(
50
+ options?: PluginAnalysisShadowsEnableOptions,
51
+ ): PluginApiReturn<boolean>
52
+
53
+ /**
54
+ * Turn real-time sun shadows OFF.
55
+ *
56
+ * A no-op (returns `false`) when shadows are already off. The stored sun
57
+ * date-time is kept for the next enable.
58
+ *
59
+ * @returns `false` — shadows are disabled after the call.
60
+ * @throws When plugin writes are disabled.
61
+ *
62
+ * @examplePrompt Turn off shadows
63
+ * @examplePrompt Hide the sun shadows
64
+ * @examplePrompt Disable shadow rendering in the scene
65
+ *
66
+ * # Example
67
+ * ```ts
68
+ * await snaptrude.analysis.shadows.disable()
69
+ * ```
70
+ */
71
+ public abstract disable(): PluginApiReturn<boolean>
72
+
73
+ /**
74
+ * Whether real-time sun shadows are currently enabled.
75
+ *
76
+ * A pure read — never mutates, never throws.
77
+ *
78
+ * @returns `true` when shadows are rendering.
79
+ *
80
+ * @examplePrompt Are shadows on?
81
+ * @examplePrompt Check whether sun shadows are enabled
82
+ * @examplePrompt Is the scene showing shadows right now?
83
+ *
84
+ * # Example
85
+ * ```ts
86
+ * const on = await snaptrude.analysis.shadows.isEnabled()
87
+ * ```
88
+ */
89
+ public abstract isEnabled(): PluginApiReturn<boolean>
90
+
91
+ /**
92
+ * Move the sun to a specific date and time.
93
+ *
94
+ * Takes an ISO 8601 date-time string in the project's local time; the
95
+ * engine snaps the time down to its half-hour grid and re-renders the shadows
96
+ * (when they are enabled). The engine stores no year — only the month, day,
97
+ * and time are applied, and the returned date-time always carries the
98
+ * **current year** (setting `"2020-12-21T09:30"` returns
99
+ * `"2026-12-21T09:30"` in 2026). Paired with
100
+ * {@linkcode PluginAnalysisShadowsApi.getDateTime}.
101
+ *
102
+ * @param dateTime - ISO 8601 local date-time, e.g. `"2026-12-21T09:30"`.
103
+ * @returns A {@linkcode PluginAnalysisShadowsDateTimeResult} — the applied
104
+ * ISO date-time after half-hour snapping.
105
+ * @throws When the project has no geo-located site/terrain.
106
+ * @throws When `dateTime` is not a parseable ISO date-time.
107
+ * @throws When plugin writes are disabled.
108
+ *
109
+ * @examplePrompt Set the shadow time to 9:30 am on the winter solstice
110
+ * @examplePrompt Move the sun to noon on March 1st
111
+ * @examplePrompt Change the shadow study date to December 21
112
+ *
113
+ * # Example
114
+ * ```ts
115
+ * const applied = await snaptrude.analysis.shadows.setDateTime("2026-12-21T09:30")
116
+ * console.log(applied) // "2026-12-21T09:30" (snapped to the half-hour grid)
117
+ * ```
118
+ */
119
+ public abstract setDateTime(
120
+ dateTime: string,
121
+ ): PluginApiReturn<PluginAnalysisShadowsDateTimeResult>
122
+
123
+ /**
124
+ * Get the sun's current date and time.
125
+ *
126
+ * Returns the stored sun position as an ISO 8601 local date-time string —
127
+ * the value shadows render at (whether or not they are enabled). The engine
128
+ * stores no year, so the returned string always carries the **current
129
+ * year**, whatever year was passed to
130
+ * {@linkcode PluginAnalysisShadowsApi.setDateTime} (its pair).
131
+ *
132
+ * @returns A {@linkcode PluginAnalysisShadowsDateTimeResult} — the current
133
+ * ISO local date-time of the sun.
134
+ *
135
+ * @examplePrompt What date and time are the shadows set to?
136
+ * @examplePrompt Get the current sun position date
137
+ * @examplePrompt Which time of day is the shadow study showing?
138
+ *
139
+ * # Example
140
+ * ```ts
141
+ * const dateTime = await snaptrude.analysis.shadows.getDateTime()
142
+ * ```
143
+ */
144
+ public abstract getDateTime(): PluginApiReturn<PluginAnalysisShadowsDateTimeResult>
145
+ }
146
+
147
+ /**
148
+ * Options for {@linkcode PluginAnalysisShadowsApi.enable}.
149
+ *
150
+ * | Property | Type | Description |
151
+ * |---|---|---|
152
+ * | `dateTime` | `string \| undefined` | ISO 8601 local date-time to position the sun at (snapped to the half-hour grid) |
153
+ */
154
+ export const PluginAnalysisShadowsEnableOptions = z.object({
155
+ dateTime: z.string().optional(),
156
+ })
157
+ export type PluginAnalysisShadowsEnableOptions = z.infer<
158
+ typeof PluginAnalysisShadowsEnableOptions
159
+ >
160
+
161
+ /**
162
+ * Arguments for {@linkcode PluginAnalysisShadowsApi.setDateTime}.
163
+ *
164
+ * | Property | Type | Description |
165
+ * |---|---|---|
166
+ * | `dateTime` | `string` | ISO 8601 local date-time, e.g. `"2026-06-21T14:30"` |
167
+ */
168
+ export const PluginAnalysisShadowsSetDateTimeArgs = z.object({
169
+ dateTime: z.string(),
170
+ })
171
+ export type PluginAnalysisShadowsSetDateTimeArgs = z.infer<
172
+ typeof PluginAnalysisShadowsSetDateTimeArgs
173
+ >
174
+
175
+ /**
176
+ * Result of {@linkcode PluginAnalysisShadowsApi.setDateTime} /
177
+ * {@linkcode PluginAnalysisShadowsApi.getDateTime} — the sun's ISO 8601
178
+ * local date-time (minute precision, on the engine's half-hour grid).
179
+ */
180
+ export const PluginAnalysisShadowsDateTimeResult = z.string()
181
+ export type PluginAnalysisShadowsDateTimeResult = z.infer<
182
+ typeof PluginAnalysisShadowsDateTimeResult
183
+ >