@capyclaw/offline-ddr0 0.0.0-stage → 1.9.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/LICENSE +21 -0
- package/README.md +441 -2
- package/client/client.js +603 -0
- package/cordis.patch.yml +13 -0
- package/docs/STORAGE-MIGRATION.md +136 -0
- package/lib/atomic.mjs +40 -0
- package/lib/http-cache.mjs +42 -0
- package/lib/inbox.mjs +64 -0
- package/lib/media.mjs +242 -0
- package/lib/migrate-json.mjs +101 -0
- package/lib/mirror-index.mjs +105 -0
- package/lib/mirror.mjs +123 -0
- package/lib/proxy.mjs +188 -0
- package/lib/remote.mjs +158 -0
- package/lib/render.mjs +93 -0
- package/lib/repository.mjs +71 -0
- package/lib/store.mjs +610 -0
- package/lib/surface.mjs +74 -0
- package/lib/sync-ui.mjs +108 -0
- package/lib/sync.mjs +433 -0
- package/lib/wire.mjs +211 -0
- package/lib/workstore-repository.mjs +316 -0
- package/lib/workstore.mjs +338 -0
- package/mirror/files/00001.html +2045 -0
- package/mirror/files/00002.json +1 -0
- package/mirror/files/00003.json +1 -0
- package/mirror/files/00004.json +1 -0
- package/mirror/files/00005.json +1 -0
- package/mirror/files/00006.json +1 -0
- package/mirror/files/00007.json +1 -0
- package/mirror/files/00008.json +1 -0
- package/mirror/files/00009.json +1 -0
- package/mirror/files/00010.json +1 -0
- package/mirror/files/00011.json +1 -0
- package/mirror/files/00012.json +1 -0
- package/mirror/files/00013.json +1 -0
- package/mirror/files/00014.json +1 -0
- package/mirror/files/00015.json +1 -0
- package/mirror/files/00016.json +1 -0
- package/mirror/files/00017.json +1 -0
- package/mirror/files/00018.json +1 -0
- package/mirror/files/00019.json +1 -0
- package/mirror/files/00020.json +1 -0
- package/mirror/files/00021.json +1 -0
- package/mirror/files/00022.json +1 -0
- package/mirror/files/00023.js +205 -0
- package/mirror/files/00024.json +1 -0
- package/mirror/files/00025.json +1 -0
- package/mirror/files/00026.json +1 -0
- package/mirror/files/00027.js +51 -0
- package/mirror/files/00028.json +1 -0
- package/mirror/files/00029.json +1 -0
- package/mirror/files/00030.json +1 -0
- package/mirror/files/00031.json +1 -0
- package/mirror/files/00032.json +1 -0
- package/mirror/files/00033.json +1 -0
- package/mirror/files/00034.json +1 -0
- package/mirror/files/00035.json +1 -0
- package/mirror/files/00036.json +1 -0
- package/mirror/files/00037.json +1 -0
- package/mirror/files/00038.json +1 -0
- package/mirror/files/00039.json +1 -0
- package/mirror/files/00040.js +2311 -0
- package/mirror/files/00041.json +1 -0
- package/mirror/files/00042.json +1 -0
- package/mirror/files/00043.json +1 -0
- package/mirror/files/00044.json +1 -0
- package/mirror/files/00045.js +575 -0
- package/mirror/files/00046.json +1 -0
- package/mirror/files/00047.js +575 -0
- package/mirror/files/00048.js +575 -0
- package/mirror/files/00049.json +1 -0
- package/mirror/files/00050.json +1 -0
- package/mirror/files/00051.json +1 -0
- package/mirror/files/00052.json +1 -0
- package/mirror/files/00053.js +575 -0
- package/mirror/files/00054.json +1 -0
- package/mirror/files/00055.json +1 -0
- package/mirror/files/00056.js +575 -0
- package/mirror/files/00057.json +1 -0
- package/mirror/files/00058.json +1 -0
- package/mirror/files/00059.js +360 -0
- package/mirror/files/00060.json +1 -0
- package/mirror/files/00061.json +1 -0
- package/mirror/files/00062.json +1 -0
- package/mirror/files/00063.json +1 -0
- package/mirror/files/00064.json +1 -0
- package/mirror/files/00065.js +144 -0
- package/mirror/files/00066.js +7 -0
- package/mirror/files/00067.json +1 -0
- package/mirror/files/00068.json +1 -0
- package/mirror/files/00069.json +1 -0
- package/mirror/files/00070.json +1 -0
- package/mirror/files/00071.json +1 -0
- package/mirror/files/00072.json +1 -0
- package/mirror/files/00073.js +1 -0
- package/mirror/files/00074.json +1 -0
- package/mirror/files/00075.json +1 -0
- package/mirror/files/00076.json +1 -0
- package/mirror/files/00077.js +45 -0
- package/mirror/files/00078.js +1348 -0
- package/mirror/files/00079.json +1 -0
- package/mirror/files/00080.json +1 -0
- package/mirror/files/00081.js +1 -0
- package/mirror/files/00082.json +1 -0
- package/mirror/files/00083.json +1 -0
- package/mirror/files/00084.js +7 -0
- package/mirror/files/00085.json +1 -0
- package/mirror/files/00086.json +1 -0
- package/mirror/files/00087.js +7 -0
- package/mirror/files/00088.json +1 -0
- package/mirror/files/00089.json +1 -0
- package/mirror/files/00090.js +7 -0
- package/mirror/files/00091.json +1 -0
- package/mirror/files/00092.json +1 -0
- package/mirror/files/00093.js +102 -0
- package/mirror/files/00094.json +1 -0
- package/mirror/files/00095.json +1 -0
- package/mirror/files/00096.json +1 -0
- package/mirror/files/00097.json +1 -0
- package/mirror/files/00098.json +1 -0
- package/mirror/files/00099.json +1 -0
- package/mirror/files/00100.json +1 -0
- package/mirror/files/00101.js +102 -0
- package/mirror/files/00102.json +1 -0
- package/mirror/files/00103.json +1 -0
- package/mirror/files/00104.json +1 -0
- package/mirror/files/00105.json +1 -0
- package/mirror/files/00106.json +1 -0
- package/mirror/files/00107.js +110 -0
- package/mirror/files/00108.json +1 -0
- package/mirror/files/00109.json +1 -0
- package/mirror/files/00110.json +1 -0
- package/mirror/files/00111.json +1 -0
- package/mirror/files/00112.json +1 -0
- package/mirror/files/00113.json +1 -0
- package/mirror/files/00114.json +1 -0
- package/mirror/files/00115.json +1 -0
- package/mirror/files/00116.json +1 -0
- package/mirror/files/00117.json +1 -0
- package/mirror/files/00118.json +1 -0
- package/mirror/files/00119.json +1 -0
- package/mirror/files/00120.json +1 -0
- package/mirror/files/00121.json +1 -0
- package/mirror/files/00122.json +1 -0
- package/mirror/files/00123.json +1 -0
- package/mirror/files/00124.json +1 -0
- package/mirror/files/00125.json +1 -0
- package/mirror/files/00126.json +1 -0
- package/mirror/files/00127.json +1 -0
- package/mirror/files/00128.json +1 -0
- package/mirror/files/00129.json +1 -0
- package/mirror/files/00130.json +1 -0
- package/mirror/files/00131.json +1 -0
- package/mirror/files/00132.js +110 -0
- package/mirror/files/00133.json +1 -0
- package/mirror/files/00134.json +1 -0
- package/mirror/files/00135.json +1 -0
- package/mirror/files/00136.json +1 -0
- package/mirror/files/00137.js +26 -0
- package/mirror/files/00138.json +1 -0
- package/mirror/files/00139.json +1 -0
- package/mirror/files/00140.json +1 -0
- package/mirror/files/00141.json +1 -0
- package/mirror/files/00142.json +1 -0
- package/mirror/files/00143.json +1 -0
- package/mirror/files/00144.js +26 -0
- package/mirror/files/00145.json +1 -0
- package/mirror/files/00146.json +1 -0
- package/mirror/files/00147.js +29 -0
- package/mirror/files/00148.json +1 -0
- package/mirror/files/00149.json +1 -0
- package/mirror/files/00150.js +23 -0
- package/mirror/files/00151.json +1 -0
- package/mirror/files/00152.json +1 -0
- package/mirror/files/00153.js +719 -0
- package/mirror/files/00154.js +9575 -0
- package/mirror/files/00155.js +108 -0
- package/mirror/files/00156.js +379 -0
- package/mirror/files/00157.js +48 -0
- package/mirror/files/00158.json +16 -0
- package/mirror/manifest.json +1582 -0
- package/node_modules/@capyclaw/asset-service/README.md +48 -0
- package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
- package/node_modules/@capyclaw/asset-service/package.json +59 -0
- package/node_modules/@capyclaw/asset-service/src/index.mjs +223 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +68 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +160 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +87 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +188 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/service-host/README.md +86 -0
- package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
- package/node_modules/@capyclaw/service-host/package.json +60 -0
- package/node_modules/@capyclaw/service-host/src/index.mjs +571 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/suite-kit/README.md +238 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
- package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
- package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
- package/node_modules/@capyclaw/suite-kit/package.json +54 -0
- package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
- package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
- package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
- package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
- package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
- package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
- package/node_modules/@capyclaw/suite-kit/src/index.mjs +10 -0
- package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
- package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
- package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
- package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
- package/node_modules/@capyclaw/suite-kit/suite.schema.json +112 -0
- package/node_modules/@capyclaw/work-store/README.md +83 -0
- package/node_modules/@capyclaw/work-store/STANDARD.md +257 -0
- package/node_modules/@capyclaw/work-store/cordis.patch.yml +3 -0
- package/node_modules/@capyclaw/work-store/dsh-suite.json +26 -0
- package/node_modules/@capyclaw/work-store/icon.svg +7 -0
- package/node_modules/@capyclaw/work-store/lib/host.mjs +21 -0
- package/node_modules/@capyclaw/work-store/package.json +68 -0
- package/node_modules/@capyclaw/work-store/src/backend.mjs +89 -0
- package/node_modules/@capyclaw/work-store/src/db.mjs +199 -0
- package/node_modules/@capyclaw/work-store/src/envelope.mjs +132 -0
- package/node_modules/@capyclaw/work-store/src/index.mjs +570 -0
- package/node_modules/@capyclaw/work-store/src/interop.mjs +70 -0
- package/node_modules/@capyclaw/work-store/src/refs.mjs +99 -0
- package/node_modules/@capyclaw/work-store/src/routes.mjs +135 -0
- package/package.json +82 -4
- package/plugin.mjs +636 -0
- package/static/index.html +2068 -0
package/client/client.js
ADDED
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
// 离线 ddr0 · 浏览器半
|
|
2
|
+
//
|
|
3
|
+
// - 左侧全局面板区(和「插件」「自动化任务」同一排)多一个「离线 ddr0」入口;
|
|
4
|
+
// - 主区域用同源 iframe 承载离线站:index.html 由宿主半直出,/api 与
|
|
5
|
+
// /config.json 由宿主半反代,所以这里只负责挂入口和画框。
|
|
6
|
+
// - 站点前缀不写死:先按宿主注入的 __DSH_OFFLINE_DDR0__.site 试,再依次
|
|
7
|
+
// 退回 foundation 共享宿主的默认前缀与根前缀;先探测 /config.json 再开
|
|
8
|
+
// iframe,避免把 404 页当站点画进主区域。
|
|
9
|
+
// - 主题跟随 DSH:站点自己提供 Theme/ThemeSync 运行时与两个 localStorage 键
|
|
10
|
+
// (<slug>_theme 首帧模式、<slug>_theme_follow_ext 跟随开关),并在开启跟随
|
|
11
|
+
// 时每 10s 轮询 /api/theme/sync。这里三件事都走站点既有接口——装载前写首帧
|
|
12
|
+
// 键并打开跟随,装载后调 Theme.apply 立即对齐(不等 10s),DSH 主题切换时
|
|
13
|
+
// 重推一遍;同时把模式 POST 给宿主半的 /api/theme/sync,让站点的轮询拿到同
|
|
14
|
+
// 一份真源。另按站点桥协议发 {type:'fw:theme', mode} 并应答 theme-query。
|
|
15
|
+
window.__ModuleLoader__.load({
|
|
16
|
+
id: '@capyclaw/offline-ddr0',
|
|
17
|
+
factory: (require) => {
|
|
18
|
+
const module = { exports: {} }
|
|
19
|
+
const exports = module.exports
|
|
20
|
+
const React = require('react')
|
|
21
|
+
const h = React.createElement
|
|
22
|
+
|
|
23
|
+
const PANEL = 'offline-ddr0'
|
|
24
|
+
const LABEL = '离线 ddr0'
|
|
25
|
+
const boot = globalThis.__DSH_OFFLINE_DDR0__
|
|
26
|
+
const INJECTED = boot && typeof boot.site === 'string' ? boot.site.replace(/\/+$/, '') : ''
|
|
27
|
+
// foundation 默认把共享宿主挂在 /plugins/foundation-shared 下;根前缀留给
|
|
28
|
+
// 宿主直接挂 /offline-ddr0 的情形。
|
|
29
|
+
const CANDIDATES = [INJECTED, '/plugins/foundation-shared/offline-ddr0', '/offline-ddr0']
|
|
30
|
+
.filter((value, index, list) => typeof value === 'string' && value && list.indexOf(value) === index)
|
|
31
|
+
|
|
32
|
+
// 站点把主题存在 <site.slug>_theme,跟随开关存在 <site.slug>_theme_follow_ext
|
|
33
|
+
// (见站点 Theme/ThemeSync 实现)。父页面与站点同源,所以这两个键都能直接写。
|
|
34
|
+
function themeKey(slug) {
|
|
35
|
+
return `${slug || 'site'}_theme`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function followKey(slug) {
|
|
39
|
+
return `${slug || 'site'}_theme_follow_ext`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function clampMode(value) {
|
|
43
|
+
return value === 'dark' ? 'dark' : 'light'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// theme 是可选服务(和 my-works 一样用 ctx.inject 等待它就绪);
|
|
47
|
+
// 服务出现之前/不存在时退到系统偏好,避免首帧空白。
|
|
48
|
+
function fallbackMode() {
|
|
49
|
+
try {
|
|
50
|
+
if (globalThis.matchMedia && globalThis.matchMedia('(prefers-color-scheme: dark)').matches) return 'dark'
|
|
51
|
+
} catch {
|
|
52
|
+
/* ignore */
|
|
53
|
+
}
|
|
54
|
+
return 'light'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function createThemeStore(ctx) {
|
|
58
|
+
const listeners = new Set()
|
|
59
|
+
let mode = fallbackMode()
|
|
60
|
+
let off = null
|
|
61
|
+
const notify = () => {
|
|
62
|
+
for (const listener of [...listeners]) {
|
|
63
|
+
try {
|
|
64
|
+
listener()
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('[offline-ddr0] 主题监听失败', error)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const applySnapshot = (snapshot) => {
|
|
71
|
+
const scheme = snapshot && snapshot.active && snapshot.active.colorScheme
|
|
72
|
+
if (scheme === 'dark' || scheme === 'light') {
|
|
73
|
+
mode = scheme
|
|
74
|
+
notify()
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
// 等待 theme 服务:DSH 切主题、换主题包、偏好为 system 而系统配色翻转
|
|
79
|
+
// 都会走 theme/change。
|
|
80
|
+
ctx.inject(['theme'], (c) => {
|
|
81
|
+
applySnapshot(c.theme.getTheme())
|
|
82
|
+
off = c.on('theme/change', applySnapshot)
|
|
83
|
+
})
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error('[offline-ddr0] 接入 theme 服务失败', error)
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
get: () => mode,
|
|
89
|
+
subscribe(listener) {
|
|
90
|
+
listeners.add(listener)
|
|
91
|
+
return () => {
|
|
92
|
+
listeners.delete(listener)
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
dispose() {
|
|
96
|
+
listeners.clear()
|
|
97
|
+
if (typeof off === 'function') off()
|
|
98
|
+
},
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function useThemeMode(store) {
|
|
103
|
+
return React.useSyncExternalStore(store.subscribe, store.get, store.get)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 首帧预置:站点在自己启动脚本里同步读这个键,写在 iframe 发起请求之前
|
|
107
|
+
// 就不会出现「先浅后深」。同时把站点的「跟随外部主题」开关打开——这是站点
|
|
108
|
+
// 自带的接口,打开后它会每 10s 拉一次 /api/theme/sync。
|
|
109
|
+
function seedTheme(entry, mode) {
|
|
110
|
+
if (!entry) return
|
|
111
|
+
try {
|
|
112
|
+
localStorage.setItem(themeKey(entry.slug), clampMode(mode))
|
|
113
|
+
localStorage.setItem(followKey(entry.slug), '1')
|
|
114
|
+
} catch {
|
|
115
|
+
/* 隐私模式等写入失败:只影响首帧,装载后还会 apply 一次 */
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 把 DSH 的当前明暗推给宿主半的 /api/theme/sync(站点轮询它,后端没有这个端点,
|
|
120
|
+
// 由本插件的宿主半接管)。失败不提示:站点首帧键与 apply 仍然生效。
|
|
121
|
+
function pushMode(entry, mode) {
|
|
122
|
+
if (!entry) return
|
|
123
|
+
try {
|
|
124
|
+
fetch(`${entry.base}/api/theme/sync`, {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
credentials: 'same-origin',
|
|
127
|
+
headers: { 'content-type': 'application/json' },
|
|
128
|
+
body: JSON.stringify({ mode: clampMode(mode) }),
|
|
129
|
+
keepalive: true,
|
|
130
|
+
}).catch(() => {})
|
|
131
|
+
} catch {
|
|
132
|
+
/* ignore */
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function paintFrame(frame, mode) {
|
|
137
|
+
if (!frame) return
|
|
138
|
+
const value = clampMode(mode)
|
|
139
|
+
let win = null
|
|
140
|
+
try {
|
|
141
|
+
win = frame.contentWindow
|
|
142
|
+
} catch {
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
if (!win) return
|
|
146
|
+
// 站点桥协议(免 channel,父→应用),它现在不一定监听,但保持对齐。
|
|
147
|
+
try {
|
|
148
|
+
win.postMessage({ type: 'fw:theme', mode: value }, '*')
|
|
149
|
+
} catch {
|
|
150
|
+
/* ignore */
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
// 同源:站点自带 Theme 运行时是唯一真源。
|
|
154
|
+
if (win.Theme && typeof win.Theme.apply === 'function') {
|
|
155
|
+
// 跟随开关以宿主为准,避免用户在站点里切了又被 10s 轮询覆盖回来时闪烁。
|
|
156
|
+
if (typeof win.Theme.setFollowExt === 'function') win.Theme.setFollowExt(true)
|
|
157
|
+
win.Theme.apply(value)
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
const doc = win.document
|
|
161
|
+
if (doc && doc.documentElement) {
|
|
162
|
+
doc.documentElement.setAttribute('data-theme', value)
|
|
163
|
+
doc.documentElement.style.colorScheme = value
|
|
164
|
+
}
|
|
165
|
+
} catch {
|
|
166
|
+
/* 跨源/还没文档:只能靠 postMessage */
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 站点装载完成后立刻拉一次,省掉首轮 10s 等待。
|
|
171
|
+
function refreshSync(frame) {
|
|
172
|
+
try {
|
|
173
|
+
const win = frame && frame.contentWindow
|
|
174
|
+
if (win && win.ThemeSync && typeof win.ThemeSync.refresh === 'function') win.ThemeSync.refresh()
|
|
175
|
+
} catch {
|
|
176
|
+
/* ignore */
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function SiteIcon(props) {
|
|
181
|
+
const size = (props && props.size) || 18
|
|
182
|
+
return h(
|
|
183
|
+
'svg',
|
|
184
|
+
{
|
|
185
|
+
width: size,
|
|
186
|
+
height: size,
|
|
187
|
+
viewBox: '0 0 24 24',
|
|
188
|
+
fill: 'none',
|
|
189
|
+
stroke: 'currentColor',
|
|
190
|
+
strokeWidth: 1.6,
|
|
191
|
+
strokeLinecap: 'round',
|
|
192
|
+
strokeLinejoin: 'round',
|
|
193
|
+
'aria-hidden': 'true',
|
|
194
|
+
},
|
|
195
|
+
h('circle', { cx: 12, cy: 12, r: 8.2 }),
|
|
196
|
+
h('path', { d: 'M3.9 12h16.2' }),
|
|
197
|
+
h('path', { d: 'M12 3.8c2.2 2.4 3.3 5.2 3.3 8.2s-1.1 5.8-3.3 8.2c-2.2-2.4-3.3-5.2-3.3-8.2S9.8 6.2 12 3.8Z' }),
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function Hint({ children }) {
|
|
202
|
+
return h(
|
|
203
|
+
'div',
|
|
204
|
+
{
|
|
205
|
+
style: {
|
|
206
|
+
display: 'flex',
|
|
207
|
+
alignItems: 'center',
|
|
208
|
+
justifyContent: 'center',
|
|
209
|
+
width: '100%',
|
|
210
|
+
height: '100%',
|
|
211
|
+
padding: '24px',
|
|
212
|
+
color: 'var(--dsw-alias-label-secondary, #8a8f98)',
|
|
213
|
+
fontSize: '13px',
|
|
214
|
+
textAlign: 'center',
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
children,
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function probe(base) {
|
|
222
|
+
try {
|
|
223
|
+
const res = await fetch(`${base}/config.json`, { credentials: 'same-origin' })
|
|
224
|
+
if (!res.ok) return null
|
|
225
|
+
const body = await res.json()
|
|
226
|
+
if (!body || typeof body.apiBaseUrl !== 'string') return null
|
|
227
|
+
const slug = body.site && typeof body.site.slug === 'string' ? body.site.slug : ''
|
|
228
|
+
return { base, slug }
|
|
229
|
+
} catch {
|
|
230
|
+
return null
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 带超时的探测:扫端口时不能被一个死端口拖住整轮。
|
|
235
|
+
async function probeFast(base, ms) {
|
|
236
|
+
const ctrl = typeof AbortController === 'function' ? new AbortController() : null
|
|
237
|
+
const timer = ctrl ? setTimeout(() => ctrl.abort(), ms) : null
|
|
238
|
+
try {
|
|
239
|
+
const res = await fetch(`${base}/config.json`, {
|
|
240
|
+
credentials: 'omit',
|
|
241
|
+
signal: ctrl ? ctrl.signal : undefined,
|
|
242
|
+
})
|
|
243
|
+
if (!res.ok) return null
|
|
244
|
+
const body = await res.json()
|
|
245
|
+
if (!body || typeof body.apiBaseUrl !== 'string') return null
|
|
246
|
+
const slug = body.site && typeof body.site.slug === 'string' ? body.site.slug : ''
|
|
247
|
+
return { base, slug }
|
|
248
|
+
} catch {
|
|
249
|
+
return null
|
|
250
|
+
} finally {
|
|
251
|
+
if (timer) clearTimeout(timer)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// 共享宿主若退化到独立端口(旧 foundation / 启动时序),相对前缀必然 404。
|
|
256
|
+
// 独立端口由 OS 分配,通常紧挨着 GUI 端口:扫 127.0.0.1 的 +1..+8,
|
|
257
|
+
// 两种挂载形态都试。插件发 CORS *,跨源命中也能用;结果记 sessionStorage。
|
|
258
|
+
async function discoverStandalone() {
|
|
259
|
+
try {
|
|
260
|
+
const cached = sessionStorage.getItem('offline-ddr0-base')
|
|
261
|
+
if (cached) {
|
|
262
|
+
const hit = await probeFast(cached, 900)
|
|
263
|
+
if (hit) return hit
|
|
264
|
+
}
|
|
265
|
+
} catch {
|
|
266
|
+
/* 隐私模式等:直接扫 */
|
|
267
|
+
}
|
|
268
|
+
const port = Number(location.port) || (location.protocol === 'https:' ? 443 : 80)
|
|
269
|
+
const origins = []
|
|
270
|
+
for (let delta = 1; delta <= 8; delta += 1) origins.push(`http://127.0.0.1:${port + delta}`)
|
|
271
|
+
const results = await Promise.all(
|
|
272
|
+
origins.map(async (origin) => {
|
|
273
|
+
const direct = await probeFast(`${origin}/offline-ddr0`, 900)
|
|
274
|
+
if (direct) return direct
|
|
275
|
+
return probeFast(`${origin}/plugins/foundation-shared/offline-ddr0`, 900)
|
|
276
|
+
}),
|
|
277
|
+
)
|
|
278
|
+
const hit = results.find(Boolean)
|
|
279
|
+
if (hit) {
|
|
280
|
+
try {
|
|
281
|
+
sessionStorage.setItem('offline-ddr0-base', hit.base)
|
|
282
|
+
} catch {
|
|
283
|
+
/* ignore */
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return hit || null
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function createPanel(store) {
|
|
290
|
+
return function SitePanel() {
|
|
291
|
+
const [entry, setEntry] = React.useState(null)
|
|
292
|
+
const [failed, setFailed] = React.useState(false)
|
|
293
|
+
const [manageOpen, setManageOpen] = React.useState(false)
|
|
294
|
+
const [localItems, setLocalItems] = React.useState(null)
|
|
295
|
+
const [localErr, setLocalErr] = React.useState('')
|
|
296
|
+
const frameRef = React.useRef(null)
|
|
297
|
+
const fileRef = React.useRef(null)
|
|
298
|
+
const mode = useThemeMode(store)
|
|
299
|
+
|
|
300
|
+
React.useEffect(() => {
|
|
301
|
+
let alive = true
|
|
302
|
+
;(async () => {
|
|
303
|
+
// 宿主半可能比自己晚一步就位(共享宿主补挂前缀、端口刚起来),
|
|
304
|
+
// 所以失败不立刻认输:再等一会儿重试,避免只剩一句「没有响应」。
|
|
305
|
+
for (let round = 0; round < 3; round += 1) {
|
|
306
|
+
if (round > 0) await new Promise((resolve) => setTimeout(resolve, 1200))
|
|
307
|
+
for (const base of CANDIDATES) {
|
|
308
|
+
const probeResult = await probe(base)
|
|
309
|
+
if (probeResult) {
|
|
310
|
+
if (!alive) return
|
|
311
|
+
seedTheme(probeResult, store.get())
|
|
312
|
+
setEntry(probeResult)
|
|
313
|
+
return
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const found = await discoverStandalone()
|
|
317
|
+
if (found) {
|
|
318
|
+
if (!alive) return
|
|
319
|
+
seedTheme(found, store.get())
|
|
320
|
+
setEntry(found)
|
|
321
|
+
return
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (alive) setFailed(true)
|
|
325
|
+
})()
|
|
326
|
+
return () => {
|
|
327
|
+
alive = false
|
|
328
|
+
}
|
|
329
|
+
}, [])
|
|
330
|
+
|
|
331
|
+
// 装载后与每次主题切换:预置存储键、推给宿主半、再推进 iframe。
|
|
332
|
+
React.useEffect(() => {
|
|
333
|
+
if (!entry) return
|
|
334
|
+
seedTheme(entry, mode)
|
|
335
|
+
pushMode(entry, mode)
|
|
336
|
+
paintFrame(frameRef.current, mode)
|
|
337
|
+
}, [entry, mode])
|
|
338
|
+
|
|
339
|
+
// 站点若按桥协议回问 theme-query(应用页装载晚于父侧推送时的补拉口),
|
|
340
|
+
// 只应答自己这个 iframe 发出的请求。
|
|
341
|
+
React.useEffect(() => {
|
|
342
|
+
function onMessage(event) {
|
|
343
|
+
const frame = frameRef.current
|
|
344
|
+
if (!frame || event.source !== frame.contentWindow) return
|
|
345
|
+
const data = event.data
|
|
346
|
+
if (!data || data.type !== 'theme-query') return
|
|
347
|
+
paintFrame(frame, store.get())
|
|
348
|
+
}
|
|
349
|
+
window.addEventListener('message', onMessage)
|
|
350
|
+
return () => window.removeEventListener('message', onMessage)
|
|
351
|
+
}, [])
|
|
352
|
+
|
|
353
|
+
if (failed) {
|
|
354
|
+
return h(Hint, null, '离线站没有响应:宿主半没挂上,或后端端口不可达。')
|
|
355
|
+
}
|
|
356
|
+
if (!entry) return h(Hint, null, '正在连接离线站…')
|
|
357
|
+
|
|
358
|
+
// ---- 本地作品库:管理/导入/打开/删除 ----
|
|
359
|
+
async function refreshLocal() {
|
|
360
|
+
try {
|
|
361
|
+
const res = await fetch(`${entry.base}/api/local/works`, { credentials: 'omit' })
|
|
362
|
+
if (!res.ok) throw new Error(String(res.status))
|
|
363
|
+
const body = await res.json()
|
|
364
|
+
setLocalItems(Array.isArray(body.items) ? body.items : [])
|
|
365
|
+
setLocalErr('')
|
|
366
|
+
} catch {
|
|
367
|
+
setLocalItems([])
|
|
368
|
+
setLocalErr('当前宿主半还没有本地库接口:请重启一次 DSH 再试。')
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function openLocal(id) {
|
|
373
|
+
const frame = frameRef.current
|
|
374
|
+
const win = frame && frame.contentWindow
|
|
375
|
+
try {
|
|
376
|
+
if (win && win.ItemViewOrchestrator && typeof win.ItemViewOrchestrator.resolveAndOpen === 'function') {
|
|
377
|
+
win.ItemViewOrchestrator.resolveAndOpen('works', id)
|
|
378
|
+
} else if (win) {
|
|
379
|
+
win.postMessage({ type: 'offline-ddr0-open', itemType: 'works', id }, '*')
|
|
380
|
+
}
|
|
381
|
+
} catch {
|
|
382
|
+
try {
|
|
383
|
+
win.postMessage({ type: 'offline-ddr0-open', itemType: 'works', id }, '*')
|
|
384
|
+
} catch {
|
|
385
|
+
/* ignore */
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
setManageOpen(false)
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
async function deleteLocal(id) {
|
|
392
|
+
try {
|
|
393
|
+
await fetch(`${entry.base}/api/local/works/${id}`, { method: 'DELETE', credentials: 'omit' })
|
|
394
|
+
} catch {
|
|
395
|
+
/* ignore */
|
|
396
|
+
}
|
|
397
|
+
refreshLocal()
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
async function exportLocal() {
|
|
401
|
+
try {
|
|
402
|
+
const res = await fetch(`${entry.base}/api/local/export`, { credentials: 'omit' })
|
|
403
|
+
if (!res.ok) throw new Error(String(res.status))
|
|
404
|
+
const body = await res.json()
|
|
405
|
+
const blob = new Blob([JSON.stringify(body, null, 2)], { type: 'application/json' })
|
|
406
|
+
const url = URL.createObjectURL(blob)
|
|
407
|
+
const a = document.createElement('a')
|
|
408
|
+
a.href = url
|
|
409
|
+
a.download = `offline-ddr0-works-${new Date().toISOString().slice(0, 10)}.json`
|
|
410
|
+
a.click()
|
|
411
|
+
URL.revokeObjectURL(url)
|
|
412
|
+
setLocalErr('')
|
|
413
|
+
} catch (error) {
|
|
414
|
+
setLocalErr(`导出失败:${error.message}`)
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async function importFile(file) {
|
|
419
|
+
if (!file) return
|
|
420
|
+
const text = await file.text()
|
|
421
|
+
const ext = (file.name.split('.').pop() || '').toLowerCase()
|
|
422
|
+
const payload = {
|
|
423
|
+
name: file.name.replace(/\.[^.]+$/, ''),
|
|
424
|
+
description: `浏览器导入 ${file.name}`,
|
|
425
|
+
}
|
|
426
|
+
if (ext === 'json') {
|
|
427
|
+
try {
|
|
428
|
+
Object.assign(payload, JSON.parse(text))
|
|
429
|
+
} catch {
|
|
430
|
+
payload.html = text
|
|
431
|
+
}
|
|
432
|
+
} else if (ext === 'js') {
|
|
433
|
+
payload.code = text
|
|
434
|
+
} else {
|
|
435
|
+
payload.html = text
|
|
436
|
+
}
|
|
437
|
+
try {
|
|
438
|
+
const res = await fetch(`${entry.base}/api/local/works`, {
|
|
439
|
+
method: 'POST',
|
|
440
|
+
credentials: 'omit',
|
|
441
|
+
headers: { 'content-type': 'application/json' },
|
|
442
|
+
body: JSON.stringify(payload),
|
|
443
|
+
})
|
|
444
|
+
const body = await res.json().catch(() => null)
|
|
445
|
+
if (!res.ok) throw new Error((body && body.detail) || String(res.status))
|
|
446
|
+
setLocalErr('')
|
|
447
|
+
} catch (error) {
|
|
448
|
+
setLocalErr(`导入失败:${error.message}`)
|
|
449
|
+
}
|
|
450
|
+
refreshLocal()
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const btnStyle = {
|
|
454
|
+
border: '1px solid var(--dsw-alias-border, rgba(128,128,128,.35))',
|
|
455
|
+
background: 'transparent',
|
|
456
|
+
color: 'inherit',
|
|
457
|
+
borderRadius: 6,
|
|
458
|
+
padding: '3px 10px',
|
|
459
|
+
fontSize: 12,
|
|
460
|
+
cursor: 'pointer',
|
|
461
|
+
}
|
|
462
|
+
return h(
|
|
463
|
+
'div',
|
|
464
|
+
{ style: { display: 'flex', flexDirection: 'column', width: '100%', height: '100%', position: 'relative' } },
|
|
465
|
+
h(
|
|
466
|
+
'div',
|
|
467
|
+
{
|
|
468
|
+
style: {
|
|
469
|
+
display: 'flex', alignItems: 'center', gap: 8, padding: '6px 10px',
|
|
470
|
+
borderBottom: '1px solid var(--dsw-alias-border, rgba(128,128,128,.25))',
|
|
471
|
+
fontSize: 12, color: 'var(--dsw-alias-label-secondary, #8a8f98)', flex: '0 0 auto',
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
h('button', {
|
|
475
|
+
type: 'button', style: btnStyle,
|
|
476
|
+
onClick: () => { setManageOpen(true); refreshLocal() },
|
|
477
|
+
}, `本地作品${Array.isArray(localItems) ? `(${localItems.length})` : ''}`),
|
|
478
|
+
h('button', { type: 'button', style: btnStyle, onClick: () => fileRef.current && fileRef.current.click() }, '导入'),
|
|
479
|
+
h('button', { type: 'button', style: btnStyle, onClick: exportLocal }, '导出备份'),
|
|
480
|
+
h('input', {
|
|
481
|
+
ref: fileRef, type: 'file', accept: '.html,.htm,.js,.json', style: { display: 'none' },
|
|
482
|
+
onChange: (ev) => {
|
|
483
|
+
const file = ev.target.files && ev.target.files[0]
|
|
484
|
+
ev.target.value = ''
|
|
485
|
+
importFile(file)
|
|
486
|
+
},
|
|
487
|
+
}),
|
|
488
|
+
h('span', { style: { marginLeft: 'auto' } }, '离线可用 · 无需登录'),
|
|
489
|
+
),
|
|
490
|
+
h('iframe', {
|
|
491
|
+
ref: frameRef,
|
|
492
|
+
src: `${entry.base}/`,
|
|
493
|
+
title: LABEL,
|
|
494
|
+
allow: 'fullscreen',
|
|
495
|
+
onLoad: () => {
|
|
496
|
+
const frame = frameRef.current
|
|
497
|
+
paintFrame(frame, store.get())
|
|
498
|
+
refreshSync(frame)
|
|
499
|
+
},
|
|
500
|
+
style: { flex: 1, minHeight: 0, width: '100%', border: '0', display: 'block', background: 'transparent' },
|
|
501
|
+
}),
|
|
502
|
+
manageOpen
|
|
503
|
+
? h(
|
|
504
|
+
'div',
|
|
505
|
+
{
|
|
506
|
+
style: {
|
|
507
|
+
position: 'absolute', inset: 0, background: 'rgba(0,0,0,.35)',
|
|
508
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center', zIndex: 50,
|
|
509
|
+
},
|
|
510
|
+
onClick: (ev) => { if (ev.target === ev.currentTarget) setManageOpen(false) },
|
|
511
|
+
},
|
|
512
|
+
h(
|
|
513
|
+
'div',
|
|
514
|
+
{
|
|
515
|
+
style: {
|
|
516
|
+
width: 'min(680px, 92%)', maxHeight: '80%', overflow: 'auto',
|
|
517
|
+
background: 'var(--dsw-alias-bg-primary, #fff)', color: 'var(--dsw-alias-label-primary, #222)',
|
|
518
|
+
borderRadius: 12, padding: 16, boxShadow: '0 12px 40px rgba(0,0,0,.25)',
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
h(
|
|
522
|
+
'div',
|
|
523
|
+
{ style: { display: 'flex', alignItems: 'center', marginBottom: 10 } },
|
|
524
|
+
h('strong', null, '本地作品库'),
|
|
525
|
+
h('span', { style: { marginLeft: 8, fontSize: 11, opacity: .65 } }, '其它会话:inbox 丢文件 或 POST /api/local/works'),
|
|
526
|
+
h('button', { type: 'button', style: { ...btnStyle, marginLeft: 'auto' }, onClick: () => setManageOpen(false) }, '关闭'),
|
|
527
|
+
),
|
|
528
|
+
localErr ? h('div', { style: { color: '#c0392b', fontSize: 12, marginBottom: 8 } }, localErr) : null,
|
|
529
|
+
localItems === null
|
|
530
|
+
? h('div', { style: { fontSize: 12, opacity: .7 } }, '加载中…')
|
|
531
|
+
: localItems.length === 0
|
|
532
|
+
? h('div', { style: { fontSize: 12, opacity: .7 } }, '还没有本地作品。点右上「导入」,或让其它会话往 inbox 目录丢文件。')
|
|
533
|
+
: h(
|
|
534
|
+
'div',
|
|
535
|
+
null,
|
|
536
|
+
localItems.map((item) => h(
|
|
537
|
+
'div',
|
|
538
|
+
{
|
|
539
|
+
key: item.id,
|
|
540
|
+
style: {
|
|
541
|
+
display: 'flex', alignItems: 'center', padding: '8px 4px',
|
|
542
|
+
borderBottom: '1px solid var(--dsw-alias-border, rgba(128,128,128,.15))', fontSize: 13,
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
h('span', null, `${item.emoji || '📦'} ${item.name}`),
|
|
546
|
+
h('span', { style: { opacity: .6, fontSize: 11, marginLeft: 8 } }, item.ref),
|
|
547
|
+
item.local_kind === 'session'
|
|
548
|
+
? h('span', { style: { fontSize: 10, marginLeft: 8, padding: '1px 6px', borderRadius: 8, background: 'rgba(59,130,246,.15)', color: '#3b82f6' } }, '会话')
|
|
549
|
+
: null,
|
|
550
|
+
h('span', { style: { opacity: .5, fontSize: 10, marginLeft: 6 } }, `v${item.latest_version || 1}`),
|
|
551
|
+
h(
|
|
552
|
+
'span',
|
|
553
|
+
{ style: { marginLeft: 'auto', display: 'flex', gap: 6 } },
|
|
554
|
+
h('button', { type: 'button', style: btnStyle, onClick: () => openLocal(item.id) }, '打开'),
|
|
555
|
+
h('button', { type: 'button', style: { ...btnStyle, color: '#c0392b' }, onClick: () => deleteLocal(item.id) }, '删除'),
|
|
556
|
+
),
|
|
557
|
+
)),
|
|
558
|
+
),
|
|
559
|
+
),
|
|
560
|
+
)
|
|
561
|
+
: null,
|
|
562
|
+
)
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function apply(ctx) {
|
|
567
|
+
const store = createThemeStore(ctx)
|
|
568
|
+
try {
|
|
569
|
+
// Cordis effect:插件卸载/禁用时退订主题事件。
|
|
570
|
+
ctx.effect(() => () => store.dispose())
|
|
571
|
+
} catch (error) {
|
|
572
|
+
console.error('[offline-ddr0] 注册主题清理失败', error)
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const SitePanel = createPanel(store)
|
|
576
|
+
|
|
577
|
+
ctx.slots.inject('sidebar.panellist', () => {
|
|
578
|
+
try {
|
|
579
|
+
return ctx.slots.register(
|
|
580
|
+
{ name: 'sidebar.panellist', id: PANEL, order: 8, label: () => LABEL },
|
|
581
|
+
SiteIcon,
|
|
582
|
+
)
|
|
583
|
+
} catch (error) {
|
|
584
|
+
console.error('[offline-ddr0] 侧栏入口注册失败', error)
|
|
585
|
+
return () => {}
|
|
586
|
+
}
|
|
587
|
+
})
|
|
588
|
+
ctx.slots.inject('main', () => {
|
|
589
|
+
try {
|
|
590
|
+
return ctx.slots.register({ name: 'main', key: PANEL }, SitePanel)
|
|
591
|
+
} catch (error) {
|
|
592
|
+
console.error('[offline-ddr0] 主区域注册失败', error)
|
|
593
|
+
return () => {}
|
|
594
|
+
}
|
|
595
|
+
})
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
exports.name = 'offline-ddr0'
|
|
599
|
+
exports.inject = ['slots']
|
|
600
|
+
exports.apply = apply
|
|
601
|
+
return module.exports
|
|
602
|
+
},
|
|
603
|
+
})
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# offline-ddr0 bundle patch:把 port-8223 的离线版 ddr0 挂到共享宿主的 /offline-ddr0。
|
|
2
|
+
#
|
|
3
|
+
# foundation ABI 迁移后不再自己 createServer/listen:
|
|
4
|
+
# - service-host 提供 os.net 共享宿主;
|
|
5
|
+
# - foundation 提供 ctx.os;
|
|
6
|
+
# - 本插件用 http-router 托管 static/index.html(单文件前端,SUB 已改写为 /offline-ddr0),
|
|
7
|
+
# /api/*、/config.json、/media/* 反代到离线镜像后端,并在回程把 config.json 的
|
|
8
|
+
# apiBaseUrl 改写成本挂载点。
|
|
9
|
+
#
|
|
10
|
+
# 可选配置:backendUrl(DSH_OFFLINE_DDR0_BACKEND_URL,默认 https://ddr0.com/apps/works/3904)。
|
|
11
|
+
- insert:
|
|
12
|
+
- id: offline-ddr0
|
|
13
|
+
name: "@capyclaw/offline-ddr0"
|