@perkyzz/emvb 0.9.0 → 1.0.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 +1 -1
- package/package.json +2 -2
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/Editor.tsx +297 -248
- package/src/admin/editor/Timeline.tsx +2 -1
- package/src/admin/editor/TopBar.tsx +4 -2
- package/src/admin/editor/canvas/CanvasFrame.tsx +2 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +17 -9
- package/src/admin/editor/canvas/canvas-scale.ts +2 -2
- 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 +26 -4
- package/src/admin/editor/editor-chrome.tsx +3 -3
- package/src/admin/editor/editor-commands.ts +8 -3
- 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 +49 -14
- 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 +104 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +14 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +27 -16
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -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 +113 -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 +53 -1
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +51 -10
- package/src/admin/editor/panels/style-target.ts +9 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/store.ts +6 -2
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +4 -4
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +15 -6
- package/src/admin/editor/useProposals.ts +81 -0
- 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/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 +15 -1
- package/src/admin/pages/ThemePartList.tsx +15 -1
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/ui.ts +39 -2
- package/src/astro/content-port.ts +14 -1
- package/src/astro/resolve-theme.ts +14 -1
- package/src/astro/resolve.ts +89 -2
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +44 -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 +285 -0
- package/src/core/css/generate.ts +89 -20
- package/src/core/css/trace.ts +18 -9
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +4 -5
- package/src/core/design/devices.ts +13 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +17 -4
- package/src/core/elements/dynamic-elements.ts +3 -3
- package/src/core/elements/index.ts +73 -9
- 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 +1 -1
- package/src/core/import/elementor/atomic.ts +1595 -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 +949 -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 +409 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +82 -0
- package/src/core/json-schema.ts +107 -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 +5 -5
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +140 -20
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +125 -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 +2 -1
- package/src/core/schema/layout.ts +82 -14
- package/src/core/schema/style.ts +251 -114
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +1 -0
- package/src/core/theme/popup-rules.ts +17 -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 -9
- 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/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/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./limits.ts";
|
|
2
2
|
export {
|
|
3
3
|
LAYOUT_SCHEMA_VERSION,
|
|
4
|
+
CONTRACT_VERSION,
|
|
5
|
+
cssTypeName,
|
|
4
6
|
Layout,
|
|
5
7
|
type LayoutNode,
|
|
6
8
|
type UnknownNode,
|
|
@@ -10,6 +12,8 @@ export {
|
|
|
10
12
|
SvgNode,
|
|
11
13
|
TabPanelNode,
|
|
12
14
|
HeadingNode,
|
|
15
|
+
MAX_TEXT_MARKS,
|
|
16
|
+
type TextMark,
|
|
13
17
|
SpacerNode,
|
|
14
18
|
DividerNode,
|
|
15
19
|
TextNode,
|
|
@@ -91,6 +95,9 @@ export {
|
|
|
91
95
|
} from "./elements/plain-text.ts";
|
|
92
96
|
export {
|
|
93
97
|
StyleProps,
|
|
98
|
+
FlatStyleProps,
|
|
99
|
+
Motion,
|
|
100
|
+
type StylePatch,
|
|
94
101
|
StyleStates,
|
|
95
102
|
DeviceStyles,
|
|
96
103
|
HiddenOn,
|
|
@@ -100,6 +107,15 @@ export {
|
|
|
100
107
|
VariableRef,
|
|
101
108
|
} from "./schema/style.ts";
|
|
102
109
|
export { STYLE_STATES, type StyleStateName } from "./schema/state-names.ts";
|
|
110
|
+
export {
|
|
111
|
+
flattenMotion,
|
|
112
|
+
nestMotion,
|
|
113
|
+
patchNestedStyle,
|
|
114
|
+
upgradeLegacyNode,
|
|
115
|
+
FLAT_MOTION_KEYS,
|
|
116
|
+
isFlatMotionKey,
|
|
117
|
+
} from "./migrate/v18.ts";
|
|
118
|
+
export { renderableDesign, renderableLayout, renderableNode, renderableStyle } from "./contract.ts";
|
|
103
119
|
export {
|
|
104
120
|
upgradeLayout,
|
|
105
121
|
isNewerThanSupported,
|
|
@@ -361,6 +377,10 @@ export {
|
|
|
361
377
|
clampScrollPercent,
|
|
362
378
|
deviceForWidth,
|
|
363
379
|
POPUP_DEVICES,
|
|
380
|
+
DEVICES,
|
|
381
|
+
type Device,
|
|
382
|
+
STYLE_DEVICES,
|
|
383
|
+
type StyleDevice,
|
|
364
384
|
DEVICE_MEDIA,
|
|
365
385
|
DEVICE_PREVIEW_PX,
|
|
366
386
|
matchesPopupDevices,
|
|
@@ -534,6 +554,7 @@ export {
|
|
|
534
554
|
insertSavedSection,
|
|
535
555
|
MAX_SAVED_SECTIONS,
|
|
536
556
|
mergeSectionClasses,
|
|
557
|
+
remapClassIds,
|
|
537
558
|
prepareSavedSection,
|
|
538
559
|
readSavedSection,
|
|
539
560
|
SAVED_SECTION_NAME_MAX,
|
|
@@ -549,3 +570,64 @@ export {
|
|
|
549
570
|
syncedPartLayout,
|
|
550
571
|
} from "./saved-sections.ts";
|
|
551
572
|
export { portableTextToLayout } from "./portable-text.ts";
|
|
573
|
+
export {
|
|
574
|
+
type ElementorImport,
|
|
575
|
+
type ImportNote,
|
|
576
|
+
type ImportOptions,
|
|
577
|
+
importElementor,
|
|
578
|
+
MAX_IMPORT_CHARS,
|
|
579
|
+
} from "./import/elementor/index.ts";
|
|
580
|
+
|
|
581
|
+
export {
|
|
582
|
+
EXTENSION_API_VERSION,
|
|
583
|
+
EXTENSION_PLACEHOLDER_TEXT,
|
|
584
|
+
EXTENSION_PLACEHOLDER_CSS,
|
|
585
|
+
defineExtension,
|
|
586
|
+
rememberExtensions,
|
|
587
|
+
listedExtensionManifests,
|
|
588
|
+
liveExtension,
|
|
589
|
+
liveElement,
|
|
590
|
+
clearExtensions,
|
|
591
|
+
manifestsFromOptions,
|
|
592
|
+
isExtensionType,
|
|
593
|
+
parseExtensionType,
|
|
594
|
+
extensionType,
|
|
595
|
+
extensionNamespaceIssue,
|
|
596
|
+
extensionIdIssue,
|
|
597
|
+
extensionNameIssue,
|
|
598
|
+
validateExtensionProps,
|
|
599
|
+
schemaDefaults,
|
|
600
|
+
safeExtensionOutput,
|
|
601
|
+
renderExtensionNode,
|
|
602
|
+
syncSourceValues,
|
|
603
|
+
extensionPlaceholderLabel,
|
|
604
|
+
extensionPlaceholderVNode,
|
|
605
|
+
normalizeExtension,
|
|
606
|
+
type EmVBExtension,
|
|
607
|
+
type ExtensionManifest,
|
|
608
|
+
type ExtensionElement,
|
|
609
|
+
type ExtensionPanel,
|
|
610
|
+
type ExtensionSource,
|
|
611
|
+
type ExtensionPropSchema,
|
|
612
|
+
type ExtensionField,
|
|
613
|
+
type ExtensionElementManifest,
|
|
614
|
+
type ExtensionPanelManifest,
|
|
615
|
+
type ExtensionSourceManifest,
|
|
616
|
+
type ExtensionRenderContext,
|
|
617
|
+
} from "./extensions/index.ts";
|
|
618
|
+
export {
|
|
619
|
+
ProposalTarget,
|
|
620
|
+
readProposal,
|
|
621
|
+
applyProposal,
|
|
622
|
+
type Proposal,
|
|
623
|
+
type ProposalBase,
|
|
624
|
+
type ProposalRecord,
|
|
625
|
+
type ProposalRefusal,
|
|
626
|
+
} from "./proposals.ts";
|
|
627
|
+
export {
|
|
628
|
+
hasFormat,
|
|
629
|
+
type MarkFormat,
|
|
630
|
+
setFormat,
|
|
631
|
+
unsetFormat,
|
|
632
|
+
withShiftedMarks,
|
|
633
|
+
} from "./text-marks.ts";
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DESIGN_SCHEMA_VERSION, DesignSystem } from "./schema/design.ts";
|
|
3
|
+
import { CONTRACT_VERSION, KNOWN_NODE_SCHEMAS, LAYOUT_SCHEMA_VERSION } from "./schema/layout.ts";
|
|
4
|
+
import { DeviceStyles, StyleProps, StyleStates } from "./schema/style.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* JSON Schema (2020-12) exports of the stored formats (W-925, contract 1.0). They describe the
|
|
8
|
+
* keys this version knows; per D-065 a validator also keeps unknown keys on a node, its props
|
|
9
|
+
* and its style records (see docs/SCHEMA.md), so these schemas are stricter than `validateLayout`.
|
|
10
|
+
*/
|
|
11
|
+
const NOTE =
|
|
12
|
+
"EmVB keeps unknown keys on a node, its props and its style records (D-065, limits in docs/SCHEMA.md); this schema lists the known ones only. An element type this version does not know is kept too.";
|
|
13
|
+
|
|
14
|
+
type Json = Record<string, unknown>;
|
|
15
|
+
const toJson = (schema: z.ZodType): Json => {
|
|
16
|
+
const { $schema: _drop, ...rest } = z.toJSONSchema(schema, {
|
|
17
|
+
io: "input",
|
|
18
|
+
unrepresentable: "any",
|
|
19
|
+
}) as Json;
|
|
20
|
+
return rest;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Replaces every sub-schema equal to a shared one with a `$ref` to it, bottom-up. */
|
|
24
|
+
function withRefs(value: unknown, shared: ReadonlyMap<string, string>): unknown {
|
|
25
|
+
if (Array.isArray(value)) return value.map((item) => withRefs(item, shared));
|
|
26
|
+
if (typeof value !== "object" || value === null) return value;
|
|
27
|
+
const ref = shared.get(JSON.stringify(value));
|
|
28
|
+
if (ref) return { $ref: `#/$defs/${ref}` };
|
|
29
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, withRefs(v, shared)]));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The style records every node and class shares, as `$defs`, and the map that refers to them. */
|
|
33
|
+
function styleDefs(): { defs: Json; shared: Map<string, string> } {
|
|
34
|
+
const style = toJson(StyleProps);
|
|
35
|
+
const states = toJson(StyleStates);
|
|
36
|
+
const devices = toJson(DeviceStyles);
|
|
37
|
+
// A state's style is the style without `motion`; one shared definition for all three states.
|
|
38
|
+
const stateStyle = (states["properties"] as Record<string, Json>)["hover"] as Json;
|
|
39
|
+
const inner = new Map([
|
|
40
|
+
[JSON.stringify(style), "style"],
|
|
41
|
+
[JSON.stringify(stateStyle), "stateStyle"],
|
|
42
|
+
]);
|
|
43
|
+
const defs: Json = {
|
|
44
|
+
style,
|
|
45
|
+
stateStyle,
|
|
46
|
+
states: withRefs(states, inner),
|
|
47
|
+
devices: withRefs(devices, inner),
|
|
48
|
+
};
|
|
49
|
+
const shared = new Map([
|
|
50
|
+
...inner,
|
|
51
|
+
[JSON.stringify(states), "states"],
|
|
52
|
+
[JSON.stringify(devices), "devices"],
|
|
53
|
+
]);
|
|
54
|
+
return { defs, shared };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function nodeDefs(): { defs: Json; types: string[] } {
|
|
58
|
+
const { defs, shared } = styleDefs();
|
|
59
|
+
const types: string[] = [];
|
|
60
|
+
for (const schema of KNOWN_NODE_SCHEMAS) {
|
|
61
|
+
const shape = (schema as unknown as { shape: Record<string, z.ZodType> }).shape;
|
|
62
|
+
const type = (shape["type"] as unknown as { value: string }).value;
|
|
63
|
+
types.push(type);
|
|
64
|
+
const json = withRefs(toJson(schema as unknown as z.ZodType), shared) as Json;
|
|
65
|
+
const properties = json["properties"] as Json | undefined;
|
|
66
|
+
if (properties && "children" in properties) {
|
|
67
|
+
properties["children"] = { type: "array", items: { $ref: "#/$defs/node" } };
|
|
68
|
+
}
|
|
69
|
+
defs[`node:${type}`] = json;
|
|
70
|
+
}
|
|
71
|
+
defs["node"] = {
|
|
72
|
+
description: "One element. An element type this version does not know is kept (D-065).",
|
|
73
|
+
anyOf: types.map((type) => ({ $ref: `#/$defs/node:${type}` })),
|
|
74
|
+
};
|
|
75
|
+
return { defs, types };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** JSON Schema of a stored layout, for `emvb://schema/layout` (W-467) and docs/schema. */
|
|
79
|
+
export const layoutJsonSchema = (): Json => {
|
|
80
|
+
const { defs } = nodeDefs();
|
|
81
|
+
return {
|
|
82
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
83
|
+
title: `EmVB layout (schema ${LAYOUT_SCHEMA_VERSION}, contract ${CONTRACT_VERSION})`,
|
|
84
|
+
$comment: NOTE,
|
|
85
|
+
type: "object",
|
|
86
|
+
properties: {
|
|
87
|
+
schemaVersion: { type: "number", const: LAYOUT_SCHEMA_VERSION },
|
|
88
|
+
root: { $ref: "#/$defs/node:container" },
|
|
89
|
+
},
|
|
90
|
+
required: ["schemaVersion", "root"],
|
|
91
|
+
additionalProperties: false,
|
|
92
|
+
$defs: defs,
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** JSON Schema of the design system (site styles), for `emvb://schema/design`. */
|
|
97
|
+
export const designJsonSchema = (): Json => {
|
|
98
|
+
const { defs, shared } = styleDefs();
|
|
99
|
+
const body = withRefs(toJson(DesignSystem), shared) as Json;
|
|
100
|
+
return {
|
|
101
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
102
|
+
title: `EmVB design system (schema ${DESIGN_SCHEMA_VERSION}, contract ${CONTRACT_VERSION})`,
|
|
103
|
+
$comment: NOTE,
|
|
104
|
+
...body,
|
|
105
|
+
$defs: defs,
|
|
106
|
+
};
|
|
107
|
+
};
|
package/src/core/limits.ts
CHANGED
|
@@ -28,3 +28,22 @@ export function clipText(text: string, max: number): string {
|
|
|
28
28
|
const code = text.charCodeAt(max - 1);
|
|
29
29
|
return text.slice(0, code >= 0xd800 && code <= 0xdbff ? max - 1 : max);
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* D-065 (W-925): a key this version does not know is kept untouched, on a node, its props and
|
|
34
|
+
* its style records only, and never rendered. These bound what such a key may hold.
|
|
35
|
+
*/
|
|
36
|
+
export const UNKNOWN_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_.:/@-]{0,127}$/;
|
|
37
|
+
export const MAX_UNKNOWN_KEYS = 32;
|
|
38
|
+
export const MAX_UNKNOWN_DEPTH = 16;
|
|
39
|
+
|
|
40
|
+
/** W-928: proposals are bounded separately from the resulting page and site styles. */
|
|
41
|
+
export const MAX_PROPOSAL_OPS = 100;
|
|
42
|
+
export const MAX_PROPOSAL_BYTES = MAX_LAYOUT_BYTES;
|
|
43
|
+
export const MAX_PROPOSALS = 100;
|
|
44
|
+
/** W-933: one page can't hold the whole store; an agent withdraws or waits for review. */
|
|
45
|
+
export const MAX_PENDING_PER_PAGE = 10;
|
|
46
|
+
/** W-931: a request to an agent is a short brief, and a page holds a few at a time. */
|
|
47
|
+
export const MAX_REQUEST_PROMPT = 2000;
|
|
48
|
+
export const MAX_OPEN_REQUESTS_PER_PAGE = 5;
|
|
49
|
+
export const MAX_PROPOSAL_DEPTH = MAX_DEPTH * 2 + 16;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isRecord } from "../record.ts";
|
|
2
2
|
import { LAYOUT_SCHEMA_VERSION } from "../schema/layout.ts";
|
|
3
|
+
import { designTo17, layoutTo18 } from "./v18.ts";
|
|
3
4
|
|
|
4
5
|
export type Migration = (doc: Record<string, unknown>) => Record<string, unknown>;
|
|
5
6
|
|
|
@@ -17,7 +18,9 @@ export type Migration = (doc: Record<string, unknown>) => Record<string, unknown
|
|
|
17
18
|
* optional fields only (audience segments, Loop options, `ch` and negative margins), and
|
|
18
19
|
* v14 → v15 (W-341 onward) adds optional fields only (direction, image link and caption,
|
|
19
20
|
* button icons, table of contents, container queries), and layout v15 → v16 (W-481) adds the
|
|
20
|
-
* optional image `edit` record
|
|
21
|
+
* optional image `edit` record, and layout v17 → v18 / design v16 → v17 (W-925, contract 1.0)
|
|
22
|
+
* rename `section` to `part-ref`, a node's `label` to `editorLabel` and a Loop's `itemPartId` to
|
|
23
|
+
* `partId`, and fold the four motion style keys under `motion`. Every other value is unchanged.
|
|
21
24
|
*/
|
|
22
25
|
const unchanged: Migration = (doc) => doc;
|
|
23
26
|
|
|
@@ -78,6 +81,7 @@ export const LAYOUT_MIGRATIONS: Readonly<Record<number, Migration>> = {
|
|
|
78
81
|
14: unchanged,
|
|
79
82
|
15: unchanged,
|
|
80
83
|
16: unchanged,
|
|
84
|
+
17: layoutTo18,
|
|
81
85
|
};
|
|
82
86
|
|
|
83
87
|
/** `DESIGN_MIGRATIONS[n]` upgrades a version-n design document to version n + 1. */
|
|
@@ -97,6 +101,7 @@ export const DESIGN_MIGRATIONS: Readonly<Record<number, Migration>> = {
|
|
|
97
101
|
13: unchanged,
|
|
98
102
|
14: unchanged,
|
|
99
103
|
15: unchanged,
|
|
104
|
+
16: designTo17,
|
|
100
105
|
};
|
|
101
106
|
|
|
102
107
|
export type UpgradeResult =
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { isRecord } from "../record.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Schema 18 / design 17 (W-925, contract 1.0): the renames and the motion fold. Pure and
|
|
5
|
+
* idempotent, so the same helpers also tidy MCP input that still uses the 0.x names.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** The 0.x flat style key for each part of `motion`, in the order the parts are listed. */
|
|
9
|
+
const MOTION_PARTS = {
|
|
10
|
+
entrance: "entrance",
|
|
11
|
+
scroll: "scrollMotion",
|
|
12
|
+
transition: "transition",
|
|
13
|
+
icon: "iconAnimation",
|
|
14
|
+
// W-938: added in 1.0; the flat key exists only inside EmVB (style rows, CSS).
|
|
15
|
+
loop: "loopMotion",
|
|
16
|
+
} as const;
|
|
17
|
+
export type MotionPart = keyof typeof MOTION_PARTS;
|
|
18
|
+
export type FlatMotionKey = (typeof MOTION_PARTS)[MotionPart];
|
|
19
|
+
|
|
20
|
+
const PART_OF: Readonly<Record<string, MotionPart>> = {
|
|
21
|
+
entrance: "entrance",
|
|
22
|
+
scrollMotion: "scroll",
|
|
23
|
+
transition: "transition",
|
|
24
|
+
iconAnimation: "icon",
|
|
25
|
+
loopMotion: "loop",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const FLAT_MOTION_KEYS: readonly FlatMotionKey[] = Object.values(MOTION_PARTS);
|
|
29
|
+
|
|
30
|
+
export function isFlatMotionKey(key: string): key is FlatMotionKey {
|
|
31
|
+
return Object.hasOwn(PART_OF, key);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The `motion` part a 0.x flat key became, e.g. `scrollMotion` → `scroll`. */
|
|
35
|
+
function motionPartOf(key: FlatMotionKey): MotionPart {
|
|
36
|
+
return PART_OF[key] as MotionPart;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 0.x flat style → nested. `motion` takes the place of the first motion key and keeps the
|
|
41
|
+
* parts in the order they were written, so the CSS comes out in the same order whenever the
|
|
42
|
+
* motion keys were next to each other. A style with no motion key is returned as is.
|
|
43
|
+
*/
|
|
44
|
+
export function nestMotion<T>(style: T): T {
|
|
45
|
+
if (!isRecord(style)) return style;
|
|
46
|
+
if (!Object.keys(style).some(isFlatMotionKey)) return style;
|
|
47
|
+
const out: Record<string, unknown> = {};
|
|
48
|
+
const existing = isRecord(style["motion"]) ? style["motion"] : undefined;
|
|
49
|
+
let motion: Record<string, unknown> | undefined;
|
|
50
|
+
for (const [key, value] of Object.entries(style)) {
|
|
51
|
+
if (key === "motion") {
|
|
52
|
+
if (!motion) motion = out["motion"] = { ...existing };
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (!isFlatMotionKey(key)) {
|
|
56
|
+
out[key] = value;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (!motion) motion = out["motion"] = { ...existing };
|
|
60
|
+
const part = motionPartOf(key);
|
|
61
|
+
if (!(part in motion)) motion[part] = value;
|
|
62
|
+
}
|
|
63
|
+
return out as T;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Nested → flat, for the renderer and the editor's style rows, which name the parts by their
|
|
68
|
+
* 0.x keys. The parts take `motion`'s place. Idempotent: a style already flat comes back as is,
|
|
69
|
+
* so cascades and helpers can flatten whatever they are handed. With `motion` present, its
|
|
70
|
+
* parts win over stray top-level 0.x keys (those are unknown keys in a schema-18 document;
|
|
71
|
+
* `withoutStrayMotionKeys` drops them where stored documents are read for rendering).
|
|
72
|
+
*/
|
|
73
|
+
export function flattenMotion<T>(style: T): T {
|
|
74
|
+
if (!isRecord(style)) return style;
|
|
75
|
+
if (!("motion" in style)) return style;
|
|
76
|
+
const out: Record<string, unknown> = {};
|
|
77
|
+
for (const [key, value] of Object.entries(style)) {
|
|
78
|
+
if (isFlatMotionKey(key)) continue;
|
|
79
|
+
if (key !== "motion") {
|
|
80
|
+
out[key] = value;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (!isRecord(value)) continue;
|
|
84
|
+
for (const [part, partValue] of Object.entries(value)) {
|
|
85
|
+
const flat = Object.hasOwn(MOTION_PARTS, part) ? MOTION_PARTS[part as MotionPart] : undefined;
|
|
86
|
+
if (flat && partValue !== undefined) out[flat] = partValue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return out as T;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A stored (schema-18) style without top-level 0.x motion keys: there they are unknown keys
|
|
94
|
+
* (D-065), kept in the document but never rendered.
|
|
95
|
+
*/
|
|
96
|
+
export function withoutStrayMotionKeys<T>(style: T): T {
|
|
97
|
+
if (!isRecord(style) || !Object.keys(style).some(isFlatMotionKey)) return style;
|
|
98
|
+
const out: Record<string, unknown> = {};
|
|
99
|
+
for (const [key, value] of Object.entries(style)) if (!isFlatMotionKey(key)) out[key] = value;
|
|
100
|
+
return out as T;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Applies a flat style patch (0.x key names, `undefined` clears) to a stored, nested style.
|
|
105
|
+
* Keys the patch does not name are kept as they are, unknown ones included (D-065).
|
|
106
|
+
*/
|
|
107
|
+
export function patchNestedStyle(
|
|
108
|
+
stored: Readonly<Record<string, unknown>> | undefined,
|
|
109
|
+
patch: Readonly<Record<string, unknown>>,
|
|
110
|
+
): Record<string, unknown> {
|
|
111
|
+
const out: Record<string, unknown> = { ...stored };
|
|
112
|
+
let motion: Record<string, unknown> | undefined = isRecord(out["motion"])
|
|
113
|
+
? { ...out["motion"] }
|
|
114
|
+
: undefined;
|
|
115
|
+
let touchedMotion = false;
|
|
116
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
117
|
+
if (key === "motion") {
|
|
118
|
+
motion = isRecord(value) ? { ...value } : undefined;
|
|
119
|
+
touchedMotion = true;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (isFlatMotionKey(key)) {
|
|
123
|
+
const part = motionPartOf(key);
|
|
124
|
+
motion ??= {};
|
|
125
|
+
if (value === undefined) delete motion[part];
|
|
126
|
+
else motion[part] = value;
|
|
127
|
+
touchedMotion = true;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (value === undefined) delete out[key];
|
|
131
|
+
else out[key] = value;
|
|
132
|
+
}
|
|
133
|
+
if (touchedMotion) {
|
|
134
|
+
if (motion && Object.keys(motion).length > 0) out["motion"] = motion;
|
|
135
|
+
else delete out["motion"];
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function foldDevices(devices: unknown): unknown {
|
|
141
|
+
if (!isRecord(devices)) return devices;
|
|
142
|
+
const out: Record<string, unknown> = { ...devices };
|
|
143
|
+
for (const device of ["laptop", "tablet", "mobile"]) {
|
|
144
|
+
if (device in out) out[device] = nestMotion(out[device]);
|
|
145
|
+
}
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* One 0.x node (and its children) in schema-18 names: `section` → `part-ref`, node `label` →
|
|
151
|
+
* `editorLabel`, a Loop's `itemPartId` → `partId`, and motion folded under `motion`. An
|
|
152
|
+
* already-current node comes back equal. Never mutates the input.
|
|
153
|
+
*/
|
|
154
|
+
export function upgradeLegacyNode(node: unknown): unknown {
|
|
155
|
+
if (!isRecord(node)) return node;
|
|
156
|
+
const out: Record<string, unknown> = {};
|
|
157
|
+
for (const [key, value] of Object.entries(node)) {
|
|
158
|
+
if (key === "label" && !("editorLabel" in node)) out["editorLabel"] = value;
|
|
159
|
+
else if (key === "type" && value === "section") out[key] = "part-ref";
|
|
160
|
+
else if (key === "style") out[key] = nestMotion(value);
|
|
161
|
+
else if (key === "devices") out[key] = foldDevices(value);
|
|
162
|
+
else if (key === "query" && isRecord(value))
|
|
163
|
+
out[key] = "style" in value ? { ...value, style: nestMotion(value["style"]) } : value;
|
|
164
|
+
else if (key === "children" && Array.isArray(value))
|
|
165
|
+
out[key] = value.map((child) => upgradeLegacyNode(child));
|
|
166
|
+
else out[key] = value;
|
|
167
|
+
}
|
|
168
|
+
if (out["type"] === "loop" && isRecord(out["props"]) && "itemPartId" in out["props"]) {
|
|
169
|
+
const props: Record<string, unknown> = {};
|
|
170
|
+
for (const [key, value] of Object.entries(out["props"])) {
|
|
171
|
+
if (key !== "itemPartId") props[key] = value;
|
|
172
|
+
else if (!("partId" in out["props"])) props["partId"] = value;
|
|
173
|
+
}
|
|
174
|
+
out["props"] = props;
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* W-956: before Laptop, "hidden on Desktop" covered every screen from 1025 px, laptops included;
|
|
181
|
+
* a stored 0.x element hidden on Desktop is hidden on Laptop too, so it renders as before.
|
|
182
|
+
*/
|
|
183
|
+
function hiddenWithLaptop(hiddenOn: unknown): unknown {
|
|
184
|
+
if (!Array.isArray(hiddenOn) || !hiddenOn.includes("desktop") || hiddenOn.includes("laptop"))
|
|
185
|
+
return hiddenOn;
|
|
186
|
+
const at = hiddenOn.indexOf("desktop");
|
|
187
|
+
return [...hiddenOn.slice(0, at + 1), "laptop", ...hiddenOn.slice(at + 1)];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function laptopHidden(node: unknown): unknown {
|
|
191
|
+
if (!isRecord(node)) return node;
|
|
192
|
+
const out: Record<string, unknown> = { ...node };
|
|
193
|
+
if ("hiddenOn" in node) out["hiddenOn"] = hiddenWithLaptop(node["hiddenOn"]);
|
|
194
|
+
if (Array.isArray(node["children"])) out["children"] = node["children"].map(laptopHidden);
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Layout v17 → v18. */
|
|
199
|
+
export function layoutTo18(doc: Record<string, unknown>): Record<string, unknown> {
|
|
200
|
+
return "root" in doc ? { ...doc, root: laptopHidden(upgradeLegacyNode(doc["root"])) } : doc;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Design v16 → v17: motion folded in classes (style and devices) and tag defaults. */
|
|
204
|
+
export function designTo17(doc: Record<string, unknown>): Record<string, unknown> {
|
|
205
|
+
const out: Record<string, unknown> = { ...doc };
|
|
206
|
+
if (Array.isArray(doc["classes"])) {
|
|
207
|
+
out["classes"] = doc["classes"].map((cls: unknown) => {
|
|
208
|
+
if (!isRecord(cls)) return cls;
|
|
209
|
+
const next: Record<string, unknown> = { ...cls };
|
|
210
|
+
if ("style" in cls) next["style"] = nestMotion(cls["style"]);
|
|
211
|
+
if ("devices" in cls) next["devices"] = foldDevices(cls["devices"]);
|
|
212
|
+
if ("hiddenOn" in cls) next["hiddenOn"] = hiddenWithLaptop(cls["hiddenOn"]);
|
|
213
|
+
return next;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
if (isRecord(doc["defaults"])) {
|
|
217
|
+
const defaults: Record<string, unknown> = {};
|
|
218
|
+
for (const [tag, style] of Object.entries(doc["defaults"])) defaults[tag] = nestMotion(style);
|
|
219
|
+
out["defaults"] = defaults;
|
|
220
|
+
}
|
|
221
|
+
return out;
|
|
222
|
+
}
|
package/src/core/perf/meter.ts
CHANGED
|
@@ -86,12 +86,12 @@ function media(
|
|
|
86
86
|
const seen = new Set<Layout>();
|
|
87
87
|
/** W-671: a synced section or Loop Item part the canvas loaded is weighed with the page. */
|
|
88
88
|
const part = (n: LayoutNode): Layout | undefined => {
|
|
89
|
-
const props = n.props as { partId?: unknown
|
|
89
|
+
const props = n.props as { partId?: unknown };
|
|
90
90
|
const found =
|
|
91
|
-
n.type === "
|
|
91
|
+
n.type === "part-ref" && typeof props.partId === "string"
|
|
92
92
|
? dynamic?.sectionTemplates?.[props.partId.trim()]
|
|
93
|
-
: n.type === "loop" && typeof props.
|
|
94
|
-
? dynamic?.loopTemplates?.[props.
|
|
93
|
+
: n.type === "loop" && typeof props.partId === "string"
|
|
94
|
+
? dynamic?.loopTemplates?.[props.partId.trim()]
|
|
95
95
|
: undefined;
|
|
96
96
|
if (!found || seen.has(found)) return undefined;
|
|
97
97
|
seen.add(found);
|
|
@@ -161,7 +161,7 @@ export function measurePage(
|
|
|
161
161
|
sections.push({
|
|
162
162
|
id: child.id,
|
|
163
163
|
type: child.type,
|
|
164
|
-
...(child.
|
|
164
|
+
...(child.editorLabel ? { label: child.editorLabel } : {}),
|
|
165
165
|
bytes: Math.round(utf8(one.html) * GZIP) + m.bytes,
|
|
166
166
|
images: m.images,
|
|
167
167
|
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ELEMENT_DESCRIPTORS } from "./elements/index.ts";
|
|
2
|
+
import { isFlatMotionKey } from "./migrate/v18.ts";
|
|
3
|
+
import { isRecord } from "./record.ts";
|
|
4
|
+
import { isSafeCssValue, isSafeFontStack } from "./sanitize/css.ts";
|
|
5
|
+
import { sanitizeHref } from "./sanitize/href.ts";
|
|
6
|
+
import { sanitizeMediaUrl } from "./sanitize/media-url.ts";
|
|
7
|
+
import { isSafeSvgMarkup } from "./sanitize/svg.ts";
|
|
8
|
+
import type { DesignSystem } from "./schema/design.ts";
|
|
9
|
+
import type { Layout } from "./schema/layout.ts";
|
|
10
|
+
import { stableJson } from "./stable-json.ts";
|
|
11
|
+
import { findNode, forEachNode } from "./tree-ops.ts";
|
|
12
|
+
|
|
13
|
+
const same = (a: unknown, b: unknown) => stableJson(a) === stableJson(b);
|
|
14
|
+
|
|
15
|
+
function styleRefusal(raw: unknown, key = ""): string | undefined {
|
|
16
|
+
if (typeof raw === "string" && raw !== "") {
|
|
17
|
+
const safe = key === "fontFamily" ? isSafeFontStack(raw) : isSafeCssValue(raw);
|
|
18
|
+
if (!safe) return `Unsafe style value at ${key}.`;
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(raw)) {
|
|
21
|
+
for (const value of raw) {
|
|
22
|
+
const reason = styleRefusal(value, key);
|
|
23
|
+
if (reason) return reason;
|
|
24
|
+
}
|
|
25
|
+
} else if (isRecord(raw)) {
|
|
26
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
27
|
+
if (key !== "motion" && isFlatMotionKey(name))
|
|
28
|
+
return "Use frozen style.motion keys, not legacy motion fields.";
|
|
29
|
+
if ((name === "src" || name === "url") && typeof value === "string") {
|
|
30
|
+
if (value.trim() && !sanitizeMediaUrl(value)) return "Unsafe background media URL.";
|
|
31
|
+
} else {
|
|
32
|
+
const reason = styleRefusal(value, name);
|
|
33
|
+
if (reason) return reason;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Reuse the renderer's allowlists. Old, unchanged unsafe fields remain readable like MCP writes. */
|
|
41
|
+
export function proposalSafetyRefusal(
|
|
42
|
+
before: Layout,
|
|
43
|
+
after: Layout,
|
|
44
|
+
oldDesign: DesignSystem,
|
|
45
|
+
design: DesignSystem,
|
|
46
|
+
): string | undefined {
|
|
47
|
+
let reason: string | undefined;
|
|
48
|
+
forEachNode(after.root, (node) => {
|
|
49
|
+
if (reason) return;
|
|
50
|
+
const old = findNode(before, node.id);
|
|
51
|
+
const props = node.props as Record<string, unknown>;
|
|
52
|
+
const oldProps = old?.props as Record<string, unknown> | undefined;
|
|
53
|
+
for (const field of ELEMENT_DESCRIPTORS.find((d) => d.type === node.type)?.fields ?? []) {
|
|
54
|
+
const value = props[field.key];
|
|
55
|
+
if (
|
|
56
|
+
field.kind === "href" &&
|
|
57
|
+
typeof value === "string" &&
|
|
58
|
+
value.trim() &&
|
|
59
|
+
value !== oldProps?.[field.key] &&
|
|
60
|
+
sanitizeHref(value) === undefined
|
|
61
|
+
)
|
|
62
|
+
reason = `Unsafe link on ${node.id}.${field.key}.`;
|
|
63
|
+
}
|
|
64
|
+
if (!same(node.props, old?.props)) {
|
|
65
|
+
const sources = node.type === "image" && Array.isArray(props.sources) ? props.sources : [];
|
|
66
|
+
const urls = [
|
|
67
|
+
node.type === "image" || node.type === "video" ? props.src : undefined,
|
|
68
|
+
...sources.map((s: { src?: unknown }) => s.src),
|
|
69
|
+
];
|
|
70
|
+
if (urls.some((url) => typeof url === "string" && url.trim() && !sanitizeMediaUrl(url)))
|
|
71
|
+
reason = `Unsafe media URL on ${node.id}.`;
|
|
72
|
+
for (const markup of [node.type === "svg" ? props.markup : undefined, props.iconSvg]) {
|
|
73
|
+
if (typeof markup === "string" && markup.trim() && !isSafeSvgMarkup(markup))
|
|
74
|
+
reason = `Unsafe SVG on ${node.id}.`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const key of ["style", "states", "devices", "query"] as const) {
|
|
78
|
+
if (!same(node[key], old?.[key])) reason ??= styleRefusal(node[key]);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
for (const cls of design.classes ?? []) {
|
|
82
|
+
if (
|
|
83
|
+
!same(
|
|
84
|
+
cls,
|
|
85
|
+
oldDesign.classes?.find((c) => c.id === cls.id),
|
|
86
|
+
)
|
|
87
|
+
) {
|
|
88
|
+
for (const raw of [cls.style, cls.states, cls.devices]) reason ??= styleRefusal(raw);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const font of design.variables.fonts ?? []) {
|
|
92
|
+
if (
|
|
93
|
+
!same(
|
|
94
|
+
font,
|
|
95
|
+
oldDesign.variables.fonts?.find((v) => v.id === font.id),
|
|
96
|
+
) &&
|
|
97
|
+
!isSafeFontStack(font.value)
|
|
98
|
+
)
|
|
99
|
+
reason ??= "Unsafe font stack.";
|
|
100
|
+
}
|
|
101
|
+
return reason;
|
|
102
|
+
}
|