license import { DetectableImage , DetectedImage } from '../../../defs/detected-image.js' ; import { typeIsThing } from '../schema/core-schema-org.js' ; import { ARArtifact , ARTargetTypes } from '../schema/extension-ar-artifacts.js' ; import { ArtifactStore , PerceptionResult , PerceptionState } from './artifact-store.js' ; import { LocalImageStore } from './local-image-store.js' ; import { LocalMarkerStore } from './local-marker-store.js' ; export class LocalArtifactStore implements ArtifactStore { private readonly markerStore = new LocalMarkerStore ( ) ; private readonly imageStore = new LocalImageStore ( ) ; addArtifact ( artifact ) { if ( ! artifact . arTarget ) { return 0 ; } let targets ; if ( Array . isArray ( artifact . arTarget ) ) { targets = artifact . arTarget ; } else { targets = [ artifact . arTarget ] ; } let totalAdded = 0 ; for ( const target of targets ) { if ( ! typeIsThing ( target ) ) { continue ; } switch ( target [ '@type' ] ) { case 'Barcode' : if ( this . markerStore . addMarker ( artifact , target ) ) { totalAdded ++ ; } break ; case 'ARImageTarget' : if ( this . imageStore . addImage ( artifact , target ) ) { totalAdded ++ ; } break ; default : break ; } } return totalAdded ; } async findRelevantArtifacts ? ( state ) { return [ ... this . markerStore . findRelevantArtifacts ( state . markers || [ ] ) , ... this . imageStore . findRelevantArtifacts ( state . images || [ ] ) , ] ; } async getDetectableImages ( state ) { return this . imageStore . getDetectableImages ( ) ; } }