@perkyzz/emvb 0.4.0 → 0.6.0
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/README.md +23 -3
- package/THIRD_PARTY_NOTICES.md +23 -1
- package/licenses/exif-js.LICENSE +21 -0
- package/licenses/fflate.LICENSE +21 -0
- package/licenses/glfx.js.LICENSE +19 -0
- package/licenses/mini-photo-editor.LICENSE +21 -0
- package/licenses/photocn.LICENSE +21 -0
- package/package.json +5 -3
- package/src/admin/agents-api.ts +39 -0
- package/src/admin/editor/CommandPalette.tsx +43 -2
- package/src/admin/editor/Editor.tsx +33 -0
- package/src/admin/editor/Timeline.tsx +108 -6
- package/src/admin/editor/collection-previews.ts +6 -1
- package/src/admin/editor/editor-chrome.tsx +49 -0
- package/src/admin/editor/editor-commands.ts +13 -0
- package/src/admin/editor/editor-css.ts +7 -0
- package/src/admin/editor/feature-css.ts +22 -3
- package/src/admin/editor/palette.ts +6 -2
- package/src/admin/editor/panels/ColorControl.tsx +24 -12
- package/src/admin/editor/panels/ElementPanel.tsx +1 -1
- package/src/admin/editor/panels/LayersPanel.tsx +13 -3
- package/src/admin/editor/panels/TokenScales.tsx +4 -2
- package/src/admin/editor/panels/VariableSection.tsx +5 -3
- package/src/admin/editor/panels/color-space.ts +12 -1
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +84 -28
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +42 -4
- package/src/admin/editor/panels/settings/DraftTextField.tsx +38 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +24 -7
- package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +156 -7
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +76 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- package/src/admin/editor/panels/settings/link-rules.ts +19 -0
- package/src/admin/editor/panels/settings/number-input.ts +11 -0
- package/src/admin/editor/panels/settings/query-style.ts +65 -0
- package/src/admin/editor/panels/variable-values.ts +18 -2
- package/src/admin/editor/remote-change.ts +67 -0
- package/src/admin/editor/store.ts +7 -3
- package/src/admin/image-editor/BlurFocus.tsx +112 -0
- package/src/admin/image-editor/Canvas.tsx +261 -0
- package/src/admin/image-editor/CropOverlay.tsx +390 -0
- package/src/admin/image-editor/CurvesPanel.tsx +394 -0
- package/src/admin/image-editor/ExportDialog.tsx +354 -0
- package/src/admin/image-editor/ImageEditButton.tsx +83 -0
- package/src/admin/image-editor/ImageEditorDialog.tsx +786 -0
- package/src/admin/image-editor/MetadataPanel.tsx +183 -0
- package/src/admin/image-editor/announce.tsx +65 -0
- package/src/admin/image-editor/crop-geometry.ts +161 -0
- package/src/admin/image-editor/curve-math.ts +177 -0
- package/src/admin/image-editor/data-url-fetch.ts +59 -0
- package/src/admin/image-editor/engine.ts +55 -0
- package/src/admin/image-editor/exif.ts +82 -0
- package/src/admin/image-editor/flatten.ts +54 -0
- package/src/admin/image-editor/gpu-fit.ts +81 -0
- package/src/admin/image-editor/image-editor-css.ts +398 -0
- package/src/admin/image-editor/load.ts +109 -0
- package/src/admin/image-editor/panels.tsx +287 -0
- package/src/admin/image-editor/parts.tsx +565 -0
- package/src/admin/image-editor/save.ts +125 -0
- package/src/admin/image-editor/tone-panels.tsx +338 -0
- package/src/admin/image-editor/tools.ts +59 -0
- package/src/admin/image-editor/worker.ts +111 -0
- package/src/admin/index.tsx +3 -1
- package/src/admin/media-api.ts +132 -2
- package/src/admin/pages/AgentsPage.tsx +274 -0
- package/src/admin/ui.ts +33 -0
- package/src/astro/EmVBPage.astro +11 -2
- package/src/astro/floats/runtime.ts +10 -0
- package/src/astro/popups/runtime.ts +15 -0
- package/src/astro/render.ts +3 -0
- package/src/astro/resolve-theme.ts +15 -4
- package/src/astro/tabs/runtime.ts +60 -1
- package/src/astro/visitor.ts +4 -3
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +202 -26
- package/src/core/arrange.ts +13 -3
- package/src/core/css/generate.ts +9 -1
- package/src/core/data/bindings.ts +12 -6
- package/src/core/design/classes.ts +5 -3
- package/src/core/design/diff.ts +3 -1
- package/src/core/design/merge.ts +3 -1
- package/src/core/design/transfer.ts +13 -2
- package/src/core/design/variables.ts +2 -1
- package/src/core/elements/dynamic-elements.ts +9 -1
- package/src/core/elements/form-elements.ts +18 -3
- package/src/core/elements/index.ts +39 -11
- package/src/core/elements/plain-text.ts +2 -2
- package/src/core/forms/binding.ts +148 -1
- package/src/core/history/diff.ts +32 -4
- package/src/core/image-edit/schema.ts +145 -0
- package/src/core/image-edit/summary.ts +58 -0
- package/src/core/index.ts +14 -0
- package/src/core/limits.ts +10 -0
- package/src/core/migrate/index.ts +3 -1
- package/src/core/perf/meter.ts +9 -1
- package/src/core/render/dynamic-post.ts +23 -6
- package/src/core/render/form.ts +36 -11
- package/src/core/render/index.ts +75 -15
- package/src/core/render/pagination.ts +21 -2
- package/src/core/sanitize/embed-url.ts +7 -1
- package/src/core/sanitize/href.ts +13 -1
- package/src/core/schema/descriptors.ts +4 -1
- package/src/core/schema/layout.ts +21 -4
- package/src/core/share/link.ts +9 -3
- package/src/core/stable-json.ts +15 -0
- package/src/core/theme/dynamic.ts +32 -24
- package/src/core/theme/pagination.ts +30 -3
- package/src/core/theme/popup-rules.ts +10 -5
- package/src/mcp/errors.ts +44 -0
- package/src/mcp/index.ts +4 -0
- package/src/mcp/ports.ts +85 -0
- package/src/mcp/prompts.ts +76 -0
- package/src/mcp/publish.ts +60 -0
- package/src/mcp/queue.ts +19 -0
- package/src/mcp/rate-limit.ts +80 -0
- package/src/mcp/read.ts +486 -0
- package/src/mcp/refs.ts +84 -0
- package/src/mcp/settings.ts +18 -0
- package/src/mcp/tools.ts +265 -0
- package/src/mcp/write.ts +664 -0
- package/src/server/agent-settings.ts +159 -0
- package/src/server/design-routes.ts +71 -17
- package/src/server/icon-routes.ts +13 -6
- package/src/server/mcp-routes.ts +323 -0
- package/src/server/plugin.ts +32 -2
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { Banner, ClipboardText, Empty, Loader, Switch, Table } from "@cloudflare/kumo";
|
|
2
|
+
import {
|
|
3
|
+
ArrowSquareOutIcon,
|
|
4
|
+
GlobeIcon,
|
|
5
|
+
LockKeyIcon,
|
|
6
|
+
PlugsConnectedIcon,
|
|
7
|
+
RobotIcon,
|
|
8
|
+
ShieldCheckIcon,
|
|
9
|
+
TerminalWindowIcon,
|
|
10
|
+
UploadSimpleIcon,
|
|
11
|
+
WarningCircleIcon,
|
|
12
|
+
type Icon,
|
|
13
|
+
} from "@phosphor-icons/react";
|
|
14
|
+
import type { ReactNode } from "react";
|
|
15
|
+
import { useEffect, useState } from "react";
|
|
16
|
+
import { defaultFetcher, type Fetcher } from "../api.ts";
|
|
17
|
+
import { loadAgents, saveAgentSettings, type AgentsState } from "../agents-api.ts";
|
|
18
|
+
import { useRole } from "../access/role.ts";
|
|
19
|
+
import { editorUrl } from "../editor/exit.ts";
|
|
20
|
+
import type { AgentSettings } from "../../mcp/settings.ts";
|
|
21
|
+
import { UI_CSS } from "../ui.ts";
|
|
22
|
+
|
|
23
|
+
const ADMIN_ROLE = 50;
|
|
24
|
+
|
|
25
|
+
/** The stdio bridge config a person pastes into their MCP client (plan § 4). */
|
|
26
|
+
const stdioSnippet = (site: string) =>
|
|
27
|
+
JSON.stringify(
|
|
28
|
+
{
|
|
29
|
+
mcpServers: {
|
|
30
|
+
emvb: {
|
|
31
|
+
command: "npx",
|
|
32
|
+
args: ["-y", "@perkyzz/emvb-mcp", "--site", site],
|
|
33
|
+
env: { EMVB_TOKEN: "<your EmDash API token>" },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
null,
|
|
38
|
+
2,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const remoteSnippet = (endpoint: string) =>
|
|
42
|
+
JSON.stringify({ mcpServers: { emvb: { url: endpoint } } }, null, 2);
|
|
43
|
+
|
|
44
|
+
/** A card's heading row: an icon tile, the title and one line on what the card is for (W-477). */
|
|
45
|
+
function SectionHead({
|
|
46
|
+
id,
|
|
47
|
+
icon: SectionIcon,
|
|
48
|
+
title,
|
|
49
|
+
children,
|
|
50
|
+
}: {
|
|
51
|
+
id: string;
|
|
52
|
+
icon: Icon;
|
|
53
|
+
title: string;
|
|
54
|
+
children: ReactNode;
|
|
55
|
+
}) {
|
|
56
|
+
return (
|
|
57
|
+
<div className="emvb-agents-head">
|
|
58
|
+
<span className="emvb-agents-icon" aria-hidden="true">
|
|
59
|
+
<SectionIcon size={18} />
|
|
60
|
+
</span>
|
|
61
|
+
<div>
|
|
62
|
+
<h2 id={id}>{title}</h2>
|
|
63
|
+
<p>{children}</p>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** AI agents (`/agents`, W-463): the master switch, publishing, how to connect, recent activity. */
|
|
70
|
+
export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher }) {
|
|
71
|
+
const role = useRole(fetcher);
|
|
72
|
+
const [state, setState] = useState<AgentsState | null>(null);
|
|
73
|
+
const [error, setError] = useState<string | null>(null);
|
|
74
|
+
const [saving, setSaving] = useState(false);
|
|
75
|
+
const isAdmin = role.state === "ready" && role.role >= ADMIN_ROLE;
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (!isAdmin) return;
|
|
79
|
+
loadAgents(fetcher)
|
|
80
|
+
.then(setState)
|
|
81
|
+
.catch((e: unknown) => setError(e instanceof Error ? e.message : String(e)));
|
|
82
|
+
}, [fetcher, isAdmin]);
|
|
83
|
+
|
|
84
|
+
if (role.state === "loading") return <Loader />;
|
|
85
|
+
if (!isAdmin) {
|
|
86
|
+
return (
|
|
87
|
+
<section data-emvb-access="denied">
|
|
88
|
+
<Empty
|
|
89
|
+
icon={<LockKeyIcon aria-hidden="true" />}
|
|
90
|
+
title="Only administrators can manage AI agents"
|
|
91
|
+
description="Ask an administrator to change these settings."
|
|
92
|
+
/>
|
|
93
|
+
</section>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
if (error) {
|
|
97
|
+
return (
|
|
98
|
+
<Banner
|
|
99
|
+
variant="error"
|
|
100
|
+
icon={<WarningCircleIcon aria-hidden="true" />}
|
|
101
|
+
title="Couldn't load the AI agent settings"
|
|
102
|
+
description={error}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (!state) return <Loader />;
|
|
107
|
+
|
|
108
|
+
const change = async (patch: Partial<AgentSettings>) => {
|
|
109
|
+
const settings = { ...state.settings, ...patch };
|
|
110
|
+
setSaving(true);
|
|
111
|
+
try {
|
|
112
|
+
const revision = await saveAgentSettings(fetcher, settings, state.revision);
|
|
113
|
+
setState({ ...state, settings, revision });
|
|
114
|
+
} catch (e) {
|
|
115
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
116
|
+
} finally {
|
|
117
|
+
setSaving(false);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const site = new URL(state.endpoint).origin;
|
|
121
|
+
const { settings } = state;
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<div className="emvb-pages emvb-agents" data-emvb-agents="ready">
|
|
125
|
+
<style>{UI_CSS}</style>
|
|
126
|
+
<header className="emvb-agents-header">
|
|
127
|
+
<div>
|
|
128
|
+
<h1 className="emvb-page-title">AI agents</h1>
|
|
129
|
+
<p>Let AI assistants build and edit EmVB pages through MCP. They only change drafts.</p>
|
|
130
|
+
</div>
|
|
131
|
+
<span className="emvb-agents-status" data-on={settings.mcpEnabled ? "true" : "false"}>
|
|
132
|
+
<span aria-hidden="true" />
|
|
133
|
+
{settings.mcpEnabled ? "Agents on" : "Agents off"}
|
|
134
|
+
</span>
|
|
135
|
+
</header>
|
|
136
|
+
<section
|
|
137
|
+
className="emvb-surface-card emvb-agents-section"
|
|
138
|
+
aria-labelledby="emvb-agents-access"
|
|
139
|
+
>
|
|
140
|
+
<SectionHead id="emvb-agents-access" icon={ShieldCheckIcon} title="Access">
|
|
141
|
+
The master switch. Turning it off refuses every agent call at once.
|
|
142
|
+
</SectionHead>
|
|
143
|
+
<div className="emvb-agents-option">
|
|
144
|
+
<Switch
|
|
145
|
+
label="Let AI agents edit EmVB pages"
|
|
146
|
+
checked={settings.mcpEnabled}
|
|
147
|
+
disabled={saving}
|
|
148
|
+
onCheckedChange={(checked: boolean) => void change({ mcpEnabled: checked })}
|
|
149
|
+
/>
|
|
150
|
+
<p>
|
|
151
|
+
Agents only change drafts. Every change shows in the page's version timeline and can be
|
|
152
|
+
restored.
|
|
153
|
+
</p>
|
|
154
|
+
</div>
|
|
155
|
+
<div className="emvb-agents-field">
|
|
156
|
+
<h3>MCP endpoint</h3>
|
|
157
|
+
<ClipboardText text={state.endpoint} />
|
|
158
|
+
</div>
|
|
159
|
+
</section>
|
|
160
|
+
<section
|
|
161
|
+
className="emvb-surface-card emvb-agents-section"
|
|
162
|
+
aria-labelledby="emvb-agents-publish"
|
|
163
|
+
>
|
|
164
|
+
<SectionHead id="emvb-agents-publish" icon={UploadSimpleIcon} title="Publishing">
|
|
165
|
+
Published changes go live immediately. Each one is still in the version timeline.
|
|
166
|
+
</SectionHead>
|
|
167
|
+
<div className="emvb-agents-option">
|
|
168
|
+
<Switch
|
|
169
|
+
label="Agents may publish pages"
|
|
170
|
+
checked={settings.publishPages}
|
|
171
|
+
disabled={saving || !settings.mcpEnabled}
|
|
172
|
+
onCheckedChange={(checked: boolean) => void change({ publishPages: checked })}
|
|
173
|
+
/>
|
|
174
|
+
<p>Off: agents save drafts and a person publishes them.</p>
|
|
175
|
+
</div>
|
|
176
|
+
<div className="emvb-agents-option">
|
|
177
|
+
<Switch
|
|
178
|
+
label="Agents may publish site styles"
|
|
179
|
+
checked={settings.publishStyles}
|
|
180
|
+
disabled={saving || !settings.mcpEnabled}
|
|
181
|
+
onCheckedChange={(checked: boolean) => void change({ publishStyles: checked })}
|
|
182
|
+
/>
|
|
183
|
+
<p>Site styles change every page at once, so leave this off unless you need it.</p>
|
|
184
|
+
</div>
|
|
185
|
+
</section>
|
|
186
|
+
<section
|
|
187
|
+
className="emvb-surface-card emvb-agents-section"
|
|
188
|
+
aria-labelledby="emvb-agents-connect"
|
|
189
|
+
>
|
|
190
|
+
<SectionHead id="emvb-agents-connect" icon={PlugsConnectedIcon} title="How to connect">
|
|
191
|
+
Create a token in EmDash → API tokens with the scope <code>mcp:tools:emvb</code> for a
|
|
192
|
+
user who is an editor or above. Never give an agent an admin token.
|
|
193
|
+
</SectionHead>
|
|
194
|
+
<div className="emvb-agents-snippets">
|
|
195
|
+
<div className="emvb-agents-snippet">
|
|
196
|
+
<h3>
|
|
197
|
+
<GlobeIcon aria-hidden="true" size={16} />
|
|
198
|
+
Remote (EmDash MCP, sign in with OAuth)
|
|
199
|
+
</h3>
|
|
200
|
+
<pre data-emvb-snippet="remote">{remoteSnippet(state.endpoint)}</pre>
|
|
201
|
+
</div>
|
|
202
|
+
<div className="emvb-agents-snippet">
|
|
203
|
+
<h3>
|
|
204
|
+
<TerminalWindowIcon aria-hidden="true" size={16} />
|
|
205
|
+
Local (stdio)
|
|
206
|
+
</h3>
|
|
207
|
+
<pre data-emvb-snippet="stdio">{stdioSnippet(site)}</pre>
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
</section>
|
|
211
|
+
<section
|
|
212
|
+
className="emvb-surface-card emvb-agents-section"
|
|
213
|
+
aria-labelledby="emvb-agents-activity"
|
|
214
|
+
>
|
|
215
|
+
<SectionHead id="emvb-agents-activity" icon={RobotIcon} title="Recent agent activity">
|
|
216
|
+
The latest changes agents made, newest first.
|
|
217
|
+
</SectionHead>
|
|
218
|
+
{state.activity.length === 0 ? (
|
|
219
|
+
<div data-emvb-agents-empty="">
|
|
220
|
+
<Empty
|
|
221
|
+
icon={<RobotIcon aria-hidden="true" />}
|
|
222
|
+
title="No agent changes yet"
|
|
223
|
+
description="When an agent edits a page, it shows up here with a link to the editor."
|
|
224
|
+
/>
|
|
225
|
+
</div>
|
|
226
|
+
) : (
|
|
227
|
+
<div className="emvb-agents-table">
|
|
228
|
+
<Table>
|
|
229
|
+
<Table.Header>
|
|
230
|
+
<Table.Row>
|
|
231
|
+
<Table.Head>When</Table.Head>
|
|
232
|
+
<Table.Head>Who</Table.Head>
|
|
233
|
+
<Table.Head>Change</Table.Head>
|
|
234
|
+
<Table.Head>Page</Table.Head>
|
|
235
|
+
</Table.Row>
|
|
236
|
+
</Table.Header>
|
|
237
|
+
<Table.Body>
|
|
238
|
+
{state.activity.map((entry) => (
|
|
239
|
+
<Table.Row key={entry.id}>
|
|
240
|
+
<Table.Cell>
|
|
241
|
+
<span className="emvb-agents-when">
|
|
242
|
+
{new Date(entry.at).toLocaleString()}
|
|
243
|
+
</span>
|
|
244
|
+
</Table.Cell>
|
|
245
|
+
<Table.Cell>
|
|
246
|
+
<span className="emvb-agents-who">
|
|
247
|
+
<span className="emvb-timeline-agent">
|
|
248
|
+
<RobotIcon aria-hidden="true" size={12} />
|
|
249
|
+
{entry.client ?? "Agent"}
|
|
250
|
+
</span>
|
|
251
|
+
{entry.userId ?? "unknown"}
|
|
252
|
+
</span>
|
|
253
|
+
</Table.Cell>
|
|
254
|
+
<Table.Cell>{entry.summary}</Table.Cell>
|
|
255
|
+
<Table.Cell>
|
|
256
|
+
{entry.pageId ? (
|
|
257
|
+
<a className="emvb-agents-link" href={editorUrl(entry.pageId)}>
|
|
258
|
+
Open in editor
|
|
259
|
+
<ArrowSquareOutIcon aria-hidden="true" size={14} />
|
|
260
|
+
</a>
|
|
261
|
+
) : (
|
|
262
|
+
"—"
|
|
263
|
+
)}
|
|
264
|
+
</Table.Cell>
|
|
265
|
+
</Table.Row>
|
|
266
|
+
))}
|
|
267
|
+
</Table.Body>
|
|
268
|
+
</Table>
|
|
269
|
+
</div>
|
|
270
|
+
)}
|
|
271
|
+
</section>
|
|
272
|
+
</div>
|
|
273
|
+
);
|
|
274
|
+
}
|
package/src/admin/ui.ts
CHANGED
|
@@ -47,6 +47,11 @@ export const UI_CSS = `
|
|
|
47
47
|
.emvb-mono { font-family: var(--font-mono); }
|
|
48
48
|
.emvb-helper { margin: 0; font-size: 12px; line-height: 16px; color: var(--text-color-kumo-subtle); }
|
|
49
49
|
.emvb-helper a { color: var(--text-color-kumo-default); text-decoration: underline; text-underline-offset: 2px; }
|
|
50
|
+
.emvb-required-notice { margin-top: 4px; }
|
|
51
|
+
.emvb-required-notice__list { margin: 6px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 12px; line-height: 16px; }
|
|
52
|
+
.emvb-required-notice__list > li { padding-inline-start: 10px; border-inline-start: 2px solid currentColor; }
|
|
53
|
+
.emvb-required-notice__list strong { font-weight: 600; }
|
|
54
|
+
.emvb-required-notice__hint { display: block; margin-top: 8px; font-size: 12px; line-height: 16px; opacity: 0.85; }
|
|
50
55
|
.emvb-inline-error { display: flex; gap: 4px; align-items: flex-start; margin: 0; font-size: 12px; line-height: 16px; color: var(--text-color-kumo-danger); }
|
|
51
56
|
.emvb-status {
|
|
52
57
|
display: inline-flex;
|
|
@@ -91,6 +96,34 @@ export const UI_CSS = `
|
|
|
91
96
|
backdrop-filter: blur(var(--emvb-glass-blur, 6px));
|
|
92
97
|
box-shadow: var(--emvb-elevation-s);
|
|
93
98
|
}
|
|
99
|
+
/* Live MCP test: the AI agents page reads as cards with clear headings, not bare browser defaults. */
|
|
100
|
+
.emvb-agents { max-width: 960px; }
|
|
101
|
+
.emvb-agents-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
|
|
102
|
+
.emvb-agents-header p { margin: 4px 0 0; font-size: 14px; line-height: 20px; color: var(--text-color-kumo-subtle); }
|
|
103
|
+
.emvb-agents-status { display: inline-flex; flex: none; align-items: center; gap: 6px; margin-top: 6px; padding: 2px 10px; border: 1px solid var(--color-kumo-line); border-radius: 999px; background: var(--color-kumo-base); color: var(--text-color-kumo-default); font-size: 12px; line-height: 20px; font-weight: 600; }
|
|
104
|
+
.emvb-agents-status > span { width: 8px; height: 8px; border-radius: 999px; background: var(--text-color-kumo-subtle); }
|
|
105
|
+
.emvb-agents-status[data-on="true"] > span { background: var(--text-color-kumo-success); }
|
|
106
|
+
.emvb-agents-section { gap: 16px; padding: 20px; }
|
|
107
|
+
.emvb-agents-head { display: flex; align-items: flex-start; gap: 12px; }
|
|
108
|
+
.emvb-agents-icon { display: grid; flex: none; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--color-kumo-tint); color: var(--text-color-kumo-default); }
|
|
109
|
+
.emvb-agents-section h2 { margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; color: var(--text-color-kumo-default); }
|
|
110
|
+
.emvb-agents-section h3 { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; line-height: 20px; font-weight: 600; color: var(--text-color-kumo-default); }
|
|
111
|
+
.emvb-agents-section p { margin: 0; font-size: 14px; line-height: 20px; color: var(--text-color-kumo-subtle); }
|
|
112
|
+
.emvb-agents-section code { padding: 1px 5px; border-radius: 4px; background: var(--color-kumo-tint); font-family: var(--font-mono); font-size: 12px; }
|
|
113
|
+
.emvb-agents-option { display: grid; gap: 4px; padding-top: 16px; border-top: 1px solid var(--color-kumo-line); }
|
|
114
|
+
.emvb-agents-option > p { padding-inline-start: 44px; font-size: 13px; }
|
|
115
|
+
.emvb-agents-field { display: grid; gap: 6px; }
|
|
116
|
+
.emvb-agents-snippets { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
|
|
117
|
+
.emvb-agents-snippet { display: grid; align-content: start; gap: 8px; min-width: 0; padding: 12px; border: 1px solid var(--color-kumo-line); border-radius: 8px; }
|
|
118
|
+
.emvb-agents-section pre { margin: 0; padding: 12px; overflow-x: auto; border-radius: 6px; background: var(--color-kumo-recessed, rgba(127,127,127,.08)); font-family: var(--font-mono); font-size: 12px; line-height: 18px; }
|
|
119
|
+
.emvb-agents-table { overflow-x: auto; margin-inline: -20px; margin-bottom: -20px; border-top: 1px solid var(--color-kumo-line); }
|
|
120
|
+
.emvb-agents-table table { width: 100%; }
|
|
121
|
+
.emvb-agents-when { color: var(--text-color-kumo-subtle); font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
122
|
+
.emvb-agents-who { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
|
|
123
|
+
.emvb-agents-link { display: inline-flex; align-items: center; gap: 4px; color: var(--text-color-kumo-link, var(--text-color-kumo-brand)); font-weight: 500; white-space: nowrap; }
|
|
124
|
+
.emvb-agents-link:hover { text-decoration: underline; }
|
|
125
|
+
.emvb-agents-link:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 2px; border-radius: 4px; }
|
|
126
|
+
.emvb-timeline-agent { display: inline-flex; flex: none; align-items: center; gap: 3px; padding: 1px 7px 1px 5px; border: 1px solid var(--color-kumo-line); border-radius: 999px; background: var(--color-kumo-base); color: var(--text-color-kumo-default); font-size: 11px; line-height: 16px; font-weight: 600; }
|
|
94
127
|
.emvb-surface-card[data-emvb-list] { gap: 0; padding: 0; overflow: hidden; }
|
|
95
128
|
.emvb-surface-card[data-emvb-list] table { width: 100%; }
|
|
96
129
|
.emvb-surface-card .emvb-empty-shell,
|
package/src/astro/EmVBPage.astro
CHANGED
|
@@ -21,16 +21,25 @@ interface Props {
|
|
|
21
21
|
* canonical, robots (No index), Open Graph and Twitter card. Pass `getSeoMeta(entry, …)`.
|
|
22
22
|
*/
|
|
23
23
|
seo?: PageMeta;
|
|
24
|
+
/**
|
|
25
|
+
* W-528: the document language in blank canvas mode, e.g. "fr-CA". Defaults to the request's
|
|
26
|
+
* Astro locale, then "en"; it was always "en", so screen readers read other sites in English.
|
|
27
|
+
*/
|
|
28
|
+
lang?: string;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
|
|
31
|
+
/** A BCP 47-shaped language tag, or undefined. */
|
|
32
|
+
const LANG_TAG = /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/;
|
|
33
|
+
|
|
34
|
+
const { page, standalone = false, title = "", description, seo, lang } = Astro.props;
|
|
35
|
+
const docLang = [lang, Astro.currentLocale].find((tag) => tag && LANG_TAG.test(tag)) ?? "en";
|
|
27
36
|
const ogTitle = seo?.ogTitle || title;
|
|
28
37
|
const ogDescription = seo?.ogDescription ?? description;
|
|
29
38
|
---
|
|
30
39
|
|
|
31
40
|
{
|
|
32
41
|
standalone ? (
|
|
33
|
-
<html lang=
|
|
42
|
+
<html lang={docLang} dir={page.dir}>
|
|
34
43
|
<head>
|
|
35
44
|
<meta charset="utf-8" />
|
|
36
45
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
@@ -59,6 +59,10 @@ function hide(el: HTMLElement): void {
|
|
|
59
59
|
|
|
60
60
|
/** Hide floats already closed this visit, then keep bars stacked. */
|
|
61
61
|
export function initFloats(): void {
|
|
62
|
+
// W-407: a second call (a host loading the script twice) added a second click handler.
|
|
63
|
+
const marked = document.documentElement;
|
|
64
|
+
if (marked.dataset["emvbFloatsReady"] === "1") return;
|
|
65
|
+
marked.dataset["emvbFloatsReady"] = "1";
|
|
62
66
|
for (const el of bars()) {
|
|
63
67
|
const id = el.getAttribute("data-emvb-float");
|
|
64
68
|
if (id && closed(id)) el.hidden = true;
|
|
@@ -75,4 +79,10 @@ export function initFloats(): void {
|
|
|
75
79
|
hide(float);
|
|
76
80
|
});
|
|
77
81
|
window.addEventListener("resize", placeFloats);
|
|
82
|
+
// W-407: a bar's height also changes without a window resize (web fonts arriving, text
|
|
83
|
+
// wrapping once styles load), which left the reserved padding short and the bar over content.
|
|
84
|
+
if (typeof ResizeObserver === "function") {
|
|
85
|
+
const observer = new ResizeObserver(() => placeFloats());
|
|
86
|
+
for (const el of bars()) observer.observe(el);
|
|
87
|
+
}
|
|
78
88
|
}
|
|
@@ -177,6 +177,21 @@ function bindA11y(ctrl: Controller): void {
|
|
|
177
177
|
ctrl.close();
|
|
178
178
|
}
|
|
179
179
|
});
|
|
180
|
+
// W-406: when the focused control disappears (a form swapped for its thank-you message), focus
|
|
181
|
+
// falls to <body>; Escape and Tab then never reached the dialog, so the popup couldn't be closed
|
|
182
|
+
// from the keyboard and Tab walked the page behind it.
|
|
183
|
+
document.addEventListener("keydown", (event) => {
|
|
184
|
+
if (!ctrl.opened || event.defaultPrevented || !ctrl.root.isConnected) return;
|
|
185
|
+
const active = document.activeElement;
|
|
186
|
+
if (active && active !== document.body && active !== document.documentElement) return;
|
|
187
|
+
if (event.key === "Tab") {
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
(focusables(ctrl.dialog)[0] ?? ctrl.dialog).focus();
|
|
190
|
+
} else if (event.key === "Escape") {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
ctrl.close();
|
|
193
|
+
}
|
|
194
|
+
});
|
|
180
195
|
ctrl.dialog.addEventListener("keydown", (event) => {
|
|
181
196
|
if (event.key === "Escape") {
|
|
182
197
|
event.preventDefault();
|
package/src/astro/render.ts
CHANGED
|
@@ -70,6 +70,8 @@ export function renderStored(
|
|
|
70
70
|
pageId: string,
|
|
71
71
|
formDefinitions?: FormDefinitions,
|
|
72
72
|
dynamic?: ThemeDynamicData,
|
|
73
|
+
/** A theme part: generated ids get a suffix of its own (W-527). */
|
|
74
|
+
partIds = false,
|
|
73
75
|
): RenderedPage {
|
|
74
76
|
const { layout, problem } = inspectLayout(raw);
|
|
75
77
|
if (!layout) {
|
|
@@ -95,6 +97,7 @@ export function renderStored(
|
|
|
95
97
|
formDefinitions,
|
|
96
98
|
dynamic,
|
|
97
99
|
scope: pageId,
|
|
100
|
+
...(partIds ? { partIds } : {}),
|
|
98
101
|
},
|
|
99
102
|
);
|
|
100
103
|
return {
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
type TriggersDoc,
|
|
30
30
|
archivePagePath,
|
|
31
31
|
loopPerPage,
|
|
32
|
+
paginationTitleText,
|
|
32
33
|
type ArchivePagination,
|
|
33
34
|
} from "../core/index.ts";
|
|
34
35
|
import { THEME_PARTS_COLLECTION } from "../constants.ts";
|
|
@@ -105,11 +106,16 @@ export type ResolvedThemeParts = {
|
|
|
105
106
|
canonicalPath?: string;
|
|
106
107
|
/**
|
|
107
108
|
* The archive's title when an Archive part renders: "Posts", or the category/tag slug
|
|
108
|
-
* (W-229). Hosts build "Posts – page 2" with `archivePageTitle`.
|
|
109
|
+
* (W-229). Hosts build "Posts – page 2" with `archivePageTitle` and `archiveTitleText`.
|
|
109
110
|
*/
|
|
110
111
|
archiveTitle?: string;
|
|
111
112
|
/** The archive page number when an Archive part renders (1 for the bare URL). */
|
|
112
113
|
archivePage?: number;
|
|
114
|
+
/**
|
|
115
|
+
* The Archive part's Pagination "Page title text", when set (W-529). Pass it to
|
|
116
|
+
* `archivePageTitle(archiveTitle, page, archiveTitleText)` for the site's own wording.
|
|
117
|
+
*/
|
|
118
|
+
archiveTitleText?: string;
|
|
113
119
|
/** The site's text direction from Site styles when a part renders, for `<html dir>` (W-230). */
|
|
114
120
|
dir?: "ltr" | "rtl" | "auto";
|
|
115
121
|
};
|
|
@@ -484,7 +490,7 @@ export async function resolveThemePartsWith(
|
|
|
484
490
|
...Object.values(dynamic?.loopTemplates ?? {}),
|
|
485
491
|
]),
|
|
486
492
|
);
|
|
487
|
-
const page = renderStored(stored.layout, design, stored.id, formDefinitions, dynamic);
|
|
493
|
+
const page = renderStored(stored.layout, design, stored.id, formDefinitions, dynamic, true);
|
|
488
494
|
rendered.push(page);
|
|
489
495
|
// W-216: a header or footer part is the page's banner or contentinfo landmark (hosts put it
|
|
490
496
|
// straight in <body> instead of their own <header>/<footer>).
|
|
@@ -511,7 +517,7 @@ export async function resolveThemePartsWith(
|
|
|
511
517
|
};
|
|
512
518
|
|
|
513
519
|
let pastLastPage = false;
|
|
514
|
-
let archiveInfo: { title?: string; page: number } | undefined;
|
|
520
|
+
let archiveInfo: { title?: string; page: number; titleText?: string } | undefined;
|
|
515
521
|
const renderPart = async (
|
|
516
522
|
winner: ThemePartCandidate | null,
|
|
517
523
|
): Promise<RenderedThemePart | null> => {
|
|
@@ -528,7 +534,11 @@ export async function resolveThemePartsWith(
|
|
|
528
534
|
: referenced;
|
|
529
535
|
// A page past the last one has no posts; the host answers 404 (W-221).
|
|
530
536
|
if (winner === contentWinner && dynamic?.pagination) {
|
|
531
|
-
archiveInfo = {
|
|
537
|
+
archiveInfo = {
|
|
538
|
+
title: dynamic.archiveTitle,
|
|
539
|
+
page: dynamic.pagination.page,
|
|
540
|
+
titleText: layout ? paginationTitleText(layout) : undefined,
|
|
541
|
+
};
|
|
532
542
|
}
|
|
533
543
|
if (winner === contentWinner && (dynamic?.pagination?.page ?? 1) > 1) {
|
|
534
544
|
pastLastPage = (dynamic?.posts ?? []).length === 0;
|
|
@@ -630,6 +640,7 @@ export async function resolveThemePartsWith(
|
|
|
630
640
|
...(design.direction ? { dir: design.direction } : {}),
|
|
631
641
|
...(archiveInfo?.title ? { archiveTitle: archiveInfo.title } : {}),
|
|
632
642
|
...(archiveInfo ? { archivePage: archiveInfo.page } : {}),
|
|
643
|
+
...(archiveInfo?.titleText ? { archiveTitleText: archiveInfo.titleText } : {}),
|
|
633
644
|
...(empty.canonicalPath ? { canonicalPath: empty.canonicalPath } : {}),
|
|
634
645
|
};
|
|
635
646
|
}
|
|
@@ -90,7 +90,15 @@ function enhance(root: HTMLElement): void {
|
|
|
90
90
|
activate(root, selectedIndex(root));
|
|
91
91
|
|
|
92
92
|
list.addEventListener("keydown", (event) => {
|
|
93
|
-
|
|
93
|
+
// W-405: in right-to-left text the first tab is on the right, so the arrows swap.
|
|
94
|
+
const rtl = list.closest("[dir]")?.getAttribute("dir")?.toLowerCase() === "rtl";
|
|
95
|
+
const key =
|
|
96
|
+
rtl && event.key === "ArrowRight"
|
|
97
|
+
? "ArrowLeft"
|
|
98
|
+
: rtl && event.key === "ArrowLeft"
|
|
99
|
+
? "ArrowRight"
|
|
100
|
+
: event.key;
|
|
101
|
+
const target = KEY_TARGETS[key];
|
|
94
102
|
if (!target) return;
|
|
95
103
|
event.preventDefault();
|
|
96
104
|
if (labels.length === 0) return;
|
|
@@ -105,9 +113,60 @@ function enhance(root: HTMLElement): void {
|
|
|
105
113
|
});
|
|
106
114
|
}
|
|
107
115
|
|
|
116
|
+
/**
|
|
117
|
+
* W-414: opens every closed tab around `target` (outermost first) so a link to something inside a
|
|
118
|
+
* tab, a table of contents entry most often, lands on it. True when a tab was opened.
|
|
119
|
+
*/
|
|
120
|
+
function revealInTabs(target: Element): boolean {
|
|
121
|
+
const steps: { root: HTMLElement; index: number }[] = [];
|
|
122
|
+
let panel = target.closest<HTMLElement>(".emvb-tab-panel");
|
|
123
|
+
while (panel) {
|
|
124
|
+
const root = panel.parentElement?.parentElement;
|
|
125
|
+
if (root?.classList.contains("emvb-tabs")) {
|
|
126
|
+
const index = parts(root).panels.indexOf(panel);
|
|
127
|
+
if (index >= 0) steps.unshift({ root, index });
|
|
128
|
+
}
|
|
129
|
+
panel = root?.parentElement?.closest<HTMLElement>(".emvb-tab-panel") ?? null;
|
|
130
|
+
}
|
|
131
|
+
let opened = false;
|
|
132
|
+
for (const { root, index } of steps) {
|
|
133
|
+
if (selectedIndex(root) === index) continue;
|
|
134
|
+
activate(root, index);
|
|
135
|
+
opened = true;
|
|
136
|
+
}
|
|
137
|
+
return opened;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function targetOf(hash: string): Element | null {
|
|
141
|
+
if (!hash || hash === "#") return null;
|
|
142
|
+
try {
|
|
143
|
+
return document.getElementById(decodeURIComponent(hash.slice(1)));
|
|
144
|
+
} catch {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** After opening a tab, the browser's own jump already happened, so scroll again. */
|
|
150
|
+
function revealHash(hash: string): void {
|
|
151
|
+
const target = targetOf(hash);
|
|
152
|
+
if (!target || !revealInTabs(target)) return;
|
|
153
|
+
target.scrollIntoView?.({ block: "start" });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let hashWatch = false;
|
|
157
|
+
|
|
108
158
|
export function initTabs(root: ParentNode = document): void {
|
|
109
159
|
const nodes = root.querySelectorAll<HTMLElement>(".emvb-tabs");
|
|
110
160
|
for (const node of nodes) enhance(node);
|
|
161
|
+
if (hashWatch || typeof window === "undefined") return;
|
|
162
|
+
hashWatch = true;
|
|
163
|
+
// A link to the page's own anchors, then the URL's hash on load and on back/forward.
|
|
164
|
+
document.addEventListener("click", (event) => {
|
|
165
|
+
const link = (event.target as Element | null)?.closest?.<HTMLAnchorElement>('a[href^="#"]');
|
|
166
|
+
if (link) revealHash(link.getAttribute("href") ?? "");
|
|
167
|
+
});
|
|
168
|
+
window.addEventListener("hashchange", () => revealHash(window.location.hash));
|
|
169
|
+
revealHash(window.location.hash);
|
|
111
170
|
}
|
|
112
171
|
|
|
113
172
|
/** Test helper: select tab by index after enhance. */
|
package/src/astro/visitor.ts
CHANGED
|
@@ -108,6 +108,8 @@ function requestCookie(astro: VisitorAstro, name: string): string | undefined {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
const COUNTRY = /^[A-Z]{2}$/;
|
|
111
|
+
/** XX is Cloudflare's "unknown" and T1 is Tor: neither is a country (W-514: host facts too). */
|
|
112
|
+
const isCountry = (code: string) => COUNTRY.test(code) && code !== "XX" && code !== "T1";
|
|
111
113
|
|
|
112
114
|
/**
|
|
113
115
|
* The visitor's country from the edge: Cloudflare's header or `request.cf`, or Vercel's header.
|
|
@@ -123,8 +125,7 @@ function countryOf(astro: VisitorAstro): string | undefined {
|
|
|
123
125
|
];
|
|
124
126
|
for (const value of candidates) {
|
|
125
127
|
const code = typeof value === "string" ? value.trim().toUpperCase() : "";
|
|
126
|
-
|
|
127
|
-
if (COUNTRY.test(code) && code !== "XX" && code !== "T1") return code;
|
|
128
|
+
if (isCountry(code)) return code;
|
|
128
129
|
}
|
|
129
130
|
return undefined;
|
|
130
131
|
}
|
|
@@ -159,7 +160,7 @@ export function hostVisitorFacts(host: HostVisitor | undefined): Partial<Visitor
|
|
|
159
160
|
facts.segments = segments;
|
|
160
161
|
}
|
|
161
162
|
const country = typeof host.country === "string" ? host.country.trim().toUpperCase() : "";
|
|
162
|
-
if (
|
|
163
|
+
if (isCountry(country)) facts.country = country;
|
|
163
164
|
if (host.device === "mobile" || host.device === "tablet" || host.device === "desktop")
|
|
164
165
|
facts.device = host.device;
|
|
165
166
|
if (typeof host.returning === "boolean") facts.returning = host.returning;
|
package/src/constants.ts
CHANGED