kempo 3.2.1 → 4.1.0
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/dist/components/Component.js +1 -1
- package/dist/components/Dialog.js +1 -1
- package/dist/components/LazyComponent.js +1 -1
- package/dist/components/Toast.js +1 -0
- package/dist/utils/Server.js +1 -0
- package/dist/utils/drag.js +1 -1
- package/dist/utils/fs-utils.js +1 -0
- package/dist/utils/minify.js +1 -0
- package/docs/components/toast.html +330 -0
- package/docs/icons/error.svg +1 -0
- package/docs/icons/warning.svg +1 -0
- package/docs/kempo/components/Component.js +1 -1
- package/docs/kempo/components/Dialog.js +1 -1
- package/docs/kempo/components/LazyComponent.js +1 -1
- package/docs/kempo/components/Toast.js +1 -0
- package/docs/kempo/utils/Server.js +1 -0
- package/docs/kempo/utils/drag.js +1 -1
- package/docs/kempo/utils/fs-utils.js +1 -0
- package/docs/kempo/utils/minify.js +1 -0
- package/docs/nav.inc.html +2 -1
- package/docs/utils/Server.html +119 -0
- package/icons/error.svg +1 -0
- package/icons/warning.svg +1 -0
- package/package.json +2 -4
- package/scripts/build.js +8 -8
- package/scripts/docs.js +20 -20
- package/src/components/Dialog.js +11 -1
- package/src/components/Toast.js +424 -0
- package/src/utils/Server.js +189 -0
- package/src/utils/fs-utils.js +41 -0
- package/test/index.js +27 -16
- package/scripts/test.js +0 -31
package/docs/kempo/utils/drag.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default(e={})=>{let t,o,n;const{element:s=(
|
|
1
|
+
export default(e={})=>{let t,o,n;const{element:s=()=>{},callback:a=()=>{},startCallback:v=()=>{},moveCallback:i=()=>{},endCallback:r=()=>{},preventScroll:d=!1}=e,u=s=>{d&&s.preventDefault(),clearTimeout(n);const v=s.pageX||s.touches[0].pageX,r=s.pageY||s.touches[0].pageY,u={x:v-t,y:r-o,...e};a(u),i(u)},c=({pageX:s,pageY:v})=>{clearTimeout(n);const i={x:s-t,y:v-o,...e};a(i),r(i),m()},p=s=>{clearTimeout(n),t=s.pageX||s.touches[0].pageX,o=s.pageY||s.touches[0].pageY;const a={x:0,y:0,...e};v(a),window.addEventListener("mousemove",u,{passive:!d}),window.addEventListener("mouseup",c,{passive:!d}),window.addEventListener("touchmove",u,{passive:!d}),window.addEventListener("touchend",c,{passive:!d})},m=()=>{window.removeEventListener("mousemove",u),window.removeEventListener("mouseup",c),window.removeEventListener("touchmove",u),window.removeEventListener("touchend",c)};return s.addEventListener("mousedown",p,{passive:!d}),s.addEventListener("touchstart",p,{passive:!d}),()=>{s.removeEventListener("mousedown",p),m()}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import fs from"fs/promises";import path from"path";export async function ensureDir(i){try{await fs.mkdir(i,{recursive:!0})}catch(i){if("EEXIST"!==i.code)throw i}}export async function copyDir(i,r){await ensureDir(r);const t=await fs.readdir(i,{withFileTypes:!0});for(const a of t){const t=path.join(i,a.name),o=path.join(r,a.name);a.isDirectory()?await copyDir(t,o):await fs.copyFile(t,o)}}export async function emptyDir(i){try{const r=await fs.readdir(i);await Promise.all(r.map((r=>fs.rm(path.join(i,r),{recursive:!0,force:!0}))))}catch(i){if("ENOENT"!==i.code)throw i}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function minifyCss(e){return e.replace(/\s*\{\s*/g,"{").replace(/\s*\}\s*/g,"}").replace(/\n/g,"").replace(/\r/g,"").replace(/\s+/g," ").replace(/\s*\:\s*/g,":").replace(/\s*\;\s*/g,";").replace(/;\}/g,"}")}
|
package/docs/nav.inc.html
CHANGED
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
<a href="%%root%%components/table.html">Table</a>
|
|
56
56
|
<a href="%%root%%components/tabs.html">Tabs</a>
|
|
57
57
|
<a href="%%root%%components/tags.html">Tags</a>
|
|
58
|
+
<a href="%%root%%components/toast.html">Toast</a>
|
|
58
59
|
<a href="%%root%%components/theme-switcher.html">Theme Switcher</a>
|
|
59
60
|
<a href="%%root%%components/timestamp.html">Timestamp</a>
|
|
60
61
|
<a href="%%root%%components/toggle.html">Toggle</a>
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
|
|
63
64
|
<h5 class="mb0">Utils</h5>
|
|
64
65
|
<div class="pl mb">
|
|
65
|
-
|
|
66
|
+
<a href="%%root%%utils/Server.html">Server</a>
|
|
66
67
|
</div>
|
|
67
68
|
</menu>
|
|
68
69
|
</k-side-menu>
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Template - Utils - Kempo Docs - A Web Components Solution</title>
|
|
7
|
+
<link rel="stylesheet" href="../kempo/kempo-vars.css" /><link rel="stylesheet" href="../kempo/kempo-styles.css" />
|
|
8
|
+
<link rel="stylesheet" href="../kempo/kempo-hljs.css" />
|
|
9
|
+
<script type="module">
|
|
10
|
+
import Import from '../kempo/components/Import.js';
|
|
11
|
+
import Icon from '../kempo/components/Icon.js';
|
|
12
|
+
import Search from '../kempo/components/Search.js';
|
|
13
|
+
Import.addReplacement('root', '../');
|
|
14
|
+
Icon.pathToIcons = ['../icons'];
|
|
15
|
+
Search.searchDataUrl = '../search.json';
|
|
16
|
+
</script>
|
|
17
|
+
</head>
|
|
18
|
+
<body>
|
|
19
|
+
<k-import src="../nav.inc.html"></k-import>
|
|
20
|
+
<h1 class="ta-center">Server</h1>
|
|
21
|
+
<main>
|
|
22
|
+
<details class="b r mb">
|
|
23
|
+
<summary class="p">Table of Contents</summary>
|
|
24
|
+
<div class="m mt0 pl">
|
|
25
|
+
<h6>Examples</h6>
|
|
26
|
+
<a href="#basicUsage">Basic Usage</a><br />
|
|
27
|
+
<a href="#staticServing">Static File Serving</a><br />
|
|
28
|
+
<a href="#routePatterns">Route Patterns</a><br />
|
|
29
|
+
|
|
30
|
+
<h6 class="mt">JavaScript Reference</h6>
|
|
31
|
+
<a href="#constructor">Constructor</a><br />
|
|
32
|
+
<a href="#requirements">Requirements</a><br />
|
|
33
|
+
<a href="#methods">Methods</a><br />
|
|
34
|
+
<a href="#staticMembers">Static Members</a><br />
|
|
35
|
+
</div>
|
|
36
|
+
</details>
|
|
37
|
+
|
|
38
|
+
<h3>Description</h3>
|
|
39
|
+
<p>A lightweight HTTP server utility for serving static files and handling route patterns with wildcard support.</p>
|
|
40
|
+
|
|
41
|
+
<h3 id="basicUsage"><a href="#basicUsage" class="no-link">Basic Usage</a></h3>
|
|
42
|
+
<pre><code class="language-javascript">import { Server } from '../utils/Server.js';
|
|
43
|
+
|
|
44
|
+
const server = new Server();
|
|
45
|
+
server
|
|
46
|
+
.static('/assets', './public')
|
|
47
|
+
.route('/api/*.json', async (req, res) => {
|
|
48
|
+
// Handle JSON requests
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
await server.listen(8080);</code></pre>
|
|
52
|
+
|
|
53
|
+
<h3 id="staticServing"><a href="#staticServing" class="no-link">Static File Serving</a></h3>
|
|
54
|
+
<pre><code class="language-javascript">// Serve entire directories
|
|
55
|
+
server.static('/assets', './public');
|
|
56
|
+
server.static('/docs', './documentation');
|
|
57
|
+
|
|
58
|
+
// Serve single files with custom headers
|
|
59
|
+
server.route('/style.css', async (req, res) => {
|
|
60
|
+
await server.serveFile('./styles/main.css', res, {
|
|
61
|
+
'Cache-Control': 'no-cache'
|
|
62
|
+
});
|
|
63
|
+
});</code></pre>
|
|
64
|
+
|
|
65
|
+
<h3 id="routePatterns"><a href="#routePatterns" class="no-link">Route Patterns</a></h3>
|
|
66
|
+
<p>Routes support wildcard patterns for flexible path matching:</p>
|
|
67
|
+
<ul>
|
|
68
|
+
<li><code>*</li>
|
|
69
|
+
<li><code>**</code> - Matches any characters including /</li>
|
|
70
|
+
</ul>
|
|
71
|
+
<pre><code class="language-javascript">// Match specific file types
|
|
72
|
+
server.route('/api/*.json', handler);
|
|
73
|
+
|
|
74
|
+
// Match files in subdirectories
|
|
75
|
+
server.route('/docs/**/*.html', handler);
|
|
76
|
+
|
|
77
|
+
// Match everything under a path
|
|
78
|
+
server.route('/assets/**/*', handler);</code></pre>
|
|
79
|
+
|
|
80
|
+
<h2 id="jsRef">JavaScript Reference</h2>
|
|
81
|
+
|
|
82
|
+
<h3 id="constructor"><a href="#constructor" class="no-link">Constructor</a></h3>
|
|
83
|
+
<h5><code>new Server()</code></h5>
|
|
84
|
+
<p>Creates a new server instance.</p>
|
|
85
|
+
|
|
86
|
+
<h3 id="requirements"><a href="#requirements" class="no-link">Requirements</a></h3>
|
|
87
|
+
<ul>
|
|
88
|
+
<li>Node.js built-in modules only (http, fs/promises, path)</li>
|
|
89
|
+
<li>No external dependencies</li>
|
|
90
|
+
</ul>
|
|
91
|
+
|
|
92
|
+
<h3 id="methods"><a href="#methods" class="no-link">Methods</a></h3>
|
|
93
|
+
|
|
94
|
+
<h5><code>route(path: string, handler: Function, methods?: string[]): Server</code></h5>
|
|
95
|
+
<p>Registers a route handler with optional HTTP method restrictions. Returns this for chaining.</p>
|
|
96
|
+
|
|
97
|
+
<h5><code>static(urlPath: string, dirPath: string): Server</code></h5>
|
|
98
|
+
<p>Serves an entire directory of static files. Returns this for chaining.</p>
|
|
99
|
+
|
|
100
|
+
<h5><code>serveFile(filePath: string, res: Response, headers?: object): Promise<void></code></h5>
|
|
101
|
+
<p>Serves a single file with appropriate MIME type and optional headers.</p>
|
|
102
|
+
|
|
103
|
+
<h5><code>listen(port?: number): Promise<http.Server></code></h5>
|
|
104
|
+
<p>Starts the server on the specified port. Returns a Promise that resolves to the server instance.</p>
|
|
105
|
+
|
|
106
|
+
<h3 id="staticMembers"><a href="#staticMembers" class="no-link">Static Members</a></h3>
|
|
107
|
+
|
|
108
|
+
<h5><code>static mimeTypes: Record<string, string></code></h5>
|
|
109
|
+
<p>MIME type mappings for file extensions.</p>
|
|
110
|
+
|
|
111
|
+
<h5><code>static textExtensions: string[]</code></h5>
|
|
112
|
+
<p>List of file extensions that should be served as text.</p>
|
|
113
|
+
|
|
114
|
+
<h5><code>static getMimeType(filePath: string): string</code></h5>
|
|
115
|
+
<p>Returns the appropriate MIME type for a file based on its extension.</p>
|
|
116
|
+
</main>
|
|
117
|
+
<script type="module" src="../kempo/components/Import.js"></script>
|
|
118
|
+
</body>
|
|
119
|
+
</html>
|
package/icons/error.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="error" d="M480-280q17 0 28.5-11.5T520-320q0-17-11.5-28.5T480-360q-17 0-28.5 11.5T440-320q0 17 11.5 28.5T480-280Zm-40-160h80v-240h-80v240ZM330-120 120-330v-300l210-210h300l210 210v300L630-120H330Zm34-80h232l164-164v-232L596-760H364L200-596v232l164 164Zm116-280Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="warning" d="m40-120 440-760 440 760H40Zm138-80h604L480-720 178-200Zm302-40q17 0 28.5-11.5T520-280q0-17-11.5-28.5T480-320q-17 0-28.5 11.5T440-280q0 17 11.5 28.5T480-240Zm-40-120h80v-200h-80v200Zm40-100Z"/></svg>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kempo",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A web component library",
|
|
6
6
|
"exports": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"./components/*": "./dist/components/*.js"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"test": "node ./
|
|
14
|
+
"test": "node ./test/index.js",
|
|
15
15
|
"build": "node ./scripts/build.js",
|
|
16
16
|
"docs": "node ./scripts/docs.js",
|
|
17
17
|
"docs-src": "node ./scripts/docs.js -s"
|
|
@@ -20,8 +20,6 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"express": "^4.18.3",
|
|
24
|
-
"fs-extra": "^11.2.0",
|
|
25
23
|
"terser": "^5.29.2"
|
|
26
24
|
},
|
|
27
25
|
"directories": {
|
package/scripts/build.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
|
-
import fse from 'fs-extra';
|
|
3
2
|
import { minify } from 'terser';
|
|
4
3
|
import path from 'path';
|
|
5
4
|
import { fileURLToPath } from 'url';
|
|
5
|
+
import { ensureDir, copyDir, emptyDir } from '../src/utils/fs-utils.js';
|
|
6
6
|
|
|
7
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
8
|
const __dirname = path.dirname(__filename);
|
|
@@ -57,7 +57,7 @@ process.stdout.write(`0/${components.length} = 0%`);
|
|
|
57
57
|
await Promise.all(components.map(async component => {
|
|
58
58
|
const relativePath = path.relative(componentsDir, component);
|
|
59
59
|
const destPath = path.join('./dist/components', relativePath);
|
|
60
|
-
await
|
|
60
|
+
await ensureDir(path.dirname(destPath));
|
|
61
61
|
await fs.writeFile(destPath, minifiedComponents[component], 'utf-8');
|
|
62
62
|
process.stdout.write("\r");
|
|
63
63
|
complete++;
|
|
@@ -95,7 +95,7 @@ process.stdout.write("\n");
|
|
|
95
95
|
complete = 0;
|
|
96
96
|
console.log('Saving Minified Utils to dist/');
|
|
97
97
|
process.stdout.write(`0/${utils.length} = 0%`);
|
|
98
|
-
await
|
|
98
|
+
await ensureDir('./dist/utils');
|
|
99
99
|
await Promise.all(utils.map(async util => {
|
|
100
100
|
await fs.writeFile(`./dist/utils/${util}.js`, minifiedUtils[util], 'utf-8');
|
|
101
101
|
process.stdout.write("\r");
|
|
@@ -139,16 +139,16 @@ console.log('Saving kempo-hljs.css');
|
|
|
139
139
|
await fs.writeFile('./dist/kempo-hljs.css', minifiedKempoHljsCSS, 'utf-8');
|
|
140
140
|
|
|
141
141
|
console.log('Copying dist/ to docs/');
|
|
142
|
-
await
|
|
143
|
-
await
|
|
142
|
+
await ensureDir('./docs/'); // will also ensure docs/kempo
|
|
143
|
+
await copyDir('./dist', './docs/kempo')
|
|
144
144
|
|
|
145
145
|
const iconsSrcDir = path.join(__dirname, '../icons');
|
|
146
146
|
const iconsDestDir = path.join(__dirname, '../docs/icons');
|
|
147
147
|
|
|
148
148
|
console.log('Deleting svg icons currently in docs/icons');
|
|
149
|
-
await
|
|
150
|
-
await
|
|
149
|
+
await ensureDir(iconsDestDir);
|
|
150
|
+
await emptyDir(iconsDestDir);
|
|
151
151
|
console.log('Copying all files from icons to docs/icons');
|
|
152
|
-
await
|
|
152
|
+
await copyDir(iconsSrcDir, iconsDestDir);
|
|
153
153
|
|
|
154
154
|
console.log('Build Complete');
|
package/scripts/docs.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
1
|
import { dirname, join } from 'path';
|
|
3
2
|
import { fileURLToPath } from 'url';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
runChildNodeProcess
|
|
7
|
-
} from '../src/utils/cli.js';
|
|
3
|
+
import { Server } from '../src/utils/Server.js';
|
|
4
|
+
import { getArgs, runChildNodeProcess } from '../src/utils/cli.js';
|
|
8
5
|
|
|
9
6
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
7
|
const __dirname = dirname(__filename);
|
|
@@ -25,23 +22,26 @@ if(build){
|
|
|
25
22
|
runChildNodeProcess(join(__dirname, 'build.js'));
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
const
|
|
25
|
+
const server = new Server();
|
|
29
26
|
|
|
30
|
-
if(src){
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
if (src) {
|
|
28
|
+
server
|
|
29
|
+
.get('/', join(__dirname, '../docs/'))
|
|
30
|
+
.get('/kempo/kempo-styles.css', join(__dirname, '../src/kempo-styles.css'))
|
|
31
|
+
.get('/kempo/*', join(__dirname, '../src/*'))
|
|
32
|
+
.get('/icons/*', join(__dirname, '../icons/*'))
|
|
33
|
+
.get('/*', join(__dirname, '../docs/*'));
|
|
37
34
|
} else {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
server
|
|
36
|
+
.get('/', join(__dirname, '../docs/'))
|
|
37
|
+
.get('/kempo/kempo-styles.css', join(__dirname, '../docs/kempo/kempo-styles.css'))
|
|
38
|
+
.get('/*', join(__dirname, '../docs/*'));
|
|
42
39
|
}
|
|
43
|
-
app.use(express.static('docs'));
|
|
44
40
|
|
|
45
|
-
|
|
41
|
+
try {
|
|
42
|
+
await server.listen(port);
|
|
46
43
|
console.log(`Docs Running on: http://localhost:${port}`);
|
|
47
|
-
})
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.error('Failed to start server:', err.message);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
package/src/components/Dialog.js
CHANGED
|
@@ -244,9 +244,19 @@ export default class Dialog extends Component {
|
|
|
244
244
|
|
|
245
245
|
static create(contents = '', options = {}){
|
|
246
246
|
if(options.closeExisting!==false)document.querySelectorAll('k-dialog').forEach(d=>d.close());
|
|
247
|
+
const {
|
|
248
|
+
removeOnClose = true,
|
|
249
|
+
closeCallback = () => {}
|
|
250
|
+
} = options;
|
|
247
251
|
const $dialog = new Dialog({
|
|
248
252
|
opened: true,
|
|
249
|
-
...options
|
|
253
|
+
...options,
|
|
254
|
+
closeCallback: (...args) => {
|
|
255
|
+
if(removeOnClose){
|
|
256
|
+
$dialog.remove();
|
|
257
|
+
}
|
|
258
|
+
closeCallback(...args);
|
|
259
|
+
}
|
|
250
260
|
});
|
|
251
261
|
onEvent($dialog, 'close', $dialog.remove);
|
|
252
262
|
if(contents instanceof HTMLElement || contents instanceof DocumentFragment){
|