@dsh-plugin/dsh-ui-experience 1.0.0-dev.43488936935 → 1.0.0-dev.43490289639

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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/lib/client.js +25 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -160,12 +160,12 @@ M3 那侧的分离要说明白:Material 3 的 `emphasized` 整体是两段首
160
160
  - `跟随系统`(默认):系统开启「减弱动态效果」时,全部时长压到 1ms、动画只跑一轮。
161
161
  - `始终减弱动效`:无论系统设置,一律压制。
162
162
 
163
- 这一条是整层里唯一使用 `!important` 的地方——它要压掉本层从未写过的声明,逐条改写做不到。压制期间不再改写曲线,因为没有可观察的时长。
163
+ 这一条是整层里唯一使用 `!important` 的地方——它要压掉本层从未写过的声明,逐条改写做不到。进入压制时会先撤掉已改写的曲线并停掉观察者:时长已被压到 1ms,改写既看不见,还会在压制表插入时被自己的观察者重新触发一次扫描。
164
164
 
165
165
  ### 生效范围
166
166
 
167
- - 覆盖页面上的全部样式表,包括其他插件注入的。首次应用时全量扫描,之后用 `MutationObserver` 监视 `head` 与 `body`,新注入的 `<style>` 在下一个微任务内被补上。
168
- - 通过 `document.adoptedStyleSheets` 挂载的构造式样式表不是 DOM 变更,只在首次应用与下一次 `apply` 时被读取。
167
+ - 覆盖页面上的全部样式表,包括其他插件注入的。首次应用时全量扫描,之后用 `MutationObserver` 监视 `head` 与 `body`;只有当新增节点本身是 `<style>` / `<link>`,或子树里含有时才补扫——聊天流式输出每帧都在改 DOM,无条件补扫会把一次性开销变成每帧开销。
168
+ - 通过 `document.adoptedStyleSheets` 挂载的构造式样式表不是 DOM 变更,观察者看不到它,只能在下一次全量扫描(切换曲线族、解除减弱动效、重新应用设置)时被读到。
169
169
  - 跨源样式表读不到 `cssRules`,会在浏览器控制台记录一行并跳过——这类表的规则无法改写,静默跳过会让部分界面停留在原生曲线而无迹可循。(这条诊断走控制台而非 `~/.dsh/ui-experience.log`:后者由宿主半写入,浏览器半够不到文件系统。)
170
170
  - 状态会写在 `<html data-dsh-uix-motion="m3|m3e">` 上,便于区分曲线来源。
171
171
 
package/lib/client.js CHANGED
@@ -195,7 +195,6 @@
195
195
  ];
196
196
  function createMotion() {
197
197
  const patches = /* @__PURE__ */ new Map();
198
- const durationBase = /* @__PURE__ */ new Map();
199
198
  const unreadable = /* @__PURE__ */ new Set();
200
199
  const media = window.matchMedia("(prefers-reduced-motion: reduce)");
201
200
  let settings;
@@ -318,14 +317,10 @@
318
317
  const root = document.documentElement;
319
318
  const computed = window.getComputedStyle(root);
320
319
  for (const token of DURATION_TOKENS) {
321
- let base = durationBase.get(token);
320
+ const base = parseDurationMs(computed.getPropertyValue(token).trim());
322
321
  if (base === void 0) {
323
- base = parseDurationMs(computed.getPropertyValue(token).trim());
324
- if (base === void 0) {
325
- console.error(`ui-experience: motion cannot read ${token}; durations using it keep their shipped value`);
326
- continue;
327
- }
328
- durationBase.set(token, base);
322
+ console.error(`ui-experience: motion cannot read ${token}; durations using it keep their shipped value`);
323
+ continue;
329
324
  }
330
325
  root.style.setProperty(token, `${Math.round(base * active.durationScale)}ms`);
331
326
  }
@@ -353,13 +348,15 @@
353
348
  function realize() {
354
349
  const active = settings;
355
350
  if (active === void 0 || active.mode === "off") return;
356
- const want = wantsReduced();
357
- setReducedSheet(want);
358
- if (want) {
351
+ if (wantsReduced()) {
352
+ observer?.disconnect();
353
+ observer = void 0;
354
+ setReducedSheet(true);
359
355
  restoreDeclarations();
360
356
  clearDurationTokens();
361
357
  return;
362
358
  }
359
+ setReducedSheet(false);
363
360
  applyDurationTokens();
364
361
  scan();
365
362
  observer ??= observeDocument();
@@ -372,9 +369,22 @@
372
369
  scan();
373
370
  });
374
371
  }
372
+ function bringsStylesheet(node) {
373
+ if (node === void 0) return false;
374
+ const name = node.nodeName?.toUpperCase();
375
+ if (name === "STYLE" || name === "LINK") return true;
376
+ return (node.querySelectorAll?.("style,link")?.length ?? 0) > 0;
377
+ }
375
378
  function observeDocument() {
376
- const instance = new MutationObserver(() => {
377
- refresh();
379
+ const instance = new MutationObserver((records) => {
380
+ for (const record of records) {
381
+ for (let index = 0; index < record.addedNodes.length; index += 1) {
382
+ if (bringsStylesheet(record.addedNodes[index])) {
383
+ refresh();
384
+ return;
385
+ }
386
+ }
387
+ }
378
388
  });
379
389
  instance.observe(document.head, { childList: true, subtree: true });
380
390
  instance.observe(document.body, { childList: true, subtree: true });
@@ -540,9 +550,9 @@
540
550
  report(media.matches);
541
551
  };
542
552
  report(media.matches);
543
- media.addEventListener?.("change", listener);
553
+ media.addEventListener("change", listener);
544
554
  return () => {
545
- media.removeEventListener?.("change", listener);
555
+ media.removeEventListener("change", listener);
546
556
  };
547
557
  }
548
558
  var SOURCE = "@dsh-plugin/dsh-ui-experience";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-plugin/dsh-ui-experience",
3
- "version": "1.0.0-dev.43488936935",
3
+ "version": "1.0.0-dev.43490289639",
4
4
  "type": "module",
5
5
  "description": "UI experience enhancements for DeepSeek Harness: follow the system matugen Material You palette as the interface theme, and rewrite interface motion onto Material 3 / Material 3 Expressive curves.",
6
6
  "license": "MIT",