tempest-react-sdk 0.38.3 → 0.39.1

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 (519) hide show
  1. package/README.md +1 -1
  2. package/dist/_virtual/_rolldown/runtime.cjs +1 -1
  3. package/dist/access/access-control-context.cjs.map +1 -1
  4. package/dist/access/use-can.cjs.map +1 -1
  5. package/dist/app/AppProviders.cjs.map +1 -1
  6. package/dist/app/AppProviders.js.map +1 -1
  7. package/dist/audio/use-audio-recorder.cjs.map +1 -1
  8. package/dist/audio/use-audio.cjs.map +1 -1
  9. package/dist/audio/use-microphone.cjs.map +1 -1
  10. package/dist/auth/create-auth-store.cjs.map +1 -1
  11. package/dist/auth/lazy-with-retry.cjs.map +1 -1
  12. package/dist/auth/use-passkey.cjs.map +1 -1
  13. package/dist/br/BrazilMap.cjs +1 -1
  14. package/dist/br/BrazilMap.cjs.map +1 -1
  15. package/dist/br/BrazilMap.js +2 -2
  16. package/dist/br/BrazilMap.js.map +1 -1
  17. package/dist/br/BrazilStateCitySelect.cjs.map +1 -1
  18. package/dist/br/BrazilStateCitySelect.js.map +1 -1
  19. package/dist/br/BrazilStateMap.cjs +1 -1
  20. package/dist/br/BrazilStateMap.cjs.map +1 -1
  21. package/dist/br/BrazilStateMap.js +2 -2
  22. package/dist/br/BrazilStateMap.js.map +1 -1
  23. package/dist/br/MapLegend.cjs.map +1 -1
  24. package/dist/br/MapLegend.js.map +1 -1
  25. package/dist/br/MapMarkers.cjs.map +1 -1
  26. package/dist/br/MapMarkers.js.map +1 -1
  27. package/dist/br/MunicipalitySearch.cjs.map +1 -1
  28. package/dist/br/MunicipalitySearch.js.map +1 -1
  29. package/dist/br/PixQRCode.cjs.map +1 -1
  30. package/dist/br/PixQRCode.js.map +1 -1
  31. package/dist/br/use-map-hover.cjs.map +1 -1
  32. package/dist/br/use-map-zoom.cjs.map +1 -1
  33. package/dist/capture/media-recorder.cjs +1 -1
  34. package/dist/capture/media-recorder.js +2 -2
  35. package/dist/capture/use-barcode-scanner.cjs +1 -1
  36. package/dist/capture/use-barcode-scanner.cjs.map +1 -1
  37. package/dist/capture/use-barcode-scanner.js +2 -2
  38. package/dist/capture/use-barcode-scanner.js.map +1 -1
  39. package/dist/capture/use-screen-capture.cjs.map +1 -1
  40. package/dist/capture/use-speech-recognition.cjs.map +1 -1
  41. package/dist/capture/use-torch.cjs.map +1 -1
  42. package/dist/capture/use-video-recorder.cjs.map +1 -1
  43. package/dist/charts/AreaChart.cjs.map +1 -1
  44. package/dist/charts/AreaChart.js.map +1 -1
  45. package/dist/charts/BarChart.cjs.map +1 -1
  46. package/dist/charts/BarChart.js.map +1 -1
  47. package/dist/charts/LineChart.cjs.map +1 -1
  48. package/dist/charts/LineChart.js.map +1 -1
  49. package/dist/charts/PieChart.cjs.map +1 -1
  50. package/dist/charts/PieChart.js.map +1 -1
  51. package/dist/charts/RadarChart.cjs.map +1 -1
  52. package/dist/charts/RadarChart.js.map +1 -1
  53. package/dist/charts/use-chart-colors.cjs.map +1 -1
  54. package/dist/components/AIChat/AIChat.cjs.map +1 -1
  55. package/dist/components/AIChat/AIChat.js.map +1 -1
  56. package/dist/components/AIChat/AIChatComposer.cjs.map +1 -1
  57. package/dist/components/AIChat/AIChatComposer.js.map +1 -1
  58. package/dist/components/AIChat/AIChatTurn.cjs.map +1 -1
  59. package/dist/components/AIChat/AIChatTurn.js.map +1 -1
  60. package/dist/components/Accordion/Accordion.cjs.map +1 -1
  61. package/dist/components/Accordion/Accordion.js.map +1 -1
  62. package/dist/components/Alert/Alert.cjs.map +1 -1
  63. package/dist/components/Alert/Alert.js.map +1 -1
  64. package/dist/components/AppBar/AppBar.cjs.map +1 -1
  65. package/dist/components/AppBar/AppBar.js.map +1 -1
  66. package/dist/components/AppShell/AppShell.cjs.map +1 -1
  67. package/dist/components/AppShell/AppShell.js.map +1 -1
  68. package/dist/components/AudioPlayer/AudioPlayer.cjs.map +1 -1
  69. package/dist/components/AudioPlayer/AudioPlayer.js.map +1 -1
  70. package/dist/components/AudioRecorder/AudioRecorder.cjs.map +1 -1
  71. package/dist/components/AudioRecorder/AudioRecorder.js.map +1 -1
  72. package/dist/components/Avatar/Avatar.cjs.map +1 -1
  73. package/dist/components/Avatar/Avatar.js.map +1 -1
  74. package/dist/components/AvatarGroup/AvatarGroup.cjs.map +1 -1
  75. package/dist/components/AvatarGroup/AvatarGroup.js.map +1 -1
  76. package/dist/components/Badge/Badge.cjs.map +1 -1
  77. package/dist/components/Badge/Badge.js.map +1 -1
  78. package/dist/components/Banner/Banner.cjs.map +1 -1
  79. package/dist/components/Banner/Banner.js.map +1 -1
  80. package/dist/components/BarcodeScanner/BarcodeScanner.cjs.map +1 -1
  81. package/dist/components/BarcodeScanner/BarcodeScanner.js.map +1 -1
  82. package/dist/components/BottomNavigation/BottomNavigation.cjs.map +1 -1
  83. package/dist/components/BottomNavigation/BottomNavigation.js.map +1 -1
  84. package/dist/components/BottomSheet/BottomSheet.cjs.map +1 -1
  85. package/dist/components/BottomSheet/BottomSheet.js.map +1 -1
  86. package/dist/components/Breadcrumbs/Breadcrumbs.cjs.map +1 -1
  87. package/dist/components/Breadcrumbs/Breadcrumbs.js.map +1 -1
  88. package/dist/components/Button/Button.cjs.map +1 -1
  89. package/dist/components/Button/Button.js.map +1 -1
  90. package/dist/components/Calendar/Calendar.cjs +1 -1
  91. package/dist/components/Calendar/Calendar.cjs.map +1 -1
  92. package/dist/components/Calendar/Calendar.js +38 -41
  93. package/dist/components/Calendar/Calendar.js.map +1 -1
  94. package/dist/components/Card/Card.cjs.map +1 -1
  95. package/dist/components/Card/Card.js.map +1 -1
  96. package/dist/components/Carousel/Carousel.cjs.map +1 -1
  97. package/dist/components/Carousel/Carousel.js.map +1 -1
  98. package/dist/components/Chat/Chat.cjs.map +1 -1
  99. package/dist/components/Chat/Chat.js.map +1 -1
  100. package/dist/components/Chat/ChatComposer.cjs.map +1 -1
  101. package/dist/components/Chat/ChatComposer.js.map +1 -1
  102. package/dist/components/Chat/chat-groups.cjs +1 -1
  103. package/dist/components/Chat/chat-groups.cjs.map +1 -1
  104. package/dist/components/Chat/chat-groups.js +2 -2
  105. package/dist/components/Chat/chat-groups.js.map +1 -1
  106. package/dist/components/Checkbox/Checkbox.cjs.map +1 -1
  107. package/dist/components/Checkbox/Checkbox.js.map +1 -1
  108. package/dist/components/ChipInput/ChipInput.cjs.map +1 -1
  109. package/dist/components/ChipInput/ChipInput.js.map +1 -1
  110. package/dist/components/ClickOutside/ClickOutside.cjs.map +1 -1
  111. package/dist/components/CodeBlock/CodeBlock.cjs.map +1 -1
  112. package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
  113. package/dist/components/Collapsible/Collapsible.cjs.map +1 -1
  114. package/dist/components/Collapsible/Collapsible.js.map +1 -1
  115. package/dist/components/Combobox/Combobox.cjs.map +1 -1
  116. package/dist/components/Combobox/Combobox.js.map +1 -1
  117. package/dist/components/Command/Command.cjs.map +1 -1
  118. package/dist/components/Command/Command.js.map +1 -1
  119. package/dist/components/ConfirmDialog/ConfirmDialog.cjs.map +1 -1
  120. package/dist/components/ConfirmDialog/ConfirmDialog.js.map +1 -1
  121. package/dist/components/ContextMenu/ContextMenu.cjs.map +1 -1
  122. package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
  123. package/dist/components/CopyButton/CopyButton.cjs.map +1 -1
  124. package/dist/components/CopyButton/CopyButton.js.map +1 -1
  125. package/dist/components/DataList/DataList.cjs.map +1 -1
  126. package/dist/components/DataList/DataList.js.map +1 -1
  127. package/dist/components/DataTable/DataTable.cjs +1 -1
  128. package/dist/components/DataTable/DataTable.cjs.map +1 -1
  129. package/dist/components/DataTable/DataTable.js +2 -2
  130. package/dist/components/DataTable/DataTable.js.map +1 -1
  131. package/dist/components/DataTable/EditableCell.cjs.map +1 -1
  132. package/dist/components/DataTable/EditableCell.js.map +1 -1
  133. package/dist/components/DatePicker/DatePicker.cjs.map +1 -1
  134. package/dist/components/DateRangePicker/DateRangePicker.cjs.map +1 -1
  135. package/dist/components/DateRangePicker/DateRangePicker.js.map +1 -1
  136. package/dist/components/DescriptionList/DescriptionList.cjs.map +1 -1
  137. package/dist/components/DescriptionList/DescriptionList.js.map +1 -1
  138. package/dist/components/Divider/Divider.cjs.map +1 -1
  139. package/dist/components/Divider/Divider.js.map +1 -1
  140. package/dist/components/Drawer/Drawer.cjs.map +1 -1
  141. package/dist/components/Drawer/Drawer.js.map +1 -1
  142. package/dist/components/DropdownMenu/DropdownMenu.cjs.map +1 -1
  143. package/dist/components/DropdownMenu/DropdownMenu.js.map +1 -1
  144. package/dist/components/Dropzone/Dropzone.cjs.map +1 -1
  145. package/dist/components/Dropzone/Dropzone.js.map +1 -1
  146. package/dist/components/EmptyState/EmptyState.cjs.map +1 -1
  147. package/dist/components/EmptyState/EmptyState.js.map +1 -1
  148. package/dist/components/ErrorState/ErrorState.cjs.map +1 -1
  149. package/dist/components/ErrorState/ErrorState.js.map +1 -1
  150. package/dist/components/FileUpload/FileUpload.cjs +1 -1
  151. package/dist/components/FileUpload/FileUpload.cjs.map +1 -1
  152. package/dist/components/FileUpload/FileUpload.js +1 -1
  153. package/dist/components/FileUpload/FileUpload.js.map +1 -1
  154. package/dist/components/FilterBar/FilterBar.cjs.map +1 -1
  155. package/dist/components/FilterBar/FilterBar.js.map +1 -1
  156. package/dist/components/FloatingActionButton/FloatingActionButton.cjs.map +1 -1
  157. package/dist/components/FloatingActionButton/FloatingActionButton.js.map +1 -1
  158. package/dist/components/Form/Form.cjs.map +1 -1
  159. package/dist/components/Form/Form.js.map +1 -1
  160. package/dist/components/HoverCard/HoverCard.cjs.map +1 -1
  161. package/dist/components/HoverCard/HoverCard.js.map +1 -1
  162. package/dist/components/Image/Image.cjs.map +1 -1
  163. package/dist/components/ImageCropper/ImageCropper.cjs +1 -1
  164. package/dist/components/ImageCropper/ImageCropper.cjs.map +1 -1
  165. package/dist/components/ImageCropper/ImageCropper.js +1 -1
  166. package/dist/components/ImageCropper/ImageCropper.js.map +1 -1
  167. package/dist/components/Input/Input.cjs.map +1 -1
  168. package/dist/components/Input/Input.js.map +1 -1
  169. package/dist/components/InstallBanner/InstallBanner.cjs.map +1 -1
  170. package/dist/components/InstallBanner/InstallBanner.js.map +1 -1
  171. package/dist/components/InstallButton/InstallButton.cjs.map +1 -1
  172. package/dist/components/InstallButton/InstallButton.js.map +1 -1
  173. package/dist/components/Kanban/Kanban.cjs.map +1 -1
  174. package/dist/components/Kanban/Kanban.js.map +1 -1
  175. package/dist/components/Label/Label.cjs.map +1 -1
  176. package/dist/components/Label/Label.js.map +1 -1
  177. package/dist/components/Lightbox/Lightbox.cjs.map +1 -1
  178. package/dist/components/Lightbox/Lightbox.js.map +1 -1
  179. package/dist/components/ListTile/ListTile.cjs.map +1 -1
  180. package/dist/components/ListTile/ListTile.js.map +1 -1
  181. package/dist/components/Markdown/Markdown.cjs +1 -1
  182. package/dist/components/Markdown/Markdown.cjs.map +1 -1
  183. package/dist/components/Markdown/Markdown.js +2 -2
  184. package/dist/components/Markdown/Markdown.js.map +1 -1
  185. package/dist/components/Masonry/Masonry.cjs.map +1 -1
  186. package/dist/components/Masonry/Masonry.js.map +1 -1
  187. package/dist/components/Menubar/Menubar.cjs.map +1 -1
  188. package/dist/components/Menubar/Menubar.js.map +1 -1
  189. package/dist/components/Modal/Modal.cjs.map +1 -1
  190. package/dist/components/Modal/Modal.js.map +1 -1
  191. package/dist/components/ModalsManager/ModalsManager.cjs.map +1 -1
  192. package/dist/components/ModalsManager/ModalsManager.js.map +1 -1
  193. package/dist/components/Money/Money.cjs.map +1 -1
  194. package/dist/components/Money/Money.js.map +1 -1
  195. package/dist/components/MultiSelect/MultiSelect.cjs.map +1 -1
  196. package/dist/components/MultiSelect/MultiSelect.js.map +1 -1
  197. package/dist/components/NProgress/NProgress.cjs.map +1 -1
  198. package/dist/components/Navbar/Navbar.cjs.map +1 -1
  199. package/dist/components/Navbar/Navbar.js.map +1 -1
  200. package/dist/components/NavigationMenu/NavigationMenu.cjs.map +1 -1
  201. package/dist/components/NavigationMenu/NavigationMenu.js.map +1 -1
  202. package/dist/components/NavigationRail/NavigationRail.cjs.map +1 -1
  203. package/dist/components/NavigationRail/NavigationRail.js.map +1 -1
  204. package/dist/components/NotificationCenter/NotificationCenter.cjs.map +1 -1
  205. package/dist/components/NotificationCenter/NotificationCenter.js.map +1 -1
  206. package/dist/components/NotificationCenter/use-notification-inbox.cjs.map +1 -1
  207. package/dist/components/OfflineIndicator/OfflineIndicator.cjs.map +1 -1
  208. package/dist/components/OfflineIndicator/OfflineIndicator.js.map +1 -1
  209. package/dist/components/Page/Page.cjs.map +1 -1
  210. package/dist/components/Page/Page.js.map +1 -1
  211. package/dist/components/Pagination/Pagination.cjs.map +1 -1
  212. package/dist/components/Pagination/Pagination.js.map +1 -1
  213. package/dist/components/PasswordInput/PasswordInput.cjs.map +1 -1
  214. package/dist/components/PasswordInput/PasswordInput.js.map +1 -1
  215. package/dist/components/PinInput/PinInput.cjs.map +1 -1
  216. package/dist/components/PinInput/PinInput.js.map +1 -1
  217. package/dist/components/Popover/Popover.cjs.map +1 -1
  218. package/dist/components/Popover/Popover.js.map +1 -1
  219. package/dist/components/Portal/Portal.cjs.map +1 -1
  220. package/dist/components/Progress/Progress.cjs.map +1 -1
  221. package/dist/components/Progress/Progress.js.map +1 -1
  222. package/dist/components/QRCode/QRCode.cjs.map +1 -1
  223. package/dist/components/QRCode/QRCode.js.map +1 -1
  224. package/dist/components/Radio/Radio.cjs.map +1 -1
  225. package/dist/components/Radio/Radio.js.map +1 -1
  226. package/dist/components/RangeSlider/RangeSlider.cjs.map +1 -1
  227. package/dist/components/RangeSlider/RangeSlider.js.map +1 -1
  228. package/dist/components/RatingStars/RatingStars.cjs.map +1 -1
  229. package/dist/components/RatingStars/RatingStars.js.map +1 -1
  230. package/dist/components/RefreshIndicator/RefreshIndicator.cjs.map +1 -1
  231. package/dist/components/RefreshIndicator/RefreshIndicator.js.map +1 -1
  232. package/dist/components/RelativeTime/RelativeTime.cjs.map +1 -1
  233. package/dist/components/RelativeTime/RelativeTime.js.map +1 -1
  234. package/dist/components/Resizable/Resizable.cjs.map +1 -1
  235. package/dist/components/Resizable/Resizable.js.map +1 -1
  236. package/dist/components/Scheduler/Scheduler.cjs.map +1 -1
  237. package/dist/components/Scheduler/Scheduler.js.map +1 -1
  238. package/dist/components/ScrollArea/ScrollArea.cjs.map +1 -1
  239. package/dist/components/SearchBar/SearchBar.cjs.map +1 -1
  240. package/dist/components/SearchBar/SearchBar.js.map +1 -1
  241. package/dist/components/SegmentedControl/SegmentedControl.cjs.map +1 -1
  242. package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
  243. package/dist/components/Select/Select.cjs.map +1 -1
  244. package/dist/components/Select/Select.js.map +1 -1
  245. package/dist/components/Sidebar/Sidebar.cjs.map +1 -1
  246. package/dist/components/Sidebar/Sidebar.js.map +1 -1
  247. package/dist/components/SignaturePad/SignaturePad.cjs.map +1 -1
  248. package/dist/components/SignaturePad/SignaturePad.js.map +1 -1
  249. package/dist/components/Slider/Slider.cjs.map +1 -1
  250. package/dist/components/Slider/Slider.js.map +1 -1
  251. package/dist/components/Sparkline/Sparkline.cjs.map +1 -1
  252. package/dist/components/Sparkline/Sparkline.js.map +1 -1
  253. package/dist/components/Spinner/Spinner.cjs.map +1 -1
  254. package/dist/components/Spinner/Spinner.js.map +1 -1
  255. package/dist/components/Stat/Stat.cjs.map +1 -1
  256. package/dist/components/Stat/Stat.js.map +1 -1
  257. package/dist/components/Stepper/Stepper.cjs.map +1 -1
  258. package/dist/components/Stepper/Stepper.js.map +1 -1
  259. package/dist/components/StepperInput/StepperInput.cjs.map +1 -1
  260. package/dist/components/StepperInput/StepperInput.js.map +1 -1
  261. package/dist/components/Switch/Switch.cjs.map +1 -1
  262. package/dist/components/Switch/Switch.js.map +1 -1
  263. package/dist/components/SyncStatusBadge/SyncStatusBadge.cjs.map +1 -1
  264. package/dist/components/SyncStatusBadge/SyncStatusBadge.js.map +1 -1
  265. package/dist/components/Table/Table.cjs.map +1 -1
  266. package/dist/components/Table/Table.js.map +1 -1
  267. package/dist/components/Tabs/Tabs.cjs.map +1 -1
  268. package/dist/components/Tabs/Tabs.js.map +1 -1
  269. package/dist/components/Tag/Tag.cjs.map +1 -1
  270. package/dist/components/Tag/Tag.js.map +1 -1
  271. package/dist/components/Textarea/Textarea.cjs.map +1 -1
  272. package/dist/components/Textarea/Textarea.js.map +1 -1
  273. package/dist/components/TimePicker/TimePicker.cjs.map +1 -1
  274. package/dist/components/TimePicker/TimePicker.js.map +1 -1
  275. package/dist/components/Timeline/Timeline.cjs.map +1 -1
  276. package/dist/components/Timeline/Timeline.js.map +1 -1
  277. package/dist/components/Toast/ToastProvider.cjs.map +1 -1
  278. package/dist/components/Toast/ToastProvider.js.map +1 -1
  279. package/dist/components/Toggle/Toggle.cjs.map +1 -1
  280. package/dist/components/ToggleGroup/ToggleGroup.cjs.map +1 -1
  281. package/dist/components/ToggleGroup/ToggleGroup.js.map +1 -1
  282. package/dist/components/Tooltip/Tooltip.cjs.map +1 -1
  283. package/dist/components/Tooltip/Tooltip.js.map +1 -1
  284. package/dist/components/Tour/Tour.cjs.map +1 -1
  285. package/dist/components/Tour/Tour.js.map +1 -1
  286. package/dist/components/Transfer/Transfer.cjs.map +1 -1
  287. package/dist/components/Transfer/Transfer.js.map +1 -1
  288. package/dist/components/TreeView/TreeView.cjs +1 -1
  289. package/dist/components/TreeView/TreeView.cjs.map +1 -1
  290. package/dist/components/TreeView/TreeView.js +1 -4
  291. package/dist/components/TreeView/TreeView.js.map +1 -1
  292. package/dist/components/UpdatePrompt/UpdatePrompt.cjs.map +1 -1
  293. package/dist/components/UpdatePrompt/UpdatePrompt.js.map +1 -1
  294. package/dist/components/VirtualList/VirtualList.cjs.map +1 -1
  295. package/dist/components/VirtualList/VirtualList.js.map +1 -1
  296. package/dist/components/VirtualTable/VirtualTable.cjs.map +1 -1
  297. package/dist/components/VirtualTable/VirtualTable.js.map +1 -1
  298. package/dist/components/VisuallyHidden/VisuallyHidden.cjs.map +1 -1
  299. package/dist/components/Wizard/Wizard.cjs.map +1 -1
  300. package/dist/components/Wizard/Wizard.js.map +1 -1
  301. package/dist/data/data-provider-context.cjs.map +1 -1
  302. package/dist/data/use-resource.cjs.map +1 -1
  303. package/dist/editor/RichTextEditor.cjs.map +1 -1
  304. package/dist/editor/RichTextEditor.js.map +1 -1
  305. package/dist/error-boundary/use-error-handler.cjs.map +1 -1
  306. package/dist/feature-flags/FeatureFlagsProvider.cjs.map +1 -1
  307. package/dist/forms/FormField.cjs.map +1 -1
  308. package/dist/forms/masked-inputs.cjs.map +1 -1
  309. package/dist/forms/use-viacep.cjs.map +1 -1
  310. package/dist/forms/use-zod-form.cjs.map +1 -1
  311. package/dist/geo/TrajectoryMap.cjs.map +1 -1
  312. package/dist/geo/TrajectoryMap.js.map +1 -1
  313. package/dist/geo/leaflet-map.cjs.map +1 -1
  314. package/dist/geo/leaflet-map.js.map +1 -1
  315. package/dist/geo/use-position-tracker.cjs.map +1 -1
  316. package/dist/hooks/use-announce.cjs.map +1 -1
  317. package/dist/hooks/use-async.cjs.map +1 -1
  318. package/dist/hooks/use-before-install-prompt.cjs.map +1 -1
  319. package/dist/hooks/use-breakpoint.cjs.map +1 -1
  320. package/dist/hooks/use-click-outside.cjs.map +1 -1
  321. package/dist/hooks/use-client-filter.cjs.map +1 -1
  322. package/dist/hooks/use-clipboard.cjs.map +1 -1
  323. package/dist/hooks/use-counter.cjs.map +1 -1
  324. package/dist/hooks/use-debounce.cjs.map +1 -1
  325. package/dist/hooks/use-deep-memo.cjs.map +1 -1
  326. package/dist/hooks/use-disclosure.cjs.map +1 -1
  327. package/dist/hooks/use-document-visibility.cjs.map +1 -1
  328. package/dist/hooks/use-event-listener.cjs.map +1 -1
  329. package/dist/hooks/use-geolocation.cjs.map +1 -1
  330. package/dist/hooks/use-hover.cjs.map +1 -1
  331. package/dist/hooks/use-idle.cjs.map +1 -1
  332. package/dist/hooks/use-install-prompt.cjs +1 -1
  333. package/dist/hooks/use-install-prompt.cjs.map +1 -1
  334. package/dist/hooks/use-install-prompt.js +1 -1
  335. package/dist/hooks/use-install-prompt.js.map +1 -1
  336. package/dist/hooks/use-intersection-observer.cjs.map +1 -1
  337. package/dist/hooks/use-interval.cjs.map +1 -1
  338. package/dist/hooks/use-is-first-render.cjs.map +1 -1
  339. package/dist/hooks/use-keyboard-shortcut.cjs +1 -1
  340. package/dist/hooks/use-keyboard-shortcut.cjs.map +1 -1
  341. package/dist/hooks/use-keyboard-shortcut.js +1 -1
  342. package/dist/hooks/use-keyboard-shortcut.js.map +1 -1
  343. package/dist/hooks/use-list-state.cjs.map +1 -1
  344. package/dist/hooks/use-local-storage.cjs.map +1 -1
  345. package/dist/hooks/use-long-press-handlers.cjs.map +1 -1
  346. package/dist/hooks/use-long-press.cjs.map +1 -1
  347. package/dist/hooks/use-map.cjs.map +1 -1
  348. package/dist/hooks/use-media-devices.cjs.map +1 -1
  349. package/dist/hooks/use-media-permission.cjs.map +1 -1
  350. package/dist/hooks/use-media-query.cjs.map +1 -1
  351. package/dist/hooks/use-object-url.cjs.map +1 -1
  352. package/dist/hooks/use-online.cjs.map +1 -1
  353. package/dist/hooks/use-pagination.cjs.map +1 -1
  354. package/dist/hooks/use-previous.cjs.map +1 -1
  355. package/dist/hooks/use-queue.cjs.map +1 -1
  356. package/dist/hooks/use-resize-observer.cjs.map +1 -1
  357. package/dist/hooks/use-scroll-overflow.cjs.map +1 -1
  358. package/dist/hooks/use-service-worker-update.cjs.map +1 -1
  359. package/dist/hooks/use-set.cjs.map +1 -1
  360. package/dist/hooks/use-sortable.cjs +1 -1
  361. package/dist/hooks/use-sortable.cjs.map +1 -1
  362. package/dist/hooks/use-sortable.js +0 -2
  363. package/dist/hooks/use-sortable.js.map +1 -1
  364. package/dist/hooks/use-stable-callback.cjs.map +1 -1
  365. package/dist/hooks/use-storage-estimate.cjs.map +1 -1
  366. package/dist/hooks/use-throttle.cjs.map +1 -1
  367. package/dist/hooks/use-timeout.cjs.map +1 -1
  368. package/dist/hooks/use-toggle.cjs.map +1 -1
  369. package/dist/hooks/use-window-size.cjs.map +1 -1
  370. package/dist/http/api-client.cjs +1 -1
  371. package/dist/http/api-client.cjs.map +1 -1
  372. package/dist/http/api-client.js +7 -5
  373. package/dist/http/api-client.js.map +1 -1
  374. package/dist/http/resumable-upload.cjs +1 -1
  375. package/dist/http/resumable-upload.cjs.map +1 -1
  376. package/dist/http/resumable-upload.js +1 -1
  377. package/dist/http/resumable-upload.js.map +1 -1
  378. package/dist/http/use-poll.cjs.map +1 -1
  379. package/dist/i18n/I18nProvider.cjs.map +1 -1
  380. package/dist/icons/Icon.cjs.map +1 -1
  381. package/dist/icons/IconProvider.cjs.map +1 -1
  382. package/dist/icons/icon-context.cjs.map +1 -1
  383. package/dist/icons/use-icon.cjs.map +1 -1
  384. package/dist/imaging/use-image-processing.cjs.map +1 -1
  385. package/dist/oauth/GoogleSignIn.cjs.map +1 -1
  386. package/dist/oauth/GoogleSignIn.js.map +1 -1
  387. package/dist/oauth/use-oauth-callback.cjs.map +1 -1
  388. package/dist/offline/use-offline-sync.cjs.map +1 -1
  389. package/dist/push/use-push-subscription.cjs.map +1 -1
  390. package/dist/query/QueryProvider.cjs.map +1 -1
  391. package/dist/query/constants.cjs +1 -1
  392. package/dist/query/constants.cjs.map +1 -1
  393. package/dist/query/constants.js +10 -10
  394. package/dist/query/constants.js.map +1 -1
  395. package/dist/query/create-query-keys.cjs +1 -1
  396. package/dist/query/create-query-keys.cjs.map +1 -1
  397. package/dist/query/create-query-keys.js +1 -1
  398. package/dist/query/create-query-keys.js.map +1 -1
  399. package/dist/query/offline-persistence.cjs.map +1 -1
  400. package/dist/query/use-cursor-query.cjs.map +1 -1
  401. package/dist/query/use-offline-mutation.cjs.map +1 -1
  402. package/dist/query/use-paginated-query.cjs.map +1 -1
  403. package/dist/router/AppRouter.cjs +1 -1
  404. package/dist/router/AppRouter.cjs.map +1 -1
  405. package/dist/router/AppRouter.js +7 -2
  406. package/dist/router/AppRouter.js.map +1 -1
  407. package/dist/sse/use-event-stream.cjs.map +1 -1
  408. package/dist/store/create-store.cjs.map +1 -1
  409. package/dist/tabular/use-tabular-predictor.cjs.map +1 -1
  410. package/dist/telemetry/TelemetryProvider.cjs.map +1 -1
  411. package/dist/theme/ThemeProvider.cjs.map +1 -1
  412. package/dist/theme/color.cjs +1 -1
  413. package/dist/theme/color.cjs.map +1 -1
  414. package/dist/theme/color.js +1 -1
  415. package/dist/theme/color.js.map +1 -1
  416. package/dist/utils/cn.cjs +1 -1
  417. package/dist/utils/cn.cjs.map +1 -1
  418. package/dist/utils/cn.js +1 -1
  419. package/dist/utils/cn.js.map +1 -1
  420. package/dist/utils/objects.cjs +1 -1
  421. package/dist/utils/objects.cjs.map +1 -1
  422. package/dist/utils/objects.js +1 -1
  423. package/dist/utils/objects.js.map +1 -1
  424. package/dist/utils/xlsx.cjs +1 -1
  425. package/dist/utils/xlsx.cjs.map +1 -1
  426. package/dist/utils/xlsx.js +3 -3
  427. package/dist/utils/xlsx.js.map +1 -1
  428. package/dist/vision/core/canvas.cjs +1 -1
  429. package/dist/vision/core/canvas.cjs.map +1 -1
  430. package/dist/vision/core/canvas.js +4 -4
  431. package/dist/vision/core/canvas.js.map +1 -1
  432. package/dist/vision/core/exceptions.cjs +1 -1
  433. package/dist/vision/core/exceptions.cjs.map +1 -1
  434. package/dist/vision/core/exceptions.js +2 -2
  435. package/dist/vision/core/exceptions.js.map +1 -1
  436. package/dist/vision/core/metadata.cjs +2 -2
  437. package/dist/vision/core/metadata.cjs.map +1 -1
  438. package/dist/vision/core/metadata.js +11 -8
  439. package/dist/vision/core/metadata.js.map +1 -1
  440. package/dist/vision/core/session.cjs +1 -1
  441. package/dist/vision/core/session.cjs.map +1 -1
  442. package/dist/vision/core/session.js +8 -5
  443. package/dist/vision/core/session.js.map +1 -1
  444. package/dist/vision/fusion.cjs +2 -0
  445. package/dist/vision/fusion.cjs.map +1 -0
  446. package/dist/vision/fusion.js +42 -0
  447. package/dist/vision/fusion.js.map +1 -0
  448. package/dist/vision/index.cjs +1 -1
  449. package/dist/vision/index.cjs.map +1 -1
  450. package/dist/vision/index.js +23 -20
  451. package/dist/vision/index.js.map +1 -1
  452. package/dist/vision/io/image.cjs +1 -1
  453. package/dist/vision/io/image.cjs.map +1 -1
  454. package/dist/vision/io/image.js +4 -2
  455. package/dist/vision/io/image.js.map +1 -1
  456. package/dist/vision/labels.cjs +1 -1
  457. package/dist/vision/labels.cjs.map +1 -1
  458. package/dist/vision/labels.js +7 -4
  459. package/dist/vision/labels.js.map +1 -1
  460. package/dist/vision/postprocess/detection.cjs +1 -1
  461. package/dist/vision/postprocess/detection.cjs.map +1 -1
  462. package/dist/vision/postprocess/detection.js +3 -10
  463. package/dist/vision/postprocess/detection.js.map +1 -1
  464. package/dist/vision/postprocess/segmentation.cjs +1 -1
  465. package/dist/vision/postprocess/segmentation.cjs.map +1 -1
  466. package/dist/vision/postprocess/segmentation.js +11 -15
  467. package/dist/vision/postprocess/segmentation.js.map +1 -1
  468. package/dist/vision/preprocess/image.cjs +1 -1
  469. package/dist/vision/preprocess/image.cjs.map +1 -1
  470. package/dist/vision/preprocess/image.js +4 -2
  471. package/dist/vision/preprocess/image.js.map +1 -1
  472. package/dist/vision/preprocess/pipeline.cjs +2 -0
  473. package/dist/vision/preprocess/pipeline.cjs.map +1 -0
  474. package/dist/vision/preprocess/pipeline.js +61 -0
  475. package/dist/vision/preprocess/pipeline.js.map +1 -0
  476. package/dist/vision/results.cjs +1 -1
  477. package/dist/vision/results.cjs.map +1 -1
  478. package/dist/vision/results.js +23 -2
  479. package/dist/vision/results.js.map +1 -1
  480. package/dist/vision/tasks/base.cjs +1 -1
  481. package/dist/vision/tasks/base.cjs.map +1 -1
  482. package/dist/vision/tasks/base.js +11 -2
  483. package/dist/vision/tasks/base.js.map +1 -1
  484. package/dist/vision/tasks/classifier.cjs +1 -1
  485. package/dist/vision/tasks/classifier.cjs.map +1 -1
  486. package/dist/vision/tasks/classifier.js +2 -2
  487. package/dist/vision/tasks/classifier.js.map +1 -1
  488. package/dist/vision/tasks/detectClassify.cjs +2 -0
  489. package/dist/vision/tasks/detectClassify.cjs.map +1 -0
  490. package/dist/vision/tasks/detectClassify.js +222 -0
  491. package/dist/vision/tasks/detectClassify.js.map +1 -0
  492. package/dist/vision/tasks/detector.cjs +1 -1
  493. package/dist/vision/tasks/detector.cjs.map +1 -1
  494. package/dist/vision/tasks/detector.js +54 -29
  495. package/dist/vision/tasks/detector.js.map +1 -1
  496. package/dist/vision/tasks/segmenter.cjs +1 -1
  497. package/dist/vision/tasks/segmenter.cjs.map +1 -1
  498. package/dist/vision/tasks/segmenter.js +53 -28
  499. package/dist/vision/tasks/segmenter.js.map +1 -1
  500. package/dist/vision/types.cjs.map +1 -1
  501. package/dist/vision/types.js.map +1 -1
  502. package/dist/vision/use-camera-stream.cjs.map +1 -1
  503. package/dist/vision/use-live-luminance.cjs.map +1 -1
  504. package/dist/vision.cjs +1 -1
  505. package/dist/vision.d.ts +1517 -962
  506. package/dist/vision.js +25 -22
  507. package/dist/vite/create-vite-config.cjs +1 -1
  508. package/dist/vite/create-vite-config.cjs.map +1 -1
  509. package/dist/vite/create-vite-config.js +3 -3
  510. package/dist/vite/create-vite-config.js.map +1 -1
  511. package/dist/vite/tempest-icons.cjs.map +1 -1
  512. package/dist/vite/tempest-pwa-dev-sw.cjs.map +1 -1
  513. package/dist/vite/tempest-pwa-icons.cjs.map +1 -1
  514. package/dist/ws/use-web-socket.cjs +1 -1
  515. package/dist/ws/use-web-socket.cjs.map +1 -1
  516. package/dist/ws/use-web-socket.js +5 -3
  517. package/dist/ws/use-web-socket.js.map +1 -1
  518. package/package.json +2 -2
  519. package/template/package.json +1 -1
@@ -1,16 +1,17 @@
1
1
  import { Mask as e, RGBImage as t } from "../types.js";
2
2
  import { SpeedTimer as n } from "../core/timing.js";
3
3
  import { Boxes as r, Masks as i, SegmentationResults as a } from "../results.js";
4
- import { resolveLabels as o } from "../labels.js";
5
- import { detectionNumClasses as s, resolveInputSize as c } from "../core/graph.js";
6
- import { modelNames as l } from "../core/metadata.js";
7
- import { OrtSession as u } from "../core/session.js";
8
- import { loadImage as d } from "../io/image.js";
9
- import { letterbox as f, toCHW as p, toFloat32 as m, toFloat32Tensor as h } from "../preprocess/image.js";
4
+ import { defaultLabels as o, resolveLabels as s } from "../labels.js";
5
+ import { detectionNumClasses as c, resolveInputSize as l } from "../core/graph.js";
6
+ import { modelNames as u } from "../core/metadata.js";
7
+ import { OrtSession as d } from "../core/session.js";
8
+ import { loadImage as f } from "../io/image.js";
9
+ import { toFloat32Tensor as p } from "../preprocess/image.js";
10
+ import { LetterboxPipeline as m, zeroTensorData as h } from "../preprocess/pipeline.js";
10
11
  import { decodeYoloSeg as g } from "../postprocess/segmentation.js";
11
- import { VisionTask as _ } from "./base.js";
12
+ import { VisionTask as _, requireDetections as v } from "./base.js";
12
13
  //#region src/vision/tasks/segmenter.ts
13
- var v = class v extends _ {
14
+ var y = class y extends _ {
14
15
  _head;
15
16
  _labels;
16
17
  _names;
@@ -19,19 +20,36 @@ var v = class v extends _ {
19
20
  _iouThreshold;
20
21
  _maxDetections;
21
22
  _maskThreshold;
22
- constructor(e, t, n, r, i, a, o, s, c) {
23
- super(e), this._head = t, this._labels = n, this._names = r, this._inputSize = i, this._confThreshold = a, this._iouThreshold = o, this._maxDetections = s, this._maskThreshold = c;
23
+ _raiseOnEmpty;
24
+ constructor(e, t, n, r, i, a, o, s, c, l) {
25
+ super(e), this._head = t, this._labels = n, this._names = r, this._inputSize = i, this._confThreshold = a, this._iouThreshold = o, this._maxDetections = s, this._maskThreshold = c, this._raiseOnEmpty = l;
26
+ }
27
+ _pipelineCache = null;
28
+ async warmup(e = 1) {
29
+ let [t, n] = this._inputSize;
30
+ for (let r = 0; r < e; r++) {
31
+ let e = p(h(t, n), [
32
+ 1,
33
+ 3,
34
+ n,
35
+ t
36
+ ]);
37
+ await this._session.run({ [this._session.inputName]: e });
38
+ }
39
+ }
40
+ get _pipeline() {
41
+ return this._pipelineCache === null && (this._pipelineCache = new m(this._inputSize[0], this._inputSize[1])), this._pipelineCache;
24
42
  }
25
43
  static async create(e, t = {}) {
26
44
  let n = t.head ?? "yolo-seg";
27
45
  if (n !== "yolo-seg") throw Error(`Unsupported segmenter head '${n}'. Supported: 'yolo-seg'.`);
28
- let r = await u.create(e, t), i = o(t.labels ?? l(r.metadata) ?? "coco", { numClasses: t.numClasses ?? s(r.outputShape) ?? void 0 }), a = {};
29
- for (let e = 0; e < i.length; e++) a[e] = i[e];
30
- return new v(r, n, i, a, c({
46
+ let r = await d.create(e, t), i = t.numClasses ?? c(r.outputShape) ?? void 0, a = s(t.labels ?? u(r.metadata) ?? o(i), { numClasses: i }), f = {};
47
+ for (let e = 0; e < a.length; e++) f[e] = a[e];
48
+ return new y(r, n, a, f, l({
31
49
  graphShape: r.inputShape,
32
50
  requested: t.inputSize,
33
51
  fallback: [640, 640]
34
- }), t.confThreshold ?? .25, t.iouThreshold ?? .45, t.maxDetections ?? 300, t.maskThreshold ?? .5);
52
+ }), t.confThreshold ?? .25, t.iouThreshold ?? .45, t.maxDetections ?? 300, t.maskThreshold ?? .5, t.raiseOnEmpty ?? !1);
35
53
  }
36
54
  get head() {
37
55
  return this._head;
@@ -52,13 +70,13 @@ var v = class v extends _ {
52
70
  return this.predict(e, t);
53
71
  }
54
72
  async predict(e, t = {}) {
55
- let r = new n(), i = typeof e == "string" ? e : null, o = await d(e);
73
+ let r = new n(), i = typeof e == "string" ? e : null, o = await f(e);
56
74
  r.stage("load");
57
75
  let { tensor: s, scale: c, padLeft: l, padTop: u } = this._preprocess(o);
58
76
  r.stage("preprocess");
59
- let f = await this._session.run({ [this._session.inputName]: s });
60
- r.stage("inference");
61
- let { perAnchor: p, prototypes: m } = this._splitOutputs(f), h = g(p.data, p.dims, m.data, m.dims, {
77
+ let d = await this._session.run({ [this._session.inputName]: s });
78
+ this._pipeline.release(), r.stage("inference");
79
+ let { perAnchor: p, prototypes: m } = this._splitOutputs(d), h = t.confThreshold ?? this._confThreshold, _ = g(p.data, p.dims, m.data, m.dims, {
62
80
  numClasses: this._labels.length,
63
81
  inputWidth: this._inputSize[0],
64
82
  inputHeight: this._inputSize[1],
@@ -67,24 +85,31 @@ var v = class v extends _ {
67
85
  padLeft: l,
68
86
  padTop: u,
69
87
  scale: c,
70
- confThreshold: t.confThreshold ?? this._confThreshold,
88
+ confThreshold: h,
71
89
  iouThreshold: t.iouThreshold ?? this._iouThreshold,
72
90
  maxDetections: this._maxDetections,
73
91
  maskThreshold: this._maskThreshold
74
- }), _ = (t.classes === void 0 ? h : (() => {
92
+ }), y = t.classes === void 0 ? _ : (() => {
75
93
  let e = new Set(t.classes);
76
- return h.filter((t) => e.has(t.classId));
77
- })()).map((e) => this._buildResult(o, e.bbox, e.classId, e.confidence, e.mask)), v = [o.height, o.width], y = this._buildBoxes(_, v), b = this._buildMasks(_, v);
78
- return r.stage("postprocess"), [new a(y, b, _, this._names, o, v, i, r.speed())];
94
+ return _.filter((t) => e.has(t.classId));
95
+ })();
96
+ v(y.length, {
97
+ raiseOnEmpty: t.raiseOnEmpty ?? this._raiseOnEmpty,
98
+ confThreshold: h,
99
+ classes: t.classes,
100
+ path: i
101
+ });
102
+ let b = y.map((e) => this._buildResult(o, e.bbox, e.classId, e.confidence, e.mask)), x = [o.height, o.width], S = this._buildBoxes(b, x), C = this._buildMasks(b, x);
103
+ return r.stage("postprocess"), [new a(S, C, b, this._names, o, x, i, r.speed())];
79
104
  }
80
105
  _preprocess(e) {
81
- let [t, n] = this._inputSize, r = f(e, t, n);
106
+ let [t, n] = this._inputSize, r = this._pipeline.run(e);
82
107
  return {
83
- tensor: h(p(m(r.image), r.image.width, r.image.height, 3), [
108
+ tensor: p(r.data, [
84
109
  1,
85
110
  3,
86
- r.image.height,
87
- r.image.width
111
+ n,
112
+ t
88
113
  ]),
89
114
  scale: r.scale,
90
115
  padLeft: r.padLeft,
@@ -155,6 +180,6 @@ var v = class v extends _ {
155
180
  }
156
181
  };
157
182
  //#endregion
158
- export { v as Segmenter };
183
+ export { y as Segmenter };
159
184
 
160
185
  //# sourceMappingURL=segmenter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"segmenter.js","names":[],"sources":["../../../src/vision/tasks/segmenter.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Instance-segmentation task using YOLO seg ONNX models (v8-seg / v11-seg / ...).\n */\n\nimport type * as ort from \"onnxruntime-web\";\n\nimport { type ModelSource, type OrtSessionOptions, OrtSession } from \"../core/session\";\nimport { SpeedTimer } from \"../core/timing\";\n\nimport { type ImageInput, loadImage } from \"../io/image\";\nimport { detectionNumClasses, resolveInputSize } from \"../core/graph\";\nimport { modelNames } from \"../core/metadata\";\nimport { type LabelSpec, resolveLabels } from \"../labels\";\nimport { decodeYoloSeg } from \"../postprocess/segmentation\";\nimport { letterbox, toCHW, toFloat32, toFloat32Tensor } from \"../preprocess/image\";\nimport { Boxes, Masks, SegmentationResults } from \"../results\";\nimport { VisionTask } from \"./base\";\nimport { type BoundingBox, type SegmentationResult, Mask, RGBImage } from \"../types\";\n\n/**\n * Decoder family for the segmentation head.\n *\n * - `\"yolo-seg\"`: YOLO instance-segmentation head with two outputs —\n * `[1, 4 + nc + nm, N]` per-anchor predictions plus `[1, nm, mh, mw]`\n * prototype masks. Covers YOLOv8-seg, v11-seg, v26-seg.\n *\n * The SDK does **not** auto-detect this — the caller is responsible for\n * picking a head that matches their export.\n */\nexport type SegmenterHead = \"yolo-seg\";\n\nexport interface SegmenterOptions extends OrtSessionOptions {\n /**\n * Decoder family for the segmentation head. Default `\"yolo-seg\"` covers\n * YOLOv8-seg/v11-seg/v26-seg.\n */\n readonly head?: SegmenterHead;\n /** Class label spec — see {@link resolveLabels}. Defaults to the COCO 80-class preset. */\n readonly labels?: LabelSpec;\n /** Number of classes — used to validate the supplied labels. */\n readonly numClasses?: number;\n /**\n * Model input `[width, height]` in pixels for letterboxing.\n *\n * Only used when the model's graph leaves its spatial axes dynamic: a graph\n * that declares a static size always wins, since that is the only shape ONNX\n * Runtime will accept. Defaults to `[640, 640]`.\n */\n readonly inputSize?: readonly [number, number];\n /** Default minimum class score to keep a candidate. */\n readonly confThreshold?: number;\n /** Default IoU threshold for non-maximum suppression. */\n readonly iouThreshold?: number;\n /** Maximum number of instances per image. */\n readonly maxDetections?: number;\n /** Probability cutoff applied to soft masks. Defaults to `0.5`. */\n readonly maskThreshold?: number;\n}\n\nexport interface SegmenterPredictOptions {\n readonly confThreshold?: number;\n readonly iouThreshold?: number;\n /**\n * If set, keep only instances whose `classId` is in this list.\n * Mirrors Ultralytics' `model.predict(img, classes=[0, 16])`.\n */\n readonly classes?: readonly number[];\n}\n\n/**\n * Instance segmenter for YOLO seg ONNX models (v8-seg / v11-seg / ...).\n *\n * The model is expected to expose two outputs:\n *\n * 1. `output0`: `(1, 4 + numClasses + numMaskCoefs, numAnchors)` — per-anchor\n * predictions (boxes, class scores, mask coefficients).\n * 2. `output1`: `(1, numMaskCoefs, maskH, maskW)` — prototype masks.\n *\n * `predict()` returns `Promise<SegmentationResults[]>` (length 1 for a\n * single image), mirroring Ultralytics' API. The envelope exposes:\n *\n * - `boxes`: bulk numpy view (`xyxy`, `xywh`, `xyxyn`, `xywhn`, `cls`, `conf`).\n * - `masks`: per-instance binary masks cropped to each box.\n * - per-instance {@link SegmentationResult} via iteration.\n *\n * @example\n * ```typescript\n * const seg = await Segmenter.create(\"/models/yolov8n-seg.onnx\");\n * const r = (await seg.predict(\"/images/street.jpg\"))[0];\n * for (const inst of r) {\n * console.log(inst.cls, inst.conf, inst.box.xyxy);\n * }\n * ```\n */\nexport class Segmenter extends VisionTask {\n private constructor(\n session: OrtSession,\n private readonly _head: SegmenterHead,\n private readonly _labels: readonly string[],\n private readonly _names: Readonly<Record<number, string>>,\n private readonly _inputSize: readonly [number, number],\n private readonly _confThreshold: number,\n private readonly _iouThreshold: number,\n private readonly _maxDetections: number,\n private readonly _maskThreshold: number,\n ) {\n super(session);\n }\n\n /** Load the model and resolve labels. */\n static async create(model: ModelSource, options: SegmenterOptions = {}): Promise<Segmenter> {\n const head: SegmenterHead = options.head ?? \"yolo-seg\";\n if (head !== \"yolo-seg\") {\n throw new Error(`Unsupported segmenter head '${head}'. Supported: 'yolo-seg'.`);\n }\n const session = await OrtSession.create(model, options);\n const labels = resolveLabels(options.labels ?? modelNames(session.metadata) ?? \"coco\", {\n numClasses: options.numClasses ?? detectionNumClasses(session.outputShape) ?? undefined,\n });\n const names: Record<number, string> = {};\n for (let i = 0; i < labels.length; i++) {\n names[i] = labels[i] as string;\n }\n return new Segmenter(\n session,\n head,\n labels,\n names,\n resolveInputSize({\n graphShape: session.inputShape,\n requested: options.inputSize,\n fallback: [640, 640],\n }),\n options.confThreshold ?? 0.25,\n options.iouThreshold ?? 0.45,\n options.maxDetections ?? 300,\n options.maskThreshold ?? 0.5,\n );\n }\n\n /** The decoder family used to interpret the model's output. */\n get head(): SegmenterHead {\n return this._head;\n }\n\n /** Class labels indexed by class id. */\n get labels(): readonly string[] {\n return this._labels;\n }\n\n /** Class id → class name dict (matches Ultralytics' `model.names`). */\n get names(): Readonly<Record<number, string>> {\n return this._names;\n }\n\n /**\n * The `[width, height]` this task preprocesses to.\n *\n * Resolved at creation time from the model's graph when it declares a static\n * input, so reading it back tells you the resolution inference really runs at\n * — not merely what was requested.\n */\n get inputSize(): readonly [number, number] {\n return this._inputSize;\n }\n\n /** Number of classes the model predicts. */\n get numClasses(): number {\n return this._labels.length;\n }\n\n /** Alias for {@link predict} (parity with PyTorch `nn.Module.__call__`). */\n async call(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n return this.predict(image, options);\n }\n\n /** Run instance segmentation on a single image. */\n async predict(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n const timer = new SpeedTimer();\n const path = typeof image === \"string\" ? image : null;\n const original = await loadImage(image);\n timer.stage(\"load\");\n const { tensor, scale, padLeft, padTop } = this._preprocess(original);\n timer.stage(\"preprocess\");\n const outputs = await this._session.run({ [this._session.inputName]: tensor });\n timer.stage(\"inference\");\n\n const { perAnchor, prototypes } = this._splitOutputs(outputs);\n\n const decodedAll = decodeYoloSeg(\n perAnchor.data as Float32Array,\n perAnchor.dims,\n prototypes.data as Float32Array,\n prototypes.dims,\n {\n numClasses: this._labels.length,\n inputWidth: this._inputSize[0],\n inputHeight: this._inputSize[1],\n originalWidth: original.width,\n originalHeight: original.height,\n padLeft,\n padTop,\n scale,\n confThreshold: options.confThreshold ?? this._confThreshold,\n iouThreshold: options.iouThreshold ?? this._iouThreshold,\n maxDetections: this._maxDetections,\n maskThreshold: this._maskThreshold,\n },\n );\n\n const decoded =\n options.classes !== undefined\n ? (() => {\n const allowed = new Set(options.classes);\n return decodedAll.filter((d) => allowed.has(d.classId));\n })()\n : decodedAll;\n\n const detections = decoded.map((d) =>\n this._buildResult(original, d.bbox, d.classId, d.confidence, d.mask),\n );\n\n const orig: readonly [number, number] = [original.height, original.width];\n const boxes = this._buildBoxes(detections, orig);\n const masks = this._buildMasks(detections, orig);\n timer.stage(\"postprocess\");\n return [\n new SegmentationResults(\n boxes,\n masks,\n detections,\n this._names,\n original,\n orig,\n path,\n timer.speed(),\n ),\n ];\n }\n\n private _preprocess(image: RGBImage): {\n tensor: ort.Tensor;\n scale: number;\n padLeft: number;\n padTop: number;\n } {\n const [tw, th] = this._inputSize;\n const lb = letterbox(image, tw, th);\n const f32 = toFloat32(lb.image);\n const chw = toCHW(f32, lb.image.width, lb.image.height, 3);\n return {\n tensor: toFloat32Tensor(chw, [1, 3, lb.image.height, lb.image.width]),\n scale: lb.scale,\n padLeft: lb.padLeft,\n padTop: lb.padTop,\n };\n }\n\n private _splitOutputs(outputs: Record<string, ort.Tensor>): {\n perAnchor: ort.Tensor;\n prototypes: ort.Tensor;\n } {\n let perAnchor: ort.Tensor | undefined;\n let prototypes: ort.Tensor | undefined;\n for (const name of this._session.outputNames) {\n const t = outputs[name];\n if (t === undefined) continue;\n if (t.dims.length === 3 && perAnchor === undefined) {\n perAnchor = t;\n } else if (t.dims.length === 4 && prototypes === undefined) {\n prototypes = t;\n }\n }\n if (perAnchor === undefined || prototypes === undefined) {\n const shapes = this._session.outputNames.map(\n (n) => `${n}: ${JSON.stringify(outputs[n]?.dims ?? [])}`,\n );\n throw new Error(\n `Segmenter expected one 3-D and one 4-D output, got [${shapes.join(\", \")}].`,\n );\n }\n return { perAnchor, prototypes };\n }\n\n private _buildResult(\n original: RGBImage,\n bbox: BoundingBox,\n classId: number,\n confidence: number,\n mask: Mask,\n ): SegmentationResult {\n const [x1, y1, x2, y2] = bbox.asIntXyxy();\n const cx1 = Math.max(0, x1);\n const cy1 = Math.max(0, y1);\n const cx2 = Math.min(original.width, x2);\n const cy2 = Math.min(original.height, y2);\n\n let segmentedImage: RGBImage;\n let finalMask = mask;\n if (cx2 > cx1 && cy2 > cy1 && mask.data.length > 0) {\n const cropW = cx2 - cx1;\n const cropH = cy2 - cy1;\n const mw = Math.min(mask.width, cropW);\n const mh = Math.min(mask.height, cropH);\n const segData = new Uint8Array(mw * mh * 3);\n for (let row = 0; row < mh; row++) {\n const srcRowOffset = ((cy1 + row) * original.width + cx1) * 3;\n const dstRowOffset = row * mw * 3;\n const maskRowOffset = row * mask.width;\n for (let col = 0; col < mw; col++) {\n const m = mask.data[maskRowOffset + col];\n if (m !== 0) {\n const s = srcRowOffset + col * 3;\n const d = dstRowOffset + col * 3;\n segData[d] = original.data[s];\n segData[d + 1] = original.data[s + 1];\n segData[d + 2] = original.data[s + 2];\n }\n }\n }\n segmentedImage = new RGBImage(segData, mw, mh);\n if (mw !== mask.width || mh !== mask.height) {\n const trimmed = new Uint8Array(mw * mh);\n for (let row = 0; row < mh; row++) {\n trimmed.set(\n mask.data.subarray(row * mask.width, row * mask.width + mw),\n row * mw,\n );\n }\n finalMask = new Mask(trimmed, mw, mh);\n }\n } else {\n finalMask = new Mask(new Uint8Array(0), 0, 0);\n segmentedImage = new RGBImage(new Uint8Array(0), 0, 0);\n }\n\n const className = this._names[classId] ?? `class_${classId}`;\n\n return {\n classId,\n className,\n confidence,\n bbox,\n cls: classId,\n name: className,\n conf: confidence,\n box: bbox,\n mask: finalMask,\n segmentedImage,\n };\n }\n\n private _buildBoxes(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Boxes {\n const n = detections.length;\n const xyxy = new Float32Array(n * 4);\n const cls = new Int32Array(n);\n const conf = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n cls[i] = d.classId;\n conf[i] = d.confidence;\n }\n return new Boxes(xyxy, cls, conf, origShape);\n }\n\n private _buildMasks(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Masks {\n const xyxy = new Float32Array(detections.length * 4);\n for (let i = 0; i < detections.length; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n }\n return new Masks(\n detections.map((d) => d.mask),\n xyxy,\n origShape,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AA+FA,IAAa,IAAb,MAAa,UAAkB,EAAW;CAGjB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CATrB,YACI,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACF;EADmB,AAEjB,MAAM,CAAO,GATI,KAAA,QAAA,GACA,KAAA,UAAA,GACA,KAAA,SAAA,GACA,KAAA,aAAA,GACA,KAAA,iBAAA,G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IAAI,IAAI,KAAK,EAAE,KAAK,IACzB,EAAI,KAAK,EAAE,SACX,EAAK,KAAK,EAAE;EAChB;EACA,OAAO,IAAI,EAAM,GAAM,GAAK,GAAM,CAAS;CAC/C;CAEA,YACI,GACA,GACK;EACL,IAAM,IAAO,IAAI,aAAa,EAAW,SAAS,CAAC;EACnD,KAAK,IAAI,IAAI,GAAG,IAAI,EAAW,QAAQ,KAAK;GACxC,IAAM,IAAI,EAAW;GAIrB,AAHA,EAAK,IAAI,KAAK,EAAE,KAAK,IACrB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK,IACzB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK,IACzB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK;EAC7B;EACA,OAAO,IAAI,EACP,EAAW,KAAK,MAAM,EAAE,IAAI,GAC5B,GACA,CACJ;CACJ;AACJ"}
1
+ {"version":3,"file":"segmenter.js","names":[],"sources":["../../../src/vision/tasks/segmenter.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Instance-segmentation task using YOLO seg ONNX models (v8-seg / v11-seg / ...).\n */\n\nimport type * as ort from \"onnxruntime-web\";\n\nimport { type ModelSource, type OrtSessionOptions, OrtSession } from \"../core/session\";\nimport { SpeedTimer } from \"../core/timing\";\n\nimport { type ImageInput, loadImage } from \"../io/image\";\nimport { detectionNumClasses, resolveInputSize } from \"../core/graph\";\nimport { modelNames } from \"../core/metadata\";\nimport { type LabelSpec, defaultLabels, resolveLabels } from \"../labels\";\nimport { decodeYoloSeg } from \"../postprocess/segmentation\";\nimport { toFloat32Tensor } from \"../preprocess/image\";\nimport { LetterboxPipeline, zeroTensorData } from \"../preprocess/pipeline\";\nimport { Boxes, Masks, SegmentationResults } from \"../results\";\nimport { VisionTask, requireDetections } from \"./base\";\nimport { type BoundingBox, type SegmentationResult, Mask, RGBImage } from \"../types\";\n\n/**\n * Decoder family for the segmentation head.\n *\n * - `\"yolo-seg\"`: YOLO instance-segmentation head with two outputs —\n * `[1, 4 + nc + nm, N]` per-anchor predictions plus `[1, nm, mh, mw]`\n * prototype masks. Covers YOLOv8-seg, v11-seg, v26-seg.\n *\n * The SDK does **not** auto-detect this — the caller is responsible for\n * picking a head that matches their export.\n */\nexport type SegmenterHead = \"yolo-seg\";\n\nexport interface SegmenterOptions extends OrtSessionOptions {\n /**\n * Decoder family for the segmentation head. Default `\"yolo-seg\"` covers\n * YOLOv8-seg/v11-seg/v26-seg.\n */\n readonly head?: SegmenterHead;\n /** Class label spec — see {@link resolveLabels}. Defaults to the COCO 80-class preset. */\n readonly labels?: LabelSpec;\n /** Number of classes — used to validate the supplied labels. */\n readonly numClasses?: number;\n /**\n * Model input `[width, height]` in pixels for letterboxing.\n *\n * Only used when the model's graph leaves its spatial axes dynamic: a graph\n * that declares a static size always wins, since that is the only shape ONNX\n * Runtime will accept. Defaults to `[640, 640]`.\n */\n readonly inputSize?: readonly [number, number];\n /** Default minimum class score to keep a candidate. */\n readonly confThreshold?: number;\n /** Default IoU threshold for non-maximum suppression. */\n readonly iouThreshold?: number;\n /** Maximum number of instances per image. */\n readonly maxDetections?: number;\n /**\n * If `true`, a run that finds nothing throws {@link NoDetectionsError}\n * instead of returning an empty envelope. Default `false`, because looking\n * and finding nothing is a successful inference. Turn it on when an empty\n * result means the surrounding pipeline should stop rather than carry on with\n * zero rows. Can be overridden per `predict` call.\n */\n readonly raiseOnEmpty?: boolean;\n /** Probability cutoff applied to soft masks. Defaults to `0.5`. */\n readonly maskThreshold?: number;\n}\n\nexport interface SegmenterPredictOptions {\n readonly confThreshold?: number;\n readonly iouThreshold?: number;\n /**\n * If set, keep only instances whose `classId` is in this list.\n * Mirrors Ultralytics' `model.predict(img, classes=[0, 16])`.\n */\n readonly classes?: readonly number[];\n /** Override the constructor's `raiseOnEmpty` setting for this call. */\n readonly raiseOnEmpty?: boolean;\n}\n\n/**\n * Instance segmenter for YOLO seg ONNX models (v8-seg / v11-seg / ...).\n *\n * The model is expected to expose two outputs:\n *\n * 1. `output0`: `(1, 4 + numClasses + numMaskCoefs, numAnchors)` — per-anchor\n * predictions (boxes, class scores, mask coefficients).\n * 2. `output1`: `(1, numMaskCoefs, maskH, maskW)` — prototype masks.\n *\n * `predict()` returns `Promise<SegmentationResults[]>` (length 1 for a\n * single image), mirroring Ultralytics' API. The envelope exposes:\n *\n * - `boxes`: bulk numpy view (`xyxy`, `xywh`, `xyxyn`, `xywhn`, `cls`, `conf`).\n * - `masks`: per-instance binary masks cropped to each box.\n * - per-instance {@link SegmentationResult} via iteration.\n *\n * @example\n * ```typescript\n * const seg = await Segmenter.create(\"/models/yolov8n-seg.onnx\");\n * const r = (await seg.predict(\"/images/street.jpg\"))[0];\n * for (const inst of r) {\n * console.log(inst.cls, inst.conf, inst.box.xyxy);\n * }\n * ```\n */\nexport class Segmenter extends VisionTask {\n private constructor(\n session: OrtSession,\n private readonly _head: SegmenterHead,\n private readonly _labels: readonly string[],\n private readonly _names: Readonly<Record<number, string>>,\n private readonly _inputSize: readonly [number, number],\n private readonly _confThreshold: number,\n private readonly _iouThreshold: number,\n private readonly _maxDetections: number,\n private readonly _maskThreshold: number,\n private readonly _raiseOnEmpty: boolean,\n ) {\n super(session);\n }\n\n private _pipelineCache: LetterboxPipeline | null = null;\n\n /**\n * Run the model once on a zero-filled tensor, paying one-time costs up front.\n *\n * The first inference of a session is not representative: WebGPU compiles its\n * shaders on it and the WASM backend faults in its arenas, which on a phone\n * can turn the first frame into seconds while every later frame is tens of\n * milliseconds. Calling this while a loading spinner is still up moves that\n * cost somewhere the user is already waiting.\n *\n * @param runs How many warm-up inferences to run. One is enough for WASM;\n * WebGPU sometimes settles on the second.\n */\n async warmup(runs: number = 1): Promise<void> {\n const [tw, th] = this._inputSize;\n for (let i = 0; i < runs; i++) {\n const tensor = toFloat32Tensor(zeroTensorData(tw, th), [1, 3, th, tw]);\n await this._session.run({ [this._session.inputName]: tensor });\n }\n }\n\n /**\n * The fused preprocessing pipeline, built on first use.\n *\n * Lazily, because constructing it allocates canvases: a task built in an\n * environment without a canvas implementation stays constructible, and only\n * fails if it is actually asked to preprocess something.\n */\n private get _pipeline(): LetterboxPipeline {\n if (this._pipelineCache === null) {\n this._pipelineCache = new LetterboxPipeline(this._inputSize[0], this._inputSize[1]);\n }\n return this._pipelineCache;\n }\n\n /** Load the model and resolve labels. */\n static async create(model: ModelSource, options: SegmenterOptions = {}): Promise<Segmenter> {\n const head: SegmenterHead = options.head ?? \"yolo-seg\";\n if (head !== \"yolo-seg\") {\n throw new Error(`Unsupported segmenter head '${head}'. Supported: 'yolo-seg'.`);\n }\n const session = await OrtSession.create(model, options);\n const numClasses =\n options.numClasses ?? detectionNumClasses(session.outputShape) ?? undefined;\n const labels = resolveLabels(\n options.labels ?? modelNames(session.metadata) ?? defaultLabels(numClasses),\n { numClasses },\n );\n const names: Record<number, string> = {};\n for (let i = 0; i < labels.length; i++) {\n names[i] = labels[i] as string;\n }\n return new Segmenter(\n session,\n head,\n labels,\n names,\n resolveInputSize({\n graphShape: session.inputShape,\n requested: options.inputSize,\n fallback: [640, 640],\n }),\n options.confThreshold ?? 0.25,\n options.iouThreshold ?? 0.45,\n options.maxDetections ?? 300,\n options.maskThreshold ?? 0.5,\n options.raiseOnEmpty ?? false,\n );\n }\n\n /** The decoder family used to interpret the model's output. */\n get head(): SegmenterHead {\n return this._head;\n }\n\n /** Class labels indexed by class id. */\n get labels(): readonly string[] {\n return this._labels;\n }\n\n /** Class id → class name dict (matches Ultralytics' `model.names`). */\n get names(): Readonly<Record<number, string>> {\n return this._names;\n }\n\n /**\n * The `[width, height]` this task preprocesses to.\n *\n * Resolved at creation time from the model's graph when it declares a static\n * input, so reading it back tells you the resolution inference really runs at\n * — not merely what was requested.\n */\n get inputSize(): readonly [number, number] {\n return this._inputSize;\n }\n\n /** Number of classes the model predicts. */\n get numClasses(): number {\n return this._labels.length;\n }\n\n /** Alias for {@link predict} (parity with PyTorch `nn.Module.__call__`). */\n async call(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n return this.predict(image, options);\n }\n\n /** Run instance segmentation on a single image. */\n async predict(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n const timer = new SpeedTimer();\n const path = typeof image === \"string\" ? image : null;\n const original = await loadImage(image);\n timer.stage(\"load\");\n const { tensor, scale, padLeft, padTop } = this._preprocess(original);\n timer.stage(\"preprocess\");\n const outputs = await this._session.run({ [this._session.inputName]: tensor });\n this._pipeline.release();\n timer.stage(\"inference\");\n\n const { perAnchor, prototypes } = this._splitOutputs(outputs);\n\n const threshold = options.confThreshold ?? this._confThreshold;\n const decodedAll = decodeYoloSeg(\n perAnchor.data as Float32Array,\n perAnchor.dims,\n prototypes.data as Float32Array,\n prototypes.dims,\n {\n numClasses: this._labels.length,\n inputWidth: this._inputSize[0],\n inputHeight: this._inputSize[1],\n originalWidth: original.width,\n originalHeight: original.height,\n padLeft,\n padTop,\n scale,\n confThreshold: threshold,\n iouThreshold: options.iouThreshold ?? this._iouThreshold,\n maxDetections: this._maxDetections,\n maskThreshold: this._maskThreshold,\n },\n );\n\n const decoded =\n options.classes !== undefined\n ? (() => {\n const allowed = new Set(options.classes);\n return decodedAll.filter((d) => allowed.has(d.classId));\n })()\n : decodedAll;\n\n requireDetections(decoded.length, {\n raiseOnEmpty: options.raiseOnEmpty ?? this._raiseOnEmpty,\n confThreshold: threshold,\n classes: options.classes,\n path,\n });\n\n const detections = decoded.map((d) =>\n this._buildResult(original, d.bbox, d.classId, d.confidence, d.mask),\n );\n\n const orig: readonly [number, number] = [original.height, original.width];\n const boxes = this._buildBoxes(detections, orig);\n const masks = this._buildMasks(detections, orig);\n timer.stage(\"postprocess\");\n return [\n new SegmentationResults(\n boxes,\n masks,\n detections,\n this._names,\n original,\n orig,\n path,\n timer.speed(),\n ),\n ];\n }\n\n private _preprocess(image: RGBImage): {\n tensor: ort.Tensor;\n scale: number;\n padLeft: number;\n padTop: number;\n } {\n const [tw, th] = this._inputSize;\n const fused = this._pipeline.run(image);\n return {\n tensor: toFloat32Tensor(fused.data, [1, 3, th, tw]),\n scale: fused.scale,\n padLeft: fused.padLeft,\n padTop: fused.padTop,\n };\n }\n\n private _splitOutputs(outputs: Record<string, ort.Tensor>): {\n perAnchor: ort.Tensor;\n prototypes: ort.Tensor;\n } {\n let perAnchor: ort.Tensor | undefined;\n let prototypes: ort.Tensor | undefined;\n for (const name of this._session.outputNames) {\n const t = outputs[name];\n if (t === undefined) continue;\n if (t.dims.length === 3 && perAnchor === undefined) {\n perAnchor = t;\n } else if (t.dims.length === 4 && prototypes === undefined) {\n prototypes = t;\n }\n }\n if (perAnchor === undefined || prototypes === undefined) {\n const shapes = this._session.outputNames.map(\n (n) => `${n}: ${JSON.stringify(outputs[n]?.dims ?? [])}`,\n );\n throw new Error(\n `Segmenter expected one 3-D and one 4-D output, got [${shapes.join(\", \")}].`,\n );\n }\n return { perAnchor, prototypes };\n }\n\n private _buildResult(\n original: RGBImage,\n bbox: BoundingBox,\n classId: number,\n confidence: number,\n mask: Mask,\n ): SegmentationResult {\n const [x1, y1, x2, y2] = bbox.asIntXyxy();\n const cx1 = Math.max(0, x1);\n const cy1 = Math.max(0, y1);\n const cx2 = Math.min(original.width, x2);\n const cy2 = Math.min(original.height, y2);\n\n let segmentedImage: RGBImage;\n let finalMask = mask;\n if (cx2 > cx1 && cy2 > cy1 && mask.data.length > 0) {\n const cropW = cx2 - cx1;\n const cropH = cy2 - cy1;\n const mw = Math.min(mask.width, cropW);\n const mh = Math.min(mask.height, cropH);\n const segData = new Uint8Array(mw * mh * 3);\n for (let row = 0; row < mh; row++) {\n const srcRowOffset = ((cy1 + row) * original.width + cx1) * 3;\n const dstRowOffset = row * mw * 3;\n const maskRowOffset = row * mask.width;\n for (let col = 0; col < mw; col++) {\n const m = mask.data[maskRowOffset + col];\n if (m !== 0) {\n const s = srcRowOffset + col * 3;\n const d = dstRowOffset + col * 3;\n segData[d] = original.data[s];\n segData[d + 1] = original.data[s + 1];\n segData[d + 2] = original.data[s + 2];\n }\n }\n }\n segmentedImage = new RGBImage(segData, mw, mh);\n if (mw !== mask.width || mh !== mask.height) {\n const trimmed = new Uint8Array(mw * mh);\n for (let row = 0; row < mh; row++) {\n trimmed.set(\n mask.data.subarray(row * mask.width, row * mask.width + mw),\n row * mw,\n );\n }\n finalMask = new Mask(trimmed, mw, mh);\n }\n } else {\n finalMask = new Mask(new Uint8Array(0), 0, 0);\n segmentedImage = new RGBImage(new Uint8Array(0), 0, 0);\n }\n\n const className = this._names[classId] ?? `class_${classId}`;\n\n return {\n classId,\n className,\n confidence,\n bbox,\n cls: classId,\n name: className,\n conf: confidence,\n box: bbox,\n mask: finalMask,\n segmentedImage,\n };\n }\n\n private _buildBoxes(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Boxes {\n const n = detections.length;\n const xyxy = new Float32Array(n * 4);\n const cls = new Int32Array(n);\n const conf = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n cls[i] = d.classId;\n conf[i] = d.confidence;\n }\n return new Boxes(xyxy, cls, conf, origShape);\n }\n\n private _buildMasks(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Masks {\n const xyxy = new Float32Array(detections.length * 4);\n for (let i = 0; i < detections.length; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n }\n return new Masks(\n detections.map((d) => d.mask),\n xyxy,\n origShape,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA0GA,I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K,IAAI,IAAI,KAAK,EAAE,KAAK;EAC7B;EACA,OAAO,IAAI,EACP,EAAW,KAAK,MAAM,EAAE,IAAI,GAC5B,GACA,CACJ;CACJ;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","names":[],"sources":["../../src/vision/types.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Public output types returned by the SDK's vision tasks.\n *\n * These types form the contract between the SDK and its callers. They mirror\n * the Python `ort-vision-sdk` output dataclasses 1-to-1.\n *\n * Naming is intentionally compatible with the Ultralytics / torchvision idiom\n * (`cls`, `conf`, `box`, `xyxy`, `xywh`, normalized variants) so code ported\n * from those projects keeps working with minimal edits. The original verbose\n * names (`classId`, `className`, `confidence`, `bbox`) are still populated for\n * backwards compatibility.\n */\n\nimport { ImageLoadError } from \"./core/exceptions\";\n\n/**\n * HWC RGB uint8 image — the canonical image format used across the SDK.\n *\n * `data.length` must equal `width * height * 3`. The buffer is laid out row\n * by row, top-to-bottom, with each pixel as `[R, G, B]`.\n */\nexport class RGBImage {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height * 3) {\n throw new ImageLoadError(\n `RGBImage data length ${data.length} does not match width * height * 3 = ${\n width * height * 3\n }.`,\n );\n }\n }\n}\n\n/**\n * Axis-aligned bounding box in absolute pixel coordinates (xyxy format).\n *\n * Coordinates refer to the original input image (before any internal resize),\n * so callers can map detections back onto their source image without any\n * additional bookkeeping.\n */\nexport class BoundingBox {\n constructor(\n public readonly x1: number,\n public readonly y1: number,\n public readonly x2: number,\n public readonly y2: number,\n ) {}\n\n /** Box width in pixels (clamped to non-negative). */\n get width(): number {\n return Math.max(0, this.x2 - this.x1);\n }\n\n /** Box height in pixels (clamped to non-negative). */\n get height(): number {\n return Math.max(0, this.y2 - this.y1);\n }\n\n /** Box area in pixels squared. */\n get area(): number {\n return this.width * this.height;\n }\n\n /** The box as `[x1, y1, x2, y2]` in absolute pixels (Ultralytics-style). */\n get xyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * The box as `[cx, cy, w, h]` with `(cx, cy)` at the center.\n *\n * Matches Ultralytics' `boxes.xywh` and YOLO's native head format. For the\n * top-left `[x, y, w, h]` convention, use {@link asXywh}.\n */\n get xywh(): readonly [number, number, number, number] {\n return [(this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2, this.width, this.height];\n }\n\n /**\n * The box as `[x1, y1, x2, y2]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xyxyn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n return [this.x1 / w, this.y1 / h, this.x2 / w, this.y2 / h];\n }\n\n /**\n * The box as `[cx, cy, w, h]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xywhn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n const [cx, cy, bw, bh] = this.xywh;\n return [cx / w, cy / h, bw / w, bh / h];\n }\n\n /** Returns `[x1, y1, x2, y2]`. */\n asXyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * Returns `[x, y, width, height]` with `(x, y)` at the **top-left**.\n *\n * Note: this is the top-left convention. Ultralytics' `xywh` getter uses\n * **center** coordinates — for that, read {@link xywh}.\n */\n asXywh(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.width, this.height];\n }\n\n /** Returns `[x1, y1, x2, y2]` truncated to integers, useful for slicing arrays. */\n asIntXyxy(): readonly [number, number, number, number] {\n return [Math.trunc(this.x1), Math.trunc(this.y1), Math.trunc(this.x2), Math.trunc(this.y2)];\n }\n}\n\n/**\n * Probability assigned to a single class for a classification prediction.\n *\n * `cls` / `name` / `conf` are Ultralytics-style aliases populated alongside\n * the verbose `classId` / `className` / `probability` fields.\n */\nexport interface ClassProbability {\n readonly classId: number;\n readonly className: string;\n readonly probability: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `probability` (Ultralytics-style). */\n readonly conf: number;\n}\n\n/**\n * Output of an image classification inference.\n */\nexport interface ClassificationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** The original input image as an HWC RGB uint8 array. */\n readonly image: RGBImage;\n /**\n * Probabilities per class, sorted in descending order. The first entry\n * mirrors `classId`, `className`, and `confidence`. When `topK` was passed\n * to `predict`, the array is truncated to that length.\n */\n readonly probabilities: readonly ClassProbability[];\n}\n\n/**\n * Single detected object produced by an object-detection model.\n */\nexport interface DetectionResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * The original image cropped to `bbox`, HWC RGB uint8. Empty boxes\n * (zero area) yield a zero-sized `RGBImage`.\n */\n readonly croppedImage: RGBImage;\n}\n\n/**\n * Single-channel binary or grayscale mask, laid out row-major.\n *\n * `data.length` must equal `width * height`. For binary masks, values are\n * `0` (background) or `255` (foreground); soft masks may use the full\n * `[0, 255]` range.\n */\nexport class Mask {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height) {\n throw new ImageLoadError(\n `Mask data length ${data.length} does not match width * height = ${\n width * height\n }.`,\n );\n }\n }\n}\n\n/**\n * Single segmented instance produced by an instance-segmentation model.\n *\n * Mirrors {@link DetectionResult} and adds the per-instance binary mask\n * plus a \"ready-to-display\" background-removed crop.\n */\nexport interface SegmentationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * Binary mask cropped to `bbox`. Values are `0` (background) or `255`\n * (foreground). Empty boxes yield a zero-sized `Mask`.\n */\n readonly mask: Mask;\n /**\n * The original image cropped to `bbox` with background pixels (where\n * `mask.data[i] === 0`) zeroed out. Empty boxes yield a zero-sized\n * `RGBImage`.\n */\n readonly segmentedImage: RGBImage;\n}\n"],"mappings":"yCAsBA,IAAa,EAAb,KAAsB,CAEE,KACA,MACA,OAHpB,YACI,EACA,EACA,EACF,CACE,GAJgB,KAAA,KAAA,EACA,KAAA,MAAA,EACA,KAAA,OAAA,EAEZ,EAAK,SAAW,EAAQ,EAAS,EACjC,MAAM,IAAI,EAAA,eACN,wBAAwB,EAAK,OAAO,uCAChC,EAAQ,EAAS,EACpB,EACL,CAER,CACJ,EASa,EAAb,KAAyB,CAED,GACA,GACA,GACA,GAJpB,YACI,EACA,EACA,EACA,EACF,CAJkB,KAAA,GAAA,EACA,KAAA,GAAA,EACA,KAAA,GAAA,EACA,KAAA,GAAA,CACjB,CAGH,IAAI,OAAgB,CAChB,OAAO,KAAK,IAAI,EAAG,KAAK,GAAK,KAAK,EAAE,CACxC,CAGA,IAAI,QAAiB,CACjB,OAAO,KAAK,IAAI,EAAG,KAAK,GAAK,KAAK,EAAE,CACxC,CAGA,IAAI,MAAe,CACf,OAAO,KAAK,MAAQ,KAAK,MAC7B,CAGA,IAAI,MAAkD,CAClD,MAAO,CAAC,KAAK,GAAI,KAAK,GAAI,KAAK,GAA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** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Public output types returned by the SDK's vision tasks.\n *\n * These types form the contract between the SDK and its callers. They mirror\n * the Python `ort-vision-sdk` output dataclasses 1-to-1.\n *\n * Naming is intentionally compatible with the Ultralytics / torchvision idiom\n * (`cls`, `conf`, `box`, `xyxy`, `xywh`, normalized variants) so code ported\n * from those projects keeps working with minimal edits. The original verbose\n * names (`classId`, `className`, `confidence`, `bbox`) are still populated for\n * backwards compatibility.\n */\n\nimport { ImageLoadError } from \"./core/exceptions\";\n\n/**\n * HWC RGB uint8 image — the canonical image format used across the SDK.\n *\n * `data.length` must equal `width * height * 3`. The buffer is laid out row\n * by row, top-to-bottom, with each pixel as `[R, G, B]`.\n */\nexport class RGBImage {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height * 3) {\n throw new ImageLoadError(\n `RGBImage data length ${data.length} does not match width * height * 3 = ${\n width * height * 3\n }.`,\n );\n }\n }\n}\n\n/**\n * Axis-aligned bounding box in absolute pixel coordinates (xyxy format).\n *\n * Coordinates refer to the original input image (before any internal resize),\n * so callers can map detections back onto their source image without any\n * additional bookkeeping.\n */\nexport class BoundingBox {\n constructor(\n public readonly x1: number,\n public readonly y1: number,\n public readonly x2: number,\n public readonly y2: number,\n ) {}\n\n /** Box width in pixels (clamped to non-negative). */\n get width(): number {\n return Math.max(0, this.x2 - this.x1);\n }\n\n /** Box height in pixels (clamped to non-negative). */\n get height(): number {\n return Math.max(0, this.y2 - this.y1);\n }\n\n /** Box area in pixels squared. */\n get area(): number {\n return this.width * this.height;\n }\n\n /** The box as `[x1, y1, x2, y2]` in absolute pixels (Ultralytics-style). */\n get xyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * The box as `[cx, cy, w, h]` with `(cx, cy)` at the center.\n *\n * Matches Ultralytics' `boxes.xywh` and YOLO's native head format. For the\n * top-left `[x, y, w, h]` convention, use {@link asXywh}.\n */\n get xywh(): readonly [number, number, number, number] {\n return [(this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2, this.width, this.height];\n }\n\n /**\n * The box as `[x1, y1, x2, y2]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xyxyn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n return [this.x1 / w, this.y1 / h, this.x2 / w, this.y2 / h];\n }\n\n /**\n * The box as `[cx, cy, w, h]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xywhn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n const [cx, cy, bw, bh] = this.xywh;\n return [cx / w, cy / h, bw / w, bh / h];\n }\n\n /** Returns `[x1, y1, x2, y2]`. */\n asXyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * Returns `[x, y, width, height]` with `(x, y)` at the **top-left**.\n *\n * Note: this is the top-left convention. Ultralytics' `xywh` getter uses\n * **center** coordinates — for that, read {@link xywh}.\n */\n asXywh(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.width, this.height];\n }\n\n /** Returns `[x1, y1, x2, y2]` truncated to integers, useful for slicing arrays. */\n asIntXyxy(): readonly [number, number, number, number] {\n return [Math.trunc(this.x1), Math.trunc(this.y1), Math.trunc(this.x2), Math.trunc(this.y2)];\n }\n}\n\n/**\n * Probability assigned to a single class for a classification prediction.\n *\n * `cls` / `name` / `conf` are Ultralytics-style aliases populated alongside\n * the verbose `classId` / `className` / `probability` fields.\n */\nexport interface ClassProbability {\n readonly classId: number;\n readonly className: string;\n readonly probability: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `probability` (Ultralytics-style). */\n readonly conf: number;\n}\n\n/**\n * Output of an image classification inference.\n */\nexport interface ClassificationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** The original input image as an HWC RGB uint8 array. */\n readonly image: RGBImage;\n /**\n * Probabilities per class, sorted in descending order. The first entry\n * mirrors `classId`, `className`, and `confidence`. When `topK` was passed\n * to `predict`, the array is truncated to that length.\n */\n readonly probabilities: readonly ClassProbability[];\n}\n\n/**\n * Single detected object produced by an object-detection model.\n */\nexport interface DetectionResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * The original image cropped to `bbox`, HWC RGB uint8. Empty boxes\n * (zero area) yield a zero-sized `RGBImage`.\n */\n readonly croppedImage: RGBImage;\n /**\n * What a second, classification stage predicted **for this crop** —\n * populated only by {@link DetectClassify}, and `null` for a plain detector.\n *\n * Kept as its own field rather than folded into `classId`/`className`\n * because the two answers are different questions: the detector says *what\n * kind of object this is*, the classifier says *which sub-category the object\n * belongs to*, and collapsing them would lose one of the two.\n */\n readonly classification?: ClassificationResult | null;\n}\n\n/**\n * Single-channel binary or grayscale mask, laid out row-major.\n *\n * `data.length` must equal `width * height`. For binary masks, values are\n * `0` (background) or `255` (foreground); soft masks may use the full\n * `[0, 255]` range.\n */\nexport class Mask {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height) {\n throw new ImageLoadError(\n `Mask data length ${data.length} does not match width * height = ${\n width * height\n }.`,\n );\n }\n }\n}\n\n/**\n * Single segmented instance produced by an instance-segmentation model.\n *\n * Mirrors {@link DetectionResult} and adds the per-instance binary mask\n * plus a \"ready-to-display\" background-removed crop.\n */\nexport interface SegmentationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * Binary mask cropped to `bbox`. Values are `0` (background) or `255`\n * (foreground). Empty boxes yield a zero-sized `Mask`.\n */\n readonly mask: Mask;\n /**\n * The original image cropped to `bbox` with background pixels (where\n * `mask.data[i] === 0`) zeroed out. Empty boxes yield a zero-sized\n * `RGBImage`.\n */\n readonly segmentedImage: RGBImage;\n}\n"],"mappings":"yCAsBA,IAAa,EAAb,KAAsB,CAEE,KACA,MACA,OAHpB,YACI,EACA,EACA,EACF,CACE,GAJgB,KAAA,KAAA,EACA,KAAA,MAAA,EACA,KAAA,OAAA,EAEZ,EAAK,SAAW,EAAQ,EAAS,EACjC,MAAM,IAAI,EAAA,eACN,wBAAwB,EAAK,OAAO,uCAChC,EAAQ,EAAS,EACpB,EACL,CAER,CACJ,EASa,EAAb,KAAyB,CAED,GACA,GACA,GACA,GAJpB,YACI,EACA,EACA,EACA,EACF,CAJkB,KAAA,GAAA,EACA,KAAA,GAAA,EACA,KAAA,GAAA,EACA,KAAA,GAAA,CACjB,CAGH,IAAI,OAAgB,CAChB,OAAO,KAAK,IAAI,EAAG,KAAK,GAAK,KAAK,EAAE,CACxC,CAGA,IAAI,QAAiB,CACjB,OAAO,KAAK,IAAI,EAAG,KAAK,GAAK,KAAK,EAAE,CACxC,CAGA,IAAI,MAAe,CACf,OAAO,KAAK,MAAQ,KAAK,MAC7B,CAGA,IAAI,MAAkD,CAClD,MAAO,CAAC,KAAK,GAAI,KAAK,GAAI,KAAK,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"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Public output types returned by the SDK's vision tasks.\n *\n * These types form the contract between the SDK and its callers. They mirror\n * the Python `ort-vision-sdk` output dataclasses 1-to-1.\n *\n * Naming is intentionally compatible with the Ultralytics / torchvision idiom\n * (`cls`, `conf`, `box`, `xyxy`, `xywh`, normalized variants) so code ported\n * from those projects keeps working with minimal edits. The original verbose\n * names (`classId`, `className`, `confidence`, `bbox`) are still populated for\n * backwards compatibility.\n */\n\nimport { ImageLoadError } from \"./core/exceptions\";\n\n/**\n * HWC RGB uint8 image — the canonical image format used across the SDK.\n *\n * `data.length` must equal `width * height * 3`. The buffer is laid out row\n * by row, top-to-bottom, with each pixel as `[R, G, B]`.\n */\nexport class RGBImage {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height * 3) {\n throw new ImageLoadError(\n `RGBImage data length ${data.length} does not match width * height * 3 = ${\n width * height * 3\n }.`,\n );\n }\n }\n}\n\n/**\n * Axis-aligned bounding box in absolute pixel coordinates (xyxy format).\n *\n * Coordinates refer to the original input image (before any internal resize),\n * so callers can map detections back onto their source image without any\n * additional bookkeeping.\n */\nexport class BoundingBox {\n constructor(\n public readonly x1: number,\n public readonly y1: number,\n public readonly x2: number,\n public readonly y2: number,\n ) {}\n\n /** Box width in pixels (clamped to non-negative). */\n get width(): number {\n return Math.max(0, this.x2 - this.x1);\n }\n\n /** Box height in pixels (clamped to non-negative). */\n get height(): number {\n return Math.max(0, this.y2 - this.y1);\n }\n\n /** Box area in pixels squared. */\n get area(): number {\n return this.width * this.height;\n }\n\n /** The box as `[x1, y1, x2, y2]` in absolute pixels (Ultralytics-style). */\n get xyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * The box as `[cx, cy, w, h]` with `(cx, cy)` at the center.\n *\n * Matches Ultralytics' `boxes.xywh` and YOLO's native head format. For the\n * top-left `[x, y, w, h]` convention, use {@link asXywh}.\n */\n get xywh(): readonly [number, number, number, number] {\n return [(this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2, this.width, this.height];\n }\n\n /**\n * The box as `[x1, y1, x2, y2]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xyxyn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n return [this.x1 / w, this.y1 / h, this.x2 / w, this.y2 / h];\n }\n\n /**\n * The box as `[cx, cy, w, h]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xywhn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n const [cx, cy, bw, bh] = this.xywh;\n return [cx / w, cy / h, bw / w, bh / h];\n }\n\n /** Returns `[x1, y1, x2, y2]`. */\n asXyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * Returns `[x, y, width, height]` with `(x, y)` at the **top-left**.\n *\n * Note: this is the top-left convention. Ultralytics' `xywh` getter uses\n * **center** coordinates — for that, read {@link xywh}.\n */\n asXywh(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.width, this.height];\n }\n\n /** Returns `[x1, y1, x2, y2]` truncated to integers, useful for slicing arrays. */\n asIntXyxy(): readonly [number, number, number, number] {\n return [Math.trunc(this.x1), Math.trunc(this.y1), Math.trunc(this.x2), Math.trunc(this.y2)];\n }\n}\n\n/**\n * Probability assigned to a single class for a classification prediction.\n *\n * `cls` / `name` / `conf` are Ultralytics-style aliases populated alongside\n * the verbose `classId` / `className` / `probability` fields.\n */\nexport interface ClassProbability {\n readonly classId: number;\n readonly className: string;\n readonly probability: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `probability` (Ultralytics-style). */\n readonly conf: number;\n}\n\n/**\n * Output of an image classification inference.\n */\nexport interface ClassificationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** The original input image as an HWC RGB uint8 array. */\n readonly image: RGBImage;\n /**\n * Probabilities per class, sorted in descending order. The first entry\n * mirrors `classId`, `className`, and `confidence`. When `topK` was passed\n * to `predict`, the array is truncated to that length.\n */\n readonly probabilities: readonly ClassProbability[];\n}\n\n/**\n * Single detected object produced by an object-detection model.\n */\nexport interface DetectionResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * The original image cropped to `bbox`, HWC RGB uint8. Empty boxes\n * (zero area) yield a zero-sized `RGBImage`.\n */\n readonly croppedImage: RGBImage;\n}\n\n/**\n * Single-channel binary or grayscale mask, laid out row-major.\n *\n * `data.length` must equal `width * height`. For binary masks, values are\n * `0` (background) or `255` (foreground); soft masks may use the full\n * `[0, 255]` range.\n */\nexport class Mask {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height) {\n throw new ImageLoadError(\n `Mask data length ${data.length} does not match width * height = ${\n width * height\n }.`,\n );\n }\n }\n}\n\n/**\n * Single segmented instance produced by an instance-segmentation model.\n *\n * Mirrors {@link DetectionResult} and adds the per-instance binary mask\n * plus a \"ready-to-display\" background-removed crop.\n */\nexport interface SegmentationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * Binary mask cropped to `bbox`. Values are `0` (background) or `255`\n * (foreground). Empty boxes yield a zero-sized `Mask`.\n */\n readonly mask: Mask;\n /**\n * The original image cropped to `bbox` with background pixels (where\n * `mask.data[i] === 0`) zeroed out. Empty boxes yield a zero-sized\n * `RGBImage`.\n */\n readonly segmentedImage: RGBImage;\n}\n"],"mappings":";;AAsBA,IAAa,IAAb,MAAsB;CAEE;CACA;CACA;CAHpB,YACI,GACA,GACA,GACF;EACE,IAJgB,KAAA,OAAA,GACA,KAAA,QAAA,GACA,KAAA,SAAA,GAEZ,EAAK,WAAW,IAAQ,IAAS,GACjC,MAAM,IAAI,EACN,wBAAwB,EAAK,OAAO,uCAChC,IAAQ,IAAS,EACpB,EACL;CAER;AACJ,GASa,IAAb,MAAyB;CAED;CACA;CACA;CACA;CAJpB,YACI,GACA,GACA,GACA,GACF;EADkB,AAHA,KAAA,KAAA,GACA,KAAA,KAAA,GACA,KAAA,KAAA,GACA,KAAA,KAAA;CACjB;CAGH,IAAI,QAAgB;EAChB,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,KAAK,EAAE;CACxC;CAGA,IAAI,SAAiB;EACjB,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,KAAK,EAAE;CACxC;CAGA,IAAI,OAAe;EACf,OAAO,KAAK,QAAQ,KAAK;CAC7B;CAGA,IAAI,OAAkD;EAClD,OAAO;GAAC,KAAK;GAAI,KAAK;GAAI,KAAK;GAAI,KAAK;EAAE;CAC9C;CAQA,IAAI,OAAkD;EAClD,OAAO;IAAE,KAAK,KAAK,KAAK,MAAM;IAAI,KAAK,KAAK,KAAK,MAAM;GAAG,KAAK;GAAO,KAAK;EAAM;CACrF;CAOA,MAAM,GAAiF;EACnF,IAAM,CAAC,GAAG,KAAK;EAEf,OADI,KAAK,KAAK,KAAK,IAAU;GAAC;GAAG;GAAG;GAAG;EAAC,IACjC;GAAC,KAAK,KAAK;GAAG,KAAK,KAAK;GAAG,KAAK,KAAK;GAAG,KAAK,KAAK;EAAC;CAC9D;CAOA,MAAM,GAAiF;EACnF,IAAM,CAAC,GAAG,KAAK;EACf,IAAI,KAAK,KAAK,KAAK,GAAG,OAAO;GAAC;GAAG;GAAG;GAAG;EAAC;EACxC,IAAM,CAAC,GAAI,GAAI,GAAI,KAAM,KAAK;EAC9B,OAAO;GAAC,IAAK;GAAG,IAAK;GAAG,IAAK;GAAG,IAAK;EAAC;CAC1C;CAGA,SAAoD;EAChD,OAAO;GAAC,KAAK;GAAI,KAAK;GAAI,KAAK;GAAI,KAAK;EAAE;CAC9C;CAQA,SAAoD;EAChD,OAAO;GAAC,KAAK;GAAI,KAAK;GAAI,KAAK;GAAO,KAAK;EAAM;CACrD;CAGA,YAAuD;EACnD,OAAO;GAAC,KAAK,MAAM,KAAK,EAAE;GAAG,KAAK,MAAM,KAAK,EAAE;GAAG,KAAK,MAAM,KAAK,EAAE;GAAG,KAAK,MAAM,KAAK,EAAE;EAAC;CAC9F;AACJ,GAyEa,IAAb,MAAkB;CAEM;CACA;CACA;CAHpB,YACI,GACA,GACA,GACF;EACE,IAJgB,KAAA,OAAA,GACA,KAAA,QAAA,GACA,KAAA,SAAA,GAEZ,EAAK,WAAW,IAAQ,GACxB,MAAM,IAAI,EACN,oBAAoB,EAAK,OAAO,mCAC5B,IAAQ,EACX,EACL;CAER;AACJ"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/vision/types.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Public output types returned by the SDK's vision tasks.\n *\n * These types form the contract between the SDK and its callers. They mirror\n * the Python `ort-vision-sdk` output dataclasses 1-to-1.\n *\n * Naming is intentionally compatible with the Ultralytics / torchvision idiom\n * (`cls`, `conf`, `box`, `xyxy`, `xywh`, normalized variants) so code ported\n * from those projects keeps working with minimal edits. The original verbose\n * names (`classId`, `className`, `confidence`, `bbox`) are still populated for\n * backwards compatibility.\n */\n\nimport { ImageLoadError } from \"./core/exceptions\";\n\n/**\n * HWC RGB uint8 image — the canonical image format used across the SDK.\n *\n * `data.length` must equal `width * height * 3`. The buffer is laid out row\n * by row, top-to-bottom, with each pixel as `[R, G, B]`.\n */\nexport class RGBImage {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height * 3) {\n throw new ImageLoadError(\n `RGBImage data length ${data.length} does not match width * height * 3 = ${\n width * height * 3\n }.`,\n );\n }\n }\n}\n\n/**\n * Axis-aligned bounding box in absolute pixel coordinates (xyxy format).\n *\n * Coordinates refer to the original input image (before any internal resize),\n * so callers can map detections back onto their source image without any\n * additional bookkeeping.\n */\nexport class BoundingBox {\n constructor(\n public readonly x1: number,\n public readonly y1: number,\n public readonly x2: number,\n public readonly y2: number,\n ) {}\n\n /** Box width in pixels (clamped to non-negative). */\n get width(): number {\n return Math.max(0, this.x2 - this.x1);\n }\n\n /** Box height in pixels (clamped to non-negative). */\n get height(): number {\n return Math.max(0, this.y2 - this.y1);\n }\n\n /** Box area in pixels squared. */\n get area(): number {\n return this.width * this.height;\n }\n\n /** The box as `[x1, y1, x2, y2]` in absolute pixels (Ultralytics-style). */\n get xyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * The box as `[cx, cy, w, h]` with `(cx, cy)` at the center.\n *\n * Matches Ultralytics' `boxes.xywh` and YOLO's native head format. For the\n * top-left `[x, y, w, h]` convention, use {@link asXywh}.\n */\n get xywh(): readonly [number, number, number, number] {\n return [(this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2, this.width, this.height];\n }\n\n /**\n * The box as `[x1, y1, x2, y2]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xyxyn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n return [this.x1 / w, this.y1 / h, this.x2 / w, this.y2 / h];\n }\n\n /**\n * The box as `[cx, cy, w, h]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xywhn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n const [cx, cy, bw, bh] = this.xywh;\n return [cx / w, cy / h, bw / w, bh / h];\n }\n\n /** Returns `[x1, y1, x2, y2]`. */\n asXyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * Returns `[x, y, width, height]` with `(x, y)` at the **top-left**.\n *\n * Note: this is the top-left convention. Ultralytics' `xywh` getter uses\n * **center** coordinates — for that, read {@link xywh}.\n */\n asXywh(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.width, this.height];\n }\n\n /** Returns `[x1, y1, x2, y2]` truncated to integers, useful for slicing arrays. */\n asIntXyxy(): readonly [number, number, number, number] {\n return [Math.trunc(this.x1), Math.trunc(this.y1), Math.trunc(this.x2), Math.trunc(this.y2)];\n }\n}\n\n/**\n * Probability assigned to a single class for a classification prediction.\n *\n * `cls` / `name` / `conf` are Ultralytics-style aliases populated alongside\n * the verbose `classId` / `className` / `probability` fields.\n */\nexport interface ClassProbability {\n readonly classId: number;\n readonly className: string;\n readonly probability: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `probability` (Ultralytics-style). */\n readonly conf: number;\n}\n\n/**\n * Output of an image classification inference.\n */\nexport interface ClassificationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** The original input image as an HWC RGB uint8 array. */\n readonly image: RGBImage;\n /**\n * Probabilities per class, sorted in descending order. The first entry\n * mirrors `classId`, `className`, and `confidence`. When `topK` was passed\n * to `predict`, the array is truncated to that length.\n */\n readonly probabilities: readonly ClassProbability[];\n}\n\n/**\n * Single detected object produced by an object-detection model.\n */\nexport interface DetectionResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * The original image cropped to `bbox`, HWC RGB uint8. Empty boxes\n * (zero area) yield a zero-sized `RGBImage`.\n */\n readonly croppedImage: RGBImage;\n /**\n * What a second, classification stage predicted **for this crop** —\n * populated only by {@link DetectClassify}, and `null` for a plain detector.\n *\n * Kept as its own field rather than folded into `classId`/`className`\n * because the two answers are different questions: the detector says *what\n * kind of object this is*, the classifier says *which sub-category the object\n * belongs to*, and collapsing them would lose one of the two.\n */\n readonly classification?: ClassificationResult | null;\n}\n\n/**\n * Single-channel binary or grayscale mask, laid out row-major.\n *\n * `data.length` must equal `width * height`. For binary masks, values are\n * `0` (background) or `255` (foreground); soft masks may use the full\n * `[0, 255]` range.\n */\nexport class Mask {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height) {\n throw new ImageLoadError(\n `Mask data length ${data.length} does not match width * height = ${\n width * height\n }.`,\n );\n }\n }\n}\n\n/**\n * Single segmented instance produced by an instance-segmentation model.\n *\n * Mirrors {@link DetectionResult} and adds the per-instance binary mask\n * plus a \"ready-to-display\" background-removed crop.\n */\nexport interface SegmentationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * Binary mask cropped to `bbox`. Values are `0` (background) or `255`\n * (foreground). Empty boxes yield a zero-sized `Mask`.\n */\n readonly mask: Mask;\n /**\n * The original image cropped to `bbox` with background pixels (where\n * `mask.data[i] === 0`) zeroed out. Empty boxes yield a zero-sized\n * `RGBImage`.\n */\n readonly segmentedImage: RGBImage;\n}\n"],"mappings":";;AAsBA,IAAa,IAAb,MAAsB;CAEE;CACA;CACA;CAHpB,YACI,GACA,GACA,GACF;EACE,IAJgB,KAAA,OAAA,GACA,KAAA,QAAA,GACA,KAAA,SAAA,GAEZ,EAAK,WAAW,IAAQ,IAAS,GACjC,MAAM,IAAI,EACN,wBAAwB,EAAK,OAAO,uCAChC,IAAQ,IAAS,EACpB,EACL;CAER;AACJ,GASa,IAAb,MAAyB;CAED;CACA;CACA;CACA;CAJpB,YACI,GACA,GACA,GACA,GACF;EADkB,AAHA,KAAA,KAAA,GACA,KAAA,KAAA,GACA,KAAA,KAAA,GACA,KAAA,KAAA;CACjB;CAGH,IAAI,QAAgB;EAChB,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,KAAK,EAAE;CACxC;CAGA,IAAI,SAAiB;EACjB,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,KAAK,EAAE;CACxC;CAGA,IAAI,OAAe;EACf,OAAO,KAAK,QAAQ,KAAK;CAC7B;CAGA,IAAI,OAAkD;EAClD,OAAO;GAAC,KAAK;GAAI,KAAK;GAAI,KAAK;GAAI,KAAK;EAAE;CAC9C;CAQA,IAAI,OAAkD;EAClD,OAAO;IAAE,KAAK,KAAK,KAAK,MAAM;IAAI,KAAK,KAAK,KAAK,MAAM;GAAG,KAAK;GAAO,KAAK;EAAM;CACrF;CAOA,MAAM,GAAiF;EACnF,IAAM,CAAC,GAAG,KAAK;EAEf,OADI,KAAK,KAAK,KAAK,IAAU;GAAC;GAAG;GAAG;GAAG;EAAC,IACjC;GAAC,KAAK,KAAK;GAAG,KAAK,KAAK;GAAG,KAAK,KAAK;GAAG,KAAK,KAAK;EAAC;CAC9D;CAOA,MAAM,GAAiF;EACnF,IAAM,CAAC,GAAG,KAAK;EACf,IAAI,KAAK,KAAK,KAAK,GAAG,OAAO;GAAC;GAAG;GAAG;GAAG;EAAC;EACxC,IAAM,CAAC,GAAI,GAAI,GAAI,KAAM,KAAK;EAC9B,OAAO;GAAC,IAAK;GAAG,IAAK;GAAG,IAAK;GAAG,IAAK;EAAC;CAC1C;CAGA,SAAoD;EAChD,OAAO;GAAC,KAAK;GAAI,KAAK;GAAI,KAAK;GAAI,KAAK;EAAE;CAC9C;CAQA,SAAoD;EAChD,OAAO;GAAC,KAAK;GAAI,KAAK;GAAI,KAAK;GAAO,KAAK;EAAM;CACrD;CAGA,YAAuD;EACnD,OAAO;GAAC,KAAK,MAAM,KAAK,EAAE;GAAG,KAAK,MAAM,KAAK,EAAE;GAAG,KAAK,MAAM,KAAK,EAAE;GAAG,KAAK,MAAM,KAAK,EAAE;EAAC;CAC9F;AACJ,GAmFa,IAAb,MAAkB;CAEM;CACA;CACA;CAHpB,YACI,GACA,GACA,GACF;EACE,IAJgB,KAAA,OAAA,GACA,KAAA,QAAA,GACA,KAAA,SAAA,GAEZ,EAAK,WAAW,IAAQ,GACxB,MAAM,IAAI,EACN,oBAAoB,EAAK,OAAO,mCAC5B,IAAQ,EACX,EACL;CAER;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-camera-stream.cjs","names":[],"sources":["../../src/vision/use-camera-stream.ts"],"sourcesContent":["import { useEffect, useRef, useState, type RefObject } from \"react\";\n\nimport {\n classifyMediaError,\n missingCaptureApiError,\n type MediaAccessError,\n} from \"@/audio/media-access\";\n\n/** Lifecycle status of the camera stream. */\nexport type CameraStreamStatus = \"idle\" | \"loading\" | \"ready\" | \"error\";\n\n/** Classified reason a camera stream could not be acquired. */\nexport type CameraStreamErrorKind =\n \"unsupported\" | \"permission-denied\" | \"no-camera\" | \"in-use\" | \"insecure\" | \"unknown\";\n\n/** A classified camera error with a human-readable, English message. */\nexport interface CameraStreamError {\n kind: CameraStreamErrorKind;\n message: string;\n}\n\n/** Options for {@link useCameraStream}. */\nexport interface UseCameraStreamOptions {\n /**\n * Constraints passed to `getUserMedia`. Defaults to the rear\n * (\"environment\") camera at Full-HD ideal resolution with audio off.\n * Read when the stream (re)starts — change it and call `retry()` to apply.\n */\n constraints?: MediaStreamConstraints;\n /**\n * Hold off acquiring the camera until this is `true`. Default `true`.\n *\n * The point is to be able to *not* prompt. A permission prompt costs the user a\n * decision and, if they refuse, costs the app the feature permanently — so a\n * surface that already knows it cannot do its job (a barcode scanner in a browser\n * with no decoder) must not open the camera to then say so. Flipping this to `false`\n * also releases a stream that is already live.\n */\n enabled?: boolean;\n}\n\n/** Value returned by {@link useCameraStream}. */\nexport interface UseCameraStreamApi {\n /** Current lifecycle status. */\n status: CameraStreamStatus;\n /** The classified error, or `null` while not in the `error` status. */\n error: CameraStreamError | null;\n /** Attach to a `<video ref={…} />`. The stream is wired to it once ready. */\n videoRef: RefObject<HTMLVideoElement | null>;\n /**\n * The live stream, or `null`.\n *\n * Exposed for the things that need the **track** rather than the picture — the LED\n * torch (`useTorch`), the real frame size from `getSettings()`, recording it with\n * `useVideoRecorder`. Do not stop it yourself: the hook owns its lifetime and\n * releases it on unmount and on `retry()`.\n */\n stream: MediaStream | null;\n /** Manually re-attempt after an error (e.g. the user changed permissions). */\n retry: () => void;\n}\n\n/** Rear-camera Full-HD defaults used when no `constraints` are supplied. */\nconst DEFAULT_CONSTRAINTS: MediaStreamConstraints = {\n video: {\n facingMode: { ideal: \"environment\" },\n width: { ideal: 1920 },\n height: { ideal: 1080 },\n },\n audio: false,\n};\n\n/**\n * Re-label a {@link MediaAccessError} as a {@link CameraStreamError}.\n *\n * The classification itself lives in one place for the whole SDK\n * (`classifyMediaError`), so a microphone and a camera failure are never explained\n * two different ways. Only the name of one kind differs: this surface shipped\n * `\"no-camera\"` where the shared taxonomy says `\"not-found\"`, and renaming a\n * published union member would break every consumer switching on it.\n *\n * @param error - The shared classification.\n * @returns The same error under this module's kind names.\n */\nfunction toCameraError({ kind, message }: MediaAccessError): CameraStreamError {\n return { kind: kind === \"not-found\" ? \"no-camera\" : kind, message };\n}\n\n/**\n * Map an unknown `getUserMedia` failure into a {@link CameraStreamError}. Secure-context\n * and environment checks run first (they are the reason `getUserMedia` is missing or\n * rejects), then the `DOMException.name` is mapped to a stable `kind`.\n */\nfunction classifyError(err: unknown): CameraStreamError {\n return toCameraError(classifyMediaError(err, \"camera\"));\n}\n\n/**\n * Acquire a `MediaStream` via `getUserMedia`, attach it to a `<video>` element,\n * and expose status/error so the page can render permission and error states.\n * The stream is automatically released on unmount or retry.\n *\n * Defaults to the rear (\"environment\") camera; desktops fall back to whatever\n * single camera they expose. Pass `options.constraints` to override, or\n * `options.enabled: false` to render the surface without prompting for the camera\n * at all.\n *\n * Implementation notes:\n * - Cleanup detaches the stream from a *snapshotted* video node, so it releases\n * the same element it attached to even if the page remounts the `<video>`.\n * - When `getUserMedia` is missing, an insecure context is the usual cause, so\n * the hook prefers that (actionable) error; otherwise it reports `unsupported`.\n * - `video.play()` rejections are swallowed: autoplay may be blocked, but the\n * user gesture that opened the camera usually counts and playback resumes on\n * the next interaction.\n *\n * @param options - optional configuration (see {@link UseCameraStreamOptions}).\n * @returns The stream status, classified error, a `videoRef` to attach, the live\n * `stream` for whatever needs the track itself, and a `retry()` to re-attempt\n * acquisition.\n */\nexport function useCameraStream(options: UseCameraStreamOptions = {}): UseCameraStreamApi {\n const [status, setStatus] = useState<CameraStreamStatus>(\"loading\");\n const [error, setError] = useState<CameraStreamError | null>(null);\n const [live, setLive] = useState<MediaStream | null>(null);\n const [retryToken, setRetryToken] = useState(0);\n const videoRef = useRef<HTMLVideoElement | null>(null);\n const constraintsRef = useRef<MediaStreamConstraints>(\n options.constraints ?? DEFAULT_CONSTRAINTS,\n );\n useEffect(() => {\n constraintsRef.current = options.constraints ?? DEFAULT_CONSTRAINTS;\n }, [options.constraints]);\n\n const enabled = options.enabled ?? true;\n\n useEffect(() => {\n let cancelled = false;\n let stream: MediaStream | null = null;\n let attachedVideo: HTMLVideoElement | null = null;\n\n async function start(): Promise<void> {\n if (!enabled) {\n setStatus(\"idle\");\n setError(null);\n return;\n }\n setStatus(\"loading\");\n setError(null);\n\n if (\n typeof navigator === \"undefined\" ||\n !navigator.mediaDevices ||\n typeof navigator.mediaDevices.getUserMedia !== \"function\"\n ) {\n if (!cancelled) {\n setError(toCameraError(missingCaptureApiError(\"camera\")));\n setStatus(\"error\");\n }\n return;\n }\n\n try {\n stream = await navigator.mediaDevices.getUserMedia(constraintsRef.current);\n if (cancelled) {\n stream.getTracks().forEach((track) => track.stop());\n return;\n }\n const video = videoRef.current;\n if (!video) {\n stream.getTracks().forEach((track) => track.stop());\n return;\n }\n attachedVideo = video;\n video.srcObject = stream;\n setLive(stream);\n await video.play().catch(() => undefined);\n if (!cancelled) setStatus(\"ready\");\n } catch (err) {\n if (!cancelled) {\n setError(classifyError(err));\n setStatus(\"error\");\n }\n }\n }\n\n void start();\n\n return () => {\n cancelled = true;\n if (stream) {\n stream.getTracks().forEach((track) => track.stop());\n }\n if (attachedVideo) {\n attachedVideo.srcObject = null;\n }\n setLive(null);\n };\n }, [retryToken, enabled]);\n\n return {\n status,\n error,\n videoRef,\n stream: live,\n retry: () => setRetryToken((n) => n + 1),\n };\n}\n"],"mappings":"oEA+DA,IAAM,EAA8C,CAChD,MAAO,CACH,WAAY,CAAE,MAAO,aAAc,EACnC,MAAO,CAAE,MAAO,IAAK,EACrB,OAAQ,CAAE,MAAO,IAAK,CAC1B,EACA,MAAO,EACX,EAcA,SAAS,EAAc,CAAE,OAAM,WAAgD,CAC3E,MAAO,CAAE,KAAM,IAAS,YAAc,YAAc,EAAM,SAAQ,CACt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,CACA,EAAgB,EAChB,EAAM,UAAY,EAClB,EAAQ,CAAM,EACd,MAAM,EAAM,KAAK,CAAC,CAAC,UAAY,IAAA,EAAS,EACnC,GAAW,EAAU,OAAO,CACrC,OAAS,EAAK,CACL,IACD,EAAS,EAAc,CAAG,CAAC,EAC3B,EAAU,OAAO,EAEzB,CACJ,CAIA,OAFA,EAAW,MAEE,CACT,EAAY,GACR,GACA,EAAO,UAAU,CAAC,CAAC,QAAS,GAAU,EAAM,KAAK,CAAC,EAElD,IACA,EAAc,UAAY,MAE9B,EAAQ,IAAI,CAChB,CACJ,EAAG,CAAC,EAAY,CAAO,CAAC,EAEjB,CACH,SACA,QACA,WACA,OAAQ,EACR,UAAa,EAAe,GAAM,EAAI,CAAC,CAC3C,CACJ"}
1
+ {"version":3,"file":"use-camera-stream.cjs","names":[],"sources":["../../src/vision/use-camera-stream.ts"],"sourcesContent":["import { useEffect, useRef, useState, type RefObject } from \"react\";\n\nimport {\n classifyMediaError,\n missingCaptureApiError,\n type MediaAccessError,\n} from \"@/audio/media-access\";\n\n/** Lifecycle status of the camera stream. */\nexport type CameraStreamStatus = \"idle\" | \"loading\" | \"ready\" | \"error\";\n\n/** Classified reason a camera stream could not be acquired. */\nexport type CameraStreamErrorKind =\n \"unsupported\" | \"permission-denied\" | \"no-camera\" | \"in-use\" | \"insecure\" | \"unknown\";\n\n/** A classified camera error with a human-readable, English message. */\nexport interface CameraStreamError {\n kind: CameraStreamErrorKind;\n message: string;\n}\n\n/** Options for {@link useCameraStream}. */\nexport interface UseCameraStreamOptions {\n /**\n * Constraints passed to `getUserMedia`. Defaults to the rear\n * (\"environment\") camera at Full-HD ideal resolution with audio off.\n * Read when the stream (re)starts — change it and call `retry()` to apply.\n */\n constraints?: MediaStreamConstraints;\n /**\n * Hold off acquiring the camera until this is `true`. Default `true`.\n *\n * The point is to be able to *not* prompt. A permission prompt costs the user a\n * decision and, if they refuse, costs the app the feature permanently — so a\n * surface that already knows it cannot do its job (a barcode scanner in a browser\n * with no decoder) must not open the camera to then say so. Flipping this to `false`\n * also releases a stream that is already live.\n */\n enabled?: boolean;\n}\n\n/** Value returned by {@link useCameraStream}. */\nexport interface UseCameraStreamApi {\n /** Current lifecycle status. */\n status: CameraStreamStatus;\n /** The classified error, or `null` while not in the `error` status. */\n error: CameraStreamError | null;\n /** Attach to a `<video ref={…} />`. The stream is wired to it once ready. */\n videoRef: RefObject<HTMLVideoElement | null>;\n /**\n * The live stream, or `null`.\n *\n * Exposed for the things that need the **track** rather than the picture — the LED\n * torch (`useTorch`), the real frame size from `getSettings()`, recording it with\n * `useVideoRecorder`. Do not stop it yourself: the hook owns its lifetime and\n * releases it on unmount and on `retry()`.\n */\n stream: MediaStream | null;\n /** Manually re-attempt after an error (e.g. the user changed permissions). */\n retry: () => void;\n}\n\n/** Rear-camera Full-HD defaults used when no `constraints` are supplied. */\nconst DEFAULT_CONSTRAINTS: MediaStreamConstraints = {\n video: {\n facingMode: { ideal: \"environment\" },\n width: { ideal: 1920 },\n height: { ideal: 1080 },\n },\n audio: false,\n};\n\n/**\n * Re-label a {@link MediaAccessError} as a {@link CameraStreamError}.\n *\n * The classification itself lives in one place for the whole SDK\n * (`classifyMediaError`), so a microphone and a camera failure are never explained\n * two different ways. Only the name of one kind differs: this surface shipped\n * `\"no-camera\"` where the shared taxonomy says `\"not-found\"`, and renaming a\n * published union member would break every consumer switching on it.\n *\n * @param error - The shared classification.\n * @returns The same error under this module's kind names.\n */\nfunction toCameraError({ kind, message }: MediaAccessError): CameraStreamError {\n return { kind: kind === \"not-found\" ? \"no-camera\" : kind, message };\n}\n\n/**\n * Map an unknown `getUserMedia` failure into a {@link CameraStreamError}. Secure-context\n * and environment checks run first (they are the reason `getUserMedia` is missing or\n * rejects), then the `DOMException.name` is mapped to a stable `kind`.\n */\nfunction classifyError(err: unknown): CameraStreamError {\n return toCameraError(classifyMediaError(err, \"camera\"));\n}\n\n/**\n * Acquire a `MediaStream` via `getUserMedia`, attach it to a `<video>` element,\n * and expose status/error so the page can render permission and error states.\n * The stream is automatically released on unmount or retry.\n *\n * Defaults to the rear (\"environment\") camera; desktops fall back to whatever\n * single camera they expose. Pass `options.constraints` to override, or\n * `options.enabled: false` to render the surface without prompting for the camera\n * at all.\n *\n * Implementation notes:\n * - Cleanup detaches the stream from a *snapshotted* video node, so it releases\n * the same element it attached to even if the page remounts the `<video>`.\n * - When `getUserMedia` is missing, an insecure context is the usual cause, so\n * the hook prefers that (actionable) error; otherwise it reports `unsupported`.\n * - `video.play()` rejections are swallowed: autoplay may be blocked, but the\n * user gesture that opened the camera usually counts and playback resumes on\n * the next interaction.\n *\n * @param options - optional configuration (see {@link UseCameraStreamOptions}).\n * @returns The stream status, classified error, a `videoRef` to attach, the live\n * `stream` for whatever needs the track itself, and a `retry()` to re-attempt\n * acquisition.\n */\nexport function useCameraStream(options: UseCameraStreamOptions = {}): UseCameraStreamApi {\n const [status, setStatus] = useState<CameraStreamStatus>(\"loading\");\n const [error, setError] = useState<CameraStreamError | null>(null);\n const [live, setLive] = useState<MediaStream | null>(null);\n const [retryToken, setRetryToken] = useState(0);\n const videoRef = useRef<HTMLVideoElement | null>(null);\n const constraintsRef = useRef<MediaStreamConstraints>(\n options.constraints ?? DEFAULT_CONSTRAINTS,\n );\n useEffect(() => {\n constraintsRef.current = options.constraints ?? DEFAULT_CONSTRAINTS;\n }, [options.constraints]);\n\n const enabled = options.enabled ?? true;\n\n useEffect(() => {\n let cancelled = false;\n let stream: MediaStream | null = null;\n let attachedVideo: HTMLVideoElement | null = null;\n\n async function start(): Promise<void> {\n if (!enabled) {\n setStatus(\"idle\");\n setError(null);\n return;\n }\n setStatus(\"loading\");\n setError(null);\n\n if (\n typeof navigator === \"undefined\" ||\n !navigator.mediaDevices ||\n typeof navigator.mediaDevices.getUserMedia !== \"function\"\n ) {\n if (!cancelled) {\n setError(toCameraError(missingCaptureApiError(\"camera\")));\n setStatus(\"error\");\n }\n return;\n }\n\n try {\n stream = await navigator.mediaDevices.getUserMedia(constraintsRef.current);\n if (cancelled) {\n stream.getTracks().forEach((track) => track.stop());\n return;\n }\n const video = videoRef.current;\n if (!video) {\n stream.getTracks().forEach((track) => track.stop());\n return;\n }\n attachedVideo = video;\n video.srcObject = stream;\n setLive(stream);\n await video.play().catch(() => undefined);\n if (!cancelled) setStatus(\"ready\");\n } catch (err) {\n if (!cancelled) {\n setError(classifyError(err));\n setStatus(\"error\");\n }\n }\n }\n\n void start();\n\n return () => {\n cancelled = true;\n if (stream) {\n stream.getTracks().forEach((track) => track.stop());\n }\n if (attachedVideo) {\n attachedVideo.srcObject = null;\n }\n setLive(null);\n };\n }, [retryToken, enabled]);\n\n return {\n status,\n error,\n videoRef,\n stream: live,\n retry: () => setRetryToken((n) => n + 1),\n };\n}\n"],"mappings":"oEA+DA,IAAM,EAA8C,CAChD,MAAO,CACH,WAAY,CAAE,MAAO,aAAc,EACnC,MAAO,CAAE,MAAO,IAAK,EACrB,OAAQ,CAAE,MAAO,IAAK,CAC1B,EACA,MAAO,EACX,EAcA,SAAS,EAAc,CAAE,OAAM,WAAgD,CAC3E,MAAO,CAAE,KAAM,IAAS,YAAc,YAAc,EAAM,SAAQ,CACtE,CAOA,SAAS,EAAc,EAAiC,CACpD,OAAO,EAAc,EAAA,mBAAmB,EAAK,QAAQ,CAAC,CAC1D,CA0BA,SAAgB,EAAgB,EAAkC,CAAC,EAAuB,CACtF,GAAM,CAAC,EAAQ,IAAA,EAAa,EAAA,SAAA,CAA6B,SAAS,EAC5D,CAAC,EAAO,IAAA,EAAY,EAAA,SAAA,CAAmC,IAAI,EAC3D,CAAC,EAAM,IAAA,EAAW,EAAA,SAAA,CAA6B,IAAI,EACnD,CAAC,EAAY,IAAA,EAAiB,EAAA,SAAA,CAAS,CAAC,EACxC,GAAA,EAAW,EAAA,OAAA,CAAgC,IAAI,EAC/C,GAAA,EAAiB,EAAA,OAAA,CACnB,EAAQ,aAAe,CAC3B,GACA,EAAA,EAAA,UAAA,KAAgB,CACZ,EAAe,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":3,"file":"use-live-luminance.cjs","names":[],"sources":["../../src/vision/use-live-luminance.ts"],"sourcesContent":["import { useEffect, useRef, useState, type RefObject } from \"react\";\nimport { computeImageLuminance } from \"./luminance\";\n\n/** Options for {@link useLiveLuminance}. */\nexport interface UseLiveLuminanceOptions {\n /** When `false` the loop is paused (e.g. while a capture is in flight). Default: `true`. */\n enabled?: boolean;\n /** Throttle measurements in milliseconds. Default: `160` (~6 fps), plenty for UX. */\n intervalMs?: number;\n}\n\n/**\n * Sample mean luminance from a `<video>` source on a `requestAnimationFrame`\n * loop and expose the rolling value. Sampling is throttled by `intervalMs` and\n * paused whenever `enabled` is `false` or the video is not ready yet\n * (`readyState < 2` or `videoWidth === 0`).\n *\n * One offscreen canvas is reused across frames to avoid GC pressure. Designed\n * to feed a live brightness bar / border color on a camera page.\n *\n * @param videoRef - ref to the `<video>` element to sample.\n * @param options - optional configuration (see {@link UseLiveLuminanceOptions}).\n * @returns The rolling mean luminance in `0..255` (`0` until the first sample).\n */\nexport function useLiveLuminance(\n videoRef: RefObject<HTMLVideoElement | null>,\n { enabled = true, intervalMs = 160 }: UseLiveLuminanceOptions = {},\n): number {\n const [luminance, setLuminance] = useState(0);\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n\n useEffect(() => {\n if (!enabled) return;\n if (typeof window === \"undefined\") return;\n if (!canvasRef.current) canvasRef.current = document.createElement(\"canvas\");\n\n let rafId = 0;\n let lastSampledAt = 0;\n\n const tick = (timestamp: number): void => {\n const video = videoRef.current;\n if (!video || video.readyState < 2 || video.videoWidth === 0) {\n rafId = window.requestAnimationFrame(tick);\n return;\n }\n if (timestamp - lastSampledAt >= intervalMs) {\n lastSampledAt = timestamp;\n setLuminance(computeImageLuminance(video, canvasRef.current ?? undefined));\n }\n rafId = window.requestAnimationFrame(tick);\n };\n\n rafId = window.requestAnimationFrame(tick);\n return () => window.cancelAnimationFrame(rafId);\n }, [videoRef, enabled, intervalMs]);\n\n return luminance;\n}\n"],"mappings":"0DAwBA,SAAgB,EACZ,EACA,CAAE,UAAU,GAAM,aAAa,KAAiC,CAAC,EAC3D,CACN,GAAM,CAAC,EAAW,IAAA,EAAA,EAAA,SAAA,CAAyB,CAAC,EACtC,GAAA,EAAA,EAAA,OAAA,CAA6C,IAAI,EA2BvD,OAzBA,EAAA,EAAA,UAAA,KAAgB,CAEZ,GADI,CAAC,GACD,OAAO,OAAW,IAAa,OACnC,AAAwB,EAAU,UAAU,SAAS,cAAc,QAAQ,EAE3E,IAAI,EAAQ,EACR,EAAgB,EAEd,EAAQ,GAA4B,CACtC,IAAM,EAAQ,EAAS,QACvB,GAAI,CAAC,GAAS,EAAM,WAAa,GAAK,EAAM,aAAe,EAAG,CAC1D,EAAQ,OAAO,sBAAsB,CAAI,EACzC,MACJ,CACI,EAAY,GAAiB,IAC7B,EAAgB,EAChB,EAAa,EAAA,sBAAsB,EAAO,EAAU,SAAW,IAAA,EAAS,CAAC,GAE7E,EAAQ,OAAO,sBAAsB,CAAI,CAC7C,EAGA,MADA,GAAQ,OAAO,sBAAsB,CAAI,MAC5B,OAAO,qBAAqB,CAAK,CAClD,EAAG,CAAC,EAAU,EAAS,CAAU,CAAC,EAE3B,CACX"}
1
+ {"version":3,"file":"use-live-luminance.cjs","names":[],"sources":["../../src/vision/use-live-luminance.ts"],"sourcesContent":["import { useEffect, useRef, useState, type RefObject } from \"react\";\nimport { computeImageLuminance } from \"./luminance\";\n\n/** Options for {@link useLiveLuminance}. */\nexport interface UseLiveLuminanceOptions {\n /** When `false` the loop is paused (e.g. while a capture is in flight). Default: `true`. */\n enabled?: boolean;\n /** Throttle measurements in milliseconds. Default: `160` (~6 fps), plenty for UX. */\n intervalMs?: number;\n}\n\n/**\n * Sample mean luminance from a `<video>` source on a `requestAnimationFrame`\n * loop and expose the rolling value. Sampling is throttled by `intervalMs` and\n * paused whenever `enabled` is `false` or the video is not ready yet\n * (`readyState < 2` or `videoWidth === 0`).\n *\n * One offscreen canvas is reused across frames to avoid GC pressure. Designed\n * to feed a live brightness bar / border color on a camera page.\n *\n * @param videoRef - ref to the `<video>` element to sample.\n * @param options - optional configuration (see {@link UseLiveLuminanceOptions}).\n * @returns The rolling mean luminance in `0..255` (`0` until the first sample).\n */\nexport function useLiveLuminance(\n videoRef: RefObject<HTMLVideoElement | null>,\n { enabled = true, intervalMs = 160 }: UseLiveLuminanceOptions = {},\n): number {\n const [luminance, setLuminance] = useState(0);\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n\n useEffect(() => {\n if (!enabled) return;\n if (typeof window === \"undefined\") return;\n if (!canvasRef.current) canvasRef.current = document.createElement(\"canvas\");\n\n let rafId = 0;\n let lastSampledAt = 0;\n\n const tick = (timestamp: number): void => {\n const video = videoRef.current;\n if (!video || video.readyState < 2 || video.videoWidth === 0) {\n rafId = window.requestAnimationFrame(tick);\n return;\n }\n if (timestamp - lastSampledAt >= intervalMs) {\n lastSampledAt = timestamp;\n setLuminance(computeImageLuminance(video, canvasRef.current ?? undefined));\n }\n rafId = window.requestAnimationFrame(tick);\n };\n\n rafId = window.requestAnimationFrame(tick);\n return () => window.cancelAnimationFrame(rafId);\n }, [videoRef, enabled, intervalMs]);\n\n return luminance;\n}\n"],"mappings":"0DAwBA,SAAgB,EACZ,EACA,CAAE,UAAU,GAAM,aAAa,KAAiC,CAAC,EAC3D,CACN,GAAM,CAAC,EAAW,IAAA,EAAgB,EAAA,SAAA,CAAS,CAAC,EACtC,GAAA,EAAY,EAAA,OAAA,CAAiC,IAAI,EA2BvD,OAzBA,EAAA,EAAA,UAAA,KAAgB,CAEZ,GADI,CAAC,GACD,OAAO,OAAW,IAAa,OACnC,AAAwB,EAAU,UAAU,SAAS,cAAc,QAAQ,EAE3E,IAAI,EAAQ,EACR,EAAgB,EAEd,EAAQ,GAA4B,CACtC,IAAM,EAAQ,EAAS,QACvB,GAAI,CAAC,GAAS,EAAM,WAAa,GAAK,EAAM,aAAe,EAAG,CAC1D,EAAQ,OAAO,sBAAsB,CAAI,EACzC,MACJ,CACI,EAAY,GAAiB,IAC7B,EAAgB,EAChB,EAAa,EAAA,sBAAsB,EAAO,EAAU,SAAW,IAAA,EAAS,CAAC,GAE7E,EAAQ,OAAO,sBAAsB,CAAI,CAC7C,EAGA,MADA,GAAQ,OAAO,sBAAsB,CAAI,MAC5B,OAAO,qBAAqB,CAAK,CAClD,EAAG,CAAC,EAAU,EAAS,CAAU,CAAC,EAE3B,CACX"}
package/dist/vision.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./vision/use-camera-stream.cjs"),t=require("./vision/core/exceptions.cjs"),n=require("./vision/types.cjs"),r=require("./vision/core/timing.cjs"),i=require("./vision/results.cjs"),a=require("./vision/labels.cjs"),o=require("./vision/core/graph.cjs"),s=require("./vision/core/metadata.cjs"),c=require("./vision/core/providers.cjs"),l=require("./vision/core/session.cjs"),u=require("./vision/io/image.cjs"),d=require("./vision/preprocess/image.cjs"),f=require("./vision/postprocess/classification.cjs"),p=require("./vision/postprocess/detection.cjs"),m=require("./vision/postprocess/segmentation.cjs"),h=require("./vision/tasks/base.cjs"),g=require("./vision/tasks/classifier.cjs"),_=require("./vision/tasks/detector.cjs"),v=require("./vision/tasks/segmenter.cjs"),y=require("./vision/index.cjs"),b=require("./vision/luminance.cjs"),x=require("./vision/use-live-luminance.cjs");exports.BoundingBox=n.BoundingBox,exports.Boxes=i.Boxes,exports.COCO_CLASSES=a.COCO_CLASSES,exports.ClassificationResults=i.ClassificationResults,exports.Classifier=g.Classifier,exports.DEFAULT_PROVIDERS=c.DEFAULT_PROVIDERS,exports.DetectionResults=i.DetectionResults,exports.Detector=_.Detector,exports.ImageLoadError=t.ImageLoadError,exports.InferenceError=t.InferenceError,exports.LUMINANCE_SAMPLE_MAX_EDGE=b.LUMINANCE_SAMPLE_MAX_EDGE,exports.LabelMapError=t.LabelMapError,exports.LowLuminanceError=b.LowLuminanceError,exports.Mask=n.Mask,exports.Masks=i.Masks,exports.ModelLoadError=t.ModelLoadError,exports.OrtSession=l.OrtSession,exports.OrtVisionError=t.OrtVisionError,exports.Probs=i.Probs,exports.ProviderNotAvailableError=t.ProviderNotAvailableError,exports.RGBImage=n.RGBImage,exports.SegmentationResults=i.SegmentationResults,exports.Segmenter=v.Segmenter,exports.SpeedTimer=r.SpeedTimer,exports.VERSION=y.VERSION,exports.VisionTask=h.VisionTask,exports.batchedNms=p.batchedNms,exports.classificationNumClasses=o.classificationNumClasses,exports.computeImageLuminance=b.computeImageLuminance,exports.declaredShapesFrom=o.declaredShapesFrom,exports.decodeYolo=p.decodeYolo,exports.decodeYoloAnchors=p.decodeYoloAnchors,exports.decodeYoloSeg=m.decodeYoloSeg,exports.decodeYoloV8=p.decodeYoloV8,exports.decodeYoloV8Anchors=p.decodeYoloV8Anchors,exports.decodeYoloV8Seg=m.decodeYoloV8Seg,exports.detectionNumClasses=o.detectionNumClasses,exports.fromCv2=d.fromCv2,exports.isLuminanceAcceptable=b.isLuminanceAcceptable,exports.letterbox=d.letterbox,exports.loadImage=u.loadImage,exports.modelNames=s.modelNames,exports.nms=p.nms,exports.normalize=d.normalize,exports.readModelMetadata=s.readModelMetadata,exports.resize=d.resize,exports.resolveInputSize=o.resolveInputSize,exports.resolveLabels=a.resolveLabels,exports.resolveProviders=c.resolveProviders,exports.softmax=f.softmax,exports.spatialInputSize=o.spatialInputSize,exports.toCHW=d.toCHW,exports.toCv2=d.toCv2,exports.toFloat32=d.toFloat32,exports.toFloat32Tensor=d.toFloat32Tensor,exports.toTensor=d.toTensor,exports.topK=f.topK,exports.useCameraStream=e.useCameraStream,exports.useLiveLuminance=x.useLiveLuminance;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./vision/use-camera-stream.cjs"),t=require("./vision/core/exceptions.cjs"),n=require("./vision/types.cjs"),r=require("./vision/core/timing.cjs"),i=require("./vision/results.cjs"),a=require("./vision/labels.cjs"),o=require("./vision/core/graph.cjs"),s=require("./vision/core/metadata.cjs"),c=require("./vision/core/providers.cjs"),l=require("./vision/core/session.cjs"),u=require("./vision/io/image.cjs"),d=require("./vision/fusion.cjs"),f=require("./vision/preprocess/image.cjs"),p=require("./vision/preprocess/pipeline.cjs"),m=require("./vision/postprocess/classification.cjs"),h=require("./vision/postprocess/detection.cjs"),g=require("./vision/postprocess/segmentation.cjs"),_=require("./vision/tasks/base.cjs"),v=require("./vision/tasks/classifier.cjs"),y=require("./vision/tasks/detectClassify.cjs"),b=require("./vision/tasks/detector.cjs"),x=require("./vision/tasks/segmenter.cjs"),S=require("./vision/index.cjs"),C=require("./vision/luminance.cjs"),w=require("./vision/use-live-luminance.cjs");exports.BoundingBox=n.BoundingBox,exports.Boxes=i.Boxes,exports.COCO_CLASSES=a.COCO_CLASSES,exports.ClassificationResults=i.ClassificationResults,exports.Classifier=v.Classifier,exports.DEFAULT_PROVIDERS=c.DEFAULT_PROVIDERS,exports.DetectClassify=y.DetectClassify,exports.DetectClassifyResults=i.DetectClassifyResults,exports.DetectionResults=i.DetectionResults,exports.Detector=b.Detector,exports.FUSION_KIND_DETECT_CLASSIFY=d.FUSION_KIND_DETECT_CLASSIFY,exports.FusionError=t.FusionError,exports.INPUT_IMAGE=d.INPUT_IMAGE,exports.INPUT_PAD=d.INPUT_PAD,exports.INPUT_SCALE=d.INPUT_SCALE,exports.INPUT_SOURCE=d.INPUT_SOURCE,exports.ImageLoadError=t.ImageLoadError,exports.InferenceError=t.InferenceError,exports.LUMINANCE_SAMPLE_MAX_EDGE=C.LUMINANCE_SAMPLE_MAX_EDGE,exports.LabelMapError=t.LabelMapError,exports.LetterboxPipeline=p.LetterboxPipeline,exports.LowLuminanceError=C.LowLuminanceError,exports.METADATA_PREFIX=d.METADATA_PREFIX,exports.Mask=n.Mask,exports.Masks=i.Masks,exports.ModelLoadError=t.ModelLoadError,exports.NoDetectionsError=t.NoDetectionsError,exports.OUTPUT_BOXES=d.OUTPUT_BOXES,exports.OUTPUT_CLASSES=d.OUTPUT_CLASSES,exports.OUTPUT_NUM_DETECTIONS=d.OUTPUT_NUM_DETECTIONS,exports.OUTPUT_PROBS=d.OUTPUT_PROBS,exports.OUTPUT_SCORES=d.OUTPUT_SCORES,exports.OrtSession=l.OrtSession,exports.OrtVisionError=t.OrtVisionError,exports.Probs=i.Probs,exports.ProviderNotAvailableError=t.ProviderNotAvailableError,exports.RGBImage=n.RGBImage,exports.SegmentationResults=i.SegmentationResults,exports.Segmenter=x.Segmenter,exports.SpeedTimer=r.SpeedTimer,exports.VERSION=S.VERSION,exports.VisionTask=_.VisionTask,exports.batchedNms=h.batchedNms,exports.classificationNumClasses=o.classificationNumClasses,exports.computeImageLuminance=C.computeImageLuminance,exports.declaredShapesFrom=o.declaredShapesFrom,exports.decodeYolo=h.decodeYolo,exports.decodeYoloAnchors=h.decodeYoloAnchors,exports.decodeYoloSeg=g.decodeYoloSeg,exports.defaultLabels=a.defaultLabels,exports.detectionNumClasses=o.detectionNumClasses,exports.fromCv2=f.fromCv2,exports.isLuminanceAcceptable=C.isLuminanceAcceptable,exports.letterbox=f.letterbox,exports.letterboxToTensorData=p.letterboxToTensorData,exports.loadImage=u.loadImage,exports.modelNames=s.modelNames,exports.nms=h.nms,exports.normalize=f.normalize,exports.parseNames=s.parseNames,exports.readFusionSpec=d.readFusionSpec,exports.readModelMetadata=s.readModelMetadata,exports.requireDetections=_.requireDetections,exports.resize=f.resize,exports.resolveInputSize=o.resolveInputSize,exports.resolveLabels=a.resolveLabels,exports.resolveProviders=c.resolveProviders,exports.softmax=m.softmax,exports.spatialInputSize=o.spatialInputSize,exports.toCHW=f.toCHW,exports.toCv2=f.toCv2,exports.toFloat32=f.toFloat32,exports.toFloat32Tensor=f.toFloat32Tensor,exports.toTensor=f.toTensor,exports.topK=m.topK,exports.useCameraStream=e.useCameraStream,exports.useLiveLuminance=w.useLiveLuminance,exports.zeroTensorData=p.zeroTensorData;