webc.site 0.1.19 → 0.1.21
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/package.json +1 -1
- package/x.js +1 -1
- package/x.js.map +1 -1
- package/importmap/genDoc.md +0 -9
- package/importmap/x/On.js +0 -13
- package/importmap/x/On.md +0 -8
- package/importmap/x/a.js +0 -23
- package/importmap/x/a.md +0 -3
- package/importmap/x/delayRoute.js +0 -17
- package/importmap/x/delayRoute.md +0 -11
- package/importmap/x/dom.js +0 -3
- package/importmap/x/dom.md +0 -7
- package/importmap/x/package.json +0 -22
- package/importmap/x/rmWait.js +0 -2
- package/importmap/x/rmWait.md +0 -3
- package/importmap/x/route.js +0 -59
- package/importmap/x/route.md +0 -37
- package/importmap/x/selfA.js +0 -13
- package/importmap/x/selfA.md +0 -6
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"webc.site","version":"0.1.
|
|
1
|
+
{"name":"webc.site","version":"0.1.21","description":"","keywords":[],"homepage":"https://webc-zh.github.io","license":"MulanPSL-2.0","author":"i18n.site@gmail.com","repository":{"type":"git","url":"git+https://github.com/webc-zh/webc-zh.github.io.git"},"files":["./*"],"type":"module","exports":{"./*":"./*"},"scripts":{},"devDependencies":{}}
|
package/x.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=(e,t)=>{let n,r;for(n in t)r=t[n],e.addEventListener(n,r);return()=>{for(n in t)r=t[n],e.removeEventListener(n,r)}},t=
|
|
1
|
+
const e=(e,t)=>{let n,r;for(n in t)r=t[n],e.addEventListener(n,r);return()=>{for(n in t)r=t[n],e.removeEventListener(n,r)}},t=document,n=t.body,r=t.createElement.bind(t);export{n as B,t as D,e as On,r as newEl};
|
package/x.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x.js","names":[],"sources":["../../importmap/x/On.js","../../importmap/x/
|
|
1
|
+
{"version":3,"file":"x.js","names":[],"sources":["../../importmap/x/On.js","../../importmap/x/dom.js"],"sourcesContent":["export const On = (elem, dict) => {\n let event, func;\n for (event in dict) {\n func = dict[event];\n elem.addEventListener(event, func);\n }\n return () => {\n for (event in dict) {\n func = dict[event];\n elem.removeEventListener(event, func);\n }\n };\n};\n","export const D = document,\n B = D.body,\n newEl = D.createElement.bind(D);\n"],"mappings":"AAAA,MAAa,GAAM,EAAM,IAAS,CAChC,IAAI,EAAO,EACX,IAAK,KAAS,EACZ,EAAO,EAAK,GACZ,EAAK,iBAAiB,EAAO,CAAI,EAEnC,UAAa,CACX,IAAK,KAAS,EACZ,EAAO,EAAK,GACZ,EAAK,oBAAoB,EAAO,CAAI,CAExC,CACF,ECZa,EAAI,SACf,EAAI,EAAE,KACN,EAAQ,EAAE,cAAc,KAAK,CAAC"}
|
package/importmap/genDoc.md
DELETED
package/importmap/x/On.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const On = (elem, dict) => {
|
|
2
|
-
let event, func;
|
|
3
|
-
for (event in dict) {
|
|
4
|
-
func = dict[event];
|
|
5
|
-
elem.addEventListener(event, func);
|
|
6
|
-
}
|
|
7
|
-
return () => {
|
|
8
|
-
for (event in dict) {
|
|
9
|
-
func = dict[event];
|
|
10
|
-
elem.removeEventListener(event, func);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
};
|
package/importmap/x/On.md
DELETED
package/importmap/x/a.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { goto, selfA, B } from "../../x.js";
|
|
2
|
-
B.addEventListener("click", (e) => {
|
|
3
|
-
var href, name, p;
|
|
4
|
-
p = e.target;
|
|
5
|
-
while (p) {
|
|
6
|
-
({ nodeName: name } = p);
|
|
7
|
-
if (name === "A") {
|
|
8
|
-
({ href } = p);
|
|
9
|
-
if (href) {
|
|
10
|
-
href = selfA(p, e);
|
|
11
|
-
if (href !== void 0) {
|
|
12
|
-
goto(href);
|
|
13
|
-
} else if (!p.target) {
|
|
14
|
-
p.target = "_blank";
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
break;
|
|
18
|
-
} else if (name === "BODY") {
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
p = p.parentNode;
|
|
22
|
-
}
|
|
23
|
-
});
|
package/importmap/x/a.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { route } from "./route.js";
|
|
2
|
-
|
|
3
|
-
// 避免 onMount 之前,route 被触发,导致重复加载数据
|
|
4
|
-
export const delayRoute = (loadUrl) => {
|
|
5
|
-
let t;
|
|
6
|
-
const unbind = route((url, preUrl) => {
|
|
7
|
-
t = setTimeout(() => {
|
|
8
|
-
loadUrl(url, preUrl);
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
return () => {
|
|
12
|
-
unbind();
|
|
13
|
-
clearTimeout(t);
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default delayRoute;
|
package/importmap/x/dom.js
DELETED
package/importmap/x/dom.md
DELETED
package/importmap/x/package.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@3-/x",
|
|
3
|
-
"version": "0.2.0",
|
|
4
|
-
"description": "",
|
|
5
|
-
"keywords": [],
|
|
6
|
-
"homepage": "https://webc-zh.github.io",
|
|
7
|
-
"license": "MulanPSL-2.0",
|
|
8
|
-
"author": "i18n.site@gmail.com",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/webc-zh/webc-zh.github.io.git"
|
|
12
|
-
},
|
|
13
|
-
"files": [
|
|
14
|
-
"./*"
|
|
15
|
-
],
|
|
16
|
-
"type": "module",
|
|
17
|
-
"exports": {
|
|
18
|
-
"./*": "./*"
|
|
19
|
-
},
|
|
20
|
-
"scripts": {},
|
|
21
|
-
"devDependencies": {}
|
|
22
|
-
}
|
package/importmap/x/rmWait.js
DELETED
package/importmap/x/rmWait.md
DELETED
package/importmap/x/route.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { On } from "../../x.js";
|
|
2
|
-
export const nowUrl = () => location.pathname.slice(1),
|
|
3
|
-
[route, setPre, preUrl, refresh, removeSlash, split, setUrl, goto] = (() => {
|
|
4
|
-
let PRE = nowUrl(),
|
|
5
|
-
HOOK = [];
|
|
6
|
-
if (location.hash) PRE += location.hash;
|
|
7
|
-
|
|
8
|
-
const HASH = "#",
|
|
9
|
-
route = (hook) => {
|
|
10
|
-
HOOK.push(hook);
|
|
11
|
-
hook(nowUrl());
|
|
12
|
-
return () => {
|
|
13
|
-
HOOK = HOOK.filter((f) => f !== hook);
|
|
14
|
-
};
|
|
15
|
-
},
|
|
16
|
-
setPre = (url) => {
|
|
17
|
-
PRE = url;
|
|
18
|
-
},
|
|
19
|
-
preUrl = () => PRE,
|
|
20
|
-
refresh = (url) => {
|
|
21
|
-
url = url || nowUrl();
|
|
22
|
-
for (const f of HOOK) f(url, PRE);
|
|
23
|
-
setPre(url);
|
|
24
|
-
},
|
|
25
|
-
removeSlash = (url) => (url[0] === "/" ? url.slice(1) : url),
|
|
26
|
-
split = (str, s) => {
|
|
27
|
-
const p = str.indexOf(s);
|
|
28
|
-
return p >= 0 ? [str.slice(0, p), str.slice(p + 1)] : [str, ""];
|
|
29
|
-
},
|
|
30
|
-
setUrl = (url) => {
|
|
31
|
-
url = removeSlash(url);
|
|
32
|
-
if (url !== PRE) {
|
|
33
|
-
const [path, hash] = split(url, HASH),
|
|
34
|
-
[p] = split(PRE, HASH);
|
|
35
|
-
setPre(url);
|
|
36
|
-
if (path !== p) {
|
|
37
|
-
history.pushState(null, "", "/" + url);
|
|
38
|
-
return 1;
|
|
39
|
-
}
|
|
40
|
-
if (location.hash.slice(1) !== hash) {
|
|
41
|
-
location.hash = hash;
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
window.dispatchEvent(new HashChangeEvent("hashchange"));
|
|
46
|
-
},
|
|
47
|
-
goto = (url) => {
|
|
48
|
-
if (setUrl(url)) refresh(url);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
On(window, {
|
|
52
|
-
popstate: () => {
|
|
53
|
-
const url = nowUrl();
|
|
54
|
-
if (url !== split(PRE, HASH)[0]) refresh(url);
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return [route, setPre, preUrl, refresh, removeSlash, split, setUrl, goto];
|
|
59
|
-
})();
|
package/importmap/x/route.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# 路由管理与跳转
|
|
2
|
-
|
|
3
|
-
- `nowUrl()`
|
|
4
|
-
- 返回值:当前 URL 路径(不含首部斜杠)。
|
|
5
|
-
|
|
6
|
-
- `route(hook)`
|
|
7
|
-
- `hook`: 路由变化时执行的回调函数。格式:
|
|
8
|
-
- 参数:
|
|
9
|
-
- `url`: 字符串,新 URL 路径。
|
|
10
|
-
- `preUrl`: 字符串(可选),旧 URL 路径。
|
|
11
|
-
- 返回值:无。
|
|
12
|
-
- 返回值:取消订阅的函数,格式为 `() => void`。
|
|
13
|
-
|
|
14
|
-
- `setPre(url)`
|
|
15
|
-
- `url`: 字符串,新的前一次 URL 路径。
|
|
16
|
-
|
|
17
|
-
- `preUrl()`
|
|
18
|
-
- 返回值:前一次的 URL 路径。
|
|
19
|
-
|
|
20
|
-
- `refresh(url)`
|
|
21
|
-
- `url`: 字符串(可选),要触发回调的 URL 路径,默认是当前 URL。
|
|
22
|
-
|
|
23
|
-
- `removeSlash(url)`
|
|
24
|
-
- `url`: 字符串。
|
|
25
|
-
- 返回值:移除首部斜杠后的字符串。
|
|
26
|
-
|
|
27
|
-
- `split(str, s)`
|
|
28
|
-
- `str`: 待拆分字符串。
|
|
29
|
-
- `s`: 分隔符。
|
|
30
|
-
- 返回值:包含两个元素的数组 `[前部, 后部]`。
|
|
31
|
-
|
|
32
|
-
- `setUrl(url)`
|
|
33
|
-
- `url`: 目标 URL 路径。
|
|
34
|
-
- 返回值:若路径改变返回 `1`,若仅 hash 改变不返回值。
|
|
35
|
-
|
|
36
|
-
- `goto(url)`
|
|
37
|
-
- `url`: 目标 URL 路径。
|
package/importmap/x/selfA.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// 判断A标签的href是否为当前网站的, 如果是, 返回url, 以实现不刷新跳转
|
|
2
|
-
export const selfA = (p, e) => {
|
|
3
|
-
var hash, url;
|
|
4
|
-
if (p.host === location.host) {
|
|
5
|
-
({ hash } = p);
|
|
6
|
-
url = p.pathname.slice(1) + p.search;
|
|
7
|
-
if (hash) {
|
|
8
|
-
url += hash;
|
|
9
|
-
}
|
|
10
|
-
e.preventDefault();
|
|
11
|
-
return url;
|
|
12
|
-
}
|
|
13
|
-
};
|