@snaptrude/plugin-core 0.2.9 → 0.5.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 (269) hide show
  1. package/AGENTS.md +128 -50
  2. package/CHANGELOG.md +52 -6
  3. package/api-manifest.full.json +3999 -0
  4. package/api-manifest.json +3845 -0
  5. package/dist/api/core/buildings.d.ts +427 -0
  6. package/dist/api/core/buildings.d.ts.map +1 -0
  7. package/dist/api/core/comment/index.d.ts +230 -0
  8. package/dist/api/core/comment/index.d.ts.map +1 -0
  9. package/dist/api/core/geom/create/index.d.ts +247 -0
  10. package/dist/api/core/geom/create/index.d.ts.map +1 -0
  11. package/dist/api/core/geom/delete/index.d.ts +72 -0
  12. package/dist/api/core/geom/delete/index.d.ts.map +1 -0
  13. package/dist/api/core/geom/index.d.ts +24 -23
  14. package/dist/api/core/geom/index.d.ts.map +1 -1
  15. package/dist/api/core/geom/query/arc.d.ts +169 -0
  16. package/dist/api/core/geom/query/arc.d.ts.map +1 -0
  17. package/dist/api/core/geom/query/brep.d.ts +402 -0
  18. package/dist/api/core/geom/query/brep.d.ts.map +1 -0
  19. package/dist/api/core/geom/query/circle.d.ts +378 -0
  20. package/dist/api/core/geom/query/circle.d.ts.map +1 -0
  21. package/dist/api/core/geom/query/contour.d.ts +450 -0
  22. package/dist/api/core/geom/query/contour.d.ts.map +1 -0
  23. package/dist/api/core/geom/query/curve.d.ts +918 -0
  24. package/dist/api/core/geom/query/curve.d.ts.map +1 -0
  25. package/dist/api/core/geom/query/edge.d.ts +128 -0
  26. package/dist/api/core/geom/query/edge.d.ts.map +1 -0
  27. package/dist/api/core/geom/query/face.d.ts +363 -0
  28. package/dist/api/core/geom/query/face.d.ts.map +1 -0
  29. package/dist/api/core/geom/query/halfedge.d.ts +206 -0
  30. package/dist/api/core/geom/query/halfedge.d.ts.map +1 -0
  31. package/dist/api/core/geom/query/index.d.ts +61 -0
  32. package/dist/api/core/geom/query/index.d.ts.map +1 -0
  33. package/dist/api/core/geom/query/profile.d.ts +410 -0
  34. package/dist/api/core/geom/query/profile.d.ts.map +1 -0
  35. package/dist/api/core/geom/query/vertex.d.ts +187 -0
  36. package/dist/api/core/geom/query/vertex.d.ts.map +1 -0
  37. package/dist/api/core/geom/update/contour.d.ts +272 -0
  38. package/dist/api/core/geom/update/contour.d.ts.map +1 -0
  39. package/dist/api/core/geom/update/curve.d.ts +180 -0
  40. package/dist/api/core/geom/update/curve.d.ts.map +1 -0
  41. package/dist/api/core/geom/update/index.d.ts +27 -0
  42. package/dist/api/core/geom/update/index.d.ts.map +1 -0
  43. package/dist/api/core/geom/update/profile.d.ts +329 -0
  44. package/dist/api/core/geom/update/profile.d.ts.map +1 -0
  45. package/dist/api/core/groups.d.ts +485 -0
  46. package/dist/api/core/groups.d.ts.map +1 -0
  47. package/dist/api/core/history/index.d.ts +78 -0
  48. package/dist/api/core/history/index.d.ts.map +1 -0
  49. package/dist/api/core/index.d.ts +46 -1
  50. package/dist/api/core/index.d.ts.map +1 -1
  51. package/dist/api/core/layers.d.ts +402 -0
  52. package/dist/api/core/layers.d.ts.map +1 -0
  53. package/dist/api/core/math/quat.d.ts +111 -128
  54. package/dist/api/core/math/quat.d.ts.map +1 -1
  55. package/dist/api/core/math/vec3.d.ts +120 -102
  56. package/dist/api/core/math/vec3.d.ts.map +1 -1
  57. package/dist/api/core/project/index.d.ts +399 -0
  58. package/dist/api/core/project/index.d.ts.map +1 -0
  59. package/dist/api/core/tags.d.ts +755 -0
  60. package/dist/api/core/tags.d.ts.map +1 -0
  61. package/dist/api/core/units/index.d.ts +175 -0
  62. package/dist/api/core/units/index.d.ts.map +1 -0
  63. package/dist/api/core/zoom/index.d.ts +45 -0
  64. package/dist/api/core/zoom/index.d.ts.map +1 -0
  65. package/dist/api/design/boolean/index.d.ts +168 -0
  66. package/dist/api/design/boolean/index.d.ts.map +1 -0
  67. package/dist/api/design/create/index.d.ts +828 -0
  68. package/dist/api/design/create/index.d.ts.map +1 -0
  69. package/dist/api/design/delete/index.d.ts +63 -0
  70. package/dist/api/design/delete/index.d.ts.map +1 -0
  71. package/dist/api/design/doors/index.d.ts +268 -0
  72. package/dist/api/design/doors/index.d.ts.map +1 -0
  73. package/dist/api/design/edit/index.d.ts +49 -0
  74. package/dist/api/design/edit/index.d.ts.map +1 -0
  75. package/dist/api/design/erase/index.d.ts +160 -0
  76. package/dist/api/design/erase/index.d.ts.map +1 -0
  77. package/dist/api/design/furniture/index.d.ts +123 -0
  78. package/dist/api/design/furniture/index.d.ts.map +1 -0
  79. package/dist/api/design/index.d.ts +153 -0
  80. package/dist/api/design/index.d.ts.map +1 -0
  81. package/dist/api/design/lock.d.ts +41 -0
  82. package/dist/api/design/lock.d.ts.map +1 -0
  83. package/dist/api/design/materials/index.d.ts +297 -0
  84. package/dist/api/design/materials/index.d.ts.map +1 -0
  85. package/dist/api/design/query/geometry/index.d.ts +140 -0
  86. package/dist/api/design/query/geometry/index.d.ts.map +1 -0
  87. package/dist/api/design/query/index.d.ts +1011 -0
  88. package/dist/api/design/query/index.d.ts.map +1 -0
  89. package/dist/api/design/query/spaces.d.ts +221 -0
  90. package/dist/api/design/query/spaces.d.ts.map +1 -0
  91. package/dist/api/design/selection/index.d.ts +138 -0
  92. package/dist/api/design/selection/index.d.ts.map +1 -0
  93. package/dist/api/design/shared.d.ts +38 -0
  94. package/dist/api/design/shared.d.ts.map +1 -0
  95. package/dist/api/design/transform/index.d.ts +87 -0
  96. package/dist/api/design/transform/index.d.ts.map +1 -0
  97. package/dist/api/design/update/index.d.ts +178 -0
  98. package/dist/api/design/update/index.d.ts.map +1 -0
  99. package/dist/api/design/windows/index.d.ts +189 -0
  100. package/dist/api/design/windows/index.d.ts.map +1 -0
  101. package/dist/api/entity/buildableEnvelope.d.ts +51 -23
  102. package/dist/api/entity/buildableEnvelope.d.ts.map +1 -1
  103. package/dist/api/entity/department.d.ts +0 -98
  104. package/dist/api/entity/department.d.ts.map +1 -1
  105. package/dist/api/entity/index.d.ts +4 -9
  106. package/dist/api/entity/index.d.ts.map +1 -1
  107. package/dist/api/entity/referenceLine.d.ts +49 -106
  108. package/dist/api/entity/referenceLine.d.ts.map +1 -1
  109. package/dist/api/entity/space.d.ts +76 -828
  110. package/dist/api/entity/space.d.ts.map +1 -1
  111. package/dist/api/entity/story.d.ts +47 -37
  112. package/dist/api/entity/story.d.ts.map +1 -1
  113. package/dist/api/index.d.ts +17 -17
  114. package/dist/api/index.d.ts.map +1 -1
  115. package/dist/api/presentation/aiInspiration.d.ts +440 -0
  116. package/dist/api/presentation/aiInspiration.d.ts.map +1 -0
  117. package/dist/api/presentation/diagrams.d.ts +81 -0
  118. package/dist/api/presentation/diagrams.d.ts.map +1 -0
  119. package/dist/api/presentation/import.d.ts +113 -0
  120. package/dist/api/presentation/import.d.ts.map +1 -0
  121. package/dist/api/presentation/index.d.ts +46 -0
  122. package/dist/api/presentation/index.d.ts.map +1 -0
  123. package/dist/api/presentation/sheets.d.ts +176 -0
  124. package/dist/api/presentation/sheets.d.ts.map +1 -0
  125. package/dist/api/presentation/views.d.ts +296 -0
  126. package/dist/api/presentation/views.d.ts.map +1 -0
  127. package/dist/api/program/adjacency.d.ts +155 -0
  128. package/dist/api/program/adjacency.d.ts.map +1 -0
  129. package/dist/api/program/areas.d.ts +360 -0
  130. package/dist/api/program/areas.d.ts.map +1 -0
  131. package/dist/api/program/classification.d.ts +135 -0
  132. package/dist/api/program/classification.d.ts.map +1 -0
  133. package/dist/api/program/cores.d.ts +174 -0
  134. package/dist/api/program/cores.d.ts.map +1 -0
  135. package/dist/api/program/departments.d.ts +431 -0
  136. package/dist/api/program/departments.d.ts.map +1 -0
  137. package/dist/api/program/index.d.ts +69 -0
  138. package/dist/api/program/index.d.ts.map +1 -0
  139. package/dist/api/program/layout.d.ts +63 -0
  140. package/dist/api/program/layout.d.ts.map +1 -0
  141. package/dist/api/program/metrics.d.ts +108 -0
  142. package/dist/api/program/metrics.d.ts.map +1 -0
  143. package/dist/api/program/site.d.ts +367 -0
  144. package/dist/api/program/site.d.ts.map +1 -0
  145. package/dist/api/program/spreadsheet.d.ts +2041 -0
  146. package/dist/api/program/spreadsheet.d.ts.map +1 -0
  147. package/dist/handles.d.ts +138 -0
  148. package/dist/handles.d.ts.map +1 -0
  149. package/dist/host-utils.d.ts +7 -5
  150. package/dist/host-utils.d.ts.map +1 -1
  151. package/dist/index.cjs +3897 -1542
  152. package/dist/index.cjs.map +1 -1
  153. package/dist/index.d.ts +1 -0
  154. package/dist/index.d.ts.map +1 -1
  155. package/dist/index.js +3326 -1462
  156. package/dist/index.js.map +1 -1
  157. package/package.json +6 -2
  158. package/scripts/generate-manifest.mjs +193 -0
  159. package/scripts/generate-manifest.test.mjs +193 -0
  160. package/src/api/core/buildings.ts +485 -0
  161. package/src/api/core/comment/index.ts +258 -0
  162. package/src/api/core/geom/create/index.ts +293 -0
  163. package/src/api/core/geom/delete/index.ts +78 -0
  164. package/src/api/core/geom/index.ts +24 -23
  165. package/src/api/core/geom/query/arc.ts +169 -0
  166. package/src/api/core/geom/query/brep.ts +444 -0
  167. package/src/api/core/geom/query/circle.ts +404 -0
  168. package/src/api/core/geom/query/contour.ts +540 -0
  169. package/src/api/core/geom/query/curve.ts +1078 -0
  170. package/src/api/core/geom/query/edge.ts +130 -0
  171. package/src/api/core/geom/query/face.ts +403 -0
  172. package/src/api/core/geom/query/halfedge.ts +210 -0
  173. package/src/api/core/geom/query/index.ts +63 -0
  174. package/src/api/core/geom/query/profile.ts +473 -0
  175. package/src/api/core/geom/query/vertex.ts +205 -0
  176. package/src/api/core/geom/update/contour.ts +315 -0
  177. package/src/api/core/geom/update/curve.ts +209 -0
  178. package/src/api/core/geom/update/index.ts +29 -0
  179. package/src/api/core/geom/update/profile.ts +377 -0
  180. package/src/api/core/groups.ts +521 -0
  181. package/src/api/core/history/index.ts +84 -0
  182. package/src/api/core/index.ts +46 -1
  183. package/src/api/core/layers.ts +333 -0
  184. package/src/api/core/math/quat.ts +112 -235
  185. package/src/api/core/math/vec3.ts +124 -159
  186. package/src/api/core/project/index.ts +418 -0
  187. package/src/api/core/tags.ts +808 -0
  188. package/src/api/core/units/index.ts +164 -0
  189. package/src/api/core/zoom/index.ts +47 -0
  190. package/src/api/design/boolean/index.ts +179 -0
  191. package/src/api/design/create/index.ts +886 -0
  192. package/src/api/design/delete/index.ts +67 -0
  193. package/src/api/design/doors/index.ts +285 -0
  194. package/src/api/design/edit/index.ts +54 -0
  195. package/src/api/design/erase/index.ts +151 -0
  196. package/src/api/design/furniture/index.ts +130 -0
  197. package/src/api/design/index.ts +162 -0
  198. package/src/api/design/lock.ts +42 -0
  199. package/src/api/design/materials/index.ts +301 -0
  200. package/src/api/design/query/geometry/index.ts +166 -0
  201. package/src/api/design/query/index.ts +937 -0
  202. package/src/api/design/query/spaces.ts +132 -0
  203. package/src/api/design/selection/index.ts +144 -0
  204. package/src/api/design/shared.ts +40 -0
  205. package/src/api/design/transform/index.ts +93 -0
  206. package/src/api/design/update/index.ts +117 -0
  207. package/src/api/design/windows/index.ts +207 -0
  208. package/src/api/entity/buildableEnvelope.ts +64 -23
  209. package/src/api/entity/department.ts +0 -113
  210. package/src/api/entity/index.ts +4 -9
  211. package/src/api/entity/referenceLine.ts +50 -38
  212. package/src/api/entity/space.ts +84 -440
  213. package/src/api/entity/story.ts +53 -42
  214. package/src/api/index.ts +17 -17
  215. package/src/api/presentation/aiInspiration.ts +362 -0
  216. package/src/api/presentation/diagrams.ts +84 -0
  217. package/src/api/presentation/import.ts +112 -0
  218. package/src/api/presentation/index.ts +48 -0
  219. package/src/api/presentation/sheets.ts +198 -0
  220. package/src/api/presentation/views.ts +303 -0
  221. package/src/api/program/adjacency.ts +164 -0
  222. package/src/api/program/areas.ts +335 -0
  223. package/src/api/program/classification.ts +138 -0
  224. package/src/api/program/cores.ts +171 -0
  225. package/src/api/program/departments.ts +465 -0
  226. package/src/api/program/index.ts +71 -0
  227. package/src/api/program/layout.ts +68 -0
  228. package/src/api/program/metrics.ts +120 -0
  229. package/src/api/program/site.ts +326 -0
  230. package/src/api/program/spreadsheet.ts +2075 -0
  231. package/src/handles.ts +148 -0
  232. package/src/host-utils.ts +10 -6
  233. package/src/index.ts +1 -0
  234. package/dist/api/core/geom/arc.d.ts +0 -81
  235. package/dist/api/core/geom/arc.d.ts.map +0 -1
  236. package/dist/api/core/geom/curve.d.ts +0 -70
  237. package/dist/api/core/geom/curve.d.ts.map +0 -1
  238. package/dist/api/core/geom/line.d.ts +0 -56
  239. package/dist/api/core/geom/line.d.ts.map +0 -1
  240. package/dist/api/core/geom/profile.d.ts +0 -121
  241. package/dist/api/core/geom/profile.d.ts.map +0 -1
  242. package/dist/api/documentation/aiInspiration.d.ts +0 -2155
  243. package/dist/api/documentation/aiInspiration.d.ts.map +0 -1
  244. package/dist/api/documentation/index.d.ts +0 -13
  245. package/dist/api/documentation/index.d.ts.map +0 -1
  246. package/dist/api/tools/copy.d.ts +0 -59
  247. package/dist/api/tools/copy.d.ts.map +0 -1
  248. package/dist/api/tools/index.d.ts +0 -29
  249. package/dist/api/tools/index.d.ts.map +0 -1
  250. package/dist/api/tools/offset.d.ts +0 -43
  251. package/dist/api/tools/offset.d.ts.map +0 -1
  252. package/dist/api/tools/selection.d.ts +0 -48
  253. package/dist/api/tools/selection.d.ts.map +0 -1
  254. package/dist/api/tools/transform.d.ts +0 -114
  255. package/dist/api/tools/transform.d.ts.map +0 -1
  256. package/dist/api/units/index.d.ts +0 -163
  257. package/dist/api/units/index.d.ts.map +0 -1
  258. package/src/api/core/geom/arc.ts +0 -70
  259. package/src/api/core/geom/curve.ts +0 -41
  260. package/src/api/core/geom/line.ts +0 -53
  261. package/src/api/core/geom/profile.ts +0 -94
  262. package/src/api/documentation/aiInspiration.ts +0 -871
  263. package/src/api/documentation/index.ts +0 -15
  264. package/src/api/tools/copy.ts +0 -55
  265. package/src/api/tools/index.ts +0 -35
  266. package/src/api/tools/offset.ts +0 -43
  267. package/src/api/tools/selection.ts +0 -51
  268. package/src/api/tools/transform.ts +0 -117
  269. package/src/api/units/index.ts +0 -163
@@ -0,0 +1,2075 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../types"
3
+ import { PluginAreaUnit } from "./metrics"
4
+
5
+ /**
6
+ * Program spreadsheet — read a building's program/takeoff data and render, build,
7
+ * and export report sheets from it. The surface spans two levels:
8
+ *
9
+ * - **High-level renders** — {@linkcode PluginProgramSpreadsheetApi.render} (rows +
10
+ * columns → a formatted, titled table) and its dataset specializations
11
+ * {@linkcode PluginProgramSpreadsheetApi.renderTakeoff} /
12
+ * {@linkcode PluginProgramSpreadsheetApi.renderProgram} (the host pulls the
13
+ * dataset). Authors think "render my takeoff to a sheet".
14
+ * - **Low-level construction** — for authors who need fine control:
15
+ * {@linkcode PluginProgramSpreadsheetApi.createSheet},
16
+ * {@linkcode PluginProgramSpreadsheetApi.setValues},
17
+ * {@linkcode PluginProgramSpreadsheetApi.setFormulas},
18
+ * {@linkcode PluginProgramSpreadsheetApi.setStyles},
19
+ * {@linkcode PluginProgramSpreadsheetApi.mergeCells},
20
+ * {@linkcode PluginProgramSpreadsheetApi.addConditionalFormatting},
21
+ * {@linkcode PluginProgramSpreadsheetApi.recalculate}, and
22
+ * {@linkcode PluginProgramSpreadsheetApi.transaction} (atomic, undoable batch).
23
+ *
24
+ * Plus dataset reads ({@linkcode PluginProgramSpreadsheetApi.getProgram} /
25
+ * {@linkcode PluginProgramSpreadsheetApi.getTakeoff} — the data the render* methods
26
+ * draw), sheet reads ({@linkcode PluginProgramSpreadsheetApi.listSheets} /
27
+ * {@linkcode PluginProgramSpreadsheetApi.getSheetData}), charts + emphasis
28
+ * ({@linkcode PluginProgramSpreadsheetApi.addChart} /
29
+ * {@linkcode PluginProgramSpreadsheetApi.highlightCells}), workbook file export
30
+ * ({@linkcode PluginProgramSpreadsheetApi.export}), reusable
31
+ * {@linkcode PluginProgramSpreadsheetApi.templates}, live
32
+ * {@linkcode PluginProgramSpreadsheetApi.bindings}, a sandboxed script escape hatch
33
+ * ({@linkcode PluginProgramSpreadsheetApi.runScript}), an audit log
34
+ * ({@linkcode PluginProgramSpreadsheetApi.getAuditLog}), and a liveness
35
+ * {@linkcode PluginProgramSpreadsheetApi.ping}. `addTable` is intentionally not
36
+ * exposed — `render` composes header + rows + table in one call.
37
+ *
38
+ * **Verb note (naming authority; rows pending merge into constitution §4 by its owner).**
39
+ * Existing §4 verbs used as-is: `get`, `list`, `set` (bulk cell/format writes;
40
+ * read back via {@linkcode PluginProgramSpreadsheetApi.getSheetData}), `create`,
41
+ * `add` (charts, conditional formats), `apply` (templates), `export`, and
42
+ * `transaction` (the sanctioned atomic-batch verb), plus the ratified `render` and
43
+ * `highlight` program domain verbs ◆. New program-domain verbs ratified here ◆:
44
+ * `recalculate` (recompute the workbook's formula results — distinct from
45
+ * `refresh`), `merge` ({@linkcode PluginProgramSpreadsheetApi.mergeCells} spans a
46
+ * cell range — a spreadsheet-domain verb, explicitly NOT the CSG-solid `union`
47
+ * fold), `refresh` ({@linkcode PluginProgramSpreadsheetBindingsApi.refresh}
48
+ * re-pulls a binding's live source — distinct from `recalculate`), `run`
49
+ * ({@linkcode PluginProgramSpreadsheetApi.runScript} executes a sandboxed script),
50
+ * and `ping` (a meta liveness probe). Renames for compliance: the host's `save` →
51
+ * `templates.create`; `getRecentEntries` → `getAuditLog`.
52
+ *
53
+ * Accessed via `snaptrude.program.spreadsheet`.
54
+ */
55
+ export abstract class PluginProgramSpreadsheetApi {
56
+ constructor() {}
57
+
58
+ /**
59
+ * Reusable sheet templates — capture a sheet's layout as a named template and
60
+ * re-apply it to another sheet. See {@linkcode PluginProgramSpreadsheetTemplatesApi}.
61
+ */
62
+ public abstract templates: PluginProgramSpreadsheetTemplatesApi
63
+
64
+ /**
65
+ * Live data bindings — bind a program dataset to a sheet range and refresh it
66
+ * on demand. See {@linkcode PluginProgramSpreadsheetBindingsApi}.
67
+ */
68
+ public abstract bindings: PluginProgramSpreadsheetBindingsApi
69
+
70
+ /**
71
+ * Render a titled, formatted table onto a named sheet (create-or-replace).
72
+ *
73
+ * The intent-level replacement for the raw cell-write sequence: it writes the
74
+ * header + rows, applies per-column format/alignment, optionally wraps the
75
+ * block in a table, freezes the header, and appends a totals row. This is the
76
+ * generic table render; the `render*` family is reserved to also carry
77
+ * dataset-specific renders (`renderTakeoff`, `renderProgram`) once their
78
+ * argument shapes are ratified.
79
+ *
80
+ * @param sheetName - Target sheet name.
81
+ * @param columns - Column definitions, at least one (see
82
+ * {@linkcode PluginSpreadsheetColumn}).
83
+ * @param rows - Row objects keyed by column `key`.
84
+ * @param options - Optional `title`, `startCell` (default `"A1"`), `whenExists`
85
+ * (default `"replace"`), `asTable` (default `true`), `freezeHeader` (default
86
+ * `true`), and `totals` row.
87
+ * @returns A {@linkcode PluginProgramSpreadsheetRenderResult} with the written
88
+ * ranges and counts.
89
+ * @throws If `columns` is empty, the target sheet exists and `whenExists` is
90
+ * `"error"`, or a cell address is invalid.
91
+ *
92
+ * @examplePrompt Render my takeoff as a table on a sheet
93
+ * @examplePrompt Write the area schedule to a spreadsheet with totals
94
+ * @examplePrompt Put the department breakdown on a sheet called "Program"
95
+ * @examplePrompt Output this data as a formatted table with a header
96
+ * @examplePrompt Create a report sheet from these rows and columns
97
+ *
98
+ * # Example
99
+ * ```ts
100
+ * await snaptrude.program.spreadsheet.render(
101
+ * "Program",
102
+ * [
103
+ * { key: "name", header: "Department" },
104
+ * { key: "area", header: "Area", format: "0.00", align: "right" },
105
+ * ],
106
+ * [{ name: "FOH", area: 120.5 }],
107
+ * { totals: [{ column: "area", fn: "sum", label: "Total" }] },
108
+ * )
109
+ * ```
110
+ */
111
+ public abstract render(
112
+ sheetName: string,
113
+ columns: PluginSpreadsheetColumn[],
114
+ rows: Record<string, PluginSpreadsheetCell>[],
115
+ options?: {
116
+ title?: string
117
+ startCell?: string
118
+ whenExists?: "replace" | "error"
119
+ asTable?: boolean
120
+ freezeHeader?: boolean
121
+ totals?: PluginSpreadsheetTotal[]
122
+ },
123
+ ): PluginApiReturn<PluginProgramSpreadsheetRenderResult>
124
+
125
+ /**
126
+ * Render the quantity/material takeoff onto a sheet.
127
+ *
128
+ * A specialization of the render* family: the **host pulls and projects the
129
+ * current takeoff dataset itself** — the plugin supplies only the target
130
+ * `sheetName`, an optional `title`, and an optional `filter`; there is **no
131
+ * data argument**. Returns the same rendered-artifact record as
132
+ * {@linkcode PluginProgramSpreadsheetApi.render}.
133
+ * _(Authored ahead — optional via the `spreadsheet?` mount until the host
134
+ * round-trip is live.)_
135
+ *
136
+ * @param options - Optional `sheetName`, `title`, and `filter` (a
137
+ * {@linkcode PluginProgramSpreadsheetRenderDatasetArgs}).
138
+ * @returns A {@linkcode PluginProgramSpreadsheetRenderResult} with the written
139
+ * ranges and counts.
140
+ * @throws If the takeoff cannot be rendered.
141
+ *
142
+ * @examplePrompt Render the takeoff onto a sheet
143
+ * @examplePrompt Put the quantity takeoff on a spreadsheet
144
+ * @examplePrompt Generate the takeoff schedule sheet titled Takeoff
145
+ * @examplePrompt Render the material takeoff filtered to the walls
146
+ *
147
+ * # Example
148
+ * ```ts
149
+ * await snaptrude.program.spreadsheet.renderTakeoff({ sheetName: "Takeoff" })
150
+ * ```
151
+ */
152
+ public abstract renderTakeoff(
153
+ options?: { sheetName?: string; title?: string; filter?: string },
154
+ ): PluginApiReturn<PluginProgramSpreadsheetRenderResult>
155
+
156
+ /**
157
+ * Render the area program onto a sheet.
158
+ *
159
+ * A specialization of the render* family: the **host pulls and projects the
160
+ * current program dataset itself** (departments with area targets vs allocated)
161
+ * — the plugin supplies only the target `sheetName`, an optional `title`, and an
162
+ * optional `filter`; there is **no data argument**. Returns the same
163
+ * rendered-artifact record as {@linkcode PluginProgramSpreadsheetApi.render}.
164
+ * _(Authored ahead — optional via the `spreadsheet?` mount until the host
165
+ * round-trip is live.)_
166
+ *
167
+ * @param options - Optional `sheetName`, `title`, and `filter` (a
168
+ * {@linkcode PluginProgramSpreadsheetRenderDatasetArgs}).
169
+ * @returns A {@linkcode PluginProgramSpreadsheetRenderResult} with the written
170
+ * ranges and counts.
171
+ * @throws If the program cannot be rendered.
172
+ *
173
+ * @examplePrompt Render the area program onto a sheet
174
+ * @examplePrompt Put the department program on a spreadsheet
175
+ * @examplePrompt Generate the program schedule sheet titled Program
176
+ * @examplePrompt Render the program filtered to the residential departments
177
+ *
178
+ * # Example
179
+ * ```ts
180
+ * await snaptrude.program.spreadsheet.renderProgram({ sheetName: "Program" })
181
+ * ```
182
+ */
183
+ public abstract renderProgram(
184
+ options?: { sheetName?: string; title?: string; filter?: string },
185
+ ): PluginApiReturn<PluginProgramSpreadsheetRenderResult>
186
+
187
+ /**
188
+ * Export the whole report workbook to a file (xlsx, pdf, or csv).
189
+ *
190
+ * Returns the file content as base64 so the plugin can download, upload, or
191
+ * attach it. This is the workbook **file** export; to read cell **values** back
192
+ * as data, use {@linkcode PluginProgramSpreadsheetApi.getSheetData} instead.
193
+ *
194
+ * @param format - The file format to export the workbook to.
195
+ * @param options - Optional `fileName` (without extension); a default is used
196
+ * when omitted.
197
+ * @returns A {@linkcode PluginProgramSpreadsheetExportResult} with the file's
198
+ * `fileName`, `mimeType`, and base64 `dataBase64`.
199
+ * @throws If the workbook cannot be serialized to the requested format.
200
+ *
201
+ * @examplePrompt Export the report as an Excel file
202
+ * @examplePrompt Download the whole workbook as a PDF
203
+ * @examplePrompt Export the program workbook to xlsx
204
+ * @examplePrompt Save the report as a csv file
205
+ *
206
+ * # Example
207
+ * ```ts
208
+ * const file = await snaptrude.program.spreadsheet.export("xlsx")
209
+ * // file.fileName, file.mimeType, file.dataBase64
210
+ * ```
211
+ */
212
+ public abstract export(
213
+ format: PluginSpreadsheetExportFormat,
214
+ options?: { fileName?: string },
215
+ ): PluginApiReturn<PluginProgramSpreadsheetExportResult>
216
+
217
+ /**
218
+ * List the sheets in the report workbook.
219
+ *
220
+ * @returns A {@linkcode PluginProgramSpreadsheetListSheetsResult} with each sheet's
221
+ * name/index/visibility/size, plus the active sheet name.
222
+ *
223
+ * @examplePrompt List the sheets in the spreadsheet
224
+ * @examplePrompt What sheets are in the report workbook?
225
+ * @examplePrompt Which sheet is currently active?
226
+ * @examplePrompt How many sheets does the report have?
227
+ *
228
+ * # Example
229
+ * ```ts
230
+ * const { sheets, activeSheet } = await snaptrude.program.spreadsheet.listSheets()
231
+ * ```
232
+ */
233
+ public abstract listSheets(): PluginApiReturn<PluginProgramSpreadsheetListSheetsResult>
234
+
235
+ /**
236
+ * Read a sheet's data back as a matrix (and optionally as header-keyed records).
237
+ *
238
+ * @param sheetName - Sheet to read.
239
+ * @param options - Optional `range` (A1; omit to read the sheet's used range)
240
+ * and `header` (`true` to also get records keyed by the header row).
241
+ * @returns A {@linkcode PluginProgramSpreadsheetGetSheetDataResult} with the read
242
+ * `range`, `values` matrix, and optional `records`.
243
+ * @throws If the sheet does not exist or the range is invalid.
244
+ *
245
+ * @examplePrompt Read the data back from the Program sheet
246
+ * @examplePrompt Get the values in range A1:D20 of a sheet
247
+ * @examplePrompt Read a sheet as rows of records keyed by header
248
+ * @examplePrompt What's in the takeoff sheet right now?
249
+ *
250
+ * # Example
251
+ * ```ts
252
+ * const { values, records } = await snaptrude.program.spreadsheet.getSheetData(
253
+ * "Program",
254
+ * { header: true },
255
+ * )
256
+ * ```
257
+ */
258
+ public abstract getSheetData(
259
+ sheetName: string,
260
+ options?: { range?: string; header?: boolean },
261
+ ): PluginApiReturn<PluginProgramSpreadsheetGetSheetDataResult>
262
+
263
+ /**
264
+ * Add a chart to a sheet, driven by a cell range.
265
+ *
266
+ * @param sheetName - Sheet to add the chart to.
267
+ * @param chartType - Chart type (see {@linkcode PluginSpreadsheetChartType}).
268
+ * @param dataRange - A1 range driving the chart.
269
+ * @param options - Optional `title`, `position` (sheet coords), and `size` (px).
270
+ * @returns A {@linkcode PluginProgramSpreadsheetAddChartResult} with the new
271
+ * chart's id.
272
+ * @throws If the sheet or data range is invalid.
273
+ *
274
+ * @examplePrompt Add a bar chart of the department areas
275
+ * @examplePrompt Insert a pie chart from range B2:C10
276
+ * @examplePrompt Put a column chart on the Program sheet
277
+ * @examplePrompt Chart the area breakdown by department
278
+ *
279
+ * # Example
280
+ * ```ts
281
+ * const { chartId } = await snaptrude.program.spreadsheet.addChart(
282
+ * "Program",
283
+ * "column",
284
+ * "A1:B10",
285
+ * { title: "Area by department" },
286
+ * )
287
+ * ```
288
+ */
289
+ public abstract addChart(
290
+ sheetName: string,
291
+ chartType: PluginSpreadsheetChartType,
292
+ dataRange: string,
293
+ options?: {
294
+ title?: string
295
+ position?: { x: number; y: number }
296
+ size?: { width: number; height: number }
297
+ },
298
+ ): PluginApiReturn<PluginProgramSpreadsheetAddChartResult>
299
+
300
+ /**
301
+ * Highlight a range of cells (background color and optional emphasis).
302
+ *
303
+ * @param sheetName - Sheet containing the range.
304
+ * @param range - A1 range to highlight.
305
+ * @param options - Optional `color` (CSS hex; a default emphasis is used when
306
+ * omitted) and `bold`.
307
+ * @returns A {@linkcode PluginProgramSpreadsheetHighlightCellsResult} echoing the
308
+ * highlighted sheet and range.
309
+ * @throws If the sheet or range is invalid.
310
+ *
311
+ * @examplePrompt Highlight the cells that are over budget
312
+ * @examplePrompt Color range A2:A10 red
313
+ * @examplePrompt Highlight B2:D2 in yellow
314
+ * @examplePrompt Emphasize the totals row on the Program sheet
315
+ *
316
+ * # Example
317
+ * ```ts
318
+ * await snaptrude.program.spreadsheet.highlightCells("Program", "A2:A10", {
319
+ * color: "#ffe08a",
320
+ * })
321
+ * ```
322
+ */
323
+ public abstract highlightCells(
324
+ sheetName: string,
325
+ range: string,
326
+ options?: { color?: string; bold?: boolean },
327
+ ): PluginApiReturn<PluginProgramSpreadsheetHighlightCellsResult>
328
+
329
+ // --- Program / takeoff dataset reads (the data the render* methods draw) ---
330
+
331
+ /**
332
+ * Read the area-program dataset (departments with target vs allocated area).
333
+ *
334
+ * Returns the same figures {@linkcode PluginProgramSpreadsheetApi.renderProgram}
335
+ * projects onto a sheet, as render-ready rows — so a plugin can inspect or
336
+ * transform the program before rendering it (or render it itself via
337
+ * {@linkcode PluginProgramSpreadsheetApi.render}). For the canonical
338
+ * area-program summary read, see {@linkcode PluginProgramMetricsApi.get}.
339
+ *
340
+ * @returns A {@linkcode PluginProgramSpreadsheetGetProgramResult} with per-department
341
+ * rows (`targetArea`/`allocatedArea`/`variance`), totals, and the report `units`.
342
+ *
343
+ * @examplePrompt Get the area program data
344
+ * @examplePrompt Read the department program before I render it
345
+ * @examplePrompt Give me the program rows with target vs allocated area
346
+ * @examplePrompt What's the program dataset the report is built from?
347
+ *
348
+ * # Example
349
+ * ```ts
350
+ * const program = await snaptrude.program.spreadsheet.getProgram()
351
+ * for (const row of program.rows) console.log(row.name, row.allocatedArea, row.targetArea)
352
+ * ```
353
+ */
354
+ public abstract getProgram(): PluginApiReturn<PluginProgramSpreadsheetGetProgramResult>
355
+
356
+ /**
357
+ * Read the quantity/material takeoff dataset (per-element quantities).
358
+ *
359
+ * Returns the same rows {@linkcode PluginProgramSpreadsheetApi.renderTakeoff}
360
+ * projects onto a sheet — one record per counted element (category, item,
361
+ * level, quantity, unit) — so a plugin can inspect or transform the takeoff
362
+ * before rendering it (or render it itself via
363
+ * {@linkcode PluginProgramSpreadsheetApi.render}).
364
+ *
365
+ * @returns A {@linkcode PluginProgramSpreadsheetGetTakeoffResult} with the takeoff
366
+ * `rows`, a `rowCount`, and the `generatedAt` timestamp.
367
+ *
368
+ * @examplePrompt Get the takeoff data
369
+ * @examplePrompt Read the quantity takeoff rows
370
+ * @examplePrompt Give me the per-element quantities before I render them
371
+ * @examplePrompt What's in the material takeoff right now?
372
+ *
373
+ * # Example
374
+ * ```ts
375
+ * const takeoff = await snaptrude.program.spreadsheet.getTakeoff()
376
+ * console.log(takeoff.rowCount, "elements")
377
+ * ```
378
+ */
379
+ public abstract getTakeoff(): PluginApiReturn<PluginProgramSpreadsheetGetTakeoffResult>
380
+
381
+ // --- Sheet construction (lower-level cell writes; render is the high-level path) ---
382
+
383
+ /**
384
+ * Create (or reuse/replace) a named sheet in the report workbook.
385
+ *
386
+ * The blank-canvas complement to {@linkcode PluginProgramSpreadsheetApi.render}:
387
+ * use it when you want an empty sheet to write into with
388
+ * {@linkcode PluginProgramSpreadsheetApi.setValues} /
389
+ * {@linkcode PluginProgramSpreadsheetApi.setFormulas}. By default an existing
390
+ * sheet of the same name is reused; pass `whenExists` to replace or error.
391
+ *
392
+ * @param name - The sheet name to create.
393
+ * @param whenExists - Behaviour if the name exists: `"reuse"` (default),
394
+ * `"replace"`, or `"error"`.
395
+ * @returns A {@linkcode PluginProgramSpreadsheetCreateSheetResult} with the resolved
396
+ * `sheetName`, whether it `replaced` an existing sheet, and its `sheetIndex`.
397
+ * @throws If the sheet exists and `whenExists` is `"error"`.
398
+ *
399
+ * @examplePrompt Create a sheet called Summary
400
+ * @examplePrompt Add a new blank sheet named Takeoff
401
+ * @examplePrompt Make a sheet, replacing it if it already exists
402
+ * @examplePrompt Start a fresh sheet to write into
403
+ *
404
+ * # Example
405
+ * ```ts
406
+ * await snaptrude.program.spreadsheet.createSheet("Summary")
407
+ * ```
408
+ */
409
+ public abstract createSheet(
410
+ name: string,
411
+ whenExists?: PluginSpreadsheetWhenExists,
412
+ ): PluginApiReturn<PluginProgramSpreadsheetCreateSheetResult>
413
+
414
+ /**
415
+ * Write a block of raw values into a sheet, anchored at a cell.
416
+ *
417
+ * The low-level cell-write path (the high-level path is
418
+ * {@linkcode PluginProgramSpreadsheetApi.render}, which adds a header, format,
419
+ * and totals). Values are written row-major from `startCell` (default `"A1"`);
420
+ * columns are auto-sized to fit.
421
+ *
422
+ * @param sheetName - Sheet to write into.
423
+ * @param values - Row-major matrix of values to write.
424
+ * @param startCell - Top-left anchor in A1 notation (default `"A1"`).
425
+ * @returns A {@linkcode PluginProgramSpreadsheetSetValuesResult} with the written
426
+ * `startCell`, `rowCount`, and `colCount`.
427
+ * @throws If the sheet does not exist or `startCell` is invalid.
428
+ *
429
+ * @examplePrompt Write these rows to the sheet starting at A1
430
+ * @examplePrompt Put this data into the Summary sheet
431
+ * @examplePrompt Set the values in the takeoff sheet from B2
432
+ * @examplePrompt Drop this matrix of numbers onto a sheet
433
+ *
434
+ * # Example
435
+ * ```ts
436
+ * await snaptrude.program.spreadsheet.setValues(
437
+ * "Summary",
438
+ * [["Department", "Area"], ["FOH", 120.5]],
439
+ * "A1",
440
+ * )
441
+ * ```
442
+ */
443
+ public abstract setValues(
444
+ sheetName: string,
445
+ values: PluginSpreadsheetCell[][],
446
+ startCell?: string,
447
+ ): PluginApiReturn<PluginProgramSpreadsheetSetValuesResult>
448
+
449
+ /**
450
+ * Set formulas on individual cells of a sheet.
451
+ *
452
+ * Each entry targets one cell (A1 notation) with a formula expression (a
453
+ * leading `=` is optional). Pairs with
454
+ * {@linkcode PluginProgramSpreadsheetApi.recalculate} when you need to force a
455
+ * recompute.
456
+ *
457
+ * @param sheetName - Sheet to set formulas on.
458
+ * @param formulas - The cell → formula assignments (see
459
+ * {@linkcode PluginSpreadsheetFormula}).
460
+ * @returns A {@linkcode PluginProgramSpreadsheetSetFormulasResult} with the `count`
461
+ * of formulas set.
462
+ * @throws If the sheet does not exist or a cell address is invalid.
463
+ *
464
+ * @examplePrompt Put a SUM formula in cell B10
465
+ * @examplePrompt Set formulas totalling each column
466
+ * @examplePrompt Add a formula to compute the variance column
467
+ * @examplePrompt Write =SUM(B2:B9) into B10 on the Summary sheet
468
+ *
469
+ * # Example
470
+ * ```ts
471
+ * await snaptrude.program.spreadsheet.setFormulas("Summary", [
472
+ * { cell: "B10", formula: "=SUM(B2:B9)" },
473
+ * ])
474
+ * ```
475
+ */
476
+ public abstract setFormulas(
477
+ sheetName: string,
478
+ formulas: PluginSpreadsheetFormula[],
479
+ ): PluginApiReturn<PluginProgramSpreadsheetSetFormulasResult>
480
+
481
+ // --- Formatting ---
482
+
483
+ /**
484
+ * Apply cell styles to one or more ranges of a sheet.
485
+ *
486
+ * Sets fill/text color, font, alignment, and number format on each given range.
487
+ * For a quick single-range emphasis,
488
+ * {@linkcode PluginProgramSpreadsheetApi.highlightCells} is the shortcut.
489
+ *
490
+ * @param sheetName - Sheet containing the ranges.
491
+ * @param ranges - Range → style assignments (each a range + a
492
+ * {@linkcode PluginSpreadsheetCellStyle}).
493
+ * @returns A {@linkcode PluginProgramSpreadsheetSetStylesResult} with the `count` of
494
+ * ranges styled.
495
+ * @throws If the sheet does not exist or a range is invalid.
496
+ *
497
+ * @examplePrompt Make the header row bold with a grey fill
498
+ * @examplePrompt Right-align the numbers in column B
499
+ * @examplePrompt Format A1:D1 with a background color and bold text
500
+ * @examplePrompt Style the totals row
501
+ *
502
+ * # Example
503
+ * ```ts
504
+ * await snaptrude.program.spreadsheet.setStyles("Summary", [
505
+ * { range: "A1:D1", style: { fontWeight: "bold", backColor: "#eef" } },
506
+ * ])
507
+ * ```
508
+ */
509
+ public abstract setStyles(
510
+ sheetName: string,
511
+ ranges: PluginSpreadsheetRangeStyle[],
512
+ ): PluginApiReturn<PluginProgramSpreadsheetSetStylesResult>
513
+
514
+ /**
515
+ * Merge a contiguous range of cells into a single spanned cell.
516
+ *
517
+ * Optionally sets the merged cell's value. (Verb ruling: `merge` is a
518
+ * spreadsheet-domain verb here — spanning cells — not the CSG-solid `union`.)
519
+ *
520
+ * @param sheetName - Sheet containing the range.
521
+ * @param range - A1 range to merge into one spanned cell.
522
+ * @param value - Optional value to set in the merged (top-left) cell.
523
+ * @returns A {@linkcode PluginProgramSpreadsheetMergeCellsResult} echoing the merged
524
+ * sheet and range.
525
+ * @throws If the sheet does not exist or the range is invalid.
526
+ *
527
+ * @examplePrompt Merge cells A1 to D1 for the title
528
+ * @examplePrompt Span the header across the first four columns
529
+ * @examplePrompt Merge A1:D1 and set it to "Program Summary"
530
+ *
531
+ * # Example
532
+ * ```ts
533
+ * await snaptrude.program.spreadsheet.mergeCells("Summary", "A1:D1", "Program Summary")
534
+ * ```
535
+ */
536
+ public abstract mergeCells(
537
+ sheetName: string,
538
+ range: string,
539
+ value?: PluginSpreadsheetCell,
540
+ ): PluginApiReturn<PluginProgramSpreadsheetMergeCellsResult>
541
+
542
+ /**
543
+ * Add a conditional-formatting rule to a range.
544
+ *
545
+ * Currently supports data-bar rules (a proportional in-cell bar); more rule
546
+ * types are reserved. For static (non-conditional) emphasis use
547
+ * {@linkcode PluginProgramSpreadsheetApi.highlightCells} or
548
+ * {@linkcode PluginProgramSpreadsheetApi.setStyles}.
549
+ *
550
+ * @param sheetName - Sheet containing the range.
551
+ * @param range - A1 range to format.
552
+ * @param rule - The conditional-format rule (see
553
+ * {@linkcode PluginSpreadsheetConditionalRule}).
554
+ * @returns A {@linkcode PluginProgramSpreadsheetAddConditionalFormattingResult} with
555
+ * whether a rule was `created`.
556
+ * @throws If the sheet does not exist or the range is invalid.
557
+ *
558
+ * @examplePrompt Add data bars to the area column
559
+ * @examplePrompt Show a proportional bar inside cells B2:B10
560
+ * @examplePrompt Add conditional formatting data bars to the quantities
561
+ *
562
+ * # Example
563
+ * ```ts
564
+ * await snaptrude.program.spreadsheet.addConditionalFormatting("Summary", "B2:B10", {
565
+ * type: "dataBar",
566
+ * color: "#4f9cf9",
567
+ * })
568
+ * ```
569
+ */
570
+ public abstract addConditionalFormatting(
571
+ sheetName: string,
572
+ range: string,
573
+ rule: PluginSpreadsheetConditionalRule,
574
+ ): PluginApiReturn<PluginProgramSpreadsheetAddConditionalFormattingResult>
575
+
576
+ // --- Recalculation & atomic batching ---
577
+
578
+ /**
579
+ * Recompute the workbook's formula results.
580
+ *
581
+ * Recalculates every formula (or, when `sheetName` is given, focuses that sheet
582
+ * before recalculating the workbook). (Verb ruling: `recalculate` recomputes
583
+ * formulas — distinct from {@linkcode PluginProgramSpreadsheetBindingsApi.refresh},
584
+ * which re-pulls a binding's source data.)
585
+ *
586
+ * @param options - Optional `sheetName` to focus before recalculating; omit for
587
+ * the whole workbook.
588
+ * @returns A {@linkcode PluginProgramSpreadsheetRecalculateResult} with the recompute
589
+ * `scope` and the focused `sheetName` (or `null`).
590
+ *
591
+ * @examplePrompt Recalculate the workbook
592
+ * @examplePrompt Recompute all the formulas
593
+ * @examplePrompt Recalculate the Summary sheet
594
+ *
595
+ * # Example
596
+ * ```ts
597
+ * await snaptrude.program.spreadsheet.recalculate()
598
+ * ```
599
+ */
600
+ public abstract recalculate(
601
+ options?: { sheetName?: string },
602
+ ): PluginApiReturn<PluginProgramSpreadsheetRecalculateResult>
603
+
604
+ /**
605
+ * Run a sequence of sheet operations as one atomic, undoable transaction.
606
+ *
607
+ * Batches cell-construction operations (createSheet/setValues/setFormulas/
608
+ * setStyles/mergeCells) so they commit together and undo as a single step, with
609
+ * events suspended for speed. (`transaction` is the sanctioned §4 atomic-batch
610
+ * verb.)
611
+ *
612
+ * @param operations - The operations to run in order. Each operation's `args`
613
+ * stays that method's schema **object** (the wire shape), not positional.
614
+ * @param label - Optional undo-history label for the batch.
615
+ * @returns A {@linkcode PluginProgramSpreadsheetTransactionResult} with the
616
+ * `operationCount` and each operation's `results`.
617
+ * @throws If any operation names an unsupported method or fails.
618
+ *
619
+ * @examplePrompt Create a sheet and write to it in one atomic step
620
+ * @examplePrompt Batch these sheet edits as a single undoable action
621
+ * @examplePrompt Run these operations together as one transaction
622
+ *
623
+ * # Example
624
+ * ```ts
625
+ * await snaptrude.program.spreadsheet.transaction(
626
+ * [
627
+ * { method: "createSheet", args: { name: "Summary" } },
628
+ * { method: "setValues", args: { sheetName: "Summary", values: [["A", 1]] } },
629
+ * ],
630
+ * "Build summary",
631
+ * )
632
+ * ```
633
+ */
634
+ public abstract transaction(
635
+ operations: PluginSpreadsheetTransactionOp[],
636
+ label?: string,
637
+ ): PluginApiReturn<PluginProgramSpreadsheetTransactionResult>
638
+
639
+ // --- Meta: script escape hatch, audit log, liveness ---
640
+
641
+ /**
642
+ * Run an author-supplied script against a sandboxed workbook facade.
643
+ *
644
+ * The escape hatch for advanced automation the typed methods don't cover: the
645
+ * `script` runs against a restricted `workbook` object with browser/network
646
+ * globals blocked, and its return value is handed back as `result`. Prefer the
647
+ * typed methods where they exist. (Verb ruling: `run` executes a script.)
648
+ *
649
+ * @param script - Script source, run against the sandboxed `workbook` facade.
650
+ * @returns A {@linkcode PluginProgramSpreadsheetRunScriptResult} with the script's
651
+ * `result`.
652
+ * @throws If the script uses a blocked browser/network API or throws at runtime.
653
+ *
654
+ * @examplePrompt Run this SpreadJS script against the workbook
655
+ * @examplePrompt Execute a custom script on the sheets
656
+ * @examplePrompt Run a script to tweak the workbook
657
+ *
658
+ * # Example
659
+ * ```ts
660
+ * const { result } = await snaptrude.program.spreadsheet.runScript(
661
+ * "return workbook.getSheetCount();",
662
+ * )
663
+ * ```
664
+ */
665
+ public abstract runScript(
666
+ script: string,
667
+ ): PluginApiReturn<PluginProgramSpreadsheetRunScriptResult>
668
+
669
+ /**
670
+ * Read the recent audit log of program-spreadsheet operations.
671
+ *
672
+ * Returns the most recent operations performed through this API (method, sheet,
673
+ * status, summary, timestamp), newest first — useful for showing the user what
674
+ * a plugin changed. (Renamed from the host's `getRecentEntries` for §4 `get`
675
+ * compliance.)
676
+ *
677
+ * @param options - Optional `limit` on the entries returned (clamped 1–100,
678
+ * default 20).
679
+ * @returns A {@linkcode PluginProgramSpreadsheetGetAuditLogResult} with the audit
680
+ * `entries`, newest first.
681
+ *
682
+ * @examplePrompt Show the recent spreadsheet actions
683
+ * @examplePrompt What did the plugin change in the workbook?
684
+ * @examplePrompt Get the last 10 audit log entries
685
+ * @examplePrompt Read the program spreadsheet audit log
686
+ *
687
+ * # Example
688
+ * ```ts
689
+ * const { entries } = await snaptrude.program.spreadsheet.getAuditLog({ limit: 10 })
690
+ * ```
691
+ */
692
+ public abstract getAuditLog(
693
+ options?: { limit?: number },
694
+ ): PluginApiReturn<PluginProgramSpreadsheetGetAuditLogResult>
695
+
696
+ /**
697
+ * Ping the program-mode spreadsheet bridge to check it is reachable.
698
+ *
699
+ * A liveness probe: resolves with `{ pong: true }` when the program-mode
700
+ * workbook bridge is up. (Verb ruling: `ping` is a meta liveness verb.)
701
+ *
702
+ * @returns A {@linkcode PluginProgramSpreadsheetPingResult} — `{ pong: true }` when
703
+ * the bridge is reachable.
704
+ *
705
+ * @examplePrompt Ping the spreadsheet bridge
706
+ * @examplePrompt Is the program spreadsheet available?
707
+ * @examplePrompt Check the spreadsheet connection is alive
708
+ *
709
+ * # Example
710
+ * ```ts
711
+ * const { pong } = await snaptrude.program.spreadsheet.ping()
712
+ * ```
713
+ */
714
+ public abstract ping(): PluginApiReturn<PluginProgramSpreadsheetPingResult>
715
+ }
716
+
717
+ /**
718
+ * Program-spreadsheet templates — capture a sheet's layout as a named, reusable
719
+ * template and re-apply it to another sheet.
720
+ *
721
+ * Accessed via `snaptrude.program.spreadsheet.templates`.
722
+ */
723
+ export abstract class PluginProgramSpreadsheetTemplatesApi {
724
+ constructor() {}
725
+
726
+ /**
727
+ * Save a sheet's current layout as a named template.
728
+ *
729
+ * (Renamed from the host's `save` to `create` for §4 compliance.)
730
+ *
731
+ * @param name - Template name (re-saving the same name overwrites it).
732
+ * @param sheetName - The source sheet to capture.
733
+ * @param scope - Template scope: `"project"` (default) or `"global"`.
734
+ * @returns A {@linkcode PluginProgramSpreadsheetTemplatesCreateResult} with the new
735
+ * template's `id`, `name`, `scope`, and source `sheetName`.
736
+ * @throws If the source sheet does not exist.
737
+ *
738
+ * @examplePrompt Save this sheet as a reusable template
739
+ * @examplePrompt Create a template from the Summary sheet
740
+ * @examplePrompt Save the current layout as a template called "Cover"
741
+ *
742
+ * # Example
743
+ * ```ts
744
+ * await snaptrude.program.spreadsheet.templates.create("Cover", "Summary")
745
+ * ```
746
+ */
747
+ public abstract create(
748
+ name: string,
749
+ sheetName: string,
750
+ scope?: PluginSpreadsheetTemplateScope,
751
+ ): PluginApiReturn<PluginProgramSpreadsheetTemplatesCreateResult>
752
+
753
+ /**
754
+ * Apply a saved template to a target sheet (create-or-replace).
755
+ *
756
+ * @param name - The template to apply.
757
+ * @param targetSheetName - The sheet to create/replace from the template.
758
+ * @returns A {@linkcode PluginProgramSpreadsheetTemplatesApplyResult} echoing the
759
+ * applied template and target sheet.
760
+ * @throws If the named template does not exist.
761
+ *
762
+ * @examplePrompt Apply the Cover template to a new sheet
763
+ * @examplePrompt Use my saved template on the Report sheet
764
+ * @examplePrompt Apply template "Cover" to sheet "Report"
765
+ *
766
+ * # Example
767
+ * ```ts
768
+ * await snaptrude.program.spreadsheet.templates.apply("Cover", "Report")
769
+ * ```
770
+ */
771
+ public abstract apply(
772
+ name: string,
773
+ targetSheetName: string,
774
+ ): PluginApiReturn<PluginProgramSpreadsheetTemplatesApplyResult>
775
+ }
776
+
777
+ /**
778
+ * Program-spreadsheet data bindings — bind a live program dataset to a sheet
779
+ * range so it can be refreshed on demand.
780
+ *
781
+ * A binding links a dataset (e.g. the takeoff) to a target sheet range; a refresh
782
+ * re-pulls the current data and rewrites the range. Accessed via
783
+ * `snaptrude.program.spreadsheet.bindings`.
784
+ */
785
+ export abstract class PluginProgramSpreadsheetBindingsApi {
786
+ constructor() {}
787
+
788
+ /**
789
+ * Create a named binding from a dataset to a sheet range (and do an initial refresh).
790
+ *
791
+ * @param name - Binding name (re-using a name overwrites it).
792
+ * @param source - The dataset to bind (see
793
+ * {@linkcode PluginSpreadsheetBindingSource}).
794
+ * @param target - The target sheet range (see
795
+ * {@linkcode PluginSpreadsheetBindingTarget}).
796
+ * @param mode - How a refresh writes into the target (default `"replaceRange"`).
797
+ * @returns A {@linkcode PluginProgramSpreadsheetBindingsCreateResult} — the stored
798
+ * binding plus the `refresh` result of the initial pull.
799
+ * @throws If the target sheet does not exist.
800
+ *
801
+ * @examplePrompt Bind the takeoff to the Data sheet
802
+ * @examplePrompt Create a live binding from the takeoff to A1 on Data
803
+ * @examplePrompt Link the takeoff dataset to a sheet range
804
+ *
805
+ * # Example
806
+ * ```ts
807
+ * await snaptrude.program.spreadsheet.bindings.create(
808
+ * "takeoff",
809
+ * { dataset: "takeoff" },
810
+ * { sheetName: "Data", startCell: "A1" },
811
+ * )
812
+ * ```
813
+ */
814
+ public abstract create(
815
+ name: string,
816
+ source: PluginSpreadsheetBindingSource,
817
+ target: PluginSpreadsheetBindingTarget,
818
+ mode?: PluginSpreadsheetBindingMode,
819
+ ): PluginApiReturn<PluginProgramSpreadsheetBindingsCreateResult>
820
+
821
+ /**
822
+ * Refresh one binding (by name) or all bindings, re-pulling their source data.
823
+ *
824
+ * (Verb ruling: `refresh` re-pulls a binding's live source into its target
825
+ * range — distinct from {@linkcode PluginProgramSpreadsheetApi.recalculate},
826
+ * which recomputes formulas.)
827
+ *
828
+ * @param options - Optional binding `name`; omit it to refresh every binding.
829
+ * @returns A {@linkcode PluginProgramSpreadsheetBindingsRefreshResult} with a
830
+ * `refreshed` entry per binding that was updated.
831
+ * @throws If a `name` is given but no binding with that name exists.
832
+ *
833
+ * @examplePrompt Refresh the takeoff binding
834
+ * @examplePrompt Re-pull all my data bindings
835
+ * @examplePrompt Refresh every binding on the sheets
836
+ *
837
+ * # Example
838
+ * ```ts
839
+ * await snaptrude.program.spreadsheet.bindings.refresh({ name: "takeoff" })
840
+ * ```
841
+ */
842
+ public abstract refresh(
843
+ options?: { name?: string },
844
+ ): PluginApiReturn<PluginProgramSpreadsheetBindingsRefreshResult>
845
+
846
+ /**
847
+ * List all data bindings in the workbook.
848
+ *
849
+ * @returns A {@linkcode PluginProgramSpreadsheetBindingsListResult} with every
850
+ * stored {@linkcode PluginSpreadsheetBinding}.
851
+ *
852
+ * @examplePrompt List the data bindings
853
+ * @examplePrompt What bindings are set up on the sheets?
854
+ * @examplePrompt Show all the live data bindings
855
+ *
856
+ * # Example
857
+ * ```ts
858
+ * const { bindings } = await snaptrude.program.spreadsheet.bindings.list()
859
+ * ```
860
+ */
861
+ public abstract list(): PluginApiReturn<PluginProgramSpreadsheetBindingsListResult>
862
+ }
863
+
864
+ /** A single spreadsheet cell value. */
865
+ export const PluginSpreadsheetCell = z.union([
866
+ z.string(),
867
+ z.number(),
868
+ z.boolean(),
869
+ z.null(),
870
+ ])
871
+ export type PluginSpreadsheetCell = z.infer<typeof PluginSpreadsheetCell>
872
+
873
+ /** Horizontal alignment for a rendered column. */
874
+ export const PluginSpreadsheetAlign = z.enum(["left", "center", "right"])
875
+ export type PluginSpreadsheetAlign = z.infer<typeof PluginSpreadsheetAlign>
876
+
877
+ /**
878
+ * A column definition for {@linkcode PluginProgramSpreadsheetApi.render}.
879
+ *
880
+ * | Property | Type | Description |
881
+ * |---|---|---|
882
+ * | `key` | `string` | Key into each row object |
883
+ * | `header` | `string` | Column header text |
884
+ * | `width` | `number?` | Fixed column width in px; auto-fit when omitted |
885
+ * | `format` | `string?` | Number/date format string applied to the data cells |
886
+ * | `align` | `"left" \| "center" \| "right"?` | Cell alignment |
887
+ */
888
+ export const PluginSpreadsheetColumn = z.object({
889
+ key: z.string(),
890
+ header: z.string(),
891
+ width: z.number().optional(),
892
+ format: z.string().optional(),
893
+ align: PluginSpreadsheetAlign.optional(),
894
+ })
895
+ export type PluginSpreadsheetColumn = z.infer<typeof PluginSpreadsheetColumn>
896
+
897
+ /**
898
+ * A totals-row aggregation for {@linkcode PluginProgramSpreadsheetApi.render}.
899
+ *
900
+ * | Property | Type | Description |
901
+ * |---|---|---|
902
+ * | `column` | `string` | The {@linkcode PluginSpreadsheetColumn} `key` to aggregate |
903
+ * | `fn` | `"sum" \| "avg" \| "count" \| "min" \| "max"` | Aggregation function |
904
+ * | `label` | `string?` | Optional label printed in the first column of the totals row |
905
+ */
906
+ export const PluginSpreadsheetTotal = z.object({
907
+ column: z.string(),
908
+ fn: z.enum(["sum", "avg", "count", "min", "max"]),
909
+ label: z.string().optional(),
910
+ })
911
+ export type PluginSpreadsheetTotal = z.infer<typeof PluginSpreadsheetTotal>
912
+
913
+ /**
914
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.render}.
915
+ *
916
+ * | Property | Type | Description |
917
+ * |---|---|---|
918
+ * | `sheetName` | `string` | Target sheet name |
919
+ * | `columns` | {@linkcode PluginSpreadsheetColumn}`[]` | Column definitions (at least one) |
920
+ * | `rows` | `Record<string, cell>[]` | Row objects keyed by column `key` |
921
+ * | `title` | `string?` | Optional title rendered above the header |
922
+ * | `startCell` | `string?` | Top-left anchor in A1 notation (default `"A1"`) |
923
+ * | `whenExists` | `"replace" \| "error"?` | Behaviour if the sheet exists (default `"replace"`) |
924
+ * | `asTable` | `boolean?` | Wrap the block in a table (default `true`) |
925
+ * | `freezeHeader` | `boolean?` | Freeze rows above the data (default `true`) |
926
+ * | `totals` | {@linkcode PluginSpreadsheetTotal}`[]?` | Optional totals row |
927
+ */
928
+ export const PluginProgramSpreadsheetRenderArgs = z.object({
929
+ sheetName: z.string(),
930
+ columns: z.array(PluginSpreadsheetColumn),
931
+ rows: z.array(z.record(z.string(), PluginSpreadsheetCell)),
932
+ title: z.string().optional(),
933
+ startCell: z.string().optional(),
934
+ whenExists: z.enum(["replace", "error"]).optional(),
935
+ asTable: z.boolean().optional(),
936
+ freezeHeader: z.boolean().optional(),
937
+ totals: z.array(PluginSpreadsheetTotal).optional(),
938
+ })
939
+ export type PluginProgramSpreadsheetRenderArgs = z.infer<
940
+ typeof PluginProgramSpreadsheetRenderArgs
941
+ >
942
+
943
+ /**
944
+ * Result of {@linkcode PluginProgramSpreadsheetApi.render}.
945
+ *
946
+ * | Property | Type | Description |
947
+ * |---|---|---|
948
+ * | `sheetName` | `string` | The sheet that was written |
949
+ * | `range` | `string` | A1 range covering the full written block (title + header + data + totals) |
950
+ * | `headerRange` | `string` | A1 range of the header row alone |
951
+ * | `rowCount` | `number` | Number of data rows written (excludes title/header/totals) |
952
+ * | `colCount` | `number` | Number of columns written |
953
+ * | `tableName` | `string \| null` | The created table's name, or `null` when not wrapped as a table |
954
+ * | `replaced` | `boolean` | Whether an existing sheet was replaced |
955
+ */
956
+ export const PluginProgramSpreadsheetRenderResult = z.object({
957
+ sheetName: z.string(),
958
+ range: z.string(),
959
+ headerRange: z.string(),
960
+ rowCount: z.number(),
961
+ colCount: z.number(),
962
+ tableName: z.string().nullable(),
963
+ replaced: z.boolean(),
964
+ })
965
+ export type PluginProgramSpreadsheetRenderResult = z.infer<
966
+ typeof PluginProgramSpreadsheetRenderResult
967
+ >
968
+
969
+ /**
970
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.renderTakeoff} and
971
+ * {@linkcode PluginProgramSpreadsheetApi.renderProgram} — the dataset render
972
+ * methods. There is **no data argument**: the host pulls and projects the
973
+ * takeoff/program dataset itself. All fields are optional. (Both methods share
974
+ * this args type, as `import.image`/`import.pdf` share their args.)
975
+ *
976
+ * | Property | Type | Description |
977
+ * |---|---|---|
978
+ * | `sheetName` | `string?` | Target sheet name (a default is used when omitted) |
979
+ * | `title` | `string?` | Optional title rendered above the table |
980
+ * | `filter` | `string?` | Optional dataset-filter expression to narrow the rows |
981
+ */
982
+ export const PluginProgramSpreadsheetRenderDatasetArgs = z.object({
983
+ sheetName: z.string().optional(),
984
+ title: z.string().optional(),
985
+ filter: z.string().optional(),
986
+ })
987
+ export type PluginProgramSpreadsheetRenderDatasetArgs = z.infer<
988
+ typeof PluginProgramSpreadsheetRenderDatasetArgs
989
+ >
990
+
991
+ /** The workbook export file format. */
992
+ export const PluginSpreadsheetExportFormat = z.enum(["xlsx", "pdf", "csv"])
993
+ export type PluginSpreadsheetExportFormat = z.infer<
994
+ typeof PluginSpreadsheetExportFormat
995
+ >
996
+
997
+ /**
998
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.export}.
999
+ *
1000
+ * | Property | Type | Description |
1001
+ * |---|---|---|
1002
+ * | `format` | `"xlsx" \| "pdf" \| "csv"` | The file format to export the workbook to |
1003
+ * | `fileName` | `string?` | Desired file name (without extension); a default is used when omitted |
1004
+ */
1005
+ export const PluginProgramSpreadsheetExportArgs = z.object({
1006
+ format: PluginSpreadsheetExportFormat,
1007
+ fileName: z.string().optional(),
1008
+ })
1009
+ export type PluginProgramSpreadsheetExportArgs = z.infer<
1010
+ typeof PluginProgramSpreadsheetExportArgs
1011
+ >
1012
+
1013
+ /**
1014
+ * Result of {@linkcode PluginProgramSpreadsheetApi.export} — the exported workbook file.
1015
+ *
1016
+ * | Property | Type | Description |
1017
+ * |---|---|---|
1018
+ * | `format` | `"xlsx" \| "pdf" \| "csv"` | The format the file was exported in |
1019
+ * | `fileName` | `string` | The file name (with extension) |
1020
+ * | `mimeType` | `string` | The file's MIME type |
1021
+ * | `dataBase64` | `string` | The file's bytes, base64-encoded |
1022
+ */
1023
+ export const PluginProgramSpreadsheetExportResult = z.object({
1024
+ format: PluginSpreadsheetExportFormat,
1025
+ fileName: z.string(),
1026
+ mimeType: z.string(),
1027
+ dataBase64: z.string(),
1028
+ })
1029
+ export type PluginProgramSpreadsheetExportResult = z.infer<
1030
+ typeof PluginProgramSpreadsheetExportResult
1031
+ >
1032
+
1033
+ /**
1034
+ * Metadata for one sheet in {@linkcode PluginProgramSpreadsheetListSheetsResult}.
1035
+ *
1036
+ * | Property | Type | Description |
1037
+ * |---|---|---|
1038
+ * | `name` | `string` | Sheet name |
1039
+ * | `index` | `number` | Zero-based sheet index |
1040
+ * | `visible` | `boolean` | Whether the sheet is visible |
1041
+ * | `rowCount` | `number` | Total rows in the sheet |
1042
+ * | `colCount` | `number` | Total columns in the sheet |
1043
+ */
1044
+ export const PluginSpreadsheetSheetInfo = z.object({
1045
+ name: z.string(),
1046
+ index: z.number(),
1047
+ visible: z.boolean(),
1048
+ rowCount: z.number(),
1049
+ colCount: z.number(),
1050
+ })
1051
+ export type PluginSpreadsheetSheetInfo = z.infer<
1052
+ typeof PluginSpreadsheetSheetInfo
1053
+ >
1054
+
1055
+ /**
1056
+ * Result of {@linkcode PluginProgramSpreadsheetApi.listSheets}.
1057
+ *
1058
+ * | Property | Type | Description |
1059
+ * |---|---|---|
1060
+ * | `sheets` | {@linkcode PluginSpreadsheetSheetInfo}`[]` | All sheets in the workbook |
1061
+ * | `activeSheet` | `string \| null` | The active sheet name, or `null` |
1062
+ */
1063
+ export const PluginProgramSpreadsheetListSheetsResult = z.object({
1064
+ sheets: z.array(PluginSpreadsheetSheetInfo),
1065
+ activeSheet: z.string().nullable(),
1066
+ })
1067
+ export type PluginProgramSpreadsheetListSheetsResult = z.infer<
1068
+ typeof PluginProgramSpreadsheetListSheetsResult
1069
+ >
1070
+
1071
+ /**
1072
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.getSheetData}.
1073
+ *
1074
+ * | Property | Type | Description |
1075
+ * |---|---|---|
1076
+ * | `sheetName` | `string` | Sheet to read |
1077
+ * | `range` | `string?` | A1 range; defaults to the sheet's used range |
1078
+ * | `header` | `boolean?` | When `true`, also return records keyed by the first (header) row |
1079
+ */
1080
+ export const PluginProgramSpreadsheetGetSheetDataArgs = z.object({
1081
+ sheetName: z.string(),
1082
+ range: z.string().optional(),
1083
+ header: z.boolean().optional(),
1084
+ })
1085
+ export type PluginProgramSpreadsheetGetSheetDataArgs = z.infer<
1086
+ typeof PluginProgramSpreadsheetGetSheetDataArgs
1087
+ >
1088
+
1089
+ /**
1090
+ * Result of {@linkcode PluginProgramSpreadsheetApi.getSheetData}.
1091
+ *
1092
+ * | Property | Type | Description |
1093
+ * |---|---|---|
1094
+ * | `sheetName` | `string` | The sheet that was read |
1095
+ * | `range` | `string` | A1 range that was read |
1096
+ * | `values` | `cell[][]` | Row-major matrix of cell values |
1097
+ * | `records` | `Record<string, cell>[]?` | Present only when `header` was `true`: rows keyed by header |
1098
+ */
1099
+ export const PluginProgramSpreadsheetGetSheetDataResult = z.object({
1100
+ sheetName: z.string(),
1101
+ range: z.string(),
1102
+ values: z.array(z.array(PluginSpreadsheetCell)),
1103
+ records: z.array(z.record(z.string(), PluginSpreadsheetCell)).optional(),
1104
+ })
1105
+ export type PluginProgramSpreadsheetGetSheetDataResult = z.infer<
1106
+ typeof PluginProgramSpreadsheetGetSheetDataResult
1107
+ >
1108
+
1109
+ /** Chart type for {@linkcode PluginProgramSpreadsheetApi.addChart}. */
1110
+ export const PluginSpreadsheetChartType = z.enum([
1111
+ "column",
1112
+ "bar",
1113
+ "line",
1114
+ "pie",
1115
+ "area",
1116
+ "scatter",
1117
+ ])
1118
+ export type PluginSpreadsheetChartType = z.infer<
1119
+ typeof PluginSpreadsheetChartType
1120
+ >
1121
+
1122
+ /**
1123
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.addChart}.
1124
+ *
1125
+ * | Property | Type | Description |
1126
+ * |---|---|---|
1127
+ * | `sheetName` | `string` | Sheet to add the chart to |
1128
+ * | `chartType` | `"column" \| "bar" \| "line" \| "pie" \| "area" \| "scatter"` | Chart type |
1129
+ * | `dataRange` | `string` | A1 range driving the chart |
1130
+ * | `title` | `string?` | Optional chart title |
1131
+ * | `position` | `{ x; y }?` | Top-left position (sheet coords) |
1132
+ * | `size` | `{ width; height }?` | Chart size in px |
1133
+ */
1134
+ export const PluginProgramSpreadsheetAddChartArgs = z.object({
1135
+ sheetName: z.string(),
1136
+ chartType: PluginSpreadsheetChartType,
1137
+ dataRange: z.string(),
1138
+ title: z.string().optional(),
1139
+ position: z.object({ x: z.number(), y: z.number() }).optional(),
1140
+ size: z.object({ width: z.number(), height: z.number() }).optional(),
1141
+ })
1142
+ export type PluginProgramSpreadsheetAddChartArgs = z.infer<
1143
+ typeof PluginProgramSpreadsheetAddChartArgs
1144
+ >
1145
+
1146
+ /**
1147
+ * Result of {@linkcode PluginProgramSpreadsheetApi.addChart}.
1148
+ *
1149
+ * | Property | Type | Description |
1150
+ * |---|---|---|
1151
+ * | `chartId` | `string` | Id of the created chart |
1152
+ */
1153
+ export const PluginProgramSpreadsheetAddChartResult = z.object({
1154
+ chartId: z.string(),
1155
+ })
1156
+ export type PluginProgramSpreadsheetAddChartResult = z.infer<
1157
+ typeof PluginProgramSpreadsheetAddChartResult
1158
+ >
1159
+
1160
+ /**
1161
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.highlightCells}.
1162
+ *
1163
+ * | Property | Type | Description |
1164
+ * |---|---|---|
1165
+ * | `sheetName` | `string` | Sheet containing the range |
1166
+ * | `range` | `string` | A1 range to highlight |
1167
+ * | `color` | `string?` | CSS hex background color (a default emphasis is used when omitted) |
1168
+ * | `bold` | `boolean?` | Also bold the text |
1169
+ */
1170
+ export const PluginProgramSpreadsheetHighlightCellsArgs = z.object({
1171
+ sheetName: z.string(),
1172
+ range: z.string(),
1173
+ color: z.string().optional(),
1174
+ bold: z.boolean().optional(),
1175
+ })
1176
+ export type PluginProgramSpreadsheetHighlightCellsArgs = z.infer<
1177
+ typeof PluginProgramSpreadsheetHighlightCellsArgs
1178
+ >
1179
+
1180
+ /**
1181
+ * Result of {@linkcode PluginProgramSpreadsheetApi.highlightCells}.
1182
+ *
1183
+ * | Property | Type | Description |
1184
+ * |---|---|---|
1185
+ * | `sheetName` | `string` | The sheet that was highlighted |
1186
+ * | `range` | `string` | The range that was highlighted |
1187
+ */
1188
+ export const PluginProgramSpreadsheetHighlightCellsResult = z.object({
1189
+ sheetName: z.string(),
1190
+ range: z.string(),
1191
+ })
1192
+ export type PluginProgramSpreadsheetHighlightCellsResult = z.infer<
1193
+ typeof PluginProgramSpreadsheetHighlightCellsResult
1194
+ >
1195
+
1196
+ // --- getProgram / getTakeoff dataset reads ---------------------------------
1197
+
1198
+ /**
1199
+ * One department row in the area-program dataset. Areas are in the enclosing
1200
+ * {@linkcode PluginProgramSpreadsheetGetProgramResult}'s `units`. This mirrors
1201
+ * {@linkcode PluginProgramDepartmentMetric}, plus a derived `variance`.
1202
+ *
1203
+ * | Property | Type | Description |
1204
+ * |---|---|---|
1205
+ * | `departmentId` | `string` | Department id |
1206
+ * | `name` | `string` | Department name |
1207
+ * | `targetArea` | `number \| null` | Target area, or `null` if no target is set |
1208
+ * | `allocatedArea` | `number` | Area currently allocated to this department |
1209
+ * | `variance` | `number \| null` | `allocatedArea − targetArea`, or `null` when no target |
1210
+ */
1211
+ export const PluginSpreadsheetProgramRow = z.object({
1212
+ departmentId: z.string(),
1213
+ name: z.string(),
1214
+ targetArea: z.number().nullable(),
1215
+ allocatedArea: z.number(),
1216
+ variance: z.number().nullable(),
1217
+ })
1218
+ export type PluginSpreadsheetProgramRow = z.infer<
1219
+ typeof PluginSpreadsheetProgramRow
1220
+ >
1221
+
1222
+ /**
1223
+ * Result of {@linkcode PluginProgramSpreadsheetApi.getProgram} — the area-program
1224
+ * dataset {@linkcode PluginProgramSpreadsheetApi.renderProgram} draws. For the
1225
+ * canonical summary read, see {@linkcode PluginProgramMetricsApi.get}.
1226
+ *
1227
+ * | Property | Type | Description |
1228
+ * |---|---|---|
1229
+ * | `units` | `"ft2" \| "m2"` | The unit every area in this dataset is reported in |
1230
+ * | `rows` | {@linkcode PluginSpreadsheetProgramRow}`[]` | Per-department program rows |
1231
+ * | `totalTargetArea` | `number` | Sum of all department target areas |
1232
+ * | `totalAllocatedArea` | `number` | Total allocated area |
1233
+ * | `generatedAt` | `string` | ISO timestamp of when the dataset was projected |
1234
+ */
1235
+ export const PluginProgramSpreadsheetGetProgramResult = z.object({
1236
+ units: PluginAreaUnit,
1237
+ rows: z.array(PluginSpreadsheetProgramRow),
1238
+ totalTargetArea: z.number(),
1239
+ totalAllocatedArea: z.number(),
1240
+ generatedAt: z.string(),
1241
+ })
1242
+ export type PluginProgramSpreadsheetGetProgramResult = z.infer<
1243
+ typeof PluginProgramSpreadsheetGetProgramResult
1244
+ >
1245
+
1246
+ /**
1247
+ * One family-aggregated row in the quantity/material takeoff dataset. The takeoff
1248
+ * is grouped by object type + category + family (not per element), so each row is
1249
+ * a rolled-up quantity for that family.
1250
+ *
1251
+ * | Property | Type | Description |
1252
+ * |---|---|---|
1253
+ * | `objectType` | `string` | Element object type (e.g. `"Wall"`, `"Door"`, `"Window"`) |
1254
+ * | `category` | `string` | Element category |
1255
+ * | `family` | `string` | Element family the quantity is aggregated over |
1256
+ * | `quantity` | `number` | Aggregated quantity in `unit` |
1257
+ * | `unit` | `string` | Quantity unit (e.g. `"m"` for length, `"m2"` for area) |
1258
+ */
1259
+ export const PluginSpreadsheetTakeoffRow = z.object({
1260
+ objectType: z.string(),
1261
+ category: z.string(),
1262
+ family: z.string(),
1263
+ quantity: z.number(),
1264
+ unit: z.string(),
1265
+ })
1266
+ export type PluginSpreadsheetTakeoffRow = z.infer<
1267
+ typeof PluginSpreadsheetTakeoffRow
1268
+ >
1269
+
1270
+ /**
1271
+ * Result of {@linkcode PluginProgramSpreadsheetApi.getTakeoff} — the takeoff dataset
1272
+ * {@linkcode PluginProgramSpreadsheetApi.renderTakeoff} draws.
1273
+ *
1274
+ * | Property | Type | Description |
1275
+ * |---|---|---|
1276
+ * | `rows` | {@linkcode PluginSpreadsheetTakeoffRow}`[]` | One row per aggregated object-type/category/family group |
1277
+ * | `rowCount` | `number` | Number of rows |
1278
+ * | `generatedAt` | `string` | ISO timestamp of when the dataset was read |
1279
+ */
1280
+ export const PluginProgramSpreadsheetGetTakeoffResult = z.object({
1281
+ rows: z.array(PluginSpreadsheetTakeoffRow),
1282
+ rowCount: z.number(),
1283
+ generatedAt: z.string(),
1284
+ })
1285
+ export type PluginProgramSpreadsheetGetTakeoffResult = z.infer<
1286
+ typeof PluginProgramSpreadsheetGetTakeoffResult
1287
+ >
1288
+
1289
+ // --- createSheet -----------------------------------------------------------
1290
+
1291
+ /** Behaviour when {@linkcode PluginProgramSpreadsheetApi.createSheet} targets an existing sheet name. */
1292
+ export const PluginSpreadsheetWhenExists = z.enum(["reuse", "replace", "error"])
1293
+ export type PluginSpreadsheetWhenExists = z.infer<
1294
+ typeof PluginSpreadsheetWhenExists
1295
+ >
1296
+
1297
+ /**
1298
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.createSheet}.
1299
+ *
1300
+ * | Property | Type | Description |
1301
+ * |---|---|---|
1302
+ * | `name` | `string` | The sheet name to create |
1303
+ * | `whenExists` | `"reuse" \| "replace" \| "error"?` | Behaviour if the name exists (default `"reuse"`) |
1304
+ */
1305
+ export const PluginProgramSpreadsheetCreateSheetArgs = z.object({
1306
+ name: z.string(),
1307
+ whenExists: PluginSpreadsheetWhenExists.optional(),
1308
+ })
1309
+ export type PluginProgramSpreadsheetCreateSheetArgs = z.infer<
1310
+ typeof PluginProgramSpreadsheetCreateSheetArgs
1311
+ >
1312
+
1313
+ /**
1314
+ * Result of {@linkcode PluginProgramSpreadsheetApi.createSheet}.
1315
+ *
1316
+ * | Property | Type | Description |
1317
+ * |---|---|---|
1318
+ * | `sheetName` | `string` | The resolved sheet name |
1319
+ * | `replaced` | `boolean` | Whether an existing sheet was replaced/cleared |
1320
+ * | `sheetIndex` | `number \| null` | Zero-based index of the sheet, or `null` if unknown |
1321
+ */
1322
+ export const PluginProgramSpreadsheetCreateSheetResult = z.object({
1323
+ sheetName: z.string(),
1324
+ replaced: z.boolean(),
1325
+ sheetIndex: z.number().nullable(),
1326
+ })
1327
+ export type PluginProgramSpreadsheetCreateSheetResult = z.infer<
1328
+ typeof PluginProgramSpreadsheetCreateSheetResult
1329
+ >
1330
+
1331
+ // --- setValues -------------------------------------------------------------
1332
+
1333
+ /**
1334
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.setValues}.
1335
+ *
1336
+ * | Property | Type | Description |
1337
+ * |---|---|---|
1338
+ * | `sheetName` | `string` | Sheet to write into |
1339
+ * | `values` | `cell[][]` | Row-major matrix of values to write |
1340
+ * | `startCell` | `string?` | Top-left anchor in A1 notation (default `"A1"`) |
1341
+ */
1342
+ export const PluginProgramSpreadsheetSetValuesArgs = z.object({
1343
+ sheetName: z.string(),
1344
+ values: z.array(z.array(PluginSpreadsheetCell)),
1345
+ startCell: z.string().optional(),
1346
+ })
1347
+ export type PluginProgramSpreadsheetSetValuesArgs = z.infer<
1348
+ typeof PluginProgramSpreadsheetSetValuesArgs
1349
+ >
1350
+
1351
+ /**
1352
+ * Result of {@linkcode PluginProgramSpreadsheetApi.setValues}.
1353
+ *
1354
+ * | Property | Type | Description |
1355
+ * |---|---|---|
1356
+ * | `sheetName` | `string` | The sheet that was written |
1357
+ * | `startCell` | `string` | The anchor cell values were written from |
1358
+ * | `rowCount` | `number` | Number of rows written |
1359
+ * | `colCount` | `number` | Widest row's column count |
1360
+ */
1361
+ export const PluginProgramSpreadsheetSetValuesResult = z.object({
1362
+ sheetName: z.string(),
1363
+ startCell: z.string(),
1364
+ rowCount: z.number(),
1365
+ colCount: z.number(),
1366
+ })
1367
+ export type PluginProgramSpreadsheetSetValuesResult = z.infer<
1368
+ typeof PluginProgramSpreadsheetSetValuesResult
1369
+ >
1370
+
1371
+ // --- setFormulas -----------------------------------------------------------
1372
+
1373
+ /**
1374
+ * A single cell formula for {@linkcode PluginProgramSpreadsheetApi.setFormulas}.
1375
+ *
1376
+ * | Property | Type | Description |
1377
+ * |---|---|---|
1378
+ * | `cell` | `string` | Target cell in A1 notation |
1379
+ * | `formula` | `string` | Formula expression (a leading `=` is optional) |
1380
+ */
1381
+ export const PluginSpreadsheetFormula = z.object({
1382
+ cell: z.string(),
1383
+ formula: z.string(),
1384
+ })
1385
+ export type PluginSpreadsheetFormula = z.infer<typeof PluginSpreadsheetFormula>
1386
+
1387
+ /**
1388
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.setFormulas}.
1389
+ *
1390
+ * | Property | Type | Description |
1391
+ * |---|---|---|
1392
+ * | `sheetName` | `string` | Sheet to set formulas on |
1393
+ * | `formulas` | {@linkcode PluginSpreadsheetFormula}`[]` | The cell → formula assignments |
1394
+ */
1395
+ export const PluginProgramSpreadsheetSetFormulasArgs = z.object({
1396
+ sheetName: z.string(),
1397
+ formulas: z.array(PluginSpreadsheetFormula),
1398
+ })
1399
+ export type PluginProgramSpreadsheetSetFormulasArgs = z.infer<
1400
+ typeof PluginProgramSpreadsheetSetFormulasArgs
1401
+ >
1402
+
1403
+ /**
1404
+ * Result of {@linkcode PluginProgramSpreadsheetApi.setFormulas}.
1405
+ *
1406
+ * | Property | Type | Description |
1407
+ * |---|---|---|
1408
+ * | `sheetName` | `string` | The sheet that was written |
1409
+ * | `count` | `number` | Number of formulas set |
1410
+ */
1411
+ export const PluginProgramSpreadsheetSetFormulasResult = z.object({
1412
+ sheetName: z.string(),
1413
+ count: z.number(),
1414
+ })
1415
+ export type PluginProgramSpreadsheetSetFormulasResult = z.infer<
1416
+ typeof PluginProgramSpreadsheetSetFormulasResult
1417
+ >
1418
+
1419
+ // --- setStyles -------------------------------------------------------------
1420
+
1421
+ /** Font weight for a {@linkcode PluginSpreadsheetCellStyle}. */
1422
+ export const PluginSpreadsheetFontWeight = z.enum(["normal", "bold"])
1423
+ export type PluginSpreadsheetFontWeight = z.infer<
1424
+ typeof PluginSpreadsheetFontWeight
1425
+ >
1426
+
1427
+ /** Font style for a {@linkcode PluginSpreadsheetCellStyle}. */
1428
+ export const PluginSpreadsheetFontStyle = z.enum(["normal", "italic"])
1429
+ export type PluginSpreadsheetFontStyle = z.infer<
1430
+ typeof PluginSpreadsheetFontStyle
1431
+ >
1432
+
1433
+ /** Horizontal cell alignment for a {@linkcode PluginSpreadsheetCellStyle}. */
1434
+ export const PluginSpreadsheetHorizontalAlign = z.enum([
1435
+ "left",
1436
+ "center",
1437
+ "right",
1438
+ "general",
1439
+ ])
1440
+ export type PluginSpreadsheetHorizontalAlign = z.infer<
1441
+ typeof PluginSpreadsheetHorizontalAlign
1442
+ >
1443
+
1444
+ /** Vertical cell alignment for a {@linkcode PluginSpreadsheetCellStyle}. */
1445
+ export const PluginSpreadsheetVerticalAlign = z.enum([
1446
+ "top",
1447
+ "center",
1448
+ "bottom",
1449
+ ])
1450
+ export type PluginSpreadsheetVerticalAlign = z.infer<
1451
+ typeof PluginSpreadsheetVerticalAlign
1452
+ >
1453
+
1454
+ /**
1455
+ * A cell style for {@linkcode PluginProgramSpreadsheetApi.setStyles}. All fields
1456
+ * are optional; only the ones provided are applied.
1457
+ *
1458
+ * | Property | Type | Description |
1459
+ * |---|---|---|
1460
+ * | `backColor` | `string?` | Background (fill) color, CSS hex |
1461
+ * | `foreColor` | `string?` | Text color, CSS hex |
1462
+ * | `font` | `string?` | Full CSS font shorthand (overrides the parts below) |
1463
+ * | `fontFamily` | `string?` | Font family |
1464
+ * | `fontSize` | `number?` | Font size in px |
1465
+ * | `fontWeight` | `"normal" \| "bold"?` | Font weight |
1466
+ * | `fontStyle` | `"normal" \| "italic"?` | Font style |
1467
+ * | `formatter` | `string?` | Number/date format string |
1468
+ * | `horizontalAlign` | `"left" \| "center" \| "right" \| "general"?` | Horizontal alignment |
1469
+ * | `verticalAlign` | `"top" \| "center" \| "bottom"?` | Vertical alignment |
1470
+ */
1471
+ export const PluginSpreadsheetCellStyle = z.object({
1472
+ backColor: z.string().optional(),
1473
+ foreColor: z.string().optional(),
1474
+ font: z.string().optional(),
1475
+ fontFamily: z.string().optional(),
1476
+ fontSize: z.number().optional(),
1477
+ fontWeight: PluginSpreadsheetFontWeight.optional(),
1478
+ fontStyle: PluginSpreadsheetFontStyle.optional(),
1479
+ formatter: z.string().optional(),
1480
+ horizontalAlign: PluginSpreadsheetHorizontalAlign.optional(),
1481
+ verticalAlign: PluginSpreadsheetVerticalAlign.optional(),
1482
+ })
1483
+ export type PluginSpreadsheetCellStyle = z.infer<
1484
+ typeof PluginSpreadsheetCellStyle
1485
+ >
1486
+
1487
+ /**
1488
+ * A range + the style to apply to it, for {@linkcode PluginProgramSpreadsheetApi.setStyles}.
1489
+ *
1490
+ * | Property | Type | Description |
1491
+ * |---|---|---|
1492
+ * | `range` | `string` | A1 range to style |
1493
+ * | `style` | {@linkcode PluginSpreadsheetCellStyle} | The style to apply |
1494
+ */
1495
+ export const PluginSpreadsheetRangeStyle = z.object({
1496
+ range: z.string(),
1497
+ style: PluginSpreadsheetCellStyle,
1498
+ })
1499
+ export type PluginSpreadsheetRangeStyle = z.infer<
1500
+ typeof PluginSpreadsheetRangeStyle
1501
+ >
1502
+
1503
+ /**
1504
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.setStyles}.
1505
+ *
1506
+ * | Property | Type | Description |
1507
+ * |---|---|---|
1508
+ * | `sheetName` | `string` | Sheet containing the ranges |
1509
+ * | `ranges` | {@linkcode PluginSpreadsheetRangeStyle}`[]` | Range → style assignments |
1510
+ */
1511
+ export const PluginProgramSpreadsheetSetStylesArgs = z.object({
1512
+ sheetName: z.string(),
1513
+ ranges: z.array(PluginSpreadsheetRangeStyle),
1514
+ })
1515
+ export type PluginProgramSpreadsheetSetStylesArgs = z.infer<
1516
+ typeof PluginProgramSpreadsheetSetStylesArgs
1517
+ >
1518
+
1519
+ /**
1520
+ * Result of {@linkcode PluginProgramSpreadsheetApi.setStyles}.
1521
+ *
1522
+ * | Property | Type | Description |
1523
+ * |---|---|---|
1524
+ * | `sheetName` | `string` | The sheet that was styled |
1525
+ * | `count` | `number` | Number of ranges styled |
1526
+ */
1527
+ export const PluginProgramSpreadsheetSetStylesResult = z.object({
1528
+ sheetName: z.string(),
1529
+ count: z.number(),
1530
+ })
1531
+ export type PluginProgramSpreadsheetSetStylesResult = z.infer<
1532
+ typeof PluginProgramSpreadsheetSetStylesResult
1533
+ >
1534
+
1535
+ // --- mergeCells ------------------------------------------------------------
1536
+
1537
+ /**
1538
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.mergeCells}.
1539
+ *
1540
+ * | Property | Type | Description |
1541
+ * |---|---|---|
1542
+ * | `sheetName` | `string` | Sheet containing the range |
1543
+ * | `range` | `string` | A1 range to merge into one spanned cell |
1544
+ * | `value` | `cell?` | Optional value to set in the merged (top-left) cell |
1545
+ */
1546
+ export const PluginProgramSpreadsheetMergeCellsArgs = z.object({
1547
+ sheetName: z.string(),
1548
+ range: z.string(),
1549
+ value: PluginSpreadsheetCell.optional(),
1550
+ })
1551
+ export type PluginProgramSpreadsheetMergeCellsArgs = z.infer<
1552
+ typeof PluginProgramSpreadsheetMergeCellsArgs
1553
+ >
1554
+
1555
+ /**
1556
+ * Result of {@linkcode PluginProgramSpreadsheetApi.mergeCells}.
1557
+ *
1558
+ * | Property | Type | Description |
1559
+ * |---|---|---|
1560
+ * | `sheetName` | `string` | The sheet that was merged |
1561
+ * | `range` | `string` | The range that was merged |
1562
+ */
1563
+ export const PluginProgramSpreadsheetMergeCellsResult = z.object({
1564
+ sheetName: z.string(),
1565
+ range: z.string(),
1566
+ })
1567
+ export type PluginProgramSpreadsheetMergeCellsResult = z.infer<
1568
+ typeof PluginProgramSpreadsheetMergeCellsResult
1569
+ >
1570
+
1571
+ // --- addConditionalFormatting ----------------------------------------------
1572
+
1573
+ /** Conditional-formatting rule type. Currently only `dataBar`; more are reserved. */
1574
+ export const PluginSpreadsheetConditionalRuleType = z.enum(["dataBar"])
1575
+ export type PluginSpreadsheetConditionalRuleType = z.infer<
1576
+ typeof PluginSpreadsheetConditionalRuleType
1577
+ >
1578
+
1579
+ /**
1580
+ * A conditional-formatting rule for {@linkcode PluginProgramSpreadsheetApi.addConditionalFormatting}.
1581
+ *
1582
+ * | Property | Type | Description |
1583
+ * |---|---|---|
1584
+ * | `type` | `"dataBar"` | The rule kind (a proportional in-cell bar) |
1585
+ * | `color` | `string?` | Bar color, CSS hex (a default is used when omitted) |
1586
+ */
1587
+ export const PluginSpreadsheetConditionalRule = z.object({
1588
+ type: PluginSpreadsheetConditionalRuleType,
1589
+ color: z.string().optional(),
1590
+ })
1591
+ export type PluginSpreadsheetConditionalRule = z.infer<
1592
+ typeof PluginSpreadsheetConditionalRule
1593
+ >
1594
+
1595
+ /**
1596
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.addConditionalFormatting}.
1597
+ *
1598
+ * | Property | Type | Description |
1599
+ * |---|---|---|
1600
+ * | `sheetName` | `string` | Sheet containing the range |
1601
+ * | `range` | `string` | A1 range to format |
1602
+ * | `rule` | {@linkcode PluginSpreadsheetConditionalRule} | The conditional-format rule |
1603
+ */
1604
+ export const PluginProgramSpreadsheetAddConditionalFormattingArgs = z.object({
1605
+ sheetName: z.string(),
1606
+ range: z.string(),
1607
+ rule: PluginSpreadsheetConditionalRule,
1608
+ })
1609
+ export type PluginProgramSpreadsheetAddConditionalFormattingArgs = z.infer<
1610
+ typeof PluginProgramSpreadsheetAddConditionalFormattingArgs
1611
+ >
1612
+
1613
+ /**
1614
+ * Result of {@linkcode PluginProgramSpreadsheetApi.addConditionalFormatting}.
1615
+ *
1616
+ * | Property | Type | Description |
1617
+ * |---|---|---|
1618
+ * | `sheetName` | `string` | The sheet that was formatted |
1619
+ * | `range` | `string` | The range the rule was applied to |
1620
+ * | `created` | `boolean` | Whether a data-bar rule was created (vs a fallback fill) |
1621
+ */
1622
+ export const PluginProgramSpreadsheetAddConditionalFormattingResult = z.object({
1623
+ sheetName: z.string(),
1624
+ range: z.string(),
1625
+ created: z.boolean(),
1626
+ })
1627
+ export type PluginProgramSpreadsheetAddConditionalFormattingResult = z.infer<
1628
+ typeof PluginProgramSpreadsheetAddConditionalFormattingResult
1629
+ >
1630
+
1631
+ // --- recalculate -----------------------------------------------------------
1632
+
1633
+ /**
1634
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.recalculate}.
1635
+ *
1636
+ * | Property | Type | Description |
1637
+ * |---|---|---|
1638
+ * | `sheetName` | `string?` | A sheet to focus before recalculating; omit for the whole workbook |
1639
+ */
1640
+ export const PluginProgramSpreadsheetRecalculateArgs = z.object({
1641
+ sheetName: z.string().optional(),
1642
+ })
1643
+ export type PluginProgramSpreadsheetRecalculateArgs = z.infer<
1644
+ typeof PluginProgramSpreadsheetRecalculateArgs
1645
+ >
1646
+
1647
+ /**
1648
+ * Result of {@linkcode PluginProgramSpreadsheetApi.recalculate}.
1649
+ *
1650
+ * | Property | Type | Description |
1651
+ * |---|---|---|
1652
+ * | `scope` | `"sheet" \| "workbook"` | Whether a single sheet was focused or the whole workbook |
1653
+ * | `sheetName` | `string \| null` | The focused sheet, or `null` for a workbook-wide recompute |
1654
+ */
1655
+ export const PluginProgramSpreadsheetRecalculateResult = z.object({
1656
+ scope: z.enum(["sheet", "workbook"]),
1657
+ sheetName: z.string().nullable(),
1658
+ })
1659
+ export type PluginProgramSpreadsheetRecalculateResult = z.infer<
1660
+ typeof PluginProgramSpreadsheetRecalculateResult
1661
+ >
1662
+
1663
+ // --- transaction -----------------------------------------------------------
1664
+
1665
+ /** A batchable operation name for {@linkcode PluginProgramSpreadsheetApi.transaction}. */
1666
+ export const PluginSpreadsheetTransactionMethod = z.enum([
1667
+ "createSheet",
1668
+ "setValues",
1669
+ "setFormulas",
1670
+ "setStyles",
1671
+ "mergeCells",
1672
+ ])
1673
+ export type PluginSpreadsheetTransactionMethod = z.infer<
1674
+ typeof PluginSpreadsheetTransactionMethod
1675
+ >
1676
+
1677
+ /**
1678
+ * One operation within a {@linkcode PluginProgramSpreadsheetApi.transaction}.
1679
+ *
1680
+ * | Property | Type | Description |
1681
+ * |---|---|---|
1682
+ * | `method` | {@linkcode PluginSpreadsheetTransactionMethod} | The batchable method to run |
1683
+ * | `args` | `unknown` | The `method`'s own arguments object |
1684
+ */
1685
+ export const PluginSpreadsheetTransactionOp = z.object({
1686
+ method: PluginSpreadsheetTransactionMethod,
1687
+ args: z.unknown(),
1688
+ })
1689
+ export type PluginSpreadsheetTransactionOp = z.infer<
1690
+ typeof PluginSpreadsheetTransactionOp
1691
+ >
1692
+
1693
+ /**
1694
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.transaction}.
1695
+ *
1696
+ * | Property | Type | Description |
1697
+ * |---|---|---|
1698
+ * | `operations` | {@linkcode PluginSpreadsheetTransactionOp}`[]` | The operations to run in order |
1699
+ * | `label` | `string?` | Undo-history label for the batch |
1700
+ */
1701
+ export const PluginProgramSpreadsheetTransactionArgs = z.object({
1702
+ operations: z.array(PluginSpreadsheetTransactionOp),
1703
+ label: z.string().optional(),
1704
+ })
1705
+ export type PluginProgramSpreadsheetTransactionArgs = z.infer<
1706
+ typeof PluginProgramSpreadsheetTransactionArgs
1707
+ >
1708
+
1709
+ /**
1710
+ * Result of {@linkcode PluginProgramSpreadsheetApi.transaction}.
1711
+ *
1712
+ * | Property | Type | Description |
1713
+ * |---|---|---|
1714
+ * | `label` | `string` | The undo-history label used |
1715
+ * | `operationCount` | `number` | Number of operations run |
1716
+ * | `results` | `unknown[]` | Each operation's result, in order |
1717
+ */
1718
+ export const PluginProgramSpreadsheetTransactionResult = z.object({
1719
+ label: z.string(),
1720
+ operationCount: z.number(),
1721
+ results: z.array(z.unknown()),
1722
+ })
1723
+ export type PluginProgramSpreadsheetTransactionResult = z.infer<
1724
+ typeof PluginProgramSpreadsheetTransactionResult
1725
+ >
1726
+
1727
+ // --- runScript -------------------------------------------------------------
1728
+
1729
+ /**
1730
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.runScript}.
1731
+ *
1732
+ * | Property | Type | Description |
1733
+ * |---|---|---|
1734
+ * | `script` | `string` | Script source, run against a sandboxed `workbook` facade |
1735
+ */
1736
+ export const PluginProgramSpreadsheetRunScriptArgs = z.object({
1737
+ script: z.string(),
1738
+ })
1739
+ export type PluginProgramSpreadsheetRunScriptArgs = z.infer<
1740
+ typeof PluginProgramSpreadsheetRunScriptArgs
1741
+ >
1742
+
1743
+ /**
1744
+ * Result of {@linkcode PluginProgramSpreadsheetApi.runScript}.
1745
+ *
1746
+ * | Property | Type | Description |
1747
+ * |---|---|---|
1748
+ * | `result` | `unknown` | The script's return value (`null` when it returns nothing) |
1749
+ */
1750
+ export const PluginProgramSpreadsheetRunScriptResult = z.object({
1751
+ result: z.unknown(),
1752
+ })
1753
+ export type PluginProgramSpreadsheetRunScriptResult = z.infer<
1754
+ typeof PluginProgramSpreadsheetRunScriptResult
1755
+ >
1756
+
1757
+ // --- getAuditLog -----------------------------------------------------------
1758
+
1759
+ /** Status of an audit-log entry. */
1760
+ export const PluginSpreadsheetAuditStatus = z.enum(["success", "error"])
1761
+ export type PluginSpreadsheetAuditStatus = z.infer<
1762
+ typeof PluginSpreadsheetAuditStatus
1763
+ >
1764
+
1765
+ /**
1766
+ * One entry in the program-spreadsheet audit log.
1767
+ *
1768
+ * | Property | Type | Description |
1769
+ * |---|---|---|
1770
+ * | `id` | `string` | Entry id |
1771
+ * | `pluginId` | `string` | Id of the plugin that performed the operation |
1772
+ * | `method` | `string` | The API method invoked |
1773
+ * | `label` | `string?` | Optional operation label |
1774
+ * | `sheetName` | `string?` | The sheet the operation targeted, if any |
1775
+ * | `timestamp` | `string` | ISO timestamp |
1776
+ * | `status` | `"success" \| "error"` | Whether the operation succeeded |
1777
+ * | `summary` | `string?` | Short human-readable summary |
1778
+ */
1779
+ export const PluginSpreadsheetAuditEntry = z.object({
1780
+ id: z.string(),
1781
+ pluginId: z.string(),
1782
+ method: z.string(),
1783
+ label: z.string().optional(),
1784
+ sheetName: z.string().optional(),
1785
+ timestamp: z.string(),
1786
+ status: PluginSpreadsheetAuditStatus,
1787
+ summary: z.string().optional(),
1788
+ })
1789
+ export type PluginSpreadsheetAuditEntry = z.infer<
1790
+ typeof PluginSpreadsheetAuditEntry
1791
+ >
1792
+
1793
+ /**
1794
+ * Arguments for {@linkcode PluginProgramSpreadsheetApi.getAuditLog}.
1795
+ *
1796
+ * | Property | Type | Description |
1797
+ * |---|---|---|
1798
+ * | `limit` | `number?` | Max entries to return (clamped 1–100, default 20) |
1799
+ */
1800
+ export const PluginProgramSpreadsheetGetAuditLogArgs = z.object({
1801
+ limit: z.number().optional(),
1802
+ })
1803
+ export type PluginProgramSpreadsheetGetAuditLogArgs = z.infer<
1804
+ typeof PluginProgramSpreadsheetGetAuditLogArgs
1805
+ >
1806
+
1807
+ /**
1808
+ * Result of {@linkcode PluginProgramSpreadsheetApi.getAuditLog}.
1809
+ *
1810
+ * | Property | Type | Description |
1811
+ * |---|---|---|
1812
+ * | `entries` | {@linkcode PluginSpreadsheetAuditEntry}`[]` | Recent audit entries, newest first |
1813
+ */
1814
+ export const PluginProgramSpreadsheetGetAuditLogResult = z.object({
1815
+ entries: z.array(PluginSpreadsheetAuditEntry),
1816
+ })
1817
+ export type PluginProgramSpreadsheetGetAuditLogResult = z.infer<
1818
+ typeof PluginProgramSpreadsheetGetAuditLogResult
1819
+ >
1820
+
1821
+ // --- ping ------------------------------------------------------------------
1822
+
1823
+ /**
1824
+ * Result of {@linkcode PluginProgramSpreadsheetApi.ping}.
1825
+ *
1826
+ * | Property | Type | Description |
1827
+ * |---|---|---|
1828
+ * | `pong` | `boolean` | `true` when the program-mode spreadsheet bridge is reachable |
1829
+ */
1830
+ export const PluginProgramSpreadsheetPingResult = z.object({
1831
+ pong: z.boolean(),
1832
+ })
1833
+ export type PluginProgramSpreadsheetPingResult = z.infer<
1834
+ typeof PluginProgramSpreadsheetPingResult
1835
+ >
1836
+
1837
+ // --- templates.* -----------------------------------------------------------
1838
+
1839
+ /** The visibility scope of a saved template. */
1840
+ export const PluginSpreadsheetTemplateScope = z.enum(["project", "global"])
1841
+ export type PluginSpreadsheetTemplateScope = z.infer<
1842
+ typeof PluginSpreadsheetTemplateScope
1843
+ >
1844
+
1845
+ /**
1846
+ * Arguments for {@linkcode PluginProgramSpreadsheetTemplatesApi.create}.
1847
+ *
1848
+ * | Property | Type | Description |
1849
+ * |---|---|---|
1850
+ * | `name` | `string` | Template name (re-saving the same name overwrites it) |
1851
+ * | `sheetName` | `string` | The source sheet to capture |
1852
+ * | `scope` | `"project" \| "global"?` | Template scope (default `"project"`) |
1853
+ */
1854
+ export const PluginProgramSpreadsheetTemplatesCreateArgs = z.object({
1855
+ name: z.string(),
1856
+ sheetName: z.string(),
1857
+ scope: PluginSpreadsheetTemplateScope.optional(),
1858
+ })
1859
+ export type PluginProgramSpreadsheetTemplatesCreateArgs = z.infer<
1860
+ typeof PluginProgramSpreadsheetTemplatesCreateArgs
1861
+ >
1862
+
1863
+ /**
1864
+ * Result of {@linkcode PluginProgramSpreadsheetTemplatesApi.create}.
1865
+ *
1866
+ * | Property | Type | Description |
1867
+ * |---|---|---|
1868
+ * | `id` | `string` | The new template's id |
1869
+ * | `name` | `string` | The template name |
1870
+ * | `scope` | `"project" \| "global"` | The template scope |
1871
+ * | `sheetName` | `string` | The source sheet captured |
1872
+ */
1873
+ export const PluginProgramSpreadsheetTemplatesCreateResult = z.object({
1874
+ id: z.string(),
1875
+ name: z.string(),
1876
+ scope: PluginSpreadsheetTemplateScope,
1877
+ sheetName: z.string(),
1878
+ })
1879
+ export type PluginProgramSpreadsheetTemplatesCreateResult = z.infer<
1880
+ typeof PluginProgramSpreadsheetTemplatesCreateResult
1881
+ >
1882
+
1883
+ /**
1884
+ * Arguments for {@linkcode PluginProgramSpreadsheetTemplatesApi.apply}.
1885
+ *
1886
+ * | Property | Type | Description |
1887
+ * |---|---|---|
1888
+ * | `name` | `string` | The template to apply |
1889
+ * | `targetSheetName` | `string` | The sheet to create/replace from the template |
1890
+ */
1891
+ export const PluginProgramSpreadsheetTemplatesApplyArgs = z.object({
1892
+ name: z.string(),
1893
+ targetSheetName: z.string(),
1894
+ })
1895
+ export type PluginProgramSpreadsheetTemplatesApplyArgs = z.infer<
1896
+ typeof PluginProgramSpreadsheetTemplatesApplyArgs
1897
+ >
1898
+
1899
+ /**
1900
+ * Result of {@linkcode PluginProgramSpreadsheetTemplatesApi.apply}.
1901
+ *
1902
+ * | Property | Type | Description |
1903
+ * |---|---|---|
1904
+ * | `name` | `string` | The template that was applied |
1905
+ * | `targetSheetName` | `string` | The sheet it was applied to |
1906
+ */
1907
+ export const PluginProgramSpreadsheetTemplatesApplyResult = z.object({
1908
+ name: z.string(),
1909
+ targetSheetName: z.string(),
1910
+ })
1911
+ export type PluginProgramSpreadsheetTemplatesApplyResult = z.infer<
1912
+ typeof PluginProgramSpreadsheetTemplatesApplyResult
1913
+ >
1914
+
1915
+ // --- bindings.* ------------------------------------------------------------
1916
+
1917
+ /**
1918
+ * A binding's data source. Currently only the takeoff dataset; `program` is
1919
+ * reserved for a future source.
1920
+ *
1921
+ * | Property | Type | Description |
1922
+ * |---|---|---|
1923
+ * | `dataset` | `"takeoff"` | The dataset the binding pulls from |
1924
+ */
1925
+ export const PluginSpreadsheetBindingSource = z.object({
1926
+ dataset: z.enum(["takeoff"]),
1927
+ })
1928
+ export type PluginSpreadsheetBindingSource = z.infer<
1929
+ typeof PluginSpreadsheetBindingSource
1930
+ >
1931
+
1932
+ /** How a binding refresh writes into its target range. Currently only `replaceRange`. */
1933
+ export const PluginSpreadsheetBindingMode = z.enum(["replaceRange"])
1934
+ export type PluginSpreadsheetBindingMode = z.infer<
1935
+ typeof PluginSpreadsheetBindingMode
1936
+ >
1937
+
1938
+ /**
1939
+ * A binding's target range, for {@linkcode PluginProgramSpreadsheetBindingsApi.create}.
1940
+ *
1941
+ * | Property | Type | Description |
1942
+ * |---|---|---|
1943
+ * | `sheetName` | `string` | The sheet to write into |
1944
+ * | `startCell` | `string?` | Top-left anchor in A1 notation (default `"A1"`) |
1945
+ */
1946
+ export const PluginSpreadsheetBindingTarget = z.object({
1947
+ sheetName: z.string(),
1948
+ startCell: z.string().optional(),
1949
+ })
1950
+ export type PluginSpreadsheetBindingTarget = z.infer<
1951
+ typeof PluginSpreadsheetBindingTarget
1952
+ >
1953
+
1954
+ /**
1955
+ * A stored data binding.
1956
+ *
1957
+ * | Property | Type | Description |
1958
+ * |---|---|---|
1959
+ * | `id` | `string` | Binding id |
1960
+ * | `name` | `string` | Binding name (unique per workbook) |
1961
+ * | `pluginId` | `string` | Id of the plugin that owns the binding |
1962
+ * | `source` | {@linkcode PluginSpreadsheetBindingSource} | The bound dataset |
1963
+ * | `target` | `{ sheetName: string; startCell: string }` | The resolved target range anchor |
1964
+ * | `mode` | {@linkcode PluginSpreadsheetBindingMode} | How a refresh writes into the target |
1965
+ * | `createdAt` | `string` | ISO creation timestamp |
1966
+ * | `updatedAt` | `string` | ISO last-refresh timestamp |
1967
+ */
1968
+ export const PluginSpreadsheetBinding = z.object({
1969
+ id: z.string(),
1970
+ name: z.string(),
1971
+ pluginId: z.string(),
1972
+ source: PluginSpreadsheetBindingSource,
1973
+ target: z.object({
1974
+ sheetName: z.string(),
1975
+ startCell: z.string(),
1976
+ }),
1977
+ mode: PluginSpreadsheetBindingMode,
1978
+ createdAt: z.string(),
1979
+ updatedAt: z.string(),
1980
+ })
1981
+ export type PluginSpreadsheetBinding = z.infer<typeof PluginSpreadsheetBinding>
1982
+
1983
+ /**
1984
+ * The outcome of refreshing a single binding.
1985
+ *
1986
+ * | Property | Type | Description |
1987
+ * |---|---|---|
1988
+ * | `id` | `string` | The refreshed binding's id |
1989
+ * | `name` | `string` | The refreshed binding's name |
1990
+ * | `sheetName` | `string` | The sheet that was rewritten |
1991
+ * | `rowCount` | `number` | Number of rows written |
1992
+ */
1993
+ export const PluginSpreadsheetBindingRefresh = z.object({
1994
+ id: z.string(),
1995
+ name: z.string(),
1996
+ sheetName: z.string(),
1997
+ rowCount: z.number(),
1998
+ })
1999
+ export type PluginSpreadsheetBindingRefresh = z.infer<
2000
+ typeof PluginSpreadsheetBindingRefresh
2001
+ >
2002
+
2003
+ /**
2004
+ * Arguments for {@linkcode PluginProgramSpreadsheetBindingsApi.create}.
2005
+ *
2006
+ * | Property | Type | Description |
2007
+ * |---|---|---|
2008
+ * | `name` | `string` | Binding name (re-using a name overwrites it) |
2009
+ * | `source` | {@linkcode PluginSpreadsheetBindingSource} | The dataset to bind |
2010
+ * | `target` | {@linkcode PluginSpreadsheetBindingTarget} | The target sheet range |
2011
+ * | `mode` | {@linkcode PluginSpreadsheetBindingMode}`?` | How a refresh writes (default `"replaceRange"`) |
2012
+ */
2013
+ export const PluginProgramSpreadsheetBindingsCreateArgs = z.object({
2014
+ name: z.string(),
2015
+ source: PluginSpreadsheetBindingSource,
2016
+ target: PluginSpreadsheetBindingTarget,
2017
+ mode: PluginSpreadsheetBindingMode.optional(),
2018
+ })
2019
+ export type PluginProgramSpreadsheetBindingsCreateArgs = z.infer<
2020
+ typeof PluginProgramSpreadsheetBindingsCreateArgs
2021
+ >
2022
+
2023
+ /**
2024
+ * Result of {@linkcode PluginProgramSpreadsheetBindingsApi.create} — the stored
2025
+ * {@linkcode PluginSpreadsheetBinding} plus the initial `refresh` outcome.
2026
+ */
2027
+ export const PluginProgramSpreadsheetBindingsCreateResult =
2028
+ PluginSpreadsheetBinding.extend({
2029
+ refresh: PluginSpreadsheetBindingRefresh,
2030
+ })
2031
+ export type PluginProgramSpreadsheetBindingsCreateResult = z.infer<
2032
+ typeof PluginProgramSpreadsheetBindingsCreateResult
2033
+ >
2034
+
2035
+ /**
2036
+ * Arguments for {@linkcode PluginProgramSpreadsheetBindingsApi.refresh}.
2037
+ *
2038
+ * | Property | Type | Description |
2039
+ * |---|---|---|
2040
+ * | `name` | `string?` | The binding to refresh; omit to refresh every binding |
2041
+ */
2042
+ export const PluginProgramSpreadsheetBindingsRefreshArgs = z.object({
2043
+ name: z.string().optional(),
2044
+ })
2045
+ export type PluginProgramSpreadsheetBindingsRefreshArgs = z.infer<
2046
+ typeof PluginProgramSpreadsheetBindingsRefreshArgs
2047
+ >
2048
+
2049
+ /**
2050
+ * Result of {@linkcode PluginProgramSpreadsheetBindingsApi.refresh}.
2051
+ *
2052
+ * | Property | Type | Description |
2053
+ * |---|---|---|
2054
+ * | `refreshed` | {@linkcode PluginSpreadsheetBindingRefresh}`[]` | One entry per binding refreshed |
2055
+ */
2056
+ export const PluginProgramSpreadsheetBindingsRefreshResult = z.object({
2057
+ refreshed: z.array(PluginSpreadsheetBindingRefresh),
2058
+ })
2059
+ export type PluginProgramSpreadsheetBindingsRefreshResult = z.infer<
2060
+ typeof PluginProgramSpreadsheetBindingsRefreshResult
2061
+ >
2062
+
2063
+ /**
2064
+ * Result of {@linkcode PluginProgramSpreadsheetBindingsApi.list}.
2065
+ *
2066
+ * | Property | Type | Description |
2067
+ * |---|---|---|
2068
+ * | `bindings` | {@linkcode PluginSpreadsheetBinding}`[]` | Every stored binding |
2069
+ */
2070
+ export const PluginProgramSpreadsheetBindingsListResult = z.object({
2071
+ bindings: z.array(PluginSpreadsheetBinding),
2072
+ })
2073
+ export type PluginProgramSpreadsheetBindingsListResult = z.infer<
2074
+ typeof PluginProgramSpreadsheetBindingsListResult
2075
+ >