tempest-react-sdk 0.33.2 → 0.35.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.
- package/README.md +5 -3
- package/dist/components/AIChat/AIChat.cjs +2 -0
- package/dist/components/AIChat/AIChat.cjs.map +1 -0
- package/dist/components/AIChat/AIChat.js +141 -0
- package/dist/components/AIChat/AIChat.js.map +1 -0
- package/dist/components/AIChat/AIChat.module.cjs +2 -0
- package/dist/components/AIChat/AIChat.module.cjs.map +1 -0
- package/dist/components/AIChat/AIChat.module.js +58 -0
- package/dist/components/AIChat/AIChat.module.js.map +1 -0
- package/dist/components/AIChat/AIChatComposer.cjs +2 -0
- package/dist/components/AIChat/AIChatComposer.cjs.map +1 -0
- package/dist/components/AIChat/AIChatComposer.js +87 -0
- package/dist/components/AIChat/AIChatComposer.js.map +1 -0
- package/dist/components/AIChat/AIChatTurn.cjs +3 -0
- package/dist/components/AIChat/AIChatTurn.cjs.map +1 -0
- package/dist/components/AIChat/AIChatTurn.js +217 -0
- package/dist/components/AIChat/AIChatTurn.js.map +1 -0
- package/dist/components/AIChat/ai-chat-turns.cjs +2 -0
- package/dist/components/AIChat/ai-chat-turns.cjs.map +1 -0
- package/dist/components/AIChat/ai-chat-turns.js +90 -0
- package/dist/components/AIChat/ai-chat-turns.js.map +1 -0
- package/dist/perf/cache-size.cjs +2 -0
- package/dist/perf/cache-size.cjs.map +1 -0
- package/dist/perf/cache-size.js +16 -0
- package/dist/perf/cache-size.js.map +1 -0
- package/dist/perf/device.cjs +2 -0
- package/dist/perf/device.cjs.map +1 -0
- package/dist/perf/device.js +22 -0
- package/dist/perf/device.js.map +1 -0
- package/dist/perf/format.cjs +2 -0
- package/dist/perf/format.cjs.map +1 -0
- package/dist/perf/format.js +8 -0
- package/dist/perf/format.js.map +1 -0
- package/dist/perf/profiler.cjs +2 -0
- package/dist/perf/profiler.cjs.map +1 -0
- package/dist/perf/profiler.js +46 -0
- package/dist/perf/profiler.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/tempest-react-sdk.cjs +1 -1
- package/dist/tempest-react-sdk.d.ts +626 -9
- package/dist/tempest-react-sdk.js +122 -114
- package/dist/vision/core/timing.cjs +2 -0
- package/dist/vision/core/timing.cjs.map +1 -0
- package/dist/vision/core/timing.js +24 -0
- package/dist/vision/core/timing.js.map +1 -0
- package/dist/vision/index.cjs +1 -1
- package/dist/vision/index.cjs.map +1 -1
- package/dist/vision/index.js +16 -15
- package/dist/vision/index.js.map +1 -1
- package/dist/vision/postprocess/detection.cjs +1 -1
- package/dist/vision/postprocess/detection.cjs.map +1 -1
- package/dist/vision/postprocess/detection.js +2 -2
- package/dist/vision/postprocess/detection.js.map +1 -1
- package/dist/vision/postprocess/segmentation.cjs +1 -1
- package/dist/vision/postprocess/segmentation.cjs.map +1 -1
- package/dist/vision/postprocess/segmentation.js +1 -1
- package/dist/vision/postprocess/segmentation.js.map +1 -1
- package/dist/vision/results.cjs +1 -1
- package/dist/vision/results.cjs.map +1 -1
- package/dist/vision/results.js +18 -13
- package/dist/vision/results.js.map +1 -1
- package/dist/vision/tasks/classifier.cjs +1 -1
- package/dist/vision/tasks/classifier.cjs.map +1 -1
- package/dist/vision/tasks/classifier.js +46 -39
- package/dist/vision/tasks/classifier.js.map +1 -1
- package/dist/vision/tasks/detector.cjs +1 -1
- package/dist/vision/tasks/detector.cjs.map +1 -1
- package/dist/vision/tasks/detector.js +40 -33
- package/dist/vision/tasks/detector.js.map +1 -1
- package/dist/vision/tasks/segmenter.cjs +1 -1
- package/dist/vision/tasks/segmenter.cjs.map +1 -1
- package/dist/vision/tasks/segmenter.js +35 -28
- package/dist/vision/tasks/segmenter.js.map +1 -1
- package/dist/vision.cjs +1 -1
- package/dist/vision.d.ts +68 -10
- package/dist/vision.js +19 -18
- package/dist/ws/create-web-socket.cjs +1 -1
- package/dist/ws/create-web-socket.cjs.map +1 -1
- package/dist/ws/create-web-socket.js +54 -37
- package/dist/ws/create-web-socket.js.map +1 -1
- package/dist/ws/use-web-socket.cjs +1 -1
- package/dist/ws/use-web-socket.cjs.map +1 -1
- package/dist/ws/use-web-socket.js +49 -18
- package/dist/ws/use-web-socket.js.map +1 -1
- package/package.json +1 -1
- package/template/src/lib/api.ts +27 -5
- package/template/src/stores/auth.ts +14 -0
|
@@ -175,117 +175,125 @@ import { SignaturePad as Hn } from "./components/SignaturePad/SignaturePad.js";
|
|
|
175
175
|
import { chatStrings as Un, dayLabel as Wn, groupMessages as Gn, timeLabel as Kn, typingLabel as qn } from "./components/Chat/chat-groups.js";
|
|
176
176
|
import { ChatComposer as Jn } from "./components/Chat/ChatComposer.js";
|
|
177
177
|
import { Chat as Yn } from "./components/Chat/Chat.js";
|
|
178
|
-
import {
|
|
179
|
-
import {
|
|
180
|
-
import {
|
|
181
|
-
import {
|
|
182
|
-
import {
|
|
183
|
-
import {
|
|
184
|
-
import {
|
|
185
|
-
import {
|
|
186
|
-
import {
|
|
187
|
-
import {
|
|
188
|
-
import {
|
|
189
|
-
import {
|
|
190
|
-
import {
|
|
191
|
-
import {
|
|
192
|
-
import {
|
|
193
|
-
import {
|
|
194
|
-
import {
|
|
195
|
-
import {
|
|
196
|
-
import {
|
|
197
|
-
import {
|
|
198
|
-
import {
|
|
199
|
-
import {
|
|
200
|
-
import {
|
|
201
|
-
import {
|
|
202
|
-
import {
|
|
203
|
-
import {
|
|
204
|
-
import {
|
|
205
|
-
import {
|
|
206
|
-
import {
|
|
207
|
-
import {
|
|
208
|
-
import {
|
|
209
|
-
import {
|
|
210
|
-
import {
|
|
211
|
-
import {
|
|
212
|
-
import {
|
|
213
|
-
import {
|
|
214
|
-
import {
|
|
215
|
-
import {
|
|
216
|
-
import {
|
|
217
|
-
import {
|
|
218
|
-
import {
|
|
219
|
-
import {
|
|
220
|
-
import {
|
|
221
|
-
import {
|
|
222
|
-
import {
|
|
223
|
-
import {
|
|
224
|
-
import {
|
|
225
|
-
import {
|
|
226
|
-
import {
|
|
227
|
-
import {
|
|
228
|
-
import {
|
|
229
|
-
import {
|
|
230
|
-
import {
|
|
231
|
-
import {
|
|
232
|
-
import {
|
|
233
|
-
import {
|
|
234
|
-
import {
|
|
235
|
-
import {
|
|
236
|
-
import {
|
|
237
|
-
import {
|
|
238
|
-
import {
|
|
239
|
-
import {
|
|
240
|
-
import {
|
|
241
|
-
import {
|
|
242
|
-
import {
|
|
243
|
-
import {
|
|
244
|
-
import {
|
|
245
|
-
import {
|
|
246
|
-
import {
|
|
247
|
-
import {
|
|
248
|
-
import {
|
|
249
|
-
import {
|
|
250
|
-
import {
|
|
251
|
-
import {
|
|
252
|
-
import {
|
|
253
|
-
import {
|
|
254
|
-
import {
|
|
255
|
-
import {
|
|
256
|
-
import {
|
|
257
|
-
import {
|
|
258
|
-
import {
|
|
259
|
-
import {
|
|
260
|
-
import {
|
|
261
|
-
import {
|
|
262
|
-
import {
|
|
263
|
-
import {
|
|
264
|
-
import {
|
|
265
|
-
import {
|
|
266
|
-
import {
|
|
267
|
-
import {
|
|
268
|
-
import {
|
|
269
|
-
import {
|
|
270
|
-
import {
|
|
271
|
-
import {
|
|
272
|
-
import {
|
|
273
|
-
import {
|
|
274
|
-
import {
|
|
275
|
-
import {
|
|
276
|
-
import {
|
|
277
|
-
import {
|
|
278
|
-
import {
|
|
279
|
-
import {
|
|
280
|
-
import {
|
|
281
|
-
import {
|
|
282
|
-
import {
|
|
283
|
-
import {
|
|
284
|
-
import {
|
|
285
|
-
import {
|
|
286
|
-
import {
|
|
287
|
-
import {
|
|
288
|
-
import {
|
|
289
|
-
import {
|
|
290
|
-
import {
|
|
291
|
-
|
|
178
|
+
import { aiChatStrings as Xn, isGenerating as Zn, lastAssistantId as Qn, roleLabel as $n, tailSignature as er, turnTime as tr, visibleTurns as nr } from "./components/AIChat/ai-chat-turns.js";
|
|
179
|
+
import { AIChatComposer as rr } from "./components/AIChat/AIChatComposer.js";
|
|
180
|
+
import { safeLinkUrl as ir } from "./components/Markdown/markdown-url.js";
|
|
181
|
+
import { parseMarkdown as ar } from "./components/Markdown/markdown-parse.js";
|
|
182
|
+
import { Markdown as or } from "./components/Markdown/Markdown.js";
|
|
183
|
+
import { AIChatTurn as sr } from "./components/AIChat/AIChatTurn.js";
|
|
184
|
+
import { AIChat as cr } from "./components/AIChat/AIChat.js";
|
|
185
|
+
import { applyMove as lr, splitSides as ur } from "./components/Transfer/transfer-state.js";
|
|
186
|
+
import { Transfer as dr } from "./components/Transfer/Transfer.js";
|
|
187
|
+
import { Masonry as fr } from "./components/Masonry/Masonry.js";
|
|
188
|
+
import { Tour as pr } from "./components/Tour/Tour.js";
|
|
189
|
+
import { describeFilter as mr, filtersFromSearchParams as hr, filtersToSearchParams as gr, operatorsFor as _r } from "./components/FilterBar/filter-model.js";
|
|
190
|
+
import { FilterBar as vr } from "./components/FilterBar/FilterBar.js";
|
|
191
|
+
import { formatCPF as yr, formatCurrency as br, formatDate as xr, formatDateTime as Sr, formatPercent as Cr, formatPhone as wr } from "./utils/format.js";
|
|
192
|
+
import { storage as Tr } from "./utils/storage.js";
|
|
193
|
+
import { camelCase as Er, capitalize as Dr, kebabCase as Or, pluralize as kr, slugify as Ar, truncate as jr } from "./utils/strings.js";
|
|
194
|
+
import { chunk as Mr, groupBy as Nr, range as Pr, uniqueBy as Fr } from "./utils/arrays.js";
|
|
195
|
+
import { deepMerge as Ir, isEmpty as Lr, omit as Rr, pick as zr } from "./utils/objects.js";
|
|
196
|
+
import { assertNever as Br, isDefined as Vr, isNumber as Hr, isPlainObject as Ur, isString as Wr } from "./utils/guards.js";
|
|
197
|
+
import { debounce as Gr, memoizeOne as Kr, once as qr, throttle as Jr } from "./utils/functions.js";
|
|
198
|
+
import { sleep as Yr, withTimeout as Xr } from "./utils/promises.js";
|
|
199
|
+
import { randomId as Zr } from "./utils/ids.js";
|
|
200
|
+
import { writeXlsx as Qr } from "./utils/xlsx.js";
|
|
201
|
+
import { TempestApiError as $r, buildApiError as ei, isApiError as ti } from "./http/errors.js";
|
|
202
|
+
import { createApiClient as ni } from "./http/api-client.js";
|
|
203
|
+
import { parseResponse as ri } from "./http/parse-response.js";
|
|
204
|
+
import { uploadWithProgress as ii } from "./http/upload-with-progress.js";
|
|
205
|
+
import { retry as ai } from "./http/retry.js";
|
|
206
|
+
import { generateIdempotencyKey as oi } from "./http/idempotency.js";
|
|
207
|
+
import { usePoll as si } from "./http/use-poll.js";
|
|
208
|
+
import { createAuthStore as ci } from "./auth/create-auth-store.js";
|
|
209
|
+
import { AuthGuard as li } from "./auth/AuthGuard.js";
|
|
210
|
+
import { decodeJWT as ui, isJWTExpired as di } from "./auth/jwt.js";
|
|
211
|
+
import { lazyWithRetry as fi } from "./auth/lazy-with-retry.js";
|
|
212
|
+
import { createRefreshQueue as pi } from "./auth/refresh-queue.js";
|
|
213
|
+
import { createTempestAuth as mi } from "./auth/create-tempest-auth.js";
|
|
214
|
+
import { AccessControlProvider as hi, useAccessControl as gi } from "./access/access-control-context.js";
|
|
215
|
+
import { useCan as _i } from "./access/use-can.js";
|
|
216
|
+
import { Can as vi } from "./access/Can.js";
|
|
217
|
+
import { createRoleAccessControl as yi } from "./access/create-role-access-control.js";
|
|
218
|
+
import { permissionsFromToken as bi } from "./access/permissions-from-token.js";
|
|
219
|
+
import { GoogleSignIn as xi } from "./oauth/GoogleSignIn.js";
|
|
220
|
+
import { useOAuthCallback as Si } from "./oauth/use-oauth-callback.js";
|
|
221
|
+
import { CACHE_TIME as Ci, REFETCH_TIME as wi, STALE_TIME as Ti } from "./query/constants.js";
|
|
222
|
+
import { createQueryKeys as Ei } from "./query/create-query-keys.js";
|
|
223
|
+
import { QueryProvider as Di } from "./query/QueryProvider.js";
|
|
224
|
+
import { emptyOffsetPage as Oi, isCursorPage as ki, isOffsetPage as Ai } from "./query/pagination.js";
|
|
225
|
+
import { usePaginatedQuery as ji } from "./query/use-paginated-query.js";
|
|
226
|
+
import { useCursorQuery as Mi } from "./query/use-cursor-query.js";
|
|
227
|
+
import { useOfflineMutation as Ni } from "./query/use-offline-mutation.js";
|
|
228
|
+
import { removeById as Pi, upsertById as Fi } from "./query/optimistic.js";
|
|
229
|
+
import { createOfflineStore as Ii } from "./offline/create-offline-store.js";
|
|
230
|
+
import { persistQueryClientOffline as Li } from "./query/offline-persistence.js";
|
|
231
|
+
import { createDataProvider as Ri } from "./data/create-data-provider.js";
|
|
232
|
+
import { TempestDataProvider as zi, useDataProvider as Bi } from "./data/data-provider-context.js";
|
|
233
|
+
import { listQueryKey as Vi, oneQueryKey as Hi, useCreate as Ui, useDelete as Wi, useList as Gi, useOne as Ki, useUpdate as qi } from "./data/use-resource.js";
|
|
234
|
+
import { RouteGuard as Ji } from "./router/RouteGuard.js";
|
|
235
|
+
import { AppRouter as Yi, defineRoutes as Xi } from "./router/AppRouter.js";
|
|
236
|
+
import { BrowserRouter as Zi, HashRouter as Qi, Link as $i, MemoryRouter as ea, NavLink as ta, Navigate as na, Outlet as ra, Route as ia, Routes as aa, redirect as oa, useLocation as sa, useMatch as ca, useNavigate as la, useParams as ua, useRouteError as da, useSearchParams as fa } from "./router/index.js";
|
|
237
|
+
import { createStore as pa } from "./store/create-store.js";
|
|
238
|
+
import { createSelectors as ma } from "./store/create-selectors.js";
|
|
239
|
+
import { ThemeProvider as ha, useTheme as ga } from "./theme/ThemeProvider.js";
|
|
240
|
+
import { createI18n as _a } from "./i18n/create-i18n.js";
|
|
241
|
+
import { I18nProvider as va, useI18n as ya, useTranslate as ba } from "./i18n/I18nProvider.js";
|
|
242
|
+
import { ErrorBoundary as xa } from "./error-boundary/ErrorBoundary.js";
|
|
243
|
+
import { AppProviders as Sa } from "./app/AppProviders.js";
|
|
244
|
+
import { createEventStream as Ca } from "./sse/create-event-stream.js";
|
|
245
|
+
import { useEventStream as wa } from "./sse/use-event-stream.js";
|
|
246
|
+
import { isPushSupported as Ta, urlBase64ToUint8Array as Ea } from "./push/utils.js";
|
|
247
|
+
import { WebPushClient as Da, WebPushPermissionDeniedError as Oa, WebPushUnsupportedError as ka } from "./push/web-push-client.js";
|
|
248
|
+
import { usePushSubscription as Aa } from "./push/use-push-subscription.js";
|
|
249
|
+
import { installNotificationClickHandler as ja, installPushHandler as Ma, installSkipWaitingListener as Na } from "./sw/create-push-handler.js";
|
|
250
|
+
import { createPartialResponse as Pa, installPrecache as Fa, installRuntimeCache as Ia } from "./sw/cache.js";
|
|
251
|
+
import { installBackgroundSync as La } from "./sw/background-sync.js";
|
|
252
|
+
import { registerPeriodicSync as Ra } from "./sw/periodic-sync.js";
|
|
253
|
+
import { clearCaches as za, inspectCaches as Ba } from "./sw/cache-inspect.js";
|
|
254
|
+
import { createAudioPlayer as Va, playAudio as Ha, stopAudio as Ua } from "./audio/audio-player.js";
|
|
255
|
+
import { useAudio as Wa } from "./audio/use-audio.js";
|
|
256
|
+
import { createOfflineSync as Ga } from "./offline/create-offline-sync.js";
|
|
257
|
+
import { higherVersionWins as Ka, lastWriteWins as qa } from "./offline/conflict.js";
|
|
258
|
+
import { useErrorHandler as Ja } from "./error-boundary/use-error-handler.js";
|
|
259
|
+
import { FormField as Ya } from "./forms/FormField.js";
|
|
260
|
+
import { validateForm as Xa } from "./forms/validate-form.js";
|
|
261
|
+
import { zodResolver as Za } from "./forms/zod-resolver.js";
|
|
262
|
+
import { useZodForm as Qa } from "./forms/use-zod-form.js";
|
|
263
|
+
import { formatCEP as $a, formatCNPJ as eo, unmask as to, validateCNPJ as no, validateCPF as ro } from "./forms/br-validators.js";
|
|
264
|
+
import { CEPInput as io, CNPJInput as ao, CPFInput as oo, MoneyInput as so, PhoneInput as co } from "./forms/masked-inputs.js";
|
|
265
|
+
import { useViaCEP as lo } from "./forms/use-viacep.js";
|
|
266
|
+
import { Controller as uo, FormProvider as fo, useFieldArray as po, useForm as mo, useFormContext as ho, useFormState as go, useWatch as _o } from "./forms/index.js";
|
|
267
|
+
import { createWebSocket as vo } from "./ws/create-web-socket.js";
|
|
268
|
+
import { useWebSocket as yo } from "./ws/use-web-socket.js";
|
|
269
|
+
import { clampLatitude as bo, isCoordinate as xo, isValidLatitude as So, isValidLongitude as Co, normalizeLongitude as wo } from "./geo/types.js";
|
|
270
|
+
import { EARTH_RADIUS_KM as To, bearingDeg as Eo, haversineKm as Do, pathLengthKm as Oo, toRadians as ko } from "./geo/distance.js";
|
|
271
|
+
import { DEFAULT_CAR_SPEED_KMH as Ao, DEFAULT_CIRCUITY_FACTOR as jo, DEFAULT_MODE_DURATION_FACTORS as Mo, durationFactor as No, estimateTravel as Po } from "./geo/estimate.js";
|
|
272
|
+
import { boundingBox as Fo, boundsCenter as Io, expandBounds as Lo } from "./geo/bounds.js";
|
|
273
|
+
import { MERCATOR_MAX_LATITUDE as Ro, fitProjection as zo, projectMercator as Bo, unprojectMercator as Vo } from "./geo/projection.js";
|
|
274
|
+
import { createOSRMBackend as Ho } from "./geo/routing.js";
|
|
275
|
+
import { createPositionTracker as Uo } from "./geo/create-position-tracker.js";
|
|
276
|
+
import { usePositionTracker as Wo } from "./geo/use-position-tracker.js";
|
|
277
|
+
import { TrajectoryMap as Go } from "./geo/TrajectoryMap.js";
|
|
278
|
+
import { THEME_STYLE_ID as Ko, applyTheme as qo, readThemeToken as Jo } from "./theme/apply-theme.js";
|
|
279
|
+
import { contrastRatio as Yo, createColorScale as Xo, hexToOklch as Zo, hexToRgb as Qo, hexToRgbaString as $o, oklchToHex as es, readableForeground as ts, relativeLuminance as ns, rgbToHex as rs } from "./theme/color.js";
|
|
280
|
+
import { createTheme as is, themeContrast as as } from "./theme/create-theme.js";
|
|
281
|
+
import { getThemePreset as os, themePresets as ss } from "./theme/theme-presets.js";
|
|
282
|
+
import { getInitialTheme as cs, themeInitScript as ls } from "./theme/initial-theme.js";
|
|
283
|
+
import { consoleSink as us, createLogger as ds } from "./logger/logger.js";
|
|
284
|
+
import { TelemetryProvider as fs, useTelemetry as ps } from "./telemetry/TelemetryProvider.js";
|
|
285
|
+
import { consoleTelemetryAdapter as ms } from "./telemetry/console-adapter.js";
|
|
286
|
+
import { createSentryTelemetryAdapter as hs } from "./telemetry/sentry-adapter.js";
|
|
287
|
+
import { createPostHogTelemetryAdapter as gs } from "./telemetry/posthog-adapter.js";
|
|
288
|
+
import { FeatureFlagsProvider as _s, useFeatureFlag as vs, useFlagValue as ys } from "./feature-flags/FeatureFlagsProvider.js";
|
|
289
|
+
import { createInMemoryFlags as bs } from "./feature-flags/in-memory-adapter.js";
|
|
290
|
+
import { createGrowthBookFeatureFlagsAdapter as xs } from "./feature-flags/growthbook-adapter.js";
|
|
291
|
+
import { createLaunchDarklyFeatureFlagsAdapter as Ss } from "./feature-flags/launchdarkly-adapter.js";
|
|
292
|
+
import { isShareSupported as Cs, share as ws } from "./share/share.js";
|
|
293
|
+
import { shareOrDownloadBlob as Ts } from "./share/share-or-download.js";
|
|
294
|
+
import { DIVERGING_STEP_COUNT as Es, ORDINAL_START_STEP as Ds, SEQUENTIAL_STEP_COUNT as Os, divergingScale as ks, scaleSteps as As, sequentialScale as js } from "./charts/scales.js";
|
|
295
|
+
import { cachedResponseBytes as Ms } from "./perf/cache-size.js";
|
|
296
|
+
import { readDeviceProfile as Ns } from "./perf/device.js";
|
|
297
|
+
import { formatDurationMs as Ps } from "./perf/format.js";
|
|
298
|
+
import { createInferenceProfiler as Fs } from "./perf/profiler.js";
|
|
299
|
+
export { cr as AIChat, rr as AIChatComposer, sr as AIChatTurn, hi as AccessControlProvider, t as Accordion, n as Alert, r as AppBar, Sa as AppProviders, Yi as AppRouter, o as AppShell, s as AspectRatio, li as AuthGuard, c as Avatar, l as AvatarGroup, i as BREAKPOINTS, u as Badge, d as Banner, f as BottomNavigation, p as BottomSheet, m as Breadcrumbs, Zi as BrowserRouter, h as Button, Ci as CACHE_TIME, io as CEPInput, ao as CNPJInput, oo as CPFInput, Dn as Calendar, vi as Can, g as Card, Nn as Carousel, _ as Center, Yn as Chat, Jn as ChatComposer, v as Checkbox, y as ChipInput, un as ClickOutside, nn as CodeBlock, xn as Collapsible, b as Combobox, wn as Command, dn as ConditionalWrapper, S as ConfirmDialog, I as Container, Sn as ContextMenu, uo as Controller, Qt as CopyButton, Ao as DEFAULT_CAR_SPEED_KMH, jo as DEFAULT_CIRCUITY_FACTOR, Mo as DEFAULT_MODE_DURATION_FACTORS, Es as DIVERGING_STEP_COUNT, hn as DataList, Pn as DataTable, w as DatePicker, An as DateRangePicker, gn as DescriptionList, T as Divider, E as Drawer, D as DropdownMenu, O as Dropzone, To as EARTH_RADIUS_KM, k as EmptyState, xa as ErrorBoundary, A as ErrorState, pn as ErrorText, _s as FeatureFlagsProvider, j as FileUpload, vr as FilterBar, In as FloatingActionButton, fn as For, M as Form, N as FormActions, Ya as FormField, fo as FormProvider, P as FormRow, F as FormSection, xi as GoogleSignIn, L as Grid, Qi as HashRouter, pt as Hide, Cn as HoverCard, va as I18nProvider, mn as Image, Rt as ImageCropper, C as Input, B as InstallBanner, V as InstallButton, Je as Kanban, Xe as Kbd, bn as Label, Vn as Lightbox, $i as Link, Fn as ListTile, Ro as MERCATOR_MAX_LATITUDE, or as Markdown, fr as Masonry, ea as MemoryRouter, Mn as Menubar, x as Modal, Ze as ModalsProvider, an as Money, so as MoneyInput, kn as MultiSelect, et as NProgressBar, ta as NavLink, $e as Navbar, na as Navigate, jn as NavigationMenu, Ln as NavigationRail, Ht as NotificationCenter, Ds as ORDINAL_START_STEP, Ue as OfflineIndicator, ra as Outlet, nt as Page, rt as Pagination, it as PasswordInput, co as PhoneInput, ot as PinInput, st as Popover, ln as Portal, ct as Progress, qt as QRCapacityError, Zt as QRCode, Di as QueryProvider, wi as REFETCH_TIME, lt as Radio, ut as RadioGroup, dt as RangeSlider, ft as RatingStars, zn as RefreshIndicator, rn as RelativeTime, En as Resizable, ia as Route, Ji as RouteGuard, aa as Routes, Os as SEQUENTIAL_STEP_COUNT, Ti as STALE_TIME, ht as SafeArea, Bt as Scheduler, Tn as ScrollArea, gt as SearchBar, _t as SegmentedControl, vt as Select, mt as Show, yt as Sidebar, Hn as SignaturePad, bt as Skeleton, On as Slider, xt as Spacer, zt as Sparkline, St as Spinner, R as Stack, Ct as Stat, wt as Stepper, Ot as StepperInput, kt as Switch, Ke as SyncStatusBadge, Ko as THEME_STYLE_ID, jt as Table, Mt as Tabs, At as Tag, fs as TelemetryProvider, $r as TempestApiError, zi as TempestDataProvider, Nt as Textarea, ha as ThemeProvider, Rn as TimePicker, Pt as Timeline, It as ToastProvider, _n as Toggle, vn as ToggleGroup, yn as ToggleGroupItem, Ft as Tooltip, pr as Tour, Go as TrajectoryMap, dr as Transfer, on as TreeView, sn as TruncateText, qe as UpdatePrompt, Wt as VirtualList, Kt as VirtualTable, cn as VisuallyHidden, Da as WebPushClient, Oa as WebPushPermissionDeniedError, ka as WebPushUnsupportedError, Bn as Wizard, Xn as aiChatStrings, Ye as applyKanbanMove, qo as applyTheme, lr as applyTransferMove, Br as assertNever, Eo as bearingDeg, Fo as boundingBox, Io as boundsCenter, ei as buildApiError, De as buildOpenInChromeIntent, Ms as cachedResponseBytes, Er as camelCase, Dr as capitalize, Un as chatStrings, Mr as chunk, Tt as clamp, bo as clampLatitude, za as clearCaches, e as cn, Gt as compareValues, us as consoleSink, ms as consoleTelemetryAdapter, Yo as contrastRatio, ni as createApiClient, Va as createAudioPlayer, ci as createAuthStore, Xo as createColorScale, Ri as createDataProvider, Ca as createEventStream, xs as createGrowthBookFeatureFlagsAdapter, _a as createI18n, bs as createInMemoryFlags, Fs as createInferenceProfiler, Ss as createLaunchDarklyFeatureFlagsAdapter, ds as createLogger, Ho as createOSRMBackend, Ii as createOfflineStore, Ga as createOfflineSync, Pa as createPartialResponse, Uo as createPositionTracker, gs as createPostHogTelemetryAdapter, Ei as createQueryKeys, pi as createRefreshQueue, yi as createRoleAccessControl, ma as createSelectors, hs as createSentryTelemetryAdapter, pa as createStore, mi as createTempestAuth, is as createTheme, vo as createWebSocket, Wn as dayLabel, Gr as debounce, ui as decodeJWT, Ir as deepMerge, Xi as defineRoutes, mr as describeFilter, ks as divergingScale, No as durationFactor, Oi as emptyOffsetPage, Jt as encodeQR, at as estimatePasswordStrength, Le as estimateStorage, Po as estimateTravel, Lo as expandBounds, hr as filtersFromSearchParams, gr as filtersToSearchParams, zo as fitProjection, Et as formatBytes, $a as formatCEP, eo as formatCNPJ, yr as formatCPF, Dt as formatCompactNumber, br as formatCurrency, xr as formatDate, Sr as formatDateTime, Ps as formatDurationMs, Cr as formatPercent, wr as formatPhone, oi as generateIdempotencyKey, cs as getInitialTheme, os as getThemePreset, Nr as groupBy, Gn as groupMessages, Do as haversineKm, Zo as hexToOklch, Qo as hexToRgb, $o as hexToRgbaString, Ka as higherVersionWins, Ba as inspectCaches, La as installBackgroundSync, ja as installNotificationClickHandler, Fa as installPrecache, Ma as installPushHandler, Ia as installRuntimeCache, Na as installSkipWaitingListener, Oe as isAndroid, ke as isAndroidWithoutPromptApi, ti as isApiError, xo as isCoordinate, ki as isCursorPage, Vr as isDefined, Lr as isEmpty, Zn as isGenerating, Ae as isIOS, di as isJWTExpired, Hr as isNumber, Ai as isOffsetPage, Ur as isPlainObject, Ta as isPushSupported, Cs as isShareSupported, je as isStandalone, Wr as isString, So as isValidLatitude, Co as isValidLongitude, Or as kebabCase, Qn as lastAssistantId, qa as lastWriteWins, fi as lazyWithRetry, Vi as listQueryKey, Yt as matrixToPath, Kr as memoizeOne, Be as moveItem, wo as normalizeLongitude, tt as nprogress, es as oklchToHex, Rr as omit, qr as once, Hi as oneQueryKey, _r as operatorsFor, ar as parseMarkdown, ri as parseResponse, Oo as pathLengthKm, bi as permissionsFromToken, Li as persistQueryClientOffline, zr as pick, Ha as playAudio, kr as pluralize, Bo as projectMercator, Zr as randomId, Pr as range, Ns as readDeviceProfile, Jo as readThemeToken, ts as readableForeground, oa as redirect, Ra as registerPeriodicSync, Ne as registerServiceWorker, ns as relativeLuminance, Vt as relativeTime, Pi as removeById, Re as requestPersistentStorage, $t as resolveLanguage, ai as retry, rs as rgbToHex, $n as roleLabel, ir as safeLinkUrl, As as scaleSteps, Xt as selectMode, js as sequentialScale, ws as share, Ts as shareOrDownloadBlob, Pe as skipWaiting, Yr as sleep, Ar as slugify, ur as splitTransferSides, Ua as stopAudio, Tr as storage, er as tailSignature, as as themeContrast, ls as themeInitScript, ss as themePresets, Jr as throttle, Kn as timeLabel, ko as toRadians, en as tokenize, tn as tokenizeLines, jr as truncate, tr as turnTime, qn as typingLabel, Fr as uniqueBy, to as unmask, Vo as unprojectMercator, Fe as unregisterAllServiceWorkers, ii as uploadWithProgress, Fi as upsertById, Ea as urlBase64ToUint8Array, gi as useAccessControl, Y as useAsync, Wa as useAudio, z as useBeforeInstallPrompt, a as useBreakpoint, _i as useCan, Ce as useClickOutside, W as useClientFilter, ee as useClipboard, _e as useCounter, Ui as useCreate, Mi as useCursorQuery, Bi as useDataProvider, H as useDebounce, se as useDeepMemo, Wi as useDelete, he as useDisclosure, ve as useDocumentTitle, Z as useDocumentVisibility, Ja as useErrorHandler, K as useEventListener, wa as useEventStream, ye as useFavicon, vs as useFeatureFlag, po as useFieldArray, ys as useFlagValue, ae as useFocusTrap, mo as useForm, ho as useFormContext, go as useFormState, re as useGeolocation, pe as useHover, ya as useI18n, ne as useIdle, Me as useInstallPrompt, Q as useIntersectionObserver, le as useInterval, we as useIsFirstRender, te as useKeyboardShortcut, Gi as useList, ge as useListState, q as useLocalStorage, sa as useLocation, me as useLongPress, Ee as useLongPressHandlers, be as useMap, ca as useMatch, G as useMediaQuery, Qe as useModals, la as useNavigate, Ut as useNotificationInbox, Si as useOAuthCallback, Te as useObjectUrl, Ni as useOfflineMutation, We as useOfflineSync, Ki as useOne, X as useOnline, ji as usePaginatedQuery, U as usePagination, ua as useParams, si as usePoll, Wo as usePositionTracker, ce as usePrevious, Aa as usePushSubscription, Se as useQueue, $ as useResizeObserver, da as useRouteError, ie as useScrollLock, He as useScrollOverflow, fa as useSearchParams, Ie as useServiceWorkerUpdate, xe as useSet, Ve as useSortable, oe as useStableCallback, ze as useStorageEstimate, Ge as useSyncStatus, ps as useTelemetry, ga as useTheme, de as useThrottle, ue as useTimeout, Lt as useToast, J as useToggle, ba as useTranslate, qi as useUpdate, lo as useViaCEP, _o as useWatch, yo as useWebSocket, fe as useWindowSize, Qa as useZodForm, no as validateCNPJ, ro as validateCPF, Xa as validateForm, nr as visibleTurns, Xr as withTimeout, Qr as writeXlsx, Za as zodResolver };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class{_last;_speed={load:0,preprocess:0,inference:0,postprocess:0};constructor(){this._last=performance.now()}stage(e){let t=performance.now();this._speed[e]+=t-this._last,this._last=t}speed(){return{...this._speed}}};exports.SpeedTimer=e;
|
|
2
|
+
//# sourceMappingURL=timing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.cjs","names":[],"sources":["../../../src/vision/core/timing.ts"],"sourcesContent":["/**\n * Per-stage timing for a single `predict()` call.\n *\n * Populates the `speed` field every `Results` envelope carries, mirroring\n * Ultralytics' `results[0].speed`. All values are milliseconds measured with\n * `performance.now()`.\n */\n\n/**\n * Stage durations of one inference, in milliseconds.\n *\n * `preprocess`, `inference` and `postprocess` are the three keys Ultralytics\n * reports, measured over the same boundaries. `load` is specific to this SDK:\n * `predict()` accepts a URL, `Blob` or DOM element and decodes it internally,\n * so the fetch/decode cost would otherwise be invisible — and on a cold cache\n * it dominates everything else.\n */\nexport interface Speed {\n /** Fetching and decoding the input into an `RGBImage`. */\n load: number;\n /** Letterbox/resize, normalization and tensor packing. */\n preprocess: number;\n /** The ONNX Runtime forward pass. */\n inference: number;\n /** Decoding raw outputs into results (NMS, mask assembly, top-k). */\n postprocess: number;\n}\n\n/**\n * Accumulate stage durations while a `predict()` call runs.\n *\n * Each `stage()` call closes the previous stage: the elapsed time since the\n * last boundary is attributed to the name given. This keeps the call sites\n * free of paired start/stop bookkeeping and guarantees the four stages tile\n * the whole call without gaps.\n */\nexport class SpeedTimer {\n private _last: number;\n private readonly _speed: Speed = {\n load: 0,\n preprocess: 0,\n inference: 0,\n postprocess: 0,\n };\n\n constructor() {\n this._last = performance.now();\n }\n\n /**\n * Attribute the time elapsed since the previous boundary to `stage`.\n *\n * @param stage Which stage just finished.\n */\n stage(stage: keyof Speed): void {\n const now = performance.now();\n this._speed[stage] += now - this._last;\n this._last = now;\n }\n\n /**\n * The accumulated durations.\n *\n * @returns The `speed` object to hand to the `Results` envelope.\n */\n speed(): Speed {\n return { ...this._speed };\n }\n}\n"],"mappings":"AAoCA,IAAa,EAAb,KAAwB,CACpB,MACA,OAAiC,CAC7B,KAAM,EACN,WAAY,EACZ,UAAW,EACX,YAAa,CACjB,EAEA,aAAc,CACV,KAAK,MAAQ,YAAY,IAAI,CACjC,CAOA,MAAM,EAA0B,CAC5B,IAAM,EAAM,YAAY,IAAI,EAC5B,KAAK,OAAO,IAAU,EAAM,KAAK,MACjC,KAAK,MAAQ,CACjB,CAOA,OAAe,CACX,MAAO,CAAE,GAAG,KAAK,MAAO,CAC5B,CACJ"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/vision/core/timing.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
_last;
|
|
4
|
+
_speed = {
|
|
5
|
+
load: 0,
|
|
6
|
+
preprocess: 0,
|
|
7
|
+
inference: 0,
|
|
8
|
+
postprocess: 0
|
|
9
|
+
};
|
|
10
|
+
constructor() {
|
|
11
|
+
this._last = performance.now();
|
|
12
|
+
}
|
|
13
|
+
stage(e) {
|
|
14
|
+
let t = performance.now();
|
|
15
|
+
this._speed[e] += t - this._last, this._last = t;
|
|
16
|
+
}
|
|
17
|
+
speed() {
|
|
18
|
+
return { ...this._speed };
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { e as SpeedTimer };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=timing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.js","names":[],"sources":["../../../src/vision/core/timing.ts"],"sourcesContent":["/**\n * Per-stage timing for a single `predict()` call.\n *\n * Populates the `speed` field every `Results` envelope carries, mirroring\n * Ultralytics' `results[0].speed`. All values are milliseconds measured with\n * `performance.now()`.\n */\n\n/**\n * Stage durations of one inference, in milliseconds.\n *\n * `preprocess`, `inference` and `postprocess` are the three keys Ultralytics\n * reports, measured over the same boundaries. `load` is specific to this SDK:\n * `predict()` accepts a URL, `Blob` or DOM element and decodes it internally,\n * so the fetch/decode cost would otherwise be invisible — and on a cold cache\n * it dominates everything else.\n */\nexport interface Speed {\n /** Fetching and decoding the input into an `RGBImage`. */\n load: number;\n /** Letterbox/resize, normalization and tensor packing. */\n preprocess: number;\n /** The ONNX Runtime forward pass. */\n inference: number;\n /** Decoding raw outputs into results (NMS, mask assembly, top-k). */\n postprocess: number;\n}\n\n/**\n * Accumulate stage durations while a `predict()` call runs.\n *\n * Each `stage()` call closes the previous stage: the elapsed time since the\n * last boundary is attributed to the name given. This keeps the call sites\n * free of paired start/stop bookkeeping and guarantees the four stages tile\n * the whole call without gaps.\n */\nexport class SpeedTimer {\n private _last: number;\n private readonly _speed: Speed = {\n load: 0,\n preprocess: 0,\n inference: 0,\n postprocess: 0,\n };\n\n constructor() {\n this._last = performance.now();\n }\n\n /**\n * Attribute the time elapsed since the previous boundary to `stage`.\n *\n * @param stage Which stage just finished.\n */\n stage(stage: keyof Speed): void {\n const now = performance.now();\n this._speed[stage] += now - this._last;\n this._last = now;\n }\n\n /**\n * The accumulated durations.\n *\n * @returns The `speed` object to hand to the `Results` envelope.\n */\n speed(): Speed {\n return { ...this._speed };\n }\n}\n"],"mappings":";AAoCA,IAAa,IAAb,MAAwB;CACpB;CACA,SAAiC;EAC7B,MAAM;EACN,YAAY;EACZ,WAAW;EACX,aAAa;CACjB;CAEA,cAAc;EACV,KAAK,QAAQ,YAAY,IAAI;CACjC;CAOA,MAAM,GAA0B;EAC5B,IAAM,IAAM,YAAY,IAAI;EAE5B,AADA,KAAK,OAAO,MAAU,IAAM,KAAK,OACjC,KAAK,QAAQ;CACjB;CAOA,QAAe;EACX,OAAO,EAAE,GAAG,KAAK,OAAO;CAC5B;AACJ"}
|
package/dist/vision/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./core/exceptions.cjs"),t=require("./types.cjs"),n=require("./
|
|
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/providers.cjs"),o=require("./core/session.cjs"),s=require("./io/image.cjs"),c=require("./preprocess/image.cjs"),l=require("./postprocess/classification.cjs"),u=require("./postprocess/detection.cjs"),d=require("./postprocess/segmentation.cjs"),f=require("./tasks/base.cjs"),p=require("./tasks/classifier.cjs"),m=require("./tasks/detector.cjs"),h=require("./tasks/segmenter.cjs");var g=`0.3.0`;exports.BoundingBox=t.BoundingBox,exports.Boxes=r.Boxes,exports.COCO_CLASSES=i.COCO_CLASSES,exports.ClassificationResults=r.ClassificationResults,exports.Classifier=p.Classifier,exports.DEFAULT_PROVIDERS=a.DEFAULT_PROVIDERS,exports.DetectionResults=r.DetectionResults,exports.Detector=m.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=o.OrtSession,exports.OrtVisionError=e.OrtVisionError,exports.Probs=r.Probs,exports.ProviderNotAvailableError=e.ProviderNotAvailableError,exports.RGBImage=t.RGBImage,exports.SegmentationResults=r.SegmentationResults,exports.Segmenter=h.Segmenter,exports.SpeedTimer=n.SpeedTimer,exports.VERSION=g,exports.VisionTask=f.VisionTask,exports.batchedNms=u.batchedNms,exports.decodeYolo=u.decodeYolo,exports.decodeYoloAnchors=u.decodeYoloAnchors,exports.decodeYoloSeg=d.decodeYoloSeg,exports.decodeYoloV8=u.decodeYoloV8,exports.decodeYoloV8Anchors=u.decodeYoloV8Anchors,exports.decodeYoloV8Seg=d.decodeYoloV8Seg,exports.fromCv2=c.fromCv2,exports.letterbox=c.letterbox,exports.loadImage=s.loadImage,exports.nms=u.nms,exports.normalize=c.normalize,exports.resize=c.resize,exports.resolveLabels=i.resolveLabels,exports.resolveProviders=a.resolveProviders,exports.softmax=l.softmax,exports.toCHW=c.toCHW,exports.toCv2=c.toCv2,exports.toFloat32=c.toFloat32,exports.toFloat32Tensor=c.toFloat32Tensor,exports.toTensor=c.toTensor,exports.topK=l.topK;
|
|
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.
|
|
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.3.0` (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 { 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.3.0\";\n"],"mappings":"kiBAyGA,IAAa,EAAkB"}
|
package/dist/vision/index.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
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
2
|
import { BoundingBox as o, Mask as s, RGBImage as c } from "./types.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
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 { DEFAULT_PROVIDERS as v, resolveProviders as y } from "./core/providers.js";
|
|
7
|
+
import { OrtSession as b } from "./core/session.js";
|
|
8
|
+
import { loadImage as x } from "./io/image.js";
|
|
9
|
+
import { fromCv2 as S, letterbox as C, normalize as w, resize as T, toCHW as E, toCv2 as D, toFloat32 as O, toFloat32Tensor as k, toTensor as A } from "./preprocess/image.js";
|
|
10
|
+
import { softmax as j, topK as M } from "./postprocess/classification.js";
|
|
11
|
+
import { batchedNms as N, decodeYolo as P, decodeYoloAnchors as F, decodeYoloV8 as I, decodeYoloV8Anchors as L, nms as R } from "./postprocess/detection.js";
|
|
12
|
+
import { decodeYoloSeg as z, decodeYoloV8Seg as B } from "./postprocess/segmentation.js";
|
|
13
|
+
import { VisionTask as V } from "./tasks/base.js";
|
|
14
|
+
import { Classifier as H } from "./tasks/classifier.js";
|
|
15
|
+
import { Detector as U } from "./tasks/detector.js";
|
|
16
|
+
import { Segmenter as W } from "./tasks/segmenter.js";
|
|
16
17
|
//#region src/vision/index.ts
|
|
17
|
-
var
|
|
18
|
+
var G = "0.3.0";
|
|
18
19
|
//#endregion
|
|
19
|
-
export { o as BoundingBox,
|
|
20
|
+
export { o as BoundingBox, u as Boxes, g as COCO_CLASSES, d as ClassificationResults, H as Classifier, v as DEFAULT_PROVIDERS, f as DetectionResults, U as Detector, e as ImageLoadError, t as InferenceError, n as LabelMapError, s as Mask, p as Masks, r as ModelLoadError, b as OrtSession, i as OrtVisionError, m as Probs, a as ProviderNotAvailableError, c as RGBImage, h as SegmentationResults, W as Segmenter, l as SpeedTimer, G as VERSION, V as VisionTask, N as batchedNms, P as decodeYolo, F as decodeYoloAnchors, z as decodeYoloSeg, I as decodeYoloV8, L as decodeYoloV8Anchors, B as decodeYoloV8Seg, S as fromCv2, C as letterbox, x as loadImage, R as nms, w as normalize, T as resize, _ as resolveLabels, y as resolveProviders, j as softmax, E as toCHW, D as toCv2, O as toFloat32, k as toFloat32Tensor, A as toTensor, M as topK };
|
|
20
21
|
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/dist/vision/index.js.map
CHANGED
|
@@ -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.
|
|
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.3.0` (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 { 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.3.0\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAyGA,IAAa,IAAkB"}
|
|
@@ -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.
|
|
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;
|
|
2
2
|
//# sourceMappingURL=detection.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detection.cjs","names":[],"sources":["../../../src/vision/postprocess/detection.ts"],"sourcesContent":["/**\n * Detection head postprocessing: anchor-free YOLO decoding + non-maximum suppression.\n *\n * The shared {@link decodeYoloAnchors} helper does the per-anchor work that\n * is identical for plain detection and segmentation (transpose, xywh→xyxy,\n * letterbox unmap, per-class NMS, sort & cap). {@link decodeYolo} is a thin\n * wrapper around it; the segmentation module ({@link ./segmentation.js})\n * calls the helper directly so it can also recover the per-anchor mask\n * coefficients.\n *\n * Works for any YOLO export with the post-v8 anchor-free head:\n * **YOLOv8 / v9 / v10 / v11 / v12** detect heads, all of which share the\n * `[1, 4 + nc, N]` output layout.\n */\n\nimport { BoundingBox } from \"../types\";\n\n/**\n * Greedy non-maximum suppression on axis-aligned bounding boxes.\n *\n * Mirrors `torchvision.ops.nms` (keeps boxes with the highest score, drops\n * any subsequent box whose IoU exceeds the threshold).\n *\n * @param boxes Flat array of length `4 * N` in xyxy order: `[x1,y1,x2,y2, ...]`.\n * @param scores Detection score per box, length `N`.\n * @param iouThreshold Boxes with IoU above this threshold relative to a kept box are suppressed.\n * @returns Indices of kept boxes, in descending score order.\n */\nexport function nms(boxes: Float32Array, scores: Float32Array, iouThreshold: number): Int32Array {\n const n = scores.length;\n if (n === 0) return new Int32Array(0);\n\n const areas = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const x1 = boxes[i * 4] as number;\n const y1 = boxes[i * 4 + 1] as number;\n const x2 = boxes[i * 4 + 2] as number;\n const y2 = boxes[i * 4 + 3] as number;\n areas[i] = Math.max(0, x2 - x1) * Math.max(0, y2 - y1);\n }\n\n const order = new Array<number>(n);\n for (let i = 0; i < n; i++) order[i] = i;\n order.sort((a, b) => (scores[b] as number) - (scores[a] as number));\n\n const suppressed = new Uint8Array(n);\n const keep: number[] = [];\n\n for (let oi = 0; oi < order.length; oi++) {\n const i = order[oi] as number;\n if (suppressed[i]) continue;\n keep.push(i);\n\n const ax1 = boxes[i * 4] as number;\n const ay1 = boxes[i * 4 + 1] as number;\n const ax2 = boxes[i * 4 + 2] as number;\n const ay2 = boxes[i * 4 + 3] as number;\n const ai = areas[i] as number;\n\n for (let oj = oi + 1; oj < order.length; oj++) {\n const j = order[oj] as number;\n if (suppressed[j]) continue;\n\n const bx1 = boxes[j * 4] as number;\n const by1 = boxes[j * 4 + 1] as number;\n const bx2 = boxes[j * 4 + 2] as number;\n const by2 = boxes[j * 4 + 3] as number;\n\n const ix1 = Math.max(ax1, bx1);\n const iy1 = Math.max(ay1, by1);\n const ix2 = Math.min(ax2, bx2);\n const iy2 = Math.min(ay2, by2);\n const iw = Math.max(0, ix2 - ix1);\n const ih = Math.max(0, iy2 - iy1);\n const inter = iw * ih;\n const union = ai + (areas[j] as number) - inter;\n const iou = union > 0 ? inter / union : 0;\n if (iou > iouThreshold) suppressed[j] = 1;\n }\n }\n\n return Int32Array.from(keep);\n}\n\n/**\n * Per-class NMS — boxes are suppressed only by other boxes of the same class.\n *\n * Mirrors `torchvision.ops.batched_nms`.\n *\n * @param boxes Flat array of length `4 * N` in xyxy order.\n * @param scores Detection score per box, length `N`.\n * @param idxs Class index per box, length `N`. Boxes with different `idxs`\n * never suppress each other.\n * @param iouThreshold IoU threshold for suppression within a class.\n */\nexport function batchedNms(\n boxes: Float32Array,\n scores: Float32Array,\n idxs: Int32Array,\n iouThreshold: number,\n): Int32Array {\n if (scores.length === 0) return new Int32Array(0);\n\n const byClass = new Map<number, number[]>();\n for (let i = 0; i < idxs.length; i++) {\n const c = idxs[i] as number;\n const list = byClass.get(c);\n if (list === undefined) byClass.set(c, [i]);\n else list.push(i);\n }\n\n const keep: number[] = [];\n for (const indices of byClass.values()) {\n const m = indices.length;\n const subBoxes = new Float32Array(m * 4);\n const subScores = new Float32Array(m);\n for (let k = 0; k < m; k++) {\n const i = indices[k] as number;\n subBoxes[k * 4] = boxes[i * 4] as number;\n subBoxes[k * 4 + 1] = boxes[i * 4 + 1] as number;\n subBoxes[k * 4 + 2] = boxes[i * 4 + 2] as number;\n subBoxes[k * 4 + 3] = boxes[i * 4 + 3] as number;\n subScores[k] = scores[i] as number;\n }\n const subKeep = nms(subBoxes, subScores, iouThreshold);\n for (let k = 0; k < subKeep.length; k++) {\n keep.push(indices[subKeep[k] as number] as number);\n }\n }\n\n keep.sort((a, b) => (scores[b] as number) - (scores[a] as number));\n return Int32Array.from(keep);\n}\n\nexport interface DecodeYoloAnchorsOptions {\n /** Number of class-score channels following the 4 box channels. */\n readonly numClasses: number;\n readonly originalWidth: number;\n readonly originalHeight: number;\n readonly padLeft: number;\n readonly padTop: number;\n readonly scale: number;\n readonly confThreshold: number;\n readonly iouThreshold: number;\n readonly maxDetections: number;\n}\n\nexport interface DecodedAnchors {\n /** Indices into the original `numAnchors` axis, in descending confidence order. */\n readonly anchorIndices: Int32Array;\n /** `[k, 4]` boxes in original-image pixel coords, flat row-major xyxy. */\n readonly boxesXyxy: Float32Array;\n /** Predicted class id per survivor. */\n readonly classIds: Int32Array;\n /** Confidence per survivor. */\n readonly confidences: Float32Array;\n}\n\n/**\n * Shared YOLO per-anchor decode used by both detection and segmentation\n * (v8 / v9 / v10 / v11 / v12).\n *\n * Only the first `4 + numClasses` channels are read; later channels (e.g.\n * mask coefficients) are ignored — callers can fetch them via the returned\n * {@link DecodedAnchors.anchorIndices}.\n *\n * @param data Flat per-anchor output, length `channels * numAnchors`.\n * @param dims Dims as reported by ORT, e.g. `[1, 84, 8400]` (det) or\n * `[1, 116, 8400]` (seg). The leading batch dim must be 1.\n */\nexport function decodeYoloAnchors(\n data: Float32Array,\n dims: readonly number[],\n options: DecodeYoloAnchorsOptions,\n): DecodedAnchors {\n let normalized = dims;\n if (normalized.length === 3) {\n if (normalized[0] !== 1) {\n throw new Error(`decodeYoloAnchors: expected batch size 1, got ${normalized[0]}.`);\n }\n normalized = [normalized[1] as number, normalized[2] as number];\n }\n if (normalized.length !== 2) {\n throw new Error(\n `decodeYoloAnchors: expected 2-D output after batch removal, got dims=${JSON.stringify(dims)}.`,\n );\n }\n const channels = normalized[0] as number;\n const numAnchors = normalized[1] as number;\n\n const {\n numClasses,\n originalWidth,\n originalHeight,\n padLeft,\n padTop,\n scale,\n confThreshold,\n iouThreshold,\n maxDetections,\n } = options;\n\n if (numClasses < 1 || numClasses + 4 > channels) {\n throw new Error(\n `decodeYoloAnchors: invalid numClasses=${numClasses} for channels=${channels}.`,\n );\n }\n if (data.length !== channels * numAnchors) {\n throw new Error(\n `decodeYoloAnchors: data length ${data.length} does not match channels*numAnchors=${channels * numAnchors}.`,\n );\n }\n\n type Candidate = {\n anchorIdx: number;\n x1: number;\n y1: number;\n x2: number;\n y2: number;\n classId: number;\n confidence: number;\n };\n const candidates: Candidate[] = [];\n\n for (let a = 0; a < numAnchors; a++) {\n let bestCls = 0;\n let bestScore = -Infinity;\n for (let c = 0; c < numClasses; c++) {\n const s = data[(4 + c) * numAnchors + a];\n if (s !== undefined && s > bestScore) {\n bestScore = s;\n bestCls = c;\n }\n }\n if (bestScore < confThreshold) continue;\n\n const cx = data[a] as number;\n const cy = data[numAnchors + a] as number;\n const w = data[2 * numAnchors + a] as number;\n const h = data[3 * numAnchors + a] as number;\n\n let x1 = cx - w / 2;\n let y1 = cy - h / 2;\n let x2 = cx + w / 2;\n let y2 = cy + h / 2;\n\n x1 = (x1 - padLeft) / scale;\n y1 = (y1 - padTop) / scale;\n x2 = (x2 - padLeft) / scale;\n y2 = (y2 - padTop) / scale;\n\n x1 = Math.max(0, Math.min(originalWidth, x1));\n y1 = Math.max(0, Math.min(originalHeight, y1));\n x2 = Math.max(0, Math.min(originalWidth, x2));\n y2 = Math.max(0, Math.min(originalHeight, y2));\n\n candidates.push({ anchorIdx: a, x1, y1, x2, y2, classId: bestCls, confidence: bestScore });\n }\n\n if (candidates.length === 0) return emptyDecoded();\n\n // Build flat arrays then delegate to batchedNms — same algorithm as before\n // but funnelled through the public per-class NMS helper.\n const flatBoxes = new Float32Array(candidates.length * 4);\n const scoresArr = new Float32Array(candidates.length);\n const idxsArr = new Int32Array(candidates.length);\n for (let i = 0; i < candidates.length; i++) {\n const c = candidates[i] as Candidate;\n flatBoxes[i * 4] = c.x1;\n flatBoxes[i * 4 + 1] = c.y1;\n flatBoxes[i * 4 + 2] = c.x2;\n flatBoxes[i * 4 + 3] = c.y2;\n scoresArr[i] = c.confidence;\n idxsArr[i] = c.classId;\n }\n const kept = batchedNms(flatBoxes, scoresArr, idxsArr, iouThreshold);\n if (kept.length === 0) return emptyDecoded();\n\n const limited = Array.from(kept).slice(0, maxDetections);\n const k = limited.length;\n const anchorIndices = new Int32Array(k);\n const boxesXyxy = new Float32Array(k * 4);\n const classIds = new Int32Array(k);\n const confidences = new Float32Array(k);\n for (let i = 0; i < k; i++) {\n const c = candidates[limited[i] as number] as Candidate;\n anchorIndices[i] = c.anchorIdx;\n boxesXyxy[i * 4] = c.x1;\n boxesXyxy[i * 4 + 1] = c.y1;\n boxesXyxy[i * 4 + 2] = c.x2;\n boxesXyxy[i * 4 + 3] = c.y2;\n classIds[i] = c.classId;\n confidences[i] = c.confidence;\n }\n return { anchorIndices, boxesXyxy, classIds, confidences };\n}\n\nfunction emptyDecoded(): DecodedAnchors {\n return {\n anchorIndices: new Int32Array(0),\n boxesXyxy: new Float32Array(0),\n classIds: new Int32Array(0),\n confidences: new Float32Array(0),\n };\n}\n\nexport interface DecodeYoloOptions {\n readonly originalWidth: number;\n readonly originalHeight: number;\n readonly padLeft: number;\n readonly padTop: number;\n readonly scale: number;\n readonly confThreshold: number;\n readonly iouThreshold: number;\n readonly maxDetections: number;\n}\n\nexport interface DecodedDetection {\n readonly bbox: BoundingBox;\n readonly classId: number;\n readonly confidence: number;\n}\n\n/**\n * Decode an anchor-free YOLO detection output into a list of detections.\n *\n * Works for **YOLOv8 / v9 / v10 / v11 / v12** detect heads.\n *\n * Expected raw shape: `[1, 4 + numClasses, N]`. `numClasses` is inferred\n * from the channel count.\n */\nexport function decodeYolo(\n output: Float32Array,\n outputDims: readonly number[],\n options: DecodeYoloOptions,\n): DecodedDetection[] {\n const channels = outputDims.length === 3 ? outputDims[1] : outputDims[0];\n if (channels === undefined || channels < 5) {\n throw new Error(`decodeYolo: invalid output channel count ${channels} (expected >= 5).`);\n }\n const numClasses = channels - 4;\n\n const decoded = decodeYoloAnchors(output, outputDims, {\n numClasses,\n ...options,\n });\n\n const results: DecodedDetection[] = [];\n for (let i = 0; i < decoded.classIds.length; i++) {\n results.push({\n bbox: new BoundingBox(\n decoded.boxesXyxy[i * 4] as number,\n decoded.boxesXyxy[i * 4 + 1] as number,\n decoded.boxesXyxy[i * 4 + 2] as number,\n decoded.boxesXyxy[i * 4 + 3] as number,\n ),\n classId: decoded.classIds[i] as number,\n confidence: decoded.confidences[i] as number,\n });\n }\n return results;\n}\n\nlet _warnedDecodeYoloV8 = false;\nlet _warnedDecodeYoloV8Anchors = false;\n\n/**\n * @deprecated since 0.2.0 — use {@link decodeYolo}. Same behavior; the\n * decoder covers v8/v9/v10/v11/v12 detect heads. Will be removed in 0.3.0.\n */\nexport function decodeYoloV8(\n output: Float32Array,\n outputDims: readonly number[],\n options: DecodeYoloOptions,\n): DecodedDetection[] {\n if (!_warnedDecodeYoloV8) {\n _warnedDecodeYoloV8 = true;\n console.warn(\n \"[@ort-vision-sdk/web] decodeYoloV8 is deprecated since 0.2.0; use decodeYolo. \" +\n \"The alias will be removed in 0.3.0.\",\n );\n }\n return decodeYolo(output, outputDims, options);\n}\n\n/**\n * @deprecated since 0.2.0 — use {@link decodeYoloAnchors}. Will be removed in 0.3.0.\n */\nexport function decodeYoloV8Anchors(\n data: Float32Array,\n dims: readonly number[],\n options: DecodeYoloAnchorsOptions,\n): DecodedAnchors {\n if (!_warnedDecodeYoloV8Anchors) {\n _warnedDecodeYoloV8Anchors = true;\n console.warn(\n \"[@ort-vision-sdk/web] decodeYoloV8Anchors is deprecated since 0.2.0; use decodeYoloAnchors. \" +\n \"The alias will be removed in 0.3.0.\",\n );\n }\n return decodeYoloAnchors(data, dims, options);\n}\n\n/** @deprecated since 0.2.0 — use {@link DecodeYoloAnchorsOptions}. */\nexport type DecodeYoloV8AnchorsOptions = DecodeYoloAnchorsOptions;\n\n/** @deprecated since 0.2.0 — use {@link DecodeYoloOptions}. */\nexport type DecodeYoloV8Options = DecodeYoloOptions;\n"],"mappings":"gCA4BA,SAAgB,EAAI,EAAqB,EAAsB,EAAkC,CAC7F,IAAM,EAAI,EAAO,OACjB,GAAI,IAAM,EAAG,OAAO,IAAI,WAExB,IAAM,EAAQ,IAAI,aAAa,CAAC,EAChC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,CACxB,IAAM,EAAK,EAAM,EAAI,GACf,EAAK,EAAM,EAAI,EAAI,GACnB,EAAK,EAAM,EAAI,EAAI,GACnB,EAAK,EAAM,EAAI,EAAI,GACzB,EAAM,GAAK,KAAK,IAAI,EAAG,EAAK,CAAE,EAAI,KAAK,IAAI,EAAG,EAAK,CAAE,CACzD,CAEA,IAAM,EAAY,MAAc,CAAC,EACjC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,EAAM,GAAK,EACvC,EAAM,MAAM,EAAG,IAAO,EAAO,GAAiB,EAAO,EAAa,EAElE,IAAM,EAAa,IAAI,WAAW,CAAC,EAC7B,EAAiB,CAAC,EAExB,IAAK,IAAI,EAAK,EAAG,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GAC1B,EAAQ,UAAU,EAAI,EAAI,GAC1B,EAAQ,UAAU,EAAI,EAAI,EAC9B,EACA,QAAS,EAAQ,SAAS,GAC1B,WAAY,EAAQ,YAAY,EACpC,CAAC,EAEL,OAAO,CACX,CAEA,IAAI,EAAsB,GACtB,EAA6B,GAMjC,SAAgB,EACZ,EACA,EACA,EACkB,CAQlB,OAPK,IACD,EAAsB,GACtB,QAAQ,KACJ,mHAEJ,GAEG,EAAW,EAAQ,EAAY,CAAO,CACjD,CAKA,SAAgB,EACZ,EACA,EACA,EACc,CAQd,OAPK,IACD,EAA6B,GAC7B,QAAQ,KACJ,iIAEJ,GAEG,EAAkB,EAAM,EAAM,CAAO,CAChD"}
|
|
1
|
+
{"version":3,"file":"detection.cjs","names":[],"sources":["../../../src/vision/postprocess/detection.ts"],"sourcesContent":["/**\n * Detection head postprocessing: anchor-free YOLO decoding + non-maximum suppression.\n *\n * The shared {@link decodeYoloAnchors} helper does the per-anchor work that\n * is identical for plain detection and segmentation (transpose, xywh→xyxy,\n * letterbox unmap, per-class NMS, sort & cap). {@link decodeYolo} is a thin\n * wrapper around it; the segmentation module ({@link ./segmentation.js})\n * calls the helper directly so it can also recover the per-anchor mask\n * coefficients.\n *\n * Works for any YOLO export with the post-v8 anchor-free head:\n * **YOLOv8 / v9 / v10 / v11 / v12** detect heads, all of which share the\n * `[1, 4 + nc, N]` output layout.\n */\n\nimport { BoundingBox } from \"../types\";\n\n/**\n * Greedy non-maximum suppression on axis-aligned bounding boxes.\n *\n * Mirrors `torchvision.ops.nms` (keeps boxes with the highest score, drops\n * any subsequent box whose IoU exceeds the threshold).\n *\n * @param boxes Flat array of length `4 * N` in xyxy order: `[x1,y1,x2,y2, ...]`.\n * @param scores Detection score per box, length `N`.\n * @param iouThreshold Boxes with IoU above this threshold relative to a kept box are suppressed.\n * @returns Indices of kept boxes, in descending score order.\n */\nexport function nms(boxes: Float32Array, scores: Float32Array, iouThreshold: number): Int32Array {\n const n = scores.length;\n if (n === 0) return new Int32Array(0);\n\n const areas = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const x1 = boxes[i * 4] as number;\n const y1 = boxes[i * 4 + 1] as number;\n const x2 = boxes[i * 4 + 2] as number;\n const y2 = boxes[i * 4 + 3] as number;\n areas[i] = Math.max(0, x2 - x1) * Math.max(0, y2 - y1);\n }\n\n const order = new Array<number>(n);\n for (let i = 0; i < n; i++) order[i] = i;\n order.sort((a, b) => (scores[b] as number) - (scores[a] as number));\n\n const suppressed = new Uint8Array(n);\n const keep: number[] = [];\n\n for (let oi = 0; oi < order.length; oi++) {\n const i = order[oi] as number;\n if (suppressed[i]) continue;\n keep.push(i);\n\n const ax1 = boxes[i * 4] as number;\n const ay1 = boxes[i * 4 + 1] as number;\n const ax2 = boxes[i * 4 + 2] as number;\n const ay2 = boxes[i * 4 + 3] as number;\n const ai = areas[i] as number;\n\n for (let oj = oi + 1; oj < order.length; oj++) {\n const j = order[oj] as number;\n if (suppressed[j]) continue;\n\n const bx1 = boxes[j * 4] as number;\n const by1 = boxes[j * 4 + 1] as number;\n const bx2 = boxes[j * 4 + 2] as number;\n const by2 = boxes[j * 4 + 3] as number;\n\n const ix1 = Math.max(ax1, bx1);\n const iy1 = Math.max(ay1, by1);\n const ix2 = Math.min(ax2, bx2);\n const iy2 = Math.min(ay2, by2);\n const iw = Math.max(0, ix2 - ix1);\n const ih = Math.max(0, iy2 - iy1);\n const inter = iw * ih;\n const union = ai + (areas[j] as number) - inter;\n const iou = union > 0 ? inter / union : 0;\n if (iou > iouThreshold) suppressed[j] = 1;\n }\n }\n\n return Int32Array.from(keep);\n}\n\n/**\n * Per-class NMS — boxes are suppressed only by other boxes of the same class.\n *\n * Mirrors `torchvision.ops.batched_nms`.\n *\n * @param boxes Flat array of length `4 * N` in xyxy order.\n * @param scores Detection score per box, length `N`.\n * @param idxs Class index per box, length `N`. Boxes with different `idxs`\n * never suppress each other.\n * @param iouThreshold IoU threshold for suppression within a class.\n */\nexport function batchedNms(\n boxes: Float32Array,\n scores: Float32Array,\n idxs: Int32Array,\n iouThreshold: number,\n): Int32Array {\n if (scores.length === 0) return new Int32Array(0);\n\n const byClass = new Map<number, number[]>();\n for (let i = 0; i < idxs.length; i++) {\n const c = idxs[i] as number;\n const list = byClass.get(c);\n if (list === undefined) byClass.set(c, [i]);\n else list.push(i);\n }\n\n const keep: number[] = [];\n for (const indices of byClass.values()) {\n const m = indices.length;\n const subBoxes = new Float32Array(m * 4);\n const subScores = new Float32Array(m);\n for (let k = 0; k < m; k++) {\n const i = indices[k] as number;\n subBoxes[k * 4] = boxes[i * 4] as number;\n subBoxes[k * 4 + 1] = boxes[i * 4 + 1] as number;\n subBoxes[k * 4 + 2] = boxes[i * 4 + 2] as number;\n subBoxes[k * 4 + 3] = boxes[i * 4 + 3] as number;\n subScores[k] = scores[i] as number;\n }\n const subKeep = nms(subBoxes, subScores, iouThreshold);\n for (let k = 0; k < subKeep.length; k++) {\n keep.push(indices[subKeep[k] as number] as number);\n }\n }\n\n keep.sort((a, b) => (scores[b] as number) - (scores[a] as number));\n return Int32Array.from(keep);\n}\n\nexport interface DecodeYoloAnchorsOptions {\n /** Number of class-score channels following the 4 box channels. */\n readonly numClasses: number;\n readonly originalWidth: number;\n readonly originalHeight: number;\n readonly padLeft: number;\n readonly padTop: number;\n readonly scale: number;\n readonly confThreshold: number;\n readonly iouThreshold: number;\n readonly maxDetections: number;\n}\n\nexport interface DecodedAnchors {\n /** Indices into the original `numAnchors` axis, in descending confidence order. */\n readonly anchorIndices: Int32Array;\n /** `[k, 4]` boxes in original-image pixel coords, flat row-major xyxy. */\n readonly boxesXyxy: Float32Array;\n /** Predicted class id per survivor. */\n readonly classIds: Int32Array;\n /** Confidence per survivor. */\n readonly confidences: Float32Array;\n}\n\n/**\n * Shared YOLO per-anchor decode used by both detection and segmentation\n * (v8 / v9 / v10 / v11 / v12).\n *\n * Only the first `4 + numClasses` channels are read; later channels (e.g.\n * mask coefficients) are ignored — callers can fetch them via the returned\n * {@link DecodedAnchors.anchorIndices}.\n *\n * @param data Flat per-anchor output, length `channels * numAnchors`.\n * @param dims Dims as reported by ORT, e.g. `[1, 84, 8400]` (det) or\n * `[1, 116, 8400]` (seg). The leading batch dim must be 1.\n */\nexport function decodeYoloAnchors(\n data: Float32Array,\n dims: readonly number[],\n options: DecodeYoloAnchorsOptions,\n): DecodedAnchors {\n let normalized = dims;\n if (normalized.length === 3) {\n if (normalized[0] !== 1) {\n throw new Error(`decodeYoloAnchors: expected batch size 1, got ${normalized[0]}.`);\n }\n normalized = [normalized[1] as number, normalized[2] as number];\n }\n if (normalized.length !== 2) {\n throw new Error(\n `decodeYoloAnchors: expected 2-D output after batch removal, got dims=${JSON.stringify(dims)}.`,\n );\n }\n const channels = normalized[0] as number;\n const numAnchors = normalized[1] as number;\n\n const {\n numClasses,\n originalWidth,\n originalHeight,\n padLeft,\n padTop,\n scale,\n confThreshold,\n iouThreshold,\n maxDetections,\n } = options;\n\n if (numClasses < 1 || numClasses + 4 > channels) {\n throw new Error(\n `decodeYoloAnchors: invalid numClasses=${numClasses} for channels=${channels}.`,\n );\n }\n if (data.length !== channels * numAnchors) {\n throw new Error(\n `decodeYoloAnchors: data length ${data.length} does not match channels*numAnchors=${channels * numAnchors}.`,\n );\n }\n\n type Candidate = {\n anchorIdx: number;\n x1: number;\n y1: number;\n x2: number;\n y2: number;\n classId: number;\n confidence: number;\n };\n const candidates: Candidate[] = [];\n\n for (let a = 0; a < numAnchors; a++) {\n let bestCls = 0;\n let bestScore = -Infinity;\n for (let c = 0; c < numClasses; c++) {\n const s = data[(4 + c) * numAnchors + a];\n if (s !== undefined && s > bestScore) {\n bestScore = s;\n bestCls = c;\n }\n }\n if (bestScore < confThreshold) continue;\n\n const cx = data[a] as number;\n const cy = data[numAnchors + a] as number;\n const w = data[2 * numAnchors + a] as number;\n const h = data[3 * numAnchors + a] as number;\n\n let x1 = cx - w / 2;\n let y1 = cy - h / 2;\n let x2 = cx + w / 2;\n let y2 = cy + h / 2;\n\n x1 = (x1 - padLeft) / scale;\n y1 = (y1 - padTop) / scale;\n x2 = (x2 - padLeft) / scale;\n y2 = (y2 - padTop) / scale;\n\n x1 = Math.max(0, Math.min(originalWidth, x1));\n y1 = Math.max(0, Math.min(originalHeight, y1));\n x2 = Math.max(0, Math.min(originalWidth, x2));\n y2 = Math.max(0, Math.min(originalHeight, y2));\n\n candidates.push({ anchorIdx: a, x1, y1, x2, y2, classId: bestCls, confidence: bestScore });\n }\n\n if (candidates.length === 0) return emptyDecoded();\n\n // Build flat arrays then delegate to batchedNms — same algorithm as before\n // but funnelled through the public per-class NMS helper.\n const flatBoxes = new Float32Array(candidates.length * 4);\n const scoresArr = new Float32Array(candidates.length);\n const idxsArr = new Int32Array(candidates.length);\n for (let i = 0; i < candidates.length; i++) {\n const c = candidates[i] as Candidate;\n flatBoxes[i * 4] = c.x1;\n flatBoxes[i * 4 + 1] = c.y1;\n flatBoxes[i * 4 + 2] = c.x2;\n flatBoxes[i * 4 + 3] = c.y2;\n scoresArr[i] = c.confidence;\n idxsArr[i] = c.classId;\n }\n const kept = batchedNms(flatBoxes, scoresArr, idxsArr, iouThreshold);\n if (kept.length === 0) return emptyDecoded();\n\n const limited = Array.from(kept).slice(0, maxDetections);\n const k = limited.length;\n const anchorIndices = new Int32Array(k);\n const boxesXyxy = new Float32Array(k * 4);\n const classIds = new Int32Array(k);\n const confidences = new Float32Array(k);\n for (let i = 0; i < k; i++) {\n const c = candidates[limited[i] as number] as Candidate;\n anchorIndices[i] = c.anchorIdx;\n boxesXyxy[i * 4] = c.x1;\n boxesXyxy[i * 4 + 1] = c.y1;\n boxesXyxy[i * 4 + 2] = c.x2;\n boxesXyxy[i * 4 + 3] = c.y2;\n classIds[i] = c.classId;\n confidences[i] = c.confidence;\n }\n return { anchorIndices, boxesXyxy, classIds, confidences };\n}\n\nfunction emptyDecoded(): DecodedAnchors {\n return {\n anchorIndices: new Int32Array(0),\n boxesXyxy: new Float32Array(0),\n classIds: new Int32Array(0),\n confidences: new Float32Array(0),\n };\n}\n\nexport interface DecodeYoloOptions {\n readonly originalWidth: number;\n readonly originalHeight: number;\n readonly padLeft: number;\n readonly padTop: number;\n readonly scale: number;\n readonly confThreshold: number;\n readonly iouThreshold: number;\n readonly maxDetections: number;\n}\n\nexport interface DecodedDetection {\n readonly bbox: BoundingBox;\n readonly classId: number;\n readonly confidence: number;\n}\n\n/**\n * Decode an anchor-free YOLO detection output into a list of detections.\n *\n * Works for **YOLOv8 / v9 / v10 / v11 / v12** detect heads.\n *\n * Expected raw shape: `[1, 4 + numClasses, N]`. `numClasses` is inferred\n * from the channel count.\n */\nexport function decodeYolo(\n output: Float32Array,\n outputDims: readonly number[],\n options: DecodeYoloOptions,\n): DecodedDetection[] {\n const channels = outputDims.length === 3 ? outputDims[1] : outputDims[0];\n if (channels === undefined || channels < 5) {\n throw new Error(`decodeYolo: invalid output channel count ${channels} (expected >= 5).`);\n }\n const numClasses = channels - 4;\n\n const decoded = decodeYoloAnchors(output, outputDims, {\n numClasses,\n ...options,\n });\n\n const results: DecodedDetection[] = [];\n for (let i = 0; i < decoded.classIds.length; i++) {\n results.push({\n bbox: new BoundingBox(\n decoded.boxesXyxy[i * 4] as number,\n decoded.boxesXyxy[i * 4 + 1] as number,\n decoded.boxesXyxy[i * 4 + 2] as number,\n decoded.boxesXyxy[i * 4 + 3] as number,\n ),\n classId: decoded.classIds[i] as number,\n confidence: decoded.confidences[i] as number,\n });\n }\n return results;\n}\n\nlet _warnedDecodeYoloV8 = false;\nlet _warnedDecodeYoloV8Anchors = false;\n\n/**\n * @deprecated since 0.2.0 — use {@link decodeYolo}. Same behavior; the\n * decoder covers v8/v9/v10/v11/v12 detect heads. Will be removed in 0.4.0.\n */\nexport function decodeYoloV8(\n output: Float32Array,\n outputDims: readonly number[],\n options: DecodeYoloOptions,\n): DecodedDetection[] {\n if (!_warnedDecodeYoloV8) {\n _warnedDecodeYoloV8 = true;\n console.warn(\n \"[@ort-vision-sdk/web] decodeYoloV8 is deprecated since 0.2.0; use decodeYolo. \" +\n \"The alias will be removed in 0.4.0.\",\n );\n }\n return decodeYolo(output, outputDims, options);\n}\n\n/**\n * @deprecated since 0.2.0 — use {@link decodeYoloAnchors}. Will be removed in 0.4.0.\n */\nexport function decodeYoloV8Anchors(\n data: Float32Array,\n dims: readonly number[],\n options: DecodeYoloAnchorsOptions,\n): DecodedAnchors {\n if (!_warnedDecodeYoloV8Anchors) {\n _warnedDecodeYoloV8Anchors = true;\n console.warn(\n \"[@ort-vision-sdk/web] decodeYoloV8Anchors is deprecated since 0.2.0; use decodeYoloAnchors. \" +\n \"The alias will be removed in 0.4.0.\",\n );\n }\n return decodeYoloAnchors(data, dims, options);\n}\n\n/** @deprecated since 0.2.0 — use {@link DecodeYoloAnchorsOptions}. */\nexport type DecodeYoloV8AnchorsOptions = DecodeYoloAnchorsOptions;\n\n/** @deprecated since 0.2.0 — use {@link DecodeYoloOptions}. */\nexport type DecodeYoloV8Options = DecodeYoloOptions;\n"],"mappings":"gCA4BA,SAAgB,EAAI,EAAqB,EAAsB,EAAkC,CAC7F,IAAM,EAAI,EAAO,OACjB,GAAI,IAAM,EAAG,OAAO,IAAI,WAExB,IAAM,EAAQ,IAAI,aAAa,CAAC,EAChC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,CACxB,IAAM,EAAK,EAAM,EAAI,GACf,EAAK,EAAM,EAAI,EAAI,GACnB,EAAK,EAAM,EAAI,EAAI,GACnB,EAAK,EAAM,EAAI,EAAI,GACzB,EAAM,GAAK,KAAK,IAAI,EAAG,EAAK,CAAE,EAAI,KAAK,IAAI,EAAG,EAAK,CAAE,CACzD,CAEA,IAAM,EAAY,MAAc,CAAC,EACjC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,EAAM,GAAK,EACvC,EAAM,MAAM,EAAG,IAAO,EAAO,GAAiB,EAAO,EAAa,EAElE,IAAM,EAAa,IAAI,WAAW,CAAC,EAC7B,EAAiB,CAAC,EAExB,I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