{"version":3,"sources":["../../web.ts"],"names":["PreferencesWeb","group","this","options","value","impl","getItem","applyPrefix","key","setItem","removeItem","keys","rawKeys","map","k","substring","prefix","length","migrated","existing","oldprefix","Object","filter","indexOf","oldkey","get","push","set","window","localStorage"],"mappings":"wOAaaA,EAAe,kDAA5B,mBACqC,OADrC,qB,2BACUC,MAAQ,mBAAmB,CA+ErC,CADG,OACF,uFA7EQ,+FACgB,kBADEA,EAAK,EAALA,SAErBC,KAAKD,MAAQA,GACd,gDACF,mDAyEF,IAzEE,kEAEM,WAAUE,GAAmB,iFAC4B,OAAxDC,EAAQF,KAAKG,KAAKC,QAAQJ,KAAKK,YAAYJ,EAAQK,MAAK,kBAEvD,CAAEJ,UAAO,gDACjB,mDANA,IAMA,kEAEM,WAAUD,GAAmB,2EAClCD,KAAKG,KAAKI,QAAQP,KAAKK,YAAYJ,EAAQK,KAAML,EAAQC,OAAO,gDACjE,mDAJA,IAIA,qEAEM,WAAaD,GAAsB,2EACxCD,KAAKG,KAAKK,WAAWR,KAAKK,YAAYJ,EAAQK,MAAM,gDACrD,mDAJA,IAIA,mEAEM,qGACgE,OAA/DG,EAAOT,KAAKU,UAAUC,KAAI,SAAAC,GAAC,OAAIA,EAAEC,UAAU,EAAKC,OAAOC,OAAO,IAAC,kBAE9D,CAAEN,SAAM,gDAChB,kDANA,IAMA,oEAEM,gHACaT,KAAKU,WAAS,IAAhC,IAAK,EAAL,qBAAWJ,EAAG,QACZN,KAAKG,KAAKK,WAAWF,EACtB,+EACF,kDANA,IAMA,sEAEM,kHACCU,EAAqB,GACrBC,EAAqB,GACrBC,EAAY,QACZT,EAAOU,OAAOV,KAAKT,KAAKG,MAAMiB,QAAO,SAAAR,GAAC,OAA6B,IAAzBA,EAAES,QAAQH,EAAgB,IAAC,cAEtDT,GAAI,yDAEsB,OAFpCa,EAAM,QACThB,EAAMgB,EAAOT,UAAUK,EAAUH,QACjCb,EAAiC,QAA5B,EAAGF,KAAKG,KAAKC,QAAQkB,UAAO,QAAI,GAAE,UACPtB,KAAKuB,IAAI,CAAEjB,QAAM,QAA1C,GAA0C,SAE3B,kBAFD,EAAnBJ,MAE4B,iBAClCe,EAASO,KAAKlB,GAAK,yCAEbN,KAAKyB,IAAI,CAAEnB,MAAKJ,UAAQ,QAC9Bc,EAASQ,KAAKlB,GAAK,wKAIhB,CAAEU,WAAUC,aAAU,gEAC9B,kDAtBA,IAsBA,wEAEM,oGACa,QACZR,EAAOU,OAAOV,KAAKT,KAAKG,MAAMiB,QAAO,SAAAR,GAAC,OAA6B,IAAzBA,EAAES,QADhC,QACwD,IAAC,cACtDZ,GAAI,IAAzB,IAAK,EAAL,qBAAWa,EAAM,QACftB,KAAKG,KAAKK,WAAWc,EACtB,+EACF,kDARA,IAQA,gBAED,WACE,OAAOI,OAAOC,YAChB,GAAC,kBAED,WACE,MAAsB,kBAAf3B,KAAKD,MAA4B,GAAK,GAAH,OAAMC,KAAKD,MAAK,IAC5D,GAAC,qBAEO,WAAO,WACb,OAAOoB,OAAOV,KAAKT,KAAKG,MAAMiB,QAAO,SAAAR,GAAC,OAA+B,IAA3BA,EAAES,QAAQ,EAAKP,OAAa,GACxE,GAAC,yBAEO,SAAYR,GAClB,OAAON,KAAKc,OAASR,CACvB,KAAC,EA/EyB,C,MAAQ,E","file":"static/js/10.a6b8bf65.chunk.js","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n PreferencesPlugin,\n ConfigureOptions,\n GetOptions,\n GetResult,\n SetOptions,\n RemoveOptions,\n KeysResult,\n MigrateResult,\n} from './definitions';\n\nexport class PreferencesWeb extends WebPlugin implements PreferencesPlugin {\n private group = 'CapacitorStorage';\n\n public async configure({ group }: ConfigureOptions): Promise {\n if (typeof group === 'string') {\n this.group = group;\n }\n }\n\n public async get(options: GetOptions): Promise {\n const value = this.impl.getItem(this.applyPrefix(options.key));\n\n return { value };\n }\n\n public async set(options: SetOptions): Promise {\n this.impl.setItem(this.applyPrefix(options.key), options.value);\n }\n\n public async remove(options: RemoveOptions): Promise {\n this.impl.removeItem(this.applyPrefix(options.key));\n }\n\n public async keys(): Promise {\n const keys = this.rawKeys().map(k => k.substring(this.prefix.length));\n\n return { keys };\n }\n\n public async clear(): Promise {\n for (const key of this.rawKeys()) {\n this.impl.removeItem(key);\n }\n }\n\n public async migrate(): Promise {\n const migrated: string[] = [];\n const existing: string[] = [];\n const oldprefix = '_cap_';\n const keys = Object.keys(this.impl).filter(k => k.indexOf(oldprefix) === 0);\n\n for (const oldkey of keys) {\n const key = oldkey.substring(oldprefix.length);\n const value = this.impl.getItem(oldkey) ?? '';\n const { value: currentValue } = await this.get({ key });\n\n if (typeof currentValue === 'string') {\n existing.push(key);\n } else {\n await this.set({ key, value });\n migrated.push(key);\n }\n }\n\n return { migrated, existing };\n }\n\n public async removeOld(): Promise {\n const oldprefix = '_cap_';\n const keys = Object.keys(this.impl).filter(k => k.indexOf(oldprefix) === 0);\n for (const oldkey of keys) {\n this.impl.removeItem(oldkey);\n }\n }\n\n private get impl(): Storage {\n return window.localStorage;\n }\n\n private get prefix(): string {\n return this.group === 'NativeStorage' ? '' : `${this.group}.`;\n }\n\n private rawKeys(): string[] {\n return Object.keys(this.impl).filter(k => k.indexOf(this.prefix) === 0);\n }\n\n private applyPrefix(key: string) {\n return this.prefix + key;\n }\n}\n"],"sourceRoot":""}