@akanjs/client 0.0.54 → 0.0.56
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.cjs +17 -0
- package/package.json +19 -2
- package/src/cookie.cjs +142 -0
- package/src/createFont.cjs +29 -0
- package/src/csrTypes.cjs +51 -0
- package/src/device.cjs +127 -0
- package/src/index.cjs +23 -0
- package/src/navigation.cjs +47 -0
- package/src/router.cjs +214 -0
- package/src/storage.cjs +54 -0
- package/src/types.cjs +28 -0
package/index.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.56",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -15,6 +15,23 @@
|
|
|
15
15
|
"node": ">=22"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"
|
|
18
|
+
"@capacitor/core": "^7.2.0",
|
|
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"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"require": "./index.cjs",
|
|
34
|
+
"import": "./index.js"
|
|
35
|
+
}
|
|
19
36
|
}
|
|
20
37
|
}
|
package/src/cookie.cjs
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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 __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"), 1);
|
|
50
|
+
var import_jwt_decode = require("jwt-decode");
|
|
51
|
+
var import_react = __toESM(require("react"), 1);
|
|
52
|
+
var import_router = require("./router");
|
|
53
|
+
var import_storage = require("./storage");
|
|
54
|
+
const cookies = import_base.baseClientEnv.side === "server" ? () => {
|
|
55
|
+
const nextHeaders = require("next/headers");
|
|
56
|
+
const cookies2 = nextHeaders.cookies();
|
|
57
|
+
return import_react.default.use(cookies2);
|
|
58
|
+
} : () => {
|
|
59
|
+
const cookie = import_js_cookie.default.get();
|
|
60
|
+
return new Map(
|
|
61
|
+
Object.entries(cookie).map(([key, value]) => [
|
|
62
|
+
key,
|
|
63
|
+
{
|
|
64
|
+
name: key,
|
|
65
|
+
value: typeof value === "string" && value.startsWith("j:") ? JSON.parse(value.slice(2)) : value
|
|
66
|
+
}
|
|
67
|
+
])
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
const setCookie = (key, value, options = { path: "/", sameSite: "none", secure: true }) => {
|
|
71
|
+
if (import_base.baseClientEnv.side === "server")
|
|
72
|
+
return;
|
|
73
|
+
else
|
|
74
|
+
void import_core.CapacitorCookies.setCookie({ key, value });
|
|
75
|
+
};
|
|
76
|
+
const getCookie = (key) => {
|
|
77
|
+
if (import_base.baseClientEnv.side === "server")
|
|
78
|
+
return cookies().get(key)?.value;
|
|
79
|
+
else
|
|
80
|
+
return document.cookie.split(";").find((c) => c.trim().startsWith(`${key}=`))?.split("=")[1];
|
|
81
|
+
};
|
|
82
|
+
const removeCookie = (key, options = { path: "/" }) => {
|
|
83
|
+
if (import_base.baseClientEnv.side === "server")
|
|
84
|
+
return cookies().delete(key);
|
|
85
|
+
else {
|
|
86
|
+
document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const headers = import_base.baseClientEnv.side === "server" ? () => import_react.default.use(require("next/headers").headers()) : () => /* @__PURE__ */ new Map();
|
|
90
|
+
const getHeader = (key) => {
|
|
91
|
+
return headers().get(key);
|
|
92
|
+
};
|
|
93
|
+
const getAccount = () => {
|
|
94
|
+
const jwt = getCookie("jwt") ?? getHeader("jwt");
|
|
95
|
+
if (!jwt)
|
|
96
|
+
return import_signal2.defaultAccount;
|
|
97
|
+
const account = (0, import_jwt_decode.jwtDecode)(jwt);
|
|
98
|
+
if (account.appName !== import_base.baseEnv.appName || account.environment !== import_base.baseEnv.environment)
|
|
99
|
+
return import_signal2.defaultAccount;
|
|
100
|
+
return account;
|
|
101
|
+
};
|
|
102
|
+
function getMe(option) {
|
|
103
|
+
const me = getAccount().me;
|
|
104
|
+
if (!me && option) {
|
|
105
|
+
if (option.unauthorize === "notFound")
|
|
106
|
+
import_router.router.notFound();
|
|
107
|
+
else if (import_base.baseClientEnv.side === "client")
|
|
108
|
+
import_router.router.replace(option.unauthorize);
|
|
109
|
+
else
|
|
110
|
+
import_react.default.use(import_router.router.redirect(option.unauthorize));
|
|
111
|
+
}
|
|
112
|
+
return me;
|
|
113
|
+
}
|
|
114
|
+
function getSelf(option) {
|
|
115
|
+
const self = getAccount().self;
|
|
116
|
+
if (!self && option) {
|
|
117
|
+
if (option.unauthorize === "notFound")
|
|
118
|
+
import_router.router.notFound();
|
|
119
|
+
else if (import_base.baseClientEnv.side === "client")
|
|
120
|
+
import_router.router.replace(option.unauthorize);
|
|
121
|
+
else
|
|
122
|
+
import_react.default.use(import_router.router.redirect(option.unauthorize));
|
|
123
|
+
}
|
|
124
|
+
return self;
|
|
125
|
+
}
|
|
126
|
+
const setAuth = ({ jwt }) => {
|
|
127
|
+
import_signal.client.setJwt(jwt);
|
|
128
|
+
setCookie("jwt", jwt);
|
|
129
|
+
void import_storage.storage.setItem("jwt", jwt);
|
|
130
|
+
};
|
|
131
|
+
const initAuth = ({ jwt } = {}) => {
|
|
132
|
+
const token = jwt ?? cookies().get("jwt")?.value;
|
|
133
|
+
if (token)
|
|
134
|
+
setAuth({ jwt: token });
|
|
135
|
+
import_signal.client.init();
|
|
136
|
+
import_common.Logger.verbose(`JWT set from cookie: ${token}`);
|
|
137
|
+
};
|
|
138
|
+
const resetAuth = () => {
|
|
139
|
+
import_signal.client.reset();
|
|
140
|
+
removeCookie("jwt");
|
|
141
|
+
void import_storage.storage.removeItem("jwt");
|
|
142
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
const createFont = (data) => null;
|
|
27
|
+
var createFont_default = createFont;
|
|
28
|
+
const Nanum_Gothic_Coding = createFont;
|
|
29
|
+
const Noto_Sans_KR = createFont;
|
package/src/csrTypes.cjs
ADDED
|
@@ -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 __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");
|
|
31
|
+
const DEFAULT_TOP_INSET = 48;
|
|
32
|
+
const DEFAULT_BOTTOM_INSET = 60;
|
|
33
|
+
const defaultPageState = {
|
|
34
|
+
transition: "none",
|
|
35
|
+
topSafeArea: 0,
|
|
36
|
+
bottomSafeArea: 0,
|
|
37
|
+
topInset: 0,
|
|
38
|
+
bottomInset: 0,
|
|
39
|
+
gesture: true,
|
|
40
|
+
cache: false
|
|
41
|
+
};
|
|
42
|
+
const csrContext = (0, import_react.createContext)({});
|
|
43
|
+
const useCsr = () => {
|
|
44
|
+
const contextValues = (0, import_react.useContext)(csrContext);
|
|
45
|
+
return contextValues;
|
|
46
|
+
};
|
|
47
|
+
const pathContext = (0, import_react.createContext)({});
|
|
48
|
+
const usePathCtx = () => {
|
|
49
|
+
const contextValues = (0, import_react.useContext)(pathContext);
|
|
50
|
+
return contextValues;
|
|
51
|
+
};
|
package/src/device.cjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
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 __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 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");
|
|
29
|
+
class Device {
|
|
30
|
+
info;
|
|
31
|
+
lang;
|
|
32
|
+
topSafeArea;
|
|
33
|
+
bottomSafeArea;
|
|
34
|
+
isMobile = import_react_device_detect.isMobile;
|
|
35
|
+
#keyboard = import_keyboard.Keyboard;
|
|
36
|
+
#haptics = import_haptics.Haptics;
|
|
37
|
+
#pageContentRef = null;
|
|
38
|
+
async init({ lang, supportLanguages = [] } = {}) {
|
|
39
|
+
const [
|
|
40
|
+
info,
|
|
41
|
+
{ value: languageCode },
|
|
42
|
+
{
|
|
43
|
+
insets: { top: topSafeArea, bottom: bottomSafeArea }
|
|
44
|
+
}
|
|
45
|
+
] = await Promise.all([import_device.Device.getInfo(), import_device.Device.getLanguageCode(), import_capacitor_plugin_safe_area.SafeArea.getSafeAreaInsets()]);
|
|
46
|
+
const predefinedLangPath = window.location.pathname.split("/")[1]?.split("?")[0];
|
|
47
|
+
const predefinedLang = supportLanguages.find((language) => language === predefinedLangPath);
|
|
48
|
+
this.info = info;
|
|
49
|
+
this.lang = lang ?? predefinedLang ?? languageCode;
|
|
50
|
+
this.topSafeArea = topSafeArea;
|
|
51
|
+
this.bottomSafeArea = bottomSafeArea;
|
|
52
|
+
}
|
|
53
|
+
setPageContentRef(pageContentRef) {
|
|
54
|
+
this.#pageContentRef = pageContentRef;
|
|
55
|
+
}
|
|
56
|
+
async showKeyboard() {
|
|
57
|
+
if (this.info.platform === "web")
|
|
58
|
+
return;
|
|
59
|
+
await this.#keyboard.show();
|
|
60
|
+
}
|
|
61
|
+
async hideKeyboard() {
|
|
62
|
+
if (this.info.platform === "web")
|
|
63
|
+
return;
|
|
64
|
+
await this.#keyboard.hide();
|
|
65
|
+
}
|
|
66
|
+
listenKeyboardChanged(onKeyboardChanged) {
|
|
67
|
+
if (this.info.platform === "web")
|
|
68
|
+
return;
|
|
69
|
+
void this.#keyboard.addListener("keyboardWillShow", (keyboard) => {
|
|
70
|
+
onKeyboardChanged(keyboard.keyboardHeight);
|
|
71
|
+
});
|
|
72
|
+
void this.#keyboard.addListener("keyboardDidShow", (keyboard) => {
|
|
73
|
+
onKeyboardChanged(keyboard.keyboardHeight);
|
|
74
|
+
});
|
|
75
|
+
void this.#keyboard.addListener("keyboardWillHide", () => {
|
|
76
|
+
onKeyboardChanged(0);
|
|
77
|
+
});
|
|
78
|
+
void this.#keyboard.addListener("keyboardDidHide", () => {
|
|
79
|
+
onKeyboardChanged(0);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
unlistenKeyboardChanged() {
|
|
83
|
+
if (this.info.platform === "web")
|
|
84
|
+
return;
|
|
85
|
+
void this.#keyboard.removeAllListeners();
|
|
86
|
+
}
|
|
87
|
+
async vibrate(type = "medium") {
|
|
88
|
+
if (typeof type === "number") {
|
|
89
|
+
await this.#haptics.vibrate({ duration: type });
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const handleImpact = {
|
|
93
|
+
light: async () => {
|
|
94
|
+
await this.#haptics.impact({ style: import_haptics.ImpactStyle.Light });
|
|
95
|
+
},
|
|
96
|
+
medium: async () => {
|
|
97
|
+
await this.#haptics.impact({ style: import_haptics.ImpactStyle.Medium });
|
|
98
|
+
},
|
|
99
|
+
heavy: async () => {
|
|
100
|
+
await this.#haptics.impact({ style: import_haptics.ImpactStyle.Heavy });
|
|
101
|
+
},
|
|
102
|
+
selectionStart: async () => {
|
|
103
|
+
await this.#haptics.selectionStart();
|
|
104
|
+
},
|
|
105
|
+
selectionChanged: async () => {
|
|
106
|
+
await this.#haptics.selectionChanged();
|
|
107
|
+
},
|
|
108
|
+
selectionEnd: async () => {
|
|
109
|
+
await this.#haptics.selectionEnd();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
await handleImpact[type]();
|
|
113
|
+
}
|
|
114
|
+
getScrollTop() {
|
|
115
|
+
if (this.info.platform === "web")
|
|
116
|
+
return window.scrollY;
|
|
117
|
+
return this.#pageContentRef?.current?.scrollTop ?? 0;
|
|
118
|
+
}
|
|
119
|
+
setScrollTop(scrollTop) {
|
|
120
|
+
if (this.info.platform === "web") {
|
|
121
|
+
window.scrollTo({ top: scrollTop });
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
return this.#pageContentRef?.current?.scrollTo({ top: scrollTop });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const device = new Device();
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
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 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);
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
const notFound = () => {
|
|
30
|
+
throw new Error("Not found");
|
|
31
|
+
};
|
|
32
|
+
const redirect = (url) => {
|
|
33
|
+
};
|
|
34
|
+
const useParams = () => {
|
|
35
|
+
};
|
|
36
|
+
const usePathname = () => {
|
|
37
|
+
};
|
|
38
|
+
const useRouter = () => {
|
|
39
|
+
};
|
|
40
|
+
const useSearchParams = () => {
|
|
41
|
+
};
|
|
42
|
+
const NextResponse = {
|
|
43
|
+
next: () => {
|
|
44
|
+
},
|
|
45
|
+
redirect: (url) => {
|
|
46
|
+
}
|
|
47
|
+
};
|
package/src/router.cjs
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
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 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");
|
|
27
|
+
const getPathInfo = (href, lang, prefix) => {
|
|
28
|
+
const langLength = lang.length + 1;
|
|
29
|
+
const pathWithSubRoute = href === `/${lang}` ? "/" : href.startsWith(`/${lang}/`) ? href.slice(langLength) : href;
|
|
30
|
+
const prefixLength = prefix ? prefix.length + 1 : 0;
|
|
31
|
+
const path = !prefixLength ? pathWithSubRoute : pathWithSubRoute === `/${prefix}` ? "/" : pathWithSubRoute.startsWith(`/${prefix}`) ? pathWithSubRoute.slice(prefixLength) : pathWithSubRoute;
|
|
32
|
+
const subRoute = prefix ? `/${prefix}` : "";
|
|
33
|
+
const pathname = path.startsWith("http") ? path : path === "/" ? `/${lang}${subRoute}` : `/${lang}${subRoute}${path}`;
|
|
34
|
+
return { path, pathname };
|
|
35
|
+
};
|
|
36
|
+
class Router {
|
|
37
|
+
isInitialized = false;
|
|
38
|
+
#prefix = "";
|
|
39
|
+
#lang = "en";
|
|
40
|
+
#instance = {
|
|
41
|
+
push: (href) => {
|
|
42
|
+
const { pathname } = this.#getPathInfo(href);
|
|
43
|
+
import_common.Logger.log(`push to:${pathname}`);
|
|
44
|
+
if (import_base.baseClientEnv.side === "server")
|
|
45
|
+
void (0, import_navigation.redirect)(pathname);
|
|
46
|
+
},
|
|
47
|
+
replace: (href) => {
|
|
48
|
+
const { pathname } = this.#getPathInfo(href);
|
|
49
|
+
import_common.Logger.log(`replace to:${pathname}`);
|
|
50
|
+
if (import_base.baseClientEnv.side === "server")
|
|
51
|
+
void (0, import_navigation.redirect)(pathname);
|
|
52
|
+
},
|
|
53
|
+
back: () => {
|
|
54
|
+
throw new Error("back is only available in client");
|
|
55
|
+
},
|
|
56
|
+
refresh: () => {
|
|
57
|
+
throw new Error("refresh is only available in client");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
init(options) {
|
|
61
|
+
this.#prefix = options.prefix ?? "";
|
|
62
|
+
this.#lang = options.lang ?? "en";
|
|
63
|
+
if (options.type === "csr")
|
|
64
|
+
this.#initCSRClientRouter(options);
|
|
65
|
+
else if (options.side === "server")
|
|
66
|
+
this.#initNextServerRouter(options);
|
|
67
|
+
else
|
|
68
|
+
this.#initNextClientRouter(options);
|
|
69
|
+
this.isInitialized = true;
|
|
70
|
+
import_common.Logger.verbose("Router initialized");
|
|
71
|
+
}
|
|
72
|
+
#initNextServerRouter(options) {
|
|
73
|
+
}
|
|
74
|
+
#initNextClientRouter(options) {
|
|
75
|
+
this.#instance = {
|
|
76
|
+
push: (href) => {
|
|
77
|
+
const { path, pathname } = this.#getPathInfo(href);
|
|
78
|
+
this.#postPathChange({ path, pathname });
|
|
79
|
+
options.router.push(pathname);
|
|
80
|
+
},
|
|
81
|
+
replace: (href) => {
|
|
82
|
+
const { path, pathname } = this.#getPathInfo(href);
|
|
83
|
+
this.#postPathChange({ path, pathname });
|
|
84
|
+
options.router.replace(pathname);
|
|
85
|
+
},
|
|
86
|
+
back: () => {
|
|
87
|
+
const { path, pathname } = this.#getPathInfo(document.referrer);
|
|
88
|
+
this.#postPathChange({ path, pathname });
|
|
89
|
+
options.router.back();
|
|
90
|
+
},
|
|
91
|
+
refresh: () => {
|
|
92
|
+
const { path, pathname } = this.#getPathInfo(location.pathname);
|
|
93
|
+
this.#postPathChange({ path, pathname });
|
|
94
|
+
options.router.refresh();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
#initCSRClientRouter(options) {
|
|
99
|
+
this.#instance = {
|
|
100
|
+
push: (href) => {
|
|
101
|
+
const { path, pathname } = this.#getPathInfo(href);
|
|
102
|
+
if (location.pathname === pathname)
|
|
103
|
+
return;
|
|
104
|
+
this.#postPathChange({ path, pathname });
|
|
105
|
+
options.router.push(pathname);
|
|
106
|
+
},
|
|
107
|
+
replace: (href) => {
|
|
108
|
+
const { path, pathname } = this.#getPathInfo(href);
|
|
109
|
+
if (location.pathname === pathname)
|
|
110
|
+
return;
|
|
111
|
+
this.#postPathChange({ path, pathname });
|
|
112
|
+
options.router.replace(pathname);
|
|
113
|
+
},
|
|
114
|
+
back: () => {
|
|
115
|
+
const { path, pathname } = this.#getPathInfo(document.referrer);
|
|
116
|
+
if (location.pathname === pathname)
|
|
117
|
+
return;
|
|
118
|
+
this.#postPathChange({ path, pathname });
|
|
119
|
+
options.router.back();
|
|
120
|
+
},
|
|
121
|
+
refresh: () => {
|
|
122
|
+
const { path, pathname } = this.#getPathInfo(location.pathname);
|
|
123
|
+
this.#postPathChange({ path, pathname });
|
|
124
|
+
options.router.refresh();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
#checkInitialized() {
|
|
129
|
+
if (!this.isInitialized)
|
|
130
|
+
throw new Error("Router is not initialized");
|
|
131
|
+
}
|
|
132
|
+
#getPathInfo(href, prefix = this.#prefix) {
|
|
133
|
+
return getPathInfo(href, this.#lang, prefix);
|
|
134
|
+
}
|
|
135
|
+
#postPathChange({ path, pathname }) {
|
|
136
|
+
import_common.Logger.log(`pathChange-start:${path}`);
|
|
137
|
+
window.parent.postMessage({ type: "pathChange", path, pathname }, "*");
|
|
138
|
+
}
|
|
139
|
+
push(href) {
|
|
140
|
+
this.#checkInitialized();
|
|
141
|
+
this.#instance.push(href);
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
replace(href) {
|
|
145
|
+
this.#checkInitialized();
|
|
146
|
+
this.#instance.replace(href);
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
back() {
|
|
150
|
+
if (import_base.baseClientEnv.side === "server")
|
|
151
|
+
throw new Error("back is only available in client side");
|
|
152
|
+
this.#checkInitialized();
|
|
153
|
+
this.#instance.back();
|
|
154
|
+
return void 0;
|
|
155
|
+
}
|
|
156
|
+
refresh() {
|
|
157
|
+
if (import_base.baseClientEnv.side === "server")
|
|
158
|
+
throw new Error("refresh is only available in client side");
|
|
159
|
+
this.#checkInitialized();
|
|
160
|
+
this.#instance.refresh();
|
|
161
|
+
return void 0;
|
|
162
|
+
}
|
|
163
|
+
async redirect(href) {
|
|
164
|
+
if (import_base.baseClientEnv.side === "server") {
|
|
165
|
+
const nextHeaders = require("next/headers");
|
|
166
|
+
const headers = await nextHeaders.headers?.() ?? /* @__PURE__ */ new Map();
|
|
167
|
+
const lang = headers.get("x-locale") ?? this.#lang;
|
|
168
|
+
const basePath = headers.get("x-base-path");
|
|
169
|
+
const { pathname } = getPathInfo(href, lang, basePath ?? "");
|
|
170
|
+
import_common.Logger.log(`redirect to:${pathname}`);
|
|
171
|
+
(0, import_navigation.redirect)(pathname);
|
|
172
|
+
} else {
|
|
173
|
+
const { pathname } = getPathInfo(href, this.#lang, this.#prefix);
|
|
174
|
+
this.#instance.replace(pathname);
|
|
175
|
+
}
|
|
176
|
+
return void 0;
|
|
177
|
+
}
|
|
178
|
+
notFound() {
|
|
179
|
+
this.#checkInitialized();
|
|
180
|
+
if (import_base.baseClientEnv.side === "server") {
|
|
181
|
+
import_common.Logger.log(`redirect to:/404`);
|
|
182
|
+
(0, import_navigation.notFound)();
|
|
183
|
+
} else
|
|
184
|
+
this.#instance.replace("/404");
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
setLang(lang) {
|
|
188
|
+
if (import_base.baseClientEnv.side === "server")
|
|
189
|
+
throw new Error("setLang is only available in client side");
|
|
190
|
+
this.#checkInitialized();
|
|
191
|
+
const { path } = getPathInfo(window.location.pathname, this.#lang, this.#prefix);
|
|
192
|
+
this.#lang = lang;
|
|
193
|
+
this.#instance.replace(`/${lang}${path}`);
|
|
194
|
+
return void 0;
|
|
195
|
+
}
|
|
196
|
+
getPath(pathname = window.location.pathname) {
|
|
197
|
+
if (import_base.baseClientEnv.side === "server")
|
|
198
|
+
throw new Error("getPath is only available in client side");
|
|
199
|
+
const { path } = getPathInfo(pathname, this.#lang, this.#prefix);
|
|
200
|
+
return path;
|
|
201
|
+
}
|
|
202
|
+
getFullPath(withLang = true) {
|
|
203
|
+
if (import_base.baseClientEnv.side === "server")
|
|
204
|
+
throw new Error("getPath is only available in client side");
|
|
205
|
+
return `${withLang ? `/${this.#lang}` : ""}/${this.#prefix}${this.getPath()}`;
|
|
206
|
+
}
|
|
207
|
+
getPrefix() {
|
|
208
|
+
return this.#prefix;
|
|
209
|
+
}
|
|
210
|
+
getPrefixedPath(path) {
|
|
211
|
+
return this.#prefix ? `${this.#lang ? `/${this.#lang}` : ""}/${this.#prefix}${path}` : path;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const router = new Router();
|
package/src/storage.cjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
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 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");
|
|
25
|
+
const storage = {
|
|
26
|
+
getItem: async (key) => {
|
|
27
|
+
if (import_base.baseClientEnv.side === "server")
|
|
28
|
+
return;
|
|
29
|
+
if (import_base.baseClientEnv.renderMode === "ssr")
|
|
30
|
+
return localStorage.getItem(key);
|
|
31
|
+
else
|
|
32
|
+
return (await import_preferences.Preferences.get({ key })).value;
|
|
33
|
+
},
|
|
34
|
+
setItem: async (key, value) => {
|
|
35
|
+
if (import_base.baseClientEnv.side === "server")
|
|
36
|
+
return;
|
|
37
|
+
if (import_base.baseClientEnv.renderMode === "ssr") {
|
|
38
|
+
localStorage.setItem(key, value);
|
|
39
|
+
return;
|
|
40
|
+
} else {
|
|
41
|
+
await import_preferences.Preferences.set({ key, value });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
removeItem: (key) => {
|
|
46
|
+
if (import_base.baseClientEnv.side === "server")
|
|
47
|
+
return;
|
|
48
|
+
if (import_base.baseClientEnv.renderMode === "ssr") {
|
|
49
|
+
localStorage.removeItem(key);
|
|
50
|
+
return;
|
|
51
|
+
} else
|
|
52
|
+
return import_preferences.Preferences.remove({ key });
|
|
53
|
+
}
|
|
54
|
+
};
|
package/src/types.cjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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 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);
|
|
26
|
+
const loadFonts = (fonts) => {
|
|
27
|
+
return fonts.map(({ name, nextFont, paths }) => nextFont ?? { name, paths });
|
|
28
|
+
};
|