Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 1x 1x 15x 15x 15x 5x 15x 255x 1x | import { addProvider } from '../metaData'; let state: Record<string, any> = {}; // Calibrated pixel spacing per imageId /** * Simple metadata provider that stores some sort of meta data for each imageId. */ const metadataProvider = { /** * Adds a cloned copy of the metadata for an imageId as the given type. * Note that this will strip out any functions or other non-cloneables. * * @param imageId - the imageId for the metadata to store * @param payload - the payload */ add: (imageId: string, payload: { metadata: any; type: string }): void => { metadataProvider.addRaw(imageId, { ...payload, metadata: structuredClone(payload.metadata), }); }, /** * Adds a raw metadata instances for an imageId. This allows preserving * class inheritance values and member functions/proxy instances, but runs * the risk that the raw object can be modified through side affects. */ addRaw: (imageId: string, payload: { metadata: any; type: string }) => { const type = payload.type; if (!state[imageId]) { state[imageId] = {}; } // Use the raw metadata here state[imageId][type] = payload.metadata; }, /** * Returns the metadata for an imageId if it exists. * @param type - the type of metadata to enquire about * @param imageId - the imageId to enquire about */ get: (type: string, imageId: string): any => { return state[imageId]?.[type]; }, /** * Clears all metadata. */ clear: (): void => { state = {}; }, }; addProvider(metadataProvider.get); export default metadataProvider; |