@akanjs/client 0.0.46 → 0.0.48

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 CHANGED
@@ -1,13 +1,7 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  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
5
  var __copyProps = (to, from, except, desc) => {
12
6
  if (from && typeof from === "object" || typeof from === "function") {
13
7
  for (let key of __getOwnPropNames(from))
@@ -16,516 +10,8 @@ var __copyProps = (to, from, except, desc) => {
16
10
  }
17
11
  return to;
18
12
  };
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
- ));
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
27
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // pkgs/@akanjs/client/index.ts
30
15
  var client_exports = {};
31
- __export(client_exports, {
32
- DEFAULT_BOTTOM_INSET: () => DEFAULT_BOTTOM_INSET,
33
- DEFAULT_TOP_INSET: () => DEFAULT_TOP_INSET,
34
- Nanum_Gothic_Coding: () => Nanum_Gothic_Coding,
35
- Noto_Sans_KR: () => Noto_Sans_KR,
36
- clsx: () => clsx,
37
- cookies: () => cookies,
38
- createFont: () => createFont,
39
- csrContext: () => csrContext,
40
- defaultPageState: () => defaultPageState,
41
- device: () => device,
42
- getAccount: () => getAccount,
43
- getCookie: () => getCookie,
44
- getHeader: () => getHeader,
45
- getMe: () => getMe,
46
- getPathInfo: () => getPathInfo,
47
- getSelf: () => getSelf,
48
- headers: () => headers,
49
- initAuth: () => initAuth,
50
- loadFonts: () => loadFonts,
51
- pathContext: () => pathContext,
52
- removeCookie: () => removeCookie,
53
- resetAuth: () => resetAuth,
54
- router: () => router,
55
- setAuth: () => setAuth,
56
- setCookie: () => setCookie,
57
- storage: () => storage,
58
- useCsr: () => useCsr,
59
- usePathCtx: () => usePathCtx
60
- });
61
16
  module.exports = __toCommonJS(client_exports);
62
-
63
- // pkgs/@akanjs/client/src/types.ts
64
- var import_clsx = require("clsx");
65
- var clsx = (...args) => (0, import_clsx.clsx)(...args);
66
- var loadFonts = (fonts) => {
67
- return fonts.map(({ name, nextFont, paths }) => nextFont ?? { name, paths });
68
- };
69
-
70
- // pkgs/@akanjs/client/src/csrTypes.ts
71
- var import_react = require("react");
72
- var DEFAULT_TOP_INSET = 48;
73
- var DEFAULT_BOTTOM_INSET = 60;
74
- var defaultPageState = {
75
- transition: "none",
76
- topSafeArea: 0,
77
- bottomSafeArea: 0,
78
- topInset: 0,
79
- bottomInset: 0,
80
- gesture: true,
81
- cache: false
82
- };
83
- var csrContext = (0, import_react.createContext)({});
84
- var useCsr = () => {
85
- const contextValues = (0, import_react.useContext)(csrContext);
86
- return contextValues;
87
- };
88
- var pathContext = (0, import_react.createContext)({});
89
- var usePathCtx = () => {
90
- const contextValues = (0, import_react.useContext)(pathContext);
91
- return contextValues;
92
- };
93
-
94
- // pkgs/@akanjs/client/src/router.ts
95
- var import_base = require("@akanjs/base");
96
- var import_common = require("@akanjs/common");
97
- var import_navigation = require("next/navigation");
98
- var getPathInfo = (href, lang, prefix) => {
99
- const langLength = lang.length + 1;
100
- const pathWithSubRoute = href === `/${lang}` ? "/" : href.startsWith(`/${lang}/`) ? href.slice(langLength) : href;
101
- const prefixLength = prefix ? prefix.length + 1 : 0;
102
- const path = !prefixLength ? pathWithSubRoute : pathWithSubRoute === `/${prefix}` ? "/" : pathWithSubRoute.startsWith(`/${prefix}`) ? pathWithSubRoute.slice(prefixLength) : pathWithSubRoute;
103
- const subRoute = prefix ? `/${prefix}` : "";
104
- const pathname = path.startsWith("http") ? path : path === "/" ? `/${lang}${subRoute}` : `/${lang}${subRoute}${path}`;
105
- return { path, pathname };
106
- };
107
- var Router = class {
108
- isInitialized = false;
109
- #prefix = "";
110
- #lang = "en";
111
- #instance = {
112
- push: (href) => {
113
- const { pathname } = this.#getPathInfo(href);
114
- import_common.Logger.log(`push to:${pathname}`);
115
- if (import_base.baseClientEnv.side === "server")
116
- void (0, import_navigation.redirect)(pathname);
117
- },
118
- replace: (href) => {
119
- const { pathname } = this.#getPathInfo(href);
120
- import_common.Logger.log(`replace to:${pathname}`);
121
- if (import_base.baseClientEnv.side === "server")
122
- void (0, import_navigation.redirect)(pathname);
123
- },
124
- back: () => {
125
- throw new Error("back is only available in client");
126
- },
127
- refresh: () => {
128
- throw new Error("refresh is only available in client");
129
- }
130
- };
131
- init(options) {
132
- this.#prefix = options.prefix ?? "";
133
- this.#lang = options.lang ?? "en";
134
- if (options.type === "csr")
135
- this.#initCSRClientRouter(options);
136
- else if (options.side === "server")
137
- this.#initNextServerRouter(options);
138
- else
139
- this.#initNextClientRouter(options);
140
- this.isInitialized = true;
141
- import_common.Logger.verbose("Router initialized");
142
- }
143
- #initNextServerRouter(options) {
144
- }
145
- #initNextClientRouter(options) {
146
- this.#instance = {
147
- push: (href) => {
148
- const { path, pathname } = this.#getPathInfo(href);
149
- this.#postPathChange({ path, pathname });
150
- options.router.push(pathname);
151
- },
152
- replace: (href) => {
153
- const { path, pathname } = this.#getPathInfo(href);
154
- this.#postPathChange({ path, pathname });
155
- options.router.replace(pathname);
156
- },
157
- back: () => {
158
- const { path, pathname } = this.#getPathInfo(document.referrer);
159
- this.#postPathChange({ path, pathname });
160
- options.router.back();
161
- },
162
- refresh: () => {
163
- const { path, pathname } = this.#getPathInfo(location.pathname);
164
- this.#postPathChange({ path, pathname });
165
- options.router.refresh();
166
- }
167
- };
168
- }
169
- #initCSRClientRouter(options) {
170
- this.#instance = {
171
- push: (href) => {
172
- const { path, pathname } = this.#getPathInfo(href);
173
- if (location.pathname === pathname)
174
- return;
175
- this.#postPathChange({ path, pathname });
176
- options.router.push(pathname);
177
- },
178
- replace: (href) => {
179
- const { path, pathname } = this.#getPathInfo(href);
180
- if (location.pathname === pathname)
181
- return;
182
- this.#postPathChange({ path, pathname });
183
- options.router.replace(pathname);
184
- },
185
- back: () => {
186
- const { path, pathname } = this.#getPathInfo(document.referrer);
187
- if (location.pathname === pathname)
188
- return;
189
- this.#postPathChange({ path, pathname });
190
- options.router.back();
191
- },
192
- refresh: () => {
193
- const { path, pathname } = this.#getPathInfo(location.pathname);
194
- this.#postPathChange({ path, pathname });
195
- options.router.refresh();
196
- }
197
- };
198
- }
199
- #checkInitialized() {
200
- if (!this.isInitialized)
201
- throw new Error("Router is not initialized");
202
- }
203
- #getPathInfo(href, prefix = this.#prefix) {
204
- return getPathInfo(href, this.#lang, prefix);
205
- }
206
- #postPathChange({ path, pathname }) {
207
- import_common.Logger.log(`pathChange-start:${path}`);
208
- window.parent.postMessage({ type: "pathChange", path, pathname }, "*");
209
- }
210
- push(href) {
211
- this.#checkInitialized();
212
- this.#instance.push(href);
213
- return void 0;
214
- }
215
- replace(href) {
216
- this.#checkInitialized();
217
- this.#instance.replace(href);
218
- return void 0;
219
- }
220
- back() {
221
- if (import_base.baseClientEnv.side === "server")
222
- throw new Error("back is only available in client side");
223
- this.#checkInitialized();
224
- this.#instance.back();
225
- return void 0;
226
- }
227
- refresh() {
228
- if (import_base.baseClientEnv.side === "server")
229
- throw new Error("refresh is only available in client side");
230
- this.#checkInitialized();
231
- this.#instance.refresh();
232
- return void 0;
233
- }
234
- async redirect(href) {
235
- if (import_base.baseClientEnv.side === "server") {
236
- const nextHeaders = require("next/headers");
237
- const headers2 = await nextHeaders.headers?.() ?? /* @__PURE__ */ new Map();
238
- const lang = headers2.get("x-locale") ?? this.#lang;
239
- const basePath = headers2.get("x-base-path");
240
- const { pathname } = getPathInfo(href, lang, basePath ?? "");
241
- import_common.Logger.log(`redirect to:${pathname}`);
242
- (0, import_navigation.redirect)(pathname);
243
- } else {
244
- const { pathname } = getPathInfo(href, this.#lang, this.#prefix);
245
- this.#instance.replace(pathname);
246
- }
247
- return void 0;
248
- }
249
- notFound() {
250
- this.#checkInitialized();
251
- if (import_base.baseClientEnv.side === "server") {
252
- import_common.Logger.log(`redirect to:/404`);
253
- (0, import_navigation.notFound)();
254
- } else
255
- this.#instance.replace("/404");
256
- return void 0;
257
- }
258
- setLang(lang) {
259
- if (import_base.baseClientEnv.side === "server")
260
- throw new Error("setLang is only available in client side");
261
- this.#checkInitialized();
262
- const { path } = getPathInfo(window.location.pathname, this.#lang, this.#prefix);
263
- this.#lang = lang;
264
- this.#instance.replace(`/${lang}${path}`);
265
- return void 0;
266
- }
267
- getPath(pathname = window.location.pathname) {
268
- if (import_base.baseClientEnv.side === "server")
269
- throw new Error("getPath is only available in client side");
270
- const { path } = getPathInfo(pathname, this.#lang, this.#prefix);
271
- return path;
272
- }
273
- getFullPath(withLang = true) {
274
- if (import_base.baseClientEnv.side === "server")
275
- throw new Error("getPath is only available in client side");
276
- return `${withLang ? `/${this.#lang}` : ""}/${this.#prefix}${this.getPath()}`;
277
- }
278
- getPrefix() {
279
- return this.#prefix;
280
- }
281
- getPrefixedPath(path) {
282
- return this.#prefix ? `${this.#lang ? `/${this.#lang}` : ""}/${this.#prefix}${path}` : path;
283
- }
284
- };
285
- var router = new Router();
286
-
287
- // pkgs/@akanjs/client/src/cookie.ts
288
- var import_base3 = require("@akanjs/base");
289
- var import_common2 = require("@akanjs/common");
290
- var import_signal = require("@akanjs/signal");
291
- var import_signal2 = require("@akanjs/signal");
292
- var import_core = require("@capacitor/core");
293
- var import_js_cookie = __toESM(require("js-cookie"));
294
- var import_jwt_decode = require("jwt-decode");
295
- var import_react2 = __toESM(require("react"));
296
-
297
- // pkgs/@akanjs/client/src/storage.ts
298
- var import_base2 = require("@akanjs/base");
299
- var import_preferences = require("@capacitor/preferences");
300
- var storage = {
301
- getItem: async (key) => {
302
- if (import_base2.baseClientEnv.side === "server")
303
- return;
304
- if (import_base2.baseClientEnv.renderMode === "ssr")
305
- return localStorage.getItem(key);
306
- else
307
- return (await import_preferences.Preferences.get({ key })).value;
308
- },
309
- setItem: async (key, value) => {
310
- if (import_base2.baseClientEnv.side === "server")
311
- return;
312
- if (import_base2.baseClientEnv.renderMode === "ssr") {
313
- localStorage.setItem(key, value);
314
- return;
315
- } else {
316
- await import_preferences.Preferences.set({ key, value });
317
- return;
318
- }
319
- },
320
- removeItem: (key) => {
321
- if (import_base2.baseClientEnv.side === "server")
322
- return;
323
- if (import_base2.baseClientEnv.renderMode === "ssr") {
324
- localStorage.removeItem(key);
325
- return;
326
- } else
327
- return import_preferences.Preferences.remove({ key });
328
- }
329
- };
330
-
331
- // pkgs/@akanjs/client/src/cookie.ts
332
- var cookies = import_base3.baseClientEnv.side === "server" ? () => {
333
- const nextHeaders = require("next/headers");
334
- const cookies2 = nextHeaders.cookies();
335
- return import_react2.default.use(cookies2);
336
- } : () => {
337
- const cookie = import_js_cookie.default.get();
338
- return new Map(
339
- Object.entries(cookie).map(([key, value]) => [
340
- key,
341
- {
342
- name: key,
343
- value: typeof value === "string" && value.startsWith("j:") ? JSON.parse(value.slice(2)) : value
344
- }
345
- ])
346
- );
347
- };
348
- var setCookie = (key, value, options = { path: "/", sameSite: "none", secure: true }) => {
349
- if (import_base3.baseClientEnv.side === "server")
350
- return;
351
- else
352
- void import_core.CapacitorCookies.setCookie({ key, value });
353
- };
354
- var getCookie = (key) => {
355
- if (import_base3.baseClientEnv.side === "server")
356
- return cookies().get(key)?.value;
357
- else
358
- return document.cookie.split(";").find((c) => c.trim().startsWith(`${key}=`))?.split("=")[1];
359
- };
360
- var removeCookie = (key, options = { path: "/" }) => {
361
- if (import_base3.baseClientEnv.side === "server")
362
- return cookies().delete(key);
363
- else {
364
- document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
365
- }
366
- };
367
- var headers = import_base3.baseClientEnv.side === "server" ? () => import_react2.default.use(require("next/headers").headers()) : () => /* @__PURE__ */ new Map();
368
- var getHeader = (key) => {
369
- return headers().get(key);
370
- };
371
- var getAccount = () => {
372
- const jwt = getCookie("jwt") ?? getHeader("jwt");
373
- if (!jwt)
374
- return import_signal2.defaultAccount;
375
- const account = (0, import_jwt_decode.jwtDecode)(jwt);
376
- if (account.appName !== import_base3.baseEnv.appName || account.environment !== import_base3.baseEnv.environment)
377
- return import_signal2.defaultAccount;
378
- return account;
379
- };
380
- function getMe(option) {
381
- const me = getAccount().me;
382
- if (!me && option) {
383
- if (option.unauthorize === "notFound")
384
- router.notFound();
385
- else if (import_base3.baseClientEnv.side === "client")
386
- router.replace(option.unauthorize);
387
- else
388
- import_react2.default.use(router.redirect(option.unauthorize));
389
- }
390
- return me;
391
- }
392
- function getSelf(option) {
393
- const self = getAccount().self;
394
- if (!self && option) {
395
- if (option.unauthorize === "notFound")
396
- router.notFound();
397
- else if (import_base3.baseClientEnv.side === "client")
398
- router.replace(option.unauthorize);
399
- else
400
- import_react2.default.use(router.redirect(option.unauthorize));
401
- }
402
- return self;
403
- }
404
- var setAuth = ({ jwt }) => {
405
- import_signal.client.setJwt(jwt);
406
- setCookie("jwt", jwt);
407
- void storage.setItem("jwt", jwt);
408
- };
409
- var initAuth = ({ jwt } = {}) => {
410
- const token = jwt ?? cookies().get("jwt")?.value;
411
- if (token)
412
- setAuth({ jwt: token });
413
- import_signal.client.init();
414
- import_common2.Logger.verbose(`JWT set from cookie: ${token}`);
415
- };
416
- var resetAuth = () => {
417
- import_signal.client.reset();
418
- removeCookie("jwt");
419
- void storage.removeItem("jwt");
420
- };
421
-
422
- // pkgs/@akanjs/client/src/device.ts
423
- var import_device = require("@capacitor/device");
424
- var import_haptics = require("@capacitor/haptics");
425
- var import_keyboard = require("@capacitor/keyboard");
426
- var import_capacitor_plugin_safe_area = require("capacitor-plugin-safe-area");
427
- var import_react_device_detect = require("react-device-detect");
428
- var Device = class {
429
- info;
430
- lang;
431
- topSafeArea;
432
- bottomSafeArea;
433
- isMobile = import_react_device_detect.isMobile;
434
- #keyboard = import_keyboard.Keyboard;
435
- #haptics = import_haptics.Haptics;
436
- #pageContentRef = null;
437
- async init({ lang, supportLanguages = [] } = {}) {
438
- const [
439
- info,
440
- { value: languageCode },
441
- {
442
- insets: { top: topSafeArea, bottom: bottomSafeArea }
443
- }
444
- ] = await Promise.all([import_device.Device.getInfo(), import_device.Device.getLanguageCode(), import_capacitor_plugin_safe_area.SafeArea.getSafeAreaInsets()]);
445
- const predefinedLangPath = window.location.pathname.split("/")[1]?.split("?")[0];
446
- const predefinedLang = supportLanguages.find((language) => language === predefinedLangPath);
447
- this.info = info;
448
- this.lang = lang ?? predefinedLang ?? languageCode;
449
- this.topSafeArea = topSafeArea;
450
- this.bottomSafeArea = bottomSafeArea;
451
- }
452
- setPageContentRef(pageContentRef) {
453
- this.#pageContentRef = pageContentRef;
454
- }
455
- async showKeyboard() {
456
- if (this.info.platform === "web")
457
- return;
458
- await this.#keyboard.show();
459
- }
460
- async hideKeyboard() {
461
- if (this.info.platform === "web")
462
- return;
463
- await this.#keyboard.hide();
464
- }
465
- listenKeyboardChanged(onKeyboardChanged) {
466
- if (this.info.platform === "web")
467
- return;
468
- void this.#keyboard.addListener("keyboardWillShow", (keyboard) => {
469
- onKeyboardChanged(keyboard.keyboardHeight);
470
- });
471
- void this.#keyboard.addListener("keyboardDidShow", (keyboard) => {
472
- onKeyboardChanged(keyboard.keyboardHeight);
473
- });
474
- void this.#keyboard.addListener("keyboardWillHide", () => {
475
- onKeyboardChanged(0);
476
- });
477
- void this.#keyboard.addListener("keyboardDidHide", () => {
478
- onKeyboardChanged(0);
479
- });
480
- }
481
- unlistenKeyboardChanged() {
482
- if (this.info.platform === "web")
483
- return;
484
- void this.#keyboard.removeAllListeners();
485
- }
486
- async vibrate(type = "medium") {
487
- if (typeof type === "number") {
488
- await this.#haptics.vibrate({ duration: type });
489
- return;
490
- }
491
- const handleImpact = {
492
- light: async () => {
493
- await this.#haptics.impact({ style: import_haptics.ImpactStyle.Light });
494
- },
495
- medium: async () => {
496
- await this.#haptics.impact({ style: import_haptics.ImpactStyle.Medium });
497
- },
498
- heavy: async () => {
499
- await this.#haptics.impact({ style: import_haptics.ImpactStyle.Heavy });
500
- },
501
- selectionStart: async () => {
502
- await this.#haptics.selectionStart();
503
- },
504
- selectionChanged: async () => {
505
- await this.#haptics.selectionChanged();
506
- },
507
- selectionEnd: async () => {
508
- await this.#haptics.selectionEnd();
509
- }
510
- };
511
- await handleImpact[type]();
512
- }
513
- getScrollTop() {
514
- if (this.info.platform === "web")
515
- return window.scrollY;
516
- return this.#pageContentRef?.current?.scrollTop ?? 0;
517
- }
518
- setScrollTop(scrollTop) {
519
- if (this.info.platform === "web") {
520
- window.scrollTo({ top: scrollTop });
521
- return;
522
- }
523
- return this.#pageContentRef?.current?.scrollTo({ top: scrollTop });
524
- }
525
- };
526
- var device = new Device();
527
-
528
- // pkgs/@akanjs/client/src/createFont.ts
529
- var createFont = (data) => null;
530
- var Nanum_Gothic_Coding = createFont;
531
- var Noto_Sans_KR = createFont;
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.46",
3
+ "version": "0.0.48",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/cookie.js 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"));
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" ? () => {
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;
@@ -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.js 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.js 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,10 @@
1
+ export declare const notFound: () => never;
2
+ export declare const redirect: (url: string) => void;
3
+ export declare const useParams: () => void;
4
+ export declare const usePathname: () => void;
5
+ export declare const useRouter: () => void;
6
+ export declare const useSearchParams: () => void;
7
+ export declare const NextResponse: {
8
+ next: () => void;
9
+ redirect: (url: string) => void;
10
+ };
@@ -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.js 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.js 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.js 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
+ };