@perkyzz/emvb 0.2.1 → 0.3.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/package.json +1 -1
- package/src/admin/editor/A11yCopilot.tsx +126 -0
- package/src/admin/editor/CommandPalette.tsx +118 -0
- package/src/admin/editor/Editor.tsx +274 -12
- package/src/admin/editor/EditorOverlay.tsx +6 -0
- package/src/admin/editor/PerfMeter.tsx +121 -0
- package/src/admin/editor/ShareLink.tsx +164 -0
- package/src/admin/editor/Timeline.tsx +274 -0
- package/src/admin/editor/TopBar.tsx +4 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +12 -3
- package/src/admin/editor/canvas/SelectionOverlay.tsx +1 -1
- package/src/admin/editor/collection-previews.ts +91 -0
- package/src/admin/editor/editor-css.ts +5 -3
- package/src/admin/editor/feature-css.ts +105 -0
- package/src/admin/editor/host.ts +2 -0
- package/src/admin/editor/live-data.tsx +71 -0
- package/src/admin/editor/palette-items.ts +105 -0
- package/src/admin/editor/palette.ts +67 -0
- package/src/admin/editor/panels/AddPanel.tsx +47 -2
- package/src/admin/editor/panels/ClassesSection.tsx +5 -1
- package/src/admin/editor/panels/ElementPanel.tsx +34 -3
- package/src/admin/editor/panels/LayersPanel.tsx +38 -1
- package/src/admin/editor/panels/LeftPanel.tsx +4 -1
- package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +2 -0
- package/src/admin/editor/panels/TokenScales.tsx +168 -0
- package/src/admin/editor/panels/VariableSection.tsx +9 -4
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +215 -0
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
- package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
- package/src/admin/editor/panels/settings/MotionControl.tsx +252 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +12 -0
- package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
- package/src/admin/editor/panels/settings/length-units.ts +1 -1
- package/src/admin/editor/panels/settings/style-sections.ts +2 -1
- package/src/admin/editor/shortcuts.ts +2 -1
- package/src/admin/editor/useEditorShortcuts.ts +8 -0
- package/src/admin/editor/useNodeActions.ts +38 -15
- package/src/admin/ui.ts +4 -4
- package/src/astro/request-data.ts +97 -0
- package/src/astro/resolve-theme.ts +35 -5
- package/src/astro/resolve.ts +8 -2
- package/src/astro/theme-posts.ts +32 -0
- package/src/astro/visitor.ts +142 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +282 -0
- package/src/core/arrange.ts +91 -0
- package/src/core/audience/rules.ts +104 -0
- package/src/core/audience/variants.ts +51 -0
- package/src/core/css/generate.ts +20 -2
- package/src/core/css/trace.ts +169 -0
- package/src/core/data/bindings.ts +257 -0
- package/src/core/design/tokens.ts +127 -0
- package/src/core/elements/dynamic-elements.ts +87 -2
- package/src/core/elements/index.ts +2 -0
- package/src/core/history/diff.ts +152 -0
- package/src/core/index.ts +111 -0
- package/src/core/migrate/index.ts +4 -1
- package/src/core/nesting.ts +1 -0
- package/src/core/perf/meter.ts +160 -0
- package/src/core/perf/scripts.ts +58 -0
- package/src/core/recipes/index.ts +433 -0
- package/src/core/render/index.ts +51 -4
- package/src/core/render/loop.ts +54 -7
- package/src/core/render/pagination.ts +9 -1
- package/src/core/sanitize/css.ts +39 -3
- package/src/core/sanitize/motion.ts +129 -0
- package/src/core/schema/design.ts +25 -2
- package/src/core/schema/layout.ts +168 -18
- package/src/core/schema/motion.ts +14 -0
- package/src/core/schema/style.ts +48 -3
- package/src/core/share/link.ts +147 -0
- package/src/core/theme/dynamic.ts +49 -0
- package/src/core/theme/pagination.ts +56 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
BIND_SOURCES,
|
|
4
|
+
BIND_SOURCE_LABELS,
|
|
5
|
+
POST_BIND_KEYS,
|
|
6
|
+
SITE_BIND_KEYS,
|
|
7
|
+
bindableFields,
|
|
8
|
+
boundValue,
|
|
9
|
+
resolveBinding,
|
|
10
|
+
withBinding,
|
|
11
|
+
type BindSource,
|
|
12
|
+
type Binding,
|
|
13
|
+
type LayoutNode,
|
|
14
|
+
type ThemePostFields,
|
|
15
|
+
} from "../../../../core/index.ts";
|
|
16
|
+
import { siteOrigin, useLiveData } from "../../live-data.tsx";
|
|
17
|
+
|
|
18
|
+
const KEY = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;
|
|
19
|
+
const STATIC = "static";
|
|
20
|
+
|
|
21
|
+
/** Suggested keys for a source; any other key can be typed. */
|
|
22
|
+
function suggestions(source: BindSource, site: Readonly<Record<string, string>>): string[] {
|
|
23
|
+
if (source === "post") return POST_BIND_KEYS.map((k) => k.key);
|
|
24
|
+
if (source === "site") {
|
|
25
|
+
return [...new Set([...SITE_BIND_KEYS.map((k) => k.key), ...Object.keys(site)])];
|
|
26
|
+
}
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const firstKey = (source: BindSource) =>
|
|
31
|
+
source === "post" ? "title" : source === "site" ? "title" : "ref";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Dynamic data (W-307): bind a text, image or link field to a post field, a site setting or a
|
|
35
|
+
* URL parameter. The field's typed value is the fallback, and the live value shows here and on
|
|
36
|
+
* the canvas while you edit.
|
|
37
|
+
*/
|
|
38
|
+
export function BindingsEditor({
|
|
39
|
+
node,
|
|
40
|
+
onChange,
|
|
41
|
+
post,
|
|
42
|
+
}: {
|
|
43
|
+
node: LayoutNode;
|
|
44
|
+
onChange: (node: LayoutNode) => void;
|
|
45
|
+
/** The post the canvas shows (a sample outside a post template). */
|
|
46
|
+
post?: ThemePostFields;
|
|
47
|
+
}) {
|
|
48
|
+
const fields = bindableFields(node.type);
|
|
49
|
+
const live = useLiveData();
|
|
50
|
+
if (fields.length === 0) return null;
|
|
51
|
+
const listId = `emvb-bind-keys-${node.id}`;
|
|
52
|
+
return (
|
|
53
|
+
<section className="emvb-bind" data-emvb-bindings="" aria-labelledby={`${listId}-title`}>
|
|
54
|
+
<h3 className="emvb-bind-title" id={`${listId}-title`}>
|
|
55
|
+
Dynamic data
|
|
56
|
+
</h3>
|
|
57
|
+
<p className="emvb-helper">
|
|
58
|
+
Show live data instead of the typed value. The typed value is used when there is none.
|
|
59
|
+
</p>
|
|
60
|
+
{fields.map((field) => {
|
|
61
|
+
const binding = node.bind?.[field.key];
|
|
62
|
+
const source = binding?.source;
|
|
63
|
+
const data = { post, site: live.site, params: live.params, origin: siteOrigin() };
|
|
64
|
+
const value = binding ? boundValue(field, binding, data, field.kind === "text") : undefined;
|
|
65
|
+
// W-307: a value that exists but is refused (another site, or an unsafe URL).
|
|
66
|
+
const refused =
|
|
67
|
+
binding !== undefined &&
|
|
68
|
+
value === undefined &&
|
|
69
|
+
resolveBinding(binding, data) !== undefined;
|
|
70
|
+
const offSiteOption = binding?.source === "param" && field.kind !== "text";
|
|
71
|
+
const selectId = `${listId}-${field.key}`;
|
|
72
|
+
return (
|
|
73
|
+
<div className="emvb-bind-row" key={field.key} data-emvb-bind-field={field.key}>
|
|
74
|
+
{/* "Text source", not "Text": the field's own input is already named "Text". */}
|
|
75
|
+
<label className="emvb-bind-label" htmlFor={selectId}>
|
|
76
|
+
{`${field.label} source`}
|
|
77
|
+
</label>
|
|
78
|
+
<select
|
|
79
|
+
id={selectId}
|
|
80
|
+
className="emvb-native-select"
|
|
81
|
+
value={source ?? STATIC}
|
|
82
|
+
onChange={(event) => {
|
|
83
|
+
const next = event.target.value;
|
|
84
|
+
if (next === STATIC) onChange(withBinding(node, field.key, undefined));
|
|
85
|
+
else {
|
|
86
|
+
const src = next as BindSource;
|
|
87
|
+
onChange(withBinding(node, field.key, { source: src, key: firstKey(src) }));
|
|
88
|
+
}
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
<option value={STATIC}>Typed value</option>
|
|
92
|
+
{BIND_SOURCES.map((s) => (
|
|
93
|
+
<option key={s} value={s}>
|
|
94
|
+
{BIND_SOURCE_LABELS[s]}
|
|
95
|
+
</option>
|
|
96
|
+
))}
|
|
97
|
+
</select>
|
|
98
|
+
{binding ? (
|
|
99
|
+
<BindKeyInput
|
|
100
|
+
fieldLabel={field.label}
|
|
101
|
+
binding={binding}
|
|
102
|
+
listId={`${selectId}-keys`}
|
|
103
|
+
options={suggestions(binding.source, live.site)}
|
|
104
|
+
onCommit={(key) => onChange(withBinding(node, field.key, { ...binding, key }))}
|
|
105
|
+
/>
|
|
106
|
+
) : (
|
|
107
|
+
<span />
|
|
108
|
+
)}
|
|
109
|
+
{binding && (
|
|
110
|
+
<p className="emvb-bind-live" data-emvb-bind-live="">
|
|
111
|
+
{refused ? (
|
|
112
|
+
<>
|
|
113
|
+
{offSiteOption && !binding.outside
|
|
114
|
+
? "Not a link on this site, so the typed value shows."
|
|
115
|
+
: "Not a usable URL, so the typed value shows."}
|
|
116
|
+
</>
|
|
117
|
+
) : value === undefined ? (
|
|
118
|
+
<>No value here, so the typed value shows.</>
|
|
119
|
+
) : (
|
|
120
|
+
<>
|
|
121
|
+
Live: <b>{value}</b>
|
|
122
|
+
</>
|
|
123
|
+
)}
|
|
124
|
+
</p>
|
|
125
|
+
)}
|
|
126
|
+
{binding && offSiteOption && (
|
|
127
|
+
<div className="emvb-bind-outside" data-emvb-bind-outside="">
|
|
128
|
+
<label>
|
|
129
|
+
<input
|
|
130
|
+
type="checkbox"
|
|
131
|
+
checked={binding.outside === true}
|
|
132
|
+
onChange={(event) => {
|
|
133
|
+
const { outside: _old, ...rest } = binding;
|
|
134
|
+
const next = event.target.checked ? { ...rest, outside: true } : rest;
|
|
135
|
+
onChange(withBinding(node, field.key, next));
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
{`Allow outside sites for ${field.label}`}
|
|
139
|
+
</label>
|
|
140
|
+
{binding.outside ? (
|
|
141
|
+
<p className="emvb-bind-warning" role="note">
|
|
142
|
+
Phishing risk: anyone can share a link to this page that sends visitors to any
|
|
143
|
+
site or shows any image under your address. Only allow this if you trust where
|
|
144
|
+
those links come from.
|
|
145
|
+
</p>
|
|
146
|
+
) : (
|
|
147
|
+
<p className="emvb-helper">
|
|
148
|
+
Only links and images on this site are used. Others show the typed value.
|
|
149
|
+
</p>
|
|
150
|
+
)}
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
153
|
+
</div>
|
|
154
|
+
);
|
|
155
|
+
})}
|
|
156
|
+
{Object.values(node.bind ?? {}).some((b) => b.source === "param") && <PreviewQuery />}
|
|
157
|
+
</section>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function BindKeyInput({
|
|
162
|
+
fieldLabel,
|
|
163
|
+
binding,
|
|
164
|
+
listId,
|
|
165
|
+
options,
|
|
166
|
+
onCommit,
|
|
167
|
+
}: {
|
|
168
|
+
fieldLabel: string;
|
|
169
|
+
binding: Binding;
|
|
170
|
+
listId: string;
|
|
171
|
+
options: string[];
|
|
172
|
+
onCommit: (key: string) => void;
|
|
173
|
+
}) {
|
|
174
|
+
const [draft, setDraft] = React.useState(binding.key);
|
|
175
|
+
React.useEffect(() => setDraft(binding.key), [binding.key]);
|
|
176
|
+
const valid = KEY.test(draft);
|
|
177
|
+
const commit = () => {
|
|
178
|
+
if (valid && draft !== binding.key) onCommit(draft);
|
|
179
|
+
if (!valid) setDraft(binding.key);
|
|
180
|
+
};
|
|
181
|
+
return (
|
|
182
|
+
<>
|
|
183
|
+
<input
|
|
184
|
+
className="emvb-native-input"
|
|
185
|
+
aria-label={`${fieldLabel} ${binding.source === "param" ? "parameter name" : "field name"}`}
|
|
186
|
+
aria-invalid={valid ? undefined : true}
|
|
187
|
+
list={options.length > 0 ? listId : undefined}
|
|
188
|
+
value={draft}
|
|
189
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
190
|
+
onBlur={commit}
|
|
191
|
+
onKeyDown={(event) => {
|
|
192
|
+
if (event.key === "Enter") commit();
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
{options.length > 0 && (
|
|
196
|
+
<datalist id={listId}>
|
|
197
|
+
{options.map((option) => (
|
|
198
|
+
<option key={option} value={option} />
|
|
199
|
+
))}
|
|
200
|
+
</datalist>
|
|
201
|
+
)}
|
|
202
|
+
</>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The URL parameters the canvas previews with; they never reach the published page. */
|
|
207
|
+
function PreviewQuery() {
|
|
208
|
+
const live = useLiveData();
|
|
209
|
+
return (
|
|
210
|
+
<label className="emvb-bind-row" data-emvb-preview-query="">
|
|
211
|
+
<span className="emvb-bind-label">Preview URL parameters (editor only)</span>
|
|
212
|
+
<input
|
|
213
|
+
className="emvb-native-input"
|
|
214
|
+
style={{ gridColumn: "1 / -1" }}
|
|
215
|
+
placeholder="plan=pro&name=Ada"
|
|
216
|
+
value={live.query}
|
|
217
|
+
onChange={(event) => live.setQuery(event.target.value)}
|
|
218
|
+
/>
|
|
219
|
+
</label>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
@@ -43,7 +43,7 @@ const optionKey = (option: ClassOption) =>
|
|
|
43
43
|
option.kind === "class" ? option.cls.id : `create-${option.name}`;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* The Style tab's Classes field (W-087): a Local chip, one chip per
|
|
46
|
+
* The Style tab's Classes field (W-087, DESIGN.md "class chip input"): a Local chip, one chip per
|
|
47
47
|
* applied class in cascade order, and a combobox that suggests classes or creates one.
|
|
48
48
|
*/
|
|
49
49
|
export function ClassChipInput({
|
|
@@ -11,7 +11,7 @@ type Filter = NonNullable<StyleProps["filter"]>;
|
|
|
11
11
|
type Transition = NonNullable<StyleProps["transition"]>;
|
|
12
12
|
type Entrance = NonNullable<StyleProps["entrance"]>;
|
|
13
13
|
|
|
14
|
-
/** Add shadow starts at 0 4 12 0, 18 % black. */
|
|
14
|
+
/** DESIGN.md: Add shadow starts at 0 4 12 0, 18 % black. */
|
|
15
15
|
const NEW_SHADOW: Shadow = { x: 0, y: 4, blur: 12, spread: 0, color: "#0000002e" };
|
|
16
16
|
|
|
17
17
|
const OFFSET: NumberSpec = { min: -1000, max: 1000, example: "4" };
|
|
@@ -174,7 +174,7 @@ const APPLIES_TO: ReadonlyArray<{ value: Transition["property"]; label: string }
|
|
|
174
174
|
{ value: "filter", label: "Filters" },
|
|
175
175
|
];
|
|
176
176
|
|
|
177
|
-
function TransitionSelect<T extends string>({
|
|
177
|
+
export function TransitionSelect<T extends string>({
|
|
178
178
|
label,
|
|
179
179
|
value,
|
|
180
180
|
options,
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { Button } from "@cloudflare/kumo";
|
|
2
|
+
import { PlusIcon, XIcon } from "@phosphor-icons/react";
|
|
3
|
+
import type * as React from "react";
|
|
4
|
+
import {
|
|
5
|
+
MOTION_EFFECTS,
|
|
6
|
+
MOTION_LIMITS,
|
|
7
|
+
type MotionEffect,
|
|
8
|
+
type StyleProps,
|
|
9
|
+
} from "../../../../core/index.ts";
|
|
10
|
+
import { BUTTON } from "../../../ui.ts";
|
|
11
|
+
import { TransitionSelect } from "./EffectsControls.tsx";
|
|
12
|
+
import { NumberField, type NumberSpec } from "./NumberRow.tsx";
|
|
13
|
+
|
|
14
|
+
type Motion = NonNullable<StyleProps["scrollMotion"]>;
|
|
15
|
+
type Playing = Extract<Motion, { effects: unknown }>;
|
|
16
|
+
type Effect = Playing["effects"][number];
|
|
17
|
+
|
|
18
|
+
const EFFECT_LABELS: Record<MotionEffect, { label: string; unit: string; neutral: number }> = {
|
|
19
|
+
fade: { label: "Opacity", unit: "%", neutral: 100 },
|
|
20
|
+
"move-x": { label: "Move sideways", unit: "px", neutral: 0 },
|
|
21
|
+
"move-y": { label: "Move up/down", unit: "px", neutral: 0 },
|
|
22
|
+
scale: { label: "Scale", unit: "%", neutral: 100 },
|
|
23
|
+
rotate: { label: "Rotate", unit: "°", neutral: 0 },
|
|
24
|
+
blur: { label: "Blur", unit: "px", neutral: 0 },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const RANGES: { value: Playing["range"]; label: string }[] = [
|
|
28
|
+
{ value: "enter", label: "As it comes into view" },
|
|
29
|
+
{ value: "cross", label: "While it crosses the screen" },
|
|
30
|
+
{ value: "exit", label: "As it leaves the screen" },
|
|
31
|
+
{ value: "page", label: "Over the whole page scroll" },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
/** Ready-made motions (W-319). Each is a plain value: pick one, then tune it. */
|
|
35
|
+
export const MOTION_PRESETS: { id: string; label: string; value: Playing }[] = [
|
|
36
|
+
{
|
|
37
|
+
id: "fade-in",
|
|
38
|
+
label: "Fade in",
|
|
39
|
+
value: { range: "enter", effects: [{ type: "fade", from: 0, to: 100 }] },
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "rise",
|
|
43
|
+
label: "Rise in",
|
|
44
|
+
value: {
|
|
45
|
+
range: "enter",
|
|
46
|
+
effects: [
|
|
47
|
+
{ type: "fade", from: 0, to: 100 },
|
|
48
|
+
{ type: "move-y", from: 60, to: 0 },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "slide-left",
|
|
54
|
+
label: "Slide in from the side",
|
|
55
|
+
value: {
|
|
56
|
+
range: "enter",
|
|
57
|
+
effects: [
|
|
58
|
+
{ type: "fade", from: 0, to: 100 },
|
|
59
|
+
{ type: "move-x", from: -80, to: 0 },
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "zoom",
|
|
65
|
+
label: "Zoom in",
|
|
66
|
+
value: { range: "enter", effects: [{ type: "scale", from: 80, to: 100 }] },
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "parallax",
|
|
70
|
+
label: "Parallax",
|
|
71
|
+
value: { range: "cross", effects: [{ type: "move-y", from: 80, to: -80 }] },
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "spin",
|
|
75
|
+
label: "Turn while scrolling",
|
|
76
|
+
value: { range: "cross", effects: [{ type: "rotate", from: -10, to: 10 }] },
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "blur-in",
|
|
80
|
+
label: "Sharpen in",
|
|
81
|
+
value: { range: "enter", effects: [{ type: "blur", from: 12, to: 0 }] },
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "fade-out",
|
|
85
|
+
label: "Fade out on leave",
|
|
86
|
+
value: { range: "exit", effects: [{ type: "fade", from: 100, to: 0 }] },
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
const specFor = (type: MotionEffect): NumberSpec => {
|
|
91
|
+
const [min, max] = MOTION_LIMITS[type];
|
|
92
|
+
return {
|
|
93
|
+
min,
|
|
94
|
+
max,
|
|
95
|
+
integer: true,
|
|
96
|
+
example: String(EFFECT_LABELS[type].neutral),
|
|
97
|
+
suffix: EFFECT_LABELS[type].unit,
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** The preset a value matches exactly, or "custom". */
|
|
102
|
+
export function presetOf(value: Playing): string {
|
|
103
|
+
const key = JSON.stringify(value);
|
|
104
|
+
return MOTION_PRESETS.find((p) => JSON.stringify(p.value) === key)?.id ?? "custom";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Scroll motion (W-319, Normal only): a preset, when it plays and each effect's start and end.
|
|
109
|
+
* Plays with CSS scroll-driven animations; never for visitors who prefer reduced motion.
|
|
110
|
+
*/
|
|
111
|
+
export function MotionControl({
|
|
112
|
+
value,
|
|
113
|
+
onChange,
|
|
114
|
+
reset,
|
|
115
|
+
}: {
|
|
116
|
+
value: Motion | undefined;
|
|
117
|
+
onChange: (next: Motion | undefined) => void;
|
|
118
|
+
reset: React.ReactNode;
|
|
119
|
+
}) {
|
|
120
|
+
const playing = value && "effects" in value ? value : undefined;
|
|
121
|
+
const setEffects = (effects: Effect[]) => {
|
|
122
|
+
if (!playing) return;
|
|
123
|
+
onChange(effects.length > 0 ? { ...playing, effects } : undefined);
|
|
124
|
+
};
|
|
125
|
+
const unused = MOTION_EFFECTS.filter((t) => !playing?.effects.some((e) => e.type === t));
|
|
126
|
+
const presetOptions = [
|
|
127
|
+
...MOTION_PRESETS.map((p) => ({ value: p.id, label: p.label })),
|
|
128
|
+
...(playing && presetOf(playing) === "custom" ? [{ value: "custom", label: "Custom" }] : []),
|
|
129
|
+
];
|
|
130
|
+
return (
|
|
131
|
+
<div
|
|
132
|
+
className="emvb-style-row"
|
|
133
|
+
data-emvb-style="scrollMotion"
|
|
134
|
+
data-set={value ? "true" : undefined}
|
|
135
|
+
>
|
|
136
|
+
<div className="emvb-field-group emvb-transition emvb-motion">
|
|
137
|
+
<span className="emvb-var-field-label">Scroll motion</span>
|
|
138
|
+
{value && !playing && (
|
|
139
|
+
<p className="emvb-helper" data-emvb-motion-off="">
|
|
140
|
+
Off on this screen.
|
|
141
|
+
</p>
|
|
142
|
+
)}
|
|
143
|
+
{playing && (
|
|
144
|
+
<>
|
|
145
|
+
<TransitionSelect
|
|
146
|
+
label="Motion"
|
|
147
|
+
value={presetOf(playing)}
|
|
148
|
+
options={presetOptions}
|
|
149
|
+
onChange={(id) => {
|
|
150
|
+
const preset = MOTION_PRESETS.find((p) => p.id === id);
|
|
151
|
+
if (preset) onChange(structuredClone(preset.value));
|
|
152
|
+
}}
|
|
153
|
+
/>
|
|
154
|
+
<TransitionSelect
|
|
155
|
+
label="Plays"
|
|
156
|
+
value={playing.range}
|
|
157
|
+
options={RANGES}
|
|
158
|
+
onChange={(range) => onChange({ ...playing, range })}
|
|
159
|
+
/>
|
|
160
|
+
{playing.effects.map((effect, index) => (
|
|
161
|
+
<div className="emvb-motion-effect" key={effect.type} data-emvb-motion={effect.type}>
|
|
162
|
+
<span className="emvb-motion-name">{EFFECT_LABELS[effect.type].label}</span>
|
|
163
|
+
<NumberField
|
|
164
|
+
fieldKey={`scrollMotion.${effect.type}.from`}
|
|
165
|
+
label="From"
|
|
166
|
+
value={effect.from}
|
|
167
|
+
spec={specFor(effect.type)}
|
|
168
|
+
onCommit={(n) =>
|
|
169
|
+
setEffects(
|
|
170
|
+
playing.effects.with(index, {
|
|
171
|
+
...effect,
|
|
172
|
+
from: n ?? EFFECT_LABELS[effect.type].neutral,
|
|
173
|
+
}),
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
/>
|
|
177
|
+
<NumberField
|
|
178
|
+
fieldKey={`scrollMotion.${effect.type}.to`}
|
|
179
|
+
label="To"
|
|
180
|
+
value={effect.to}
|
|
181
|
+
spec={specFor(effect.type)}
|
|
182
|
+
onCommit={(n) =>
|
|
183
|
+
setEffects(
|
|
184
|
+
playing.effects.with(index, {
|
|
185
|
+
...effect,
|
|
186
|
+
to: n ?? EFFECT_LABELS[effect.type].neutral,
|
|
187
|
+
}),
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
/>
|
|
191
|
+
<Button
|
|
192
|
+
type="button"
|
|
193
|
+
variant="ghost"
|
|
194
|
+
shape="square"
|
|
195
|
+
className={BUTTON}
|
|
196
|
+
aria-label={`Remove ${EFFECT_LABELS[effect.type].label}`}
|
|
197
|
+
icon={<XIcon aria-hidden="true" />}
|
|
198
|
+
onClick={() => setEffects(playing.effects.filter((_, i) => i !== index))}
|
|
199
|
+
/>
|
|
200
|
+
</div>
|
|
201
|
+
))}
|
|
202
|
+
{unused.length > 0 && (
|
|
203
|
+
<TransitionSelect
|
|
204
|
+
label="Add effect"
|
|
205
|
+
value={"" as MotionEffect | ""}
|
|
206
|
+
options={[
|
|
207
|
+
{ value: "" as const, label: "Choose…" },
|
|
208
|
+
...unused.map((t) => ({ value: t, label: EFFECT_LABELS[t].label })),
|
|
209
|
+
]}
|
|
210
|
+
onChange={(type) => {
|
|
211
|
+
if (!type) return;
|
|
212
|
+
const n = EFFECT_LABELS[type].neutral;
|
|
213
|
+
setEffects([...playing.effects, { type, from: n, to: n }]);
|
|
214
|
+
}}
|
|
215
|
+
/>
|
|
216
|
+
)}
|
|
217
|
+
<p className="emvb-helper">
|
|
218
|
+
Plays as visitors scroll, in browsers that support scroll-driven animations. Visitors
|
|
219
|
+
who ask for reduced motion see it still.
|
|
220
|
+
</p>
|
|
221
|
+
</>
|
|
222
|
+
)}
|
|
223
|
+
{!value && (
|
|
224
|
+
<Button
|
|
225
|
+
type="button"
|
|
226
|
+
variant="secondary"
|
|
227
|
+
className={`${BUTTON} emvb-add-shadow`}
|
|
228
|
+
icon={<PlusIcon aria-hidden="true" />}
|
|
229
|
+
onClick={() =>
|
|
230
|
+
onChange(
|
|
231
|
+
structuredClone((MOTION_PRESETS[1] as (typeof MOTION_PRESETS)[number]).value),
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
>
|
|
235
|
+
Add scroll motion
|
|
236
|
+
</Button>
|
|
237
|
+
)}
|
|
238
|
+
{playing && (
|
|
239
|
+
<Button
|
|
240
|
+
type="button"
|
|
241
|
+
variant="ghost"
|
|
242
|
+
className={BUTTON}
|
|
243
|
+
onClick={() => onChange({ type: "none" })}
|
|
244
|
+
>
|
|
245
|
+
Turn off here
|
|
246
|
+
</Button>
|
|
247
|
+
)}
|
|
248
|
+
</div>
|
|
249
|
+
{reset}
|
|
250
|
+
</div>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
@@ -18,7 +18,7 @@ const isChoice = (value: string): value is StyleStateChoice =>
|
|
|
18
18
|
(CHOICES as string[]).includes(value);
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* The dot shown where state styles exist. Decorative on the state tabs,
|
|
21
|
+
* The dot shown where state styles exist (DESIGN.md § State styles). Decorative on the state tabs,
|
|
22
22
|
* so their names stay "Hover", "Focus" and "Active".
|
|
23
23
|
*/
|
|
24
24
|
export function StateDot({ decorative = false }: { decorative?: boolean }) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Input, Select } from "@cloudflare/kumo";
|
|
2
|
+
import { MotionControl } from "./MotionControl.tsx";
|
|
2
3
|
import { isSafeFontStack, type DesignSystem, type StyleProps } from "../../../../core/index.ts";
|
|
3
4
|
import type { Fetcher } from "../../../api.ts";
|
|
4
5
|
import { FIELD } from "../../../ui.ts";
|
|
@@ -497,6 +498,16 @@ export function StyleRow({
|
|
|
497
498
|
);
|
|
498
499
|
}
|
|
499
500
|
|
|
501
|
+
if (styleKey === "scrollMotion") {
|
|
502
|
+
return (
|
|
503
|
+
<MotionControl
|
|
504
|
+
value={style?.scrollMotion}
|
|
505
|
+
onChange={(scrollMotion) => onPatch({ scrollMotion })}
|
|
506
|
+
reset={reset}
|
|
507
|
+
/>
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
|
|
500
511
|
if (styleKey === "transition") {
|
|
501
512
|
return (
|
|
502
513
|
<TransitionControl
|
|
@@ -547,6 +558,7 @@ export const IMPLEMENTED_STYLE_KEYS: StyleKey[] = [
|
|
|
547
558
|
"boxShadow",
|
|
548
559
|
"filter",
|
|
549
560
|
"entrance",
|
|
561
|
+
"scrollMotion",
|
|
550
562
|
"transition",
|
|
551
563
|
"iconRotate",
|
|
552
564
|
"iconFlip",
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
traceStyle,
|
|
3
|
+
type DesignSystem,
|
|
4
|
+
type LayoutNode,
|
|
5
|
+
type StyleSource,
|
|
6
|
+
type TraceDevice,
|
|
7
|
+
} from "../../../../core/index.ts";
|
|
8
|
+
|
|
9
|
+
/** "backgroundColor" → "Background color". */
|
|
10
|
+
const propertyName = (key: string) => {
|
|
11
|
+
const words = key.replace(/([A-Z])/g, " $1").toLowerCase();
|
|
12
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** A short, readable value: a colour, a length, a variable, or JSON cut short. */
|
|
16
|
+
export function sourceValue(value: unknown, design?: DesignSystem): string {
|
|
17
|
+
if (typeof value === "string" || typeof value === "number") return String(value);
|
|
18
|
+
if (value && typeof value === "object") {
|
|
19
|
+
if ("var" in value) {
|
|
20
|
+
const id = (value as { var: string }).var;
|
|
21
|
+
const { colors, fonts, fontSizes, spacings } = design?.variables ?? { colors: [] };
|
|
22
|
+
const named = [...colors, ...(fonts ?? []), ...(fontSizes ?? []), ...(spacings ?? [])].find(
|
|
23
|
+
(v) => v.id === id,
|
|
24
|
+
);
|
|
25
|
+
return named ? named.name : `var ${id}`;
|
|
26
|
+
}
|
|
27
|
+
if ("value" in value && "unit" in value) {
|
|
28
|
+
const v = value as { value: number; unit: string };
|
|
29
|
+
return `${v.value}${v.unit}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const json = JSON.stringify(value) ?? "";
|
|
33
|
+
return json.length > 32 ? `${json.slice(0, 31)}…` : json;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const where = (s: StyleSource) => (s.layer === "Desktop" ? s.label : `${s.label} · ${s.layer}`);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Style inheritance inspector (W-318): every property that applies to this element here, the
|
|
40
|
+
* layer it comes from (site default, a class, this element; Desktop, Tablet, Mobile or a state)
|
|
41
|
+
* and what it overrides.
|
|
42
|
+
*/
|
|
43
|
+
export function StyleSources({
|
|
44
|
+
node,
|
|
45
|
+
design,
|
|
46
|
+
device,
|
|
47
|
+
state,
|
|
48
|
+
}: {
|
|
49
|
+
node: LayoutNode;
|
|
50
|
+
design: DesignSystem;
|
|
51
|
+
device: TraceDevice;
|
|
52
|
+
state: "normal" | "hover" | "focus" | "active";
|
|
53
|
+
}) {
|
|
54
|
+
const trace = traceStyle(node, design, device, state);
|
|
55
|
+
const keys = Object.keys(trace).toSorted();
|
|
56
|
+
const fromElsewhere = keys.filter((key) => trace[key]?.winner.kind !== "local").length;
|
|
57
|
+
return (
|
|
58
|
+
<details className="emvb-sources" data-emvb-style-sources="">
|
|
59
|
+
<summary>
|
|
60
|
+
Where styles come from
|
|
61
|
+
<span className="emvb-sources-count">
|
|
62
|
+
{keys.length === 0
|
|
63
|
+
? "nothing set"
|
|
64
|
+
: `${keys.length} set${fromElsewhere > 0 ? `, ${fromElsewhere} inherited` : ""}`}
|
|
65
|
+
</span>
|
|
66
|
+
</summary>
|
|
67
|
+
{keys.length === 0 ? (
|
|
68
|
+
<p className="emvb-helper">No styles apply yet beyond the element's defaults.</p>
|
|
69
|
+
) : (
|
|
70
|
+
<ul>
|
|
71
|
+
{keys.map((key) => {
|
|
72
|
+
const t = trace[key];
|
|
73
|
+
if (!t) return null;
|
|
74
|
+
return (
|
|
75
|
+
<li key={key} data-emvb-source={key} data-kind={t.winner.kind}>
|
|
76
|
+
<span className="emvb-sources-prop">{propertyName(key)}</span>
|
|
77
|
+
<span className="emvb-sources-value">{sourceValue(t.winner.value, design)}</span>
|
|
78
|
+
<span className="emvb-sources-from">{where(t.winner)}</span>
|
|
79
|
+
{t.overridden.length > 0 && (
|
|
80
|
+
<span className="emvb-sources-over">
|
|
81
|
+
overrides{" "}
|
|
82
|
+
{t.overridden
|
|
83
|
+
.map((o) => `${where(o)} (${sourceValue(o.value, design)})`)
|
|
84
|
+
.join(", ")}
|
|
85
|
+
</span>
|
|
86
|
+
)}
|
|
87
|
+
</li>
|
|
88
|
+
);
|
|
89
|
+
})}
|
|
90
|
+
</ul>
|
|
91
|
+
)}
|
|
92
|
+
</details>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -126,7 +126,7 @@ export function VariableButton({
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
|
-
* The variable chip that stands in for a bound value: the kind icon, the variable's
|
|
129
|
+
* The variable chip that stands in for a bound value (DESIGN.md): the kind icon, the variable's
|
|
130
130
|
* name and an × that detaches it, keeping the variable's current value as a literal.
|
|
131
131
|
*/
|
|
132
132
|
export function VariableChip({
|