@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
|
@@ -3,9 +3,13 @@ import { unified } from "unified";
|
|
|
3
3
|
import remarkParse from "remark-parse";
|
|
4
4
|
import remarkGfm from "remark-gfm";
|
|
5
5
|
import { trBulk, trBulkForLocale } from "../../../server-helpers/translate";
|
|
6
|
+
import { resolvePhiImagePresentation } from "../../media/image-presentation";
|
|
7
|
+
import { isPhiMediaSvgContentType } from "../../../constants/media";
|
|
8
|
+
import { readPhiMarkdownImageAddress, resolvePhiMarkdownImageAspectRatioCss, resolvePhiMarkdownImageAspectRatioValue, } from "./markdown-image-vocabulary";
|
|
6
9
|
import { resolvePhiCodeLanguage, tokenizePhiCode } from "./markdown-code-tokens";
|
|
7
10
|
import { readPhiInternalReference } from "../../../types/references";
|
|
8
11
|
import { resolvePhiWidgetInternalReferences } from "../helpers/internal-reference-resolver.server";
|
|
12
|
+
import { protectPhiMailHref, splitPhiMailAddresses } from "../../../helpers/protected-mail";
|
|
9
13
|
import { resolvePhiWidgetSourceUrl } from "../helpers/widget-source-url";
|
|
10
14
|
const MARKDOWN_DEFAULT_REVALIDATE_SECONDS = 14400;
|
|
11
15
|
function normalizeMarkdownSourceUrl(sourceUrl, publicUrl) {
|
|
@@ -107,10 +111,11 @@ function projectExternalMarkdownNodes(nodes, sourceUrl, pageUrl = readExternalDo
|
|
|
107
111
|
async function projectInternalMarkdownNodes(tree, runtime) {
|
|
108
112
|
const pageReferences = [];
|
|
109
113
|
const assetIds = [];
|
|
114
|
+
const figures = new Map();
|
|
110
115
|
const collect = (nodes) => {
|
|
111
116
|
for (const node of nodes ?? []) {
|
|
112
117
|
if (node.type === "link" || node.type === "image") {
|
|
113
|
-
const reference = readPhiInternalReference(node.url);
|
|
118
|
+
const reference = readPhiInternalReference(node.type === "image" ? readPhiMarkdownImageAddress(node.url ?? "").reference : node.url);
|
|
114
119
|
if (reference?.kind === "page")
|
|
115
120
|
pageReferences.push(reference.reference);
|
|
116
121
|
if (reference?.kind === "asset")
|
|
@@ -134,10 +139,23 @@ async function projectInternalMarkdownNodes(tree, runtime) {
|
|
|
134
139
|
return [{ ...node, children }];
|
|
135
140
|
}
|
|
136
141
|
if (node.type === "image") {
|
|
137
|
-
const
|
|
142
|
+
const address = readPhiMarkdownImageAddress(node.url ?? "");
|
|
143
|
+
const reference = readPhiInternalReference(address.reference);
|
|
138
144
|
if (reference?.kind === "asset") {
|
|
139
|
-
const
|
|
140
|
-
|
|
145
|
+
const asset = resolved.assets.get(reference.assetId);
|
|
146
|
+
if (!asset)
|
|
147
|
+
return [];
|
|
148
|
+
/*
|
|
149
|
+
* Each picture gets an address of its own, so two pictures of one Asset can say different things:
|
|
150
|
+
* the fragment never reaches the server, and it travels with the address through a translation.
|
|
151
|
+
*/
|
|
152
|
+
const src = `${asset.deliveryUrl}#phi-figure-${figures.size}`;
|
|
153
|
+
figures.set(src, {
|
|
154
|
+
asset,
|
|
155
|
+
...(address.aspectRatio ? { aspectRatio: address.aspectRatio } : {}),
|
|
156
|
+
...(address.float ? { float: address.float } : {}),
|
|
157
|
+
});
|
|
158
|
+
return [{ ...node, url: src, children }];
|
|
141
159
|
}
|
|
142
160
|
if (!/^https?:/iu.test(node.url ?? "") && !PHI_INLINE_IMAGE_DATA_URL.test(node.url ?? ""))
|
|
143
161
|
return [];
|
|
@@ -146,6 +164,57 @@ async function projectInternalMarkdownNodes(tree, runtime) {
|
|
|
146
164
|
return [{ ...node, ...(node.children ? { children } : {}) }];
|
|
147
165
|
});
|
|
148
166
|
tree.children = project(tree.children);
|
|
167
|
+
return figures;
|
|
168
|
+
}
|
|
169
|
+
/*
|
|
170
|
+
* A paragraph that is one Media picture and nothing else is a figure: a block of its own, drawn by the
|
|
171
|
+
* house's picture Control -- optimised, sized, its box reserved and its corners the Theme's. A picture in
|
|
172
|
+
* the middle of a sentence, or one on somebody else's server, stays the plain picture it was.
|
|
173
|
+
*/
|
|
174
|
+
function promoteMarkdownFigures(blocks, figures, defaults) {
|
|
175
|
+
if (figures.size === 0)
|
|
176
|
+
return blocks;
|
|
177
|
+
return blocks.map((block) => {
|
|
178
|
+
if (block.kind === "blockquote")
|
|
179
|
+
return { ...block, children: promoteMarkdownFigures(block.children, figures, defaults) };
|
|
180
|
+
if (block.kind === "list")
|
|
181
|
+
return { ...block, items: block.items.map((item) => promoteMarkdownFigures(item, figures, defaults)) };
|
|
182
|
+
if (block.kind !== "paragraph")
|
|
183
|
+
return block;
|
|
184
|
+
const content = block.inlines.filter((inline) => !(inline.kind === "text" && !inline.text.trim()));
|
|
185
|
+
const only = content.length === 1 ? content[0] : null;
|
|
186
|
+
const source = only?.kind === "image" ? figures.get(only.src) : undefined;
|
|
187
|
+
if (!only || only.kind !== "image" || !source)
|
|
188
|
+
return block;
|
|
189
|
+
return { kind: "image", image: buildMarkdownFigure(only, source, defaults) };
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function buildMarkdownFigure(image, source, defaults) {
|
|
193
|
+
const aspectRatio = source.aspectRatio ?? defaults.aspectRatio ?? "auto";
|
|
194
|
+
const frameAspectRatio = resolvePhiMarkdownImageAspectRatioValue(aspectRatio);
|
|
195
|
+
const { asset } = source;
|
|
196
|
+
const presentation = resolvePhiImagePresentation({
|
|
197
|
+
sourceKind: "asset",
|
|
198
|
+
assetId: asset.id,
|
|
199
|
+
variantKey: null,
|
|
200
|
+
variantVersion: asset.variantVersion,
|
|
201
|
+
deliveryRevision: asset.deliveryRevision,
|
|
202
|
+
originalUrl: asset.deliveryUrl,
|
|
203
|
+
focalRect: asset.focalRect,
|
|
204
|
+
sourceWidth: asset.width,
|
|
205
|
+
sourceHeight: asset.height,
|
|
206
|
+
frameAspectRatio,
|
|
207
|
+
});
|
|
208
|
+
return {
|
|
209
|
+
presentation,
|
|
210
|
+
alt: (image.alt || asset.altText || "").trim(),
|
|
211
|
+
...(image.title ? { title: image.title } : {}),
|
|
212
|
+
blurDataUrl: asset.blurDataUrl,
|
|
213
|
+
// Only a public Asset resolves here; the optimiser takes every original that is not an SVG.
|
|
214
|
+
optimizable: !isPhiMediaSvgContentType(asset.contentType),
|
|
215
|
+
aspectRatio: resolvePhiMarkdownImageAspectRatioCss(aspectRatio),
|
|
216
|
+
float: source.float ?? defaults.float ?? "none",
|
|
217
|
+
};
|
|
149
218
|
}
|
|
150
219
|
function mapInlineNodes(nodes) {
|
|
151
220
|
return (nodes ?? []).flatMap((node) => {
|
|
@@ -517,20 +586,24 @@ export async function resolveMarkdownRenderData(config, runtime) {
|
|
|
517
586
|
*/
|
|
518
587
|
config?.sourceLocale?.trim() || undefined, sourceMode, sourceMode === "url" && config?.sourceUrl
|
|
519
588
|
? normalizeMarkdownSourceUrl(config.sourceUrl, runtime?.site.publicUrl)
|
|
520
|
-
: null, runtime, config?.extent ?? "document", config?.headingOffset ?? 0
|
|
589
|
+
: null, runtime, config?.extent ?? "document", config?.headingOffset ?? 0, {
|
|
590
|
+
...(config?.imageAspectRatio ? { aspectRatio: config.imageAspectRatio } : {}),
|
|
591
|
+
...(config?.imageFloat ? { float: config.imageFloat } : {}),
|
|
592
|
+
});
|
|
521
593
|
}
|
|
522
|
-
async function resolveMarkdownRenderDataFromSource(markdown, translate, headingIdPrefix, sourceLocale, sourceMode = "inline", sourceUrl = null, runtime, extent = "document", headingOffset = 0) {
|
|
594
|
+
async function resolveMarkdownRenderDataFromSource(markdown, translate, headingIdPrefix, sourceLocale, sourceMode = "inline", sourceUrl = null, runtime, extent = "document", headingOffset = 0, imageDefaults = {}) {
|
|
523
595
|
const tree = parseMarkdown(markdown);
|
|
524
596
|
if (extent === "first-paragraph") {
|
|
525
597
|
// Cut by the parser's own reading, never by blank lines: a fence or a list may hold those too.
|
|
526
598
|
const paragraph = tree.children?.find((node) => node.type === "paragraph");
|
|
527
599
|
tree.children = paragraph ? [paragraph] : [];
|
|
528
600
|
}
|
|
601
|
+
let figures = new Map();
|
|
529
602
|
if (sourceMode === "url" && sourceUrl) {
|
|
530
603
|
tree.children = projectExternalMarkdownNodes(tree.children, sourceUrl);
|
|
531
604
|
}
|
|
532
605
|
else if (runtime) {
|
|
533
|
-
await projectInternalMarkdownNodes(tree, runtime);
|
|
606
|
+
figures = await projectInternalMarkdownNodes(tree, runtime);
|
|
534
607
|
}
|
|
535
608
|
const context = {
|
|
536
609
|
headings: [],
|
|
@@ -539,7 +612,7 @@ async function resolveMarkdownRenderDataFromSource(markdown, translate, headingI
|
|
|
539
612
|
headingOffset,
|
|
540
613
|
};
|
|
541
614
|
const inlineMap = await buildMarkdownInlineMap(tree, translate, sourceLocale, runtime?.locale.current);
|
|
542
|
-
const blocks = mapBlockNodes(tree.children, context, inlineMap);
|
|
615
|
+
const blocks = promoteMarkdownFigures(protectMarkdownMail(mapBlockNodes(tree.children, context, inlineMap)), figures, imageDefaults);
|
|
543
616
|
return { blocks, headings: context.headings };
|
|
544
617
|
}
|
|
545
618
|
/** remark-gfm states `left`, `center`, `right` or nothing; nothing else can come out of its parser. */
|
|
@@ -552,3 +625,45 @@ function readMarkdownTableAlign(value) {
|
|
|
552
625
|
}
|
|
553
626
|
throw new Error(`Unknown Markdown table alignment "${value}".`);
|
|
554
627
|
}
|
|
628
|
+
/*
|
|
629
|
+
* Every address in the finished blocks, protected (`helpers/protected-mail.ts`): a `mailto:` link's
|
|
630
|
+
* target, and an address written as text, a link's own label among them. Once, over the blocks, because
|
|
631
|
+
* they are built along two roads -- straight from the tree and back out of a translation.
|
|
632
|
+
*/
|
|
633
|
+
function protectMarkdownMail(blocks) {
|
|
634
|
+
return blocks.map((block) => {
|
|
635
|
+
switch (block.kind) {
|
|
636
|
+
case "heading":
|
|
637
|
+
case "paragraph":
|
|
638
|
+
return { ...block, inlines: protectMarkdownInlineMail(block.inlines) };
|
|
639
|
+
case "blockquote":
|
|
640
|
+
return { ...block, children: protectMarkdownMail(block.children) };
|
|
641
|
+
case "list":
|
|
642
|
+
return { ...block, items: block.items.map(protectMarkdownMail) };
|
|
643
|
+
case "table":
|
|
644
|
+
return {
|
|
645
|
+
...block,
|
|
646
|
+
header: block.header.map(protectMarkdownInlineMail),
|
|
647
|
+
rows: block.rows.map((cells) => cells.map(protectMarkdownInlineMail)),
|
|
648
|
+
};
|
|
649
|
+
default:
|
|
650
|
+
return block;
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
function protectMarkdownInlineMail(inlines) {
|
|
655
|
+
return inlines.flatMap((inline) => {
|
|
656
|
+
switch (inline.kind) {
|
|
657
|
+
case "text":
|
|
658
|
+
return splitPhiMailAddresses(inline.text).map((segment) => segment.kind === "mail" ? { kind: "mail_text", token: segment.token } : { kind: "text", text: segment.text });
|
|
659
|
+
case "link":
|
|
660
|
+
return [{ ...inline, href: protectPhiMailHref(inline.href), children: protectMarkdownInlineMail(inline.children) }];
|
|
661
|
+
case "strong":
|
|
662
|
+
case "emphasis":
|
|
663
|
+
case "delete":
|
|
664
|
+
return [{ ...inline, children: protectMarkdownInlineMail(inline.children) }];
|
|
665
|
+
default:
|
|
666
|
+
return [inline];
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PhiMarkdownBlock } from "./markdown-body-client";
|
|
2
|
+
/** Whether the text's sections fold, and how: each on its own, or one open at a time. */
|
|
3
|
+
export declare const PHI_MARKDOWN_FOLD_SECTIONS: readonly ["none", "independent", "accordion"];
|
|
4
|
+
export type PhiMarkdownFoldSections = (typeof PHI_MARKDOWN_FOLD_SECTIONS)[number];
|
|
5
|
+
export declare function readPhiMarkdownFoldSections(value: unknown): PhiMarkdownFoldSections | undefined;
|
|
6
|
+
type PhiMarkdownHeadingBlock = Extract<PhiMarkdownBlock, {
|
|
7
|
+
kind: "heading";
|
|
8
|
+
}>;
|
|
9
|
+
export type PhiMarkdownSection = {
|
|
10
|
+
heading: PhiMarkdownHeadingBlock;
|
|
11
|
+
blocks: PhiMarkdownBlock[];
|
|
12
|
+
};
|
|
13
|
+
export type PhiMarkdownSegment = {
|
|
14
|
+
kind: "text";
|
|
15
|
+
blocks: PhiMarkdownBlock[];
|
|
16
|
+
} | {
|
|
17
|
+
kind: "sections";
|
|
18
|
+
sections: PhiMarkdownSection[];
|
|
19
|
+
};
|
|
20
|
+
/** The level that folds: `##` as written, after the text's own offset; a heading never goes below 5. */
|
|
21
|
+
export declare function resolvePhiMarkdownFoldLevel(headingOffset: number | undefined): number;
|
|
22
|
+
/** The text in order: open runs of blocks, and runs of sections that fold. */
|
|
23
|
+
export declare function splitPhiMarkdownSegments(blocks: readonly PhiMarkdownBlock[], level: number): PhiMarkdownSegment[];
|
|
24
|
+
/**
|
|
25
|
+
* The folding sections as schema.org `FAQPage` data: each heading a question, what follows it the answer.
|
|
26
|
+
* Absent when the text has no section with an answer -- an empty FAQ is not a claim worth making.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildPhiMarkdownFaqStructuredData(blocks: readonly PhiMarkdownBlock[], level: number): {
|
|
29
|
+
"@context": string;
|
|
30
|
+
"@type": string;
|
|
31
|
+
mainEntity: {
|
|
32
|
+
"@type": string;
|
|
33
|
+
name: string;
|
|
34
|
+
acceptedAnswer: {
|
|
35
|
+
"@type": string;
|
|
36
|
+
text: string;
|
|
37
|
+
};
|
|
38
|
+
}[];
|
|
39
|
+
} | null;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A Markdown text read as sections that fold (`foldSections` on the Markdown Widget): every heading of the
|
|
3
|
+
* text's second level -- `##` as written, moved down with the text's `headingOffset` -- opens a section
|
|
4
|
+
* that runs to the next heading of that level or above. What stands before the first one, and what follows
|
|
5
|
+
* a heading above the level, stays open text. The FAQ case: a question is a `##`, its answer what follows.
|
|
6
|
+
*
|
|
7
|
+
* Pure, and apart from the Client half, because both halves read it: the Client draws the sections, the
|
|
8
|
+
* server writes the same questions and answers as schema.org `FAQPage` data.
|
|
9
|
+
*/
|
|
10
|
+
/** Whether the text's sections fold, and how: each on its own, or one open at a time. */
|
|
11
|
+
export const PHI_MARKDOWN_FOLD_SECTIONS = ["none", "independent", "accordion"];
|
|
12
|
+
export function readPhiMarkdownFoldSections(value) {
|
|
13
|
+
return PHI_MARKDOWN_FOLD_SECTIONS.find((mode) => mode === value);
|
|
14
|
+
}
|
|
15
|
+
/** The level that folds: `##` as written, after the text's own offset; a heading never goes below 5. */
|
|
16
|
+
export function resolvePhiMarkdownFoldLevel(headingOffset) {
|
|
17
|
+
return Math.min(5, 2 + Math.max(0, headingOffset ?? 0));
|
|
18
|
+
}
|
|
19
|
+
/** The text in order: open runs of blocks, and runs of sections that fold. */
|
|
20
|
+
export function splitPhiMarkdownSegments(blocks, level) {
|
|
21
|
+
const segments = [];
|
|
22
|
+
let current = null;
|
|
23
|
+
const textRun = () => {
|
|
24
|
+
const last = segments.at(-1);
|
|
25
|
+
if (last?.kind === "text")
|
|
26
|
+
return last.blocks;
|
|
27
|
+
const run = [];
|
|
28
|
+
segments.push({ kind: "text", blocks: run });
|
|
29
|
+
return run;
|
|
30
|
+
};
|
|
31
|
+
for (const block of blocks) {
|
|
32
|
+
if (block.kind === "heading" && block.level === level) {
|
|
33
|
+
current = { heading: block, blocks: [] };
|
|
34
|
+
const last = segments.at(-1);
|
|
35
|
+
if (last?.kind === "sections")
|
|
36
|
+
last.sections.push(current);
|
|
37
|
+
else
|
|
38
|
+
segments.push({ kind: "sections", sections: [current] });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (block.kind === "heading" && block.level < level)
|
|
42
|
+
current = null;
|
|
43
|
+
if (current)
|
|
44
|
+
current.blocks.push(block);
|
|
45
|
+
else
|
|
46
|
+
textRun().push(block);
|
|
47
|
+
}
|
|
48
|
+
return segments;
|
|
49
|
+
}
|
|
50
|
+
/** The words of a run of inlines, as a reader would read them aloud; a protected address is left out. */
|
|
51
|
+
function readPhiMarkdownInlineText(inlines) {
|
|
52
|
+
return inlines.map((inline) => {
|
|
53
|
+
switch (inline.kind) {
|
|
54
|
+
case "text":
|
|
55
|
+
case "inline_code":
|
|
56
|
+
return inline.text;
|
|
57
|
+
case "strong":
|
|
58
|
+
case "emphasis":
|
|
59
|
+
case "delete":
|
|
60
|
+
case "link":
|
|
61
|
+
return readPhiMarkdownInlineText(inline.children);
|
|
62
|
+
case "image":
|
|
63
|
+
return inline.alt;
|
|
64
|
+
case "break":
|
|
65
|
+
return "\n";
|
|
66
|
+
default:
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
}).join("");
|
|
70
|
+
}
|
|
71
|
+
function readPhiMarkdownBlockText(block) {
|
|
72
|
+
switch (block.kind) {
|
|
73
|
+
case "heading":
|
|
74
|
+
case "paragraph":
|
|
75
|
+
return readPhiMarkdownInlineText(block.inlines);
|
|
76
|
+
case "blockquote":
|
|
77
|
+
return block.children.map(readPhiMarkdownBlockText).join("\n");
|
|
78
|
+
case "list":
|
|
79
|
+
return block.items.map((item) => item.map(readPhiMarkdownBlockText).join(" ")).join("\n");
|
|
80
|
+
case "table":
|
|
81
|
+
return [block.header, ...block.rows].map((cells) => cells.map(readPhiMarkdownInlineText).join(" | ")).join("\n");
|
|
82
|
+
case "image":
|
|
83
|
+
return block.image.alt;
|
|
84
|
+
default:
|
|
85
|
+
return "";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The folding sections as schema.org `FAQPage` data: each heading a question, what follows it the answer.
|
|
90
|
+
* Absent when the text has no section with an answer -- an empty FAQ is not a claim worth making.
|
|
91
|
+
*/
|
|
92
|
+
export function buildPhiMarkdownFaqStructuredData(blocks, level) {
|
|
93
|
+
const questions = splitPhiMarkdownSegments(blocks, level)
|
|
94
|
+
.flatMap((segment) => segment.kind === "sections" ? segment.sections : [])
|
|
95
|
+
.map((section) => ({
|
|
96
|
+
name: readPhiMarkdownInlineText(section.heading.inlines).trim(),
|
|
97
|
+
text: section.blocks.map(readPhiMarkdownBlockText).filter((line) => line.trim()).join("\n").trim(),
|
|
98
|
+
}))
|
|
99
|
+
.filter((entry) => entry.name && entry.text);
|
|
100
|
+
if (questions.length === 0)
|
|
101
|
+
return null;
|
|
102
|
+
return {
|
|
103
|
+
"@context": "https://schema.org",
|
|
104
|
+
"@type": "FAQPage",
|
|
105
|
+
mainEntity: questions.map((entry) => ({
|
|
106
|
+
"@type": "Question",
|
|
107
|
+
name: entry.name,
|
|
108
|
+
acceptedAnswer: { "@type": "Answer", text: entry.text },
|
|
109
|
+
})),
|
|
110
|
+
};
|
|
111
|
+
}
|
package/helpers/external-href.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Scrambles `value` -- a whole `mailto:` href or a bare address -- into a `phi-mail:` string. */
|
|
2
|
+
export declare function encodePhiProtectedMail(value: string): string;
|
|
3
|
+
export declare function isPhiProtectedMail(value: string | null | undefined): value is string;
|
|
4
|
+
/** The value `encodePhiProtectedMail` was given, or `null` for anything it did not write. */
|
|
5
|
+
export declare function decodePhiProtectedMail(value: string): string | null;
|
|
6
|
+
/** A `mailto:` href protected; every other href as it is. */
|
|
7
|
+
export declare function protectPhiMailHref<T extends string | null | undefined>(href: T): T | string;
|
|
8
|
+
export type PhiMailTextSegment = {
|
|
9
|
+
kind: "text";
|
|
10
|
+
text: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "mail";
|
|
13
|
+
token: string;
|
|
14
|
+
};
|
|
15
|
+
/** A text cut where it names an address, each address protected; one text segment when it names none. */
|
|
16
|
+
export declare function splitPhiMailAddresses(text: string): PhiMailTextSegment[];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An e-mail address kept out of the page's source, for crawlers that harvest them.
|
|
3
|
+
*
|
|
4
|
+
* A crawler reads the HTML and the React payload beside it and runs no script; a reader's browser runs
|
|
5
|
+
* one. So the server writes an address as `phi-mail:` and a scrambled hex string, and the client turns it
|
|
6
|
+
* back into the address after the page has mounted (`components/navigation/use-phi-protected-mail.ts`).
|
|
7
|
+
* It is obfuscation, not secrecy: anybody who runs the page sees the address, which is the point.
|
|
8
|
+
*
|
|
9
|
+
* **Only where a page is delivered.** A stored config keeps `mailto:` as the operator wrote it -- the
|
|
10
|
+
* Builder shows the field it edits -- and the server renderer protects it on the way out. A value that
|
|
11
|
+
* only ever reaches the client as data, a table's rows, is beyond this: the rows are in the payload.
|
|
12
|
+
*
|
|
13
|
+
* The key is derived from the address, not drawn at random, so the server and a client render of the same
|
|
14
|
+
* value write the same string and hydration agrees.
|
|
15
|
+
*/
|
|
16
|
+
const PHI_PROTECTED_MAIL_PREFIX = "phi-mail:";
|
|
17
|
+
const PHI_MAIL_ADDRESS_PATTERN = /[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/gu;
|
|
18
|
+
function derivePhiMailKey(value) {
|
|
19
|
+
let hash = 0x811c9dc5;
|
|
20
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
21
|
+
hash = Math.imul(hash ^ value.charCodeAt(index), 0x01000193) >>> 0;
|
|
22
|
+
}
|
|
23
|
+
return (hash % 255) + 1;
|
|
24
|
+
}
|
|
25
|
+
function toHex(byte) {
|
|
26
|
+
return byte.toString(16).padStart(2, "0");
|
|
27
|
+
}
|
|
28
|
+
/** Scrambles `value` -- a whole `mailto:` href or a bare address -- into a `phi-mail:` string. */
|
|
29
|
+
export function encodePhiProtectedMail(value) {
|
|
30
|
+
const key = derivePhiMailKey(value);
|
|
31
|
+
const bytes = new TextEncoder().encode(value);
|
|
32
|
+
let hex = toHex(key);
|
|
33
|
+
bytes.forEach((byte, index) => {
|
|
34
|
+
hex += toHex(byte ^ ((key + index * 31) & 0xff));
|
|
35
|
+
});
|
|
36
|
+
return `${PHI_PROTECTED_MAIL_PREFIX}${hex}`;
|
|
37
|
+
}
|
|
38
|
+
export function isPhiProtectedMail(value) {
|
|
39
|
+
return typeof value === "string" && value.startsWith(PHI_PROTECTED_MAIL_PREFIX);
|
|
40
|
+
}
|
|
41
|
+
/** The value `encodePhiProtectedMail` was given, or `null` for anything it did not write. */
|
|
42
|
+
export function decodePhiProtectedMail(value) {
|
|
43
|
+
if (!isPhiProtectedMail(value))
|
|
44
|
+
return null;
|
|
45
|
+
const hex = value.slice(PHI_PROTECTED_MAIL_PREFIX.length);
|
|
46
|
+
if (hex.length < 2 || hex.length % 2 !== 0 || !/^[0-9a-f]+$/u.test(hex))
|
|
47
|
+
return null;
|
|
48
|
+
const key = Number.parseInt(hex.slice(0, 2), 16);
|
|
49
|
+
const bytes = new Uint8Array((hex.length - 2) / 2);
|
|
50
|
+
for (let index = 0; index < bytes.length; index += 1) {
|
|
51
|
+
const byte = Number.parseInt(hex.slice(2 + index * 2, 4 + index * 2), 16);
|
|
52
|
+
bytes[index] = byte ^ ((key + index * 31) & 0xff);
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** A `mailto:` href protected; every other href as it is. */
|
|
62
|
+
export function protectPhiMailHref(href) {
|
|
63
|
+
if (typeof href !== "string")
|
|
64
|
+
return href;
|
|
65
|
+
return /^mailto:/iu.test(href.trim()) ? encodePhiProtectedMail(href.trim()) : href;
|
|
66
|
+
}
|
|
67
|
+
/** A text cut where it names an address, each address protected; one text segment when it names none. */
|
|
68
|
+
export function splitPhiMailAddresses(text) {
|
|
69
|
+
const segments = [];
|
|
70
|
+
let cursor = 0;
|
|
71
|
+
for (const match of text.matchAll(PHI_MAIL_ADDRESS_PATTERN)) {
|
|
72
|
+
const start = match.index ?? 0;
|
|
73
|
+
if (start > cursor)
|
|
74
|
+
segments.push({ kind: "text", text: text.slice(cursor, start) });
|
|
75
|
+
segments.push({ kind: "mail", token: encodePhiProtectedMail(match[0]) });
|
|
76
|
+
cursor = start + match[0].length;
|
|
77
|
+
}
|
|
78
|
+
if (cursor < text.length || segments.length === 0)
|
|
79
|
+
segments.push({ kind: "text", text: text.slice(cursor) });
|
|
80
|
+
return segments;
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phis/ui",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -503,7 +503,7 @@
|
|
|
503
503
|
"@lexical/rich-text": "0.50.0",
|
|
504
504
|
"@lexical/selection": "0.50.0",
|
|
505
505
|
"@lexical/utils": "0.50.0",
|
|
506
|
-
"@phis/contracts": "^0.7.
|
|
506
|
+
"@phis/contracts": "^0.7.2",
|
|
507
507
|
"dayjs": "^1.11.23",
|
|
508
508
|
"dom-serializer": "^2.0.0",
|
|
509
509
|
"htmlparser2": "^10.1.0",
|
|
@@ -11,6 +11,8 @@ import { PhiTypographyControl } from "../../../../components/controls/phi-typogr
|
|
|
11
11
|
import { PHI_INSPECTOR_WIDGET_DEFAULT_LABELS } from "../../../../components/widgets/label-types/inspector";
|
|
12
12
|
import { PhiRegionVisibilityFields } from "./region-visibility-fields";
|
|
13
13
|
import { renderPhiInspectorConfigField } from "./inspector-config-field";
|
|
14
|
+
import { hasPhiFlag, readPhiFlags } from "../../../../helpers/flags";
|
|
15
|
+
import { PhiCmsFlags } from "../../../../constants/phi-cms";
|
|
14
16
|
const PHI_GAP_SM = "var(--ant-padding-sm)";
|
|
15
17
|
const REGION_PADDING_KEYS = [
|
|
16
18
|
"padding",
|
|
@@ -93,7 +95,24 @@ export function PhiDeveloperBuilderRegionInspectorWidgetClient({ section, builde
|
|
|
93
95
|
{
|
|
94
96
|
key: "viewport",
|
|
95
97
|
title: geometryLabels?.fields.viewport ?? "Viewport",
|
|
96
|
-
children: (_jsx(PhiViewportVisibilityControl, { disabled: isPreviewMode || !onDraftChange, value: effectiveDraft.viewportFlags, labels: geometryLabels?.viewport, onChange: (viewportFlags) => updateDraft({ viewportFlags }) })
|
|
98
|
+
children: (_jsxs("div", { style: { display: "grid", gap: PHI_GAP_SM, width: "100%" }, children: [_jsx(PhiViewportVisibilityControl, { disabled: isPreviewMode || !onDraftChange, value: effectiveDraft.viewportFlags, labels: geometryLabels?.viewport, onChange: (viewportFlags) => updateDraft({ viewportFlags }) }), selectedRegionKey === "sider_left" ? renderPhiInspectorConfigField({
|
|
99
|
+
field: { key: "mobileDrawer", type: "boolean", label: visibilityLabels.siderMobileDrawer },
|
|
100
|
+
value: hasPhiFlag(readPhiFlags(effectiveDraft.regionConfig?.flags), PhiCmsFlags.MobileDrawer),
|
|
101
|
+
defaultValue: false,
|
|
102
|
+
config: effectiveDraft.regionConfig ?? {},
|
|
103
|
+
disabled: isPreviewMode || !onDraftChange,
|
|
104
|
+
onChange: (patch) => {
|
|
105
|
+
const flags = readPhiFlags(effectiveDraft.regionConfig?.flags);
|
|
106
|
+
updateDraft({
|
|
107
|
+
regionConfig: {
|
|
108
|
+
...(effectiveDraft.regionConfig ?? {}),
|
|
109
|
+
flags: patch.mobileDrawer === true
|
|
110
|
+
? flags | PhiCmsFlags.MobileDrawer
|
|
111
|
+
: flags & ~PhiCmsFlags.MobileDrawer,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
}) : null] })),
|
|
97
116
|
},
|
|
98
117
|
{
|
|
99
118
|
key: "visibility",
|
|
@@ -5,7 +5,7 @@ import type { PhiImageAssetVariantKeyValue } from "../../../../../types/media";
|
|
|
5
5
|
import { type PhiLinkTarget } from "../../../../../types/references";
|
|
6
6
|
import { type PhiBackgroundOverlay } from "../../../../../components/widgets/config/background";
|
|
7
7
|
import { type PhiBulletListEntry, type PhiBulletListStyle } from "../../../../../components/widgets/shared/bullet-list-vocabulary";
|
|
8
|
-
import { type PhiCardBillingPeriod, type PhiCardHeadingLevel, type PhiCardHoverEffect, type PhiCardIconPlacement, type PhiCardTextAlign, type PhiCardBadgeStyle, type PhiCardVariant, type PhiCardWidgetBody } from "../../../../../components/widgets/shared/card-vocabulary";
|
|
8
|
+
import { type PhiCardBillingPeriod, type PhiCardHeadingLevel, type PhiCardHoverEffect, type PhiCardIconPlacement, type PhiCardTextAlign, type PhiCardBadgeStyle, type PhiCardMediaAspectRatio, type PhiCardVariant, type PhiCardWidgetBody } from "../../../../../components/widgets/shared/card-vocabulary";
|
|
9
9
|
import { type PhiSignalRouteSet } from "../../../../../types/signals";
|
|
10
10
|
import { type PhiCmsWidgetConfigBase } from "../../../../../components/widgets/config/parser-primitives";
|
|
11
11
|
type PhiCardImageSource = {
|
|
@@ -56,6 +56,11 @@ export type PhiCmsCardWidgetConfig = PhiCmsWidgetConfigBase & PhiCardImageSource
|
|
|
56
56
|
iconBackground?: string;
|
|
57
57
|
/** The picture's words for a reader who cannot see it; an Asset brings its own. */
|
|
58
58
|
alt?: string;
|
|
59
|
+
/**
|
|
60
|
+
* How tall the picture stands (`PHI_CARD_MEDIA_ASPECT_RATIOS`); absent is `auto`, the proportion of the
|
|
61
|
+
* file shown -- for a Media picture the Card variant's 3:2.
|
|
62
|
+
*/
|
|
63
|
+
mediaAspectRatio?: PhiCardMediaAspectRatio;
|
|
59
64
|
/** How much of the picture shows, in percent; the card's ground shows through the rest. */
|
|
60
65
|
imageOpacity?: number;
|
|
61
66
|
/**
|
|
@@ -120,6 +125,7 @@ export declare const PHI_CARD_WIDGET_DEFINITION: {
|
|
|
120
125
|
};
|
|
121
126
|
defaultConfig: {
|
|
122
127
|
body: "text";
|
|
128
|
+
mediaAspectRatio: "auto";
|
|
123
129
|
imageOpacity: number;
|
|
124
130
|
headingLevel: "h3";
|
|
125
131
|
textAlign: "start";
|
|
@@ -145,6 +151,7 @@ export declare const PHI_CARD_WIDGET_DEFINITION: {
|
|
|
145
151
|
};
|
|
146
152
|
actionLabel: string;
|
|
147
153
|
body: "text";
|
|
154
|
+
mediaAspectRatio: "auto";
|
|
148
155
|
imageOpacity: number;
|
|
149
156
|
headingLevel: "h3";
|
|
150
157
|
textAlign: "start";
|
|
@@ -8,7 +8,7 @@ import { readPhiMediaImageSourceConfig } from "../../../../../components/widgets
|
|
|
8
8
|
import { PHI_SURFACE_CARD } from "../../../../../helpers/surface-presets";
|
|
9
9
|
import { normalizePhiBackgroundWidgetConfig } from "../../../../../components/widgets/config/background";
|
|
10
10
|
import { buildPhiBulletListFields, readPhiBulletListEntries, readPhiBulletListStyle, } from "../../../../../components/widgets/shared/bullet-list-vocabulary";
|
|
11
|
-
import { PHI_CARD_HEADING_LEVELS, PHI_CARD_HOVER_EFFECTS, PHI_CARD_ICON_PLACEMENTS, PHI_CARD_TEXT_ALIGNS, PHI_CARD_BADGE_STYLES, PHI_CARD_VARIANTS, readPhiCardBillingPeriod, } from "../../../../../components/widgets/shared/card-vocabulary";
|
|
11
|
+
import { PHI_CARD_HEADING_LEVELS, PHI_CARD_HOVER_EFFECTS, PHI_CARD_ICON_PLACEMENTS, PHI_CARD_TEXT_ALIGNS, PHI_CARD_BADGE_STYLES, PHI_CARD_MEDIA_ASPECT_RATIOS, PHI_CARD_VARIANTS, readPhiCardBillingPeriod, } from "../../../../../components/widgets/shared/card-vocabulary";
|
|
12
12
|
import { readPhiControlLabel } from "../../../../../components/widgets/config/common-action-field";
|
|
13
13
|
import { PHI_CARD_SIGNALS } from "../../../../../components/widgets/signals/control-signal-capabilities";
|
|
14
14
|
import { readPhiSignalRouteSet } from "../../../../../types/signals";
|
|
@@ -52,6 +52,7 @@ function parsePhiCmsCardWidgetConfig(config) {
|
|
|
52
52
|
iconColor: readString(config.iconColor),
|
|
53
53
|
iconBackground: readString(config.iconBackground),
|
|
54
54
|
alt: readString(config.alt),
|
|
55
|
+
mediaAspectRatio: readChoice(readString(config.mediaAspectRatio), PHI_CARD_MEDIA_ASPECT_RATIOS),
|
|
55
56
|
imageOpacity: readPhiCardImageOpacity(config.imageOpacity),
|
|
56
57
|
imageOverlay: readPhiCardImageOverlay(config.imageOverlay),
|
|
57
58
|
linkTarget: readPhiLinkTarget(config.linkTarget) ?? undefined,
|
|
@@ -78,6 +79,7 @@ function parsePhiCmsCardWidgetConfig(config) {
|
|
|
78
79
|
}
|
|
79
80
|
const PHI_CARD_DEFAULT_CONFIG = {
|
|
80
81
|
body: "text",
|
|
82
|
+
mediaAspectRatio: "auto",
|
|
81
83
|
imageOpacity: 100,
|
|
82
84
|
headingLevel: "h3",
|
|
83
85
|
textAlign: "start",
|
|
@@ -177,6 +179,25 @@ export const PHI_CARD_WIDGET_DEFINITION = {
|
|
|
177
179
|
],
|
|
178
180
|
},
|
|
179
181
|
{ key: "image", type: "image", heading: "Image", label: "Image" },
|
|
182
|
+
/*
|
|
183
|
+
* Automatic is the Card variant's 3:2 for a Media picture, so a row of cards stands at one height; a
|
|
184
|
+
* step crops every card it is set on into the same box, Original shows the whole picture.
|
|
185
|
+
*/
|
|
186
|
+
{
|
|
187
|
+
key: "mediaAspectRatio",
|
|
188
|
+
type: "choice",
|
|
189
|
+
label: "Proportion",
|
|
190
|
+
options: [
|
|
191
|
+
{ value: "auto", label: "Automatic" },
|
|
192
|
+
{ value: "original", label: "Original" },
|
|
193
|
+
{ value: "phi", label: "φ (golden)" },
|
|
194
|
+
{ value: "3:2", label: "3:2" },
|
|
195
|
+
{ value: "4:3", label: "4:3" },
|
|
196
|
+
{ value: "16:9", label: "16:9" },
|
|
197
|
+
{ value: "2:1", label: "2:1" },
|
|
198
|
+
{ value: "1:1", label: "1:1" },
|
|
199
|
+
],
|
|
200
|
+
},
|
|
180
201
|
{
|
|
181
202
|
key: "imageOpacity",
|
|
182
203
|
type: "number",
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { buildPhiMediaAssetContentDeliveryUrl } from "../../../../../constants/media";
|
|
5
5
|
import { resolvePhiImagePresentation } from "../../../../../components/media/image-presentation";
|
|
6
|
+
import { resolvePhiCardImageVariantKey, resolvePhiCardMediaAspectRatioCss, resolvePhiCardMediaAspectRatioValue, } from "../../../../../components/widgets/shared/card-vocabulary";
|
|
6
7
|
import { usePhiAuthoringAssetDetails } from "../../../../../components/media/use-authoring-asset-details";
|
|
7
8
|
import { PhiInlineTextEditor } from "../../../../../components/controls/phi-inline-text-editor";
|
|
8
9
|
import { PhiTypographyControl } from "../../../../../components/controls/phi-typography-control";
|
|
@@ -112,7 +113,13 @@ export function PhiCardWidgetEditor({ config, onChange }) {
|
|
|
112
113
|
const presentation = resolvePhiImagePresentation({
|
|
113
114
|
sourceKind: config.sourceKind,
|
|
114
115
|
assetId,
|
|
115
|
-
|
|
116
|
+
/* The card's own variant, else the Card variant where its box is that variant's proportion. */
|
|
117
|
+
variantKey: resolvePhiCardImageVariantKey({
|
|
118
|
+
sourceKind: config.sourceKind,
|
|
119
|
+
variantKey: config.sourceKind === "asset" ? config.variantKey : null,
|
|
120
|
+
mediaAspectRatio: config.mediaAspectRatio,
|
|
121
|
+
}),
|
|
122
|
+
frameAspectRatio: resolvePhiCardMediaAspectRatioValue(config.mediaAspectRatio),
|
|
116
123
|
variantVersion: asset?.variantVersion ?? (config.sourceKind === "asset" ? config.variantVersion : null),
|
|
117
124
|
deliveryRevision: asset?.deliveryRevision,
|
|
118
125
|
originalUrl: assetId == null ? null : buildPhiMediaAssetContentDeliveryUrl(assetId),
|
|
@@ -148,6 +155,7 @@ export function PhiCardWidgetEditor({ config, onChange }) {
|
|
|
148
155
|
}, config: {
|
|
149
156
|
// A card that states no Surface has none, on the canvas as on the page: "None" is its contents.
|
|
150
157
|
surface: config.surface ?? null,
|
|
158
|
+
mediaAspectRatio: resolvePhiCardMediaAspectRatioCss(config.mediaAspectRatio),
|
|
151
159
|
image: presentation.url
|
|
152
160
|
? {
|
|
153
161
|
presentation,
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { trBulk, trBulkForLocale } from "../../../../../server-helpers/translate";
|
|
3
3
|
import { isPhiMediaSvgContentType } from "../../../../../constants/media";
|
|
4
4
|
import { resolvePhiImagePresentation } from "../../../../../components/media/image-presentation";
|
|
5
|
+
import { resolvePhiCardImageVariantKey, resolvePhiCardMediaAspectRatioCss, resolvePhiCardMediaAspectRatioValue, } from "../../../../../components/widgets/shared/card-vocabulary";
|
|
5
6
|
import { resolvePhiPublicAssetReference } from "../../../../../components/widgets/helpers/internal-reference-resolver.server";
|
|
6
7
|
import { resolvePhiLinkHref } from "../../../../../helpers/link-target";
|
|
7
8
|
import { PhiCmsWidgetType } from "../../../../../constants/cms-widget-types";
|
|
@@ -60,7 +61,13 @@ export async function PhiCardWidget({ labels, config, runtime, links, translate,
|
|
|
60
61
|
const presentation = resolvePhiImagePresentation({
|
|
61
62
|
sourceKind: config?.sourceKind,
|
|
62
63
|
assetId: resolvedAsset?.id,
|
|
63
|
-
|
|
64
|
+
/* The card's own variant, else the Card variant where its box is that variant's proportion. */
|
|
65
|
+
variantKey: resolvePhiCardImageVariantKey({
|
|
66
|
+
sourceKind: config?.sourceKind,
|
|
67
|
+
variantKey: config?.sourceKind === "asset" ? config?.variantKey : null,
|
|
68
|
+
mediaAspectRatio: config?.mediaAspectRatio,
|
|
69
|
+
}),
|
|
70
|
+
frameAspectRatio: resolvePhiCardMediaAspectRatioValue(config?.mediaAspectRatio),
|
|
64
71
|
variantVersion: resolvedAsset?.variantVersion,
|
|
65
72
|
deliveryRevision: resolvedAsset?.deliveryRevision,
|
|
66
73
|
originalUrl: resolvedAsset?.deliveryUrl,
|
|
@@ -74,6 +81,7 @@ export async function PhiCardWidget({ labels, config, runtime, links, translate,
|
|
|
74
81
|
const actionLink = preview || !actionEnabled ? null : resolvePhiLinkHref(config?.actionLinkTarget, links);
|
|
75
82
|
const clientConfig = {
|
|
76
83
|
surface: config?.surface ?? null,
|
|
84
|
+
mediaAspectRatio: resolvePhiCardMediaAspectRatioCss(config?.mediaAspectRatio),
|
|
77
85
|
image: presentation.url
|
|
78
86
|
? {
|
|
79
87
|
presentation,
|