@haklex/rich-style-token 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Innei
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+
24
+ Additional Terms and Conditions
25
+
26
+ ----------------
27
+
28
+ Use of this software is governed by the terms of MIT and, in addition, by the terms and conditions described in the additional file (ADDITIONAL_TERMS.md). By using this software, you agree to abide by these additional terms and conditions.
package/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # @haklex/rich-style-token
2
+
3
+ 设计令牌和 CSS 变量,基于 Vanilla Extract 实现零运行时样式。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pnpm add @haklex/rich-style-token
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```tsx
14
+ import { vars } from '@haklex/rich-style-token'
15
+ import { style } from '@vanilla-extract/css'
16
+
17
+ export const container = style({
18
+ color: vars.color.text,
19
+ padding: vars.spacing.md,
20
+ borderRadius: vars.borderRadius.md,
21
+ })
22
+ ```
23
+
24
+ ## 导出
25
+
26
+ ```ts
27
+ // CSS 变量契约
28
+ export { vars } from './vars.css'
29
+
30
+ // 主题配置
31
+ export { articleLayout, commentLayout, noteLayout } from './themes'
32
+ export { serifFonts, sharedFonts } from './themes'
33
+ export { darkColors, lightArticleColors, lightCommentColors } from './themes'
34
+
35
+ // Portal 主题
36
+ export { PortalThemeProvider, PortalThemeWrapper, usePortalTheme } from './portal-theme'
37
+ ```
38
+
39
+ ## 变量结构
40
+
41
+ ### vars.color
42
+
43
+ ```ts
44
+ vars.color.text // 主文本色
45
+ vars.color.textSecondary // 次要文本
46
+ vars.color.bg // 背景色
47
+ vars.color.bgSecondary // 次要背景
48
+ vars.color.border // 边框色
49
+ vars.color.accent // 强调色
50
+ vars.color.accentLight // 浅强调色
51
+ vars.color.link // 链接色
52
+ vars.color.codeText // 代码文本
53
+ vars.color.codeBg // 代码背景
54
+ vars.color.quoteBorder // 引用边框
55
+ vars.color.quoteBg // 引用背景
56
+ vars.color.alertInfo // 提示色
57
+ vars.color.alertWarning // 警告色
58
+ vars.color.alertTip // 建议色
59
+ vars.color.alertCaution // 注意色
60
+ vars.color.alertImportant // 重要色
61
+ ```
62
+
63
+ ### vars.spacing
64
+
65
+ ```ts
66
+ vars.spacing.xs // article: 4px, comment: 2px
67
+ vars.spacing.sm // article: 8px, comment: 4px
68
+ vars.spacing.md // article: 16px, comment: 10px
69
+ vars.spacing.lg // article: 24px, comment: 16px
70
+ vars.spacing.xl // article: 32px, comment: 20px
71
+ ```
72
+
73
+ ### vars.typography
74
+
75
+ ```ts
76
+ vars.typography.fontFamily // 字体族
77
+ vars.typography.fontMono // 等宽字体
78
+ vars.typography.fontSizeBase // 基础字号
79
+ vars.typography.fontSizeSmall // 小字号
80
+ vars.typography.fontSizeLarge // 大字号
81
+ vars.typography.lineHeight // 行高
82
+ vars.typography.lineHeightTight // 紧行高
83
+ ```
84
+
85
+ ### vars.borderRadius
86
+
87
+ ```ts
88
+ vars.borderRadius.sm // article: 4px, comment: 3px
89
+ vars.borderRadius.md // article: 8px, comment: 6px
90
+ vars.borderRadius.lg // article: 12px, comment: 8px
91
+ ```
92
+
93
+ ## 预设主题
94
+
95
+ ```ts
96
+ import {
97
+ lightArticleColors,
98
+ darkColors,
99
+ articleLayout
100
+ } from '@haklex/rich-style-token'
101
+
102
+ // 浅色文章主题
103
+ lightArticleColors.text // '#1a1a1a'
104
+ lightArticleColors.accent // '#33A6B8'
105
+
106
+ // 深色主题
107
+ darkColors.text // '#e5e5e5'
108
+ darkColors.accent // '#F596AA'
109
+
110
+ // 布局配置
111
+ articleLayout.typography.fontSizeBase // '16px'
112
+ articleLayout.typography.lineHeight // '1.7'
113
+ ```
114
+
115
+ ## 依赖
116
+
117
+ ```json
118
+ {
119
+ "@vanilla-extract/css": "^1.17.1",
120
+ "react": ">=19"
121
+ }
122
+ ```
123
+
124
+ ## License
125
+
126
+ MIT
@@ -0,0 +1,4 @@
1
+ export { PortalThemeProvider, PortalThemeWrapper, usePortalTheme, } from './portal-theme';
2
+ export { articleLayout, commentLayout, darkColors, lightArticleColors, lightCommentColors, noteLayout, serifFonts, sharedFonts, } from './themes';
3
+ export { vars } from './vars.css';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACV,UAAU,EACV,WAAW,GACZ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,127 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext, useMemo, use } from "react";
3
+ const PortalThemeContext = createContext({
4
+ className: ""
5
+ });
6
+ function PortalThemeProvider({
7
+ className,
8
+ children
9
+ }) {
10
+ return /* @__PURE__ */ jsx(
11
+ PortalThemeContext.Provider,
12
+ {
13
+ value: useMemo(() => ({ className }), [className]),
14
+ children
15
+ }
16
+ );
17
+ }
18
+ function usePortalTheme() {
19
+ return use(PortalThemeContext);
20
+ }
21
+ function PortalThemeWrapper({ children }) {
22
+ const { className } = usePortalTheme();
23
+ if (!className) return children;
24
+ return /* @__PURE__ */ jsx("div", { style: { display: "contents" }, className, children });
25
+ }
26
+ const sharedFonts = {
27
+ fontFamily: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
28
+ fontMono: '"SF Mono", SFMono-Regular, ui-monospace, "DejaVu Sans Mono", Menlo, Consolas, monospace'
29
+ };
30
+ const serifFonts = {
31
+ fontFamily: '"Noto Serif CJK SC", "Source Han Serif SC", "Source Han Serif", "source-han-serif-sc", "Songti SC", STSong, "华文宋体", serif',
32
+ fontMono: sharedFonts.fontMono
33
+ };
34
+ const lightArticleColors = {
35
+ text: "#1a1a1a",
36
+ textSecondary: "#6b7280",
37
+ bg: "#ffffff",
38
+ bgSecondary: "#f9fafb",
39
+ border: "#e5e7eb",
40
+ accent: "#33A6B8",
41
+ accentLight: "#33A6B833",
42
+ link: "#33A6B8",
43
+ codeText: "#e83e8c",
44
+ codeBg: "#f3f4f6",
45
+ quoteBorder: "#33A6B8",
46
+ quoteBg: "#f0f9fb",
47
+ alertInfo: "#3b82f6",
48
+ alertWarning: "#f59e0b",
49
+ alertTip: "#22c55e",
50
+ alertCaution: "#ef4444",
51
+ alertImportant: "#a855f7"
52
+ };
53
+ const lightCommentColors = {
54
+ ...lightArticleColors,
55
+ quoteBorder: "#9ca3af",
56
+ quoteBg: "#f9fafb"
57
+ };
58
+ const darkColors = {
59
+ text: "#e5e5e5",
60
+ textSecondary: "#a3a3a3",
61
+ bg: "#171717",
62
+ bgSecondary: "#262626",
63
+ border: "#404040",
64
+ accent: "#F596AA",
65
+ accentLight: "#F596AA33",
66
+ link: "#F596AA",
67
+ codeText: "#f472b6",
68
+ codeBg: "#262626",
69
+ quoteBorder: "#F596AA",
70
+ quoteBg: "#262626",
71
+ alertInfo: "#60a5fa",
72
+ alertWarning: "#fbbf24",
73
+ alertTip: "#4ade80",
74
+ alertCaution: "#f87171",
75
+ alertImportant: "#c084fc"
76
+ };
77
+ const articleLayout = {
78
+ spacing: { xs: "4px", sm: "8px", md: "16px", lg: "24px", xl: "32px" },
79
+ typography: {
80
+ ...sharedFonts,
81
+ fontSizeBase: "16px",
82
+ fontSizeSmall: "14px",
83
+ fontSizeLarge: "18px",
84
+ lineHeight: "1.7",
85
+ lineHeightTight: "1.4"
86
+ },
87
+ borderRadius: { sm: "4px", md: "8px", lg: "12px" }
88
+ };
89
+ const noteLayout = {
90
+ spacing: articleLayout.spacing,
91
+ typography: {
92
+ ...serifFonts,
93
+ fontSizeBase: "16px",
94
+ fontSizeSmall: "14px",
95
+ fontSizeLarge: "18px",
96
+ lineHeight: "1.8",
97
+ lineHeightTight: "1.4"
98
+ },
99
+ borderRadius: articleLayout.borderRadius
100
+ };
101
+ const commentLayout = {
102
+ spacing: { xs: "2px", sm: "4px", md: "10px", lg: "16px", xl: "20px" },
103
+ typography: {
104
+ ...sharedFonts,
105
+ fontSizeBase: "14px",
106
+ fontSizeSmall: "12px",
107
+ fontSizeLarge: "15px",
108
+ lineHeight: "1.5",
109
+ lineHeightTight: "1.3"
110
+ },
111
+ borderRadius: { sm: "3px", md: "6px", lg: "8px" }
112
+ };
113
+ var vars = { color: { text: "var(--rc-text)", textSecondary: "var(--rc-text-secondary)", bg: "var(--rc-bg)", bgSecondary: "var(--rc-bg-secondary)", border: "var(--rc-border)", accent: "var(--rc-accent)", accentLight: "var(--rc-accent-light)", link: "var(--rc-link)", codeText: "var(--rc-code-text)", codeBg: "var(--rc-code-bg)", quoteBorder: "var(--rc-quote-border)", quoteBg: "var(--rc-quote-bg)", alertInfo: "var(--rc-alert-info)", alertWarning: "var(--rc-alert-warning)", alertTip: "var(--rc-alert-tip)", alertCaution: "var(--rc-alert-caution)", alertImportant: "var(--rc-alert-important)" }, spacing: { xs: "var(--rc-space-xs)", sm: "var(--rc-space-sm)", md: "var(--rc-space-md)", lg: "var(--rc-space-lg)", xl: "var(--rc-space-xl)" }, typography: { fontFamily: "var(--rc-font-family)", fontMono: "var(--rc-font-mono)", fontSizeBase: "var(--rc-font-size-base)", fontSizeSmall: "var(--rc-font-size-small)", fontSizeLarge: "var(--rc-font-size-large)", lineHeight: "var(--rc-line-height)", lineHeightTight: "var(--rc-line-height-tight)" }, borderRadius: { sm: "var(--rc-radius-sm)", md: "var(--rc-radius-md)", lg: "var(--rc-radius-lg)" } };
114
+ export {
115
+ PortalThemeProvider,
116
+ PortalThemeWrapper,
117
+ articleLayout,
118
+ commentLayout,
119
+ darkColors,
120
+ lightArticleColors,
121
+ lightCommentColors,
122
+ noteLayout,
123
+ serifFonts,
124
+ sharedFonts,
125
+ usePortalTheme,
126
+ vars
127
+ };
@@ -0,0 +1,14 @@
1
+ import { ReactNode } from 'react';
2
+ type PortalThemeContextType = {
3
+ className: string;
4
+ };
5
+ export declare function PortalThemeProvider({ className, children, }: {
6
+ className: string;
7
+ children?: ReactNode;
8
+ }): import("react/jsx-runtime").JSX.Element;
9
+ export declare function usePortalTheme(): PortalThemeContextType;
10
+ export declare function PortalThemeWrapper({ children }: {
11
+ children: ReactNode;
12
+ }): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
13
+ export {};
14
+ //# sourceMappingURL=portal-theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-theme.d.ts","sourceRoot":"","sources":["../src/portal-theme.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGtC,KAAK,sBAAsB,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAMD,wBAAgB,mBAAmB,CAAC,EAClC,SAAS,EACT,QAAQ,GACT,EAAE;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB,2CAQA;AAED,wBAAgB,cAAc,2BAE7B;AAED,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2UAQvE"}
@@ -0,0 +1,135 @@
1
+ export declare const sharedFonts: {
2
+ fontFamily: string;
3
+ fontMono: string;
4
+ };
5
+ export declare const serifFonts: {
6
+ fontFamily: string;
7
+ fontMono: string;
8
+ };
9
+ export declare const lightArticleColors: {
10
+ text: string;
11
+ textSecondary: string;
12
+ bg: string;
13
+ bgSecondary: string;
14
+ border: string;
15
+ accent: string;
16
+ accentLight: string;
17
+ link: string;
18
+ codeText: string;
19
+ codeBg: string;
20
+ quoteBorder: string;
21
+ quoteBg: string;
22
+ alertInfo: string;
23
+ alertWarning: string;
24
+ alertTip: string;
25
+ alertCaution: string;
26
+ alertImportant: string;
27
+ };
28
+ export declare const lightCommentColors: {
29
+ quoteBorder: string;
30
+ quoteBg: string;
31
+ text: string;
32
+ textSecondary: string;
33
+ bg: string;
34
+ bgSecondary: string;
35
+ border: string;
36
+ accent: string;
37
+ accentLight: string;
38
+ link: string;
39
+ codeText: string;
40
+ codeBg: string;
41
+ alertInfo: string;
42
+ alertWarning: string;
43
+ alertTip: string;
44
+ alertCaution: string;
45
+ alertImportant: string;
46
+ };
47
+ export declare const darkColors: {
48
+ text: string;
49
+ textSecondary: string;
50
+ bg: string;
51
+ bgSecondary: string;
52
+ border: string;
53
+ accent: string;
54
+ accentLight: string;
55
+ link: string;
56
+ codeText: string;
57
+ codeBg: string;
58
+ quoteBorder: string;
59
+ quoteBg: string;
60
+ alertInfo: string;
61
+ alertWarning: string;
62
+ alertTip: string;
63
+ alertCaution: string;
64
+ alertImportant: string;
65
+ };
66
+ export declare const articleLayout: {
67
+ spacing: {
68
+ xs: string;
69
+ sm: string;
70
+ md: string;
71
+ lg: string;
72
+ xl: string;
73
+ };
74
+ typography: {
75
+ fontSizeBase: string;
76
+ fontSizeSmall: string;
77
+ fontSizeLarge: string;
78
+ lineHeight: string;
79
+ lineHeightTight: string;
80
+ fontFamily: string;
81
+ fontMono: string;
82
+ };
83
+ borderRadius: {
84
+ sm: string;
85
+ md: string;
86
+ lg: string;
87
+ };
88
+ };
89
+ export declare const noteLayout: {
90
+ spacing: {
91
+ xs: string;
92
+ sm: string;
93
+ md: string;
94
+ lg: string;
95
+ xl: string;
96
+ };
97
+ typography: {
98
+ fontSizeBase: string;
99
+ fontSizeSmall: string;
100
+ fontSizeLarge: string;
101
+ lineHeight: string;
102
+ lineHeightTight: string;
103
+ fontFamily: string;
104
+ fontMono: string;
105
+ };
106
+ borderRadius: {
107
+ sm: string;
108
+ md: string;
109
+ lg: string;
110
+ };
111
+ };
112
+ export declare const commentLayout: {
113
+ spacing: {
114
+ xs: string;
115
+ sm: string;
116
+ md: string;
117
+ lg: string;
118
+ xl: string;
119
+ };
120
+ typography: {
121
+ fontSizeBase: string;
122
+ fontSizeSmall: string;
123
+ fontSizeLarge: string;
124
+ lineHeight: string;
125
+ lineHeightTight: string;
126
+ fontFamily: string;
127
+ fontMono: string;
128
+ };
129
+ borderRadius: {
130
+ sm: string;
131
+ md: string;
132
+ lg: string;
133
+ };
134
+ };
135
+ //# sourceMappingURL=themes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themes.d.ts","sourceRoot":"","sources":["../src/themes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW;;;CAKvB,CAAA;AAED,eAAO,MAAM,UAAU;;;CAItB,CAAA;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;CAkB9B,CAAA;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;CAI9B,CAAA;AAED,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;CAkBtB,CAAA;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;CAWzB,CAAA;AAED,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;CAWtB,CAAA;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;CAWzB,CAAA"}
@@ -0,0 +1,43 @@
1
+ export declare const vars: {
2
+ color: {
3
+ text: `var(--${string})`;
4
+ textSecondary: `var(--${string})`;
5
+ bg: `var(--${string})`;
6
+ bgSecondary: `var(--${string})`;
7
+ border: `var(--${string})`;
8
+ accent: `var(--${string})`;
9
+ accentLight: `var(--${string})`;
10
+ link: `var(--${string})`;
11
+ codeText: `var(--${string})`;
12
+ codeBg: `var(--${string})`;
13
+ quoteBorder: `var(--${string})`;
14
+ quoteBg: `var(--${string})`;
15
+ alertInfo: `var(--${string})`;
16
+ alertWarning: `var(--${string})`;
17
+ alertTip: `var(--${string})`;
18
+ alertCaution: `var(--${string})`;
19
+ alertImportant: `var(--${string})`;
20
+ };
21
+ spacing: {
22
+ xs: `var(--${string})`;
23
+ sm: `var(--${string})`;
24
+ md: `var(--${string})`;
25
+ lg: `var(--${string})`;
26
+ xl: `var(--${string})`;
27
+ };
28
+ typography: {
29
+ fontFamily: `var(--${string})`;
30
+ fontMono: `var(--${string})`;
31
+ fontSizeBase: `var(--${string})`;
32
+ fontSizeSmall: `var(--${string})`;
33
+ fontSizeLarge: `var(--${string})`;
34
+ lineHeight: `var(--${string})`;
35
+ lineHeightTight: `var(--${string})`;
36
+ };
37
+ borderRadius: {
38
+ sm: `var(--${string})`;
39
+ md: `var(--${string})`;
40
+ lg: `var(--${string})`;
41
+ };
42
+ };
43
+ //# sourceMappingURL=vars.css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vars.css.d.ts","sourceRoot":"","sources":["../src/vars.css.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCf,CAAA"}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@haklex/rich-style-token",
3
+ "version": "0.0.1",
4
+ "description": "Style tokens and CSS variables for haklex rich editor",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "main": "./dist/index.mjs",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "devDependencies": {
18
+ "@types/react": "^19.2.9",
19
+ "@vanilla-extract/css": "^1.17.1",
20
+ "@vanilla-extract/vite-plugin": "^4.0.20",
21
+ "react": ">=19",
22
+ "typescript": "^5.9.0",
23
+ "vite": "^7.3.1",
24
+ "vite-plugin-dts": "^4.5.0"
25
+ },
26
+ "peerDependencies": {
27
+ "react": ">=19"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "build": "vite build",
34
+ "dev:build": "vite build --watch"
35
+ },
36
+ "types": "./dist/index.d.ts"
37
+ }