@perkyzz/emvb 0.5.0 → 0.7.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 +4 -0
- package/THIRD_PARTY_NOTICES.md +23 -1
- package/licenses/exif-js.LICENSE +21 -0
- package/licenses/fflate.LICENSE +21 -0
- package/licenses/glfx.js.LICENSE +19 -0
- package/licenses/mini-photo-editor.LICENSE +21 -0
- package/licenses/photocn.LICENSE +21 -0
- package/package.json +2 -1
- package/src/admin/access/RequireEditor.tsx +7 -7
- package/src/admin/access/role.ts +5 -2
- package/src/admin/content-api.ts +10 -3
- package/src/admin/content-item.ts +1 -1
- package/src/admin/editor/A11yCopilot.tsx +104 -56
- package/src/admin/editor/CommandPalette.tsx +29 -13
- package/src/admin/editor/Editor.tsx +88 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +97 -72
- package/src/admin/editor/ShareLink.tsx +107 -72
- package/src/admin/editor/ShortcutsDialog.tsx +27 -16
- package/src/admin/editor/Timeline.tsx +255 -160
- package/src/admin/editor/TopBar.tsx +71 -14
- package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
- package/src/admin/editor/canvas/drop-line.ts +11 -3
- package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
- package/src/admin/editor/canvas/vnode-react.tsx +7 -0
- package/src/admin/editor/collection-previews.ts +16 -1
- package/src/admin/editor/dialogs.tsx +38 -14
- package/src/admin/editor/dnd/drop-target.ts +26 -1
- package/src/admin/editor/edited-noun.ts +15 -0
- package/src/admin/editor/editor-chrome.tsx +108 -7
- package/src/admin/editor/editor-commands.ts +15 -1
- package/src/admin/editor/editor-css.ts +75 -22
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +45 -13
- package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
- package/src/admin/editor/icons/library.ts +1 -1
- package/src/admin/editor/icons/use-icon-library.ts +5 -2
- package/src/admin/editor/ime.ts +29 -0
- package/src/admin/editor/palette-items.ts +10 -3
- package/src/admin/editor/panels/AddPanel.tsx +35 -10
- package/src/admin/editor/panels/ClassesSection.tsx +18 -7
- package/src/admin/editor/panels/ColorControl.tsx +135 -27
- package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
- package/src/admin/editor/panels/ElementPanel.tsx +134 -24
- package/src/admin/editor/panels/LayersPanel.tsx +68 -22
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
- package/src/admin/editor/panels/TokenScales.tsx +76 -36
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
- package/src/admin/editor/panels/VariableSection.tsx +53 -21
- package/src/admin/editor/panels/color-space.ts +9 -3
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
- package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
- package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
- package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
- package/src/admin/editor/panels/settings/FieldControl.tsx +38 -15
- package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
- package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
- package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
- package/src/admin/editor/panels/settings/MediaPicker.tsx +274 -20
- package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
- package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
- package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +141 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
- package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
- package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
- package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
- package/src/admin/editor/panels/settings/query-style.ts +38 -9
- package/src/admin/editor/panels/settings/svg-images.ts +13 -0
- package/src/admin/editor/panels/site-list.tsx +20 -6
- package/src/admin/editor/panels/variable-values.ts +25 -4
- package/src/admin/editor/restore-deleted.ts +21 -2
- package/src/admin/editor/section-templates.ts +81 -12
- package/src/admin/editor/shortcuts.ts +17 -2
- package/src/admin/editor/store.ts +14 -3
- package/src/admin/editor/useEditorCommands.ts +61 -15
- package/src/admin/editor/useEditorData.ts +4 -2
- package/src/admin/editor/useEditorShortcuts.ts +17 -7
- package/src/admin/editor/useNodeActions.ts +61 -6
- package/src/admin/editor/useSave.ts +22 -7
- package/src/admin/forms-api.ts +2 -0
- package/src/admin/image-editor/BlurFocus.tsx +112 -0
- package/src/admin/image-editor/Canvas.tsx +261 -0
- package/src/admin/image-editor/CropOverlay.tsx +390 -0
- package/src/admin/image-editor/CurvesPanel.tsx +395 -0
- package/src/admin/image-editor/ExportDialog.tsx +384 -0
- package/src/admin/image-editor/ImageEditButton.tsx +83 -0
- package/src/admin/image-editor/ImageEditorDialog.tsx +828 -0
- package/src/admin/image-editor/MetadataPanel.tsx +194 -0
- package/src/admin/image-editor/announce.tsx +65 -0
- package/src/admin/image-editor/crop-geometry.ts +162 -0
- package/src/admin/image-editor/curve-math.ts +177 -0
- package/src/admin/image-editor/data-url-fetch.ts +59 -0
- package/src/admin/image-editor/engine.ts +55 -0
- package/src/admin/image-editor/exif.ts +82 -0
- package/src/admin/image-editor/flatten.ts +54 -0
- package/src/admin/image-editor/gpu-fit.ts +81 -0
- package/src/admin/image-editor/image-editor-css.ts +400 -0
- package/src/admin/image-editor/load.ts +116 -0
- package/src/admin/image-editor/panels.tsx +287 -0
- package/src/admin/image-editor/parts.tsx +614 -0
- package/src/admin/image-editor/save.ts +141 -0
- package/src/admin/image-editor/tone-panels.tsx +338 -0
- package/src/admin/image-editor/tools.ts +59 -0
- package/src/admin/image-editor/worker.ts +111 -0
- package/src/admin/media-api.ts +114 -3
- package/src/admin/pages/AgentsPage.tsx +138 -27
- package/src/admin/pages/CreateDialog.tsx +97 -30
- package/src/admin/pages/NewPageDialog.tsx +21 -3
- package/src/admin/pages/NewThemePartDialog.tsx +11 -3
- package/src/admin/pages/PageList.tsx +14 -6
- package/src/admin/pages/SetupShell.tsx +28 -12
- package/src/admin/pages/ThemePartList.tsx +27 -7
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +13 -3
- package/src/admin/ui.ts +78 -22
- package/src/astro/EmVBPage.astro +11 -2
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +33 -3
- package/src/astro/render.ts +6 -0
- package/src/astro/resolve-theme.ts +67 -14
- package/src/astro/resolve.ts +9 -1
- package/src/astro/tabs/runtime.ts +12 -0
- package/src/astro/theme-posts.ts +2 -2
- package/src/astro/visitor.ts +6 -3
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +171 -24
- package/src/core/arrange.ts +29 -6
- package/src/core/audience/rules.ts +5 -1
- package/src/core/audience/variants.ts +29 -3
- package/src/core/clipboard.ts +7 -0
- package/src/core/css/generate.ts +31 -6
- package/src/core/data/bindings.ts +19 -6
- package/src/core/design/classes.ts +20 -9
- package/src/core/design/diff.ts +9 -1
- package/src/core/design/merge.ts +93 -3
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +46 -8
- package/src/core/design/variables.ts +32 -10
- package/src/core/elements/dynamic-elements.ts +53 -6
- package/src/core/elements/form-elements.ts +68 -30
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -19
- package/src/core/elements/plain-text.ts +2 -2
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +190 -2
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +49 -4
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +155 -0
- package/src/core/image-edit/summary.ts +61 -0
- package/src/core/index.ts +29 -1
- package/src/core/limits.ts +21 -0
- package/src/core/migrate/index.ts +3 -1
- package/src/core/perf/meter.ts +51 -8
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +71 -13
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +164 -12
- package/src/core/render/index.ts +179 -22
- package/src/core/render/loop.ts +43 -7
- package/src/core/render/pagination.ts +18 -4
- package/src/core/render/section.ts +27 -0
- package/src/core/render/tabs.ts +12 -3
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +15 -2
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/schema/layout.ts +26 -7
- package/src/core/share/link.ts +5 -2
- package/src/core/stable-json.ts +15 -0
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +57 -23
- package/src/core/theme/float.ts +9 -2
- package/src/core/theme/pagination.ts +57 -10
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +11 -5
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/ports.ts +8 -1
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +82 -3
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/tools.ts +1 -1
- package/src/mcp/write.ts +271 -25
- package/src/server/agent-settings.ts +29 -4
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +33 -9
- package/src/server/mcp-routes.ts +74 -11
package/src/core/index.ts
CHANGED
|
@@ -150,11 +150,19 @@ export { classStylesInListOrder, resolveCascade } from "./design/cascade.ts";
|
|
|
150
150
|
export {
|
|
151
151
|
findMissingRequiredFields,
|
|
152
152
|
layoutHasForm,
|
|
153
|
+
requiredFieldIssues,
|
|
154
|
+
requiredFieldIssueText,
|
|
153
155
|
type MissingRequiredField,
|
|
156
|
+
type RequiredFieldInfo,
|
|
157
|
+
type RequiredFieldIssue,
|
|
154
158
|
} from "./forms/binding.ts";
|
|
155
159
|
export {
|
|
156
160
|
fieldsOf,
|
|
157
161
|
fieldByName,
|
|
162
|
+
impossibleRangeFields,
|
|
163
|
+
mismatchedControls,
|
|
164
|
+
type ImpossibleRangeField,
|
|
165
|
+
type MismatchedControl,
|
|
158
166
|
type PublicFormDefinition,
|
|
159
167
|
type PublicFormField,
|
|
160
168
|
type FormDefinitions,
|
|
@@ -163,6 +171,7 @@ export { FORMS_SUBMIT_PATH } from "./render/index.ts";
|
|
|
163
171
|
|
|
164
172
|
export {
|
|
165
173
|
cleanClassName,
|
|
174
|
+
nameKey,
|
|
166
175
|
MAX_CLASSES,
|
|
167
176
|
moveClassId,
|
|
168
177
|
addClassId,
|
|
@@ -251,6 +260,7 @@ export {
|
|
|
251
260
|
nodeIdAtPath,
|
|
252
261
|
newNodeId,
|
|
253
262
|
starterLayout,
|
|
263
|
+
pageSlug,
|
|
254
264
|
slugify,
|
|
255
265
|
type Removed,
|
|
256
266
|
} from "./tree-ops.ts";
|
|
@@ -357,7 +367,12 @@ export {
|
|
|
357
367
|
type PopupDevice,
|
|
358
368
|
} from "./theme/popup-rules.ts";
|
|
359
369
|
|
|
360
|
-
export {
|
|
370
|
+
export {
|
|
371
|
+
POPUP_CHROME_CSS,
|
|
372
|
+
wrapPopupMarkup,
|
|
373
|
+
type ChromeLabels,
|
|
374
|
+
type PopupPublicConfig,
|
|
375
|
+
} from "./theme/popup-markup.ts";
|
|
361
376
|
|
|
362
377
|
export {
|
|
363
378
|
FLOAT_EDGES,
|
|
@@ -390,6 +405,8 @@ export {
|
|
|
390
405
|
archivePageTitle,
|
|
391
406
|
DEFAULT_PER_PAGE,
|
|
392
407
|
loopPerPage,
|
|
408
|
+
paginationArchiveTitle,
|
|
409
|
+
paginationTitleText,
|
|
393
410
|
MAX_ARCHIVE_PAGE,
|
|
394
411
|
paginationItems,
|
|
395
412
|
splitArchivePage,
|
|
@@ -440,6 +457,7 @@ export {
|
|
|
440
457
|
export {
|
|
441
458
|
abCookieName,
|
|
442
459
|
collectAbTests,
|
|
460
|
+
loneAbTests,
|
|
443
461
|
pickArm,
|
|
444
462
|
variantShows,
|
|
445
463
|
type AbArm,
|
|
@@ -499,3 +517,13 @@ export {
|
|
|
499
517
|
type ShareRead,
|
|
500
518
|
} from "./share/link.ts";
|
|
501
519
|
export { canvasStyleUrls, MAX_CANVAS_STYLES } from "./canvas-styles.ts";
|
|
520
|
+
export {
|
|
521
|
+
IMAGE_EDIT_CURVE_POINTS_MAX,
|
|
522
|
+
IMAGE_EDIT_FORMATS,
|
|
523
|
+
IMAGE_EDIT_RECIPE_MAX_BYTES,
|
|
524
|
+
ImageEdit,
|
|
525
|
+
ImageEditOutput,
|
|
526
|
+
ImageEditRecipe,
|
|
527
|
+
} from "./image-edit/schema.ts";
|
|
528
|
+
export { summarizeImageEdit } from "./image-edit/summary.ts";
|
|
529
|
+
export { boxLinkHeldBack } from "./render/extras.ts";
|
package/src/core/limits.ts
CHANGED
|
@@ -7,3 +7,24 @@ export const MAX_NODES = 2000;
|
|
|
7
7
|
export const MAX_TEXT_LENGTH = 2000;
|
|
8
8
|
/** Tabs show at most this many panels; the CSS-only switcher has a rule per tab. */
|
|
9
9
|
export const MAX_TABS = 12;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* W-509: `text` cut to at most `max` UTF-16 units, as schema limits count, without leaving half
|
|
13
|
+
* of an emoji (a lone surrogate), an accent's base letter or half a flag at the end.
|
|
14
|
+
*/
|
|
15
|
+
export function clipText(text: string, max: number): string {
|
|
16
|
+
if (text.length <= max) return text;
|
|
17
|
+
// W-543: whole characters as people see them, so an accent or half a flag isn't left behind.
|
|
18
|
+
if (typeof Intl !== "undefined" && "Segmenter" in Intl) {
|
|
19
|
+
let end = 0;
|
|
20
|
+
for (const { segment } of new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(
|
|
21
|
+
text.slice(0, max + 32),
|
|
22
|
+
)) {
|
|
23
|
+
if (end + segment.length > max) break;
|
|
24
|
+
end += segment.length;
|
|
25
|
+
}
|
|
26
|
+
return text.slice(0, end);
|
|
27
|
+
}
|
|
28
|
+
const code = text.charCodeAt(max - 1);
|
|
29
|
+
return text.slice(0, code >= 0xd800 && code <= 0xdbff ? max - 1 : max);
|
|
30
|
+
}
|
|
@@ -16,7 +16,8 @@ export type Migration = (doc: Record<string, unknown>) => Record<string, unknown
|
|
|
16
16
|
* (bindings, and the rest of the W-307 feature batch), and v13 → v14 (W-329 onward) adds
|
|
17
17
|
* optional fields only (audience segments, Loop options, `ch` and negative margins), and
|
|
18
18
|
* v14 → v15 (W-341 onward) adds optional fields only (direction, image link and caption,
|
|
19
|
-
* button icons, table of contents, container queries)
|
|
19
|
+
* button icons, table of contents, container queries), and layout v15 → v16 (W-481) adds the
|
|
20
|
+
* optional image `edit` record. Every other value is unchanged.
|
|
20
21
|
*/
|
|
21
22
|
const unchanged: Migration = (doc) => doc;
|
|
22
23
|
|
|
@@ -74,6 +75,7 @@ export const LAYOUT_MIGRATIONS: Readonly<Record<number, Migration>> = {
|
|
|
74
75
|
12: unchanged,
|
|
75
76
|
13: unchanged,
|
|
76
77
|
14: unchanged,
|
|
78
|
+
15: unchanged,
|
|
77
79
|
};
|
|
78
80
|
|
|
79
81
|
/** `DESIGN_MIGRATIONS[n]` upgrades a version-n design document to version n + 1. */
|
package/src/core/perf/meter.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { DesignSystem } from "../schema/design.ts";
|
|
|
2
2
|
import { isParentNode, type Layout, type LayoutNode } from "../schema/layout.ts";
|
|
3
3
|
import { renderPage } from "../render/index.ts";
|
|
4
4
|
import type { ThemeDynamicData } from "../theme/dynamic.ts";
|
|
5
|
+
import { resolveEmbedUrl } from "../sanitize/embed-url.ts";
|
|
5
6
|
import { layoutScripts, SCRIPT_BYTES, type PageScript } from "./scripts.ts";
|
|
6
7
|
|
|
7
8
|
/** Budgets per page (W-310), in bytes over the wire. Generous for a marketing page. */
|
|
@@ -50,20 +51,55 @@ function imageBytes(node: LayoutNode): number {
|
|
|
50
51
|
return w > 0 && h > 0 ? Math.max(5_000, Math.round(w * h * 0.25)) : IMAGE_GUESS;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
type Sheets = { style?: unknown; devices?: Record<string, unknown>; query?: { style?: unknown } };
|
|
55
|
+
const sheetsHaveBackground = (owner: Sheets): boolean => {
|
|
56
|
+
// W-645: a container-query override (W-346) can set the background too.
|
|
57
|
+
const sheets = [owner.style, ...Object.values(owner.devices ?? {}), owner.query?.style];
|
|
55
58
|
return sheets.some((style) => {
|
|
56
59
|
const value = (style as { backgroundImage?: unknown } | undefined)?.backgroundImage;
|
|
57
60
|
return typeof value === "string" ? value.length > 0 : Boolean(value);
|
|
58
61
|
});
|
|
59
62
|
};
|
|
60
63
|
|
|
64
|
+
/** Ids of global classes that set a background image (W-635). */
|
|
65
|
+
const backgroundClasses = (design: DesignSystem): Set<string> =>
|
|
66
|
+
new Set((design.classes ?? []).filter((c) => sheetsHaveBackground(c)).map((c) => c.id));
|
|
67
|
+
|
|
68
|
+
/** Its own style or one of its classes sets a background image (W-635). */
|
|
69
|
+
const hasBackgroundImage = (node: LayoutNode, bgClasses: Set<string>): boolean =>
|
|
70
|
+
sheetsHaveBackground(node as Sheets) || (node.classes ?? []).some((id) => bgClasses.has(id));
|
|
71
|
+
|
|
72
|
+
const isPlayerEmbed = (node: LayoutNode): boolean => {
|
|
73
|
+
const url = (node.props as { url?: unknown }).url;
|
|
74
|
+
return typeof url === "string" && resolveEmbedUrl(url)?.kind === "iframe";
|
|
75
|
+
};
|
|
76
|
+
|
|
61
77
|
/** Images and embeds under a node, with their estimated weight. */
|
|
62
|
-
function media(
|
|
78
|
+
function media(
|
|
79
|
+
node: LayoutNode,
|
|
80
|
+
bgClasses: Set<string>,
|
|
81
|
+
dynamic?: ThemeDynamicData,
|
|
82
|
+
): { images: number; bytes: number; embeds: number } {
|
|
63
83
|
let images = 0;
|
|
64
84
|
let bytes = 0;
|
|
65
85
|
let embeds = 0;
|
|
86
|
+
const seen = new Set<Layout>();
|
|
87
|
+
/** W-671: a synced section or Loop Item part the canvas loaded is weighed with the page. */
|
|
88
|
+
const part = (n: LayoutNode): Layout | undefined => {
|
|
89
|
+
const props = n.props as { partId?: unknown; itemPartId?: unknown };
|
|
90
|
+
const found =
|
|
91
|
+
n.type === "section" && typeof props.partId === "string"
|
|
92
|
+
? dynamic?.sectionTemplates?.[props.partId.trim()]
|
|
93
|
+
: n.type === "loop" && typeof props.itemPartId === "string"
|
|
94
|
+
? dynamic?.loopTemplates?.[props.itemPartId.trim()]
|
|
95
|
+
: undefined;
|
|
96
|
+
if (!found || seen.has(found)) return undefined;
|
|
97
|
+
seen.add(found);
|
|
98
|
+
return found;
|
|
99
|
+
};
|
|
66
100
|
const walk = (n: LayoutNode): void => {
|
|
101
|
+
const template = part(n);
|
|
102
|
+
if (template) walk(template.root);
|
|
67
103
|
if (n.type === "image" || n.type === "post-image") {
|
|
68
104
|
const src = (n.props as { src?: unknown }).src;
|
|
69
105
|
if (n.type === "post-image" || (typeof src === "string" && src.trim())) {
|
|
@@ -71,11 +107,13 @@ function media(node: LayoutNode): { images: number; bytes: number; embeds: numbe
|
|
|
71
107
|
bytes += imageBytes(n);
|
|
72
108
|
}
|
|
73
109
|
}
|
|
74
|
-
if (hasBackgroundImage(n)) {
|
|
110
|
+
if (hasBackgroundImage(n, bgClasses)) {
|
|
75
111
|
images += 1;
|
|
76
112
|
bytes += IMAGE_GUESS;
|
|
77
113
|
}
|
|
78
|
-
|
|
114
|
+
// W-508: only a YouTube or Vimeo player is a third-party embed; a media-library video loads
|
|
115
|
+
// its metadata only, and a missing or refused URL renders nothing.
|
|
116
|
+
if (n.type === "video" && isPlayerEmbed(n)) {
|
|
79
117
|
embeds += 1;
|
|
80
118
|
bytes += EMBED_BYTES;
|
|
81
119
|
}
|
|
@@ -102,7 +140,8 @@ export function measurePage(
|
|
|
102
140
|
bytes: SCRIPT_BYTES[script],
|
|
103
141
|
nodeIds,
|
|
104
142
|
}));
|
|
105
|
-
const
|
|
143
|
+
const bgClasses = backgroundClasses(design);
|
|
144
|
+
const all = media(layout.root, bgClasses, dynamic);
|
|
106
145
|
const bytes: Record<PerfKind, number> = {
|
|
107
146
|
html: Math.round(utf8(rendered.html) * GZIP),
|
|
108
147
|
css: Math.round(utf8(rendered.css) * GZIP),
|
|
@@ -118,7 +157,7 @@ export function measurePage(
|
|
|
118
157
|
root: Object.assign({}, layout.root, { children: [child] }),
|
|
119
158
|
};
|
|
120
159
|
const one = renderPage(alone, design, opts);
|
|
121
|
-
const m = media(child);
|
|
160
|
+
const m = media(child, bgClasses, dynamic);
|
|
122
161
|
sections.push({
|
|
123
162
|
id: child.id,
|
|
124
163
|
type: child.type,
|
|
@@ -149,8 +188,12 @@ export function measurePage(
|
|
|
149
188
|
return { bytes, over, scripts, imageCount: all.images, embeds: all.embeds, sections, warnings };
|
|
150
189
|
}
|
|
151
190
|
|
|
191
|
+
/** W-574: the first image that renders; an Image with no picture yet shows nothing to load. */
|
|
152
192
|
function findFirstImage(node: LayoutNode): LayoutNode | undefined {
|
|
153
|
-
if (node.type === "image")
|
|
193
|
+
if (node.type === "image") {
|
|
194
|
+
const src = (node.props as { src?: unknown }).src;
|
|
195
|
+
if (typeof src === "string" && src.trim()) return node;
|
|
196
|
+
}
|
|
154
197
|
if (!isParentNode(node)) return undefined;
|
|
155
198
|
for (const child of node.children) {
|
|
156
199
|
const found = findFirstImage(child);
|
|
@@ -103,12 +103,13 @@ export function siteTokens(design: DesignSystem): RecipeTokens {
|
|
|
103
103
|
if (surface) tokens.surface = surface;
|
|
104
104
|
const onAccent = color(pick(others, /on[- ]?(primary|brand|accent)|inverse|white/));
|
|
105
105
|
if (onAccent) tokens.onAccent = onAccent;
|
|
106
|
-
else if (accentVar && /^#[0-9a-f]{6}$/i.test(accentVar.value)) {
|
|
106
|
+
else if (accentVar && /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(accentVar.value)) {
|
|
107
107
|
// No "on accent" colour: white or near-black, whichever reads better on the accent.
|
|
108
|
+
// W-642: a short (#fd0) or alpha (#ffdd00cc) accent is judged as its six-digit colour.
|
|
109
|
+
const h = accentVar.value.slice(1);
|
|
110
|
+
const hex = `#${(h.length <= 4 ? [...h].map((c) => c + c).join("") : h).slice(0, 6)}`;
|
|
108
111
|
tokens.onAccent =
|
|
109
|
-
contrastRatio(
|
|
110
|
-
? "#ffffff"
|
|
111
|
-
: "#111111";
|
|
112
|
+
contrastRatio(hex, "#ffffff") >= contrastRatio(hex, "#111111") ? "#ffffff" : "#111111";
|
|
112
113
|
}
|
|
113
114
|
const buttonCls = pick(design.classes, /\b(button|btn)\b/, /cta/);
|
|
114
115
|
if (buttonCls) {
|
|
@@ -18,6 +18,14 @@ export type RenderContext = {
|
|
|
18
18
|
* stay with their own copy.
|
|
19
19
|
*/
|
|
20
20
|
uniqueId: (base: string) => string;
|
|
21
|
+
/**
|
|
22
|
+
* W-653: claims `nodes` elements from this render's synced-section budget; false once spent.
|
|
23
|
+
* Sections nested in sections multiply, so a few small parts could expand to millions of
|
|
24
|
+
* elements and stall the page.
|
|
25
|
+
*/
|
|
26
|
+
takeSectionBudget?: (nodes: number) => boolean;
|
|
27
|
+
/** The page's language, e.g. "fr-CA", for dates (W-688). */
|
|
28
|
+
lang?: string;
|
|
21
29
|
/** The form whose children are rendering, so each field reads that form's definition. */
|
|
22
30
|
formId?: string;
|
|
23
31
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { clipText } from "../limits.ts";
|
|
1
2
|
import { HEADING_TAGS } from "../elements/index.ts";
|
|
2
3
|
import type { LayoutNode, POST_DATE_FORMATS } from "../schema/layout.ts";
|
|
3
4
|
import { sanitizeHref } from "../sanitize/href.ts";
|
|
@@ -6,6 +7,39 @@ import { portableTextToVNodes, type ThemePostFields } from "../theme/dynamic.ts"
|
|
|
6
7
|
import type { RenderMode } from "./context.ts";
|
|
7
8
|
import type { VNode } from "./vnode.ts";
|
|
8
9
|
|
|
10
|
+
/** Scripts written without spaces between words; a space-separated chunk holds many words. */
|
|
11
|
+
const UNSPACED =
|
|
12
|
+
/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u;
|
|
13
|
+
let wordSegmenter: Intl.Segmenter | undefined;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The first `max` words, then "…". W-660: Japanese, Chinese or Thai text has no spaces between
|
|
17
|
+
* words, so splitting on spaces counted a whole excerpt as one word and never shortened it.
|
|
18
|
+
* Those chunks are split into words; spaced text is counted by spaces as before.
|
|
19
|
+
*/
|
|
20
|
+
function limitWords(text: string, max: number | undefined): string {
|
|
21
|
+
if (!max || max < 1) return text;
|
|
22
|
+
let count = 0;
|
|
23
|
+
for (const chunk of text.matchAll(/\S+/g)) {
|
|
24
|
+
const start = chunk.index ?? 0;
|
|
25
|
+
if (!UNSPACED.test(chunk[0])) {
|
|
26
|
+
count++;
|
|
27
|
+
if (count === max) return finish(text, start + chunk[0].length);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
wordSegmenter ??= new Intl.Segmenter(undefined, { granularity: "word" });
|
|
31
|
+
for (const piece of wordSegmenter.segment(chunk[0])) {
|
|
32
|
+
if (!piece.isWordLike) continue;
|
|
33
|
+
count++;
|
|
34
|
+
if (count === max) return finish(text, start + piece.index + piece.segment.length);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return text;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const finish = (text: string, end: number) =>
|
|
41
|
+
text.slice(end).trim() === "" ? text : `${text.slice(0, end).trim().replace(/\s+/g, " ")}…`;
|
|
42
|
+
|
|
9
43
|
/**
|
|
10
44
|
* W-196: only an ISO date (`2026-10-06`, optionally with a time) is read as a date. `Date.parse`
|
|
11
45
|
* also takes text like "Spring 2026" (as Jan 1) or "2026-02-30", which would show a wrong date.
|
|
@@ -16,8 +50,10 @@ const parseIsoDate = (raw: string): number => {
|
|
|
16
50
|
const parsed = Date.parse(raw.replace(" ", "T"));
|
|
17
51
|
if (Number.isNaN(parsed)) return Number.NaN;
|
|
18
52
|
const day = new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3])));
|
|
53
|
+
// W-599: the day as written. A post at 22:00-04:00 was published that day, not the next
|
|
54
|
+
// one in UTC, and a time with no zone isn't moved by the server's zone.
|
|
19
55
|
return day.getUTCDate() === Number(match[3]) && day.getUTCMonth() === Number(match[2]) - 1
|
|
20
|
-
?
|
|
56
|
+
? day.getTime()
|
|
21
57
|
: Number.NaN;
|
|
22
58
|
};
|
|
23
59
|
|
|
@@ -34,16 +70,32 @@ type PostField = {
|
|
|
34
70
|
attrs: Attrs,
|
|
35
71
|
post: ThemePostFields,
|
|
36
72
|
inLoop: boolean,
|
|
73
|
+
lang?: string,
|
|
37
74
|
) => VNode | undefined;
|
|
38
75
|
};
|
|
39
76
|
|
|
40
77
|
type PostDateFormat = (typeof POST_DATE_FORMATS)[number];
|
|
41
78
|
|
|
42
|
-
/**
|
|
43
|
-
function
|
|
79
|
+
/** A BCP 47-shaped language tag Intl can use, else English (W-688). */
|
|
80
|
+
function dateLocale(lang: string | undefined): string {
|
|
81
|
+
if (!lang || !/^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(lang)) return "en";
|
|
82
|
+
try {
|
|
83
|
+
return Intl.DateTimeFormat.supportedLocalesOf([lang])[0] ?? "en";
|
|
84
|
+
} catch {
|
|
85
|
+
return "en";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* In UTC on the written day, so the date doesn't move with the server's time zone.
|
|
91
|
+
* W-688: in the page's language ("6 oct. 2026" on a French site); it was always English.
|
|
92
|
+
*/
|
|
93
|
+
function formatPostDate(time: number, format: PostDateFormat, lang?: string): string {
|
|
44
94
|
const date = new Date(time);
|
|
45
95
|
if (format === "numeric") return date.toISOString().slice(0, 10);
|
|
46
|
-
return new Intl.DateTimeFormat(
|
|
96
|
+
return new Intl.DateTimeFormat(dateLocale(lang), { dateStyle: format, timeZone: "UTC" }).format(
|
|
97
|
+
date,
|
|
98
|
+
);
|
|
47
99
|
}
|
|
48
100
|
|
|
49
101
|
const props = <T>(node: LayoutNode) => node.props as T;
|
|
@@ -53,6 +105,9 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
53
105
|
"post-title",
|
|
54
106
|
{
|
|
55
107
|
placeholder: (attrs) => ({ tag: "h1", attrs, children: ["Post Title"] }),
|
|
108
|
+
// W-661: an untitled post left an empty heading on the page (a blank entry for screen
|
|
109
|
+
// reader heading lists).
|
|
110
|
+
has: (post) => !!post.title?.trim(),
|
|
56
111
|
render: (node, attrs, post) => {
|
|
57
112
|
const level = props<{ level?: number }>(node).level ?? 1;
|
|
58
113
|
const tag = HEADING_TAGS[Math.min(6, Math.max(1, level)) - 1] ?? "h1";
|
|
@@ -65,10 +120,8 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
65
120
|
{
|
|
66
121
|
placeholder: (attrs) => ({ tag: "p", attrs, children: ["Post excerpt…"] }),
|
|
67
122
|
render: (node, attrs, post) => {
|
|
68
|
-
if (!post.excerpt) return undefined;
|
|
69
|
-
const
|
|
70
|
-
const words = post.excerpt.trim().split(/\s+/);
|
|
71
|
-
const text = max && words.length > max ? `${words.slice(0, max).join(" ")}…` : post.excerpt;
|
|
123
|
+
if (!post.excerpt?.trim()) return undefined;
|
|
124
|
+
const text = limitWords(post.excerpt, props<{ maxWords?: number }>(node).maxWords);
|
|
72
125
|
return { tag: "p", attrs, children: [text] };
|
|
73
126
|
},
|
|
74
127
|
},
|
|
@@ -101,7 +154,7 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
101
154
|
if (!src) return undefined;
|
|
102
155
|
const alt = props<{ decorative?: boolean }>(node).decorative
|
|
103
156
|
? ""
|
|
104
|
-
: post.featuredImageAlt?.trim() || post.title || "Featured image";
|
|
157
|
+
: post.featuredImageAlt?.trim() || post.title?.trim() || "Featured image";
|
|
105
158
|
// W-440: a Loop's images below the fold loaded all at once; like Image, they wait.
|
|
106
159
|
// A single post's featured image is usually the hero, so it isn't delayed.
|
|
107
160
|
const lazy: Attrs = inLoop ? { loading: "lazy", decoding: "async" } : {};
|
|
@@ -146,12 +199,15 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
146
199
|
{
|
|
147
200
|
placeholder: (attrs) => ({ tag: "time", attrs, children: ["Post date"] }),
|
|
148
201
|
has: (post) => !!post.publishedAt?.trim(),
|
|
149
|
-
render: (node, attrs, post) => {
|
|
202
|
+
render: (node, attrs, post, _inLoop, lang) => {
|
|
150
203
|
const raw = post.publishedAt?.trim();
|
|
151
204
|
if (!raw) return undefined;
|
|
152
205
|
const parsed = parseIsoDate(raw);
|
|
153
206
|
const format = props<{ format?: PostDateFormat }>(node).format ?? "medium";
|
|
154
|
-
|
|
207
|
+
// W-700: whole characters, so a long free-text date doesn't end in half an emoji.
|
|
208
|
+
const text = Number.isNaN(parsed)
|
|
209
|
+
? clipText(raw, 80)
|
|
210
|
+
: formatPostDate(parsed, format, lang);
|
|
155
211
|
// W-196: `datetime` must be machine-readable, so a date we can't read only shows as text.
|
|
156
212
|
const timeAttrs = Number.isNaN(parsed) ? attrs : { ...attrs, datetime: raw.slice(0, 80) };
|
|
157
213
|
return { tag: "time", attrs: timeAttrs, children: [text] };
|
|
@@ -165,7 +221,7 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
165
221
|
has: (post) => !!post.authorName?.trim(),
|
|
166
222
|
render: (_node, attrs, post) => {
|
|
167
223
|
const name = post.authorName?.trim();
|
|
168
|
-
return name ? { tag: "span", attrs, children: [name
|
|
224
|
+
return name ? { tag: "span", attrs, children: [clipText(name, 200)] } : undefined;
|
|
169
225
|
},
|
|
170
226
|
},
|
|
171
227
|
],
|
|
@@ -180,11 +236,13 @@ export function renderDynamicPost(
|
|
|
180
236
|
post: ThemePostFields | undefined,
|
|
181
237
|
mode: RenderMode,
|
|
182
238
|
inLoop = false,
|
|
239
|
+
/** The page's language, e.g. "fr-CA", for dates (W-688). */
|
|
240
|
+
lang?: string,
|
|
183
241
|
): VNode | undefined {
|
|
184
242
|
const field = POST_FIELDS.get(node.type);
|
|
185
243
|
if (!field) return undefined;
|
|
186
244
|
if (!post || field.has?.(post) === false) {
|
|
187
245
|
return mode === "editor" ? field.placeholder(attrs) : undefined;
|
|
188
246
|
}
|
|
189
|
-
return field.render(node, attrs, post, inLoop);
|
|
247
|
+
return field.render(node, attrs, post, inLoop, lang);
|
|
190
248
|
}
|
|
@@ -46,9 +46,49 @@ function childrenOf(node: LayoutNode): LayoutNode[] {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/** A link, a button, or a box that is already a link. */
|
|
49
|
+
/**
|
|
50
|
+
* W-668: elements that always render a link, control or embed. A linked box around one of these
|
|
51
|
+
* nested an <a> in an <a> (the browser then splits the box apart) or put a menu, form field,
|
|
52
|
+
* accordion toggle or video player inside a link.
|
|
53
|
+
*/
|
|
54
|
+
const ALWAYS_INTERACTIVE = new Set([
|
|
55
|
+
"link",
|
|
56
|
+
"post-link",
|
|
57
|
+
"button",
|
|
58
|
+
"menu",
|
|
59
|
+
"menu-item",
|
|
60
|
+
"accordion",
|
|
61
|
+
"accordion-item",
|
|
62
|
+
"tabs",
|
|
63
|
+
"video",
|
|
64
|
+
"form",
|
|
65
|
+
"text-input",
|
|
66
|
+
"textarea",
|
|
67
|
+
"select",
|
|
68
|
+
"checkbox",
|
|
69
|
+
"radio",
|
|
70
|
+
"submit",
|
|
71
|
+
"pagination",
|
|
72
|
+
"toc",
|
|
73
|
+
// Post content can hold links of its own.
|
|
74
|
+
"post-content",
|
|
75
|
+
]);
|
|
76
|
+
|
|
49
77
|
function containsInteractive(node: LayoutNode): boolean {
|
|
50
|
-
if (
|
|
51
|
-
|
|
78
|
+
if (ALWAYS_INTERACTIVE.has(node.type)) return true;
|
|
79
|
+
const props = node.props as { partId?: unknown; itemPartId?: unknown };
|
|
80
|
+
// A synced section or Loop Item part is another layout this check can't see into.
|
|
81
|
+
if (node.type === "section" && typeof props.partId === "string" && props.partId.trim())
|
|
82
|
+
return true;
|
|
83
|
+
if (node.type === "loop" && typeof props.itemPartId === "string" && props.itemPartId.trim()) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (
|
|
87
|
+
BOX.has(node.type) ||
|
|
88
|
+
node.type === "heading" ||
|
|
89
|
+
node.type === "icon" ||
|
|
90
|
+
node.type === "image"
|
|
91
|
+
) {
|
|
52
92
|
const href = (node.props as { href?: unknown }).href;
|
|
53
93
|
if (typeof href === "string" && href.trim()) return true;
|
|
54
94
|
}
|
|
@@ -59,6 +99,26 @@ function containsInteractive(node: LayoutNode): boolean {
|
|
|
59
99
|
* A div box becomes the link. A landmark tag stays a landmark. A link already inside the box
|
|
60
100
|
* keeps the box from becoming a link, so the page never nests anchors.
|
|
61
101
|
*/
|
|
102
|
+
/**
|
|
103
|
+
* W-669: a box with a working Link that still renders as a box because something inside it is a
|
|
104
|
+
* link, control or embed. The editor says so; the Link otherwise did nothing without a word.
|
|
105
|
+
*/
|
|
106
|
+
export function boxLinkHeldBack(node: LayoutNode): boolean {
|
|
107
|
+
if (!BOX.has(node.type)) return false;
|
|
108
|
+
const href = (node.props as { href?: unknown }).href;
|
|
109
|
+
if (typeof href !== "string" || !href.trim() || !sanitizeHref(href)) return false;
|
|
110
|
+
return childrenOf(node).some(containsInteractive);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** W-798: the same test applyBoxLink makes, for checks that see only the layout (the audit). */
|
|
114
|
+
export function boxBecomesLink(node: LayoutNode): boolean {
|
|
115
|
+
if (!BOX.has(node.type)) return false;
|
|
116
|
+
const { href, tag } = node.props as { href?: unknown; tag?: unknown };
|
|
117
|
+
if (tag !== undefined && tag !== "div") return false;
|
|
118
|
+
if (typeof href !== "string" || !href.trim() || !sanitizeHref(href)) return false;
|
|
119
|
+
return !childrenOf(node).some(containsInteractive);
|
|
120
|
+
}
|
|
121
|
+
|
|
62
122
|
export function applyBoxLink(node: LayoutNode, vnode: VNode): VNode {
|
|
63
123
|
if (!BOX.has(node.type) || vnode.tag !== "div") return vnode;
|
|
64
124
|
const { href, newTab } = node.props as { href?: string; newTab?: boolean };
|
|
@@ -66,7 +126,11 @@ export function applyBoxLink(node: LayoutNode, vnode: VNode): VNode {
|
|
|
66
126
|
if (childrenOf(node).some(containsInteractive)) return vnode;
|
|
67
127
|
const safe = sanitizeHref(href);
|
|
68
128
|
if (!safe) return vnode;
|
|
69
|
-
const attrs: Record<string, string> = {
|
|
129
|
+
const attrs: Record<string, string> = {
|
|
130
|
+
...vnode.attrs,
|
|
131
|
+
class: `${vnode.attrs.class ?? ""} emvb-box-link`.trim(),
|
|
132
|
+
href: safe,
|
|
133
|
+
};
|
|
70
134
|
if (newTab) {
|
|
71
135
|
attrs.target = "_blank";
|
|
72
136
|
attrs.rel = "noopener noreferrer";
|
|
@@ -89,7 +153,16 @@ export function applyBackgroundVideo(vnode: VNode, src: string | undefined): VNo
|
|
|
89
153
|
children: [
|
|
90
154
|
{
|
|
91
155
|
tag: "video",
|
|
92
|
-
|
|
156
|
+
// W-801: decoration, not content, so screen readers skip it.
|
|
157
|
+
attrs: {
|
|
158
|
+
class: "emvb-bg-video",
|
|
159
|
+
src,
|
|
160
|
+
muted: "",
|
|
161
|
+
loop: "",
|
|
162
|
+
playsinline: "",
|
|
163
|
+
autoplay: "",
|
|
164
|
+
"aria-hidden": "true",
|
|
165
|
+
},
|
|
93
166
|
children: [],
|
|
94
167
|
},
|
|
95
168
|
...vnode.children,
|