{"version":3,"file":"base.cjs","names":[],"sources":["../../../src/vision/tasks/base.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Common foundation for task-oriented vision SDK objects.\n *\n * The base only owns the {@link OrtSession} — label resolution lives in each\n * subclass because how `numClasses` is read from the model differs per task.\n */\n\nimport { NoDetectionsError } from \"../core/exceptions\";\nimport type { OrtSession } from \"../core/session\";\n\nexport abstract class VisionTask {\n    protected constructor(protected readonly _session: OrtSession) {}\n\n    /** The underlying {@link OrtSession} used to run inference. */\n    get session(): OrtSession {\n        return this._session;\n    }\n}\n\n/**\n * Render a confidence threshold the way the Python SDK renders it.\n *\n * JavaScript and Python disagree on how a number becomes text. A whole\n * threshold is `1` here and `1.0` there; JavaScript holds off on exponent\n * notation until `1e-7` while Python switches at `1e-5`. A fused pipeline is\n * built once and runs under both runtimes from the same file, so a message that\n * quotes the threshold has to quote it identically — otherwise the two SDKs\n * describe the same run with two different numbers.\n *\n * Six decimals with the trailing zeros trimmed covers every threshold a caller\n * can meaningfully set and agrees byte for byte with `_format_threshold` in the\n * Python SDK's `tasks/base.py`. The pairing is fixed by a shared table in both\n * test suites, so a change on one side that is not mirrored on the other fails.\n *\n * @param value The threshold to render.\n * @returns The threshold as text, without trailing zeros or a trailing dot.\n */\nfunction formatThreshold(value: number): string {\n    return value.toFixed(6).replace(/0+$/, \"\").replace(/\\.$/, \"\");\n}\n\n/**\n * Turn an empty result into an error, when the caller asked for that.\n *\n * Shared by every task that can come back with nothing — {@link Detector},\n * {@link Segmenter} and {@link DetectClassify} — so the three agree on when\n * they throw and on what the message says. The message names the two settings\n * that decide the outcome, because \"no detections\" on its own leaves the reader\n * unable to tell a blank image from a threshold set too high.\n *\n * @param count How many detections survived every filter.\n * @param options The flag for this call, the threshold actually applied (after\n *   any per-call override), the class allowlist if one narrowed the search, and\n *   the source path when the input was one.\n * @throws {@link NoDetectionsError} when the flag is set and `count` is zero.\n */\nexport function requireDetections(\n    count: number,\n    options: {\n        readonly raiseOnEmpty: boolean;\n        readonly confThreshold: number;\n        readonly classes: readonly number[] | undefined;\n        readonly path: string | null;\n    },\n): void {\n    if (!options.raiseOnEmpty || count > 0) return;\n    const where = options.path ? ` in ${options.path}` : \"\";\n    const narrowed =\n        options.classes === undefined\n            ? \"\"\n            : ` among classes [${[...options.classes].sort((a, b) => a - b).join(\", \")}]`;\n    throw new NoDetectionsError(\n        `No detections${where}${narrowed}: nothing cleared confThreshold=${formatThreshold(options.confThreshold)}.`,\n    );\n}\n"],"mappings":"0CAWA,IAAsB,EAAtB,KAAiC,CACY,SAAzC,YAAsB,EAAyC,CAAtB,KAAA,SAAA,CAAuB,CAGhE,IAAI,SAAsB,CACtB,OAAO,KAAK,QAChB,CACJ,EAoBA,SAAS,EAAgB,EAAuB,CAC5C,OAAO,EAAM,QAAQ,CAAC,CAAC,CAAC,QAAQ,MAAO,EAAE,CAAC,CAAC,QAAQ,MAAO,EAAE,CAChE,CAiBA,SAAgB,EACZ,EACA,EAMI,CACJ,GAAI,CAAC,EAAQ,cAAgB,EAAQ,EAAG,OACxC,IAAM,EAAQ,EAAQ,KAAO,OAAO,EAAQ,OAAS,GAC/C,EACF,EAAQ,UAAY,IAAA,GACd,GACA,mBAAmB,CAAC,GAAG,EAAQ,OAAO,CAAC,CAAC,MAAM,EAAG,IAAM,EAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,GACnF,MAAM,IAAI,EAAA,kBACN,gBAAgB,IAAQ,EAAS,kCAAkC,EAAgB,EAAQ,aAAa,EAAE,EAC9G,CACJ"}