@akanjs/client 0.0.52 → 0.0.54
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/index.js +1 -17
- package/package.json +3 -14
- package/src/cookie.js +50 -79
- package/src/createFont.js +6 -25
- package/src/csrTypes.js +14 -33
- package/src/device.js +15 -34
- package/src/index.js +7 -23
- package/src/navigation.js +9 -28
- package/src/router.js +26 -45
- package/src/storage.js +14 -33
- package/src/types.js +6 -25
package/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var client_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(client_exports);
|
|
17
|
-
__reExport(client_exports, require("./src"), module.exports);
|
|
1
|
+
export * from "./src";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/client",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "0.0.54",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -15,17 +15,6 @@
|
|
|
15
15
|
"node": ">=22"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"
|
|
19
|
-
"@capacitor/device": "^7.0.1",
|
|
20
|
-
"@capacitor/haptics": "^7.0.1",
|
|
21
|
-
"@capacitor/keyboard": "^7.0.1",
|
|
22
|
-
"@capacitor/preferences": "^7.0.1",
|
|
23
|
-
"capacitor-plugin-safe-area": "^3.0.4",
|
|
24
|
-
"clsx": "^2.1.1",
|
|
25
|
-
"js-cookie": "^3.0.5",
|
|
26
|
-
"jwt-decode": "^4.0.0",
|
|
27
|
-
"next": "^15.3.2",
|
|
28
|
-
"react": "^18.3.1",
|
|
29
|
-
"react-device-detect": "^2.2.3"
|
|
18
|
+
"next": "^15.3.2"
|
|
30
19
|
}
|
|
31
20
|
}
|
package/src/cookie.js
CHANGED
|
@@ -1,62 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var cookie_exports = {};
|
|
29
|
-
__export(cookie_exports, {
|
|
30
|
-
cookies: () => cookies,
|
|
31
|
-
getAccount: () => getAccount,
|
|
32
|
-
getCookie: () => getCookie,
|
|
33
|
-
getHeader: () => getHeader,
|
|
34
|
-
getMe: () => getMe,
|
|
35
|
-
getSelf: () => getSelf,
|
|
36
|
-
headers: () => headers,
|
|
37
|
-
initAuth: () => initAuth,
|
|
38
|
-
removeCookie: () => removeCookie,
|
|
39
|
-
resetAuth: () => resetAuth,
|
|
40
|
-
setAuth: () => setAuth,
|
|
41
|
-
setCookie: () => setCookie
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(cookie_exports);
|
|
44
|
-
var import_base = require("@akanjs/base");
|
|
45
|
-
var import_common = require("@akanjs/common");
|
|
46
|
-
var import_signal = require("@akanjs/signal");
|
|
47
|
-
var import_signal2 = require("@akanjs/signal");
|
|
48
|
-
var import_core = require("@capacitor/core");
|
|
49
|
-
var import_js_cookie = __toESM(require("js-cookie"));
|
|
50
|
-
var import_jwt_decode = require("jwt-decode");
|
|
51
|
-
var import_react = __toESM(require("react"));
|
|
52
|
-
var import_router = require("./router");
|
|
53
|
-
var import_storage = require("./storage");
|
|
54
|
-
const cookies = import_base.baseClientEnv.side === "server" ? () => {
|
|
1
|
+
import { baseClientEnv, baseEnv } from "@akanjs/base";
|
|
2
|
+
import { Logger } from "@akanjs/common";
|
|
3
|
+
import { client } from "@akanjs/signal";
|
|
4
|
+
import { defaultAccount } from "@akanjs/signal";
|
|
5
|
+
import { CapacitorCookies } from "@capacitor/core";
|
|
6
|
+
import Cookies from "js-cookie";
|
|
7
|
+
import { jwtDecode } from "jwt-decode";
|
|
8
|
+
import React from "react";
|
|
9
|
+
import { router } from "./router";
|
|
10
|
+
import { storage } from "./storage";
|
|
11
|
+
const cookies = baseClientEnv.side === "server" ? () => {
|
|
55
12
|
const nextHeaders = require("next/headers");
|
|
56
13
|
const cookies2 = nextHeaders.cookies();
|
|
57
|
-
return
|
|
14
|
+
return React.use(cookies2);
|
|
58
15
|
} : () => {
|
|
59
|
-
const cookie =
|
|
16
|
+
const cookie = Cookies.get();
|
|
60
17
|
return new Map(
|
|
61
18
|
Object.entries(cookie).map(([key, value]) => [
|
|
62
19
|
key,
|
|
@@ -68,46 +25,46 @@ const cookies = import_base.baseClientEnv.side === "server" ? () => {
|
|
|
68
25
|
);
|
|
69
26
|
};
|
|
70
27
|
const setCookie = (key, value, options = { path: "/", sameSite: "none", secure: true }) => {
|
|
71
|
-
if (
|
|
28
|
+
if (baseClientEnv.side === "server")
|
|
72
29
|
return;
|
|
73
30
|
else
|
|
74
|
-
void
|
|
31
|
+
void CapacitorCookies.setCookie({ key, value });
|
|
75
32
|
};
|
|
76
33
|
const getCookie = (key) => {
|
|
77
|
-
if (
|
|
34
|
+
if (baseClientEnv.side === "server")
|
|
78
35
|
return cookies().get(key)?.value;
|
|
79
36
|
else
|
|
80
37
|
return document.cookie.split(";").find((c) => c.trim().startsWith(`${key}=`))?.split("=")[1];
|
|
81
38
|
};
|
|
82
39
|
const removeCookie = (key, options = { path: "/" }) => {
|
|
83
|
-
if (
|
|
40
|
+
if (baseClientEnv.side === "server")
|
|
84
41
|
return cookies().delete(key);
|
|
85
42
|
else {
|
|
86
43
|
document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
|
87
44
|
}
|
|
88
45
|
};
|
|
89
|
-
const headers =
|
|
46
|
+
const headers = baseClientEnv.side === "server" ? () => React.use(require("next/headers").headers()) : () => /* @__PURE__ */ new Map();
|
|
90
47
|
const getHeader = (key) => {
|
|
91
48
|
return headers().get(key);
|
|
92
49
|
};
|
|
93
50
|
const getAccount = () => {
|
|
94
51
|
const jwt = getCookie("jwt") ?? getHeader("jwt");
|
|
95
52
|
if (!jwt)
|
|
96
|
-
return
|
|
97
|
-
const account =
|
|
98
|
-
if (account.appName !==
|
|
99
|
-
return
|
|
53
|
+
return defaultAccount;
|
|
54
|
+
const account = jwtDecode(jwt);
|
|
55
|
+
if (account.appName !== baseEnv.appName || account.environment !== baseEnv.environment)
|
|
56
|
+
return defaultAccount;
|
|
100
57
|
return account;
|
|
101
58
|
};
|
|
102
59
|
function getMe(option) {
|
|
103
60
|
const me = getAccount().me;
|
|
104
61
|
if (!me && option) {
|
|
105
62
|
if (option.unauthorize === "notFound")
|
|
106
|
-
|
|
107
|
-
else if (
|
|
108
|
-
|
|
63
|
+
router.notFound();
|
|
64
|
+
else if (baseClientEnv.side === "client")
|
|
65
|
+
router.replace(option.unauthorize);
|
|
109
66
|
else
|
|
110
|
-
|
|
67
|
+
React.use(router.redirect(option.unauthorize));
|
|
111
68
|
}
|
|
112
69
|
return me;
|
|
113
70
|
}
|
|
@@ -115,28 +72,42 @@ function getSelf(option) {
|
|
|
115
72
|
const self = getAccount().self;
|
|
116
73
|
if (!self && option) {
|
|
117
74
|
if (option.unauthorize === "notFound")
|
|
118
|
-
|
|
119
|
-
else if (
|
|
120
|
-
|
|
75
|
+
router.notFound();
|
|
76
|
+
else if (baseClientEnv.side === "client")
|
|
77
|
+
router.replace(option.unauthorize);
|
|
121
78
|
else
|
|
122
|
-
|
|
79
|
+
React.use(router.redirect(option.unauthorize));
|
|
123
80
|
}
|
|
124
81
|
return self;
|
|
125
82
|
}
|
|
126
83
|
const setAuth = ({ jwt }) => {
|
|
127
|
-
|
|
84
|
+
client.setJwt(jwt);
|
|
128
85
|
setCookie("jwt", jwt);
|
|
129
|
-
void
|
|
86
|
+
void storage.setItem("jwt", jwt);
|
|
130
87
|
};
|
|
131
88
|
const initAuth = ({ jwt } = {}) => {
|
|
132
89
|
const token = jwt ?? cookies().get("jwt")?.value;
|
|
133
90
|
if (token)
|
|
134
91
|
setAuth({ jwt: token });
|
|
135
|
-
|
|
136
|
-
|
|
92
|
+
client.init();
|
|
93
|
+
Logger.verbose(`JWT set from cookie: ${token}`);
|
|
137
94
|
};
|
|
138
95
|
const resetAuth = () => {
|
|
139
|
-
|
|
96
|
+
client.reset();
|
|
140
97
|
removeCookie("jwt");
|
|
141
|
-
void
|
|
98
|
+
void storage.removeItem("jwt");
|
|
99
|
+
};
|
|
100
|
+
export {
|
|
101
|
+
cookies,
|
|
102
|
+
getAccount,
|
|
103
|
+
getCookie,
|
|
104
|
+
getHeader,
|
|
105
|
+
getMe,
|
|
106
|
+
getSelf,
|
|
107
|
+
headers,
|
|
108
|
+
initAuth,
|
|
109
|
+
removeCookie,
|
|
110
|
+
resetAuth,
|
|
111
|
+
setAuth,
|
|
112
|
+
setCookie
|
|
142
113
|
};
|
package/src/createFont.js
CHANGED
|
@@ -1,29 +1,10 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var createFont_exports = {};
|
|
19
|
-
__export(createFont_exports, {
|
|
20
|
-
Nanum_Gothic_Coding: () => Nanum_Gothic_Coding,
|
|
21
|
-
Noto_Sans_KR: () => Noto_Sans_KR,
|
|
22
|
-
createFont: () => createFont,
|
|
23
|
-
default: () => createFont_default
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(createFont_exports);
|
|
26
1
|
const createFont = (data) => null;
|
|
27
2
|
var createFont_default = createFont;
|
|
28
3
|
const Nanum_Gothic_Coding = createFont;
|
|
29
4
|
const Noto_Sans_KR = createFont;
|
|
5
|
+
export {
|
|
6
|
+
Nanum_Gothic_Coding,
|
|
7
|
+
Noto_Sans_KR,
|
|
8
|
+
createFont,
|
|
9
|
+
createFont_default as default
|
|
10
|
+
};
|
package/src/csrTypes.js
CHANGED
|
@@ -1,33 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var csrTypes_exports = {};
|
|
20
|
-
__export(csrTypes_exports, {
|
|
21
|
-
DEFAULT_BOTTOM_INSET: () => DEFAULT_BOTTOM_INSET,
|
|
22
|
-
DEFAULT_TOP_INSET: () => DEFAULT_TOP_INSET,
|
|
23
|
-
csrContext: () => csrContext,
|
|
24
|
-
defaultPageState: () => defaultPageState,
|
|
25
|
-
pathContext: () => pathContext,
|
|
26
|
-
useCsr: () => useCsr,
|
|
27
|
-
usePathCtx: () => usePathCtx
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(csrTypes_exports);
|
|
30
|
-
var import_react = require("react");
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
31
3
|
const DEFAULT_TOP_INSET = 48;
|
|
32
4
|
const DEFAULT_BOTTOM_INSET = 60;
|
|
33
5
|
const defaultPageState = {
|
|
@@ -39,13 +11,22 @@ const defaultPageState = {
|
|
|
39
11
|
gesture: true,
|
|
40
12
|
cache: false
|
|
41
13
|
};
|
|
42
|
-
const csrContext =
|
|
14
|
+
const csrContext = createContext({});
|
|
43
15
|
const useCsr = () => {
|
|
44
|
-
const contextValues =
|
|
16
|
+
const contextValues = useContext(csrContext);
|
|
45
17
|
return contextValues;
|
|
46
18
|
};
|
|
47
|
-
const pathContext =
|
|
19
|
+
const pathContext = createContext({});
|
|
48
20
|
const usePathCtx = () => {
|
|
49
|
-
const contextValues =
|
|
21
|
+
const contextValues = useContext(pathContext);
|
|
50
22
|
return contextValues;
|
|
51
23
|
};
|
|
24
|
+
export {
|
|
25
|
+
DEFAULT_BOTTOM_INSET,
|
|
26
|
+
DEFAULT_TOP_INSET,
|
|
27
|
+
csrContext,
|
|
28
|
+
defaultPageState,
|
|
29
|
+
pathContext,
|
|
30
|
+
useCsr,
|
|
31
|
+
usePathCtx
|
|
32
|
+
};
|
package/src/device.js
CHANGED
|
@@ -1,39 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var device_exports = {};
|
|
20
|
-
__export(device_exports, {
|
|
21
|
-
device: () => device
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(device_exports);
|
|
24
|
-
var import_device = require("@capacitor/device");
|
|
25
|
-
var import_haptics = require("@capacitor/haptics");
|
|
26
|
-
var import_keyboard = require("@capacitor/keyboard");
|
|
27
|
-
var import_capacitor_plugin_safe_area = require("capacitor-plugin-safe-area");
|
|
28
|
-
var import_react_device_detect = require("react-device-detect");
|
|
2
|
+
import { Device as CapacitorDevice } from "@capacitor/device";
|
|
3
|
+
import { Haptics, ImpactStyle } from "@capacitor/haptics";
|
|
4
|
+
import { Keyboard } from "@capacitor/keyboard";
|
|
5
|
+
import { SafeArea } from "capacitor-plugin-safe-area";
|
|
6
|
+
import { isMobile } from "react-device-detect";
|
|
29
7
|
class Device {
|
|
30
8
|
info;
|
|
31
9
|
lang;
|
|
32
10
|
topSafeArea;
|
|
33
11
|
bottomSafeArea;
|
|
34
|
-
isMobile =
|
|
35
|
-
#keyboard =
|
|
36
|
-
#haptics =
|
|
12
|
+
isMobile = isMobile;
|
|
13
|
+
#keyboard = Keyboard;
|
|
14
|
+
#haptics = Haptics;
|
|
37
15
|
#pageContentRef = null;
|
|
38
16
|
async init({ lang, supportLanguages = [] } = {}) {
|
|
39
17
|
const [
|
|
@@ -42,7 +20,7 @@ class Device {
|
|
|
42
20
|
{
|
|
43
21
|
insets: { top: topSafeArea, bottom: bottomSafeArea }
|
|
44
22
|
}
|
|
45
|
-
] = await Promise.all([
|
|
23
|
+
] = await Promise.all([CapacitorDevice.getInfo(), CapacitorDevice.getLanguageCode(), SafeArea.getSafeAreaInsets()]);
|
|
46
24
|
const predefinedLangPath = window.location.pathname.split("/")[1]?.split("?")[0];
|
|
47
25
|
const predefinedLang = supportLanguages.find((language) => language === predefinedLangPath);
|
|
48
26
|
this.info = info;
|
|
@@ -91,13 +69,13 @@ class Device {
|
|
|
91
69
|
}
|
|
92
70
|
const handleImpact = {
|
|
93
71
|
light: async () => {
|
|
94
|
-
await this.#haptics.impact({ style:
|
|
72
|
+
await this.#haptics.impact({ style: ImpactStyle.Light });
|
|
95
73
|
},
|
|
96
74
|
medium: async () => {
|
|
97
|
-
await this.#haptics.impact({ style:
|
|
75
|
+
await this.#haptics.impact({ style: ImpactStyle.Medium });
|
|
98
76
|
},
|
|
99
77
|
heavy: async () => {
|
|
100
|
-
await this.#haptics.impact({ style:
|
|
78
|
+
await this.#haptics.impact({ style: ImpactStyle.Heavy });
|
|
101
79
|
},
|
|
102
80
|
selectionStart: async () => {
|
|
103
81
|
await this.#haptics.selectionStart();
|
|
@@ -125,3 +103,6 @@ class Device {
|
|
|
125
103
|
}
|
|
126
104
|
}
|
|
127
105
|
const device = new Device();
|
|
106
|
+
export {
|
|
107
|
+
device
|
|
108
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var src_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(src_exports);
|
|
17
|
-
__reExport(src_exports, require("./types"), module.exports);
|
|
18
|
-
__reExport(src_exports, require("./csrTypes"), module.exports);
|
|
19
|
-
__reExport(src_exports, require("./router"), module.exports);
|
|
20
|
-
__reExport(src_exports, require("./cookie"), module.exports);
|
|
21
|
-
__reExport(src_exports, require("./storage"), module.exports);
|
|
22
|
-
__reExport(src_exports, require("./device"), module.exports);
|
|
23
|
-
__reExport(src_exports, require("./createFont"), module.exports);
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./csrTypes";
|
|
3
|
+
export * from "./router";
|
|
4
|
+
export * from "./cookie";
|
|
5
|
+
export * from "./storage";
|
|
6
|
+
export * from "./device";
|
|
7
|
+
export * from "./createFont";
|
package/src/navigation.js
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var navigation_exports = {};
|
|
19
|
-
__export(navigation_exports, {
|
|
20
|
-
NextResponse: () => NextResponse,
|
|
21
|
-
notFound: () => notFound,
|
|
22
|
-
redirect: () => redirect,
|
|
23
|
-
useParams: () => useParams,
|
|
24
|
-
usePathname: () => usePathname,
|
|
25
|
-
useRouter: () => useRouter,
|
|
26
|
-
useSearchParams: () => useSearchParams
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(navigation_exports);
|
|
29
1
|
const notFound = () => {
|
|
30
2
|
throw new Error("Not found");
|
|
31
3
|
};
|
|
@@ -45,3 +17,12 @@ const NextResponse = {
|
|
|
45
17
|
redirect: (url) => {
|
|
46
18
|
}
|
|
47
19
|
};
|
|
20
|
+
export {
|
|
21
|
+
NextResponse,
|
|
22
|
+
notFound,
|
|
23
|
+
redirect,
|
|
24
|
+
useParams,
|
|
25
|
+
usePathname,
|
|
26
|
+
useRouter,
|
|
27
|
+
useSearchParams
|
|
28
|
+
};
|
package/src/router.js
CHANGED
|
@@ -1,29 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var router_exports = {};
|
|
19
|
-
__export(router_exports, {
|
|
20
|
-
getPathInfo: () => getPathInfo,
|
|
21
|
-
router: () => router
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(router_exports);
|
|
24
|
-
var import_base = require("@akanjs/base");
|
|
25
|
-
var import_common = require("@akanjs/common");
|
|
26
|
-
var import_navigation = require("next/navigation");
|
|
1
|
+
import { baseClientEnv } from "@akanjs/base";
|
|
2
|
+
import { Logger } from "@akanjs/common";
|
|
3
|
+
import { notFound, redirect } from "next/navigation";
|
|
27
4
|
const getPathInfo = (href, lang, prefix) => {
|
|
28
5
|
const langLength = lang.length + 1;
|
|
29
6
|
const pathWithSubRoute = href === `/${lang}` ? "/" : href.startsWith(`/${lang}/`) ? href.slice(langLength) : href;
|
|
@@ -40,15 +17,15 @@ class Router {
|
|
|
40
17
|
#instance = {
|
|
41
18
|
push: (href) => {
|
|
42
19
|
const { pathname } = this.#getPathInfo(href);
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
void
|
|
20
|
+
Logger.log(`push to:${pathname}`);
|
|
21
|
+
if (baseClientEnv.side === "server")
|
|
22
|
+
void redirect(pathname);
|
|
46
23
|
},
|
|
47
24
|
replace: (href) => {
|
|
48
25
|
const { pathname } = this.#getPathInfo(href);
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
void
|
|
26
|
+
Logger.log(`replace to:${pathname}`);
|
|
27
|
+
if (baseClientEnv.side === "server")
|
|
28
|
+
void redirect(pathname);
|
|
52
29
|
},
|
|
53
30
|
back: () => {
|
|
54
31
|
throw new Error("back is only available in client");
|
|
@@ -67,7 +44,7 @@ class Router {
|
|
|
67
44
|
else
|
|
68
45
|
this.#initNextClientRouter(options);
|
|
69
46
|
this.isInitialized = true;
|
|
70
|
-
|
|
47
|
+
Logger.verbose("Router initialized");
|
|
71
48
|
}
|
|
72
49
|
#initNextServerRouter(options) {
|
|
73
50
|
}
|
|
@@ -133,7 +110,7 @@ class Router {
|
|
|
133
110
|
return getPathInfo(href, this.#lang, prefix);
|
|
134
111
|
}
|
|
135
112
|
#postPathChange({ path, pathname }) {
|
|
136
|
-
|
|
113
|
+
Logger.log(`pathChange-start:${path}`);
|
|
137
114
|
window.parent.postMessage({ type: "pathChange", path, pathname }, "*");
|
|
138
115
|
}
|
|
139
116
|
push(href) {
|
|
@@ -147,28 +124,28 @@ class Router {
|
|
|
147
124
|
return void 0;
|
|
148
125
|
}
|
|
149
126
|
back() {
|
|
150
|
-
if (
|
|
127
|
+
if (baseClientEnv.side === "server")
|
|
151
128
|
throw new Error("back is only available in client side");
|
|
152
129
|
this.#checkInitialized();
|
|
153
130
|
this.#instance.back();
|
|
154
131
|
return void 0;
|
|
155
132
|
}
|
|
156
133
|
refresh() {
|
|
157
|
-
if (
|
|
134
|
+
if (baseClientEnv.side === "server")
|
|
158
135
|
throw new Error("refresh is only available in client side");
|
|
159
136
|
this.#checkInitialized();
|
|
160
137
|
this.#instance.refresh();
|
|
161
138
|
return void 0;
|
|
162
139
|
}
|
|
163
140
|
async redirect(href) {
|
|
164
|
-
if (
|
|
141
|
+
if (baseClientEnv.side === "server") {
|
|
165
142
|
const nextHeaders = require("next/headers");
|
|
166
143
|
const headers = await nextHeaders.headers?.() ?? /* @__PURE__ */ new Map();
|
|
167
144
|
const lang = headers.get("x-locale") ?? this.#lang;
|
|
168
145
|
const basePath = headers.get("x-base-path");
|
|
169
146
|
const { pathname } = getPathInfo(href, lang, basePath ?? "");
|
|
170
|
-
|
|
171
|
-
|
|
147
|
+
Logger.log(`redirect to:${pathname}`);
|
|
148
|
+
redirect(pathname);
|
|
172
149
|
} else {
|
|
173
150
|
const { pathname } = getPathInfo(href, this.#lang, this.#prefix);
|
|
174
151
|
this.#instance.replace(pathname);
|
|
@@ -177,15 +154,15 @@ class Router {
|
|
|
177
154
|
}
|
|
178
155
|
notFound() {
|
|
179
156
|
this.#checkInitialized();
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
|
|
157
|
+
if (baseClientEnv.side === "server") {
|
|
158
|
+
Logger.log(`redirect to:/404`);
|
|
159
|
+
notFound();
|
|
183
160
|
} else
|
|
184
161
|
this.#instance.replace("/404");
|
|
185
162
|
return void 0;
|
|
186
163
|
}
|
|
187
164
|
setLang(lang) {
|
|
188
|
-
if (
|
|
165
|
+
if (baseClientEnv.side === "server")
|
|
189
166
|
throw new Error("setLang is only available in client side");
|
|
190
167
|
this.#checkInitialized();
|
|
191
168
|
const { path } = getPathInfo(window.location.pathname, this.#lang, this.#prefix);
|
|
@@ -194,13 +171,13 @@ class Router {
|
|
|
194
171
|
return void 0;
|
|
195
172
|
}
|
|
196
173
|
getPath(pathname = window.location.pathname) {
|
|
197
|
-
if (
|
|
174
|
+
if (baseClientEnv.side === "server")
|
|
198
175
|
throw new Error("getPath is only available in client side");
|
|
199
176
|
const { path } = getPathInfo(pathname, this.#lang, this.#prefix);
|
|
200
177
|
return path;
|
|
201
178
|
}
|
|
202
179
|
getFullPath(withLang = true) {
|
|
203
|
-
if (
|
|
180
|
+
if (baseClientEnv.side === "server")
|
|
204
181
|
throw new Error("getPath is only available in client side");
|
|
205
182
|
return `${withLang ? `/${this.#lang}` : ""}/${this.#prefix}${this.getPath()}`;
|
|
206
183
|
}
|
|
@@ -212,3 +189,7 @@ class Router {
|
|
|
212
189
|
}
|
|
213
190
|
}
|
|
214
191
|
const router = new Router();
|
|
192
|
+
export {
|
|
193
|
+
getPathInfo,
|
|
194
|
+
router
|
|
195
|
+
};
|
package/src/storage.js
CHANGED
|
@@ -1,54 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var storage_exports = {};
|
|
19
|
-
__export(storage_exports, {
|
|
20
|
-
storage: () => storage
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(storage_exports);
|
|
23
|
-
var import_base = require("@akanjs/base");
|
|
24
|
-
var import_preferences = require("@capacitor/preferences");
|
|
1
|
+
import { baseClientEnv } from "@akanjs/base";
|
|
2
|
+
import { Preferences } from "@capacitor/preferences";
|
|
25
3
|
const storage = {
|
|
26
4
|
getItem: async (key) => {
|
|
27
|
-
if (
|
|
5
|
+
if (baseClientEnv.side === "server")
|
|
28
6
|
return;
|
|
29
|
-
if (
|
|
7
|
+
if (baseClientEnv.renderMode === "ssr")
|
|
30
8
|
return localStorage.getItem(key);
|
|
31
9
|
else
|
|
32
|
-
return (await
|
|
10
|
+
return (await Preferences.get({ key })).value;
|
|
33
11
|
},
|
|
34
12
|
setItem: async (key, value) => {
|
|
35
|
-
if (
|
|
13
|
+
if (baseClientEnv.side === "server")
|
|
36
14
|
return;
|
|
37
|
-
if (
|
|
15
|
+
if (baseClientEnv.renderMode === "ssr") {
|
|
38
16
|
localStorage.setItem(key, value);
|
|
39
17
|
return;
|
|
40
18
|
} else {
|
|
41
|
-
await
|
|
19
|
+
await Preferences.set({ key, value });
|
|
42
20
|
return;
|
|
43
21
|
}
|
|
44
22
|
},
|
|
45
23
|
removeItem: (key) => {
|
|
46
|
-
if (
|
|
24
|
+
if (baseClientEnv.side === "server")
|
|
47
25
|
return;
|
|
48
|
-
if (
|
|
26
|
+
if (baseClientEnv.renderMode === "ssr") {
|
|
49
27
|
localStorage.removeItem(key);
|
|
50
28
|
return;
|
|
51
29
|
} else
|
|
52
|
-
return
|
|
30
|
+
return Preferences.remove({ key });
|
|
53
31
|
}
|
|
54
32
|
};
|
|
33
|
+
export {
|
|
34
|
+
storage
|
|
35
|
+
};
|
package/src/types.js
CHANGED
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var types_exports = {};
|
|
19
|
-
__export(types_exports, {
|
|
20
|
-
clsx: () => clsx,
|
|
21
|
-
loadFonts: () => loadFonts
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(types_exports);
|
|
24
|
-
var import_clsx = require("clsx");
|
|
25
|
-
const clsx = (...args) => (0, import_clsx.clsx)(...args);
|
|
1
|
+
import { clsx as clsxLib } from "clsx";
|
|
2
|
+
const clsx = (...args) => clsxLib(...args);
|
|
26
3
|
const loadFonts = (fonts) => {
|
|
27
4
|
return fonts.map(({ name, nextFont, paths }) => nextFont ?? { name, paths });
|
|
28
5
|
};
|
|
6
|
+
export {
|
|
7
|
+
clsx,
|
|
8
|
+
loadFonts
|
|
9
|
+
};
|