123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- // G:/work/project/2024/手机壳DIY/用户端/phone_uni/node_modules/destr/dist/index.mjs
- var suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
- var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
- var JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
- function jsonParseTransform(key, value) {
- if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
- warnKeyDropped(key);
- return;
- }
- return value;
- }
- function warnKeyDropped(key) {
- console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
- }
- function destr(value, options = {}) {
- if (typeof value !== "string") {
- return value;
- }
- const _value = value.trim();
- if (
- // eslint-disable-next-line unicorn/prefer-at
- value[0] === '"' && value.endsWith('"') && !value.includes("\\")
- ) {
- return _value.slice(1, -1);
- }
- if (_value.length <= 9) {
- const _lval = _value.toLowerCase();
- if (_lval === "true") {
- return true;
- }
- if (_lval === "false") {
- return false;
- }
- if (_lval === "undefined") {
- return void 0;
- }
- if (_lval === "null") {
- return null;
- }
- if (_lval === "nan") {
- return Number.NaN;
- }
- if (_lval === "infinity") {
- return Number.POSITIVE_INFINITY;
- }
- if (_lval === "-infinity") {
- return Number.NEGATIVE_INFINITY;
- }
- }
- if (!JsonSigRx.test(value)) {
- if (options.strict) {
- throw new SyntaxError("[destr] Invalid JSON");
- }
- return value;
- }
- try {
- if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
- if (options.strict) {
- throw new Error("[destr] Possible prototype pollution");
- }
- return JSON.parse(value, jsonParseTransform);
- }
- return JSON.parse(value);
- } catch (error) {
- if (options.strict) {
- throw error;
- }
- return value;
- }
- }
- // G:/work/project/2024/手机壳DIY/用户端/phone_uni/node_modules/deep-pick-omit/dist/index.mjs
- function get(obj, path) {
- if (obj == null)
- return void 0;
- let value = obj;
- for (let i = 0; i < path.length; i++) {
- if (value == null || value[path[i]] == null)
- return void 0;
- value = value[path[i]];
- }
- return value;
- }
- function set(obj, value, path) {
- if (path.length === 0)
- return value;
- const idx = path[0];
- if (path.length > 1) {
- value = set(
- typeof obj !== "object" || obj === null || !Object.prototype.hasOwnProperty.call(obj, idx) ? Number.isInteger(Number(path[1])) ? [] : {} : obj[idx],
- value,
- Array.prototype.slice.call(path, 1)
- );
- }
- if (Number.isInteger(Number(idx)) && Array.isArray(obj))
- return obj.slice()[idx];
- return Object.assign({}, obj, { [idx]: value });
- }
- function unset(obj, path) {
- if (obj == null || path.length === 0)
- return obj;
- if (path.length === 1) {
- if (obj == null)
- return obj;
- if (Number.isInteger(path[0]) && Array.isArray(obj))
- return Array.prototype.slice.call(obj, 0).splice(path[0], 1);
- const result = {};
- for (const p in obj)
- result[p] = obj[p];
- delete result[path[0]];
- return result;
- }
- if (obj[path[0]] == null) {
- if (Number.isInteger(path[0]) && Array.isArray(obj))
- return Array.prototype.concat.call([], obj);
- const result = {};
- for (const p in obj)
- result[p] = obj[p];
- return result;
- }
- return set(
- obj,
- unset(
- obj[path[0]],
- Array.prototype.slice.call(path, 1)
- ),
- [path[0]]
- );
- }
- function deepPickUnsafe(obj, paths) {
- return paths.map((p) => p.split(".")).map((p) => [p, get(obj, p)]).filter((t) => t[1] !== void 0).reduce((acc, cur) => set(acc, cur[1], cur[0]), {});
- }
- function deepOmitUnsafe(obj, paths) {
- return paths.map((p) => p.split(".")).reduce((acc, cur) => unset(acc, cur), obj);
- }
- // G:/work/project/2024/手机壳DIY/用户端/phone_uni/node_modules/pinia-plugin-persistedstate/dist/index.js
- function hydrateStore(store, {
- storage,
- serializer,
- key,
- debug,
- pick,
- omit,
- beforeHydrate,
- afterHydrate
- }, context, runHooks = true) {
- try {
- if (runHooks)
- beforeHydrate == null ? void 0 : beforeHydrate(context);
- const fromStorage = storage.getItem(key);
- if (fromStorage) {
- const deserialized = serializer.deserialize(fromStorage);
- const picked = pick ? deepPickUnsafe(deserialized, pick) : deserialized;
- const omitted = omit ? deepOmitUnsafe(picked, omit) : picked;
- store.$patch(omitted);
- }
- if (runHooks)
- afterHydrate == null ? void 0 : afterHydrate(context);
- } catch (error) {
- if (debug)
- console.error("[pinia-plugin-persistedstate]", error);
- }
- }
- function persistState(state, {
- storage,
- serializer,
- key,
- debug,
- pick,
- omit
- }) {
- try {
- const picked = pick ? deepPickUnsafe(state, pick) : state;
- const omitted = omit ? deepOmitUnsafe(picked, omit) : picked;
- const toStorage = serializer.serialize(omitted);
- storage.setItem(key, toStorage);
- } catch (error) {
- if (debug)
- console.error("[pinia-plugin-persistedstate]", error);
- }
- }
- function createPersistence(context, optionsParser, auto) {
- const { pinia, store, options: { persist = auto } } = context;
- if (!persist)
- return;
- if (!(store.$id in pinia.state.value)) {
- const originalStore = pinia._s.get(store.$id.replace("__hot:", ""));
- if (originalStore)
- Promise.resolve().then(() => originalStore.$persist());
- return;
- }
- const persistenceOptions = Array.isArray(persist) ? persist : persist === true ? [{}] : [persist];
- const persistences = persistenceOptions.map(optionsParser);
- store.$hydrate = ({ runHooks = true } = {}) => {
- persistences.forEach((p) => {
- hydrateStore(store, p, context, runHooks);
- });
- };
- store.$persist = () => {
- persistences.forEach((p) => {
- persistState(store.$state, p);
- });
- };
- persistences.forEach((p) => {
- hydrateStore(store, p, context);
- store.$subscribe(
- (_mutation, state) => persistState(state, p),
- { detached: true }
- );
- });
- }
- function createPersistedState(options = {}) {
- return function(context) {
- createPersistence(
- context,
- (p) => ({
- key: (options.key ? options.key : (x) => x)(p.key ?? context.store.$id),
- debug: p.debug ?? options.debug ?? false,
- serializer: p.serializer ?? options.serializer ?? {
- serialize: (data) => JSON.stringify(data),
- deserialize: (data) => destr(data)
- },
- storage: p.storage ?? options.storage ?? window.localStorage,
- beforeHydrate: p.beforeHydrate,
- afterHydrate: p.afterHydrate,
- pick: p.pick,
- omit: p.omit
- }),
- options.auto ?? false
- );
- };
- }
- var src_default = createPersistedState();
- export {
- createPersistedState,
- src_default as default
- };
- //# sourceMappingURL=pinia-plugin-persistedstate.js.map
|