@deot/docs-launch 0.0.0-stage → 1.0.1
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/README.md +34 -2
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +54 -0
- package/package.json +19 -3
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @deot/docs-launch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
轻量浏览器启动入口:并发探测 CDN,选定唯一节点,先注入四份 CSS,再注入 Client module。
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<div id="app"></div>
|
|
7
|
+
<script>
|
|
8
|
+
window.$docs = {
|
|
9
|
+
locales: { 'zh-CN': { label: '简体中文' } },
|
|
10
|
+
routes: { '/:name': { content: 'default' } },
|
|
11
|
+
// 可省略,以下是默认候选。
|
|
12
|
+
cdns: ['https://cdn.jsdelivr.net/npm/', 'https://esm.unpkg.com/'],
|
|
13
|
+
resolve: {
|
|
14
|
+
cdn: ({ url }) => url
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
</script>
|
|
18
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@deot/docs-launch/+esm"></script>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
省略或清空 `cdns` 时使用默认候选。探针请求同一份固定小文件 `@deot/docs-theme@1.1.4/package.json?raw`,最先完整读取成功响应的节点胜出,每个请求超时 5 秒,随后取消剩余探针。结果写入 `$docs.runtime.cdn`,同一页面重复启动复用同一任务。
|
|
22
|
+
|
|
23
|
+
选中节点保存在 `localStorage['@deot/docs-launch:cdn']`。有缓存且该节点仍在当前候选中时,立即使用缓存启动,同时静默探测并更新缓存,供下次页面启动使用;本次页面的节点和资源保持不变。没有可用缓存时,先探测再加载。后台探测失败时保留原缓存;存储不可用时仍可正常探测和启动。
|
|
24
|
+
|
|
25
|
+
启动器按 Client、Renderer、Markdown、Playground 的顺序插入 stylesheet link,再插入 Client module script;不等待 CSS load 事件才请求 JS。所有地址先按选中节点生成,再经过用户可选的同步 `resolve.cdn({ url })`。返回 `null`、`undefined` 或空字符串时保留原地址,钩子本身不会被启动器替换,探针不经过钩子。
|
|
26
|
+
|
|
27
|
+
Client 与 Playground 内置 jsDelivr / UNPKG 地址转换,继续使用选中的同一节点,再调用用户钩子。原配置与缓存保留原始地址。转换服务内部模块引用及重定向仍交给浏览器处理。
|
|
28
|
+
|
|
29
|
+
没有可用缓存且全部探针失败时不启动应用;选定后的资源加载失败只报告错误,不跨 CDN 回退。每次页面启动只探测一次,不提供持续测速或网络代理。启动器自身首次下载由 HTML 的脚本地址决定。自定义候选默认使用 jsDelivr 兼容路径,特殊资源入口通过最终钩子调整。
|
|
30
|
+
|
|
31
|
+
包没有运行时依赖,通过 `--minify-package 'launch'` 生成单个自包含的普通压缩 ESM,体积预算为 3 KiB、gzip 后 1.5 KiB。无需 eval 或解压器。聚合包不会重导出自动启动入口。
|
|
32
|
+
|
|
33
|
+
本仓库 `doc dev` 继续使用本地 Client;`doc preview` 构建并映射本地 launch 和 Client,预览适配会先调用用户钩子,再映射本地 Client URL。消费项目仍使用声明的发布地址。
|
|
34
|
+
|
|
35
|
+
发布顺序:先发布支持 `runtime.cdn` / `resolve.cdn` 的 Playground 与 Client,再发布 launch,最后迁移 HTML 入口。
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=[`https://cdn.jsdelivr.net/npm/`,`https://esm.unpkg.com/`],t=Symbol.for(`@deot/docs-launch`),n=`@deot/docs-launch:cdn`,r=(r=window)=>{let i=r;return i[t]??=(async()=>{let t=i.$docs||={},r=t.cdns?.map(e=>e.trim()).filter(Boolean),a=[...new Set((r?.length?r:e).map(e=>`${e.replace(/\/+$/u,``)}/`))],o=(async()=>{let e=a.map(()=>new AbortController);try{return await Promise.any(a.map(async(t,n)=>{let r=e[n],i=setTimeout(()=>r.abort(),5e3);try{let e=await fetch(`${t}@deot/docs-theme@1.1.4/package.json?raw`,{signal:r.signal});if(!e.ok)throw Error(`${e.status} ${t}`);return await e.text(),t}finally{clearTimeout(i)}}))}finally{e.forEach(e=>e.abort())}})().then(e=>{try{i.localStorage.setItem(n,e)}catch{}return e}),s=``;try{s=i.localStorage.getItem(n)||``}catch{}a.includes(s)?o.catch(()=>{}):s=await o,t.runtime={...t.runtime,mode:t.runtime?.mode||`production`,cdn:s};let c=e=>{let n=`${s}${e}`;return t.resolve?.cdn?.({url:n})||n},l=i.document;for(let e of[`client`,`renderer`,`markdown`,`playground`]){let t=l.createElement(`link`);t.rel=`stylesheet`,t.href=c(`@deot/docs-${e}/dist/index.style.css`),t.onerror=()=>console.error(`[docs-launch] Failed to load ${t.href}`),l.head.appendChild(t)}let u=l.createElement(`script`);u.type=`module`,u.src=c(`@deot/docs-client${new URL(s).hostname===`esm.unpkg.com`?``:`/+esm`}`),u.onerror=()=>console.error(`[docs-launch] Failed to load ${u.src}`),l.body.appendChild(u)})()};typeof window<`u`&&document.querySelector(`#app`)&&r().catch(e=>console.error(`[docs-launch] Failed to launch`,e)),exports.launch=r;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region packages/launch/src/index.ts
|
|
2
|
+
var e = ["https://cdn.jsdelivr.net/npm/", "https://esm.unpkg.com/"], t = Symbol.for("@deot/docs-launch"), n = "@deot/docs-launch:cdn", r = (r = window) => {
|
|
3
|
+
let i = r;
|
|
4
|
+
return i[t] ??= (async () => {
|
|
5
|
+
let t = i.$docs ||= {}, r = t.cdns?.map((e) => e.trim()).filter(Boolean), a = [...new Set((r?.length ? r : e).map((e) => `${e.replace(/\/+$/u, "")}/`))], o = (async () => {
|
|
6
|
+
let e = a.map(() => new AbortController());
|
|
7
|
+
try {
|
|
8
|
+
return await Promise.any(a.map(async (t, n) => {
|
|
9
|
+
let r = e[n], i = setTimeout(() => r.abort(), 5e3);
|
|
10
|
+
try {
|
|
11
|
+
let e = await fetch(`${t}@deot/docs-theme@1.1.4/package.json?raw`, { signal: r.signal });
|
|
12
|
+
if (!e.ok) throw Error(`${e.status} ${t}`);
|
|
13
|
+
return await e.text(), t;
|
|
14
|
+
} finally {
|
|
15
|
+
clearTimeout(i);
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
18
|
+
} finally {
|
|
19
|
+
e.forEach((e) => e.abort());
|
|
20
|
+
}
|
|
21
|
+
})().then((e) => {
|
|
22
|
+
try {
|
|
23
|
+
i.localStorage.setItem(n, e);
|
|
24
|
+
} catch {}
|
|
25
|
+
return e;
|
|
26
|
+
}), s = "";
|
|
27
|
+
try {
|
|
28
|
+
s = i.localStorage.getItem(n) || "";
|
|
29
|
+
} catch {}
|
|
30
|
+
a.includes(s) ? o.catch(() => {}) : s = await o, t.runtime = {
|
|
31
|
+
...t.runtime,
|
|
32
|
+
mode: t.runtime?.mode || "production",
|
|
33
|
+
cdn: s
|
|
34
|
+
};
|
|
35
|
+
let c = (e) => {
|
|
36
|
+
let n = `${s}${e}`;
|
|
37
|
+
return t.resolve?.cdn?.({ url: n }) || n;
|
|
38
|
+
}, l = i.document;
|
|
39
|
+
for (let e of [
|
|
40
|
+
"client",
|
|
41
|
+
"renderer",
|
|
42
|
+
"markdown",
|
|
43
|
+
"playground"
|
|
44
|
+
]) {
|
|
45
|
+
let t = l.createElement("link");
|
|
46
|
+
t.rel = "stylesheet", t.href = c(`@deot/docs-${e}/dist/index.style.css`), t.onerror = () => console.error(`[docs-launch] Failed to load ${t.href}`), l.head.appendChild(t);
|
|
47
|
+
}
|
|
48
|
+
let u = l.createElement("script");
|
|
49
|
+
u.type = "module", u.src = c(`@deot/docs-client${new URL(s).hostname === "esm.unpkg.com" ? "" : "/+esm"}`), u.onerror = () => console.error(`[docs-launch] Failed to load ${u.src}`), l.body.appendChild(u);
|
|
50
|
+
})();
|
|
51
|
+
};
|
|
52
|
+
typeof window < "u" && document.querySelector("#app") && r().catch((e) => console.error("[docs-launch] Failed to launch", e));
|
|
53
|
+
//#endregion
|
|
54
|
+
export { r as launch };
|
package/package.json
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deot/docs-launch",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"sideEffects": true,
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
}
|
|
6
22
|
}
|