@phis/ui 0.4.5 → 0.4.6
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/components/cms/phi-cms-root-layout.js +1 -1
- package/components/controls/phi-button-control.d.ts +3 -1
- package/components/controls/phi-button-control.js +2 -2
- package/components/controls/phi-collapse-control.d.ts +6 -2
- package/components/controls/phi-collapse-control.js +2 -2
- package/components/controls/phi-dialog-control.d.ts +11 -5
- package/components/controls/phi-dialog-control.js +19 -13
- package/components/controls/phi-menu-control-vocabulary.d.ts +7 -0
- package/components/controls/phi-menu-control-vocabulary.js +10 -0
- package/components/controls/phi-menu-control.d.ts +4 -1
- package/components/controls/phi-menu-control.js +6 -1
- package/components/layouts/clients/phi-split-card-layout-client.js +13 -5
- package/components/layouts/clients/phi-three-column-layout-client.js +9 -3
- package/components/layouts/split-card-geometry.js +6 -2
- package/components/media/aspect-ratios.d.ts +2 -2
- package/components/menus/phi-account-menu.js +3 -1
- package/components/navigation/phi-link.js +7 -2
- package/components/navigation/use-phi-protected-mail.d.ts +11 -0
- package/components/navigation/use-phi-protected-mail.js +29 -0
- package/components/regions/clients/cms-region-container-client.js +5 -1
- package/components/regions/phi-cms-region-shell.d.ts +1 -0
- package/components/regions/phi-cms-region-shell.js +11 -0
- package/components/regions/presets/phi-area-shell-preset-nodes.js +2 -1
- package/components/root/phi-config-provider.js +16 -0
- package/components/shell/phi-cms-shell.d.ts +3 -1
- package/components/shell/phi-cms-shell.js +7 -3
- package/components/shell/phi-nav-link.js +7 -2
- package/components/shell/phi-shell-sider-drawer.d.ts +17 -0
- package/components/shell/phi-shell-sider-drawer.js +88 -0
- package/components/widgets/helpers/internal-reference-resolver.server.d.ts +1 -0
- package/components/widgets/helpers/internal-reference-resolver.server.js +4 -1
- package/components/widgets/label-sets/inspector.js +2 -0
- package/components/widgets/label-types/inspector.d.ts +2 -0
- package/components/widgets/label-types/inspector.js +1 -0
- package/components/widgets/server/navigation-request.js +13 -1
- package/components/widgets/shared/card-body-client.d.ts +2 -0
- package/components/widgets/shared/card-body-client.js +8 -7
- package/components/widgets/shared/card-vocabulary.d.ts +36 -0
- package/components/widgets/shared/card-vocabulary.js +52 -0
- package/components/widgets/shared/markdown-body-client.d.ts +29 -0
- package/components/widgets/shared/markdown-body-client.js +60 -5
- package/components/widgets/shared/markdown-image-vocabulary.d.ts +31 -0
- package/components/widgets/shared/markdown-image-vocabulary.js +68 -0
- package/components/widgets/shared/markdown-render.d.ts +5 -0
- package/components/widgets/shared/markdown-render.js +123 -8
- package/components/widgets/shared/markdown-sections.d.ts +40 -0
- package/components/widgets/shared/markdown-sections.js +111 -0
- package/helpers/external-href.js +1 -1
- package/helpers/protected-mail.d.ts +16 -0
- package/helpers/protected-mail.js +81 -0
- package/package.json +2 -2
- package/plugins/runtime-modules/builder/clients/region-inspector.js +20 -1
- package/plugins/runtime-modules/core/widgets/card/config.d.ts +8 -1
- package/plugins/runtime-modules/core/widgets/card/config.js +22 -1
- package/plugins/runtime-modules/core/widgets/card/editor.js +9 -1
- package/plugins/runtime-modules/core/widgets/card/server.js +9 -1
- package/plugins/runtime-modules/core/widgets/entry-list/view.server.js +2 -1
- package/plugins/runtime-modules/core/widgets/gallery/config.d.ts +3 -3
- package/plugins/runtime-modules/core/widgets/header-navigation/client.d.ts +6 -1
- package/plugins/runtime-modules/core/widgets/header-navigation/client.js +40 -13
- package/plugins/runtime-modules/core/widgets/header-navigation/config.d.ts +26 -1
- package/plugins/runtime-modules/core/widgets/header-navigation/config.js +27 -0
- package/plugins/runtime-modules/core/widgets/header-navigation/plugin.js +1 -1
- package/plugins/runtime-modules/core/widgets/header-navigation/server.d.ts +2 -2
- package/plugins/runtime-modules/core/widgets/header-navigation/server.js +3 -1
- package/plugins/runtime-modules/core/widgets/image/client.js +11 -7
- package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +16 -0
- package/plugins/runtime-modules/core/widgets/markdown/config.js +46 -1
- package/plugins/runtime-modules/core/widgets/markdown/server.js +22 -8
- package/plugins/runtime-modules/core/widgets/simple-text/server.js +11 -1
- package/styles/controls.css +108 -10
- package/styles/layout.css +35 -0
- package/styles/shell.css +142 -0
- package/theme/phi-tokens.d.ts +6 -0
- package/theme/phi-tokens.js +6 -0
- package/theme.d.ts +1 -0
- package/theme.js +6 -0
- package/types/core-widget-placements.d.ts +5 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useLayoutEffect, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { usePhiPathname } from "../runtime/use-phi-pathname";
|
|
6
|
+
import { PhiButtonControl } from "../controls/phi-button-control";
|
|
7
|
+
import { PhiIcon } from "./phi-icon";
|
|
8
|
+
/** Where the drawer's top stands within the Shell, published on the Shell element (`styles/shell.css`). */
|
|
9
|
+
const PHI_SHELL_SIDER_DRAWER_TOP_PROPERTY = "--phi-shell-sider-drawer-top";
|
|
10
|
+
/**
|
|
11
|
+
* A `sider_left` with `MobileDrawer`, on a phone: the menu button that opens it, the mask behind it, and
|
|
12
|
+
* the rules that close it again (SHELL.md "The Sider on a phone").
|
|
13
|
+
*
|
|
14
|
+
* The Sider itself does not move. `styles/shell.css` takes it out of its column below 768px and stands it
|
|
15
|
+
* at the inline start, off screen until the Shell says `data-phi-sider-drawer-open`; this component only
|
|
16
|
+
* says so. The Region keeps rendering where it always renders -- statically or through its own client --
|
|
17
|
+
* so nothing it holds is mounted twice.
|
|
18
|
+
*
|
|
19
|
+
* **The Shell is a container**, and a container is the containing block of what is `position: fixed`
|
|
20
|
+
* inside it: the drawer's top is the Shell's, not the viewport's. So the page stops scrolling while the
|
|
21
|
+
* drawer is open, and the drawer is moved to where the viewport's top is on the Shell at that moment.
|
|
22
|
+
*
|
|
23
|
+
* The button goes into `header_main`, at its inline start; a Shell without one gets it at its own top.
|
|
24
|
+
* Opening needs JavaScript: without it the Sider stays off screen on a phone.
|
|
25
|
+
*/
|
|
26
|
+
export function PhiShellSiderDrawer() {
|
|
27
|
+
const pathname = usePhiPathname();
|
|
28
|
+
const [shell, setShell] = useState(null);
|
|
29
|
+
/*
|
|
30
|
+
* The Page the drawer was opened on. Following a link to another Page closes it without an effect
|
|
31
|
+
* having to notice the navigation: on the new path it is simply not open.
|
|
32
|
+
*/
|
|
33
|
+
const [openedOn, setOpenedOn] = useState(null);
|
|
34
|
+
const open = openedOn != null && openedOn === pathname;
|
|
35
|
+
const close = useCallback(() => setOpenedOn(null), []);
|
|
36
|
+
const anchorRef = useCallback((node) => {
|
|
37
|
+
setShell(node?.closest("[data-phi-shell-layout]") ?? null);
|
|
38
|
+
}, []);
|
|
39
|
+
const sider = shell?.querySelector('[data-phi-sider-mobile="drawer"]') ?? null;
|
|
40
|
+
const header = shell?.querySelector('[data-phi-region-key="header_main"]') ?? null;
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
if (!shell)
|
|
43
|
+
return;
|
|
44
|
+
if (!open) {
|
|
45
|
+
shell.removeAttribute("data-phi-sider-drawer-open");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const root = document.documentElement;
|
|
49
|
+
const previousOverflow = root.style.overflow;
|
|
50
|
+
root.style.overflow = "hidden";
|
|
51
|
+
shell.style.setProperty(PHI_SHELL_SIDER_DRAWER_TOP_PROPERTY, `${-shell.getBoundingClientRect().top}px`);
|
|
52
|
+
shell.setAttribute("data-phi-sider-drawer-open", "true");
|
|
53
|
+
return () => {
|
|
54
|
+
root.style.overflow = previousOverflow;
|
|
55
|
+
shell.removeAttribute("data-phi-sider-drawer-open");
|
|
56
|
+
shell.style.removeProperty(PHI_SHELL_SIDER_DRAWER_TOP_PROPERTY);
|
|
57
|
+
};
|
|
58
|
+
}, [open, shell]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (!open || !sider)
|
|
61
|
+
return;
|
|
62
|
+
const onKeyDown = (event) => {
|
|
63
|
+
if (event.key === "Escape")
|
|
64
|
+
close();
|
|
65
|
+
};
|
|
66
|
+
// A link chosen in the drawer is where the reader is going; one to the Page they are on goes nowhere.
|
|
67
|
+
const onClick = (event) => {
|
|
68
|
+
if (event.target instanceof Element && event.target.closest("a[href]"))
|
|
69
|
+
close();
|
|
70
|
+
};
|
|
71
|
+
const previousTabIndex = sider.getAttribute("tabindex");
|
|
72
|
+
if (previousTabIndex == null)
|
|
73
|
+
sider.setAttribute("tabindex", "-1");
|
|
74
|
+
sider.focus({ preventScroll: true });
|
|
75
|
+
document.addEventListener("keydown", onKeyDown);
|
|
76
|
+
sider.addEventListener("click", onClick);
|
|
77
|
+
return () => {
|
|
78
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
79
|
+
sider.removeEventListener("click", onClick);
|
|
80
|
+
if (previousTabIndex == null)
|
|
81
|
+
sider.removeAttribute("tabindex");
|
|
82
|
+
};
|
|
83
|
+
}, [close, open, sider]);
|
|
84
|
+
const button = (_jsx("span", { className: header ? "phi-shell-sider-drawer-button" : "phi-shell-sider-drawer-button phi-shell-sider-drawer-button--shell", children: _jsx(PhiButtonControl, { type: "text", ariaLabel: open ? "Close menu" : "Open menu", ariaExpanded: open, icon: _jsx(PhiIcon, { name: open ? "close" : "menu", size: "inherit" }), onClick: () => setOpenedOn(open ? null : pathname) }) }));
|
|
85
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { hidden: true, ref: anchorRef }), shell ? createPortal(button, header ?? shell) : null, shell && open
|
|
86
|
+
? createPortal(_jsx("div", { "aria-hidden": true, className: "phi-shell-sider-drawer-mask", onClick: close }), shell)
|
|
87
|
+
: null] }));
|
|
88
|
+
}
|
|
@@ -69,5 +69,8 @@ export async function resolvePhiWidgetInternalReferences(input) {
|
|
|
69
69
|
// renderable and must not be re-filtered here.
|
|
70
70
|
const assetUrls = new Map([...projection.assets.values()]
|
|
71
71
|
.flatMap((asset) => asset.deliveryUrl ? [[asset.id, asset.deliveryUrl]] : []));
|
|
72
|
-
|
|
72
|
+
/* The whole public projection as well, for a reader that draws the picture and not only links it. */
|
|
73
|
+
const assets = new Map([...projection.assets.values()]
|
|
74
|
+
.flatMap((asset) => asset.deliveryUrl ? [[asset.id, asset]] : []));
|
|
75
|
+
return { pagePaths, assetUrls, assets };
|
|
73
76
|
}
|
|
@@ -32,6 +32,7 @@ const PHI_INSPECTOR_WIDGET_LABEL_SET = definePhiLabelSet({
|
|
|
32
32
|
region_visibility_always: PHI_INSPECTOR_WIDGET_DEFAULT_LABELS.regionVisibility.always,
|
|
33
33
|
region_visibility_hover: PHI_INSPECTOR_WIDGET_DEFAULT_LABELS.regionVisibility.hover,
|
|
34
34
|
region_hero_overlap: PHI_INSPECTOR_WIDGET_DEFAULT_LABELS.regionVisibility.heroOverlap,
|
|
35
|
+
region_sider_mobile_drawer: PHI_INSPECTOR_WIDGET_DEFAULT_LABELS.regionVisibility.siderMobileDrawer,
|
|
35
36
|
region_visibility_scroll_up: PHI_INSPECTOR_WIDGET_DEFAULT_LABELS.regionVisibility.scrollUp,
|
|
36
37
|
region_visibility_page_owned: definePhiMessageLabel(PHI_INSPECTOR_WIDGET_DEFAULT_LABELS.regionVisibility.pageOwned),
|
|
37
38
|
surface_style_title: PHI_INSPECTOR_WIDGET_DEFAULT_LABELS.surfaceStyle.title,
|
|
@@ -112,6 +113,7 @@ export async function getPhiInspectorWidgetLabels(options) {
|
|
|
112
113
|
scrollUp: labels.region_visibility_scroll_up,
|
|
113
114
|
pageOwned: labels.region_visibility_page_owned,
|
|
114
115
|
heroOverlap: labels.region_hero_overlap,
|
|
116
|
+
siderMobileDrawer: labels.region_sider_mobile_drawer,
|
|
115
117
|
},
|
|
116
118
|
surfaceStyle: {
|
|
117
119
|
title: labels.surface_style_title,
|
|
@@ -74,6 +74,8 @@ export type PhiInspectorRegionVisibilityLabels = {
|
|
|
74
74
|
pageOwned: string;
|
|
75
75
|
/** How far the Page's `content` reaches up into its Hero (`PhiCmsRegionConfig.heroOverlap`). */
|
|
76
76
|
heroOverlap: string;
|
|
77
|
+
/** `sider_left` opens as a drawer on a phone (`PhiCmsFlags.MobileDrawer`). */
|
|
78
|
+
siderMobileDrawer: string;
|
|
77
79
|
};
|
|
78
80
|
export type PhiInspectorLinkTargetLabels = {
|
|
79
81
|
none: string;
|
|
@@ -31,6 +31,7 @@ export const PHI_INSPECTOR_WIDGET_DEFAULT_LABELS = {
|
|
|
31
31
|
scrollUp: "When scrolling up",
|
|
32
32
|
pageOwned: "This Region belongs to its Page and stands on that Page alone.",
|
|
33
33
|
heroOverlap: "Reaches into the Hero",
|
|
34
|
+
siderMobileDrawer: "On a phone, opens from the menu button",
|
|
34
35
|
},
|
|
35
36
|
surfaceStyle: {
|
|
36
37
|
title: "Style",
|
|
@@ -5,6 +5,7 @@ import { isPhiCmsGatewayAuthError } from "../../../gateway/errors";
|
|
|
5
5
|
import { fetchSiteNavigationOverlay } from "../../../gateway/site-nav";
|
|
6
6
|
import { phiRuntime } from "../../../server-helpers/phi-runtime";
|
|
7
7
|
import { resolvePhiCmsReviewParams } from "../../../server-helpers/cms-review";
|
|
8
|
+
import { protectPhiMailHref } from "../../../helpers/protected-mail";
|
|
8
9
|
import { resolvePhiDescriptorNavigationItems, } from "../navigation-descriptor-resolver.server";
|
|
9
10
|
function resolvePhiNavigationRevisionFromRuntime(runtime) {
|
|
10
11
|
const rawNavRevision = runtime.request?.searchParams?.navRevision?.trim();
|
|
@@ -45,5 +46,16 @@ export async function resolvePhiNavigationItems(runtime, navKey) {
|
|
|
45
46
|
if (navRevision != null && overlay == null) {
|
|
46
47
|
return null;
|
|
47
48
|
}
|
|
48
|
-
return (await resolvePhiDescriptorNavigationItems(runtime, navKey, overlay)) ?? [];
|
|
49
|
+
return protectPhiNavMailHrefs((await resolvePhiDescriptorNavigationItems(runtime, navKey, overlay)) ?? []);
|
|
50
|
+
}
|
|
51
|
+
/*
|
|
52
|
+
* An entry that writes to somebody leaves here protected (`helpers/protected-mail.ts`): the items go to
|
|
53
|
+
* the client as props, and a `mailto:` in them stood in the page's payload for any crawler to read.
|
|
54
|
+
*/
|
|
55
|
+
function protectPhiNavMailHrefs(items) {
|
|
56
|
+
return items.map((item) => ({
|
|
57
|
+
...item,
|
|
58
|
+
...(item.href ? { href: protectPhiMailHref(item.href) } : {}),
|
|
59
|
+
...(item.children ? { children: protectPhiNavMailHrefs(item.children) } : {}),
|
|
60
|
+
}));
|
|
49
61
|
}
|
|
@@ -55,6 +55,8 @@ export type PhiCardWidgetImage = {
|
|
|
55
55
|
export type PhiCardWidgetClientConfig = {
|
|
56
56
|
surface?: PhiSurface | null;
|
|
57
57
|
image?: PhiCardWidgetImage | null;
|
|
58
|
+
/** The picture's box as CSS (`3 / 2`) where the card states one; absent, the variant's or the file's. */
|
|
59
|
+
mediaAspectRatio?: string | null;
|
|
58
60
|
iconName?: string;
|
|
59
61
|
iconPlacement?: PhiCardIconPlacement;
|
|
60
62
|
/** The icon's colour and its ground; absent, the Theme's. */
|
|
@@ -20,7 +20,7 @@ import { resolvePhiSurfaceStyle } from "../../../helpers/surface-style";
|
|
|
20
20
|
import { usePhiControlSignalController } from "../client/shared/phi-control-signals";
|
|
21
21
|
import { PHI_COLOR, PHI_SPACE } from "../../../theme/antd-css-var-contract";
|
|
22
22
|
import { PHI_THEME_HEADING_FONT_VARIABLE } from "../../../theme/phi-theme-typography";
|
|
23
|
-
import { PHI_CARD_TEXT_SLOTS, readPhiCardBillingPeriod } from "./card-vocabulary";
|
|
23
|
+
import { PHI_CARD_IMAGE_SIZES, PHI_CARD_TEXT_SLOTS, readPhiCardBillingPeriod } from "./card-vocabulary";
|
|
24
24
|
/**
|
|
25
25
|
* The layer over a card's picture. A colour or a gradient is drawn as CSS, each colour mixed down to the
|
|
26
26
|
* Overlay's opacity, so a Theme variable (`var(--ant-color-bg-container)`) resolves and the picture fades
|
|
@@ -282,9 +282,9 @@ export function PhiCardWidgetClient({ labels: placedLabels, config, binding, lis
|
|
|
282
282
|
const headingRow = iconPlacement === "inline" && iconName ? (_jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: justify, gap, ...slotWidth }, children: [iconMark(iconSize, inlineIconFrame), heading] })) : heading;
|
|
283
283
|
const media = image ? (_jsxs("div", { className: "phi-card__media", style: {
|
|
284
284
|
position: "relative",
|
|
285
|
-
aspectRatio: metrics.mediaAspectRatio ?? resolveMediaAspectRatio(image.presentation),
|
|
285
|
+
aspectRatio: config?.mediaAspectRatio ?? metrics.mediaAspectRatio ?? resolveMediaAspectRatio(image.presentation),
|
|
286
286
|
overflow: "hidden",
|
|
287
|
-
}, children: [_jsx(PhiImageControl, { presentation: image.presentation, source: image.source, alt: image.alt, blurDataUrl: image.blurDataUrl, optimizable: image.optimizable, style: { width: "100%", height: "100%" }, imageStyle: {
|
|
287
|
+
}, children: [_jsx(PhiImageControl, { presentation: image.presentation, source: image.source, alt: image.alt, blurDataUrl: image.blurDataUrl, optimizable: image.optimizable, sizes: PHI_CARD_IMAGE_SIZES, style: { width: "100%", height: "100%" }, imageStyle: {
|
|
288
288
|
width: "100%",
|
|
289
289
|
height: "100%",
|
|
290
290
|
...(image.opacity == null || image.opacity >= 1 ? {} : { opacity: image.opacity }),
|
|
@@ -336,11 +336,12 @@ export function PhiCardWidgetClient({ labels: placedLabels, config, binding, lis
|
|
|
336
336
|
...(highlight ? { "--phi-card-highlight-color": PHI_COLOR.primary } : {}),
|
|
337
337
|
};
|
|
338
338
|
/*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* stand in a column that fills the card, and the button takes what is left above
|
|
339
|
+
* The button stands at the card's foot, whatever the body: cards side by side in a Grid row are one
|
|
340
|
+
* height, their words are not, and their buttons belong on one line. The words keep their grid; the
|
|
341
|
+
* grid and the button stand in a column that fills the card, and the button takes what is left above
|
|
342
|
+
* it. A card standing alone is as tall as its content, so there the foot is right under the words.
|
|
342
343
|
*/
|
|
343
|
-
const footAction =
|
|
344
|
+
const footAction = action != null;
|
|
344
345
|
const actionButton = action ? (_jsx("div", { className: "phi-card__action",
|
|
345
346
|
/* At the foot, it stands where the words' alignment puts it, as it does among them. */
|
|
346
347
|
style: footAction ? { marginTop: "auto", alignSelf: textAlign === "center" ? "center" : textAlign === "end" ? "flex-end" : "flex-start" } : undefined, children: _jsx(PhiButtonControl, { ...(action.variant
|
|
@@ -70,6 +70,42 @@ export type PhiCardHoverEffect = (typeof PHI_CARD_HOVER_EFFECTS)[number];
|
|
|
70
70
|
*/
|
|
71
71
|
export declare const PHI_CARD_VARIANTS: readonly ["default", "compact", "center"];
|
|
72
72
|
export type PhiCardVariant = (typeof PHI_CARD_VARIANTS)[number];
|
|
73
|
+
/**
|
|
74
|
+
* How tall a card's picture stands, as a proportion of its width.
|
|
75
|
+
*
|
|
76
|
+
* `auto` is the proportion of the file the card shows. A Media picture that names no variant is shown as
|
|
77
|
+
* the Media library's Card variant (3:2, cropped around the picture's focal rectangle), so cards side by
|
|
78
|
+
* side stand at one height without anybody choosing one, and the browser gets a file sized for a card
|
|
79
|
+
* rather than the original. A picture that names a variant shows that variant and its proportion; one
|
|
80
|
+
* given by address, its own. `original` is the escape: the Media picture's original file, uncropped.
|
|
81
|
+
*
|
|
82
|
+
* `phi` is the golden rectangle, φ : 1 (`PHI_GOLDEN_RATIO`), between 3:2 and 16:9.
|
|
83
|
+
*
|
|
84
|
+
* A step crops whatever file the card shows into that box around the focal rectangle. 3:2 is the Card
|
|
85
|
+
* variant's own proportion, so it keeps taking that file; every other step shows the original, which the
|
|
86
|
+
* image optimiser scales to the card's width.
|
|
87
|
+
*/
|
|
88
|
+
export declare const PHI_CARD_MEDIA_ASPECT_RATIOS: readonly ["auto", "original", "phi", "3:2", "4:3", "16:9", "2:1", "1:1"];
|
|
89
|
+
export type PhiCardMediaAspectRatio = (typeof PHI_CARD_MEDIA_ASPECT_RATIOS)[number];
|
|
90
|
+
/** A step as a number, width over height; `auto` and `original` have none -- the file decides. */
|
|
91
|
+
export declare function resolvePhiCardMediaAspectRatioValue(ratio: PhiCardMediaAspectRatio | undefined): number | null;
|
|
92
|
+
/** A step as CSS writes it (`3 / 2`); `auto` and `original` have none. */
|
|
93
|
+
export declare function resolvePhiCardMediaAspectRatioCss(ratio: PhiCardMediaAspectRatio | undefined): string | null;
|
|
94
|
+
/**
|
|
95
|
+
* Which variant of a Media picture the card shows: the one the card names, else the Card variant where the
|
|
96
|
+
* box is the Card variant's own proportion (`auto`, `3:2`), else the original.
|
|
97
|
+
*/
|
|
98
|
+
export declare function resolvePhiCardImageVariantKey({ sourceKind, variantKey, mediaAspectRatio, }: {
|
|
99
|
+
sourceKind: string | undefined;
|
|
100
|
+
variantKey: number | null | undefined;
|
|
101
|
+
mediaAspectRatio: PhiCardMediaAspectRatio | undefined;
|
|
102
|
+
}): number | null;
|
|
103
|
+
/**
|
|
104
|
+
* How wide a card's picture is drawn, for the image optimiser: the window's width on a phone, where cards
|
|
105
|
+
* stand one under the other, and at most half of it beside another card. Without it the optimiser takes
|
|
106
|
+
* the file's own width -- a 1920 px original for a 350 px card.
|
|
107
|
+
*/
|
|
108
|
+
export declare const PHI_CARD_IMAGE_SIZES = "(max-width: 768px) 100vw, 50vw";
|
|
73
109
|
/**
|
|
74
110
|
* The words a card shows, each in its own place; what an editor can put a field in, and what a signal can
|
|
75
111
|
* write. `badge` is the band at the card's end edge, any body may carry one. The prices are figures like
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* The Card Widget's words, apart from its Client half: the Widget's definition is read on the server, and
|
|
3
3
|
* a value imported from the Client file would make that file a client reference of every route.
|
|
4
4
|
*/
|
|
5
|
+
import { PhiImageAssetVariantKey } from "../../../constants/media";
|
|
6
|
+
import { PHI_GOLDEN_RATIO } from "../../../theme/phi-tokens";
|
|
5
7
|
/**
|
|
6
8
|
* Which of a plan card's two prices it shows. A plan states one, the other, or both; one that states
|
|
7
9
|
* only the monthly price shows it under `yearly` as well, so a period switch on the page never leaves a
|
|
@@ -52,6 +54,56 @@ export const PHI_CARD_HOVER_EFFECTS = ["none", "lift", "zoom", "icon"];
|
|
|
52
54
|
* not another branch in every size the card draws. `default` is what a card without one is.
|
|
53
55
|
*/
|
|
54
56
|
export const PHI_CARD_VARIANTS = ["default", "compact", "center"];
|
|
57
|
+
/**
|
|
58
|
+
* How tall a card's picture stands, as a proportion of its width.
|
|
59
|
+
*
|
|
60
|
+
* `auto` is the proportion of the file the card shows. A Media picture that names no variant is shown as
|
|
61
|
+
* the Media library's Card variant (3:2, cropped around the picture's focal rectangle), so cards side by
|
|
62
|
+
* side stand at one height without anybody choosing one, and the browser gets a file sized for a card
|
|
63
|
+
* rather than the original. A picture that names a variant shows that variant and its proportion; one
|
|
64
|
+
* given by address, its own. `original` is the escape: the Media picture's original file, uncropped.
|
|
65
|
+
*
|
|
66
|
+
* `phi` is the golden rectangle, φ : 1 (`PHI_GOLDEN_RATIO`), between 3:2 and 16:9.
|
|
67
|
+
*
|
|
68
|
+
* A step crops whatever file the card shows into that box around the focal rectangle. 3:2 is the Card
|
|
69
|
+
* variant's own proportion, so it keeps taking that file; every other step shows the original, which the
|
|
70
|
+
* image optimiser scales to the card's width.
|
|
71
|
+
*/
|
|
72
|
+
export const PHI_CARD_MEDIA_ASPECT_RATIOS = ["auto", "original", "phi", "3:2", "4:3", "16:9", "2:1", "1:1"];
|
|
73
|
+
/** A step as a number, width over height; `auto` and `original` have none -- the file decides. */
|
|
74
|
+
export function resolvePhiCardMediaAspectRatioValue(ratio) {
|
|
75
|
+
if (ratio == null || ratio === "auto" || ratio === "original")
|
|
76
|
+
return null;
|
|
77
|
+
if (ratio === "phi")
|
|
78
|
+
return PHI_GOLDEN_RATIO;
|
|
79
|
+
const [width, height] = ratio.split(":").map(Number);
|
|
80
|
+
return width / height;
|
|
81
|
+
}
|
|
82
|
+
/** A step as CSS writes it (`3 / 2`); `auto` and `original` have none. */
|
|
83
|
+
export function resolvePhiCardMediaAspectRatioCss(ratio) {
|
|
84
|
+
if (ratio == null || ratio === "auto" || ratio === "original")
|
|
85
|
+
return null;
|
|
86
|
+
return ratio === "phi" ? `${PHI_GOLDEN_RATIO.toFixed(6)} / 1` : ratio.replace(":", " / ");
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Which variant of a Media picture the card shows: the one the card names, else the Card variant where the
|
|
90
|
+
* box is the Card variant's own proportion (`auto`, `3:2`), else the original.
|
|
91
|
+
*/
|
|
92
|
+
export function resolvePhiCardImageVariantKey({ sourceKind, variantKey, mediaAspectRatio, }) {
|
|
93
|
+
if (sourceKind !== "asset")
|
|
94
|
+
return null;
|
|
95
|
+
if (variantKey != null)
|
|
96
|
+
return variantKey;
|
|
97
|
+
return mediaAspectRatio == null || mediaAspectRatio === "auto" || mediaAspectRatio === "3:2"
|
|
98
|
+
? PhiImageAssetVariantKey.Card
|
|
99
|
+
: null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* How wide a card's picture is drawn, for the image optimiser: the window's width on a phone, where cards
|
|
103
|
+
* stand one under the other, and at most half of it beside another card. Without it the optimiser takes
|
|
104
|
+
* the file's own width -- a 1920 px original for a 350 px card.
|
|
105
|
+
*/
|
|
106
|
+
export const PHI_CARD_IMAGE_SIZES = "(max-width: 768px) 100vw, 50vw";
|
|
55
107
|
/**
|
|
56
108
|
* The words a card shows, each in its own place; what an editor can put a field in, and what a signal can
|
|
57
109
|
* write. `badge` is the band at the card's end edge, any body may carry one. The prices are figures like
|
|
@@ -3,10 +3,18 @@ import type { PhiCodeToken } from "./markdown-code-tokens";
|
|
|
3
3
|
import type { PhiMarkdownImageFloat, PhiMarkdownTextAlign } from "../../../types/core-widget-placements";
|
|
4
4
|
import { type PhiSpacingScaleKey } from "../config/spacing-options";
|
|
5
5
|
import type { PhiMarkdownTocHeading } from "../../../types/markdown";
|
|
6
|
+
import { type PhiMarkdownFoldSections } from "./markdown-sections";
|
|
7
|
+
import type { PhiImagePresentation } from "../../media/image-presentation";
|
|
8
|
+
import { type PhiMarkdownFigureFloat } from "./markdown-image-vocabulary";
|
|
6
9
|
import { type PhiBulletListStyle } from "./bullet-list-vocabulary";
|
|
7
10
|
export type PhiMarkdownInline = {
|
|
8
11
|
kind: "text";
|
|
9
12
|
text: string;
|
|
13
|
+
}
|
|
14
|
+
/** An address in the text, protected (`helpers/protected-mail.ts`) and written in once mounted. */
|
|
15
|
+
| {
|
|
16
|
+
kind: "mail_text";
|
|
17
|
+
token: string;
|
|
10
18
|
} | {
|
|
11
19
|
kind: "strong";
|
|
12
20
|
children: PhiMarkdownInline[];
|
|
@@ -33,6 +41,20 @@ export type PhiMarkdownInline = {
|
|
|
33
41
|
kind: "break";
|
|
34
42
|
};
|
|
35
43
|
export type PhiMarkdownTableAlign = "left" | "center" | "right" | null;
|
|
44
|
+
/**
|
|
45
|
+
* A Media picture standing on its own in the text, resolved on the server (`markdown-render.ts`): which
|
|
46
|
+
* bytes and how they are framed, the box it stands in, and where it stands.
|
|
47
|
+
*/
|
|
48
|
+
export type PhiMarkdownFigure = {
|
|
49
|
+
presentation: PhiImagePresentation;
|
|
50
|
+
alt: string;
|
|
51
|
+
title?: string;
|
|
52
|
+
blurDataUrl: string | null;
|
|
53
|
+
optimizable: boolean;
|
|
54
|
+
/** The box as CSS (`16 / 9`) where a step was chosen; `null` is the picture's own proportion. */
|
|
55
|
+
aspectRatio: string | null;
|
|
56
|
+
float: PhiMarkdownFigureFloat;
|
|
57
|
+
};
|
|
36
58
|
export type PhiMarkdownBlock = {
|
|
37
59
|
kind: "heading";
|
|
38
60
|
id: string;
|
|
@@ -67,6 +89,9 @@ export type PhiMarkdownBlock = {
|
|
|
67
89
|
align: PhiMarkdownTableAlign[];
|
|
68
90
|
} | {
|
|
69
91
|
kind: "divider";
|
|
92
|
+
} | {
|
|
93
|
+
kind: "image";
|
|
94
|
+
image: PhiMarkdownFigure;
|
|
70
95
|
};
|
|
71
96
|
export type PhiMarkdownWidgetClientProps = PhiClientBlockBaseProps<PhiNoLabels, {
|
|
72
97
|
blocks: PhiMarkdownBlock[];
|
|
@@ -82,5 +107,9 @@ export type PhiMarkdownWidgetClientProps = PhiClientBlockBaseProps<PhiNoLabels,
|
|
|
82
107
|
headingBlockSpacingAfter?: PhiSpacingScaleKey;
|
|
83
108
|
/** How the text's lists are set (`bullet-list-vocabulary.ts`). */
|
|
84
109
|
list?: PhiBulletListStyle;
|
|
110
|
+
/** Whether the text's `##` sections fold (`markdown-sections.ts`); absent, `none`. */
|
|
111
|
+
foldSections?: PhiMarkdownFoldSections;
|
|
112
|
+
/** How far the text's headings moved down, which moves the level that folds with them. */
|
|
113
|
+
headingOffset?: number;
|
|
85
114
|
}>;
|
|
86
115
|
export declare function PhiMarkdownWidgetClient({ config }: PhiMarkdownWidgetClientProps): import("react").JSX.Element | null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { Fragment, useEffect, useMemo } from "react";
|
|
3
|
+
import { Fragment, useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { PhiProtectedMailText } from "../../navigation/use-phi-protected-mail";
|
|
4
5
|
import { PhiLink } from "../../navigation/phi-link";
|
|
5
6
|
import { PHI_SIGNAL_VALUE_SCHEMAS } from "../../../types/signals";
|
|
6
7
|
import { usePhiSignalEmitter } from "../../runtime/runtime-signal-identity";
|
|
@@ -11,6 +12,10 @@ import { PhiPlainTable } from "../../tables/phi-plain-table";
|
|
|
11
12
|
import { PhiTypographyControl } from "../../controls/phi-typography-control";
|
|
12
13
|
import { PhiDividerControl } from "../../controls/phi-divider-control";
|
|
13
14
|
import { PhiBulletListControl } from "../../controls/phi-bullet-list-control";
|
|
15
|
+
import { PhiImageControl } from "../../controls/phi-image-control";
|
|
16
|
+
import { PhiCollapseControl } from "../../controls/phi-collapse-control";
|
|
17
|
+
import { resolvePhiMarkdownFoldLevel, splitPhiMarkdownSegments, } from "./markdown-sections";
|
|
18
|
+
import { resolvePhiMarkdownFigureSizes } from "./markdown-image-vocabulary";
|
|
14
19
|
import { resolvePhiBulletListStyle, } from "./bullet-list-vocabulary";
|
|
15
20
|
/**
|
|
16
21
|
* The colour a kind of code is drawn in, from the Theme and from nowhere else.
|
|
@@ -51,6 +56,8 @@ function renderInlineNodes(inlines) {
|
|
|
51
56
|
switch (inline.kind) {
|
|
52
57
|
case "text":
|
|
53
58
|
return _jsx(Fragment, { children: inline.text }, key);
|
|
59
|
+
case "mail_text":
|
|
60
|
+
return _jsx(PhiProtectedMailText, { token: inline.token }, key);
|
|
54
61
|
case "strong":
|
|
55
62
|
return _jsx("strong", { children: renderInlineNodes(inline.children) }, key);
|
|
56
63
|
case "emphasis":
|
|
@@ -83,6 +90,8 @@ function renderBlocks(blocks, token, paragraphStyle, headingStyle, lists, atStar
|
|
|
83
90
|
return (_jsx(PhiTypographyControl, { presentation: "title", id: block.id, level: block.level, style: headingBlockStyle, children: renderInlineNodes(block.inlines) }, key));
|
|
84
91
|
case "paragraph":
|
|
85
92
|
return (_jsx(PhiTypographyControl, { presentation: "paragraph", style: paragraphBlockStyle, children: renderInlineNodes(block.inlines) }, key));
|
|
93
|
+
case "image":
|
|
94
|
+
return _jsx(PhiMarkdownFigureBlock, { figure: block.image }, key);
|
|
86
95
|
case "blockquote":
|
|
87
96
|
return (_jsx("blockquote", { style: {
|
|
88
97
|
margin: 0,
|
|
@@ -186,6 +195,7 @@ export function PhiMarkdownWidgetClient({ config }) {
|
|
|
186
195
|
paddingBlockStart: resolvePhiSpacingScaleValue(config?.headingBlockSpacingBefore ?? "sm"),
|
|
187
196
|
marginBlockEnd: resolvePhiSpacingScaleValue(config?.headingBlockSpacingAfter ?? "sm"),
|
|
188
197
|
};
|
|
198
|
+
const lists = { style: resolvePhiBulletListStyle(config?.list), depth: 1 };
|
|
189
199
|
return (_jsx("div", { className: config?.imageFloat
|
|
190
200
|
? `phi-markdown-text phi-markdown-body phi-markdown-body--float-${config.imageFloat}`
|
|
191
201
|
: "phi-markdown-text",
|
|
@@ -193,8 +203,53 @@ export function PhiMarkdownWidgetClient({ config }) {
|
|
|
193
203
|
// browser's `normal`, and its marker centres on a line shorter than the one its words stand on.
|
|
194
204
|
style: config?.imageFloat
|
|
195
205
|
? { display: "flow-root", width: "100%", textAlign: config.textAlign, containerType: "inline-size", lineHeight: token.lineHeight }
|
|
196
|
-
: { display: "grid", gap: 0, width: "100%", textAlign: config?.textAlign, lineHeight: token.lineHeight }, children:
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
206
|
+
: { display: "grid", gap: 0, width: "100%", textAlign: config?.textAlign, lineHeight: token.lineHeight }, children: config?.foldSections && config.foldSections !== "none"
|
|
207
|
+
? splitPhiMarkdownSegments(blocks, resolvePhiMarkdownFoldLevel(config.headingOffset)).map((segment, index) => segment.kind === "text"
|
|
208
|
+
? _jsx(Fragment, { children: renderBlocks(segment.blocks, token, paragraphBlockStyle, headingBlockStyle, lists, index === 0) }, `text-${index}`)
|
|
209
|
+
: (_jsx(PhiMarkdownFoldedSections, { sections: segment.sections, accordion: config.foldSections === "accordion", renderBody: (sectionBlocks) => renderBlocks(sectionBlocks, token, paragraphBlockStyle, headingBlockStyle, lists, true) }, `sections-${index}`)))
|
|
210
|
+
: renderBlocks(blocks, token, paragraphBlockStyle, headingBlockStyle, lists, true) }));
|
|
211
|
+
}
|
|
212
|
+
/*
|
|
213
|
+
* The sections that fold: each heading is a header, what follows it the body. Every answer is drawn even
|
|
214
|
+
* while folded, so a search engine and the browser's own find read the whole text. A heading keeps its id,
|
|
215
|
+
* so the table of contents and a link to `#that-question` reach it -- and a link to it opens it, on arrival
|
|
216
|
+
* and whenever the address's fragment changes.
|
|
217
|
+
*/
|
|
218
|
+
function PhiMarkdownFoldedSections({ sections, accordion, renderBody, }) {
|
|
219
|
+
const [openKeys, setOpenKeys] = useState([]);
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
const openFromAddress = () => {
|
|
222
|
+
const id = decodeURIComponent(window.location.hash.slice(1));
|
|
223
|
+
if (!id)
|
|
224
|
+
return;
|
|
225
|
+
const section = sections.find((entry) => entry.heading.id === id || entry.blocks.some((block) => block.kind === "heading" && block.id === id));
|
|
226
|
+
if (!section)
|
|
227
|
+
return;
|
|
228
|
+
setOpenKeys((current) => accordion ? [section.heading.id] : [...new Set([...current, section.heading.id])]);
|
|
229
|
+
window.requestAnimationFrame(() => document.getElementById(id)?.scrollIntoView({ block: "start" }));
|
|
230
|
+
};
|
|
231
|
+
openFromAddress();
|
|
232
|
+
window.addEventListener("hashchange", openFromAddress);
|
|
233
|
+
return () => window.removeEventListener("hashchange", openFromAddress);
|
|
234
|
+
}, [accordion, sections]);
|
|
235
|
+
return (_jsx("div", { className: "phi-markdown-folds", children: _jsx(PhiCollapseControl, { sections: sections.map((section) => ({
|
|
236
|
+
key: section.heading.id,
|
|
237
|
+
label: (_jsx(PhiTypographyControl, { presentation: "title", id: section.heading.id, level: section.heading.level, style: { margin: 0 }, children: renderInlineNodes(section.heading.inlines) })),
|
|
238
|
+
children: renderBody(section.blocks),
|
|
239
|
+
forceRender: true,
|
|
240
|
+
})), openKeys: openKeys, onOpenKeysChange: setOpenKeys, accordion: accordion,
|
|
241
|
+
// A question is answered wherever its row is clicked, not only on its words.
|
|
242
|
+
collapsible: "row", ghost: true, expandIconPlacement: "end",
|
|
243
|
+
// Flush with the text around them: a question starts where a paragraph starts.
|
|
244
|
+
headerPadding: `${PHI_SPACE.sm} 0`, bodyPadding: `0 0 ${PHI_SPACE.sm}` }) }));
|
|
245
|
+
}
|
|
246
|
+
/*
|
|
247
|
+
* A picture standing on its own: a figure, so it is a block between the paragraphs and never a box inside
|
|
248
|
+
* one. The box is reserved from the start -- the chosen proportion, else the picture's own -- so the text
|
|
249
|
+
* does not jump when the bytes arrive, and its corners are the Theme's surface step (`styles/controls.css`).
|
|
250
|
+
*/
|
|
251
|
+
function PhiMarkdownFigureBlock({ figure }) {
|
|
252
|
+
const { presentation } = figure;
|
|
253
|
+
const ownRatio = presentation.width && presentation.height ? `${presentation.width} / ${presentation.height}` : undefined;
|
|
254
|
+
return (_jsx("figure", { className: `phi-markdown-figure phi-markdown-figure--float-${figure.float}`, children: _jsx("div", { className: "phi-markdown-figure__frame", style: { aspectRatio: figure.aspectRatio ?? ownRatio }, children: _jsx(PhiImageControl, { presentation: presentation, source: "asset", alt: figure.alt, title: figure.title, blurDataUrl: figure.blurDataUrl, optimizable: figure.optimizable, sizes: resolvePhiMarkdownFigureSizes(figure.float), style: { width: "100%", height: "100%" }, imageStyle: { width: "100%", height: "100%" } }) }) }));
|
|
200
255
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How tall a picture stands, as a proportion of its width. `auto` is the picture's own proportion -- a text
|
|
3
|
+
* shows what was put in it; a step crops into that box around the picture's focal rectangle. `phi` is the
|
|
4
|
+
* golden rectangle, φ : 1 (`PHI_GOLDEN_RATIO`), between 3:2 and 16:9.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PHI_MARKDOWN_IMAGE_ASPECT_RATIOS: readonly ["auto", "phi", "3:2", "4:3", "16:9", "2:1", "1:1"];
|
|
7
|
+
export type PhiMarkdownImageAspectRatio = (typeof PHI_MARKDOWN_IMAGE_ASPECT_RATIOS)[number];
|
|
8
|
+
/** Where a picture stands: at an edge with the text flowing past it, or on a line of its own (`none`). */
|
|
9
|
+
export declare const PHI_MARKDOWN_FIGURE_FLOATS: readonly ["start", "end", "none"];
|
|
10
|
+
export type PhiMarkdownFigureFloat = (typeof PHI_MARKDOWN_FIGURE_FLOATS)[number];
|
|
11
|
+
export declare function readPhiMarkdownImageAspectRatio(value: unknown): PhiMarkdownImageAspectRatio | undefined;
|
|
12
|
+
/** A step as a number, width over height; `auto` has none -- the picture decides. */
|
|
13
|
+
export declare function resolvePhiMarkdownImageAspectRatioValue(ratio: PhiMarkdownImageAspectRatio | undefined): number | null;
|
|
14
|
+
/** A step as CSS writes it (`16 / 9`); `auto` has none. */
|
|
15
|
+
export declare function resolvePhiMarkdownImageAspectRatioCss(ratio: PhiMarkdownImageAspectRatio | undefined): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* A picture's address read apart: the reference, and what the picture says for itself. Only `ratio` and
|
|
18
|
+
* `float` are read; anything else after the `?` is left out of the reference and ignored, so an address a
|
|
19
|
+
* later release learns more words for still names its Asset today.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readPhiMarkdownImageAddress(url: string): {
|
|
22
|
+
reference: string;
|
|
23
|
+
aspectRatio?: PhiMarkdownImageAspectRatio;
|
|
24
|
+
float?: PhiMarkdownFigureFloat;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* How wide a picture is drawn, for the image optimiser: beside the text its golden share of the column
|
|
28
|
+
* (`styles/controls.css`, about 0.38 of a reading column of at most 1120 px), on a line of its own the
|
|
29
|
+
* reading column's.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolvePhiMarkdownFigureSizes(float: PhiMarkdownFigureFloat): "(max-width: 768px) 100vw, 1120px" | "(max-width: 560px) 100vw, 440px";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* How a Markdown text sets its pictures, apart from the Widget's Client half: the render on the server and
|
|
3
|
+
* the Widget's definition read these, and a value imported from the Client file would make it a client
|
|
4
|
+
* reference of every route.
|
|
5
|
+
*
|
|
6
|
+
* Two places say it, and the nearer one wins. The Widget states what every picture in its text does -- the
|
|
7
|
+
* Inspector's "Image proportion" and "Image Float" -- and a picture that needs something else says so in its
|
|
8
|
+
* own address, after the Asset: ``. The address stays a
|
|
9
|
+
* `phis:asset/<id>` reference for everything that reads one (the server's reference index finds the id at
|
|
10
|
+
* its start), and it is plain Markdown, so a translation carries it through untouched.
|
|
11
|
+
*/
|
|
12
|
+
import { PHI_GOLDEN_RATIO } from "../../../theme/phi-tokens";
|
|
13
|
+
/**
|
|
14
|
+
* How tall a picture stands, as a proportion of its width. `auto` is the picture's own proportion -- a text
|
|
15
|
+
* shows what was put in it; a step crops into that box around the picture's focal rectangle. `phi` is the
|
|
16
|
+
* golden rectangle, φ : 1 (`PHI_GOLDEN_RATIO`), between 3:2 and 16:9.
|
|
17
|
+
*/
|
|
18
|
+
export const PHI_MARKDOWN_IMAGE_ASPECT_RATIOS = ["auto", "phi", "3:2", "4:3", "16:9", "2:1", "1:1"];
|
|
19
|
+
/** Where a picture stands: at an edge with the text flowing past it, or on a line of its own (`none`). */
|
|
20
|
+
export const PHI_MARKDOWN_FIGURE_FLOATS = ["start", "end", "none"];
|
|
21
|
+
export function readPhiMarkdownImageAspectRatio(value) {
|
|
22
|
+
return PHI_MARKDOWN_IMAGE_ASPECT_RATIOS.find((ratio) => ratio === value);
|
|
23
|
+
}
|
|
24
|
+
function readPhiMarkdownFigureFloat(value) {
|
|
25
|
+
return PHI_MARKDOWN_FIGURE_FLOATS.find((float) => float === value);
|
|
26
|
+
}
|
|
27
|
+
/** A step as a number, width over height; `auto` has none -- the picture decides. */
|
|
28
|
+
export function resolvePhiMarkdownImageAspectRatioValue(ratio) {
|
|
29
|
+
if (ratio == null || ratio === "auto")
|
|
30
|
+
return null;
|
|
31
|
+
if (ratio === "phi")
|
|
32
|
+
return PHI_GOLDEN_RATIO;
|
|
33
|
+
const [width, height] = ratio.split(":").map(Number);
|
|
34
|
+
return width / height;
|
|
35
|
+
}
|
|
36
|
+
/** A step as CSS writes it (`16 / 9`); `auto` has none. */
|
|
37
|
+
export function resolvePhiMarkdownImageAspectRatioCss(ratio) {
|
|
38
|
+
const value = resolvePhiMarkdownImageAspectRatioValue(ratio);
|
|
39
|
+
if (value == null)
|
|
40
|
+
return null;
|
|
41
|
+
return ratio === "phi" ? `${PHI_GOLDEN_RATIO.toFixed(6)} / 1` : ratio.replace(":", " / ");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A picture's address read apart: the reference, and what the picture says for itself. Only `ratio` and
|
|
45
|
+
* `float` are read; anything else after the `?` is left out of the reference and ignored, so an address a
|
|
46
|
+
* later release learns more words for still names its Asset today.
|
|
47
|
+
*/
|
|
48
|
+
export function readPhiMarkdownImageAddress(url) {
|
|
49
|
+
const question = url.indexOf("?");
|
|
50
|
+
if (question < 0)
|
|
51
|
+
return { reference: url };
|
|
52
|
+
const params = new URLSearchParams(url.slice(question + 1));
|
|
53
|
+
const aspectRatio = readPhiMarkdownImageAspectRatio(params.get("ratio"));
|
|
54
|
+
const float = readPhiMarkdownFigureFloat(params.get("float"));
|
|
55
|
+
return {
|
|
56
|
+
reference: url.slice(0, question),
|
|
57
|
+
...(aspectRatio ? { aspectRatio } : {}),
|
|
58
|
+
...(float ? { float } : {}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* How wide a picture is drawn, for the image optimiser: beside the text its golden share of the column
|
|
63
|
+
* (`styles/controls.css`, about 0.38 of a reading column of at most 1120 px), on a line of its own the
|
|
64
|
+
* reading column's.
|
|
65
|
+
*/
|
|
66
|
+
export function resolvePhiMarkdownFigureSizes(float) {
|
|
67
|
+
return float === "none" ? "(max-width: 768px) 100vw, 1120px" : "(max-width: 560px) 100vw, 440px";
|
|
68
|
+
}
|
|
@@ -2,6 +2,8 @@ import type { PhiBlockRuntime, PhiRenderableBlockRenderMode } from "../../../typ
|
|
|
2
2
|
import type { PhiCmsResolvedContent } from "../../../types/cms";
|
|
3
3
|
import type { PhiMarkdownTocHeading } from "../../../types/markdown";
|
|
4
4
|
import type { PhiMarkdownBlock } from "./markdown-body-client";
|
|
5
|
+
import type { PhiMarkdownImageFloat } from "../../../types/core-widget-placements";
|
|
6
|
+
import { type PhiMarkdownImageAspectRatio } from "./markdown-image-vocabulary";
|
|
5
7
|
/**
|
|
6
8
|
* Where Markdown comes from and how it is turned into blocks: inline text, a stored content field, or a
|
|
7
9
|
* document fetched by URL, translated or not, with heading ids under a prefix of its own.
|
|
@@ -32,6 +34,9 @@ export type PhiMarkdownSourceConfig = {
|
|
|
32
34
|
* header -- starts at `h2`, so `#` does not draw a second title of the same size. The level stops at 5.
|
|
33
35
|
*/
|
|
34
36
|
headingOffset?: number;
|
|
37
|
+
/** What every picture in the text does, unless its own address says otherwise (`markdown-image-vocabulary.ts`). */
|
|
38
|
+
imageAspectRatio?: PhiMarkdownImageAspectRatio;
|
|
39
|
+
imageFloat?: PhiMarkdownImageFloat;
|
|
35
40
|
};
|
|
36
41
|
export type MarkdownRenderData = {
|
|
37
42
|
blocks: PhiMarkdownBlock[];
|