@reekon-tools/boldr-cad 0.1.0 → 1.0.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 (547) hide show
  1. package/README.md +81 -9
  2. package/dist/app/edit.d.ts +12 -1
  3. package/dist/app/edit.js +96 -11
  4. package/dist/app/edit.js.map +1 -1
  5. package/dist/app/state.d.ts +31 -4
  6. package/dist/app/state.js +31 -2
  7. package/dist/app/state.js.map +1 -1
  8. package/dist/data/memory.d.ts +5 -0
  9. package/dist/data/memory.js +2 -2
  10. package/dist/data/memory.js.map +1 -1
  11. package/dist/data/provider.d.ts +19 -7
  12. package/dist/data/sync.d.ts +7 -2
  13. package/dist/data/sync.js +115 -64
  14. package/dist/data/sync.js.map +1 -1
  15. package/dist/editor/actions.d.ts +1 -2
  16. package/dist/editor/actions.js +391 -113
  17. package/dist/editor/actions.js.map +1 -1
  18. package/dist/editor/confirm.d.ts +23 -0
  19. package/dist/editor/confirm.js +35 -0
  20. package/dist/editor/confirm.js.map +1 -0
  21. package/dist/editor/elevation.d.ts +191 -90
  22. package/dist/editor/elevation.js +812 -616
  23. package/dist/editor/elevation.js.map +1 -1
  24. package/dist/editor/face.d.ts +73 -0
  25. package/dist/editor/face.js +269 -0
  26. package/dist/editor/face.js.map +1 -0
  27. package/dist/editor/files.d.ts +6 -0
  28. package/dist/editor/files.js +50 -4
  29. package/dist/editor/files.js.map +1 -1
  30. package/dist/editor/gestures.d.ts +18 -3
  31. package/dist/editor/gestures.js +145 -30
  32. package/dist/editor/gestures.js.map +1 -1
  33. package/dist/editor/keypad.d.ts +19 -4
  34. package/dist/editor/keypad.js +39 -9
  35. package/dist/editor/keypad.js.map +1 -1
  36. package/dist/editor/keys.js +36 -4
  37. package/dist/editor/keys.js.map +1 -1
  38. package/dist/editor/laser.d.ts +20 -4
  39. package/dist/editor/laser.js +104 -21
  40. package/dist/editor/laser.js.map +1 -1
  41. package/dist/editor/linkActions.d.ts +49 -0
  42. package/dist/editor/linkActions.js +210 -0
  43. package/dist/editor/linkActions.js.map +1 -0
  44. package/dist/editor/linkFollow.d.ts +2 -0
  45. package/dist/editor/linkFollow.js +53 -0
  46. package/dist/editor/linkFollow.js.map +1 -0
  47. package/dist/editor/linkWrite.d.ts +13 -0
  48. package/dist/editor/linkWrite.js +84 -0
  49. package/dist/editor/linkWrite.js.map +1 -0
  50. package/dist/editor/links.d.ts +84 -0
  51. package/dist/editor/links.js +130 -0
  52. package/dist/editor/links.js.map +1 -0
  53. package/dist/editor/markup.d.ts +29 -3
  54. package/dist/editor/markup.js +95 -10
  55. package/dist/editor/markup.js.map +1 -1
  56. package/dist/editor/mode.d.ts +40 -2
  57. package/dist/editor/mode.js +71 -4
  58. package/dist/editor/mode.js.map +1 -1
  59. package/dist/editor/ports.d.ts +36 -6
  60. package/dist/editor/ports.js +10 -1
  61. package/dist/editor/ports.js.map +1 -1
  62. package/dist/editor/project.d.ts +38 -6
  63. package/dist/editor/project.js +167 -27
  64. package/dist/editor/project.js.map +1 -1
  65. package/dist/editor/selection.d.ts +10 -0
  66. package/dist/editor/selection.js +62 -8
  67. package/dist/editor/selection.js.map +1 -1
  68. package/dist/editor/status.js +3 -0
  69. package/dist/editor/status.js.map +1 -1
  70. package/dist/editor/tooltips.d.ts +5 -0
  71. package/dist/editor/tooltips.js +48 -0
  72. package/dist/editor/tooltips.js.map +1 -0
  73. package/dist/editor/view3d.d.ts +17 -0
  74. package/dist/editor/view3d.js +135 -0
  75. package/dist/editor/view3d.js.map +1 -0
  76. package/dist/editor/view3dState.d.ts +39 -0
  77. package/dist/editor/view3dState.js +44 -0
  78. package/dist/editor/view3dState.js.map +1 -0
  79. package/dist/export/dxf.js +1 -1
  80. package/dist/export/dxf.js.map +1 -1
  81. package/dist/export/pdf.js +17 -12
  82. package/dist/export/pdf.js.map +1 -1
  83. package/dist/export/plan.d.ts +23 -6
  84. package/dist/export/plan.js +127 -44
  85. package/dist/export/plan.js.map +1 -1
  86. package/dist/index.d.ts +5 -0
  87. package/dist/index.js +2 -0
  88. package/dist/index.js.map +1 -1
  89. package/dist/model/constraints.js +15 -4
  90. package/dist/model/constraints.js.map +1 -1
  91. package/dist/model/demo.js +3 -3
  92. package/dist/model/demo.js.map +1 -1
  93. package/dist/model/elevation.d.ts +6 -9
  94. package/dist/model/elevation.js +5 -13
  95. package/dist/model/elevation.js.map +1 -1
  96. package/dist/model/faces.d.ts +58 -0
  97. package/dist/model/faces.js +197 -0
  98. package/dist/model/faces.js.map +1 -0
  99. package/dist/model/facesolve.d.ts +72 -0
  100. package/dist/model/facesolve.js +369 -0
  101. package/dist/model/facesolve.js.map +1 -0
  102. package/dist/model/history.d.ts +3 -2
  103. package/dist/model/history.js +17 -11
  104. package/dist/model/history.js.map +1 -1
  105. package/dist/model/images.d.ts +18 -0
  106. package/dist/model/images.js +26 -0
  107. package/dist/model/images.js.map +1 -0
  108. package/dist/model/links.d.ts +46 -0
  109. package/dist/model/links.js +73 -0
  110. package/dist/model/links.js.map +1 -0
  111. package/dist/model/markup.d.ts +46 -0
  112. package/dist/model/markup.js +71 -0
  113. package/dist/model/markup.js.map +1 -0
  114. package/dist/model/measurement.d.ts +11 -0
  115. package/dist/model/measurement.js +24 -0
  116. package/dist/model/measurement.js.map +1 -0
  117. package/dist/model/openings.d.ts +4 -0
  118. package/dist/model/openings.js +4 -0
  119. package/dist/model/openings.js.map +1 -1
  120. package/dist/model/planGeom.d.ts +72 -2
  121. package/dist/model/planGeom.js +184 -10
  122. package/dist/model/planGeom.js.map +1 -1
  123. package/dist/model/project.js +3 -2
  124. package/dist/model/project.js.map +1 -1
  125. package/dist/model/projectfile.js +2 -1
  126. package/dist/model/projectfile.js.map +1 -1
  127. package/dist/model/rooms.js +2 -2
  128. package/dist/model/rooms.js.map +1 -1
  129. package/dist/model/settings.d.ts +6 -0
  130. package/dist/model/settings.js +2 -2
  131. package/dist/model/settings.js.map +1 -1
  132. package/dist/model/sketch.d.ts +14 -0
  133. package/dist/model/sketch.js +143 -24
  134. package/dist/model/sketch.js.map +1 -1
  135. package/dist/model/smooth.d.ts +6 -0
  136. package/dist/model/smooth.js +52 -0
  137. package/dist/model/smooth.js.map +1 -0
  138. package/dist/model/store.d.ts +12 -0
  139. package/dist/model/store.js +35 -3
  140. package/dist/model/store.js.map +1 -1
  141. package/dist/model/types.d.ts +173 -8
  142. package/dist/model/wallfaces.d.ts +32 -0
  143. package/dist/model/wallfaces.js +133 -20
  144. package/dist/model/wallfaces.js.map +1 -1
  145. package/dist/model/wallshape.d.ts +15 -0
  146. package/dist/model/wallshape.js +89 -0
  147. package/dist/model/wallshape.js.map +1 -0
  148. package/dist/react/BottomBar.d.ts +9 -5
  149. package/dist/react/BottomBar.js +213 -24
  150. package/dist/react/BottomBar.js.map +1 -1
  151. package/dist/react/Buttons.d.ts +13 -2
  152. package/dist/react/Buttons.js +37 -5
  153. package/dist/react/Buttons.js.map +1 -1
  154. package/dist/react/CadEditor.d.ts +46 -3
  155. package/dist/react/CadEditor.js +77 -20
  156. package/dist/react/CadEditor.js.map +1 -1
  157. package/dist/react/ConfirmSheet.d.ts +4 -0
  158. package/dist/react/ConfirmSheet.js +31 -0
  159. package/dist/react/ConfirmSheet.js.map +1 -0
  160. package/dist/react/ConflictSheet.d.ts +2 -1
  161. package/dist/react/ConflictSheet.js +16 -8
  162. package/dist/react/ConflictSheet.js.map +1 -1
  163. package/dist/react/Drawer.d.ts +8 -2
  164. package/dist/react/Drawer.js +167 -38
  165. package/dist/react/Drawer.js.map +1 -1
  166. package/dist/react/Duck.d.ts +13 -0
  167. package/dist/react/Duck.js +45 -0
  168. package/dist/react/Duck.js.map +1 -0
  169. package/dist/react/Empty3D.d.ts +2 -0
  170. package/dist/react/Empty3D.js +39 -0
  171. package/dist/react/Empty3D.js.map +1 -0
  172. package/dist/react/FitScroll.d.ts +6 -0
  173. package/dist/react/FitScroll.js +14 -0
  174. package/dist/react/FitScroll.js.map +1 -0
  175. package/dist/react/Icon.native.d.ts +6 -0
  176. package/dist/react/Icon.native.js +4 -0
  177. package/dist/react/Icon.native.js.map +1 -1
  178. package/dist/react/Icon.web.d.ts +6 -0
  179. package/dist/react/Icon.web.js +4 -0
  180. package/dist/react/Icon.web.js.map +1 -1
  181. package/dist/react/KeypadSheet.d.ts +9 -2
  182. package/dist/react/KeypadSheet.js +174 -42
  183. package/dist/react/KeypadSheet.js.map +1 -1
  184. package/dist/react/LaserTray.js +8 -5
  185. package/dist/react/LaserTray.js.map +1 -1
  186. package/dist/react/MarkupPanel.d.ts +8 -0
  187. package/dist/react/MarkupPanel.js +67 -0
  188. package/dist/react/MarkupPanel.js.map +1 -0
  189. package/dist/react/PageThumb.native.d.ts +7 -2
  190. package/dist/react/PageThumb.native.js +19 -7
  191. package/dist/react/PageThumb.native.js.map +1 -1
  192. package/dist/react/PageThumb.web.d.ts +3 -2
  193. package/dist/react/PageThumb.web.js +4 -4
  194. package/dist/react/PageThumb.web.js.map +1 -1
  195. package/dist/react/PlanCanvas.native.d.ts +1 -1
  196. package/dist/react/PlanCanvas.native.js +134 -36
  197. package/dist/react/PlanCanvas.native.js.map +1 -1
  198. package/dist/react/PlanCanvas.web.js +16 -5
  199. package/dist/react/PlanCanvas.web.js.map +1 -1
  200. package/dist/react/Popovers.d.ts +12 -6
  201. package/dist/react/Popovers.js +53 -26
  202. package/dist/react/Popovers.js.map +1 -1
  203. package/dist/react/Rail.d.ts +24 -0
  204. package/dist/react/Rail.js +324 -34
  205. package/dist/react/Rail.js.map +1 -1
  206. package/dist/react/ShapeMenu.d.ts +7 -0
  207. package/dist/react/ShapeMenu.js +58 -0
  208. package/dist/react/ShapeMenu.js.map +1 -0
  209. package/dist/react/Sheet.d.ts +14 -4
  210. package/dist/react/Sheet.js +54 -9
  211. package/dist/react/Sheet.js.map +1 -1
  212. package/dist/react/Slider.d.ts +18 -0
  213. package/dist/react/Slider.js +27 -0
  214. package/dist/react/Slider.js.map +1 -0
  215. package/dist/react/Toast.js +14 -6
  216. package/dist/react/Toast.js.map +1 -1
  217. package/dist/react/ToolTip.d.ts +7 -0
  218. package/dist/react/ToolTip.js +43 -0
  219. package/dist/react/ToolTip.js.map +1 -0
  220. package/dist/react/TopBar.d.ts +6 -3
  221. package/dist/react/TopBar.js +48 -17
  222. package/dist/react/TopBar.js.map +1 -1
  223. package/dist/react/Tween.d.ts +7 -0
  224. package/dist/react/Tween.js +26 -0
  225. package/dist/react/Tween.js.map +1 -0
  226. package/dist/react/Tween.native.d.ts +6 -0
  227. package/dist/react/Tween.native.js +43 -0
  228. package/dist/react/Tween.native.js.map +1 -0
  229. package/dist/react/View3D.native.d.ts +4 -0
  230. package/dist/react/View3D.native.js +103 -0
  231. package/dist/react/View3D.native.js.map +1 -0
  232. package/dist/react/View3D.web.d.ts +4 -0
  233. package/dist/react/View3D.web.js +151 -0
  234. package/dist/react/View3D.web.js.map +1 -0
  235. package/dist/react/View3DHost.d.ts +143 -0
  236. package/dist/react/View3DHost.js +377 -0
  237. package/dist/react/View3DHost.js.map +1 -0
  238. package/dist/react/corners.d.ts +7 -0
  239. package/dist/react/corners.js +51 -0
  240. package/dist/react/corners.js.map +1 -0
  241. package/dist/react/easing.d.ts +15 -0
  242. package/dist/react/easing.js +10 -0
  243. package/dist/react/easing.js.map +1 -0
  244. package/dist/react/host.d.ts +7 -2
  245. package/dist/react/host.js +8 -3
  246. package/dist/react/host.js.map +1 -1
  247. package/dist/react/hostKeypad.d.ts +56 -0
  248. package/dist/react/hostKeypad.js +5 -0
  249. package/dist/react/hostKeypad.js.map +1 -0
  250. package/dist/react/motion.d.ts +77 -0
  251. package/dist/react/motion.js +173 -0
  252. package/dist/react/motion.js.map +1 -0
  253. package/dist/react/ports.js +90 -8
  254. package/dist/react/ports.js.map +1 -1
  255. package/dist/react/saving.d.ts +15 -0
  256. package/dist/react/saving.js +76 -0
  257. package/dist/react/saving.js.map +1 -0
  258. package/dist/react/store.d.ts +38 -1
  259. package/dist/react/store.js +31 -1
  260. package/dist/react/store.js.map +1 -1
  261. package/dist/react/theme.d.ts +10 -0
  262. package/dist/react/theme.js +8 -0
  263. package/dist/react/theme.js.map +1 -1
  264. package/dist/react/topRow.d.ts +22 -0
  265. package/dist/react/topRow.js +61 -0
  266. package/dist/react/topRow.js.map +1 -0
  267. package/dist/react/touch.d.ts +6 -0
  268. package/dist/react/touch.js +9 -0
  269. package/dist/react/touch.js.map +1 -0
  270. package/dist/render/ctx.d.ts +8 -0
  271. package/dist/render/draw.d.ts +33 -1
  272. package/dist/render/draw.js +593 -215
  273. package/dist/render/draw.js.map +1 -1
  274. package/dist/render/elevation.d.ts +65 -43
  275. package/dist/render/elevation.js +414 -140
  276. package/dist/render/elevation.js.map +1 -1
  277. package/dist/render/figmaIcons.d.ts +12 -0
  278. package/dist/render/figmaIcons.js +21 -0
  279. package/dist/render/figmaIcons.js.map +1 -0
  280. package/dist/render/hit.d.ts +22 -2
  281. package/dist/render/hit.js +168 -25
  282. package/dist/render/hit.js.map +1 -1
  283. package/dist/render/icons.js +69 -10
  284. package/dist/render/icons.js.map +1 -1
  285. package/dist/render/linkTile.d.ts +15 -0
  286. package/dist/render/linkTile.js +369 -0
  287. package/dist/render/linkTile.js.map +1 -0
  288. package/dist/render/markup.d.ts +11 -0
  289. package/dist/render/markup.js +112 -0
  290. package/dist/render/markup.js.map +1 -0
  291. package/dist/render/navigate.d.ts +88 -0
  292. package/dist/render/navigate.js +100 -0
  293. package/dist/render/navigate.js.map +1 -0
  294. package/dist/render/snap.d.ts +20 -1
  295. package/dist/render/snap.js +118 -25
  296. package/dist/render/snap.js.map +1 -1
  297. package/dist/render/squircle.d.ts +8 -0
  298. package/dist/render/squircle.js +71 -0
  299. package/dist/render/squircle.js.map +1 -0
  300. package/dist/render/view.d.ts +115 -2
  301. package/dist/render/view.js +244 -19
  302. package/dist/render/view.js.map +1 -1
  303. package/dist/skia/SkiaDrawCtx.d.ts +30 -2
  304. package/dist/skia/SkiaDrawCtx.js +198 -43
  305. package/dist/skia/SkiaDrawCtx.js.map +1 -1
  306. package/dist/skia/host.d.ts +18 -2
  307. package/dist/skia/host.js +46 -1
  308. package/dist/skia/host.js.map +1 -1
  309. package/dist/solver/equations.js +37 -2
  310. package/dist/solver/equations.js.map +1 -1
  311. package/dist/solver/gauss-newton.d.ts +17 -0
  312. package/dist/solver/gauss-newton.js +144 -36
  313. package/dist/solver/gauss-newton.js.map +1 -1
  314. package/dist/solver/linalg.d.ts +45 -2
  315. package/dist/solver/linalg.js +164 -10
  316. package/dist/solver/linalg.js.map +1 -1
  317. package/dist/solver/types.d.ts +5 -0
  318. package/dist/tools/annotate.d.ts +57 -1
  319. package/dist/tools/annotate.js +64 -43
  320. package/dist/tools/annotate.js.map +1 -1
  321. package/dist/tools/chamfer.d.ts +12 -0
  322. package/dist/tools/chamfer.js +114 -0
  323. package/dist/tools/chamfer.js.map +1 -0
  324. package/dist/tools/corner.d.ts +38 -0
  325. package/dist/tools/corner.js +99 -0
  326. package/dist/tools/corner.js.map +1 -0
  327. package/dist/tools/dim.d.ts +86 -9
  328. package/dist/tools/dim.js +581 -96
  329. package/dist/tools/dim.js.map +1 -1
  330. package/dist/tools/elevation.js +1 -1
  331. package/dist/tools/elevation.js.map +1 -1
  332. package/dist/tools/fillet.d.ts +9 -0
  333. package/dist/tools/fillet.js +86 -0
  334. package/dist/tools/fillet.js.map +1 -0
  335. package/dist/tools/freehand.d.ts +3 -2
  336. package/dist/tools/freehand.js +19 -12
  337. package/dist/tools/freehand.js.map +1 -1
  338. package/dist/tools/index.js +14 -4
  339. package/dist/tools/index.js.map +1 -1
  340. package/dist/tools/line.d.ts +8 -3
  341. package/dist/tools/line.js +66 -30
  342. package/dist/tools/line.js.map +1 -1
  343. package/dist/tools/modify.d.ts +13 -0
  344. package/dist/tools/modify.js +105 -25
  345. package/dist/tools/modify.js.map +1 -1
  346. package/dist/tools/openings.js +22 -15
  347. package/dist/tools/openings.js.map +1 -1
  348. package/dist/tools/registry.d.ts +8 -0
  349. package/dist/tools/registry.js +42 -2
  350. package/dist/tools/registry.js.map +1 -1
  351. package/dist/tools/select.d.ts +77 -3
  352. package/dist/tools/select.js +560 -74
  353. package/dist/tools/select.js.map +1 -1
  354. package/dist/tools/shapes.d.ts +14 -0
  355. package/dist/tools/shapes.js +154 -75
  356. package/dist/tools/shapes.js.map +1 -1
  357. package/dist/units/format.d.ts +10 -2
  358. package/dist/units/format.js +18 -3
  359. package/dist/units/format.js.map +1 -1
  360. package/dist/view3d/build.d.ts +35 -0
  361. package/dist/view3d/build.js +630 -0
  362. package/dist/view3d/build.js.map +1 -0
  363. package/dist/view3d/camera.d.ts +60 -0
  364. package/dist/view3d/camera.js +84 -0
  365. package/dist/view3d/camera.js.map +1 -0
  366. package/dist/view3d/fatLines.d.ts +11 -0
  367. package/dist/view3d/fatLines.js +83 -0
  368. package/dist/view3d/fatLines.js.map +1 -0
  369. package/dist/view3d/lines.d.ts +17 -0
  370. package/dist/view3d/lines.js +271 -0
  371. package/dist/view3d/lines.js.map +1 -0
  372. package/dist/view3d/mesh.d.ts +51 -0
  373. package/dist/view3d/mesh.js +101 -0
  374. package/dist/view3d/mesh.js.map +1 -0
  375. package/dist/view3d/poly.d.ts +16 -0
  376. package/dist/view3d/poly.js +109 -0
  377. package/dist/view3d/poly.js.map +1 -0
  378. package/dist/view3d/viewer.d.ts +86 -0
  379. package/dist/view3d/viewer.js +350 -0
  380. package/dist/view3d/viewer.js.map +1 -0
  381. package/package.json +15 -2
  382. package/src/app/edit.ts +83 -12
  383. package/src/app/main.ts +11 -5
  384. package/src/app/state.ts +38 -5
  385. package/src/data/memory.ts +2 -2
  386. package/src/data/provider.ts +15 -7
  387. package/src/data/sync.ts +87 -50
  388. package/src/editor/actions.ts +292 -83
  389. package/src/editor/confirm.ts +58 -0
  390. package/src/editor/elevation.ts +698 -478
  391. package/src/editor/face.ts +227 -0
  392. package/src/editor/files.ts +40 -4
  393. package/src/editor/gestures.ts +147 -31
  394. package/src/editor/keypad.ts +43 -11
  395. package/src/editor/keys.ts +25 -5
  396. package/src/editor/laser.ts +98 -20
  397. package/src/editor/linkActions.ts +194 -0
  398. package/src/editor/linkFollow.ts +43 -0
  399. package/src/editor/linkWrite.ts +77 -0
  400. package/src/editor/links.ts +181 -0
  401. package/src/editor/markup.ts +92 -8
  402. package/src/editor/mode.ts +83 -7
  403. package/src/editor/ports.ts +37 -6
  404. package/src/editor/project.ts +155 -26
  405. package/src/editor/selection.ts +54 -8
  406. package/src/editor/status.ts +2 -0
  407. package/src/editor/tooltips.ts +47 -0
  408. package/src/editor/view3d.ts +119 -0
  409. package/src/editor/view3dState.ts +61 -0
  410. package/src/export/dxf.ts +1 -1
  411. package/src/export/pdf.ts +15 -7
  412. package/src/export/plan.ts +119 -35
  413. package/src/index.ts +5 -0
  414. package/src/input/keyboard.ts +2 -4
  415. package/src/model/constraints.ts +13 -4
  416. package/src/model/demo.ts +3 -3
  417. package/src/model/elevation.ts +6 -16
  418. package/src/model/faces.ts +153 -0
  419. package/src/model/facesolve.ts +322 -0
  420. package/src/model/history.ts +19 -11
  421. package/src/model/images.ts +35 -0
  422. package/src/model/links.ts +77 -0
  423. package/src/model/markup.ts +80 -0
  424. package/src/model/measurement.ts +26 -0
  425. package/src/model/openings.ts +6 -0
  426. package/src/model/planGeom.ts +174 -8
  427. package/src/model/project.ts +3 -2
  428. package/src/model/projectfile.ts +2 -1
  429. package/src/model/rooms.ts +1 -1
  430. package/src/model/settings.ts +8 -2
  431. package/src/model/sketch.ts +101 -14
  432. package/src/model/smooth.ts +51 -0
  433. package/src/model/store.ts +35 -4
  434. package/src/model/types.ts +170 -8
  435. package/src/model/wallfaces.ts +126 -17
  436. package/src/model/wallshape.ts +97 -0
  437. package/src/react/BottomBar.tsx +263 -46
  438. package/src/react/Buttons.tsx +50 -9
  439. package/src/react/CadEditor.tsx +133 -30
  440. package/src/react/ConfirmSheet.tsx +38 -0
  441. package/src/react/ConflictSheet.tsx +19 -12
  442. package/src/react/Drawer.tsx +213 -110
  443. package/src/react/Duck.tsx +50 -0
  444. package/src/react/Empty3D.tsx +32 -0
  445. package/src/react/FitScroll.tsx +19 -0
  446. package/src/react/Icon.native.tsx +5 -0
  447. package/src/react/Icon.web.tsx +5 -0
  448. package/src/react/KeypadSheet.tsx +253 -60
  449. package/src/react/LaserTray.tsx +12 -8
  450. package/src/react/MarkupPanel.tsx +150 -0
  451. package/src/react/PageThumb.native.tsx +18 -7
  452. package/src/react/PageThumb.web.tsx +4 -4
  453. package/src/react/PlanCanvas.native.tsx +151 -34
  454. package/src/react/PlanCanvas.web.tsx +15 -5
  455. package/src/react/Popovers.tsx +116 -51
  456. package/src/react/Rail.tsx +360 -27
  457. package/src/react/ShapeMenu.tsx +66 -0
  458. package/src/react/Sheet.tsx +56 -11
  459. package/src/react/Slider.tsx +48 -0
  460. package/src/react/Toast.tsx +16 -9
  461. package/src/react/ToolTip.tsx +49 -0
  462. package/src/react/TopBar.tsx +97 -39
  463. package/src/react/Tween.native.tsx +36 -0
  464. package/src/react/Tween.tsx +24 -0
  465. package/src/react/View3D.native.tsx +131 -0
  466. package/src/react/View3D.web.tsx +131 -0
  467. package/src/react/View3DHost.ts +367 -0
  468. package/src/react/corners.ts +52 -0
  469. package/src/react/easing.ts +14 -0
  470. package/src/react/host.ts +8 -3
  471. package/src/react/hostKeypad.ts +66 -0
  472. package/src/react/motion.tsx +239 -0
  473. package/src/react/ports.ts +78 -9
  474. package/src/react/saving.ts +80 -0
  475. package/src/react/store.ts +35 -3
  476. package/src/react/theme.ts +8 -0
  477. package/src/react/topRow.ts +71 -0
  478. package/src/react/touch.ts +10 -0
  479. package/src/render/ctx.ts +8 -0
  480. package/src/render/draw.ts +437 -175
  481. package/src/render/elevation.ts +349 -143
  482. package/src/render/figmaIcons.ts +22 -0
  483. package/src/render/hit.ts +140 -21
  484. package/src/render/icons.ts +69 -10
  485. package/src/render/linkTile.ts +297 -0
  486. package/src/render/markup.ts +91 -0
  487. package/src/render/navigate.ts +114 -0
  488. package/src/render/snap.ts +105 -22
  489. package/src/render/squircle.ts +73 -0
  490. package/src/render/view.ts +255 -19
  491. package/src/skia/SkiaDrawCtx.ts +163 -41
  492. package/src/skia/host.ts +46 -1
  493. package/src/solver/equations.ts +37 -2
  494. package/src/solver/gauss-newton.ts +125 -28
  495. package/src/solver/linalg.ts +141 -5
  496. package/src/solver/types.ts +5 -0
  497. package/src/styles.css +91 -42
  498. package/src/tools/annotate.ts +58 -29
  499. package/src/tools/chamfer.ts +103 -0
  500. package/src/tools/corner.ts +99 -0
  501. package/src/tools/dim.ts +524 -92
  502. package/src/tools/elevation.ts +1 -1
  503. package/src/tools/fillet.ts +82 -0
  504. package/src/tools/freehand.ts +20 -16
  505. package/src/tools/index.ts +17 -4
  506. package/src/tools/line.ts +59 -23
  507. package/src/tools/modify.ts +86 -24
  508. package/src/tools/openings.ts +8 -13
  509. package/src/tools/registry.ts +27 -2
  510. package/src/tools/select.ts +424 -75
  511. package/src/tools/shapes.ts +119 -58
  512. package/src/ui/ctx.ts +2 -1
  513. package/src/ui/domPorts.ts +23 -4
  514. package/src/ui/drawer.ts +6 -26
  515. package/src/ui/elevation.ts +10 -101
  516. package/src/ui/keypad.ts +8 -14
  517. package/src/ui/laser.ts +2 -2
  518. package/src/ui/menu.ts +63 -17
  519. package/src/ui/noteinput.ts +3 -3
  520. package/src/ui/opacity.ts +108 -0
  521. package/src/ui/palette.ts +67 -12
  522. package/src/ui/rail.ts +21 -7
  523. package/src/ui/topbar.ts +4 -14
  524. package/src/units/format.ts +18 -3
  525. package/src/view3d/build.ts +607 -0
  526. package/src/view3d/camera.ts +113 -0
  527. package/src/view3d/fatLines.ts +83 -0
  528. package/src/view3d/lines.ts +258 -0
  529. package/src/view3d/mesh.ts +111 -0
  530. package/src/view3d/poly.ts +104 -0
  531. package/src/view3d/viewer.ts +348 -0
  532. package/dist/react/ElevCanvas.native.d.ts +0 -3
  533. package/dist/react/ElevCanvas.native.js +0 -58
  534. package/dist/react/ElevCanvas.native.js.map +0 -1
  535. package/dist/react/ElevCanvas.web.d.ts +0 -4
  536. package/dist/react/ElevCanvas.web.js +0 -44
  537. package/dist/react/ElevCanvas.web.js.map +0 -1
  538. package/dist/react/ElevationSheet.d.ts +0 -2
  539. package/dist/react/ElevationSheet.js +0 -38
  540. package/dist/react/ElevationSheet.js.map +0 -1
  541. package/dist/render/elevationView.d.ts +0 -3
  542. package/dist/render/elevationView.js +0 -100
  543. package/dist/render/elevationView.js.map +0 -1
  544. package/src/react/ElevCanvas.native.tsx +0 -68
  545. package/src/react/ElevCanvas.web.tsx +0 -42
  546. package/src/react/ElevationSheet.tsx +0 -88
  547. package/src/render/elevationView.ts +0 -73
@@ -1,591 +1,811 @@
1
- import { afterEdit, redo, resolveOpeningsNow, undo } from '../app/edit';
2
- import { ed } from '../app/state';
3
- import { addElevLine, elevFrame, elevKey, elevLines, elevLineUZ, elevOpenings, openingHeights, roomSideOf, toU, wallHeight, WINDOW_H, type ElevFrame, type ElevOpening } from '../model/elevation';
1
+ import { afterEdit, analyze, resolveOpeningsNow, undo } from '../app/edit';
2
+ import { ed, type Hit } from '../app/state';
3
+ import { DOOR_H, elevFrame, elevOpenings, openingHeights, roomSideOf, toU, wallHeight, WINDOW_H, type ElevFrame } from '../model/elevation';
4
+ import { faceEdit, faceKey, faceKeyParts } from '../model/faces';
5
+ import { wallFace } from '../model/wallfaces';
6
+ import { faceOverflow, forgetSynced, openFace, placedMarks, planOverflow, pushedOut, setPlacedMarks, syncFace, syncFaces, type Overflow } from '../model/facesolve';
4
7
  import { clamp } from '../model/geom';
5
8
  import { pushHistory } from '../model/history';
6
9
  import { uid } from '../model/ids';
7
- import { applySlide, openingSpan, pickBetween, sameRef, slideGroup, type SlideGroup } from '../model/openings';
8
- import { onSessionReset, sessionState } from '../model/session';
10
+ import { applySlide, edgeS, openingSpan, pickBetween, resolveOpenings, sameRef, slideGroup, STANDARD_OPENING_W, type SlideGroup } from '../model/openings';
11
+ import { sessionState } from '../model/session';
9
12
  import { settings } from '../model/settings';
10
- import { deleteSel, lineLen } from '../model/sketch';
11
- import { SK } from '../model/store';
12
- import type { OpeningDim, OpeningRef } from '../model/types';
13
- import { elevT, type ElevAct, type ElevHit, type ElevView } from '../render/elevation';
14
- import { requestDraw, S } from '../render/view';
13
+ import { deleteSel, gc, lineLen, restorePos, snapshotPos, type PosSnapshot } from '../model/sketch';
14
+ import { planSK, SK } from '../model/store';
15
+ import type { Opening, OpeningDim, OpeningRef, Sketch, WallFace } from '../model/types';
16
+ import type { DrawCtx } from '../render/ctx';
17
+ import { cabBox, previewChip, type ElevAct } from '../render/elevation';
18
+ import { TH } from '../render/theme';
19
+ import { fitView, mainT, requestDraw, requestOverlayDraw, S, setWallBox, type Xform } from '../render/view';
15
20
  import { editElevationPosition, editOpeningHeight, editSill, editWallHeight } from '../tools/elevation';
16
21
  import { editOpeningDim } from '../tools/openings';
22
+ import { cancelTool, type PEv, type Tool } from '../tools/registry';
17
23
  import { fmtLen } from '../units';
18
- import type { PointerIn } from './gestures';
19
- import type { KeyIn } from './keys';
20
- import { openKeypad, renderElevation, setCursor, toast, updateCtx } from './ports';
24
+ import { addCabinet, addHeightLine, CAB, cabinetSpot, deleteCabinets, dimensionFace, editCabinet, editCabinetDepth, snapObjectMove } from './face';
25
+ import type { RailItem } from './mode';
26
+ import { openKeypad, refreshModes, renderElevation, toast, updateCtx, updateHint, updateRail, updateTopBar } from './ports';
21
27
 
22
28
  /*
23
- The wall elevation: a full-screen view of one straight wall, straight on, whatever draws it.
24
- It shows the live drawing (nothing is copied), so the plan and the elevation can't disagree. Drag a door or
25
- window to move it (unless a dimension locks it); tap a dimension to select it, then + changes it; draw lines and
26
- guides on the wall face; place doors and windows. This module holds the view's state, tools, snapping, selection,
27
- the bar's decisions, delete, and pointer routing; the interface draws it (render/elevationView.ts) and shows it.
29
+ The wall view: one straight wall seen straight on, edited with the plan's own tools. Opening a wall makes the
30
+ editor work on that wall face's sketch (model/faces.ts: SK() is the face) — its grid, lines, circles and arcs,
31
+ constraints, dimensions, selection and dragging are the plan's — with the plan's corners, floor, ceiling, doors and
32
+ windows as fixed anchors to snap and constrain to. On top of that, the wall view's own: doors and windows placed
33
+ and dragged on the wall (they're the plan's), cabinets, height lines, and the dimension chips doors, windows and
34
+ cabinets get (render/elevation.ts), each tapped to select and changed with the yellow +.
28
35
  */
29
36
 
30
- /** The open wall view's state (the interface reads it to draw). */
37
+ /** The open wall: which wall, from which side, and its frame (from the live plan). */
31
38
  export const elev = sessionState(() => ({
32
39
  lid: null as string | null,
33
40
  flip: false,
34
- view: null as ElevView | null,
35
41
  frame: null as ElevFrame | null,
36
- W: 0, H: 0,
37
- hits: [] as ElevHit[],
38
- /** the selected dimension (ringed in yellow; the bar's + opens its keypad) */
39
- active: null as string | null,
40
- /** the opening being dragged (outlined in yellow) */
41
- dragOp: null as string | null,
42
- /** selected openings, wall corners and drawn lines (tap; Shift/⌘-tap adds) — the bar's + dimensions them */
43
- objs: [] as Obj[],
44
- /** the active tool (the toolbar on the left) */
45
- tool: 'select' as ElevTool,
46
- /** line / guide tool: the first point, [u, z], once placed */
47
- lineStart: null as [number, number] | null,
48
- /** where the pointer is (snapped), for previews while a drawing tool is active */
49
- cursor: null as Snapped | null,
50
42
  }));
51
43
 
52
- /** Something selectable in the elevation: a door/window, a corner of the wall face, or a line drawn on it. */
53
- export type Obj = { k: 'op'; id: string } | { k: 'corner'; end: 'a' | 'b' } | { k: 'line'; id: string };
54
- const objKey = (o: Obj) => (o.k === 'corner' ? 'corner:' + o.end : o.k + ':' + o.id);
55
-
56
- /** Wall view tools: a simplified version of the plan's toolbar. */
57
- export type ElevTool = 'select' | 'door' | 'window' | 'line' | 'guide';
58
- /** A point under the pointer, snapped: kind says what it snapped to (drawn as a purple marker). */
59
- export interface Snapped { p: [number, number]; kind: 'pt' | 'edge' | 'hv' | null }
60
-
61
44
  /** Size of a new door/window placed in the wall view (as the plan's tool), inches. */
62
- export const NEW_W = 36;
45
+ export const NEW_W = STANDARD_OPENING_W;
63
46
 
64
47
  export const elevOpen = (): boolean => elev.lid != null;
65
48
 
66
- /** Tappable dimension chips of the open elevation (canvas pixels), for tests. */
67
- export const elevHits = (): readonly ElevHit[] => elev.hits;
68
- /** Open the elevation of a straight wall, seen from the room side. */
69
- export function openElevation(lid: string): void {
70
- const sk = SK();
71
- if (!elevFrame(sk, lid)) { toast('Elevations work on straight walls. Turn the line into a wall first.'); return; }
72
- elev.lid = lid; elev.flip = false; elev.view = null; elev.active = null; elev.objs = []; elev.lineStart = null; elev.cursor = null;
73
- setElevTool('select', true); // renders: the interface shows the sheet first, so the view fits its real size
49
+ /** The open wall, for the wall view to fit: along it from corner to corner, and from the floor to its height. */
50
+ const wallBox = () => (elev.frame ? { x0: elev.frame.face[0], y0: 0, x1: elev.frame.face[1], y1: elev.frame.H } : null);
51
+
52
+ /** Open the wall view of a straight wall, seen from the room side. */
53
+ /** Open a wall's view: from the side a room is on — or `side`, the face to the left (+1) or right (−1) of its A → B. */
54
+ export function openElevation(lid: string, side?: 1 | -1): void {
55
+ if (!elevFrame(planSK(), lid)) { toast('Elevations work on straight walls. Turn the line into a wall first.', { warn: true }); return; }
56
+ cancelTool();
57
+ elev.lid = lid; elev.flip = side != null && side !== (roomSideOf(planSK(), lid) || 1);
58
+ enterFace();
74
59
  }
75
60
 
76
- /** Back to the plan (the interface hides the sheet). */
61
+ /** Start editing the open wall's face (from the side `elev.flip` says). */
62
+ function enterFace(): void {
63
+ const f = elevFrame(planSK(), elev.lid!, elev.flip)!;
64
+ elev.frame = f;
65
+ // (handed over here, not as this module loads: the view module is still loading then)
66
+ setWallBox(wallBox);
67
+ faceEdit.key = faceKey(f.lid, f.side);
68
+ openFace(planSK(), f.lid, f.side as 1 | -1);
69
+ ed.mode = 'draft'; ed.tool = 'select'; ed.sel = []; ed.hover = null; ed.snapState = null; ed.preview = null; ed.boxSel = null;
70
+ analyze();
71
+ fitView();
72
+ refreshModes(); updateRail(); updateCtx(); updateHint(); updateTopBar(); renderElevation(); requestDraw();
73
+ }
74
+
75
+ /** Stop editing the face (a face with nothing on it isn't kept). */
76
+ function leaveFace(): void {
77
+ cancelTool();
78
+ faceEdit.key = null;
79
+ gc(planSK());
80
+ }
81
+
82
+ /** Open the wall a cabinet is on, from its side, with the cabinet selected (a tap on its footprint in the plan). */
83
+ export function openCabinet(key: string, cabId: string): void {
84
+ const { lid, side } = faceKeyParts(key);
85
+ openElevation(lid);
86
+ if (!elevOpen()) return;
87
+ if (elev.frame && elev.frame.side !== side) flipElevation();
88
+ if ((SK() as WallFace).cabs?.[cabId]) { ed.sel = [{ type: 'cab', id: cabId }]; updateCtx(); updateHint(); requestDraw(); }
89
+ toast('This cabinet’s wall — Back returns to the plan.');
90
+ }
91
+
92
+ /** Back to the plan, with the wall selected. */
77
93
  export function closeElevation(): void {
78
94
  if (!elevOpen()) return;
79
- elev.lid = null; elev.frame = null; elev.active = null; elev.objs = []; elev.lineStart = null; elev.cursor = null;
80
- renderElevation();
81
- requestDraw();
95
+ const lid = elev.lid!;
96
+ leaveFace();
97
+ elev.lid = null; elev.frame = null;
98
+ ed.tool = 'select'; ed.hover = null; ed.preview = null;
99
+ ed.sel = planSK().lines[lid] ? [{ type: 'line', id: lid }] : [];
100
+ analyze();
101
+ refreshModes(); updateRail(); updateCtx(); updateHint(); updateTopBar(); renderElevation(); requestDraw();
82
102
  }
103
+
104
+ /** Look at the wall from its other side (each side has its own drawing). */
83
105
  export function flipElevation(): void {
84
106
  if (!elevOpen()) return;
85
- elev.flip = !elev.flip; elev.view = null; elev.active = null; elev.objs = []; elev.lineStart = null;
86
- renderElevation();
107
+ leaveFace();
108
+ elev.flip = !elev.flip;
109
+ enterFace();
87
110
  }
111
+
88
112
  /** Fit the wall to the view again. */
89
- export function fitElevation(): void { elev.view = null; renderElevation(); }
90
- /** The open wall's frame, from the live drawing. Closes the view if the wall is gone. */
113
+ export function fitElevation(): void { fitView(); }
114
+
115
+ /** The open wall's frame, from the live plan. Closes the view if the wall is gone (or isn't a straight wall now). */
91
116
  export function elevSyncFrame(): ElevFrame | null {
92
117
  if (!elevOpen()) return null;
93
- const f = elevFrame(SK(), elev.lid!, elev.flip);
118
+ const f = elevFrame(planSK(), elev.lid!, elev.flip);
94
119
  if (!f) { closeElevation(); return null; }
95
120
  elev.frame = f;
121
+ // a room appeared or went on one side: the side "inside" is the other face now
122
+ const key = faceKey(f.lid, f.side);
123
+ if (faceEdit.key !== key) { faceEdit.key = key; openFace(planSK(), f.lid, f.side as 1 | -1); ed.sel = []; analyze(); }
96
124
  return f;
97
125
  }
98
126
 
99
- /**
100
- * After drawing: keep the tappable chips, drop a selected dimension that no longer shows and selected things that
101
- * are gone. Returns the selected dimension's chip, if any.
102
- */
103
- export function elevAfterRender(hits: ElevHit[]): ElevHit | undefined {
104
- elev.hits = hits;
105
- let on = elev.active ? hits.find(h => JSON.stringify(h.act) === elev.active) : undefined;
106
- if (elev.active && !on) { elev.active = null; on = undefined; }
107
- const sk = SK(), lines = elev.frame ? elevLines(sk, elev.frame) : [];
108
- elev.objs = elev.objs.filter(o => o.k === 'corner' || (o.k === 'op' ? !!sk.openings[o.id] : lines.some(l => l.id === o.id)));
109
- return on;
110
- }
111
-
112
- /** Whether the trash has something to do: free or remove the selected dimension, or delete selected things. */
113
- export const elevTrashEnabled = (on?: ElevHit): boolean =>
114
- on ? !!storedDim(on.act) || !!lockedSill(on.act) : elev.objs.some(o => o.k !== 'corner');
115
-
116
127
  /** The view's title: the wall's length, and which side it's seen from. */
117
128
  export function elevTitle(): { title: string; sub: string } {
118
- const sk = SK(), f = elev.frame!, hasRoom = roomSideOf(sk, elev.lid!) !== 0;
129
+ const sk = planSK(), f = elev.frame!, hasRoom = roomSideOf(sk, elev.lid!) !== 0;
119
130
  return {
120
131
  title: 'Wall ' + fmtLen(lineLen(sk, sk.lines[elev.lid!])),
121
132
  sub: hasRoom ? (f.inside ? 'Seen from inside' : 'Seen from outside') : 'Side ' + (elev.flip ? 2 : 1) + ' of 2',
122
133
  };
123
134
  }
124
135
 
125
- const hitAt = (x: number, y: number): ElevHit | undefined =>
126
- [...elev.hits].reverse().find(h => x >= h.x && x <= h.x + h.w && y >= h.y && y <= h.y + h.h);
136
+ // ---- keeping what's drawn inside the wall ----
127
137
 
128
- const nameOf = (op: string) => (SK().openings[op].type === 'door' ? 'door' : 'window');
138
+ /** The open wall face's edges: across from corner to corner, up from the floor to the ceiling. Null outside the wall view. */
139
+ export function wallBounds(): { x0: number; x1: number; y0: number; y1: number } | null {
140
+ const f = elevOpen() ? elev.frame : null;
141
+ return f ? { x0: f.face[0], x1: f.face[1], y0: 0, y1: f.H } : null;
142
+ }
129
143
 
130
- /** What dragging an opening will do, given its locks. */
131
- function dragHint(op: string): string {
132
- const sk = SK(), o = sk.openings[op], locked = !slideGroup(sk, op), n = nameOf(op);
133
- if (o.type === 'door') return locked ? 'This door is locked by a dimension. Change the dimension, or make it a reference, to move it.' : 'Drag the door to slide it along the floor.';
134
- if (locked && o.sillLocked) return 'This window is locked along the wall and in height. Select a blue dimension and press Delete to free it.';
135
- if (o.sillLocked) return 'This window’s height above the floor is locked — it only slides along the wall. Delete the blue sill dimension to free it.';
136
- return locked ? 'This window is locked along the wall by a dimension — drag it to raise or lower it.' : 'Drag the ' + n + ' to move it along the wall or up and down.';
144
+ /** A point brought inside the wall (as it is, outside the wall view). */
145
+ export function intoWall(x: number, y: number): [number, number] {
146
+ const b = wallBounds();
147
+ return b ? [Math.min(Math.max(x, b.x0), b.x1), Math.min(Math.max(y, b.y0), b.y1)] : [x, y];
137
148
  }
138
149
 
139
150
  /**
140
- * Drag an opening along the wall — or, if it's locked to other openings, the whole free chain it's part of
141
- * (a dimension between openings fixes their spacing, not where they sit) — unless the chain is locked to the
142
- * wall itself. Windows also move up and down; doors stay on the floor. The sill snaps to the display precision.
151
+ * How far what's drawn on the face reaches past the wall, inches (0: it's all inside): each point, and each circle's
152
+ * and arc's reach. Edits that make this grow are refused, so nothing is pushed out (a wall made shorter in the plan can
153
+ * leave something outside: it can still be edited, just not pushed further out).
143
154
  */
144
- /** cx, cy: where the press started, in client (window) pixels — steady even while the sheet animates in */
145
- interface Drag { op: string; group: SlideGroup | null; sill: number; lockedH: boolean; started: boolean; cx: number; cy: number }
146
- function startDrag(op: string, cx: number, cy: number): Drag | null {
147
- const sk = SK(), o = sk.openings[op];
148
- if (!o) return null;
149
- const group = slideGroup(sk, op);
150
- return { op, group, sill: openingHeights(o).sill, lockedH: !group, started: false, cx, cy };
155
+ export function wallOverflow(sk = SK()): Overflow {
156
+ const b = wallBounds();
157
+ return b ? faceOverflow(sk, b) : {};
151
158
  }
152
- function moveDrag(d: Drag, du: number, dz: number): void {
153
- const sk = SK(), o = sk.openings[d.op], f = elev.frame, g = o && openingSpan(sk, o), l = o && sk.lines[o.line];
154
- if (!o || !f || !g || !l) return;
155
- if (!d.started) {
156
- const stuck = d.lockedH && (o.type === 'door' || !!o.sillLocked);
157
- if (stuck) { toast(dragHint(d.op)); elev.dragOp = null; return; }
158
- if (d.lockedH || o.sillLocked) toast(dragHint(d.op));
159
- d.started = true;
160
- pushHistory();
161
- elev.dragOp = d.op;
162
- elev.active = null;
163
- if (!elev.objs.some(x => x.k === 'op' && x.id === d.op)) elev.objs = [{ k: 'op', id: d.op }];
164
- }
165
- if (d.group) applySlide(sk, d.group, f.mirror ? -du : du);
166
- if (o.type === 'window' && !o.sillLocked) {
167
- const { sill, head } = openingHeights(o), q = 1 / settings.denom;
168
- o.sill = clamp(Math.round((d.sill + dz) / q) * q, 0, Math.max(0, wallHeight(l) - (head - sill)));
169
- }
170
- resolveOpeningsNow();
171
- requestDraw();
172
- renderElevation();
173
- }
174
- // ---- drawing tools ----
175
-
176
- /** The wall view's toolbar: [tool, label, shortcut, icon]. */
177
- export const ELEV_RAIL: ([ElevTool, string, string, string] | '|')[] = [
178
- ['select', 'Select', 'V', 'select'], ['door', 'Door', 'B', 'door'], ['window', 'Window', 'N', 'window'],
179
- ['line', 'Line', 'L', 'line'], ['guide', 'Guide line', 'X', 'constr'], '|',
180
- ];
181
159
 
182
- export const TOOL_HINT: Record<ElevTool, string> = {
183
- select: '',
184
- door: 'Tap the wall to place a 3\'-0" door. It sits on the floor where you tap.',
185
- window: 'Tap the wall to place a 3\'-0" window, centered where you tap.',
186
- line: 'Tap two points, or drag, to draw a line. It snaps to corners, openings, the floor and ceiling, and level/plumb.',
187
- guide: 'Tap two points, or drag, to draw a dashed guide line.',
188
- };
189
- /** Switch the wall view's tool. */
190
- export function setElevTool(t: ElevTool, quiet = false): void {
191
- elev.tool = t; elev.lineStart = null; elev.cursor = null;
192
- if (t !== 'select') { elev.active = null; }
193
- if (!quiet && TOOL_HINT[t]) toast(TOOL_HINT[t]);
194
- renderElevation();
195
- }
196
-
197
- /** Esc in the wall view: cancel a line in progress, then leave the tool, then close the view. */
198
- export function elevEscape(): void {
199
- if (elev.lineStart) { elev.lineStart = null; renderElevation(); return; }
200
- if (elev.tool !== 'select') { setElevTool('select', true); return; }
201
- if (elev.objs.length || elev.active) { elev.objs = []; elev.active = null; renderElevation(); return; }
202
- closeElevation();
160
+ /**
161
+ * How far things run past their walls, once an edit has been followed through: in the wall view, what's drawn on it;
162
+ * in the plan, the doors and windows (re-placed from their dimensions) and what's drawn on each wall face (brought up
163
+ * to date with the plan). Edits that make this grow are refused — a wall can't be made shorter than what's on it.
164
+ */
165
+ export function overflow(sk = SK()): Overflow {
166
+ if (elevOpen()) return wallOverflow(sk);
167
+ if (sk !== planSK()) return {};
168
+ resolveOpenings(sk);
169
+ syncFaces(sk, true);
170
+ return planOverflow(sk);
171
+ }
172
+
173
+ /** Everything following an edit through can change (see overflow), to put back if the edit is refused. */
174
+ export interface FitState {
175
+ pos: PosSnapshot;
176
+ /** each door and window as it was (its place, sill, width, dimensions: whatever the edit may have changed) */
177
+ ops?: Record<string, string>;
178
+ /** each wall face's positions and where its corners were (what a sync moves; the rest it rebuilds from the plan) */
179
+ faces?: Record<string, { pos: PosSnapshot; wall?: WallFace['wall'] }>;
180
+ marks?: string;
181
+ }
182
+
183
+ export function fitState(sk = SK()): FitState {
184
+ if (elevOpen() || sk !== planSK()) return { pos: snapshotPos(sk) };
185
+ return planFitState(sk);
186
+ }
187
+
188
+ /** Everything following a change to the plan through can change (see planFit), whichever view is open. */
189
+ export function planFitState(sk = planSK()): FitState {
190
+ const pos = snapshotPos(sk);
191
+ const ops: FitState['ops'] = {}, faces: FitState['faces'] = {};
192
+ Object.assign(ops, snapOpenings(sk));
193
+ // (copied by hand: React Native has no structuredClone)
194
+ for (const [key, face] of Object.entries(sk.faces ?? {})) faces[key] = { pos: snapshotPos(face), wall: face.wall && { u: [...face.wall.u], ends: [[...face.wall.ends[0]], [...face.wall.ends[1]]] } };
195
+ return { pos, ops, faces, marks: placedMarks() };
196
+ }
197
+
198
+ /** Each door and window as it is — its place, sill, width, dimensions: whatever an edit to it may change. */
199
+ function snapOpenings(sk: Sketch): Record<string, string> {
200
+ const out: Record<string, string> = {};
201
+ for (const [id, o] of Object.entries(sk.openings)) out[id] = JSON.stringify(o);
202
+ return out;
203
+ }
204
+ /** Put them back as they were — in place: what holds on to a door or window (a drag, a keypad) keeps the same one. */
205
+ function putOpenings(sk: Sketch, snap: Record<string, string>): void {
206
+ for (const [id, v] of Object.entries(snap)) {
207
+ const o = sk.openings[id] as unknown as Record<string, unknown> | undefined;
208
+ if (!o) continue;
209
+ const was = JSON.parse(v) as Record<string, unknown>;
210
+ for (const k of Object.keys(o)) if (!(k in was)) delete o[k];
211
+ Object.assign(o, was);
212
+ }
203
213
  }
204
214
 
205
- /** Keyboard shortcuts for the wall view's tools. Returns true if the key was one. */
206
- export function elevToolKey(k: string): boolean {
207
- const t = ({ v: 'select', b: 'door', n: 'window', l: 'line', x: 'guide' } as Record<string, ElevTool>)[k.toLowerCase()];
208
- if (!t) return false;
209
- setElevTool(t);
210
- return true;
215
+ export function restoreFit(sk: Sketch, s: FitState): void {
216
+ restorePos(sk, s.pos);
217
+ if (!s.ops) return;
218
+ putOpenings(sk, s.ops);
219
+ for (const [key, v] of Object.entries(s.faces ?? {})) {
220
+ const face = sk.faces?.[key];
221
+ if (!face) continue;
222
+ restorePos(face, v.pos);
223
+ if (v.wall) face.wall = v.wall; else delete face.wall;
224
+ }
225
+ setPlacedMarks(s.marks!);
226
+ forgetSynced();
227
+ }
228
+
229
+ /** Limit a move of points (from where they started) so they all stay inside the wall, circles centred on them whole. */
230
+ export function keepInWall(sk: Sketch, ids: string[], start: { x: number; y: number }[], dx: number, dy: number): [number, number] {
231
+ const b = wallBounds();
232
+ if (!b || !ids.length) return [dx, dy];
233
+ let lo = -Infinity, hi = Infinity, dlo = -Infinity, dhi = Infinity;
234
+ ids.forEach((id, i) => {
235
+ const r = Math.max(0, ...Object.values(sk.circles).filter(c => c.c === id).map(c => c.r)), p = start[i];
236
+ lo = Math.max(lo, b.x0 - (p.x - r)); hi = Math.min(hi, b.x1 - (p.x + r));
237
+ dlo = Math.max(dlo, b.y0 - (p.y - r)); dhi = Math.min(dhi, b.y1 - (p.y + r));
238
+ });
239
+ return [lo <= hi ? Math.min(Math.max(dx, lo), hi) : 0, dlo <= dhi ? Math.min(Math.max(dy, dlo), dhi) : 0];
211
240
  }
212
241
 
213
- const toWorld = (x: number, y: number): [number, number] => { const T = elevT(elev.view!, elev.W, elev.H); return [(x - T.ox) / T.s, (T.oy - y) / T.s]; };
242
+ export const PAST_WALL = 'That would run past the edge of the wall.';
243
+ /** A door or window moved or resized in a way that would shove what's tied to it (a cabinet) off its wall. */
244
+ export const PUSHES_OFF = 'That would push what’s tied to it past the edge of the wall.';
214
245
 
215
246
  /**
216
- * Snap a screen point for drawing: to a feature point (wall corners, opening corners, line ends and middles),
217
- * else each axis to a nearby feature line (floor, ceiling, wall ends, opening edges and sill/head heights, line ends),
218
- * else level/plumb from the line's start, else to the display precision.
247
+ * How far things run past their walls in the plan — doors and windows past their walls' ends, what's on each wall
248
+ * face past its corners, floor and ceiling — once a change to the plan has been followed through (the doors and
249
+ * windows re-placed from their dimensions, the faces brought up to date). Whichever view is open: a door or window
250
+ * changed from the wall view (its width, its distance from a corner) is the plan's.
219
251
  */
220
- function snapUZ(x: number, y: number, from: [number, number] | null): Snapped {
221
- const sk = SK(), f = elev.frame!, T = elevT(elev.view!, elev.W, elev.H), R = 12 / T.s;
222
- const [u, z] = toWorld(x, y);
223
- const ops = elevOpenings(sk, f), lines = elevLines(sk, f).map(l => elevLineUZ(f, l));
224
- const pts: [number, number][] = [[f.face[0], 0], [f.face[0], f.H], [f.face[1], 0], [f.face[1], f.H]];
225
- for (const o of ops) pts.push([o.u0, o.sill], [o.u0, o.head], [o.u1, o.sill], [o.u1, o.head]);
226
- for (const [a, b] of lines) pts.push(a, b, [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2]);
227
- let best: [number, number] | null = null, bd = R;
228
- for (const p of pts) { const d = Math.hypot(p[0] - u, p[1] - z); if (d < bd) { bd = d; best = p; } }
229
- if (best) return { p: [best[0], best[1]], kind: 'pt' };
230
- const us = [f.face[0], f.face[1], ...ops.flatMap(o => [o.u0, o.u1]), ...lines.flatMap(([a, b]) => [a[0], b[0]])];
231
- const zs = [0, f.H, ...ops.flatMap(o => [o.sill, o.head]), ...lines.flatMap(([a, b]) => [a[1], b[1]])];
232
- const near = (v: number, list: number[]) => list.reduce<number | null>((m, x) => (Math.abs(x - v) < R && (m == null || Math.abs(x - v) < Math.abs(m - v)) ? x : m), null);
233
- const q = 1 / settings.denom, su = near(u, us), sz = near(z, zs);
234
- let pu = su ?? Math.round(u / q) * q, pz = sz ?? Math.round(z / q) * q, kind: Snapped['kind'] = su != null || sz != null ? 'edge' : null;
235
- if (from) {
236
- const du = Math.abs(pu - from[0]), dz = Math.abs(pz - from[1]), tan = Math.tan((6 * Math.PI) / 180);
237
- if (sz == null && dz < du * tan) { pz = from[1]; kind = 'hv'; }
238
- else if (su == null && du < dz * tan) { pu = from[0]; kind = 'hv'; }
239
- }
240
- return { p: [pu, pz], kind };
252
+ export function planFit(sk = planSK()): Overflow {
253
+ resolveOpenings(sk);
254
+ syncFaces(sk, true);
255
+ return planOverflow(sk);
241
256
  }
242
257
 
243
- /** Where a new door/window would go for a pointer at (u, z): centre s along the wall, and the window's sill. */
244
- export function openingAt(type: 'door' | 'window', u: number, z: number): { at: number; sill: number } | null {
245
- const f = elev.frame!, w = NEW_W;
246
- if (f.L < w + 2) return null;
247
- const at = clamp(toU(f, u), w / 2, f.L - w / 2);
248
- const q = 1 / settings.denom, sill = type === 'door' ? 0 : clamp(Math.round((z - WINDOW_H / 2) / q) * q, 0, Math.max(0, f.H - WINDOW_H));
249
- return { at, sill };
250
- }
251
-
252
- function placeOpening(type: 'door' | 'window', u: number, z: number): void {
253
- const sk = SK(), f = elev.frame!, spot = openingAt(type, u, z);
254
- if (!spot) { toast('That wall is too short for a ' + fmtLen(NEW_W) + ' ' + type + '.', { warn: true }); return; }
255
- pushHistory();
256
- const id = uid('o');
257
- // a door swings toward the side you're looking from
258
- sk.openings[id] = { line: f.lid, at: spot.at, w: NEW_W, type, flip: f.side !== 1, ...(type === 'window' ? { sill: spot.sill } : {}) };
259
- elev.objs = [{ k: 'op', id }];
260
- afterEdit();
258
+ /**
259
+ * Make a change to the plan's doors and windows — a width, a distance entered — only if it pushes nothing on a wall
260
+ * past its edges (a cabinet tied to a window would otherwise be shoved off the wall). Taken back, and said, if it
261
+ * would. Returns whether it was made.
262
+ */
263
+ export function withinWalls(change: () => void): boolean {
264
+ const sk = planSK(), was = planFit(sk), held = planFitState(sk);
265
+ change();
266
+ if (!pushedOut(was, planFit(sk))) return true;
267
+ restoreFit(sk, held);
268
+ planFit(sk);
269
+ toast(PUSHES_OFF, { warn: true });
270
+ return false;
261
271
  }
262
272
 
263
- function finishLine(b: [number, number]): void {
264
- const a = elev.lineStart, f = elev.frame;
265
- if (!a || !f) return;
266
- if (Math.hypot(b[0] - a[0], b[1] - a[1]) < 0.5) return; // too short: keep waiting for the second point
267
- pushHistory();
268
- const id = uid('el');
269
- addElevLine(SK(), f, a, b, elev.tool === 'guide', id);
270
- elev.lineStart = null;
271
- elev.objs = [{ k: 'line', id }];
272
- afterEdit();
273
- }
274
- /** The drawn line nearest a screen point (within 9 px). */
275
- function lineAt(x: number, y: number): string | null {
276
- const sk = SK(), f = elev.frame, T = elev.view && elevT(elev.view, elev.W, elev.H);
277
- if (!f || !T) return null;
278
- let best: string | null = null, bd = 9;
279
- for (const ln of elevLines(sk, f)) {
280
- const [a, b] = elevLineUZ(f, ln), p = S(T, a[0], a[1]), q = S(T, b[0], b[1]);
281
- const dx = q[0] - p[0], dy = q[1] - p[1], L2 = dx * dx + dy * dy || 1, t = clamp(((x - p[0]) * dx + (y - p[1]) * dy) / L2, 0, 1);
282
- const d = Math.hypot(x - (p[0] + dx * t), y - (p[1] + dy * t));
283
- if (d < bd) { bd = d; best = ln.id; }
273
+ /**
274
+ * Slide a chain of doors and windows along their wall in the plan to `delta` from where it started, no further than
275
+ * what's drawn on the wall's faces can follow without being pushed off them (`base`: what ran past its wall when the
276
+ * slide began; `from`: the last slide that pushed nothing further out). The faces follow as it goes. Returns the
277
+ * slide made.
278
+ */
279
+ export function slideWithinWalls(sk: Sketch, group: SlideGroup, delta: number, from: number, base: Overflow): number {
280
+ const held = planFitState(sk);
281
+ const tryAt = (v: number) => { applySlide(sk, group, v); return !pushedOut(base, planFit(sk)); };
282
+ if (tryAt(delta)) return delta;
283
+ let lo = 0, hi = 1;
284
+ for (let i = 0; i < 8; i++) {
285
+ const m = (lo + hi) / 2;
286
+ restoreFit(sk, held);
287
+ if (tryAt(from + (delta - from) * m)) lo = m; else hi = m;
284
288
  }
285
- return best;
286
- }
287
-
288
- /** What's under a screen point: chips first, then drawn lines, then openings and corners. */
289
- function pickAt(x: number, y: number): ElevAct | null {
290
- const h = hitAt(x, y);
291
- if (h && h.act.k !== 'body' && h.act.k !== 'corner') return h.act;
292
- const l = lineAt(x, y);
293
- if (l) return { k: 'eline', id: l };
294
- return h ? h.act : null;
295
- }
296
-
297
- /** Set a drawn line's length (its first end stays put). */
298
- function editLineLength(id: string): void {
299
- const sk = SK(), f = elev.frame, ln = f && elevLines(sk, f).find(l => l.id === id);
300
- if (!ln) return;
301
- const cur = Math.hypot(ln.b[0] - ln.a[0], ln.b[1] - ln.a[1]);
302
- openKeypad({
303
- title: ln.guide ? 'Guide line length' : 'Line length', initial: fmtLen(cur), selectAll: true, laser: true,
304
- onDone: v => {
305
- if (v <= 0) return;
306
- pushHistory();
307
- const k = v / (cur || 1);
308
- ln.b = [ln.a[0] + (ln.b[0] - ln.a[0]) * k, ln.a[1] + (ln.b[1] - ln.a[1]) * k];
309
- afterEdit();
310
- },
311
- });
289
+ // none of the way: back exactly as it was (solved again from there, the faces can land a hair apart — past the wall)
290
+ restoreFit(sk, held);
291
+ if (lo === 0) return from;
292
+ const to = from + (delta - from) * lo;
293
+ tryAt(to);
294
+ return to;
312
295
  }
296
+ /** In the plan: a wall made shorter than what's on it. */
297
+ export const TOO_SHORT = 'The wall can’t be shorter than what’s on it. Move or remove things on it first.';
298
+ /** The right message for an edit refused by overflow(). */
299
+ export const pastWallMsg = (): string => (elevOpen() ? PAST_WALL : TOO_SHORT);
300
+
301
+ // ---- the dimension chips ----
313
302
 
314
303
  /**
315
- * A tap. On a door/window or a wall corner: select it (`add`: add or remove it — Shift/⌘/Ctrl with a mouse, any tap by touch).
316
- * On a dimension chip: select that dimension. The keypad only opens from the bar's yellow +.
304
+ * What can be tapped in the wall view, in canvas pixels, for tests: the doors' and windows' bodies, cabinets, the
305
+ * wall's corners (its end edges), and the dimension chips as last drawn (with their look).
317
306
  */
318
- function tap(a: ElevAct | null, add: boolean): void {
319
- if (a && (a.k === 'body' || a.k === 'corner' || a.k === 'eline')) {
320
- const o: Obj = a.k === 'body' ? { k: 'op', id: a.op } : a.k === 'eline' ? { k: 'line', id: a.id } : { k: 'corner', end: a.end }, key = objKey(o);
321
- elev.active = null;
322
- if (add) elev.objs = elev.objs.some(x => objKey(x) === key) ? elev.objs.filter(x => objKey(x) !== key) : [...elev.objs, o];
323
- else elev.objs = [o];
324
- renderElevation();
325
- return;
326
- }
327
- elev.objs = [];
328
- selectDim(a);
329
- }
330
-
331
- /** Select an elevation dimension (null clears): yellow border and the bar with its name and the yellow +. */
332
- function selectDim(a: ElevAct | null): void {
333
- elev.active = a ? JSON.stringify(a) : null;
334
- renderElevation();
335
- }
336
-
337
- /** What the + does for the selected objects, with the bar's name for it (null: nothing to dimension). */
338
- function objPlan(): { name: string; run: () => void } | null {
339
- const sk = SK(), f = elev.frame, objs = elev.objs;
340
- if (!f || !objs.length) return null;
341
- const ops = elevOpenings(sk, f), seen = (id: string) => ops.find(o => o.id === id);
342
- const label = (id: string) => (sk.openings[id].type === 'door' ? 'Door' : 'Window');
343
- const opsSel = objs.filter((o): o is { k: 'op'; id: string } => o.k === 'op').map(o => seen(o.id)).filter((o): o is ElevOpening => !!o);
344
- const corners = objs.filter((o): o is { k: 'corner'; end: 'a' | 'b' } => o.k === 'corner');
345
- const lines = objs.filter((o): o is { k: 'line'; id: string } => o.k === 'line');
346
- if (objs.length === 1 && lines.length === 1) {
347
- const ln = elevLines(sk, f).find(l => l.id === lines[0].id);
348
- if (!ln) return null;
349
- return { name: (ln.guide ? 'Guide line ' : 'Line ') + fmtLen(Math.hypot(ln.b[0] - ln.a[0], ln.b[1] - ln.a[1])), run: () => editLineLength(ln.id) };
307
+ export function elevHits(): { x: number; y: number; w: number; h: number; act: ElevAct | { k: 'body'; op: string } | { k: 'cab'; id: string } | { k: 'corner'; end: 'a' | 'b' }; look?: string }[] {
308
+ const f = elev.frame;
309
+ if (!elevOpen() || !f) return [];
310
+ const T = mainT(), out: ReturnType<typeof elevHits> = [];
311
+ for (const o of elevOpenings(planSK(), f)) {
312
+ const [x0, y0] = S(T, o.u0, o.head), [x1, y1] = S(T, o.u1, o.sill);
313
+ out.push({ x: x0, y: y0, w: x1 - x0, h: y1 - y0, act: { k: 'body', op: o.id } });
350
314
  }
351
- if (lines.length) return { name: objs.length + ' selected', run: () => toast('Select one line to set its length.') };
352
- if (objs.length === 1 && opsSel.length === 1) return { name: label(opsSel[0].id), run: () => editOpeningDim(opsSel[0].id, 'w') };
353
- if (objs.length === 1 && corners.length === 1) return { name: 'Corner', run: () => toast('Select a door or window too (Shift-tap), then + for the distance between them.') };
354
- if (objs.length === 2 && opsSel.length === 2) {
355
- const [l, r] = [...opsSel].sort((p, q) => p.u0 - q.u0), t = pickBetween(sk, l.id, l.e1, r.id, r.e0);
356
- return { name: label(l.id) + ' + ' + label(r.id).toLowerCase(), run: () => editElevationPosition(t.op, t.edge, t.ref, 'Space between') };
315
+ for (const id of Object.keys((SK() as WallFace).cabs ?? {})) {
316
+ const b = cabBox(SK() as WallFace, id);
317
+ if (!b) continue;
318
+ const [x0, y0] = S(T, b.u0, b.z1), [x1, y1] = S(T, b.u1, b.z0);
319
+ out.push({ x: x0, y: y0, w: x1 - x0, h: y1 - y0, act: { k: 'cab', id } });
357
320
  }
358
- if (objs.length === 2 && opsSel.length === 1 && corners.length === 1) {
359
- const o = opsSel[0], end = corners[0].end, leftCorner = end === f.leftEnd;
360
- const ref: OpeningRef = { face: end, line: f.lid, side: f.side as 1 | -1 };
361
- return { name: label(o.id) + ' + corner', run: () => editElevationPosition(o.id, leftCorner ? o.e0 : o.e1, ref, 'Distance from the corner') };
321
+ for (const [u, end] of [[f.face[0], f.leftEnd], [f.face[1], f.leftEnd === 'a' ? 'b' : 'a']] as const) {
322
+ const [x, yTop] = S(T, u, f.H), [, yBot] = S(T, u, 0);
323
+ out.push({ x: x - 10, y: yTop, w: 20, h: yBot - yTop, act: { k: 'corner', end } });
362
324
  }
363
- if (corners.length === 2 && objs.length === 2) return { name: 'Both corners', run: () => toast('The wall’s length is set in the plan. Go back and use the wall’s +.') };
364
- return { name: objs.length + ' selected', run: () => toast('Select two things — two openings, or an opening and a corner — to dimension between them.') };
365
- }
366
- export interface ElevBarAction { icon: string; label: string; run: () => void }
367
- /** The wall view's bar: what's selected, its actions, and whether the yellow + shows. Null: no bar. */
368
- export interface ElevBar { label: string; plus: boolean; actions: ElevBarAction[] }
369
-
370
- /** The bar: the selected dimension, or the selected objects (with Height / Sill for a single opening). */
371
- export function elevBar(dimAct: ElevAct | null): ElevBar | null {
372
- const plan = dimAct ? null : objPlan();
373
- if (!dimAct && !plan) return null;
374
- if (dimAct && dimAct.k === 'len') return { label: 'Wall length · set in the floor plan', plus: false, actions: [{ icon: 'back', label: 'Go to plan', run: goToPlan }] };
375
- if (dimAct) return { label: dimName(dimAct), plus: true, actions: [] };
376
- const actions: ElevBarAction[] = [];
377
- const one = elev.objs.length === 1 && elev.objs[0].k === 'op' ? SK().openings[elev.objs[0].id] : null;
378
- if (one) {
379
- const id = (elev.objs[0] as { id: string }).id;
380
- actions.push({ icon: 'v', label: 'Height', run: () => editOpeningHeight(id) });
381
- if (one.type === 'window') actions.push({ icon: 'h', label: 'Sill', run: () => editSill(id) });
382
- }
383
- return { label: plan!.name, plus: true, actions };
325
+ for (const h of ed.hitChips) if (h.kind === 'elev') out.push({ x: h.x, y: h.y, w: h.w, h: h.h, act: JSON.parse(h.id) as ElevAct, look: h.part });
326
+ return out;
327
+ }
328
+
329
+ export const elevAct = (id: string): ElevAct => JSON.parse(id) as ElevAct;
330
+
331
+ /** A chip's name, as the bar shows it. */
332
+ export function elevChipName(a: ElevAct): string {
333
+ if (a.k === 'gap') return a.title;
334
+ if (a.k === 'len') return 'Wall length · set in the floor plan';
335
+ if (a.k === 'wallH') return 'Wall height';
336
+ if (a.k === 'pos') return a.title;
337
+ if (a.k === 'fdim') return 'Dimension';
338
+ if (a.k === 'depth') return 'Cabinet depth · out from the wall';
339
+ const o = planSK().openings[a.op], n = o ? (o.type === 'door' ? 'Door' : 'Window') : '';
340
+ return a.k === 'w' ? n + ' width' : a.k === 'sill' ? n + ' sill height' : n + ' height';
384
341
  }
385
342
 
386
- const dimName = (a: ElevAct): string => {
387
- const sk = SK(), o = 'op' in a ? sk.openings[a.op] : null, n = o ? (o.type === 'door' ? 'Door' : 'Window') : '';
388
- return a.k === 'w' ? n + ' width' : a.k === 'sill' ? n + ' sill height' : a.k === 'h' ? n + ' height' : a.k === 'wallH' ? 'Wall height'
389
- : a.k === 'pos' ? a.title : '';
390
- };
343
+ /** The yellow + on a selected chip: its keypad. */
344
+ export function editElevChip(a: ElevAct): void {
345
+ if (a.k === 'w') editOpeningDim(a.op, 'w');
346
+ else if (a.k === 'sill') editSill(a.op);
347
+ else if (a.k === 'h') editOpeningHeight(a.op);
348
+ else if (a.k === 'wallH') editWallHeight(elev.lid!);
349
+ else if (a.k === 'pos') editElevationPosition(a.op, a.edge, a.ref, a.title);
350
+ else if (a.k === 'gap') dimensionFace(a.kind, a.a, a.b, a.title);
351
+ else if (a.k === 'depth') editCabinetDepth(a.cab);
352
+ else if (a.k === 'len') goToPlan();
353
+ }
391
354
 
392
- /** The window whose locked sill height a selected chip shows, if any. */
393
- function lockedSill(a: ElevAct | null) {
394
- if (!a || a.k !== 'sill') return null;
395
- const o = SK().openings[a.op];
355
+ /** The window whose locked sill height a chip shows, if any. */
356
+ function lockedSill(a: ElevAct) {
357
+ if (a.k !== 'sill') return null;
358
+ const o = planSK().openings[a.op];
396
359
  return o && o.sillLocked ? o : null;
397
360
  }
398
361
 
399
- /** The stored door/window dimension a selected position chip shows, if any. */
400
- function storedDim(a: ElevAct | null): { op: string; d: OpeningDim } | null {
401
- if (!a || a.k !== 'pos') return null;
402
- const o = SK().openings[a.op], d = o && (o.dims || []).find(x => x.edge === a.edge && sameRef(x.ref, a.ref));
362
+ /** The stored door/window dimension a position chip shows, if any. */
363
+ function storedDim(a: ElevAct): { op: string; d: OpeningDim } | null {
364
+ if (a.k !== 'pos') return null;
365
+ const o = planSK().openings[a.op], d = o && (o.dims || []).find(x => x.edge === a.edge && sameRef(x.ref, a.ref));
403
366
  return d ? { op: a.op, d } : null;
404
367
  }
405
368
 
406
- /**
407
- * Delete (trash or the Delete key). Selected doors/windows are deleted (with Undo), along with dimensions that
408
- * measure from them. A selected dimension: a locked one is freed — it stays as a reference — and a reference is removed.
409
- */
410
- export function deleteSelectedElevDim(): void {
411
- const doomed = elev.objs.filter((o): o is { k: 'op'; id: string } => o.k === 'op').map(o => o.id);
412
- const doomedLines = elev.objs.filter((o): o is { k: 'line'; id: string } => o.k === 'line').map(o => o.id);
413
- if (!elev.active && (doomed.length || doomedLines.length)) {
414
- const sk = SK(), n = doomed.length + doomedLines.length, one = doomed.length === 1 && !doomedLines.length ? sk.openings[doomed[0]] : null;
369
+ /** Whether the trash does something for a selected chip: frees a locked one, or removes a reference. */
370
+ export const elevChipDeletable = (a: ElevAct): boolean => !!storedDim(a) || !!lockedSill(a);
371
+
372
+ /** The trash on a selected chip: a locked door/window dimension is freed (it stays as a reference), a reference is removed, a locked sill is freed. */
373
+ export function deleteElevChip(a: ElevAct): void {
374
+ // a cabinet's entered depth: back to the standard one (grey), as an entered size is wiped
375
+ if (a.k === 'depth') {
376
+ const cb = (SK() as WallFace).cabs?.[a.cab];
377
+ if (!cb) return;
378
+ if (!cb.depthSet) { toast('That’s the standard depth. Tap + to enter one.', { warn: true }); return; }
415
379
  pushHistory();
416
- deleteSel(sk, doomed.map(id => ({ type: 'opening' as const, id })));
417
- const key = elev.frame && elevKey(elev.frame.lid, elev.frame.side);
418
- if (key && sk.elev?.[key]) sk.elev[key] = sk.elev[key].filter(l => !doomedLines.includes(l.id));
419
- elev.objs = elev.objs.filter(o => o.k === 'corner');
420
- ed.sel = ed.sel.filter(x => !(x.type === 'opening' && doomed.includes(x.id)));
380
+ cb.depth = CAB.d; cb.depthSet = false;
421
381
  afterEdit();
422
- const what = one ? (one.type === 'door' ? 'Door' : 'Window') : n === 1 ? 'Line' : n + ' items';
423
- toast(what + ' deleted', { action: { label: 'Undo', fn: () => undo() } });
382
+ toast('Depth cleared — back to the standard ' + fmtLen(CAB.d) + '.', { action: { label: 'Undo', fn: () => undo() } });
424
383
  return;
425
384
  }
426
- const a = elev.active ? (JSON.parse(elev.active) as ElevAct) : null, s = storedDim(a);
427
385
  const ls = lockedSill(a);
428
- if (ls) {
429
- pushHistory();
430
- ls.sillLocked = false;
431
- afterEdit();
432
- toast('Sill height freed — drag the window to raise or lower it.');
433
- return;
434
- }
435
- if (!s) { if (a) toast('Only locked dimensions and door/window position dimensions can be deleted here.'); return; }
436
- const o = SK().openings[s.op], name = o.type === 'door' ? 'door' : 'window';
386
+ if (ls) { pushHistory(); ls.sillLocked = false; afterEdit(); toast('Sill height freed — drag the window to raise or lower it.'); return; }
387
+ const s = storedDim(a);
388
+ if (!s) { toast('Only locked dimensions and door/window position dimensions can be deleted here.', { warn: true }); return; }
389
+ const o = planSK().openings[s.op], name = o.type === 'door' ? 'door' : 'window';
437
390
  pushHistory();
438
391
  if (s.d.driving) { s.d.driving = false; afterEdit(); toast('Now a reference — it no longer sets the ' + name + '’s position.'); }
439
- else { o.dims = (o.dims || []).filter(x => x !== s.d); afterEdit(); toast('Dimension removed'); }
392
+ else { o.dims = (o.dims || []).filter(x => x !== s.d); ed.sel = []; afterEdit(); toast('Dimension removed'); }
440
393
  }
441
394
 
442
395
  /** Back to the floor plan with this wall selected, ready for its + (where its length is set). */
443
396
  function goToPlan(): void {
444
- const lid = elev.lid;
445
397
  closeElevation();
446
- if (!lid) return;
447
- ed.sel = [{ type: 'line', id: lid }];
448
- updateCtx(); requestDraw();
449
398
  toast('Tap + to change the wall’s length.');
450
399
  }
451
400
 
452
- /** The yellow +: the keypad for the selected dimension (or what the selected things measure). */
453
- export function editSelected(): void {
454
- const a = elev.active ? (JSON.parse(elev.active) as ElevAct) : null;
455
- if (!a) { objPlan()?.run(); return; }
456
- if (a.k === 'w') editOpeningDim(a.op, 'w');
457
- else if (a.k === 'sill') editSill(a.op);
458
- else if (a.k === 'h') editOpeningHeight(a.op);
459
- else if (a.k === 'wallH') editWallHeight(elev.lid!);
460
- else if (a.k === 'pos') editElevationPosition(a.op, a.edge, a.ref, a.title);
461
- else if (a.k === 'len') goToPlan();
401
+ // ---- doors and windows on the wall ----
402
+
403
+ /** Where a new door/window would go for a pointer at (u, z): centre s along the wall, and the window's sill. */
404
+ export function openingAt(type: 'door' | 'window', u: number, z: number, tol = 0): { at: number; sill: number } | null {
405
+ const f = elev.frame!, w = NEW_W;
406
+ if (f.L < w + 2) return null;
407
+ // snapped (Object snapping) as a door or window dragged on the wall is: its sides to the corners and the other
408
+ // doors', windows' and cabinets' sides; a window's sill and head to the floor, the ceiling, cabinet tops and other
409
+ // windows' (a door sits on the floor)
410
+ const raw = type === 'door' ? 0 : z - WINDOW_H / 2, h = type === 'door' ? DOOR_H : WINDOW_H;
411
+ const [du, dz] = tol > 0 ? snapObjectMove({}, { u0: u - w / 2, u1: u + w / 2, z0: raw, z1: raw + h }, 0, 0, tol) : [0, 0];
412
+ const at = clamp(toU(f, u + du), w / 2, f.L - w / 2);
413
+ const q = 1 / settings.denom, sill = type === 'door' ? 0 : clamp(Math.round((raw + dz) / q) * q, 0, Math.max(0, f.H - WINDOW_H));
414
+ return { at, sill };
462
415
  }
463
- // ---- pointers: one finger or the mouse pans, two fingers pinch, the wheel zooms; tap selects; drag moves a door/window ----
464
-
465
- const gp = new Map<number, { x: number; y: number }>();
466
- let pinch: { d: number; s: number } | null = null;
467
- let down: { x: number; y: number; moved: boolean } | null = null, drag: Drag | null = null;
468
- /** middle mouse button: always pans; a press that started a line (drag to draw) */
469
- let panBtn = false, pressStartedLine = false, mid: { x: number; y: number } | null = null;
470
- onSessionReset(() => { gp.clear(); pinch = null; down = null; drag = null; panBtn = false; pressStartedLine = false; mid = null; });
471
-
472
- function zoomElevAt(sx: number, sy: number, f: number): void {
473
- const v = elev.view!;
474
- const u = v.cu + (sx - elev.W / 2) / v.s, z = v.cz - (sy - elev.H / 2) / v.s;
475
- v.s = clamp(v.s * f, 0.05, 60);
476
- v.cu = u - (sx - elev.W / 2) / v.s; v.cz = z + (sy - elev.H / 2) / v.s;
477
- renderElevation();
478
- }
479
- const drawing = () => elev.tool === 'line' || elev.tool === 'guide';
480
- const endDrag = () => { if (elev.dragOp) { elev.dragOp = null; afterEdit(); } };
481
-
482
- /** Pointers on the elevation canvas, in canvas pixels; drags measure from `cx`/`cy` (window pixels) when given. */
483
- export function elevPointerDown(e: PointerIn): void {
484
- const p = { x: e.x, y: e.y };
485
- gp.set(e.id, p); pinch = null; mid = null;
486
- down = gp.size === 1 ? { ...p, moved: false } : null;
487
- panBtn = e.button === 1;
488
- // a second finger while a press is drawing a line: it's a pinch, not a line
489
- if (gp.size > 1 && pressStartedLine) { elev.lineStart = null; elev.cursor = null; renderElevation(); }
490
- pressStartedLine = false;
491
- drag = null;
492
- if (!down || panBtn || !elev.view) return;
493
- if (drawing()) {
494
- // first point now (drag to draw), or the second point of a tap-tap line
495
- const sp = snapUZ(p.x, p.y, elev.lineStart);
496
- elev.cursor = sp;
497
- if (!elev.lineStart) { elev.lineStart = sp.p; pressStartedLine = true; renderElevation(); }
498
- else finishLine(sp.p);
499
- return;
500
- }
501
- if (elev.tool !== 'select') return; // door/window: placed on release (a drag pans instead)
502
- const h = hitAt(p.x, p.y);
503
- drag = h && h.act.k === 'body' ? startDrag(h.act.op, e.cx ?? e.x, e.cy ?? e.y) : null;
504
- }
505
-
506
- export function elevPointerMove(e: PointerIn): void {
507
- const prev = gp.get(e.id), p = { x: e.x, y: e.y };
508
- if (!prev) {
509
- // hover (mouse): cursor, and previews for the drawing tools
510
- if (e.kind !== 'mouse' || !elev.view) return;
511
- if (elev.tool === 'select') { const h = pickAt(p.x, p.y); setCursor(!h ? '' : h.k === 'body' ? 'grab' : 'pointer', 'elevation'); return; }
512
- elev.cursor = snapUZ(p.x, p.y, elev.lineStart);
513
- renderElevation();
514
- return;
416
+
417
+ function placeOpening(type: 'door' | 'window', u: number, z: number, tol = 0): void {
418
+ const sk = planSK(), f = elev.frame!, spot = openingAt(type, u, z, tol);
419
+ if (!spot) { toast('That wall is too short for a ' + fmtLen(NEW_W) + ' ' + type + '.', { warn: true }); return; }
420
+ pushHistory();
421
+ const id = uid('o');
422
+ // a door swings toward the side you're looking from
423
+ sk.openings[id] = { line: f.lid, at: spot.at, w: NEW_W, wSet: false, type, flip: f.side !== 1, ...(type === 'window' ? { sill: spot.sill } : {}) };
424
+ // (placed, not selected: tap it to size it)
425
+ ed.sel = [];
426
+ afterEdit();
427
+ }
428
+
429
+ const nameOf = (op: string) => (planSK().openings[op].type === 'door' ? 'door' : 'window');
430
+
431
+ /** What dragging an opening will do, given its locks. */
432
+ function dragHint(op: string): string {
433
+ const sk = planSK(), o = sk.openings[op], locked = !slideGroup(sk, op), n = nameOf(op);
434
+ if (o.type === 'door') return locked ? 'This door is locked by a dimension. Change the dimension, or make it a reference, to move it.' : 'Drag the door to slide it along the floor.';
435
+ if (locked && o.sillLocked) return 'This window is locked along the wall and in height. Select a blue dimension and press Delete to free it.';
436
+ if (o.sillLocked) return 'This window’s height above the floor is locked — it only slides along the wall. Delete the blue sill dimension to free it.';
437
+ return locked ? 'This window is locked along the wall by a dimension — drag it to raise or lower it.' : 'Drag the ' + n + ' to move it along the wall or up and down.';
438
+ }
439
+
440
+ /**
441
+ * Dragging a door or window on the wall: along it — or, if it's locked to other openings, the whole free chain it's
442
+ * part of (a dimension between openings fixes their spacing, not where they sit) — unless the chain is locked to the
443
+ * wall itself. Windows also move up and down; doors stay on the floor. The sill snaps to the display precision.
444
+ */
445
+ export interface OpeningDrag {
446
+ op: string; group: SlideGroup | null; sill: number; lockedH: boolean; started: boolean; box: { u0: number; u1: number; z0: number; z1: number } | null;
447
+ /** what on the wall was past it when the drag began, and the last move that pushed nothing further out */
448
+ base?: Overflow; last?: { du: number; dz: number };
449
+ }
450
+ export function startOpeningDrag(op: string): OpeningDrag | null {
451
+ const sk = planSK(), o = sk.openings[op];
452
+ if (!o) return null;
453
+ const group = slideGroup(sk, op), e = elev.frame ? elevOpenings(sk, elev.frame).find(x => x.id === op) : null;
454
+ return { op, group, sill: openingHeights(o).sill, lockedH: !group, started: false, box: e ? { u0: e.u0, u1: e.u1, z0: e.sill, z1: e.head } : null };
455
+ }
456
+ /**
457
+ * Move a drag to (du, dz) inches from where it started, snapping to corners and the other objects (within `tol`
458
+ * inches). Returns false if it can't move at all (a locked door).
459
+ */
460
+ export function moveOpeningDrag(d: OpeningDrag, du: number, dz: number, tol = 0): boolean {
461
+ if (d.box && tol > 0) [du, dz] = snapObjectMove({ op: d.op }, d.box, du, dz, tol);
462
+ const sk = planSK(), o = sk.openings[d.op], f = elev.frame, g = o && openingSpan(sk, o), l = o && sk.lines[o.line];
463
+ if (!o || !f || !g || !l) return false;
464
+ if (!d.started) {
465
+ if (d.lockedH && (o.type === 'door' || !!o.sillLocked)) { toast(dragHint(d.op), { warn: true }); return false; }
466
+ if (d.lockedH || o.sillLocked) toast(dragHint(d.op), { warn: true });
467
+ d.started = true;
515
468
  }
516
- if (!elev.view) return;
517
- if (down && !down.moved) { if (Math.hypot(p.x - down.x, p.y - down.y) < 6) { if (drawing()) { elev.cursor = snapUZ(p.x, p.y, elev.lineStart); renderElevation(); } return; } down.moved = true; }
518
- gp.set(e.id, p);
519
- if (drawing() && gp.size === 1 && !panBtn) { elev.cursor = snapUZ(p.x, p.y, elev.lineStart); renderElevation(); return; }
520
- if (gp.size === 2) {
521
- // two fingers: pinch to zoom and move to pan
522
- const [a, b] = [...gp.values()], m = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
523
- if (mid) { elev.view.cu -= (m.x - mid.x) / elev.view.s; elev.view.cz += (m.y - mid.y) / elev.view.s; }
524
- mid = m;
469
+ const face = faceEdit.key ? SK() : null;
470
+ /** The opening at (u, z) from where it started, and what's drawn on the face following it (cabinets tied to it). */
471
+ const place = (u: number, z: number) => {
472
+ // (a slide is measured from where the chain started)
473
+ if (d.group) applySlide(sk, d.group, f.mirror ? -u : u);
474
+ if (o.type === 'window' && !o.sillLocked) {
475
+ // kept between the floor and the ceiling — but one already past them (pushed there before) isn't yanked back
476
+ // at the first touch: that dragged whatever's tied to it along, through the floor
477
+ const { sill, head } = openingHeights(o), q = 1 / settings.denom;
478
+ o.sill = clamp(Math.round((d.sill + z) / q) * q, Math.min(0, d.sill), Math.max(0, wallHeight(l) - (head - sill), d.sill));
479
+ }
480
+ resolveOpeningsNow();
481
+ // what's drawn on the face follows the opening's corners as it moves
482
+ if (faceEdit.key) syncFace(sk, faceEdit.key);
483
+ };
484
+ if (!face) { place(du, dz); requestDraw(); return true; }
485
+ // what's tied to it (a cabinet a set distance below a window) can't be pushed off the wall — past its floor,
486
+ // ceiling or ends: the opening goes as far as that allows and stops there, as a cabinet dragged to the edge does
487
+ d.base ??= wallOverflow(face);
488
+ const from = d.last ?? { du: 0, dz: 0 }, held = holdFace(sk, face);
489
+ const at = (t: number) => ({ du: from.du + (du - from.du) * t, dz: from.dz + (dz - from.dz) * t });
490
+ const fits = () => !pushedOut(d.base!, wallOverflow(face));
491
+ place(du, dz);
492
+ let to = { du, dz };
493
+ if (!fits()) {
494
+ let lo = 0, hi = 1;
495
+ for (let i = 0; i < 8; i++) {
496
+ const m = (lo + hi) / 2;
497
+ putBack(sk, face, held); place(at(m).du, at(m).dz);
498
+ if (fits()) lo = m; else hi = m;
499
+ }
500
+ putBack(sk, face, held);
501
+ // (none of the way: left exactly as it was — solved again, it can land a hair apart)
502
+ to = at(lo);
503
+ if (lo > 0) place(to.du, to.dz);
525
504
  }
526
- if (drag && gp.size === 1 && down) {
527
- moveDrag(drag, ((e.cx ?? e.x) - drag.cx) / elev.view.s, -((e.cy ?? e.y) - drag.cy) / elev.view.s);
528
- if (!elev.dragOp) drag = null; // refused (locked door)
529
- return;
505
+ d.last = to;
506
+ requestDraw();
507
+ return true;
508
+ }
509
+
510
+ /** The doors' and windows' places in the plan and what's drawn on the face, to put back if a move is taken back. */
511
+ function holdFace(sk: Sketch, face: Sketch) {
512
+ return { ops: snapOpenings(sk), pos: snapshotPos(face), marks: placedMarks() };
513
+ }
514
+ function putBack(sk: Sketch, face: Sketch, h: ReturnType<typeof holdFace>): void {
515
+ putOpenings(sk, h.ops);
516
+ restorePos(face, h.pos);
517
+ setPlacedMarks(h.marks);
518
+ forgetSynced();
519
+ }
520
+
521
+ /**
522
+ * Where a door or window sliding along its wall in the plan can snap its edges: the wall's ends, its corners on both
523
+ * sides, and the edges of the other doors and windows on it — not those sliding with it (locked to it in a chain).
524
+ * Empty when Object snapping is off.
525
+ */
526
+ /**
527
+ * Where a door or window placed on wall `lid` in the plan snaps its edges (Object snapping): the wall's ends, its
528
+ * corners on both sides, and the edges of the doors and windows already on it — as one slid along it does.
529
+ */
530
+ export function placeTargets(sk: Sketch, lid: string): number[] {
531
+ const l = sk.lines[lid];
532
+ if (!l || !settings.layers.objSnap) return [];
533
+ const A = sk.points[l.a], B = sk.points[l.b], out = [0, Math.hypot(B.x - A.x, B.y - A.y)];
534
+ for (const side of [1, -1] as const) { const wf = wallFace(sk, lid, side); if (wf) out.push(wf.s0, wf.s1); }
535
+ for (const x of Object.values(sk.openings)) {
536
+ if (x.line !== lid) continue;
537
+ const g = openingSpan(sk, x);
538
+ if (g) out.push(edgeS(x, g.w, 's0'), edgeS(x, g.w, 's1'));
530
539
  }
531
- if (drag) { endDrag(); drag = null; } // a second finger: stop dragging, pinch instead
532
- if (gp.size === 1) { elev.view.cu -= (p.x - prev.x) / elev.view.s; elev.view.cz += (p.y - prev.y) / elev.view.s; renderElevation(); return; }
533
- const [a, b] = [...gp.values()], d = Math.hypot(a.x - b.x, a.y - b.y);
534
- if (!pinch) { pinch = { d, s: elev.view.s }; return; }
535
- zoomElevAt((a.x + b.x) / 2, (a.y + b.y) / 2, (pinch.s * (d / pinch.d)) / elev.view.s);
536
- }
537
-
538
- export function elevPointerUp(e: PointerIn): void {
539
- const tapped = down && !down.moved && gp.size === 1;
540
- gp.delete(e.id); pinch = null;
541
- if (panBtn) { panBtn = false; down = null; return; }
542
- if (drawing()) {
543
- // a drag from the first point draws the line on release; a tap waits for the second tap
544
- if (pressStartedLine && down?.moved && elev.lineStart) finishLine(snapUZ(e.x, e.y, elev.lineStart).p);
545
- pressStartedLine = false; down = null;
546
- return;
540
+ return out;
541
+ }
542
+
543
+ export function slideTargets(sk: Sketch, op: string, group: SlideGroup): number[] {
544
+ const o = sk.openings[op], l = o && sk.lines[o.line];
545
+ if (!o || !l || !settings.layers.objSnap) return [];
546
+ // which move with it: slide the chain a little and see
547
+ const before = Object.fromEntries(Object.entries(sk.openings).map(([id, x]) => [id, x.at]));
548
+ applySlide(sk, group, group.hi > 0.25 ? 0.25 : group.lo < -0.25 ? -0.25 : (group.hi || group.lo)); resolveOpeningsNow();
549
+ const moving = new Set(Object.keys(sk.openings).filter(id => Math.abs(sk.openings[id].at - before[id]) > 1e-9));
550
+ applySlide(sk, group, 0); resolveOpeningsNow();
551
+ const A = sk.points[l.a], B = sk.points[l.b], out = [0, Math.hypot(B.x - A.x, B.y - A.y)];
552
+ for (const side of [1, -1] as const) { const wf = wallFace(sk, o.line, side); if (wf) out.push(wf.s0, wf.s1); }
553
+ for (const [id, x] of Object.entries(sk.openings)) {
554
+ if (x.line !== o.line || moving.has(id) || id === op) continue;
555
+ const g = openingSpan(sk, x);
556
+ if (g) out.push(edgeS(x, g.w, 's0'), edgeS(x, g.w, 's1'));
547
557
  }
548
- if ((elev.tool === 'door' || elev.tool === 'window') && tapped && elev.view) {
549
- const [u, z] = toWorld(down!.x, down!.y);
550
- if (z < -2 || z > (elev.frame?.H ?? 0) + 2) toast('Tap on the wall to place it.');
551
- else placeOpening(elev.tool, u, z);
552
- down = null;
553
- return;
558
+ return out;
559
+ }
560
+
561
+ /** A slide `delta` of a door or window (centre `at0`, width `w`, when the drag began) pulled so an edge meets the nearest target within `tol`. */
562
+ export function snapSlide(at0: number, w: number, delta: number, targets: number[], tol: number): number {
563
+ let best: number | null = null;
564
+ for (const e of [at0 + delta - w / 2, at0 + delta + w / 2]) for (const t of targets) if (Math.abs(t - e) < tol && (best == null || Math.abs(t - e) < Math.abs(best))) best = t - e;
565
+ return delta + (best ?? 0);
566
+ }
567
+
568
+ // ---- the wall tools ----
569
+
570
+ /** A ghost of what a placing tool would put at the pointer. */
571
+ function ghost(c: DrawCtx, T: Xform, u0: number, z0: number, w: number, h: number, label?: string): void {
572
+ const [x0, y0] = S(T, u0, z0 + h), [x1, y1] = S(T, u0 + w, z0);
573
+ c.save();
574
+ c.fillStyle = 'rgba(0,102,255,.08)'; c.fillRect(x0, y0, x1 - x0, y1 - y0);
575
+ c.strokeStyle = TH.blue; c.lineWidth = 1.5; c.setLineDash([6, 4]); c.strokeRect(x0, y0, x1 - x0, y1 - y0);
576
+ c.restore();
577
+ if (label) previewChip(c, label, (x0 + x1) / 2, y0 - 16);
578
+ }
579
+
580
+ /** On the wall (with a little slack), or not. */
581
+ const onWall = (u: number, z: number): boolean => { const f = elev.frame; return !!f && z >= -2 && z <= f.H + 2 && u >= f.face[0] - 2 && u <= f.face[1] + 2; };
582
+
583
+ interface PlacingState { down?: PEv; far?: boolean }
584
+
585
+ /** A tool that does something where the wall is tapped: a ghost follows the pointer, a tap acts (a drag doesn't). */
586
+ /**
587
+ * A tool that places something where the wall is tapped, a ghost of it following the pointer first. `tol`: how near
588
+ * (inches) it snaps to what's on the wall — a finger's reach or a mouse's, as a drag snaps (Object snapping).
589
+ */
590
+ function placingTool(o: { preview: (c: DrawCtx, T: Xform, u: number, z: number, tol: number) => void; place: (u: number, z: number, tol: number) => void; hint: string }): Tool {
591
+ const tolOf = (ev: PEv) => (ev.touch ? 16 : 10) / mainT().s;
592
+ return {
593
+ st: {} as PlacingState,
594
+ reset() { this.st = {}; ed.preview = null; },
595
+ hover(ev: PEv) {
596
+ const tol = tolOf(ev);
597
+ ed.preview = onWall(ev.wx, ev.wy) ? (c, T) => o.preview(c, T, ev.wx, ev.wy, tol) : null;
598
+ requestOverlayDraw();
599
+ },
600
+ down(ev: PEv) { this.st = { down: ev, far: false }; this.hover!(ev); },
601
+ move(ev: PEv) {
602
+ const st = this.st as PlacingState;
603
+ if (st.down && Math.hypot(ev.sx - st.down.sx, ev.sy - st.down.sy) > (ev.touch ? 12 : 6)) st.far = true;
604
+ this.hover!(ev);
605
+ },
606
+ up(ev: PEv) {
607
+ const st = this.st as PlacingState;
608
+ this.st = {};
609
+ if (ev.touch) ed.preview = null;
610
+ requestOverlayDraw();
611
+ if (!st.down || st.far) return;
612
+ if (!onWall(ev.wx, ev.wy)) { toast('Tap on the wall to place it.', { warn: true }); return; }
613
+ o.place(ev.wx, ev.wy, tolOf(ev));
614
+ },
615
+ hint: () => o.hint,
616
+ };
617
+ }
618
+
619
+ const openingTool = (type: 'door' | 'window'): Tool => placingTool({
620
+ preview(c, T, u, z, tol) {
621
+ const spot = openingAt(type, u, z, tol), f = elev.frame;
622
+ if (!spot || !f) return;
623
+ const a = toU(f, spot.at - NEW_W / 2), b = toU(f, spot.at + NEW_W / 2);
624
+ ghost(c, T, Math.min(a, b), spot.sill, NEW_W, type === 'door' ? DOOR_H : WINDOW_H);
625
+ },
626
+ place: (u, z, tol) => placeOpening(type, u, z, tol),
627
+ hint: type === 'door' ? 'Tap the wall to place a 3\'-0" door. It sits on the floor where you tap.' : 'Tap the wall to place a 3\'-0" window, centered where you tap.',
628
+ });
629
+
630
+ export const wallDoorTool = openingTool('door');
631
+ export const wallWindowTool = openingTool('window');
632
+
633
+ export const cabinetTool = placingTool({
634
+ preview(c, T, u, z) { const spot = cabinetSpot(u, z); if (spot) ghost(c, T, spot.u0, spot.z0, CAB.w, CAB.h, fmtLen(CAB.w) + ' × ' + fmtLen(CAB.h)); },
635
+ place: (u, z) => { addCabinet(u, z); },
636
+ hint: 'Tap the wall to place a cabinet (24" wide, 34½" high, 24" deep) — anywhere, like a window. Tap it, then one of its dimensions, to set it.',
637
+ });
638
+
639
+ export const heightTool = placingTool({
640
+ preview(c, T, _u, z) {
641
+ const f = elev.frame;
642
+ if (!f) return;
643
+ const q = 1 / settings.denom, h = clamp(Math.round(z / q) * q, 0, f.H), [x0, y] = S(T, f.face[0], h), [x1] = S(T, f.face[1], h);
644
+ c.save(); c.strokeStyle = TH.blue; c.lineWidth = 1.5; c.setLineDash([6, 4]); c.beginPath(); c.moveTo(x0, y); c.lineTo(x1, y); c.stroke(); c.restore();
645
+ previewChip(c, fmtLen(h), x1 - 40, y - 16);
646
+ },
647
+ place: (_u, z) => {
648
+ const q = 1 / settings.denom, start = clamp(Math.round(z / q) * q, 0, elev.frame!.H);
649
+ openKeypad({ title: 'Height line', sub: 'Floor to the line — it runs across the whole wall', initial: fmtLen(start), selectAll: true, laser: true, onDone: v => { addHeightLine(v); } });
650
+ },
651
+ hint: 'Tap the wall at a height, then enter it: a level line across the wall (a counter, a rail).',
652
+ });
653
+
654
+ /** The wall view's toolbar: the plan's drawing tools, then what goes on a wall. (The height line tool is kept off it for now.) */
655
+ export const WALL_RAIL: RailItem[] = [
656
+ ['select', 'Select', 'V'], ['line', 'Line', 'L'], ['freehand', 'Draw to shape', 'S'], ['rect', 'Rectangle', 'R'], ['circle', 'Circle', 'C'], ['arc', 'Arc', 'A'], '|',
657
+ ['dim', 'Dimension', 'D'], ['wdoor', 'Door', 'B'], ['wwindow', 'Window', 'N'], ['cabinet', 'Cabinet', 'K'], '|', ['constr', 'Construction lines', 'X', 'toggle'], '|',
658
+ ['undo', 'Undo', '⌘Z', 'act'], ['redo', 'Redo', '⇧⌘Z', 'act'],
659
+ ];
660
+ /** Tool letters in the wall view. */
661
+ export const WALL_KEYS: Record<string, string> = { v: 'select', l: 'line', s: 'freehand', r: 'rect', c: 'circle', a: 'arc', d: 'dim', t: 'trim', o: 'offset', b: 'wdoor', n: 'wwindow', k: 'cabinet' };
662
+ /** The icon for a wall tool whose id isn't an icon's name. */
663
+ export const WALL_ICON: Record<string, string> = { wdoor: 'door', wwindow: 'window', height: 'hline' };
664
+
665
+ // ---- what's under the pointer, beyond the face's own geometry ----
666
+
667
+ /** A cabinet (on it, or within `slack` inches of its outline) or a door/window body under a world point on the face (cabinets first). */
668
+ export function wallBodyAt(wx: number, wy: number, slack = 0): Hit | null {
669
+ const face = SK() as WallFace, f = elev.frame;
670
+ if (!f) return null;
671
+ // (inside it: right on its edge picks the edge, as a window's)
672
+ for (const id of Object.keys(face.cabs ?? {}).reverse()) {
673
+ const b = cabBox(face, id);
674
+ if (b && wx > b.u0 && wx < b.u1 && wy > b.z0 && wy < b.z1) return { type: 'cab', id };
554
675
  }
555
- if (drag) { const was = drag.started; endDrag(); drag = null; if (was) { down = null; return; } }
556
- // mouse: Shift/⌘/Ctrl adds to the selection; touch and pencil have no Shift, so their taps always add (tap empty space to clear)
557
- if (tapped) tap(pickAt(down!.x, down!.y), !!e.shift || !!e.mod || e.kind !== 'mouse');
558
- down = null;
676
+ for (const o of elevOpenings(planSK(), f)) if (wx > o.u0 && wx < o.u1 && wy > o.sill && wy < o.head) return { type: 'opening', id: o.id };
677
+ return null;
559
678
  }
560
679
 
561
- export function elevPointerCancel(e: PointerIn): void {
562
- gp.delete(e.id); pinch = null;
563
- if (drag) { endDrag(); drag = null; }
564
- if (pressStartedLine) { elev.lineStart = null; pressStartedLine = false; }
680
+ // ---- the bar, the yellow + and the trash for wall things ----
681
+
682
+ export interface WallBarItem { ic: string; label: string; act: string }
683
+
684
+ /** Two doors/windows, or one and a wall end: the + sets the distance between them (the plan's door/window dimension). */
685
+ function wallPair(): { op: string; other: { op: string } | { end: 'a' | 'b' } } | null {
686
+ if (ed.sel.length !== 2) return null;
687
+ const ops = ed.sel.filter(x => x.type === 'opening').map(x => x.id);
688
+ const ends = ed.sel.filter(x => x.type === 'line' && (x.id === '@ea' || x.id === '@eb')).map(x => x.id.slice(2) as 'a' | 'b');
689
+ if (ops.length === 2) return { op: ops[0], other: { op: ops[1] } };
690
+ if (ops.length === 1 && ends.length === 1) return { op: ops[0], other: { end: ends[0] } };
691
+ return null;
565
692
  }
566
693
 
567
- /** A mouse left the canvas: drop the drawing tools' preview. */
568
- export function elevPointerLeave(kind: string): void {
569
- if (kind === 'mouse' && elev.cursor && !gp.size) { elev.cursor = null; renderElevation(); }
694
+ /** The bar for what's selected on the wall that the plan doesn't know (a door or window, a cabinet, a chip). Null: the plan's bar. */
695
+ export function wallBar(): { label?: string; items: WallBarItem[]; plus: boolean } | null {
696
+ if (!elevOpen()) return null;
697
+ const pair = wallPair();
698
+ if (pair) {
699
+ const name = (id: string) => (planSK().openings[id]?.type === 'door' ? 'Door' : 'Window');
700
+ const label = name(pair.op) + ' + ' + ('op' in pair.other ? name(pair.other.op).toLowerCase() : 'corner');
701
+ return { label, items: [{ ic: 'dim', label: 'Distance', act: 'wallDist' }], plus: true };
702
+ }
703
+ if (ed.sel.length !== 1) return null;
704
+ const s = ed.sel[0], sk = planSK();
705
+ if (s.type === 'elev') {
706
+ const a = elevAct(s.id);
707
+ return { label: elevChipName(a), items: a.k === 'len' ? [{ ic: 'back', label: 'Go to plan', act: 'wallGoPlan' }] : [], plus: a.k !== 'len' };
708
+ }
709
+ // a door, window or cabinet picked as a whole: its sizes to set, by name (no + — it isn't one dimension)
710
+ if (s.type === 'opening') {
711
+ const o = sk.openings[s.id];
712
+ if (!o) return null;
713
+ return { label: openingLabel(o), items: OPENING_SIZES, plus: false };
714
+ }
715
+ if (s.type === 'cab') {
716
+ const face = SK() as WallFace, b = cabBox(face, s.id), cb = face.cabs[s.id];
717
+ return {
718
+ label: 'Cabinet' + (b ? ' ' + fmtLen(b.u1 - b.u0) + ' L × ' + fmtLen(b.z1 - b.z0) + ' H × ' + fmtLen(cb.depth) + ' D' : ''),
719
+ items: [{ ic: 'v', label: 'Height', act: 'cabH' }, { ic: 'h', label: 'Length', act: 'cabW' }, { ic: 'thick', label: 'Depth', act: 'cabD' }], plus: false,
720
+ };
721
+ }
722
+ const face = SK() as WallFace;
723
+ if (s.type === 'line' && face.lines[s.id]?.anchor) return { label: anchorName(s.id), items: [], plus: false };
724
+ if (s.type === 'line' && face.lines[s.id]?.cab) return { label: 'Cabinet edge', items: [], plus: false };
725
+ if (s.type === 'point' && face.points[s.id]?.anchor) return { label: 'Corner · set by the plan', items: [], plus: false };
726
+ return null;
727
+ }
728
+
729
+ /** What one of the plan's edges on the face is. */
730
+ function anchorName(id: string): string {
731
+ if (id === '@floor') return 'Floor';
732
+ if (id === '@ceil') return 'Ceiling';
733
+ if (id === '@ea' || id === '@eb') return 'Wall corner';
734
+ const op = planSK().openings[id.split(':')[1]];
735
+ return (op?.type === 'door' ? 'Door' : 'Window') + ' edge';
736
+ }
737
+
738
+ /** A door's or window's sizes to set, in the bar (the wall view's and the plan's): its height and its length. */
739
+ export const OPENING_SIZES: WallBarItem[] = [{ ic: 'v', label: 'Height', act: 'opHeight' }, { ic: 'h', label: 'Length', act: 'opLength' }];
740
+
741
+ /** What the bar calls a door or window: its kind and sizes, length by height ("Door 3'-0" L × 6'-8" H"). */
742
+ export function openingLabel(o: Opening): string {
743
+ const { sill, head } = openingHeights(o);
744
+ return (o.type === 'door' ? 'Door ' : 'Window ') + fmtLen(o.w) + ' L × ' + fmtLen(head - sill) + ' H';
745
+ }
746
+
747
+ /** Run a bar action for the wall view's things (a door's or window's sizes work in the plan too). Returns false if it isn't one. */
748
+ export function wallAction(act: string): boolean {
749
+ const s = ed.sel[0];
750
+ switch (act) {
751
+ case 'opHeight': editOpeningHeight(s.id); return true;
752
+ case 'opLength': editOpeningDim(s.id, 'w'); return true;
753
+ case 'cabW': editCabinet(s.id, 'w'); return true;
754
+ case 'opSill': editSill(s.id); return true;
755
+ case 'cabH': editCabinet(s.id, 'h'); return true;
756
+ case 'cabD': editCabinetDepth(s.id); return true;
757
+ case 'cabZ': editCabinet(s.id, 'z'); return true;
758
+ case 'wallGoPlan': goToPlan(); return true;
759
+ case 'wallDist': wallPlus(); return true;
760
+ }
761
+ return false;
570
762
  }
571
763
 
572
- /** The wheel zooms around the pointer. */
573
- export function elevWheel(x: number, y: number, dy: number): void {
574
- if (!elev.view) return;
575
- zoomElevAt(x, y, Math.exp(-dy * 0.0015));
764
+ /** The yellow + for wall things. Returns false if the plan's + should handle the selection. */
765
+ export function wallPlus(): boolean {
766
+ if (!elevOpen()) return false;
767
+ const pair = wallPair(), f = elev.frame!;
768
+ if (pair) {
769
+ const ops = elevOpenings(planSK(), f), a = ops.find(o => o.id === pair.op);
770
+ if (!a) return true;
771
+ if ('op' in pair.other) {
772
+ const otherId = pair.other.op, b = ops.find(o => o.id === otherId);
773
+ if (!b) return true;
774
+ const [l, r] = a.u0 <= b.u0 ? [a, b] : [b, a], t = pickBetween(planSK(), l.id, l.e1, r.id, r.e0);
775
+ editElevationPosition(t.op, t.edge, t.ref, 'Space between');
776
+ } else {
777
+ const end = pair.other.end, ref: OpeningRef = { face: end, line: f.lid, side: f.side as 1 | -1 };
778
+ editElevationPosition(a.id, end === f.leftEnd ? a.e0 : a.e1, ref, 'Distance from the corner');
779
+ }
780
+ return true;
781
+ }
782
+ if (ed.sel.length !== 1) return false;
783
+ const s = ed.sel[0];
784
+ if (s.type === 'elev') { editElevChip(elevAct(s.id)); return true; }
785
+ if (s.type === 'opening') { editOpeningDim(s.id, 'w'); return true; }
786
+ if (s.type === 'cab') { editCabinet(s.id, 'w'); return true; }
787
+ return false;
576
788
  }
577
789
 
578
790
  /**
579
- * Keyboard shortcuts while the wall view is open: Esc steps back, ⌘Z / ⇧⌘Z / ⌘Y undo and redo, F fits, tool letters,
580
- * Delete removes. Returns true when the key was used (the host should stop its default action).
791
+ * Delete in the wall view: a selected chip's dimension is freed or removed; doors and windows go from the plan,
792
+ * cabinets from the face, the rest as in the plan. The plan's anchors stay. Returns false outside the wall view.
581
793
  */
582
- export function elevKeyDown(e: KeyIn): boolean {
583
- const k = e.key.toLowerCase();
584
- if (e.key === 'Escape') { elevEscape(); return true; }
585
- if (e.mod && k === 'z') { if (e.shift) redo(); else undo(); return true; }
586
- if (e.mod && k === 'y') { redo(); return true; }
587
- if (k === 'f' && !e.mod) { fitElevation(); return true; }
588
- if (!e.mod && !e.alt && elevToolKey(e.key)) return true;
589
- if (e.key === 'Delete' || e.key === 'Backspace') { deleteSelectedElevDim(); return true; }
590
- return false;
794
+ export function wallDelete(): boolean {
795
+ if (!elevOpen()) return false;
796
+ if (ed.sel.length === 1 && ed.sel[0].type === 'elev') { deleteElevChip(elevAct(ed.sel[0].id)); return true; }
797
+ const face = SK() as WallFace;
798
+ const anchor = (x: { type: string; id: string }) => (x.type === 'line' && !!face.lines[x.id]?.anchor) || (x.type === 'point' && !!face.points[x.id]?.anchor);
799
+ const items = ed.sel.filter(x => !anchor(x) && x.type !== 'elev');
800
+ if (!items.length) { toast('The wall’s edges and corners come from the plan — they can’t be deleted here.', { warn: true }); return true; }
801
+ const one = items.length === 1 ? items[0] : null, op = one?.type === 'opening' ? planSK().openings[one.id] : null;
802
+ const what = one?.type === 'cab' ? 'Cabinet deleted' : op ? (op.type === 'door' ? 'Door' : 'Window') + ' deleted' : 'Deleted';
803
+ pushHistory();
804
+ deleteSel(planSK(), items.filter(x => x.type === 'opening'));
805
+ deleteCabinets(items.filter(x => x.type === 'cab').map(x => x.id));
806
+ deleteSel(face, items.filter(x => x.type !== 'opening' && x.type !== 'cab'));
807
+ ed.sel = [];
808
+ afterEdit();
809
+ toast(what, { action: { label: 'Undo', fn: () => undo() } });
810
+ return true;
591
811
  }