@hezhijie0327/zjdesign 0.0.0-stage → 0.1.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/AGENTS.md +106 -0
- package/DESIGN.md +98 -0
- package/LICENSE +39 -0
- package/README.md +89 -2
- package/dist/brand/index.d.mts +19 -0
- package/dist/brand/index.mjs +18 -0
- package/dist/hooks/index.d.mts +2 -0
- package/dist/hooks/index.mjs +3 -0
- package/dist/hooks-_Gk75q-U.mjs +220 -0
- package/dist/index-B-bZqvO6.d.mts +101 -0
- package/dist/index.d.mts +256 -0
- package/dist/index.mjs +421 -0
- package/dist/paper/index.d.mts +20 -0
- package/dist/paper/index.mjs +35 -0
- package/dist/styles/index.d.mts +118 -0
- package/dist/styles/index.mjs +3 -0
- package/dist/styles-CZ-LL-aM.mjs +123 -0
- package/dist/tokens/base.css +133 -0
- package/dist/tokens/behaviors.css +115 -0
- package/dist/tokens/index.css +8 -0
- package/dist/tokens/paper.css +207 -0
- package/dist/tokens/tokens.css +316 -0
- package/package.json +99 -4
package/AGENTS.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
ZJ Design (`@hezhijie0327/zjdesign`) — the shared design system of the ZJ product family (ZJBlog / ZJKVM / ZJSearch / ZJStudio): warm paper, ink text, amber gold. It packages the family's design tokens (CSS), Tailwind class fragments, theme hooks and React components so the four apps consume one versioned source instead of repo-local copies. Design language reference: [DESIGN.md](DESIGN.md); human-facing docs: [README.md](README.md).
|
|
4
|
+
|
|
5
|
+
## Behavioral Guidelines
|
|
6
|
+
|
|
7
|
+
**Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment.
|
|
8
|
+
|
|
9
|
+
### 1. Think Before Coding
|
|
10
|
+
|
|
11
|
+
**Don't assume. Don't hide confusion. Surface tradeoffs.**
|
|
12
|
+
|
|
13
|
+
- State assumptions explicitly; ask when uncertain.
|
|
14
|
+
- If multiple interpretations exist, present them — don't pick silently.
|
|
15
|
+
- If a simpler approach exists, say so. Push back when warranted.
|
|
16
|
+
|
|
17
|
+
### 2. Simplicity First
|
|
18
|
+
|
|
19
|
+
**Minimum code that solves the problem. Nothing speculative.**
|
|
20
|
+
|
|
21
|
+
- No features beyond what was asked; no abstractions for single-use code.
|
|
22
|
+
- No "flexibility" or "configurability" that wasn't requested.
|
|
23
|
+
|
|
24
|
+
### 3. Surgical Changes
|
|
25
|
+
|
|
26
|
+
**Touch only what you must. Clean up only your own mess.**
|
|
27
|
+
|
|
28
|
+
- Match existing style; don't refactor what isn't broken.
|
|
29
|
+
- Remove only what your own change orphaned.
|
|
30
|
+
|
|
31
|
+
### 4. Goal-Driven Execution
|
|
32
|
+
|
|
33
|
+
**Define success criteria. Loop until verified.**
|
|
34
|
+
|
|
35
|
+
For every change: `pnpm lint && pnpm check && pnpm test && pnpm build` must pass, and visual changes must be verified in the playground (`pnpm dev`) against all three palette tiers (light / dark / black).
|
|
36
|
+
|
|
37
|
+
## Git commit convention
|
|
38
|
+
|
|
39
|
+
Every commit subject starts with a type prefix — `feat` / `fix` / `chore` / `docs` / `revert` / `refactor` / `perf` / `test` / `build` — optionally scoped: `fix(modal): ...`. Subject: imperative, lowercase start, no trailing period, aim ≤ 72 chars; detail goes in the body after a blank line (why, not what). Never rewrite pushed history.
|
|
40
|
+
|
|
41
|
+
Commit incrementally — one logical change per commit, after lint and tests pass. Only ONE co-author line is allowed:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
Co-authored-by: ZCode <noreply@z.ai>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Documentation format
|
|
48
|
+
|
|
49
|
+
- **Language**: AGENTS.md, DESIGN.md are English; README.md is Chinese (human-facing). Keep literal UI strings and code identifiers verbatim.
|
|
50
|
+
- **Formatting**: ATX headings (`#`), never skip a level; code fences always carry a language tag; tables for structured reference; no decorative emoji in headings or bullets; bold for key terms only.
|
|
51
|
+
|
|
52
|
+
## Project
|
|
53
|
+
|
|
54
|
+
**Architecture: single package, multi-entry** (lobe-ui style). One npm package `@hezhijie0327/zjdesign`, five JS subpaths plus a CSS subpath:
|
|
55
|
+
|
|
56
|
+
| Subpath | Contents |
|
|
57
|
+
| ---------- | ------------------------------------------------------------------- |
|
|
58
|
+
| `.` | React components + hooks (re-exports `components/` and `hooks/`) |
|
|
59
|
+
| `./styles` | `cn()` + class fragments (`fragments.ts`) |
|
|
60
|
+
| `./hooks` | theme controller / `useTheme` / `useExitPresence` / `reducedMotion` |
|
|
61
|
+
| `./paper` | `Tape` + `tapePhysics` (seed physics) |
|
|
62
|
+
| `./brand` | `Wordmark` |
|
|
63
|
+
| `./tokens` | CSS entry (also `./tokens/*.css` per file) |
|
|
64
|
+
|
|
65
|
+
Layering (strict, top depends on bottom only):
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
tokens (CSS) ← styles (fragments + cn) ← hooks ← components / paper / brand
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Key constraints:**
|
|
72
|
+
|
|
73
|
+
1. **Tokens are the family contract.** `src/tokens/tokens.css` values must stay byte-identical to the family contract (ZJBlog DESIGN.md §3). Changing a value is a spec change: update DESIGN.md first, then sync, then release a minor bump. Never add raw colors anywhere else.
|
|
74
|
+
2. **Fragments before classes.** Recurring Tailwind combinations must be added to `src/styles/fragments.ts` and consumed via `className={FRAGMENT}` + `cn()` overrides — never hand-write long class strings inside components.
|
|
75
|
+
3. **Styling = Tailwind utilities only** inside components. CSS files under `src/tokens/` carry only what utilities cannot reach (@property registrations, pseudo-elements, clip-path paper language, document behaviors). If a widget skin is needed (e.g. `.zj-range` for range pseudo-elements), it lives there and must be token-driven.
|
|
76
|
+
4. **Peer deps only.** `react`, `react-dom`, `lucide-react`, `tailwindcss` are peer dependencies; runtime deps are limited to `clsx` + `tailwind-merge`. Do not add state libraries (jotai etc.) — the Toast bus is deliberately dependency-free.
|
|
77
|
+
5. **Consumers scan the dist.** Fragment classes live in shipped JS; consumer Tailwind setup must `@source` the package (see README). Never rely on utilities that only exist in an app's own source.
|
|
78
|
+
|
|
79
|
+
## Commands
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pnpm install # install
|
|
83
|
+
pnpm build # tsdown build → dist/ (JS + dts + copied CSS)
|
|
84
|
+
pnpm check # tsc --noEmit
|
|
85
|
+
pnpm lint # biome check .
|
|
86
|
+
pnpm lint:fix # biome check --write .
|
|
87
|
+
pnpm test # vitest run (jsdom)
|
|
88
|
+
pnpm dev # vite playground (visual verification, :5199 in docs)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Release: bump version in `package.json`, `pnpm build && pnpm test && pnpm lint && pnpm check`, `npm publish` (publishConfig pins the official registry). npm package names are lowercase — the scope is `@hezhijie0327`, package `zjdesign`.
|
|
92
|
+
|
|
93
|
+
## Conventions
|
|
94
|
+
|
|
95
|
+
- **Named export only**, no default exports; explicit `.ts` / `.tsx` import extensions (bundler resolution + `allowImportingTsExtensions`).
|
|
96
|
+
- **Biome 2.6**: 2-space indent, 120 cols, double quotes, semicolons, trailing commas.
|
|
97
|
+
- TypeScript strict + `noUncheckedIndexedAccess` + `verbatimModuleSyntax`.
|
|
98
|
+
- Every component directory: `Widget.tsx` + `index.ts` (lobe-ui layout). Tests live in `/tests` (flat, family repo style).
|
|
99
|
+
- Gotcha: `tapePhysics` shifts MUST use logical `>>>` (arithmetic `>>` sign-extends int32 and breaks the spec range — see DESIGN.md §7). Do not change its constants; the visual spec lives in DESIGN.md and is two-way synced with the family repos.
|
|
100
|
+
- Gotcha: jsdom lacks `matchMedia` — `tests/setup.ts` stubs it globally; add new matchMedia-dependent setup there.
|
|
101
|
+
|
|
102
|
+
## Key Docs
|
|
103
|
+
|
|
104
|
+
- [DESIGN.md](DESIGN.md) — design language spec (tokens, fragments, paper physics, motion)
|
|
105
|
+
- [README.md](README.md) — Chinese user docs: install, consumer setup, component list
|
|
106
|
+
- Family repos: `C:\Users\zhijie.he\Lab\{blog,ZJKVM,searxng,ZJStudio}` (consumer apps during migration)
|
package/DESIGN.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# DESIGN.md
|
|
2
|
+
|
|
3
|
+
The ZJ family design language, packaged. This file is the packaging repo's view of the family contract; the authoritative narrative lives in ZJBlog's DESIGN.md (§1–18). Values below are normative for this package — token values must stay byte-identical across the family.
|
|
4
|
+
|
|
5
|
+
## 1. Design principles
|
|
6
|
+
|
|
7
|
+
- **Warm paper × ink × amber gold**: page ground is warm paper (`--bg`), text is ink (`--ink`), the single accent family is amber gold (`--accent*`).
|
|
8
|
+
- **Paper physics**: decorations imitate physical paper (torn edges, tape, postmarks) and follow deterministic physics — never random, so SSR and hydration agree.
|
|
9
|
+
- **Editorial typography**: serif for headings and long-form (`--font-serif`), sans for UI chrome, mono for meta and code. Zero webfonts — system stacks only.
|
|
10
|
+
- **Restraint**: three surface tiers (`--bg` → `--surface` → `--surface-2`), two elevations (`--shadow-card` → `--shadow-pop`), three palette tiers (light / dark / black-OLED).
|
|
11
|
+
- **Motion contract**: every interactive surface has enter/exit animations with timeout fallbacks; global `prefers-reduced-motion` gate.
|
|
12
|
+
|
|
13
|
+
## 2. Tokens (`src/tokens/tokens.css`)
|
|
14
|
+
|
|
15
|
+
All color tokens are registered as `<color>` `@property` (initial-value = light tier). When `html.dark` flips, the variables interpolate on `<html>` — one transition (behaviors.css) drives the whole-page cross-fade. `.black` (OLED, declared after `.dark`) overrides surface/line/ink neutrals only; gold stays.
|
|
16
|
+
|
|
17
|
+
| Token | Light | Dark | Black | Role |
|
|
18
|
+
| ------------------------- | ----------------------------- | --------------------- | ------------ | ------------------------------------------------------------------------------------------ |
|
|
19
|
+
| `--bg` | `#faf9f6` | `#1b1a18` | `#000000` | page ground |
|
|
20
|
+
| `--surface` | `#ffffff` | `#232120` | `#0b0b0c` | cards / panels |
|
|
21
|
+
| `--surface-2` | `#f1efe8` | `#2c2a27` | `#161617` | hover ground / secondary surface |
|
|
22
|
+
| `--line` | `#e6e2d7` | `#38342f` | `#242426` | hairlines / strokes |
|
|
23
|
+
| `--ink` | `#201d17` | `#eceae4` | `#ececec` | primary text |
|
|
24
|
+
| `--ink-2` | `#6b675c` | `#a8a399` | `#9a9a9a` | secondary text |
|
|
25
|
+
| `--ink-3` | `#716c61` | `#9b958a` | `#828282` | meta text (≥4.5:1) |
|
|
26
|
+
| `--accent` | `#8c6800` | `#fec843` | dark | **text** accent (links / chips) |
|
|
27
|
+
| `--accent-hover` | `#7a5c00` | `#ffd76b` | dark | text accent hover |
|
|
28
|
+
| `--accent-strong` | `#f5c84c` | `#fec843` | dark | **fill** accent (primary buttons / selected pills); text on it must be `--accent-contrast` |
|
|
29
|
+
| `--accent-strong-hover` | `#eebd35` | `#ffd76b` | dark | fill accent hover |
|
|
30
|
+
| `--accent-soft` | `#faf0cf` | `#3a3320` | `#292413` | soft accent ground (tape / icon tiles) |
|
|
31
|
+
| `--accent-contrast` | `#241d0e` | `#241d0e` | dark | text on gold fills (mandatory) |
|
|
32
|
+
| `--highlight-bg` | `#fde68a` | `#4a4020` | `#3d3617` | highlights / selection |
|
|
33
|
+
| `--danger` | `#dc2626` | `#f87171` | dark | destructive / errors |
|
|
34
|
+
| `--warning` | `#b45309` | `#fbbf24` | dark | connecting / pending |
|
|
35
|
+
| `--ok` | `#15803d` | `#4ade80` | dark | success / connected |
|
|
36
|
+
| `--code-bg` / `--code-fg` | `#fbfaf6` / `#24211a` | `#0d0b08` / `#e0d9c8` | dark | code blocks |
|
|
37
|
+
| `--shadow-card` | warm 5% | black 35/30% | black 60/50% | static cards |
|
|
38
|
+
| `--shadow-pop` | warm 7/16% | black 45/55% | — | overlays / hover lift |
|
|
39
|
+
| `--scrim` | `rgb(0 0 0 / 0.6)` both tiers | | | lightbox backdrops (physical black, never flips) |
|
|
40
|
+
|
|
41
|
+
Iron rules: no raw hex / `text-gray-*` outside tokens.css; `--accent` is text-only, `--accent-strong` is fill-only; new tokens are registered in tokens.css first, documented here, then consumed.
|
|
42
|
+
|
|
43
|
+
Fonts (`@theme inline` mappings, zero webfonts):
|
|
44
|
+
|
|
45
|
+
- `--font-sans`: `ui-sans-serif, system-ui, …` — UI
|
|
46
|
+
- `--font-serif`: `"Noto Serif SC", "Source Han Serif SC", …` — headings + long-form
|
|
47
|
+
- `--font-mono`: `ui-monospace, "SF Mono", …` — meta / code / readouts
|
|
48
|
+
|
|
49
|
+
Informational text floor: 12px. Interactive controls: 13px (`text-[13px]`) or 14px. Brand wordmark: `font-serif text-2xl font-semibold tracking-tight` + gold dot (`BRAND_DOT`, 0.25em circle).
|
|
50
|
+
|
|
51
|
+
## 3. Fragments (`src/styles/fragments.ts`)
|
|
52
|
+
|
|
53
|
+
The single source for recurring Tailwind combinations; components consume `className={FRAGMENT}` and override via `cn(FRAGMENT, "...")`. Family sections (byte-identical across the four repos before packaging) and app-panel additions both live here. Canonical list: `ICON_BTN`, `CARD`, `CARD_HOVER`, `DIVIDE_LIST`, `LIST_ROW`, `BTN_PRIMARY`, `BTN_OUTLINE`, `BTN_GHOST`, `PAPER_STRIP`(+`STRIP_PRIMARY`/`STRIP_PAPER`), `ALERT_DANGER`, `MEDIA_FAILED`, `CHIP`, `MONO_CHIP`, `META`, `EYEBROW`, `BRAND_DOT`, `INPUT`, `PANEL`, `TAPE`, `GHOST_DATE`, `GHOST_TEXT`, `SECTION`, `SECTION_DETAIL`, `PANEL_ROW`, `PANEL_COL`, `SEGMENT`(+`SEGMENT_ITEM_ON/OFF`), `PANEL_STATE_CHIP`, `TOOLBAR`(+`TOOLBAR_DIVIDER`), `STATUS_CHIP`, `MODAL_SCRIM`/`MODAL_PANEL`, `SHEET`.
|
|
54
|
+
|
|
55
|
+
z-index ladder: 20 stage info → 30 sheets → 40 floating chrome → 50 nav/progress → 90 popovers → 100 modals → 110 toasts.
|
|
56
|
+
|
|
57
|
+
## 4. Paper language (`src/tokens/paper.css`)
|
|
58
|
+
|
|
59
|
+
Utilities cannot express clip-path / pseudo-element paper; these classes are token-driven:
|
|
60
|
+
|
|
61
|
+
- `.paper-note` / `.paper-note--blank` — torn-edge note ground (ruled / blank); clip-path on the element itself, so tape must be a SIBLING node.
|
|
62
|
+
- `.paper-strip` — torn-edge strip on `::before` (keeps focus ring intact); paper color via `[--strip:…]` (see `PAPER_STRIP` + `STRIP_PRIMARY`/`STRIP_PAPER`).
|
|
63
|
+
- `.marker-strip` — torn highlight strip behind headline keywords (position inside `relative inline-block`, text in a following `relative` span).
|
|
64
|
+
- `.hollow-text` — stroked watermark (`--hollow-stroke` override); decorative only, `aria-hidden` mandatory.
|
|
65
|
+
- `.paper-chapter` — hand-drawn divider between sibling sections.
|
|
66
|
+
- `.film-number` — film-sprocket numeral (storyboard strips).
|
|
67
|
+
- `.paper-postmark` — dashed outer + solid inner ring (carries information; NOT aria-hidden).
|
|
68
|
+
- `.zj-range` (base.css) — token-driven range skin (warm line track, gold thumb).
|
|
69
|
+
|
|
70
|
+
Decor physics: whitespace only, `aria-hidden` + `pointer-events-none`, deterministic micro-tilts.
|
|
71
|
+
|
|
72
|
+
### Tape seed physics (authoritative)
|
|
73
|
+
|
|
74
|
+
`tapePhysics(seed, corner?)` in `src/paper/Tape.tsx` — djb2 (`h = ((h << 5) + h + c) >>> 0`, start 5381), all shifts use logical `>>>` (arithmetic `>>` sign-extends int32 and breaks the range — regression from 2026-10 visual debugging, do not revert):
|
|
75
|
+
|
|
76
|
+
- `top = -(6 + h % 4)` → −6..−9px
|
|
77
|
+
- `rotate = (h % 2 ? −1 : +1) × (4 + (h >>> 4) % 4)` → ±4..7°
|
|
78
|
+
- side composition: `inset = 24 + (h >>> 2) % 5 × 4` px, side = seed parity unless `corner` given
|
|
79
|
+
- center composition: `drift = (h >>> 6) % 5 × 6 − 12` px, `translateX(-50%)` then rotate
|
|
80
|
+
|
|
81
|
+
The component is the family's single implementation; the algorithm must stay verbatim-compatible with the apps' copies until each app migrates.
|
|
82
|
+
|
|
83
|
+
## 5. Theme (`src/hooks/theme.ts`)
|
|
84
|
+
|
|
85
|
+
Class strategy: `html.dark` (+ `html.black` OLED tier). `data-theme-mode` drives icon visibility (behaviors.css). Storage contract: localStorage `zj-theme` (default) or cookie `simple_style` (server-rendered apps). `THEME_BOOTSTRAP` is the pre-paint inline script (anti-FOUC). Palette transition + `.zjs-palette-anim` stand-down window (350 ms) live in behaviors.css; the JS module only flips classes. `applyThemeStyle` is pure (no persistence); `setThemeStyle` persists + applies.
|
|
86
|
+
|
|
87
|
+
## 6. Motion
|
|
88
|
+
|
|
89
|
+
- Enter/exit pairs: `fade-up` 0.35s `cubic-bezier(0.22,1,0.36,1)` / `fade-out` 0.16s; overlays `slide-in-right` / `slide-out-right` (ZJSearch).
|
|
90
|
+
- Unmount windows are plain timers sized to the animation (`useExitPresence`), doubling as the timeout fallback (animation contract).
|
|
91
|
+
- Global reduced-motion gate collapses everything to 0.01ms.
|
|
92
|
+
|
|
93
|
+
## 7. Governance
|
|
94
|
+
|
|
95
|
+
1. Spec change → DESIGN.md (family) → tokens.css → release.
|
|
96
|
+
2. New fragment → fragments.ts + this doc §3 → release.
|
|
97
|
+
3. New component → playground demo + visual check on all three tiers + test if behavior-bearing.
|
|
98
|
+
4. A release without a green `lint + check + test + build` is forbidden.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Apache License 2.0 with Commons Clause
|
|
2
|
+
--------------------------------------
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Zhijie He.
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License.
|
|
8
|
+
You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
See the License for the specific language governing permissions and
|
|
16
|
+
limitations under the License.
|
|
17
|
+
|
|
18
|
+
Commons Clause Restriction
|
|
19
|
+
--------------------------
|
|
20
|
+
|
|
21
|
+
The Software is provided to you by the Licensor under the License, as
|
|
22
|
+
defined below, subject to the following condition.
|
|
23
|
+
|
|
24
|
+
Without limiting other conditions in the License, the grant of rights
|
|
25
|
+
under the License will not include, and the License does not grant to
|
|
26
|
+
you, the right to Sell the Software.
|
|
27
|
+
|
|
28
|
+
For purposes of the foregoing, "Sell" means practicing any or all of
|
|
29
|
+
the rights granted to you under the License to provide to third parties,
|
|
30
|
+
for a fee or other consideration (including without limitation fees for
|
|
31
|
+
hosting or consulting/support services related to the Software), a
|
|
32
|
+
product or service whose value derives, entirely or substantially, from
|
|
33
|
+
the functionality of the Software. Any license notice or attribution
|
|
34
|
+
required by the License must also include this Commons Clause License
|
|
35
|
+
Condition notice.
|
|
36
|
+
|
|
37
|
+
Software: ZJ Design (@hezhijie0327/zjdesign)
|
|
38
|
+
|
|
39
|
+
License: Apache 2.0 with Commons Clause
|
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ZJDesign
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@hezhijie0327/zjdesign)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://biomejs.dev/)
|
|
7
|
+
|
|
8
|
+
ZJ 产品家族的共享设计系统:暖纸底 × 墨色文字 × 琥珀金。将 ZJBlog / ZJKVM / ZJSearch / ZJStudio 四个项目的 tokens、Tailwind 片段、主题逻辑与 React 组件收敛为一个可发布的 npm 包(架构参考 lobe-ui 的单包多入口模式)。
|
|
9
|
+
|
|
10
|
+
- npm 包:`@hezhijie0327/zjdesign`
|
|
11
|
+
- 设计规范(英文):[DESIGN.md](./DESIGN.md)
|
|
12
|
+
- 代理开发手册:[AGENTS.md](./AGENTS.md)
|
|
13
|
+
|
|
14
|
+
## 特性
|
|
15
|
+
|
|
16
|
+
- **Tokens 层(技术栈无关)**:`@property` 注册的颜色 token + 亮 / 暗 / OLED 黑三档 + 整页 0.3s 交叉淡化 + 零 webfont 字体栈,纯 CSS,任何项目可直接 import
|
|
17
|
+
- **Tailwind 片段层**:家族统一的类名片段常量(`CARD` / `BTN_PRIMARY` / `CHIP` …)+ `cn()`(clsx + tailwind-merge)
|
|
18
|
+
- **React 组件层**:Button / IconButton / Modal / Popover / Dropdown / Segmented / Switch / Slider / Kbd / Toast / Collapse / CopyButton / ProgressBar
|
|
19
|
+
- **主题层**:`useTheme`(auto / light / dark / black 四态)+ 防闪 bootstrap 脚本 + localStorage / cookie 双持久化
|
|
20
|
+
- **纸张语言**:撕纸 / 胶带(djb2 种子物理)/ 邮戳 / 荧光笔等 clip-path 装饰 + 确定性微倾角
|
|
21
|
+
- **零状态库依赖**:Toast 总线不依赖 jotai;运行时依赖仅 clsx + tailwind-merge
|
|
22
|
+
|
|
23
|
+
## 快速开始
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm add @hezhijie0327/zjdesign
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
消费方 `global.css`(Tailwind v4):
|
|
30
|
+
|
|
31
|
+
```css
|
|
32
|
+
@import "tailwindcss";
|
|
33
|
+
@import "@hezhijie0327/zjdesign/tokens"; /* tokens + base + paper + behaviors */
|
|
34
|
+
|
|
35
|
+
@custom-variant dark (&:where(.dark, .dark *));
|
|
36
|
+
|
|
37
|
+
/* 片段类在包的 JS 产物里,需要让 Tailwind 扫描它 */
|
|
38
|
+
@source "../node_modules/@hezhijie0327/zjdesign/dist";
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
防闪脚本(首绘前注入 `<head>`):
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { THEME_BOOTSTRAP } from "@hezhijie0327/zjdesign/hooks";
|
|
45
|
+
|
|
46
|
+
// <script dangerouslySetInnerHTML={{ __html: THEME_BOOTSTRAP }} />
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 用法
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { Button, Modal, toast, Toaster, useTheme } from "@hezhijie0327/zjdesign";
|
|
53
|
+
import { Tape } from "@hezhijie0327/zjdesign/paper";
|
|
54
|
+
import { Wordmark } from "@hezhijie0327/zjdesign/brand";
|
|
55
|
+
import { CARD, CHIP } from "@hezhijie0327/zjdesign/styles";
|
|
56
|
+
|
|
57
|
+
<Button variant="primary" onClick={() => toast("Saved")}>
|
|
58
|
+
保存
|
|
59
|
+
</Button>;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
子入口一览:
|
|
63
|
+
|
|
64
|
+
| 入口 | 内容 |
|
|
65
|
+
| ------------------------------- | ------------------------------------------- |
|
|
66
|
+
| `@hezhijie0327/zjdesign` | React 组件 + hooks(主入口) |
|
|
67
|
+
| `@hezhijie0327/zjdesign/styles` | 片段常量 + `cn()` |
|
|
68
|
+
| `@hezhijie0327/zjdesign/hooks` | 主题 / `useExitPresence` / `reducedMotion` |
|
|
69
|
+
| `@hezhijie0327/zjdesign/paper` | `Tape`(种子物理胶带) |
|
|
70
|
+
| `@hezhijie0327/zjdesign/brand` | `Wordmark`(衬线字标 + 金句点) |
|
|
71
|
+
| `@hezhijie0327/zjdesign/tokens` | CSS 入口(`/tokens/base.css` 等可单独引入) |
|
|
72
|
+
|
|
73
|
+
## 本地开发
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pnpm install
|
|
77
|
+
pnpm build # 构建 dist/
|
|
78
|
+
pnpm test # vitest(jsdom)
|
|
79
|
+
pnpm lint # biome
|
|
80
|
+
pnpm dev # playground 视觉验证
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 文档
|
|
84
|
+
|
|
85
|
+
- [DESIGN.md](./DESIGN.md):设计语言规范(tokens / 片段 / 纸张物理 / 动效)
|
|
86
|
+
- [AGENTS.md](./AGENTS.md):代理协作约定与发布流程
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
Apache-2.0 with Commons Clause — 详见 [LICENSE](./LICENSE)。
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as react0 from "react";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/brand/Wordmark.d.ts
|
|
5
|
+
/** Family wordmark: serif logotype + the gold full stop (em-relative dot,
|
|
6
|
+
* scales with the wordmark font size — the family signature). */
|
|
7
|
+
declare function Wordmark({
|
|
8
|
+
children,
|
|
9
|
+
className,
|
|
10
|
+
dotClassName
|
|
11
|
+
}: {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
/** Typography on the logotype (size etc.); the family default is the
|
|
14
|
+
* navigation-bar scale — pass e.g. "text-xl" for compact bars */
|
|
15
|
+
className?: string;
|
|
16
|
+
dotClassName?: string;
|
|
17
|
+
}): react0.JSX.Element;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Wordmark };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { n as BRAND_DOT, z as cn } from "../styles-CZ-LL-aM.mjs";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/brand/Wordmark.tsx
|
|
5
|
+
/** Family wordmark: serif logotype + the gold full stop (em-relative dot,
|
|
6
|
+
* scales with the wordmark font size — the family signature). */
|
|
7
|
+
function Wordmark({ children, className, dotClassName }) {
|
|
8
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
9
|
+
className: cn("font-serif text-2xl font-semibold tracking-tight", className),
|
|
10
|
+
children: [children, /* @__PURE__ */ jsx("span", {
|
|
11
|
+
"aria-hidden": "true",
|
|
12
|
+
className: cn(BRAND_DOT, "ms-0.5", dotClassName)
|
|
13
|
+
})]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { Wordmark };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as watchSystemTheme, a as THEME_BOOTSTRAP, c as THEME_COLOR_LIGHT, d as applyThemeStyle, f as cookieThemeStorage, g as setThemeStyle, h as readThemeStyle, i as useExitPresence, l as ThemeStorage, m as localStorageThemeStorage, n as UseThemeResult, o as THEME_COLOR_BLACK, p as createThemeController, r as useTheme, s as THEME_COLOR_DARK, t as UseThemeOptions, u as ThemeStyle, v as watchThemeDark, y as reducedMotion } from "../index-B-bZqvO6.mjs";
|
|
2
|
+
export { THEME_BOOTSTRAP, THEME_COLOR_BLACK, THEME_COLOR_DARK, THEME_COLOR_LIGHT, ThemeStorage, ThemeStyle, UseThemeOptions, UseThemeResult, applyThemeStyle, cookieThemeStorage, createThemeController, localStorageThemeStorage, readThemeStyle, reducedMotion, setThemeStyle, useExitPresence, useTheme, watchSystemTheme, watchThemeDark };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as THEME_COLOR_DARK, c as cookieThemeStorage, d as readThemeStyle, f as setThemeStyle, h as reducedMotion, i as THEME_COLOR_BLACK, l as createThemeController, m as watchThemeDark, n as useExitPresence, o as THEME_COLOR_LIGHT, p as watchSystemTheme, r as THEME_BOOTSTRAP, s as applyThemeStyle, t as useTheme, u as localStorageThemeStorage } from "../hooks-_Gk75q-U.mjs";
|
|
2
|
+
|
|
3
|
+
export { THEME_BOOTSTRAP, THEME_COLOR_BLACK, THEME_COLOR_DARK, THEME_COLOR_LIGHT, applyThemeStyle, cookieThemeStorage, createThemeController, localStorageThemeStorage, readThemeStyle, reducedMotion, setThemeStyle, useExitPresence, useTheme, watchSystemTheme, watchThemeDark };
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/motion.ts
|
|
4
|
+
/** True when the user prefers reduced motion (the global stylesheet gate
|
|
5
|
+
* collapses animations to 0.01ms, so callers should skip exit windows and
|
|
6
|
+
* transitions entirely). */
|
|
7
|
+
function reducedMotion() {
|
|
8
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/hooks/theme.ts
|
|
13
|
+
/** theme-color (browser UI / PWA title bar) takes the page background */
|
|
14
|
+
const THEME_COLOR_LIGHT = "#faf9f6";
|
|
15
|
+
const THEME_COLOR_DARK = "#1b1a18";
|
|
16
|
+
const THEME_COLOR_BLACK = "#000000";
|
|
17
|
+
/** localStorage adapter (default; key follows the family contract). */
|
|
18
|
+
function localStorageThemeStorage(key = "zj-theme") {
|
|
19
|
+
return {
|
|
20
|
+
read: () => {
|
|
21
|
+
try {
|
|
22
|
+
return localStorage.getItem(key);
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
write: (value) => {
|
|
28
|
+
try {
|
|
29
|
+
localStorage.setItem(key, value);
|
|
30
|
+
} catch {}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Cookie adapter (ZJSearch contract: server renders the first paint, so the
|
|
35
|
+
* preference must ride the request). Value names follow the `simple_style`
|
|
36
|
+
* cookie. */
|
|
37
|
+
function cookieThemeStorage(key = "simple_style", days = 365) {
|
|
38
|
+
return {
|
|
39
|
+
read: () => {
|
|
40
|
+
const match = document.cookie.match(/* @__PURE__ */ new RegExp(`(?:^|; )${key}=([^;]*)`));
|
|
41
|
+
return match?.[1] ? decodeURIComponent(match[1]) : null;
|
|
42
|
+
},
|
|
43
|
+
write: (value) => {
|
|
44
|
+
document.cookie = `${key}=${encodeURIComponent(value)}; max-age=${days * 86400}; path=/; samesite=lax`;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function isThemeStyle(value) {
|
|
49
|
+
return value === "light" || value === "dark" || value === "black";
|
|
50
|
+
}
|
|
51
|
+
let paletteAnimTimer;
|
|
52
|
+
function resolvedDark(style) {
|
|
53
|
+
return style === "dark" || style === "black" || style === "auto" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
54
|
+
}
|
|
55
|
+
/** Collapse the theme-color metas in head to the resolved value: the first drops its
|
|
56
|
+
* media attribute and gets the actual background color, the rest are removed. Idempotent —
|
|
57
|
+
* both the pre-paint bootstrap and every palette flip go through here. */
|
|
58
|
+
function syncThemeColorMeta(dark, black) {
|
|
59
|
+
const metas = document.querySelectorAll("meta[name=\"theme-color\"]");
|
|
60
|
+
const primary = metas.item(0);
|
|
61
|
+
if (!primary) return;
|
|
62
|
+
primary.removeAttribute("media");
|
|
63
|
+
primary.setAttribute("content", black ? THEME_COLOR_BLACK : dark ? THEME_COLOR_DARK : THEME_COLOR_LIGHT);
|
|
64
|
+
metas.forEach((meta, index) => {
|
|
65
|
+
if (index > 0) meta.remove();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function createThemeController(storage = localStorageThemeStorage()) {
|
|
69
|
+
const readThemeStyle$1 = () => {
|
|
70
|
+
const value = storage.read();
|
|
71
|
+
return isThemeStyle(value) ? value : "auto";
|
|
72
|
+
};
|
|
73
|
+
const applyThemeStyle$1 = (style) => {
|
|
74
|
+
const dark = resolvedDark(style);
|
|
75
|
+
const root = document.documentElement;
|
|
76
|
+
if ((root.classList.contains("dark") !== dark || root.classList.contains("black") !== (style === "black")) && !window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
77
|
+
root.classList.add("zjs-palette-anim");
|
|
78
|
+
window.clearTimeout(paletteAnimTimer);
|
|
79
|
+
paletteAnimTimer = window.setTimeout(() => root.classList.remove("zjs-palette-anim"), 350);
|
|
80
|
+
}
|
|
81
|
+
root.classList.toggle("dark", dark);
|
|
82
|
+
root.classList.toggle("black", style === "black");
|
|
83
|
+
root.setAttribute("data-theme-mode", style);
|
|
84
|
+
syncThemeColorMeta(dark, style === "black");
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
storage,
|
|
88
|
+
readThemeStyle: readThemeStyle$1,
|
|
89
|
+
applyThemeStyle: applyThemeStyle$1,
|
|
90
|
+
setThemeStyle(style) {
|
|
91
|
+
storage.write(style);
|
|
92
|
+
applyThemeStyle$1(style);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const defaultController = /* @__PURE__ */ createThemeController();
|
|
97
|
+
const readThemeStyle = defaultController.readThemeStyle;
|
|
98
|
+
const applyThemeStyle = defaultController.applyThemeStyle;
|
|
99
|
+
const setThemeStyle = defaultController.setThemeStyle;
|
|
100
|
+
/** In auto mode, follow the system light/dark switch in real time. */
|
|
101
|
+
function watchSystemTheme(storage = localStorageThemeStorage()) {
|
|
102
|
+
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
|
|
103
|
+
const controller = createThemeController(storage);
|
|
104
|
+
if (controller.readThemeStyle() === "auto") controller.applyThemeStyle("auto");
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** Subscribe to the dark state (html.dark is the single source of truth; both in-site
|
|
108
|
+
* toggles and system-follow flip it). Returns an unsubscribe function. Heavy theme
|
|
109
|
+
* dependencies (giscus iframe / mermaid re-render) hook in here — do not attach your own
|
|
110
|
+
* MutationObserver. */
|
|
111
|
+
function watchThemeDark(onChange) {
|
|
112
|
+
const root = document.documentElement;
|
|
113
|
+
const observer = new MutationObserver(() => onChange(root.classList.contains("dark")));
|
|
114
|
+
observer.observe(root, {
|
|
115
|
+
attributeFilter: ["class"],
|
|
116
|
+
attributes: true
|
|
117
|
+
});
|
|
118
|
+
return () => {
|
|
119
|
+
observer.disconnect();
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/** Inline script for the prerendered HTML <head>: attaches .dark / .black and
|
|
123
|
+
* data-theme-mode before the first frame to prevent light/dark and icon flashes;
|
|
124
|
+
* under an explicit theme it also collapses the theme-color meta (auto keeps the
|
|
125
|
+
* media pair and follows the system natively). localStorage contract. */
|
|
126
|
+
const THEME_BOOTSTRAP = `(function(){try{var s=localStorage.getItem("zj-theme");if(s!=="light"&&s!=="dark"&&s!=="black")s="auto";var d=s==="dark"||s==="black"||(s==="auto"&&window.matchMedia("(prefers-color-scheme: dark)").matches);var r=document.documentElement;if(d)r.classList.add("dark");if(s==="black")r.classList.add("black");r.setAttribute("data-theme-mode",s);if(s!=="auto"){var m=document.querySelectorAll('meta[name="theme-color"]');if(m.length>0){m[0].removeAttribute("media");m[0].setAttribute("content",s==="black"?"${THEME_COLOR_BLACK}":d?"${THEME_COLOR_DARK}":"${THEME_COLOR_LIGHT}");for(var i=1;i<m.length;i++)m[i].remove();}}}catch(e){}})();`;
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/hooks/useExitPresence.ts
|
|
130
|
+
/**
|
|
131
|
+
* Exit-animation presence for conditionally rendered surfaces (dropdown
|
|
132
|
+
* menus, dialogs, drawers, popovers): a dismissal keeps the surface mounted
|
|
133
|
+
* for the exit animation instead of snapping it out of the DOM. Returns
|
|
134
|
+
* `render` (keep the element in the tree) and `closing` (the exit phase —
|
|
135
|
+
* apply the `-out` animation class, set `inert`, and short-circuit handlers
|
|
136
|
+
* that must not re-fire, e.g. a second Escape re-opening history).
|
|
137
|
+
*
|
|
138
|
+
* The unmount is a plain timer sized to the CSS animation duration —
|
|
139
|
+
* deterministic, and it doubles as the timeout fallback for the animation
|
|
140
|
+
* itself. Reduced motion skips the window entirely (the global stylesheet
|
|
141
|
+
* guard collapses the animation to 0.01ms, so an instant unmount is what
|
|
142
|
+
* the user asked for).
|
|
143
|
+
*/
|
|
144
|
+
function useExitPresence(open, ms = 160) {
|
|
145
|
+
const [render, setRender] = useState(open);
|
|
146
|
+
const [closing, setClosing] = useState(false);
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (open) {
|
|
149
|
+
setRender(true);
|
|
150
|
+
setClosing(false);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (!render || reducedMotion()) {
|
|
154
|
+
setRender(false);
|
|
155
|
+
setClosing(false);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
setClosing(true);
|
|
159
|
+
const timer = window.setTimeout(() => {
|
|
160
|
+
setRender(false);
|
|
161
|
+
setClosing(false);
|
|
162
|
+
}, ms);
|
|
163
|
+
return () => {
|
|
164
|
+
window.clearTimeout(timer);
|
|
165
|
+
};
|
|
166
|
+
}, [
|
|
167
|
+
open,
|
|
168
|
+
ms,
|
|
169
|
+
render
|
|
170
|
+
]);
|
|
171
|
+
return {
|
|
172
|
+
render,
|
|
173
|
+
closing
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/hooks/useTheme.ts
|
|
179
|
+
/** React binding over the theme controller: keeps component state in sync with
|
|
180
|
+
* the html classes, persists the preference, and follows the system in auto
|
|
181
|
+
* mode. Mount once near the app root. */
|
|
182
|
+
function useTheme({ storage = localStorageThemeStorage(), order = [
|
|
183
|
+
"auto",
|
|
184
|
+
"light",
|
|
185
|
+
"dark"
|
|
186
|
+
] } = {}) {
|
|
187
|
+
const controller = createThemeController(storage);
|
|
188
|
+
const [style, setStyleState] = useState(controller.readThemeStyle);
|
|
189
|
+
const [dark, setDark] = useState(() => document.documentElement.classList.contains("dark"));
|
|
190
|
+
const setStyle = useCallback((next) => {
|
|
191
|
+
controller.setThemeStyle(next);
|
|
192
|
+
setStyleState(next);
|
|
193
|
+
}, [controller]);
|
|
194
|
+
const cycle = useCallback(() => {
|
|
195
|
+
setStyle(order[(order.indexOf(style) + 1) % order.length] ?? order[0] ?? "auto");
|
|
196
|
+
}, [
|
|
197
|
+
order,
|
|
198
|
+
setStyle,
|
|
199
|
+
style
|
|
200
|
+
]);
|
|
201
|
+
useEffect(() => watchSystemTheme(storage), [storage]);
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
const root = document.documentElement;
|
|
204
|
+
const observer = new MutationObserver(() => setDark(root.classList.contains("dark")));
|
|
205
|
+
observer.observe(root, {
|
|
206
|
+
attributeFilter: ["class"],
|
|
207
|
+
attributes: true
|
|
208
|
+
});
|
|
209
|
+
return () => observer.disconnect();
|
|
210
|
+
}, []);
|
|
211
|
+
return {
|
|
212
|
+
style,
|
|
213
|
+
dark,
|
|
214
|
+
setStyle,
|
|
215
|
+
cycle
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
export { THEME_COLOR_DARK as a, cookieThemeStorage as c, readThemeStyle as d, setThemeStyle as f, reducedMotion as h, THEME_COLOR_BLACK as i, createThemeController as l, watchThemeDark as m, useExitPresence as n, THEME_COLOR_LIGHT as o, watchSystemTheme as p, THEME_BOOTSTRAP as r, applyThemeStyle as s, useTheme as t, localStorageThemeStorage as u };
|