@scanly/core 2.0.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 +3 -0
- package/dist/barcode/contracts.d.ts +44 -0
- package/dist/barcode/contracts.d.ts.map +1 -0
- package/dist/barcode/contracts.js +33 -0
- package/dist/barcode/contracts.js.map +1 -0
- package/dist/barcode/format-selection.d.ts +12 -0
- package/dist/barcode/format-selection.d.ts.map +1 -0
- package/dist/barcode/format-selection.js +32 -0
- package/dist/barcode/format-selection.js.map +1 -0
- package/dist/barcode/format.d.ts +7 -0
- package/dist/barcode/format.d.ts.map +1 -0
- package/dist/barcode/format.js +20 -0
- package/dist/barcode/format.js.map +1 -0
- package/dist/barcode/index.d.ts +5 -0
- package/dist/barcode/index.d.ts.map +1 -0
- package/dist/barcode/index.js +5 -0
- package/dist/barcode/index.js.map +1 -0
- package/dist/barcode/retail.d.ts +16 -0
- package/dist/barcode/retail.d.ts.map +1 -0
- package/dist/barcode/retail.js +95 -0
- package/dist/barcode/retail.js.map +1 -0
- package/dist/contracts/engine.d.ts +84 -0
- package/dist/contracts/engine.d.ts.map +1 -0
- package/dist/contracts/engine.js +2 -0
- package/dist/contracts/engine.js.map +1 -0
- package/dist/contracts/errors.d.ts +17 -0
- package/dist/contracts/errors.d.ts.map +1 -0
- package/dist/contracts/errors.js +31 -0
- package/dist/contracts/errors.js.map +1 -0
- package/dist/contracts/frame.d.ts +37 -0
- package/dist/contracts/frame.d.ts.map +1 -0
- package/dist/contracts/frame.js +77 -0
- package/dist/contracts/frame.js.map +1 -0
- package/dist/contracts/operator.d.ts +46 -0
- package/dist/contracts/operator.d.ts.map +1 -0
- package/dist/contracts/operator.js +14 -0
- package/dist/contracts/operator.js.map +1 -0
- package/dist/contracts/result.d.ts +135 -0
- package/dist/contracts/result.d.ts.map +1 -0
- package/dist/contracts/result.js +2 -0
- package/dist/contracts/result.js.map +1 -0
- package/dist/contracts/validator.d.ts +15 -0
- package/dist/contracts/validator.d.ts.map +1 -0
- package/dist/contracts/validator.js +2 -0
- package/dist/contracts/validator.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/industrial/candidate-region.d.ts +15 -0
- package/dist/industrial/candidate-region.d.ts.map +1 -0
- package/dist/industrial/candidate-region.js +108 -0
- package/dist/industrial/candidate-region.js.map +1 -0
- package/dist/industrial/coordinate-transform.d.ts +9 -0
- package/dist/industrial/coordinate-transform.d.ts.map +1 -0
- package/dist/industrial/coordinate-transform.js +42 -0
- package/dist/industrial/coordinate-transform.js.map +1 -0
- package/dist/industrial/decode-candidate-conflict.d.ts +8 -0
- package/dist/industrial/decode-candidate-conflict.d.ts.map +1 -0
- package/dist/industrial/decode-candidate-conflict.js +97 -0
- package/dist/industrial/decode-candidate-conflict.js.map +1 -0
- package/dist/industrial/difficulty-diagnosis.d.ts +15 -0
- package/dist/industrial/difficulty-diagnosis.d.ts.map +1 -0
- package/dist/industrial/difficulty-diagnosis.js +291 -0
- package/dist/industrial/difficulty-diagnosis.js.map +1 -0
- package/dist/industrial/index.d.ts +13 -0
- package/dist/industrial/index.d.ts.map +1 -0
- package/dist/industrial/index.js +13 -0
- package/dist/industrial/index.js.map +1 -0
- package/dist/industrial/memory.d.ts +28 -0
- package/dist/industrial/memory.d.ts.map +1 -0
- package/dist/industrial/memory.js +65 -0
- package/dist/industrial/memory.js.map +1 -0
- package/dist/industrial/pixels.d.ts +44 -0
- package/dist/industrial/pixels.d.ts.map +1 -0
- package/dist/industrial/pixels.js +295 -0
- package/dist/industrial/pixels.js.map +1 -0
- package/dist/industrial/recovery-pipeline.d.ts +26 -0
- package/dist/industrial/recovery-pipeline.d.ts.map +1 -0
- package/dist/industrial/recovery-pipeline.js +149 -0
- package/dist/industrial/recovery-pipeline.js.map +1 -0
- package/dist/industrial/recovery-planner.d.ts +10 -0
- package/dist/industrial/recovery-planner.d.ts.map +1 -0
- package/dist/industrial/recovery-planner.js +107 -0
- package/dist/industrial/recovery-planner.js.map +1 -0
- package/dist/industrial/recovery-route-registry.d.ts +12 -0
- package/dist/industrial/recovery-route-registry.d.ts.map +1 -0
- package/dist/industrial/recovery-route-registry.js +15 -0
- package/dist/industrial/recovery-route-registry.js.map +1 -0
- package/dist/industrial/recovery-routes.d.ts +89 -0
- package/dist/industrial/recovery-routes.d.ts.map +1 -0
- package/dist/industrial/recovery-routes.js +280 -0
- package/dist/industrial/recovery-routes.js.map +1 -0
- package/dist/industrial/scan-evidence.d.ts +5 -0
- package/dist/industrial/scan-evidence.d.ts.map +1 -0
- package/dist/industrial/scan-evidence.js +63 -0
- package/dist/industrial/scan-evidence.js.map +1 -0
- package/dist/industrial/scanner-diagnostics.d.ts +19 -0
- package/dist/industrial/scanner-diagnostics.d.ts.map +1 -0
- package/dist/industrial/scanner-diagnostics.js +35 -0
- package/dist/industrial/scanner-diagnostics.js.map +1 -0
- package/dist/industrial/types.d.ts +189 -0
- package/dist/industrial/types.d.ts.map +1 -0
- package/dist/industrial/types.js +2 -0
- package/dist/industrial/types.js.map +1 -0
- package/dist/node.d.ts +2 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +2 -0
- package/dist/node.js.map +1 -0
- package/dist/qr/candidate-dedupe.d.ts +6 -0
- package/dist/qr/candidate-dedupe.d.ts.map +1 -0
- package/dist/qr/candidate-dedupe.js +27 -0
- package/dist/qr/candidate-dedupe.js.map +1 -0
- package/dist/qr/candidate-generation.d.ts +46 -0
- package/dist/qr/candidate-generation.d.ts.map +1 -0
- package/dist/qr/candidate-generation.js +277 -0
- package/dist/qr/candidate-generation.js.map +1 -0
- package/dist/qr/decode-pipeline.d.ts +14 -0
- package/dist/qr/decode-pipeline.d.ts.map +1 -0
- package/dist/qr/decode-pipeline.js +615 -0
- package/dist/qr/decode-pipeline.js.map +1 -0
- package/dist/qr/geometry.d.ts +24 -0
- package/dist/qr/geometry.d.ts.map +1 -0
- package/dist/qr/geometry.js +64 -0
- package/dist/qr/geometry.js.map +1 -0
- package/dist/qr/grayscale.d.ts +13 -0
- package/dist/qr/grayscale.d.ts.map +1 -0
- package/dist/qr/grayscale.js +46 -0
- package/dist/qr/grayscale.js.map +1 -0
- package/dist/qr/image-loader-node.d.ts +4 -0
- package/dist/qr/image-loader-node.d.ts.map +1 -0
- package/dist/qr/image-loader-node.js +26 -0
- package/dist/qr/image-loader-node.js.map +1 -0
- package/dist/qr/index.d.ts +15 -0
- package/dist/qr/index.d.ts.map +1 -0
- package/dist/qr/index.js +15 -0
- package/dist/qr/index.js.map +1 -0
- package/dist/qr/jsqr-decoder.d.ts +10 -0
- package/dist/qr/jsqr-decoder.d.ts.map +1 -0
- package/dist/qr/jsqr-decoder.js +18 -0
- package/dist/qr/jsqr-decoder.js.map +1 -0
- package/dist/qr/preprocess.d.ts +18 -0
- package/dist/qr/preprocess.d.ts.map +1 -0
- package/dist/qr/preprocess.js +165 -0
- package/dist/qr/preprocess.js.map +1 -0
- package/dist/qr/region-detection.d.ts +25 -0
- package/dist/qr/region-detection.d.ts.map +1 -0
- package/dist/qr/region-detection.js +129 -0
- package/dist/qr/region-detection.js.map +1 -0
- package/dist/qr/result-normalizer.d.ts +9 -0
- package/dist/qr/result-normalizer.d.ts.map +1 -0
- package/dist/qr/result-normalizer.js +70 -0
- package/dist/qr/result-normalizer.js.map +1 -0
- package/dist/qr/rotate.d.ts +5 -0
- package/dist/qr/rotate.d.ts.map +1 -0
- package/dist/qr/rotate.js +51 -0
- package/dist/qr/rotate.js.map +1 -0
- package/dist/qr/types.d.ts +186 -0
- package/dist/qr/types.d.ts.map +1 -0
- package/dist/qr/types.js +67 -0
- package/dist/qr/types.js.map +1 -0
- package/dist/qr/zxing-decoder.d.ts +8 -0
- package/dist/qr/zxing-decoder.d.ts.map +1 -0
- package/dist/qr/zxing-decoder.js +33 -0
- package/dist/qr/zxing-decoder.js.map +1 -0
- package/dist/runtime/artifacts.d.ts +16 -0
- package/dist/runtime/artifacts.d.ts.map +1 -0
- package/dist/runtime/artifacts.js +52 -0
- package/dist/runtime/artifacts.js.map +1 -0
- package/dist/runtime/builtin-operators.d.ts +12 -0
- package/dist/runtime/builtin-operators.d.ts.map +1 -0
- package/dist/runtime/builtin-operators.js +487 -0
- package/dist/runtime/builtin-operators.js.map +1 -0
- package/dist/runtime/capabilities.d.ts +32 -0
- package/dist/runtime/capabilities.d.ts.map +1 -0
- package/dist/runtime/capabilities.js +18 -0
- package/dist/runtime/capabilities.js.map +1 -0
- package/dist/runtime/engine-registry.d.ts +19 -0
- package/dist/runtime/engine-registry.d.ts.map +1 -0
- package/dist/runtime/engine-registry.js +136 -0
- package/dist/runtime/engine-registry.js.map +1 -0
- package/dist/runtime/execution-budget.d.ts +25 -0
- package/dist/runtime/execution-budget.d.ts.map +1 -0
- package/dist/runtime/execution-budget.js +41 -0
- package/dist/runtime/execution-budget.js.map +1 -0
- package/dist/runtime/frame-lease.d.ts +10 -0
- package/dist/runtime/frame-lease.d.ts.map +1 -0
- package/dist/runtime/frame-lease.js +17 -0
- package/dist/runtime/frame-lease.js.map +1 -0
- package/dist/runtime/frame-normalization.d.ts +13 -0
- package/dist/runtime/frame-normalization.d.ts.map +1 -0
- package/dist/runtime/frame-normalization.js +21 -0
- package/dist/runtime/frame-normalization.js.map +1 -0
- package/dist/runtime/memory-budget.d.ts +32 -0
- package/dist/runtime/memory-budget.d.ts.map +1 -0
- package/dist/runtime/memory-budget.js +109 -0
- package/dist/runtime/memory-budget.js.map +1 -0
- package/dist/runtime/operator-registry.d.ts +11 -0
- package/dist/runtime/operator-registry.d.ts.map +1 -0
- package/dist/runtime/operator-registry.js +19 -0
- package/dist/runtime/operator-registry.js.map +1 -0
- package/dist/runtime/result-policies.d.ts +21 -0
- package/dist/runtime/result-policies.d.ts.map +1 -0
- package/dist/runtime/result-policies.js +62 -0
- package/dist/runtime/result-policies.js.map +1 -0
- package/dist/runtime/router.d.ts +45 -0
- package/dist/runtime/router.d.ts.map +1 -0
- package/dist/runtime/router.js +202 -0
- package/dist/runtime/router.js.map +1 -0
- package/dist/runtime/scenario-compiler.d.ts +32 -0
- package/dist/runtime/scenario-compiler.d.ts.map +1 -0
- package/dist/runtime/scenario-compiler.js +131 -0
- package/dist/runtime/scenario-compiler.js.map +1 -0
- package/dist/runtime/scenario-runtime.d.ts +4 -0
- package/dist/runtime/scenario-runtime.d.ts.map +1 -0
- package/dist/runtime/scenario-runtime.js +32 -0
- package/dist/runtime/scenario-runtime.js.map +1 -0
- package/dist/runtime/session.d.ts +40 -0
- package/dist/runtime/session.d.ts.map +1 -0
- package/dist/runtime/session.js +117 -0
- package/dist/runtime/session.js.map +1 -0
- package/dist/runtime/validator-registry.d.ts +11 -0
- package/dist/runtime/validator-registry.d.ts.map +1 -0
- package/dist/runtime/validator-registry.js +16 -0
- package/dist/runtime/validator-registry.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BarcodeFormat } from "@scanly/scenario-schema";
|
|
2
|
+
import type { EngineCapabilities } from "../contracts/engine.js";
|
|
3
|
+
import type { FramePixelFormat } from "../contracts/frame.js";
|
|
4
|
+
import type { OperatorDescriptor } from "../contracts/operator.js";
|
|
5
|
+
import type { EngineRegistry } from "./engine-registry.js";
|
|
6
|
+
import type { OperatorRegistry } from "./operator-registry.js";
|
|
7
|
+
export interface EngineCapabilityReport {
|
|
8
|
+
id: string;
|
|
9
|
+
version: string;
|
|
10
|
+
capabilities: EngineCapabilities;
|
|
11
|
+
}
|
|
12
|
+
export interface OperatorCapabilityReport {
|
|
13
|
+
id: string;
|
|
14
|
+
version: string;
|
|
15
|
+
descriptor: OperatorDescriptor;
|
|
16
|
+
}
|
|
17
|
+
export interface ScanlyCapabilities {
|
|
18
|
+
formats: BarcodeFormat[];
|
|
19
|
+
pixelFormats: FramePixelFormat[];
|
|
20
|
+
scenarioFeatures: {
|
|
21
|
+
roi: boolean;
|
|
22
|
+
parallelEngines: boolean;
|
|
23
|
+
spatialDeduplication: boolean;
|
|
24
|
+
temporalTracking: boolean;
|
|
25
|
+
heuristicQuality: boolean;
|
|
26
|
+
yuvNormalization: boolean;
|
|
27
|
+
};
|
|
28
|
+
engines: EngineCapabilityReport[];
|
|
29
|
+
operators: OperatorCapabilityReport[];
|
|
30
|
+
}
|
|
31
|
+
export declare function inspectCapabilities(engines: EngineRegistry, operators: OperatorRegistry): ScanlyCapabilities;
|
|
32
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/runtime/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,kBAAkB,CAAC;CAClC;AAED,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,kBAAkB,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,YAAY,EAAE,gBAAgB,EAAE,CAAC;IACjC,gBAAgB,EAAE;QAChB,GAAG,EAAE,OAAO,CAAC;QACb,eAAe,EAAE,OAAO,CAAC;QACzB,oBAAoB,EAAE,OAAO,CAAC;QAC9B,gBAAgB,EAAE,OAAO,CAAC;QAC1B,gBAAgB,EAAE,OAAO,CAAC;QAC1B,gBAAgB,EAAE,OAAO,CAAC;KAC3B,CAAC;IACF,OAAO,EAAE,sBAAsB,EAAE,CAAC;IAClC,SAAS,EAAE,wBAAwB,EAAE,CAAC;CACvC;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,gBAAgB,GAAG,kBAAkB,CAgB5G"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function inspectCapabilities(engines, operators) {
|
|
2
|
+
const registered = engines.list();
|
|
3
|
+
return {
|
|
4
|
+
formats: [...new Set(registered.flatMap((engine) => engine.capabilities.formats))].sort(),
|
|
5
|
+
pixelFormats: ["rgba8888", "rgb888", "gray8"],
|
|
6
|
+
scenarioFeatures: {
|
|
7
|
+
roi: true,
|
|
8
|
+
parallelEngines: registered.length > 1,
|
|
9
|
+
spatialDeduplication: true,
|
|
10
|
+
temporalTracking: false,
|
|
11
|
+
heuristicQuality: false,
|
|
12
|
+
yuvNormalization: false,
|
|
13
|
+
},
|
|
14
|
+
engines: registered.map((engine) => ({ id: engine.id, version: engine.version, capabilities: { ...engine.capabilities, formats: [...engine.capabilities.formats] } })),
|
|
15
|
+
operators: operators.list().map((operator) => ({ id: operator.descriptor.id, version: operator.descriptor.version, descriptor: { ...operator.descriptor } })),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../src/runtime/capabilities.ts"],"names":[],"mappings":"AAkCA,MAAM,UAAU,mBAAmB,CAAC,OAAuB,EAAE,SAA2B;IACtF,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAClC,OAAO;QACL,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;QACzF,YAAY,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC;QAC7C,gBAAgB,EAAE;YAChB,GAAG,EAAE,IAAI;YACT,eAAe,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC;YACtC,oBAAoB,EAAE,IAAI;YAC1B,gBAAgB,EAAE,KAAK;YACvB,gBAAgB,EAAE,KAAK;YACvB,gBAAgB,EAAE,KAAK;SACxB;QACD,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,GAAG,MAAM,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;QACtK,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,GAAG,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;KAC9J,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BarcodeFormat } from "@scanly/scenario-schema";
|
|
2
|
+
import type { DecoderEngine, EngineDecodeOptions, EngineOutcome, EngineRegistrationOptions, EngineRegistryContract } from "../contracts/engine.js";
|
|
3
|
+
import type { NormalizedFrame } from "../contracts/frame.js";
|
|
4
|
+
export declare class EngineRegistry implements EngineRegistryContract {
|
|
5
|
+
private readonly records;
|
|
6
|
+
private disposed;
|
|
7
|
+
register(engine: DecoderEngine, options?: EngineRegistrationOptions): void;
|
|
8
|
+
unregister(id: string): void;
|
|
9
|
+
get(id: string): DecoderEngine | undefined;
|
|
10
|
+
list(): readonly DecoderEngine[];
|
|
11
|
+
resolve(formats: readonly BarcodeFormat[]): readonly DecoderEngine[];
|
|
12
|
+
initializeAll(): Promise<void>;
|
|
13
|
+
decode(id: string, frame: NormalizedFrame, options: EngineDecodeOptions): Promise<EngineOutcome>;
|
|
14
|
+
disposeAll(): Promise<void>;
|
|
15
|
+
get isDisposed(): boolean;
|
|
16
|
+
private initialize;
|
|
17
|
+
private assertUsable;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=engine-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-registry.d.ts","sourceRoot":"","sources":["../../src/runtime/engine-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAuB7D,qBAAa,cAAe,YAAW,sBAAsB;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAC3D,OAAO,CAAC,QAAQ,CAAS;IAEzB,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,yBAA8B,GAAG,IAAI;IAe9E,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAU5B,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAI1C,IAAI,IAAI,SAAS,aAAa,EAAE;IAIhC,OAAO,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,GAAG,SAAS,aAAa,EAAE;IAQ9D,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;IAkChG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBjC,IAAI,UAAU,IAAI,OAAO,CAA0B;YAErC,UAAU;IAuBxB,OAAO,CAAC,YAAY;CAGrB"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { SdkException, sdkError } from "../contracts/errors.js";
|
|
2
|
+
function initializationFailure(engine, cause) {
|
|
3
|
+
return new SdkException(sdkError("engine_initialization_failure", `Decoder engine '${engine.id}' failed to initialize.`, { engineId: engine.id, engineVersion: engine.version }, cause));
|
|
4
|
+
}
|
|
5
|
+
export class EngineRegistry {
|
|
6
|
+
records = new Map();
|
|
7
|
+
disposed = false;
|
|
8
|
+
register(engine, options = {}) {
|
|
9
|
+
this.assertUsable();
|
|
10
|
+
if (!engine || typeof engine.id !== "string" || !engine.id.trim()) {
|
|
11
|
+
throw new SdkException(sdkError("invalid_configuration", "Decoder engine id must be a non-empty string."));
|
|
12
|
+
}
|
|
13
|
+
const prior = this.records.get(engine.id);
|
|
14
|
+
if (prior && !options.replace) {
|
|
15
|
+
throw new SdkException(sdkError("invalid_configuration", `Decoder engine '${engine.id}' is already registered.`, { engineId: engine.id }));
|
|
16
|
+
}
|
|
17
|
+
if (prior && prior.state !== "registered") {
|
|
18
|
+
throw new SdkException(sdkError("invalid_configuration", `Initialized decoder engine '${engine.id}' cannot be replaced; unregister or dispose it first.`, { engineId: engine.id }));
|
|
19
|
+
}
|
|
20
|
+
this.records.set(engine.id, { engine, state: "registered", tail: Promise.resolve(), active: new Set() });
|
|
21
|
+
}
|
|
22
|
+
unregister(id) {
|
|
23
|
+
this.assertUsable();
|
|
24
|
+
const record = this.records.get(id);
|
|
25
|
+
if (!record)
|
|
26
|
+
return;
|
|
27
|
+
if (record.state !== "registered") {
|
|
28
|
+
throw new SdkException(sdkError("invalid_configuration", `Decoder engine '${id}' is active and cannot be unregistered without disposal.`, { engineId: id }));
|
|
29
|
+
}
|
|
30
|
+
this.records.delete(id);
|
|
31
|
+
}
|
|
32
|
+
get(id) {
|
|
33
|
+
return this.records.get(id)?.engine;
|
|
34
|
+
}
|
|
35
|
+
list() {
|
|
36
|
+
return Object.freeze([...this.records.values()].map((record) => record.engine));
|
|
37
|
+
}
|
|
38
|
+
resolve(formats) {
|
|
39
|
+
const requested = new Set(formats);
|
|
40
|
+
if (requested.size === 0)
|
|
41
|
+
throw new SdkException(sdkError("unsupported_format", "At least one barcode format must be requested."));
|
|
42
|
+
const resolved = this.list().filter((engine) => engine.capabilities.formats.some((format) => requested.has(format)));
|
|
43
|
+
if (!resolved.length)
|
|
44
|
+
throw new SdkException(sdkError("unsupported_format", `No registered engine supports: ${[...requested].join(", ")}.`));
|
|
45
|
+
return Object.freeze(resolved);
|
|
46
|
+
}
|
|
47
|
+
async initializeAll() {
|
|
48
|
+
this.assertUsable();
|
|
49
|
+
await Promise.all([...this.records.values()].map((record) => this.initialize(record)));
|
|
50
|
+
}
|
|
51
|
+
async decode(id, frame, options) {
|
|
52
|
+
this.assertUsable();
|
|
53
|
+
const record = this.records.get(id);
|
|
54
|
+
if (!record) {
|
|
55
|
+
throw new SdkException(sdkError("invalid_configuration", `Decoder engine '${id}' is not registered.`, { engineId: id }));
|
|
56
|
+
}
|
|
57
|
+
await this.initialize(record);
|
|
58
|
+
this.assertUsable();
|
|
59
|
+
if (record.state !== "ready")
|
|
60
|
+
throw initializationFailure(record.engine, new Error("Engine is not ready."));
|
|
61
|
+
const execute = async () => {
|
|
62
|
+
if (this.disposed || record.state === "disposed") {
|
|
63
|
+
throw new SdkException(sdkError("session_disposed", `Decoder engine '${id}' has been disposed.`, { engineId: id }));
|
|
64
|
+
}
|
|
65
|
+
return record.engine.decode(frame, options);
|
|
66
|
+
};
|
|
67
|
+
const track = (operation) => {
|
|
68
|
+
record.active.add(operation);
|
|
69
|
+
void operation.finally(() => record.active.delete(operation)).catch(() => undefined);
|
|
70
|
+
return operation;
|
|
71
|
+
};
|
|
72
|
+
if (record.engine.capabilities.threadSafe)
|
|
73
|
+
return track(execute());
|
|
74
|
+
const previous = record.tail;
|
|
75
|
+
let release;
|
|
76
|
+
record.tail = new Promise((resolve) => { release = resolve; });
|
|
77
|
+
await previous;
|
|
78
|
+
try {
|
|
79
|
+
return await track(execute());
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
release();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async disposeAll() {
|
|
86
|
+
if (this.disposed) {
|
|
87
|
+
await Promise.all([...this.records.values()].map((record) => record.disposePromise));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.disposed = true;
|
|
91
|
+
await Promise.all([...this.records.values()].map(async (record) => {
|
|
92
|
+
if (record.disposePromise)
|
|
93
|
+
return record.disposePromise;
|
|
94
|
+
record.disposePromise = (async () => {
|
|
95
|
+
await record.initializePromise?.catch(() => undefined);
|
|
96
|
+
await record.tail;
|
|
97
|
+
await Promise.allSettled([...record.active]);
|
|
98
|
+
if (record.state !== "disposed")
|
|
99
|
+
await record.engine.dispose?.();
|
|
100
|
+
record.state = "disposed";
|
|
101
|
+
})();
|
|
102
|
+
return record.disposePromise;
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
get isDisposed() { return this.disposed; }
|
|
106
|
+
async initialize(record) {
|
|
107
|
+
if (record.state === "ready")
|
|
108
|
+
return;
|
|
109
|
+
if (record.state === "disposed" || this.disposed)
|
|
110
|
+
this.assertUsable();
|
|
111
|
+
if (!record.initializePromise) {
|
|
112
|
+
record.state = "initializing";
|
|
113
|
+
const promise = Promise.resolve()
|
|
114
|
+
.then(() => record.engine.initialize?.())
|
|
115
|
+
.then(() => { record.state = "ready"; })
|
|
116
|
+
.catch((cause) => {
|
|
117
|
+
record.state = "failed";
|
|
118
|
+
throw initializationFailure(record.engine, cause);
|
|
119
|
+
})
|
|
120
|
+
.finally(() => {
|
|
121
|
+
// Failed engines may define their own bounded retry/circuit-breaker policy.
|
|
122
|
+
// Clearing only the failed promise preserves in-flight deduplication while
|
|
123
|
+
// allowing a later decode to make one explicit retry.
|
|
124
|
+
if (record.state === "failed" && record.initializePromise === promise)
|
|
125
|
+
record.initializePromise = undefined;
|
|
126
|
+
});
|
|
127
|
+
record.initializePromise = promise;
|
|
128
|
+
}
|
|
129
|
+
await record.initializePromise;
|
|
130
|
+
}
|
|
131
|
+
assertUsable() {
|
|
132
|
+
if (this.disposed)
|
|
133
|
+
throw new SdkException(sdkError("session_disposed", "Decoder engine registry has been disposed."));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=engine-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-registry.js","sourceRoot":"","sources":["../../src/runtime/engine-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAsBhE,SAAS,qBAAqB,CAAC,MAAqB,EAAE,KAAc;IAClE,OAAO,IAAI,YAAY,CAAC,QAAQ,CAC9B,+BAA+B,EAC/B,mBAAmB,MAAM,CAAC,EAAE,yBAAyB,EACrD,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,EAAE,aAAa,EAAE,MAAM,CAAC,OAAO,EAAE,EACtD,KAAK,CACN,CAAC,CAAC;AACL,CAAC;AAED,MAAM,OAAO,cAAc;IACR,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;IACnD,QAAQ,GAAG,KAAK,CAAC;IAEzB,QAAQ,CAAC,MAAqB,EAAE,UAAqC,EAAE;QACrE,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,EAAE,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;YAClE,MAAM,IAAI,Y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2E;gBAC3E,sDAAsD;gBACtD,IAAI,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,iBAAiB,KAAK,OAAO;oBAAE,MAAM,CAAC,iBAAiB,GAAG,SAAS,CAAC;YAC9G,CAAC,CAAC,CAAC;YACL,MAAM,CAAC,iBAAiB,GAAG,OAAO,CAAC;QACrC,CAAC;QACD,MAAM,MAAM,CAAC,iBAAiB,CAAC;IACjC,CAAC;IAEO,YAAY;QAClB,IAAI,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,kBAAkB,EAAE,4CAA4C,CAAC,CAAC,CAAC;IACxH,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FrameMemoryBudget } from "./memory-budget.js";
|
|
2
|
+
export declare function monotonicNow(): number;
|
|
3
|
+
export interface ExecutionBudgetOptions {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
deadlineMs: number;
|
|
6
|
+
now?: () => number;
|
|
7
|
+
remainingAttempts?: () => number;
|
|
8
|
+
memory?: FrameMemoryBudget;
|
|
9
|
+
totalAttempts?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class ExecutionBudget {
|
|
12
|
+
readonly signal?: AbortSignal;
|
|
13
|
+
readonly deadlineMs: number;
|
|
14
|
+
readonly memory?: FrameMemoryBudget;
|
|
15
|
+
private readonly clock;
|
|
16
|
+
private readonly attempts;
|
|
17
|
+
private remaining;
|
|
18
|
+
constructor(options: ExecutionBudgetOptions);
|
|
19
|
+
now(): number;
|
|
20
|
+
remainingAttempts(): number;
|
|
21
|
+
tryConsumeAttempt(): boolean;
|
|
22
|
+
remainingIntermediateBytes(): number;
|
|
23
|
+
throwIfExceeded(stage: string): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=execution-budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-budget.d.ts","sourceRoot":"","sources":["../../src/runtime/execution-budget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,wBAAgB,YAAY,IAAI,MAAM,CAIrC;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,MAAM,CAAC;IACjC,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,eAAe;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,iBAAiB,CAAC;IACpC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IACxC,OAAO,CAAC,SAAS,CAAgB;gBAErB,OAAO,EAAE,sBAAsB;IAS3C,GAAG,IAAI,MAAM;IACb,iBAAiB,IAAI,MAAM;IAC3B,iBAAiB,IAAI,OAAO;IAM5B,0BAA0B,IAAI,MAAM;IAEpC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAQrC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function monotonicNow() {
|
|
2
|
+
return typeof performance !== "undefined" && typeof performance.now === "function"
|
|
3
|
+
? performance.now()
|
|
4
|
+
: Date.now();
|
|
5
|
+
}
|
|
6
|
+
export class ExecutionBudget {
|
|
7
|
+
signal;
|
|
8
|
+
deadlineMs;
|
|
9
|
+
memory;
|
|
10
|
+
clock;
|
|
11
|
+
attempts;
|
|
12
|
+
remaining;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.signal = options.signal;
|
|
15
|
+
this.deadlineMs = options.deadlineMs;
|
|
16
|
+
this.clock = options.now ?? monotonicNow;
|
|
17
|
+
this.attempts = options.remainingAttempts ?? (() => Number.POSITIVE_INFINITY);
|
|
18
|
+
this.remaining = options.totalAttempts === undefined ? null : Math.max(0, Math.floor(options.totalAttempts));
|
|
19
|
+
this.memory = options.memory;
|
|
20
|
+
}
|
|
21
|
+
now() { return this.clock(); }
|
|
22
|
+
remainingAttempts() { return this.remaining ?? Math.max(0, this.attempts()); }
|
|
23
|
+
tryConsumeAttempt() {
|
|
24
|
+
if (this.remaining === null)
|
|
25
|
+
return this.attempts() > 0;
|
|
26
|
+
if (this.remaining <= 0)
|
|
27
|
+
return false;
|
|
28
|
+
this.remaining -= 1;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
remainingIntermediateBytes() { return this.memory?.remainingBytes ?? Number.POSITIVE_INFINITY; }
|
|
32
|
+
throwIfExceeded(stage) {
|
|
33
|
+
if (this.signal?.aborted) {
|
|
34
|
+
throw Object.assign(new Error(`Execution cancelled during ${stage}.`), { name: "AbortError", code: "cancelled", stage });
|
|
35
|
+
}
|
|
36
|
+
if (this.clock() >= this.deadlineMs) {
|
|
37
|
+
throw Object.assign(new Error(`Execution deadline exceeded during ${stage}.`), { name: "TimeoutError", code: "timeout", stage });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=execution-budget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-budget.js","sourceRoot":"","sources":["../../src/runtime/execution-budget.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI,OAAO,WAAW,CAAC,GAAG,KAAK,UAAU;QAChF,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE;QACnB,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AACjB,CAAC;AAWD,MAAM,OAAO,eAAe;IACjB,MAAM,CAAe;IACrB,UAA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AC,KAAa;QAC3B,IAAI,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;YACzB,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,8BAA8B,KAAK,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3H,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpC,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sCAAsC,KAAK,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;QACnI,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NormalizedFrame } from "../contracts/frame.js";
|
|
2
|
+
/** Owns the exactly-once release boundary for a frame, including preflight failures. */
|
|
3
|
+
export declare class FrameLease {
|
|
4
|
+
readonly frame: NormalizedFrame;
|
|
5
|
+
private released;
|
|
6
|
+
constructor(frame: NormalizedFrame);
|
|
7
|
+
release(): void;
|
|
8
|
+
get isReleased(): boolean;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=frame-lease.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-lease.d.ts","sourceRoot":"","sources":["../../src/runtime/frame-lease.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,wFAAwF;AACxF,qBAAa,UAAU;IAET,QAAQ,CAAC,KAAK,EAAE,eAAe;IAD3C,OAAO,CAAC,QAAQ,CAAS;gBACJ,KAAK,EAAE,eAAe;IAE3C,OAAO,IAAI,IAAI;IAMf,IAAI,UAAU,IAAI,OAAO,CAA0B;CACpD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Owns the exactly-once release boundary for a frame, including preflight failures. */
|
|
2
|
+
export class FrameLease {
|
|
3
|
+
frame;
|
|
4
|
+
released = false;
|
|
5
|
+
constructor(frame) {
|
|
6
|
+
this.frame = frame;
|
|
7
|
+
}
|
|
8
|
+
release() {
|
|
9
|
+
if (this.released)
|
|
10
|
+
return;
|
|
11
|
+
this.released = true;
|
|
12
|
+
if (this.frame?.ownership !== "borrowed")
|
|
13
|
+
this.frame?.dispose?.();
|
|
14
|
+
}
|
|
15
|
+
get isReleased() { return this.released; }
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=frame-lease.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-lease.js","sourceRoot":"","sources":["../../src/runtime/frame-lease.ts"],"names":[],"mappings":"AAEA,wFAAwF;AACxF,MAAM,OAAO,UAAU;IAEA;IADb,QAAQ,GAAG,KAAK,CAAC;IACzB,YAAqB,KAAsB;QAAtB,UAAK,GAAL,KAAK,CAAiB;IAAG,CAAC;IAE/C,OAAO;QACL,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,IAAI,CAAC,KAAK,EAAE,SAAS,KAAK,UAAU;YAAE,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC;IACpE,CAAC;IAED,IAAI,UAAU,KAAc,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;CACpD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FrameOrientation } from "../contracts/frame.js";
|
|
2
|
+
import type { PixelBuffer } from "../qr/types.js";
|
|
3
|
+
import { type CoordinateTransform, type Matrix3x3 } from "../qr/geometry.js";
|
|
4
|
+
import type { ExecutionBudget } from "./execution-budget.js";
|
|
5
|
+
export interface OrientationNormalization {
|
|
6
|
+
buffer: PixelBuffer;
|
|
7
|
+
sourceToUpright: CoordinateTransform;
|
|
8
|
+
sourceOrientation: FrameOrientation;
|
|
9
|
+
}
|
|
10
|
+
export declare function sourceToUprightMatrix(orientation: FrameOrientation, width: number, height: number): Matrix3x3;
|
|
11
|
+
/** Converts source-buffer pixels to canonical upright RGBA coordinates. */
|
|
12
|
+
export declare function normalizeRgbaOrientation(buffer: PixelBuffer, orientation: FrameOrientation, budget?: ExecutionBudget): OrientationNormalization;
|
|
13
|
+
//# sourceMappingURL=frame-normalization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-normalization.d.ts","sourceRoot":"","sources":["../../src/runtime/frame-normalization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAA8C,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEzH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,WAAW,CAAC;IACpB,eAAe,EAAE,mBAAmB,CAAC;IACrC,iBAAiB,EAAE,gBAAgB,CAAC;CACrC;AAED,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAK7G;AAED,2EAA2E;AAC3E,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,wBAAwB,CAa/I"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createCoordinateTransform, IDENTITY_MATRIX } from "../qr/geometry.js";
|
|
2
|
+
import { rotateBuffer } from "../qr/rotate.js";
|
|
3
|
+
export function sourceToUprightMatrix(orientation, width, height) {
|
|
4
|
+
if (orientation === 90)
|
|
5
|
+
return [0, -1, height - 1, 1, 0, 0, 0, 0, 1];
|
|
6
|
+
if (orientation === 180)
|
|
7
|
+
return [-1, 0, width - 1, 0, -1, height - 1, 0, 0, 1];
|
|
8
|
+
if (orientation === 270)
|
|
9
|
+
return [0, 1, 0, -1, 0, width - 1, 0, 0, 1];
|
|
10
|
+
return IDENTITY_MATRIX;
|
|
11
|
+
}
|
|
12
|
+
/** Converts source-buffer pixels to canonical upright RGBA coordinates. */
|
|
13
|
+
export function normalizeRgbaOrientation(buffer, orientation, budget) {
|
|
14
|
+
const upright = orientation === 0 ? buffer : rotateBuffer(buffer, orientation, budget);
|
|
15
|
+
return {
|
|
16
|
+
buffer: upright,
|
|
17
|
+
sourceOrientation: orientation,
|
|
18
|
+
sourceToUpright: createCoordinateTransform(sourceToUprightMatrix(orientation, buffer.width, buffer.height), buffer.width, buffer.height, upright.width, upright.height),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=frame-normalization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-normalization.js","sourceRoot":"","sources":["../../src/runtime/frame-normalization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,eAAe,EAA4C,MAAM,mBAAmB,CAAC;AACzH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAS/C,MAAM,UAAU,qBAAqB,CAAC,WAA6B,EAAE,KAAa,EAAE,MAAc;IAChG,IAAI,WAAW,KAAK,EAAE;QAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrE,IAAI,WAAW,KAAK,GAAG;QAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/E,IAAI,WAAW,KAAK,GAAG;QAAE,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrE,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,wBAAwB,CAAC,MAAmB,EAAE,WAA6B,EAAE,MAAwB;IACnH,MAAM,OAAO,GAAG,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IACvF,OAAO;QACL,MAAM,EAAE,OAAO;QACf,iBAAiB,EAAE,WAAW;QAC9B,eAAe,EAAE,yBAAyB,CACxC,qBAAqB,CAAC,WAAW,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAC/D,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,MAAM,EACb,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,MAAM,CACf;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface MemoryLease {
|
|
2
|
+
readonly bytes: number;
|
|
3
|
+
readonly label: string;
|
|
4
|
+
readonly kind: MemoryLeaseKind;
|
|
5
|
+
readonly released: boolean;
|
|
6
|
+
reclassify(kind: MemoryLeaseKind, label?: string): void;
|
|
7
|
+
release(): void;
|
|
8
|
+
}
|
|
9
|
+
export type MemoryLeaseKind = "artifact" | "cache" | "scratch";
|
|
10
|
+
export interface MemoryObservation {
|
|
11
|
+
currentControlledBytes: number;
|
|
12
|
+
peakControlledBytes: number;
|
|
13
|
+
retainedArtifactBytes: number;
|
|
14
|
+
retainedCacheBytes: number;
|
|
15
|
+
transientScratchBytes: number;
|
|
16
|
+
}
|
|
17
|
+
export declare class FrameMemoryBudget {
|
|
18
|
+
readonly limitBytes: number;
|
|
19
|
+
private bytes;
|
|
20
|
+
private peakBytes;
|
|
21
|
+
private readonly byKind;
|
|
22
|
+
private leases;
|
|
23
|
+
constructor(limitBytes: number);
|
|
24
|
+
get retainedBytes(): number;
|
|
25
|
+
get remainingBytes(): number;
|
|
26
|
+
get observation(): MemoryObservation;
|
|
27
|
+
reserve(bytes: number, label: string, kind?: MemoryLeaseKind): MemoryLease;
|
|
28
|
+
reserveScratch(bytes: number, label: string): MemoryLease;
|
|
29
|
+
resize(lease: MemoryLease, bytes: number): void;
|
|
30
|
+
releaseAll(): void;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=memory-budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-budget.d.ts","sourceRoot":"","sources":["../../src/runtime/memory-budget.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxD,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,CAAC;AAE/D,MAAM,WAAW,iBAAiB;IAChC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED,qBAAa,iBAAiB;IAKhB,QAAQ,CAAC,UAAU,EAAE,MAAM;IAJvC,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0E;IACjG,OAAO,CAAC,MAAM,CAA8B;gBACvB,UAAU,EAAE,MAAM;IAIvC,IAAI,aAAa,IAAI,MAAM,CAAuB;IAClD,IAAI,cAAc,IAAI,MAAM,CAAsD;IAClF,IAAI,WAAW,IAAI,iBAAiB,CAQnC;IAED,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,eAA4B,GAAG,WAAW;IA0BtF,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW;IAIzD,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAgB/C,UAAU,IAAI,IAAI;CAGnB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export class FrameMemoryBudget {
|
|
2
|
+
limitBytes;
|
|
3
|
+
bytes = 0;
|
|
4
|
+
peakBytes = 0;
|
|
5
|
+
byKind = { artifact: 0, cache: 0, scratch: 0 };
|
|
6
|
+
leases = new Set();
|
|
7
|
+
constructor(limitBytes) {
|
|
8
|
+
this.limitBytes = limitBytes;
|
|
9
|
+
if (!Number.isFinite(limitBytes) || limitBytes < 1)
|
|
10
|
+
throw new RangeError("Frame memory limit must be positive.");
|
|
11
|
+
}
|
|
12
|
+
get retainedBytes() { return this.bytes; }
|
|
13
|
+
get remainingBytes() { return Math.max(0, this.limitBytes - this.bytes); }
|
|
14
|
+
get observation() {
|
|
15
|
+
return {
|
|
16
|
+
currentControlledBytes: this.bytes,
|
|
17
|
+
peakControlledBytes: this.peakBytes,
|
|
18
|
+
retainedArtifactBytes: this.byKind.artifact,
|
|
19
|
+
retainedCacheBytes: this.byKind.cache,
|
|
20
|
+
transientScratchBytes: this.byKind.scratch,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
reserve(bytes, label, kind = "artifact") {
|
|
24
|
+
const normalized = Math.max(0, Math.ceil(bytes));
|
|
25
|
+
if (this.bytes + normalized > this.limitBytes) {
|
|
26
|
+
throw Object.assign(new Error(`Frame memory budget exceeded while reserving '${label}'.`), {
|
|
27
|
+
code: "resource_limit_exceeded",
|
|
28
|
+
requestedBytes: normalized,
|
|
29
|
+
retainedBytes: this.bytes,
|
|
30
|
+
limitBytes: this.limitBytes,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const lease = new MemoryLeaseImpl(normalized, label, kind, (released) => {
|
|
34
|
+
if (!this.leases.delete(lease))
|
|
35
|
+
return;
|
|
36
|
+
this.bytes = Math.max(0, this.bytes - released.bytes);
|
|
37
|
+
this.byKind[released.kind] = Math.max(0, this.byKind[released.kind] - released.bytes);
|
|
38
|
+
}, (target, nextKind, priorKind) => {
|
|
39
|
+
if (!this.leases.has(target) || nextKind === priorKind)
|
|
40
|
+
return;
|
|
41
|
+
this.byKind[priorKind] = Math.max(0, this.byKind[priorKind] - target.bytes);
|
|
42
|
+
this.byKind[nextKind] += target.bytes;
|
|
43
|
+
});
|
|
44
|
+
this.bytes += normalized;
|
|
45
|
+
this.byKind[kind] += normalized;
|
|
46
|
+
this.peakBytes = Math.max(this.peakBytes, this.bytes);
|
|
47
|
+
this.leases.add(lease);
|
|
48
|
+
return lease;
|
|
49
|
+
}
|
|
50
|
+
reserveScratch(bytes, label) {
|
|
51
|
+
return this.reserve(bytes, label, "scratch");
|
|
52
|
+
}
|
|
53
|
+
resize(lease, bytes) {
|
|
54
|
+
const target = lease;
|
|
55
|
+
if (!this.leases.has(target) || target.released)
|
|
56
|
+
throw new Error("Cannot resize a released or foreign memory lease.");
|
|
57
|
+
const normalized = Math.max(0, Math.ceil(bytes));
|
|
58
|
+
const delta = normalized - target.bytes;
|
|
59
|
+
if (delta > this.remainingBytes) {
|
|
60
|
+
throw Object.assign(new Error(`Frame memory budget exceeded while resizing '${target.label}'.`), {
|
|
61
|
+
code: "resource_limit_exceeded", requestedBytes: delta, retainedBytes: this.bytes, limitBytes: this.limitBytes,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
this.bytes += delta;
|
|
65
|
+
this.byKind[target.kind] += delta;
|
|
66
|
+
target.setBytes(normalized);
|
|
67
|
+
this.peakBytes = Math.max(this.peakBytes, this.bytes);
|
|
68
|
+
}
|
|
69
|
+
releaseAll() {
|
|
70
|
+
for (const lease of [...this.leases])
|
|
71
|
+
lease.release();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
class MemoryLeaseImpl {
|
|
75
|
+
onRelease;
|
|
76
|
+
onReclassify;
|
|
77
|
+
done = false;
|
|
78
|
+
byteCount;
|
|
79
|
+
leaseLabel;
|
|
80
|
+
leaseKind;
|
|
81
|
+
constructor(bytes, label, kind, onRelease, onReclassify) {
|
|
82
|
+
this.onRelease = onRelease;
|
|
83
|
+
this.onReclassify = onReclassify;
|
|
84
|
+
this.byteCount = bytes;
|
|
85
|
+
this.leaseLabel = label;
|
|
86
|
+
this.leaseKind = kind;
|
|
87
|
+
}
|
|
88
|
+
get bytes() { return this.byteCount; }
|
|
89
|
+
get label() { return this.leaseLabel; }
|
|
90
|
+
get kind() { return this.leaseKind; }
|
|
91
|
+
get released() { return this.done; }
|
|
92
|
+
setBytes(bytes) { this.byteCount = bytes; }
|
|
93
|
+
reclassify(kind, label) {
|
|
94
|
+
if (this.done)
|
|
95
|
+
throw new Error("Cannot reclassify a released memory lease.");
|
|
96
|
+
const prior = this.leaseKind;
|
|
97
|
+
this.onReclassify(this, kind, prior);
|
|
98
|
+
this.leaseKind = kind;
|
|
99
|
+
if (label)
|
|
100
|
+
this.leaseLabel = label;
|
|
101
|
+
}
|
|
102
|
+
release() {
|
|
103
|
+
if (this.done)
|
|
104
|
+
return;
|
|
105
|
+
this.done = true;
|
|
106
|
+
this.onRelease(this);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMapping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I,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,KAAK;YAAE,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IACrC,CAAC;IACD,OAAO;QACL,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Operator } from "../contracts/operator.js";
|
|
2
|
+
export declare class OperatorRegistry {
|
|
3
|
+
private readonly operators;
|
|
4
|
+
register<I, O, C>(operator: Operator<I, O, C>, options?: {
|
|
5
|
+
replace?: boolean;
|
|
6
|
+
}): void;
|
|
7
|
+
unregister(id: string): void;
|
|
8
|
+
get<I = unknown, O = unknown, C = unknown>(id: string): Operator<I, O, C> | undefined;
|
|
9
|
+
list(): readonly Operator<unknown, unknown, unknown>[];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=operator-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator-registry.d.ts","sourceRoot":"","sources":["../../src/runtime/operator-registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0D;IAEpF,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,IAAI;IASzF,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAC5B,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS;IAGrF,IAAI,IAAI,SAAS,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;CACvD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SdkException, sdkError } from "../contracts/errors.js";
|
|
2
|
+
export class OperatorRegistry {
|
|
3
|
+
operators = new Map();
|
|
4
|
+
register(operator, options = {}) {
|
|
5
|
+
const id = operator.descriptor.id;
|
|
6
|
+
if (!id.trim())
|
|
7
|
+
throw new SdkException(sdkError("invalid_configuration", "Operator id must be non-empty."));
|
|
8
|
+
if (this.operators.has(id) && !options.replace) {
|
|
9
|
+
throw new SdkException(sdkError("invalid_configuration", `Operator '${id}' is already registered.`, { operatorId: id }));
|
|
10
|
+
}
|
|
11
|
+
this.operators.set(id, operator);
|
|
12
|
+
}
|
|
13
|
+
unregister(id) { this.operators.delete(id); }
|
|
14
|
+
get(id) {
|
|
15
|
+
return this.operators.get(id);
|
|
16
|
+
}
|
|
17
|
+
list() { return Object.freeze([...this.operators.values()]); }
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=operator-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator-registry.js","sourceRoot":"","sources":["../../src/runtime/operator-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGhE,MAAM,OAAO,gBAAgB;IACV,SAAS,GAAG,IAAI,GAAG,EAA+C,CAAC;IAEpF,QAAQ,CAAU,QAA2B,EAAE,UAAiC,EAAE;QAChF,MAAM,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,uBAAuB,EAAE,gCAAgC,CAAC,CAAC,CAAC;QAC5G,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAC/C,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,uBAAuB,EAAE,aAAa,EAAE,0BAA0B,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;QAC3H,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,QAA+C,CAAC,CAAC;IAC1E,CAAC;IAED,UAAU,CAAC,EAAU,IAAU,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3D,GAAG,CAAwC,EAAU;QACnD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAkC,CAAC;IACjE,CAAC;IACD,IAAI,KAAqD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/G"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ScanOutcome } from "../contracts/result.js";
|
|
2
|
+
export interface DuplicateIdentityOptions {
|
|
3
|
+
includeFormat?: boolean;
|
|
4
|
+
includeSpatialTrack?: boolean;
|
|
5
|
+
maxEntries?: number;
|
|
6
|
+
}
|
|
7
|
+
/** Session-scoped, bounded duplicate suppression for continuous sources. */
|
|
8
|
+
export declare class DuplicateSuppressionPolicy {
|
|
9
|
+
private windowMs;
|
|
10
|
+
private readonly identity;
|
|
11
|
+
private readonly seen;
|
|
12
|
+
private readonly maxEntries;
|
|
13
|
+
constructor(windowMs: number, identity?: DuplicateIdentityOptions);
|
|
14
|
+
updateWindow(windowMs: number): void;
|
|
15
|
+
filter(outcome: ScanOutcome, nowMs?: number): ScanOutcome;
|
|
16
|
+
clear(): void;
|
|
17
|
+
get size(): number;
|
|
18
|
+
private key;
|
|
19
|
+
private prune;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=result-policies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-policies.d.ts","sourceRoot":"","sources":["../../src/runtime/result-policies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,wBAAwB,CAAC;AAEtE,MAAM,WAAW,wBAAwB;IACvC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,4EAA4E;AAC5E,qBAAa,0BAA0B;IAGzB,OAAO,CAAC,QAAQ;IAAU,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAF/D,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA6B;IAClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAChB,QAAQ,EAAE,MAAM,EAAmB,QAAQ,GAAE,wBAA6B;IAI9F,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKpC,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,SAAa,GAAG,WAAW;IA0B7D,KAAK,IAAI,IAAI;IACb,IAAI,IAAI,IAAI,MAAM,CAA2B;IAE7C,OAAO,CAAC,GAAG;IAQX,OAAO,CAAC,KAAK;CAOd"}
|