@perkyzz/emvb 0.9.0 → 1.1.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 +10 -1
- package/package.json +2 -2
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/bulk-api.ts +67 -0
- package/src/admin/content-api.ts +10 -6
- package/src/admin/copy-rich-text.ts +119 -0
- package/src/admin/dialog-tab-wrap.ts +78 -0
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +311 -250
- package/src/admin/editor/Timeline.tsx +8 -3
- package/src/admin/editor/TopBar.tsx +29 -7
- package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +31 -10
- package/src/admin/editor/canvas/canvas-scale.ts +3 -3
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/co-design.ts +190 -0
- package/src/admin/editor/dnd/new-element.ts +48 -4
- package/src/admin/editor/editor-chrome.tsx +8 -6
- package/src/admin/editor/editor-commands.ts +15 -4
- package/src/admin/editor/editor-css.ts +2 -1
- package/src/admin/editor/element-chrome.ts +3 -1
- package/src/admin/editor/extension-manifests.ts +20 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
- package/src/admin/editor/extensions-context.tsx +27 -0
- package/src/admin/editor/feature-css.ts +17 -0
- package/src/admin/editor/palette-items.ts +2 -2
- package/src/admin/editor/panels/AddPanel.tsx +31 -1
- package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
- package/src/admin/editor/panels/ClassesSection.tsx +9 -6
- package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ElementPanel.tsx +68 -20
- package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
- package/src/admin/editor/panels/LayersPanel.tsx +10 -6
- package/src/admin/editor/panels/LeftPanel.tsx +33 -5
- package/src/admin/editor/panels/PageSettings.tsx +4 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +72 -15
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
- package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
- package/src/admin/editor/panels/settings/EffectsControls.tsx +183 -10
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +25 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +63 -19
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +19 -1
- package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
- package/src/admin/editor/panels/settings/StyleRow.tsx +120 -13
- package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
- package/src/admin/editor/panels/settings/background-mode.ts +14 -11
- package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
- package/src/admin/editor/panels/settings/box-sides.ts +22 -14
- package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
- package/src/admin/editor/panels/settings/length-units.ts +68 -4
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +52 -10
- package/src/admin/editor/panels/style-target.ts +22 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/section-templates.ts +26 -4
- package/src/admin/editor/store.ts +14 -4
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +7 -5
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +18 -7
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/export-api.ts +221 -0
- package/src/admin/index.tsx +6 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +9 -26
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ExportDialog.tsx +395 -0
- package/src/admin/pages/ImportButton.tsx +18 -0
- package/src/admin/pages/ImportElementorDialog.tsx +669 -0
- package/src/admin/pages/ImportPageLinks.tsx +86 -0
- package/src/admin/pages/PageList.tsx +82 -3
- package/src/admin/pages/ThemePartList.tsx +52 -2
- package/src/admin/pages/bulk.tsx +303 -0
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/search.ts +20 -0
- package/src/admin/theme-api.ts +4 -0
- package/src/admin/ui.ts +50 -4
- package/src/admin/widgets/CanvasField.tsx +8 -0
- package/src/admin/widgets/ConvertToRichText.tsx +136 -0
- package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
- package/src/admin/widgets/convert-body.ts +73 -2
- package/src/astro/content-port.ts +14 -1
- package/src/astro/render.ts +6 -6
- package/src/astro/resolve-theme.ts +25 -8
- package/src/astro/resolve.ts +89 -2
- package/src/astro/tabs/runtime.ts +16 -6
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +45 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +305 -0
- package/src/core/css/generate.ts +151 -20
- package/src/core/css/scope.ts +10 -2
- package/src/core/css/trace.ts +47 -13
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +28 -9
- package/src/core/design/devices.ts +89 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +31 -5
- package/src/core/elements/dynamic-elements.ts +3 -3
- package/src/core/elements/index.ts +73 -9
- package/src/core/export/runtimes.generated.ts +9 -0
- package/src/core/export/site.ts +562 -0
- package/src/core/export/zip.ts +95 -0
- package/src/core/extensions/define.ts +13 -0
- package/src/core/extensions/index.ts +41 -0
- package/src/core/extensions/namespace.ts +82 -0
- package/src/core/extensions/normalize.ts +141 -0
- package/src/core/extensions/placeholder.ts +41 -0
- package/src/core/extensions/registry.ts +94 -0
- package/src/core/extensions/render-ext.ts +118 -0
- package/src/core/extensions/safe-nodes.ts +93 -0
- package/src/core/extensions/schema.ts +112 -0
- package/src/core/extensions/types.ts +159 -0
- package/src/core/forms/binding.ts +1 -1
- package/src/core/history/diff.ts +26 -1
- package/src/core/import/elementor/atomic.ts +1608 -0
- package/src/core/import/elementor/classes.ts +127 -0
- package/src/core/import/elementor/context.ts +429 -0
- package/src/core/import/elementor/counter-steps.ts +72 -0
- package/src/core/import/elementor/css.ts +445 -0
- package/src/core/import/elementor/html.ts +500 -0
- package/src/core/import/elementor/index.ts +967 -0
- package/src/core/import/elementor/inline-marks.ts +81 -0
- package/src/core/import/elementor/snapshots.ts +48 -0
- package/src/core/import/elementor/style.ts +429 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +96 -0
- package/src/core/json-schema.ts +114 -0
- package/src/core/limits.ts +19 -0
- package/src/core/migrate/index.ts +6 -1
- package/src/core/migrate/v18.ts +222 -0
- package/src/core/perf/meter.ts +42 -24
- package/src/core/portable-text-export.ts +243 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/public-attributes.ts +30 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +222 -23
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/tabs.ts +18 -11
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +151 -10
- package/src/core/sanitize/motion.ts +116 -0
- package/src/core/saved-sections.ts +6 -0
- package/src/core/schema/descriptors.ts +3 -1
- package/src/core/schema/design.ts +4 -3
- package/src/core/schema/layout.ts +92 -16
- package/src/core/schema/style.ts +296 -112
- package/src/core/search-text.ts +70 -0
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +2 -0
- package/src/core/theme/popup-rules.ts +33 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +24 -0
- package/src/mcp/errors.ts +3 -1
- package/src/mcp/ports.ts +67 -0
- package/src/mcp/prompts.ts +1 -11
- package/src/mcp/proposals.ts +281 -0
- package/src/mcp/read.ts +10 -10
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +5 -1
- package/src/server/icon-routes.ts +52 -12
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +35 -2
- package/src/server/presence.ts +78 -0
- package/src/server/proposals.ts +261 -0
- package/src/server/requests.ts +196 -0
- package/src/server/tools-served.ts +45 -0
package/src/core/sanitize/css.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ALIGN_ITEMS,
|
|
3
|
+
ALIGN_SELF,
|
|
3
4
|
BACKGROUND_POSITIONS,
|
|
4
5
|
BACKGROUND_REPEATS,
|
|
5
6
|
BACKGROUND_SIZES,
|
|
@@ -7,22 +8,26 @@ import {
|
|
|
7
8
|
CURSORS,
|
|
8
9
|
FLEX_DIRECTIONS as FLEX_DIRECTION_VALUES,
|
|
9
10
|
FLEX_WRAPS as FLEX_WRAP_VALUES,
|
|
11
|
+
FONT_STYLES,
|
|
10
12
|
FONT_WEIGHTS,
|
|
11
13
|
HEX_COLOR,
|
|
12
14
|
JUSTIFY_CONTENT,
|
|
13
15
|
LENGTH_UNITS,
|
|
14
16
|
OBJECT_FITS,
|
|
17
|
+
OVERFLOW_WRAPS,
|
|
15
18
|
OVERFLOWS,
|
|
16
19
|
POSITIONS,
|
|
17
20
|
TEXT_ALIGNS,
|
|
18
21
|
TEXT_DECORATIONS,
|
|
19
22
|
TEXT_TRANSFORMS,
|
|
23
|
+
WHITE_SPACES,
|
|
20
24
|
TRANSITION_EASINGS as TRANSITION_EASING_VALUES,
|
|
21
25
|
} from "../css-keywords.ts";
|
|
22
26
|
import { STYLE_STATES, type StyleStateName } from "../schema/state-names.ts";
|
|
23
|
-
import type {
|
|
27
|
+
import type { FlatStyleProps } from "../schema/style.ts";
|
|
28
|
+
import { fluidClamp } from "../design/tokens.ts";
|
|
24
29
|
import { sanitizeMediaUrl } from "./media-url.ts";
|
|
25
|
-
import { motionDeclarations, withMotion } from "./motion.ts";
|
|
30
|
+
import { loopDeclarations, motionDeclarations, withLoop, withMotion } from "./motion.ts";
|
|
26
31
|
import { isRecord } from "../record.ts";
|
|
27
32
|
import { iconAnimationRuns } from "../icons/animation-runs.ts";
|
|
28
33
|
|
|
@@ -38,6 +43,10 @@ const TEXT_DECORATION = setOf(TEXT_DECORATIONS);
|
|
|
38
43
|
const BORDER_STYLE = setOf(BORDER_STYLES);
|
|
39
44
|
const OVERFLOW = setOf(OVERFLOWS);
|
|
40
45
|
const OBJECT_FIT = setOf(OBJECT_FITS);
|
|
46
|
+
const ALIGN_SELF_SET = setOf(ALIGN_SELF);
|
|
47
|
+
const FONT_STYLE = setOf(FONT_STYLES);
|
|
48
|
+
const WHITE_SPACE = setOf(WHITE_SPACES);
|
|
49
|
+
const OVERFLOW_WRAP = setOf(OVERFLOW_WRAPS);
|
|
41
50
|
const POSITION = setOf(POSITIONS);
|
|
42
51
|
const CURSOR = setOf(CURSORS);
|
|
43
52
|
const ASPECT_RATIO = /^([1-9]\d{0,3})\/([1-9]\d{0,3})$/;
|
|
@@ -132,6 +141,7 @@ function cssFontFamily(value: unknown): string | undefined {
|
|
|
132
141
|
|
|
133
142
|
export function cssLength(value: unknown): string | undefined {
|
|
134
143
|
if (typeof value !== "object" || value === null) return undefined;
|
|
144
|
+
if ("fluid" in value) return cssFluid((value as { fluid: unknown }).fluid);
|
|
135
145
|
const ref = refOf(value);
|
|
136
146
|
if (ref) {
|
|
137
147
|
if (ref.from === "fontSize") {
|
|
@@ -150,6 +160,19 @@ export function cssLength(value: unknown): string | undefined {
|
|
|
150
160
|
return `${n}${unit}`;
|
|
151
161
|
}
|
|
152
162
|
|
|
163
|
+
/**
|
|
164
|
+
* W-955: `{ min, max }` px as a `clamp()` that grows between 360 and 1280 px wide screens. Both
|
|
165
|
+
* are checked here as well as by the schema, so a stored page can't emit anything else.
|
|
166
|
+
*/
|
|
167
|
+
function cssFluid(fluid: unknown): string | undefined {
|
|
168
|
+
if (!isRecord(fluid)) return undefined;
|
|
169
|
+
const { min, max } = fluid;
|
|
170
|
+
return fluidPx(min) && fluidPx(max) ? fluidClamp(min, max) : undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const fluidPx = (n: unknown): n is number =>
|
|
174
|
+
typeof n === "number" && Number.isFinite(n) && n >= 0 && n <= 10_000;
|
|
175
|
+
|
|
153
176
|
/** A length, or `auto` where the property allows it (W-088). */
|
|
154
177
|
const cssLengthOrAuto = (value: unknown): string | undefined =>
|
|
155
178
|
value === "auto" ? "auto" : cssLength(value);
|
|
@@ -157,7 +180,8 @@ const cssLengthOrAuto = (value: unknown): string | undefined =>
|
|
|
157
180
|
/** An offset: `auto`, a variable, or a length from -10000 to 10000 (W-088). */
|
|
158
181
|
function cssOffset(value: unknown): string | undefined {
|
|
159
182
|
if (value === "auto") return "auto";
|
|
160
|
-
if (typeof value !== "object" || value === null || "var" in value
|
|
183
|
+
if (typeof value !== "object" || value === null || "var" in value || "fluid" in value)
|
|
184
|
+
return cssLength(value);
|
|
161
185
|
const { value: n, unit } = value as { value?: unknown; unit?: unknown };
|
|
162
186
|
if (typeof n !== "number" || !Number.isFinite(n) || n < -10_000 || n > 10_000) return undefined;
|
|
163
187
|
if (typeof unit !== "string" || !UNITS.has(unit)) return undefined;
|
|
@@ -169,6 +193,17 @@ const cssZIndex = (value: unknown): string | undefined =>
|
|
|
169
193
|
? String(value)
|
|
170
194
|
: undefined;
|
|
171
195
|
|
|
196
|
+
/** W-954: a grow or shrink factor, 0–100. */
|
|
197
|
+
const cssFlexFactor = (value: unknown): string | undefined =>
|
|
198
|
+
typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 100
|
|
199
|
+
? String(value)
|
|
200
|
+
: undefined;
|
|
201
|
+
|
|
202
|
+
const cssOrder = (value: unknown): string | undefined =>
|
|
203
|
+
Number.isInteger(value) && (value as number) >= -99 && (value as number) <= 99
|
|
204
|
+
? String(value)
|
|
205
|
+
: undefined;
|
|
206
|
+
|
|
172
207
|
const ENTRANCES = new Set(["fade", "fade-up", "fade-down", "slide-up", "slide-down", "scale"]);
|
|
173
208
|
|
|
174
209
|
/** `emvb-<type> <ms> ease-out [delay] both`. A bad trigger drops the whole entrance. */
|
|
@@ -317,6 +352,7 @@ const TRANSITION_PROPERTIES: Readonly<Record<string, readonly string[]>> = {
|
|
|
317
352
|
opacity: ["opacity"],
|
|
318
353
|
shadow: ["box-shadow"],
|
|
319
354
|
filter: ["filter"],
|
|
355
|
+
transform: ["translate", "scale", "rotate"],
|
|
320
356
|
};
|
|
321
357
|
const TRANSITION_KEYS = new Set(["duration", "delay", "easing", "property"]);
|
|
322
358
|
|
|
@@ -440,7 +476,11 @@ function cssAngle(value: unknown, fallback: number): number | undefined {
|
|
|
440
476
|
return angle as number;
|
|
441
477
|
}
|
|
442
478
|
|
|
443
|
-
function cssGradient(
|
|
479
|
+
function cssGradient(
|
|
480
|
+
value: unknown,
|
|
481
|
+
/** W-949: a gradient overlay fades every stop by its opacity. */
|
|
482
|
+
paint: (color: string) => string | undefined = (color) => color,
|
|
483
|
+
): string | undefined {
|
|
444
484
|
if (!isRecord(value)) return undefined;
|
|
445
485
|
if (
|
|
446
486
|
Object.keys(value).some(
|
|
@@ -455,7 +495,8 @@ function cssGradient(value: unknown): string | undefined {
|
|
|
455
495
|
for (const stop of stops) {
|
|
456
496
|
if (!isRecord(stop) || Object.keys(stop).some((key) => key !== "color" && key !== "at"))
|
|
457
497
|
return undefined;
|
|
458
|
-
const
|
|
498
|
+
const base = cssColor(stop["color"]);
|
|
499
|
+
const color = base ? paint(base) : undefined;
|
|
459
500
|
const at = stop["at"];
|
|
460
501
|
if (!color || !Number.isInteger(at) || (at as number) < 0 || (at as number) > 100)
|
|
461
502
|
return undefined;
|
|
@@ -502,6 +543,14 @@ function overlayPaint(color: string, opacity: number): string | undefined {
|
|
|
502
543
|
|
|
503
544
|
function cssOverlay(value: unknown): string | undefined {
|
|
504
545
|
if (!isRecord(value)) return undefined;
|
|
546
|
+
if ("gradient" in value) {
|
|
547
|
+
// W-949: a gradient overlay; `opacity` (default 1) fades each stop.
|
|
548
|
+
if (Object.keys(value).some((key) => key !== "gradient" && key !== "opacity")) return undefined;
|
|
549
|
+
const opacity = value["opacity"] === undefined ? 1 : value["opacity"];
|
|
550
|
+
if (typeof opacity !== "number" || !Number.isFinite(opacity) || opacity < 0 || opacity > 1)
|
|
551
|
+
return undefined;
|
|
552
|
+
return cssGradient(value["gradient"], (color) => overlayPaint(color, opacity));
|
|
553
|
+
}
|
|
505
554
|
if (Object.keys(value).some((key) => key !== "color" && key !== "opacity")) return undefined;
|
|
506
555
|
const color = cssColor(value["color"]);
|
|
507
556
|
const opacity = value["opacity"];
|
|
@@ -590,7 +639,10 @@ function composeBackground(style: Record<string, unknown>): {
|
|
|
590
639
|
}
|
|
591
640
|
|
|
592
641
|
const PROPERTY_MAP: {
|
|
593
|
-
[K in keyof Required<
|
|
642
|
+
[K in keyof Required<FlatStyleProps>]: {
|
|
643
|
+
css: string;
|
|
644
|
+
toValue: (v: unknown) => string | undefined;
|
|
645
|
+
};
|
|
594
646
|
} = {
|
|
595
647
|
flexDirection: { css: "flex-direction", toValue: cssFlexDirection },
|
|
596
648
|
flexWrap: { css: "flex-wrap", toValue: keyword(FLEX_WRAPS) },
|
|
@@ -609,8 +661,11 @@ const PROPERTY_MAP: {
|
|
|
609
661
|
minHeight: { css: "min-height", toValue: cssLength },
|
|
610
662
|
maxHeight: { css: "max-height", toValue: cssLength },
|
|
611
663
|
overflow: { css: "overflow", toValue: keyword(OVERFLOW) },
|
|
664
|
+
overflowX: { css: "overflow-x", toValue: keyword(OVERFLOW) },
|
|
665
|
+
overflowY: { css: "overflow-y", toValue: keyword(OVERFLOW) },
|
|
612
666
|
aspectRatio: { css: "aspect-ratio", toValue: cssAspectRatio },
|
|
613
667
|
objectFit: { css: "object-fit", toValue: keyword(OBJECT_FIT) },
|
|
668
|
+
objectPosition: { css: "object-position", toValue: keyword(BACKGROUND_POSITION) },
|
|
614
669
|
paddingTop: { css: "padding-top", toValue: cssLength },
|
|
615
670
|
paddingRight: { css: "padding-inline-end", toValue: cssLength },
|
|
616
671
|
paddingBottom: { css: "padding-bottom", toValue: cssLength },
|
|
@@ -625,6 +680,11 @@ const PROPERTY_MAP: {
|
|
|
625
680
|
bottom: { css: "bottom", toValue: cssOffset },
|
|
626
681
|
left: { css: "inset-inline-start", toValue: cssOffset },
|
|
627
682
|
zIndex: { css: "z-index", toValue: cssZIndex },
|
|
683
|
+
flexGrow: { css: "flex-grow", toValue: cssFlexFactor },
|
|
684
|
+
flexShrink: { css: "flex-shrink", toValue: cssFlexFactor },
|
|
685
|
+
flexBasis: { css: "flex-basis", toValue: cssLengthOrAuto },
|
|
686
|
+
alignSelf: { css: "align-self", toValue: keyword(ALIGN_SELF_SET) },
|
|
687
|
+
order: { css: "order", toValue: cssOrder },
|
|
628
688
|
fontFamily: { css: "font-family", toValue: cssFontFamily },
|
|
629
689
|
fontSize: { css: "font-size", toValue: cssLength },
|
|
630
690
|
fontWeight: { css: "font-weight", toValue: cssFontWeight },
|
|
@@ -633,6 +693,12 @@ const PROPERTY_MAP: {
|
|
|
633
693
|
textAlign: { css: "text-align", toValue: cssTextAlign },
|
|
634
694
|
textTransform: { css: "text-transform", toValue: keyword(TEXT_TRANSFORM) },
|
|
635
695
|
textDecoration: { css: "text-decoration", toValue: keyword(TEXT_DECORATION) },
|
|
696
|
+
// W-952: read by the list marker rules (sent only when a page uses them).
|
|
697
|
+
markerColor: { css: "--emvb-marker-color", toValue: cssColor },
|
|
698
|
+
markerSize: { css: "--emvb-marker-size", toValue: cssLength },
|
|
699
|
+
fontStyle: { css: "font-style", toValue: keyword(FONT_STYLE) },
|
|
700
|
+
whiteSpace: { css: "white-space", toValue: keyword(WHITE_SPACE) },
|
|
701
|
+
overflowWrap: { css: "overflow-wrap", toValue: keyword(OVERFLOW_WRAP) },
|
|
636
702
|
color: { css: "color", toValue: cssColor },
|
|
637
703
|
backgroundColor: { css: "background-color", toValue: cssColor },
|
|
638
704
|
backgroundImage: { css: "background-image", toValue: cssBackgroundImage },
|
|
@@ -657,16 +723,23 @@ const PROPERTY_MAP: {
|
|
|
657
723
|
opacity: { css: "opacity", toValue: cssOpacity },
|
|
658
724
|
boxShadow: { css: "box-shadow", toValue: cssBoxShadow },
|
|
659
725
|
filter: { css: "filter", toValue: cssFilter },
|
|
726
|
+
backdropFilter: { css: "backdrop-filter", toValue: cssFilter },
|
|
727
|
+
// Written by `transformDeclarations` (three properties); never a declaration of its own.
|
|
728
|
+
transform: { css: "translate", toValue: () => undefined },
|
|
660
729
|
cursor: { css: "cursor", toValue: keyword(CURSOR) },
|
|
661
730
|
transition: { css: "transition", toValue: cssTransition },
|
|
662
731
|
entrance: { css: "animation", toValue: cssEntrance },
|
|
663
732
|
// W-319: written by `motionDeclarations` in `styleDeclarations`; this entry only names it.
|
|
664
733
|
scrollMotion: { css: "animation", toValue: () => undefined },
|
|
734
|
+
// W-938: written by `loopDeclarations` in `styleDeclarations`; this entry only names it.
|
|
735
|
+
loopMotion: { css: "animation", toValue: () => undefined },
|
|
665
736
|
iconRotate: { css: "--emvb-icon-rotate", toValue: cssIconRotate },
|
|
666
737
|
iconFlip: { css: "--emvb-icon-flip", toValue: cssIconFlip },
|
|
667
738
|
iconScale: { css: "scale", toValue: cssIconScale },
|
|
668
739
|
iconStrokeWidth: { css: "--emvb-icon-stroke", toValue: cssIconStroke },
|
|
669
740
|
iconShadow: { css: "--emvb-icon-shadow", toValue: cssIconShadow },
|
|
741
|
+
// W-974: applied by `withViewportUnits` to the record's lengths; never a declaration of its own.
|
|
742
|
+
viewportUnits: { css: "--emvb-viewport-units", toValue: () => undefined },
|
|
670
743
|
iconAnimation: { css: "--emvb-icon-animation", toValue: cssIconAnimation },
|
|
671
744
|
};
|
|
672
745
|
|
|
@@ -686,6 +759,58 @@ const shorthandsFirst = (record: Record<string, unknown>): [string, unknown][] =
|
|
|
686
759
|
};
|
|
687
760
|
|
|
688
761
|
/** Converts style props into safe declarations; anything that fails validation is dropped and reported. */
|
|
762
|
+
const TRANSFORM_KEYS = new Set(["x", "y", "scale", "rotate"]);
|
|
763
|
+
const int = (v: unknown, min: number, max: number) =>
|
|
764
|
+
typeof v === "number" && Number.isInteger(v) && v >= min && v <= max;
|
|
765
|
+
|
|
766
|
+
/** W-953: `{ x?, y?, scale?, rotate? }` → `translate`, `scale`, `rotate` (only those set). */
|
|
767
|
+
function transformDeclarations(value: unknown): Declaration[] | undefined {
|
|
768
|
+
if (!isRecord(value) || Object.keys(value).some((key) => !TRANSFORM_KEYS.has(key)))
|
|
769
|
+
return undefined;
|
|
770
|
+
const { x, y, scale, rotate } = value;
|
|
771
|
+
if ([x, y, scale, rotate].every((v) => v === undefined)) return undefined;
|
|
772
|
+
const out: Declaration[] = [];
|
|
773
|
+
if (x !== undefined || y !== undefined) {
|
|
774
|
+
if ((x !== undefined && !int(x, -2000, 2000)) || (y !== undefined && !int(y, -2000, 2000)))
|
|
775
|
+
return undefined;
|
|
776
|
+
out.push({
|
|
777
|
+
property: "translate",
|
|
778
|
+
value: `${(x as number | undefined) ?? 0}px ${(y as number | undefined) ?? 0}px`,
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
if (scale !== undefined) {
|
|
782
|
+
if (!int(scale, 10, 400)) return undefined;
|
|
783
|
+
out.push({ property: "scale", value: String((scale as number) / 100) });
|
|
784
|
+
}
|
|
785
|
+
if (rotate !== undefined) {
|
|
786
|
+
if (!int(rotate, -360, 360)) return undefined;
|
|
787
|
+
out.push({ property: "rotate", value: `${rotate as number}deg` });
|
|
788
|
+
}
|
|
789
|
+
return out;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
const VH_LENGTH = /^(-?\d+(?:\.\d+)?)vh$/;
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* W-974: a `vh` length the record marks as `dvh` or `svh` is written in that unit. Only a plain
|
|
796
|
+
* number with `vh` changes; a variable, `clamp()` or `auto` is left alone.
|
|
797
|
+
*/
|
|
798
|
+
function withViewportUnits(declarations: Declaration[], units: unknown): void {
|
|
799
|
+
if (!isRecord(units)) return;
|
|
800
|
+
for (const [key, unit] of Object.entries(units)) {
|
|
801
|
+
if (unit !== "dvh" && unit !== "svh") continue;
|
|
802
|
+
const entry = Object.hasOwn(PROPERTY_MAP, key)
|
|
803
|
+
? PROPERTY_MAP[key as keyof FlatStyleProps]
|
|
804
|
+
: undefined;
|
|
805
|
+
if (!entry) continue;
|
|
806
|
+
for (const declaration of declarations) {
|
|
807
|
+
if (declaration.property !== entry.css) continue;
|
|
808
|
+
const match = VH_LENGTH.exec(declaration.value);
|
|
809
|
+
if (match) declaration.value = `${match[1]}${unit}`;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
|
|
689
814
|
export function styleDeclarations(style: unknown): {
|
|
690
815
|
declarations: Declaration[];
|
|
691
816
|
rejected: string[];
|
|
@@ -695,6 +820,7 @@ export function styleDeclarations(style: unknown): {
|
|
|
695
820
|
if (typeof style !== "object" || style === null) return { declarations, rejected };
|
|
696
821
|
const record = style as Record<string, unknown>;
|
|
697
822
|
let motion: Declaration[] = [];
|
|
823
|
+
let loop: Declaration[] = [];
|
|
698
824
|
for (const [key, raw] of shorthandsFirst(record)) {
|
|
699
825
|
if (BACKGROUND_KEYS.has(key)) continue;
|
|
700
826
|
if (
|
|
@@ -705,6 +831,19 @@ export function styleDeclarations(style: unknown): {
|
|
|
705
831
|
) {
|
|
706
832
|
continue;
|
|
707
833
|
}
|
|
834
|
+
if (key === "viewportUnits") continue;
|
|
835
|
+
if (key === "loopMotion") {
|
|
836
|
+
const found = loopDeclarations(raw);
|
|
837
|
+
if (found && found.every((d) => isSafeCssValue(d.value))) loop = found;
|
|
838
|
+
else rejected.push(key);
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
if (key === "transform") {
|
|
842
|
+
const found = transformDeclarations(raw);
|
|
843
|
+
if (found) declarations.push(...found);
|
|
844
|
+
else rejected.push(key);
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
708
847
|
if (key === "scrollMotion") {
|
|
709
848
|
const found = motionDeclarations(raw);
|
|
710
849
|
if (found && found.every((d) => isSafeCssValue(d.value))) motion = found;
|
|
@@ -712,7 +851,7 @@ export function styleDeclarations(style: unknown): {
|
|
|
712
851
|
continue;
|
|
713
852
|
}
|
|
714
853
|
const entry = Object.hasOwn(PROPERTY_MAP, key)
|
|
715
|
-
? PROPERTY_MAP[key as keyof
|
|
854
|
+
? PROPERTY_MAP[key as keyof FlatStyleProps]
|
|
716
855
|
: undefined;
|
|
717
856
|
const value = entry?.toValue(raw);
|
|
718
857
|
const safe =
|
|
@@ -733,6 +872,7 @@ export function styleDeclarations(style: unknown): {
|
|
|
733
872
|
rejected.push(key);
|
|
734
873
|
}
|
|
735
874
|
}
|
|
875
|
+
withViewportUnits(declarations, record["viewportUnits"]);
|
|
736
876
|
const background = composeBackground(record);
|
|
737
877
|
declarations.push(...background.declarations);
|
|
738
878
|
rejected.push(...background.rejected);
|
|
@@ -748,11 +888,11 @@ export function styleDeclarations(style: unknown): {
|
|
|
748
888
|
if (column.badSpan) rejected.push("gridColumnSpan");
|
|
749
889
|
if (row.badStart) rejected.push("gridRowStart");
|
|
750
890
|
if (row.badSpan) rejected.push("gridRowSpan");
|
|
751
|
-
return { declarations: withMotion(declarations, motion), rejected };
|
|
891
|
+
return { declarations: withLoop(withMotion(declarations, motion), loop), rejected };
|
|
752
892
|
}
|
|
753
893
|
|
|
754
894
|
/** Normal only (W-089, W-237): a state's `transition` and `iconAnimation` are dropped and reported. */
|
|
755
|
-
const NORMAL_ONLY = ["transition", "iconAnimation", "scrollMotion"] as const;
|
|
895
|
+
const NORMAL_ONLY = ["transition", "iconAnimation", "scrollMotion", "loopMotion"] as const;
|
|
756
896
|
const withoutTransition = (style: unknown): unknown => {
|
|
757
897
|
if (typeof style !== "object" || style === null) return style;
|
|
758
898
|
if (!NORMAL_ONLY.some((key) => key in style)) return style;
|
|
@@ -760,6 +900,7 @@ const withoutTransition = (style: unknown): unknown => {
|
|
|
760
900
|
transition: _drop,
|
|
761
901
|
iconAnimation: _loop,
|
|
762
902
|
scrollMotion: _scroll,
|
|
903
|
+
loopMotion: _loopMotion,
|
|
763
904
|
...rest
|
|
764
905
|
} = style as Record<string, unknown>;
|
|
765
906
|
return rest;
|
|
@@ -810,7 +951,7 @@ const BACKGROUND_LAYER_KEYS = [
|
|
|
810
951
|
* gradient) are filled in from `inherited` here. Otherwise they vanish on that device.
|
|
811
952
|
*/
|
|
812
953
|
/** Both write `animation` (W-319), so one set alone would drop the other it inherits. */
|
|
813
|
-
const ANIMATION_KEYS = ["entrance", "scrollMotion"] as const;
|
|
954
|
+
const ANIMATION_KEYS = ["entrance", "scrollMotion", "loopMotion"] as const;
|
|
814
955
|
|
|
815
956
|
/**
|
|
816
957
|
* A style that sets an entrance or scroll motion keeps the other one it inherits from a wider
|
|
@@ -127,3 +127,119 @@ export function withMotion(declarations: Declaration[], motion: Declaration[]):
|
|
|
127
127
|
...vars,
|
|
128
128
|
];
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
/** W-938: time-based loop keyframes, one per CSS property, read from `--emvb-l*` values. */
|
|
132
|
+
const LOOP_KEYFRAMES_BY_NAME: Record<string, string> = {
|
|
133
|
+
lo: "opacity",
|
|
134
|
+
lt: "translate",
|
|
135
|
+
ls: "scale",
|
|
136
|
+
lr: "rotate",
|
|
137
|
+
lb: "filter",
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The loop keyframes (W-938). Only for visitors who haven't asked for reduced motion; anywhere
|
|
142
|
+
* else `emvb-l*` names nothing and the element stays still.
|
|
143
|
+
*/
|
|
144
|
+
export const LOOP_KEYFRAMES = `@media (prefers-reduced-motion: no-preference){${Object.entries(
|
|
145
|
+
LOOP_KEYFRAMES_BY_NAME,
|
|
146
|
+
)
|
|
147
|
+
.map(
|
|
148
|
+
([name, prop]) =>
|
|
149
|
+
`@keyframes emvb-${name}{from{${prop}:var(--emvb-${name}0)}to{${prop}:var(--emvb-${name}1)}}`,
|
|
150
|
+
)
|
|
151
|
+
.join("")}}`;
|
|
152
|
+
|
|
153
|
+
const LOOP_EASINGS = new Set(["ease", "ease-in", "ease-out", "ease-in-out", "linear"]);
|
|
154
|
+
/** About 5 seconds of motion unless it loops forever (as an Icon's spin, D-057/D-059). */
|
|
155
|
+
const LOOP_STOP_MS = 5000;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Declarations for a `loopMotion` value (W-938): `animation` (one per animated property, a time
|
|
159
|
+
* timeline), and the `--emvb-l*` values. Undefined for a bad value; `{ type: "none" }` is
|
|
160
|
+
* `animation: none`. Bounded: 200 ms to 20 s, the effects' own limits, at most 5 s unless `loop`.
|
|
161
|
+
*/
|
|
162
|
+
export function loopDeclarations(value: unknown): Declaration[] | undefined {
|
|
163
|
+
if (typeof value !== "object" || value === null) return undefined;
|
|
164
|
+
const record = value as Record<string, unknown>;
|
|
165
|
+
if (record["type"] === "none" && Object.keys(record).length === 1) {
|
|
166
|
+
return [{ property: "animation", value: "none" }];
|
|
167
|
+
}
|
|
168
|
+
const allowed = new Set(["effects", "duration", "easing", "alternate", "loop"]);
|
|
169
|
+
if (Object.keys(record).some((key) => !allowed.has(key))) return undefined;
|
|
170
|
+
const { effects, duration, easing, alternate, loop } = record;
|
|
171
|
+
if (!Number.isInteger(duration) || (duration as number) < 200 || (duration as number) > 20_000)
|
|
172
|
+
return undefined;
|
|
173
|
+
if (easing !== undefined && (typeof easing !== "string" || !LOOP_EASINGS.has(easing)))
|
|
174
|
+
return undefined;
|
|
175
|
+
if (alternate !== undefined && typeof alternate !== "boolean") return undefined;
|
|
176
|
+
if (loop !== undefined && loop !== true) return undefined;
|
|
177
|
+
if (!Array.isArray(effects) || effects.length === 0 || effects.length > MOTION_EFFECTS.length) {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
if (!effects.every(isEffect)) return undefined;
|
|
181
|
+
const by = new Map(effects.map((e) => [e.type, e]));
|
|
182
|
+
if (by.size !== effects.length) return undefined;
|
|
183
|
+
const frames: [string, string, string][] = [];
|
|
184
|
+
const fade = by.get("fade");
|
|
185
|
+
if (fade) frames.push(["lo", num(fade.from / 100), num(fade.to / 100)]);
|
|
186
|
+
const x = by.get("move-x");
|
|
187
|
+
const y = by.get("move-y");
|
|
188
|
+
if (x || y) {
|
|
189
|
+
frames.push([
|
|
190
|
+
"lt",
|
|
191
|
+
`${num(x?.from ?? 0)}px ${num(y?.from ?? 0)}px`,
|
|
192
|
+
`${num(x?.to ?? 0)}px ${num(y?.to ?? 0)}px`,
|
|
193
|
+
]);
|
|
194
|
+
}
|
|
195
|
+
const scale = by.get("scale");
|
|
196
|
+
if (scale) frames.push(["ls", num(scale.from / 100), num(scale.to / 100)]);
|
|
197
|
+
const rotate = by.get("rotate");
|
|
198
|
+
if (rotate) frames.push(["lr", `${num(rotate.from)}deg`, `${num(rotate.to)}deg`]);
|
|
199
|
+
const blur = by.get("blur");
|
|
200
|
+
if (blur) frames.push(["lb", `blur(${num(blur.from)}px)`, `blur(${num(blur.to)}px)`]);
|
|
201
|
+
const ms = duration as number;
|
|
202
|
+
const runs = loop ? "infinite" : String(Math.max(1, Math.floor(LOOP_STOP_MS / ms)));
|
|
203
|
+
const direction = alternate === false ? "normal" : "alternate";
|
|
204
|
+
const timing = `${ms}ms ${(easing as string | undefined) ?? "ease-in-out"} ${runs} ${direction}`;
|
|
205
|
+
return [
|
|
206
|
+
{ property: "animation", value: frames.map(([n]) => `emvb-${n} ${timing}`).join(", ") },
|
|
207
|
+
{ property: "animation-timeline", value: frames.map(() => "auto").join(", ") },
|
|
208
|
+
{ property: "animation-range", value: frames.map(() => "normal").join(", ") },
|
|
209
|
+
...frames.flatMap(([n, from, to]) => [
|
|
210
|
+
{ property: `--emvb-${n}0`, value: from },
|
|
211
|
+
{ property: `--emvb-${n}1`, value: to },
|
|
212
|
+
]),
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* W-938: adds a loop to declarations that may already animate (an entrance, scroll motion). The
|
|
218
|
+
* lists are joined, the loop last, with timelines and ranges kept per animation; a loop `none`
|
|
219
|
+
* leaves the others alone.
|
|
220
|
+
*/
|
|
221
|
+
export function withLoop(declarations: Declaration[], loop: Declaration[]): Declaration[] {
|
|
222
|
+
const [animation, timeline, range, ...vars] = loop;
|
|
223
|
+
if (!animation) return declarations;
|
|
224
|
+
const current = declarations.find((d) => d.property === "animation");
|
|
225
|
+
if (!current) return [...declarations, ...loop];
|
|
226
|
+
if (animation.value === "none" || !timeline || !range) return declarations;
|
|
227
|
+
const count = current.value.split(",").length;
|
|
228
|
+
const currentTimeline = declarations.find((d) => d.property === "animation-timeline");
|
|
229
|
+
const currentRange = declarations.find((d) => d.property === "animation-range");
|
|
230
|
+
const rest = declarations.filter(
|
|
231
|
+
(d) => d !== current && d !== currentTimeline && d !== currentRange,
|
|
232
|
+
);
|
|
233
|
+
const fill = (found: Declaration | undefined, value: string) =>
|
|
234
|
+
found?.value ?? Array.from({ length: count }, () => value).join(", ");
|
|
235
|
+
return [
|
|
236
|
+
...rest,
|
|
237
|
+
{ property: "animation", value: `${current.value}, ${animation.value}` },
|
|
238
|
+
{
|
|
239
|
+
property: "animation-timeline",
|
|
240
|
+
value: `${fill(currentTimeline, "auto")}, ${timeline.value}`,
|
|
241
|
+
},
|
|
242
|
+
{ property: "animation-range", value: `${fill(currentRange, "normal")}, ${range.value}` },
|
|
243
|
+
...vars,
|
|
244
|
+
];
|
|
245
|
+
}
|
|
@@ -242,6 +242,12 @@ function withClassIds(node: LayoutNode, ids: ReadonlyMap<string, string>): Layou
|
|
|
242
242
|
return next;
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
/** W-958: a whole layout with its class refs moved to the ids a merge gave them. */
|
|
246
|
+
export const remapClassIds = (layout: Layout, ids: ReadonlyMap<string, string>): Layout => ({
|
|
247
|
+
...layout,
|
|
248
|
+
root: withClassIds(layout.root, ids) as Layout["root"],
|
|
249
|
+
});
|
|
250
|
+
|
|
245
251
|
export type PreparedSection = {
|
|
246
252
|
node: LayoutNode;
|
|
247
253
|
design: DesignSystem;
|
|
@@ -10,7 +10,9 @@ export type FieldKind =
|
|
|
10
10
|
| "media"
|
|
11
11
|
| "icon"
|
|
12
12
|
| "list-items"
|
|
13
|
-
| "image-sources"
|
|
13
|
+
| "image-sources"
|
|
14
|
+
/** W-950: formatting (bold, italic, colour, link) on words of the element's Text. */
|
|
15
|
+
| "marks";
|
|
14
16
|
|
|
15
17
|
export type FieldOption = { value: string | number | boolean; label: string };
|
|
16
18
|
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { HEX_COLOR } from "../css-keywords.ts";
|
|
3
|
-
import { DeviceStyles, HiddenOn, StyleProps, StyleStates } from "./style.ts";
|
|
3
|
+
import { DeviceStyles, HiddenOn, OwnStyle, StyleProps, StyleStates } from "./style.ts";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
+
* 17 since W-925 (contract 1.0): the motion style keys sit under one `motion` record.
|
|
6
7
|
* 15 since W-341, in step with layouts (optional fields only; the design document itself is unchanged).
|
|
7
8
|
* 14 since W-329, in step with layouts (optional fields only: `ch` lengths, negative margins).
|
|
8
9
|
* 13 since W-307, in step with layouts (the W-307 batch only adds optional fields).
|
|
9
10
|
* 12 since W-160: class gradients use the same stops as layouts. v11 `{ angle, from, to }` upgrades on read.
|
|
10
11
|
*/
|
|
11
|
-
export const DESIGN_SCHEMA_VERSION =
|
|
12
|
+
export const DESIGN_SCHEMA_VERSION = 17;
|
|
12
13
|
|
|
13
14
|
/** Tags a site can give a starting style. Classes and local styles still win. */
|
|
14
15
|
export const DEFAULT_STYLE_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "a", "button"] as const;
|
|
@@ -64,7 +65,7 @@ export type FluidRange = z.infer<typeof FluidRange>;
|
|
|
64
65
|
const StyleClass = z.strictObject({
|
|
65
66
|
id: VariableId,
|
|
66
67
|
name: z.string().min(1).max(60),
|
|
67
|
-
style:
|
|
68
|
+
style: OwnStyle,
|
|
68
69
|
states: StyleStates.optional(),
|
|
69
70
|
devices: DeviceStyles.optional(),
|
|
70
71
|
hiddenOn: HiddenOn.optional(),
|