@perkyzz/emvb 1.3.0 → 1.4.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 +2 -2
- package/package.json +2 -2
- package/src/admin/bulk-api.ts +5 -1
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +22 -2
- package/src/admin/editor/Timeline.tsx +1 -8
- package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
- package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
- package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
- package/src/admin/editor/canvas/vnode-react.tsx +2 -0
- package/src/admin/editor/co-design.ts +36 -1
- package/src/admin/editor/dnd/dragged-source.ts +22 -0
- package/src/admin/editor/dnd/layer-drop.ts +141 -0
- package/src/admin/editor/dnd/new-element.ts +16 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +6 -0
- package/src/admin/editor/feature-css.ts +22 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/FontFaces.tsx +342 -0
- package/src/admin/editor/panels/LayersPanel.tsx +56 -6
- package/src/admin/editor/panels/LeftPanel.tsx +153 -29
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
- package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
- package/src/admin/editor/panels/TokenScales.tsx +2 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
- package/src/admin/editor/panels/VariableSection.tsx +111 -7
- package/src/admin/editor/panels/color-space.ts +71 -6
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +18 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
- package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
- package/src/admin/editor/panels/settings/style-sections.ts +19 -2
- package/src/admin/editor/panels/url-rules.ts +43 -0
- package/src/admin/editor/panels/use-layers-drop.ts +232 -0
- package/src/admin/editor/store.ts +4 -2
- package/src/admin/editor/useExtensions.ts +3 -1
- package/src/admin/editor/useNodeActions.ts +74 -1
- package/src/admin/editor/useSave.ts +116 -85
- package/src/admin/export-api.ts +25 -2
- package/src/admin/extension-outputs.ts +179 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +22 -188
- package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
- package/src/admin/pages/ImportImageCopies.tsx +167 -0
- package/src/admin/pages/ImportReport.tsx +63 -0
- package/src/admin/pages/NewPageDialog.tsx +54 -32
- package/src/admin/pages/PageList.tsx +9 -0
- package/src/admin/pages/ThemePartList.tsx +9 -0
- package/src/astro/EmVBPage.astro +5 -2
- package/src/astro/extension-styles.ts +35 -0
- package/src/astro/forms/EmVBFormsClient.astro +3 -0
- package/src/astro/forms/enhance.ts +107 -0
- package/src/astro/popups/runtime.ts +47 -2
- package/src/astro/render.ts +19 -4
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +18 -7
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +14 -5
- package/src/astro/widgets/sticky.ts +87 -0
- package/src/astro/widgets/theme.ts +52 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +150 -2
- package/src/core/arrange.ts +19 -1
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +35 -1
- package/src/core/elements/form-elements.ts +119 -9
- package/src/core/elements/icon-svg.ts +14 -0
- package/src/core/elements/index.ts +24 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +13 -3
- package/src/core/export/runtimes.generated.ts +7 -5
- package/src/core/export/site.ts +50 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +17 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +66 -21
- package/src/core/extensions/safe-nodes.ts +67 -11
- package/src/core/extensions/types.ts +48 -1
- package/src/core/fonts/files.ts +74 -0
- package/src/core/fonts/google.ts +112 -0
- package/src/core/fonts/test-font.ts +9 -0
- package/src/core/import/elementor/context.ts +13 -4
- package/src/core/import/elementor/index.ts +32 -21
- package/src/core/import/elementor/widgets.ts +114 -12
- package/src/core/import/html/blocks.ts +602 -0
- package/src/core/import/html/index.ts +155 -0
- package/src/core/import/html/map.ts +958 -0
- package/src/core/import/html/parse.ts +430 -0
- package/src/core/index.ts +45 -0
- package/src/core/migrate/v18.ts +3 -0
- package/src/core/public-attributes.ts +17 -0
- package/src/core/render/extras.ts +31 -7
- package/src/core/render/form.ts +103 -10
- package/src/core/render/index.ts +151 -15
- package/src/core/render/section.ts +31 -1
- package/src/core/render/spacer-basis.ts +102 -0
- package/src/core/render/theme-boot.ts +16 -0
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +68 -3
- package/src/core/sanitize/motion.ts +12 -0
- package/src/core/schema/design.ts +40 -0
- package/src/core/schema/layout.ts +114 -5
- package/src/core/schema/style.ts +28 -0
- package/src/core/templates/index.ts +218 -0
- package/src/core/templates/pages.ts +29 -0
- package/src/core/templates/sections.ts +794 -0
- package/src/core/templates/types.ts +9 -0
- package/src/core/theme/dynamic.ts +9 -6
- package/src/core/theme/popup-markup.ts +21 -2
- package/src/core/theme/popup-rules.ts +36 -0
- package/src/core/theme/triggers.ts +64 -5
- package/src/core/translatable.ts +5 -2
- package/src/extension-build.ts +331 -0
- package/src/index.ts +25 -3
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +29 -1
- package/src/mcp/tools.ts +40 -1
- package/src/mcp/write.ts +41 -1
- package/src/server/extension-routes.ts +73 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +9 -0
package/src/core/a11y/audit.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { DesignSystem } from "../schema/design.ts";
|
|
|
4
4
|
import { isParentNode, type Layout, type LayoutNode } from "../schema/layout.ts";
|
|
5
5
|
import { boxBecomesLink } from "../render/extras.ts";
|
|
6
6
|
import { ICON_ANIMATION_LIMIT_MS, iconAnimationRuns } from "../icons/animation-runs.ts";
|
|
7
|
-
import { updateNode } from "../tree-ops.ts";
|
|
7
|
+
import { someNode, updateNode } from "../tree-ops.ts";
|
|
8
8
|
import { DEVICES } from "../theme/popup-rules.ts";
|
|
9
9
|
import { hiddenOnEveryDevice } from "../design/devices.ts";
|
|
10
10
|
import { sanitizeHref } from "../sanitize/href.ts";
|
|
@@ -46,7 +46,12 @@ export type A11yIssue = {
|
|
|
46
46
|
| "landmark-name"
|
|
47
47
|
| "motion"
|
|
48
48
|
| "empty-alert"
|
|
49
|
-
| "counter-title"
|
|
49
|
+
| "counter-title"
|
|
50
|
+
| "flip-box-face"
|
|
51
|
+
| "countdown-title"
|
|
52
|
+
| "hotspot-names"
|
|
53
|
+
| "mega-panel"
|
|
54
|
+
| "form-steps";
|
|
50
55
|
severity: "error" | "warning";
|
|
51
56
|
message: string;
|
|
52
57
|
/** The one-click fix, when there is a safe one. */
|
|
@@ -130,6 +135,7 @@ const TEXT_TYPES = new Set([
|
|
|
130
135
|
"post-excerpt",
|
|
131
136
|
]);
|
|
132
137
|
const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "radio"]);
|
|
138
|
+
const isStep = (node: LayoutNode) => node.type === "form-step";
|
|
133
139
|
const LINKISH = new Set(["link", "button", "menu-item"]);
|
|
134
140
|
|
|
135
141
|
function px(value: unknown, design?: DesignSystem): number | undefined {
|
|
@@ -259,6 +265,10 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
259
265
|
let fade = 1;
|
|
260
266
|
// W-445: per device, like H1s, so a desktop menu and a mobile menu may share a name.
|
|
261
267
|
const menuNames = DEVICES.map(() => new Set<string>());
|
|
268
|
+
// W-1076: carousels are regions, listed by name like menus.
|
|
269
|
+
const carouselNames = DEVICES.map(() => new Set<string>());
|
|
270
|
+
// W-1069: inside a menu item's dropdown, where a mega panel would open from a flyout.
|
|
271
|
+
let inDropdown = false;
|
|
262
272
|
const walk = (node: LayoutNode, bg: string | undefined, color: string | undefined): void => {
|
|
263
273
|
// W-413: an element hidden on every device (and what's inside it) is never shown or read.
|
|
264
274
|
if (node !== layout.root && hiddenOnEveryDevice(node)) {
|
|
@@ -581,6 +591,119 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
581
591
|
'This counter has no title, so its number doesn\'t say what it counts. Add a title such as "Happy clients".',
|
|
582
592
|
});
|
|
583
593
|
}
|
|
594
|
+
// W-1076: screen readers list carousels as regions by name; two with one name sound the same.
|
|
595
|
+
if (node.type === "carousel") {
|
|
596
|
+
const name = spoken(props["label"]) || "Carousel";
|
|
597
|
+
const key = name.toLowerCase();
|
|
598
|
+
if (carouselNames.some((names, i) => shownOn[i] && names.has(key))) {
|
|
599
|
+
add({
|
|
600
|
+
nodeId: node.id,
|
|
601
|
+
rule: "landmark-name",
|
|
602
|
+
severity: "warning",
|
|
603
|
+
message: `Another carousel on this page is also named "${name}"; give each carousel its own name, such as "Customer stories".`,
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
carouselNames.forEach((listed, i) => {
|
|
607
|
+
if (shownOn[i]) listed.add(key);
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
// W-1076: a Flip box's faces are headings and text; an empty one turns over to nothing.
|
|
611
|
+
if (node.type === "flip-box" && !node.bind) {
|
|
612
|
+
if (!spoken(props["frontTitle"])) {
|
|
613
|
+
add({
|
|
614
|
+
nodeId: node.id,
|
|
615
|
+
rule: "flip-box-face",
|
|
616
|
+
severity: "warning",
|
|
617
|
+
message:
|
|
618
|
+
"This flip box's front has no title, so its heading is empty. Add a front title.",
|
|
619
|
+
});
|
|
620
|
+
} else if (
|
|
621
|
+
!spoken(props["backTitle"]) &&
|
|
622
|
+
!spoken(props["backText"]) &&
|
|
623
|
+
!spoken(props["buttonText"])
|
|
624
|
+
) {
|
|
625
|
+
add({
|
|
626
|
+
nodeId: node.id,
|
|
627
|
+
rule: "flip-box-face",
|
|
628
|
+
severity: "warning",
|
|
629
|
+
message:
|
|
630
|
+
"This flip box's back is empty, so turning it over shows nothing. Add a back title, text or button.",
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
// The back's button is a link: with no address it can use, the page leaves it out.
|
|
634
|
+
const href = typeof props["href"] === "string" ? props["href"].trim() : "";
|
|
635
|
+
if (spoken(props["buttonText"]) && (!href || !sanitizeHref(href))) {
|
|
636
|
+
add({
|
|
637
|
+
nodeId: node.id,
|
|
638
|
+
rule: "link-name",
|
|
639
|
+
severity: "warning",
|
|
640
|
+
message:
|
|
641
|
+
"This flip box's button has no link it can use, so the page leaves the button out. Add a button link, or clear the button text.",
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
// W-1076: "Ends 1 Dec 2026" alone doesn't say what ends.
|
|
646
|
+
if (node.type === "countdown" && !spoken(props["title"]) && !node.bind) {
|
|
647
|
+
add({
|
|
648
|
+
nodeId: node.id,
|
|
649
|
+
rule: "countdown-title",
|
|
650
|
+
severity: "warning",
|
|
651
|
+
message:
|
|
652
|
+
'This countdown has no title, so its date doesn\'t say what ends. Add a title such as "Launch sale".',
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
// W-1076: each marker is a button named by its title; two alike can't be told apart.
|
|
656
|
+
if (node.type === "hotspots" && isParentNode(node)) {
|
|
657
|
+
const seen = new Set<string>();
|
|
658
|
+
for (const marker of node.children) {
|
|
659
|
+
const title = spoken((marker.props as Record<string, unknown>)["title"]).toLowerCase();
|
|
660
|
+
if (title && seen.has(title)) {
|
|
661
|
+
add({
|
|
662
|
+
nodeId: marker.id,
|
|
663
|
+
rule: "hotspot-names",
|
|
664
|
+
severity: "warning",
|
|
665
|
+
message: `Another marker on this picture is also called "${spoken((marker.props as Record<string, unknown>)["title"])}"; screen readers can't tell them apart. Give each its own title.`,
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
seen.add(title);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
// W-1065: a form with steps shows one step at a time; each is read out by its title.
|
|
672
|
+
if (node.type === "form" && isParentNode(node) && node.children.some(isStep)) {
|
|
673
|
+
let place = 0;
|
|
674
|
+
for (const child of node.children) {
|
|
675
|
+
if (!isStep(child)) {
|
|
676
|
+
if (someNode(child, (n) => FIELD_TYPES.has(n.type))) {
|
|
677
|
+
add({
|
|
678
|
+
nodeId: child.id,
|
|
679
|
+
rule: "form-steps",
|
|
680
|
+
severity: "warning",
|
|
681
|
+
message:
|
|
682
|
+
"This field is outside the form's steps, so it shows on every step and isn't checked before Next. Move it into a step.",
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
place += 1;
|
|
688
|
+
const title = spoken((child.props as Record<string, unknown>)["title"]);
|
|
689
|
+
if (!title && !child.bind) {
|
|
690
|
+
add({
|
|
691
|
+
nodeId: child.id,
|
|
692
|
+
rule: "form-steps",
|
|
693
|
+
severity: "warning",
|
|
694
|
+
message: `This form step has no title, so screen readers only hear "Step ${place}". Give it a title, such as "Your details".`,
|
|
695
|
+
});
|
|
696
|
+
} else if (!someNode(child, (n) => FIELD_TYPES.has(n.type))) {
|
|
697
|
+
add({
|
|
698
|
+
nodeId: child.id,
|
|
699
|
+
rule: "form-steps",
|
|
700
|
+
severity: "warning",
|
|
701
|
+
message:
|
|
702
|
+
"This form step has no fields, so Next opens an empty step. Add fields or remove it.",
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
584
707
|
// W-419: an empty heading still shows up in screen readers' heading list, with nothing to say.
|
|
585
708
|
if (node.type === "heading" && !spoken(props["text"]) && !node.bind) {
|
|
586
709
|
add({
|
|
@@ -626,6 +749,28 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
626
749
|
message: "This box is a link, but nothing inside it has text, so the link has no name.",
|
|
627
750
|
});
|
|
628
751
|
}
|
|
752
|
+
// W-1069: a mega panel's toggle is named by its item's text ("Open Products", or the text
|
|
753
|
+
// itself), so a vague one says nothing about what opens; and one in a dropdown is a whole
|
|
754
|
+
// layout opened from a flyout, two disclosures deep for keyboard and screen reader users.
|
|
755
|
+
if (node.type === "menu-item" && spoken(props["panelPartId"])) {
|
|
756
|
+
const text = spoken(props["text"]);
|
|
757
|
+
if (inDropdown) {
|
|
758
|
+
add({
|
|
759
|
+
nodeId: node.id,
|
|
760
|
+
rule: "mega-panel",
|
|
761
|
+
severity: "warning",
|
|
762
|
+
message:
|
|
763
|
+
"This mega panel opens from inside another dropdown; put the item straight in the Menu so it opens from the menu bar.",
|
|
764
|
+
});
|
|
765
|
+
} else if (text && VAGUE.test(text)) {
|
|
766
|
+
add({
|
|
767
|
+
nodeId: node.id,
|
|
768
|
+
rule: "mega-panel",
|
|
769
|
+
severity: "warning",
|
|
770
|
+
message: `"${text}" doesn't say what this item's panel holds; name it for its contents, such as "Products".`,
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
}
|
|
629
774
|
if (LINKISH.has(node.type) || (node.type === "icon" && props["href"])) {
|
|
630
775
|
const text = spoken(props["text"] ?? props["title"]);
|
|
631
776
|
const hasHref = typeof props["href"] === "string" && props["href"].trim() !== "";
|
|
@@ -717,9 +862,12 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
717
862
|
});
|
|
718
863
|
}
|
|
719
864
|
const outerHidden = ariaHiddenAbove;
|
|
865
|
+
const outerDropdown = inDropdown;
|
|
720
866
|
if (ownAriaHidden) ariaHiddenAbove = true;
|
|
867
|
+
if (node.type === "menu-item") inDropdown = true;
|
|
721
868
|
if (isParentNode(node)) for (const child of node.children) walk(child, nextBg, nextColor);
|
|
722
869
|
ariaHiddenAbove = outerHidden;
|
|
870
|
+
inDropdown = outerDropdown;
|
|
723
871
|
};
|
|
724
872
|
walk(layout.root, undefined, undefined);
|
|
725
873
|
if (h1s.every((count) => count === 0) && layout.root.children.length > 0) {
|
package/src/core/arrange.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
newNodeId,
|
|
29
29
|
nodeChildren,
|
|
30
30
|
removeNode,
|
|
31
|
+
someNode,
|
|
31
32
|
starterLayout,
|
|
32
33
|
updateNode,
|
|
33
34
|
} from "./tree-ops.ts";
|
|
@@ -66,7 +67,9 @@ export const REASONS = {
|
|
|
66
67
|
top: "It's already at the top level.",
|
|
67
68
|
noContainerAbove: "There's no container just above it to move into.",
|
|
68
69
|
nestedForm: "A form can't go inside another form.",
|
|
70
|
+
searchInForm: "A Search form can't go inside a form.",
|
|
69
71
|
fieldOutsideForm: "Form fields must be placed inside a form.",
|
|
72
|
+
stepOutsideForm: "Form steps can only go directly inside a form.",
|
|
70
73
|
formIntoField: "A form can only go inside a layout container.",
|
|
71
74
|
tabOutsideTabs: "Tab panels can only go inside Tabs.",
|
|
72
75
|
onlyTabPanels: "Tabs can only hold tab panels.",
|
|
@@ -204,7 +207,11 @@ export function parentChildRefusal(
|
|
|
204
207
|
}
|
|
205
208
|
if (parent.type === "hotspots" && child.type !== "hotspot") return REASONS.onlyHotspots;
|
|
206
209
|
if (isFormNode(child) && inForm) return REASONS.nestedForm;
|
|
210
|
+
// W-1073: a Search form is a <form> too; inside a form its button sent that form.
|
|
211
|
+
if (child.type === "search-form" && inForm) return REASONS.searchInForm;
|
|
207
212
|
if (isFormFieldType(child.type) && !inForm) return REASONS.fieldOutsideForm;
|
|
213
|
+
// W-1065: the forms script pages through the form's own steps; a nested one would never show.
|
|
214
|
+
if (child.type === "form-step" && !isFormNode(parent)) return REASONS.stepOutsideForm;
|
|
208
215
|
return undefined;
|
|
209
216
|
}
|
|
210
217
|
|
|
@@ -295,8 +302,19 @@ export function canDrop(layout: Layout, source: DragSource, parentId: string): A
|
|
|
295
302
|
const moving = dragged(layout, source, parentId);
|
|
296
303
|
if (!moving.ok) return moving;
|
|
297
304
|
if (!isParentNode(into.node)) return refuse(REASONS.notContainer);
|
|
298
|
-
const
|
|
305
|
+
const inForm = underForm(layout, into.node.id);
|
|
306
|
+
const placed = parentChildRefusal(into.node, moving.node, inForm);
|
|
299
307
|
if (placed) return refuse(placed);
|
|
308
|
+
// A box holding a form or Search form can't go into a form either: the save would refuse it.
|
|
309
|
+
if (inForm) {
|
|
310
|
+
const inner = nodeChildren(moving.node).find((child) =>
|
|
311
|
+
someNode(child, (n) => isFormNode(n) || n.type === "search-form"),
|
|
312
|
+
);
|
|
313
|
+
if (inner) {
|
|
314
|
+
const nested = someNode(inner, isFormNode);
|
|
315
|
+
return refuse(nested ? REASONS.nestedForm : REASONS.searchInForm);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
300
318
|
const drop: Drop = { layout, node: moving.node, into, isNew: source.kind === "new" };
|
|
301
319
|
const broken = DROP_RULES.find(([breaks]) => breaks(drop));
|
|
302
320
|
return broken ? refuse(broken[1]) : { ok: true };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { FONT_FAMILY_NAME, UNICODE_RANGE } from "../schema/design.ts";
|
|
2
|
+
import type { FontFace, FontVariable } from "../schema/design.ts";
|
|
3
|
+
import { fontVariableName } from "../sanitize/css.ts";
|
|
4
|
+
import { sanitizeMediaUrl } from "../sanitize/media-url.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* W-1072: the characters a font file URL may hold in the emitted CSS. A URL that passes the media
|
|
8
|
+
* URL check may still hold braces, parentheses, `;` or spaces, which are harmless inside a quoted
|
|
9
|
+
* `url("…")` but would confuse the scoping pass, so those URLs are left out.
|
|
10
|
+
*/
|
|
11
|
+
const SRC_CHARS = /^[A-Za-z0-9\-._~:/?#[\]@!$&*+,=%]+$/;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A font file URL safe to write in `url("…")`, or undefined. Only a path on the site itself
|
|
15
|
+
* (`/…`, never `//host`): a page must not ask Google Fonts or any other host for a font, even when
|
|
16
|
+
* a design was edited by hand, imported or written by an agent.
|
|
17
|
+
*/
|
|
18
|
+
export function fontFaceSrc(src: string): string | undefined {
|
|
19
|
+
const url = sanitizeMediaUrl(src);
|
|
20
|
+
if (!url?.startsWith("/") || url.startsWith("//")) return undefined;
|
|
21
|
+
return SRC_CHARS.test(url) ? url : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A double-quoted CSS string. Letters, digits, spaces, `_`, `.` and `-` stay as they are; any
|
|
26
|
+
* other character (a quote, a backslash, a newline, `<`) is written as a hex escape.
|
|
27
|
+
*/
|
|
28
|
+
export function cssString(value: string): string {
|
|
29
|
+
let out = "";
|
|
30
|
+
for (const ch of value) {
|
|
31
|
+
out += /^[\p{L}\p{N} _.-]$/u.test(ch) ? ch : `\\${(ch.codePointAt(0) ?? 0).toString(16)} `;
|
|
32
|
+
}
|
|
33
|
+
return `"${out}"`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function faceRule(family: string, face: FontFace): string | undefined {
|
|
37
|
+
const src = fontFaceSrc(face.src);
|
|
38
|
+
if (!src) return undefined;
|
|
39
|
+
if (!Number.isInteger(face.weight) || face.weight < 1 || face.weight > 1000) return undefined;
|
|
40
|
+
if (face.style !== "normal" && face.style !== "italic") return undefined;
|
|
41
|
+
const range =
|
|
42
|
+
face.unicodeRange !== undefined && face.unicodeRange.length <= 1000
|
|
43
|
+
? UNICODE_RANGE.test(face.unicodeRange)
|
|
44
|
+
? `;unicode-range:${face.unicodeRange}`
|
|
45
|
+
: undefined
|
|
46
|
+
: "";
|
|
47
|
+
if (range === undefined) return undefined;
|
|
48
|
+
return `@font-face{font-family:${cssString(family)};src:url("${src}") format("woff2");font-weight:${face.weight};font-style:${face.style};font-display:swap${range}}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Every `@font-face` rule of one font variable, whether a page uses it or not. */
|
|
52
|
+
export function fontFaceRules(font: Pick<FontVariable, "family" | "faces">): string[] {
|
|
53
|
+
const family = font.family;
|
|
54
|
+
if (!family || !FONT_FAMILY_NAME.test(family)) return [];
|
|
55
|
+
const rules = (font.faces ?? []).flatMap((face) => faceRule(family, face) ?? []);
|
|
56
|
+
return [...new Set(rules)];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* W-1072: the `@font-face` rules of the font variables `sheet` uses (`var(--emvb-f-<id>)`), so a
|
|
61
|
+
* page downloads only the fonts it shows. Empty when no used variable has custom faces, so every
|
|
62
|
+
* existing design keeps the exact CSS it had.
|
|
63
|
+
*/
|
|
64
|
+
export function fontFaceCss(fonts: readonly FontVariable[] | undefined, sheet: string): string {
|
|
65
|
+
const rules = (fonts ?? []).flatMap((font) => {
|
|
66
|
+
const name = fontVariableName(font.id);
|
|
67
|
+
if (!name || !font.faces?.length) return [];
|
|
68
|
+
if (!sheet.includes(`var(${name})`) && !sheet.includes(`var(${name},`)) return [];
|
|
69
|
+
return fontFaceRules(font);
|
|
70
|
+
});
|
|
71
|
+
return [...new Set(rules)].join("");
|
|
72
|
+
}
|
package/src/core/css/generate.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cssTypeName } from "../schema/layout.ts";
|
|
2
2
|
import { MARK_CSS } from "../text-marks.ts";
|
|
3
|
+
import { fontFaceCss } from "./font-face.ts";
|
|
3
4
|
import { DEFAULT_FLUID_RANGE, fluidClamp } from "../design/tokens.ts";
|
|
4
5
|
import type { FluidRange, LengthVariable } from "../schema/design.ts";
|
|
5
6
|
import type { DesignSystem } from "../schema/design.ts";
|
|
@@ -20,7 +21,12 @@ import {
|
|
|
20
21
|
} from "../sanitize/css.ts";
|
|
21
22
|
import { STYLE_STATES, type StyleStateName } from "../schema/state-names.ts";
|
|
22
23
|
import { DEVICE_MEDIA, type Device, type EditorDevice } from "../theme/popup-rules.ts";
|
|
23
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
LOOP_KEYFRAMES,
|
|
26
|
+
MOTION_KEYFRAMES,
|
|
27
|
+
STICKY_KEYFRAMES,
|
|
28
|
+
usesSticky,
|
|
29
|
+
} from "../sanitize/motion.ts";
|
|
24
30
|
|
|
25
31
|
export type CssInput = {
|
|
26
32
|
design: DesignSystem;
|
|
@@ -145,6 +151,25 @@ function declare<T extends { id: string }>(
|
|
|
145
151
|
});
|
|
146
152
|
}
|
|
147
153
|
|
|
154
|
+
/**
|
|
155
|
+
* W-1067: colour variables' dark values. They apply when the visitor's system prefers dark and no
|
|
156
|
+
* Theme toggle chose light, and whenever it chose dark; the toggle marks `<html>` with
|
|
157
|
+
* `data-emvb-theme`. Written as `.emvb-root:is([…] *)` so the sheet's scope prefix still matches.
|
|
158
|
+
*/
|
|
159
|
+
function darkCss(colors: DesignSystem["variables"]["colors"]): string {
|
|
160
|
+
const dark = declare(
|
|
161
|
+
colors.filter((color) => color.dark !== undefined),
|
|
162
|
+
colorVariableName,
|
|
163
|
+
(color) => safe(color.dark ?? ""),
|
|
164
|
+
);
|
|
165
|
+
if (dark.length === 0) return "";
|
|
166
|
+
const declarations = [...dark, { property: "color-scheme", value: "dark" }];
|
|
167
|
+
return (
|
|
168
|
+
`@media (prefers-color-scheme: dark){${block('.emvb-root:not(:is([data-emvb-theme="light"] *))', declarations)}}` +
|
|
169
|
+
block('.emvb-root:is([data-emvb-theme="dark"] *)', declarations)
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
148
173
|
/** W-319: declarations that play scroll motion. */
|
|
149
174
|
const usesMotion = (declarations: readonly Declaration[]) =>
|
|
150
175
|
declarations.some((d) => d.property === "animation" && /\bemvb-m[otsrb]\b/.test(d.value));
|
|
@@ -199,6 +224,8 @@ export function generateCss({
|
|
|
199
224
|
let motion = false;
|
|
200
225
|
/** W-938: any loop on the page, so its keyframes are sent. */
|
|
201
226
|
let loops = false;
|
|
227
|
+
/** W-1070: any sticky effect, so its keyframes are sent. */
|
|
228
|
+
let sticky = false;
|
|
202
229
|
const rules = (selector: string, declarations: Declaration[], states: StateDeclarations) => [
|
|
203
230
|
block(selector, declarations),
|
|
204
231
|
...STYLE_STATES.map((state) =>
|
|
@@ -215,6 +242,7 @@ export function generateCss({
|
|
|
215
242
|
if (declarations.some((d) => d.property === "animation")) entrances.push(selector);
|
|
216
243
|
if (usesMotion(declarations)) motion = true;
|
|
217
244
|
if (usesLoop(declarations)) loops = true;
|
|
245
|
+
if (usesSticky(declarations)) sticky = true;
|
|
218
246
|
return declarations;
|
|
219
247
|
};
|
|
220
248
|
const classes = (design.classes ?? []).flatMap((cls) => {
|
|
@@ -338,6 +366,7 @@ export function generateCss({
|
|
|
338
366
|
const devices = [rule.wide ?? [], rule.laptop, rule.tablet, rule.mobile];
|
|
339
367
|
if (devices.some(usesMotion)) motion = true;
|
|
340
368
|
if (devices.some(usesLoop)) loops = true;
|
|
369
|
+
if (devices.some(usesSticky)) sticky = true;
|
|
341
370
|
if (
|
|
342
371
|
!entrances.includes(rule.selector) &&
|
|
343
372
|
devices.flat().some((d) => d.property === "animation")
|
|
@@ -353,6 +382,7 @@ export function generateCss({
|
|
|
353
382
|
const selector = `.emvb-e-${rule.id}`;
|
|
354
383
|
if (usesMotion(query)) motion = true;
|
|
355
384
|
if (usesLoop(query)) loops = true;
|
|
385
|
+
if (usesSticky(query)) sticky = true;
|
|
356
386
|
if (!entrances.includes(selector) && query.some((d) => d.property === "animation")) {
|
|
357
387
|
entrances.push(selector);
|
|
358
388
|
}
|
|
@@ -366,7 +396,9 @@ export function generateCss({
|
|
|
366
396
|
: "",
|
|
367
397
|
entrances.length > 0 && motion ? MOTION_KEYFRAMES : "",
|
|
368
398
|
entrances.length > 0 && loops ? LOOP_KEYFRAMES : "",
|
|
399
|
+
entrances.length > 0 && sticky ? STICKY_KEYFRAMES : "",
|
|
369
400
|
block(".emvb-root", variables),
|
|
401
|
+
darkCss(colors),
|
|
370
402
|
defaultsCss,
|
|
371
403
|
backgroundVideo
|
|
372
404
|
? ".emvb-has-bg-video{position:relative;overflow:hidden}.emvb-bg-video{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;z-index:0;pointer-events:none}.emvb-has-bg-video>:not(.emvb-bg-video){position:relative;z-index:1}" +
|
|
@@ -406,6 +438,8 @@ export function generateCss({
|
|
|
406
438
|
// W-952: list marker colour and size, and numbered steps, only on pages that use them, so
|
|
407
439
|
// every page saved before them keeps the exact CSS it had.
|
|
408
440
|
return [
|
|
441
|
+
// W-1072: the custom fonts this sheet uses, first; nothing for a design without them.
|
|
442
|
+
fontFaceCss(fonts, sheet),
|
|
409
443
|
sheet,
|
|
410
444
|
sheet.includes("--emvb-marker-") ? LIST_MARKER_CSS : "",
|
|
411
445
|
listSteps ? LIST_STEPS_CSS : "",
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { selectPrompt } from "./select-prompt.ts";
|
|
2
2
|
import { controlId } from "./field-id.ts";
|
|
3
|
+
import { typedInputAttrs } from "./input-limits.ts";
|
|
3
4
|
import type {
|
|
4
5
|
CheckboxNode,
|
|
5
6
|
FormNode,
|
|
7
|
+
FormStepNode,
|
|
6
8
|
RadioNode,
|
|
7
9
|
SelectNode,
|
|
8
10
|
SubmitNode,
|
|
9
11
|
TextInputNode,
|
|
10
12
|
TextareaNode,
|
|
11
13
|
} from "../schema/layout.ts";
|
|
14
|
+
import { MAX_INPUT_NUMBER } from "../schema/layout.ts";
|
|
12
15
|
import type { VNode } from "../render/vnode.ts";
|
|
13
16
|
import type { ElementDescriptor } from "../schema/descriptors.ts";
|
|
14
17
|
import type { ElementDefinition } from "./definition.ts";
|
|
@@ -57,6 +60,20 @@ export const form: ElementDefinition<FormNode> = {
|
|
|
57
60
|
defaults: () => ({ type: "form", props: { formId: "" }, children: [] }),
|
|
58
61
|
descriptor: fieldDescriptor("form", "Form", [
|
|
59
62
|
{ key: "formId", kind: "text", label: "Form id", message: "Paste a forms-plugin form id." },
|
|
63
|
+
{
|
|
64
|
+
key: "nextLabel",
|
|
65
|
+
kind: "text",
|
|
66
|
+
label: "Next button",
|
|
67
|
+
optional: true,
|
|
68
|
+
message: 'For a form with steps. Leave it empty for "Next".',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
key: "prevLabel",
|
|
72
|
+
kind: "text",
|
|
73
|
+
label: "Previous button",
|
|
74
|
+
optional: true,
|
|
75
|
+
message: 'For a form with steps. Leave it empty for "Previous".',
|
|
76
|
+
},
|
|
60
77
|
]),
|
|
61
78
|
build: (_node, attrs, children) => ({
|
|
62
79
|
tag: "form",
|
|
@@ -65,6 +82,44 @@ export const form: ElementDefinition<FormNode> = {
|
|
|
65
82
|
}),
|
|
66
83
|
};
|
|
67
84
|
|
|
85
|
+
/**
|
|
86
|
+
* W-1065: a form step. The form renders it as a page of the forms plugin's multi-page markup
|
|
87
|
+
* (`data-page`, render/form.ts); on its own it is a fieldset named by its title.
|
|
88
|
+
*/
|
|
89
|
+
export const formStep: ElementDefinition<FormStepNode> = {
|
|
90
|
+
baseCss:
|
|
91
|
+
".emvb-form-step{display:flex;flex-direction:column;gap:12px;min-width:0;margin:0;padding:0;border:0}.emvb-form-step[hidden]{display:none!important}.emvb-form-step:focus{outline:none}" +
|
|
92
|
+
":where(.emvb-form-step-title){float:left;width:100%;margin:0 0 4px;padding:0;font-weight:700;font-size:1.125em}" +
|
|
93
|
+
".emvb-form-step-nav{display:flex;flex-wrap:wrap;gap:8px}.emvb-form-step-nav [hidden],.emvb-form .ec-form-submit[hidden]{display:none!important}" +
|
|
94
|
+
":where(.emvb-form-step-nav button){padding:.5em 1em;font:inherit;color:inherit;background:transparent;border:1px solid currentColor;border-radius:6px;cursor:pointer}" +
|
|
95
|
+
":where(.emvb-form-step-nav button:focus-visible){outline:2px solid currentColor;outline-offset:2px}" +
|
|
96
|
+
".emvb-form-step-progress{margin:0}.emvb-form-step-progress:empty{display:none}" +
|
|
97
|
+
"@media (prefers-reduced-motion:no-preference){.emvb-form-step[data-page]:not([hidden]){animation:emvb-form-step-in .2s ease-out}}@keyframes emvb-form-step-in{from{opacity:0;transform:translateY(6px)}}",
|
|
98
|
+
defaults: () => ({ type: "form-step", props: { title: "Step" }, children: [] }),
|
|
99
|
+
descriptor: fieldDescriptor("form-step", "Form step", [
|
|
100
|
+
{
|
|
101
|
+
key: "title",
|
|
102
|
+
kind: "text",
|
|
103
|
+
label: "Title",
|
|
104
|
+
optional: true,
|
|
105
|
+
message: 'Read out when the step opens. Leave it empty for "Step 2".',
|
|
106
|
+
},
|
|
107
|
+
]),
|
|
108
|
+
build: (node, attrs, children) => {
|
|
109
|
+
const title = node.props.title?.trim();
|
|
110
|
+
return {
|
|
111
|
+
tag: "fieldset",
|
|
112
|
+
attrs,
|
|
113
|
+
children: [
|
|
114
|
+
...(title
|
|
115
|
+
? [{ tag: "legend", attrs: { class: "emvb-form-step-title" }, children: [title] }]
|
|
116
|
+
: []),
|
|
117
|
+
...children,
|
|
118
|
+
],
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
68
123
|
/** Where the forms runtime writes a field's validation message. */
|
|
69
124
|
const errorSlot = (name: string, controlFor: string): VNode => ({
|
|
70
125
|
tag: "span",
|
|
@@ -146,15 +201,70 @@ const textControl = (
|
|
|
146
201
|
export const textInput: ElementDefinition<TextInputNode> = {
|
|
147
202
|
baseCss: ".emvb-text-input{display:flex;flex-direction:column;gap:4px}",
|
|
148
203
|
defaults: () => ({ type: "text-input", props: { field: "name", label: "Name" } }),
|
|
149
|
-
descriptor: fieldDescriptor("text-input", "Text input",
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
204
|
+
descriptor: fieldDescriptor("text-input", "Text input", [
|
|
205
|
+
...TEXT_FIELDS,
|
|
206
|
+
{
|
|
207
|
+
key: "inputType",
|
|
208
|
+
kind: "select",
|
|
209
|
+
label: "Asks for",
|
|
210
|
+
optional: true,
|
|
211
|
+
options: [
|
|
212
|
+
{ value: "number", label: "A number" },
|
|
213
|
+
{ value: "date", label: "A date" },
|
|
214
|
+
],
|
|
215
|
+
message: "Unset: text. A form field that is an email, number or date keeps its own type.",
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
key: "min",
|
|
219
|
+
kind: "decimal",
|
|
220
|
+
label: "Lowest number",
|
|
221
|
+
optional: true,
|
|
222
|
+
min: -MAX_INPUT_NUMBER,
|
|
223
|
+
max: MAX_INPUT_NUMBER,
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
key: "max",
|
|
227
|
+
kind: "decimal",
|
|
228
|
+
label: "Highest number",
|
|
229
|
+
optional: true,
|
|
230
|
+
min: -MAX_INPUT_NUMBER,
|
|
231
|
+
max: MAX_INPUT_NUMBER,
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
key: "step",
|
|
235
|
+
kind: "decimal",
|
|
236
|
+
label: "Step",
|
|
237
|
+
optional: true,
|
|
238
|
+
min: 0.000001,
|
|
239
|
+
max: MAX_INPUT_NUMBER,
|
|
240
|
+
message: "Allowed numbers go up by this much, such as 1 or 0.5. Leave it empty for any.",
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
key: "minDate",
|
|
244
|
+
kind: "text",
|
|
245
|
+
label: "Earliest date",
|
|
246
|
+
optional: true,
|
|
247
|
+
message: "As YYYY-MM-DD, such as 2026-01-31.",
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
key: "maxDate",
|
|
251
|
+
kind: "text",
|
|
252
|
+
label: "Latest date",
|
|
253
|
+
optional: true,
|
|
254
|
+
message: "As YYYY-MM-DD, such as 2026-12-31.",
|
|
255
|
+
},
|
|
256
|
+
]),
|
|
257
|
+
build: (node, attrs) => {
|
|
258
|
+
const control = textControl("input", node.props, controlId(node.id));
|
|
259
|
+
const type = node.props.inputType;
|
|
260
|
+
const typed: VNode = type
|
|
261
|
+
? {
|
|
262
|
+
...control,
|
|
263
|
+
attrs: { ...control.attrs, type, ...typedInputAttrs(type, node.props) },
|
|
264
|
+
}
|
|
265
|
+
: control;
|
|
266
|
+
return fieldWrap(controlId(node.id), node.props.field, node.props.label, typed, attrs);
|
|
267
|
+
},
|
|
158
268
|
};
|
|
159
269
|
|
|
160
270
|
export const textareaEl: ElementDefinition<TextareaNode> = {
|
|
@@ -92,6 +92,18 @@ function pickedIconAttrs(attrs: Record<string, string>): Record<string, string>
|
|
|
92
92
|
* W-1020: an icon's `<svg>` at `size` px with `aria` (its name, or `aria-hidden`), or undefined
|
|
93
93
|
* when the id is unknown and no SVG is stored.
|
|
94
94
|
*/
|
|
95
|
+
/**
|
|
96
|
+
* W-1079: an icon that points along the reading direction (an arrow, chevron, caret or angle to
|
|
97
|
+
* the left or right). On a right-to-left page it is mirrored, so "next" still points forward.
|
|
98
|
+
*/
|
|
99
|
+
export function isDirectionalIcon(iconId: string): boolean {
|
|
100
|
+
const name = (iconId.split(":").pop() ?? "").toLowerCase();
|
|
101
|
+
return (
|
|
102
|
+
/(^|[-_])(arrows?|chevrons?|carets?|angles?|triangle)([-_]|$)/.test(name) &&
|
|
103
|
+
/(^|[-_])(left|right)([-_]|$)/.test(name)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
95
107
|
export function iconGlyph(
|
|
96
108
|
props: { iconId: string; iconSvg?: string | undefined; singleColor?: boolean | undefined },
|
|
97
109
|
size: number,
|
|
@@ -129,6 +141,8 @@ export function iconGlyph(
|
|
|
129
141
|
children: [],
|
|
130
142
|
}));
|
|
131
143
|
strokeClass(svgAttrs);
|
|
144
|
+
if (isDirectionalIcon(props.iconId))
|
|
145
|
+
svgAttrs.class = svgAttrs.class ? `${svgAttrs.class} emvb-icon-dir` : "emvb-icon-dir";
|
|
132
146
|
const single = picked !== undefined && props.singleColor === true;
|
|
133
147
|
if (single) monochromeRoot(svgAttrs);
|
|
134
148
|
return { tag: "svg", attrs: svgAttrs, children: single ? monochrome(children) : children };
|