@perkyzz/emvb 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +59 -2
- package/THIRD_PARTY_NOTICES.md +32 -0
- package/licenses/fontawesome-free.LICENSE +165 -0
- package/licenses/lucide-static.LICENSE +43 -0
- package/licenses/remixicon.LICENSE +201 -0
- package/licenses/tabler-icons.LICENSE +21 -0
- package/package.json +76 -4
- package/src/admin/access/RequireEditor.tsx +39 -0
- package/src/admin/access/role.ts +36 -0
- package/src/admin/access/sidebar-shim.ts +108 -0
- package/src/admin/api.ts +75 -0
- package/src/admin/content-api.ts +210 -0
- package/src/admin/editor/Editor.tsx +532 -0
- package/src/admin/editor/EditorOverlay.tsx +66 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +21 -0
- package/src/admin/editor/TopBar.tsx +243 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +536 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +91 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +239 -0
- package/src/admin/editor/canvas/canvas-events.ts +245 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +101 -0
- package/src/admin/editor/canvas/vnode-react.tsx +69 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +164 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +148 -0
- package/src/admin/editor/dnd/new-element.ts +107 -0
- package/src/admin/editor/editor-css.ts +625 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/host.ts +30 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
- package/src/admin/editor/icons/library.ts +243 -0
- package/src/admin/editor/icons/set-format.ts +29 -0
- package/src/admin/editor/icons/sets/fontawesome.json +1 -0
- package/src/admin/editor/icons/sets/lucide.json +1 -0
- package/src/admin/editor/icons/sets/remix.json +1 -0
- package/src/admin/editor/icons/sets/tabler.json +1 -0
- package/src/admin/editor/panels/AddPanel.tsx +146 -0
- package/src/admin/editor/panels/ClassesSection.tsx +372 -0
- package/src/admin/editor/panels/ColorControl.tsx +477 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +773 -0
- package/src/admin/editor/panels/LayersPanel.tsx +573 -0
- package/src/admin/editor/panels/LeftPanel.tsx +81 -0
- package/src/admin/editor/panels/PageSettings.tsx +255 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +113 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +548 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +214 -0
- package/src/admin/editor/panels/VariableSection.tsx +530 -0
- package/src/admin/editor/panels/color-space.ts +195 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +418 -0
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
- package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
- package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +451 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +242 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +354 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +119 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +270 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +106 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +170 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +217 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +130 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +220 -0
- package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +563 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +171 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
- package/src/admin/editor/panels/settings/background-mode.ts +112 -0
- package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
- package/src/admin/editor/panels/settings/box-sides.ts +153 -0
- package/src/admin/editor/panels/settings/button-url.ts +27 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +53 -0
- package/src/admin/editor/panels/settings/form-names.ts +38 -0
- package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
- package/src/admin/editor/panels/settings/image-alt.ts +25 -0
- package/src/admin/editor/panels/settings/length-units.ts +116 -0
- package/src/admin/editor/panels/settings/loop-context.ts +26 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +394 -0
- package/src/admin/editor/panels/settings/svg-images.ts +14 -0
- package/src/admin/editor/panels/site-list.tsx +209 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/restore-deleted.ts +80 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +240 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +203 -0
- package/src/admin/editor/useEditorData.ts +193 -0
- package/src/admin/editor/useEditorShortcuts.ts +180 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +184 -0
- package/src/admin/editor/useSave.ts +242 -0
- package/src/admin/entry-status.ts +19 -0
- package/src/admin/forms-api.ts +73 -0
- package/src/admin/icon-uploads-api.ts +44 -0
- package/src/admin/index.tsx +20 -0
- package/src/admin/media-api.ts +68 -0
- package/src/admin/pages/CreateDialog.tsx +150 -0
- package/src/admin/pages/EditorPage.tsx +57 -0
- package/src/admin/pages/NewPageDialog.tsx +83 -0
- package/src/admin/pages/NewThemePartDialog.tsx +61 -0
- package/src/admin/pages/PageList.tsx +91 -0
- package/src/admin/pages/PagesPage.tsx +25 -0
- package/src/admin/pages/SetupShell.tsx +90 -0
- package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
- package/src/admin/pages/ThemePartList.tsx +221 -0
- package/src/admin/pages/list-kit.tsx +125 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +107 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +233 -0
- package/src/admin/ui.ts +244 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +63 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
- package/src/astro/floats/index.ts +1 -0
- package/src/astro/floats/runtime.ts +78 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +126 -0
- package/src/astro/index.ts +16 -0
- package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
- package/src/astro/menu/index.ts +1 -0
- package/src/astro/menu/runtime.ts +37 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +296 -0
- package/src/astro/render.ts +108 -0
- package/src/astro/resolve-theme.ts +515 -0
- package/src/astro/resolve.ts +65 -0
- package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
- package/src/astro/tabs/index.ts +1 -0
- package/src/astro/tabs/runtime.ts +116 -0
- package/src/astro/theme-context.ts +89 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +448 -0
- package/src/core/clipboard.ts +504 -0
- package/src/core/css/generate.ts +236 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +224 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +132 -0
- package/src/core/design/variables.ts +359 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +225 -0
- package/src/core/elements/field-id.ts +6 -0
- package/src/core/elements/form-elements.ts +219 -0
- package/src/core/elements/index.ts +960 -0
- package/src/core/elements/menu.ts +190 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +45 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +380 -0
- package/src/core/limits.ts +9 -0
- package/src/core/migrate/index.ts +126 -0
- package/src/core/nesting.ts +51 -0
- package/src/core/render/context.ts +21 -0
- package/src/core/render/dynamic-post.ts +175 -0
- package/src/core/render/extras.ts +98 -0
- package/src/core/render/form.ts +235 -0
- package/src/core/render/index.ts +372 -0
- package/src/core/render/loop.ts +43 -0
- package/src/core/render/pagination.ts +76 -0
- package/src/core/render/section.ts +37 -0
- package/src/core/render/tabs.ts +76 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +771 -0
- package/src/core/sanitize/embed-url.ts +160 -0
- package/src/core/sanitize/escape.ts +10 -0
- package/src/core/sanitize/href.ts +6 -0
- package/src/core/sanitize/media-url.ts +7 -0
- package/src/core/sanitize/svg-upload.ts +203 -0
- package/src/core/sanitize/svg.ts +374 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +37 -0
- package/src/core/schema/design.ts +93 -0
- package/src/core/schema/layout.ts +1008 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +336 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +25 -0
- package/src/core/theme/conditions.ts +324 -0
- package/src/core/theme/dynamic.ts +143 -0
- package/src/core/theme/float.ts +113 -0
- package/src/core/theme/pagination.ts +97 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +81 -0
- package/src/core/theme/popup-markup.ts +41 -0
- package/src/core/theme/popup-rules.ts +62 -0
- package/src/core/theme/triggers.ts +104 -0
- package/src/core/tree-ops.ts +139 -0
- package/src/core/validate.ts +185 -0
- package/src/index.ts +18 -0
- package/src/server/design-routes.ts +125 -0
- package/src/server/hooks.ts +118 -0
- package/src/server/icon-routes.ts +79 -0
- package/src/server/plugin.ts +43 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { isSafeFontStack } from "../sanitize/css.ts";
|
|
3
|
+
import { sanitizeMediaUrl } from "../sanitize/media-url.ts";
|
|
4
|
+
import { POPUP_DEVICES } from "../theme/popup-rules.ts";
|
|
5
|
+
|
|
6
|
+
/** Colour refs omit `from` (legacy). Length/font refs set `from` (W-028). */
|
|
7
|
+
export const VariableRef = z.strictObject({
|
|
8
|
+
var: z.string().regex(/^[a-z0-9-]{1,40}$/),
|
|
9
|
+
from: z.enum(["color", "font", "fontSize", "spacing"]).optional(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const HEX_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
13
|
+
export const ColorValue = z.union([
|
|
14
|
+
z.string().regex(HEX_COLOR, "Use a hex color such as #1a2b3c"),
|
|
15
|
+
VariableRef,
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const LengthUnit = z.enum(["px", "rem", "em", "%", "vw", "vh"]);
|
|
19
|
+
|
|
20
|
+
export const Length = z.strictObject({
|
|
21
|
+
value: z.number().finite().min(0).max(10_000),
|
|
22
|
+
unit: LengthUnit,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/** Literal length or a fontSize/spacing variable reference. */
|
|
26
|
+
export const LengthValue = z.union([Length, VariableRef]);
|
|
27
|
+
|
|
28
|
+
/** Width, height and margins may also be `auto` (W-088). */
|
|
29
|
+
const SizeValue = z.union([Length, VariableRef, z.literal("auto")]);
|
|
30
|
+
|
|
31
|
+
/** Top, right, bottom and left may be negative, `auto` or a spacing variable (W-088). */
|
|
32
|
+
const OffsetValue = z.union([
|
|
33
|
+
z.strictObject({ value: z.number().finite().min(-10_000).max(10_000), unit: LengthUnit }),
|
|
34
|
+
VariableRef,
|
|
35
|
+
z.literal("auto"),
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
/** `w/h` with whole numbers 1–9999, emitted as `w / h` (W-088). */
|
|
39
|
+
const ASPECT_RATIO = /^[1-9]\d{0,3}\/[1-9]\d{0,3}$/;
|
|
40
|
+
|
|
41
|
+
const num = (min: number, max: number) => z.number().finite().min(min).max(max);
|
|
42
|
+
|
|
43
|
+
/** One box shadow in px (W-088). No colour means the text colour, as in CSS. */
|
|
44
|
+
const BoxShadow = z.strictObject({
|
|
45
|
+
x: num(-1000, 1000),
|
|
46
|
+
y: num(-1000, 1000),
|
|
47
|
+
blur: num(0, 1000),
|
|
48
|
+
spread: num(-1000, 1000),
|
|
49
|
+
color: ColorValue.optional(),
|
|
50
|
+
inset: z.boolean().optional(),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/** Filter functions, emitted in a fixed order; at least one is set (W-088). */
|
|
54
|
+
const Filter = z
|
|
55
|
+
.strictObject({
|
|
56
|
+
blur: num(0, 100).optional(),
|
|
57
|
+
brightness: num(0, 300).optional(),
|
|
58
|
+
contrast: num(0, 300).optional(),
|
|
59
|
+
saturate: num(0, 300).optional(),
|
|
60
|
+
grayscale: num(0, 100).optional(),
|
|
61
|
+
hueRotate: num(0, 360).optional(),
|
|
62
|
+
})
|
|
63
|
+
.refine(
|
|
64
|
+
(filter) => Object.values(filter).some((v) => v !== undefined),
|
|
65
|
+
"Set at least one filter",
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A simple transition (W-089, Normal only): one duration, delay and easing for a fixed property
|
|
70
|
+
* group. `colors` means color, background-color and border-color. No free-form lists or curves.
|
|
71
|
+
*/
|
|
72
|
+
const Transition = z.strictObject({
|
|
73
|
+
duration: z.number().int().min(0).max(2000),
|
|
74
|
+
delay: z.number().int().min(0).max(2000).optional(),
|
|
75
|
+
easing: z.enum(["ease", "ease-in", "ease-out", "ease-in-out", "linear"]),
|
|
76
|
+
property: z.enum(["all", "colors", "opacity", "shadow", "filter"]),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/** Style properties for layout and text elements (W-017 / R-012). Unknown keys are rejected. */
|
|
80
|
+
export const StyleProps = z.strictObject({
|
|
81
|
+
flexDirection: z.enum(["row", "column", "row-reverse", "column-reverse"]).optional(),
|
|
82
|
+
flexWrap: z.enum(["nowrap", "wrap", "wrap-reverse"]).optional(),
|
|
83
|
+
justifyContent: z
|
|
84
|
+
.enum(["flex-start", "flex-end", "center", "space-between", "space-around", "space-evenly"])
|
|
85
|
+
.optional(),
|
|
86
|
+
alignItems: z.enum(["stretch", "flex-start", "flex-end", "center", "baseline"]).optional(),
|
|
87
|
+
gap: LengthValue.optional(),
|
|
88
|
+
/** How many grid columns this element spans (1–12). */
|
|
89
|
+
gridColumnSpan: z.number().int().min(1).max(12).optional(),
|
|
90
|
+
/** How many grid rows this element spans (1–12). */
|
|
91
|
+
gridRowSpan: z.number().int().min(1).max(12).optional(),
|
|
92
|
+
width: SizeValue.optional(),
|
|
93
|
+
minWidth: LengthValue.optional(),
|
|
94
|
+
maxWidth: LengthValue.optional(),
|
|
95
|
+
height: SizeValue.optional(),
|
|
96
|
+
minHeight: LengthValue.optional(),
|
|
97
|
+
maxHeight: LengthValue.optional(),
|
|
98
|
+
overflow: z.enum(["visible", "hidden", "clip", "scroll", "auto"]).optional(),
|
|
99
|
+
aspectRatio: z
|
|
100
|
+
.union([z.literal("auto"), z.string().regex(ASPECT_RATIO, "Use a ratio such as 16/9")])
|
|
101
|
+
.optional(),
|
|
102
|
+
objectFit: z.enum(["fill", "contain", "cover", "none", "scale-down"]).optional(),
|
|
103
|
+
paddingTop: LengthValue.optional(),
|
|
104
|
+
paddingRight: LengthValue.optional(),
|
|
105
|
+
paddingBottom: LengthValue.optional(),
|
|
106
|
+
paddingLeft: LengthValue.optional(),
|
|
107
|
+
marginTop: SizeValue.optional(),
|
|
108
|
+
marginRight: SizeValue.optional(),
|
|
109
|
+
marginBottom: SizeValue.optional(),
|
|
110
|
+
marginLeft: SizeValue.optional(),
|
|
111
|
+
position: z.enum(["static", "relative", "absolute", "fixed", "sticky"]).optional(),
|
|
112
|
+
top: OffsetValue.optional(),
|
|
113
|
+
right: OffsetValue.optional(),
|
|
114
|
+
bottom: OffsetValue.optional(),
|
|
115
|
+
left: OffsetValue.optional(),
|
|
116
|
+
zIndex: z.number().int().min(-9999).max(9999).optional(),
|
|
117
|
+
fontFamily: z
|
|
118
|
+
.union([
|
|
119
|
+
z.string().min(1).max(200).refine(isSafeFontStack, "Font stack looks unsafe."),
|
|
120
|
+
VariableRef,
|
|
121
|
+
])
|
|
122
|
+
.optional(),
|
|
123
|
+
fontSize: LengthValue.optional(),
|
|
124
|
+
/** W-213: any weight 100–900 in steps of 100 (the font must ship it to look different). */
|
|
125
|
+
fontWeight: z
|
|
126
|
+
.union([
|
|
127
|
+
z.literal(100),
|
|
128
|
+
z.literal(200),
|
|
129
|
+
z.literal(300),
|
|
130
|
+
z.literal(400),
|
|
131
|
+
z.literal(500),
|
|
132
|
+
z.literal(600),
|
|
133
|
+
z.literal(700),
|
|
134
|
+
z.literal(800),
|
|
135
|
+
z.literal(900),
|
|
136
|
+
z.enum(["normal", "bold"]),
|
|
137
|
+
])
|
|
138
|
+
.optional(),
|
|
139
|
+
/** W-213: also a plain number (unitless, 0–100), which scales with each child's font size. */
|
|
140
|
+
lineHeight: z.union([Length, VariableRef, z.number().finite().min(0).max(100)]).optional(),
|
|
141
|
+
/** W-213: may be negative, for tight display headings. */
|
|
142
|
+
letterSpacing: z
|
|
143
|
+
.union([
|
|
144
|
+
z.strictObject({ value: z.number().finite().min(-10_000).max(10_000), unit: LengthUnit }),
|
|
145
|
+
VariableRef,
|
|
146
|
+
])
|
|
147
|
+
.optional(),
|
|
148
|
+
textAlign: z.enum(["left", "center", "right", "justify"]).optional(),
|
|
149
|
+
textTransform: z.enum(["none", "uppercase", "lowercase", "capitalize"]).optional(),
|
|
150
|
+
/** W-113. A button sets `none` in its base CSS, so it is not underlined unless a style says so. */
|
|
151
|
+
textDecoration: z.enum(["none", "underline", "overline", "line-through"]).optional(),
|
|
152
|
+
color: ColorValue.optional(),
|
|
153
|
+
backgroundColor: ColorValue.optional(),
|
|
154
|
+
/** http(s) or a site path. Spaces, quotes and parentheses are refused so the URL can sit inside `url("")`. */
|
|
155
|
+
backgroundImage: z
|
|
156
|
+
.string()
|
|
157
|
+
.min(1)
|
|
158
|
+
.max(2000)
|
|
159
|
+
.refine(
|
|
160
|
+
(value) => sanitizeMediaUrl(value) === value && !/[()\\\s"'`]/.test(value),
|
|
161
|
+
"Use an http(s) URL or a site path, with no spaces or parentheses",
|
|
162
|
+
)
|
|
163
|
+
.optional(),
|
|
164
|
+
backgroundSize: z.enum(["auto", "cover", "contain"]).optional(),
|
|
165
|
+
backgroundPosition: z
|
|
166
|
+
.enum([
|
|
167
|
+
"center",
|
|
168
|
+
"top",
|
|
169
|
+
"bottom",
|
|
170
|
+
"left",
|
|
171
|
+
"right",
|
|
172
|
+
"top left",
|
|
173
|
+
"top right",
|
|
174
|
+
"bottom left",
|
|
175
|
+
"bottom right",
|
|
176
|
+
])
|
|
177
|
+
.optional(),
|
|
178
|
+
backgroundRepeat: z.enum(["no-repeat", "repeat", "repeat-x", "repeat-y"]).optional(),
|
|
179
|
+
/** Video behind the element. Same URL rules as a background image (W-110). */
|
|
180
|
+
backgroundVideo: z
|
|
181
|
+
.string()
|
|
182
|
+
.min(1)
|
|
183
|
+
.max(2000)
|
|
184
|
+
.refine(
|
|
185
|
+
(value) => sanitizeMediaUrl(value) === value && !/[()\\\s"'`]/.test(value),
|
|
186
|
+
"Use an http(s) URL or a site path, with no spaces or parentheses",
|
|
187
|
+
)
|
|
188
|
+
.optional(),
|
|
189
|
+
/**
|
|
190
|
+
* Background gradient (W-160). Up to 10 stops. `angle` is the linear direction and the conic
|
|
191
|
+
* start; `position` is the radial centre. A stop colour variable is a colour use.
|
|
192
|
+
*/
|
|
193
|
+
gradient: z
|
|
194
|
+
.strictObject({
|
|
195
|
+
type: z.enum(["linear", "radial", "conic"]),
|
|
196
|
+
angle: z.number().int().min(0).max(360).optional(),
|
|
197
|
+
position: z
|
|
198
|
+
.enum([
|
|
199
|
+
"center",
|
|
200
|
+
"top",
|
|
201
|
+
"bottom",
|
|
202
|
+
"left",
|
|
203
|
+
"right",
|
|
204
|
+
"top left",
|
|
205
|
+
"top right",
|
|
206
|
+
"bottom left",
|
|
207
|
+
"bottom right",
|
|
208
|
+
])
|
|
209
|
+
.optional(),
|
|
210
|
+
stops: z
|
|
211
|
+
.array(
|
|
212
|
+
z.strictObject({
|
|
213
|
+
color: ColorValue,
|
|
214
|
+
at: z.number().int().min(0).max(100),
|
|
215
|
+
}),
|
|
216
|
+
)
|
|
217
|
+
.min(2)
|
|
218
|
+
.max(10),
|
|
219
|
+
})
|
|
220
|
+
.optional(),
|
|
221
|
+
/** A colour laid over the image and gradient. `opacity` is 0–1 (W-094). */
|
|
222
|
+
overlay: z
|
|
223
|
+
.strictObject({
|
|
224
|
+
color: ColorValue,
|
|
225
|
+
opacity: z.number().finite().min(0).max(1),
|
|
226
|
+
})
|
|
227
|
+
.optional(),
|
|
228
|
+
borderWidth: LengthValue.optional(),
|
|
229
|
+
/** Per-side widths (W-138, D-044), after `borderWidth`, so a side beats the all-sides value. */
|
|
230
|
+
borderTopWidth: LengthValue.optional(),
|
|
231
|
+
borderRightWidth: LengthValue.optional(),
|
|
232
|
+
borderBottomWidth: LengthValue.optional(),
|
|
233
|
+
borderLeftWidth: LengthValue.optional(),
|
|
234
|
+
borderStyle: z.enum(["none", "solid", "dashed", "dotted"]).optional(),
|
|
235
|
+
borderColor: ColorValue.optional(),
|
|
236
|
+
borderRadius: LengthValue.optional(),
|
|
237
|
+
/** Per-corner radii (W-138, D-044), after `borderRadius`. */
|
|
238
|
+
borderTopLeftRadius: LengthValue.optional(),
|
|
239
|
+
borderTopRightRadius: LengthValue.optional(),
|
|
240
|
+
borderBottomRightRadius: LengthValue.optional(),
|
|
241
|
+
borderBottomLeftRadius: LengthValue.optional(),
|
|
242
|
+
opacity: z.number().finite().min(0).max(1).optional(),
|
|
243
|
+
boxShadow: BoxShadow.optional(),
|
|
244
|
+
filter: Filter.optional(),
|
|
245
|
+
cursor: z
|
|
246
|
+
.enum([
|
|
247
|
+
"default",
|
|
248
|
+
"pointer",
|
|
249
|
+
"text",
|
|
250
|
+
"move",
|
|
251
|
+
"grab",
|
|
252
|
+
"not-allowed",
|
|
253
|
+
"help",
|
|
254
|
+
"crosshair",
|
|
255
|
+
"zoom-in",
|
|
256
|
+
])
|
|
257
|
+
.optional(),
|
|
258
|
+
transition: Transition.optional(),
|
|
259
|
+
/**
|
|
260
|
+
* Icon element glyph styling (W-237). Emitted as custom properties on the icon's wrapper, so
|
|
261
|
+
* they work in states, devices and classes; the Icon's base CSS applies them to its `<svg>`.
|
|
262
|
+
* Elsewhere they do nothing. `iconScale` scales the whole icon (with its background shape).
|
|
263
|
+
*/
|
|
264
|
+
iconRotate: z.number().int().min(-360).max(360).optional(),
|
|
265
|
+
iconFlip: z.enum(["none", "horizontal", "vertical", "both"]).optional(),
|
|
266
|
+
iconScale: num(0.1, 4).optional(),
|
|
267
|
+
iconStrokeWidth: num(0.25, 6).optional(),
|
|
268
|
+
/** A drop shadow that follows the glyph's shape (CSS `drop-shadow`), in px. */
|
|
269
|
+
iconShadow: z
|
|
270
|
+
.strictObject({
|
|
271
|
+
x: num(-100, 100),
|
|
272
|
+
y: num(-100, 100),
|
|
273
|
+
blur: num(0, 100),
|
|
274
|
+
color: ColorValue.optional(),
|
|
275
|
+
})
|
|
276
|
+
.optional(),
|
|
277
|
+
/**
|
|
278
|
+
* A looping spin or pulse; off for visitors who prefer reduced motion. `{ type: "none" }`
|
|
279
|
+
* (W-248) stops an animation a device would otherwise inherit from a wider one.
|
|
280
|
+
*/
|
|
281
|
+
iconAnimation: z
|
|
282
|
+
.union([
|
|
283
|
+
z.strictObject({
|
|
284
|
+
type: z.enum(["spin", "pulse"]),
|
|
285
|
+
duration: z.number().int().min(200).max(10_000),
|
|
286
|
+
}),
|
|
287
|
+
z.strictObject({ type: z.literal("none") }),
|
|
288
|
+
])
|
|
289
|
+
.optional(),
|
|
290
|
+
/**
|
|
291
|
+
* Plays once (W-101, W-107). `delay` waits before it starts. `view` starts as the element
|
|
292
|
+
* scrolls into view, using CSS scroll-driven animations, and falls back to playing on load.
|
|
293
|
+
* Not a state style.
|
|
294
|
+
*/
|
|
295
|
+
entrance: z
|
|
296
|
+
.strictObject({
|
|
297
|
+
type: z.enum(["fade", "fade-up", "fade-down", "slide-up", "slide-down", "scale"]),
|
|
298
|
+
duration: z.number().int().min(0).max(2000),
|
|
299
|
+
delay: z.number().int().min(0).max(2000).optional(),
|
|
300
|
+
trigger: z.enum(["load", "view"]).optional(),
|
|
301
|
+
})
|
|
302
|
+
.optional(),
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
export type StyleProps = z.infer<typeof StyleProps>;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* `states` on a node or class (D-032, W-089): hover, focus (`:focus-visible`) and active, each with
|
|
309
|
+
* the same keys and limits as `style` except `transition`, `entrance` and `iconAnimation`. Unknown
|
|
310
|
+
* states are refused.
|
|
311
|
+
*/
|
|
312
|
+
const StateStyle = StyleProps.omit({ transition: true, entrance: true, iconAnimation: true });
|
|
313
|
+
|
|
314
|
+
export const StyleStates = z.strictObject({
|
|
315
|
+
hover: StateStyle.optional(),
|
|
316
|
+
focus: StateStyle.optional(),
|
|
317
|
+
active: StateStyle.optional(),
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
export type StyleStates = z.infer<typeof StyleStates>;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Tablet and mobile overrides (W-096). Desktop is the element's `style`. Only keys that differ
|
|
324
|
+
* are stored. A phone matches both media queries, so mobile wins over tablet for the same key.
|
|
325
|
+
*/
|
|
326
|
+
export const DeviceStyles = z.strictObject({
|
|
327
|
+
tablet: StyleProps.optional(),
|
|
328
|
+
mobile: StyleProps.optional(),
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
export type DeviceStyles = z.infer<typeof DeviceStyles>;
|
|
332
|
+
|
|
333
|
+
/** Devices on which the element is `display: none`. Empty means shown everywhere. */
|
|
334
|
+
export const HiddenOn = z.array(z.enum(POPUP_DEVICES)).max(3);
|
|
335
|
+
|
|
336
|
+
export type HiddenOn = z.infer<typeof HiddenOn>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type LayoutSummary = { nodes: number; schemaVersion: number | undefined };
|
|
2
|
+
|
|
3
|
+
/** Counts nodes without trusting the input shape (used for read-only summaries). */
|
|
4
|
+
export function summarizeLayout(input: unknown): LayoutSummary | undefined {
|
|
5
|
+
if (typeof input !== "object" || input === null) return undefined;
|
|
6
|
+
const doc = input as { schemaVersion?: unknown; root?: unknown };
|
|
7
|
+
const schemaVersion = typeof doc.schemaVersion === "number" ? doc.schemaVersion : undefined;
|
|
8
|
+
let nodes = 0;
|
|
9
|
+
const stack: unknown[] = doc.root === undefined ? [] : [doc.root];
|
|
10
|
+
while (stack.length > 0 && nodes <= 100_000) {
|
|
11
|
+
const node = stack.pop();
|
|
12
|
+
if (typeof node !== "object" || node === null) continue;
|
|
13
|
+
nodes++;
|
|
14
|
+
const children = (node as { children?: unknown }).children;
|
|
15
|
+
if (Array.isArray(children)) stack.push(...children);
|
|
16
|
+
}
|
|
17
|
+
return { nodes, schemaVersion };
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isTabsNode, type Layout, type LayoutNode } from "../schema/layout.ts";
|
|
2
|
+
import { nodeChildren } from "../tree-ops.ts";
|
|
3
|
+
|
|
4
|
+
function walk(node: LayoutNode, visit: (node: LayoutNode) => void): void {
|
|
5
|
+
visit(node);
|
|
6
|
+
for (const child of nodeChildren(node)) walk(child, visit);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** True when the layout includes at least one Tabs element (optional public runtime). */
|
|
10
|
+
export function layoutHasTabs(layout: Layout): boolean {
|
|
11
|
+
let found = false;
|
|
12
|
+
walk(layout.root, (node) => {
|
|
13
|
+
if (isTabsNode(node)) found = true;
|
|
14
|
+
});
|
|
15
|
+
return found;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A Menu with a dropdown, so hosts load the Escape-to-close menu script (W-197). */
|
|
19
|
+
export function layoutHasMenuDropdown(layout: Layout): boolean {
|
|
20
|
+
let found = false;
|
|
21
|
+
walk(layout.root, (node) => {
|
|
22
|
+
if (node.type === "menu-item" && nodeChildren(node).length > 0) found = true;
|
|
23
|
+
});
|
|
24
|
+
return found;
|
|
25
|
+
}
|