tempest-react-sdk 0.38.2 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/README.md +1 -1
  2. package/bin/lib/design/collect.mjs +19 -0
  3. package/bin/lib/design/functions.mjs +5 -0
  4. package/bin/lib/design/index.mjs +8 -3
  5. package/bin/lib/design/index.test.mjs +31 -0
  6. package/bin/lib/design/scan.mjs +34 -2
  7. package/bin/lib/design/scan.test.mjs +78 -0
  8. package/bin/lib/doctor/doctor.e2e.test.mjs +85 -0
  9. package/bin/tempest.mjs +90 -6
  10. package/dist/audio/level-meter.cjs.map +1 -1
  11. package/dist/audio/level-meter.js.map +1 -1
  12. package/dist/audio/use-audio-recorder.cjs.map +1 -1
  13. package/dist/audio/use-audio-recorder.js.map +1 -1
  14. package/dist/auth/passkey.cjs.map +1 -1
  15. package/dist/auth/passkey.js.map +1 -1
  16. package/dist/auth/use-passkey.cjs.map +1 -1
  17. package/dist/auth/use-passkey.js.map +1 -1
  18. package/dist/br/BrazilMap.cjs.map +1 -1
  19. package/dist/br/BrazilMap.js.map +1 -1
  20. package/dist/br/BrazilStateCitySelect.cjs.map +1 -1
  21. package/dist/br/BrazilStateCitySelect.js.map +1 -1
  22. package/dist/br/BrazilStateMap.cjs.map +1 -1
  23. package/dist/br/BrazilStateMap.js.map +1 -1
  24. package/dist/br/PixQRCode.cjs.map +1 -1
  25. package/dist/br/PixQRCode.js.map +1 -1
  26. package/dist/br/boleto.cjs.map +1 -1
  27. package/dist/br/boleto.js.map +1 -1
  28. package/dist/br/pix.cjs.map +1 -1
  29. package/dist/br/pix.js.map +1 -1
  30. package/dist/br.d.ts +8 -0
  31. package/dist/capture/media-recorder.cjs.map +1 -1
  32. package/dist/capture/media-recorder.js.map +1 -1
  33. package/dist/capture/use-barcode-scanner.cjs.map +1 -1
  34. package/dist/capture/use-barcode-scanner.js.map +1 -1
  35. package/dist/capture/use-screen-capture.cjs.map +1 -1
  36. package/dist/capture/use-screen-capture.js.map +1 -1
  37. package/dist/capture/use-speech-recognition.cjs.map +1 -1
  38. package/dist/capture/use-speech-recognition.js.map +1 -1
  39. package/dist/capture/use-video-recorder.cjs.map +1 -1
  40. package/dist/capture/use-video-recorder.js.map +1 -1
  41. package/dist/charts/types.cjs.map +1 -1
  42. package/dist/charts/types.js.map +1 -1
  43. package/dist/charts.d.ts +8 -0
  44. package/dist/components/AIChat/AIChat.cjs.map +1 -1
  45. package/dist/components/AIChat/AIChat.js.map +1 -1
  46. package/dist/components/AIChat/AIChatComposer.cjs.map +1 -1
  47. package/dist/components/AIChat/AIChatComposer.js.map +1 -1
  48. package/dist/components/AIChat/AIChatTurn.cjs.map +1 -1
  49. package/dist/components/AIChat/AIChatTurn.js.map +1 -1
  50. package/dist/components/AppBar/AppBar.cjs.map +1 -1
  51. package/dist/components/AppBar/AppBar.js.map +1 -1
  52. package/dist/components/AudioPlayer/AudioPlayer.cjs.map +1 -1
  53. package/dist/components/AudioPlayer/AudioPlayer.js.map +1 -1
  54. package/dist/components/AudioRecorder/AudioRecorder.cjs.map +1 -1
  55. package/dist/components/AudioRecorder/AudioRecorder.js.map +1 -1
  56. package/dist/components/BarcodeScanner/BarcodeScanner.cjs.map +1 -1
  57. package/dist/components/BarcodeScanner/BarcodeScanner.js.map +1 -1
  58. package/dist/components/Button/Button.cjs.map +1 -1
  59. package/dist/components/Button/Button.js.map +1 -1
  60. package/dist/components/Calendar/Calendar.cjs.map +1 -1
  61. package/dist/components/Calendar/Calendar.js.map +1 -1
  62. package/dist/components/Carousel/Carousel.cjs.map +1 -1
  63. package/dist/components/Carousel/Carousel.js.map +1 -1
  64. package/dist/components/Chat/Chat.cjs.map +1 -1
  65. package/dist/components/Chat/Chat.js.map +1 -1
  66. package/dist/components/ChipInput/ChipInput.cjs.map +1 -1
  67. package/dist/components/ChipInput/ChipInput.js.map +1 -1
  68. package/dist/components/CodeBlock/CodeBlock.cjs.map +1 -1
  69. package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
  70. package/dist/components/Combobox/Combobox.cjs.map +1 -1
  71. package/dist/components/Combobox/Combobox.js.map +1 -1
  72. package/dist/components/Command/Command.cjs.map +1 -1
  73. package/dist/components/Command/Command.js.map +1 -1
  74. package/dist/components/ConfirmDialog/ConfirmDialog.cjs.map +1 -1
  75. package/dist/components/ConfirmDialog/ConfirmDialog.js.map +1 -1
  76. package/dist/components/ContextMenu/ContextMenu.cjs.map +1 -1
  77. package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
  78. package/dist/components/CopyButton/CopyButton.cjs.map +1 -1
  79. package/dist/components/CopyButton/CopyButton.js.map +1 -1
  80. package/dist/components/DataTable/DataTable.cjs.map +1 -1
  81. package/dist/components/DataTable/DataTable.js.map +1 -1
  82. package/dist/components/DataTable/DataTable.module.cjs.map +1 -1
  83. package/dist/components/DataTable/DataTable.module.js.map +1 -1
  84. package/dist/components/DataTable/EditableCell.cjs.map +1 -1
  85. package/dist/components/DataTable/EditableCell.js.map +1 -1
  86. package/dist/components/DatePicker/DatePicker.cjs.map +1 -1
  87. package/dist/components/DatePicker/DatePicker.js.map +1 -1
  88. package/dist/components/DateRangePicker/DateRangePicker.cjs.map +1 -1
  89. package/dist/components/DateRangePicker/DateRangePicker.js.map +1 -1
  90. package/dist/components/Drawer/Drawer.cjs.map +1 -1
  91. package/dist/components/Drawer/Drawer.js.map +1 -1
  92. package/dist/components/DropdownMenu/DropdownMenu.cjs.map +1 -1
  93. package/dist/components/DropdownMenu/DropdownMenu.js.map +1 -1
  94. package/dist/components/Dropzone/Dropzone.cjs.map +1 -1
  95. package/dist/components/Dropzone/Dropzone.js.map +1 -1
  96. package/dist/components/FileUpload/FileUpload.cjs.map +1 -1
  97. package/dist/components/FileUpload/FileUpload.js.map +1 -1
  98. package/dist/components/FilterBar/FilterBar.cjs.map +1 -1
  99. package/dist/components/FilterBar/FilterBar.js.map +1 -1
  100. package/dist/components/ImageCropper/ImageCropper.cjs.map +1 -1
  101. package/dist/components/ImageCropper/ImageCropper.js.map +1 -1
  102. package/dist/components/InstallBanner/InstallBanner.cjs.map +1 -1
  103. package/dist/components/InstallBanner/InstallBanner.js.map +1 -1
  104. package/dist/components/Kanban/Kanban.cjs.map +1 -1
  105. package/dist/components/Kanban/Kanban.js.map +1 -1
  106. package/dist/components/Lightbox/Lightbox.cjs.map +1 -1
  107. package/dist/components/Lightbox/Lightbox.js.map +1 -1
  108. package/dist/components/ListTile/ListTile.cjs.map +1 -1
  109. package/dist/components/ListTile/ListTile.js.map +1 -1
  110. package/dist/components/Markdown/Markdown.cjs.map +1 -1
  111. package/dist/components/Markdown/Markdown.js.map +1 -1
  112. package/dist/components/Markdown/markdown-parse.cjs.map +1 -1
  113. package/dist/components/Markdown/markdown-parse.js.map +1 -1
  114. package/dist/components/Menubar/Menubar.cjs.map +1 -1
  115. package/dist/components/Menubar/Menubar.js.map +1 -1
  116. package/dist/components/Modal/Modal.cjs.map +1 -1
  117. package/dist/components/Modal/Modal.js.map +1 -1
  118. package/dist/components/ModalsManager/ModalsManager.cjs.map +1 -1
  119. package/dist/components/ModalsManager/ModalsManager.js.map +1 -1
  120. package/dist/components/MultiSelect/MultiSelect.cjs.map +1 -1
  121. package/dist/components/MultiSelect/MultiSelect.js.map +1 -1
  122. package/dist/components/NavigationMenu/NavigationMenu.cjs.map +1 -1
  123. package/dist/components/NavigationMenu/NavigationMenu.js.map +1 -1
  124. package/dist/components/NotificationCenter/NotificationCenter.cjs.map +1 -1
  125. package/dist/components/NotificationCenter/NotificationCenter.js.map +1 -1
  126. package/dist/components/Page/Page.cjs.map +1 -1
  127. package/dist/components/Page/Page.js.map +1 -1
  128. package/dist/components/Pagination/Pagination.cjs.map +1 -1
  129. package/dist/components/Pagination/Pagination.js.map +1 -1
  130. package/dist/components/PasswordInput/PasswordInput.cjs.map +1 -1
  131. package/dist/components/PasswordInput/PasswordInput.js.map +1 -1
  132. package/dist/components/PinInput/PinInput.cjs.map +1 -1
  133. package/dist/components/PinInput/PinInput.js.map +1 -1
  134. package/dist/components/Popover/Popover.cjs.map +1 -1
  135. package/dist/components/Popover/Popover.js.map +1 -1
  136. package/dist/components/Progress/Progress.cjs.map +1 -1
  137. package/dist/components/Progress/Progress.js.map +1 -1
  138. package/dist/components/QRCode/qr-encode.cjs.map +1 -1
  139. package/dist/components/QRCode/qr-encode.js.map +1 -1
  140. package/dist/components/Radio/Radio.cjs.map +1 -1
  141. package/dist/components/Radio/Radio.js.map +1 -1
  142. package/dist/components/RangeSlider/RangeSlider.cjs.map +1 -1
  143. package/dist/components/RangeSlider/RangeSlider.js.map +1 -1
  144. package/dist/components/RatingStars/RatingStars.cjs.map +1 -1
  145. package/dist/components/RatingStars/RatingStars.js.map +1 -1
  146. package/dist/components/RefreshIndicator/RefreshIndicator.cjs.map +1 -1
  147. package/dist/components/RefreshIndicator/RefreshIndicator.js.map +1 -1
  148. package/dist/components/Resizable/Resizable.cjs.map +1 -1
  149. package/dist/components/Resizable/Resizable.js.map +1 -1
  150. package/dist/components/Scheduler/Scheduler.cjs.map +1 -1
  151. package/dist/components/Scheduler/Scheduler.js.map +1 -1
  152. package/dist/components/Sidebar/Sidebar.cjs.map +1 -1
  153. package/dist/components/Sidebar/Sidebar.js.map +1 -1
  154. package/dist/components/SignaturePad/SignaturePad.cjs.map +1 -1
  155. package/dist/components/SignaturePad/SignaturePad.js.map +1 -1
  156. package/dist/components/Slider/Slider.cjs.map +1 -1
  157. package/dist/components/Slider/Slider.js.map +1 -1
  158. package/dist/components/Sparkline/Sparkline.cjs.map +1 -1
  159. package/dist/components/Sparkline/Sparkline.js.map +1 -1
  160. package/dist/components/StepperInput/StepperInput.cjs.map +1 -1
  161. package/dist/components/StepperInput/StepperInput.js.map +1 -1
  162. package/dist/components/Table/Table.cjs.map +1 -1
  163. package/dist/components/Table/Table.js.map +1 -1
  164. package/dist/components/TimePicker/TimePicker.cjs.map +1 -1
  165. package/dist/components/TimePicker/TimePicker.js.map +1 -1
  166. package/dist/components/Toast/ToastProvider.cjs.map +1 -1
  167. package/dist/components/Toast/ToastProvider.js.map +1 -1
  168. package/dist/components/Tour/Tour.cjs.map +1 -1
  169. package/dist/components/Tour/Tour.js.map +1 -1
  170. package/dist/components/Transfer/Transfer.cjs.map +1 -1
  171. package/dist/components/Transfer/Transfer.js.map +1 -1
  172. package/dist/components/TreeView/TreeView.cjs.map +1 -1
  173. package/dist/components/TreeView/TreeView.js.map +1 -1
  174. package/dist/components/VirtualList/VirtualList.cjs.map +1 -1
  175. package/dist/components/VirtualList/VirtualList.js.map +1 -1
  176. package/dist/components/VirtualTable/VirtualTable.cjs.map +1 -1
  177. package/dist/components/VirtualTable/VirtualTable.js.map +1 -1
  178. package/dist/components/Wizard/Wizard.cjs.map +1 -1
  179. package/dist/components/Wizard/Wizard.js.map +1 -1
  180. package/dist/editor/RichTextEditor.cjs.map +1 -1
  181. package/dist/editor/RichTextEditor.js.map +1 -1
  182. package/dist/forms/FormField.cjs.map +1 -1
  183. package/dist/forms/FormField.js.map +1 -1
  184. package/dist/geo/TrajectoryMap.cjs.map +1 -1
  185. package/dist/geo/TrajectoryMap.js.map +1 -1
  186. package/dist/geo/estimate.cjs.map +1 -1
  187. package/dist/geo/estimate.js.map +1 -1
  188. package/dist/geo/projection.cjs.map +1 -1
  189. package/dist/geo/projection.js.map +1 -1
  190. package/dist/hooks/use-event-listener.cjs.map +1 -1
  191. package/dist/hooks/use-event-listener.js.map +1 -1
  192. package/dist/hooks/use-local-storage.cjs.map +1 -1
  193. package/dist/hooks/use-local-storage.js.map +1 -1
  194. package/dist/hooks/use-sortable.cjs.map +1 -1
  195. package/dist/hooks/use-sortable.js.map +1 -1
  196. package/dist/http/api-client.cjs.map +1 -1
  197. package/dist/http/api-client.js.map +1 -1
  198. package/dist/http/errors.cjs.map +1 -1
  199. package/dist/http/errors.js.map +1 -1
  200. package/dist/http/resumable-upload.cjs.map +1 -1
  201. package/dist/http/resumable-upload.js.map +1 -1
  202. package/dist/http/upload-with-progress.cjs.map +1 -1
  203. package/dist/http/upload-with-progress.js.map +1 -1
  204. package/dist/i18n/I18nProvider.cjs.map +1 -1
  205. package/dist/i18n/I18nProvider.js.map +1 -1
  206. package/dist/imaging/canvas.cjs.map +1 -1
  207. package/dist/imaging/canvas.js.map +1 -1
  208. package/dist/imaging.d.ts +5 -0
  209. package/dist/logger/logger.cjs.map +1 -1
  210. package/dist/logger/logger.js.map +1 -1
  211. package/dist/oauth/GoogleSignIn.cjs.map +1 -1
  212. package/dist/oauth/GoogleSignIn.js.map +1 -1
  213. package/dist/offline/create-offline-sync.cjs.map +1 -1
  214. package/dist/offline/create-offline-sync.js.map +1 -1
  215. package/dist/perf/cache-size.cjs +1 -1
  216. package/dist/perf/cache-size.cjs.map +1 -1
  217. package/dist/perf/cache-size.js +27 -6
  218. package/dist/perf/cache-size.js.map +1 -1
  219. package/dist/sse/create-event-stream.cjs.map +1 -1
  220. package/dist/sse/create-event-stream.js.map +1 -1
  221. package/dist/styles.css +1 -1
  222. package/dist/sw/background-sync.cjs.map +1 -1
  223. package/dist/sw/background-sync.js.map +1 -1
  224. package/dist/sw/cache.cjs.map +1 -1
  225. package/dist/sw/cache.js.map +1 -1
  226. package/dist/sw.d.ts +12 -0
  227. package/dist/tabular/compact.cjs.map +1 -1
  228. package/dist/tabular/compact.js.map +1 -1
  229. package/dist/tabular/predictor.cjs.map +1 -1
  230. package/dist/tabular/predictor.js.map +1 -1
  231. package/dist/tabular.d.ts +7 -2
  232. package/dist/tempest-react-sdk.d.ts +133 -6
  233. package/dist/theme/ThemeProvider.cjs.map +1 -1
  234. package/dist/theme/ThemeProvider.js.map +1 -1
  235. package/dist/theme/color.cjs.map +1 -1
  236. package/dist/theme/color.js.map +1 -1
  237. package/dist/theme/create-theme.cjs.map +1 -1
  238. package/dist/theme/create-theme.js.map +1 -1
  239. package/dist/theme/data-viz-ramps.cjs +1 -1
  240. package/dist/theme/data-viz-ramps.cjs.map +1 -1
  241. package/dist/theme/data-viz-ramps.js +1 -1
  242. package/dist/theme/data-viz-ramps.js.map +1 -1
  243. package/dist/utils/storage.cjs.map +1 -1
  244. package/dist/utils/storage.js.map +1 -1
  245. package/dist/vision/core/canvas.cjs +1 -1
  246. package/dist/vision/core/canvas.cjs.map +1 -1
  247. package/dist/vision/core/canvas.js +4 -4
  248. package/dist/vision/core/canvas.js.map +1 -1
  249. package/dist/vision/core/exceptions.cjs +1 -1
  250. package/dist/vision/core/exceptions.cjs.map +1 -1
  251. package/dist/vision/core/exceptions.js +2 -2
  252. package/dist/vision/core/exceptions.js.map +1 -1
  253. package/dist/vision/core/graph.cjs.map +1 -1
  254. package/dist/vision/core/graph.js.map +1 -1
  255. package/dist/vision/core/metadata.cjs +2 -2
  256. package/dist/vision/core/metadata.cjs.map +1 -1
  257. package/dist/vision/core/metadata.js +10 -7
  258. package/dist/vision/core/metadata.js.map +1 -1
  259. package/dist/vision/core/providers.cjs.map +1 -1
  260. package/dist/vision/core/providers.js.map +1 -1
  261. package/dist/vision/core/session.cjs +1 -1
  262. package/dist/vision/core/session.cjs.map +1 -1
  263. package/dist/vision/core/session.js +8 -5
  264. package/dist/vision/core/session.js.map +1 -1
  265. package/dist/vision/core/timing.cjs.map +1 -1
  266. package/dist/vision/core/timing.js.map +1 -1
  267. package/dist/vision/fusion.cjs +2 -0
  268. package/dist/vision/fusion.cjs.map +1 -0
  269. package/dist/vision/fusion.js +42 -0
  270. package/dist/vision/fusion.js.map +1 -0
  271. package/dist/vision/index.cjs +1 -1
  272. package/dist/vision/index.cjs.map +1 -1
  273. package/dist/vision/index.js +23 -20
  274. package/dist/vision/index.js.map +1 -1
  275. package/dist/vision/io/image.cjs.map +1 -1
  276. package/dist/vision/io/image.js.map +1 -1
  277. package/dist/vision/labels.cjs +1 -1
  278. package/dist/vision/labels.cjs.map +1 -1
  279. package/dist/vision/labels.js +7 -4
  280. package/dist/vision/labels.js.map +1 -1
  281. package/dist/vision/luminance.cjs.map +1 -1
  282. package/dist/vision/luminance.js.map +1 -1
  283. package/dist/vision/postprocess/classification.cjs.map +1 -1
  284. package/dist/vision/postprocess/classification.js.map +1 -1
  285. package/dist/vision/postprocess/detection.cjs +1 -1
  286. package/dist/vision/postprocess/detection.cjs.map +1 -1
  287. package/dist/vision/postprocess/detection.js +3 -10
  288. package/dist/vision/postprocess/detection.js.map +1 -1
  289. package/dist/vision/postprocess/segmentation.cjs +1 -1
  290. package/dist/vision/postprocess/segmentation.cjs.map +1 -1
  291. package/dist/vision/postprocess/segmentation.js +11 -15
  292. package/dist/vision/postprocess/segmentation.js.map +1 -1
  293. package/dist/vision/preprocess/image.cjs.map +1 -1
  294. package/dist/vision/preprocess/image.js.map +1 -1
  295. package/dist/vision/preprocess/pipeline.cjs +2 -0
  296. package/dist/vision/preprocess/pipeline.cjs.map +1 -0
  297. package/dist/vision/preprocess/pipeline.js +61 -0
  298. package/dist/vision/preprocess/pipeline.js.map +1 -0
  299. package/dist/vision/results.cjs +1 -1
  300. package/dist/vision/results.cjs.map +1 -1
  301. package/dist/vision/results.js +23 -2
  302. package/dist/vision/results.js.map +1 -1
  303. package/dist/vision/tasks/base.cjs +1 -1
  304. package/dist/vision/tasks/base.cjs.map +1 -1
  305. package/dist/vision/tasks/base.js +9 -2
  306. package/dist/vision/tasks/base.js.map +1 -1
  307. package/dist/vision/tasks/classifier.cjs.map +1 -1
  308. package/dist/vision/tasks/classifier.js.map +1 -1
  309. package/dist/vision/tasks/detectClassify.cjs +2 -0
  310. package/dist/vision/tasks/detectClassify.cjs.map +1 -0
  311. package/dist/vision/tasks/detectClassify.js +221 -0
  312. package/dist/vision/tasks/detectClassify.js.map +1 -0
  313. package/dist/vision/tasks/detector.cjs +1 -1
  314. package/dist/vision/tasks/detector.cjs.map +1 -1
  315. package/dist/vision/tasks/detector.js +54 -29
  316. package/dist/vision/tasks/detector.js.map +1 -1
  317. package/dist/vision/tasks/segmenter.cjs +1 -1
  318. package/dist/vision/tasks/segmenter.cjs.map +1 -1
  319. package/dist/vision/tasks/segmenter.js +53 -28
  320. package/dist/vision/tasks/segmenter.js.map +1 -1
  321. package/dist/vision/types.cjs.map +1 -1
  322. package/dist/vision/types.js.map +1 -1
  323. package/dist/vision.cjs +1 -1
  324. package/dist/vision.d.ts +1517 -956
  325. package/dist/vision.js +25 -22
  326. package/dist/vite/tempest-icons.cjs.map +1 -1
  327. package/dist/vite/tempest-icons.js.map +1 -1
  328. package/dist/vite/tempest-pwa-icons.cjs.map +1 -1
  329. package/dist/vite/tempest-pwa-icons.js.map +1 -1
  330. package/dist/ws/create-web-socket.cjs.map +1 -1
  331. package/dist/ws/create-web-socket.js.map +1 -1
  332. package/package.json +1 -1
@@ -0,0 +1,42 @@
1
+ import { parseNames as e } from "./core/metadata.js";
2
+ //#region src/vision/fusion.ts
3
+ var t = "detect_classify", n = "ovs.", r = "images", i = "source_image", a = "letterbox_scale", o = "letterbox_pad", s = "boxes", c = "scores", l = "classes", u = "num_detections", d = "probs", f = "kind", p = "sdk_version", m = "input_size", h = "crop_size", g = "crop_source", _ = "max_detections", v = "conf_threshold", y = "iou_threshold", b = "apply_softmax", x = "detector_names", S = "classifier_names", C = "dynamic";
4
+ function w(e) {
5
+ if (!e) return null;
6
+ let t = e.split(",");
7
+ if (t.length !== 2) return null;
8
+ let n = Number(t[0]), r = Number(t[1]);
9
+ return !Number.isInteger(n) || !Number.isInteger(r) || n < 1 || r < 1 ? null : [n, r];
10
+ }
11
+ function T(e, t) {
12
+ if (!e) return t;
13
+ let n = Number(e);
14
+ return Number.isFinite(n) ? n : t;
15
+ }
16
+ function E(n) {
17
+ if (!n) return null;
18
+ let r = {};
19
+ for (let [e, t] of Object.entries(n)) e.startsWith("ovs.") && (r[e.slice(4)] = t);
20
+ if (r[f] !== "detect_classify") return null;
21
+ let i = w(r[m]), a = w(r[h]);
22
+ if (i === null || a === null) return null;
23
+ let o = r[_] ?? C, s = Number(o), c = o === C || !Number.isInteger(s) || s < 1 ? null : s, l = r[g] === "original" ? "original" : "detector_input";
24
+ return {
25
+ kind: t,
26
+ inputSize: i,
27
+ cropSize: a,
28
+ cropSource: l,
29
+ maxDetections: c,
30
+ confThreshold: T(r[v], .25),
31
+ iouThreshold: T(r[y], .45),
32
+ applySoftmax: (r[b] ?? "1") !== "0",
33
+ detectorNames: e(r[x]),
34
+ classifierNames: e(r[S]),
35
+ sdkVersion: r[p] ?? "",
36
+ needsSourceImage: l === "original"
37
+ };
38
+ }
39
+ //#endregion
40
+ export { t as FUSION_KIND_DETECT_CLASSIFY, r as INPUT_IMAGE, o as INPUT_PAD, a as INPUT_SCALE, i as INPUT_SOURCE, n as METADATA_PREFIX, s as OUTPUT_BOXES, l as OUTPUT_CLASSES, u as OUTPUT_NUM_DETECTIONS, d as OUTPUT_PROBS, c as OUTPUT_SCORES, E as readFusionSpec };
41
+
42
+ //# sourceMappingURL=fusion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fusion.js","names":[],"sources":["../../src/vision/fusion.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * The contract a fused pipeline carries inside its own `.onnx` file.\n *\n * A pipeline built by the Python SDK's `ort_vision_sdk.compose` is a single\n * graph that already contains the detector, the crop-and-resize bridge and the\n * classifier. Everything the runtime needs to drive it — the letterbox\n * resolution, the crop resolution, where the crops come from, how many\n * detections the graph emits, the class names of both stages — was decided at\n * fusion time and written into the model's metadata.\n *\n * This module reads it back. It is the browser half of a contract whose other\n * half lives in `ort_vision_sdk/fusion.py`: the same keys, the same encodings,\n * the same fallbacks. A pipeline fused once therefore runs identically in\n * Python and in a browser tab, off the same file.\n *\n * Building a pipeline stays a Python-side build step — there is no ONNX\n * protobuf writer here, and there is no reason for one: fusing is something you\n * do once next to your export pipeline, not in a page load.\n */\n\nimport { parseNames } from \"./core/metadata\";\n\n/**\n * Which tensor the bridge crops the detected boxes out of.\n *\n * - `\"detector_input\"`: the letterboxed tensor already fed to the detector.\n * The fused graph then has a **single** image input, but a small object is\n * cropped out of its downscaled copy.\n * - `\"original\"`: a second, full-resolution image input. The bridge undoes the\n * letterbox transform in-graph and crops at native resolution. Two tensors to\n * feed, still one session and one model load.\n */\nexport type CropSource = \"detector_input\" | \"original\";\n\n/** Value of the `ovs.kind` metadata key for a detector→classifier pipeline. */\nexport const FUSION_KIND_DETECT_CLASSIFY = \"detect_classify\";\n\n/**\n * Namespace for every metadata key the fusion writes.\n *\n * Namespaced on purpose: the detector's own Ultralytics metadata (`names`,\n * `task`, `imgsz`) is carried over into the fused model, and an un-prefixed key\n * would either collide with it or be mistaken for it.\n */\nexport const METADATA_PREFIX = \"ovs.\";\n\n/** Name of the fused graph's letterboxed detector input, `[1, 3, H, W]` float32 in `[0, 1]`. */\nexport const INPUT_IMAGE = \"images\";\n\n/** Name of the full-resolution input. Present only when `cropSource === \"original\"`. */\nexport const INPUT_SOURCE = \"source_image\";\n\n/** Name of the `[1]` float32 letterbox scale factor. Only with `cropSource === \"original\"`. */\nexport const INPUT_SCALE = \"letterbox_scale\";\n\n/** Name of the `[2]` float32 `[padLeft, padTop]`. Only with `cropSource === \"original\"`. */\nexport const INPUT_PAD = \"letterbox_pad\";\n\n/** Name of the `[K, 4]` float32 xyxy output, in **letterboxed** input pixels. */\nexport const OUTPUT_BOXES = \"boxes\";\n\n/** Name of the `[K]` float32 detection-confidence output. */\nexport const OUTPUT_SCORES = \"scores\";\n\n/** Name of the `[K]` int64 detector-class output. */\nexport const OUTPUT_CLASSES = \"classes\";\n\n/** Name of the `[1]` int64 output holding how many of the `K` rows are real. */\nexport const OUTPUT_NUM_DETECTIONS = \"num_detections\";\n\n/** Name of the `[K, numClassifierClasses]` float32 classifier output, one row per box. */\nexport const OUTPUT_PROBS = \"probs\";\n\n/** Everything a fused pipeline declares about how it must be driven. */\nexport interface FusionSpec {\n /** Pipeline family. Only `\"detect_classify\"` exists today. */\n readonly kind: string;\n /** `[width, height]` the detector stage expects — the resolution to letterbox to. */\n readonly inputSize: readonly [number, number];\n /** `[width, height]` every crop is resampled to inside the graph. */\n readonly cropSize: readonly [number, number];\n /** Which tensor the crops are taken from. */\n readonly cropSource: CropSource;\n /**\n * Fixed number of rows `K` every output carries, surplus zero-padded and\n * counted by {@link OUTPUT_NUM_DETECTIONS}. `null` means the graph emits\n * exactly as many rows as survived NMS.\n */\n readonly maxDetections: number | null;\n /** Score threshold baked into the graph's NMS node. */\n readonly confThreshold: number;\n /** IoU threshold baked into the graph's NMS node. */\n readonly iouThreshold: number;\n /** Whether the classifier stage emits logits that still need a softmax. */\n readonly applySoftmax: boolean;\n /** Detector class names in class-id order, or `null` when the fusion recorded none. */\n readonly detectorNames: readonly string[] | null;\n /** Classifier class names in class-id order, or `null`. */\n readonly classifierNames: readonly string[] | null;\n /** Version of `ort-vision-sdk` that produced the file. */\n readonly sdkVersion: string;\n /** Whether driving this pipeline requires feeding the full-resolution input. */\n readonly needsSourceImage: boolean;\n}\n\nconst KEY_KIND = \"kind\";\nconst KEY_SDK_VERSION = \"sdk_version\";\nconst KEY_INPUT_SIZE = \"input_size\";\nconst KEY_CROP_SIZE = \"crop_size\";\nconst KEY_CROP_SOURCE = \"crop_source\";\nconst KEY_MAX_DETECTIONS = \"max_detections\";\nconst KEY_CONF_THRESHOLD = \"conf_threshold\";\nconst KEY_IOU_THRESHOLD = \"iou_threshold\";\nconst KEY_APPLY_SOFTMAX = \"apply_softmax\";\nconst KEY_DETECTOR_NAMES = \"detector_names\";\nconst KEY_CLASSIFIER_NAMES = \"classifier_names\";\n\nconst DYNAMIC = \"dynamic\";\n\n/**\n * Decode a `\"640,640\"` pair.\n *\n * @param raw The encoded pair.\n * @returns `[width, height]`, or `null` when the value is missing or malformed.\n */\nfunction decodeSize(raw: string | undefined): readonly [number, number] | null {\n if (!raw) return null;\n const parts = raw.split(\",\");\n if (parts.length !== 2) return null;\n const width = Number(parts[0]);\n const height = Number(parts[1]);\n if (!Number.isInteger(width) || !Number.isInteger(height)) return null;\n if (width < 1 || height < 1) return null;\n return [width, height];\n}\n\n/**\n * Decode a float, falling back when the value is missing or malformed.\n *\n * @param raw The encoded value.\n * @param fallback Value to use when `raw` cannot be read.\n * @returns The parsed number, or `fallback`.\n */\nfunction decodeFloat(raw: string | undefined, fallback: number): number {\n if (!raw) return fallback;\n const value = Number(raw);\n return Number.isFinite(value) ? value : fallback;\n}\n\n/**\n * Read a pipeline spec out of a model's custom metadata.\n *\n * Individual malformed entries fall back to the value a fusion would have used\n * by default — a single bad float is not a reason to reject an otherwise\n * loadable pipeline. A malformed resolution is fatal, because there is no safe\n * default for one.\n *\n * @param metadata A model's custom metadata map, as read by\n * {@link readModelMetadata}.\n * @returns The decoded spec, or `null` when the model is not a fused pipeline —\n * it carries no `ovs.kind` entry, or one naming a pipeline kind this version\n * does not know how to drive.\n */\nexport function readFusionSpec(\n metadata: Readonly<Record<string, string>> | undefined,\n): FusionSpec | null {\n if (!metadata) return null;\n\n const read: Record<string, string> = {};\n for (const [key, value] of Object.entries(metadata)) {\n if (key.startsWith(METADATA_PREFIX)) read[key.slice(METADATA_PREFIX.length)] = value;\n }\n if (read[KEY_KIND] !== FUSION_KIND_DETECT_CLASSIFY) return null;\n\n const inputSize = decodeSize(read[KEY_INPUT_SIZE]);\n const cropSize = decodeSize(read[KEY_CROP_SIZE]);\n if (inputSize === null || cropSize === null) return null;\n\n const rawMax = read[KEY_MAX_DETECTIONS] ?? DYNAMIC;\n const parsedMax = Number(rawMax);\n const maxDetections =\n rawMax === DYNAMIC || !Number.isInteger(parsedMax) || parsedMax < 1 ? null : parsedMax;\n\n const cropSource: CropSource =\n read[KEY_CROP_SOURCE] === \"original\" ? \"original\" : \"detector_input\";\n\n return {\n kind: FUSION_KIND_DETECT_CLASSIFY,\n inputSize,\n cropSize,\n cropSource,\n maxDetections,\n confThreshold: decodeFloat(read[KEY_CONF_THRESHOLD], 0.25),\n iouThreshold: decodeFloat(read[KEY_IOU_THRESHOLD], 0.45),\n applySoftmax: (read[KEY_APPLY_SOFTMAX] ?? \"1\") !== \"0\",\n detectorNames: parseNames(read[KEY_DETECTOR_NAMES]),\n classifierNames: parseNames(read[KEY_CLASSIFIER_NAMES]),\n sdkVersion: read[KEY_SDK_VERSION] ?? \"\",\n needsSourceImage: cropSource === \"original\",\n };\n}\n"],"mappings":";;AAoCA,IAAa,IAA8B,mBAS9B,IAAkB,QAGlB,IAAc,UAGd,IAAe,gBAGf,IAAc,mBAGd,IAAY,iBAGZ,IAAe,SAGf,IAAgB,UAGhB,IAAiB,WAGjB,IAAwB,kBAGxB,IAAe,SAkCtB,IAAW,QACX,IAAkB,eAClB,IAAiB,cACjB,IAAgB,aAChB,IAAkB,eAClB,IAAqB,kBACrB,IAAqB,kBACrB,IAAoB,iBACpB,IAAoB,iBACpB,IAAqB,kBACrB,IAAuB,oBAEvB,IAAU;AAQhB,SAAS,EAAW,GAA2D;CAC3E,IAAI,CAAC,GAAK,OAAO;CACjB,IAAM,IAAQ,EAAI,MAAM,GAAG;CAC3B,IAAI,EAAM,WAAW,GAAG,OAAO;CAC/B,IAAM,IAAQ,OAAO,EAAM,EAAE,GACvB,IAAS,OAAO,EAAM,EAAE;CAG9B,OAFI,CAAC,OAAO,UAAU,CAAK,KAAK,CAAC,OAAO,UAAU,CAAM,KACpD,IAAQ,KAAK,IAAS,IAAU,OAC7B,CAAC,GAAO,CAAM;AACzB;AASA,SAAS,EAAY,GAAyB,GAA0B;CACpE,IAAI,CAAC,GAAK,OAAO;CACjB,IAAM,IAAQ,OAAO,CAAG;CACxB,OAAO,OAAO,SAAS,CAAK,IAAI,IAAQ;AAC5C;AAgBA,SAAgB,EACZ,GACiB;CACjB,IAAI,CAAC,GAAU,OAAO;CAEtB,IAAM,IAA+B,CAAC;CACtC,KAAK,IAAM,CAAC,GAAK,MAAU,OAAO,QAAQ,CAAQ,GAC9C,AAAI,EAAI,WAAA,MAA0B,MAAG,EAAK,EAAI,MAAM,CAAsB,KAAK;CAEnF,IAAI,EAAK,OAAA,mBAA2C,OAAO;CAE3D,IAAM,IAAY,EAAW,EAAK,EAAe,GAC3C,IAAW,EAAW,EAAK,EAAc;CAC/C,IAAI,MAAc,QAAQ,MAAa,MAAM,OAAO;CAEpD,IAAM,IAAS,EAAK,MAAuB,GACrC,IAAY,OAAO,CAAM,GACzB,IACF,MAAW,KAAW,CAAC,OAAO,UAAU,CAAS,KAAK,IAAY,IAAI,OAAO,GAE3E,IACF,EAAK,OAAqB,aAAa,aAAa;CAExD,OAAO;EACH,MAAM;EACN;EACA;EACA;EACA;EACA,eAAe,EAAY,EAAK,IAAqB,GAAI;EACzD,cAAc,EAAY,EAAK,IAAoB,GAAI;EACvD,eAAe,EAAK,MAAsB,SAAS;EACnD,eAAe,EAAW,EAAK,EAAmB;EAClD,iBAAiB,EAAW,EAAK,EAAqB;EACtD,YAAY,EAAK,MAAoB;EACrC,kBAAkB,MAAe;CACrC;AACJ"}
@@ -1,2 +1,2 @@
1
- const e=require("./core/exceptions.cjs"),t=require("./types.cjs"),n=require("./core/timing.cjs"),r=require("./results.cjs"),i=require("./labels.cjs"),a=require("./core/graph.cjs"),o=require("./core/metadata.cjs"),s=require("./core/providers.cjs"),c=require("./core/session.cjs"),l=require("./io/image.cjs"),u=require("./preprocess/image.cjs"),d=require("./postprocess/classification.cjs"),f=require("./postprocess/detection.cjs"),p=require("./postprocess/segmentation.cjs"),m=require("./tasks/base.cjs"),h=require("./tasks/classifier.cjs"),g=require("./tasks/detector.cjs"),_=require("./tasks/segmenter.cjs");var v=`0.5.1`;exports.BoundingBox=t.BoundingBox,exports.Boxes=r.Boxes,exports.COCO_CLASSES=i.COCO_CLASSES,exports.ClassificationResults=r.ClassificationResults,exports.Classifier=h.Classifier,exports.DEFAULT_PROVIDERS=s.DEFAULT_PROVIDERS,exports.DetectionResults=r.DetectionResults,exports.Detector=g.Detector,exports.ImageLoadError=e.ImageLoadError,exports.InferenceError=e.InferenceError,exports.LabelMapError=e.LabelMapError,exports.Mask=t.Mask,exports.Masks=r.Masks,exports.ModelLoadError=e.ModelLoadError,exports.OrtSession=c.OrtSession,exports.OrtVisionError=e.OrtVisionError,exports.Probs=r.Probs,exports.ProviderNotAvailableError=e.ProviderNotAvailableError,exports.RGBImage=t.RGBImage,exports.SegmentationResults=r.SegmentationResults,exports.Segmenter=_.Segmenter,exports.SpeedTimer=n.SpeedTimer,exports.VERSION=v,exports.VisionTask=m.VisionTask,exports.batchedNms=f.batchedNms,exports.classificationNumClasses=a.classificationNumClasses,exports.declaredShapesFrom=a.declaredShapesFrom,exports.decodeYolo=f.decodeYolo,exports.decodeYoloAnchors=f.decodeYoloAnchors,exports.decodeYoloSeg=p.decodeYoloSeg,exports.decodeYoloV8=f.decodeYoloV8,exports.decodeYoloV8Anchors=f.decodeYoloV8Anchors,exports.decodeYoloV8Seg=p.decodeYoloV8Seg,exports.detectionNumClasses=a.detectionNumClasses,exports.fromCv2=u.fromCv2,exports.letterbox=u.letterbox,exports.loadImage=l.loadImage,exports.modelNames=o.modelNames,exports.nms=f.nms,exports.normalize=u.normalize,exports.readModelMetadata=o.readModelMetadata,exports.resize=u.resize,exports.resolveInputSize=a.resolveInputSize,exports.resolveLabels=i.resolveLabels,exports.resolveProviders=s.resolveProviders,exports.softmax=d.softmax,exports.spatialInputSize=a.spatialInputSize,exports.toCHW=u.toCHW,exports.toCv2=u.toCv2,exports.toFloat32=u.toFloat32,exports.toFloat32Tensor=u.toFloat32Tensor,exports.toTensor=u.toTensor,exports.topK=d.topK;
1
+ const e=require("./core/exceptions.cjs"),t=require("./types.cjs"),n=require("./core/timing.cjs"),r=require("./results.cjs"),i=require("./labels.cjs"),a=require("./core/graph.cjs"),o=require("./core/metadata.cjs"),s=require("./core/providers.cjs"),c=require("./core/session.cjs"),l=require("./io/image.cjs"),u=require("./fusion.cjs"),d=require("./preprocess/image.cjs"),f=require("./preprocess/pipeline.cjs"),p=require("./postprocess/classification.cjs"),m=require("./postprocess/detection.cjs"),h=require("./postprocess/segmentation.cjs"),g=require("./tasks/base.cjs"),_=require("./tasks/classifier.cjs"),v=require("./tasks/detectClassify.cjs"),y=require("./tasks/detector.cjs"),b=require("./tasks/segmenter.cjs");var x=`0.6.1`;exports.BoundingBox=t.BoundingBox,exports.Boxes=r.Boxes,exports.COCO_CLASSES=i.COCO_CLASSES,exports.ClassificationResults=r.ClassificationResults,exports.Classifier=_.Classifier,exports.DEFAULT_PROVIDERS=s.DEFAULT_PROVIDERS,exports.DetectClassify=v.DetectClassify,exports.DetectClassifyResults=r.DetectClassifyResults,exports.DetectionResults=r.DetectionResults,exports.Detector=y.Detector,exports.FUSION_KIND_DETECT_CLASSIFY=u.FUSION_KIND_DETECT_CLASSIFY,exports.FusionError=e.FusionError,exports.INPUT_IMAGE=u.INPUT_IMAGE,exports.INPUT_PAD=u.INPUT_PAD,exports.INPUT_SCALE=u.INPUT_SCALE,exports.INPUT_SOURCE=u.INPUT_SOURCE,exports.ImageLoadError=e.ImageLoadError,exports.InferenceError=e.InferenceError,exports.LabelMapError=e.LabelMapError,exports.LetterboxPipeline=f.LetterboxPipeline,exports.METADATA_PREFIX=u.METADATA_PREFIX,exports.Mask=t.Mask,exports.Masks=r.Masks,exports.ModelLoadError=e.ModelLoadError,exports.NoDetectionsError=e.NoDetectionsError,exports.OUTPUT_BOXES=u.OUTPUT_BOXES,exports.OUTPUT_CLASSES=u.OUTPUT_CLASSES,exports.OUTPUT_NUM_DETECTIONS=u.OUTPUT_NUM_DETECTIONS,exports.OUTPUT_PROBS=u.OUTPUT_PROBS,exports.OUTPUT_SCORES=u.OUTPUT_SCORES,exports.OrtSession=c.OrtSession,exports.OrtVisionError=e.OrtVisionError,exports.Probs=r.Probs,exports.ProviderNotAvailableError=e.ProviderNotAvailableError,exports.RGBImage=t.RGBImage,exports.SegmentationResults=r.SegmentationResults,exports.Segmenter=b.Segmenter,exports.SpeedTimer=n.SpeedTimer,exports.VERSION=x,exports.VisionTask=g.VisionTask,exports.batchedNms=m.batchedNms,exports.classificationNumClasses=a.classificationNumClasses,exports.declaredShapesFrom=a.declaredShapesFrom,exports.decodeYolo=m.decodeYolo,exports.decodeYoloAnchors=m.decodeYoloAnchors,exports.decodeYoloSeg=h.decodeYoloSeg,exports.defaultLabels=i.defaultLabels,exports.detectionNumClasses=a.detectionNumClasses,exports.fromCv2=d.fromCv2,exports.letterbox=d.letterbox,exports.letterboxToTensorData=f.letterboxToTensorData,exports.loadImage=l.loadImage,exports.modelNames=o.modelNames,exports.nms=m.nms,exports.normalize=d.normalize,exports.parseNames=o.parseNames,exports.readFusionSpec=u.readFusionSpec,exports.readModelMetadata=o.readModelMetadata,exports.requireDetections=g.requireDetections,exports.resize=d.resize,exports.resolveInputSize=a.resolveInputSize,exports.resolveLabels=i.resolveLabels,exports.resolveProviders=s.resolveProviders,exports.softmax=p.softmax,exports.spatialInputSize=a.spatialInputSize,exports.toCHW=d.toCHW,exports.toCv2=d.toCv2,exports.toFloat32=d.toFloat32,exports.toFloat32Tensor=d.toFloat32Tensor,exports.toTensor=d.toTensor,exports.topK=p.topK,exports.zeroTensorData=f.zeroTensorData;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/vision/index.ts"],"sourcesContent":["/**\n * `tempest-react-sdk/vision` — browser computer-vision inference with ONNX\n * Runtime Web (classification, detection, segmentation).\n *\n * Vendored from `@mauriciobenjamin700/ort-vision-sdk-web@0.5.1` (MIT, same\n * author) so it ships inside this SDK without an extra package install.\n * `onnxruntime-web` stays an optional peer dependency — install it (and ship\n * the matching `.wasm` files) only when you use this subpath.\n *\n * Do not hand-edit — regenerate with `npm run vendor:vision`.\n */\n\nexport {\n BoundingBox,\n Mask,\n RGBImage,\n type ClassProbability,\n type ClassificationResult,\n type DetectionResult,\n type SegmentationResult,\n} from \"./types\";\n\nexport {\n Boxes,\n ClassificationResults,\n DetectionResults,\n Masks,\n Probs,\n SegmentationResults,\n} from \"./results\";\n\nexport { COCO_CLASSES, type LabelSpec, type ResolveLabelsOptions, resolveLabels } from \"./labels\";\n\nexport {\n ImageLoadError,\n InferenceError,\n LabelMapError,\n ModelLoadError,\n OrtVisionError,\n ProviderNotAvailableError,\n} from \"./core/exceptions\";\n\nexport { type ModelSource, type OrtSessionOptions, OrtSession } from \"./core/session\";\nexport {\n type DeclaredDim,\n type DeclaredShape,\n type ResolveInputSizeOptions,\n classificationNumClasses,\n declaredShapesFrom,\n detectionNumClasses,\n resolveInputSize,\n spatialInputSize,\n} from \"./core/graph\";\nexport { modelNames, readModelMetadata } from \"./core/metadata\";\nexport { DEFAULT_PROVIDERS, resolveProviders } from \"./core/providers\";\nexport { type Speed, SpeedTimer } from \"./core/timing\";\n\nexport { type ImageInput, loadImage } from \"./io/image\";\n\nexport {\n type LetterboxResult,\n fromCv2,\n letterbox,\n normalize,\n resize,\n toCHW,\n toCv2,\n toFloat32,\n toFloat32Tensor,\n toTensor,\n} from \"./preprocess/image\";\n\nexport { type TopKResult, softmax, topK } from \"./postprocess/classification\";\n\nexport {\n type DecodeYoloAnchorsOptions,\n type DecodeYoloOptions,\n type DecodeYoloV8AnchorsOptions,\n type DecodeYoloV8Options,\n type DecodedAnchors,\n type DecodedDetection,\n batchedNms,\n decodeYolo,\n decodeYoloAnchors,\n decodeYoloV8,\n decodeYoloV8Anchors,\n nms,\n} from \"./postprocess/detection\";\n\nexport {\n type DecodeYoloSegOptions,\n type DecodeYoloV8SegOptions,\n type DecodedSegmentation,\n decodeYoloSeg,\n decodeYoloV8Seg,\n} from \"./postprocess/segmentation\";\n\nexport { VisionTask } from \"./tasks/base\";\nexport {\n type ClassifierOptions,\n type ClassifierPredictOptions,\n Classifier,\n} from \"./tasks/classifier\";\nexport {\n type DetectorHead,\n type DetectorOptions,\n type DetectorPredictOptions,\n Detector,\n} from \"./tasks/detector\";\nexport {\n type SegmenterHead,\n type SegmenterOptions,\n type SegmenterPredictOptions,\n Segmenter,\n} from \"./tasks/segmenter\";\n\nexport const VERSION: string = \"0.5.1\";\n"],"mappings":"imBAoHA,IAAa,EAAkB"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/vision/index.ts"],"sourcesContent":["/**\n * `tempest-react-sdk/vision` — browser computer-vision inference with ONNX\n * Runtime Web (classification, detection, segmentation).\n *\n * Vendored from `@mauriciobenjamin700/ort-vision-sdk-web@0.6.1` (MIT, same\n * author) so it ships inside this SDK without an extra package install.\n * `onnxruntime-web` stays an optional peer dependency — install it (and ship\n * the matching `.wasm` files) only when you use this subpath.\n *\n * Do not hand-edit — regenerate with `npm run vendor:vision`.\n */\n\nexport {\n BoundingBox,\n Mask,\n RGBImage,\n type ClassProbability,\n type ClassificationResult,\n type DetectionResult,\n type SegmentationResult,\n} from \"./types\";\n\nexport {\n Boxes,\n ClassificationResults,\n DetectClassifyResults,\n DetectionResults,\n Masks,\n Probs,\n SegmentationResults,\n} from \"./results\";\n\nexport {\n COCO_CLASSES,\n type LabelSpec,\n type ResolveLabelsOptions,\n defaultLabels,\n resolveLabels,\n} from \"./labels\";\n\nexport {\n FusionError,\n ImageLoadError,\n InferenceError,\n LabelMapError,\n ModelLoadError,\n NoDetectionsError,\n OrtVisionError,\n ProviderNotAvailableError,\n} from \"./core/exceptions\";\n\nexport { type ModelSource, type OrtSessionOptions, OrtSession } from \"./core/session\";\nexport {\n type DeclaredDim,\n type DeclaredShape,\n type ResolveInputSizeOptions,\n classificationNumClasses,\n declaredShapesFrom,\n detectionNumClasses,\n resolveInputSize,\n spatialInputSize,\n} from \"./core/graph\";\nexport { modelNames, parseNames, readModelMetadata } from \"./core/metadata\";\nexport { DEFAULT_PROVIDERS, resolveProviders } from \"./core/providers\";\nexport { type Speed, SpeedTimer } from \"./core/timing\";\n\nexport { type ImageInput, loadImage } from \"./io/image\";\n\nexport {\n FUSION_KIND_DETECT_CLASSIFY,\n INPUT_IMAGE,\n INPUT_PAD,\n INPUT_SCALE,\n INPUT_SOURCE,\n METADATA_PREFIX,\n OUTPUT_BOXES,\n OUTPUT_CLASSES,\n OUTPUT_NUM_DETECTIONS,\n OUTPUT_PROBS,\n OUTPUT_SCORES,\n type CropSource,\n type FusionSpec,\n readFusionSpec,\n} from \"./fusion\";\n\nexport {\n type LetterboxResult,\n fromCv2,\n letterbox,\n normalize,\n resize,\n toCHW,\n toCv2,\n toFloat32,\n toFloat32Tensor,\n toTensor,\n} from \"./preprocess/image\";\n\nexport {\n type FusedLetterboxResult,\n LetterboxPipeline,\n letterboxToTensorData,\n zeroTensorData,\n} from \"./preprocess/pipeline\";\n\nexport { type TopKResult, softmax, topK } from \"./postprocess/classification\";\n\nexport {\n type DecodeYoloAnchorsOptions,\n type DecodeYoloOptions,\n type DecodedAnchors,\n type DecodedDetection,\n batchedNms,\n decodeYolo,\n decodeYoloAnchors,\n nms,\n} from \"./postprocess/detection\";\n\nexport {\n type DecodeYoloSegOptions,\n type DecodedSegmentation,\n decodeYoloSeg,\n} from \"./postprocess/segmentation\";\n\nexport { VisionTask, requireDetections } from \"./tasks/base\";\nexport {\n type ClassifierOptions,\n type ClassifierPredictOptions,\n Classifier,\n} from \"./tasks/classifier\";\nexport {\n type DetectClassifyOptions,\n type DetectClassifyPredictOptions,\n DetectClassify,\n} from \"./tasks/detectClassify\";\nexport {\n type DetectorHead,\n type DetectorOptions,\n type DetectorPredictOptions,\n Detector,\n} from \"./tasks/detector\";\nexport {\n type SegmenterHead,\n type SegmenterOptions,\n type SegmenterPredictOptions,\n Segmenter,\n} from \"./tasks/segmenter\";\n\nexport const VERSION: string = \"0.6.1\";\n"],"mappings":"0sBAoJA,IAAa,EAAkB"}
@@ -1,24 +1,27 @@
1
- import { ImageLoadError as e, InferenceError as t, LabelMapError as n, ModelLoadError as r, OrtVisionError as i, ProviderNotAvailableError as a } from "./core/exceptions.js";
2
- import { BoundingBox as o, Mask as s, RGBImage as c } from "./types.js";
3
- import { SpeedTimer as l } from "./core/timing.js";
4
- import { Boxes as u, ClassificationResults as d, DetectionResults as f, Masks as p, Probs as m, SegmentationResults as h } from "./results.js";
5
- import { COCO_CLASSES as g, resolveLabels as _ } from "./labels.js";
6
- import { classificationNumClasses as v, declaredShapesFrom as y, detectionNumClasses as b, resolveInputSize as x, spatialInputSize as S } from "./core/graph.js";
7
- import { modelNames as C, readModelMetadata as w } from "./core/metadata.js";
8
- import { DEFAULT_PROVIDERS as T, resolveProviders as E } from "./core/providers.js";
9
- import { OrtSession as D } from "./core/session.js";
10
- import { loadImage as O } from "./io/image.js";
11
- import { fromCv2 as k, letterbox as A, normalize as j, resize as M, toCHW as N, toCv2 as P, toFloat32 as F, toFloat32Tensor as I, toTensor as L } from "./preprocess/image.js";
12
- import { softmax as R, topK as z } from "./postprocess/classification.js";
13
- import { batchedNms as B, decodeYolo as V, decodeYoloAnchors as H, decodeYoloV8 as U, decodeYoloV8Anchors as W, nms as G } from "./postprocess/detection.js";
14
- import { decodeYoloSeg as K, decodeYoloV8Seg as q } from "./postprocess/segmentation.js";
15
- import { VisionTask as J } from "./tasks/base.js";
16
- import { Classifier as Y } from "./tasks/classifier.js";
17
- import { Detector as X } from "./tasks/detector.js";
18
- import { Segmenter as Z } from "./tasks/segmenter.js";
1
+ import { FusionError as e, ImageLoadError as t, InferenceError as n, LabelMapError as r, ModelLoadError as i, NoDetectionsError as a, OrtVisionError as o, ProviderNotAvailableError as s } from "./core/exceptions.js";
2
+ import { BoundingBox as c, Mask as l, RGBImage as u } from "./types.js";
3
+ import { SpeedTimer as d } from "./core/timing.js";
4
+ import { Boxes as f, ClassificationResults as p, DetectClassifyResults as m, DetectionResults as h, Masks as g, Probs as _, SegmentationResults as v } from "./results.js";
5
+ import { COCO_CLASSES as y, defaultLabels as b, resolveLabels as x } from "./labels.js";
6
+ import { classificationNumClasses as S, declaredShapesFrom as C, detectionNumClasses as w, resolveInputSize as T, spatialInputSize as E } from "./core/graph.js";
7
+ import { modelNames as D, parseNames as O, readModelMetadata as k } from "./core/metadata.js";
8
+ import { DEFAULT_PROVIDERS as A, resolveProviders as j } from "./core/providers.js";
9
+ import { OrtSession as M } from "./core/session.js";
10
+ import { loadImage as N } from "./io/image.js";
11
+ import { FUSION_KIND_DETECT_CLASSIFY as P, INPUT_IMAGE as F, INPUT_PAD as I, INPUT_SCALE as L, INPUT_SOURCE as R, METADATA_PREFIX as z, OUTPUT_BOXES as B, OUTPUT_CLASSES as V, OUTPUT_NUM_DETECTIONS as H, OUTPUT_PROBS as U, OUTPUT_SCORES as W, readFusionSpec as G } from "./fusion.js";
12
+ import { fromCv2 as K, letterbox as q, normalize as J, resize as Y, toCHW as X, toCv2 as Z, toFloat32 as Q, toFloat32Tensor as $, toTensor as ee } from "./preprocess/image.js";
13
+ import { LetterboxPipeline as te, letterboxToTensorData as ne, zeroTensorData as re } from "./preprocess/pipeline.js";
14
+ import { softmax as ie, topK as ae } from "./postprocess/classification.js";
15
+ import { batchedNms as oe, decodeYolo as se, decodeYoloAnchors as ce, nms as le } from "./postprocess/detection.js";
16
+ import { decodeYoloSeg as ue } from "./postprocess/segmentation.js";
17
+ import { VisionTask as de, requireDetections as fe } from "./tasks/base.js";
18
+ import { Classifier as pe } from "./tasks/classifier.js";
19
+ import { DetectClassify as me } from "./tasks/detectClassify.js";
20
+ import { Detector as he } from "./tasks/detector.js";
21
+ import { Segmenter as ge } from "./tasks/segmenter.js";
19
22
  //#region src/vision/index.ts
20
- var Q = "0.5.1";
23
+ var _e = "0.6.1";
21
24
  //#endregion
22
- export { o as BoundingBox, u as Boxes, g as COCO_CLASSES, d as ClassificationResults, Y as Classifier, T as DEFAULT_PROVIDERS, f as DetectionResults, X as Detector, e as ImageLoadError, t as InferenceError, n as LabelMapError, s as Mask, p as Masks, r as ModelLoadError, D as OrtSession, i as OrtVisionError, m as Probs, a as ProviderNotAvailableError, c as RGBImage, h as SegmentationResults, Z as Segmenter, l as SpeedTimer, Q as VERSION, J as VisionTask, B as batchedNms, v as classificationNumClasses, y as declaredShapesFrom, V as decodeYolo, H as decodeYoloAnchors, K as decodeYoloSeg, U as decodeYoloV8, W as decodeYoloV8Anchors, q as decodeYoloV8Seg, b as detectionNumClasses, k as fromCv2, A as letterbox, O as loadImage, C as modelNames, G as nms, j as normalize, w as readModelMetadata, M as resize, x as resolveInputSize, _ as resolveLabels, E as resolveProviders, R as softmax, S as spatialInputSize, N as toCHW, P as toCv2, F as toFloat32, I as toFloat32Tensor, L as toTensor, z as topK };
25
+ export { c as BoundingBox, f as Boxes, y as COCO_CLASSES, p as ClassificationResults, pe as Classifier, A as DEFAULT_PROVIDERS, me as DetectClassify, m as DetectClassifyResults, h as DetectionResults, he as Detector, P as FUSION_KIND_DETECT_CLASSIFY, e as FusionError, F as INPUT_IMAGE, I as INPUT_PAD, L as INPUT_SCALE, R as INPUT_SOURCE, t as ImageLoadError, n as InferenceError, r as LabelMapError, te as LetterboxPipeline, z as METADATA_PREFIX, l as Mask, g as Masks, i as ModelLoadError, a as NoDetectionsError, B as OUTPUT_BOXES, V as OUTPUT_CLASSES, H as OUTPUT_NUM_DETECTIONS, U as OUTPUT_PROBS, W as OUTPUT_SCORES, M as OrtSession, o as OrtVisionError, _ as Probs, s as ProviderNotAvailableError, u as RGBImage, v as SegmentationResults, ge as Segmenter, d as SpeedTimer, _e as VERSION, de as VisionTask, oe as batchedNms, S as classificationNumClasses, C as declaredShapesFrom, se as decodeYolo, ce as decodeYoloAnchors, ue as decodeYoloSeg, b as defaultLabels, w as detectionNumClasses, K as fromCv2, q as letterbox, ne as letterboxToTensorData, N as loadImage, D as modelNames, le as nms, J as normalize, O as parseNames, G as readFusionSpec, k as readModelMetadata, fe as requireDetections, Y as resize, T as resolveInputSize, x as resolveLabels, j as resolveProviders, ie as softmax, E as spatialInputSize, X as toCHW, Z as toCv2, Q as toFloat32, $ as toFloat32Tensor, ee as toTensor, ae as topK, re as zeroTensorData };
23
26
 
24
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/vision/index.ts"],"sourcesContent":["/**\n * `tempest-react-sdk/vision` — browser computer-vision inference with ONNX\n * Runtime Web (classification, detection, segmentation).\n *\n * Vendored from `@mauriciobenjamin700/ort-vision-sdk-web@0.5.1` (MIT, same\n * author) so it ships inside this SDK without an extra package install.\n * `onnxruntime-web` stays an optional peer dependency — install it (and ship\n * the matching `.wasm` files) only when you use this subpath.\n *\n * Do not hand-edit — regenerate with `npm run vendor:vision`.\n */\n\nexport {\n BoundingBox,\n Mask,\n RGBImage,\n type ClassProbability,\n type ClassificationResult,\n type DetectionResult,\n type SegmentationResult,\n} from \"./types\";\n\nexport {\n Boxes,\n ClassificationResults,\n DetectionResults,\n Masks,\n Probs,\n SegmentationResults,\n} from \"./results\";\n\nexport { COCO_CLASSES, type LabelSpec, type ResolveLabelsOptions, resolveLabels } from \"./labels\";\n\nexport {\n ImageLoadError,\n InferenceError,\n LabelMapError,\n ModelLoadError,\n OrtVisionError,\n ProviderNotAvailableError,\n} from \"./core/exceptions\";\n\nexport { type ModelSource, type OrtSessionOptions, OrtSession } from \"./core/session\";\nexport {\n type DeclaredDim,\n type DeclaredShape,\n type ResolveInputSizeOptions,\n classificationNumClasses,\n declaredShapesFrom,\n detectionNumClasses,\n resolveInputSize,\n spatialInputSize,\n} from \"./core/graph\";\nexport { modelNames, readModelMetadata } from \"./core/metadata\";\nexport { DEFAULT_PROVIDERS, resolveProviders } from \"./core/providers\";\nexport { type Speed, SpeedTimer } from \"./core/timing\";\n\nexport { type ImageInput, loadImage } from \"./io/image\";\n\nexport {\n type LetterboxResult,\n fromCv2,\n letterbox,\n normalize,\n resize,\n toCHW,\n toCv2,\n toFloat32,\n toFloat32Tensor,\n toTensor,\n} from \"./preprocess/image\";\n\nexport { type TopKResult, softmax, topK } from \"./postprocess/classification\";\n\nexport {\n type DecodeYoloAnchorsOptions,\n type DecodeYoloOptions,\n type DecodeYoloV8AnchorsOptions,\n type DecodeYoloV8Options,\n type DecodedAnchors,\n type DecodedDetection,\n batchedNms,\n decodeYolo,\n decodeYoloAnchors,\n decodeYoloV8,\n decodeYoloV8Anchors,\n nms,\n} from \"./postprocess/detection\";\n\nexport {\n type DecodeYoloSegOptions,\n type DecodeYoloV8SegOptions,\n type DecodedSegmentation,\n decodeYoloSeg,\n decodeYoloV8Seg,\n} from \"./postprocess/segmentation\";\n\nexport { VisionTask } from \"./tasks/base\";\nexport {\n type ClassifierOptions,\n type ClassifierPredictOptions,\n Classifier,\n} from \"./tasks/classifier\";\nexport {\n type DetectorHead,\n type DetectorOptions,\n type DetectorPredictOptions,\n Detector,\n} from \"./tasks/detector\";\nexport {\n type SegmenterHead,\n type SegmenterOptions,\n type SegmenterPredictOptions,\n Segmenter,\n} from \"./tasks/segmenter\";\n\nexport const VERSION: string = \"0.5.1\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoHA,IAAa,IAAkB"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/vision/index.ts"],"sourcesContent":["/**\n * `tempest-react-sdk/vision` — browser computer-vision inference with ONNX\n * Runtime Web (classification, detection, segmentation).\n *\n * Vendored from `@mauriciobenjamin700/ort-vision-sdk-web@0.6.1` (MIT, same\n * author) so it ships inside this SDK without an extra package install.\n * `onnxruntime-web` stays an optional peer dependency — install it (and ship\n * the matching `.wasm` files) only when you use this subpath.\n *\n * Do not hand-edit — regenerate with `npm run vendor:vision`.\n */\n\nexport {\n BoundingBox,\n Mask,\n RGBImage,\n type ClassProbability,\n type ClassificationResult,\n type DetectionResult,\n type SegmentationResult,\n} from \"./types\";\n\nexport {\n Boxes,\n ClassificationResults,\n DetectClassifyResults,\n DetectionResults,\n Masks,\n Probs,\n SegmentationResults,\n} from \"./results\";\n\nexport {\n COCO_CLASSES,\n type LabelSpec,\n type ResolveLabelsOptions,\n defaultLabels,\n resolveLabels,\n} from \"./labels\";\n\nexport {\n FusionError,\n ImageLoadError,\n InferenceError,\n LabelMapError,\n ModelLoadError,\n NoDetectionsError,\n OrtVisionError,\n ProviderNotAvailableError,\n} from \"./core/exceptions\";\n\nexport { type ModelSource, type OrtSessionOptions, OrtSession } from \"./core/session\";\nexport {\n type DeclaredDim,\n type DeclaredShape,\n type ResolveInputSizeOptions,\n classificationNumClasses,\n declaredShapesFrom,\n detectionNumClasses,\n resolveInputSize,\n spatialInputSize,\n} from \"./core/graph\";\nexport { modelNames, parseNames, readModelMetadata } from \"./core/metadata\";\nexport { DEFAULT_PROVIDERS, resolveProviders } from \"./core/providers\";\nexport { type Speed, SpeedTimer } from \"./core/timing\";\n\nexport { type ImageInput, loadImage } from \"./io/image\";\n\nexport {\n FUSION_KIND_DETECT_CLASSIFY,\n INPUT_IMAGE,\n INPUT_PAD,\n INPUT_SCALE,\n INPUT_SOURCE,\n METADATA_PREFIX,\n OUTPUT_BOXES,\n OUTPUT_CLASSES,\n OUTPUT_NUM_DETECTIONS,\n OUTPUT_PROBS,\n OUTPUT_SCORES,\n type CropSource,\n type FusionSpec,\n readFusionSpec,\n} from \"./fusion\";\n\nexport {\n type LetterboxResult,\n fromCv2,\n letterbox,\n normalize,\n resize,\n toCHW,\n toCv2,\n toFloat32,\n toFloat32Tensor,\n toTensor,\n} from \"./preprocess/image\";\n\nexport {\n type FusedLetterboxResult,\n LetterboxPipeline,\n letterboxToTensorData,\n zeroTensorData,\n} from \"./preprocess/pipeline\";\n\nexport { type TopKResult, softmax, topK } from \"./postprocess/classification\";\n\nexport {\n type DecodeYoloAnchorsOptions,\n type DecodeYoloOptions,\n type DecodedAnchors,\n type DecodedDetection,\n batchedNms,\n decodeYolo,\n decodeYoloAnchors,\n nms,\n} from \"./postprocess/detection\";\n\nexport {\n type DecodeYoloSegOptions,\n type DecodedSegmentation,\n decodeYoloSeg,\n} from \"./postprocess/segmentation\";\n\nexport { VisionTask, requireDetections } from \"./tasks/base\";\nexport {\n type ClassifierOptions,\n type ClassifierPredictOptions,\n Classifier,\n} from \"./tasks/classifier\";\nexport {\n type DetectClassifyOptions,\n type DetectClassifyPredictOptions,\n DetectClassify,\n} from \"./tasks/detectClassify\";\nexport {\n type DetectorHead,\n type DetectorOptions,\n type DetectorPredictOptions,\n Detector,\n} from \"./tasks/detector\";\nexport {\n type SegmenterHead,\n type SegmenterOptions,\n type SegmenterPredictOptions,\n Segmenter,\n} from \"./tasks/segmenter\";\n\nexport const VERSION: string = \"0.6.1\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoJA,IAAa,KAAkB"}
@@ -1 +1 @@
1
- {"version":3,"file":"image.cjs","names":[],"sources":["../../../src/vision/io/image.ts"],"sourcesContent":["/**\n * Image loading utilities — convert any supported source into the canonical\n * {@link RGBImage} format.\n *\n * Browser-only: uses `fetch`, `createImageBitmap`, and a Canvas 2D context to\n * decode arbitrary inputs into a tightly-packed `Uint8Array` of HWC RGB pixels.\n */\n\nimport { createCanvas, get2DContext, imageDataToRGB } from \"../core/canvas\";\nimport { ImageLoadError } from \"../core/exceptions\";\nimport { RGBImage } from \"../types\";\n\n/** Anything {@link loadImage} accepts as an image input. */\nexport type ImageInput =\n | string\n | Blob\n | HTMLImageElement\n | HTMLCanvasElement\n | OffscreenCanvas\n | ImageBitmap\n | ImageData\n | RGBImage;\n\n/**\n * Load an image from any supported source into a HWC uint8 RGB array.\n *\n * @throws {@link ImageLoadError} if the source cannot be decoded or has an unsupported shape.\n */\nexport async function loadImage(source: ImageInput): Promise<RGBImage> {\n if (source instanceof RGBImage) {\n return source;\n }\n\n if (typeof ImageData !== \"undefined\" && source instanceof ImageData) {\n return imageDataToRGB(source);\n }\n\n if (typeof source === \"string\") {\n return loadFromUrl(source);\n }\n\n if (typeof Blob !== \"undefined\" && source instanceof Blob) {\n return loadFromBlob(source);\n }\n\n if (typeof HTMLImageElement !== \"undefined\" && source instanceof HTMLImageElement) {\n await waitForImageElement(source);\n return drawableToRGB(source, source.naturalWidth, source.naturalHeight);\n }\n\n if (typeof HTMLCanvasElement !== \"undefined\" && source instanceof HTMLCanvasElement) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n if (typeof OffscreenCanvas !== \"undefined\" && source instanceof OffscreenCanvas) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n if (typeof ImageBitmap !== \"undefined\" && source instanceof ImageBitmap) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n throw new ImageLoadError(\n `Unsupported image source type: ${Object.prototype.toString.call(source)}`,\n );\n}\n\nasync function loadFromUrl(url: string): Promise<RGBImage> {\n let response: Response;\n try {\n response = await fetch(url);\n } catch (err) {\n throw new ImageLoadError(`Failed to fetch image from ${url}: ${(err as Error).message}`, {\n cause: err,\n });\n }\n if (!response.ok) {\n throw new ImageLoadError(\n `Failed to fetch image from ${url}: HTTP ${response.status} ${response.statusText}`,\n );\n }\n const blob = await response.blob();\n return loadFromBlob(blob);\n}\n\nasync function loadFromBlob(blob: Blob): Promise<RGBImage> {\n let bitmap: ImageBitmap;\n try {\n bitmap = await createImageBitmap(blob);\n } catch (err) {\n throw new ImageLoadError(`Failed to decode image blob: ${(err as Error).message}`, {\n cause: err,\n });\n }\n try {\n return drawableToRGB(bitmap, bitmap.width, bitmap.height);\n } finally {\n bitmap.close();\n }\n}\n\nfunction waitForImageElement(img: HTMLImageElement): Promise<void> {\n if (img.complete && img.naturalWidth > 0) {\n return Promise.resolve();\n }\n return new Promise<void>((resolve, reject) => {\n const onLoad = (): void => {\n cleanup();\n resolve();\n };\n const onError = (): void => {\n cleanup();\n reject(new ImageLoadError(\"Failed to load HTMLImageElement (load event errored)\"));\n };\n const cleanup = (): void => {\n img.removeEventListener(\"load\", onLoad);\n img.removeEventListener(\"error\", onError);\n };\n img.addEventListener(\"load\", onLoad, { once: true });\n img.addEventListener(\"error\", onError, { once: true });\n });\n}\n\nfunction drawableToRGB(drawable: CanvasImageSource, width: number, height: number): RGBImage {\n if (width === 0 || height === 0) {\n throw new ImageLoadError(`Cannot load image with zero dimension (${width}x${height}).`);\n }\n const canvas = createCanvas(width, height);\n const ctx = get2DContext(canvas);\n ctx.drawImage(drawable, 0, 0);\n const imageData = ctx.getImageData(0, 0, width, height);\n return imageDataToRGB(imageData);\n}\n"],"mappings":"oGA4BA,eAAsB,EAAU,EAAuC,CACnE,GAAI,aAAkB,EAAA,SAClB,OAAO,EAGX,GAAI,OAAO,UAAc,KAAe,aAAkB,UACtD,OAAO,EAAA,eAAe,CAAM,EAGhC,GAAI,OAAO,GAAW,SAClB,OAAO,EAAY,CAAM,EAG7B,GAAI,OAAO,KAAS,KAAe,aAAkB,KACjD,OAAO,EAAa,CAAM,EAG9B,GAAI,OAAO,iBAAqB,KAAe,aAAkB,iBAE7D,OADA,MAAM,EAAoB,CAAM,EACzB,EAAc,EAAQ,EAAO,aAAc,EAAO,aAAa,EAW1E,GARI,OAAO,kBAAsB,KAAe,aAAkB,mBAI9D,OAAO,gBAAoB,KAAe,aAAkB,iBAI5D,OAAO,YAAgB,KAAe,aAAkB,YACxD,OAAO,EAAc,EAAQ,EAAO,MAAO,EAAO,MAAM,EAG5D,MAAM,IAAI,EAAA,eACN,kCAAkC,OAAO,UAAU,SAAS,KAAK,CAAM,GAC3E,CACJ,CAEA,eAAe,EAAY,EAAgC,CACvD,IAAI,EACJ,GAAI,CACA,EAAW,MAAM,MAAM,CAAG,CAC9B,OAAS,EAAK,CACV,MAAM,IAAI,EAAA,eAAe,8BAA8B,EAAI,IAAK,EAAc,UAAW,CACrF,MAAO,CACX,CAAC,CACL,CACA,GAAI,CAAC,EAAS,GACV,MAAM,IAAI,EAAA,eACN,8BAA8B,EAAI,SAAS,EAAS,OAAO,GAAG,EAAS,YAC3E,EAGJ,OAAO,EAAa,MADD,EAAS,KAAK,CACT,CAC5B,CAEA,eAAe,EAAa,EAA+B,CACvD,IAAI,EACJ,GAAI,CACA,EAAS,MAAM,kBAAkB,CAAI,CACzC,OAAS,EAAK,CACV,MAAM,IAAI,EAAA,eAAe,gCAAiC,EAAc,UAAW,CAC/E,MAAO,CACX,CAAC,CACL,CACA,GAAI,CACA,OAAO,EAAc,EAAQ,EAAO,MAAO,EAAO,MAAM,CAC5D,QAAU,CACN,EAAO,MAAM,CACjB,CACJ,CAEA,SAAS,EAAoB,EAAsC,CAI/D,OAHI,EAAI,UAAY,EAAI,aAAe,EAC5B,QAAQ,QAAQ,EAEpB,IAAI,SAAe,EAAS,IAAW,CAC1C,IAAM,MAAqB,CACvB,EAAQ,EACR,EAAQ,CACZ,EACM,MAAsB,CACxB,EAAQ,EACR,EAAO,IAAI,EAAA,eAAe,sDAAsD,CAAC,CACrF,EACM,MAAsB,CACxB,EAAI,oBAAoB,OAAQ,CAAM,EACtC,EAAI,oBAAoB,QAAS,CAAO,CAC5C,EACA,EAAI,iBAAiB,OAAQ,EAAQ,CAAE,KAAM,EAAK,CAAC,EACnD,EAAI,iBAAiB,QAAS,EAAS,CAAE,KAAM,EAAK,CAAC,CACzD,CAAC,CACL,CAEA,SAAS,EAAc,EAA6B,EAAe,EAA0B,CACzF,GAAI,IAAU,GAAK,IAAW,EAC1B,MAAM,IAAI,EAAA,eAAe,0CAA0C,EAAM,GAAG,EAAO,GAAG,EAG1F,IAAM,EAAM,EAAA,aADG,EAAA,aAAa,EAAO,CACV,CAAM,EAG/B,OAFA,EAAI,UAAU,EAAU,EAAG,CAAC,EAErB,EAAA,eADW,EAAI,aAAa,EAAG,EAAG,EAAO,CAC1B,CAAS,CACnC"}
1
+ {"version":3,"file":"image.cjs","names":[],"sources":["../../../src/vision/io/image.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Image loading utilities — convert any supported source into the canonical\n * {@link RGBImage} format.\n *\n * Browser-only: uses `fetch`, `createImageBitmap`, and a Canvas 2D context to\n * decode arbitrary inputs into a tightly-packed `Uint8Array` of HWC RGB pixels.\n */\n\nimport { createCanvas, get2DContext, imageDataToRGB } from \"../core/canvas\";\nimport { ImageLoadError } from \"../core/exceptions\";\nimport { RGBImage } from \"../types\";\n\n/** Anything {@link loadImage} accepts as an image input. */\nexport type ImageInput =\n | string\n | Blob\n | HTMLImageElement\n | HTMLCanvasElement\n | OffscreenCanvas\n | ImageBitmap\n | ImageData\n | RGBImage;\n\n/**\n * Load an image from any supported source into a HWC uint8 RGB array.\n *\n * @throws {@link ImageLoadError} if the source cannot be decoded or has an unsupported shape.\n */\nexport async function loadImage(source: ImageInput): Promise<RGBImage> {\n if (source instanceof RGBImage) {\n return source;\n }\n\n if (typeof ImageData !== \"undefined\" && source instanceof ImageData) {\n return imageDataToRGB(source);\n }\n\n if (typeof source === \"string\") {\n return loadFromUrl(source);\n }\n\n if (typeof Blob !== \"undefined\" && source instanceof Blob) {\n return loadFromBlob(source);\n }\n\n if (typeof HTMLImageElement !== \"undefined\" && source instanceof HTMLImageElement) {\n await waitForImageElement(source);\n return drawableToRGB(source, source.naturalWidth, source.naturalHeight);\n }\n\n if (typeof HTMLCanvasElement !== \"undefined\" && source instanceof HTMLCanvasElement) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n if (typeof OffscreenCanvas !== \"undefined\" && source instanceof OffscreenCanvas) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n if (typeof ImageBitmap !== \"undefined\" && source instanceof ImageBitmap) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n throw new ImageLoadError(\n `Unsupported image source type: ${Object.prototype.toString.call(source)}`,\n );\n}\n\nasync function loadFromUrl(url: string): Promise<RGBImage> {\n let response: Response;\n try {\n response = await fetch(url);\n } catch (err) {\n throw new ImageLoadError(`Failed to fetch image from ${url}: ${(err as Error).message}`, {\n cause: err,\n });\n }\n if (!response.ok) {\n throw new ImageLoadError(\n `Failed to fetch image from ${url}: HTTP ${response.status} ${response.statusText}`,\n );\n }\n const blob = await response.blob();\n return loadFromBlob(blob);\n}\n\nasync function loadFromBlob(blob: Blob): Promise<RGBImage> {\n let bitmap: ImageBitmap;\n try {\n bitmap = await createImageBitmap(blob);\n } catch (err) {\n throw new ImageLoadError(`Failed to decode image blob: ${(err as Error).message}`, {\n cause: err,\n });\n }\n try {\n return drawableToRGB(bitmap, bitmap.width, bitmap.height);\n } finally {\n bitmap.close();\n }\n}\n\nfunction waitForImageElement(img: HTMLImageElement): Promise<void> {\n if (img.complete && img.naturalWidth > 0) {\n return Promise.resolve();\n }\n return new Promise<void>((resolve, reject) => {\n const onLoad = (): void => {\n cleanup();\n resolve();\n };\n const onError = (): void => {\n cleanup();\n reject(new ImageLoadError(\"Failed to load HTMLImageElement (load event errored)\"));\n };\n const cleanup = (): void => {\n img.removeEventListener(\"load\", onLoad);\n img.removeEventListener(\"error\", onError);\n };\n img.addEventListener(\"load\", onLoad, { once: true });\n img.addEventListener(\"error\", onError, { once: true });\n });\n}\n\nfunction drawableToRGB(drawable: CanvasImageSource, width: number, height: number): RGBImage {\n if (width === 0 || height === 0) {\n throw new ImageLoadError(`Cannot load image with zero dimension (${width}x${height}).`);\n }\n const canvas = createCanvas(width, height);\n const ctx = get2DContext(canvas);\n ctx.drawImage(drawable, 0, 0);\n const imageData = ctx.getImageData(0, 0, width, height);\n return imageDataToRGB(imageData);\n}\n"],"mappings":"oGA6BA,eAAsB,EAAU,EAAuC,CACnE,GAAI,aAAkB,EAAA,SAClB,OAAO,EAGX,GAAI,OAAO,UAAc,KAAe,aAAkB,UACtD,OAAO,EAAA,eAAe,CAAM,EAGhC,GAAI,OAAO,GAAW,SAClB,OAAO,EAAY,CAAM,EAG7B,GAAI,OAAO,KAAS,KAAe,aAAkB,KACjD,OAAO,EAAa,CAAM,EAG9B,GAAI,OAAO,iBAAqB,KAAe,aAAkB,iBAE7D,OADA,MAAM,EAAoB,CAAM,EACzB,EAAc,EAAQ,EAAO,aAAc,EAAO,aAAa,EAW1E,GARI,OAAO,kBAAsB,KAAe,aAAkB,mBAI9D,OAAO,gBAAoB,KAAe,aAAkB,iBAI5D,OAAO,YAAgB,KAAe,aAAkB,YACxD,OAAO,EAAc,EAAQ,EAAO,MAAO,EAAO,MAAM,EAG5D,MAAM,IAAI,EAAA,eACN,kCAAkC,OAAO,UAAU,SAAS,KAAK,CAAM,GAC3E,CACJ,CAEA,eAAe,EAAY,EAAgC,CACvD,IAAI,EACJ,GAAI,CACA,EAAW,MAAM,MAAM,CAAG,CAC9B,OAAS,EAAK,CACV,MAAM,IAAI,EAAA,eAAe,8BAA8B,EAAI,IAAK,EAAc,UAAW,CACrF,MAAO,CACX,CAAC,CACL,CACA,GAAI,CAAC,EAAS,GACV,MAAM,IAAI,EAAA,eACN,8BAA8B,EAAI,SAAS,EAAS,OAAO,GAAG,EAAS,YAC3E,EAGJ,OAAO,EAAa,MADD,EAAS,KAAK,CACT,CAC5B,CAEA,eAAe,EAAa,EAA+B,CACvD,IAAI,EACJ,GAAI,CACA,EAAS,MAAM,kBAAkB,CAAI,CACzC,OAAS,EAAK,CACV,MAAM,IAAI,EAAA,eAAe,gCAAiC,EAAc,UAAW,CAC/E,MAAO,CACX,CAAC,CACL,CACA,GAAI,CACA,OAAO,EAAc,EAAQ,EAAO,MAAO,EAAO,MAAM,CAC5D,QAAU,CACN,EAAO,MAAM,CACjB,CACJ,CAEA,SAAS,EAAoB,EAAsC,CAI/D,OAHI,EAAI,UAAY,EAAI,aAAe,EAC5B,QAAQ,QAAQ,EAEpB,IAAI,SAAe,EAAS,IAAW,CAC1C,IAAM,MAAqB,CACvB,EAAQ,EACR,EAAQ,CACZ,EACM,MAAsB,CACxB,EAAQ,EACR,EAAO,IAAI,EAAA,eAAe,sDAAsD,CAAC,CACrF,EACM,MAAsB,CACxB,EAAI,oBAAoB,OAAQ,CAAM,EACtC,EAAI,oBAAoB,QAAS,CAAO,CAC5C,EACA,EAAI,iBAAiB,OAAQ,EAAQ,CAAE,KAAM,EAAK,CAAC,EACnD,EAAI,iBAAiB,QAAS,EAAS,CAAE,KAAM,EAAK,CAAC,CACzD,CAAC,CACL,CAEA,SAAS,EAAc,EAA6B,EAAe,EAA0B,CACzF,GAAI,IAAU,GAAK,IAAW,EAC1B,MAAM,IAAI,EAAA,eAAe,0CAA0C,EAAM,GAAG,EAAO,GAAG,EAG1F,IAAM,EAAM,EAAA,aADG,EAAA,aAAa,EAAO,CACV,CAAM,EAG/B,OAFA,EAAI,UAAU,EAAU,EAAG,CAAC,EAErB,EAAA,eADW,EAAI,aAAa,EAAG,EAAG,EAAO,CAC1B,CAAS,CACnC"}
@@ -1 +1 @@
1
- {"version":3,"file":"image.js","names":[],"sources":["../../../src/vision/io/image.ts"],"sourcesContent":["/**\n * Image loading utilities — convert any supported source into the canonical\n * {@link RGBImage} format.\n *\n * Browser-only: uses `fetch`, `createImageBitmap`, and a Canvas 2D context to\n * decode arbitrary inputs into a tightly-packed `Uint8Array` of HWC RGB pixels.\n */\n\nimport { createCanvas, get2DContext, imageDataToRGB } from \"../core/canvas\";\nimport { ImageLoadError } from \"../core/exceptions\";\nimport { RGBImage } from \"../types\";\n\n/** Anything {@link loadImage} accepts as an image input. */\nexport type ImageInput =\n | string\n | Blob\n | HTMLImageElement\n | HTMLCanvasElement\n | OffscreenCanvas\n | ImageBitmap\n | ImageData\n | RGBImage;\n\n/**\n * Load an image from any supported source into a HWC uint8 RGB array.\n *\n * @throws {@link ImageLoadError} if the source cannot be decoded or has an unsupported shape.\n */\nexport async function loadImage(source: ImageInput): Promise<RGBImage> {\n if (source instanceof RGBImage) {\n return source;\n }\n\n if (typeof ImageData !== \"undefined\" && source instanceof ImageData) {\n return imageDataToRGB(source);\n }\n\n if (typeof source === \"string\") {\n return loadFromUrl(source);\n }\n\n if (typeof Blob !== \"undefined\" && source instanceof Blob) {\n return loadFromBlob(source);\n }\n\n if (typeof HTMLImageElement !== \"undefined\" && source instanceof HTMLImageElement) {\n await waitForImageElement(source);\n return drawableToRGB(source, source.naturalWidth, source.naturalHeight);\n }\n\n if (typeof HTMLCanvasElement !== \"undefined\" && source instanceof HTMLCanvasElement) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n if (typeof OffscreenCanvas !== \"undefined\" && source instanceof OffscreenCanvas) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n if (typeof ImageBitmap !== \"undefined\" && source instanceof ImageBitmap) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n throw new ImageLoadError(\n `Unsupported image source type: ${Object.prototype.toString.call(source)}`,\n );\n}\n\nasync function loadFromUrl(url: string): Promise<RGBImage> {\n let response: Response;\n try {\n response = await fetch(url);\n } catch (err) {\n throw new ImageLoadError(`Failed to fetch image from ${url}: ${(err as Error).message}`, {\n cause: err,\n });\n }\n if (!response.ok) {\n throw new ImageLoadError(\n `Failed to fetch image from ${url}: HTTP ${response.status} ${response.statusText}`,\n );\n }\n const blob = await response.blob();\n return loadFromBlob(blob);\n}\n\nasync function loadFromBlob(blob: Blob): Promise<RGBImage> {\n let bitmap: ImageBitmap;\n try {\n bitmap = await createImageBitmap(blob);\n } catch (err) {\n throw new ImageLoadError(`Failed to decode image blob: ${(err as Error).message}`, {\n cause: err,\n });\n }\n try {\n return drawableToRGB(bitmap, bitmap.width, bitmap.height);\n } finally {\n bitmap.close();\n }\n}\n\nfunction waitForImageElement(img: HTMLImageElement): Promise<void> {\n if (img.complete && img.naturalWidth > 0) {\n return Promise.resolve();\n }\n return new Promise<void>((resolve, reject) => {\n const onLoad = (): void => {\n cleanup();\n resolve();\n };\n const onError = (): void => {\n cleanup();\n reject(new ImageLoadError(\"Failed to load HTMLImageElement (load event errored)\"));\n };\n const cleanup = (): void => {\n img.removeEventListener(\"load\", onLoad);\n img.removeEventListener(\"error\", onError);\n };\n img.addEventListener(\"load\", onLoad, { once: true });\n img.addEventListener(\"error\", onError, { once: true });\n });\n}\n\nfunction drawableToRGB(drawable: CanvasImageSource, width: number, height: number): RGBImage {\n if (width === 0 || height === 0) {\n throw new ImageLoadError(`Cannot load image with zero dimension (${width}x${height}).`);\n }\n const canvas = createCanvas(width, height);\n const ctx = get2DContext(canvas);\n ctx.drawImage(drawable, 0, 0);\n const imageData = ctx.getImageData(0, 0, width, height);\n return imageDataToRGB(imageData);\n}\n"],"mappings":";;;;AA4BA,eAAsB,EAAU,GAAuC;CACnE,IAAI,aAAkB,GAClB,OAAO;CAGX,IAAI,OAAO,YAAc,OAAe,aAAkB,WACtD,OAAO,EAAe,CAAM;CAGhC,IAAI,OAAO,KAAW,UAClB,OAAO,EAAY,CAAM;CAG7B,IAAI,OAAO,OAAS,OAAe,aAAkB,MACjD,OAAO,EAAa,CAAM;CAG9B,IAAI,OAAO,mBAAqB,OAAe,aAAkB,kBAE7D,OADA,MAAM,EAAoB,CAAM,GACzB,EAAc,GAAQ,EAAO,cAAc,EAAO,aAAa;CAW1E,IARI,OAAO,oBAAsB,OAAe,aAAkB,qBAI9D,OAAO,kBAAoB,OAAe,aAAkB,mBAI5D,OAAO,cAAgB,OAAe,aAAkB,aACxD,OAAO,EAAc,GAAQ,EAAO,OAAO,EAAO,MAAM;CAG5D,MAAM,IAAI,EACN,kCAAkC,OAAO,UAAU,SAAS,KAAK,CAAM,GAC3E;AACJ;AAEA,eAAe,EAAY,GAAgC;CACvD,IAAI;CACJ,IAAI;EACA,IAAW,MAAM,MAAM,CAAG;CAC9B,SAAS,GAAK;EACV,MAAM,IAAI,EAAe,8BAA8B,EAAI,IAAK,EAAc,WAAW,EACrF,OAAO,EACX,CAAC;CACL;CACA,IAAI,CAAC,EAAS,IACV,MAAM,IAAI,EACN,8BAA8B,EAAI,SAAS,EAAS,OAAO,GAAG,EAAS,YAC3E;CAGJ,OAAO,EAAa,MADD,EAAS,KAAK,CACT;AAC5B;AAEA,eAAe,EAAa,GAA+B;CACvD,IAAI;CACJ,IAAI;EACA,IAAS,MAAM,kBAAkB,CAAI;CACzC,SAAS,GAAK;EACV,MAAM,IAAI,EAAe,gCAAiC,EAAc,WAAW,EAC/E,OAAO,EACX,CAAC;CACL;CACA,IAAI;EACA,OAAO,EAAc,GAAQ,EAAO,OAAO,EAAO,MAAM;CAC5D,UAAU;EACN,EAAO,MAAM;CACjB;AACJ;AAEA,SAAS,EAAoB,GAAsC;CAI/D,OAHI,EAAI,YAAY,EAAI,eAAe,IAC5B,QAAQ,QAAQ,IAEpB,IAAI,SAAe,GAAS,MAAW;EAC1C,IAAM,UAAqB;GAEvB,AADA,EAAQ,GACR,EAAQ;EACZ,GACM,UAAsB;GAExB,AADA,EAAQ,GACR,EAAO,IAAI,EAAe,sDAAsD,CAAC;EACrF,GACM,UAAsB;GAExB,AADA,EAAI,oBAAoB,QAAQ,CAAM,GACtC,EAAI,oBAAoB,SAAS,CAAO;EAC5C;EAEA,AADA,EAAI,iBAAiB,QAAQ,GAAQ,EAAE,MAAM,GAAK,CAAC,GACnD,EAAI,iBAAiB,SAAS,GAAS,EAAE,MAAM,GAAK,CAAC;CACzD,CAAC;AACL;AAEA,SAAS,EAAc,GAA6B,GAAe,GAA0B;CACzF,IAAI,MAAU,KAAK,MAAW,GAC1B,MAAM,IAAI,EAAe,0CAA0C,EAAM,GAAG,EAAO,GAAG;CAG1F,IAAM,IAAM,EADG,EAAa,GAAO,CACV,CAAM;CAG/B,OAFA,EAAI,UAAU,GAAU,GAAG,CAAC,GAErB,EADW,EAAI,aAAa,GAAG,GAAG,GAAO,CAC1B,CAAS;AACnC"}
1
+ {"version":3,"file":"image.js","names":[],"sources":["../../../src/vision/io/image.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Image loading utilities — convert any supported source into the canonical\n * {@link RGBImage} format.\n *\n * Browser-only: uses `fetch`, `createImageBitmap`, and a Canvas 2D context to\n * decode arbitrary inputs into a tightly-packed `Uint8Array` of HWC RGB pixels.\n */\n\nimport { createCanvas, get2DContext, imageDataToRGB } from \"../core/canvas\";\nimport { ImageLoadError } from \"../core/exceptions\";\nimport { RGBImage } from \"../types\";\n\n/** Anything {@link loadImage} accepts as an image input. */\nexport type ImageInput =\n | string\n | Blob\n | HTMLImageElement\n | HTMLCanvasElement\n | OffscreenCanvas\n | ImageBitmap\n | ImageData\n | RGBImage;\n\n/**\n * Load an image from any supported source into a HWC uint8 RGB array.\n *\n * @throws {@link ImageLoadError} if the source cannot be decoded or has an unsupported shape.\n */\nexport async function loadImage(source: ImageInput): Promise<RGBImage> {\n if (source instanceof RGBImage) {\n return source;\n }\n\n if (typeof ImageData !== \"undefined\" && source instanceof ImageData) {\n return imageDataToRGB(source);\n }\n\n if (typeof source === \"string\") {\n return loadFromUrl(source);\n }\n\n if (typeof Blob !== \"undefined\" && source instanceof Blob) {\n return loadFromBlob(source);\n }\n\n if (typeof HTMLImageElement !== \"undefined\" && source instanceof HTMLImageElement) {\n await waitForImageElement(source);\n return drawableToRGB(source, source.naturalWidth, source.naturalHeight);\n }\n\n if (typeof HTMLCanvasElement !== \"undefined\" && source instanceof HTMLCanvasElement) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n if (typeof OffscreenCanvas !== \"undefined\" && source instanceof OffscreenCanvas) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n if (typeof ImageBitmap !== \"undefined\" && source instanceof ImageBitmap) {\n return drawableToRGB(source, source.width, source.height);\n }\n\n throw new ImageLoadError(\n `Unsupported image source type: ${Object.prototype.toString.call(source)}`,\n );\n}\n\nasync function loadFromUrl(url: string): Promise<RGBImage> {\n let response: Response;\n try {\n response = await fetch(url);\n } catch (err) {\n throw new ImageLoadError(`Failed to fetch image from ${url}: ${(err as Error).message}`, {\n cause: err,\n });\n }\n if (!response.ok) {\n throw new ImageLoadError(\n `Failed to fetch image from ${url}: HTTP ${response.status} ${response.statusText}`,\n );\n }\n const blob = await response.blob();\n return loadFromBlob(blob);\n}\n\nasync function loadFromBlob(blob: Blob): Promise<RGBImage> {\n let bitmap: ImageBitmap;\n try {\n bitmap = await createImageBitmap(blob);\n } catch (err) {\n throw new ImageLoadError(`Failed to decode image blob: ${(err as Error).message}`, {\n cause: err,\n });\n }\n try {\n return drawableToRGB(bitmap, bitmap.width, bitmap.height);\n } finally {\n bitmap.close();\n }\n}\n\nfunction waitForImageElement(img: HTMLImageElement): Promise<void> {\n if (img.complete && img.naturalWidth > 0) {\n return Promise.resolve();\n }\n return new Promise<void>((resolve, reject) => {\n const onLoad = (): void => {\n cleanup();\n resolve();\n };\n const onError = (): void => {\n cleanup();\n reject(new ImageLoadError(\"Failed to load HTMLImageElement (load event errored)\"));\n };\n const cleanup = (): void => {\n img.removeEventListener(\"load\", onLoad);\n img.removeEventListener(\"error\", onError);\n };\n img.addEventListener(\"load\", onLoad, { once: true });\n img.addEventListener(\"error\", onError, { once: true });\n });\n}\n\nfunction drawableToRGB(drawable: CanvasImageSource, width: number, height: number): RGBImage {\n if (width === 0 || height === 0) {\n throw new ImageLoadError(`Cannot load image with zero dimension (${width}x${height}).`);\n }\n const canvas = createCanvas(width, height);\n const ctx = get2DContext(canvas);\n ctx.drawImage(drawable, 0, 0);\n const imageData = ctx.getImageData(0, 0, width, height);\n return imageDataToRGB(imageData);\n}\n"],"mappings":";;;;AA6BA,eAAsB,EAAU,GAAuC;CACnE,IAAI,aAAkB,GAClB,OAAO;CAGX,IAAI,OAAO,YAAc,OAAe,aAAkB,WACtD,OAAO,EAAe,CAAM;CAGhC,IAAI,OAAO,KAAW,UAClB,OAAO,EAAY,CAAM;CAG7B,IAAI,OAAO,OAAS,OAAe,aAAkB,MACjD,OAAO,EAAa,CAAM;CAG9B,IAAI,OAAO,mBAAqB,OAAe,aAAkB,kBAE7D,OADA,MAAM,EAAoB,CAAM,GACzB,EAAc,GAAQ,EAAO,cAAc,EAAO,aAAa;CAW1E,IARI,OAAO,oBAAsB,OAAe,aAAkB,qBAI9D,OAAO,kBAAoB,OAAe,aAAkB,mBAI5D,OAAO,cAAgB,OAAe,aAAkB,aACxD,OAAO,EAAc,GAAQ,EAAO,OAAO,EAAO,MAAM;CAG5D,MAAM,IAAI,EACN,kCAAkC,OAAO,UAAU,SAAS,KAAK,CAAM,GAC3E;AACJ;AAEA,eAAe,EAAY,GAAgC;CACvD,IAAI;CACJ,IAAI;EACA,IAAW,MAAM,MAAM,CAAG;CAC9B,SAAS,GAAK;EACV,MAAM,IAAI,EAAe,8BAA8B,EAAI,IAAK,EAAc,WAAW,EACrF,OAAO,EACX,CAAC;CACL;CACA,IAAI,CAAC,EAAS,IACV,MAAM,IAAI,EACN,8BAA8B,EAAI,SAAS,EAAS,OAAO,GAAG,EAAS,YAC3E;CAGJ,OAAO,EAAa,MADD,EAAS,KAAK,CACT;AAC5B;AAEA,eAAe,EAAa,GAA+B;CACvD,IAAI;CACJ,IAAI;EACA,IAAS,MAAM,kBAAkB,CAAI;CACzC,SAAS,GAAK;EACV,MAAM,IAAI,EAAe,gCAAiC,EAAc,WAAW,EAC/E,OAAO,EACX,CAAC;CACL;CACA,IAAI;EACA,OAAO,EAAc,GAAQ,EAAO,OAAO,EAAO,MAAM;CAC5D,UAAU;EACN,EAAO,MAAM;CACjB;AACJ;AAEA,SAAS,EAAoB,GAAsC;CAI/D,OAHI,EAAI,YAAY,EAAI,eAAe,IAC5B,QAAQ,QAAQ,IAEpB,IAAI,SAAe,GAAS,MAAW;EAC1C,IAAM,UAAqB;GAEvB,AADA,EAAQ,GACR,EAAQ;EACZ,GACM,UAAsB;GAExB,AADA,EAAQ,GACR,EAAO,IAAI,EAAe,sDAAsD,CAAC;EACrF,GACM,UAAsB;GAExB,AADA,EAAI,oBAAoB,QAAQ,CAAM,GACtC,EAAI,oBAAoB,SAAS,CAAO;EAC5C;EAEA,AADA,EAAI,iBAAiB,QAAQ,GAAQ,EAAE,MAAM,GAAK,CAAC,GACnD,EAAI,iBAAiB,SAAS,GAAS,EAAE,MAAM,GAAK,CAAC;CACzD,CAAC;AACL;AAEA,SAAS,EAAc,GAA6B,GAAe,GAA0B;CACzF,IAAI,MAAU,KAAK,MAAW,GAC1B,MAAM,IAAI,EAAe,0CAA0C,EAAM,GAAG,EAAO,GAAG;CAG1F,IAAM,IAAM,EADG,EAAa,GAAO,CACV,CAAM;CAG/B,OAFA,EAAI,UAAU,GAAU,GAAG,CAAC,GAErB,EADW,EAAI,aAAa,GAAG,GAAG,GAAO,CAC1B,CAAS;AACnC"}
@@ -1,2 +1,2 @@
1
- const e=require("./core/exceptions.cjs");var t=Object.freeze(`person.bicycle.car.motorcycle.airplane.bus.train.truck.boat.traffic light.fire hydrant.stop sign.parking meter.bench.bird.cat.dog.horse.sheep.cow.elephant.bear.zebra.giraffe.backpack.umbrella.handbag.tie.suitcase.frisbee.skis.snowboard.sports ball.kite.baseball bat.baseball glove.skateboard.surfboard.tennis racket.bottle.wine glass.cup.fork.knife.spoon.bowl.banana.apple.sandwich.orange.broccoli.carrot.hot dog.pizza.donut.cake.chair.couch.potted plant.bed.dining table.toilet.tv.laptop.mouse.remote.keyboard.cell phone.microwave.oven.toaster.sink.refrigerator.book.clock.vase.scissors.teddy bear.hair drier.toothbrush`.split(`.`)),n={coco:t};function r(t,n={}){let r=i(t,n.numClasses);if(n.numClasses!==void 0&&r.length!==n.numClasses)throw new e.LabelMapError(`Resolved ${r.length} labels but the model has ${n.numClasses} classes.`);return r}function i(t,r){if(t==null){if(r===void 0)throw new e.LabelMapError(`Cannot auto-generate labels without numClasses. Pass an explicit labels spec or numClasses.`);return Array.from({length:r},(e,t)=>`class_${t}`)}if(Array.isArray(t))return[...t];if(typeof t==`string`){let r=n[t];if(r!==void 0)return r;throw new e.LabelMapError(`Unknown labels preset: ${JSON.stringify(t)}. Known presets: ${Object.keys(n).join(`, `)}.`)}if(typeof t==`object`){let e=t,n=Object.keys(e).map(e=>Number(e));if(n.length===0)return[];let r=Math.max(...n);return Array.from({length:r+1},(t,n)=>e[n]??`class_${n}`)}throw new e.LabelMapError(`Unsupported labels spec type: ${typeof t}.`)}exports.COCO_CLASSES=t,exports.resolveLabels=r;
1
+ const e=require("./core/exceptions.cjs");var t=Object.freeze(`person.bicycle.car.motorcycle.airplane.bus.train.truck.boat.traffic light.fire hydrant.stop sign.parking meter.bench.bird.cat.dog.horse.sheep.cow.elephant.bear.zebra.giraffe.backpack.umbrella.handbag.tie.suitcase.frisbee.skis.snowboard.sports ball.kite.baseball bat.baseball glove.skateboard.surfboard.tennis racket.bottle.wine glass.cup.fork.knife.spoon.bowl.banana.apple.sandwich.orange.broccoli.carrot.hot dog.pizza.donut.cake.chair.couch.potted plant.bed.dining table.toilet.tv.laptop.mouse.remote.keyboard.cell phone.microwave.oven.toaster.sink.refrigerator.book.clock.vase.scissors.teddy bear.hair drier.toothbrush`.split(`.`)),n={coco:t};function r(e){return e===void 0||e===t.length?`coco`:null}function i(t,n={}){let r=a(t,n.numClasses);if(n.numClasses!==void 0&&r.length!==n.numClasses)throw new e.LabelMapError(`Resolved ${r.length} labels but the model has ${n.numClasses} classes.`);return r}function a(t,r){if(t==null){if(r===void 0)throw new e.LabelMapError(`Cannot auto-generate labels without numClasses. Pass an explicit labels spec or numClasses.`);return Array.from({length:r},(e,t)=>`class_${t}`)}if(Array.isArray(t))return[...t];if(typeof t==`string`){let r=n[t];if(r!==void 0)return r;throw new e.LabelMapError(`Unknown labels preset: ${JSON.stringify(t)}. Known presets: ${Object.keys(n).join(`, `)}.`)}if(typeof t==`object`){let e=t,n=Object.keys(e).map(e=>Number(e));if(n.length===0)return[];let r=Math.max(...n);return Array.from({length:r+1},(t,n)=>e[n]??`class_${n}`)}throw new e.LabelMapError(`Unsupported labels spec type: ${typeof t}.`)}exports.COCO_CLASSES=t,exports.defaultLabels=r,exports.resolveLabels=i;
2
2
  //# sourceMappingURL=labels.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"labels.cjs","names":[],"sources":["../../src/vision/labels.ts"],"sourcesContent":["/**\n * Class label resolution: presets, lists, dicts, or auto-generated.\n *\n * Tasks call {@link resolveLabels} once at construction time to turn whatever\n * the caller passed (preset name, array, dict, or `null`) into an ordered\n * array of class names indexed by class id.\n *\n * In the browser there is no filesystem, so this module does not load labels\n * from a path — fetch the file yourself and pass an array.\n */\n\nimport { LabelMapError } from \"./core/exceptions\";\n\n/**\n * Anything accepted by {@link resolveLabels}.\n *\n * - `string[]` / `readonly string[]`: explicit names indexed by class id.\n * - `Record<number, string>`: sparse mapping (gaps filled with `class_<id>`).\n * - `string`: a preset name (e.g. `\"coco\"`).\n * - `null` / `undefined`: auto-generate `class_0` ... `class_{numClasses-1}`.\n */\nexport type LabelSpec = readonly string[] | Record<number, string> | string | null | undefined;\n\n/** COCO 2017 80-class labels in canonical class-id order. */\nexport const COCO_CLASSES: readonly string[] = Object.freeze([\n \"person\",\n \"bicycle\",\n \"car\",\n \"motorcycle\",\n \"airplane\",\n \"bus\",\n \"train\",\n \"truck\",\n \"boat\",\n \"traffic light\",\n \"fire hydrant\",\n \"stop sign\",\n \"parking meter\",\n \"bench\",\n \"bird\",\n \"cat\",\n \"dog\",\n \"horse\",\n \"sheep\",\n \"cow\",\n \"elephant\",\n \"bear\",\n \"zebra\",\n \"giraffe\",\n \"backpack\",\n \"umbrella\",\n \"handbag\",\n \"tie\",\n \"suitcase\",\n \"frisbee\",\n \"skis\",\n \"snowboard\",\n \"sports ball\",\n \"kite\",\n \"baseball bat\",\n \"baseball glove\",\n \"skateboard\",\n \"surfboard\",\n \"tennis racket\",\n \"bottle\",\n \"wine glass\",\n \"cup\",\n \"fork\",\n \"knife\",\n \"spoon\",\n \"bowl\",\n \"banana\",\n \"apple\",\n \"sandwich\",\n \"orange\",\n \"broccoli\",\n \"carrot\",\n \"hot dog\",\n \"pizza\",\n \"donut\",\n \"cake\",\n \"chair\",\n \"couch\",\n \"potted plant\",\n \"bed\",\n \"dining table\",\n \"toilet\",\n \"tv\",\n \"laptop\",\n \"mouse\",\n \"remote\",\n \"keyboard\",\n \"cell phone\",\n \"microwave\",\n \"oven\",\n \"toaster\",\n \"sink\",\n \"refrigerator\",\n \"book\",\n \"clock\",\n \"vase\",\n \"scissors\",\n \"teddy bear\",\n \"hair drier\",\n \"toothbrush\",\n]);\n\nconst PRESETS: Readonly<Record<string, readonly string[]>> = {\n coco: COCO_CLASSES,\n};\n\nexport interface ResolveLabelsOptions {\n /**\n * Expected number of classes.\n *\n * - When `spec` is `null`/`undefined`, this is required to auto-generate names.\n * - When `spec` is provided, it validates that the resolved length matches.\n */\n readonly numClasses?: number;\n}\n\n/**\n * Resolve a labels specification into an ordered array of class names.\n *\n * @throws {@link LabelMapError} if the spec is invalid, the preset is unknown,\n * or the resolved length disagrees with `numClasses`.\n */\nexport function resolveLabels(\n spec: LabelSpec,\n options: ResolveLabelsOptions = {},\n): readonly string[] {\n const labels = resolve(spec, options.numClasses);\n if (options.numClasses !== undefined && labels.length !== options.numClasses) {\n throw new LabelMapError(\n `Resolved ${labels.length} labels but the model has ${options.numClasses} classes.`,\n );\n }\n return labels;\n}\n\nfunction resolve(spec: LabelSpec, numClasses: number | undefined): readonly string[] {\n if (spec === null || spec === undefined) {\n if (numClasses === undefined) {\n throw new LabelMapError(\n \"Cannot auto-generate labels without numClasses. Pass an explicit labels spec or numClasses.\",\n );\n }\n return Array.from({ length: numClasses }, (_, i) => `class_${i}`);\n }\n\n if (Array.isArray(spec)) {\n return [...spec];\n }\n\n if (typeof spec === \"string\") {\n const preset = PRESETS[spec];\n if (preset !== undefined) {\n return preset;\n }\n throw new LabelMapError(\n `Unknown labels preset: ${JSON.stringify(spec)}. Known presets: ${Object.keys(PRESETS).join(\", \")}.`,\n );\n }\n\n if (typeof spec === \"object\") {\n const map = spec as Record<number, string>;\n const ids = Object.keys(map).map((k) => Number(k));\n if (ids.length === 0) {\n return [];\n }\n const maxId = Math.max(...ids);\n return Array.from({ length: maxId + 1 }, (_, i) => map[i] ?? `class_${i}`);\n }\n\n throw new LabelMapError(`Unsupported labels spec type: ${typeof spec}.`);\n}\n"],"mappings":"yCAwBA,IAAa,EAAkC,OAAO,OAAO,wnBAiF7D,CAAC,EAEK,EAAuD,CACzD,KAAM,CACV,EAkBA,SAAgB,EACZ,EACA,EAAgC,CAAC,EAChB,CACjB,IAAM,EAAS,EAAQ,EAAM,EAAQ,UAAU,EAC/C,GAAI,EAAQ,aAAe,IAAA,IAAa,EAAO,SAAW,EAAQ,WAC9D,MAAM,IAAI,EAAA,cACN,YAAY,EAAO,OAAO,4BAA4B,EAAQ,WAAW,UAC7E,EAEJ,OAAO,CACX,CAEA,SAAS,EAAQ,EAAiB,EAAmD,CACjF,GAAI,GAAS,KAA4B,CACrC,GAAI,IAAe,IAAA,GACf,MAAM,IAAI,EAAA,cACN,6FACJ,EAEJ,OAAO,MAAM,KAAK,CAAE,OAAQ,CAAW,GAAI,EAAG,IAAM,SAAS,GAAG,CACpE,CAEA,GAAI,MAAM,QAAQ,CAAI,EAClB,MAAO,CAAC,GAAG,CAAI,EAGnB,GAAI,OAAO,GAAS,SAAU,CAC1B,IAAM,EAAS,EAAQ,GACvB,GAAI,IAAW,IAAA,GACX,OAAO,EAEX,MAAM,IAAI,EAAA,cACN,0BAA0B,KAAK,UAAU,CAAI,EAAE,mBAAmB,OAAO,KAAK,CAAO,CAAC,CAAC,KAAK,IAAI,EAAE,EACtG,CACJ,CAEA,GAAI,OAAO,GAAS,SAAU,CAC1B,IAAM,EAAM,EACN,EAAM,OAAO,KAAK,CAAG,CAAC,CAAC,IAAK,GAAM,OAAO,CAAC,CAAC,EACjD,GAAI,EAAI,SAAW,EACf,MAAO,CAAC,EAEZ,IAAM,EAAQ,KAAK,IAAI,GAAG,CAAG,EAC7B,OAAO,MAAM,KAAK,CAAE,OAAQ,EAAQ,CAAE,GAAI,EAAG,IAAM,EAAI,IAAM,SAAS,GAAG,CAC7E,CAEA,MAAM,IAAI,EAAA,cAAc,iCAAiC,OAAO,EAAK,EAAE,CAC3E"}
1
+ {"version":3,"file":"labels.cjs","names":[],"sources":["../../src/vision/labels.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Class label resolution: presets, lists, dicts, or auto-generated.\n *\n * Tasks call {@link resolveLabels} once at construction time to turn whatever\n * the caller passed (preset name, array, dict, or `null`) into an ordered\n * array of class names indexed by class id.\n *\n * In the browser there is no filesystem, so this module does not load labels\n * from a path — fetch the file yourself and pass an array.\n */\n\nimport { LabelMapError } from \"./core/exceptions\";\n\n/**\n * Anything accepted by {@link resolveLabels}.\n *\n * - `string[]` / `readonly string[]`: explicit names indexed by class id.\n * - `Record<number, string>`: sparse mapping (gaps filled with `class_<id>`).\n * - `string`: a preset name (e.g. `\"coco\"`).\n * - `null` / `undefined`: auto-generate `class_0` ... `class_{numClasses-1}`.\n */\nexport type LabelSpec = readonly string[] | Record<number, string> | string | null | undefined;\n\n/** COCO 2017 80-class labels in canonical class-id order. */\nexport const COCO_CLASSES: readonly string[] = Object.freeze([\n \"person\",\n \"bicycle\",\n \"car\",\n \"motorcycle\",\n \"airplane\",\n \"bus\",\n \"train\",\n \"truck\",\n \"boat\",\n \"traffic light\",\n \"fire hydrant\",\n \"stop sign\",\n \"parking meter\",\n \"bench\",\n \"bird\",\n \"cat\",\n \"dog\",\n \"horse\",\n \"sheep\",\n \"cow\",\n \"elephant\",\n \"bear\",\n \"zebra\",\n \"giraffe\",\n \"backpack\",\n \"umbrella\",\n \"handbag\",\n \"tie\",\n \"suitcase\",\n \"frisbee\",\n \"skis\",\n \"snowboard\",\n \"sports ball\",\n \"kite\",\n \"baseball bat\",\n \"baseball glove\",\n \"skateboard\",\n \"surfboard\",\n \"tennis racket\",\n \"bottle\",\n \"wine glass\",\n \"cup\",\n \"fork\",\n \"knife\",\n \"spoon\",\n \"bowl\",\n \"banana\",\n \"apple\",\n \"sandwich\",\n \"orange\",\n \"broccoli\",\n \"carrot\",\n \"hot dog\",\n \"pizza\",\n \"donut\",\n \"cake\",\n \"chair\",\n \"couch\",\n \"potted plant\",\n \"bed\",\n \"dining table\",\n \"toilet\",\n \"tv\",\n \"laptop\",\n \"mouse\",\n \"remote\",\n \"keyboard\",\n \"cell phone\",\n \"microwave\",\n \"oven\",\n \"toaster\",\n \"sink\",\n \"refrigerator\",\n \"book\",\n \"clock\",\n \"vase\",\n \"scissors\",\n \"teddy bear\",\n \"hair drier\",\n \"toothbrush\",\n]);\n\nconst PRESETS: Readonly<Record<string, readonly string[]>> = {\n coco: COCO_CLASSES,\n};\n\nexport interface ResolveLabelsOptions {\n /**\n * Expected number of classes.\n *\n * - When `spec` is `null`/`undefined`, this is required to auto-generate names.\n * - When `spec` is provided, it validates that the resolved length matches.\n */\n readonly numClasses?: number;\n}\n\n/**\n * Resolve a labels specification into an ordered array of class names.\n *\n * @throws {@link LabelMapError} if the spec is invalid, the preset is unknown,\n * or the resolved length disagrees with `numClasses`.\n */\n/**\n * Pick the fallback label spec for a model that declares no class names.\n *\n * The COCO preset is the right default for a stock YOLO export and an\n * impossible one for anything else: it names exactly 80 classes, so handing it\n * to a 3-class head makes {@link resolveLabels} throw `Resolved 80 labels but\n * the model has 3 classes` and the task cannot be created at all. A custom\n * model without baked-in `names` is an ordinary thing to have — it should come\n * up as `class_0`, `class_1`, ..., not as a failure.\n *\n * @param numClasses Classes the model predicts, or `undefined` when the output\n * shape does not say.\n * @returns `\"coco\"` when the preset can describe the model, otherwise `null`,\n * which makes {@link resolveLabels} generate `class_N` names.\n */\nexport function defaultLabels(numClasses: number | undefined): LabelSpec {\n if (numClasses === undefined || numClasses === COCO_CLASSES.length) {\n return \"coco\";\n }\n return null;\n}\n\nexport function resolveLabels(\n spec: LabelSpec,\n options: ResolveLabelsOptions = {},\n): readonly string[] {\n const labels = resolve(spec, options.numClasses);\n if (options.numClasses !== undefined && labels.length !== options.numClasses) {\n throw new LabelMapError(\n `Resolved ${labels.length} labels but the model has ${options.numClasses} classes.`,\n );\n }\n return labels;\n}\n\nfunction resolve(spec: LabelSpec, numClasses: number | undefined): readonly string[] {\n if (spec === null || spec === undefined) {\n if (numClasses === undefined) {\n throw new LabelMapError(\n \"Cannot auto-generate labels without numClasses. Pass an explicit labels spec or numClasses.\",\n );\n }\n return Array.from({ length: numClasses }, (_, i) => `class_${i}`);\n }\n\n if (Array.isArray(spec)) {\n return [...spec];\n }\n\n if (typeof spec === \"string\") {\n const preset = PRESETS[spec];\n if (preset !== undefined) {\n return preset;\n }\n throw new LabelMapError(\n `Unknown labels preset: ${JSON.stringify(spec)}. Known presets: ${Object.keys(PRESETS).join(\", \")}.`,\n );\n }\n\n if (typeof spec === \"object\") {\n const map = spec as Record<number, string>;\n const ids = Object.keys(map).map((k) => Number(k));\n if (ids.length === 0) {\n return [];\n }\n const maxId = Math.max(...ids);\n return Array.from({ length: maxId + 1 }, (_, i) => map[i] ?? `class_${i}`);\n }\n\n throw new LabelMapError(`Unsupported labels spec type: ${typeof spec}.`);\n}\n"],"mappings":"yCAyBA,IAAa,EAAkC,OAAO,OAAO,wnBAiF7D,CAAC,EAEK,EAAuD,CACzD,KAAM,CACV,EAiCA,SAAgB,EAAc,EAA2C,CAIrE,OAHI,IAAe,IAAA,IAAa,IAAe,EAAa,OACjD,OAEJ,IACX,CAEA,SAAgB,EACZ,EACA,EAAgC,CAAC,EAChB,CACjB,IAAM,EAAS,EAAQ,EAAM,EAAQ,UAAU,EAC/C,GAAI,EAAQ,aAAe,IAAA,IAAa,EAAO,SAAW,EAAQ,WAC9D,MAAM,IAAI,EAAA,cACN,YAAY,EAAO,OAAO,4BAA4B,EAAQ,WAAW,UAC7E,EAEJ,OAAO,CACX,CAEA,SAAS,EAAQ,EAAiB,EAAmD,CACjF,GAAI,GAAS,KAA4B,CACrC,GAAI,IAAe,IAAA,GACf,MAAM,IAAI,EAAA,cACN,6FACJ,EAEJ,OAAO,MAAM,KAAK,CAAE,OAAQ,CAAW,GAAI,EAAG,IAAM,SAAS,GAAG,CACpE,CAEA,GAAI,MAAM,QAAQ,CAAI,EAClB,MAAO,CAAC,GAAG,CAAI,EAGnB,GAAI,OAAO,GAAS,SAAU,CAC1B,IAAM,EAAS,EAAQ,GACvB,GAAI,IAAW,IAAA,GACX,OAAO,EAEX,MAAM,IAAI,EAAA,cACN,0BAA0B,KAAK,UAAU,CAAI,EAAE,mBAAmB,OAAO,KAAK,CAAO,CAAC,CAAC,KAAK,IAAI,EAAE,EACtG,CACJ,CAEA,GAAI,OAAO,GAAS,SAAU,CAC1B,IAAM,EAAM,EACN,EAAM,OAAO,KAAK,CAAG,CAAC,CAAC,IAAK,GAAM,OAAO,CAAC,CAAC,EACjD,GAAI,EAAI,SAAW,EACf,MAAO,CAAC,EAEZ,IAAM,EAAQ,KAAK,IAAI,GAAG,CAAG,EAC7B,OAAO,MAAM,KAAK,CAAE,OAAQ,EAAQ,CAAE,GAAI,EAAG,IAAM,EAAI,IAAM,SAAS,GAAG,CAC7E,CAEA,MAAM,IAAI,EAAA,cAAc,iCAAiC,OAAO,EAAK,EAAE,CAC3E"}
@@ -1,12 +1,15 @@
1
1
  import { LabelMapError as e } from "./core/exceptions.js";
2
2
  //#region src/vision/labels.ts
3
3
  var t = Object.freeze(/* @__PURE__ */ "person.bicycle.car.motorcycle.airplane.bus.train.truck.boat.traffic light.fire hydrant.stop sign.parking meter.bench.bird.cat.dog.horse.sheep.cow.elephant.bear.zebra.giraffe.backpack.umbrella.handbag.tie.suitcase.frisbee.skis.snowboard.sports ball.kite.baseball bat.baseball glove.skateboard.surfboard.tennis racket.bottle.wine glass.cup.fork.knife.spoon.bowl.banana.apple.sandwich.orange.broccoli.carrot.hot dog.pizza.donut.cake.chair.couch.potted plant.bed.dining table.toilet.tv.laptop.mouse.remote.keyboard.cell phone.microwave.oven.toaster.sink.refrigerator.book.clock.vase.scissors.teddy bear.hair drier.toothbrush".split(".")), n = { coco: t };
4
- function r(t, n = {}) {
5
- let r = i(t, n.numClasses);
4
+ function r(e) {
5
+ return e === void 0 || e === t.length ? "coco" : null;
6
+ }
7
+ function i(t, n = {}) {
8
+ let r = a(t, n.numClasses);
6
9
  if (n.numClasses !== void 0 && r.length !== n.numClasses) throw new e(`Resolved ${r.length} labels but the model has ${n.numClasses} classes.`);
7
10
  return r;
8
11
  }
9
- function i(t, r) {
12
+ function a(t, r) {
10
13
  if (t == null) {
11
14
  if (r === void 0) throw new e("Cannot auto-generate labels without numClasses. Pass an explicit labels spec or numClasses.");
12
15
  return Array.from({ length: r }, (e, t) => `class_${t}`);
@@ -26,6 +29,6 @@ function i(t, r) {
26
29
  throw new e(`Unsupported labels spec type: ${typeof t}.`);
27
30
  }
28
31
  //#endregion
29
- export { t as COCO_CLASSES, r as resolveLabels };
32
+ export { t as COCO_CLASSES, r as defaultLabels, i as resolveLabels };
30
33
 
31
34
  //# sourceMappingURL=labels.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"labels.js","names":[],"sources":["../../src/vision/labels.ts"],"sourcesContent":["/**\n * Class label resolution: presets, lists, dicts, or auto-generated.\n *\n * Tasks call {@link resolveLabels} once at construction time to turn whatever\n * the caller passed (preset name, array, dict, or `null`) into an ordered\n * array of class names indexed by class id.\n *\n * In the browser there is no filesystem, so this module does not load labels\n * from a path — fetch the file yourself and pass an array.\n */\n\nimport { LabelMapError } from \"./core/exceptions\";\n\n/**\n * Anything accepted by {@link resolveLabels}.\n *\n * - `string[]` / `readonly string[]`: explicit names indexed by class id.\n * - `Record<number, string>`: sparse mapping (gaps filled with `class_<id>`).\n * - `string`: a preset name (e.g. `\"coco\"`).\n * - `null` / `undefined`: auto-generate `class_0` ... `class_{numClasses-1}`.\n */\nexport type LabelSpec = readonly string[] | Record<number, string> | string | null | undefined;\n\n/** COCO 2017 80-class labels in canonical class-id order. */\nexport const COCO_CLASSES: readonly string[] = Object.freeze([\n \"person\",\n \"bicycle\",\n \"car\",\n \"motorcycle\",\n \"airplane\",\n \"bus\",\n \"train\",\n \"truck\",\n \"boat\",\n \"traffic light\",\n \"fire hydrant\",\n \"stop sign\",\n \"parking meter\",\n \"bench\",\n \"bird\",\n \"cat\",\n \"dog\",\n \"horse\",\n \"sheep\",\n \"cow\",\n \"elephant\",\n \"bear\",\n \"zebra\",\n \"giraffe\",\n \"backpack\",\n \"umbrella\",\n \"handbag\",\n \"tie\",\n \"suitcase\",\n \"frisbee\",\n \"skis\",\n \"snowboard\",\n \"sports ball\",\n \"kite\",\n \"baseball bat\",\n \"baseball glove\",\n \"skateboard\",\n \"surfboard\",\n \"tennis racket\",\n \"bottle\",\n \"wine glass\",\n \"cup\",\n \"fork\",\n \"knife\",\n \"spoon\",\n \"bowl\",\n \"banana\",\n \"apple\",\n \"sandwich\",\n \"orange\",\n \"broccoli\",\n \"carrot\",\n \"hot dog\",\n \"pizza\",\n \"donut\",\n \"cake\",\n \"chair\",\n \"couch\",\n \"potted plant\",\n \"bed\",\n \"dining table\",\n \"toilet\",\n \"tv\",\n \"laptop\",\n \"mouse\",\n \"remote\",\n \"keyboard\",\n \"cell phone\",\n \"microwave\",\n \"oven\",\n \"toaster\",\n \"sink\",\n \"refrigerator\",\n \"book\",\n \"clock\",\n \"vase\",\n \"scissors\",\n \"teddy bear\",\n \"hair drier\",\n \"toothbrush\",\n]);\n\nconst PRESETS: Readonly<Record<string, readonly string[]>> = {\n coco: COCO_CLASSES,\n};\n\nexport interface ResolveLabelsOptions {\n /**\n * Expected number of classes.\n *\n * - When `spec` is `null`/`undefined`, this is required to auto-generate names.\n * - When `spec` is provided, it validates that the resolved length matches.\n */\n readonly numClasses?: number;\n}\n\n/**\n * Resolve a labels specification into an ordered array of class names.\n *\n * @throws {@link LabelMapError} if the spec is invalid, the preset is unknown,\n * or the resolved length disagrees with `numClasses`.\n */\nexport function resolveLabels(\n spec: LabelSpec,\n options: ResolveLabelsOptions = {},\n): readonly string[] {\n const labels = resolve(spec, options.numClasses);\n if (options.numClasses !== undefined && labels.length !== options.numClasses) {\n throw new LabelMapError(\n `Resolved ${labels.length} labels but the model has ${options.numClasses} classes.`,\n );\n }\n return labels;\n}\n\nfunction resolve(spec: LabelSpec, numClasses: number | undefined): readonly string[] {\n if (spec === null || spec === undefined) {\n if (numClasses === undefined) {\n throw new LabelMapError(\n \"Cannot auto-generate labels without numClasses. Pass an explicit labels spec or numClasses.\",\n );\n }\n return Array.from({ length: numClasses }, (_, i) => `class_${i}`);\n }\n\n if (Array.isArray(spec)) {\n return [...spec];\n }\n\n if (typeof spec === \"string\") {\n const preset = PRESETS[spec];\n if (preset !== undefined) {\n return preset;\n }\n throw new LabelMapError(\n `Unknown labels preset: ${JSON.stringify(spec)}. Known presets: ${Object.keys(PRESETS).join(\", \")}.`,\n );\n }\n\n if (typeof spec === \"object\") {\n const map = spec as Record<number, string>;\n const ids = Object.keys(map).map((k) => Number(k));\n if (ids.length === 0) {\n return [];\n }\n const maxId = Math.max(...ids);\n return Array.from({ length: maxId + 1 }, (_, i) => map[i] ?? `class_${i}`);\n }\n\n throw new LabelMapError(`Unsupported labels spec type: ${typeof spec}.`);\n}\n"],"mappings":";;AAwBA,IAAa,IAAkC,OAAO,OAAO,woBAiF7D,CAAC,GAEK,IAAuD,EACzD,MAAM,EACV;AAkBA,SAAgB,EACZ,GACA,IAAgC,CAAC,GAChB;CACjB,IAAM,IAAS,EAAQ,GAAM,EAAQ,UAAU;CAC/C,IAAI,EAAQ,eAAe,KAAA,KAAa,EAAO,WAAW,EAAQ,YAC9D,MAAM,IAAI,EACN,YAAY,EAAO,OAAO,4BAA4B,EAAQ,WAAW,UAC7E;CAEJ,OAAO;AACX;AAEA,SAAS,EAAQ,GAAiB,GAAmD;CACjF,IAAI,KAAS,MAA4B;EACrC,IAAI,MAAe,KAAA,GACf,MAAM,IAAI,EACN,6FACJ;EAEJ,OAAO,MAAM,KAAK,EAAE,QAAQ,EAAW,IAAI,GAAG,MAAM,SAAS,GAAG;CACpE;CAEA,IAAI,MAAM,QAAQ,CAAI,GAClB,OAAO,CAAC,GAAG,CAAI;CAGnB,IAAI,OAAO,KAAS,UAAU;EAC1B,IAAM,IAAS,EAAQ;EACvB,IAAI,MAAW,KAAA,GACX,OAAO;EAEX,MAAM,IAAI,EACN,0BAA0B,KAAK,UAAU,CAAI,EAAE,mBAAmB,OAAO,KAAK,CAAO,CAAC,CAAC,KAAK,IAAI,EAAE,EACtG;CACJ;CAEA,IAAI,OAAO,KAAS,UAAU;EAC1B,IAAM,IAAM,GACN,IAAM,OAAO,KAAK,CAAG,CAAC,CAAC,KAAK,MAAM,OAAO,CAAC,CAAC;EACjD,IAAI,EAAI,WAAW,GACf,OAAO,CAAC;EAEZ,IAAM,IAAQ,KAAK,IAAI,GAAG,CAAG;EAC7B,OAAO,MAAM,KAAK,EAAE,QAAQ,IAAQ,EAAE,IAAI,GAAG,MAAM,EAAI,MAAM,SAAS,GAAG;CAC7E;CAEA,MAAM,IAAI,EAAc,iCAAiC,OAAO,EAAK,EAAE;AAC3E"}
1
+ {"version":3,"file":"labels.js","names":[],"sources":["../../src/vision/labels.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Class label resolution: presets, lists, dicts, or auto-generated.\n *\n * Tasks call {@link resolveLabels} once at construction time to turn whatever\n * the caller passed (preset name, array, dict, or `null`) into an ordered\n * array of class names indexed by class id.\n *\n * In the browser there is no filesystem, so this module does not load labels\n * from a path — fetch the file yourself and pass an array.\n */\n\nimport { LabelMapError } from \"./core/exceptions\";\n\n/**\n * Anything accepted by {@link resolveLabels}.\n *\n * - `string[]` / `readonly string[]`: explicit names indexed by class id.\n * - `Record<number, string>`: sparse mapping (gaps filled with `class_<id>`).\n * - `string`: a preset name (e.g. `\"coco\"`).\n * - `null` / `undefined`: auto-generate `class_0` ... `class_{numClasses-1}`.\n */\nexport type LabelSpec = readonly string[] | Record<number, string> | string | null | undefined;\n\n/** COCO 2017 80-class labels in canonical class-id order. */\nexport const COCO_CLASSES: readonly string[] = Object.freeze([\n \"person\",\n \"bicycle\",\n \"car\",\n \"motorcycle\",\n \"airplane\",\n \"bus\",\n \"train\",\n \"truck\",\n \"boat\",\n \"traffic light\",\n \"fire hydrant\",\n \"stop sign\",\n \"parking meter\",\n \"bench\",\n \"bird\",\n \"cat\",\n \"dog\",\n \"horse\",\n \"sheep\",\n \"cow\",\n \"elephant\",\n \"bear\",\n \"zebra\",\n \"giraffe\",\n \"backpack\",\n \"umbrella\",\n \"handbag\",\n \"tie\",\n \"suitcase\",\n \"frisbee\",\n \"skis\",\n \"snowboard\",\n \"sports ball\",\n \"kite\",\n \"baseball bat\",\n \"baseball glove\",\n \"skateboard\",\n \"surfboard\",\n \"tennis racket\",\n \"bottle\",\n \"wine glass\",\n \"cup\",\n \"fork\",\n \"knife\",\n \"spoon\",\n \"bowl\",\n \"banana\",\n \"apple\",\n \"sandwich\",\n \"orange\",\n \"broccoli\",\n \"carrot\",\n \"hot dog\",\n \"pizza\",\n \"donut\",\n \"cake\",\n \"chair\",\n \"couch\",\n \"potted plant\",\n \"bed\",\n \"dining table\",\n \"toilet\",\n \"tv\",\n \"laptop\",\n \"mouse\",\n \"remote\",\n \"keyboard\",\n \"cell phone\",\n \"microwave\",\n \"oven\",\n \"toaster\",\n \"sink\",\n \"refrigerator\",\n \"book\",\n \"clock\",\n \"vase\",\n \"scissors\",\n \"teddy bear\",\n \"hair drier\",\n \"toothbrush\",\n]);\n\nconst PRESETS: Readonly<Record<string, readonly string[]>> = {\n coco: COCO_CLASSES,\n};\n\nexport interface ResolveLabelsOptions {\n /**\n * Expected number of classes.\n *\n * - When `spec` is `null`/`undefined`, this is required to auto-generate names.\n * - When `spec` is provided, it validates that the resolved length matches.\n */\n readonly numClasses?: number;\n}\n\n/**\n * Resolve a labels specification into an ordered array of class names.\n *\n * @throws {@link LabelMapError} if the spec is invalid, the preset is unknown,\n * or the resolved length disagrees with `numClasses`.\n */\n/**\n * Pick the fallback label spec for a model that declares no class names.\n *\n * The COCO preset is the right default for a stock YOLO export and an\n * impossible one for anything else: it names exactly 80 classes, so handing it\n * to a 3-class head makes {@link resolveLabels} throw `Resolved 80 labels but\n * the model has 3 classes` and the task cannot be created at all. A custom\n * model without baked-in `names` is an ordinary thing to have — it should come\n * up as `class_0`, `class_1`, ..., not as a failure.\n *\n * @param numClasses Classes the model predicts, or `undefined` when the output\n * shape does not say.\n * @returns `\"coco\"` when the preset can describe the model, otherwise `null`,\n * which makes {@link resolveLabels} generate `class_N` names.\n */\nexport function defaultLabels(numClasses: number | undefined): LabelSpec {\n if (numClasses === undefined || numClasses === COCO_CLASSES.length) {\n return \"coco\";\n }\n return null;\n}\n\nexport function resolveLabels(\n spec: LabelSpec,\n options: ResolveLabelsOptions = {},\n): readonly string[] {\n const labels = resolve(spec, options.numClasses);\n if (options.numClasses !== undefined && labels.length !== options.numClasses) {\n throw new LabelMapError(\n `Resolved ${labels.length} labels but the model has ${options.numClasses} classes.`,\n );\n }\n return labels;\n}\n\nfunction resolve(spec: LabelSpec, numClasses: number | undefined): readonly string[] {\n if (spec === null || spec === undefined) {\n if (numClasses === undefined) {\n throw new LabelMapError(\n \"Cannot auto-generate labels without numClasses. Pass an explicit labels spec or numClasses.\",\n );\n }\n return Array.from({ length: numClasses }, (_, i) => `class_${i}`);\n }\n\n if (Array.isArray(spec)) {\n return [...spec];\n }\n\n if (typeof spec === \"string\") {\n const preset = PRESETS[spec];\n if (preset !== undefined) {\n return preset;\n }\n throw new LabelMapError(\n `Unknown labels preset: ${JSON.stringify(spec)}. Known presets: ${Object.keys(PRESETS).join(\", \")}.`,\n );\n }\n\n if (typeof spec === \"object\") {\n const map = spec as Record<number, string>;\n const ids = Object.keys(map).map((k) => Number(k));\n if (ids.length === 0) {\n return [];\n }\n const maxId = Math.max(...ids);\n return Array.from({ length: maxId + 1 }, (_, i) => map[i] ?? `class_${i}`);\n }\n\n throw new LabelMapError(`Unsupported labels spec type: ${typeof spec}.`);\n}\n"],"mappings":";;AAyBA,IAAa,IAAkC,OAAO,OAAO,woBAiF7D,CAAC,GAEK,IAAuD,EACzD,MAAM,EACV;AAiCA,SAAgB,EAAc,GAA2C;CAIrE,OAHI,MAAe,KAAA,KAAa,MAAe,EAAa,SACjD,SAEJ;AACX;AAEA,SAAgB,EACZ,GACA,IAAgC,CAAC,GAChB;CACjB,IAAM,IAAS,EAAQ,GAAM,EAAQ,UAAU;CAC/C,IAAI,EAAQ,eAAe,KAAA,KAAa,EAAO,WAAW,EAAQ,YAC9D,MAAM,IAAI,EACN,YAAY,EAAO,OAAO,4BAA4B,EAAQ,WAAW,UAC7E;CAEJ,OAAO;AACX;AAEA,SAAS,EAAQ,GAAiB,GAAmD;CACjF,IAAI,KAAS,MAA4B;EACrC,IAAI,MAAe,KAAA,GACf,MAAM,IAAI,EACN,6FACJ;EAEJ,OAAO,MAAM,KAAK,EAAE,QAAQ,EAAW,IAAI,GAAG,MAAM,SAAS,GAAG;CACpE;CAEA,IAAI,MAAM,QAAQ,CAAI,GAClB,OAAO,CAAC,GAAG,CAAI;CAGnB,IAAI,OAAO,KAAS,UAAU;EAC1B,IAAM,IAAS,EAAQ;EACvB,IAAI,MAAW,KAAA,GACX,OAAO;EAEX,MAAM,IAAI,EACN,0BAA0B,KAAK,UAAU,CAAI,EAAE,mBAAmB,OAAO,KAAK,CAAO,CAAC,CAAC,KAAK,IAAI,EAAE,EACtG;CACJ;CAEA,IAAI,OAAO,KAAS,UAAU;EAC1B,IAAM,IAAM,GACN,IAAM,OAAO,KAAK,CAAG,CAAC,CAAC,KAAK,MAAM,OAAO,CAAC,CAAC;EACjD,IAAI,EAAI,WAAW,GACf,OAAO,CAAC;EAEZ,IAAM,IAAQ,KAAK,IAAI,GAAG,CAAG;EAC7B,OAAO,MAAM,KAAK,EAAE,QAAQ,IAAQ,EAAE,IAAI,GAAG,MAAM,EAAI,MAAM,SAAS,GAAG;CAC7E;CAEA,MAAM,IAAI,EAAc,iCAAiC,OAAO,EAAK,EAAE;AAC3E"}
@@ -1 +1 @@
1
- {"version":3,"file":"luminance.cjs","names":[],"sources":["../../src/vision/luminance.ts"],"sourcesContent":["/**\n * Frame-brightness helpers — measure the mean luminance of an already-decoded\n * frame (`<img>`, `<video>`, `<canvas>`, `ImageBitmap` or `OffscreenCanvas`) so\n * a UI can reject underexposed captures before paying the cost of downstream\n * inference.\n *\n * These are framework-agnostic pure functions; {@link useLiveLuminance} wires\n * {@link computeImageLuminance} into a React `requestAnimationFrame` loop for\n * live camera feedback.\n */\n\n/**\n * Longest edge (in pixels) the source is downsampled to before sampling.\n * Averaging over a small downsample is statistically equivalent for a\n * brightness threshold and orders of magnitude faster than reading every pixel\n * of a full-resolution camera frame.\n */\nexport const LUMINANCE_SAMPLE_MAX_EDGE = 256;\n\n/**\n * Drawable source we can sample luminance from.\n *\n * The list tracks what `CanvasRenderingContext2D.drawImage` accepts and we can\n * read a pixel size off, which is what the implementation actually needs.\n * `ImageBitmap` matters for the decode-downscaled path: `createImageBitmap(blob,\n * { resizeWidth })` is how a caller avoids materialising a full-resolution\n * phone photo, and the frame it hands back is the frame whose brightness has to\n * be checked.\n */\nexport type LuminanceSource =\n HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas;\n\n/**\n * Natural pixel size of the source (`0`/`0` while it is still unloaded).\n *\n * `ImageBitmap` and `OffscreenCanvas` both expose plain `width`/`height`, so\n * they fall through to the same branch as a canvas — but they are named\n * explicitly rather than left to the `naturalWidth || width` fallback, which\n * only reads as intentional for an `<img>`.\n */\nfunction sourceSize(source: LuminanceSource): { width: number; height: number } {\n if (source instanceof HTMLVideoElement) {\n return { width: source.videoWidth, height: source.videoHeight };\n }\n if (source instanceof HTMLImageElement) {\n return {\n width: source.naturalWidth || source.width,\n height: source.naturalHeight || source.height,\n };\n }\n return { width: source.width, height: source.height };\n}\n\n/**\n * Mean BT.709 luminance (`0.2126*R + 0.7152*G + 0.0722*B`) of a decoded frame,\n * scaled to `0..255`. See {@link LuminanceSource} for what counts as one.\n *\n * The source is downsampled so its longest edge is at most\n * {@link LUMINANCE_SAMPLE_MAX_EDGE} before pixels are read. The 2D context is\n * created with `willReadFrequently` so repeated sampling (live feedback) stays\n * on the fast path.\n *\n * Pass `reusableCanvas` to avoid allocating a fresh canvas every frame in a hot\n * loop; when omitted a one-shot detached canvas is created.\n *\n * @param source - the decoded frame to sample.\n * @param reusableCanvas - optional canvas reused across frames to avoid GC churn.\n * @returns The mean luminance in `0..255`, or `0` when the source is unloaded\n * (zero-sized) or a 2D context is unavailable.\n */\nexport function computeImageLuminance(\n source: LuminanceSource,\n reusableCanvas?: HTMLCanvasElement,\n): number {\n const { width: srcW, height: srcH } = sourceSize(source);\n if (srcW === 0 || srcH === 0) return 0;\n\n const scale = Math.min(1, LUMINANCE_SAMPLE_MAX_EDGE / Math.max(srcW, srcH));\n const w = Math.max(1, Math.round(srcW * scale));\n const h = Math.max(1, Math.round(srcH * scale));\n\n const canvas = reusableCanvas ?? document.createElement(\"canvas\");\n canvas.width = w;\n canvas.height = h;\n const ctx = canvas.getContext(\"2d\", { willReadFrequently: true });\n if (!ctx) return 0;\n ctx.drawImage(source, 0, 0, w, h);\n\n const data = ctx.getImageData(0, 0, w, h).data;\n let sum = 0;\n const pixelCount = w * h;\n for (let i = 0; i < data.length; i += 4) {\n sum += 0.2126 * data[i] + 0.7152 * data[i + 1] + 0.0722 * data[i + 2];\n }\n return sum / pixelCount;\n}\n\n/**\n * Whether a measured luminance clears a brightness threshold.\n *\n * `threshold` is intentionally required — a sensible value is\n * application-specific (it depends on the model, the lighting the model was\n * trained on, and the acceptable false-reject rate), so the SDK does not bake\n * in a default.\n *\n * @param luminance - measured mean luminance in `0..255`.\n * @param threshold - minimum acceptable luminance in `0..255`.\n * @returns `true` when `luminance >= threshold`.\n */\nexport function isLuminanceAcceptable(luminance: number, threshold: number): boolean {\n return luminance >= threshold;\n}\n\n/**\n * Error raised when a captured frame is too dark to be analysed reliably.\n * Carries the measured luminance and the threshold it failed so callers can\n * surface actionable feedback.\n */\nexport class LowLuminanceError extends Error {\n /** Measured mean luminance, `0..255`. */\n readonly luminance: number;\n /** Threshold that was checked against, `0..255`. */\n readonly threshold: number;\n\n /**\n * @param luminance - the measured mean luminance in `0..255`.\n * @param threshold - the threshold the measurement failed to reach.\n */\n constructor(luminance: number, threshold: number) {\n super(\"Image is too dark to analyse. Capture again in a brighter environment.\");\n this.name = \"LowLuminanceError\";\n this.luminance = luminance;\n this.threshold = threshold;\n }\n}\n"],"mappings":"AAiBA,IAAa,EAA4B,IAuBzC,SAAS,EAAW,EAA4D,CAU5E,OATI,aAAkB,iBACX,CAAE,MAAO,EAAO,WAAY,OAAQ,EAAO,WAAY,EAE9D,aAAkB,iBACX,CACH,MAAO,EAAO,cAAgB,EAAO,MACrC,OAAQ,EAAO,eAAiB,EAAO,MAC3C,EAEG,CAAE,MAAO,EAAO,MAAO,OAAQ,EAAO,MAAO,CACxD,CAmBA,SAAgB,EACZ,EACA,EACM,CACN,GAAM,CAAE,MAAO,EAAM,OAAQ,GAAS,EAAW,CAAM,EACvD,GAAI,IAAS,GAAK,IAAS,EAAG,MAAO,GAErC,IAAM,EAAQ,KAAK,IAAI,EAAA,IAA+B,KAAK,IAAI,EAAM,CAAI,CAAC,EACpE,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAO,CAAK,CAAC,EACxC,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAO,CAAK,CAAC,EAExC,EAAS,GAAkB,SAAS,cAAc,QAAQ,EAChE,EAAO,MAAQ,EACf,EAAO,OAAS,EAChB,IAAM,EAAM,EAAO,WAAW,KAAM,CAAE,mBAAoB,EAAK,CAAC,EAChE,GAAI,CAAC,EAAK,MAAO,GACjB,EAAI,UAAU,EAAQ,EAAG,EAAG,EAAG,CAAC,EAEhC,IAAM,EAAO,EAAI,aAAa,EAAG,EAAG,EAAG,CAAC,CAAC,CAAC,KACtC,EAAM,EACJ,EAAa,EAAI,EACvB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,OAAQ,GAAK,EAClC,GAAO,MAAS,EAAK,GAAK,MAAS,EAAK,EAAI,GAAK,MAAS,EAAK,EAAI,GAEvE,OAAO,EAAM,CACjB,CAcA,SAAgB,EAAsB,EAAmB,EAA4B,CACjF,OAAO,GAAa,CACxB,CAOA,IAAa,EAAb,cAAuC,KAAM,CAEzC,UAEA,UAMA,YAAY,EAAmB,EAAmB,CAC9C,MAAM,wEAAwE,EAC9E,KAAK,KAAO,oBACZ,KAAK,UAAY,EACjB,KAAK,UAAY,CACrB,CACJ"}
1
+ {"version":3,"file":"luminance.cjs","names":[],"sources":["../../src/vision/luminance.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Frame-brightness helpers — measure the mean luminance of an already-decoded\n * frame (`<img>`, `<video>`, `<canvas>`, `ImageBitmap` or `OffscreenCanvas`) so\n * a UI can reject underexposed captures before paying the cost of downstream\n * inference.\n *\n * These are framework-agnostic pure functions; {@link useLiveLuminance} wires\n * {@link computeImageLuminance} into a React `requestAnimationFrame` loop for\n * live camera feedback.\n */\n\n/**\n * Longest edge (in pixels) the source is downsampled to before sampling.\n * Averaging over a small downsample is statistically equivalent for a\n * brightness threshold and orders of magnitude faster than reading every pixel\n * of a full-resolution camera frame.\n */\nexport const LUMINANCE_SAMPLE_MAX_EDGE = 256;\n\n/**\n * Drawable source we can sample luminance from.\n *\n * The list tracks what `CanvasRenderingContext2D.drawImage` accepts and we can\n * read a pixel size off, which is what the implementation actually needs.\n * `ImageBitmap` matters for the decode-downscaled path: `createImageBitmap(blob,\n * { resizeWidth })` is how a caller avoids materialising a full-resolution\n * phone photo, and the frame it hands back is the frame whose brightness has to\n * be checked.\n */\nexport type LuminanceSource =\n HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas;\n\n/**\n * Natural pixel size of the source (`0`/`0` while it is still unloaded).\n *\n * `ImageBitmap` and `OffscreenCanvas` both expose plain `width`/`height`, so\n * they fall through to the same branch as a canvas — but they are named\n * explicitly rather than left to the `naturalWidth || width` fallback, which\n * only reads as intentional for an `<img>`.\n */\nfunction sourceSize(source: LuminanceSource): { width: number; height: number } {\n if (source instanceof HTMLVideoElement) {\n return { width: source.videoWidth, height: source.videoHeight };\n }\n if (source instanceof HTMLImageElement) {\n return {\n width: source.naturalWidth || source.width,\n height: source.naturalHeight || source.height,\n };\n }\n return { width: source.width, height: source.height };\n}\n\n/**\n * Mean BT.709 luminance (`0.2126*R + 0.7152*G + 0.0722*B`) of a decoded frame,\n * scaled to `0..255`. See {@link LuminanceSource} for what counts as one.\n *\n * The source is downsampled so its longest edge is at most\n * {@link LUMINANCE_SAMPLE_MAX_EDGE} before pixels are read. The 2D context is\n * created with `willReadFrequently` so repeated sampling (live feedback) stays\n * on the fast path.\n *\n * Pass `reusableCanvas` to avoid allocating a fresh canvas every frame in a hot\n * loop; when omitted a one-shot detached canvas is created.\n *\n * @param source - the decoded frame to sample.\n * @param reusableCanvas - optional canvas reused across frames to avoid GC churn.\n * @returns The mean luminance in `0..255`, or `0` when the source is unloaded\n * (zero-sized) or a 2D context is unavailable.\n */\nexport function computeImageLuminance(\n source: LuminanceSource,\n reusableCanvas?: HTMLCanvasElement,\n): number {\n const { width: srcW, height: srcH } = sourceSize(source);\n if (srcW === 0 || srcH === 0) return 0;\n\n const scale = Math.min(1, LUMINANCE_SAMPLE_MAX_EDGE / Math.max(srcW, srcH));\n const w = Math.max(1, Math.round(srcW * scale));\n const h = Math.max(1, Math.round(srcH * scale));\n\n const canvas = reusableCanvas ?? document.createElement(\"canvas\");\n canvas.width = w;\n canvas.height = h;\n const ctx = canvas.getContext(\"2d\", { willReadFrequently: true });\n if (!ctx) return 0;\n ctx.drawImage(source, 0, 0, w, h);\n\n const data = ctx.getImageData(0, 0, w, h).data;\n let sum = 0;\n const pixelCount = w * h;\n for (let i = 0; i < data.length; i += 4) {\n sum += 0.2126 * data[i] + 0.7152 * data[i + 1] + 0.0722 * data[i + 2];\n }\n return sum / pixelCount;\n}\n\n/**\n * Whether a measured luminance clears a brightness threshold.\n *\n * `threshold` is intentionally required — a sensible value is\n * application-specific (it depends on the model, the lighting the model was\n * trained on, and the acceptable false-reject rate), so the SDK does not bake\n * in a default.\n *\n * @param luminance - measured mean luminance in `0..255`.\n * @param threshold - minimum acceptable luminance in `0..255`.\n * @returns `true` when `luminance >= threshold`.\n */\nexport function isLuminanceAcceptable(luminance: number, threshold: number): boolean {\n return luminance >= threshold;\n}\n\n/**\n * Error raised when a captured frame is too dark to be analysed reliably.\n * Carries the measured luminance and the threshold it failed so callers can\n * surface actionable feedback.\n */\nexport class LowLuminanceError extends Error {\n /** Measured mean luminance, `0..255`. */\n readonly luminance: number;\n /** Threshold that was checked against, `0..255`. */\n readonly threshold: number;\n\n /**\n * @param luminance - the measured mean luminance in `0..255`.\n * @param threshold - the threshold the measurement failed to reach.\n */\n constructor(luminance: number, threshold: number) {\n super(\"Image is too dark to analyse. Capture again in a brighter environment.\");\n this.name = \"LowLuminanceError\";\n this.luminance = luminance;\n this.threshold = threshold;\n }\n}\n"],"mappings":"AAkBA,IAAa,EAA4B,IAuBzC,SAAS,EAAW,EAA4D,CAU5E,OATI,aAAkB,iBACX,CAAE,MAAO,EAAO,WAAY,OAAQ,EAAO,WAAY,EAE9D,aAAkB,iBACX,CACH,MAAO,EAAO,cAAgB,EAAO,MACrC,OAAQ,EAAO,eAAiB,EAAO,MAC3C,EAEG,CAAE,MAAO,EAAO,MAAO,OAAQ,EAAO,MAAO,CACxD,CAmBA,SAAgB,EACZ,EACA,EACM,CACN,GAAM,CAAE,MAAO,EAAM,OAAQ,GAAS,EAAW,CAAM,EACvD,GAAI,IAAS,GAAK,IAAS,EAAG,MAAO,GAErC,IAAM,EAAQ,KAAK,IAAI,EAAA,IAA+B,KAAK,IAAI,EAAM,CAAI,CAAC,EACpE,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAO,CAAK,CAAC,EACxC,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAO,CAAK,CAAC,EAExC,EAAS,GAAkB,SAAS,cAAc,QAAQ,EAChE,EAAO,MAAQ,EACf,EAAO,OAAS,EAChB,IAAM,EAAM,EAAO,WAAW,KAAM,CAAE,mBAAoB,EAAK,CAAC,EAChE,GAAI,CAAC,EAAK,MAAO,GACjB,EAAI,UAAU,EAAQ,EAAG,EAAG,EAAG,CAAC,EAEhC,IAAM,EAAO,EAAI,aAAa,EAAG,EAAG,EAAG,CAAC,CAAC,CAAC,KACtC,EAAM,EACJ,EAAa,EAAI,EACvB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,OAAQ,GAAK,EAClC,GAAO,MAAS,EAAK,GAAK,MAAS,EAAK,EAAI,GAAK,MAAS,EAAK,EAAI,GAEvE,OAAO,EAAM,CACjB,CAcA,SAAgB,EAAsB,EAAmB,EAA4B,CACjF,OAAO,GAAa,CACxB,CAOA,IAAa,EAAb,cAAuC,KAAM,CAEzC,UAEA,UAMA,YAAY,EAAmB,EAAmB,CAC9C,MAAM,wEAAwE,EAC9E,KAAK,KAAO,oBACZ,KAAK,UAAY,EACjB,KAAK,UAAY,CACrB,CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"luminance.js","names":[],"sources":["../../src/vision/luminance.ts"],"sourcesContent":["/**\n * Frame-brightness helpers — measure the mean luminance of an already-decoded\n * frame (`<img>`, `<video>`, `<canvas>`, `ImageBitmap` or `OffscreenCanvas`) so\n * a UI can reject underexposed captures before paying the cost of downstream\n * inference.\n *\n * These are framework-agnostic pure functions; {@link useLiveLuminance} wires\n * {@link computeImageLuminance} into a React `requestAnimationFrame` loop for\n * live camera feedback.\n */\n\n/**\n * Longest edge (in pixels) the source is downsampled to before sampling.\n * Averaging over a small downsample is statistically equivalent for a\n * brightness threshold and orders of magnitude faster than reading every pixel\n * of a full-resolution camera frame.\n */\nexport const LUMINANCE_SAMPLE_MAX_EDGE = 256;\n\n/**\n * Drawable source we can sample luminance from.\n *\n * The list tracks what `CanvasRenderingContext2D.drawImage` accepts and we can\n * read a pixel size off, which is what the implementation actually needs.\n * `ImageBitmap` matters for the decode-downscaled path: `createImageBitmap(blob,\n * { resizeWidth })` is how a caller avoids materialising a full-resolution\n * phone photo, and the frame it hands back is the frame whose brightness has to\n * be checked.\n */\nexport type LuminanceSource =\n HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas;\n\n/**\n * Natural pixel size of the source (`0`/`0` while it is still unloaded).\n *\n * `ImageBitmap` and `OffscreenCanvas` both expose plain `width`/`height`, so\n * they fall through to the same branch as a canvas — but they are named\n * explicitly rather than left to the `naturalWidth || width` fallback, which\n * only reads as intentional for an `<img>`.\n */\nfunction sourceSize(source: LuminanceSource): { width: number; height: number } {\n if (source instanceof HTMLVideoElement) {\n return { width: source.videoWidth, height: source.videoHeight };\n }\n if (source instanceof HTMLImageElement) {\n return {\n width: source.naturalWidth || source.width,\n height: source.naturalHeight || source.height,\n };\n }\n return { width: source.width, height: source.height };\n}\n\n/**\n * Mean BT.709 luminance (`0.2126*R + 0.7152*G + 0.0722*B`) of a decoded frame,\n * scaled to `0..255`. See {@link LuminanceSource} for what counts as one.\n *\n * The source is downsampled so its longest edge is at most\n * {@link LUMINANCE_SAMPLE_MAX_EDGE} before pixels are read. The 2D context is\n * created with `willReadFrequently` so repeated sampling (live feedback) stays\n * on the fast path.\n *\n * Pass `reusableCanvas` to avoid allocating a fresh canvas every frame in a hot\n * loop; when omitted a one-shot detached canvas is created.\n *\n * @param source - the decoded frame to sample.\n * @param reusableCanvas - optional canvas reused across frames to avoid GC churn.\n * @returns The mean luminance in `0..255`, or `0` when the source is unloaded\n * (zero-sized) or a 2D context is unavailable.\n */\nexport function computeImageLuminance(\n source: LuminanceSource,\n reusableCanvas?: HTMLCanvasElement,\n): number {\n const { width: srcW, height: srcH } = sourceSize(source);\n if (srcW === 0 || srcH === 0) return 0;\n\n const scale = Math.min(1, LUMINANCE_SAMPLE_MAX_EDGE / Math.max(srcW, srcH));\n const w = Math.max(1, Math.round(srcW * scale));\n const h = Math.max(1, Math.round(srcH * scale));\n\n const canvas = reusableCanvas ?? document.createElement(\"canvas\");\n canvas.width = w;\n canvas.height = h;\n const ctx = canvas.getContext(\"2d\", { willReadFrequently: true });\n if (!ctx) return 0;\n ctx.drawImage(source, 0, 0, w, h);\n\n const data = ctx.getImageData(0, 0, w, h).data;\n let sum = 0;\n const pixelCount = w * h;\n for (let i = 0; i < data.length; i += 4) {\n sum += 0.2126 * data[i] + 0.7152 * data[i + 1] + 0.0722 * data[i + 2];\n }\n return sum / pixelCount;\n}\n\n/**\n * Whether a measured luminance clears a brightness threshold.\n *\n * `threshold` is intentionally required — a sensible value is\n * application-specific (it depends on the model, the lighting the model was\n * trained on, and the acceptable false-reject rate), so the SDK does not bake\n * in a default.\n *\n * @param luminance - measured mean luminance in `0..255`.\n * @param threshold - minimum acceptable luminance in `0..255`.\n * @returns `true` when `luminance >= threshold`.\n */\nexport function isLuminanceAcceptable(luminance: number, threshold: number): boolean {\n return luminance >= threshold;\n}\n\n/**\n * Error raised when a captured frame is too dark to be analysed reliably.\n * Carries the measured luminance and the threshold it failed so callers can\n * surface actionable feedback.\n */\nexport class LowLuminanceError extends Error {\n /** Measured mean luminance, `0..255`. */\n readonly luminance: number;\n /** Threshold that was checked against, `0..255`. */\n readonly threshold: number;\n\n /**\n * @param luminance - the measured mean luminance in `0..255`.\n * @param threshold - the threshold the measurement failed to reach.\n */\n constructor(luminance: number, threshold: number) {\n super(\"Image is too dark to analyse. Capture again in a brighter environment.\");\n this.name = \"LowLuminanceError\";\n this.luminance = luminance;\n this.threshold = threshold;\n }\n}\n"],"mappings":";AAiBA,IAAa,IAA4B;AAuBzC,SAAS,EAAW,GAA4D;CAU5E,OATI,aAAkB,mBACX;EAAE,OAAO,EAAO;EAAY,QAAQ,EAAO;CAAY,IAE9D,aAAkB,mBACX;EACH,OAAO,EAAO,gBAAgB,EAAO;EACrC,QAAQ,EAAO,iBAAiB,EAAO;CAC3C,IAEG;EAAE,OAAO,EAAO;EAAO,QAAQ,EAAO;CAAO;AACxD;AAmBA,SAAgB,EACZ,GACA,GACM;CACN,IAAM,EAAE,OAAO,GAAM,QAAQ,MAAS,EAAW,CAAM;CACvD,IAAI,MAAS,KAAK,MAAS,GAAG,OAAO;CAErC,IAAM,IAAQ,KAAK,IAAI,GAAA,MAA+B,KAAK,IAAI,GAAM,CAAI,CAAC,GACpE,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,IAAO,CAAK,CAAC,GACxC,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,IAAO,CAAK,CAAC,GAExC,IAAS,KAAkB,SAAS,cAAc,QAAQ;CAEhE,AADA,EAAO,QAAQ,GACf,EAAO,SAAS;CAChB,IAAM,IAAM,EAAO,WAAW,MAAM,EAAE,oBAAoB,GAAK,CAAC;CAChE,IAAI,CAAC,GAAK,OAAO;CACjB,EAAI,UAAU,GAAQ,GAAG,GAAG,GAAG,CAAC;CAEhC,IAAM,IAAO,EAAI,aAAa,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,MACtC,IAAM,GACJ,IAAa,IAAI;CACvB,KAAK,IAAI,IAAI,GAAG,IAAI,EAAK,QAAQ,KAAK,GAClC,KAAO,QAAS,EAAK,KAAK,QAAS,EAAK,IAAI,KAAK,QAAS,EAAK,IAAI;CAEvE,OAAO,IAAM;AACjB;AAcA,SAAgB,EAAsB,GAAmB,GAA4B;CACjF,OAAO,KAAa;AACxB;AAOA,IAAa,IAAb,cAAuC,MAAM;CAEzC;CAEA;CAMA,YAAY,GAAmB,GAAmB;EAI9C,AAHA,MAAM,wEAAwE,GAC9E,KAAK,OAAO,qBACZ,KAAK,YAAY,GACjB,KAAK,YAAY;CACrB;AACJ"}
1
+ {"version":3,"file":"luminance.js","names":[],"sources":["../../src/vision/luminance.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Frame-brightness helpers — measure the mean luminance of an already-decoded\n * frame (`<img>`, `<video>`, `<canvas>`, `ImageBitmap` or `OffscreenCanvas`) so\n * a UI can reject underexposed captures before paying the cost of downstream\n * inference.\n *\n * These are framework-agnostic pure functions; {@link useLiveLuminance} wires\n * {@link computeImageLuminance} into a React `requestAnimationFrame` loop for\n * live camera feedback.\n */\n\n/**\n * Longest edge (in pixels) the source is downsampled to before sampling.\n * Averaging over a small downsample is statistically equivalent for a\n * brightness threshold and orders of magnitude faster than reading every pixel\n * of a full-resolution camera frame.\n */\nexport const LUMINANCE_SAMPLE_MAX_EDGE = 256;\n\n/**\n * Drawable source we can sample luminance from.\n *\n * The list tracks what `CanvasRenderingContext2D.drawImage` accepts and we can\n * read a pixel size off, which is what the implementation actually needs.\n * `ImageBitmap` matters for the decode-downscaled path: `createImageBitmap(blob,\n * { resizeWidth })` is how a caller avoids materialising a full-resolution\n * phone photo, and the frame it hands back is the frame whose brightness has to\n * be checked.\n */\nexport type LuminanceSource =\n HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas;\n\n/**\n * Natural pixel size of the source (`0`/`0` while it is still unloaded).\n *\n * `ImageBitmap` and `OffscreenCanvas` both expose plain `width`/`height`, so\n * they fall through to the same branch as a canvas — but they are named\n * explicitly rather than left to the `naturalWidth || width` fallback, which\n * only reads as intentional for an `<img>`.\n */\nfunction sourceSize(source: LuminanceSource): { width: number; height: number } {\n if (source instanceof HTMLVideoElement) {\n return { width: source.videoWidth, height: source.videoHeight };\n }\n if (source instanceof HTMLImageElement) {\n return {\n width: source.naturalWidth || source.width,\n height: source.naturalHeight || source.height,\n };\n }\n return { width: source.width, height: source.height };\n}\n\n/**\n * Mean BT.709 luminance (`0.2126*R + 0.7152*G + 0.0722*B`) of a decoded frame,\n * scaled to `0..255`. See {@link LuminanceSource} for what counts as one.\n *\n * The source is downsampled so its longest edge is at most\n * {@link LUMINANCE_SAMPLE_MAX_EDGE} before pixels are read. The 2D context is\n * created with `willReadFrequently` so repeated sampling (live feedback) stays\n * on the fast path.\n *\n * Pass `reusableCanvas` to avoid allocating a fresh canvas every frame in a hot\n * loop; when omitted a one-shot detached canvas is created.\n *\n * @param source - the decoded frame to sample.\n * @param reusableCanvas - optional canvas reused across frames to avoid GC churn.\n * @returns The mean luminance in `0..255`, or `0` when the source is unloaded\n * (zero-sized) or a 2D context is unavailable.\n */\nexport function computeImageLuminance(\n source: LuminanceSource,\n reusableCanvas?: HTMLCanvasElement,\n): number {\n const { width: srcW, height: srcH } = sourceSize(source);\n if (srcW === 0 || srcH === 0) return 0;\n\n const scale = Math.min(1, LUMINANCE_SAMPLE_MAX_EDGE / Math.max(srcW, srcH));\n const w = Math.max(1, Math.round(srcW * scale));\n const h = Math.max(1, Math.round(srcH * scale));\n\n const canvas = reusableCanvas ?? document.createElement(\"canvas\");\n canvas.width = w;\n canvas.height = h;\n const ctx = canvas.getContext(\"2d\", { willReadFrequently: true });\n if (!ctx) return 0;\n ctx.drawImage(source, 0, 0, w, h);\n\n const data = ctx.getImageData(0, 0, w, h).data;\n let sum = 0;\n const pixelCount = w * h;\n for (let i = 0; i < data.length; i += 4) {\n sum += 0.2126 * data[i] + 0.7152 * data[i + 1] + 0.0722 * data[i + 2];\n }\n return sum / pixelCount;\n}\n\n/**\n * Whether a measured luminance clears a brightness threshold.\n *\n * `threshold` is intentionally required — a sensible value is\n * application-specific (it depends on the model, the lighting the model was\n * trained on, and the acceptable false-reject rate), so the SDK does not bake\n * in a default.\n *\n * @param luminance - measured mean luminance in `0..255`.\n * @param threshold - minimum acceptable luminance in `0..255`.\n * @returns `true` when `luminance >= threshold`.\n */\nexport function isLuminanceAcceptable(luminance: number, threshold: number): boolean {\n return luminance >= threshold;\n}\n\n/**\n * Error raised when a captured frame is too dark to be analysed reliably.\n * Carries the measured luminance and the threshold it failed so callers can\n * surface actionable feedback.\n */\nexport class LowLuminanceError extends Error {\n /** Measured mean luminance, `0..255`. */\n readonly luminance: number;\n /** Threshold that was checked against, `0..255`. */\n readonly threshold: number;\n\n /**\n * @param luminance - the measured mean luminance in `0..255`.\n * @param threshold - the threshold the measurement failed to reach.\n */\n constructor(luminance: number, threshold: number) {\n super(\"Image is too dark to analyse. Capture again in a brighter environment.\");\n this.name = \"LowLuminanceError\";\n this.luminance = luminance;\n this.threshold = threshold;\n }\n}\n"],"mappings":";AAkBA,IAAa,IAA4B;AAuBzC,SAAS,EAAW,GAA4D;CAU5E,OATI,aAAkB,mBACX;EAAE,OAAO,EAAO;EAAY,QAAQ,EAAO;CAAY,IAE9D,aAAkB,mBACX;EACH,OAAO,EAAO,gBAAgB,EAAO;EACrC,QAAQ,EAAO,iBAAiB,EAAO;CAC3C,IAEG;EAAE,OAAO,EAAO;EAAO,QAAQ,EAAO;CAAO;AACxD;AAmBA,SAAgB,EACZ,GACA,GACM;CACN,IAAM,EAAE,OAAO,GAAM,QAAQ,MAAS,EAAW,CAAM;CACvD,IAAI,MAAS,KAAK,MAAS,GAAG,OAAO;CAErC,IAAM,IAAQ,KAAK,IAAI,GAAA,MAA+B,KAAK,IAAI,GAAM,CAAI,CAAC,GACpE,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,IAAO,CAAK,CAAC,GACxC,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,IAAO,CAAK,CAAC,GAExC,IAAS,KAAkB,SAAS,cAAc,QAAQ;CAEhE,AADA,EAAO,QAAQ,GACf,EAAO,SAAS;CAChB,IAAM,IAAM,EAAO,WAAW,MAAM,EAAE,oBAAoB,GAAK,CAAC;CAChE,IAAI,CAAC,GAAK,OAAO;CACjB,EAAI,UAAU,GAAQ,GAAG,GAAG,GAAG,CAAC;CAEhC,IAAM,IAAO,EAAI,aAAa,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,MACtC,IAAM,GACJ,IAAa,IAAI;CACvB,KAAK,IAAI,IAAI,GAAG,IAAI,EAAK,QAAQ,KAAK,GAClC,KAAO,QAAS,EAAK,KAAK,QAAS,EAAK,IAAI,KAAK,QAAS,EAAK,IAAI;CAEvE,OAAO,IAAM;AACjB;AAcA,SAAgB,EAAsB,GAAmB,GAA4B;CACjF,OAAO,KAAa;AACxB;AAOA,IAAa,IAAb,cAAuC,MAAM;CAEzC;CAEA;CAMA,YAAY,GAAmB,GAAmB;EAI9C,AAHA,MAAM,wEAAwE,GAC9E,KAAK,OAAO,qBACZ,KAAK,YAAY,GACjB,KAAK,YAAY;CACrB;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"classification.cjs","names":[],"sources":["../../../src/vision/postprocess/classification.ts"],"sourcesContent":["/**\n * Classification head postprocessing — softmax + top-k.\n */\n\n/** Apply numerically-stable softmax to a 1-D vector of logits. */\nexport function softmax(logits: Float32Array | readonly number[]): Float32Array {\n const n = logits.length;\n const out = new Float32Array(n);\n let max = -Infinity;\n for (let i = 0; i < n; i++) {\n const v = logits[i] as number;\n if (v > max) max = v;\n }\n let sum = 0;\n for (let i = 0; i < n; i++) {\n const e = Math.exp((logits[i] as number) - max);\n out[i] = e;\n sum += e;\n }\n for (let i = 0; i < n; i++) {\n out[i] = (out[i] as number) / sum;\n }\n return out;\n}\n\nexport interface TopKResult {\n readonly indices: Int32Array;\n readonly values: Float32Array;\n}\n\n/**\n * Return the top-k entries of a 1-D probability vector, sorted descending.\n *\n * @param k Number of entries to return; `null` returns all entries.\n */\nexport function topK(probabilities: Float32Array, k: number | null): TopKResult {\n const n = probabilities.length;\n const kEff = k === null ? n : Math.min(Math.max(0, k), n);\n\n const idx = new Array<number>(n);\n for (let i = 0; i < n; i++) idx[i] = i;\n idx.sort((a, b) => (probabilities[b] as number) - (probabilities[a] as number));\n\n const indices = new Int32Array(kEff);\n const values = new Float32Array(kEff);\n for (let i = 0; i < kEff; i++) {\n const j = idx[i] as number;\n indices[i] = j;\n values[i] = probabilities[j] as number;\n }\n return { indices, values };\n}\n"],"mappings":"AAKA,SAAgB,EAAQ,EAAwD,CAC5E,IAAM,EAAI,EAAO,OACX,EAAM,IAAI,aAAa,CAAC,EAC1B,EAAM,KACV,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,CACxB,IAAM,EAAI,EAAO,GACb,EAAI,IAAK,EAAM,EACvB,CACA,IAAI,EAAM,EACV,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,CACxB,IAAM,EAAI,KAAK,IAAK,EAAO,GAAgB,CAAG,EAC9C,EAAI,GAAK,EACT,GAAO,CACX,CACA,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IACnB,EAAI,GAAM,EAAI,GAAgB,EAElC,OAAO,CACX,CAYA,SAAgB,EAAK,EAA6B,EAA8B,CAC5E,IAAM,EAAI,EAAc,OAClB,EAAO,IAAM,KAAO,EAAI,KAAK,IAAI,KAAK,IAAI,EAAG,CAAC,EAAG,CAAC,EAElD,EAAU,MAAc,CAAC,EAC/B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,EAAI,GAAK,EACrC,EAAI,MAAM,EAAG,IAAO,EAAc,GAAiB,EAAc,EAAa,EAE9E,IAAM,EAAU,IAAI,WAAW,CAAI,EAC7B,EAAS,IAAI,aAAa,CAAI,EACpC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,IAAK,CAC3B,IAAM,EAAI,EAAI,GACd,EAAQ,GAAK,EACb,EAAO,GAAK,EAAc,EAC9B,CACA,MAAO,CAAE,UAAS,QAAO,CAC7B"}
1
+ {"version":3,"file":"classification.cjs","names":[],"sources":["../../../src/vision/postprocess/classification.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Classification head postprocessing — softmax + top-k.\n */\n\n/** Apply numerically-stable softmax to a 1-D vector of logits. */\nexport function softmax(logits: Float32Array | readonly number[]): Float32Array {\n const n = logits.length;\n const out = new Float32Array(n);\n let max = -Infinity;\n for (let i = 0; i < n; i++) {\n const v = logits[i] as number;\n if (v > max) max = v;\n }\n let sum = 0;\n for (let i = 0; i < n; i++) {\n const e = Math.exp((logits[i] as number) - max);\n out[i] = e;\n sum += e;\n }\n for (let i = 0; i < n; i++) {\n out[i] = (out[i] as number) / sum;\n }\n return out;\n}\n\nexport interface TopKResult {\n readonly indices: Int32Array;\n readonly values: Float32Array;\n}\n\n/**\n * Return the top-k entries of a 1-D probability vector, sorted descending.\n *\n * @param k Number of entries to return; `null` returns all entries.\n */\nexport function topK(probabilities: Float32Array, k: number | null): TopKResult {\n const n = probabilities.length;\n const kEff = k === null ? n : Math.min(Math.max(0, k), n);\n\n const idx = new Array<number>(n);\n for (let i = 0; i < n; i++) idx[i] = i;\n idx.sort((a, b) => (probabilities[b] as number) - (probabilities[a] as number));\n\n const indices = new Int32Array(kEff);\n const values = new Float32Array(kEff);\n for (let i = 0; i < kEff; i++) {\n const j = idx[i] as number;\n indices[i] = j;\n values[i] = probabilities[j] as number;\n }\n return { indices, values };\n}\n"],"mappings":"AAMA,SAAgB,EAAQ,EAAwD,CAC5E,IAAM,EAAI,EAAO,OACX,EAAM,IAAI,aAAa,CAAC,EAC1B,EAAM,KACV,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,CACxB,IAAM,EAAI,EAAO,GACb,EAAI,IAAK,EAAM,EACvB,CACA,IAAI,EAAM,EACV,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,CACxB,IAAM,EAAI,KAAK,IAAK,EAAO,GAAgB,CAAG,EAC9C,EAAI,GAAK,EACT,GAAO,CACX,CACA,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IACnB,EAAI,GAAM,EAAI,GAAgB,EAElC,OAAO,CACX,CAYA,SAAgB,EAAK,EAA6B,EAA8B,CAC5E,IAAM,EAAI,EAAc,OAClB,EAAO,IAAM,KAAO,EAAI,KAAK,IAAI,KAAK,IAAI,EAAG,CAAC,EAAG,CAAC,EAElD,EAAU,MAAc,CAAC,EAC/B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,EAAI,GAAK,EACrC,EAAI,MAAM,EAAG,IAAO,EAAc,GAAiB,EAAc,EAAa,EAE9E,IAAM,EAAU,IAAI,WAAW,CAAI,EAC7B,EAAS,IAAI,aAAa,CAAI,EACpC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,IAAK,CAC3B,IAAM,EAAI,EAAI,GACd,EAAQ,GAAK,EACb,EAAO,GAAK,EAAc,EAC9B,CACA,MAAO,CAAE,UAAS,QAAO,CAC7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"classification.js","names":[],"sources":["../../../src/vision/postprocess/classification.ts"],"sourcesContent":["/**\n * Classification head postprocessing — softmax + top-k.\n */\n\n/** Apply numerically-stable softmax to a 1-D vector of logits. */\nexport function softmax(logits: Float32Array | readonly number[]): Float32Array {\n const n = logits.length;\n const out = new Float32Array(n);\n let max = -Infinity;\n for (let i = 0; i < n; i++) {\n const v = logits[i] as number;\n if (v > max) max = v;\n }\n let sum = 0;\n for (let i = 0; i < n; i++) {\n const e = Math.exp((logits[i] as number) - max);\n out[i] = e;\n sum += e;\n }\n for (let i = 0; i < n; i++) {\n out[i] = (out[i] as number) / sum;\n }\n return out;\n}\n\nexport interface TopKResult {\n readonly indices: Int32Array;\n readonly values: Float32Array;\n}\n\n/**\n * Return the top-k entries of a 1-D probability vector, sorted descending.\n *\n * @param k Number of entries to return; `null` returns all entries.\n */\nexport function topK(probabilities: Float32Array, k: number | null): TopKResult {\n const n = probabilities.length;\n const kEff = k === null ? n : Math.min(Math.max(0, k), n);\n\n const idx = new Array<number>(n);\n for (let i = 0; i < n; i++) idx[i] = i;\n idx.sort((a, b) => (probabilities[b] as number) - (probabilities[a] as number));\n\n const indices = new Int32Array(kEff);\n const values = new Float32Array(kEff);\n for (let i = 0; i < kEff; i++) {\n const j = idx[i] as number;\n indices[i] = j;\n values[i] = probabilities[j] as number;\n }\n return { indices, values };\n}\n"],"mappings":";AAKA,SAAgB,EAAQ,GAAwD;CAC5E,IAAM,IAAI,EAAO,QACX,IAAM,IAAI,aAAa,CAAC,GAC1B,IAAM;CACV,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;EACxB,IAAM,IAAI,EAAO;EACjB,AAAI,IAAI,MAAK,IAAM;CACvB;CACA,IAAI,IAAM;CACV,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;EACxB,IAAM,IAAI,KAAK,IAAK,EAAO,KAAgB,CAAG;EAE9C,AADA,EAAI,KAAK,GACT,KAAO;CACX;CACA,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KACnB,EAAI,KAAM,EAAI,KAAgB;CAElC,OAAO;AACX;AAYA,SAAgB,EAAK,GAA6B,GAA8B;CAC5E,IAAM,IAAI,EAAc,QAClB,IAAO,MAAM,OAAO,IAAI,KAAK,IAAI,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC,GAElD,IAAU,MAAc,CAAC;CAC/B,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK,EAAI,KAAK;CACrC,EAAI,MAAM,GAAG,MAAO,EAAc,KAAiB,EAAc,EAAa;CAE9E,IAAM,IAAU,IAAI,WAAW,CAAI,GAC7B,IAAS,IAAI,aAAa,CAAI;CACpC,KAAK,IAAI,IAAI,GAAG,IAAI,GAAM,KAAK;EAC3B,IAAM,IAAI,EAAI;EAEd,AADA,EAAQ,KAAK,GACb,EAAO,KAAK,EAAc;CAC9B;CACA,OAAO;EAAE;EAAS;CAAO;AAC7B"}
1
+ {"version":3,"file":"classification.js","names":[],"sources":["../../../src/vision/postprocess/classification.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Classification head postprocessing — softmax + top-k.\n */\n\n/** Apply numerically-stable softmax to a 1-D vector of logits. */\nexport function softmax(logits: Float32Array | readonly number[]): Float32Array {\n const n = logits.length;\n const out = new Float32Array(n);\n let max = -Infinity;\n for (let i = 0; i < n; i++) {\n const v = logits[i] as number;\n if (v > max) max = v;\n }\n let sum = 0;\n for (let i = 0; i < n; i++) {\n const e = Math.exp((logits[i] as number) - max);\n out[i] = e;\n sum += e;\n }\n for (let i = 0; i < n; i++) {\n out[i] = (out[i] as number) / sum;\n }\n return out;\n}\n\nexport interface TopKResult {\n readonly indices: Int32Array;\n readonly values: Float32Array;\n}\n\n/**\n * Return the top-k entries of a 1-D probability vector, sorted descending.\n *\n * @param k Number of entries to return; `null` returns all entries.\n */\nexport function topK(probabilities: Float32Array, k: number | null): TopKResult {\n const n = probabilities.length;\n const kEff = k === null ? n : Math.min(Math.max(0, k), n);\n\n const idx = new Array<number>(n);\n for (let i = 0; i < n; i++) idx[i] = i;\n idx.sort((a, b) => (probabilities[b] as number) - (probabilities[a] as number));\n\n const indices = new Int32Array(kEff);\n const values = new Float32Array(kEff);\n for (let i = 0; i < kEff; i++) {\n const j = idx[i] as number;\n indices[i] = j;\n values[i] = probabilities[j] as number;\n }\n return { indices, values };\n}\n"],"mappings":";AAMA,SAAgB,EAAQ,GAAwD;CAC5E,IAAM,IAAI,EAAO,QACX,IAAM,IAAI,aAAa,CAAC,GAC1B,IAAM;CACV,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;EACxB,IAAM,IAAI,EAAO;EACjB,AAAI,IAAI,MAAK,IAAM;CACvB;CACA,IAAI,IAAM;CACV,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;EACxB,IAAM,IAAI,KAAK,IAAK,EAAO,KAAgB,CAAG;EAE9C,AADA,EAAI,KAAK,GACT,KAAO;CACX;CACA,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KACnB,EAAI,KAAM,EAAI,KAAgB;CAElC,OAAO;AACX;AAYA,SAAgB,EAAK,GAA6B,GAA8B;CAC5E,IAAM,IAAI,EAAc,QAClB,IAAO,MAAM,OAAO,IAAI,KAAK,IAAI,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC,GAElD,IAAU,MAAc,CAAC;CAC/B,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK,EAAI,KAAK;CACrC,EAAI,MAAM,GAAG,MAAO,EAAc,KAAiB,EAAc,EAAa;CAE9E,IAAM,IAAU,IAAI,WAAW,CAAI,GAC7B,IAAS,IAAI,aAAa,CAAI;CACpC,KAAK,IAAI,IAAI,GAAG,IAAI,GAAM,KAAK;EAC3B,IAAM,IAAI,EAAI;EAEd,AADA,EAAQ,KAAK,GACb,EAAO,KAAK,EAAc;CAC9B;CACA,OAAO;EAAE;EAAS;CAAO;AAC7B"}
@@ -1,2 +1,2 @@
1
- const e=require("../types.cjs");function t(e,t,n){let r=t.length;if(r===0)return new Int32Array;let i=new Float32Array(r);for(let t=0;t<r;t++){let n=e[t*4],r=e[t*4+1],a=e[t*4+2],o=e[t*4+3];i[t]=Math.max(0,a-n)*Math.max(0,o-r)}let a=Array(r);for(let e=0;e<r;e++)a[e]=e;a.sort((e,n)=>t[n]-t[e]);let o=new Uint8Array(r),s=[];for(let t=0;t<a.length;t++){let r=a[t];if(o[r])continue;s.push(r);let c=e[r*4],l=e[r*4+1],u=e[r*4+2],d=e[r*4+3],f=i[r];for(let r=t+1;r<a.length;r++){let t=a[r];if(o[t])continue;let s=e[t*4],p=e[t*4+1],m=e[t*4+2],h=e[t*4+3],g=Math.max(c,s),_=Math.max(l,p),v=Math.min(u,m),y=Math.min(d,h),b=Math.max(0,v-g)*Math.max(0,y-_),x=f+i[t]-b;(x>0?b/x:0)>n&&(o[t]=1)}}return Int32Array.from(s)}function n(e,n,r,i){if(n.length===0)return new Int32Array;let a=new Map;for(let e=0;e<r.length;e++){let t=r[e],n=a.get(t);n===void 0?a.set(t,[e]):n.push(e)}let o=[];for(let r of a.values()){let a=r.length,s=new Float32Array(a*4),c=new Float32Array(a);for(let t=0;t<a;t++){let i=r[t];s[t*4]=e[i*4],s[t*4+1]=e[i*4+1],s[t*4+2]=e[i*4+2],s[t*4+3]=e[i*4+3],c[t]=n[i]}let l=t(s,c,i);for(let e=0;e<l.length;e++)o.push(r[l[e]])}return o.sort((e,t)=>n[t]-n[e]),Int32Array.from(o)}function r(e,t,r){let a=t;if(a.length===3){if(a[0]!==1)throw Error(`decodeYoloAnchors: expected batch size 1, got ${a[0]}.`);a=[a[1],a[2]]}if(a.length!==2)throw Error(`decodeYoloAnchors: expected 2-D output after batch removal, got dims=${JSON.stringify(t)}.`);let o=a[0],s=a[1],{numClasses:c,originalWidth:l,originalHeight:u,padLeft:d,padTop:f,scale:p,confThreshold:m,iouThreshold:h,maxDetections:g}=r;if(c<1||c+4>o)throw Error(`decodeYoloAnchors: invalid numClasses=${c} for channels=${o}.`);if(e.length!==o*s)throw Error(`decodeYoloAnchors: data length ${e.length} does not match channels*numAnchors=${o*s}.`);let _=[];for(let t=0;t<s;t++){let n=0,r=-1/0;for(let i=0;i<c;i++){let a=e[(4+i)*s+t];a!==void 0&&a>r&&(r=a,n=i)}if(r<m)continue;let i=e[t],a=e[s+t],o=e[2*s+t],h=e[3*s+t],g=i-o/2,v=a-h/2,y=i+o/2,b=a+h/2;g=(g-d)/p,v=(v-f)/p,y=(y-d)/p,b=(b-f)/p,g=Math.max(0,Math.min(l,g)),v=Math.max(0,Math.min(u,v)),y=Math.max(0,Math.min(l,y)),b=Math.max(0,Math.min(u,b)),_.push({anchorIdx:t,x1:g,y1:v,x2:y,y2:b,classId:n,confidence:r})}if(_.length===0)return i();let v=new Float32Array(_.length*4),y=new Float32Array(_.length),b=new Int32Array(_.length);for(let e=0;e<_.length;e++){let t=_[e];v[e*4]=t.x1,v[e*4+1]=t.y1,v[e*4+2]=t.x2,v[e*4+3]=t.y2,y[e]=t.confidence,b[e]=t.classId}let x=n(v,y,b,h);if(x.length===0)return i();let S=Array.from(x).slice(0,g),C=S.length,w=new Int32Array(C),T=new Float32Array(C*4),E=new Int32Array(C),D=new Float32Array(C);for(let e=0;e<C;e++){let t=_[S[e]];w[e]=t.anchorIdx,T[e*4]=t.x1,T[e*4+1]=t.y1,T[e*4+2]=t.x2,T[e*4+3]=t.y2,E[e]=t.classId,D[e]=t.confidence}return{anchorIndices:w,boxesXyxy:T,classIds:E,confidences:D}}function i(){return{anchorIndices:new Int32Array,boxesXyxy:new Float32Array,classIds:new Int32Array,confidences:new Float32Array}}function a(t,n,i){let a=n.length===3?n[1]:n[0];if(a===void 0||a<5)throw Error(`decodeYolo: invalid output channel count ${a} (expected >= 5).`);let o=r(t,n,{numClasses:a-4,...i}),s=[];for(let t=0;t<o.classIds.length;t++)s.push({bbox:new e.BoundingBox(o.boxesXyxy[t*4],o.boxesXyxy[t*4+1],o.boxesXyxy[t*4+2],o.boxesXyxy[t*4+3]),classId:o.classIds[t],confidence:o.confidences[t]});return s}var o=!1,s=!1;function c(e,t,n){return o||(o=!0,console.warn(`[@ort-vision-sdk/web] decodeYoloV8 is deprecated since 0.2.0; use decodeYolo. The alias will be removed in 0.4.0.`)),a(e,t,n)}function l(e,t,n){return s||(s=!0,console.warn(`[@ort-vision-sdk/web] decodeYoloV8Anchors is deprecated since 0.2.0; use decodeYoloAnchors. The alias will be removed in 0.4.0.`)),r(e,t,n)}exports.batchedNms=n,exports.decodeYolo=a,exports.decodeYoloAnchors=r,exports.decodeYoloV8=c,exports.decodeYoloV8Anchors=l,exports.nms=t;
1
+ const e=require("../types.cjs");function t(e,t,n){let r=t.length;if(r===0)return new Int32Array;let i=new Float32Array(r);for(let t=0;t<r;t++){let n=e[t*4],r=e[t*4+1],a=e[t*4+2],o=e[t*4+3];i[t]=Math.max(0,a-n)*Math.max(0,o-r)}let a=Array(r);for(let e=0;e<r;e++)a[e]=e;a.sort((e,n)=>t[n]-t[e]||e-n);let o=new Uint8Array(r),s=[];for(let t=0;t<a.length;t++){let r=a[t];if(o[r])continue;s.push(r);let c=e[r*4],l=e[r*4+1],u=e[r*4+2],d=e[r*4+3],f=i[r];for(let r=t+1;r<a.length;r++){let t=a[r];if(o[t])continue;let s=e[t*4],p=e[t*4+1],m=e[t*4+2],h=e[t*4+3],g=Math.max(c,s),_=Math.max(l,p),v=Math.min(u,m),y=Math.min(d,h),b=Math.max(0,v-g)*Math.max(0,y-_),x=f+i[t]-b;(x>0?b/x:0)>n&&(o[t]=1)}}return Int32Array.from(s)}function n(e,n,r,i){if(n.length===0)return new Int32Array;let a=new Map;for(let e=0;e<r.length;e++){let t=r[e],n=a.get(t);n===void 0?a.set(t,[e]):n.push(e)}let o=[];for(let r of a.values()){let a=r.length,s=new Float32Array(a*4),c=new Float32Array(a);for(let t=0;t<a;t++){let i=r[t];s[t*4]=e[i*4],s[t*4+1]=e[i*4+1],s[t*4+2]=e[i*4+2],s[t*4+3]=e[i*4+3],c[t]=n[i]}let l=t(s,c,i);for(let e=0;e<l.length;e++)o.push(r[l[e]])}return o.sort((e,t)=>n[t]-n[e]||e-t),Int32Array.from(o)}function r(e,t,r){let a=t;if(a.length===3){if(a[0]!==1)throw Error(`decodeYoloAnchors: expected batch size 1, got ${a[0]}.`);a=[a[1],a[2]]}if(a.length!==2)throw Error(`decodeYoloAnchors: expected 2-D output after batch removal, got dims=${JSON.stringify(t)}.`);let o=a[0],s=a[1],{numClasses:c,originalWidth:l,originalHeight:u,padLeft:d,padTop:f,scale:p,confThreshold:m,iouThreshold:h,maxDetections:g}=r;if(c<1||c+4>o)throw Error(`decodeYoloAnchors: invalid numClasses=${c} for channels=${o}.`);if(e.length!==o*s)throw Error(`decodeYoloAnchors: data length ${e.length} does not match channels*numAnchors=${o*s}.`);let _=[];for(let t=0;t<s;t++){let n=0,r=-1/0;for(let i=0;i<c;i++){let a=e[(4+i)*s+t];a!==void 0&&a>r&&(r=a,n=i)}if(r<m)continue;let i=e[t],a=e[s+t],o=e[2*s+t],h=e[3*s+t],g=i-o/2,v=a-h/2,y=i+o/2,b=a+h/2;g=(g-d)/p,v=(v-f)/p,y=(y-d)/p,b=(b-f)/p,g=Math.max(0,Math.min(l,g)),v=Math.max(0,Math.min(u,v)),y=Math.max(0,Math.min(l,y)),b=Math.max(0,Math.min(u,b)),_.push({anchorIdx:t,x1:g,y1:v,x2:y,y2:b,classId:n,confidence:r})}if(_.length===0)return i();let v=new Float32Array(_.length*4),y=new Float32Array(_.length),b=new Int32Array(_.length);for(let e=0;e<_.length;e++){let t=_[e];v[e*4]=t.x1,v[e*4+1]=t.y1,v[e*4+2]=t.x2,v[e*4+3]=t.y2,y[e]=t.confidence,b[e]=t.classId}let x=n(v,y,b,h);if(x.length===0)return i();let S=Array.from(x).slice(0,g),C=S.length,w=new Int32Array(C),T=new Float32Array(C*4),E=new Int32Array(C),D=new Float32Array(C);for(let e=0;e<C;e++){let t=_[S[e]];w[e]=t.anchorIdx,T[e*4]=t.x1,T[e*4+1]=t.y1,T[e*4+2]=t.x2,T[e*4+3]=t.y2,E[e]=t.classId,D[e]=t.confidence}return{anchorIndices:w,boxesXyxy:T,classIds:E,confidences:D}}function i(){return{anchorIndices:new Int32Array,boxesXyxy:new Float32Array,classIds:new Int32Array,confidences:new Float32Array}}function a(t,n,i){let a=n.length===3?n[1]:n[0];if(a===void 0||a<5)throw Error(`decodeYolo: invalid output channel count ${a} (expected >= 5).`);let o=r(t,n,{numClasses:a-4,...i}),s=[];for(let t=0;t<o.classIds.length;t++)s.push({bbox:new e.BoundingBox(o.boxesXyxy[t*4],o.boxesXyxy[t*4+1],o.boxesXyxy[t*4+2],o.boxesXyxy[t*4+3]),classId:o.classIds[t],confidence:o.confidences[t]});return s}exports.batchedNms=n,exports.decodeYolo=a,exports.decodeYoloAnchors=r,exports.nms=t;
2
2
  //# sourceMappingURL=detection.cjs.map