hd-garden 0.13.3 → 0.14.2
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/skills/garden-compose/SKILL.md +24 -0
- package/.agents/skills/garden-compose/references/colors.md +11 -0
- package/.agents/skills/garden-compose/references/composition-patterns.md +162 -0
- package/.agents/skills/garden-compose/references/examples.md +55 -0
- package/.agents/skills/garden-compose/references/frames.md +7 -0
- package/.agents/skills/garden-compose/references/layout-recipes.md +84 -0
- package/.agents/skills/garden-compose/references/rendering-model.md +120 -0
- package/.agents/skills/garden-compose/references/static-play.md +19 -0
- package/.agents/skills/garden-compose/references/visual-selection.md +38 -0
- package/.agents/skills/garden-compose/references/workflow.md +27 -0
- package/.agents/skills/garden-compose/scripts/_cli.mjs +12 -0
- package/.agents/skills/garden-compose/scripts/apply.mjs +2 -0
- package/.agents/skills/garden-compose/scripts/check.mjs +2 -0
- package/.agents/skills/garden-compose/scripts/prompt.mjs +2 -0
- package/.agents/skills/garden-compose/scripts/scan.mjs +2 -0
- package/.agents/skills/garden-post-review/SKILL.md +5 -16
- package/Makefile +12 -3
- package/README.en.md +10 -5
- package/README.md +10 -5
- package/app/admin/preview/[...path]/page.tsx +4 -16
- package/app/api/admin/ui/blocks/route.ts +1 -1
- package/app/components/AdminUiPanels.tsx +6 -3
- package/app/components/GardenContentGuide.tsx +7 -8
- package/app/components/MarkdownArticle.tsx +2 -0
- package/app/components/UiStudio.tsx +29 -32
- package/app/components/garden/AuthorRich.tsx +5 -0
- package/app/components/garden/ComposePreview.tsx +9 -0
- package/app/components/garden/GardenBlock.tsx +12 -10
- package/app/components/garden/GardenFile.tsx +1 -1
- package/app/components/garden/blocks.tsx +9 -197
- package/app/components/garden/file-icons.tsx +1 -1
- package/app/components/garden/patterns.tsx +7 -65
- package/app/lib/rehype-garden-blocks.mjs +30 -0
- package/app/lib/remark-garden.mjs +0 -4
- package/app/lib/ui-model.ts +8 -9
- package/app/styles/a2.css +17 -1
- package/bin/garden.mjs +34 -35
- package/docs/handbook/ai-writing.md +19 -22
- package/docs/handbook/components/compose.md +16 -7
- package/docs/handbook/components/image.md +1 -1
- package/docs/handbook/components/link-card.md +2 -2
- package/docs/handbook/components.md +5 -213
- package/docs/handbook/deploy.md +11 -0
- package/docs/handbook/en/ai-writing.md +17 -20
- package/docs/handbook/en/components/compose.md +15 -6
- package/docs/handbook/en/components/image.md +1 -1
- package/docs/handbook/en/components/link-card.md +2 -2
- package/docs/handbook/en/components.md +7 -215
- package/docs/handbook/en/deploy.md +11 -0
- package/docs/handbook/en/index.md +29 -53
- package/docs/handbook/en/reference/compose.md +77 -148
- package/docs/handbook/en/reference.md +6 -22
- package/docs/handbook/en/start.md +1 -1
- package/docs/handbook/en/workflow.md +21 -17
- package/docs/handbook/en/writing.md +3 -3
- package/docs/handbook/index.md +26 -47
- package/docs/handbook/reference/compose.md +79 -148
- package/docs/handbook/reference.md +6 -22
- package/docs/handbook/start.md +1 -1
- package/docs/handbook/workflow.md +21 -17
- package/docs/handbook/writing.md +3 -3
- package/editors/dist/typora/main.js +324 -330
- package/editors/dist/typora/style.css +4299 -11
- package/editors/dist/vscode/garden-ui-0.14.2.vsix +0 -0
- package/eslint.config.mjs +3 -0
- package/package.json +5 -3
- package/public/images/compose-resources/resource-015b41eb0f32.svg +1 -0
- package/public/images/compose-resources/resource-ecee6b47f015.svg +1 -0
- package/public/images/compose-resources/resource-fd51121b5e8c.svg +1 -0
- package/scripts/build-content.mjs +40 -131
- package/scripts/build-ui-preview.mjs +7 -5
- package/scripts/check-post.mjs +10 -106
- package/scripts/check-site.mjs +80 -0
- package/scripts/compose-style-reference.mjs +22 -0
- package/scripts/editor-preview-css.mjs +14 -0
- package/scripts/file-preview.mjs +1 -1
- package/scripts/file-sizes.mjs +7 -7
- package/scripts/generated-cache.mjs +36 -0
- package/scripts/handbook-facts.mjs +10 -3
- package/scripts/image-sizes.mjs +6 -12
- package/scripts/link-assets.mjs +35 -10
- package/scripts/managed-skills.mjs +56 -0
- package/scripts/pack-editors.mjs +12 -1
- package/scripts/prepare-pages-output.mjs +1 -1
- package/scripts/site-guide.mjs +19 -0
- package/scripts/sync-editor-version.mjs +28 -0
- package/scripts/ui-cli.mjs +26 -33
- package/templates/garden-blocks.md +4 -180
- package/templates/garden-snippets.plist +2 -183
- package/templates/site/AGENTS.en.md +89 -0
- package/templates/site/AGENTS.md +72 -0
- package/templates/site/Makefile +12 -3
- package/templates/site/Makefile.en +12 -3
- package/templates/site/README.en.md +6 -1
- package/templates/site/README.md +6 -1
- package/templates/skills-en/garden-compose/SKILL.md +24 -0
- package/templates/skills-en/garden-post-review/SKILL.md +5 -16
- package/templates/workflows/pages.en.yml +11 -0
- package/templates/workflows/pages.yml +11 -0
- package/ui/compose/compose.css +54 -14
- package/ui/compose/contracts.mjs +16 -0
- package/ui/compose/dil.mjs +109 -48
- package/ui/compose/distribution.mjs +7 -0
- package/ui/compose/features.mjs +90 -0
- package/ui/compose/icons.mjs +8 -0
- package/ui/compose/index.mjs +2 -0
- package/ui/compose/inspect.mjs +11 -0
- package/ui/compose/markup.mjs +80 -23
- package/ui/compose/preview.mjs +13 -0
- package/ui/compose/prompt-catalog.mjs +15 -3
- package/ui/compose/render.mjs +46 -11
- package/ui/compose/scenes.mjs +10 -0
- package/ui/core/apply.mjs +12 -45
- package/ui/core/catalog.mjs +22 -32
- package/ui/core/cli-locale.mjs +8 -18
- package/ui/core/color.mjs +34 -0
- package/ui/core/compile.mjs +1 -8
- package/ui/core/demos.mjs +138 -108
- package/ui/core/fence.mjs +14 -70
- package/ui/core/fix-prompt.mjs +1 -3
- package/ui/core/garden-fence.mjs +3 -63
- package/ui/core/index.mjs +3 -5
- package/ui/core/parse.mjs +22 -8
- package/ui/core/scan.mjs +31 -43
- package/ui/core/starters.mjs +3 -3
- package/ui/core/static.mjs +36 -6
- package/ui/core/transform.mjs +64 -149
- package/ui/core/validate.mjs +20 -9
- package/ui/garden/article-content.mjs +98 -0
- package/ui/garden/catalog.mjs +21 -427
- package/ui/garden/check.mjs +18 -60
- package/ui/garden/file-block.mjs +1 -1
- package/ui/garden/file-paths.mjs +8 -6
- package/ui/garden/parse.mjs +19 -182
- package/ui/garden/relations.mjs +1 -1
- package/ui/garden/snippets.mjs +12 -153
- package/ui/garden/source-icon.mjs +17 -9
- package/ui/garden/word-count.mjs +16 -85
- package/ui/index.mjs +1 -5
- package/ui/preview/dist/garden-ui.css +4300 -11
- package/ui/preview/dist/garden-ui.esm.js +446 -418
- package/ui/preview/dist/garden-ui.iife.js +446 -418
- package/ui/preview/index.tsx +31 -98
- package/ui/preview/site-config.ts +4 -0
- package/ui/prompt/build.mjs +1 -4
- package/ui/prompt/recipes/code-walkthrough.md +17 -12
- package/ui/prompt/recipes/compare.md +14 -10
- package/ui/prompt/recipes/compose.md +3 -3
- package/ui/prompt/recipes/converter.md +17 -14
- package/ui/prompt/recipes/data-chart.md +9 -8
- package/ui/prompt/recipes/inspect-grid.md +9 -8
- package/ui/prompt/recipes/param-bench.md +17 -12
- package/ui/prompt/recipes/plan.md +4 -3
- package/ui/prompt/recipes/stepper.md +18 -16
- package/ui/prompt/recipes/trace.md +20 -18
- package/ui/prompt/rules.md +26 -133
- package/ui/prompt/studio.md +3 -18
- package/ui/react/CatalogPage.tsx +19 -21
- package/ui/react/recipes.ts +3 -3
- package/ui/react/runtime.tsx +23 -2
- package/ui/react/ui.css +17 -11
- package/vite.config.ts +16 -3
- package/.agents/skills/garden-interactive-chart/SKILL.md +0 -84
- package/.agents/skills/garden-interactive-chart/references/shell.html +0 -49
- package/.agents/skills/garden-interactive-chart/references/style.md +0 -61
- package/.agents/skills/garden-ui/SKILL.md +0 -125
- package/app/components/UiBlock.tsx +0 -23
- package/app/components/WidgetChart.tsx +0 -224
- package/app/lib/generated-content.ts +0 -385
- package/docs/handbook/components/card.md +0 -67
- package/docs/handbook/components/chart.md +0 -38
- package/docs/handbook/components/choice.md +0 -42
- package/docs/handbook/components/compare.md +0 -53
- package/docs/handbook/components/file.md +0 -29
- package/docs/handbook/components/html.md +0 -49
- package/docs/handbook/components/interactive.md +0 -48
- package/docs/handbook/components/list.md +0 -65
- package/docs/handbook/components/relations.md +0 -95
- package/docs/handbook/components/stat.md +0 -39
- package/docs/handbook/components/timeline.md +0 -37
- package/docs/handbook/en/components/card.md +0 -67
- package/docs/handbook/en/components/chart.md +0 -38
- package/docs/handbook/en/components/choice.md +0 -42
- package/docs/handbook/en/components/compare.md +0 -53
- package/docs/handbook/en/components/file.md +0 -29
- package/docs/handbook/en/components/html.md +0 -49
- package/docs/handbook/en/components/interactive.md +0 -44
- package/docs/handbook/en/components/list.md +0 -65
- package/docs/handbook/en/components/relations.md +0 -95
- package/docs/handbook/en/components/stat.md +0 -39
- package/docs/handbook/en/components/timeline.md +0 -37
- package/docs/handbook/en/reference/card.md +0 -85
- package/docs/handbook/en/reference/chart.md +0 -68
- package/docs/handbook/en/reference/choice.md +0 -69
- package/docs/handbook/en/reference/compare.md +0 -59
- package/docs/handbook/en/reference/file.md +0 -50
- package/docs/handbook/en/reference/html.md +0 -62
- package/docs/handbook/en/reference/interactive.md +0 -71
- package/docs/handbook/en/reference/list.md +0 -72
- package/docs/handbook/en/reference/relations.md +0 -113
- package/docs/handbook/en/reference/stat.md +0 -60
- package/docs/handbook/en/reference/timeline.md +0 -56
- package/docs/handbook/reference/card.md +0 -85
- package/docs/handbook/reference/chart.md +0 -68
- package/docs/handbook/reference/choice.md +0 -69
- package/docs/handbook/reference/compare.md +0 -59
- package/docs/handbook/reference/file.md +0 -50
- package/docs/handbook/reference/html.md +0 -62
- package/docs/handbook/reference/interactive.md +0 -71
- package/docs/handbook/reference/list.md +0 -72
- package/docs/handbook/reference/relations.md +0 -113
- package/docs/handbook/reference/stat.md +0 -60
- package/docs/handbook/reference/timeline.md +0 -56
- package/editors/dist/vscode/garden-ui-0.1.1.vsix +0 -0
- package/templates/skills-en/garden-interactive-chart/SKILL.md +0 -84
- package/templates/skills-en/garden-interactive-chart/references/shell.html +0 -49
- package/templates/skills-en/garden-interactive-chart/references/style.md +0 -61
- package/templates/skills-en/garden-ui/SKILL.md +0 -125
package/ui/preview/index.tsx
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
1
|
+
import { useEffect, useState, type ReactNode } from "react";
|
|
2
2
|
import { createRoot } from "react-dom/client";
|
|
3
|
-
import { CATALOG_VERSION
|
|
3
|
+
import { CATALOG_VERSION } from "../core/catalog.mjs";
|
|
4
4
|
import { compileUiBlock } from "../core/compile.mjs";
|
|
5
|
-
import { scanFences
|
|
6
|
-
import {
|
|
5
|
+
import { scanFences } from "../core/fence.mjs";
|
|
6
|
+
import {parseGardenBlock} from "../garden/parse.mjs";
|
|
7
|
+
import {renderCompose} from "../compose/render.mjs";
|
|
7
8
|
import { renderStatic } from "../core/static.mjs";
|
|
8
9
|
import { collectDataSources } from "../core/transform.mjs";
|
|
9
|
-
|
|
10
|
+
|
|
10
11
|
import { CatalogPage, type RecipeSource } from "../react/CatalogPage";
|
|
11
|
-
import { IntentCard, UiErrorCard,
|
|
12
|
+
import { RuntimeLangProvider, IntentCard, UiErrorCard, type Diagnostic } from "../react/index";
|
|
12
13
|
|
|
13
14
|
export type PreviewOptions = {
|
|
14
15
|
theme?: "light" | "dark";
|
|
16
|
+
lang?: "zh" | "en";
|
|
17
|
+
/** Native host supplied by the site/editor integration, never imported by UI. */
|
|
18
|
+
renderBlock?: (block: unknown, lang?: "zh" | "en") => ReactNode;
|
|
15
19
|
mode?: "interactive" | "static";
|
|
20
|
+
onCopyPrompt?:()=>void;
|
|
16
21
|
/** Reads a path relative to the Markdown file, for Data files. */
|
|
17
22
|
readFile?: (relativePath: string) => Promise<string | undefined> | string | undefined;
|
|
18
23
|
/** Same-name-directory path as written, mapped to a URL the host can display. */
|
|
@@ -23,23 +28,6 @@ export type PreviewOptions = {
|
|
|
23
28
|
fenceLine?: number;
|
|
24
29
|
};
|
|
25
30
|
|
|
26
|
-
type ParsedNode = { t: string; n?: string; c?: ParsedNode[] };
|
|
27
|
-
|
|
28
|
-
/** A name with no close catalog match is likely newer than this plugin rather than a typo. */
|
|
29
|
-
function hasNewerComponent(body: string) {
|
|
30
|
-
const { bodyText, error } = splitUiBody(body);
|
|
31
|
-
if (error) return false;
|
|
32
|
-
const { root } = parseUiBody(bodyText) as { root: ParsedNode | null };
|
|
33
|
-
const known = new Set<string>(COMPONENT_NAMES);
|
|
34
|
-
const unknown: string[] = [];
|
|
35
|
-
const walk = (node: ParsedNode) => {
|
|
36
|
-
if (node.t === "el" && node.n && !known.has(node.n)) unknown.push(node.n);
|
|
37
|
-
node.c?.forEach(walk);
|
|
38
|
-
};
|
|
39
|
-
if (root) walk(root);
|
|
40
|
-
return unknown.some((name) => !suggestComponent(name));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
31
|
const CONTROLS = "input, button, select, textarea, a, [role='button'], [role='slider'], [role='tab'], [role='checkbox'], [tabindex]";
|
|
44
32
|
const ISOLATED_EVENTS = ["pointerdown", "mousedown", "mouseup", "click", "keydown", "keyup", "keypress", "input", "beforeinput"];
|
|
45
33
|
|
|
@@ -66,7 +54,7 @@ function bodyOf(source: string) {
|
|
|
66
54
|
|
|
67
55
|
function Preview({ source, options }: { source: string; options: PreviewOptions }) {
|
|
68
56
|
const body = bodyOf(source);
|
|
69
|
-
const sources = collectDataSources(`\`\`\`
|
|
57
|
+
const sources = collectDataSources(`\`\`\`garden compose\n${body}\n\`\`\``);
|
|
70
58
|
const sourcesKey = sources.join("\n");
|
|
71
59
|
const [files, setFiles] = useState<{ key: string; data: Record<string, string> }>({ key: "", data: {} });
|
|
72
60
|
|
|
@@ -86,54 +74,22 @@ function Preview({ source, options }: { source: string; options: PreviewOptions
|
|
|
86
74
|
}, [sourcesKey, options.readFile]);
|
|
87
75
|
|
|
88
76
|
const loading = Boolean(sourcesKey && options.readFile && files.key !== sourcesKey);
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
96
|
-
const theme = options.theme ?? "light";
|
|
97
|
-
if (loading) return <div className="garden-ui-preview" data-theme={theme}><p className="garden-ui-preview-note">正在读取数据文件…</p></div>;
|
|
98
|
-
if (!payload) {
|
|
99
|
-
const diagnostics = (check.diagnostics as Diagnostic[]).filter((item) => item.severity === "error");
|
|
100
|
-
const newer = diagnostics.some((item) => item.code === "ui-component") && hasNewerComponent(body);
|
|
101
|
-
const header = (check as { header?: { id?: unknown; caption?: unknown } | null }).header;
|
|
102
|
-
return (
|
|
103
|
-
<div className="garden-ui-preview" data-theme={theme}>
|
|
104
|
-
{newer ? <p className="garden-ui-preview-note">块里有这个插件不认识的组件,预览需要更新 Garden 插件。</p> : null}
|
|
105
|
-
<UiErrorCard
|
|
106
|
-
caption={typeof header?.caption === "string" ? header.caption : ""}
|
|
107
|
-
diagnostics={diagnostics}
|
|
108
|
-
id={typeof header?.id === "string" ? header.id : null}
|
|
109
|
-
/>
|
|
110
|
-
</div>
|
|
111
|
-
);
|
|
77
|
+
const block=parseGardenBlock("garden compose",body);
|
|
78
|
+
const theme=options.theme??"light";
|
|
79
|
+
if(loading)return <div className="garden-ui-preview" data-theme={theme}><p className="garden-ui-preview-note">正在读取数据文件…</p></div>;
|
|
80
|
+
if(!block||block.error){
|
|
81
|
+
if(block?.error?.code==="compose-uncompiled")return <div className="garden-ui-preview" data-theme={theme}><IntentCard text={body} onCopyPrompt={options.onCopyPrompt}/></div>;
|
|
82
|
+
return <div className="garden-ui-preview" data-theme={theme}><UiErrorCard caption="Compose" diagnostics={[{code:block?.error?.code??"compose-invalid",message:block?.error?.message??"无效的 Compose",line:options.fenceLine??1,severity:"error"}]}/></div>;
|
|
112
83
|
}
|
|
113
|
-
|
|
114
|
-
if
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return node.c ? { ...node, c: node.c.map(rewrite) } : node;
|
|
120
|
-
};
|
|
121
|
-
typed.root = rewrite(typed.root);
|
|
84
|
+
let ready:Record<string,unknown>={...block};
|
|
85
|
+
if(block.mode==="play"){
|
|
86
|
+
const {payload,check}=compileUiBlock(block.uiSource??"",{readData:(src:string)=>files.data[src],skipData:!options.readFile,resolveAsset:options.resolveAsset??null,markdownPath:null});
|
|
87
|
+
if(!payload)return <div className="garden-ui-preview" data-theme={theme}><UiErrorCard caption="Compose" diagnostics={check.diagnostics as Diagnostic[]}/></div>;
|
|
88
|
+
if(options.mode==="static")return <div className="garden-ui-preview" data-theme={theme}><div className="markdown-body prose" dangerouslySetInnerHTML={{__html:renderStatic(payload,"html")}}/></div>;
|
|
89
|
+
ready={...ready,payload};
|
|
122
90
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
<div className="garden-ui-preview" data-theme={theme}>
|
|
126
|
-
{stale ? <p className="garden-ui-preview-note">原话改过了,还没重编译。</p> : null}
|
|
127
|
-
{options.mode === "static" ? (
|
|
128
|
-
<figure className="garden-ui" data-frame={(typed as {frame?: string}).frame === "none" ? "none" : "card"} lang="en-US">
|
|
129
|
-
<div className="garden-ui-body garden-ui-static" dangerouslySetInnerHTML={{ __html: renderStatic(typed, "html") }} />
|
|
130
|
-
<figcaption>{typed.caption}</figcaption>
|
|
131
|
-
</figure>
|
|
132
|
-
) : (
|
|
133
|
-
<UiFigure payload={typed} />
|
|
134
|
-
)}
|
|
135
|
-
</div>
|
|
136
|
-
);
|
|
91
|
+
return <div className="garden-ui-preview" data-theme={theme}><div className="markdown-body prose">{options.renderBlock ? options.renderBlock(ready, options.lang) : <div dangerouslySetInnerHTML={{__html:ready.payload?renderStatic(ready.payload,"html"):renderCompose(block.props)}}/>}</div></div>;
|
|
92
|
+
|
|
137
93
|
}
|
|
138
94
|
|
|
139
95
|
function mount(element: HTMLElement, draw: (root: ReturnType<typeof createRoot>) => void) {
|
|
@@ -145,34 +101,11 @@ function mount(element: HTMLElement, draw: (root: ReturnType<typeof createRoot>)
|
|
|
145
101
|
export function render(element: HTMLElement, source: string, options: PreviewOptions = {}) {
|
|
146
102
|
let current = { source, options };
|
|
147
103
|
const release = options.isolateEvents ? isolate(element) : null;
|
|
148
|
-
const root = mount(element, (target) => target.render(<Preview source={current.source} options={current.options}
|
|
104
|
+
const root = mount(element, (target) => target.render(<RuntimeLangProvider lang={current.options.lang??"zh"}><Preview source={current.source} options={current.options} /></RuntimeLangProvider>));
|
|
149
105
|
return {
|
|
150
106
|
update(nextSource: string, nextOptions: PreviewOptions = current.options) {
|
|
151
107
|
current = { source: nextSource, options: nextOptions };
|
|
152
|
-
root.render(<Preview source={current.source} options={current.options}
|
|
153
|
-
},
|
|
154
|
-
destroy() {
|
|
155
|
-
release?.();
|
|
156
|
-
root.unmount();
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
type IntentOptions = { id?: string | null; theme?: "light" | "dark"; onCopyPrompt?: () => void; isolateEvents?: boolean };
|
|
162
|
-
|
|
163
|
-
export function renderIntent(element: HTMLElement, text: string, options: IntentOptions = {}) {
|
|
164
|
-
const release = options.isolateEvents ? isolate(element) : null;
|
|
165
|
-
const draw = (nextText: string, next: IntentOptions) => (
|
|
166
|
-
<div className="garden-ui-preview" data-theme={next.theme ?? "light"}>
|
|
167
|
-
<IntentCard text={bodyOf(nextText).trim()} id={next.id} onCopyPrompt={next.onCopyPrompt} />
|
|
168
|
-
</div>
|
|
169
|
-
);
|
|
170
|
-
let current = options;
|
|
171
|
-
const root = mount(element, (target) => target.render(draw(text, current)));
|
|
172
|
-
return {
|
|
173
|
-
update(nextText: string, nextOptions: IntentOptions = current) {
|
|
174
|
-
current = nextOptions;
|
|
175
|
-
root.render(draw(nextText, current));
|
|
108
|
+
root.render(<RuntimeLangProvider lang={current.options.lang??"zh"}><Preview source={current.source} options={current.options} /></RuntimeLangProvider>);
|
|
176
109
|
},
|
|
177
110
|
destroy() {
|
|
178
111
|
release?.();
|
|
@@ -181,11 +114,11 @@ export function renderIntent(element: HTMLElement, text: string, options: Intent
|
|
|
181
114
|
};
|
|
182
115
|
}
|
|
183
116
|
|
|
184
|
-
export function renderCatalog(element: HTMLElement, options: { recipes?: RecipeSource[]; theme?: "light" | "dark"; onStart?: (fence: string) => void } = {}) {
|
|
117
|
+
export function renderCatalog(element: HTMLElement, options: { recipes?: RecipeSource[]; theme?: "light" | "dark"; onStart?: (fence: string) => void; renderBlock?: PreviewOptions["renderBlock"] } = {}) {
|
|
185
118
|
if (options.theme) element.setAttribute("data-theme", options.theme);
|
|
186
|
-
const root = mount(element, (target) => target.render(<CatalogPage recipes={options.recipes ?? []} onStart={options.onStart} />));
|
|
119
|
+
const root = mount(element, (target) => target.render(<CatalogPage recipes={options.recipes ?? []} onStart={options.onStart} renderBlock={options.renderBlock} />));
|
|
187
120
|
return { destroy: () => root.unmount() };
|
|
188
121
|
}
|
|
189
122
|
|
|
190
123
|
export const catalogVersion = CATALOG_VERSION;
|
|
191
|
-
export {
|
|
124
|
+
export { composeFence, STARTERS as starters } from "../core/starters.mjs";
|
package/ui/prompt/build.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { catalogReference } from "../core/catalog.mjs";
|
|
2
1
|
import { composeCatalogReference } from "../compose/prompt-catalog.mjs";
|
|
3
2
|
|
|
4
3
|
export const RECIPE_FILES = [
|
|
@@ -17,15 +16,13 @@ export const RECIPE_FILES = [
|
|
|
17
16
|
export { composeCatalogReference };
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
|
-
* `garden ui prompt`: rules +
|
|
21
|
-
* reference + recipes. The admin workbench appends `studio` for its output contract.
|
|
19
|
+
* `garden ui prompt`: rules + generated Compose contracts + recipes. The admin workbench appends `studio` for its output contract.
|
|
22
20
|
* @param {{ rules: string, recipes: string[], studio?: string | null }} parts
|
|
23
21
|
*/
|
|
24
22
|
export function buildPrompt({ rules, recipes, studio = null }) {
|
|
25
23
|
const parts = [
|
|
26
24
|
rules.trim(),
|
|
27
25
|
composeCatalogReference().trim(),
|
|
28
|
-
catalogReference().trim(),
|
|
29
26
|
"## 配方",
|
|
30
27
|
...recipes.map((recipe) => recipe.trim()),
|
|
31
28
|
];
|
|
@@ -13,26 +13,31 @@
|
|
|
13
13
|
阶段 6 之前:
|
|
14
14
|
|
|
15
15
|
````md
|
|
16
|
-
```
|
|
17
|
-
---
|
|
16
|
+
```garden compose
|
|
18
17
|
id: binary-search-vars
|
|
19
18
|
caption: 每比较一次,搜索区间就缩小一半;8 个元素最多比较 4 次。
|
|
20
19
|
intent: |
|
|
21
20
|
在 [1 3 5 7 9 11 13 15] 里找 9,一步步列出 lo、hi、mid 和比较结果。
|
|
22
21
|
---
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
{@body const [step, setStep] = DIL.useState(0)}
|
|
23
|
+
{@body const los = [0, 4, 4]}
|
|
24
|
+
{@body const his = [7, 7, 4]}
|
|
25
|
+
{@body const mids = [3, 5, 4]}
|
|
26
|
+
{@body const prev = max(step - 1, 0)}
|
|
27
|
+
|
|
25
28
|
|
|
26
|
-
<Steps bind="step">
|
|
27
|
-
<Step title="第 1 次">mid = 3,a[3] = 7 小于 9,目标在右半边。</Step>
|
|
28
|
-
<Step title="第 2 次">lo 移到 4;mid = 5,a[5] = 11 大于 9,目标在左半边。</Step>
|
|
29
|
-
<Step title="第 3 次">hi 移到 4;mid = 4,a[4] = 9,找到。</Step>
|
|
30
|
-
</Steps>
|
|
31
29
|
|
|
32
|
-
<
|
|
33
|
-
<
|
|
30
|
+
<steps bind="step">
|
|
31
|
+
<step title="第 1 次">mid = 3,a[3] = 7 小于 9,目标在右半边。</step>
|
|
32
|
+
<step title="第 2 次">lo 移到 4;mid = 5,a[5] = 11 大于 9,目标在左半边。</step>
|
|
33
|
+
<step title="第 3 次">hi 移到 4;mid = 4,a[4] = 9,找到。</step>
|
|
34
|
+
</steps>
|
|
35
|
+
|
|
36
|
+
<table columns={["lo", "hi", "mid"]}>
|
|
37
|
+
<row cells={[los[step], his[step], mids[step]]}
|
|
34
38
|
tones={step == 0 ? "plain" : [los[step] != los[prev] ? "new" : "plain", his[step] != his[prev] ? "new" : "plain", "new"]} />
|
|
35
|
-
</
|
|
39
|
+
</table>
|
|
40
|
+
|
|
36
41
|
```
|
|
37
42
|
````
|
|
38
43
|
|
|
@@ -11,26 +11,30 @@
|
|
|
11
11
|
**骨架:** `Columns` 里放两个 `Card`,两边读同一个状态;共同的输入(`Slider`、`Toggle`)放在上面。想强调胜出的一方时,给它 `tone="accent"`。
|
|
12
12
|
|
|
13
13
|
````md
|
|
14
|
-
```
|
|
15
|
-
---
|
|
14
|
+
```garden compose
|
|
16
15
|
id: mutex-vs-rwlock
|
|
17
16
|
caption: 读者越多,Mutex 越慢;RwLock 让读者并行,总耗时不变。
|
|
18
17
|
intent: |
|
|
19
18
|
对比 Mutex 和 RwLock:读者数量 1 到 8 可调,一个写者,每次读写 10 ms,看总耗时。
|
|
20
19
|
expect:
|
|
21
|
-
- given:
|
|
20
|
+
- given:
|
|
21
|
+
readers: 3
|
|
22
22
|
mutexMs: 40
|
|
23
23
|
rwMs: 20
|
|
24
24
|
---
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
{@body const [readers, setReaders] = DIL.useState(3)}
|
|
26
|
+
{@body const mutexMs = (readers + 1) * 10}
|
|
27
|
+
{@body const rwMs = 20}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
<slider bind="readers" label="同时到达的读者" min={1} max={8} unit="个" />
|
|
27
32
|
|
|
28
|
-
<
|
|
33
|
+
<columns>
|
|
34
|
+
<card title="Mutex">读者和写者一个接一个,共 **{mutexMs} ms**。</card>
|
|
35
|
+
<card title="RwLock" tone="accent">{readers} 个读者一起读,写者再独占,共 **{rwMs} ms**。</card>
|
|
36
|
+
</columns>
|
|
29
37
|
|
|
30
|
-
<Columns>
|
|
31
|
-
<Card title="Mutex">读者和写者一个接一个,共 **{mutexMs} ms**。</Card>
|
|
32
|
-
<Card title="RwLock" tone="accent">{readers} 个读者一起读,写者再独占,共 **{rwMs} ms**。</Card>
|
|
33
|
-
</Columns>
|
|
34
38
|
```
|
|
35
39
|
````
|
|
36
40
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**什么时候用:** 几列名单、从一个点散开、从上到下的几层、一次事情的几面、上面一行顺序下面一行才是重点;或默认状态就要能看出结论、拖一下才多懂一点。
|
|
6
6
|
|
|
7
|
-
**什么时候不用:**
|
|
7
|
+
**什么时候不用:** 普通正文列表或 Mermaid 已经说清;一次乘法留在正文。图标长文用 Compose 的 icon-list/entry 或 row + 共享右侧 stack;关系图用 relations;画布动画用同一 Compose 中的 sandbox。
|
|
8
8
|
|
|
9
9
|
**围栏:** 类型始终是 `garden compose`。作者原话放进 `<intent>`,一个字不改。不要改成别的组件。正文还是一句白话时,不要发明 YAML 槽。
|
|
10
10
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
- `<lanes>` 里写 `<actor>` 和 `<message from="1" to="2" tone="forward">`
|
|
26
26
|
- `<steps>` 里每步一个 `<step id="sync">`,要点开的说明写 `<note>`
|
|
27
27
|
- `<compare>` 里 2 到 4 个 `<item>`。`<callout tone="tip">` 的 tone 是 `note`、`tip`、`warn`
|
|
28
|
-
-
|
|
28
|
+
- 普通行内 Markdown 与安全 `<u>` 可用于文字叶子。块级 Markdown/HTML 写在 `<markdown>…</markdown>` / `<html>…</html>` 内容岛,可嵌入布局并与 Play 控件共存;允许本地排版的白名单 inline CSS,不执行脚本、事件、iframe 或资源 CSS 函数。未知/不安全内容明确报错,不是任意 HTML 执行环境。Compose 标签的自定义颜色仍使用 color / backgroundColor(含 transparent)。默认继承文章字体与字号;确需强调时使用受支持 size,不缩字塞图。
|
|
29
29
|
|
|
30
30
|
**骨架(静态):**
|
|
31
31
|
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
- `{#if …}{:else}{/if}`、`{#each … as item, i}{/each}` 控制流
|
|
58
58
|
- 小写控件:`<slider>`、`<choice>`、`<button>`、`<stat>`、`<pie>` / `<chart>`…
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
作者输入只用目录中的小写标签。HTML/Markdown 内容用 markdown/html 岛;可执行动画用 sandbox。
|
|
61
61
|
|
|
62
62
|
**骨架(play):**
|
|
63
63
|
|
|
@@ -11,33 +11,36 @@
|
|
|
11
11
|
**骨架:** 一个 `Slider` 或 `Choice` 作为输入;把每一项的单位用量写进 `Let` 数组;`Table` 里用 `Each` 逐项生成行。
|
|
12
12
|
|
|
13
13
|
````md
|
|
14
|
-
```
|
|
15
|
-
---
|
|
14
|
+
```garden compose
|
|
16
15
|
id: roast-shopping
|
|
17
16
|
caption: 用料按人数线性换算;带骨羊腿每人 0.4 kg。
|
|
18
17
|
intent: |
|
|
19
18
|
按人数(2 到 12 人,默认 6 人)算周日烤羊腿要买多少:
|
|
20
19
|
带骨羊腿每人 0.4 kg,土豆每人 250 g,胡萝卜每人 1.5 根,甜点苹果每人半个。
|
|
21
20
|
expect:
|
|
22
|
-
- given:
|
|
21
|
+
- given:
|
|
22
|
+
guests: 6
|
|
23
23
|
lamb: 2.4
|
|
24
24
|
---
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
{@body const [guests, setGuests] = DIL.useState(6)}
|
|
26
|
+
{@body const lamb = 0.4 * guests}
|
|
27
|
+
{@body const items = [
|
|
28
28
|
{ name: "土豆", per: 250, unit: "g" },
|
|
29
29
|
{ name: "胡萝卜", per: 1.5, unit: "根" },
|
|
30
30
|
{ name: "苹果(甜点)", per: 0.5, unit: "个" },
|
|
31
|
-
]}
|
|
31
|
+
]}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
<slider bind="guests" label="人数" min={2} max={12} unit="人" />
|
|
32
36
|
|
|
33
|
-
<
|
|
37
|
+
<table columns={[{ label: "食材" }, { label: "数量", align: "right" }]}>
|
|
38
|
+
<row cells={["带骨羊腿", fixed(lamb, 1) + " kg"]} tones="accent" />
|
|
39
|
+
{#each items as it}
|
|
40
|
+
<row cells={[it.name, ceil(it.per * guests) + " " + it.unit]} />
|
|
41
|
+
{/each}
|
|
42
|
+
</table>
|
|
34
43
|
|
|
35
|
-
<Table columns={[{ label: "食材" }, { label: "数量", align: "right" }]}>
|
|
36
|
-
<Row cells={["带骨羊腿", fixed(lamb, 1) + " kg"]} tones="accent" />
|
|
37
|
-
<Each of={items} as="it">
|
|
38
|
-
<Row cells={[it.name, ceil(it.per * guests) + " " + it.unit]} />
|
|
39
|
-
</Each>
|
|
40
|
-
</Table>
|
|
41
44
|
```
|
|
42
45
|
````
|
|
43
46
|
|
|
@@ -13,27 +13,28 @@
|
|
|
13
13
|
下面的数字只是示例;真实的块里,每个数字都必须来自原话或数据文件。
|
|
14
14
|
|
|
15
15
|
````md
|
|
16
|
-
```
|
|
17
|
-
---
|
|
16
|
+
```garden compose
|
|
18
17
|
id: redis-io-threads
|
|
19
18
|
caption: I/O 线程从 1 加到 4,QPS 涨了两倍多;再加到 8,只多了一成多。
|
|
20
19
|
intent: |
|
|
21
20
|
把 Redis I/O 线程数的压测结果画成柱状图,再列一张表:
|
|
22
21
|
1 线程 98000,2 线程 181000,4 线程 312000,8 线程 356000。
|
|
23
22
|
---
|
|
24
|
-
|
|
23
|
+
{@body const bench = [
|
|
25
24
|
{ threads: 1, qps: 98000 },
|
|
26
25
|
{ threads: 2, qps: 181000 },
|
|
27
26
|
{ threads: 4, qps: 312000 },
|
|
28
27
|
{ threads: 8, qps: 356000 },
|
|
29
|
-
]}
|
|
28
|
+
]}
|
|
29
|
+
|
|
30
30
|
|
|
31
|
-
<
|
|
32
|
-
<
|
|
33
|
-
</
|
|
31
|
+
<chart data={bench} x={threads} xLabel="I/O 线程" yLabel="QPS" yFormat="si">
|
|
32
|
+
<bar y={qps} label="QPS" />
|
|
33
|
+
</chart>
|
|
34
34
|
|
|
35
|
-
<
|
|
35
|
+
<table data={bench} rowTone={threads == 4 ? "accent" : null}
|
|
36
36
|
columns={[{ label: "I/O 线程", key: "threads" }, { label: "QPS", key: "qps", format: "thousands" }]} />
|
|
37
|
+
|
|
37
38
|
```
|
|
38
39
|
````
|
|
39
40
|
|
|
@@ -11,23 +11,24 @@
|
|
|
11
11
|
**骨架:** `Grid` + 每行一个 `Row`;用 `tones` 标出特别的格子,用 `notes` 写每格的话,用 `legend` 解释颜色。需要切换场景时,加一个 `Choice` 或 `Toggle`。
|
|
12
12
|
|
|
13
13
|
````md
|
|
14
|
-
```
|
|
15
|
-
---
|
|
14
|
+
```garden compose
|
|
16
15
|
id: ecb-vs-cbc
|
|
17
16
|
caption: ECB 下相同的明文块得到相同的密文块;CBC 把上一块的密文混进来,重复就消失了。
|
|
18
17
|
intent: |
|
|
19
18
|
明文四块 A B A A,让读者在 ECB 和 CBC 之间切换,看密文里重复的块。
|
|
20
19
|
---
|
|
21
|
-
|
|
20
|
+
{@body const [mode, setMode] = DIL.useState("ecb")}
|
|
21
|
+
|
|
22
22
|
|
|
23
|
-
<
|
|
23
|
+
<choice bind="mode" label="模式" options={[{ value: "ecb", label: "ECB" }, { value: "cbc", label: "CBC" }]} />
|
|
24
24
|
|
|
25
|
-
<
|
|
26
|
-
<
|
|
27
|
-
<
|
|
25
|
+
<grid cols={["块1", "块2", "块3", "块4"]} legend={{ same: "密文与别的块相同" }}>
|
|
26
|
+
<row label="明文" cells={["A", "B", "A", "A"]} />
|
|
27
|
+
<row label="密文" cells={mode == "ecb" ? ["X", "Y", "X", "X"] : ["P", "Q", "R", "S"]}
|
|
28
28
|
tones={mode == "ecb" ? ["same", "plain", "same", "same"] : "plain"}
|
|
29
29
|
notes={mode == "ecb" ? ["和块3、块4相同", "", "和块1相同", "和块1相同"] : ["", "", "", ""]} />
|
|
30
|
-
</
|
|
30
|
+
</grid>
|
|
31
|
+
|
|
31
32
|
```
|
|
32
33
|
````
|
|
33
34
|
|
|
@@ -11,8 +11,7 @@
|
|
|
11
11
|
**骨架:** `State` 放输入,`Let` 写公式,`Slider` 绑输入,一句带插值的话说出当前结果,需要看趋势时加 `Chart sweep`。
|
|
12
12
|
|
|
13
13
|
````md
|
|
14
|
-
```
|
|
15
|
-
---
|
|
14
|
+
```garden compose
|
|
16
15
|
id: kv-memory
|
|
17
16
|
caption: 显存与 batch、序列长度都成正比;batch 8、序列 32K 就要 32 GiB。
|
|
18
17
|
intent: |
|
|
@@ -21,22 +20,28 @@ intent: |
|
|
|
21
20
|
显存 = 2 × 32 层 × 8 个 KV 头 × 128 维 × 序列长度 × batch × 2 字节。
|
|
22
21
|
batch 1、序列 4096 时是 512 MiB。
|
|
23
22
|
expect:
|
|
24
|
-
- given:
|
|
23
|
+
- given:
|
|
24
|
+
batch: 1
|
|
25
|
+
seq: 4096
|
|
25
26
|
mem: 536870912
|
|
26
27
|
---
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
{@body const [batch, setBatch] = DIL.useState(1)}
|
|
29
|
+
{@body const [seq, setSeq] = DIL.useState(4096)}
|
|
30
|
+
{@body const mem = 2 * 32 * 8 * 128 * seq * batch * 2}
|
|
31
|
+
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<
|
|
33
|
-
|
|
33
|
+
|
|
34
|
+
<columns>
|
|
35
|
+
<slider bind="batch" label="batch" min={1} max={32} />
|
|
36
|
+
<slider bind="seq" label="序列长度" min={1024} max={32768} scale="log" format="thousands" />
|
|
37
|
+
</columns>
|
|
34
38
|
|
|
35
39
|
batch 为 {batch}、序列 {thousands(seq)} 时,KV cache 要 **{bytes(mem)}**。
|
|
36
40
|
|
|
37
|
-
<
|
|
38
|
-
<
|
|
39
|
-
</
|
|
41
|
+
<chart sweep="seq" yLabel="KV 显存">
|
|
42
|
+
<line y={mem} label="KV 显存" format="bytes" />
|
|
43
|
+
</chart>
|
|
44
|
+
|
|
40
45
|
```
|
|
41
46
|
````
|
|
42
47
|
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
**骨架:** 一个 `Checklist`,每项写清时间或顺序、要做什么、注意什么。前面可以放一个决定清单内容的输入。
|
|
12
12
|
|
|
13
13
|
````md
|
|
14
|
-
```
|
|
15
|
-
---
|
|
14
|
+
```garden compose
|
|
16
15
|
id: roast-timeline
|
|
17
16
|
caption: 大部分活都在客人到之前做完;开饭前一小时只剩烤土豆和做肉汁。
|
|
18
17
|
intent: |
|
|
19
18
|
给一张周日烤羊腿的时间线清单,假设 5 点开饭,让读者一项项勾掉。
|
|
20
19
|
---
|
|
21
|
-
|
|
20
|
+
|
|
21
|
+
<checklist title="周日时间线" items={[
|
|
22
22
|
{ time: "前一天", title: "做好苹果酥,腌羊腿", note: "盐、蒜、迷迭香、橄榄油,冷藏过夜" },
|
|
23
23
|
{ time: "12:30", title: "羊腿出冰箱回温" },
|
|
24
24
|
{ time: "13:30", title: "羊腿进烤箱", note: "用温度计判断熟度,不要只看时间" },
|
|
@@ -28,6 +28,7 @@ intent: |
|
|
|
28
28
|
{ time: "16:45", title: "切肉装盘" },
|
|
29
29
|
{ time: "17:00", title: "开饭,苹果酥回炉加热" },
|
|
30
30
|
]} />
|
|
31
|
+
|
|
31
32
|
```
|
|
32
33
|
````
|
|
33
34
|
|
|
@@ -11,29 +11,31 @@
|
|
|
11
11
|
**骨架:** `State step={0}`,`Steps bind="step"` 里每步一句话;旁边放一个随 `step` 变化的 `Grid` 或 `Table`,把这一步变了的地方标成 `new`。
|
|
12
12
|
|
|
13
13
|
````md
|
|
14
|
-
```
|
|
15
|
-
---
|
|
14
|
+
```garden compose
|
|
16
15
|
id: prefill-decode
|
|
17
16
|
caption: Prefill 一次写满 3 行 K/V;之后每步只新算 1 行,其余读缓存。
|
|
18
17
|
intent: |
|
|
19
18
|
让读者一步步看 KV cache 怎么增长:prompt 3 个 token,再 decode 两步。
|
|
20
19
|
每步标出哪一行是新算的,哪些是读缓存。
|
|
21
20
|
---
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
{@body const [step, setStep] = DIL.useState(0)}
|
|
22
|
+
{@body const rows = step + 3}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
<steps bind="step">
|
|
27
|
+
<step title="Prefill">一次算完 3 个 prompt token 的 K/V,全部写进缓存。</step>
|
|
28
|
+
<step title="Decode 1">新 token 只算自己的 K/V,追加第 4 行;前 3 行直接读缓存。</step>
|
|
29
|
+
<step title="Decode 2">再追加一行。缓存里已有 {rows} 行,本步新算 1 行。</step>
|
|
30
|
+
</steps>
|
|
31
|
+
|
|
32
|
+
<grid cols={["K", "V"]} legend={{ new: "本步新算", cached: "读缓存" }}>
|
|
33
|
+
{#each range(0, rows) as i}
|
|
34
|
+
<row label={"t" + (i + 1)} cells={["k" + (i + 1), "v" + (i + 1)]}
|
|
34
35
|
tones={step == 0 || i == rows - 1 ? "new" : "cached"} />
|
|
35
|
-
|
|
36
|
-
</
|
|
36
|
+
{/each}
|
|
37
|
+
</grid>
|
|
38
|
+
|
|
37
39
|
```
|
|
38
40
|
````
|
|
39
41
|
|
|
@@ -11,31 +11,33 @@
|
|
|
11
11
|
**骨架(阶段 6 之前):** `Steps bind="step"` + 一张 `Table`,列出每个参与方此刻的状态,这一步变了的标成 `new`。阶段 6 起改用 `Diagram`,用 `highlight` 标出当前节点。
|
|
12
12
|
|
|
13
13
|
````md
|
|
14
|
-
```
|
|
15
|
-
---
|
|
14
|
+
```garden compose
|
|
16
15
|
id: tcp-handshake
|
|
17
16
|
caption: 三次握手里,客户端先进入 ESTABLISHED,服务端要等最后一个 ACK。
|
|
18
17
|
intent: |
|
|
19
18
|
一步步走 TCP 三次握手,每步列出客户端和服务端的状态,标出这一步变了的那一方。
|
|
20
19
|
---
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
{@body const [step, setStep] = DIL.useState(0)}
|
|
21
|
+
{@body const clientStates = ["CLOSED", "SYN-SENT", "ESTABLISHED", "ESTABLISHED"]}
|
|
22
|
+
{@body const serverStates = ["LISTEN", "SYN-RCVD", "SYN-RCVD", "ESTABLISHED"]}
|
|
23
|
+
{@body const prev = max(step - 1, 0)}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<steps bind="step">
|
|
28
|
+
<step title="开始">服务端在 LISTEN 等连接。</step>
|
|
29
|
+
<step title="SYN">客户端发 SYN;服务端收到后回 SYN+ACK,进入 SYN-RCVD。</step>
|
|
30
|
+
<step title="SYN+ACK">客户端收到 SYN+ACK,回 ACK,自己先进入 ESTABLISHED。</step>
|
|
31
|
+
<step title="ACK">服务端收到 ACK,也进入 ESTABLISHED。</step>
|
|
32
|
+
</steps>
|
|
33
|
+
|
|
34
|
+
<table columns={["一方", "状态"]}>
|
|
35
|
+
<row cells={["客户端", clientStates[step]]}
|
|
35
36
|
tones={step > 0 && clientStates[step] != clientStates[prev] ? "new" : "plain"} />
|
|
36
|
-
<
|
|
37
|
+
<row cells={["服务端", serverStates[step]]}
|
|
37
38
|
tones={step > 0 && serverStates[step] != serverStates[prev] ? "new" : "plain"} />
|
|
38
|
-
</
|
|
39
|
+
</table>
|
|
40
|
+
|
|
39
41
|
```
|
|
40
42
|
````
|
|
41
43
|
|