@manohub/ui 1.2.11 → 1.2.13

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 CHANGED
@@ -140,8 +140,8 @@ try { await save() } finally { loading.close() } // 句柄与 toast() 同形状
140
140
  ## 主题层
141
141
 
142
142
  全局令牌(`--ui-primary` / `--ui-space-*` / `--ui-font-*` 这类跨件共用的值)**不在本包**,已拆成独立包
143
- **`@manohub/theme`**(值层与面层分开:值随主题变、面不随主题变)。每个主题分五片:
144
- `colors` / `typography` / `spacing` / `radius` / `shadows`,一律锚定 **`[data-manohub-ui]`**
143
+ **`@manohub/theme`**(值层与面层分开:值随主题变、面不随主题变)。每个主题分六片:
144
+ `colors` / `typography` / `spacing` / `radius` / `shadows` / `motion`,一律锚定 **`[data-manohub-ui]`**
145
145
  (库品牌作用域锚;micro-app 的 scopecss 不作用域化 `:root`,定义在 `:root` 会泄漏到宿主)。
146
146
 
147
147
  只服务单一组件的令牌分两半落在本包:
@@ -47,6 +47,14 @@ export declare const Notification: import("vue").DefineComponent<import("vue").E
47
47
  type: BooleanConstructor;
48
48
  default: boolean;
49
49
  };
50
+ /**
51
+ * 正在退场:置位即加 `.mh-notification--leaving`(退场动画),**不自己移除 DOM** ——
52
+ * 播完由存在性持有方移除(可见性仍归调用方)。与 `Toast` 的 `leaving` 同口径。
53
+ */
54
+ leaving: {
55
+ type: BooleanConstructor;
56
+ default: boolean;
57
+ };
50
58
  /** 自动关闭毫秒数(`0` = 不自动;到点**只回调** `onClose`,不移除自己) */
51
59
  duration: {
52
60
  type: NumberConstructor;
@@ -82,6 +90,14 @@ export declare const Notification: import("vue").DefineComponent<import("vue").E
82
90
  type: BooleanConstructor;
83
91
  default: boolean;
84
92
  };
93
+ /**
94
+ * 正在退场:置位即加 `.mh-notification--leaving`(退场动画),**不自己移除 DOM** ——
95
+ * 播完由存在性持有方移除(可见性仍归调用方)。与 `Toast` 的 `leaving` 同口径。
96
+ */
97
+ leaving: {
98
+ type: BooleanConstructor;
99
+ default: boolean;
100
+ };
85
101
  /** 自动关闭毫秒数(`0` = 不自动;到点**只回调** `onClose`,不移除自己) */
86
102
  duration: {
87
103
  type: NumberConstructor;
@@ -99,6 +115,7 @@ export declare const Notification: import("vue").DefineComponent<import("vue").E
99
115
  closable: boolean;
100
116
  tone: NotificationTone;
101
117
  avatar: string;
118
+ leaving: boolean;
102
119
  duration: number;
103
120
  }, SlotsType<{
104
121
  default?: () => VNodeChild;
@@ -35,6 +35,14 @@ const Notification = /* @__PURE__ */ defineComponent({
35
35
  type: Boolean,
36
36
  default: false
37
37
  },
38
+ /**
39
+ * 正在退场:置位即加 `.mh-notification--leaving`(退场动画),**不自己移除 DOM** ——
40
+ * 播完由存在性持有方移除(可见性仍归调用方)。与 `Toast` 的 `leaving` 同口径。
41
+ */
42
+ leaving: {
43
+ type: Boolean,
44
+ default: false
45
+ },
38
46
  /** 自动关闭毫秒数(`0` = 不自动;到点**只回调** `onClose`,不移除自己) */
39
47
  duration: {
40
48
  type: Number,
@@ -62,7 +70,7 @@ const Notification = /* @__PURE__ */ defineComponent({
62
70
  const hasTitleRow = Boolean(slots.title || props.title || props.closable);
63
71
  const iconName = props.icon === true ? TONE_ICON[props.tone] : typeof props.icon === "string" ? props.icon : void 0;
64
72
  return createVNode("div", {
65
- "class": ["mh-notification", `mh-notification--${props.tone}`, attrs.class].filter(Boolean).join(" "),
73
+ "class": ["mh-notification", `mh-notification--${props.tone}`, props.leaving ? "mh-notification--leaving" : "", attrs.class].filter(Boolean).join(" "),
66
74
  "style": attrs.style
67
75
  }, [slots.avatar ? slots.avatar() : props.avatar ? createVNode("span", {
68
76
  "class": "mh-notification__avatar"
@@ -45,6 +45,15 @@ export declare const Toast: import("vue").DefineComponent<import("vue").ExtractP
45
45
  type: BooleanConstructor;
46
46
  default: boolean;
47
47
  };
48
+ /**
49
+ * 正在退场:置位即加 `.mh-toast--leaving`(退场动画),**不自己移除 DOM** ——
50
+ * 播完由存在性持有方(命令式服务 / 自管列表的调用方)移除。组件内计时到点只发 `close`,
51
+ * 不经这一档(那一档由服务置位)。
52
+ */
53
+ leaving: {
54
+ type: BooleanConstructor;
55
+ default: boolean;
56
+ };
48
57
  onAction: {
49
58
  type: PropType<() => void>;
50
59
  default: undefined;
@@ -82,6 +91,15 @@ export declare const Toast: import("vue").DefineComponent<import("vue").ExtractP
82
91
  type: BooleanConstructor;
83
92
  default: boolean;
84
93
  };
94
+ /**
95
+ * 正在退场:置位即加 `.mh-toast--leaving`(退场动画),**不自己移除 DOM** ——
96
+ * 播完由存在性持有方(命令式服务 / 自管列表的调用方)移除。组件内计时到点只发 `close`,
97
+ * 不经这一档(那一档由服务置位)。
98
+ */
99
+ leaving: {
100
+ type: BooleanConstructor;
101
+ default: boolean;
102
+ };
85
103
  onAction: {
86
104
  type: PropType<() => void>;
87
105
  default: undefined;
@@ -95,6 +113,7 @@ export declare const Toast: import("vue").DefineComponent<import("vue").ExtractP
95
113
  tone: ToastTone;
96
114
  action: string;
97
115
  onAction: () => void;
116
+ leaving: boolean;
98
117
  duration: number;
99
118
  }, SlotsType<{
100
119
  default?: () => VNodeChild;
@@ -131,6 +150,15 @@ export declare const ToastCompound: {
131
150
  type: BooleanConstructor;
132
151
  default: boolean;
133
152
  };
153
+ /**
154
+ * 正在退场:置位即加 `.mh-toast--leaving`(退场动画),**不自己移除 DOM** ——
155
+ * 播完由存在性持有方(命令式服务 / 自管列表的调用方)移除。组件内计时到点只发 `close`,
156
+ * 不经这一档(那一档由服务置位)。
157
+ */
158
+ leaving: {
159
+ type: BooleanConstructor;
160
+ default: boolean;
161
+ };
134
162
  onAction: {
135
163
  type: PropType<() => void>;
136
164
  default: undefined;
@@ -147,6 +175,7 @@ export declare const ToastCompound: {
147
175
  tone: ToastTone;
148
176
  action: string;
149
177
  onAction: () => void;
178
+ leaving: boolean;
150
179
  duration: number;
151
180
  }, true, {}, SlotsType<{
152
181
  default?: () => VNodeChild;
@@ -188,6 +217,15 @@ export declare const ToastCompound: {
188
217
  type: BooleanConstructor;
189
218
  default: boolean;
190
219
  };
220
+ /**
221
+ * 正在退场:置位即加 `.mh-toast--leaving`(退场动画),**不自己移除 DOM** ——
222
+ * 播完由存在性持有方(命令式服务 / 自管列表的调用方)移除。组件内计时到点只发 `close`,
223
+ * 不经这一档(那一档由服务置位)。
224
+ */
225
+ leaving: {
226
+ type: BooleanConstructor;
227
+ default: boolean;
228
+ };
191
229
  onAction: {
192
230
  type: PropType<() => void>;
193
231
  default: undefined;
@@ -201,6 +239,7 @@ export declare const ToastCompound: {
201
239
  tone: ToastTone;
202
240
  action: string;
203
241
  onAction: () => void;
242
+ leaving: boolean;
204
243
  duration: number;
205
244
  }>;
206
245
  __isFragment?: never;
@@ -236,6 +275,15 @@ export declare const ToastCompound: {
236
275
  type: BooleanConstructor;
237
276
  default: boolean;
238
277
  };
278
+ /**
279
+ * 正在退场:置位即加 `.mh-toast--leaving`(退场动画),**不自己移除 DOM** ——
280
+ * 播完由存在性持有方(命令式服务 / 自管列表的调用方)移除。组件内计时到点只发 `close`,
281
+ * 不经这一档(那一档由服务置位)。
282
+ */
283
+ leaving: {
284
+ type: BooleanConstructor;
285
+ default: boolean;
286
+ };
239
287
  onAction: {
240
288
  type: PropType<() => void>;
241
289
  default: undefined;
@@ -252,6 +300,7 @@ export declare const ToastCompound: {
252
300
  tone: ToastTone;
253
301
  action: string;
254
302
  onAction: () => void;
303
+ leaving: boolean;
255
304
  duration: number;
256
305
  }, {}, string, SlotsType<{
257
306
  default?: () => VNodeChild;
@@ -40,6 +40,15 @@ const Toast = /* @__PURE__ */ defineComponent({
40
40
  type: Boolean,
41
41
  default: false
42
42
  },
43
+ /**
44
+ * 正在退场:置位即加 `.mh-toast--leaving`(退场动画),**不自己移除 DOM** ——
45
+ * 播完由存在性持有方(命令式服务 / 自管列表的调用方)移除。组件内计时到点只发 `close`,
46
+ * 不经这一档(那一档由服务置位)。
47
+ */
48
+ leaving: {
49
+ type: Boolean,
50
+ default: false
51
+ },
43
52
  onAction: {
44
53
  type: Function,
45
54
  default: void 0
@@ -75,6 +84,7 @@ const Toast = /* @__PURE__ */ defineComponent({
75
84
  消费方按「组件名 → 类名」的直觉拼 `.mh-toast--success` 会落空(缺陷 §3.5)。 */
76
85
  `mh-toast--${props.tone}`,
77
86
  hasAction ? "mh-toast--action" : "",
87
+ props.leaving ? "mh-toast--leaving" : "",
78
88
  attrs.class
79
89
  ].filter(Boolean).join(" "),
80
90
  "style": attrs.style,
@@ -116,6 +126,8 @@ const ToastStack = /* @__PURE__ */ defineComponent({
116
126
  if (!el) return;
117
127
  if (!el.hasAttribute("popover")) el.setAttribute("popover", "manual");
118
128
  if (typeof el.showPopover !== "function") return;
129
+ const modalOpen = typeof document !== "undefined" && document.querySelector("dialog[open]") !== null;
130
+ if (!modalOpen && el.matches(":popover-open")) return;
119
131
  try {
120
132
  if (el.matches(":popover-open")) el.hidePopover();
121
133
  el.showPopover();
@@ -2,6 +2,7 @@ import { ref, createApp, defineComponent, nextTick, h } from "vue";
2
2
  import { Button } from "../components/button/index.js";
3
3
  import { Dialog } from "../components/dialog/index.js";
4
4
  import { createHostContainer, onHostReset } from "./base.js";
5
+ import { waitForExit } from "./motion.js";
5
6
  const pending = /* @__PURE__ */ new Set();
6
7
  function openDialog(render) {
7
8
  return new Promise((resolve) => {
@@ -16,9 +17,14 @@ function openDialog(render) {
16
17
  open.value = false;
17
18
  resolve(value);
18
19
  void nextTick(() => {
19
- app?.unmount();
20
- app = null;
21
- container.remove();
20
+ const cleanup = () => {
21
+ app?.unmount();
22
+ app = null;
23
+ container.remove();
24
+ };
25
+ const wait = waitForExit(container.querySelector("dialog"), "transition");
26
+ if (wait) void wait.then(cleanup);
27
+ else cleanup();
22
28
  });
23
29
  };
24
30
  const ctx = { isOpen: () => open.value, finish };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 服务层 · 退场等待(命令式弹窗与提示共用)。
3
+ *
4
+ * ## 为什么需要它
5
+ * 本包的浮层把「收起」做成了**有时长的**(对话框的 `display` / `overlay` 走 `allow-discrete`,
6
+ * 提示条目的存在性归服务层)—— 收场后立刻卸载节点会把退场截断,用户看到的仍是「瞬间消失」。
7
+ * 故服务要等动效播完再摘节点,但**不能写死毫秒数**:0.2s / 0.16s 归各自的组件面文件,
8
+ * JS 再抄一份必然漂。这里读**计算样式**里的时长,无样式环境(单元测试 / 未注入 CSS)读到 0
9
+ * ⇒ 立刻收尾,既有语义与用例不受影响。
10
+ */
11
+ /**
12
+ * 读一枚时长令牌的毫秒数(支持 `180ms` / `0.18s`;无样式环境读到空串 ⇒ 0)。
13
+ *
14
+ * 与 `waitForExit` 的分工:那个读**已经生效**的 transition / animation 时长;这个读设计令牌,
15
+ * 给「没有 CSS 动效、但要用同一档时长跑 WAAPI」的场景(如提示堆叠的回位)。
16
+ */
17
+ export declare function readDurationToken(el: Element, token: string): number;
18
+ /**
19
+ * 等元素自身的退场动效播完。
20
+ *
21
+ * **没有可等的时长时返回 `undefined`(而不是一个已 resolve 的 Promise)**:调用方要在同一个
22
+ * 微任务里直接收尾,不能多插一帧 —— 否则无样式环境(单测)的「立即移除」会晚一个 tick,
23
+ * 既有用例与会话里的收尾时序都会被改写。
24
+ *
25
+ * @param el 承载动效的元素(面板 / 提示条目)
26
+ * @param kind `transition` 给原生 `<dialog>`(面板与遮罩的 `allow-discrete` 过渡);
27
+ * `animation` 给自管存在性的条目(`Toast` 的退场动画)
28
+ */
29
+ export declare function waitForExit(el: Element | null, kind: 'transition' | 'animation'): Promise<void> | undefined;
@@ -0,0 +1,32 @@
1
+ function readDurationToken(el, token) {
2
+ const raw = getComputedStyle(el).getPropertyValue(token).trim();
3
+ const value = Number.parseFloat(raw);
4
+ if (!Number.isFinite(value)) return 0;
5
+ return raw.endsWith("ms") ? value : value * 1e3;
6
+ }
7
+ function waitForExit(el, kind) {
8
+ if (!el) return void 0;
9
+ const target = el;
10
+ const style = getComputedStyle(target);
11
+ const durations = (kind === "transition" ? style.transitionDuration : style.animationDuration).split(",").map((part) => Number.parseFloat(part)).filter((value) => Number.isFinite(value));
12
+ const ms = durations.reduce((max, value) => Math.max(max, value), 0) * 1e3;
13
+ if (ms <= 0) return void 0;
14
+ return new Promise((resolve) => {
15
+ let timer;
16
+ const endEvent = kind === "transition" ? "transitionend" : "animationend";
17
+ function done() {
18
+ target.removeEventListener(endEvent, onEnd);
19
+ if (timer) clearTimeout(timer);
20
+ resolve();
21
+ }
22
+ function onEnd(event) {
23
+ if (event.target === target) done();
24
+ }
25
+ target.addEventListener(endEvent, onEnd);
26
+ timer = setTimeout(done, ms + 50);
27
+ });
28
+ }
29
+ export {
30
+ readDurationToken,
31
+ waitForExit
32
+ };
@@ -1,6 +1,7 @@
1
- import { reactive, createApp, defineComponent, h } from "vue";
1
+ import { reactive, createApp, nextTick, defineComponent, h } from "vue";
2
2
  import { ToastCompound, Toast } from "../components/toast/index.js";
3
3
  import { createHostContainer, onHostReset } from "./base.js";
4
+ import { waitForExit, readDurationToken } from "./motion.js";
4
5
  const DEFAULT_DURATION = 3e3;
5
6
  const MAX_VISIBLE = 5;
6
7
  const items = reactive([]);
@@ -18,6 +19,7 @@ const ToastServiceView = defineComponent({
18
19
  text: item.text,
19
20
  duration: item.duration,
20
21
  closable: item.closable,
22
+ leaving: item.leaving,
21
23
  action: item.action?.text,
22
24
  onAction: () => item.action?.onClick(),
23
25
  onClose: () => remove(item.id)
@@ -38,15 +40,63 @@ function disposeApp() {
38
40
  container?.remove();
39
41
  container = null;
40
42
  }
41
- function remove(id) {
42
- const index = items.findIndex((item) => item.id === id);
43
- if (index >= 0) items.splice(index, 1);
44
- if (!items.length) {
45
- void Promise.resolve().then(() => {
46
- if (!items.length) disposeApp();
47
- });
43
+ function disposeWhenEmpty() {
44
+ if (!items.length) disposeApp();
45
+ }
46
+ const MOVE_ANIMATION_ID = "mh-toast-move";
47
+ function visibleToastEls() {
48
+ if (!container) return [];
49
+ return [...container.querySelectorAll(".mh-toast")].filter(
50
+ (el) => !el.classList.contains("mh-toast--leaving")
51
+ );
52
+ }
53
+ function cancelMoves(els) {
54
+ for (const el of els) {
55
+ if (typeof el.getAnimations !== "function") continue;
56
+ for (const animation of el.getAnimations()) {
57
+ if (animation.id === MOVE_ANIMATION_ID) animation.cancel();
58
+ }
48
59
  }
49
60
  }
61
+ function playMoves(els, before) {
62
+ if (!els.length || typeof window === "undefined") return;
63
+ const reduce = typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
64
+ if (reduce) return;
65
+ const duration = readDurationToken(els[0], "--ui-duration-base");
66
+ if (duration <= 0) return;
67
+ const easing = getComputedStyle(els[0]).getPropertyValue("--ui-ease-out").trim() || "ease-out";
68
+ els.forEach((el, index) => {
69
+ if (!el.isConnected || typeof el.animate !== "function") return;
70
+ const delta = before[index] - el.getBoundingClientRect().top;
71
+ if (!delta) return;
72
+ const animation = el.animate(
73
+ [{ translate: `0 ${delta}px` }, { translate: "0 0" }],
74
+ { duration, easing }
75
+ );
76
+ animation.id = MOVE_ANIMATION_ID;
77
+ });
78
+ }
79
+ function remove(id) {
80
+ const item = items.find((entry) => entry.id === id);
81
+ if (!item || item.leaving) return;
82
+ item.leaving = true;
83
+ void nextTick(() => {
84
+ const spliceNow = () => {
85
+ const index = items.findIndex((entry) => entry.id === id);
86
+ if (index < 0) return;
87
+ const moving = visibleToastEls();
88
+ cancelMoves(moving);
89
+ const before = moving.map((el) => el.getBoundingClientRect().top);
90
+ items.splice(index, 1);
91
+ void nextTick(() => playMoves(moving, before));
92
+ disposeWhenEmpty();
93
+ };
94
+ const leavingEl = container?.querySelector(".mh-toast--leaving") ?? null;
95
+ const wait = waitForExit(leavingEl, "animation");
96
+ if (wait) void wait.then(spliceNow);
97
+ else spliceNow();
98
+ });
99
+ }
50
100
  function toast(tone, text, options = {}) {
51
101
  ensureApp();
52
102
  const id = seq += 1;
@@ -58,9 +108,14 @@ function toast(tone, text, options = {}) {
58
108
  duration,
59
109
  action: options.action,
60
110
  /* 常驻提示缺省给关闭位:没有它用户就只剩刷新页面这一条路 */
61
- closable: options.closable ?? duration === 0
111
+ closable: options.closable ?? duration === 0,
112
+ leaving: false
62
113
  });
63
- while (items.length > MAX_VISIBLE) items.shift();
114
+ while (items.filter((item) => !item.leaving).length > MAX_VISIBLE) {
115
+ const oldest = items.find((item) => !item.leaving);
116
+ if (!oldest) break;
117
+ remove(oldest.id);
118
+ }
64
119
  return { close: () => remove(id) };
65
120
  }
66
121
  function clearToasts() {
@@ -6,7 +6,8 @@
6
6
  * 关闭件 20×20;真实遮罩按 Mask01 黑 45% —— 用户裁定,浅灰 25% + 模糊只留给静态样张)。
7
7
  *
8
8
  * 行为全在原生与操作层:`<dialog>` 给模态语义、Esc 关闭、焦点陷阱与 `::backdrop`;开合与定位归
9
- * `styles/operations/popup.css`(它认 `[open]`)—— 本件只给面;类名与面文件名同根(`.mh-dialog*`)。
9
+ * `styles/operations/popup.css`(它认 `[open]`)—— 本件只给面;**进出场也归本件**(操作层的开合动效只
10
+ * 服务 `[popover]`,`<dialog>` 不经过那条规则)。类名与面文件名同根(`.mh-dialog*`)。
10
11
  * 边界:规范的 `.popconfirm`(气泡确认)不在本件 —— 那是「浮层 + 按钮族」的组合用法
11
12
  * (`class="mh-popup mh-card"` + 按钮),不需要新的面;尺寸 220/r10 也不值得单开一族。
12
13
  */
@@ -40,6 +41,35 @@
40
41
  /* 规范 0 0 40px rgba(0,0,0,.04) → 本仓「卡片环境光」令牌(同族几何、色取本仓基准,不新造字面量) */
41
42
  box-shadow: var(--ui-shadow-card);
42
43
  color: var(--ui-base-content);
44
+ /* ===== 进出场(收起态是这两条,展开态见下方 `[open]`)=====
45
+ 位移只碰独立的 `translate`(不碰 `transform`:那会与 `inset: 0` + `margin: auto` 的居中打架)。
46
+ 退场必须走 **transition** 而不是 animation:原生 `close()` 会**立刻**摘掉 `[open]` 并把面板移出
47
+ top layer —— 只写进场动画的话,退场在首帧就被收走,根本没机会播。
48
+ `display` / `overlay` 走 `allow-discrete`:把「收起」延后到过渡结束;`overlay` 尤其不能漏,
49
+ 漏了面板会先离开 top layer,淡出跑到页面内容底下(看不见)。 */
50
+ opacity: 0;
51
+ translate: 0 8px;
52
+ transition-property: opacity, translate, display, overlay;
53
+ transition-duration: var(--ui-duration-slow);
54
+ transition-timing-function: var(--ui-ease-out);
55
+ transition-behavior: allow-discrete;
56
+ }
57
+ /* 展开态(`[open]` 由原生 `showModal()` 写上)。
58
+ 进场走 **animation**、不用 `@starting-style`:宿主微前端(micro-app)的作用域转换是 **at-rule 白名单**
59
+ (keyframes / media / supports / import / container / layer …),`@starting-style` 不在名单里,会被当成
60
+ 普通选择器加前缀、产出 `micro-app[name=x] @starting-style{…}` 这条非法规则并被浏览器整块丢弃 ——
61
+ 微应用里表现为「进场硬切、退场照播」。`@keyframes` 在白名单内,scoping 后保持合法。
62
+ 退场仍走上面的 transition(收起态本身就是终点,不需要前值)。 */
63
+ .mh-dialog[open] {
64
+ opacity: 1;
65
+ translate: 0 0;
66
+ animation: mh-dialog-in var(--ui-duration-slow) var(--ui-ease-out);
67
+ }
68
+ @keyframes mh-dialog-in {
69
+ from {
70
+ opacity: 0;
71
+ translate: 0 8px;
72
+ }
43
73
  }
44
74
  .mh-dialog--sm {
45
75
  width: var(--ui-dialog-width-sm);
@@ -58,9 +88,24 @@
58
88
  max-height: calc(100vh - 32px);
59
89
  }
60
90
 
61
- /* 真浮层遮罩:`<dialog>` 进 top layer 时才生成 ::backdrop(静态档不生成,对本面无影响) */
91
+ /* 真浮层遮罩:`<dialog>` 进 top layer 时才生成 ::backdrop(静态档不生成,对本面无影响)。
92
+ 与面板同源淡入淡出 —— 只给面板做过渡会让遮罩先「啪」地消失、面板再慢慢淡出。 */
62
93
  .mh-dialog::backdrop {
63
94
  background: var(--ui-dialog-mask);
95
+ opacity: 0;
96
+ transition-property: opacity, display, overlay;
97
+ transition-duration: var(--ui-duration-slow);
98
+ transition-timing-function: var(--ui-ease-out);
99
+ transition-behavior: allow-discrete;
100
+ }
101
+ .mh-dialog[open]::backdrop {
102
+ opacity: 1;
103
+ animation: mh-dialog-backdrop-in var(--ui-duration-slow) var(--ui-ease-out);
104
+ }
105
+ @keyframes mh-dialog-backdrop-in {
106
+ from {
107
+ opacity: 0;
108
+ }
64
109
  }
65
110
 
66
111
  /* 页头:标题左、关闭位右(标题行框 24 —— 面板上内距 16 + 24 + 段间距 24 = 规范页面正文起点 64) */
@@ -199,3 +244,15 @@
199
244
  flex: none; /* 高度受控时贴底且不被压缩(同 Drawer) */
200
245
  padding-inline: var(--ui-dialog-padding-x);
201
246
  }
247
+
248
+ /* 减弱动效:过渡与进场动画一起关掉(含 `display` / `overlay` 的延后)—— 收起回到「立即消失」的既有行为。
249
+ `[open]` 那两条的 animation 特异性高于基态,必须在这里显式点名压掉。 */
250
+ @media (prefers-reduced-motion: reduce) {
251
+ .mh-dialog,
252
+ .mh-dialog::backdrop,
253
+ .mh-dialog[open],
254
+ .mh-dialog[open]::backdrop {
255
+ transition: none;
256
+ animation: none;
257
+ }
258
+ }
@@ -11,8 +11,10 @@
11
11
  * 保留成令牌是让主题能改(如浮起式抽屉),不是默认切角。
12
12
  * - **宽度由组件行内下发**:接受像素数与任意合法宽度串(`min(520px, 90vw)` 这类),比在面里堆尺寸档省事。
13
13
  *
14
- * 进出场用 **animation**(不用 transition):位移只碰独立的 `translate`、不碰 `transform` —— 与全库动画
15
- * 令牌口径一致,且不会覆盖定位;`prefers-reduced-motion` 下整体关闭。类名与面文件名同根(`.mh-drawer*`)。
14
+ * 进出场用 **transition**(不用 animation):位移只碰独立的 `translate`、不碰 `transform` —— 不会覆盖定位。
15
+ * 退场必须走过渡而非动画:原生 `close()` 立刻摘掉 `[open]` 并移出 top layer,`display` / `overlay` 的
16
+ * `allow-discrete` 把「收起」延后到过渡结束,面板才有退场可播(与 `dialog.css` 同一套机制);
17
+ * `prefers-reduced-motion` 下整体关闭。类名与面文件名同根(`.mh-drawer*`)。
16
18
  */
17
19
  .mh-drawer {
18
20
  position: fixed;
@@ -31,24 +33,56 @@
31
33
  box-shadow: var(--ui-shadow-card);
32
34
  color: var(--ui-base-content);
33
35
  overflow: hidden;
36
+ /* 进场 / 退场都走这一条(收起态的起点 / 终点见下方):
37
+ `display` / `overlay` 的 `allow-discrete` 是退场能播的前提 —— 漏掉 `overlay`,面板会先离开
38
+ top layer,滑出动画跑到页面内容底下(看不见)。 */
39
+ transition-property: translate, display, overlay;
40
+ transition-duration: var(--ui-duration-slow);
41
+ transition-timing-function: var(--ui-ease-out);
42
+ transition-behavior: allow-discrete;
34
43
  }
35
44
  .mh-drawer--left {
36
45
  inset-inline: 0 auto; /* 贴左侧 */
37
46
  }
38
47
 
39
- /* 真浮层遮罩:`<dialog>` 进 top layer 时才生成 ::backdrop(静态档不生成,对本面无影响) */
48
+ /* 真浮层遮罩:`<dialog>` 进 top layer 时才生成 ::backdrop(静态档不生成,对本面无影响)。
49
+ 与面板同源淡入淡出(遮罩先消失、面板再滑出会露馅)。 */
40
50
  .mh-drawer::backdrop {
41
51
  background: var(--ui-drawer-mask);
52
+ opacity: 0;
53
+ transition-property: opacity, display, overlay;
54
+ transition-duration: var(--ui-duration-slow);
55
+ transition-timing-function: var(--ui-ease-out);
56
+ transition-behavior: allow-discrete;
57
+ }
58
+ .mh-drawer[open]::backdrop {
59
+ opacity: 1;
60
+ animation: mh-drawer-backdrop-in var(--ui-duration-slow) var(--ui-ease-out);
61
+ }
62
+ @keyframes mh-drawer-backdrop-in {
63
+ from {
64
+ opacity: 0;
65
+ }
42
66
  }
43
67
 
44
- /* 进场:从所贴那一侧推入(`translate` 是独立属性,不动 `transform` 与定位) */
68
+ /* 收起态 = 停在所贴那一侧视口外(退场的终点)。
69
+ 进场起点走 **animation**、不用 `@starting-style`:宿主微前端(micro-app)的作用域转换是 at-rule 白名单
70
+ (不含 `@starting-style`),那条规则会被改写成非法选择器、整块丢弃 ⇒ 微应用里进场硬切、退场照播。
71
+ 位移只碰独立的 `translate`,不碰 `transform`(不覆盖定位)。 */
72
+ .mh-drawer:not([open]) {
73
+ translate: 100% 0;
74
+ }
75
+ .mh-drawer--left:not([open]) {
76
+ translate: -100% 0;
77
+ }
45
78
  .mh-drawer[open] {
46
- animation: mh-drawer-in-right 0.2s ease-out;
79
+ animation: mh-drawer-in var(--ui-duration-slow) var(--ui-ease-out);
47
80
  }
81
+ /* 左档必须排在右档之后:两条特异性相同,靠源码顺序取最后一个 animation-name */
48
82
  .mh-drawer--left[open] {
49
83
  animation-name: mh-drawer-in-left;
50
84
  }
51
- @keyframes mh-drawer-in-right {
85
+ @keyframes mh-drawer-in {
52
86
  from {
53
87
  translate: 100% 0;
54
88
  }
@@ -58,8 +92,14 @@
58
92
  translate: -100% 0;
59
93
  }
60
94
  }
95
+ /* 减弱动效:过渡与进场动画一起关掉(含 `display` / `overlay` 的延后)—— 收起回到「立即消失」的既有行为。
96
+ `[open]` 那两条的 animation 特异性高于基态,必须在这里显式点名压掉。 */
61
97
  @media (prefers-reduced-motion: reduce) {
62
- .mh-drawer[open] {
98
+ .mh-drawer,
99
+ .mh-drawer::backdrop,
100
+ .mh-drawer[open],
101
+ .mh-drawer[open]::backdrop {
102
+ transition: none;
63
103
  animation: none;
64
104
  }
65
105
  }
@@ -29,6 +29,32 @@
29
29
  border-radius: var(--ui-notification-radius);
30
30
  background: var(--ui-info-weak); /* 缺省档 = info 淡底(规范通知淡底) */
31
31
  box-shadow: var(--ui-shadow-elevated);
32
+ /* 进场:淡入 + 6px 上浮(位移只碰独立 `translate`)—— 通知卡常由事件插入,落地时给一帧落点 */
33
+ animation: mh-notification-in var(--ui-duration-base) var(--ui-ease-out);
34
+ }
35
+ @keyframes mh-notification-in {
36
+ from {
37
+ opacity: 0;
38
+ translate: 0 -6px;
39
+ }
40
+ }
41
+ /* 退场:与进场对称(`forwards` 保住末帧 —— 移除由持有方在 animationend 后做,
42
+ 没有它会在播完到移除之间闪回一帧可见)。与 `Toast` 的 `--leaving` 同一套受控口径。 */
43
+ .mh-notification--leaving {
44
+ animation: mh-notification-out var(--ui-duration-base) var(--ui-ease-in) forwards;
45
+ }
46
+ @keyframes mh-notification-out {
47
+ to {
48
+ opacity: 0;
49
+ translate: 0 -6px;
50
+ }
51
+ }
52
+ /* 减弱动效:整条进场 / 退场关掉(出现与否不靠动画传达) */
53
+ @media (prefers-reduced-motion: reduce) {
54
+ .mh-notification,
55
+ .mh-notification--leaving {
56
+ animation: none;
57
+ }
32
58
  }
33
59
  .mh-notification::before {
34
60
  content: '';
@@ -33,6 +33,28 @@
33
33
  border-radius: var(--ui-toast-radius);
34
34
  background: var(--ui-base-100);
35
35
  box-shadow: var(--ui-shadow-elevated);
36
+ /* 进场:淡入 + 6px 上浮(位移只碰独立 `translate`)。
37
+ 挂在**条目**上而不是 `.mh-toast-stack`:容器在模态打开时会重进 top layer,而 `hidePopover()` +
38
+ `showPopover()` 会让子元素的 CSS 动画重播 —— 挂容器的话整叠提示会在那种更新里一起重放。
39
+ 退场由 `--leaving` 单独承担;移除归服务层(动画播完才 splice)。 */
40
+ animation: mh-toast-in var(--ui-duration-base) var(--ui-ease-out);
41
+ }
42
+ @keyframes mh-toast-in {
43
+ from {
44
+ opacity: 0;
45
+ translate: 0 -6px;
46
+ }
47
+ }
48
+ /* 退场:与进场同一位移方向(同一条时间刻度略短)。`forwards` 必须写 —— 服务层等 `animationend`
49
+ 才移除节点,没有它会在播完到移除之间闪回一帧可见。存在性归调用方(组件只加类)。 */
50
+ .mh-toast--leaving {
51
+ animation: mh-toast-out var(--ui-duration-base) var(--ui-ease-in) forwards;
52
+ }
53
+ @keyframes mh-toast-out {
54
+ to {
55
+ opacity: 0;
56
+ translate: 0 -6px;
57
+ }
36
58
  }
37
59
 
38
60
  /* loading:**不另设样张高**(高度与其它档一致,见文件头的「有意偏差」)—— 本档只差图标(转圈) */
@@ -177,3 +199,12 @@
177
199
  .mh-toast__close-icon {
178
200
  flex: none;
179
201
  }
202
+
203
+ /* 减弱动效:整条进场 / 退场关掉(出现时机由计时器决定,不靠动画传达信息)。
204
+ `--leaving` 也声明了 `animation`,必须一并点名 —— 两者同特异性,靠这里的源码顺序覆盖。 */
205
+ @media (prefers-reduced-motion: reduce) {
206
+ .mh-toast,
207
+ .mh-toast--leaving {
208
+ animation: none;
209
+ }
210
+ }
@@ -50,14 +50,18 @@
50
50
  * 域定在 `.mh-popup--hover`:静态摆样(不带该档)恒可见,不落收起末帧。 */
51
51
  .mh-tooltip.mh-popup--hover {
52
52
  opacity: 0;
53
- transition: opacity 0.2s ease-out;
53
+ transition: opacity var(--ui-duration-slow) var(--ui-ease-out);
54
54
  }
55
55
  .mh-popup-host:hover .mh-tooltip.mh-popup--hover,
56
56
  .mh-popup-host:focus-within .mh-tooltip.mh-popup--hover {
57
57
  opacity: 1;
58
+ /* 进场走 animation、不用 `@starting-style`:宿主微前端(micro-app)的作用域转换是 at-rule 白名单
59
+ (不含 `@starting-style`),那条规则会被改写成非法选择器、整块丢弃 ⇒ 微应用里只有淡出不淡入。
60
+ 显示由操作层切 `display`,元素从 `none` 变可见时浏览器会自动起播这条动画。 */
61
+ animation: mh-tooltip-in var(--ui-duration-slow) var(--ui-ease-out);
58
62
  }
59
- @starting-style {
60
- .mh-popup-host:hover .mh-tooltip.mh-popup--hover {
63
+ @keyframes mh-tooltip-in {
64
+ from {
61
65
  opacity: 0;
62
66
  }
63
67
  }
@@ -16,6 +16,7 @@
16
16
  * 直接子一律不显示(原生根由浏览器收起);收起态不留 gap(flex 列皮肤的隐藏内容槽仍占一个 flex 项)。
17
17
  * 三、硬约束:**不写底 / 边 / 圆角 / 内距 / 高 / 字号 / gap** —— 写了就会顶掉皮肤族的属性面
18
18
  * (卡片头的内距与底边线、表单分组头的行高),这正是「根上只加两个类就能组合」的前提。
19
+ * 唯一的「高」出现在开合动效里(`::details-content` 的 `block-size: 0`),那是行为的起点,不是皮肤尺寸。
19
20
  */
20
21
  .mh-collapse {
21
22
  min-width: 0; /* 仅作状态根 + 作 flex 子项时不横向溢出;面由皮肤给 */
@@ -69,3 +70,34 @@ details.mh-collapse:not([open]) > :is(summary, .mh-collapse-header) .mh-collapse
69
70
  details.mh-collapse:not([open]) {
70
71
  gap: 0;
71
72
  }
73
+
74
+ /* ===== 开合动效(渐进增强,零 JS) =====
75
+ * 为什么归本层:开合状态(`[open]`)只有这里认,内容盒由 UA 放在 `::details-content` 里 ——
76
+ * 皮肤层既拿不到状态、也拿不到这个伪元素。
77
+ * 高度从 `auto` 插值到 0 需要 `interpolate-size: allow-keywords`;`content-visibility` 走
78
+ * `allow-discrete` 把「内容被收起」延后到过渡结束,否则 UA 会先把内容藏起来、高度动画只剩空跳。
79
+ * ⚠️ 只在支持这套现代特性的浏览器里生效(Chromium 131+);不支持的浏览器**退回原来的瞬时开合** ——
80
+ * 不引入 JS 测量,也不为它改组件。
81
+ * 本块只碰 `::details-content` 的高度与可见性,不落任何皮肤面(底 / 边 / 内距仍归皮肤族)。 */
82
+ @supports (interpolate-size: allow-keywords) {
83
+ .mh-collapse {
84
+ interpolate-size: allow-keywords;
85
+ }
86
+ .mh-collapse::details-content {
87
+ block-size: 0;
88
+ overflow: clip;
89
+ transition-property: block-size, content-visibility;
90
+ transition-duration: var(--ui-duration-slow);
91
+ transition-timing-function: var(--ui-ease-out);
92
+ transition-behavior: allow-discrete;
93
+ }
94
+ .mh-collapse[open]::details-content {
95
+ block-size: auto;
96
+ }
97
+ /* 减弱动效:退回瞬时开合 */
98
+ @media (prefers-reduced-motion: reduce) {
99
+ .mh-collapse::details-content {
100
+ transition: none;
101
+ }
102
+ }
103
+ }
@@ -5,7 +5,7 @@
5
5
  * 面与几何一律来自皮肤族类,面板根上并列两个类即组合(气泡确认 = 气泡皮肤,下拉层 = 选择面板皮肤…)。
6
6
  * 箭头不由本层画:字形取 `@manohub/icon` 的 `chevron-down`,本层只负责「展开时转向」。
7
7
  *
8
- * 本层只做六件事:
8
+ * 本层只做七件事:
9
9
  * 一、状态根 `.mh-popup` —— 三条状态源等价(原生 `:popover-open` / 原生 `<dialog>[open]` / 组件
10
10
  * `data-state="open|closed"`)。收起态本该由 UA 的 `display: none` 承担,但皮肤自带 display 会以作者源
11
11
  * 压过 UA(提示皮肤实测踩坑),故收起态要按高特异性重钉一次。
@@ -19,12 +19,16 @@
19
19
  * UA 给 `dialog` 的 `margin: auto` 归零 ⇒ 弹窗贴上贴左,居中必须由件写实(见 `components/dialog.css`)。
20
20
  * 五、展开态派生 —— 箭头转向(原生路径由宿主 `:has` 反推,组件路径由 `aria-expanded` 反推)。
21
21
  * 六、hover 档 `.mh-popup--hover` —— 给「非交互提示」的纯 CSS 显形;原因与代价见该节注释。
22
+ * 七、开合动效 —— 所有 `[popover]` 浮层共用的一条淡入淡出(**含退场**);为什么归本层、为什么必须
23
+ * 带 `allow-discrete` 见该节注释。
22
24
  *
23
25
  * **硬约束:本层规则一律走 `:where()`(特异性 0)** —— 这是「不顶掉皮肤」的机械保证。例外只有三类:
24
26
  * ① 四条裸类规则(`.mh-popup` / `-anchor` / `-host` / `--anchored`)声明状态根与锚点身份;② 收起态走
25
27
  * `:is()`(0-3-0)—— 皮肤自带 display 会压过 UA 的收起 `display: none`;③ hover 档两条(同上)。三条
26
28
  * display 规则都只碰 display。
27
- * 禁写清单(与折叠同款):底 / 边 / 圆角 / 内距 / 宽高 / 字号 / 阴影 / 遮罩色 / 动画。
29
+ * 禁写清单(与折叠同款):底 / 边 / 圆角 / 内距 / 宽高 / 字号 / 阴影 / 遮罩色。
30
+ * **动效只许「开合淡入淡出」,且只在第七节定义一次**(皮肤与消费方不得自写 keyframes,
31
+ * 也禁位移 / 缩放 —— 会和四向翻面、锚点呼吸位打架),时长与缓动走 theme 的 `--ui-duration-*` / `--ui-ease-*`。
28
32
  * 层级:popover 档由 top layer 接管(零 z-index),hover 档不进 top layer 故自带一层 z-index。
29
33
  */
30
34
  /* ===== 一、状态根 ===== */
@@ -153,3 +157,40 @@
153
157
  .mh-popup-host:focus-within .mh-popup--hover {
154
158
  display: block;
155
159
  }
160
+
161
+ /* ===== 七、开合动效(所有 `[popover]` 浮层共用的一条淡入淡出) =====
162
+ * 为什么归本层:开合状态只有这里看得见(`[popover]` + 展开态伪类),皮肤层拿不到 ——
163
+ * `select` 面的契约明确禁写 popover 状态选择器(开合 / 定位归操作层)。而**退场必须靠 transition**:
164
+ * 原生收起会立刻把节点摘出 top layer,`display` / `overlay` 的 `allow-discrete` 把「收起」延后到
165
+ * 过渡结束,才有退场可播;`overlay` 漏了面板会先离开 top layer,淡出跑到页面内容底下(看不见)。
166
+ * 只碰 `opacity`:位移会与四向翻面、锚点呼吸位打架,各皮肤需要时自己加(本层 0 特异性,永远让位)。
167
+ * 进场走 animation、退场走 transition(原因见展开态那条注释);两者都只碰 `opacity`。
168
+ * 静态档(不带 `popover` 的摆样)与 hover 档不受影响;时长 / 缓动走 theme 的动效令牌。 */
169
+ :where(.mh-popup[popover]) {
170
+ opacity: 0;
171
+ transition-property: opacity, display, overlay;
172
+ transition-duration: var(--ui-duration-fast);
173
+ transition-timing-function: var(--ui-ease-out);
174
+ transition-behavior: allow-discrete;
175
+ }
176
+ :where(.mh-popup[popover]:popover-open) {
177
+ opacity: 1;
178
+ /* 进场走 animation、不用 `@starting-style`:宿主微前端(micro-app)的作用域转换是 at-rule 白名单
179
+ (keyframes / media / supports / import / container / layer …),`@starting-style` 不在名单里,
180
+ 会被当成普通选择器加前缀、产出 `micro-app[name=x] @starting-style{…}` 这条非法规则并被整块丢弃 ——
181
+ 微应用里浮层「进场硬切、退场照播」。`@keyframes` 在白名单内,scoping 后保持合法。 */
182
+ animation: mh-popup-in var(--ui-duration-fast) var(--ui-ease-out);
183
+ }
184
+ @keyframes mh-popup-in {
185
+ from {
186
+ opacity: 0;
187
+ }
188
+ }
189
+ /* 减弱动效:过渡与进场动画一起关掉(含 `display` / `overlay` 的延后)—— 收起回到「立即消失」 */
190
+ @media (prefers-reduced-motion: reduce) {
191
+ :where(.mh-popup[popover]),
192
+ :where(.mh-popup[popover]:popover-open) {
193
+ transition: none;
194
+ animation: none;
195
+ }
196
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manohub/ui",
3
- "version": "1.2.11",
3
+ "version": "1.2.13",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "AIHub 自绘组件层:不依赖 farris 的手写 Vue TSX 组件 + 自带令牌层(Farris 规范视觉 · daisyUI 式语义令牌 · shadcn 式 API 词汇)。",
@@ -35,7 +35,7 @@
35
35
  "vue": "^3.5.0"
36
36
  },
37
37
  "dependencies": {
38
- "@manohub/icon": "^1.2.11"
38
+ "@manohub/icon": "^1.2.13"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^24.0.0",