@manohub/ui 1.1.3 → 1.1.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.
@@ -1,10 +1,13 @@
1
1
  import { defineComponent, createVNode, Fragment } from "vue";
2
2
  import { Button } from "../button/index.js";
3
3
  import { STATE_ILLUSTRATION_ERROR_SVG, STATE_ILLUSTRATION_EMPTY_SVG } from "../../utils/state-illustration.js";
4
+ import { scopeSvgIds } from "../../utils/scope-svg-ids.js";
4
5
  const BUILT_IN_ILLUSTRATION = {
5
6
  empty: STATE_ILLUSTRATION_EMPTY_SVG,
6
7
  error: STATE_ILLUSTRATION_ERROR_SVG
7
8
  };
9
+ const BUNDLE_SEED = Math.random().toString(36).slice(2, 8);
10
+ let illustrationInstance = 0;
8
11
  const QueryState = /* @__PURE__ */ defineComponent({
9
12
  name: "QueryState",
10
13
  inheritAttrs: false,
@@ -77,6 +80,17 @@ const QueryState = /* @__PURE__ */ defineComponent({
77
80
  slots,
78
81
  attrs
79
82
  }) {
83
+ const illustrationScope = `${BUNDLE_SEED}${illustrationInstance += 1}`;
84
+ const scopedIllustrations = /* @__PURE__ */ new Map();
85
+ const builtInIllustration = (kind) => {
86
+ const cached = scopedIllustrations.get(kind);
87
+ if (cached !== void 0) {
88
+ return cached;
89
+ }
90
+ const scoped = scopeSvgIds(BUILT_IN_ILLUSTRATION[kind], illustrationScope);
91
+ scopedIllustrations.set(kind, scoped);
92
+ return scoped;
93
+ };
80
94
  const illustrationWidth = () => props.illustrationSize === void 0 ? void 0 : {
81
95
  width: typeof props.illustrationSize === "number" ? `${props.illustrationSize}px` : props.illustrationSize,
82
96
  height: "auto"
@@ -99,7 +113,7 @@ const QueryState = /* @__PURE__ */ defineComponent({
99
113
  "class": "mh-state-illustration",
100
114
  "style": illustrationWidth(),
101
115
  "aria-hidden": "true",
102
- "innerHTML": BUILT_IN_ILLUSTRATION[kind]
116
+ "innerHTML": builtInIllustration(kind)
103
117
  }, null);
104
118
  };
105
119
  const renderActions = (kind, actionText, onAction) => {
@@ -65,7 +65,8 @@
65
65
 
66
66
  /* ===== 插画壳 =====
67
67
  内建插画是**设计交付的 SVG 原样注入**(见 `utils/state-illustration.ts`:结构 / 坐标 / 固定色值 /
68
- `id` / `<title>` 全保留),面里因此只有外壳这一件事:壳宽(264 = 设计画布宽)、窄容器里按比例收缩、
68
+ `<title>` 全保留;`id` 原样保留,但注入前按实例加后缀,见 `utils/scope-svg-ids.ts`),
69
+ 面里因此只有外壳这一件事:壳宽(264 = 设计画布宽)、窄容器里按比例收缩、
69
70
  与下方文案的间距,以及把设计稿写死 `264 × 246` 的画布拉成「随壳自适应」。
70
71
  同理,插画**不跟随主题**(图里是设计终值色,不走 `--ui-*`)——这是「原样引用」的取舍。
71
72
  `illustration` 属性给的图片地址复用同一个壳(`<img>` 自带比例,不需要第二条规则)。 */
@@ -0,0 +1,34 @@
1
+ /**
2
+ * 内联 SVG 的 **id 作用域化**:把「一份固定 id 的设计 SVG」改成「本次渲染独占」的一串。
3
+ *
4
+ * ## 为什么必须有这层
5
+ *
6
+ * `state-illustration.ts` 是设计原样导出的 SVG,里面十几个 `id`(`empty-glow-1` / `empty-badge-clip` …)
7
+ * 是**常量**,而每个 `QueryState` 实例都把它 `innerHTML` 进 DOM 一份。微前端里子应用各自打包、
8
+ * 挂**同一个文档**(aip-web:平台页签容器),于是同一种状态同屏出现两次时,文档里就有两套同名 id。
9
+ *
10
+ * 浏览器解析 `url(#…)` 按**文档树里第一个匹配**算,后出现的那份其实在借前一份的 `<defs>`:
11
+ *
12
+ * - 前一份还渲染着 ⇒ 侥幸一模一样(这就是「只开一个页面时怎么都正常」);
13
+ * - 前一份被隐藏(平台切页签 → `display:none`,那份 `<defs>` 失去布局对象、不再作为资源存在)
14
+ * ⇒ 后一份的 `url()` 全部落空,**凡靠渐变 / 图案 / 遮罩上色的图元整块不绘制**,只剩字面色值的图元;
15
+ * 靠 `<use xlink:href="#…">` 撑起来的遮罩还会被前一份的 `visibility` 连累。
16
+ *
17
+ * 症状指纹:一张「白卡片 + 灰影」—— 恰好是所有 `url(#…)` 图元消失后的残余(2026-10-17 实测,
18
+ * aip-web 的「集成对象管理」与「服务开放」两页同开、都出空态时复现)。
19
+ *
20
+ * ## 做法
21
+ *
22
+ * 渲染前给**所有 id 与三处引用**加同一个后缀:`<mask id="x-s3">` 与 `mask="url(#x-s3)"`、
23
+ * `<use xlink:href="#x-s3">` 必须同源。漏掉引用侧就是另一种空转(定义在、引用不到 —— 回形针角标)
24
+ * ,漏掉 id 侧则是「引用了别人的」。CSS 选择器不参与:本包的样式规则只按 `.mh-*` 类走。
25
+ */
26
+ /**
27
+ * 给内联 SVG 的 id 声明与引用统一加后缀。
28
+ *
29
+ * 只认双引号属性(设计导出如此);`<?xml …?>` 头原样留着,`innerHTML` 会把它当注释丢掉。
30
+ *
31
+ * @param svg 设计原样的 SVG 串
32
+ * @param scope 本实例独占的后缀。会被塞进 `url(#…)`,须只含 `[A-Za-z0-9_-]`(不得有括号 / 引号 / 空白)
33
+ */
34
+ export declare function scopeSvgIds(svg: string, scope: string): string;
@@ -0,0 +1,15 @@
1
+ function scopeSvgIds(svg, scope) {
2
+ return svg.replace(/(\bid=")([^"]+)(")/g, (_match, before, id, after) => {
3
+ return `${before}${id}-${scope}${after}`;
4
+ }).replace(/(url\(#)([^)]+)(\))/g, (_match, before, id, after) => {
5
+ return `${before}${id}-${scope}${after}`;
6
+ }).replace(
7
+ /((?:xlink:)?href="#)([^"]+)(")/g,
8
+ (_match, before, id, after) => {
9
+ return `${before}${id}-${scope}${after}`;
10
+ }
11
+ );
12
+ }
13
+ export {
14
+ scopeSvgIds
15
+ };
@@ -7,6 +7,13 @@
7
7
  * `.mh-state-illustration` 壳(`innerHTML`,与 `@manohub/icon` 渲染字形同一套路),壳宽由 `illustrationSize` 定。
8
8
  * 成功 / 异常两张暂无内建消费方,要「提交完成」整页那样的图形时按同一路子引即可。
9
9
  * 换图 = 重新从设计导出并整体替换本文件,不要在这里改结构、也不要在组件里改细节。
10
+ *
11
+ * ## 注入前必须做 id 作用域化
12
+ *
13
+ * 本文件的 `id` 是**设计原样的常量**(`empty-glow-1` / `error-card-clip-1` …),每注入一份就多一套同名 id;
14
+ * 同一文档里出现两份时,`url(#…)` 会解析到**先出现那份**的 `<defs>`,那份一旦被隐藏,后来者整块丢图。
15
+ * 故**不要**把串直接喂 `innerHTML`:一律先过 `utils/scope-svg-ids.ts` 的 `scopeSvgIds(svg, 本实例唯一后缀)`。
16
+ * 修图时也不要「顺手把 id 改成调用方前缀」—— 图是设计资产,作用域归渲染层。
10
17
  */
11
18
  /** 空态(设计稿「空状态」):圆点底纹 + 叠加卡片 + 蓝色折角 + 绿色回形针角标 */
12
19
  export declare const STATE_ILLUSTRATION_EMPTY_SVG: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manohub/ui",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
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.1.3"
38
+ "@manohub/icon": "^1.1.4"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^24.0.0",