@cond/simasdk 0.0.0-stage → 0.2.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/CondSimasdk.podspec +18 -0
- package/Package.swift +31 -0
- package/README.md +508 -2
- package/android/build.gradle +63 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/simasdk/SimaFirebasePlugin.java +139 -0
- package/android/src/main/java/com/simasdk/SimaGamesPlugin.java +235 -0
- package/android/src/main/java/com/simasdk/SimaHapticsPlugin.java +101 -0
- package/android/src/main/java/com/simasdk/SimaReviewPlugin.java +48 -0
- package/android/src/main/java/com/simasdk/SimaStoragePlugin.java +79 -0
- package/dist/ads.cjs +214 -0
- package/dist/ads.cjs.map +1 -0
- package/dist/ads.d.cts +98 -0
- package/dist/ads.d.ts +98 -0
- package/dist/ads.js +211 -0
- package/dist/ads.js.map +1 -0
- package/dist/att.cjs +37 -0
- package/dist/att.cjs.map +1 -0
- package/dist/att.d.cts +31 -0
- package/dist/att.d.ts +31 -0
- package/dist/att.js +33 -0
- package/dist/att.js.map +1 -0
- package/dist/back-button.cjs +95 -0
- package/dist/back-button.cjs.map +1 -0
- package/dist/back-button.d.cts +45 -0
- package/dist/back-button.d.ts +45 -0
- package/dist/back-button.js +88 -0
- package/dist/back-button.js.map +1 -0
- package/dist/cli.js +723 -0
- package/dist/firebase.cjs +102 -0
- package/dist/firebase.cjs.map +1 -0
- package/dist/firebase.d.cts +40 -0
- package/dist/firebase.d.ts +40 -0
- package/dist/firebase.js +99 -0
- package/dist/firebase.js.map +1 -0
- package/dist/games.cjs +98 -0
- package/dist/games.cjs.map +1 -0
- package/dist/games.d.cts +73 -0
- package/dist/games.d.ts +73 -0
- package/dist/games.js +95 -0
- package/dist/games.js.map +1 -0
- package/dist/haptics.cjs +81 -0
- package/dist/haptics.cjs.map +1 -0
- package/dist/haptics.d.cts +51 -0
- package/dist/haptics.d.ts +51 -0
- package/dist/haptics.js +78 -0
- package/dist/haptics.js.map +1 -0
- package/dist/index.cjs +233 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +99 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.js +226 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +118 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +51 -0
- package/dist/react.d.ts +51 -0
- package/dist/react.js +113 -0
- package/dist/react.js.map +1 -0
- package/dist/review.cjs +195 -0
- package/dist/review.cjs.map +1 -0
- package/dist/review.d.cts +76 -0
- package/dist/review.d.ts +76 -0
- package/dist/review.js +192 -0
- package/dist/review.js.map +1 -0
- package/dist/shell.cjs +97 -0
- package/dist/shell.cjs.map +1 -0
- package/dist/shell.d.cts +36 -0
- package/dist/shell.d.ts +36 -0
- package/dist/shell.js +91 -0
- package/dist/shell.js.map +1 -0
- package/dist/storage.cjs +140 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +48 -0
- package/dist/storage.d.ts +48 -0
- package/dist/storage.js +136 -0
- package/dist/storage.js.map +1 -0
- package/ios/Sources/SimasdkPlugin/SimaAttPlugin.swift +41 -0
- package/ios/Sources/SimasdkPlugin/SimaFirebasePlugin.swift +188 -0
- package/ios/Sources/SimasdkPlugin/SimaGamesPlugin.swift +145 -0
- package/ios/Sources/SimasdkPlugin/SimaHapticsPlugin.swift +61 -0
- package/ios/Sources/SimasdkPlugin/SimaReviewPlugin.swift +40 -0
- package/ios/Sources/SimasdkPlugin/SimaStoragePlugin.swift +58 -0
- package/package.json +128 -4
- package/skills/simasdk/SKILL.md +189 -0
package/dist/review.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { registerPlugin, Capacitor } from '@capacitor/core';
|
|
2
|
+
|
|
3
|
+
// src/review.ts
|
|
4
|
+
var SimaReview = registerPlugin("SimaReview");
|
|
5
|
+
var STORAGE_PREFIX = "simasdk:review:v1:";
|
|
6
|
+
var MS_PER_DAY = 24 * 60 * 60 * 1e3;
|
|
7
|
+
var fallbackMemoryStore = /* @__PURE__ */ new Map();
|
|
8
|
+
var defaultStorage = {
|
|
9
|
+
getItem(key) {
|
|
10
|
+
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
11
|
+
try {
|
|
12
|
+
return window.localStorage.getItem(key);
|
|
13
|
+
} catch {
|
|
14
|
+
return fallbackMemoryStore.get(key) ?? null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return fallbackMemoryStore.get(key) ?? null;
|
|
18
|
+
},
|
|
19
|
+
setItem(key, value) {
|
|
20
|
+
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
21
|
+
try {
|
|
22
|
+
window.localStorage.setItem(key, value);
|
|
23
|
+
return;
|
|
24
|
+
} catch {
|
|
25
|
+
fallbackMemoryStore.set(key, value);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
fallbackMemoryStore.set(key, value);
|
|
30
|
+
},
|
|
31
|
+
removeItem(key) {
|
|
32
|
+
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
33
|
+
try {
|
|
34
|
+
window.localStorage.removeItem(key);
|
|
35
|
+
return;
|
|
36
|
+
} catch {
|
|
37
|
+
fallbackMemoryStore.delete(key);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
fallbackMemoryStore.delete(key);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var defaultRequester = {
|
|
45
|
+
isSupported() {
|
|
46
|
+
if (typeof window === "undefined") {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return Capacitor.isNativePlatform();
|
|
50
|
+
},
|
|
51
|
+
async requestReview() {
|
|
52
|
+
if (!Capacitor.isPluginAvailable("SimaReview")) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
'Native SimaReview plugin is not available. Run "npx cap sync" and rebuild your native project.'
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
await SimaReview.requestReview();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var keyLocks = /* @__PURE__ */ new WeakMap();
|
|
61
|
+
function withKeyLock(storage, storageKey, fn) {
|
|
62
|
+
let storageMap = keyLocks.get(storage);
|
|
63
|
+
if (!storageMap) {
|
|
64
|
+
storageMap = /* @__PURE__ */ new Map();
|
|
65
|
+
keyLocks.set(storage, storageMap);
|
|
66
|
+
}
|
|
67
|
+
const previous = storageMap.get(storageKey) ?? Promise.resolve();
|
|
68
|
+
let release;
|
|
69
|
+
const current = new Promise((resolve) => {
|
|
70
|
+
release = resolve;
|
|
71
|
+
});
|
|
72
|
+
const chained = previous.then(() => current);
|
|
73
|
+
storageMap.set(storageKey, chained);
|
|
74
|
+
return previous.then(() => fn()).finally(() => {
|
|
75
|
+
release();
|
|
76
|
+
if (storageMap?.get(storageKey) === chained) {
|
|
77
|
+
storageMap.delete(storageKey);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function parseState(raw) {
|
|
82
|
+
if (!raw) {
|
|
83
|
+
return { actionCount: 0, lastRequestedAt: null };
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const parsed = JSON.parse(raw);
|
|
87
|
+
const actionCount = typeof parsed.actionCount === "number" && Number.isInteger(parsed.actionCount) && parsed.actionCount >= 0 ? parsed.actionCount : 0;
|
|
88
|
+
const lastRequestedAt = typeof parsed.lastRequestedAt === "number" && Number.isFinite(parsed.lastRequestedAt) ? parsed.lastRequestedAt : null;
|
|
89
|
+
return { actionCount, lastRequestedAt };
|
|
90
|
+
} catch {
|
|
91
|
+
return { actionCount: 0, lastRequestedAt: null };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function createReviewPolicy(config) {
|
|
95
|
+
if (typeof config.key !== "string" || config.key.trim().length === 0) {
|
|
96
|
+
throw new Error('createReviewPolicy: "key" must be a non-empty string.');
|
|
97
|
+
}
|
|
98
|
+
if (!Number.isInteger(config.minimumActions) || config.minimumActions < 1) {
|
|
99
|
+
throw new Error('createReviewPolicy: "minimumActions" must be an integer >= 1.');
|
|
100
|
+
}
|
|
101
|
+
if (typeof config.cooldownDays !== "number" || !Number.isFinite(config.cooldownDays) || config.cooldownDays < 0) {
|
|
102
|
+
throw new Error('createReviewPolicy: "cooldownDays" must be a finite number >= 0.');
|
|
103
|
+
}
|
|
104
|
+
const storage = config.storage ?? defaultStorage;
|
|
105
|
+
const requester = config.requester ?? defaultRequester;
|
|
106
|
+
const now = config.now ?? (() => Date.now());
|
|
107
|
+
const storageKey = `${STORAGE_PREFIX}${config.key}`;
|
|
108
|
+
const cooldownMs = config.cooldownDays * MS_PER_DAY;
|
|
109
|
+
async function readState() {
|
|
110
|
+
const raw = await storage.getItem(storageKey);
|
|
111
|
+
return parseState(raw);
|
|
112
|
+
}
|
|
113
|
+
async function writeState(state) {
|
|
114
|
+
await storage.setItem(storageKey, JSON.stringify(state));
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
async recordSuccess() {
|
|
118
|
+
return withKeyLock(storage, storageKey, async () => {
|
|
119
|
+
const state = await readState();
|
|
120
|
+
const nextCount = state.actionCount + 1;
|
|
121
|
+
const updatedState = {
|
|
122
|
+
actionCount: nextCount,
|
|
123
|
+
lastRequestedAt: state.lastRequestedAt
|
|
124
|
+
};
|
|
125
|
+
await writeState(updatedState);
|
|
126
|
+
if (nextCount < config.minimumActions) {
|
|
127
|
+
return {
|
|
128
|
+
status: "not_eligible",
|
|
129
|
+
actionCount: nextCount,
|
|
130
|
+
minimumActions: config.minimumActions,
|
|
131
|
+
lastRequestedAt: state.lastRequestedAt
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const currentTime = now();
|
|
135
|
+
if (state.lastRequestedAt !== null) {
|
|
136
|
+
const nextEligibleAt = state.lastRequestedAt + cooldownMs;
|
|
137
|
+
if (currentTime < nextEligibleAt) {
|
|
138
|
+
return {
|
|
139
|
+
status: "cooldown",
|
|
140
|
+
actionCount: nextCount,
|
|
141
|
+
lastRequestedAt: state.lastRequestedAt,
|
|
142
|
+
nextEligibleAt
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (!requester.isSupported()) {
|
|
147
|
+
return {
|
|
148
|
+
status: "unsupported",
|
|
149
|
+
actionCount: nextCount,
|
|
150
|
+
lastRequestedAt: state.lastRequestedAt
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
await requester.requestReview();
|
|
155
|
+
const requestedAt = now();
|
|
156
|
+
await writeState({
|
|
157
|
+
actionCount: nextCount,
|
|
158
|
+
lastRequestedAt: requestedAt
|
|
159
|
+
});
|
|
160
|
+
return {
|
|
161
|
+
status: "requested",
|
|
162
|
+
actionCount: nextCount,
|
|
163
|
+
lastRequestedAt: requestedAt
|
|
164
|
+
};
|
|
165
|
+
} catch (err) {
|
|
166
|
+
return {
|
|
167
|
+
status: "failed",
|
|
168
|
+
actionCount: nextCount,
|
|
169
|
+
lastRequestedAt: state.lastRequestedAt,
|
|
170
|
+
error: err instanceof Error ? err : new Error(String(err))
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
async getState() {
|
|
176
|
+
return withKeyLock(storage, storageKey, readState);
|
|
177
|
+
},
|
|
178
|
+
async reset() {
|
|
179
|
+
return withKeyLock(storage, storageKey, async () => {
|
|
180
|
+
if (storage.removeItem) {
|
|
181
|
+
await storage.removeItem(storageKey);
|
|
182
|
+
} else {
|
|
183
|
+
await writeState({ actionCount: 0, lastRequestedAt: null });
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { SimaReview, createReviewPolicy };
|
|
191
|
+
//# sourceMappingURL=review.js.map
|
|
192
|
+
//# sourceMappingURL=review.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../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AA,YACL,MAAA,EAAQ,QAAA;AAAA,YACR,WAAA,EAAa,SAAA;AAAA,YACb,iBAAiB,KAAA,CAAM,eAAA;AAAA,YACvB,KAAA,EAAO,eAAe,KAAA,GAAQ,GAAA,GAAM,IAAI,KAAA,CAAM,MAAA,CAAO,GAAG,CAAC;AAAA,WAC3D;AAAA,QACF;AAAA,MACF,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,IAEA,MAAM,QAAA,GAAiC;AACrC,MAAA,OAAO,WAAA,CAAY,OAAA,EAAS,UAAA,EAAY,SAAS,CAAA;AAAA,IACnD,CAAA;AAAA,IAEA,MAAM,KAAA,GAAuB;AAC3B,MAAA,OAAO,WAAA,CAAY,OAAA,EAAS,UAAA,EAAY,YAAY;AAClD,QAAA,IAAI,QAAQ,UAAA,EAAY;AACtB,UAAA,MAAM,OAAA,CAAQ,WAAW,UAAU,CAAA;AAAA,QACrC,CAAA,MAAO;AACL,UAAA,MAAM,WAAW,EAAE,WAAA,EAAa,CAAA,EAAG,eAAA,EAAiB,MAAM,CAAA;AAAA,QAC5D;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF","file":"review.js","sourcesContent":["import { Capacitor, registerPlugin } from '@capacitor/core';\n\nexport interface SimaReviewNativePlugin {\n requestReview(): Promise<void>;\n}\n\nexport const SimaReview = registerPlugin<SimaReviewNativePlugin>('SimaReview');\n\nexport interface ReviewStorage {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n removeItem?(key: string): void | Promise<void>;\n}\n\nexport interface ReviewRequester {\n isSupported(): boolean;\n requestReview(): Promise<void>;\n}\n\nexport interface ReviewPolicyConfig {\n /** Unique key identifying this review trigger policy in persistent storage. */\n key: string;\n /** Minimum number of successful actions required before requesting a review (integer >= 1). */\n minimumActions: number;\n /** Minimum number of days to wait after a successful native review request (number >= 0). */\n cooldownDays: number;\n /** Optional custom storage backend. Defaults to `localStorage` with SSR-safe in-memory fallback. */\n storage?: ReviewStorage;\n /** Optional custom native requester (primarily for testing). */\n requester?: ReviewRequester;\n /** Optional clock function returning epoch milliseconds (primarily for testing). */\n now?: () => number;\n}\n\nexport interface ReviewState {\n actionCount: number;\n lastRequestedAt: number | null;\n}\n\nexport type ReviewStatus =\n | 'not_eligible'\n | 'cooldown'\n | 'requested'\n | 'unsupported'\n | 'failed';\n\nexport type ReviewRecordResult =\n | {\n status: 'not_eligible';\n actionCount: number;\n minimumActions: number;\n lastRequestedAt: number | null;\n }\n | {\n status: 'cooldown';\n actionCount: number;\n lastRequestedAt: number;\n nextEligibleAt: number;\n }\n | {\n status: 'requested';\n actionCount: number;\n lastRequestedAt: number;\n }\n | {\n status: 'unsupported';\n actionCount: number;\n lastRequestedAt: number | null;\n }\n | {\n status: 'failed';\n actionCount: number;\n lastRequestedAt: number | null;\n error: Error;\n };\n\nexport interface ReviewPolicy {\n /**\n * Records one successful product action and, if eligibility and cooldown rules pass,\n * invokes the native in-app review API.\n *\n * Failure semantics:\n * - `actionCount` is incremented and persisted before invoking the native review API.\n * - If the native call fails, `lastRequestedAt` is NOT updated (no cooldown penalty)\n * and `{ status: 'failed', ... }` is returned without throwing.\n * - Concurrent calls for the same `key` are serialized so at most one native request is made.\n */\n recordSuccess(): Promise<ReviewRecordResult>;\n /** Returns the current persisted state for this policy key. */\n getState(): Promise<ReviewState>;\n /** Clears persisted state for this policy key. */\n reset(): Promise<void>;\n}\n\nconst STORAGE_PREFIX = 'simasdk:review:v1:';\nconst MS_PER_DAY = 24 * 60 * 60 * 1000;\n\nconst fallbackMemoryStore = new Map<string, string>();\n\nconst defaultStorage: ReviewStorage = {\n getItem(key: string): string | null {\n if (typeof window !== 'undefined' && typeof window.localStorage !== 'undefined') {\n try {\n return window.localStorage.getItem(key);\n } catch {\n return fallbackMemoryStore.get(key) ?? null;\n }\n }\n return fallbackMemoryStore.get(key) ?? null;\n },\n setItem(key: string, value: string): void {\n if (typeof window !== 'undefined' && typeof window.localStorage !== 'undefined') {\n try {\n window.localStorage.setItem(key, value);\n return;\n } catch {\n fallbackMemoryStore.set(key, value);\n return;\n }\n }\n fallbackMemoryStore.set(key, value);\n },\n removeItem(key: string): void {\n if (typeof window !== 'undefined' && typeof window.localStorage !== 'undefined') {\n try {\n window.localStorage.removeItem(key);\n return;\n } catch {\n fallbackMemoryStore.delete(key);\n return;\n }\n }\n fallbackMemoryStore.delete(key);\n },\n};\n\nconst defaultRequester: ReviewRequester = {\n isSupported(): boolean {\n if (typeof window === 'undefined') {\n return false;\n }\n return Capacitor.isNativePlatform();\n },\n async requestReview(): Promise<void> {\n if (!Capacitor.isPluginAvailable('SimaReview')) {\n throw new Error(\n 'Native SimaReview plugin is not available. Run \"npx cap sync\" and rebuild your native project.',\n );\n }\n await SimaReview.requestReview();\n },\n};\n\n/**\n * Per-(storage, key) async serialization chains so concurrent `recordSuccess()` calls\n * even across distinct `createReviewPolicy({ key })` instances sharing the same key\n * cannot race or trigger duplicate native review requests.\n */\nconst keyLocks = new WeakMap<ReviewStorage, Map<string, Promise<void>>>();\n\nfunction withKeyLock<T>(\n storage: ReviewStorage,\n storageKey: string,\n fn: () => Promise<T>,\n): Promise<T> {\n let storageMap = keyLocks.get(storage);\n if (!storageMap) {\n storageMap = new Map();\n keyLocks.set(storage, storageMap);\n }\n\n const previous = storageMap.get(storageKey) ?? Promise.resolve();\n let release!: () => void;\n const current = new Promise<void>((resolve) => {\n release = resolve;\n });\n const chained = previous.then(() => current);\n storageMap.set(storageKey, chained);\n\n return previous\n .then(() => fn())\n .finally(() => {\n release();\n if (storageMap?.get(storageKey) === chained) {\n storageMap.delete(storageKey);\n }\n });\n}\n\nfunction parseState(raw: string | null): ReviewState {\n if (!raw) {\n return { actionCount: 0, lastRequestedAt: null };\n }\n try {\n const parsed = JSON.parse(raw) as Partial<ReviewState>;\n const actionCount =\n typeof parsed.actionCount === 'number' &&\n Number.isInteger(parsed.actionCount) &&\n parsed.actionCount >= 0\n ? parsed.actionCount\n : 0;\n const lastRequestedAt =\n typeof parsed.lastRequestedAt === 'number' && Number.isFinite(parsed.lastRequestedAt)\n ? parsed.lastRequestedAt\n : null;\n return { actionCount, lastRequestedAt };\n } catch {\n return { actionCount: 0, lastRequestedAt: null };\n }\n}\n\nexport function createReviewPolicy(config: ReviewPolicyConfig): ReviewPolicy {\n if (typeof config.key !== 'string' || config.key.trim().length === 0) {\n throw new Error('createReviewPolicy: \"key\" must be a non-empty string.');\n }\n if (!Number.isInteger(config.minimumActions) || config.minimumActions < 1) {\n throw new Error('createReviewPolicy: \"minimumActions\" must be an integer >= 1.');\n }\n if (\n typeof config.cooldownDays !== 'number' ||\n !Number.isFinite(config.cooldownDays) ||\n config.cooldownDays < 0\n ) {\n throw new Error('createReviewPolicy: \"cooldownDays\" must be a finite number >= 0.');\n }\n\n const storage = config.storage ?? defaultStorage;\n const requester = config.requester ?? defaultRequester;\n const now = config.now ?? (() => Date.now());\n const storageKey = `${STORAGE_PREFIX}${config.key}`;\n const cooldownMs = config.cooldownDays * MS_PER_DAY;\n\n async function readState(): Promise<ReviewState> {\n const raw = await storage.getItem(storageKey);\n return parseState(raw);\n }\n\n async function writeState(state: ReviewState): Promise<void> {\n await storage.setItem(storageKey, JSON.stringify(state));\n }\n\n return {\n async recordSuccess(): Promise<ReviewRecordResult> {\n return withKeyLock(storage, storageKey, async () => {\n const state = await readState();\n const nextCount = state.actionCount + 1;\n const updatedState: ReviewState = {\n actionCount: nextCount,\n lastRequestedAt: state.lastRequestedAt,\n };\n await writeState(updatedState);\n\n if (nextCount < config.minimumActions) {\n return {\n status: 'not_eligible',\n actionCount: nextCount,\n minimumActions: config.minimumActions,\n lastRequestedAt: state.lastRequestedAt,\n };\n }\n\n const currentTime = now();\n if (state.lastRequestedAt !== null) {\n const nextEligibleAt = state.lastRequestedAt + cooldownMs;\n if (currentTime < nextEligibleAt) {\n return {\n status: 'cooldown',\n actionCount: nextCount,\n lastRequestedAt: state.lastRequestedAt,\n nextEligibleAt,\n };\n }\n }\n\n if (!requester.isSupported()) {\n return {\n status: 'unsupported',\n actionCount: nextCount,\n lastRequestedAt: state.lastRequestedAt,\n };\n }\n\n try {\n await requester.requestReview();\n const requestedAt = now();\n await writeState({\n actionCount: nextCount,\n lastRequestedAt: requestedAt,\n });\n return {\n status: 'requested',\n actionCount: nextCount,\n lastRequestedAt: requestedAt,\n };\n } catch (err) {\n return {\n status: 'failed',\n actionCount: nextCount,\n lastRequestedAt: state.lastRequestedAt,\n error: err instanceof Error ? err : new Error(String(err)),\n };\n }\n });\n },\n\n async getState(): Promise<ReviewState> {\n return withKeyLock(storage, storageKey, readState);\n },\n\n async reset(): Promise<void> {\n return withKeyLock(storage, storageKey, async () => {\n if (storage.removeItem) {\n await storage.removeItem(storageKey);\n } else {\n await writeState({ actionCount: 0, lastRequestedAt: null });\n }\n });\n },\n };\n}\n"]}
|
package/dist/shell.cjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
// src/shell.ts
|
|
6
|
+
var StatusBarPlugin = core.registerPlugin("StatusBar");
|
|
7
|
+
var SplashScreenPlugin = core.registerPlugin("SplashScreen");
|
|
8
|
+
var ScreenOrientationPlugin = core.registerPlugin("ScreenOrientation");
|
|
9
|
+
function isNative() {
|
|
10
|
+
return typeof window !== "undefined" && core.Capacitor.isNativePlatform();
|
|
11
|
+
}
|
|
12
|
+
async function setStatusBar(options) {
|
|
13
|
+
if (!isNative() || !core.Capacitor.isPluginAvailable("StatusBar")) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
if (options.style) {
|
|
18
|
+
const mapped = options.style === "dark" ? "DARK" : options.style === "light" ? "LIGHT" : "DEFAULT";
|
|
19
|
+
await StatusBarPlugin.setStyle({ style: mapped });
|
|
20
|
+
}
|
|
21
|
+
if (typeof options.overlay === "boolean") {
|
|
22
|
+
await StatusBarPlugin.setOverlaysWebView({ overlay: options.overlay });
|
|
23
|
+
}
|
|
24
|
+
if (options.backgroundColor && core.Capacitor.getPlatform() === "android") {
|
|
25
|
+
await StatusBarPlugin.setBackgroundColor({ color: options.backgroundColor });
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function hideSplashScreen() {
|
|
33
|
+
if (!isNative() || !core.Capacitor.isPluginAvailable("SplashScreen")) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
await SplashScreenPlugin.hide();
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function lockOrientation(orientation) {
|
|
44
|
+
if (!isNative() || !core.Capacitor.isPluginAvailable("ScreenOrientation")) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
await ScreenOrientationPlugin.lock({ orientation });
|
|
49
|
+
return true;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function unlockOrientation() {
|
|
55
|
+
if (!isNative() || !core.Capacitor.isPluginAvailable("ScreenOrientation")) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
await ScreenOrientationPlugin.unlock();
|
|
60
|
+
return true;
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function initShell(config = {}) {
|
|
66
|
+
if (!isNative()) {
|
|
67
|
+
return {
|
|
68
|
+
platform: "web",
|
|
69
|
+
statusBarApplied: false,
|
|
70
|
+
splashHidden: false,
|
|
71
|
+
orientationLocked: false
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const [statusBarApplied, orientationLocked, splashHidden] = await Promise.all([
|
|
75
|
+
config.statusBarStyle || config.statusBarBackgroundColor || typeof config.statusBarOverlay === "boolean" ? setStatusBar({
|
|
76
|
+
style: config.statusBarStyle,
|
|
77
|
+
backgroundColor: config.statusBarBackgroundColor,
|
|
78
|
+
overlay: config.statusBarOverlay
|
|
79
|
+
}) : Promise.resolve(false),
|
|
80
|
+
config.orientation ? lockOrientation(config.orientation) : Promise.resolve(false),
|
|
81
|
+
config.hideSplash ? hideSplashScreen() : Promise.resolve(false)
|
|
82
|
+
]);
|
|
83
|
+
return {
|
|
84
|
+
platform: "native",
|
|
85
|
+
statusBarApplied,
|
|
86
|
+
splashHidden,
|
|
87
|
+
orientationLocked
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
exports.hideSplashScreen = hideSplashScreen;
|
|
92
|
+
exports.initShell = initShell;
|
|
93
|
+
exports.lockOrientation = lockOrientation;
|
|
94
|
+
exports.setStatusBar = setStatusBar;
|
|
95
|
+
exports.unlockOrientation = unlockOrientation;
|
|
96
|
+
//# sourceMappingURL=shell.cjs.map
|
|
97
|
+
//# sourceMappingURL=shell.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/shell.ts"],"names":["registerPlugin","Capacitor"],"mappings":";;;;;AAwCA,IAAM,eAAA,GAAkBA,oBAA8B,WAAW,CAAA;AACjE,IAAM,kBAAA,GAAqBA,oBAAiC,cAAc,CAAA;AAC1E,IAAM,uBAAA,GAA0BA,oBAAsC,mBAAmB,CAAA;AAEzF,SAAS,QAAA,GAAoB;AAC3B,EAAA,OAAO,OAAO,MAAA,KAAW,WAAA,IAAeC,cAAA,CAAU,gBAAA,EAAiB;AACrE;AAEA,eAAsB,aAAa,OAAA,EAId;AACnB,EAAA,IAAI,CAAC,QAAA,EAAS,IAAK,CAACA,cAAA,CAAU,iBAAA,CAAkB,WAAW,CAAA,EAAG;AAC5D,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,IAAI;AACF,IAAA,IAAI,QAAQ,KAAA,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AAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AACF","file":"shell.cjs","sourcesContent":["import { Capacitor, registerPlugin } from '@capacitor/core';\n\nexport type ShellStatusBarStyle = 'dark' | 'light' | 'default';\nexport type ShellOrientation = 'portrait' | 'landscape' | 'portrait-primary' | 'landscape-primary';\n\nexport interface ShellConfig {\n /** Status bar icon style (`'dark'` = light icons on dark bg, `'light'` = dark icons on light bg). */\n statusBarStyle?: ShellStatusBarStyle;\n /** Hex background color for Android status bar (e.g. `'#121212'`). */\n statusBarBackgroundColor?: string;\n /** Whether the WebView overlays the status bar (edge-to-edge). */\n statusBarOverlay?: boolean;\n /** Automatically hide `@capacitor/splash-screen` during `initShell()` (defaults to `false`). */\n hideSplash?: boolean;\n /** Lock screen orientation via `@capacitor/screen-orientation` if installed. */\n orientation?: ShellOrientation;\n}\n\nexport interface ShellInitResult {\n platform: 'native' | 'web';\n statusBarApplied: boolean;\n splashHidden: boolean;\n orientationLocked: boolean;\n}\n\ninterface StatusBarLike {\n setStyle(options: { style: 'DARK' | 'LIGHT' | 'DEFAULT' }): Promise<void>;\n setBackgroundColor(options: { color: string }): Promise<void>;\n setOverlaysWebView(options: { overlay: boolean }): Promise<void>;\n}\n\ninterface SplashScreenLike {\n hide(): Promise<void>;\n}\n\ninterface ScreenOrientationLike {\n lock(options: { orientation: ShellOrientation }): Promise<void>;\n unlock(): Promise<void>;\n}\n\nconst StatusBarPlugin = registerPlugin<StatusBarLike>('StatusBar');\nconst SplashScreenPlugin = registerPlugin<SplashScreenLike>('SplashScreen');\nconst ScreenOrientationPlugin = registerPlugin<ScreenOrientationLike>('ScreenOrientation');\n\nfunction isNative(): boolean {\n return typeof window !== 'undefined' && Capacitor.isNativePlatform();\n}\n\nexport async function setStatusBar(options: {\n style?: ShellStatusBarStyle;\n backgroundColor?: string;\n overlay?: boolean;\n}): Promise<boolean> {\n if (!isNative() || !Capacitor.isPluginAvailable('StatusBar')) {\n return false;\n }\n\n try {\n if (options.style) {\n const mapped =\n options.style === 'dark' ? 'DARK' : options.style === 'light' ? 'LIGHT' : 'DEFAULT';\n await StatusBarPlugin.setStyle({ style: mapped });\n }\n if (typeof options.overlay === 'boolean') {\n await StatusBarPlugin.setOverlaysWebView({ overlay: options.overlay });\n }\n if (options.backgroundColor && Capacitor.getPlatform() === 'android') {\n await StatusBarPlugin.setBackgroundColor({ color: options.backgroundColor });\n }\n return true;\n } catch {\n return false;\n }\n}\n\nexport async function hideSplashScreen(): Promise<boolean> {\n if (!isNative() || !Capacitor.isPluginAvailable('SplashScreen')) {\n return false;\n }\n try {\n await SplashScreenPlugin.hide();\n return true;\n } catch {\n return false;\n }\n}\n\nexport async function lockOrientation(orientation: ShellOrientation): Promise<boolean> {\n if (!isNative() || !Capacitor.isPluginAvailable('ScreenOrientation')) {\n return false;\n }\n try {\n await ScreenOrientationPlugin.lock({ orientation });\n return true;\n } catch {\n return false;\n }\n}\n\nexport async function unlockOrientation(): Promise<boolean> {\n if (!isNative() || !Capacitor.isPluginAvailable('ScreenOrientation')) {\n return false;\n }\n try {\n await ScreenOrientationPlugin.unlock();\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Bootstraps common native mobile shell settings (StatusBar, SplashScreen, ScreenOrientation)\n * in a single idempotent, non-throwing call. Only touches Capacitor plugins that are actually\n * installed in the host app; safely no-ops on Web/SSR.\n */\nexport async function initShell(config: ShellConfig = {}): Promise<ShellInitResult> {\n if (!isNative()) {\n return {\n platform: 'web',\n statusBarApplied: false,\n splashHidden: false,\n orientationLocked: false,\n };\n }\n\n const [statusBarApplied, orientationLocked, splashHidden] = await Promise.all([\n config.statusBarStyle ||\n config.statusBarBackgroundColor ||\n typeof config.statusBarOverlay === 'boolean'\n ? setStatusBar({\n style: config.statusBarStyle,\n backgroundColor: config.statusBarBackgroundColor,\n overlay: config.statusBarOverlay,\n })\n : Promise.resolve(false),\n config.orientation ? lockOrientation(config.orientation) : Promise.resolve(false),\n config.hideSplash ? hideSplashScreen() : Promise.resolve(false),\n ]);\n\n return {\n platform: 'native',\n statusBarApplied,\n splashHidden,\n orientationLocked,\n };\n}\n"]}
|
package/dist/shell.d.cts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type ShellStatusBarStyle = 'dark' | 'light' | 'default';
|
|
2
|
+
type ShellOrientation = 'portrait' | 'landscape' | 'portrait-primary' | 'landscape-primary';
|
|
3
|
+
interface ShellConfig {
|
|
4
|
+
/** Status bar icon style (`'dark'` = light icons on dark bg, `'light'` = dark icons on light bg). */
|
|
5
|
+
statusBarStyle?: ShellStatusBarStyle;
|
|
6
|
+
/** Hex background color for Android status bar (e.g. `'#121212'`). */
|
|
7
|
+
statusBarBackgroundColor?: string;
|
|
8
|
+
/** Whether the WebView overlays the status bar (edge-to-edge). */
|
|
9
|
+
statusBarOverlay?: boolean;
|
|
10
|
+
/** Automatically hide `@capacitor/splash-screen` during `initShell()` (defaults to `false`). */
|
|
11
|
+
hideSplash?: boolean;
|
|
12
|
+
/** Lock screen orientation via `@capacitor/screen-orientation` if installed. */
|
|
13
|
+
orientation?: ShellOrientation;
|
|
14
|
+
}
|
|
15
|
+
interface ShellInitResult {
|
|
16
|
+
platform: 'native' | 'web';
|
|
17
|
+
statusBarApplied: boolean;
|
|
18
|
+
splashHidden: boolean;
|
|
19
|
+
orientationLocked: boolean;
|
|
20
|
+
}
|
|
21
|
+
declare function setStatusBar(options: {
|
|
22
|
+
style?: ShellStatusBarStyle;
|
|
23
|
+
backgroundColor?: string;
|
|
24
|
+
overlay?: boolean;
|
|
25
|
+
}): Promise<boolean>;
|
|
26
|
+
declare function hideSplashScreen(): Promise<boolean>;
|
|
27
|
+
declare function lockOrientation(orientation: ShellOrientation): Promise<boolean>;
|
|
28
|
+
declare function unlockOrientation(): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Bootstraps common native mobile shell settings (StatusBar, SplashScreen, ScreenOrientation)
|
|
31
|
+
* in a single idempotent, non-throwing call. Only touches Capacitor plugins that are actually
|
|
32
|
+
* installed in the host app; safely no-ops on Web/SSR.
|
|
33
|
+
*/
|
|
34
|
+
declare function initShell(config?: ShellConfig): Promise<ShellInitResult>;
|
|
35
|
+
|
|
36
|
+
export { type ShellConfig, type ShellInitResult, type ShellOrientation, type ShellStatusBarStyle, hideSplashScreen, initShell, lockOrientation, setStatusBar, unlockOrientation };
|
package/dist/shell.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type ShellStatusBarStyle = 'dark' | 'light' | 'default';
|
|
2
|
+
type ShellOrientation = 'portrait' | 'landscape' | 'portrait-primary' | 'landscape-primary';
|
|
3
|
+
interface ShellConfig {
|
|
4
|
+
/** Status bar icon style (`'dark'` = light icons on dark bg, `'light'` = dark icons on light bg). */
|
|
5
|
+
statusBarStyle?: ShellStatusBarStyle;
|
|
6
|
+
/** Hex background color for Android status bar (e.g. `'#121212'`). */
|
|
7
|
+
statusBarBackgroundColor?: string;
|
|
8
|
+
/** Whether the WebView overlays the status bar (edge-to-edge). */
|
|
9
|
+
statusBarOverlay?: boolean;
|
|
10
|
+
/** Automatically hide `@capacitor/splash-screen` during `initShell()` (defaults to `false`). */
|
|
11
|
+
hideSplash?: boolean;
|
|
12
|
+
/** Lock screen orientation via `@capacitor/screen-orientation` if installed. */
|
|
13
|
+
orientation?: ShellOrientation;
|
|
14
|
+
}
|
|
15
|
+
interface ShellInitResult {
|
|
16
|
+
platform: 'native' | 'web';
|
|
17
|
+
statusBarApplied: boolean;
|
|
18
|
+
splashHidden: boolean;
|
|
19
|
+
orientationLocked: boolean;
|
|
20
|
+
}
|
|
21
|
+
declare function setStatusBar(options: {
|
|
22
|
+
style?: ShellStatusBarStyle;
|
|
23
|
+
backgroundColor?: string;
|
|
24
|
+
overlay?: boolean;
|
|
25
|
+
}): Promise<boolean>;
|
|
26
|
+
declare function hideSplashScreen(): Promise<boolean>;
|
|
27
|
+
declare function lockOrientation(orientation: ShellOrientation): Promise<boolean>;
|
|
28
|
+
declare function unlockOrientation(): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Bootstraps common native mobile shell settings (StatusBar, SplashScreen, ScreenOrientation)
|
|
31
|
+
* in a single idempotent, non-throwing call. Only touches Capacitor plugins that are actually
|
|
32
|
+
* installed in the host app; safely no-ops on Web/SSR.
|
|
33
|
+
*/
|
|
34
|
+
declare function initShell(config?: ShellConfig): Promise<ShellInitResult>;
|
|
35
|
+
|
|
36
|
+
export { type ShellConfig, type ShellInitResult, type ShellOrientation, type ShellStatusBarStyle, hideSplashScreen, initShell, lockOrientation, setStatusBar, unlockOrientation };
|
package/dist/shell.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { registerPlugin, Capacitor } from '@capacitor/core';
|
|
2
|
+
|
|
3
|
+
// src/shell.ts
|
|
4
|
+
var StatusBarPlugin = registerPlugin("StatusBar");
|
|
5
|
+
var SplashScreenPlugin = registerPlugin("SplashScreen");
|
|
6
|
+
var ScreenOrientationPlugin = registerPlugin("ScreenOrientation");
|
|
7
|
+
function isNative() {
|
|
8
|
+
return typeof window !== "undefined" && Capacitor.isNativePlatform();
|
|
9
|
+
}
|
|
10
|
+
async function setStatusBar(options) {
|
|
11
|
+
if (!isNative() || !Capacitor.isPluginAvailable("StatusBar")) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
if (options.style) {
|
|
16
|
+
const mapped = options.style === "dark" ? "DARK" : options.style === "light" ? "LIGHT" : "DEFAULT";
|
|
17
|
+
await StatusBarPlugin.setStyle({ style: mapped });
|
|
18
|
+
}
|
|
19
|
+
if (typeof options.overlay === "boolean") {
|
|
20
|
+
await StatusBarPlugin.setOverlaysWebView({ overlay: options.overlay });
|
|
21
|
+
}
|
|
22
|
+
if (options.backgroundColor && Capacitor.getPlatform() === "android") {
|
|
23
|
+
await StatusBarPlugin.setBackgroundColor({ color: options.backgroundColor });
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function hideSplashScreen() {
|
|
31
|
+
if (!isNative() || !Capacitor.isPluginAvailable("SplashScreen")) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
await SplashScreenPlugin.hide();
|
|
36
|
+
return true;
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function lockOrientation(orientation) {
|
|
42
|
+
if (!isNative() || !Capacitor.isPluginAvailable("ScreenOrientation")) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
await ScreenOrientationPlugin.lock({ orientation });
|
|
47
|
+
return true;
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function unlockOrientation() {
|
|
53
|
+
if (!isNative() || !Capacitor.isPluginAvailable("ScreenOrientation")) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
await ScreenOrientationPlugin.unlock();
|
|
58
|
+
return true;
|
|
59
|
+
} catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function initShell(config = {}) {
|
|
64
|
+
if (!isNative()) {
|
|
65
|
+
return {
|
|
66
|
+
platform: "web",
|
|
67
|
+
statusBarApplied: false,
|
|
68
|
+
splashHidden: false,
|
|
69
|
+
orientationLocked: false
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const [statusBarApplied, orientationLocked, splashHidden] = await Promise.all([
|
|
73
|
+
config.statusBarStyle || config.statusBarBackgroundColor || typeof config.statusBarOverlay === "boolean" ? setStatusBar({
|
|
74
|
+
style: config.statusBarStyle,
|
|
75
|
+
backgroundColor: config.statusBarBackgroundColor,
|
|
76
|
+
overlay: config.statusBarOverlay
|
|
77
|
+
}) : Promise.resolve(false),
|
|
78
|
+
config.orientation ? lockOrientation(config.orientation) : Promise.resolve(false),
|
|
79
|
+
config.hideSplash ? hideSplashScreen() : Promise.resolve(false)
|
|
80
|
+
]);
|
|
81
|
+
return {
|
|
82
|
+
platform: "native",
|
|
83
|
+
statusBarApplied,
|
|
84
|
+
splashHidden,
|
|
85
|
+
orientationLocked
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { hideSplashScreen, initShell, lockOrientation, setStatusBar, unlockOrientation };
|
|
90
|
+
//# sourceMappingURL=shell.js.map
|
|
91
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/shell.ts"],"names":[],"mappings":";;;AAwCA,IAAM,eAAA,GAAkB,eAA8B,WAAW,CAAA;AACjE,IAAM,kBAAA,GAAqB,eAAiC,cAAc,CAAA;AAC1E,IAAM,uBAAA,GAA0B,eAAsC,mBAAmB,CAAA;AAEzF,SAAS,QAAA,GAAoB;AAC3B,EAAA,OAAO,OAAO,MAAA,KAAW,WAAA,IAAe,SAAA,CAAU,gBAAA,EAAiB;AACrE;AAEA,eAAsB,aAAa,OAAA,EAId;AACnB,EAAA,IAAI,CAAC,QAAA,EAAS,IAAK,CAAC,SAAA,CAAU,iBAAA,CAAkB,WAAW,CAAA,EAAG;AAC5D,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,IAAI;AACF,IAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,MAAA,MAAM,MAAA,GACJ,QAAQ,KAAA,KAAU,MAAA,GAAS,SAAS,OAAA,CAAQ,KAAA,KAAU,UAAU,OAAA,GAAU,SAAA;AAC5E,MAAA,MAAM,eAAA,CAAgB,QAAA,CAAS,EAAE,KAAA,EAAO,QAAQ,CAAA;AAAA,IAClD;AACA,IAAA,IAAI,OAAO,OAAA,CAAQ,OAAA,KAAY,SAAA,EAAW;AACxC,MAAA,MAAM,gBAAgB,kBAAA,CAAmB,EAAE,OAAA,EAAS,OAAA,CA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AAA;AAAA,EACT;AACF;AAOA,eAAsB,SAAA,CAAU,MAAA,GAAsB,EAAC,EAA6B;AAClF,EAAA,IAAI,CAAC,UAAS,EAAG;AACf,IAAA,OAAO;AAAA,MACL,QAAA,EAAU,KAAA;AAAA,MACV,gBAAA,EAAkB,KAAA;AAAA,MAClB,YAAA,EAAc,KAAA;AAAA,MACd,iBAAA,EAAmB;AAAA,KACrB;AAAA,EACF;AAEA,EAAA,MAAM,CAAC,gBAAA,EAAkB,iBAAA,EAAmB,YAAY,CAAA,GAAI,MAAM,QAAQ,GAAA,CAAI;AAAA,IAC5E,MAAA,CAAO,kBACP,MAAA,CAAO,wBAAA,IACP,OAAO,MAAA,CAAO,gBAAA,KAAqB,YAC/B,YAAA,CAAa;AAAA,MACX,OAAO,MAAA,CAAO,cAAA;AAAA,MACd,iBAAiB,MAAA,CAAO,wBAAA;AAAA,MACxB,SAAS,MAAA,CAAO;AAAA,KACjB,CAAA,GACD,OAAA,CAAQ,OAAA,CAAQ,KAAK,CAAA;AAAA,IACzB,MAAA,CAAO,cAAc,eAAA,CAAgB,MAAA,CAAO,WAAW,CAAA,GAAI,OAAA,CAAQ,QAAQ,KAAK,CAAA;AAAA,IAChF,OAAO,UAAA,GAAa,gBAAA,EAAiB,GAAI,OAAA,CAAQ,QAAQ,KAAK;AAAA,GAC/D,CAAA;AAED,EAAA,OAAO;AAAA,IACL,QAAA,EAAU,QAAA;AAAA,IACV,gBAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AACF","file":"shell.js","sourcesContent":["import { Capacitor, registerPlugin } from '@capacitor/core';\n\nexport type ShellStatusBarStyle = 'dark' | 'light' | 'default';\nexport type ShellOrientation = 'portrait' | 'landscape' | 'portrait-primary' | 'landscape-primary';\n\nexport interface ShellConfig {\n /** Status bar icon style (`'dark'` = light icons on dark bg, `'light'` = dark icons on light bg). */\n statusBarStyle?: ShellStatusBarStyle;\n /** Hex background color for Android status bar (e.g. `'#121212'`). */\n statusBarBackgroundColor?: string;\n /** Whether the WebView overlays the status bar (edge-to-edge). */\n statusBarOverlay?: boolean;\n /** Automatically hide `@capacitor/splash-screen` during `initShell()` (defaults to `false`). */\n hideSplash?: boolean;\n /** Lock screen orientation via `@capacitor/screen-orientation` if installed. */\n orientation?: ShellOrientation;\n}\n\nexport interface ShellInitResult {\n platform: 'native' | 'web';\n statusBarApplied: boolean;\n splashHidden: boolean;\n orientationLocked: boolean;\n}\n\ninterface StatusBarLike {\n setStyle(options: { style: 'DARK' | 'LIGHT' | 'DEFAULT' }): Promise<void>;\n setBackgroundColor(options: { color: string }): Promise<void>;\n setOverlaysWebView(options: { overlay: boolean }): Promise<void>;\n}\n\ninterface SplashScreenLike {\n hide(): Promise<void>;\n}\n\ninterface ScreenOrientationLike {\n lock(options: { orientation: ShellOrientation }): Promise<void>;\n unlock(): Promise<void>;\n}\n\nconst StatusBarPlugin = registerPlugin<StatusBarLike>('StatusBar');\nconst SplashScreenPlugin = registerPlugin<SplashScreenLike>('SplashScreen');\nconst ScreenOrientationPlugin = registerPlugin<ScreenOrientationLike>('ScreenOrientation');\n\nfunction isNative(): boolean {\n return typeof window !== 'undefined' && Capacitor.isNativePlatform();\n}\n\nexport async function setStatusBar(options: {\n style?: ShellStatusBarStyle;\n backgroundColor?: string;\n overlay?: boolean;\n}): Promise<boolean> {\n if (!isNative() || !Capacitor.isPluginAvailable('StatusBar')) {\n return false;\n }\n\n try {\n if (options.style) {\n const mapped =\n options.style === 'dark' ? 'DARK' : options.style === 'light' ? 'LIGHT' : 'DEFAULT';\n await StatusBarPlugin.setStyle({ style: mapped });\n }\n if (typeof options.overlay === 'boolean') {\n await StatusBarPlugin.setOverlaysWebView({ overlay: options.overlay });\n }\n if (options.backgroundColor && Capacitor.getPlatform() === 'android') {\n await StatusBarPlugin.setBackgroundColor({ color: options.backgroundColor });\n }\n return true;\n } catch {\n return false;\n }\n}\n\nexport async function hideSplashScreen(): Promise<boolean> {\n if (!isNative() || !Capacitor.isPluginAvailable('SplashScreen')) {\n return false;\n }\n try {\n await SplashScreenPlugin.hide();\n return true;\n } catch {\n return false;\n }\n}\n\nexport async function lockOrientation(orientation: ShellOrientation): Promise<boolean> {\n if (!isNative() || !Capacitor.isPluginAvailable('ScreenOrientation')) {\n return false;\n }\n try {\n await ScreenOrientationPlugin.lock({ orientation });\n return true;\n } catch {\n return false;\n }\n}\n\nexport async function unlockOrientation(): Promise<boolean> {\n if (!isNative() || !Capacitor.isPluginAvailable('ScreenOrientation')) {\n return false;\n }\n try {\n await ScreenOrientationPlugin.unlock();\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Bootstraps common native mobile shell settings (StatusBar, SplashScreen, ScreenOrientation)\n * in a single idempotent, non-throwing call. Only touches Capacitor plugins that are actually\n * installed in the host app; safely no-ops on Web/SSR.\n */\nexport async function initShell(config: ShellConfig = {}): Promise<ShellInitResult> {\n if (!isNative()) {\n return {\n platform: 'web',\n statusBarApplied: false,\n splashHidden: false,\n orientationLocked: false,\n };\n }\n\n const [statusBarApplied, orientationLocked, splashHidden] = await Promise.all([\n config.statusBarStyle ||\n config.statusBarBackgroundColor ||\n typeof config.statusBarOverlay === 'boolean'\n ? setStatusBar({\n style: config.statusBarStyle,\n backgroundColor: config.statusBarBackgroundColor,\n overlay: config.statusBarOverlay,\n })\n : Promise.resolve(false),\n config.orientation ? lockOrientation(config.orientation) : Promise.resolve(false),\n config.hideSplash ? hideSplashScreen() : Promise.resolve(false),\n ]);\n\n return {\n platform: 'native',\n statusBarApplied,\n splashHidden,\n orientationLocked,\n };\n}\n"]}
|
package/dist/storage.cjs
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
// src/storage.ts
|
|
6
|
+
var SimaStorage = core.registerPlugin("SimaStorage");
|
|
7
|
+
var memoryFallback = /* @__PURE__ */ new Map();
|
|
8
|
+
function canUseNativeStorage() {
|
|
9
|
+
return typeof window !== "undefined" && core.Capacitor.isNativePlatform() && core.Capacitor.isPluginAvailable("SimaStorage");
|
|
10
|
+
}
|
|
11
|
+
var defaultStorageBackend = {
|
|
12
|
+
async getItem(key) {
|
|
13
|
+
if (canUseNativeStorage()) {
|
|
14
|
+
const { value } = await SimaStorage.get({ key });
|
|
15
|
+
return value ?? null;
|
|
16
|
+
}
|
|
17
|
+
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
18
|
+
try {
|
|
19
|
+
return window.localStorage.getItem(key);
|
|
20
|
+
} catch {
|
|
21
|
+
return memoryFallback.get(key) ?? null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return memoryFallback.get(key) ?? null;
|
|
25
|
+
},
|
|
26
|
+
async setItem(key, value) {
|
|
27
|
+
if (canUseNativeStorage()) {
|
|
28
|
+
await SimaStorage.set({ key, value });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
32
|
+
try {
|
|
33
|
+
window.localStorage.setItem(key, value);
|
|
34
|
+
return;
|
|
35
|
+
} catch {
|
|
36
|
+
memoryFallback.set(key, value);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
memoryFallback.set(key, value);
|
|
41
|
+
},
|
|
42
|
+
async removeItem(key) {
|
|
43
|
+
if (canUseNativeStorage()) {
|
|
44
|
+
await SimaStorage.remove({ key });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
48
|
+
try {
|
|
49
|
+
window.localStorage.removeItem(key);
|
|
50
|
+
return;
|
|
51
|
+
} catch {
|
|
52
|
+
memoryFallback.delete(key);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
memoryFallback.delete(key);
|
|
57
|
+
},
|
|
58
|
+
async clearPrefix(prefix) {
|
|
59
|
+
if (canUseNativeStorage()) {
|
|
60
|
+
await SimaStorage.clearPrefix({ prefix });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
64
|
+
try {
|
|
65
|
+
const toDelete = [];
|
|
66
|
+
for (let i = 0; i < window.localStorage.length; i += 1) {
|
|
67
|
+
const k = window.localStorage.key(i);
|
|
68
|
+
if (k && k.startsWith(prefix)) {
|
|
69
|
+
toDelete.push(k);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const k of toDelete) {
|
|
73
|
+
window.localStorage.removeItem(k);
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
} catch {
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const k of Array.from(memoryFallback.keys())) {
|
|
80
|
+
if (k.startsWith(prefix)) {
|
|
81
|
+
memoryFallback.delete(k);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
function createStorage(config = {}) {
|
|
87
|
+
const namespace = config.namespace ?? "default";
|
|
88
|
+
const version = config.version ?? 1;
|
|
89
|
+
const backend = config.backend ?? defaultStorageBackend;
|
|
90
|
+
const prefix = `simasdk:store:${namespace}:`;
|
|
91
|
+
function fullKey(key) {
|
|
92
|
+
return `${prefix}${key}`;
|
|
93
|
+
}
|
|
94
|
+
async function readOptional(key) {
|
|
95
|
+
const raw = await backend.getItem(fullKey(key));
|
|
96
|
+
if (raw === null) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const parsed = JSON.parse(raw);
|
|
101
|
+
if (typeof parsed !== "object" || parsed === null || !("d" in parsed)) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const storedVersion = typeof parsed.v === "number" ? parsed.v : 1;
|
|
105
|
+
if (storedVersion !== version && config.migrate) {
|
|
106
|
+
const migrated = config.migrate(key, parsed.d, storedVersion);
|
|
107
|
+
await backend.setItem(fullKey(key), JSON.stringify({ v: version, d: migrated }));
|
|
108
|
+
return migrated;
|
|
109
|
+
}
|
|
110
|
+
return parsed.d;
|
|
111
|
+
} catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
async get(key, fallback) {
|
|
117
|
+
const value = await readOptional(key);
|
|
118
|
+
return value === null ? fallback : value;
|
|
119
|
+
},
|
|
120
|
+
getOptional: readOptional,
|
|
121
|
+
async set(key, value) {
|
|
122
|
+
const envelope = { v: version, d: value };
|
|
123
|
+
await backend.setItem(fullKey(key), JSON.stringify(envelope));
|
|
124
|
+
},
|
|
125
|
+
async remove(key) {
|
|
126
|
+
await backend.removeItem(fullKey(key));
|
|
127
|
+
},
|
|
128
|
+
async clear() {
|
|
129
|
+
if (backend.clearPrefix) {
|
|
130
|
+
await backend.clearPrefix(prefix);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
exports.SimaStorage = SimaStorage;
|
|
137
|
+
exports.createStorage = createStorage;
|
|
138
|
+
exports.defaultStorageBackend = defaultStorageBackend;
|
|
139
|
+
//# sourceMappingURL=storage.cjs.map
|
|
140
|
+
//# sourceMappingURL=storage.cjs.map
|