@snaptrude/plugin-core 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/api-manifest.full.json +2644 -542
  3. package/api-manifest.json +2606 -424
  4. package/dist/api/analysis/heatmaps.d.ts +234 -0
  5. package/dist/api/analysis/heatmaps.d.ts.map +1 -0
  6. package/dist/api/analysis/illuminance.d.ts +145 -0
  7. package/dist/api/analysis/illuminance.d.ts.map +1 -0
  8. package/dist/api/analysis/index.d.ts +44 -0
  9. package/dist/api/analysis/index.d.ts.map +1 -0
  10. package/dist/api/analysis/shadows.d.ts +165 -0
  11. package/dist/api/analysis/shadows.d.ts.map +1 -0
  12. package/dist/api/analysis/sunlightHours.d.ts +208 -0
  13. package/dist/api/analysis/sunlightHours.d.ts.map +1 -0
  14. package/dist/api/analysis/sunpath.d.ts +80 -0
  15. package/dist/api/analysis/sunpath.d.ts.map +1 -0
  16. package/dist/api/core/index.d.ts +10 -0
  17. package/dist/api/core/index.d.ts.map +1 -1
  18. package/dist/api/core/io/import/index.d.ts +392 -0
  19. package/dist/api/core/io/import/index.d.ts.map +1 -0
  20. package/dist/api/core/io/index.d.ts +35 -0
  21. package/dist/api/core/io/index.d.ts.map +1 -0
  22. package/dist/api/core/io/job/index.d.ts +139 -0
  23. package/dist/api/core/io/job/index.d.ts.map +1 -0
  24. package/dist/api/core/io/query/index.d.ts +74 -0
  25. package/dist/api/core/io/query/index.d.ts.map +1 -0
  26. package/dist/api/core/io/terrain/index.d.ts +206 -0
  27. package/dist/api/core/io/terrain/index.d.ts.map +1 -0
  28. package/dist/api/core/io/underlay/index.d.ts +286 -0
  29. package/dist/api/core/io/underlay/index.d.ts.map +1 -0
  30. package/dist/api/core/layers.d.ts +7 -7
  31. package/dist/api/core/proposals/index.d.ts +475 -0
  32. package/dist/api/core/proposals/index.d.ts.map +1 -0
  33. package/dist/api/design/create/index.d.ts +218 -0
  34. package/dist/api/design/create/index.d.ts.map +1 -1
  35. package/dist/api/design/doors/index.d.ts +159 -0
  36. package/dist/api/design/doors/index.d.ts.map +1 -1
  37. package/dist/api/design/furniture/index.d.ts +34 -5
  38. package/dist/api/design/furniture/index.d.ts.map +1 -1
  39. package/dist/api/design/index.d.ts +83 -0
  40. package/dist/api/design/index.d.ts.map +1 -1
  41. package/dist/api/design/lock.d.ts +26 -0
  42. package/dist/api/design/lock.d.ts.map +1 -1
  43. package/dist/api/design/materials/index.d.ts +159 -2
  44. package/dist/api/design/materials/index.d.ts.map +1 -1
  45. package/dist/api/design/query/index.d.ts +115 -5
  46. package/dist/api/design/query/index.d.ts.map +1 -1
  47. package/dist/api/design/query/spaces.d.ts +3 -3
  48. package/dist/api/design/selection/index.d.ts +144 -0
  49. package/dist/api/design/selection/index.d.ts.map +1 -1
  50. package/dist/api/design/transform/index.d.ts +83 -2
  51. package/dist/api/design/transform/index.d.ts.map +1 -1
  52. package/dist/api/design/update/index.d.ts +168 -0
  53. package/dist/api/design/update/index.d.ts.map +1 -1
  54. package/dist/api/design/windows/index.d.ts +113 -2
  55. package/dist/api/design/windows/index.d.ts.map +1 -1
  56. package/dist/api/entity/space.d.ts +2 -2
  57. package/dist/api/entity/story.d.ts +101 -7
  58. package/dist/api/entity/story.d.ts.map +1 -1
  59. package/dist/api/index.d.ts +5 -0
  60. package/dist/api/index.d.ts.map +1 -1
  61. package/dist/api/presentation/import.d.ts +49 -4
  62. package/dist/api/presentation/import.d.ts.map +1 -1
  63. package/dist/api/presentation/views.d.ts +210 -5
  64. package/dist/api/presentation/views.d.ts.map +1 -1
  65. package/dist/api/program/areas.d.ts +42 -12
  66. package/dist/api/program/areas.d.ts.map +1 -1
  67. package/dist/api/program/index.d.ts +3 -11
  68. package/dist/api/program/index.d.ts.map +1 -1
  69. package/dist/api/program/layout.d.ts +186 -11
  70. package/dist/api/program/layout.d.ts.map +1 -1
  71. package/dist/api/program/site.d.ts +84 -0
  72. package/dist/api/program/site.d.ts.map +1 -1
  73. package/dist/errors/codes.d.ts +34 -0
  74. package/dist/errors/codes.d.ts.map +1 -0
  75. package/dist/errors/envelope.d.ts +56 -0
  76. package/dist/errors/envelope.d.ts.map +1 -0
  77. package/dist/errors/index.d.ts +6 -0
  78. package/dist/errors/index.d.ts.map +1 -0
  79. package/dist/errors/plugin-error.d.ts +69 -0
  80. package/dist/errors/plugin-error.d.ts.map +1 -0
  81. package/dist/handles.d.ts +33 -0
  82. package/dist/handles.d.ts.map +1 -1
  83. package/dist/host-utils.d.ts +4 -0
  84. package/dist/host-utils.d.ts.map +1 -1
  85. package/dist/index.cjs +1942 -998
  86. package/dist/index.cjs.map +1 -1
  87. package/dist/index.d.ts +1 -0
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/index.js +1810 -994
  90. package/dist/index.js.map +1 -1
  91. package/package.json +2 -1
  92. package/scripts/generate-manifest.test.mjs +103 -4
  93. package/src/api/analysis/heatmaps.ts +256 -0
  94. package/src/api/analysis/illuminance.ts +155 -0
  95. package/src/api/analysis/index.ts +46 -0
  96. package/src/api/analysis/shadows.ts +183 -0
  97. package/src/api/analysis/sunlightHours.ts +211 -0
  98. package/src/api/analysis/sunpath.ts +83 -0
  99. package/src/api/core/index.ts +10 -0
  100. package/src/api/core/io/import/index.ts +432 -0
  101. package/src/api/core/io/index.ts +37 -0
  102. package/src/api/core/io/job/index.ts +140 -0
  103. package/src/api/core/io/query/index.ts +71 -0
  104. package/src/api/core/io/terrain/index.ts +214 -0
  105. package/src/api/core/io/underlay/index.ts +295 -0
  106. package/src/api/core/proposals/index.ts +509 -0
  107. package/src/api/design/create/index.ts +258 -0
  108. package/src/api/design/doors/index.ts +168 -0
  109. package/src/api/design/erase/index.ts +1 -1
  110. package/src/api/design/furniture/index.ts +36 -5
  111. package/src/api/design/index.ts +87 -0
  112. package/src/api/design/lock.ts +27 -0
  113. package/src/api/design/materials/index.ts +182 -2
  114. package/src/api/design/query/index.ts +81 -0
  115. package/src/api/design/selection/index.ts +129 -0
  116. package/src/api/design/transform/index.ts +74 -2
  117. package/src/api/design/update/index.ts +167 -0
  118. package/src/api/design/windows/index.ts +128 -2
  119. package/src/api/entity/story.ts +105 -7
  120. package/src/api/index.ts +5 -0
  121. package/src/api/presentation/import.ts +45 -4
  122. package/src/api/presentation/views.ts +221 -5
  123. package/src/api/program/areas.ts +34 -12
  124. package/src/api/program/index.ts +3 -11
  125. package/src/api/program/layout.ts +195 -11
  126. package/src/api/program/site.ts +93 -0
  127. package/src/errors/codes.ts +136 -0
  128. package/src/errors/envelope.ts +75 -0
  129. package/src/errors/index.ts +21 -0
  130. package/src/errors/plugin-error.ts +134 -0
  131. package/src/handles.ts +46 -0
  132. package/src/host-utils.ts +4 -0
  133. package/src/index.ts +1 -0
  134. package/test/errors.test.mjs +184 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snaptrude/plugin-core",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -32,6 +32,7 @@
32
32
  "build": "tsup --clean",
33
33
  "dev": "tsup --watch",
34
34
  "clean-dist": "rm -rf dist",
35
+ "test": "node --test test/*.test.mjs",
35
36
  "generate:manifest": "node scripts/generate-manifest.mjs",
36
37
  "generate:manifest:check": "node scripts/generate-manifest.mjs --check",
37
38
  "generate:manifest:all": "node scripts/generate-manifest.mjs --all"
@@ -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,37 @@ 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",
134
+ // 2026-07-09 promotion — program.layout became an async-job family (was
135
+ // author-ahead optional `arrange`/`pack`; now required + getState/cancel):
136
+ "program.layout.arrange",
137
+ "program.layout.pack",
138
+ "program.layout.getState",
139
+ "program.layout.cancel",
112
140
  ]
113
141
  for (const p of promoted) {
114
142
  assert.ok(
@@ -191,3 +219,74 @@ test("v2 family writes are IN the discovery manifest (hosts landed, promoted)",
191
219
  )
192
220
  }
193
221
  })
222
+
223
+ test("0.7.0 batch — new families & methods present with intent + prompts", () => {
224
+ // The 0.7.0 wave: core.proposals, the program.layout async-job family,
225
+ // door/window catalogs + placement, furniture categories, smart layout,
226
+ // align, per-face materials, staircase read/write, footprint-area lock,
227
+ // storey duplicate, SVG import, and view display settings. Every entry is a
228
+ // required `abstract` member (react hosts landed), so each must be in the
229
+ // discovery manifest with a summary, >= 3 example prompts, and a result type.
230
+ const batch = [
231
+ // core.proposals — design-option infrastructure
232
+ "core.proposals.list",
233
+ "core.proposals.get",
234
+ "core.proposals.getActive",
235
+ "core.proposals.listForComponent",
236
+ "core.proposals.isActive",
237
+ "core.proposals.create",
238
+ "core.proposals.rename",
239
+ "core.proposals.setActive",
240
+ "core.proposals.delete",
241
+ // program.layout — async space-solver job family
242
+ "program.layout.arrange",
243
+ "program.layout.pack",
244
+ "program.layout.getState",
245
+ "program.layout.cancel",
246
+ // door / window catalogs (shared DTOs) + placement creators
247
+ "design.doors.listCatalogGroups",
248
+ "design.doors.listCatalog",
249
+ "design.doors.getCatalogItem",
250
+ "design.doors.exists",
251
+ "design.windows.listCatalogGroups",
252
+ "design.windows.listCatalog",
253
+ "design.windows.getCatalogItem",
254
+ "design.windows.exists",
255
+ "design.create.door",
256
+ "design.create.window",
257
+ // furniture categories + smart layout
258
+ "design.furniture.listCategories",
259
+ "design.create.smartLayout",
260
+ // align
261
+ "design.transform.align",
262
+ // per-face materials
263
+ "design.materials.applyToFaces",
264
+ "design.materials.resetFaces",
265
+ "design.materials.getByFace",
266
+ "design.materials.listByFace",
267
+ // staircase read/write
268
+ "design.query.getStaircaseParams",
269
+ "design.update.staircase",
270
+ // footprint-area lock
271
+ "design.lockArea",
272
+ "design.unlockArea",
273
+ "design.isAreaLocked",
274
+ "design.listAreaLocked",
275
+ // storey duplicate
276
+ "entity.story.duplicate",
277
+ // present-canvas SVG import + view display settings
278
+ "presentation.import.svg",
279
+ "presentation.views.getSettings",
280
+ "presentation.views.updateSettings",
281
+ ]
282
+ for (const p of batch) {
283
+ const m = byPath.get(p)
284
+ assert.ok(m, `missing 0.7.0 batch method: ${p}`)
285
+ assert.ok(m.summary.length > 0, `${p} has no intent summary`)
286
+ assert.ok(m.examplePrompts.length >= 3, `${p} has < 3 example prompts`)
287
+ assert.ok(
288
+ m.resultType && m.resultType !== "void",
289
+ `${p} has no result type`,
290
+ )
291
+ }
292
+ })
@@ -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"