@akanjs/next 0.0.39 → 0.0.40
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/csrTypes-B6ATv9-y.d.ts +88 -0
- package/index.d.ts +33 -0
- package/index.js +20 -2723
- package/package.json +2 -35
- package/src/bootCsr.d.ts +3 -0
- package/src/bootCsr.js +206 -0
- package/src/createNextMiddleware.d.ts +5 -0
- package/src/createNextMiddleware.js +88 -0
- package/src/createRobotPage.d.ts +5 -0
- package/src/createRobotPage.js +39 -0
- package/src/createSitemapPage.d.ts +5 -0
- package/src/createSitemapPage.js +34 -0
- package/src/index.d.ts +33 -0
- package/src/index.js +82 -0
- package/src/lazy.d.ts +8 -0
- package/src/lazy.js +40 -0
- package/src/makePageProto.d.ts +42 -0
- package/src/makePageProto.js +147 -0
- package/src/types.d.ts +9 -0
- package/src/types.js +15 -0
- package/src/useCamera.d.ts +11 -0
- package/src/useCamera.js +114 -0
- package/src/useCodepush.d.ts +51 -0
- package/src/useCodepush.js +115 -0
- package/src/useContact.d.ts +10 -0
- package/src/useContact.js +73 -0
- package/src/useCsrValues.d.ts +44 -0
- package/src/useCsrValues.js +924 -0
- package/src/useDebounce.d.ts +3 -0
- package/src/useDebounce.js +42 -0
- package/src/useFetch.d.ts +8 -0
- package/src/useFetch.js +54 -0
- package/src/useGeoLocation.d.ts +12 -0
- package/src/useGeoLocation.js +51 -0
- package/src/useHistory.d.ts +24 -0
- package/src/useHistory.js +88 -0
- package/src/useInterval.d.ts +5 -0
- package/src/useInterval.js +49 -0
- package/src/useLocation.d.ts +12 -0
- package/src/useLocation.js +92 -0
- package/src/usePurchase.d.ts +20 -0
- package/src/usePurchase.js +139 -0
- package/src/usePushNoti.d.ts +8 -0
- package/src/usePushNoti.js +68 -0
- package/src/useThrottle.d.ts +3 -0
- package/src/useThrottle.js +44 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var useDebounce_exports = {};
|
|
21
|
+
__export(useDebounce_exports, {
|
|
22
|
+
useDebounce: () => useDebounce
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useDebounce_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
const debounce = /* @__PURE__ */ __name((callback, wait = 500) => {
|
|
27
|
+
let timer;
|
|
28
|
+
return (...args) => {
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
timer = setTimeout(() => {
|
|
31
|
+
callback(...args);
|
|
32
|
+
}, wait);
|
|
33
|
+
};
|
|
34
|
+
}, "debounce");
|
|
35
|
+
const useDebounce = /* @__PURE__ */ __name((callback, states = [], wait = 100) => {
|
|
36
|
+
const fn = (0, import_react.useCallback)(debounce(callback, wait), states);
|
|
37
|
+
return fn;
|
|
38
|
+
}, "useDebounce");
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
useDebounce
|
|
42
|
+
});
|
package/src/useFetch.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var useFetch_exports = {};
|
|
21
|
+
__export(useFetch_exports, {
|
|
22
|
+
useFetch: () => useFetch
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useFetch_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
const useFetch = /* @__PURE__ */ __name((fnOrPromise, { onError } = {}) => {
|
|
27
|
+
const [fetchState, setFetchState] = (0, import_react.useState)(fnOrPromise instanceof Promise ? {
|
|
28
|
+
fulfilled: false,
|
|
29
|
+
value: null
|
|
30
|
+
} : {
|
|
31
|
+
fulfilled: true,
|
|
32
|
+
value: fnOrPromise
|
|
33
|
+
});
|
|
34
|
+
(0, import_react.useEffect)(() => {
|
|
35
|
+
void (async () => {
|
|
36
|
+
try {
|
|
37
|
+
const ret = fnOrPromise instanceof Promise ? await fnOrPromise : fnOrPromise;
|
|
38
|
+
setFetchState({
|
|
39
|
+
fulfilled: true,
|
|
40
|
+
value: ret
|
|
41
|
+
});
|
|
42
|
+
} catch (err) {
|
|
43
|
+
const content = `Error: ${typeof err === "string" ? err : err.message}`;
|
|
44
|
+
onError?.(content);
|
|
45
|
+
throw new Error(content);
|
|
46
|
+
}
|
|
47
|
+
})();
|
|
48
|
+
}, []);
|
|
49
|
+
return fetchState;
|
|
50
|
+
}, "useFetch");
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
useFetch
|
|
54
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as _capacitor_geolocation from '@capacitor/geolocation';
|
|
2
|
+
import * as _capacitor_core from '@capacitor/core';
|
|
3
|
+
|
|
4
|
+
declare const useGeoLocation: () => {
|
|
5
|
+
checkPermission: () => Promise<{
|
|
6
|
+
geolocation: _capacitor_core.PermissionState;
|
|
7
|
+
coarseLocation: _capacitor_core.PermissionState;
|
|
8
|
+
}>;
|
|
9
|
+
getPosition: () => Promise<_capacitor_geolocation.Position | undefined>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { useGeoLocation };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var useGeoLocation_exports = {};
|
|
21
|
+
__export(useGeoLocation_exports, {
|
|
22
|
+
useGeoLocation: () => useGeoLocation
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useGeoLocation_exports);
|
|
25
|
+
var import_geolocation = require("@capacitor/geolocation");
|
|
26
|
+
const useGeoLocation = /* @__PURE__ */ __name(() => {
|
|
27
|
+
const checkPermission = /* @__PURE__ */ __name(async () => {
|
|
28
|
+
const { location: geolocation, coarseLocation } = await import_geolocation.Geolocation.requestPermissions();
|
|
29
|
+
return {
|
|
30
|
+
geolocation,
|
|
31
|
+
coarseLocation
|
|
32
|
+
};
|
|
33
|
+
}, "checkPermission");
|
|
34
|
+
const getPosition = /* @__PURE__ */ __name(async () => {
|
|
35
|
+
const { geolocation, coarseLocation } = await checkPermission();
|
|
36
|
+
if (geolocation === "denied" || coarseLocation === "denied") {
|
|
37
|
+
location.assign("app-settings:");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const coordinates = await import_geolocation.Geolocation.getCurrentPosition();
|
|
41
|
+
return coordinates;
|
|
42
|
+
}, "getPosition");
|
|
43
|
+
return {
|
|
44
|
+
checkPermission,
|
|
45
|
+
getPosition
|
|
46
|
+
};
|
|
47
|
+
}, "useGeoLocation");
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
useGeoLocation
|
|
51
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { L as Location, H as History } from '../csrTypes-B6ATv9-y.js';
|
|
3
|
+
import 'react-spring';
|
|
4
|
+
|
|
5
|
+
interface setForwardOptions {
|
|
6
|
+
type: "push" | "replace" | "popForward";
|
|
7
|
+
location: Location;
|
|
8
|
+
scrollTop?: number;
|
|
9
|
+
}
|
|
10
|
+
interface setBackOptions {
|
|
11
|
+
type: "back" | "popBack";
|
|
12
|
+
location: Location;
|
|
13
|
+
scrollTop?: number;
|
|
14
|
+
}
|
|
15
|
+
declare const useHistory: (locations?: Location[]) => {
|
|
16
|
+
history: react.MutableRefObject<History>;
|
|
17
|
+
setHistoryForward: ({ type, location, scrollTop }: setForwardOptions) => void;
|
|
18
|
+
setHistoryBack: ({ location, scrollTop }: setBackOptions) => void;
|
|
19
|
+
getCurrentLocation: () => Location;
|
|
20
|
+
getPrevLocation: () => Location | null;
|
|
21
|
+
getScrollTop: (pathname?: string) => number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { useHistory };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var useHistory_exports = {};
|
|
21
|
+
__export(useHistory_exports, {
|
|
22
|
+
useHistory: () => useHistory
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useHistory_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
const useHistory = /* @__PURE__ */ __name((locations = []) => {
|
|
27
|
+
const history = (0, import_react.useRef)({
|
|
28
|
+
type: "initial",
|
|
29
|
+
locations,
|
|
30
|
+
scrollMap: /* @__PURE__ */ new Map([
|
|
31
|
+
[
|
|
32
|
+
window.location.pathname,
|
|
33
|
+
0
|
|
34
|
+
]
|
|
35
|
+
]),
|
|
36
|
+
idxMap: /* @__PURE__ */ new Map([
|
|
37
|
+
[
|
|
38
|
+
window.location.pathname,
|
|
39
|
+
0
|
|
40
|
+
]
|
|
41
|
+
]),
|
|
42
|
+
cachedLocationMap: /* @__PURE__ */ new Map(),
|
|
43
|
+
idx: 0
|
|
44
|
+
});
|
|
45
|
+
const setHistoryForward = (0, import_react.useCallback)(({ type, location, scrollTop = 0 }) => {
|
|
46
|
+
history.current.type = "forward";
|
|
47
|
+
history.current.scrollMap.set(location.pathname, scrollTop);
|
|
48
|
+
history.current.idxMap.set(location.pathname, history.current.idx);
|
|
49
|
+
if (type === "push") history.current.locations = [
|
|
50
|
+
...history.current.locations.slice(0, history.current.idx + 1),
|
|
51
|
+
location
|
|
52
|
+
];
|
|
53
|
+
else if (type === "replace") history.current.locations = [
|
|
54
|
+
...history.current.locations.slice(0, history.current.idx),
|
|
55
|
+
location
|
|
56
|
+
];
|
|
57
|
+
if (location.pathRoute.pageState.cache) history.current.cachedLocationMap.set(location.pathRoute.path, location);
|
|
58
|
+
if (type === "push" || type === "popForward") history.current.idx++;
|
|
59
|
+
}, []);
|
|
60
|
+
const setHistoryBack = (0, import_react.useCallback)(({ location, scrollTop = 0 }) => {
|
|
61
|
+
history.current.type = "back";
|
|
62
|
+
history.current.scrollMap.set(location.pathname, scrollTop);
|
|
63
|
+
history.current.idxMap.set(location.pathname, history.current.idx);
|
|
64
|
+
if (location.pathRoute.pageState.cache) history.current.cachedLocationMap.set(location.pathRoute.path, location);
|
|
65
|
+
history.current.idx--;
|
|
66
|
+
}, []);
|
|
67
|
+
const getCurrentLocation = (0, import_react.useCallback)(() => {
|
|
68
|
+
return history.current.locations[history.current.idx];
|
|
69
|
+
}, []);
|
|
70
|
+
const getPrevLocation = (0, import_react.useCallback)(() => {
|
|
71
|
+
return history.current.locations[history.current.idx - 1] ?? null;
|
|
72
|
+
}, []);
|
|
73
|
+
const getScrollTop = (0, import_react.useCallback)((pathname = history.current.locations[history.current.idx]?.pathname ?? "/") => {
|
|
74
|
+
return history.current.scrollMap.get(pathname) ?? 0;
|
|
75
|
+
}, []);
|
|
76
|
+
return {
|
|
77
|
+
history,
|
|
78
|
+
setHistoryForward,
|
|
79
|
+
setHistoryBack,
|
|
80
|
+
getCurrentLocation,
|
|
81
|
+
getPrevLocation,
|
|
82
|
+
getScrollTop
|
|
83
|
+
};
|
|
84
|
+
}, "useHistory");
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
useHistory
|
|
88
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var useInterval_exports = {};
|
|
21
|
+
__export(useInterval_exports, {
|
|
22
|
+
useInterval: () => useInterval
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useInterval_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
const useInterval = /* @__PURE__ */ __name((callback, delay) => {
|
|
27
|
+
const savedCallback = (0, import_react.useRef)(null);
|
|
28
|
+
(0, import_react.useEffect)(() => {
|
|
29
|
+
savedCallback.current = callback;
|
|
30
|
+
}, [
|
|
31
|
+
callback
|
|
32
|
+
]);
|
|
33
|
+
(0, import_react.useEffect)(() => {
|
|
34
|
+
const tick = /* @__PURE__ */ __name(() => {
|
|
35
|
+
void savedCallback.current?.();
|
|
36
|
+
}, "tick");
|
|
37
|
+
const id = setInterval(tick, delay);
|
|
38
|
+
return () => {
|
|
39
|
+
clearInterval(id);
|
|
40
|
+
};
|
|
41
|
+
}, [
|
|
42
|
+
delay
|
|
43
|
+
]);
|
|
44
|
+
return savedCallback;
|
|
45
|
+
}, "useInterval");
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
useInterval
|
|
49
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { R as RouteGuide, L as Location } from '../csrTypes-B6ATv9-y.js';
|
|
2
|
+
import 'react';
|
|
3
|
+
import 'react-spring';
|
|
4
|
+
|
|
5
|
+
interface UseLocationOptions {
|
|
6
|
+
rootRouteGuide: RouteGuide;
|
|
7
|
+
}
|
|
8
|
+
declare const useLocation: ({ rootRouteGuide }: UseLocationOptions) => {
|
|
9
|
+
getLocation: (href: string) => Location;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { useLocation };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var useLocation_exports = {};
|
|
21
|
+
__export(useLocation_exports, {
|
|
22
|
+
useLocation: () => useLocation
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useLocation_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
const useLocation = /* @__PURE__ */ __name(({ rootRouteGuide }) => {
|
|
27
|
+
const getLocation = (0, import_react.useCallback)((href) => {
|
|
28
|
+
const getPathSegments = /* @__PURE__ */ __name((pathname2) => {
|
|
29
|
+
return [
|
|
30
|
+
...pathname2.split("/").filter((pathSegment) => !!pathSegment).map((pathSegment) => `/${pathSegment}`)
|
|
31
|
+
];
|
|
32
|
+
}, "getPathSegments");
|
|
33
|
+
const getPathRoute = /* @__PURE__ */ __name((pathname2) => {
|
|
34
|
+
const pathSegments = getPathSegments(pathname2);
|
|
35
|
+
const getTargetRouteGuide = /* @__PURE__ */ __name((pathSegments2, routeGuide) => {
|
|
36
|
+
const pathSegment = pathSegments2.shift();
|
|
37
|
+
if (!pathSegment) return routeGuide;
|
|
38
|
+
const childrenSegments = Object.keys(routeGuide.children);
|
|
39
|
+
const matchingPathSegment = childrenSegments.find((segment) => segment === pathSegment);
|
|
40
|
+
const paramSegment = childrenSegments.find((segment) => segment.startsWith("/:"));
|
|
41
|
+
const childRouteGuide = matchingPathSegment ? routeGuide.children[pathSegment] : paramSegment ? routeGuide.children[paramSegment] : null;
|
|
42
|
+
if (!childRouteGuide) throw new Error("404");
|
|
43
|
+
return getTargetRouteGuide(pathSegments2, childRouteGuide);
|
|
44
|
+
}, "getTargetRouteGuide");
|
|
45
|
+
const targetRouteGuide = getTargetRouteGuide(pathSegments, rootRouteGuide);
|
|
46
|
+
const pathRoute2 = targetRouteGuide.pathRoute;
|
|
47
|
+
if (!pathRoute2) {
|
|
48
|
+
window.location.assign("/404");
|
|
49
|
+
throw new Error("404");
|
|
50
|
+
}
|
|
51
|
+
return pathRoute2;
|
|
52
|
+
}, "getPathRoute");
|
|
53
|
+
const getParams = /* @__PURE__ */ __name((pathname2, pathRoute2) => {
|
|
54
|
+
const pathSegments = getPathSegments(pathname2);
|
|
55
|
+
return pathRoute2.pathSegments.reduce((params2, pathSegment, idx) => {
|
|
56
|
+
if (pathSegment.startsWith("/:")) params2[pathSegment.slice(2)] = pathSegments[idx - 1].slice(1);
|
|
57
|
+
return params2;
|
|
58
|
+
}, {});
|
|
59
|
+
}, "getParams");
|
|
60
|
+
const getSearchParams = /* @__PURE__ */ __name((search2) => {
|
|
61
|
+
return [
|
|
62
|
+
...new URLSearchParams(search2).entries()
|
|
63
|
+
].reduce((params2, [key, value]) => {
|
|
64
|
+
params2[key] = params2[key] ? [
|
|
65
|
+
...Array.isArray(params2[key]) ? params2[key] : [
|
|
66
|
+
params2[key]
|
|
67
|
+
],
|
|
68
|
+
value
|
|
69
|
+
] : value;
|
|
70
|
+
return params2;
|
|
71
|
+
}, {});
|
|
72
|
+
}, "getSearchParams");
|
|
73
|
+
const [pathname, search] = href.split("?");
|
|
74
|
+
const pathRoute = getPathRoute(pathname);
|
|
75
|
+
const params = getParams(pathname, pathRoute);
|
|
76
|
+
const searchParams = getSearchParams(search);
|
|
77
|
+
return {
|
|
78
|
+
pathname,
|
|
79
|
+
search,
|
|
80
|
+
params,
|
|
81
|
+
searchParams,
|
|
82
|
+
pathRoute
|
|
83
|
+
};
|
|
84
|
+
}, []);
|
|
85
|
+
return {
|
|
86
|
+
getLocation
|
|
87
|
+
};
|
|
88
|
+
}, "useLocation");
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
useLocation
|
|
92
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type PlatformType = "android" | "ios" | "all";
|
|
2
|
+
interface ProductType {
|
|
3
|
+
id: string;
|
|
4
|
+
type: keyof typeof CdvPurchase.ProductType;
|
|
5
|
+
}
|
|
6
|
+
type CdvProductType = CdvPurchase.ProductType;
|
|
7
|
+
declare const usePurchase: ({ platform, productInfo, url, onPay, onSubscribe, }: {
|
|
8
|
+
platform: PlatformType;
|
|
9
|
+
productInfo: ProductType[];
|
|
10
|
+
url: string;
|
|
11
|
+
onPay?: (transaction: CdvPurchase.Transaction) => void | Promise<void>;
|
|
12
|
+
onSubscribe?: (transaction: CdvPurchase.Transaction) => void | Promise<void>;
|
|
13
|
+
}) => {
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
products: CdvPurchase.Product[];
|
|
16
|
+
purchaseProduct: (product: CdvPurchase.Product) => Promise<void>;
|
|
17
|
+
restorePurchases: () => Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { type CdvProductType, type PlatformType, type ProductType, usePurchase };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var usePurchase_exports = {};
|
|
21
|
+
__export(usePurchase_exports, {
|
|
22
|
+
usePurchase: () => usePurchase
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(usePurchase_exports);
|
|
25
|
+
var import_store = require("cordova-plugin-purchase/www/store");
|
|
26
|
+
var import_app = require("@capacitor/app");
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
const usePurchase = /* @__PURE__ */ __name(({ platform, productInfo, url, onPay, onSubscribe }) => {
|
|
29
|
+
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
30
|
+
const billingRef = (0, import_react.useRef)();
|
|
31
|
+
(0, import_react.useEffect)(() => {
|
|
32
|
+
const init = /* @__PURE__ */ __name(async () => {
|
|
33
|
+
if (CdvPurchase.store.isReady) {
|
|
34
|
+
setIsLoading(false);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const app = await import_app.App.getInfo();
|
|
38
|
+
if (platform === "all") CdvPurchase.store.register([
|
|
39
|
+
...productInfo.map((prouct) => ({
|
|
40
|
+
id: prouct.id,
|
|
41
|
+
platform: CdvPurchase.Platform.GOOGLE_PLAY,
|
|
42
|
+
type: CdvPurchase.ProductType[prouct.type]
|
|
43
|
+
})),
|
|
44
|
+
...productInfo.map((prouct) => ({
|
|
45
|
+
id: prouct.id,
|
|
46
|
+
platform: CdvPurchase.Platform.APPLE_APPSTORE,
|
|
47
|
+
type: CdvPurchase.ProductType[prouct.type]
|
|
48
|
+
}))
|
|
49
|
+
]);
|
|
50
|
+
else CdvPurchase.store.register(productInfo.map((product) => ({
|
|
51
|
+
id: product.id,
|
|
52
|
+
platform: platform === "android" ? CdvPurchase.Platform.GOOGLE_PLAY : CdvPurchase.Platform.APPLE_APPSTORE,
|
|
53
|
+
type: CdvPurchase.ProductType[product.type]
|
|
54
|
+
})));
|
|
55
|
+
await CdvPurchase.store.initialize([
|
|
56
|
+
{
|
|
57
|
+
platform: CdvPurchase.Platform.APPLE_APPSTORE,
|
|
58
|
+
options: {
|
|
59
|
+
needAppReceipt: false
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
platform: CdvPurchase.Platform.GOOGLE_PLAY
|
|
64
|
+
}
|
|
65
|
+
]);
|
|
66
|
+
await CdvPurchase.store.update();
|
|
67
|
+
await CdvPurchase.store.restorePurchases();
|
|
68
|
+
CdvPurchase.store.validator = async (request, callback) => {
|
|
69
|
+
const transactionId = request.transaction.id;
|
|
70
|
+
const transactions = CdvPurchase.store.localTransactions;
|
|
71
|
+
const verifingTransaction = transactions.find((transaction) => transaction.transactionId === transactionId);
|
|
72
|
+
if (verifingTransaction?.state !== "approved") return;
|
|
73
|
+
const billing = await fetch(`${url}/billing/verifyBilling`, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers: {
|
|
76
|
+
"Content-Type": "application/json"
|
|
77
|
+
},
|
|
78
|
+
body: JSON.stringify({
|
|
79
|
+
data: {
|
|
80
|
+
platform: verifingTransaction.platform === CdvPurchase.Platform.GOOGLE_PLAY ? "google" : "apple",
|
|
81
|
+
packageName: app.id,
|
|
82
|
+
productId: verifingTransaction.products[0].id,
|
|
83
|
+
receipt: verifingTransaction.platform === CdvPurchase.Platform.GOOGLE_PLAY ? request.transaction.purchaseToken : request.transaction.appStoreReceipt,
|
|
84
|
+
transactionId: verifingTransaction.transactionId
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
billingRef.current = billing.json();
|
|
89
|
+
callback({
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
91
|
+
ok: billing ? true : false,
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
93
|
+
data: {
|
|
94
|
+
id: request.id,
|
|
95
|
+
latest_receipt: true,
|
|
96
|
+
transaction: request.transaction
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
if (CdvPurchase.store.localReceipts.length > 0) {
|
|
101
|
+
CdvPurchase.store.localReceipts.forEach((receipt) => {
|
|
102
|
+
if (receipt.platform === CdvPurchase.Platform.GOOGLE_PLAY) if (receipt.transactions[0].state === CdvPurchase.TransactionState.APPROVED) void receipt.transactions[0].verify();
|
|
103
|
+
else void receipt.transactions[0].finish();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
CdvPurchase.store.when().approved((transaction) => {
|
|
107
|
+
void transaction.verify();
|
|
108
|
+
}).verified((receipt) => {
|
|
109
|
+
void receipt.finish();
|
|
110
|
+
}).finished((transaction) => {
|
|
111
|
+
void inAppPurchase(transaction);
|
|
112
|
+
});
|
|
113
|
+
setIsLoading(false);
|
|
114
|
+
}, "init");
|
|
115
|
+
void init();
|
|
116
|
+
}, []);
|
|
117
|
+
const purchaseProduct = /* @__PURE__ */ __name(async (product) => {
|
|
118
|
+
await product.getOffer()?.order();
|
|
119
|
+
}, "purchaseProduct");
|
|
120
|
+
const restorePurchases = /* @__PURE__ */ __name(async () => {
|
|
121
|
+
await CdvPurchase.store.restorePurchases();
|
|
122
|
+
}, "restorePurchases");
|
|
123
|
+
const inAppPurchase = /* @__PURE__ */ __name(async (transaction) => {
|
|
124
|
+
const product = CdvPurchase.store.get(transaction.products[0].id);
|
|
125
|
+
if (product?.type === "consumable") await onPay?.(transaction);
|
|
126
|
+
else await onSubscribe?.(transaction);
|
|
127
|
+
await transaction.finish();
|
|
128
|
+
}, "inAppPurchase");
|
|
129
|
+
return {
|
|
130
|
+
isLoading,
|
|
131
|
+
products: CdvPurchase.store.products,
|
|
132
|
+
purchaseProduct,
|
|
133
|
+
restorePurchases
|
|
134
|
+
};
|
|
135
|
+
}, "usePurchase");
|
|
136
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
137
|
+
0 && (module.exports = {
|
|
138
|
+
usePurchase
|
|
139
|
+
});
|