@archireport/react-native-drawing 0.2.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 (323) hide show
  1. package/README.md +181 -0
  2. package/lib/commonjs/DrawingEditor.js +815 -0
  3. package/lib/commonjs/DrawingEditor.js.map +1 -0
  4. package/lib/commonjs/assets/toolbar-icons/arrow-disabled.png +0 -0
  5. package/lib/commonjs/assets/toolbar-icons/arrow-enabled.png +0 -0
  6. package/lib/commonjs/assets/toolbar-icons/arrow.png +0 -0
  7. package/lib/commonjs/assets/toolbar-icons/circle-disabled.png +0 -0
  8. package/lib/commonjs/assets/toolbar-icons/circle-enabled.png +0 -0
  9. package/lib/commonjs/assets/toolbar-icons/circle.png +0 -0
  10. package/lib/commonjs/assets/toolbar-icons/freehand-disabled.png +0 -0
  11. package/lib/commonjs/assets/toolbar-icons/freehand-enabled.png +0 -0
  12. package/lib/commonjs/assets/toolbar-icons/freehand.png +0 -0
  13. package/lib/commonjs/assets/toolbar-icons/line-disabled.png +0 -0
  14. package/lib/commonjs/assets/toolbar-icons/line-enabled.png +0 -0
  15. package/lib/commonjs/assets/toolbar-icons/line.png +0 -0
  16. package/lib/commonjs/assets/toolbar-icons/measure-disabled.png +0 -0
  17. package/lib/commonjs/assets/toolbar-icons/measure-enabled.png +0 -0
  18. package/lib/commonjs/assets/toolbar-icons/measure.png +0 -0
  19. package/lib/commonjs/assets/toolbar-icons/move-disabled.png +0 -0
  20. package/lib/commonjs/assets/toolbar-icons/move-enabled.png +0 -0
  21. package/lib/commonjs/assets/toolbar-icons/move.png +0 -0
  22. package/lib/commonjs/assets/toolbar-icons/polygon-disabled.png +0 -0
  23. package/lib/commonjs/assets/toolbar-icons/polygon-enabled.png +0 -0
  24. package/lib/commonjs/assets/toolbar-icons/polygon.png +0 -0
  25. package/lib/commonjs/assets/toolbar-icons/rectangle-disabled.png +0 -0
  26. package/lib/commonjs/assets/toolbar-icons/rectangle-enabled.png +0 -0
  27. package/lib/commonjs/assets/toolbar-icons/rectangle.png +0 -0
  28. package/lib/commonjs/assets/toolbar-icons/text-disabled.png +0 -0
  29. package/lib/commonjs/assets/toolbar-icons/text-enabled.png +0 -0
  30. package/lib/commonjs/assets/toolbar-icons/text.png +0 -0
  31. package/lib/commonjs/components/ColorPalette.js +379 -0
  32. package/lib/commonjs/components/ColorPalette.js.map +1 -0
  33. package/lib/commonjs/components/LineWidthSlider.js +70 -0
  34. package/lib/commonjs/components/LineWidthSlider.js.map +1 -0
  35. package/lib/commonjs/components/MeasurementEditModal.js +153 -0
  36. package/lib/commonjs/components/MeasurementEditModal.js.map +1 -0
  37. package/lib/commonjs/components/MiniMap.js +244 -0
  38. package/lib/commonjs/components/MiniMap.js.map +1 -0
  39. package/lib/commonjs/components/TextAnnotation.js +162 -0
  40. package/lib/commonjs/components/TextAnnotation.js.map +1 -0
  41. package/lib/commonjs/components/TextEditModal.js +133 -0
  42. package/lib/commonjs/components/TextEditModal.js.map +1 -0
  43. package/lib/commonjs/components/Toolbar.js +198 -0
  44. package/lib/commonjs/components/Toolbar.js.map +1 -0
  45. package/lib/commonjs/components/ZoomBadge.js +161 -0
  46. package/lib/commonjs/components/ZoomBadge.js.map +1 -0
  47. package/lib/commonjs/hooks/useFreehandGesture.js +173 -0
  48. package/lib/commonjs/hooks/useFreehandGesture.js.map +1 -0
  49. package/lib/commonjs/hooks/usePolygonGesture.js +109 -0
  50. package/lib/commonjs/hooks/usePolygonGesture.js.map +1 -0
  51. package/lib/commonjs/hooks/useSelectionGesture.js +236 -0
  52. package/lib/commonjs/hooks/useSelectionGesture.js.map +1 -0
  53. package/lib/commonjs/hooks/useShapeGesture.js +181 -0
  54. package/lib/commonjs/hooks/useShapeGesture.js.map +1 -0
  55. package/lib/commonjs/hooks/useViewportGesture.js +238 -0
  56. package/lib/commonjs/hooks/useViewportGesture.js.map +1 -0
  57. package/lib/commonjs/index.js +104 -0
  58. package/lib/commonjs/index.js.map +1 -0
  59. package/lib/commonjs/package.json +1 -0
  60. package/lib/commonjs/renderers/ArrowRenderer.js +118 -0
  61. package/lib/commonjs/renderers/ArrowRenderer.js.map +1 -0
  62. package/lib/commonjs/renderers/CircleRenderer.js +51 -0
  63. package/lib/commonjs/renderers/CircleRenderer.js.map +1 -0
  64. package/lib/commonjs/renderers/FreehandRenderer.js +31 -0
  65. package/lib/commonjs/renderers/FreehandRenderer.js.map +1 -0
  66. package/lib/commonjs/renderers/InProgressRenderer.js +174 -0
  67. package/lib/commonjs/renderers/InProgressRenderer.js.map +1 -0
  68. package/lib/commonjs/renderers/LineRenderer.js +27 -0
  69. package/lib/commonjs/renderers/LineRenderer.js.map +1 -0
  70. package/lib/commonjs/renderers/MeasurementRenderer.js +134 -0
  71. package/lib/commonjs/renderers/MeasurementRenderer.js.map +1 -0
  72. package/lib/commonjs/renderers/ObjectRenderer.js +65 -0
  73. package/lib/commonjs/renderers/ObjectRenderer.js.map +1 -0
  74. package/lib/commonjs/renderers/PolygonRenderer.js +46 -0
  75. package/lib/commonjs/renderers/PolygonRenderer.js.map +1 -0
  76. package/lib/commonjs/renderers/RectRenderer.js +51 -0
  77. package/lib/commonjs/renderers/RectRenderer.js.map +1 -0
  78. package/lib/commonjs/renderers/SelectedObjectRenderer.js +592 -0
  79. package/lib/commonjs/renderers/SelectedObjectRenderer.js.map +1 -0
  80. package/lib/commonjs/renderers/SelectionOverlay.js +120 -0
  81. package/lib/commonjs/renderers/SelectionOverlay.js.map +1 -0
  82. package/lib/commonjs/store/useDrawingStore.js +354 -0
  83. package/lib/commonjs/store/useDrawingStore.js.map +1 -0
  84. package/lib/commonjs/types.js +6 -0
  85. package/lib/commonjs/types.js.map +1 -0
  86. package/lib/commonjs/utils/colors.js +44 -0
  87. package/lib/commonjs/utils/colors.js.map +1 -0
  88. package/lib/commonjs/utils/coordinates.js +81 -0
  89. package/lib/commonjs/utils/coordinates.js.map +1 -0
  90. package/lib/commonjs/utils/hitTesting.js +181 -0
  91. package/lib/commonjs/utils/hitTesting.js.map +1 -0
  92. package/lib/commonjs/utils/serialization.js +42 -0
  93. package/lib/commonjs/utils/serialization.js.map +1 -0
  94. package/lib/commonjs/utils/shapeDetection.js +151 -0
  95. package/lib/commonjs/utils/shapeDetection.js.map +1 -0
  96. package/lib/commonjs/utils/smoothing.js +85 -0
  97. package/lib/commonjs/utils/smoothing.js.map +1 -0
  98. package/lib/module/DrawingEditor.js +811 -0
  99. package/lib/module/DrawingEditor.js.map +1 -0
  100. package/lib/module/assets/toolbar-icons/arrow-disabled.png +0 -0
  101. package/lib/module/assets/toolbar-icons/arrow-enabled.png +0 -0
  102. package/lib/module/assets/toolbar-icons/arrow.png +0 -0
  103. package/lib/module/assets/toolbar-icons/circle-disabled.png +0 -0
  104. package/lib/module/assets/toolbar-icons/circle-enabled.png +0 -0
  105. package/lib/module/assets/toolbar-icons/circle.png +0 -0
  106. package/lib/module/assets/toolbar-icons/freehand-disabled.png +0 -0
  107. package/lib/module/assets/toolbar-icons/freehand-enabled.png +0 -0
  108. package/lib/module/assets/toolbar-icons/freehand.png +0 -0
  109. package/lib/module/assets/toolbar-icons/line-disabled.png +0 -0
  110. package/lib/module/assets/toolbar-icons/line-enabled.png +0 -0
  111. package/lib/module/assets/toolbar-icons/line.png +0 -0
  112. package/lib/module/assets/toolbar-icons/measure-disabled.png +0 -0
  113. package/lib/module/assets/toolbar-icons/measure-enabled.png +0 -0
  114. package/lib/module/assets/toolbar-icons/measure.png +0 -0
  115. package/lib/module/assets/toolbar-icons/move-disabled.png +0 -0
  116. package/lib/module/assets/toolbar-icons/move-enabled.png +0 -0
  117. package/lib/module/assets/toolbar-icons/move.png +0 -0
  118. package/lib/module/assets/toolbar-icons/polygon-disabled.png +0 -0
  119. package/lib/module/assets/toolbar-icons/polygon-enabled.png +0 -0
  120. package/lib/module/assets/toolbar-icons/polygon.png +0 -0
  121. package/lib/module/assets/toolbar-icons/rectangle-disabled.png +0 -0
  122. package/lib/module/assets/toolbar-icons/rectangle-enabled.png +0 -0
  123. package/lib/module/assets/toolbar-icons/rectangle.png +0 -0
  124. package/lib/module/assets/toolbar-icons/text-disabled.png +0 -0
  125. package/lib/module/assets/toolbar-icons/text-enabled.png +0 -0
  126. package/lib/module/assets/toolbar-icons/text.png +0 -0
  127. package/lib/module/components/ColorPalette.js +374 -0
  128. package/lib/module/components/ColorPalette.js.map +1 -0
  129. package/lib/module/components/LineWidthSlider.js +64 -0
  130. package/lib/module/components/LineWidthSlider.js.map +1 -0
  131. package/lib/module/components/MeasurementEditModal.js +148 -0
  132. package/lib/module/components/MeasurementEditModal.js.map +1 -0
  133. package/lib/module/components/MiniMap.js +239 -0
  134. package/lib/module/components/MiniMap.js.map +1 -0
  135. package/lib/module/components/TextAnnotation.js +157 -0
  136. package/lib/module/components/TextAnnotation.js.map +1 -0
  137. package/lib/module/components/TextEditModal.js +128 -0
  138. package/lib/module/components/TextEditModal.js.map +1 -0
  139. package/lib/module/components/Toolbar.js +193 -0
  140. package/lib/module/components/Toolbar.js.map +1 -0
  141. package/lib/module/components/ZoomBadge.js +155 -0
  142. package/lib/module/components/ZoomBadge.js.map +1 -0
  143. package/lib/module/hooks/useFreehandGesture.js +169 -0
  144. package/lib/module/hooks/useFreehandGesture.js.map +1 -0
  145. package/lib/module/hooks/usePolygonGesture.js +106 -0
  146. package/lib/module/hooks/usePolygonGesture.js.map +1 -0
  147. package/lib/module/hooks/useSelectionGesture.js +232 -0
  148. package/lib/module/hooks/useSelectionGesture.js.map +1 -0
  149. package/lib/module/hooks/useShapeGesture.js +177 -0
  150. package/lib/module/hooks/useShapeGesture.js.map +1 -0
  151. package/lib/module/hooks/useViewportGesture.js +234 -0
  152. package/lib/module/hooks/useViewportGesture.js.map +1 -0
  153. package/lib/module/index.js +20 -0
  154. package/lib/module/index.js.map +1 -0
  155. package/lib/module/package.json +1 -0
  156. package/lib/module/renderers/ArrowRenderer.js +113 -0
  157. package/lib/module/renderers/ArrowRenderer.js.map +1 -0
  158. package/lib/module/renderers/CircleRenderer.js +46 -0
  159. package/lib/module/renderers/CircleRenderer.js.map +1 -0
  160. package/lib/module/renderers/FreehandRenderer.js +26 -0
  161. package/lib/module/renderers/FreehandRenderer.js.map +1 -0
  162. package/lib/module/renderers/InProgressRenderer.js +169 -0
  163. package/lib/module/renderers/InProgressRenderer.js.map +1 -0
  164. package/lib/module/renderers/LineRenderer.js +22 -0
  165. package/lib/module/renderers/LineRenderer.js.map +1 -0
  166. package/lib/module/renderers/MeasurementRenderer.js +129 -0
  167. package/lib/module/renderers/MeasurementRenderer.js.map +1 -0
  168. package/lib/module/renderers/ObjectRenderer.js +60 -0
  169. package/lib/module/renderers/ObjectRenderer.js.map +1 -0
  170. package/lib/module/renderers/PolygonRenderer.js +41 -0
  171. package/lib/module/renderers/PolygonRenderer.js.map +1 -0
  172. package/lib/module/renderers/RectRenderer.js +46 -0
  173. package/lib/module/renderers/RectRenderer.js.map +1 -0
  174. package/lib/module/renderers/SelectedObjectRenderer.js +587 -0
  175. package/lib/module/renderers/SelectedObjectRenderer.js.map +1 -0
  176. package/lib/module/renderers/SelectionOverlay.js +116 -0
  177. package/lib/module/renderers/SelectionOverlay.js.map +1 -0
  178. package/lib/module/store/useDrawingStore.js +350 -0
  179. package/lib/module/store/useDrawingStore.js.map +1 -0
  180. package/lib/module/types.js +4 -0
  181. package/lib/module/types.js.map +1 -0
  182. package/lib/module/utils/colors.js +40 -0
  183. package/lib/module/utils/colors.js.map +1 -0
  184. package/lib/module/utils/coordinates.js +71 -0
  185. package/lib/module/utils/coordinates.js.map +1 -0
  186. package/lib/module/utils/hitTesting.js +171 -0
  187. package/lib/module/utils/hitTesting.js.map +1 -0
  188. package/lib/module/utils/serialization.js +36 -0
  189. package/lib/module/utils/serialization.js.map +1 -0
  190. package/lib/module/utils/shapeDetection.js +147 -0
  191. package/lib/module/utils/shapeDetection.js.map +1 -0
  192. package/lib/module/utils/smoothing.js +80 -0
  193. package/lib/module/utils/smoothing.js.map +1 -0
  194. package/lib/typescript/DrawingEditor.d.ts +3 -0
  195. package/lib/typescript/DrawingEditor.d.ts.map +1 -0
  196. package/lib/typescript/components/ColorPalette.d.ts +9 -0
  197. package/lib/typescript/components/ColorPalette.d.ts.map +1 -0
  198. package/lib/typescript/components/LineWidthSlider.d.ts +11 -0
  199. package/lib/typescript/components/LineWidthSlider.d.ts.map +1 -0
  200. package/lib/typescript/components/MeasurementEditModal.d.ts +11 -0
  201. package/lib/typescript/components/MeasurementEditModal.d.ts.map +1 -0
  202. package/lib/typescript/components/MiniMap.d.ts +23 -0
  203. package/lib/typescript/components/MiniMap.d.ts.map +1 -0
  204. package/lib/typescript/components/TextAnnotation.d.ts +22 -0
  205. package/lib/typescript/components/TextAnnotation.d.ts.map +1 -0
  206. package/lib/typescript/components/TextEditModal.d.ts +10 -0
  207. package/lib/typescript/components/TextEditModal.d.ts.map +1 -0
  208. package/lib/typescript/components/Toolbar.d.ts +13 -0
  209. package/lib/typescript/components/Toolbar.d.ts.map +1 -0
  210. package/lib/typescript/components/ZoomBadge.d.ts +9 -0
  211. package/lib/typescript/components/ZoomBadge.d.ts.map +1 -0
  212. package/lib/typescript/hooks/useFreehandGesture.d.ts +47 -0
  213. package/lib/typescript/hooks/useFreehandGesture.d.ts.map +1 -0
  214. package/lib/typescript/hooks/usePolygonGesture.d.ts +47 -0
  215. package/lib/typescript/hooks/usePolygonGesture.d.ts.map +1 -0
  216. package/lib/typescript/hooks/useSelectionGesture.d.ts +32 -0
  217. package/lib/typescript/hooks/useSelectionGesture.d.ts.map +1 -0
  218. package/lib/typescript/hooks/useShapeGesture.d.ts +54 -0
  219. package/lib/typescript/hooks/useShapeGesture.d.ts.map +1 -0
  220. package/lib/typescript/hooks/useViewportGesture.d.ts +37 -0
  221. package/lib/typescript/hooks/useViewportGesture.d.ts.map +1 -0
  222. package/lib/typescript/index.d.ts +11 -0
  223. package/lib/typescript/index.d.ts.map +1 -0
  224. package/lib/typescript/renderers/ArrowRenderer.d.ts +9 -0
  225. package/lib/typescript/renderers/ArrowRenderer.d.ts.map +1 -0
  226. package/lib/typescript/renderers/CircleRenderer.d.ts +9 -0
  227. package/lib/typescript/renderers/CircleRenderer.d.ts.map +1 -0
  228. package/lib/typescript/renderers/FreehandRenderer.d.ts +9 -0
  229. package/lib/typescript/renderers/FreehandRenderer.d.ts.map +1 -0
  230. package/lib/typescript/renderers/InProgressRenderer.d.ts +32 -0
  231. package/lib/typescript/renderers/InProgressRenderer.d.ts.map +1 -0
  232. package/lib/typescript/renderers/LineRenderer.d.ts +9 -0
  233. package/lib/typescript/renderers/LineRenderer.d.ts.map +1 -0
  234. package/lib/typescript/renderers/MeasurementRenderer.d.ts +9 -0
  235. package/lib/typescript/renderers/MeasurementRenderer.d.ts.map +1 -0
  236. package/lib/typescript/renderers/ObjectRenderer.d.ts +12 -0
  237. package/lib/typescript/renderers/ObjectRenderer.d.ts.map +1 -0
  238. package/lib/typescript/renderers/PolygonRenderer.d.ts +13 -0
  239. package/lib/typescript/renderers/PolygonRenderer.d.ts.map +1 -0
  240. package/lib/typescript/renderers/RectRenderer.d.ts +9 -0
  241. package/lib/typescript/renderers/RectRenderer.d.ts.map +1 -0
  242. package/lib/typescript/renderers/SelectedObjectRenderer.d.ts +18 -0
  243. package/lib/typescript/renderers/SelectedObjectRenderer.d.ts.map +1 -0
  244. package/lib/typescript/renderers/SelectionOverlay.d.ts +21 -0
  245. package/lib/typescript/renderers/SelectionOverlay.d.ts.map +1 -0
  246. package/lib/typescript/store/useDrawingStore.d.ts +30 -0
  247. package/lib/typescript/store/useDrawingStore.d.ts.map +1 -0
  248. package/lib/typescript/types.d.ts +130 -0
  249. package/lib/typescript/types.d.ts.map +1 -0
  250. package/lib/typescript/utils/colors.d.ts +11 -0
  251. package/lib/typescript/utils/colors.d.ts.map +1 -0
  252. package/lib/typescript/utils/coordinates.d.ts +34 -0
  253. package/lib/typescript/utils/coordinates.d.ts.map +1 -0
  254. package/lib/typescript/utils/hitTesting.d.ts +18 -0
  255. package/lib/typescript/utils/hitTesting.d.ts.map +1 -0
  256. package/lib/typescript/utils/serialization.d.ts +17 -0
  257. package/lib/typescript/utils/serialization.d.ts.map +1 -0
  258. package/lib/typescript/utils/shapeDetection.d.ts +22 -0
  259. package/lib/typescript/utils/shapeDetection.d.ts.map +1 -0
  260. package/lib/typescript/utils/smoothing.d.ts +16 -0
  261. package/lib/typescript/utils/smoothing.d.ts.map +1 -0
  262. package/package.json +108 -0
  263. package/src/DrawingEditor.tsx +1071 -0
  264. package/src/assets/toolbar-icons/arrow-disabled.png +0 -0
  265. package/src/assets/toolbar-icons/arrow-enabled.png +0 -0
  266. package/src/assets/toolbar-icons/arrow.png +0 -0
  267. package/src/assets/toolbar-icons/circle-disabled.png +0 -0
  268. package/src/assets/toolbar-icons/circle-enabled.png +0 -0
  269. package/src/assets/toolbar-icons/circle.png +0 -0
  270. package/src/assets/toolbar-icons/freehand-disabled.png +0 -0
  271. package/src/assets/toolbar-icons/freehand-enabled.png +0 -0
  272. package/src/assets/toolbar-icons/freehand.png +0 -0
  273. package/src/assets/toolbar-icons/line-disabled.png +0 -0
  274. package/src/assets/toolbar-icons/line-enabled.png +0 -0
  275. package/src/assets/toolbar-icons/line.png +0 -0
  276. package/src/assets/toolbar-icons/measure-disabled.png +0 -0
  277. package/src/assets/toolbar-icons/measure-enabled.png +0 -0
  278. package/src/assets/toolbar-icons/measure.png +0 -0
  279. package/src/assets/toolbar-icons/move-disabled.png +0 -0
  280. package/src/assets/toolbar-icons/move-enabled.png +0 -0
  281. package/src/assets/toolbar-icons/move.png +0 -0
  282. package/src/assets/toolbar-icons/polygon-disabled.png +0 -0
  283. package/src/assets/toolbar-icons/polygon-enabled.png +0 -0
  284. package/src/assets/toolbar-icons/polygon.png +0 -0
  285. package/src/assets/toolbar-icons/rectangle-disabled.png +0 -0
  286. package/src/assets/toolbar-icons/rectangle-enabled.png +0 -0
  287. package/src/assets/toolbar-icons/rectangle.png +0 -0
  288. package/src/assets/toolbar-icons/text-disabled.png +0 -0
  289. package/src/assets/toolbar-icons/text-enabled.png +0 -0
  290. package/src/assets/toolbar-icons/text.png +0 -0
  291. package/src/components/ColorPalette.tsx +497 -0
  292. package/src/components/LineWidthSlider.tsx +87 -0
  293. package/src/components/MeasurementEditModal.tsx +163 -0
  294. package/src/components/MiniMap.tsx +275 -0
  295. package/src/components/TextAnnotation.tsx +198 -0
  296. package/src/components/TextEditModal.tsx +139 -0
  297. package/src/components/Toolbar.tsx +254 -0
  298. package/src/components/ZoomBadge.tsx +166 -0
  299. package/src/hooks/useFreehandGesture.ts +249 -0
  300. package/src/hooks/usePolygonGesture.ts +162 -0
  301. package/src/hooks/useSelectionGesture.ts +293 -0
  302. package/src/hooks/useShapeGesture.ts +256 -0
  303. package/src/hooks/useViewportGesture.ts +337 -0
  304. package/src/index.tsx +51 -0
  305. package/src/renderers/ArrowRenderer.tsx +123 -0
  306. package/src/renderers/CircleRenderer.tsx +60 -0
  307. package/src/renderers/FreehandRenderer.tsx +33 -0
  308. package/src/renderers/InProgressRenderer.tsx +217 -0
  309. package/src/renderers/LineRenderer.tsx +34 -0
  310. package/src/renderers/MeasurementRenderer.tsx +179 -0
  311. package/src/renderers/ObjectRenderer.tsx +42 -0
  312. package/src/renderers/PolygonRenderer.tsx +66 -0
  313. package/src/renderers/RectRenderer.tsx +60 -0
  314. package/src/renderers/SelectedObjectRenderer.tsx +738 -0
  315. package/src/renderers/SelectionOverlay.tsx +170 -0
  316. package/src/store/useDrawingStore.ts +357 -0
  317. package/src/types.ts +186 -0
  318. package/src/utils/colors.ts +98 -0
  319. package/src/utils/coordinates.ts +75 -0
  320. package/src/utils/hitTesting.ts +242 -0
  321. package/src/utils/serialization.ts +45 -0
  322. package/src/utils/shapeDetection.ts +160 -0
  323. package/src/utils/smoothing.ts +84 -0
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+
3
+ import { denormalize, denormalizePoints } from "./coordinates";
4
+ import { buildSmoothedPath } from "./smoothing";
5
+ const HIT_PADDING = 20; // pixels tolerance for hit-testing lines/paths
6
+
7
+ /**
8
+ * Test if a pixel-space tap point hits a drawing object.
9
+ * All object coordinates are normalized and must be denormalized with canvasSize.
10
+ *
11
+ * Returns true if the point is within hit range of the object.
12
+ */
13
+ export function hitTestObject(object, tapPoint, canvasSize) {
14
+ switch (object.type) {
15
+ case "freehand":
16
+ return hitTestFreehand(object, tapPoint, canvasSize);
17
+ case "line":
18
+ case "arrow":
19
+ case "measure":
20
+ return hitTestLine(object, tapPoint, canvasSize);
21
+ case "rectangle":
22
+ return hitTestRect(object, tapPoint, canvasSize);
23
+ case "circle":
24
+ return hitTestEllipse(object, tapPoint, canvasSize);
25
+ case "polygon":
26
+ return hitTestPolygon(object, tapPoint, canvasSize);
27
+ case "text":
28
+ return hitTestText(object, tapPoint, canvasSize);
29
+ }
30
+ }
31
+ function hitTestFreehand(object, tap, canvasSize) {
32
+ const points = denormalizePoints(object.points, canvasSize);
33
+ const padding = HIT_PADDING + object.lineWidth / 2;
34
+
35
+ // Check distance to each segment of the smoothed path
36
+ for (let i = 0; i < points.length - 1; i++) {
37
+ const a = points[i];
38
+ const b = points[i + 1];
39
+ if (distanceToSegment(tap, a, b) < padding) {
40
+ return true;
41
+ }
42
+ }
43
+ return false;
44
+ }
45
+ function hitTestLine(object, tap, canvasSize) {
46
+ const from = denormalize(object.from, canvasSize);
47
+ const to = denormalize(object.to, canvasSize);
48
+ const padding = HIT_PADDING + object.lineWidth / 2;
49
+ return distanceToSegment(tap, from, to) < padding;
50
+ }
51
+ function hitTestRect(object, tap, canvasSize) {
52
+ const from = denormalize(object.from, canvasSize);
53
+ const to = denormalize(object.to, canvasSize);
54
+ const padding = HIT_PADDING;
55
+ const minX = Math.min(from.x, to.x) - padding;
56
+ const maxX = Math.max(from.x, to.x) + padding;
57
+ const minY = Math.min(from.y, to.y) - padding;
58
+ const maxY = Math.max(from.y, to.y) + padding;
59
+
60
+ // If has fill, hit inside the rect
61
+ if ("backgroundColor" in object && object.backgroundColor) {
62
+ return tap.x >= minX && tap.x <= maxX && tap.y >= minY && tap.y <= maxY;
63
+ }
64
+
65
+ // Otherwise, hit the border only
66
+ const innerMinX = Math.min(from.x, to.x) + padding;
67
+ const innerMaxX = Math.max(from.x, to.x) - padding;
68
+ const innerMinY = Math.min(from.y, to.y) + padding;
69
+ const innerMaxY = Math.max(from.y, to.y) - padding;
70
+ const inOuter = tap.x >= minX && tap.x <= maxX && tap.y >= minY && tap.y <= maxY;
71
+ const inInner = tap.x >= innerMinX && tap.x <= innerMaxX && tap.y >= innerMinY && tap.y <= innerMaxY;
72
+ return inOuter && !inInner;
73
+ }
74
+ function hitTestEllipse(object, tap, canvasSize) {
75
+ const from = denormalize(object.from, canvasSize);
76
+ const to = denormalize(object.to, canvasSize);
77
+ const cx = (from.x + to.x) / 2;
78
+ const cy = (from.y + to.y) / 2;
79
+ const rx = Math.abs(to.x - from.x) / 2;
80
+ const ry = Math.abs(to.y - from.y) / 2;
81
+ if (rx === 0 || ry === 0) return false;
82
+ const dx = tap.x - cx;
83
+ const dy = tap.y - cy;
84
+
85
+ // Normalized distance from center
86
+ // If has fill, hit inside the ellipse
87
+ if ("backgroundColor" in object && object.backgroundColor) {
88
+ const outerRx = rx + HIT_PADDING;
89
+ const outerRy = ry + HIT_PADDING;
90
+ return dx * dx / (outerRx * outerRx) + dy * dy / (outerRy * outerRy) <= 1;
91
+ }
92
+
93
+ // Otherwise, hit the border ring
94
+ const padding = HIT_PADDING + ("lineWidth" in object ? object.lineWidth / 2 : 2);
95
+ const outerRx = rx + padding;
96
+ const outerRy = ry + padding;
97
+ const innerRx = Math.max(0, rx - padding);
98
+ const innerRy = Math.max(0, ry - padding);
99
+ const outerDist = dx * dx / (outerRx * outerRx) + dy * dy / (outerRy * outerRy);
100
+ const innerDist = innerRx > 0 && innerRy > 0 ? dx * dx / (innerRx * innerRx) + dy * dy / (innerRy * innerRy) : Infinity;
101
+ return outerDist <= 1 && innerDist >= 1;
102
+ }
103
+ function hitTestText(object, tap, canvasSize) {
104
+ const pos = denormalize(object.position, canvasSize);
105
+ const w = object.width * canvasSize.width;
106
+ const h = object.height * canvasSize.height;
107
+ return tap.x >= pos.x && tap.x <= pos.x + w && tap.y >= pos.y && tap.y <= pos.y + h;
108
+ }
109
+ function hitTestPolygon(object, tap, canvasSize) {
110
+ const points = denormalizePoints(object.points, canvasSize);
111
+ if (points.length < 2) return false;
112
+ const padding = HIT_PADDING + object.lineWidth / 2;
113
+
114
+ // If filled and closed, check if point is inside the polygon
115
+ if (object.closed && object.backgroundColor) {
116
+ if (pointInPolygon(tap, points)) return true;
117
+ }
118
+
119
+ // Check distance to each segment (including closing segment if closed)
120
+ const len = points.length;
121
+ for (let i = 0; i < len - 1; i++) {
122
+ if (distanceToSegment(tap, points[i], points[i + 1]) < padding) {
123
+ return true;
124
+ }
125
+ }
126
+ // Closing segment
127
+ if (object.closed && len >= 3) {
128
+ if (distanceToSegment(tap, points[len - 1], points[0]) < padding) {
129
+ return true;
130
+ }
131
+ }
132
+ return false;
133
+ }
134
+
135
+ /** Ray-casting point-in-polygon test */
136
+ function pointInPolygon(p, polygon) {
137
+ let inside = false;
138
+ for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
139
+ const xi = polygon[i].x;
140
+ const yi = polygon[i].y;
141
+ const xj = polygon[j].x;
142
+ const yj = polygon[j].y;
143
+ const intersect = yi > p.y !== yj > p.y && p.x < (xj - xi) * (p.y - yi) / (yj - yi) + xi;
144
+ if (intersect) inside = !inside;
145
+ }
146
+ return inside;
147
+ }
148
+
149
+ /**
150
+ * Returns the minimum distance from point p to segment [a, b].
151
+ */
152
+ function distanceToSegment(p, a, b) {
153
+ const dx = b.x - a.x;
154
+ const dy = b.y - a.y;
155
+ const lenSq = dx * dx + dy * dy;
156
+ if (lenSq === 0) {
157
+ // a and b are the same point
158
+ return Math.sqrt((p.x - a.x) ** 2 + (p.y - a.y) ** 2);
159
+ }
160
+ let t = ((p.x - a.x) * dx + (p.y - a.y) * dy) / lenSq;
161
+ t = Math.max(0, Math.min(1, t));
162
+ const projX = a.x + t * dx;
163
+ const projY = a.y + t * dy;
164
+ return Math.sqrt((p.x - projX) ** 2 + (p.y - projY) ** 2);
165
+ }
166
+
167
+ /**
168
+ * Export for use in selection gesture calculations.
169
+ */
170
+ export { buildSmoothedPath, distanceToSegment };
171
+ //# sourceMappingURL=hitTesting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["denormalize","denormalizePoints","buildSmoothedPath","HIT_PADDING","hitTestObject","object","tapPoint","canvasSize","type","hitTestFreehand","hitTestLine","hitTestRect","hitTestEllipse","hitTestPolygon","hitTestText","tap","points","padding","lineWidth","i","length","a","b","distanceToSegment","from","to","minX","Math","min","x","maxX","max","minY","y","maxY","backgroundColor","innerMinX","innerMaxX","innerMinY","innerMaxY","inOuter","inInner","cx","cy","rx","abs","ry","dx","dy","outerRx","outerRy","innerRx","innerRy","outerDist","innerDist","Infinity","pos","position","w","width","h","height","closed","pointInPolygon","len","p","polygon","inside","j","xi","yi","xj","yj","intersect","lenSq","sqrt","t","projX","projY"],"sourceRoot":"../../../src","sources":["utils/hitTesting.ts"],"mappings":";;AASA,SAASA,WAAW,EAAEC,iBAAiB,QAAQ,eAAe;AAC9D,SAASC,iBAAiB,QAAQ,aAAa;AAE/C,MAAMC,WAAW,GAAG,EAAE,CAAC,CAAC;;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3BC,MAAqB,EACrBC,QAAe,EACfC,UAAgB,EACP;EACT,QAAQF,MAAM,CAACG,IAAI;IACjB,KAAK,UAAU;MACb,OAAOC,eAAe,CAACJ,MAAM,EAAEC,QAAQ,EAAEC,UAAU,CAAC;IACtD,KAAK,MAAM;IACX,KAAK,OAAO;IACZ,KAAK,SAAS;MACZ,OAAOG,WAAW,CAACL,MAAM,EAAEC,QAAQ,EAAEC,UAAU,CAAC;IAClD,KAAK,WAAW;MACd,OAAOI,WAAW,CAACN,MAAM,EAAEC,QAAQ,EAAEC,UAAU,CAAC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A;AACA;AACA;AACA,SAAS5E,iBAAiB,EAAEqB,iBAAiB","ignoreList":[]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Serialize drawing state to a JSON-compatible structure.
5
+ */
6
+ export function serializeObjects(objects, canvasSize) {
7
+ return JSON.stringify({
8
+ version: 1,
9
+ canvasSize,
10
+ objects
11
+ });
12
+ }
13
+
14
+ /**
15
+ * Deserialize drawing state from JSON.
16
+ */
17
+ export function deserializeObjects(json) {
18
+ try {
19
+ const data = JSON.parse(json);
20
+ if (!data.objects || !data.canvasSize) return null;
21
+ return {
22
+ objects: data.objects,
23
+ canvasSize: data.canvasSize
24
+ };
25
+ } catch {
26
+ return null;
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Generate a unique ID for drawing objects.
32
+ */
33
+ export function generateId() {
34
+ return Date.now().toString(36) + Math.random().toString(36).substring(2, 8);
35
+ }
36
+ //# sourceMappingURL=serialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["serializeObjects","objects","canvasSize","JSON","stringify","version","deserializeObjects","json","data","parse","generateId","Date","now","toString","Math","random","substring"],"sourceRoot":"../../../src","sources":["utils/serialization.ts"],"mappings":";;AAEA;AACA;AACA;AACA,OAAO,SAASA,gBAAgBA,CAC9BC,OAAwB,EACxBC,UAAgB,EACR;EACR,OAAOC,IAAI,CAACC,SAAS,CAAC;IACpBC,OAAO,EAAE,CAAC;IACVH,UAAU;IACVD;EACF,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA,OAAO,SAASK,kBAAkBA,CAACC,IAAY,EAGtC;EACP,IAAI;IACF,MAAMC,IAAI,GAAGL,IAAI,CAACM,KAAK,CAACF,IAAI,CAI3B;IACD,IAAI,CAACC,IAAI,CAACP,OAAO,IAAI,CAACO,IAAI,CAACN,UAAU,EAAE,OAAO,IAAI;IAClD,OAAO;MACLD,OAAO,EAAEO,IAAI,CAACP,OAAO;MACrBC,UAAU,EAAEM,IAAI,CAACN;IACnB,CAAC;EACH,CAAC,CAAC,MAAM;IACN,OAAO,IAAI;EACb;AACF;;AAEA;AACA;AACA;AACA,OAAO,SAASQ,UAAUA,CAAA,EAAW;EACnC,OAAOC,IAAI,CAACC,GAAG,CAAC,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,GAAGC,IAAI,CAACC,MAAM,CAAC,CAAC,CAACF,QAAQ,CAAC,EAAE,CAAC,CAACG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;AAC7E","ignoreList":[]}
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Count the number of direction changes (inflections) in a series of points.
5
+ * An inflection is when the general direction of movement reverses or sharply changes.
6
+ */
7
+ function countInflections(points, startIndex = 0) {
8
+ if (points.length < 3) return 0;
9
+ let inflections = 0;
10
+ for (let i = Math.max(startIndex, 1); i < points.length - 1; i++) {
11
+ const prev = points[i - 1];
12
+ const curr = points[i];
13
+ const next = points[i + 1];
14
+ const dx1 = curr.x - prev.x;
15
+ const dy1 = curr.y - prev.y;
16
+ const dx2 = next.x - curr.x;
17
+ const dy2 = next.y - curr.y;
18
+
19
+ // Cross product sign change indicates direction change
20
+ const cross = dx1 * dy2 - dy1 * dx2;
21
+ if (i > Math.max(startIndex, 1)) {
22
+ const prevPrev = points[i - 2];
23
+ const pdx1 = prev.x - prevPrev.x;
24
+ const pdy1 = prev.y - prevPrev.y;
25
+ const prevCross = pdx1 * dy1 - pdy1 * dx1;
26
+ if (prevCross * cross < 0) {
27
+ inflections++;
28
+ }
29
+ }
30
+ }
31
+ return inflections;
32
+ }
33
+
34
+ /**
35
+ * Compute total angle traversed by the path.
36
+ * Used for circle detection (should be ~2π for a full circle).
37
+ */
38
+ function totalAngleTraversed(points) {
39
+ if (points.length < 3) return 0;
40
+ let totalAngle = 0;
41
+ for (let i = 1; i < points.length - 1; i++) {
42
+ const prev = points[i - 1];
43
+ const curr = points[i];
44
+ const next = points[i + 1];
45
+ const a1 = Math.atan2(curr.y - prev.y, curr.x - prev.x);
46
+ const a2 = Math.atan2(next.y - curr.y, next.x - curr.x);
47
+ let delta = a2 - a1;
48
+
49
+ // Normalize to [-π, π]
50
+ while (delta > Math.PI) delta -= 2 * Math.PI;
51
+ while (delta < -Math.PI) delta += 2 * Math.PI;
52
+ totalAngle += delta;
53
+ }
54
+ return totalAngle;
55
+ }
56
+ function dist(a, b) {
57
+ const dx = a.x - b.x;
58
+ const dy = a.y - b.y;
59
+ return Math.sqrt(dx * dx + dy * dy);
60
+ }
61
+ function boundingRect(points) {
62
+ let minX = Infinity;
63
+ let minY = Infinity;
64
+ let maxX = -Infinity;
65
+ let maxY = -Infinity;
66
+ for (const p of points) {
67
+ if (p.x < minX) minX = p.x;
68
+ if (p.y < minY) minY = p.y;
69
+ if (p.x > maxX) maxX = p.x;
70
+ if (p.y > maxY) maxY = p.y;
71
+ }
72
+ return {
73
+ x: minX,
74
+ y: minY,
75
+ width: maxX - minX,
76
+ height: maxY - minY
77
+ };
78
+ }
79
+ /**
80
+ * Attempt to detect a geometric shape from freehand points.
81
+ * Returns the detected shape or null if no shape is recognized.
82
+ *
83
+ * Points should be in pixel coordinates. Duration in milliseconds.
84
+ */
85
+ export function detectShape(points, durationMs) {
86
+ if (points.length < 5) return null;
87
+ const first = points[0];
88
+ const last = points[points.length - 1];
89
+ const startEndDist = dist(first, last);
90
+ const inflections = countInflections(points);
91
+
92
+ // ── Circle detection ──
93
+ // Duration < 1.5s, inflections ≤ 5, distance start↔end < threshold,
94
+ // total angle ≈ 2π (±45°)
95
+ if (durationMs < 1500 && inflections <= 5 && startEndDist < 150) {
96
+ const totalAngle = Math.abs(totalAngleTraversed(points));
97
+ const twoPi = 2 * Math.PI;
98
+ const tolerance = Math.PI / 4; // 45°
99
+
100
+ if (Math.abs(totalAngle - twoPi) < tolerance) {
101
+ const bbox = boundingRect(points);
102
+ return {
103
+ type: "circle",
104
+ from: {
105
+ x: bbox.x,
106
+ y: bbox.y
107
+ },
108
+ to: {
109
+ x: bbox.x + bbox.width,
110
+ y: bbox.y + bbox.height
111
+ }
112
+ };
113
+ }
114
+ }
115
+
116
+ // ── Rectangle detection ──
117
+ // Duration < 12s, inflections ≤ 15, distance start↔end < threshold
118
+ if (durationMs < 12000 && inflections <= 15 && startEndDist < 30) {
119
+ const bbox = boundingRect(points);
120
+ return {
121
+ type: "rectangle",
122
+ from: {
123
+ x: bbox.x,
124
+ y: bbox.y
125
+ },
126
+ to: {
127
+ x: bbox.x + bbox.width,
128
+ y: bbox.y + bbox.height
129
+ }
130
+ };
131
+ }
132
+
133
+ // ── Line detection ──
134
+ // Duration < 4s, inflections ≤ 4 (checked from 11th point onward)
135
+ if (durationMs < 4000 && points.length >= 11) {
136
+ const lineInflections = countInflections(points, 10);
137
+ if (lineInflections <= 4) {
138
+ return {
139
+ type: "line",
140
+ from: first,
141
+ to: last
142
+ };
143
+ }
144
+ }
145
+ return null;
146
+ }
147
+ //# sourceMappingURL=shapeDetection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["countInflections","points","startIndex","length","inflections","i","Math","max","prev","curr","next","dx1","x","dy1","y","dx2","dy2","cross","prevPrev","pdx1","pdy1","prevCross","totalAngleTraversed","totalAngle","a1","atan2","a2","delta","PI","dist","a","b","dx","dy","sqrt","boundingRect","minX","Infinity","minY","maxX","maxY","p","width","height","detectShape","durationMs","first","last","startEndDist","abs","twoPi","tolerance","bbox","type","from","to","lineInflections"],"sourceRoot":"../../../src","sources":["utils/shapeDetection.ts"],"mappings":";;AAEA;AACA;AACA;AACA;AACA,SAASA,gBAAgBA,CAACC,MAAe,EAAEC,UAAU,GAAG,CAAC,EAAU;EACjE,IAAID,MAAM,CAACE,MAAM,GAAG,CAAC,EAAE,OAAO,CAAC;EAE/B,IAAIC,WAAW,GAAG,CAAC;EACnB,KAAK,IAAIC,CAAC,GAAGC,IAAI,CAACC,GAAG,CAACL,UAAU,EAAE,CAAC,CAAC,EAAEG,CAAC,GAAGJ,MAAM,CAACE,MAAM,GAAG,CAAC,EAA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EAAE,EAAE;IAC5C,MAAMqD,eAAe,GAAGxD,gBAAgB,CAACC,MAAM,EAAE,EAAE,CAAC;IACpD,IAAIuD,eAAe,IAAI,CAAC,EAAE;MACxB,OAAO;QACLH,IAAI,EAAE,MAAM;QACZC,IAAI,EAAER,KAAK;QACXS,EAAE,EAAER;MACN,CAAC;IACH;EACF;EAEA,OAAO,IAAI;AACb","ignoreList":[]}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Build a smoothed SVG path string from an array of pixel-space points
5
+ * using quadratic Bezier curves through midpoints.
6
+ *
7
+ * This is the standard "midpoint smoothing" algorithm for touch-based drawing:
8
+ * each raw point becomes a control point, and the curve passes through the
9
+ * midpoints between consecutive raw points.
10
+ */
11
+ export function buildSmoothedPath(points) {
12
+ const n = points.length;
13
+ if (n === 0) return "";
14
+ if (n === 1) return `M ${points[0].x} ${points[0].y}`;
15
+ const first = points[0];
16
+ if (n === 2) {
17
+ const second = points[1];
18
+ return `M ${first.x} ${first.y} L ${second.x} ${second.y}`;
19
+ }
20
+
21
+ // Start at first point
22
+ const parts = [`M ${first.x} ${first.y}`];
23
+
24
+ // Line to first midpoint
25
+ const p1 = points[1];
26
+ const m0x = (first.x + p1.x) / 2;
27
+ const m0y = (first.y + p1.y) / 2;
28
+ parts.push(`L ${m0x} ${m0y}`);
29
+
30
+ // Quadratic curves through midpoints
31
+ for (let i = 1; i < n - 1; i++) {
32
+ const cp = points[i];
33
+ const next = points[i + 1];
34
+ const mx = (cp.x + next.x) / 2;
35
+ const my = (cp.y + next.y) / 2;
36
+ parts.push(`Q ${cp.x} ${cp.y} ${mx} ${my}`);
37
+ }
38
+
39
+ // Line to last point
40
+ const last = points[n - 1];
41
+ parts.push(`L ${last.x} ${last.y}`);
42
+ return parts.join(" ");
43
+ }
44
+
45
+ /**
46
+ * Build a smoothed SVG path from a flat array [x0, y0, x1, y1, ...].
47
+ * Used in worklets where Point objects aren't available.
48
+ */
49
+ export function buildSmoothedPathFromFlat(coords) {
50
+ "worklet";
51
+
52
+ const n = coords.length / 2;
53
+ if (n < 1) return "";
54
+ if (n === 1) return `M ${coords[0]} ${coords[1]}`;
55
+ if (n === 2) {
56
+ return `M ${coords[0]} ${coords[1]} L ${coords[2]} ${coords[3]}`;
57
+ }
58
+ let svg = `M ${coords[0]} ${coords[1]}`;
59
+
60
+ // Line to first midpoint
61
+ const m0x = (coords[0] + coords[2]) / 2;
62
+ const m0y = (coords[1] + coords[3]) / 2;
63
+ svg += ` L ${m0x} ${m0y}`;
64
+
65
+ // Quadratic curves through midpoints
66
+ for (let i = 1; i < n - 1; i++) {
67
+ const cx = coords[i * 2];
68
+ const cy = coords[i * 2 + 1];
69
+ const nx = coords[(i + 1) * 2];
70
+ const ny = coords[(i + 1) * 2 + 1];
71
+ const mx = (cx + nx) / 2;
72
+ const my = (cy + ny) / 2;
73
+ svg += ` Q ${cx} ${cy} ${mx} ${my}`;
74
+ }
75
+
76
+ // Line to last point
77
+ svg += ` L ${coords[(n - 1) * 2]} ${coords[(n - 1) * 2 + 1]}`;
78
+ return svg;
79
+ }
80
+ //# sourceMappingURL=smoothing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["buildSmoothedPath","points","n","length","x","y","first","second","parts","p1","m0x","m0y","push","i","cp","next","mx","my","last","join","buildSmoothedPathFromFlat","coords","svg","cx","cy","nx","ny"],"sourceRoot":"../../../src","sources":["utils/smoothing.ts"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,iBAAiBA,CAACC,MAAe,EAAU;EACzD,MAAMC,CAAC,GAAGD,MAAM,CAACE,MAAM;EACvB,IAAID,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE;EACtB,IAAIA,CAAC,KAAK,CAAC,EAAE,OAAO,KAAKD,MAAM,CAAC,CAAC,CAAC,CAAEG,CAAC,IAAIH,MAAM,CAAC,CAAC,CAAC,CAAEI,CAAC,EAAE;EAEvD,MAAMC,KAAK,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AAG,CAAC,CAAE;IAC7B,MAAMY,EAAE,GAAGJ,MAAM,CAAC,CAACR,CAAC,GAAG,CAAC,IAAI,CAAC,CAAE;IAC/B,MAAMa,EAAE,GAAGL,MAAM,CAAC,CAACR,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE;IACnC,MAAMG,EAAE,GAAG,CAACO,EAAE,GAAGE,EAAE,IAAI,CAAC;IACxB,MAAMR,EAAE,GAAG,CAACO,EAAE,GAAGE,EAAE,IAAI,CAAC;IACxBJ,GAAG,IAAI,MAAMC,EAAE,IAAIC,EAAE,IAAIR,EAAE,IAAIC,EAAE,EAAE;EACrC;;EAEA;EACAK,GAAG,IAAI,MAAMD,MAAM,CAAC,CAACnB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAImB,MAAM,CAAC,CAACnB,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;EAE7D,OAAOoB,GAAG;AACZ","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ import type { DrawingEditorProps, DrawingEditorRef } from "./types";
2
+ export declare const DrawingEditor: import("react").ForwardRefExoticComponent<DrawingEditorProps & import("react").RefAttributes<DrawingEditorRef>>;
3
+ //# sourceMappingURL=DrawingEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DrawingEditor.d.ts","sourceRoot":"","sources":["../../src/DrawingEditor.tsx"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAMjB,MAAM,SAAS,CAAC;AA4EjB,eAAO,MAAM,aAAa,iHA84BzB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ interface ColorPaletteProps {
3
+ strokeColor: string;
4
+ onSelectColor: (color: string) => void;
5
+ direction?: "horizontal" | "vertical";
6
+ }
7
+ export declare const ColorPalette: React.NamedExoticComponent<ColorPaletteProps>;
8
+ export {};
9
+ //# sourceMappingURL=ColorPalette.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColorPalette.d.ts","sourceRoot":"","sources":["../../../src/components/ColorPalette.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAa9D,UAAU,iBAAiB;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,SAAS,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;CACvC;AAED,eAAO,MAAM,YAAY,+CA6DvB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ interface LineWidthSliderProps {
3
+ value: number;
4
+ onValueChange: (value: number) => void;
5
+ minimumValue?: number;
6
+ maximumValue?: number;
7
+ orientation?: "horizontal" | "vertical";
8
+ }
9
+ export declare const LineWidthSlider: React.NamedExoticComponent<LineWidthSliderProps>;
10
+ export {};
11
+ //# sourceMappingURL=LineWidthSlider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LineWidthSlider.d.ts","sourceRoot":"","sources":["../../../src/components/LineWidthSlider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAI3C,UAAU,oBAAoB;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;CACzC;AAED,eAAO,MAAM,eAAe,kDA6C1B,CAAC"}
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ interface MeasurementEditModalProps {
3
+ visible: boolean;
4
+ initialValue: string;
5
+ initialUnit: string;
6
+ onSubmit: (value: string, unit: string) => void;
7
+ onCancel: () => void;
8
+ }
9
+ export declare const MeasurementEditModal: React.NamedExoticComponent<MeasurementEditModalProps>;
10
+ export {};
11
+ //# sourceMappingURL=MeasurementEditModal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MeasurementEditModal.d.ts","sourceRoot":"","sources":["../../../src/components/MeasurementEditModal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAgC,MAAM,OAAO,CAAC;AAYrD,UAAU,yBAAyB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,oBAAoB,uDAuE/B,CAAC"}
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import { type SkImage } from "@shopify/react-native-skia";
3
+ import { type SharedValue } from "react-native-reanimated";
4
+ interface MiniMapProps {
5
+ image: SkImage | null;
6
+ /** Image rect within the layout (fitted) */
7
+ imageRect: {
8
+ x: number;
9
+ y: number;
10
+ width: number;
11
+ height: number;
12
+ };
13
+ /** Viewport shared values */
14
+ scale: SharedValue<number>;
15
+ translateX: SharedValue<number>;
16
+ translateY: SharedValue<number>;
17
+ visible: boolean;
18
+ /** Clamp translate callback — keeps viewport in bounds */
19
+ onPanViewport?: (dtx: number, dty: number) => void;
20
+ }
21
+ export declare const MiniMap: React.NamedExoticComponent<MiniMapProps>;
22
+ export {};
23
+ //# sourceMappingURL=MiniMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MiniMap.d.ts","sourceRoot":"","sources":["../../../src/components/MiniMap.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiB,MAAM,OAAO,CAAC;AAEtC,OAAO,EAIL,KAAK,OAAO,EACb,MAAM,4BAA4B,CAAC;AACpC,OAAiB,EAGf,KAAK,WAAW,EACjB,MAAM,yBAAyB,CAAC;AAKjC,UAAU,YAAY;IACpB,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IACtB,4CAA4C;IAC5C,SAAS,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,6BAA6B;IAC7B,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,0DAA0D;IAC1D,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD;AAED,eAAO,MAAM,OAAO,0CAkFlB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import type { SharedValue } from "react-native-reanimated";
3
+ import type { TextObject, Size } from "../types";
4
+ interface TextAnnotationProps {
5
+ object: TextObject;
6
+ canvasSize: Size;
7
+ imageOffset: {
8
+ x: number;
9
+ y: number;
10
+ };
11
+ isSelected: boolean;
12
+ onSelect: (id: string) => void;
13
+ onMove: (id: string, dx: number, dy: number) => void;
14
+ onDoubleTap: (id: string) => void;
15
+ onDelete: (id: string) => void;
16
+ viewScale: SharedValue<number>;
17
+ viewTranslateX: SharedValue<number>;
18
+ viewTranslateY: SharedValue<number>;
19
+ }
20
+ export declare const TextAnnotation: React.NamedExoticComponent<TextAnnotationProps>;
21
+ export {};
22
+ //# sourceMappingURL=TextAnnotation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextAnnotation.d.ts","sourceRoot":"","sources":["../../../src/components/TextAnnotation.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+B,MAAM,OAAO,CAAC;AAcpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGjD,UAAU,mBAAmB;IAC3B,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,IAAI,CAAC;IACjB,WAAW,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC/B,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACpC,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACrC;AAID,eAAO,MAAM,cAAc,iDAoIzB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ interface TextEditModalProps {
3
+ visible: boolean;
4
+ initialValue: string;
5
+ onSubmit: (value: string) => void;
6
+ onCancel: () => void;
7
+ }
8
+ export declare const TextEditModal: React.NamedExoticComponent<TextEditModalProps>;
9
+ export {};
10
+ //# sourceMappingURL=TextEditModal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextEditModal.d.ts","sourceRoot":"","sources":["../../../src/components/TextEditModal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAgC,MAAM,OAAO,CAAC;AAYrD,UAAU,kBAAkB;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,aAAa,gDA2DxB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+ import type { ToolType } from "../types";
3
+ interface ToolbarProps {
4
+ currentTool: ToolType | null;
5
+ onSelectTool: (tool: ToolType | null) => void;
6
+ onUndo: () => void;
7
+ canUndo: boolean;
8
+ isZoomed: boolean;
9
+ onResetZoom: () => void;
10
+ }
11
+ export declare const Toolbar: React.NamedExoticComponent<ToolbarProps>;
12
+ export {};
13
+ //# sourceMappingURL=Toolbar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["../../../src/components/Toolbar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAW3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,UAAU,YAAY;IACpB,WAAW,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC7B,YAAY,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,KAAK,IAAI,CAAC;IAC9C,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AA0FD,eAAO,MAAM,OAAO,0CA4DlB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { type SharedValue } from "react-native-reanimated";
3
+ interface ZoomBadgeProps {
4
+ scale: SharedValue<number>;
5
+ onPress: () => void;
6
+ }
7
+ export declare const ZoomBadge: React.NamedExoticComponent<ZoomBadgeProps>;
8
+ export {};
9
+ //# sourceMappingURL=ZoomBadge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZoomBadge.d.ts","sourceRoot":"","sources":["../../../src/components/ZoomBadge.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAiB,EAIf,KAAK,WAAW,EACjB,MAAM,yBAAyB,CAAC;AAOjC,UAAU,cAAc;IACtB,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,SAAS,4CAgEpB,CAAC"}