@24city/web-console 0.1.1 → 0.1.3

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.
@@ -30,3 +30,8 @@ export declare const EXPECTED_SEMI_VERSION: string;
30
30
  * 图标与插画包若有声明也必须是同一版本。传产品 `apps/web/package.json` 的路径;返回空数组表示一致。
31
31
  */
32
32
  export declare const checkSemiVersion: (productPackageJsonPath: string) => UiGuardViolation[];
33
+ /**
34
+ * 检查产品的 Vite 配置用了 `@24city/web-console/vite` 的 `semiCssLayer()`:不分层时本包主题会被 Semi 的样式整体压掉
35
+ * (主题写在 `semi` 层里),产品自己的覆盖样式也要逐条比 Semi 的选择器更具体才生效。传 `apps/web/vite.config.ts` 的路径。
36
+ */
37
+ export declare const checkSemiCssLayer: (viteConfigPath: string) => UiGuardViolation[];
@@ -1,8 +1,8 @@
1
- import { readFileSync as m, readdirSync as E, statSync as S } from "node:fs";
2
- import { relative as y, join as $ } from "node:path";
3
- const v = { "@douyinfe/semi-ui": "2.104.0" }, b = {
1
+ import { readFileSync as u, readdirSync as y, statSync as E } from "node:fs";
2
+ import { relative as S, join as b } from "node:path";
3
+ const v = { "@douyinfe/semi-ui": "2.104.0" }, g = {
4
4
  peerDependencies: v
5
- }, x = /<(button|input|select|textarea|option|label|form|table|thead|tbody|tr|td|th|details|summary|dialog|img|a|ul|ol|li|dl|dt|dd|h[1-6]|p)(\s|>|\/)/, A = [
5
+ }, $ = /<(button|input|select|textarea|option|label|form|table|thead|tbody|tr|td|th|details|summary|dialog|img|a|ul|ol|li|dl|dt|dd|h[1-6]|p)(\s|>|\/)/, L = [
6
6
  "lucide-react",
7
7
  "@nuwa/customer-ui",
8
8
  "@nuwa/customer-shell",
@@ -14,48 +14,58 @@ const v = { "@douyinfe/semi-ui": "2.104.0" }, b = {
14
14
  ".arco-",
15
15
  "@douyinfe/semi-ui/dist/css",
16
16
  "theme-mode"
17
- ], R = ["--semi-", "--app-"], _ = /#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{4}|[0-9a-fA-F]{3})\b/, g = /\b(?:rgba?|hsla?)\((?!\s*var\()/, D = new RegExp(`(?:^|[\\s{;'"])(${R.map((t) => t.replace(/-/g, "\\-")).join("|")})[a-z0-9_-]*\\s*['"]?\\s*:`, "m"), p = (t) => E(t).flatMap((o) => {
18
- const e = $(t, o);
19
- return S(e).isDirectory() ? p(e) : [e];
20
- }), F = (t) => /\.test\.(ts|tsx)$/.test(t) || t.startsWith("test/") || t.endsWith(".d.ts"), O = ({ sourceRoot: t, exclude: o = F }) => {
21
- const e = [], a = p(t).map((i) => ({ path: i, file: y(t, i) })).filter(({ file: i }) => !o(i));
22
- for (const { path: i, file: s } of a) {
23
- const n = s.endsWith(".tsx");
24
- if (!/\.(tsx?|css)$/.test(s)) continue;
25
- const r = m(i, "utf8");
17
+ ], x = ["--semi-", "--app-"], A = /#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{4}|[0-9a-fA-F]{3})\b/, C = /\b(?:rgba?|hsla?)\((?!\s*var\()/, R = new RegExp(`(?:^|[\\s{;'"])(${x.map((s) => s.replace(/-/g, "\\-")).join("|")})[a-z0-9_-]*\\s*['"]?\\s*:`, "m"), p = (s) => y(s).flatMap((i) => {
18
+ const e = b(s, i);
19
+ return E(e).isDirectory() ? p(e) : [e];
20
+ }), _ = (s) => /\.test\.(ts|tsx)$/.test(s) || s.startsWith("test/") || s.endsWith(".d.ts"), N = ({ sourceRoot: s, exclude: i = _ }) => {
21
+ const e = [], r = p(s).map((o) => ({ path: o, file: S(s, o) })).filter(({ file: o }) => !i(o));
22
+ for (const { path: o, file: t } of r) {
23
+ const n = t.endsWith(".tsx");
24
+ if (!/\.(tsx?|css)$/.test(t)) continue;
25
+ const c = u(o, "utf8");
26
26
  if (n) {
27
- const c = r.match(x);
28
- c && e.push({ file: s, rule: "raw-element", detail: `应改用 Semi 组件,而不是 ${c[0].trim()}` }), /className="/.test(r) && e.push({ file: s, rule: "class-string", detail: "className 应引用 CSS Module,不写工具类字符串" });
27
+ const a = c.match($);
28
+ a && e.push({ file: t, rule: "raw-element", detail: `应改用 Semi 组件,而不是 ${a[0].trim()}` }), /className="/.test(c) && e.push({ file: t, rule: "class-string", detail: "className 应引用 CSS Module,不写工具类字符串" });
29
29
  }
30
- for (const c of A)
31
- r.includes(c) && e.push({ file: s, rule: "forbidden-import", detail: `不应引用 ${c}` });
32
- const u = r.match(_);
33
- u && e.push({ file: s, rule: "color-literal", detail: `含有写死的色值 ${u[0]}` });
34
- const d = r.match(g);
35
- d && e.push({ file: s, rule: "color-literal", detail: `含有写死的色值 ${d[0]}` });
36
- const f = r.match(D);
37
- f && e.push({ file: s, rule: "reserved-variable", detail: `不得声明主题变量 ${f[1]}…,品牌主色只能通过 runtime-config 的 brand.primaryColor 设置` });
30
+ for (const a of L)
31
+ c.includes(a) && e.push({ file: t, rule: "forbidden-import", detail: `不应引用 ${a}` });
32
+ const d = c.match(A);
33
+ d && e.push({ file: t, rule: "color-literal", detail: `含有写死的色值 ${d[0]}` });
34
+ const m = c.match(C);
35
+ m && e.push({ file: t, rule: "color-literal", detail: `含有写死的色值 ${m[0]}` });
36
+ const f = c.match(R);
37
+ f && e.push({ file: t, rule: "reserved-variable", detail: `不得声明主题变量 ${f[1]}…,品牌主色只能通过 runtime-config 的 brand.primaryColor 设置` });
38
38
  }
39
39
  return e;
40
- }, I = ["@douyinfe/semi-ui", "@douyinfe/semi-icons", "@douyinfe/semi-illustrations"], N = b.peerDependencies, l = N["@douyinfe/semi-ui"], T = (t) => {
41
- var a, i;
42
- const o = JSON.parse(m(t, "utf8")), e = [];
43
- for (const s of I) {
44
- const n = ((a = o.dependencies) == null ? void 0 : a[s]) ?? ((i = o.devDependencies) == null ? void 0 : i[s]);
45
- !(s === "@douyinfe/semi-ui" || n !== void 0) || n === l || e.push({
40
+ }, w = ["@douyinfe/semi-ui", "@douyinfe/semi-icons", "@douyinfe/semi-illustrations"], D = g.peerDependencies, l = D["@douyinfe/semi-ui"], O = (s) => {
41
+ var r, o;
42
+ const i = JSON.parse(u(s, "utf8")), e = [];
43
+ for (const t of w) {
44
+ const n = ((r = i.dependencies) == null ? void 0 : r[t]) ?? ((o = i.devDependencies) == null ? void 0 : o[t]);
45
+ !(t === "@douyinfe/semi-ui" || n !== void 0) || n === l || e.push({
46
46
  file: "package.json",
47
47
  rule: "semi-version",
48
- detail: n ? `${s} 必须精确声明为 ${l},现在是 ${n}` : `必须声明 ${s} ${l}`
48
+ detail: n ? `${t} 必须精确声明为 ${l},现在是 ${n}` : `必须声明 ${t} ${l}`
49
49
  });
50
50
  }
51
51
  return e;
52
+ }, T = (s) => {
53
+ const i = u(s, "utf8").replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, ""), e = /import\s*\{[^}]*\bsemiCssLayer\b[^}]*\}\s*from\s*['"]@24city\/web-console\/vite['"]/.test(i), r = /\bsemiCssLayer\s*\(\s*\)/.test(i);
54
+ return e && r ? [] : [
55
+ {
56
+ file: "vite.config.ts",
57
+ rule: "semi-css-layer",
58
+ detail: "plugins 里要加 semiCssLayer()(import { semiCssLayer } from '@24city/web-console/vite'),把 Semi 的样式放进 semi 层"
59
+ }
60
+ ];
52
61
  };
53
62
  export {
54
63
  l as EXPECTED_SEMI_VERSION,
55
- A as FORBIDDEN_SNIPPETS,
56
- x as RAW_ELEMENT_PATTERN,
57
- R as RESERVED_VARIABLE_PREFIXES,
58
- I as SEMI_PACKAGES,
59
- T as checkSemiVersion,
60
- O as checkUiLibraryUsage
64
+ L as FORBIDDEN_SNIPPETS,
65
+ $ as RAW_ELEMENT_PATTERN,
66
+ x as RESERVED_VARIABLE_PREFIXES,
67
+ w as SEMI_PACKAGES,
68
+ T as checkSemiCssLayer,
69
+ O as checkSemiVersion,
70
+ N as checkUiLibraryUsage
61
71
  };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /** 与 Vite 插件接口兼容的最小形状;本包不依赖 vite 的类型。 */
2
+ export interface SemiCssLayerPlugin {
3
+ name: string;
4
+ enforce: 'pre';
5
+ transform: (code: string, id: string) => {
6
+ code: string;
7
+ map: null;
8
+ } | null;
9
+ }
10
+ /** Semi 的样式文件:`@douyinfe/semi-ui/lib/es/_base/base.css` 和 `@douyinfe/semi-foundation/lib/es/<组件>/<组件>.css`。 */
11
+ export declare const SEMI_CSS_FILE: RegExp;
12
+ /** 分层的名字;本包主题写在同名层里。 */
13
+ export declare const SEMI_CSS_LAYER = "semi";
14
+ /** 把一份 Semi 样式包进 `@layer semi { … }`;`@charset`、`@import` 必须留在最前面。已经分过层的原样返回。 */
15
+ export declare const wrapSemiCss: (code: string) => string;
16
+ /**
17
+ * 产品的 vite.config.ts 必须加上它(本包的守卫 `checkSemiCssLayer` 会检查):
18
+ *
19
+ * ```ts
20
+ * import { semiCssLayer } from '@24city/web-console/vite'
21
+ * export default defineConfig({ plugins: [react(), semiCssLayer()] })
22
+ * ```
23
+ */
24
+ export declare const semiCssLayer: () => SemiCssLayerPlugin;
package/dist/vite.js ADDED
@@ -0,0 +1,24 @@
1
+ const a = /[\\/]@douyinfe[\\/]semi-[a-z-]+[\\/].*\.css(?:$|\?)/, r = "semi", c = /^(?:\s*(?:@charset\s[^;]*;|@import\s[^;]*;|\/\*[\s\S]*?\*\/))+/, l = (s) => {
2
+ var n;
3
+ if (new RegExp(`^\\s*@layer\\s+${r}\\s*\\{`).test(s)) return s;
4
+ const e = ((n = s.match(c)) == null ? void 0 : n[0]) ?? "", t = s.slice(e.length);
5
+ return `${e}${e ? `
6
+ ` : ""}@layer ${r} {
7
+ ${t}
8
+ }
9
+ `;
10
+ }, o = () => ({
11
+ name: "24city-web-console:semi-css-layer",
12
+ enforce: "pre",
13
+ transform(s, e) {
14
+ if (!a.test(e) || /[?&](?:raw|url)\b/.test(e)) return null;
15
+ const t = l(s);
16
+ return t === s ? null : { code: t, map: null };
17
+ }
18
+ });
19
+ export {
20
+ a as SEMI_CSS_FILE,
21
+ r as SEMI_CSS_LAYER,
22
+ o as semiCssLayer,
23
+ l as wrapSemiCss
24
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@24city/web-console",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "24.city 产品用户端的控制台外壳、账号菜单、个人中心、会员引导与 Semi Design 主题",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -92,6 +92,11 @@
92
92
  "import": "./dist/theme/index.js",
93
93
  "default": "./dist/theme/index.js"
94
94
  },
95
+ "./vite": {
96
+ "types": "./dist/vite.d.ts",
97
+ "import": "./dist/vite.js",
98
+ "default": "./dist/vite.js"
99
+ },
95
100
  "./styles.css": "./dist/styles.css",
96
101
  "./package.json": "./package.json"
97
102
  },
@@ -1,198 +0,0 @@
1
- import { jsx as t, jsxs as c, Fragment as O } from "react/jsx-runtime";
2
- import { useState as v, useEffect as R } from "react";
3
- import { Layout as f, Button as x, Typography as F, Space as Q, Nav as G } from "@douyinfe/semi-ui";
4
- import { IconSidebar as $ } from "@douyinfe/semi-icons";
5
- import { useLocation as Y, useNavigate as q, Outlet as D } from "react-router";
6
- import { h as J, B as V, o as X, e as Z, W as z, b as ee } from "./wallet-badge-CnyMLpUO.js";
7
- import { u as A, b as te, a as ne } from "./context-CaVim6ZO.js";
8
- import { u as ae } from "./use-media-query-DvyinWNg.js";
9
- const oe = "_layout_15fx1_6", se = "_header_15fx1_13", le = "_headerLeft_15fx1_34", re = "_logo_15fx1_42", ce = "_logoMark_15fx1_57", ie = "_logoText_15fx1_64", de = "_modules_15fx1_73", ue = "_module_15fx1_73", me = "_moduleText_15fx1_110", _e = "_moduleIcon_15fx1_130", he = "_moduleInk_15fx1_134", pe = "_headerRight_15fx1_154", fe = "_body_15fx1_163", xe = "_sider_15fx1_169", ye = "_siderInner_15fx1_183", ke = "_panel_15fx1_190", ge = "_expandButton_15fx1_227", Ne = "_menu_15fx1_243", ve = "_menuGroup_15fx1_254", be = "_menuGroupTitle_15fx1_263", Ie = "_menuList_15fx1_274", Ce = "_collapseButton_15fx1_390", Me = "_mask_15fx1_411", Be = "_content_15fx1_420", we = "_contentCentered_15fx1_426", Le = "_contentInner_15fx1_438", Te = "_letterMark_15fx1_491", e = {
10
- layout: oe,
11
- header: se,
12
- headerLeft: le,
13
- logo: re,
14
- logoMark: ce,
15
- logoText: ie,
16
- modules: de,
17
- module: ue,
18
- moduleText: me,
19
- moduleIcon: _e,
20
- moduleInk: he,
21
- headerRight: pe,
22
- body: fe,
23
- sider: xe,
24
- siderInner: ye,
25
- panel: ke,
26
- expandButton: ge,
27
- menu: Ne,
28
- menuGroup: ve,
29
- menuGroupTitle: be,
30
- menuList: Ie,
31
- collapseButton: Ce,
32
- mask: Me,
33
- content: Be,
34
- contentCentered: we,
35
- contentInner: Le,
36
- letterMark: Te
37
- }, Se = (a, l) => a === l || a.startsWith(`${l}/`), Ge = (a, l) => a.flatMap((o) => o.items).find((o) => new URL(o.to, "http://console.local").pathname === l), $e = (a, l) => {
38
- var o;
39
- return (o = [...a].map((r) => ({ module: r, path: new URL(r.to, "http://console.local").pathname })).filter(({ path: r }) => Se(l, r)).sort((r, u) => u.path.length - r.path.length)[0]) == null ? void 0 : o.module;
40
- }, Re = () => {
41
- const [a, l] = v(!1);
42
- return R(() => {
43
- const o = () => l(window.scrollY > 0);
44
- return o(), window.addEventListener("scroll", o, { passive: !0 }), () => window.removeEventListener("scroll", o);
45
- }, []), a;
46
- }, Ae = ({ size: a = 30, className: l }) => {
47
- const o = A(), r = (u) => l ? `${u} ${l}` : u;
48
- return o.markUrl ? /* @__PURE__ */ t(
49
- "span",
50
- {
51
- className: r(e.logoMark),
52
- style: { width: a, height: a, backgroundImage: `url("${o.markUrl}")` },
53
- "aria-hidden": "true"
54
- }
55
- ) : /* @__PURE__ */ t("span", { className: r(e.letterMark), style: { width: a, height: a }, "aria-hidden": "true", children: Array.from(o.mark).slice(0, 2).join("") });
56
- }, Fe = ({
57
- modules: a = [],
58
- activeModuleKey: l,
59
- moduleTarget: o,
60
- sidebar: r = [],
61
- selectedKey: u,
62
- renderItemLabel: b,
63
- headerRight: U,
64
- menuLabel: E = "工作台菜单",
65
- children: K,
66
- extra: P
67
- }) => {
68
- var S;
69
- const { config: I } = te(), C = A(), y = Y(), k = q(), M = I.routes.app, h = J(M, V(ne())), B = X(M, y.pathname), p = B ? [] : r ?? [], w = p.length > 0, W = l ?? ((S = $e(a, y.pathname)) == null ? void 0 : S.key), m = Ge([...p, h], y.pathname), L = u ?? (m == null ? void 0 : m.key), i = ae("(min-width: 992px)"), j = Re(), [_, g] = v(!i), [N, d] = v(!1), H = new Map([...p, h].flatMap((n) => n.items.map((s) => [s.key, s])));
70
- R(() => {
71
- g(!i), d(!1);
72
- }, [i]);
73
- const T = (n) => {
74
- const s = H.get(n);
75
- s && k(s.to), d(!1);
76
- };
77
- return /* @__PURE__ */ c(f, { className: e.layout, children: [
78
- /* @__PURE__ */ c(f.Header, { className: e.header, "data-scrolled": j ? "true" : "false", children: [
79
- /* @__PURE__ */ c("div", { className: e.headerLeft, children: [
80
- /* @__PURE__ */ c(
81
- x,
82
- {
83
- theme: "borderless",
84
- type: "tertiary",
85
- className: e.logo,
86
- "aria-label": `${C.shortName} 首页`,
87
- onClick: () => k(I.routes.publicHome),
88
- children: [
89
- /* @__PURE__ */ t(Ae, {}),
90
- /* @__PURE__ */ t(F.Text, { className: e.logoText, children: C.shortName })
91
- ]
92
- }
93
- ),
94
- a.length ? /* @__PURE__ */ t("div", { className: e.modules, role: "navigation", "aria-label": "产品模块", children: a.map((n) => /* @__PURE__ */ c(
95
- x,
96
- {
97
- theme: "borderless",
98
- type: "tertiary",
99
- className: e.module,
100
- "aria-current": W === n.key ? "page" : void 0,
101
- onClick: () => k(o ? o(n) : n.to),
102
- children: [
103
- /* @__PURE__ */ c("span", { className: e.moduleText, children: [
104
- n.icon ? /* @__PURE__ */ t("span", { className: e.moduleIcon, children: /* @__PURE__ */ t(n.icon, {}) }) : null,
105
- n.label
106
- ] }),
107
- /* @__PURE__ */ t("span", { className: e.moduleInk, "aria-hidden": "true" })
108
- ]
109
- },
110
- n.key
111
- )) }) : null
112
- ] }),
113
- /* @__PURE__ */ t(Q, { spacing: 10, className: e.headerRight, children: U ?? /* @__PURE__ */ c(O, { children: [
114
- /* @__PURE__ */ t(Z, {}),
115
- /* @__PURE__ */ t(z, {}),
116
- /* @__PURE__ */ t(ee, { personal: h, selectedKey: m && h.items.includes(m) ? m.key : void 0, onOpen: T })
117
- ] }) })
118
- ] }),
119
- /* @__PURE__ */ c(f, { className: e.body, children: [
120
- w ? /* @__PURE__ */ t("aside", { className: e.sider, "data-collapsed": _ ? "true" : "false", children: /* @__PURE__ */ c(
121
- "div",
122
- {
123
- className: e.siderInner,
124
- "data-collapsed": _ ? "true" : "false",
125
- "data-peek": N ? "true" : "false",
126
- onMouseEnter: () => {
127
- _ && i && d(!0);
128
- },
129
- onMouseLeave: () => {
130
- i && d(!1);
131
- },
132
- children: [
133
- _ ? /* @__PURE__ */ t(
134
- x,
135
- {
136
- theme: "light",
137
- type: "tertiary",
138
- className: e.expandButton,
139
- icon: /* @__PURE__ */ t($, { "aria-hidden": "true" }),
140
- "aria-label": "展开侧边栏",
141
- "aria-expanded": N,
142
- onClick: () => {
143
- i ? (g(!1), d(!1)) : d((n) => !n);
144
- }
145
- }
146
- ) : null,
147
- /* @__PURE__ */ c("div", { className: e.panel, children: [
148
- /* @__PURE__ */ t("nav", { className: e.menu, "aria-label": E, children: p.map((n) => /* @__PURE__ */ c("div", { className: e.menuGroup, role: "group", "aria-label": n.label || void 0, children: [
149
- n.label ? /* @__PURE__ */ t("div", { className: e.menuGroupTitle, children: n.label }) : null,
150
- /* @__PURE__ */ t(
151
- G,
152
- {
153
- mode: "vertical",
154
- className: e.menuList,
155
- selectedKeys: L ? [L] : [],
156
- onSelect: ({ itemKey: s }) => T(String(s)),
157
- children: n.items.map((s) => /* @__PURE__ */ t(
158
- G.Item,
159
- {
160
- itemKey: s.key,
161
- icon: s.icon ? /* @__PURE__ */ t(s.icon, {}) : void 0,
162
- text: b ? b(s) : s.label
163
- },
164
- s.key
165
- ))
166
- }
167
- )
168
- ] }, n.key)) }),
169
- i ? /* @__PURE__ */ t(
170
- x,
171
- {
172
- theme: "borderless",
173
- type: "tertiary",
174
- className: e.collapseButton,
175
- icon: /* @__PURE__ */ t($, { "aria-hidden": "true" }),
176
- onClick: () => {
177
- g((n) => !n), d(!1);
178
- },
179
- children: _ ? "固定侧边栏" : "收起侧边栏"
180
- }
181
- ) : null
182
- ] })
183
- ]
184
- }
185
- ) }) : null,
186
- N && !i && w ? /* @__PURE__ */ t("div", { className: e.mask, "aria-hidden": "true", onClick: () => d(!1) }) : null,
187
- /* @__PURE__ */ t(f.Content, { className: B ? `${e.content} ${e.contentCentered}` : e.content, children: /* @__PURE__ */ t("div", { className: e.contentInner, children: K ?? /* @__PURE__ */ t(D, {}) }) })
188
- ] }),
189
- P
190
- ] });
191
- };
192
- export {
193
- Ae as B,
194
- Fe as C,
195
- Ge as a,
196
- $e as f,
197
- Se as i
198
- };