diff --git a/index.html b/index.html
index f642281..fea7b10 100644
--- a/index.html
+++ b/index.html
@@ -24,6 +24,7 @@
+
diff --git a/lib/ui.js b/lib/ui.js
index c5e59b7..f0444cb 100644
--- a/lib/ui.js
+++ b/lib/ui.js
@@ -1,6 +1,6 @@
-import { createIcon, resolveIcon } from "./ui/icon"
-import { createCheckbox, resolveCheckbox } from "./ui/checkbox"
-import { setTooltip, resolveTooltip } from "./ui/tooltip"
+import { createIcon, resolveIcon } from "./ui/icon";
+import { createCheckbox, resolveCheckbox } from "./ui/checkbox";
+import { setTooltip, resolveTooltip } from "./ui/tooltip";
export {
createIcon,
diff --git a/lib/utility.js b/lib/utility.js
new file mode 100644
index 0000000..77e2df2
--- /dev/null
+++ b/lib/utility.js
@@ -0,0 +1,10 @@
+import { getCookie, setCookie, deleteCookie } from "./utility/cookie";
+import { get, post } from "./utility/request";
+
+export {
+ getCookie,
+ setCookie,
+ deleteCookie,
+ get,
+ post
+}
\ No newline at end of file
diff --git a/lib/utility/cookie.d.ts b/lib/utility/cookie.d.ts
new file mode 100644
index 0000000..28225cd
--- /dev/null
+++ b/lib/utility/cookie.d.ts
@@ -0,0 +1,3 @@
+export function getCookie(name: string): string
+export function setCookie(name: string, value: string, expireDays?: Number): void
+export function deleteCookie(name: string): void
\ No newline at end of file
diff --git a/lib/utility/cookie.js b/lib/utility/cookie.js
new file mode 100644
index 0000000..a2cd5a5
--- /dev/null
+++ b/lib/utility/cookie.js
@@ -0,0 +1,34 @@
+function setCookie(name, value, expireDays) {
+ let extra = `; domain=${location.host}; path=/`;
+ if (expireDays != null) {
+ const d = new Date();
+ d.setTime(d.getTime() + (expireDays * 24 * 60 * 60 * 1000));
+ extra += `; expires=${d.toGMTString()}`;
+ }
+ if (/^(https|wss):$/.test(location.protocol)) {
+ extra += '; secure';
+ }
+ document.cookie = `${name}=${encodeURIComponent(value)}${extra}`;
+}
+
+function getCookie(name) {
+ name += '=';
+ const cookies = document.cookie.split(';');
+ for (let cookie of cookies) {
+ cookie = cookie.trim();
+ if (cookie.indexOf(name) === 0) {
+ return decodeURIComponent(cookie.substring(name.length));
+ }
+ }
+ return null;
+}
+
+function deleteCookie(name) {
+ setCookie(name, '', -1);
+}
+
+export {
+ getCookie,
+ setCookie,
+ deleteCookie
+}
\ No newline at end of file
diff --git a/lib/utility/request.d.ts b/lib/utility/request.d.ts
new file mode 100644
index 0000000..2b2c0fd
--- /dev/null
+++ b/lib/utility/request.d.ts
@@ -0,0 +1,9 @@
+interface RequestOptions {
+ method?: string;
+ contentType?: string;
+ customerHeaders?: { [key: string]: string };
+ signal?: AbortSignal | null;
+}
+
+export function get(url: string, options?: RequestOptions): Promise
+export function post(url: string, data?: BodyInit | null, options?: RequestOptions): Promise
\ No newline at end of file
diff --git a/lib/utility/request.js b/lib/utility/request.js
new file mode 100644
index 0000000..fe47c2d
--- /dev/null
+++ b/lib/utility/request.js
@@ -0,0 +1,38 @@
+function combineUrl(url) {
+ if (typeof consts === 'undefined') {
+ return url;
+ }
+ return (consts.path || '') + url;
+}
+
+function get(url, options) {
+ options ??= {};
+ return fetch(combineUrl(url), {
+ method: options.method || 'GET',
+ headers: {
+ ...options.customerHeaders,
+ 'Content-Type': options.contentType || 'application/json'
+ },
+ signal: options.signal,
+ cache: 'default'
+ });
+}
+
+function post(url, data, options) {
+ options ??= {};
+ return fetch(combineUrl(url), {
+ method: options.method || 'POST',
+ headers: {
+ ...options.customerHeaders,
+ 'Content-Type': options.contentType || 'application/json'
+ },
+ body: data,
+ signal: options.signal,
+ cache: 'no-cache'
+ });
+}
+
+export {
+ get,
+ post
+}
\ No newline at end of file
diff --git a/main.js b/main.js
index 08a613f..9395530 100644
--- a/main.js
+++ b/main.js
@@ -1,9 +1,10 @@
import './css/ui.min.css'
import './style.css'
-import javascriptLogo from './javascript.svg'
+// import javascriptLogo from './javascript.svg'
import { resolveCheckbox, resolveIcon, resolveTooltip } from './lib/ui'
+import { get, post } from './lib/utility'
-document.querySelector('#js-logo').src = javascriptLogo
+// document.querySelector('#js-logo').src = javascriptLogo
window.consts = {
path: '/',
@@ -18,4 +19,13 @@ resolveIcon(document.querySelector('#create-icon'))
// }))
resolveCheckbox(document.querySelector('#create-checkbox'))
-resolveTooltip(document.querySelector('#buttons'))
\ No newline at end of file
+resolveTooltip(document.querySelector('#buttons'))
+
+document.querySelector('#button-fetch').addEventListener('click', () => {
+ // get('./javascript.svg')
+ // .then(r => r.blob())
+ // .then(blob => document.querySelector('#js-logo').src = URL.createObjectURL(blob));
+ post('./', JSON.stringify({ a: 1, b: 'test' }))
+ .then(r => console.log(r))
+ .catch(e => console.warn(e));
+});
\ No newline at end of file
diff --git a/package.json b/package.json
index d94e3b3..f60e6ac 100644
--- a/package.json
+++ b/package.json
@@ -6,17 +6,19 @@
"files": [
"dist"
],
- "main": "./dist/ui-lib.umd.cjs",
- "module": "./dist/ui-lib.js",
"exports": {
- "./lib": {
- "import": "./dist/ui-lib.js",
- "require": "./dist/ui-lib.umd.cjs"
+ "ui": {
+ "import": "./dist/ui.es.js",
+ "require": "./dist/ui.min.js"
+ },
+ "utility": {
+ "import": "./dist/utility.es.js",
+ "require": "./dist/utility.min.js"
}
},
"scripts": {
"dev": "vite",
- "build": "vite build"
+ "build": "node ./vite.build.js"
},
"devDependencies": {
"vite": "^4.0.4"
diff --git a/vite.build.js b/vite.build.js
new file mode 100644
index 0000000..24bcc67
--- /dev/null
+++ b/vite.build.js
@@ -0,0 +1,24 @@
+import { build } from "vite";
+
+const libraries = [
+ {
+ entry: './lib/ui.js',
+ name: 'lib-ui'
+ },
+ {
+ entry: './lib/utility.js',
+ name: 'lib-utility'
+ }
+]
+
+libraries.forEach(async (lib) => {
+ await build({
+ build: {
+ lib: {
+ ...lib,
+ formats: ['umd'],
+ fileName: (_format, name) => `${name}.min.js`
+ }
+ }
+ })
+})
diff --git a/vite.config.js b/vite.config.js
deleted file mode 100644
index 885d4f9..0000000
--- a/vite.config.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import { defineConfig } from "vite";
-
-export default defineConfig({
- build: {
- lib: {
- entry: './lib/main.js',
- name: 'uiLib',
- fileName: 'ui-lib'
- }
- }
-})
\ No newline at end of file