@snaptrude/plugin-core 0.3.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/AGENTS.md +130 -48
  2. package/CHANGELOG.md +163 -0
  3. package/api-manifest.full.json +5600 -0
  4. package/api-manifest.json +5502 -0
  5. package/dist/api/analysis/heatmaps.d.ts +234 -0
  6. package/dist/api/analysis/heatmaps.d.ts.map +1 -0
  7. package/dist/api/analysis/illuminance.d.ts +145 -0
  8. package/dist/api/analysis/illuminance.d.ts.map +1 -0
  9. package/dist/api/analysis/index.d.ts +44 -0
  10. package/dist/api/analysis/index.d.ts.map +1 -0
  11. package/dist/api/analysis/shadows.d.ts +165 -0
  12. package/dist/api/analysis/shadows.d.ts.map +1 -0
  13. package/dist/api/analysis/sunlightHours.d.ts +208 -0
  14. package/dist/api/analysis/sunlightHours.d.ts.map +1 -0
  15. package/dist/api/analysis/sunpath.d.ts +80 -0
  16. package/dist/api/analysis/sunpath.d.ts.map +1 -0
  17. package/dist/api/core/buildings.d.ts +427 -0
  18. package/dist/api/core/buildings.d.ts.map +1 -0
  19. package/dist/api/core/comment/index.d.ts +230 -0
  20. package/dist/api/core/comment/index.d.ts.map +1 -0
  21. package/dist/api/core/geom/create/index.d.ts +247 -0
  22. package/dist/api/core/geom/create/index.d.ts.map +1 -0
  23. package/dist/api/core/geom/delete/index.d.ts +72 -0
  24. package/dist/api/core/geom/delete/index.d.ts.map +1 -0
  25. package/dist/api/core/geom/index.d.ts +24 -23
  26. package/dist/api/core/geom/index.d.ts.map +1 -1
  27. package/dist/api/core/geom/query/arc.d.ts +169 -0
  28. package/dist/api/core/geom/query/arc.d.ts.map +1 -0
  29. package/dist/api/core/geom/query/brep.d.ts +402 -0
  30. package/dist/api/core/geom/query/brep.d.ts.map +1 -0
  31. package/dist/api/core/geom/query/circle.d.ts +378 -0
  32. package/dist/api/core/geom/query/circle.d.ts.map +1 -0
  33. package/dist/api/core/geom/query/contour.d.ts +450 -0
  34. package/dist/api/core/geom/query/contour.d.ts.map +1 -0
  35. package/dist/api/core/geom/query/curve.d.ts +918 -0
  36. package/dist/api/core/geom/query/curve.d.ts.map +1 -0
  37. package/dist/api/core/geom/query/edge.d.ts +128 -0
  38. package/dist/api/core/geom/query/edge.d.ts.map +1 -0
  39. package/dist/api/core/geom/query/face.d.ts +363 -0
  40. package/dist/api/core/geom/query/face.d.ts.map +1 -0
  41. package/dist/api/core/geom/query/halfedge.d.ts +206 -0
  42. package/dist/api/core/geom/query/halfedge.d.ts.map +1 -0
  43. package/dist/api/core/geom/query/index.d.ts +61 -0
  44. package/dist/api/core/geom/query/index.d.ts.map +1 -0
  45. package/dist/api/core/geom/query/profile.d.ts +410 -0
  46. package/dist/api/core/geom/query/profile.d.ts.map +1 -0
  47. package/dist/api/core/geom/query/vertex.d.ts +187 -0
  48. package/dist/api/core/geom/query/vertex.d.ts.map +1 -0
  49. package/dist/api/core/geom/update/contour.d.ts +272 -0
  50. package/dist/api/core/geom/update/contour.d.ts.map +1 -0
  51. package/dist/api/core/geom/update/curve.d.ts +180 -0
  52. package/dist/api/core/geom/update/curve.d.ts.map +1 -0
  53. package/dist/api/core/geom/update/index.d.ts +27 -0
  54. package/dist/api/core/geom/update/index.d.ts.map +1 -0
  55. package/dist/api/core/geom/update/profile.d.ts +329 -0
  56. package/dist/api/core/geom/update/profile.d.ts.map +1 -0
  57. package/dist/api/core/groups.d.ts +485 -0
  58. package/dist/api/core/groups.d.ts.map +1 -0
  59. package/dist/api/core/history/index.d.ts +78 -0
  60. package/dist/api/core/history/index.d.ts.map +1 -0
  61. package/dist/api/core/index.d.ts +51 -1
  62. package/dist/api/core/index.d.ts.map +1 -1
  63. package/dist/api/core/io/import/index.d.ts +392 -0
  64. package/dist/api/core/io/import/index.d.ts.map +1 -0
  65. package/dist/api/core/io/index.d.ts +35 -0
  66. package/dist/api/core/io/index.d.ts.map +1 -0
  67. package/dist/api/core/io/job/index.d.ts +139 -0
  68. package/dist/api/core/io/job/index.d.ts.map +1 -0
  69. package/dist/api/core/io/query/index.d.ts +74 -0
  70. package/dist/api/core/io/query/index.d.ts.map +1 -0
  71. package/dist/api/core/io/terrain/index.d.ts +206 -0
  72. package/dist/api/core/io/terrain/index.d.ts.map +1 -0
  73. package/dist/api/core/io/underlay/index.d.ts +286 -0
  74. package/dist/api/core/io/underlay/index.d.ts.map +1 -0
  75. package/dist/api/core/layers.d.ts +402 -0
  76. package/dist/api/core/layers.d.ts.map +1 -0
  77. package/dist/api/core/math/quat.d.ts +111 -128
  78. package/dist/api/core/math/quat.d.ts.map +1 -1
  79. package/dist/api/core/math/vec3.d.ts +120 -102
  80. package/dist/api/core/math/vec3.d.ts.map +1 -1
  81. package/dist/api/core/project/index.d.ts +399 -0
  82. package/dist/api/core/project/index.d.ts.map +1 -0
  83. package/dist/api/core/tags.d.ts +755 -0
  84. package/dist/api/core/tags.d.ts.map +1 -0
  85. package/dist/api/core/units/index.d.ts +175 -0
  86. package/dist/api/core/units/index.d.ts.map +1 -0
  87. package/dist/api/core/zoom/index.d.ts +45 -0
  88. package/dist/api/core/zoom/index.d.ts.map +1 -0
  89. package/dist/api/design/boolean/index.d.ts +168 -0
  90. package/dist/api/design/boolean/index.d.ts.map +1 -0
  91. package/dist/api/design/create/index.d.ts +837 -0
  92. package/dist/api/design/create/index.d.ts.map +1 -0
  93. package/dist/api/design/delete/index.d.ts +63 -0
  94. package/dist/api/design/delete/index.d.ts.map +1 -0
  95. package/dist/api/design/doors/index.d.ts +268 -0
  96. package/dist/api/design/doors/index.d.ts.map +1 -0
  97. package/dist/api/design/edit/index.d.ts +49 -0
  98. package/dist/api/design/edit/index.d.ts.map +1 -0
  99. package/dist/api/design/erase/index.d.ts +160 -0
  100. package/dist/api/design/erase/index.d.ts.map +1 -0
  101. package/dist/api/design/furniture/index.d.ts +123 -0
  102. package/dist/api/design/furniture/index.d.ts.map +1 -0
  103. package/dist/api/design/index.d.ts +153 -0
  104. package/dist/api/design/index.d.ts.map +1 -0
  105. package/dist/api/design/lock.d.ts +41 -0
  106. package/dist/api/design/lock.d.ts.map +1 -0
  107. package/dist/api/design/materials/index.d.ts +297 -0
  108. package/dist/api/design/materials/index.d.ts.map +1 -0
  109. package/dist/api/design/query/geometry/index.d.ts +140 -0
  110. package/dist/api/design/query/geometry/index.d.ts.map +1 -0
  111. package/dist/api/design/query/index.d.ts +1011 -0
  112. package/dist/api/design/query/index.d.ts.map +1 -0
  113. package/dist/api/design/query/spaces.d.ts +221 -0
  114. package/dist/api/design/query/spaces.d.ts.map +1 -0
  115. package/dist/api/design/selection/index.d.ts +282 -0
  116. package/dist/api/design/selection/index.d.ts.map +1 -0
  117. package/dist/api/design/shared.d.ts +38 -0
  118. package/dist/api/design/shared.d.ts.map +1 -0
  119. package/dist/api/design/transform/index.d.ts +87 -0
  120. package/dist/api/design/transform/index.d.ts.map +1 -0
  121. package/dist/api/design/update/index.d.ts +178 -0
  122. package/dist/api/design/update/index.d.ts.map +1 -0
  123. package/dist/api/design/windows/index.d.ts +189 -0
  124. package/dist/api/design/windows/index.d.ts.map +1 -0
  125. package/dist/api/entity/buildableEnvelope.d.ts +261 -0
  126. package/dist/api/entity/buildableEnvelope.d.ts.map +1 -0
  127. package/dist/api/entity/department.d.ts +0 -98
  128. package/dist/api/entity/department.d.ts.map +1 -1
  129. package/dist/api/entity/index.d.ts +9 -9
  130. package/dist/api/entity/index.d.ts.map +1 -1
  131. package/dist/api/entity/referenceLine.d.ts +49 -106
  132. package/dist/api/entity/referenceLine.d.ts.map +1 -1
  133. package/dist/api/entity/space.d.ts +484 -251
  134. package/dist/api/entity/space.d.ts.map +1 -1
  135. package/dist/api/entity/story.d.ts +49 -39
  136. package/dist/api/entity/story.d.ts.map +1 -1
  137. package/dist/api/index.d.ts +22 -12
  138. package/dist/api/index.d.ts.map +1 -1
  139. package/dist/api/presentation/aiInspiration.d.ts +440 -0
  140. package/dist/api/presentation/aiInspiration.d.ts.map +1 -0
  141. package/dist/api/presentation/diagrams.d.ts +81 -0
  142. package/dist/api/presentation/diagrams.d.ts.map +1 -0
  143. package/dist/api/presentation/import.d.ts +113 -0
  144. package/dist/api/presentation/import.d.ts.map +1 -0
  145. package/dist/api/presentation/index.d.ts +46 -0
  146. package/dist/api/presentation/index.d.ts.map +1 -0
  147. package/dist/api/presentation/sheets.d.ts +176 -0
  148. package/dist/api/presentation/sheets.d.ts.map +1 -0
  149. package/dist/api/presentation/views.d.ts +296 -0
  150. package/dist/api/presentation/views.d.ts.map +1 -0
  151. package/dist/api/program/adjacency.d.ts +155 -0
  152. package/dist/api/program/adjacency.d.ts.map +1 -0
  153. package/dist/api/program/areas.d.ts +360 -0
  154. package/dist/api/program/areas.d.ts.map +1 -0
  155. package/dist/api/program/classification.d.ts +135 -0
  156. package/dist/api/program/classification.d.ts.map +1 -0
  157. package/dist/api/program/cores.d.ts +174 -0
  158. package/dist/api/program/cores.d.ts.map +1 -0
  159. package/dist/api/program/departments.d.ts +431 -0
  160. package/dist/api/program/departments.d.ts.map +1 -0
  161. package/dist/api/program/index.d.ts +69 -0
  162. package/dist/api/program/index.d.ts.map +1 -0
  163. package/dist/api/program/layout.d.ts +63 -0
  164. package/dist/api/program/layout.d.ts.map +1 -0
  165. package/dist/api/program/metrics.d.ts +108 -0
  166. package/dist/api/program/metrics.d.ts.map +1 -0
  167. package/dist/api/program/site.d.ts +451 -0
  168. package/dist/api/program/site.d.ts.map +1 -0
  169. package/dist/api/program/spreadsheet.d.ts +2041 -0
  170. package/dist/api/program/spreadsheet.d.ts.map +1 -0
  171. package/dist/handles.d.ts +171 -0
  172. package/dist/handles.d.ts.map +1 -0
  173. package/dist/host-utils.d.ts +7 -5
  174. package/dist/host-utils.d.ts.map +1 -1
  175. package/dist/index.cjs +4344 -899
  176. package/dist/index.cjs.map +1 -1
  177. package/dist/index.d.ts +1 -0
  178. package/dist/index.d.ts.map +1 -1
  179. package/dist/index.js +3682 -865
  180. package/dist/index.js.map +1 -1
  181. package/package.json +6 -2
  182. package/scripts/generate-manifest.mjs +193 -0
  183. package/scripts/generate-manifest.test.mjs +215 -0
  184. package/src/api/analysis/heatmaps.ts +256 -0
  185. package/src/api/analysis/illuminance.ts +155 -0
  186. package/src/api/analysis/index.ts +46 -0
  187. package/src/api/analysis/shadows.ts +183 -0
  188. package/src/api/analysis/sunlightHours.ts +211 -0
  189. package/src/api/analysis/sunpath.ts +83 -0
  190. package/src/api/core/buildings.ts +485 -0
  191. package/src/api/core/comment/index.ts +258 -0
  192. package/src/api/core/geom/create/index.ts +293 -0
  193. package/src/api/core/geom/delete/index.ts +78 -0
  194. package/src/api/core/geom/index.ts +24 -23
  195. package/src/api/core/geom/query/arc.ts +169 -0
  196. package/src/api/core/geom/query/brep.ts +444 -0
  197. package/src/api/core/geom/query/circle.ts +404 -0
  198. package/src/api/core/geom/query/contour.ts +540 -0
  199. package/src/api/core/geom/query/curve.ts +1078 -0
  200. package/src/api/core/geom/query/edge.ts +130 -0
  201. package/src/api/core/geom/query/face.ts +403 -0
  202. package/src/api/core/geom/query/halfedge.ts +210 -0
  203. package/src/api/core/geom/query/index.ts +63 -0
  204. package/src/api/core/geom/query/profile.ts +473 -0
  205. package/src/api/core/geom/query/vertex.ts +205 -0
  206. package/src/api/core/geom/update/contour.ts +315 -0
  207. package/src/api/core/geom/update/curve.ts +209 -0
  208. package/src/api/core/geom/update/index.ts +29 -0
  209. package/src/api/core/geom/update/profile.ts +377 -0
  210. package/src/api/core/groups.ts +521 -0
  211. package/src/api/core/history/index.ts +84 -0
  212. package/src/api/core/index.ts +51 -1
  213. package/src/api/core/io/import/index.ts +432 -0
  214. package/src/api/core/io/index.ts +37 -0
  215. package/src/api/core/io/job/index.ts +140 -0
  216. package/src/api/core/io/query/index.ts +71 -0
  217. package/src/api/core/io/terrain/index.ts +214 -0
  218. package/src/api/core/io/underlay/index.ts +295 -0
  219. package/src/api/core/layers.ts +333 -0
  220. package/src/api/core/math/quat.ts +112 -235
  221. package/src/api/core/math/vec3.ts +124 -159
  222. package/src/api/core/project/index.ts +418 -0
  223. package/src/api/core/tags.ts +808 -0
  224. package/src/api/core/units/index.ts +164 -0
  225. package/src/api/core/zoom/index.ts +47 -0
  226. package/src/api/design/boolean/index.ts +179 -0
  227. package/src/api/design/create/index.ts +895 -0
  228. package/src/api/design/delete/index.ts +67 -0
  229. package/src/api/design/doors/index.ts +285 -0
  230. package/src/api/design/edit/index.ts +54 -0
  231. package/src/api/design/erase/index.ts +151 -0
  232. package/src/api/design/furniture/index.ts +130 -0
  233. package/src/api/design/index.ts +162 -0
  234. package/src/api/design/lock.ts +42 -0
  235. package/src/api/design/materials/index.ts +301 -0
  236. package/src/api/design/query/geometry/index.ts +166 -0
  237. package/src/api/design/query/index.ts +937 -0
  238. package/src/api/design/query/spaces.ts +132 -0
  239. package/src/api/design/selection/index.ts +273 -0
  240. package/src/api/design/shared.ts +40 -0
  241. package/src/api/design/transform/index.ts +93 -0
  242. package/src/api/design/update/index.ts +117 -0
  243. package/src/api/design/windows/index.ts +207 -0
  244. package/src/api/entity/buildableEnvelope.ts +318 -0
  245. package/src/api/entity/department.ts +0 -113
  246. package/src/api/entity/index.ts +9 -9
  247. package/src/api/entity/referenceLine.ts +50 -38
  248. package/src/api/entity/space.ts +285 -226
  249. package/src/api/entity/story.ts +53 -42
  250. package/src/api/index.ts +22 -12
  251. package/src/api/presentation/aiInspiration.ts +362 -0
  252. package/src/api/presentation/diagrams.ts +84 -0
  253. package/src/api/presentation/import.ts +112 -0
  254. package/src/api/presentation/index.ts +48 -0
  255. package/src/api/presentation/sheets.ts +198 -0
  256. package/src/api/presentation/views.ts +303 -0
  257. package/src/api/program/adjacency.ts +164 -0
  258. package/src/api/program/areas.ts +335 -0
  259. package/src/api/program/classification.ts +138 -0
  260. package/src/api/program/cores.ts +171 -0
  261. package/src/api/program/departments.ts +465 -0
  262. package/src/api/program/index.ts +71 -0
  263. package/src/api/program/layout.ts +68 -0
  264. package/src/api/program/metrics.ts +120 -0
  265. package/src/api/program/site.ts +419 -0
  266. package/src/api/program/spreadsheet.ts +2075 -0
  267. package/src/handles.ts +194 -0
  268. package/src/host-utils.ts +10 -6
  269. package/src/index.ts +1 -0
  270. package/dist/api/core/geom/arc.d.ts +0 -81
  271. package/dist/api/core/geom/arc.d.ts.map +0 -1
  272. package/dist/api/core/geom/curve.d.ts +0 -70
  273. package/dist/api/core/geom/curve.d.ts.map +0 -1
  274. package/dist/api/core/geom/line.d.ts +0 -56
  275. package/dist/api/core/geom/line.d.ts.map +0 -1
  276. package/dist/api/core/geom/profile.d.ts +0 -121
  277. package/dist/api/core/geom/profile.d.ts.map +0 -1
  278. package/dist/api/tools/copy.d.ts +0 -59
  279. package/dist/api/tools/copy.d.ts.map +0 -1
  280. package/dist/api/tools/index.d.ts +0 -33
  281. package/dist/api/tools/index.d.ts.map +0 -1
  282. package/dist/api/tools/material.d.ts +0 -51
  283. package/dist/api/tools/material.d.ts.map +0 -1
  284. package/dist/api/tools/offset.d.ts +0 -43
  285. package/dist/api/tools/offset.d.ts.map +0 -1
  286. package/dist/api/tools/selection.d.ts +0 -48
  287. package/dist/api/tools/selection.d.ts.map +0 -1
  288. package/dist/api/tools/transform.d.ts +0 -114
  289. package/dist/api/tools/transform.d.ts.map +0 -1
  290. package/dist/api/units/index.d.ts +0 -163
  291. package/dist/api/units/index.d.ts.map +0 -1
  292. package/src/api/core/geom/arc.ts +0 -70
  293. package/src/api/core/geom/curve.ts +0 -41
  294. package/src/api/core/geom/line.ts +0 -53
  295. package/src/api/core/geom/profile.ts +0 -94
  296. package/src/api/tools/copy.ts +0 -55
  297. package/src/api/tools/index.ts +0 -39
  298. package/src/api/tools/material.ts +0 -49
  299. package/src/api/tools/offset.ts +0 -43
  300. package/src/api/tools/selection.ts +0 -51
  301. package/src/api/tools/transform.ts +0 -117
  302. package/src/api/units/index.ts +0 -163
@@ -0,0 +1,432 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../../../types"
3
+ import {
4
+ Vec3Handle,
5
+ UnderlayHandle,
6
+ TerrainHandle,
7
+ ImportJobHandle,
8
+ ComponentHandle,
9
+ } from "../../../../handles"
10
+
11
+ /**
12
+ * A file `source` accepted by every importer: an `https://` URL or a `data:`
13
+ * URL (base64). Validated for shape at the boundary — other schemes (`http:`,
14
+ * `blob:`, `file:`) are rejected, since the host page (HTTPS) cannot fetch them.
15
+ */
16
+ export const ImportSource = z
17
+ .string()
18
+ .min(1)
19
+ .refine((s) => s.startsWith("https://") || s.startsWith("data:"), {
20
+ message: "source must be an https:// URL or a data: URL",
21
+ })
22
+
23
+ /**
24
+ * File import — bring external files into the Snaptrude **scene**.
25
+ *
26
+ * `core.io.import.*` ingests images, PDFs, CAD drawings, 3D models, and site
27
+ * terrain and commits them to the model as traceable underlays, placed geometry,
28
+ * or topography. It is the scene counterpart to `presentation.import.*` (which
29
+ * drops assets on the Present canvas, not the model).
30
+ *
31
+ * ## The `source` argument
32
+ * Every file importer takes a single `source` **string** — either an `https://`
33
+ * URL or a `data:` URL (base64). A plugin worker cannot hand a browser `File`
34
+ * across the boundary, so the host fetches `source` and rebuilds the `File`
35
+ * itself. Both forms go through the same path.
36
+ *
37
+ * ## Return values
38
+ * - `image` / `pdf` / `cadJson` → an {@linkcode UnderlayHandle} (a placed 2D
39
+ * reference plane; drive it with `core.io.underlay.*`).
40
+ * - `dwg` → an {@linkcode ImportJobHandle} — DWG conversion is a long server job,
41
+ * so `dwg` returns immediately and you poll it with `core.io.job.*`.
42
+ * - `model` → a {@linkcode ComponentHandle} (a placed 3D component).
43
+ * - `terrain` → a {@linkcode TerrainHandle} (the project's single site terrain).
44
+ *
45
+ * Every importer **throws** on failure (bad source, unsupported format, engine
46
+ * error). Accessed via `snaptrude.core.io.import`.
47
+ */
48
+ export abstract class PluginCoreIoImportApi {
49
+ constructor() {}
50
+
51
+ /**
52
+ * Import a raster image as a scene **underlay** — a flat, textured reference
53
+ * plane placed on a storey that you can trace over.
54
+ *
55
+ * Supported formats: PNG, JPG/JPEG, BMP. The image is placed on the target
56
+ * storey's "Image" layer at ~50% opacity by default.
57
+ *
58
+ * The plane is placed at the storey origin (the engine's import placement);
59
+ * there is no placement parameter — calibrate size with
60
+ * {@link PluginCoreIoUnderlayApi.setScale} after import.
61
+ *
62
+ * @param source - The image to import: an `https://` URL or a `data:` URL.
63
+ * @param storey - Target storey number. Defaults to the active storey.
64
+ * @param scale - Initial uniform scale factor applied to the plane. Calibrate
65
+ * precisely afterwards with {@link PluginCoreIoUnderlayApi.setScale}.
66
+ * @param opacity - Plane opacity, `0`..`1` (default ~`0.5`).
67
+ * @param label - A name for the created underlay.
68
+ * @returns the created {@linkcode UnderlayHandle}.
69
+ * @throws if writes are disabled, the source can't be loaded, the format is
70
+ * unsupported, or the engine fails to place the plane.
71
+ *
72
+ * @examplePrompt Import this floor plan image onto the ground floor to trace over
73
+ * @examplePrompt Drop this survey PNG in as a reference underlay at 30% opacity
74
+ * @examplePrompt Add a site plan image on storey 2
75
+ * @examplePrompt Bring in a sketch to trace, faded to half opacity
76
+ *
77
+ * # Example
78
+ * ```ts
79
+ * // Place a floor plan on storey 1, then calibrate it to a real-world size.
80
+ * const plan = await snaptrude.core.io.import.image(
81
+ * "https://example.com/floorplan.png",
82
+ * 1, // storey
83
+ * undefined, // scale
84
+ * 0.4, // opacity
85
+ * "Ground floor plan",
86
+ * )
87
+ * // Make the plan's longest side exactly 40 project-units:
88
+ * await snaptrude.core.io.underlay.setScale(plan, { planSize: 40 })
89
+ * ```
90
+ */
91
+ public abstract image(
92
+ source: string,
93
+ storey?: number,
94
+ scale?: number,
95
+ opacity?: number,
96
+ label?: string,
97
+ ): PluginApiReturn<UnderlayHandle>
98
+
99
+ /**
100
+ * Import one page of a PDF as a scene **underlay** (a traceable reference plane).
101
+ *
102
+ * One PDF per storey, one page per call. To bring in several pages, call once
103
+ * per page onto different storeys.
104
+ *
105
+ * @param source - The PDF to import: an `https://` URL or a `data:` URL.
106
+ * @param storey - Target storey number. Defaults to the active storey.
107
+ * @param page - 1-based page number to import (multi-page PDFs). Default `1`.
108
+ * @param scale - A drawing-scale **label** that sizes the page in real-world
109
+ * units, matching the project's unit mode: metric `"1:10"`..`"1:1000"` (e.g.
110
+ * `"1:100"`) or imperial `` `1/8" = 1'` `` / `` `1" = 10'` ``. Must be a valid
111
+ * label for the current unit mode (invalid → throws). Defaults to `"1:100"`
112
+ * in metric projects and `` `1" = 1'` `` in imperial projects. Re-calibrate
113
+ * afterwards with {@link PluginCoreIoUnderlayApi.setScale}.
114
+ * @param opacity - Plane opacity, `0`..`1` (default ~`0.5`).
115
+ * @returns the created {@linkcode UnderlayHandle}.
116
+ * @throws if writes are disabled, the source can't be loaded, the storey
117
+ * already has a PDF, the page is out of range, the scale label is invalid for
118
+ * the unit mode, or the engine fails.
119
+ *
120
+ * @examplePrompt Import page 1 of this PDF floor plan onto storey 1
121
+ * @examplePrompt Bring in the second page of this PDF as an underlay at 1:50
122
+ * @examplePrompt Add this PDF plan to the ground floor to trace over
123
+ * @examplePrompt Place page 3 of the drawing set on storey 3
124
+ *
125
+ * # Example
126
+ * ```ts
127
+ * const sheet = await snaptrude.core.io.import.pdf(
128
+ * "https://example.com/plans.pdf",
129
+ * 1, // storey
130
+ * 2, // page
131
+ * "1:100", // drawing scale
132
+ * )
133
+ * ```
134
+ */
135
+ public abstract pdf(
136
+ source: string,
137
+ storey?: number,
138
+ page?: number,
139
+ scale?: string,
140
+ opacity?: number,
141
+ ): PluginApiReturn<UnderlayHandle>
142
+
143
+ /**
144
+ * Import a **DWG** CAD drawing as a scene underlay. `.dwg` only (no DXF).
145
+ *
146
+ * DWG conversion runs on a server and can take minutes, so this **starts a job
147
+ * and returns immediately** with an {@linkcode ImportJobHandle}. One CAD
148
+ * import runs at a time: starting a second while one is in flight throws —
149
+ * poll the first job to completion first. Poll it with
150
+ * {@link PluginCoreIoJobApi.isComplete} / {@link PluginCoreIoJobApi.getStatus}, then call
151
+ * {@link PluginCoreIoJobApi.getResult} to get the placed {@linkcode UnderlayHandle}.
152
+ * For CAD you already have parsed as JSON, use {@link PluginCoreIoImportApi.cadJson}
153
+ * (synchronous, no server round-trip).
154
+ *
155
+ * All CAD layers are imported (there is no layer filter).
156
+ *
157
+ * @param source - The `.dwg` file: an `https://` URL or a `data:` URL.
158
+ * @param storey - Target storey number. Defaults to the active storey.
159
+ * @returns an {@linkcode ImportJobHandle} to poll via `core.io.job.*`.
160
+ * @throws if writes are disabled or the upload cannot be started. (Conversion
161
+ * failures surface later via {@link PluginCoreIoJobApi.getError}.)
162
+ *
163
+ * @examplePrompt Import this DWG floor plan onto storey 1
164
+ * @examplePrompt Bring in a CAD drawing as an underlay and tell me when it's ready
165
+ * @examplePrompt Start importing this CAD file onto the ground floor
166
+ *
167
+ * # Example
168
+ * ```ts
169
+ * const job = await snaptrude.core.io.import.dwg("https://example.com/plan.dwg", 1)
170
+ * // Poll until the server-side conversion finishes — always with a timeout
171
+ * // (a UI-cancelled import stays "processing" forever).
172
+ * const deadline = Date.now() + 5 * 60_000
173
+ * while (!(await snaptrude.core.io.job.isComplete(job))) {
174
+ * if (Date.now() > deadline) throw new Error("DWG import timed out")
175
+ * await new Promise((r) => setTimeout(r, 2000))
176
+ * }
177
+ * // The DWG lands as a CAD underlay. CAD scaling isn't supported; manage it
178
+ * // (list / fade / delete) via core.io.underlay.*.
179
+ * const cad = await snaptrude.core.io.job.getResult(job)
180
+ * if (cad) console.log("DWG imported as CAD underlay:", cad)
181
+ * ```
182
+ */
183
+ public abstract dwg(source: string, storey?: number): PluginApiReturn<ImportJobHandle>
184
+
185
+ /**
186
+ * Sketch a CAD underlay from **already-parsed CAD JSON** — synchronous, with no
187
+ * server round-trip. Use this when you hold parsed CAD data (e.g. produced by
188
+ * your own converter); use {@link PluginCoreIoImportApi.dwg} for raw `.dwg`
189
+ * files.
190
+ *
191
+ * All layers in the JSON are sketched (there is no layer filter), at the
192
+ * drawing's own coordinates.
193
+ *
194
+ * @param cad - The parsed CAD data: `{ unit, geometry: [...] }` describing the
195
+ * drawing's lines/arcs/layers.
196
+ * @param storey - Target storey number. Defaults to the active storey.
197
+ * @returns the created {@linkcode UnderlayHandle}.
198
+ * @throws if writes are disabled, the JSON yields no drawable geometry, or the
199
+ * drawing is out of bounds.
200
+ *
201
+ * @examplePrompt Sketch this parsed CAD JSON onto the active storey
202
+ * @examplePrompt Draw these CAD curves as an underlay on storey 2
203
+ * @examplePrompt Create a CAD sketch from this geometry data
204
+ * @examplePrompt Import my converted CAD JSON onto the ground floor
205
+ *
206
+ * # Example
207
+ * ```ts
208
+ * const cad = await snaptrude.core.io.import.cadJson(
209
+ * { unit: "mm", geometry: [{ type: "line", layer: "WALLS", ... }] },
210
+ * 1,
211
+ * )
212
+ * ```
213
+ */
214
+ public abstract cadJson(cad: CadJsonInput, storey?: number): PluginApiReturn<UnderlayHandle>
215
+
216
+ /**
217
+ * Import a **3D model** file and place it in the scene as a component.
218
+ *
219
+ * Supported formats: SketchUp (`.skp`), FBX (`.fbx`), OBJ (`.obj`), 3DS
220
+ * (`.3ds`), and zipped bundles (`.zip`). The file is converted on the server,
221
+ * then placed. `.glb`/`.gltf`/`.ifc`/`.stl` and Rhino/Revit are not supported.
222
+ *
223
+ * The model is placed at its source dimensions (interpreted in the file's own
224
+ * units); there is no import-time scale override.
225
+ *
226
+ * Unlike `dwg`, this call **waits for the server conversion**: a large model
227
+ * may exceed the 60-second call cap and reject at the API boundary while the
228
+ * import still completes in the background (the model then appears without a
229
+ * handle being returned — re-query the scene to find it). Keep sources small.
230
+ *
231
+ * @param source - The model file: an `https://` URL or a `data:` URL.
232
+ * @param storey - Target storey number. Defaults to the active storey.
233
+ * @param format - The file's format. Inferred from `source` when omitted.
234
+ * @param position - Where to place the model. Defaults to the storey origin.
235
+ * @param label - A name for the placed component.
236
+ * @returns the placed {@linkcode ComponentHandle}.
237
+ * @throws if writes are disabled, the source can't be loaded, the format is
238
+ * unsupported, conversion/placement fails, or the converted model cannot be
239
+ * found in the library after upload.
240
+ *
241
+ * @examplePrompt Import this SketchUp model onto storey 1
242
+ * @examplePrompt Bring in this OBJ file and place it at the origin
243
+ * @examplePrompt Add this 3D model to the ground floor
244
+ *
245
+ * # Example
246
+ * ```ts
247
+ * const model = await snaptrude.core.io.import.model(
248
+ * "https://example.com/tree.skp",
249
+ * 1, // storey
250
+ * "skp",
251
+ * )
252
+ * ```
253
+ */
254
+ public abstract model(
255
+ source: string,
256
+ storey?: number,
257
+ format?: ModelFormat,
258
+ position?: Vec3Handle,
259
+ label?: string,
260
+ ): PluginApiReturn<ComponentHandle>
261
+
262
+ /**
263
+ * Import **site terrain** for a location — Mapbox topography (elevation +
264
+ * satellite/streets imagery, optional neighborhood buildings and parcels).
265
+ *
266
+ * One terrain per project (a singleton). `width`/`length` describe the
267
+ * real-world extent of the area to load **in metres** (regardless of the
268
+ * project's unit mode); the host converts them to the right map zoom
269
+ * internally — you do not pass a zoom level.
270
+ *
271
+ * @param lat - Site latitude (degrees), `-90`..`90`.
272
+ * @param lng - Site longitude (degrees), `-180`..`180`.
273
+ * @param width - East–west extent of the area to load, in metres.
274
+ * @param length - North–south extent of the area to load, in metres.
275
+ * @param elevation - Include DEM elevation (a real terrain surface). Default `true`.
276
+ * @param satellite - Drape satellite imagery. Default `true`.
277
+ * @param neighborhood - Include surrounding context buildings. Default `false`.
278
+ * @param parcels - Include site parcel boundaries. Default `false`.
279
+ * @returns the created {@linkcode TerrainHandle}.
280
+ * @throws if writes are disabled, a terrain already exists, or the map/mesh
281
+ * generation fails.
282
+ *
283
+ * @examplePrompt Import the site terrain for this location, about 500m across
284
+ * @examplePrompt Load the topography at 40.7128, -74.0060 for a 300 by 300 meter site
285
+ * @examplePrompt Bring in satellite terrain for the site with the surrounding buildings
286
+ * @examplePrompt Add site elevation for a 1km by 1km area at these coordinates
287
+ *
288
+ * # Example
289
+ * ```ts
290
+ * // 300m × 300m site with elevation + satellite imagery.
291
+ * const terrain = await snaptrude.core.io.import.terrain(
292
+ * 40.7128, // lat
293
+ * -74.006, // lng
294
+ * 300, // width (metres)
295
+ * 300, // length (metres)
296
+ * true, // elevation
297
+ * true, // satellite
298
+ * )
299
+ * ```
300
+ */
301
+ public abstract terrain(
302
+ lat: number,
303
+ lng: number,
304
+ width: number,
305
+ length: number,
306
+ elevation?: boolean,
307
+ satellite?: boolean,
308
+ neighborhood?: boolean,
309
+ parcels?: boolean,
310
+ ): PluginApiReturn<TerrainHandle>
311
+ }
312
+
313
+ /**
314
+ * Supported 3D model import formats. `.glb`/`.gltf`/`.ifc`/`.stl` and Rhino/Revit
315
+ * are intentionally excluded (no in-app import path).
316
+ */
317
+ export const ModelFormat = z.enum(["skp", "fbx", "obj", "3ds", "zip"])
318
+ export type ModelFormat = z.infer<typeof ModelFormat>
319
+
320
+ /**
321
+ * Parsed CAD JSON accepted by {@link PluginCoreIoImportApi.cadJson}. `unit` sets
322
+ * the drawing's length unit; `geometry` is the array of CAD entities (lines,
323
+ * polylines, arcs, circles), each tagged with its CAD `layer`. Additional fields
324
+ * are passed through untouched.
325
+ */
326
+ export const CadJsonInput = z
327
+ .object({
328
+ unit: z.string().optional(),
329
+ geometry: z.array(z.record(z.string(), z.unknown())).optional(),
330
+ })
331
+ .passthrough()
332
+ export type CadJsonInput = z.infer<typeof CadJsonInput>
333
+
334
+ /**
335
+ * Arguments for {@link PluginCoreIoImportApi.image}.
336
+ *
337
+ * | Property | Type | Description |
338
+ * |---|---|---|
339
+ * | `source` | `string` | Image `https://` URL or `data:` URL (png/jpg/jpeg/bmp) |
340
+ * | `storey` | `number`? | Target storey (default: active) |
341
+ * | `scale` | `number`? | Initial uniform scale |
342
+ * | `opacity` | `number`? | `0`..`1` (default ~`0.5`) |
343
+ * | `label` | `string`? | Name for the underlay |
344
+ */
345
+ export const PluginImportImageArgs = z.object({
346
+ source: ImportSource,
347
+ storey: z.number().int().optional(),
348
+ scale: z.number().positive().optional(),
349
+ opacity: z.number().min(0).max(1).optional(),
350
+ label: z.string().optional(),
351
+ })
352
+ export type PluginImportImageArgs = z.infer<typeof PluginImportImageArgs>
353
+
354
+ /**
355
+ * Arguments for {@link PluginCoreIoImportApi.pdf}.
356
+ *
357
+ * | Property | Type | Description |
358
+ * |---|---|---|
359
+ * | `source` | `string` | PDF `https://` URL or `data:` URL |
360
+ * | `storey` | `number`? | Target storey (default: active) |
361
+ * | `page` | `number`? | 1-based page (default `1`) |
362
+ * | `scale` | `string`? | Drawing-scale label, e.g. `"1:100"` |
363
+ * | `opacity` | `number`? | `0`..`1` (default ~`0.5`) |
364
+ */
365
+ export const PluginImportPdfArgs = z.object({
366
+ source: ImportSource,
367
+ storey: z.number().int().optional(),
368
+ page: z.number().int().positive().optional(),
369
+ scale: z.string().optional(),
370
+ opacity: z.number().min(0).max(1).optional(),
371
+ })
372
+ export type PluginImportPdfArgs = z.infer<typeof PluginImportPdfArgs>
373
+
374
+ /** Arguments for {@link PluginCoreIoImportApi.dwg}. */
375
+ export const PluginImportDwgArgs = z.object({
376
+ source: ImportSource,
377
+ storey: z.number().int().optional(),
378
+ })
379
+ export type PluginImportDwgArgs = z.infer<typeof PluginImportDwgArgs>
380
+
381
+ /** Arguments for {@link PluginCoreIoImportApi.cadJson}. */
382
+ export const PluginImportCadJsonArgs = z.object({
383
+ cad: CadJsonInput,
384
+ storey: z.number().int().optional(),
385
+ })
386
+ export type PluginImportCadJsonArgs = z.infer<typeof PluginImportCadJsonArgs>
387
+
388
+ /**
389
+ * Arguments for {@link PluginCoreIoImportApi.model}.
390
+ *
391
+ * | Property | Type | Description |
392
+ * |---|---|---|
393
+ * | `source` | `string` | Model `https://` URL or `data:` URL |
394
+ * | `storey` | `number`? | Target storey (default: active) |
395
+ * | `format` | {@link ModelFormat}? | File format (inferred when omitted) |
396
+ * | `position` | {@link Vec3Handle}? | Placement (default: storey origin) |
397
+ * | `label` | `string`? | Name for the component |
398
+ */
399
+ export const PluginImportModelArgs = z.object({
400
+ source: ImportSource,
401
+ storey: z.number().int().optional(),
402
+ format: ModelFormat.optional(),
403
+ position: Vec3Handle.optional(),
404
+ label: z.string().optional(),
405
+ })
406
+ export type PluginImportModelArgs = z.infer<typeof PluginImportModelArgs>
407
+
408
+ /**
409
+ * Arguments for {@link PluginCoreIoImportApi.terrain}.
410
+ *
411
+ * | Property | Type | Description |
412
+ * |---|---|---|
413
+ * | `lat` | `number` | Latitude (degrees), `-90`..`90` |
414
+ * | `lng` | `number` | Longitude (degrees), `-180`..`180` |
415
+ * | `width` | `number` | East–west extent, metres |
416
+ * | `length` | `number` | North–south extent, metres |
417
+ * | `elevation` | `boolean`? | Include DEM elevation (default `true`) |
418
+ * | `satellite` | `boolean`? | Drape satellite imagery (default `true`) |
419
+ * | `neighborhood` | `boolean`? | Include context buildings (default `false`) |
420
+ * | `parcels` | `boolean`? | Include parcel boundaries (default `false`) |
421
+ */
422
+ export const PluginImportTerrainArgs = z.object({
423
+ lat: z.number().min(-90).max(90),
424
+ lng: z.number().min(-180).max(180),
425
+ width: z.number().positive().finite(),
426
+ length: z.number().positive().finite(),
427
+ elevation: z.boolean().optional(),
428
+ satellite: z.boolean().optional(),
429
+ neighborhood: z.boolean().optional(),
430
+ parcels: z.boolean().optional(),
431
+ })
432
+ export type PluginImportTerrainArgs = z.infer<typeof PluginImportTerrainArgs>
@@ -0,0 +1,37 @@
1
+ import { PluginCoreIoImportApi } from "./import"
2
+ import { PluginCoreIoJobApi } from "./job"
3
+ import { PluginCoreIoUnderlayApi } from "./underlay"
4
+ import { PluginCoreIoTerrainApi } from "./terrain"
5
+ import { PluginCoreIoQueryApi } from "./query"
6
+
7
+ /**
8
+ * I/O — bring external files into the project and manage what was imported.
9
+ *
10
+ * - {@linkcode PluginCoreIoApi.import} — import images, PDFs, CAD, 3D models, terrain
11
+ * - {@linkcode PluginCoreIoApi.query} — read source metadata before importing (pdf pages, cad layers)
12
+ * - {@linkcode PluginCoreIoApi.job} — poll long-running async imports (e.g. DWG)
13
+ * - {@linkcode PluginCoreIoApi.underlay} — inspect/scale/opacity/delete placed underlays
14
+ * - {@linkcode PluginCoreIoApi.terrain} — inspect/edit the site terrain (datum, layers, delete)
15
+ *
16
+ * Accessed via `snaptrude.core.io`.
17
+ */
18
+ export abstract class PluginCoreIoApi {
19
+ /** Import external files into the scene. See {@linkcode PluginCoreIoImportApi}. */
20
+ public abstract import: PluginCoreIoImportApi
21
+ /** Read source metadata before import. See {@linkcode PluginCoreIoQueryApi}. */
22
+ public abstract query: PluginCoreIoQueryApi
23
+ /** Poll long-running import jobs. See {@linkcode PluginCoreIoJobApi}. */
24
+ public abstract job: PluginCoreIoJobApi
25
+ /** Inspect and edit placed underlays. See {@linkcode PluginCoreIoUnderlayApi}. */
26
+ public abstract underlay: PluginCoreIoUnderlayApi
27
+ /** Inspect and manage the site terrain. See {@linkcode PluginCoreIoTerrainApi}. */
28
+ public abstract terrain: PluginCoreIoTerrainApi
29
+
30
+ constructor() {}
31
+ }
32
+
33
+ export * from "./import"
34
+ export * from "./job"
35
+ export * from "./underlay"
36
+ export * from "./terrain"
37
+ export * from "./query"
@@ -0,0 +1,140 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../../../types"
3
+ import { ImportJobHandle, UnderlayHandle } from "../../../../handles"
4
+
5
+ /**
6
+ * Import jobs — poll a long-running asynchronous import.
7
+ *
8
+ * Some imports run on a server and take a while (today: `core.io.import.dwg`,
9
+ * whose DWG → Snaptrude conversion can take minutes). Those importers return an
10
+ * {@linkcode ImportJobHandle} immediately instead of blocking; you drive the job
11
+ * to completion here:
12
+ *
13
+ * 1. poll {@link PluginCoreIoJobApi.isComplete} (or read {@link PluginCoreIoJobApi.getStatus}),
14
+ * 2. once complete, call {@link PluginCoreIoJobApi.getResult} for the placed handle,
15
+ * 3. or read {@link PluginCoreIoJobApi.getError} if it failed.
16
+ *
17
+ * **Always poll with a timeout.** If the import is cancelled from the app UI
18
+ * (or the tab reloads mid-conversion), the job never reaches a terminal state
19
+ * and `getStatus` keeps returning `"processing"` — an unbounded poll loop would
20
+ * spin forever. Give up after a few minutes and surface that to the user.
21
+ *
22
+ * Accessed via `snaptrude.core.io.job`.
23
+ */
24
+ export abstract class PluginCoreIoJobApi {
25
+ constructor() {}
26
+
27
+ /**
28
+ * Read a job's current status: `"pending"` (queued), `"processing"` (running),
29
+ * `"complete"` (result ready), or `"failed"`.
30
+ *
31
+ * Limitation: a job cancelled from the app UI never turns `"failed"` — it
32
+ * stays `"processing"` indefinitely. Bound your poll loop with a timeout.
33
+ *
34
+ * @param job - The import job to inspect.
35
+ * @returns the {@linkcode ImportJobStatus}.
36
+ * @throws {@link HandleInvalidError} if the job handle is unknown.
37
+ *
38
+ * @examplePrompt What's the status of my DWG import?
39
+ * @examplePrompt Is the CAD import still processing?
40
+ * @examplePrompt Check where the import job is up to
41
+ * @examplePrompt Did the import job fail?
42
+ *
43
+ * # Example
44
+ * ```ts
45
+ * const job = await snaptrude.core.io.import.dwg(url, 1)
46
+ * console.log(await snaptrude.core.io.job.getStatus(job)) // "processing"
47
+ * ```
48
+ */
49
+ public abstract getStatus(job: ImportJobHandle): PluginApiReturn<ImportJobStatus>
50
+
51
+ /**
52
+ * Whether the job has finished successfully (status is `"complete"` and a
53
+ * result is ready). Returns `false` while pending/processing and on failure.
54
+ *
55
+ * @param job - The import job to inspect.
56
+ * @throws {@link HandleInvalidError} if the job handle is unknown.
57
+ *
58
+ * @examplePrompt Is the DWG import done yet?
59
+ * @examplePrompt Has the CAD import finished?
60
+ * @examplePrompt Tell me when the import job completes
61
+ * @examplePrompt Is my import ready?
62
+ *
63
+ * # Example
64
+ * ```ts
65
+ * const job = await snaptrude.core.io.import.dwg(url, 1)
66
+ * const deadline = Date.now() + 5 * 60_000 // cap the poll — see getStatus limitation
67
+ * while (!(await snaptrude.core.io.job.isComplete(job))) {
68
+ * if (Date.now() > deadline) throw new Error("DWG import timed out")
69
+ * await new Promise((r) => setTimeout(r, 2000))
70
+ * }
71
+ * ```
72
+ */
73
+ public abstract isComplete(job: ImportJobHandle): PluginApiReturn<boolean>
74
+
75
+ /**
76
+ * The imported result once the job is complete — the placed
77
+ * {@linkcode UnderlayHandle}. Returns `null` while the job is still
78
+ * pending/processing or if it failed (check {@link PluginCoreIoJobApi.getError}).
79
+ *
80
+ * @param job - The completed import job.
81
+ * @throws {@link HandleInvalidError} if the job handle is unknown.
82
+ *
83
+ * @examplePrompt Get the underlay from my finished DWG import
84
+ * @examplePrompt Give me the result of the CAD import job
85
+ * @examplePrompt Fetch the imported CAD sketch once it's ready
86
+ * @examplePrompt Return the handle for the completed import
87
+ *
88
+ * # Example
89
+ * ```ts
90
+ * const job = await snaptrude.core.io.import.dwg(url, 1)
91
+ * const deadline = Date.now() + 5 * 60_000
92
+ * while (!(await snaptrude.core.io.job.isComplete(job))) {
93
+ * if (Date.now() > deadline) throw new Error("DWG import timed out")
94
+ * await new Promise((r) => setTimeout(r, 2000))
95
+ * }
96
+ * // DWG results are CAD underlays (CAD scaling isn't supported); manage them
97
+ * // via core.io.underlay.* (list / setOpacity / delete).
98
+ * const cad = await snaptrude.core.io.job.getResult(job)
99
+ * if (cad) console.log("import complete:", cad)
100
+ * ```
101
+ */
102
+ public abstract getResult(job: ImportJobHandle): PluginApiReturn<UnderlayHandle | null>
103
+
104
+ /**
105
+ * The failure message if the job's status is `"failed"`; otherwise `null`.
106
+ *
107
+ * @param job - The import job to inspect.
108
+ * @throws {@link HandleInvalidError} if the job handle is unknown.
109
+ *
110
+ * @examplePrompt Why did my DWG import fail?
111
+ * @examplePrompt What went wrong with the CAD import?
112
+ * @examplePrompt Show the error from the failed import job
113
+ * @examplePrompt Did the import error out, and why?
114
+ *
115
+ * # Example
116
+ * ```ts
117
+ * const job = await snaptrude.core.io.import.dwg(url, 1)
118
+ * if ((await snaptrude.core.io.job.getStatus(job)) === "failed") {
119
+ * console.error(await snaptrude.core.io.job.getError(job))
120
+ * }
121
+ * ```
122
+ */
123
+ public abstract getError(job: ImportJobHandle): PluginApiReturn<string | null>
124
+ }
125
+
126
+ /** Lifecycle status of an asynchronous import job. */
127
+ export const ImportJobStatus = z.enum(["pending", "processing", "complete", "failed"])
128
+ export type ImportJobStatus = z.infer<typeof ImportJobStatus>
129
+
130
+ /**
131
+ * Arguments for the `core.io.job.*` readers.
132
+ *
133
+ * | Property | Type | Description |
134
+ * |---|---|---|
135
+ * | `job` | {@link ImportJobHandle} | The import job to inspect |
136
+ */
137
+ export const PluginImportJobArgs = z.object({
138
+ job: ImportJobHandle,
139
+ })
140
+ export type PluginImportJobArgs = z.infer<typeof PluginImportJobArgs>
@@ -0,0 +1,71 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../../../types"
3
+ import { CadJsonInput } from "../import"
4
+
5
+ /**
6
+ * Import queries — read metadata about a source **before** importing it.
7
+ *
8
+ * These reads let a plugin discover a source's shape before importing it:
9
+ * how many pages a PDF has (for `import.pdf`'s `page`), and which CAD layers a
10
+ * drawing defines (imports always bring in every layer — there is no filter —
11
+ * but the names tell you what the drawing contains).
12
+ *
13
+ * Accessed via `snaptrude.core.io.query`.
14
+ */
15
+ export abstract class PluginCoreIoQueryApi {
16
+ constructor() {}
17
+
18
+ /**
19
+ * Count the pages of a PDF without importing it. `null` if the source can't be
20
+ * read as a PDF.
21
+ *
22
+ * @param source - The PDF: an `https://` URL or a `data:` URL.
23
+ * @returns the page count, or `null`.
24
+ *
25
+ * @examplePrompt How many pages does this PDF have?
26
+ * @examplePrompt Count the pages in the drawing set before importing
27
+ * @examplePrompt Get the PDF page count
28
+ * @examplePrompt Is this a multi-page PDF, and how many?
29
+ *
30
+ * # Example
31
+ * ```ts
32
+ * const pages = await snaptrude.core.io.query.getPdfPageCount(url)
33
+ * for (let p = 1; p <= (pages ?? 0); p++) {
34
+ * await snaptrude.core.io.import.pdf(url, p, p) // one page per storey
35
+ * }
36
+ * ```
37
+ */
38
+ public abstract getPdfPageCount(source: string): PluginApiReturn<number | null>
39
+
40
+ /**
41
+ * List the distinct CAD layer names tagged on a parsed CAD JSON's entities.
42
+ * Read-only inspection: imports always bring in **every** layer (there is no
43
+ * layer filter on {@link core.io.import.dwg} / {@link core.io.import.cadJson}) —
44
+ * use the names to decide whether to import at all, or what to tell the user.
45
+ *
46
+ * @param cad - Parsed CAD JSON (same shape `import.cadJson` accepts).
47
+ * @returns the layer names (empty array if none).
48
+ *
49
+ * @examplePrompt What CAD layers are in this drawing?
50
+ * @examplePrompt List the layers before importing the CAD
51
+ * @examplePrompt Show the DWG layer names so I can pick which to import
52
+ * @examplePrompt Enumerate the CAD JSON layers
53
+ *
54
+ * # Example
55
+ * ```ts
56
+ * const layers = await snaptrude.core.io.query.listCadLayers(cad)
57
+ * if (layers.some((l) => l.toUpperCase().includes("WALL"))) {
58
+ * await snaptrude.core.io.import.cadJson(cad, 1) // all layers import together
59
+ * }
60
+ * ```
61
+ */
62
+ public abstract listCadLayers(cad: CadJsonInput): PluginApiReturn<string[]>
63
+ }
64
+
65
+ /** Arguments for {@link PluginCoreIoQueryApi.getPdfPageCount}. */
66
+ export const PluginQueryPdfPageCountArgs = z.object({ source: z.string().min(1) })
67
+ export type PluginQueryPdfPageCountArgs = z.infer<typeof PluginQueryPdfPageCountArgs>
68
+
69
+ /** Arguments for {@link PluginCoreIoQueryApi.listCadLayers}. */
70
+ export const PluginQueryCadLayersArgs = z.object({ cad: CadJsonInput })
71
+ export type PluginQueryCadLayersArgs = z.infer<typeof PluginQueryCadLayersArgs>