@akanjs/next 0.0.52 → 0.0.53

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/bootCsr.js ADDED
@@ -0,0 +1,162 @@
1
+ "use client";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var bootCsr_exports = {};
30
+ __export(bootCsr_exports, {
31
+ bootCsr: () => bootCsr
32
+ });
33
+ module.exports = __toCommonJS(bootCsr_exports);
34
+ var import_client = require("@akanjs/client");
35
+ var import_client2 = require("@akanjs/client");
36
+ var import_common = require("@akanjs/common");
37
+ var import_react = __toESM(require("react"));
38
+ var ReactDOM = __toESM(require("react-dom/client"));
39
+ var import_useCsrValues = require("./useCsrValues");
40
+ const supportLanguages = ["en", "ko"];
41
+ const bootCsr = async (context, rootPath, entryPath = "/route") => {
42
+ const [, jwt] = await Promise.all([import_client.device.init({ supportLanguages }), import_client.storage.getItem("jwt")]);
43
+ if (jwt)
44
+ (0, import_client.initAuth)({ jwt });
45
+ import_common.Logger.verbose(`Set default language: ${import_client.device.lang}`);
46
+ const pages = {};
47
+ await Promise.all(
48
+ Object.entries(context).map(async ([key, value]) => {
49
+ pages[key] = await value();
50
+ })
51
+ );
52
+ const getPageState = (csrConfig) => {
53
+ const { transition, safeArea, topInset, bottomInset, gesture, cache } = csrConfig ?? {};
54
+ const pageState = {
55
+ transition: transition ?? "none",
56
+ topSafeArea: safeArea === false ? 0 : import_client.device.topSafeArea,
57
+ bottomSafeArea: safeArea === false ? 0 : import_client.device.bottomSafeArea,
58
+ // topSafeArea: safeArea === false || device.info.platform === "android" ? 0 : device.topSafeArea,
59
+ // bottomSafeArea: safeArea === false || device.info.platform === "android" ? 0 : device.bottomSafeArea,
60
+ topInset: topInset === true ? import_client2.DEFAULT_TOP_INSET : topInset === false ? 0 : topInset ?? 0,
61
+ bottomInset: bottomInset === true ? import_client2.DEFAULT_BOTTOM_INSET : bottomInset === false ? 0 : bottomInset ?? 0,
62
+ gesture: gesture ?? true,
63
+ cache: cache ?? false
64
+ };
65
+ return pageState;
66
+ };
67
+ const routeMap = /* @__PURE__ */ new Map();
68
+ routeMap.set("/", { path: "/", children: /* @__PURE__ */ new Map() });
69
+ for (const filePath of Object.keys(pages)) {
70
+ const fileName = /\.\/(.*)\.tsx$/.exec(filePath)?.[1];
71
+ if (!fileName)
72
+ continue;
73
+ const fileType = fileName.endsWith("page") ? "page" : fileName.endsWith("layout") ? "layout" : null;
74
+ if (!fileType)
75
+ continue;
76
+ const pathSegments = [
77
+ "/",
78
+ ...fileName.split("/").slice(0, -1).map((segment) => `/${segment.replace(/\[(.*?)\]/g, ":$1")}`)
79
+ ];
80
+ const targetRouteMap = pathSegments.slice(0, -1).reduce((rMap, path) => {
81
+ if (!rMap.has(path))
82
+ rMap.set(path, { path, children: /* @__PURE__ */ new Map() });
83
+ return rMap.get(path)?.children;
84
+ }, routeMap);
85
+ if (!targetRouteMap)
86
+ continue;
87
+ const targetPath = pathSegments[pathSegments.length - 1];
88
+ targetRouteMap.set(targetPath, {
89
+ // action: pages[path]?.action,
90
+ // ErrorBoundary: pages[path]?.ErrorBoundary,
91
+ ...targetRouteMap.get(targetPath) ?? { path: targetPath, children: /* @__PURE__ */ new Map() },
92
+ ...fileType === "layout" ? { Layout: pages[filePath].default } : {
93
+ Page: pages[filePath].default,
94
+ pageState: getPageState(pages[filePath].default.csrConfig),
95
+ csrConfig: pages[filePath].default.csrConfig
96
+ }
97
+ });
98
+ }
99
+ const pathname = window.location.pathname;
100
+ const initialPath = import_client.device.lang + entryPath;
101
+ window.document.body.style.overflow = "hidden";
102
+ const getPathRoutes = (route, parentRootLayouts = [], parentLayouts = [], parentPaths = []) => {
103
+ const parentPath = parentPaths.filter((path2) => path2 !== "/").join("");
104
+ const currentPathSegment = /^\/\(.*\)$/.test(route.path) ? "" : route.path;
105
+ const isRoot = ["/", "/:lang"].includes(parentPath + currentPathSegment) && parentRootLayouts.length < 2;
106
+ const path = parentPath + currentPathSegment;
107
+ const pathSegments = [...parentPaths, ...currentPathSegment ? [currentPathSegment] : []];
108
+ const RootLayouts = [...parentRootLayouts, ...isRoot && route.Layout ? [route.Layout] : []];
109
+ const Layouts = [...parentLayouts, ...!isRoot && route.Layout ? [route.Layout] : []];
110
+ return [
111
+ ...route.Page ? [
112
+ {
113
+ path,
114
+ pathSegments,
115
+ Page: route.Page,
116
+ RootLayouts,
117
+ Layouts,
118
+ pageState: route.pageState ?? import_client2.defaultPageState
119
+ }
120
+ ] : [],
121
+ ...route.children.size ? [...route.children.values()].flatMap((child) => getPathRoutes(child, RootLayouts, Layouts, pathSegments)) : []
122
+ ];
123
+ };
124
+ const rootRoute = routeMap.get("/");
125
+ if (!rootRoute)
126
+ throw new Error("No root route");
127
+ const pathRoutes = getPathRoutes(rootRoute);
128
+ const routeGuide = { pathSegment: "/", children: {} };
129
+ pathRoutes.forEach((pathRoute) => {
130
+ const pathSegments = pathRoute.pathSegments.slice(1);
131
+ pathSegments.reduce((routeGuide2, pathSegment, index) => {
132
+ const child = routeGuide2.children[pathSegment];
133
+ routeGuide2.children[pathSegment] = {
134
+ ...child ?? {},
135
+ pathSegment,
136
+ ...index === pathSegments.length - 1 ? { pathRoute } : {},
137
+ children: child?.children ?? {}
138
+ };
139
+ return routeGuide2.children[pathSegment];
140
+ }, routeGuide);
141
+ });
142
+ const RouterProvider = () => {
143
+ const csrValues = (0, import_useCsrValues.useCsrValues)(routeGuide, pathRoutes);
144
+ const { location } = csrValues;
145
+ return /* @__PURE__ */ import_react.default.createElement(import_client2.csrContext.Provider, { value: csrValues }, location.pathRoute.RootLayouts.reduceRight(
146
+ (children, Layout) => {
147
+ return /* @__PURE__ */ import_react.default.createElement(Layout, { params: location.params, searchParams: location.searchParams }, children);
148
+ },
149
+ /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null)
150
+ ));
151
+ };
152
+ if (pathname !== `/${initialPath}`) {
153
+ window.location.replace(initialPath);
154
+ return;
155
+ } else {
156
+ const el = document.getElementById("root");
157
+ if (!el)
158
+ throw new Error("No root element");
159
+ const root = ReactDOM.createRoot(el);
160
+ root.render(/* @__PURE__ */ import_react.default.createElement(RouterProvider, null));
161
+ }
162
+ };
@@ -0,0 +1,78 @@
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 createNextMiddleware_exports = {};
29
+ __export(createNextMiddleware_exports, {
30
+ createNextMiddleware: () => createNextMiddleware
31
+ });
32
+ module.exports = __toCommonJS(createNextMiddleware_exports);
33
+ var import_base = require("@akanjs/base");
34
+ var import_common = require("@akanjs/common");
35
+ var import_intl_localematcher = require("@formatjs/intl-localematcher");
36
+ var import_negotiator = __toESM(require("negotiator"));
37
+ var import_server = require("next/server");
38
+ const i18n = { defaultLocale: "en", locales: ["en", "ko"] };
39
+ const basePaths = process.env.basePaths ? process.env.basePaths.split(",") : [];
40
+ function getLocale(request) {
41
+ if (!request.headers.get("accept-language"))
42
+ return i18n.defaultLocale;
43
+ const negotiatorHeaders = {};
44
+ request.headers.forEach((value, key) => negotiatorHeaders[key] = value);
45
+ try {
46
+ const languages = new import_negotiator.default({ headers: negotiatorHeaders }).languages();
47
+ return (0, import_intl_localematcher.match)(languages, i18n.locales, i18n.defaultLocale);
48
+ } catch (e) {
49
+ return i18n.defaultLocale;
50
+ }
51
+ }
52
+ const createNextMiddleware = () => {
53
+ import_common.Logger.rawLog(import_base.logo, "console");
54
+ const middleware = (request) => {
55
+ const pathname = request.nextUrl.pathname;
56
+ const pathnameIsMissingLocale = i18n.locales.every(
57
+ (locale2) => !pathname.startsWith(`/${locale2}/`) && pathname !== `/${locale2}`
58
+ );
59
+ if (pathnameIsMissingLocale)
60
+ return import_server.NextResponse.redirect(
61
+ new URL(`/${getLocale(request)}/${request.nextUrl.href.split("/").slice(3).join("/")}`, request.url)
62
+ );
63
+ const splits = pathname.split("/");
64
+ const locale = splits[1];
65
+ const basePath = basePaths.includes(splits[2]) ? splits[2] : null;
66
+ const headers = new Headers(request.headers);
67
+ const searchParams = new URLSearchParams(request.nextUrl.search);
68
+ const searchParamJwt = searchParams.get("jwt");
69
+ headers.set("x-locale", locale);
70
+ headers.set("x-path", "/" + splits.slice(2).join("/"));
71
+ if (basePath)
72
+ headers.set("x-base-path", basePath);
73
+ if (searchParamJwt)
74
+ headers.set("jwt", searchParamJwt);
75
+ return import_server.NextResponse.next({ request: { headers } });
76
+ };
77
+ return middleware;
78
+ };
@@ -0,0 +1,34 @@
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 createRobotPage_exports = {};
19
+ __export(createRobotPage_exports, {
20
+ createRobotPage: () => createRobotPage
21
+ });
22
+ module.exports = __toCommonJS(createRobotPage_exports);
23
+ const createRobotPage = (clientHttpUri, config) => {
24
+ return {
25
+ ...config ?? {},
26
+ rules: {
27
+ userAgent: "*",
28
+ allow: "/",
29
+ disallow: "/admin/",
30
+ ...config?.rules ?? {}
31
+ },
32
+ sitemap: `${clientHttpUri}/sitemap.xml`
33
+ };
34
+ };
@@ -0,0 +1,26 @@
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 createSitemapPage_exports = {};
19
+ __export(createSitemapPage_exports, {
20
+ createSitemapPage: () => createSitemapPage
21
+ });
22
+ module.exports = __toCommonJS(createSitemapPage_exports);
23
+ const lastModified = /* @__PURE__ */ new Date();
24
+ const createSitemapPage = (clientHttpUri, paths) => {
25
+ return paths.map((path) => ({ url: `${clientHttpUri}${path}`, lastModified }));
26
+ };
package/index.js ADDED
@@ -0,0 +1,41 @@
1
+ import { useFetch } from "./useFetch";
2
+ import { lazy } from "./lazy";
3
+ import { makePageProto } from "./makePageProto";
4
+ import { useDebounce } from "./useDebounce";
5
+ import { useInterval } from "./useInterval";
6
+ import { bootCsr } from "./bootCsr";
7
+ import { useCamera } from "./useCamera";
8
+ import { useContact } from "./useContact";
9
+ import { usePushNoti } from "./usePushNoti";
10
+ import { useGeoLocation } from "./useGeoLocation";
11
+ import { useCodepush } from "./useCodepush";
12
+ import { usePurchase } from "./usePurchase";
13
+ import { useCsrValues } from "./useCsrValues";
14
+ import { createRobotPage } from "./createRobotPage";
15
+ import { createSitemapPage } from "./createSitemapPage";
16
+ import { createNextMiddleware } from "./createNextMiddleware";
17
+ //! PageAgent csr에서 말썽 일으킨다
18
+ import { useThrottle } from "./useThrottle";
19
+ import { useHistory } from "./useHistory";
20
+ import { useLocation } from "./useLocation";
21
+ export {
22
+ bootCsr,
23
+ createNextMiddleware,
24
+ createRobotPage,
25
+ createSitemapPage,
26
+ lazy,
27
+ makePageProto,
28
+ useCamera,
29
+ useCodepush,
30
+ useContact,
31
+ useCsrValues,
32
+ useDebounce,
33
+ useFetch,
34
+ useGeoLocation,
35
+ useHistory,
36
+ useInterval,
37
+ useLocation,
38
+ usePurchase,
39
+ usePushNoti,
40
+ useThrottle
41
+ };
package/lazy.js ADDED
@@ -0,0 +1,35 @@
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 lazy_exports = {};
29
+ __export(lazy_exports, {
30
+ lazy: () => lazy
31
+ });
32
+ module.exports = __toCommonJS(lazy_exports);
33
+ var import_dynamic = __toESM(require("next/dynamic"));
34
+ //! next build를 위해서 lint 무시
35
+ const lazy = (loader, option) => (0, import_dynamic.default)(loader, option ?? {});
@@ -0,0 +1,133 @@
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 makePageProto_exports = {};
19
+ __export(makePageProto_exports, {
20
+ makePageProto: () => makePageProto
21
+ });
22
+ module.exports = __toCommonJS(makePageProto_exports);
23
+ var import_base = require("@akanjs/base");
24
+ var import_client = require("@akanjs/client");
25
+ var import_common = require("@akanjs/common");
26
+ const getPageInfo = () => {
27
+ if (import_base.baseClientEnv.side !== "server") {
28
+ return {
29
+ locale: window.location.pathname.split("/")[1] ?? "en",
30
+ path: "/" + window.location.pathname.split("/").slice(2).join("/")
31
+ };
32
+ }
33
+ const locale = (0, import_client.getHeader)("x-locale") ?? "en";
34
+ const path = (0, import_client.getHeader)("x-path") ?? "/";
35
+ return { locale, path };
36
+ };
37
+ const langIdx = { en: 0, ko: 1, zhChs: 2, zhCht: 3 };
38
+ const dictionary = {};
39
+ const translator = (lang, key, param) => {
40
+ const idx = langIdx[lang];
41
+ try {
42
+ const msg = (0, import_common.pathGet)(key, dictionary)?.[idx];
43
+ if (!msg) {
44
+ import_common.Logger.error(`No translation for ${key}`);
45
+ return key;
46
+ }
47
+ return param ? msg.replace(/{([^}]+)}/g, (_, key2) => param[key2]) : msg;
48
+ } catch (e) {
49
+ return key;
50
+ }
51
+ };
52
+ translator.rich = (lang, key, param) => {
53
+ const idx = langIdx[lang];
54
+ const msg = (0, import_common.pathGet)(key, dictionary)?.[idx];
55
+ if (!msg) {
56
+ import_common.Logger.error(`No translation for ${key}`);
57
+ return key;
58
+ }
59
+ return param ? msg.replace(/{([^}]+)}/g, (_, key2) => param[key2]) : msg;
60
+ };
61
+ const makePageProto = (locales) => {
62
+ locales.forEach((locale) => {
63
+ Object.keys(locale).forEach((key) => dictionary[key] = Object.assign(dictionary[key] ?? {}, locale[key]));
64
+ });
65
+ return () => {
66
+ const { locale, path } = getPageInfo();
67
+ const lang = locale;
68
+ const l = (key, param) => translator(lang, key, param);
69
+ l.rich = (key, param) => /* @__PURE__ */ React.createElement(
70
+ "span",
71
+ {
72
+ dangerouslySetInnerHTML: {
73
+ __html: translator.rich(lang, key, {
74
+ ...param,
75
+ // strong: (chunks: string) => `<b>${chunks}</b>`,
76
+ // "bg-primary": (chunks: string) => `<span className="bg-primary text-base-100">${chunks}</span>`,
77
+ // primary: (chunks: string) => `<span className="bg-base-100 text-primary">${chunks}</span>`,
78
+ br: `<br />`
79
+ })
80
+ }
81
+ }
82
+ );
83
+ l.field = (model, field) => {
84
+ const key = `${model}.${field}`;
85
+ return l(key);
86
+ };
87
+ l.desc = (model, field) => {
88
+ const key = `${model}.desc-${field}`;
89
+ return l(key);
90
+ };
91
+ l.enum = (model, field, value) => {
92
+ const key = `${model}.enum-${field}-${value}`;
93
+ return l(key);
94
+ };
95
+ l.enumdesc = (model, field, value) => {
96
+ const key = `${model}.enumdesc-${field}-${value}`;
97
+ return l(key);
98
+ };
99
+ l.api = (model, endpoint) => {
100
+ const key = `${model}.api-${endpoint}`;
101
+ return l(key);
102
+ };
103
+ l.apidesc = (model, endpoint) => {
104
+ const key = `${model}.apidesc-${endpoint}`;
105
+ return l(key);
106
+ };
107
+ l.arg = (model, endpoint, arg) => {
108
+ const key = `${model}.arg-${endpoint}-${arg}`;
109
+ return l(key);
110
+ };
111
+ l.argdesc = (model, endpoint, arg) => {
112
+ const key = `${model}.argdesc-${endpoint}-${arg}`;
113
+ return l(key);
114
+ };
115
+ l.qry = (model, queryKey) => {
116
+ const key = `${model}.qry-${queryKey}`;
117
+ return l(key);
118
+ };
119
+ l.qrydesc = (model, queryKey) => {
120
+ const key = `${model}.qrydesc-${queryKey}`;
121
+ return l(key);
122
+ };
123
+ l.qarg = (model, queryKey, arg) => {
124
+ const key = `${model}.qarg-${queryKey}-${arg}`;
125
+ return l(key);
126
+ };
127
+ l.qargdesc = (model, queryKey, arg) => {
128
+ const key = `${model}.qargdesc-${queryKey}-${arg}`;
129
+ return l(key);
130
+ };
131
+ return { path, l, lang };
132
+ };
133
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/next",
3
- "version": "0.0.52",
3
+ "version": "0.0.53",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/types.js ADDED
@@ -0,0 +1,15 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var types_exports = {};
15
+ module.exports = __toCommonJS(types_exports);
package/useCamera.js ADDED
@@ -0,0 +1,96 @@
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 useCamera_exports = {};
20
+ __export(useCamera_exports, {
21
+ useCamera: () => useCamera
22
+ });
23
+ module.exports = __toCommonJS(useCamera_exports);
24
+ var import_client = require("@akanjs/client");
25
+ var import_camera = require("@capacitor/camera");
26
+ var import_react = require("react");
27
+ const useCamera = () => {
28
+ const [permissions, setPermissions] = (0, import_react.useState)({ camera: "prompt", photos: "prompt" });
29
+ const checkPermission = async (type) => {
30
+ try {
31
+ if (type === "photos") {
32
+ if (permissions.photos === "prompt") {
33
+ const { photos } = await import_camera.Camera.requestPermissions();
34
+ setPermissions((prev) => ({ ...prev, photos }));
35
+ } else if (permissions.photos === "denied") {
36
+ location.assign("app-settings:");
37
+ return;
38
+ }
39
+ } else if (type === "camera") {
40
+ if (permissions.camera === "prompt") {
41
+ const { camera } = await import_camera.Camera.requestPermissions();
42
+ setPermissions((prev) => ({ ...prev, camera }));
43
+ } else if (permissions.camera === "denied") {
44
+ location.assign("app-settings:");
45
+ return;
46
+ }
47
+ } else {
48
+ if (permissions.camera === "prompt" || permissions.photos === "prompt") {
49
+ const permissions2 = await import_camera.Camera.requestPermissions();
50
+ setPermissions(permissions2);
51
+ } else if (permissions.camera === "denied" || permissions.photos === "denied") {
52
+ location.assign("app-settings:");
53
+ return;
54
+ }
55
+ }
56
+ } catch (e) {
57
+ }
58
+ };
59
+ const getPhoto = async (src = "prompt") => {
60
+ const source = import_client.device.info.platform !== "web" ? src === "prompt" ? import_camera.CameraSource.Prompt : src === "camera" ? import_camera.CameraSource.Camera : import_camera.CameraSource.Photos : import_camera.CameraSource.Photos;
61
+ const permission = src === "prompt" ? "all" : src === "camera" ? "camera" : "photos";
62
+ void checkPermission(permission);
63
+ try {
64
+ const photo = await import_camera.Camera.getPhoto({
65
+ quality: 100,
66
+ source,
67
+ allowEditing: false,
68
+ resultType: import_camera.CameraResultType.DataUrl,
69
+ promptLabelHeader: "\uD504\uB85C\uD544 \uC0AC\uC9C4\uC744 \uC62C\uB824\uC8FC\uC138\uC694",
70
+ promptLabelPhoto: "\uC568\uBC94\uC5D0\uC11C \uC120\uD0DD\uD558\uAE30",
71
+ promptLabelPicture: "\uC0AC\uC9C4 \uCC0D\uAE30",
72
+ promptLabelCancel: "\uCDE8\uC18C"
73
+ });
74
+ return photo;
75
+ } catch (e) {
76
+ if (e === "User cancelled photos app")
77
+ return;
78
+ }
79
+ };
80
+ const pickImage = async () => {
81
+ void checkPermission("photos");
82
+ const photo = await import_camera.Camera.pickImages({
83
+ quality: 90
84
+ });
85
+ return photo;
86
+ };
87
+ (0, import_react.useEffect)(() => {
88
+ void (async () => {
89
+ if (import_client.device.info.platform !== "web") {
90
+ const permissions2 = await import_camera.Camera.checkPermissions();
91
+ setPermissions(permissions2);
92
+ }
93
+ })();
94
+ }, []);
95
+ return { permissions, getPhoto, pickImage, checkPermission };
96
+ };