dsh-opencode-palette 1.6.3 → 1.6.4

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/lib/client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * dsh-opencode-palette v1.6.3 — 浏览器半(构建产物,勿手改)
2
+ * dsh-opencode-palette v1.6.4 — 浏览器半(构建产物,勿手改)
3
3
  * 数据驱动管线:opencode v1.18.12 官方主题 JSON → 颜色解析 → DSH 适配注入
4
4
  * 源:src/engine/* + runtime/client.mjs(npm run build 重新生成)
5
5
  */
@@ -8027,7 +8027,7 @@ function saveState(state) {
8027
8027
  if (globalThis.localStorage) localStorage.setItem(STORAGE_KEY, JSON.stringify(state))
8028
8028
  } catch (e) { /* 忽略持久化失败 */ }
8029
8029
  }
8030
- // ── i18n:面板文案双语表(跟随 DSH 界面语言,html[lang] 为信号源)──
8030
+ // ── i18n:面板文案双语表(跟随 DSH 界面语言,官方 locale 服务为信号源)──
8031
8031
  const I18N = {
8032
8032
  panelName: { zh: 'opencode调色板', en: 'Opencode Palette' },
8033
8033
  subtitle: { zh: '34 款 opencode 官方配色主题,点击即切换', en: '34 official opencode themes — click to switch' },
@@ -8058,7 +8058,7 @@ const I18N = {
8058
8058
  'group.special': { zh: '特殊', en: 'Special' },
8059
8059
  }
8060
8060
 
8061
- // 语言检测:html[lang] 优先,回退浏览器语言
8061
+ // 语言检测(回退):html[lang] 优先,回退浏览器语言
8062
8062
  function getLang() {
8063
8063
  try {
8064
8064
  const l = (document.documentElement && document.documentElement.lang) || (navigator.language || 'en')
@@ -8066,6 +8066,18 @@ function getLang() {
8066
8066
  } catch (e) { return 'en' }
8067
8067
  }
8068
8068
 
8069
+ // 把 key → {zh,en} 表转成 locale 服务注册形态 {zh: {...}, en: {...}}
8070
+ function toLocaleDicts(i18n) {
8071
+ const zh = {}
8072
+ const en = {}
8073
+ for (const key in i18n) {
8074
+ const pair = i18n[key]
8075
+ zh[key] = pair.zh
8076
+ en[key] = pair.en
8077
+ }
8078
+ return { zh, en }
8079
+ }
8080
+
8069
8081
 
8070
8082
  // 生成注入物并注入:token 层 + <style> 层;幂等(先清后注入)
8071
8083
  function createClient(slotTarget) {
@@ -8077,21 +8089,36 @@ function createClient(slotTarget) {
8077
8089
  let tokenDispose = null
8078
8090
  let styleTag = null
8079
8091
 
8080
- // ── i18n 运行时:语言跟随 DSH(html[lang] 变化即通知面板重渲染)──
8081
- let currentLang = getLang()
8092
+ // ── i18n 运行时:语言跟随 DSH(官方 locale 服务为信号源,html[lang] 仅作回退)──
8093
+ const localeSvc = ctx.get('locale') || ctx.locale || null
8094
+ const LOCALE_NS = 'opencode-palette'
8095
+ let dictDispose = null
8096
+ let localeUnsub = null
8097
+ let currentLang = localeSvc ? localeSvc.getLocale().active : getLang()
8082
8098
  const localeListeners = []
8083
- function tr(key) { const e = I18N[key]; return e ? e[currentLang] : key }
8099
+ function currentLocale() { return localeSvc ? localeSvc.getLocale().active : getLang() }
8100
+ function tr(key) {
8101
+ const entry = I18N[key]
8102
+ return entry ? (entry[currentLang] !== undefined ? entry[currentLang] : key) : key
8103
+ }
8084
8104
  function notifyLocale() {
8085
- const next = getLang()
8105
+ const next = currentLocale()
8086
8106
  if (next === currentLang) return
8087
8107
  currentLang = next
8088
8108
  for (const fn of localeListeners) { try { fn() } catch (e) { /* 忽略 */ } }
8089
8109
  }
8110
+ // 监听语言变化:官方 locale 服务优先;无该服务的环境(如旧版 DSH/测试沙箱)回退监听 html[lang]
8090
8111
  let localeObserver = null
8091
- if (typeof MutationObserver !== 'undefined' && typeof document !== 'undefined' && document.documentElement) {
8112
+ if (localeSvc && typeof localeSvc.subscribe === 'function') {
8113
+ localeUnsub = localeSvc.subscribe(notifyLocale)
8114
+ } else if (typeof MutationObserver !== 'undefined' && typeof document !== 'undefined' && document.documentElement) {
8092
8115
  localeObserver = new MutationObserver(notifyLocale)
8093
8116
  localeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['lang'] })
8094
8117
  }
8118
+ // 把面板双语表注册进 locale 服务:标题/文案随 DSH 语言实时切换(disposer 交给清理器)
8119
+ if (localeSvc && typeof localeSvc.register === 'function') {
8120
+ try { dictDispose = localeSvc.register(LOCALE_NS, toLocaleDicts(I18N)) } catch (e) { /* 忽略 */ }
8121
+ }
8095
8122
 
8096
8123
  function safeThemeName(name) {
8097
8124
  const names = themeNames()
@@ -8435,6 +8462,8 @@ function createClient(slotTarget) {
8435
8462
  try { if (disposePanel) disposePanel() } catch (e) { /* 忽略 */ }
8436
8463
  try { if (disposeSection) disposeSection() } catch (e) { /* 忽略 */ }
8437
8464
  try { if (globalThis.__opencodePalette) delete globalThis.__opencodePalette } catch (e) { /* 忽略 */ }
8465
+ try { if (dictDispose) dictDispose() } catch (e) { /* 忽略 */ }
8466
+ try { if (localeUnsub) localeUnsub() } catch (e) { /* 忽略 */ }
8438
8467
  try { if (localeObserver) localeObserver.disconnect() } catch (e) { /* 忽略 */ }
8439
8468
  }
8440
8469
  }, 'dsh-opencode-palette: styles')
@@ -8443,7 +8472,7 @@ function createClient(slotTarget) {
8443
8472
 
8444
8473
  __mods["client"] = { createClient }
8445
8474
  })();
8446
- exports.inject = ["theme","slots"]
8475
+ exports.inject = ["theme","slots","locale"]
8447
8476
  exports.apply = __mods["client"].createClient("settings.plugins.tab")
8448
8477
  return module.exports
8449
8478
  },
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * dsh-opencode-palette v1.6.3 — 宿主半(no-op)
2
+ * dsh-opencode-palette v1.6.4 — 宿主半(no-op)
3
3
  *
4
4
  * 主题的全部工作在浏览器端(./client.js)完成:
5
5
  * - 34 个 opencode 主题(33 内置 JSON + system)经数据驱动管线解析
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-opencode-palette",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "让 DeepSeek Harness 穿上 34 款经典皮肤——东京的霓虹夜色、德古拉的暗红月光、复古工坊的暖黄灯火、黑客帝国的数字雨、玫瑰松林间的风……一键换肤,即点即换,重启不丢。34 legendary skins for DeepSeek Harness — tokyonight's neon dusk, dracula's crimson moon, gruvbox's retro glow, the matrix's digital rain, rose-pine's rosewood calm… one click, instant, persisted.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",