@cntrl-site/sdk-nextjs 1.11.0-1 → 1.11.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.
Files changed (51) hide show
  1. package/jest.config.js +4 -1
  2. package/lib/common/useComponentElement.js +40 -0
  3. package/lib/common/useLazyVideo.js +102 -0
  4. package/lib/components/Head.js +3 -3
  5. package/lib/components/Navigation/NavigationComponent.js +5 -4
  6. package/lib/components/Section/SectionVideo.js +4 -2
  7. package/lib/components/StructuredBlockItem/StructuredBlockItem.js +4 -4
  8. package/lib/components/StructuredBlockItem/StructuredCode/StructuredCode.js +5 -1
  9. package/lib/components/StructuredBlockItem/StructuredComponent/StructuredComponent.js +6 -5
  10. package/lib/components/StructuredBlockItem/StructuredEmbed/StructuredYoutubeEmbed.js +13 -1
  11. package/lib/components/StructuredBlockItem/StructuredImage/StructuredImage.js +3 -1
  12. package/lib/components/StructuredBlockItem/StructuredRichText/StructuredRichText.js +5 -5
  13. package/lib/components/StructuredBlockItem/StructuredTable/StructuredTable.js +102 -0
  14. package/lib/components/StructuredBlockItem/StructuredVideo/StructuredVideo.js +6 -7
  15. package/lib/components/StructuredBlockItem/blocksMap.js +7 -5
  16. package/lib/components/StructuredBlockItem/textStylesRule.js +7 -9
  17. package/lib/components/StructuredContent/StructuredContent.js +3 -2
  18. package/lib/components/StructuredContent/StructuredHeader.js +71 -23
  19. package/lib/components/items/ComponentItem/ComponentItem.js +7 -6
  20. package/lib/components/items/FileItem/VideoItem.js +3 -1
  21. package/lib/components/items/RichTextItem/useRichTextItem.js +3 -4
  22. package/lib/provider/CntrlSdkContext.js +0 -7
  23. package/lib/utils/RichTextConverter/RichTextConverter.js +8 -4
  24. package/package.json +5 -5
  25. package/src/common/useComponentElement.test.ts +71 -0
  26. package/src/common/useComponentElement.ts +48 -0
  27. package/src/common/useLazyVideo.test.tsx +215 -0
  28. package/src/common/useLazyVideo.ts +100 -0
  29. package/src/components/Head.tsx +2 -2
  30. package/src/components/Navigation/NavigationComponent.tsx +7 -4
  31. package/src/components/Section/SectionVideo.tsx +3 -2
  32. package/src/components/StructuredBlockItem/StructuredBlockItem.tsx +6 -4
  33. package/src/components/StructuredBlockItem/StructuredCode/StructuredCode.tsx +5 -1
  34. package/src/components/StructuredBlockItem/StructuredComponent/StructuredComponent.tsx +7 -4
  35. package/src/components/StructuredBlockItem/StructuredEmbed/StructuredYoutubeEmbed.tsx +12 -1
  36. package/src/components/StructuredBlockItem/StructuredImage/StructuredImage.tsx +3 -1
  37. package/src/components/StructuredBlockItem/StructuredRichText/StructuredRichText.tsx +4 -3
  38. package/src/components/StructuredBlockItem/StructuredTable/StructuredTable.tsx +118 -0
  39. package/src/components/StructuredBlockItem/StructuredVideo/StructuredVideo.tsx +7 -10
  40. package/src/components/StructuredBlockItem/blocksMap.ts +7 -6
  41. package/src/components/StructuredBlockItem/textStylesRule.ts +7 -9
  42. package/src/components/StructuredContent/StructuredContent.test.tsx +141 -14
  43. package/src/components/StructuredContent/StructuredContent.tsx +3 -2
  44. package/src/components/StructuredContent/StructuredHeader.tsx +78 -24
  45. package/src/components/items/ComponentItem/ComponentItem.tsx +8 -5
  46. package/src/components/items/FileItem/VideoItem.tsx +3 -2
  47. package/src/components/items/RichTextItem/RichTextItem.tsx +1 -0
  48. package/src/components/items/RichTextItem/useRichTextItem.ts +3 -4
  49. package/src/provider/CntrlSdkContext.ts +1 -8
  50. package/src/utils/RichTextConverter/RichTextConverter.test.tsx +6 -4
  51. package/src/utils/RichTextConverter/RichTextConverter.tsx +9 -4
package/jest.config.js CHANGED
@@ -2,5 +2,8 @@
2
2
  module.exports = {
3
3
  preset: 'ts-jest',
4
4
  testEnvironment: 'jsdom',
5
- rootDir: './src'
5
+ rootDir: './src',
6
+ moduleNameMapper: {
7
+ '^@cntrl-site/components/elements$': require.resolve('@cntrl-site/components/elements')
8
+ }
6
9
  };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useComponentElement = exports.pendingElementProps = void 0;
4
+ const react_1 = require("react");
5
+ const elements_1 = require("@cntrl-site/components/elements");
6
+ const useCntrlContext_1 = require("../provider/useCntrlContext");
7
+ exports.pendingElementProps = {
8
+ dangerouslySetInnerHTML: { __html: '' },
9
+ suppressHydrationWarning: true
10
+ };
11
+ function useComponentElement(componentId) {
12
+ var _a, _b;
13
+ const sdk = (0, useCntrlContext_1.useCntrlContext)();
14
+ const [, refresh] = (0, react_1.useReducer)((count) => count + 1, 0);
15
+ const Element = (_b = (_a = sdk.getComponent(componentId)) === null || _a === void 0 ? void 0 : _a.element) !== null && _b !== void 0 ? _b : (0, elements_1.getComponentElement)(componentId);
16
+ const isLoading = !Element && (0, elements_1.hasComponentElement)(componentId);
17
+ const isFailed = isLoading && (0, elements_1.hasComponentElementFailed)(componentId);
18
+ const isPending = isLoading && !isFailed;
19
+ if (isPending) {
20
+ (0, elements_1.loadComponentElement)(componentId).catch(() => undefined);
21
+ }
22
+ (0, react_1.useEffect)(() => {
23
+ if (!isLoading)
24
+ return;
25
+ let cancelled = false;
26
+ (0, elements_1.loadComponentElement)(componentId)
27
+ .catch((error) => {
28
+ console.error(`Failed to load component "${componentId}":`, error);
29
+ })
30
+ .then(() => {
31
+ if (!cancelled)
32
+ refresh();
33
+ });
34
+ return () => {
35
+ cancelled = true;
36
+ };
37
+ }, [componentId, isLoading]);
38
+ return { Element, isPending, isFailed };
39
+ }
40
+ exports.useComponentElement = useComponentElement;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useLazyVideo = void 0;
4
+ const react_1 = require("react");
5
+ const NEAR_VIEWPORT_MARGIN = '100% 0px';
6
+ const sharedObservers = new Map();
7
+ function getSharedObserver(rootMargin) {
8
+ const existing = sharedObservers.get(rootMargin);
9
+ if (existing)
10
+ return existing;
11
+ const listeners = new Map();
12
+ const states = new Map();
13
+ const observer = new IntersectionObserver((entries) => {
14
+ var _a;
15
+ for (const entry of entries) {
16
+ states.set(entry.target, entry.isIntersecting);
17
+ (_a = listeners.get(entry.target)) === null || _a === void 0 ? void 0 : _a.forEach(listener => listener(entry.isIntersecting));
18
+ }
19
+ }, { rootMargin });
20
+ const shared = { observer, listeners, states };
21
+ sharedObservers.set(rootMargin, shared);
22
+ return shared;
23
+ }
24
+ function observeIntersection(element, rootMargin, listener) {
25
+ var _a;
26
+ const { observer, listeners, states } = getSharedObserver(rootMargin);
27
+ const elementListeners = (_a = listeners.get(element)) !== null && _a !== void 0 ? _a : new Set();
28
+ if (elementListeners.size === 0) {
29
+ listeners.set(element, elementListeners);
30
+ observer.observe(element);
31
+ }
32
+ elementListeners.add(listener);
33
+ const knownState = states.get(element);
34
+ if (knownState !== undefined)
35
+ listener(knownState);
36
+ return () => {
37
+ elementListeners.delete(listener);
38
+ if (elementListeners.size > 0)
39
+ return;
40
+ listeners.delete(element);
41
+ states.delete(element);
42
+ observer.unobserve(element);
43
+ };
44
+ }
45
+ function loadVideo(video) {
46
+ if (video.preload !== 'auto')
47
+ video.preload = 'auto';
48
+ }
49
+ function playVideo(video) {
50
+ const playPromise = video.play();
51
+ if (playPromise)
52
+ playPromise.catch(() => { });
53
+ }
54
+ function useLazyVideo(video, autoPlay) {
55
+ (0, react_1.useEffect)(() => {
56
+ if (!video)
57
+ return;
58
+ if (typeof IntersectionObserver === 'undefined') {
59
+ loadVideo(video);
60
+ video.autoplay = autoPlay;
61
+ return;
62
+ }
63
+ const stopNear = observeIntersection(video, NEAR_VIEWPORT_MARGIN, (isNear) => {
64
+ if (isNear)
65
+ loadVideo(video);
66
+ });
67
+ if (!autoPlay)
68
+ return stopNear;
69
+ let isPausedByUser = false;
70
+ let isPausingOffscreen = false;
71
+ const handlePlay = () => {
72
+ isPausedByUser = false;
73
+ };
74
+ const handlePause = () => {
75
+ if (isPausingOffscreen) {
76
+ isPausingOffscreen = false;
77
+ }
78
+ else if (!document.hidden) {
79
+ isPausedByUser = true;
80
+ }
81
+ };
82
+ video.addEventListener('play', handlePlay);
83
+ video.addEventListener('pause', handlePause);
84
+ const stopVisible = observeIntersection(video, '0px', (isVisible) => {
85
+ if (isVisible) {
86
+ if (video.paused && !isPausedByUser)
87
+ playVideo(video);
88
+ }
89
+ else if (!video.paused) {
90
+ isPausingOffscreen = true;
91
+ video.pause();
92
+ }
93
+ });
94
+ return () => {
95
+ stopNear();
96
+ stopVisible();
97
+ video.removeEventListener('play', handlePlay);
98
+ video.removeEventListener('pause', handlePause);
99
+ };
100
+ }, [video, autoPlay]);
101
+ }
102
+ exports.useLazyVideo = useLazyVideo;
@@ -15,7 +15,7 @@ const CNTRLHead = ({ meta, project, slug, siteUrl, fontsVault }) => {
15
15
  const parsedFonts = Object.assign(Object.assign({}, (typeof googleFonts === 'object' ? googleFonts : {})), (typeof adobeFonts === 'object' ? adobeFonts : {}));
16
16
  const customFonts = project.fonts.custom;
17
17
  const htmlHead = (0, html_react_parser_1.default)(project.html.head);
18
- const ffGenerator = new sdk_1.FontFaceGenerator([...fontsVault, ...customFonts]);
18
+ const ffGenerator = new sdk_1.FontFaceGenerator([...customFonts, ...fontsVault]);
19
19
  const links = Object.values(parsedFonts).map((value) => {
20
20
  var _a, _b;
21
21
  if (!value)
@@ -26,9 +26,9 @@ const CNTRLHead = ({ meta, project, slug, siteUrl, fontsVault }) => {
26
26
  return null;
27
27
  return ((0, jsx_runtime_1.jsx)("link", { rel: rel, href: href }, `link-${rel}-${href}`));
28
28
  });
29
- return ((0, jsx_runtime_1.jsxs)(head_1.default, { children: [(0, jsx_runtime_1.jsx)("title", { children: meta.title }), (0, jsx_runtime_1.jsx)("meta", { name: "description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { name: "keywords", content: meta.keywords }), (0, jsx_runtime_1.jsx)("meta", { property: "og:title", content: meta.title }), (0, jsx_runtime_1.jsx)("meta", { property: "og:image", content: meta.opengraphThumbnail }), (0, jsx_runtime_1.jsx)("meta", { property: "og:description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { property: "og:type", content: "website" }), canonicalUrl && (0, jsx_runtime_1.jsx)("link", { rel: "canonical", href: canonicalUrl }), canonicalUrl && (0, jsx_runtime_1.jsx)("meta", { property: "og:url", content: canonicalUrl }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:card", content: "summary_large_image" }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:title", content: meta.title }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:image", content: meta.opengraphThumbnail }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { name: "generator", content: "https://cntrl.site" }), (0, jsx_runtime_1.jsx)("link", { rel: "icon", href: meta.favicon }), (0, jsx_runtime_1.jsx)("style", { dangerouslySetInnerHTML: {
29
+ return ((0, jsx_runtime_1.jsxs)(head_1.default, { children: [(0, jsx_runtime_1.jsx)("title", { children: meta.title }), (0, jsx_runtime_1.jsx)("meta", { name: "description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { name: "keywords", content: meta.keywords }), (0, jsx_runtime_1.jsx)("meta", { property: "og:title", content: meta.title }), (0, jsx_runtime_1.jsx)("meta", { property: "og:image", content: meta.opengraphThumbnail }), (0, jsx_runtime_1.jsx)("meta", { property: "og:description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { property: "og:type", content: "website" }), canonicalUrl && (0, jsx_runtime_1.jsx)("link", { rel: "canonical", href: canonicalUrl }), canonicalUrl && (0, jsx_runtime_1.jsx)("meta", { property: "og:url", content: canonicalUrl }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:card", content: "summary_large_image" }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:title", content: meta.title }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:image", content: meta.opengraphThumbnail }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { name: "generator", content: "https://cntrl.site" }), (0, jsx_runtime_1.jsx)("link", { rel: "icon", href: meta.favicon }), links, (0, jsx_runtime_1.jsx)("style", { dangerouslySetInnerHTML: {
30
30
  __html: ffGenerator.generate()
31
- } }), links, htmlHead] }));
31
+ } }), htmlHead] }));
32
32
  };
33
33
  exports.CNTRLHead = CNTRLHead;
34
34
  function buildCanonicalUrl(host, slug) {
@@ -11,6 +11,7 @@ const react_1 = require("react");
11
11
  const useCntrlContext_1 = require("../../provider/useCntrlContext");
12
12
  const useLayoutContext_1 = require("../useLayoutContext");
13
13
  const mergeComponentSettings_1 = require("../../utils/mergeComponentSettings");
14
+ const useComponentElement_1 = require("../../common/useComponentElement");
14
15
  const NavigationComponent = ({ component: block, pages, currentState, isSwitchClone }) => {
15
16
  var _a, _b;
16
17
  const sdk = (0, useCntrlContext_1.useCntrlContext)();
@@ -19,17 +20,17 @@ const NavigationComponent = ({ component: block, pages, currentState, isSwitchCl
19
20
  const fallbackLayout = (_a = layouts[0]) === null || _a === void 0 ? void 0 : _a.id;
20
21
  const effectiveLayout = layout !== null && layout !== void 0 ? layout : fallbackLayout;
21
22
  const layoutValues = [block.layoutParams];
22
- const component = sdk.getComponent(block.commonParams.componentId);
23
- const Element = component ? component.element : undefined;
23
+ const { Element, isPending, isFailed } = (0, useComponentElement_1.useComponentElement)(block.commonParams.componentId);
24
+ const keepsServerMarkup = isPending || isFailed;
24
25
  const layoutParameters = effectiveLayout ? (_b = block.layoutParams[effectiveLayout]) === null || _b === void 0 ? void 0 : _b.parameters : undefined;
25
26
  const commonParameters = block.commonParams.parameters;
26
27
  const parameters = layoutParameters ? Object.assign(Object.assign({}, layoutParameters), { settings: (0, mergeComponentSettings_1.mergeComponentSettings)(layoutParameters.settings, commonParameters === null || commonParameters === void 0 ? void 0 : commonParameters.settings) }) : undefined;
27
28
  const reactId = (0, react_1.useId)();
28
29
  const id = `${reactId}-custom-component-${block.id}`;
29
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `custom-component-${block.id}`, style: { opacity: layout == null ? 0 : undefined }, children: parameters && Element && ((0, jsx_runtime_1.jsx)(Element, Object.assign({ metadata: {
30
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: `custom-component-${block.id}`, style: { opacity: layout == null || isPending ? 0 : undefined } }, (keepsServerMarkup ? useComponentElement_1.pendingElementProps : {}), { children: keepsServerMarkup ? null : parameters && Element && ((0, jsx_runtime_1.jsx)(Element, Object.assign({ metadata: {
30
31
  itemId: block.id,
31
32
  submitUrl: sdk.getSubmitUrl(commonParameters === null || commonParameters === void 0 ? void 0 : commonParameters.pluginConfigId)
32
- }, portalId: "component-portal", content: block.commonParams.content }, parameters, { layoutId: effectiveLayout, pages: pages, currentState: currentState, isSwitchClone: isSwitchClone }))) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
33
+ }, portalId: "component-portal", content: block.commonParams.content }, parameters, { layoutId: effectiveLayout, pages: pages, currentState: currentState, isSwitchClone: isSwitchClone }))) }), keepsServerMarkup ? 'pending' : 'ready'), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
33
34
  .custom-component-${block.id} {
34
35
  width: 100%;
35
36
  height: 100%;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SectionVideo = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
+ const useLazyVideo_1 = require("../../common/useLazyVideo");
6
7
  const SectionVideo = ({ container, sectionId, media }) => {
7
8
  const [video, setVideo] = (0, react_1.useState)(null);
8
9
  const [videoWrapper, setVideoWrapper] = (0, react_1.useState)(null);
@@ -11,6 +12,7 @@ const SectionVideo = ({ container, sectionId, media }) => {
11
12
  const [isPlaying, setIsPlaying] = (0, react_1.useState)(false);
12
13
  const [userPaused, setUserPaused] = (0, react_1.useState)(false);
13
14
  const [isClickedOnCover, setIsClickedOnCover] = (0, react_1.useState)(false);
15
+ (0, useLazyVideo_1.useLazyVideo)(video, play === 'auto');
14
16
  const handleCoverClick = () => {
15
17
  if (!video || play !== 'on-click')
16
18
  return;
@@ -63,7 +65,7 @@ const SectionVideo = ({ container, sectionId, media }) => {
63
65
  top: position === 'fixed' ? '100vh' : '0',
64
66
  overflow: 'hidden',
65
67
  width: '100%'
66
- }, children: [(0, jsx_runtime_1.jsx)("video", { ref: setVideo, autoPlay: play === 'auto', loop: true, style: {
68
+ }, children: [(0, jsx_runtime_1.jsx)("video", { ref: setVideo, loop: true, style: {
67
69
  opacity: !isClickedOnCover && play === 'on-click' && coverUrl ? 0 : opacity,
68
70
  objectFit: isContainHeight ? 'cover' : (size !== null && size !== void 0 ? size : 'cover'),
69
71
  width: isContainHeight && !isVideoWidthOverflow ? 'auto' : '100%',
@@ -71,7 +73,7 @@ const SectionVideo = ({ container, sectionId, media }) => {
71
73
  left: isContainHeight ? '50%' : (hasOffsetX ? `${offsetX * 100}vw` : '0'),
72
74
  height: '100%',
73
75
  position: 'relative'
74
- }, controls: play === 'on-click', muted: play === 'auto', playsInline: true, preload: "auto", className: `video-background-${sectionId}`, onPlay: () => setIsPlaying(true), onPause: () => setIsPlaying(false), children: (0, jsx_runtime_1.jsx)("source", { src: `${url}` }) }), play === 'on-click' && !isClickedOnCover && ((0, jsx_runtime_1.jsx)("div", { className: `video-background-${sectionId}-cover-container`, style: {
76
+ }, controls: play === 'on-click', muted: play === 'auto', playsInline: true, preload: "none", className: `video-background-${sectionId}`, onPlay: () => setIsPlaying(true), onPause: () => setIsPlaying(false), children: (0, jsx_runtime_1.jsx)("source", { src: `${url}` }) }), play === 'on-click' && !isClickedOnCover && ((0, jsx_runtime_1.jsx)("div", { className: `video-background-${sectionId}-cover-container`, style: {
75
77
  position: 'absolute',
76
78
  left: 0,
77
79
  width: '100%',
@@ -11,20 +11,20 @@ const style_1 = __importDefault(require("styled-jsx/style"));
11
11
  const useCntrlContext_1 = require("../../provider/useCntrlContext");
12
12
  const blockPlacement_1 = require("./blockPlacement");
13
13
  const blocksMap_1 = require("./blocksMap");
14
- const StructuredBlockItem = ({ block, readingWidth }) => {
15
- var _a;
14
+ const StructuredBlockItem = ({ block, readingWidth, hasGap }) => {
15
+ var _a, _b;
16
16
  const reactId = (0, react_1.useId)();
17
17
  const id = `${reactId}-item-${block.id}`;
18
18
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
19
19
  const layoutValues = [block.area, block.layoutParams, (_a = block.hidden) !== null && _a !== void 0 ? _a : {}];
20
- const BlockComponent = blocksMap_1.blocksMap[block.type];
20
+ const BlockComponent = (_b = blocksMap_1.blocksMap[block.type]) !== null && _b !== void 0 ? _b : blocksMap_1.UnknownBlock;
21
21
  return ((0, jsx_runtime_1.jsxs)("div", { className: `structured-block-item-${block.id}`, children: [(0, jsx_runtime_1.jsx)(BlockComponent, { block: block, readingWidth: readingWidth }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
22
22
  ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams, hidden]) => (`
23
23
  .structured-block-item-${block.id} {
24
24
  display: ${hidden ? 'none' : 'block'};
25
25
  position: relative;
26
26
  z-index: ${area.zIndex};
27
- margin-top: ${area.paddingTop ? `${area.paddingTop * 100}vw` : 0};
27
+ margin-top: ${hasGap && area.paddingTop ? `${area.paddingTop * 100}vw` : 0};
28
28
  outline: none;
29
29
  ${(0, blockPlacement_1.blockPlacement)(area, layoutParams)}
30
30
  }
@@ -19,12 +19,16 @@ const DEFAULT_COLORS = { background: '#FFFFFF', foreground: '#000000' };
19
19
  const FONT_STYLE_ITALIC = 1;
20
20
  const FONT_STYLE_BOLD = 2;
21
21
  const FONT_STYLE_UNDERLINE = 4;
22
+ const FONT_STYLE_STRIKETHROUGH = 8;
22
23
  function tokenStyle({ color, fontStyle = 0 }) {
23
24
  return {
24
25
  color,
25
26
  fontStyle: fontStyle & FONT_STYLE_ITALIC ? 'italic' : undefined,
26
27
  fontWeight: fontStyle & FONT_STYLE_BOLD ? 'bold' : undefined,
27
- textDecoration: fontStyle & FONT_STYLE_UNDERLINE ? 'underline' : undefined
28
+ textDecoration: [
29
+ fontStyle & FONT_STYLE_UNDERLINE ? 'underline' : '',
30
+ fontStyle & FONT_STYLE_STRIKETHROUGH ? 'line-through' : ''
31
+ ].filter(Boolean).join(' ') || undefined
28
32
  };
29
33
  }
30
34
  /** Code in a box coloured by its theme, as it comes from the API: in lines of coloured tokens. */
@@ -12,6 +12,7 @@ const useCntrlContext_1 = require("../../../provider/useCntrlContext");
12
12
  const useLayoutContext_1 = require("../../useLayoutContext");
13
13
  const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
14
14
  const mergeComponentSettings_1 = require("../../../utils/mergeComponentSettings");
15
+ const useComponentElement_1 = require("../../../common/useComponentElement");
15
16
  const StructuredComponent = ({ block }) => {
16
17
  var _a, _b;
17
18
  const sdk = (0, useCntrlContext_1.useCntrlContext)();
@@ -20,19 +21,19 @@ const StructuredComponent = ({ block }) => {
20
21
  const fallbackLayout = (_a = layouts[0]) === null || _a === void 0 ? void 0 : _a.id;
21
22
  const effectiveLayout = layout !== null && layout !== void 0 ? layout : fallbackLayout;
22
23
  const layoutValues = [block.layoutParams];
23
- const component = sdk.getComponent(block.commonParams.componentId);
24
+ const { Element, isPending, isFailed } = (0, useComponentElement_1.useComponentElement)(block.commonParams.componentId);
25
+ const keepsServerMarkup = isPending || isFailed;
24
26
  const [ref, setRef] = (0, react_1.useState)(null);
25
27
  (0, useItemGeometry_1.useItemGeometry)(block.id, ref);
26
- const Element = component ? component.element : undefined;
27
28
  const layoutParameters = effectiveLayout ? (_b = block.layoutParams[effectiveLayout]) === null || _b === void 0 ? void 0 : _b.parameters : undefined;
28
29
  const commonParameters = block.commonParams.parameters;
29
30
  const parameters = layoutParameters ? Object.assign(Object.assign({}, layoutParameters), { settings: (0, mergeComponentSettings_1.mergeComponentSettings)(layoutParameters.settings, commonParameters === null || commonParameters === void 0 ? void 0 : commonParameters.settings) }) : undefined;
30
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `custom-component-${block.id}`, ref: setRef,
31
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: `custom-component-${block.id}`, ref: setRef,
31
32
  // preventing layout shift while supporting SSG for proper SEO
32
- style: { opacity: layout == null ? 0 : undefined }, children: parameters && Element && ((0, jsx_runtime_1.jsx)(Element, Object.assign({ metadata: {
33
+ style: { opacity: layout == null || isPending ? 0 : undefined } }, (keepsServerMarkup ? useComponentElement_1.pendingElementProps : {}), { children: keepsServerMarkup ? null : parameters && Element && ((0, jsx_runtime_1.jsx)(Element, Object.assign({ metadata: {
33
34
  itemId: block.id,
34
35
  submitUrl: sdk.getSubmitUrl(commonParameters === null || commonParameters === void 0 ? void 0 : commonParameters.pluginConfigId)
35
- }, portalId: "component-portal", content: block.commonParams.content }, parameters))) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: block.id, children: `
36
+ }, portalId: "component-portal", content: block.commonParams.content }, parameters))) }), keepsServerMarkup ? 'pending' : 'ready'), (0, jsx_runtime_1.jsx)(style_1.default, { id: block.id, children: `
36
37
  .custom-component-${block.id} {
37
38
  width: 100%;
38
39
  height: 100%;
@@ -15,6 +15,15 @@ const useYouTubeIframeApi_1 = require("../../../utils/Youtube/useYouTubeIframeAp
15
15
  const YoutubeIframeApi_1 = require("../../../utils/Youtube/YoutubeIframeApi");
16
16
  const useLayoutContext_1 = require("../../useLayoutContext");
17
17
  const embedFrameStyles_1 = require("./embedFrameStyles");
18
+ // a link the id cannot be read from -- empty, or a host not whitelisted -- gives no player, not a failed page
19
+ function youtubeIdOf(url) {
20
+ try {
21
+ return (0, getValidYoutubeUrl_1.getYoutubeId)(new URL(url));
22
+ }
23
+ catch (_a) {
24
+ return undefined;
25
+ }
26
+ }
18
27
  /** A YouTube video playing as the YouTube item does, its cover over it until it plays. */
19
28
  const StructuredYoutubeEmbed = ({ block }) => {
20
29
  const reactId = (0, react_1.useId)();
@@ -31,12 +40,15 @@ const StructuredYoutubeEmbed = ({ block }) => {
31
40
  (0, react_1.useEffect)(() => {
32
41
  if (!YT || !frame || !layoutParams)
33
42
  return;
43
+ const videoId = youtubeIdOf(url);
44
+ if (videoId === undefined)
45
+ return;
34
46
  const { play, controls } = layoutParams;
35
47
  setIsCoverVisible(play !== 'auto' && coverUrl !== null);
36
48
  const placeholder = document.createElement('div');
37
49
  frame.appendChild(placeholder);
38
50
  const created = new YT.Player(placeholder, {
39
- videoId: (0, getValidYoutubeUrl_1.getYoutubeId)(new URL(url)),
51
+ videoId,
40
52
  playerVars: {
41
53
  autoplay: play === 'auto' ? '1' : '0',
42
54
  controls: controls ? '1' : '0'
@@ -22,7 +22,9 @@ const StructuredImage = ({ block, readingWidth }) => {
22
22
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
23
23
  const [ref, setRef] = (0, react_1.useState)(null);
24
24
  (0, useItemGeometry_1.useItemGeometry)(block.id, ref);
25
- const { urls, altText } = block.commonParams;
25
+ const { altText } = block.commonParams;
26
+ // a file the API could not resolve comes as an empty url: nothing to draw for it
27
+ const urls = block.commonParams.urls.filter(url => url !== '');
26
28
  const caption = (0, sdk_1.getShownCaption)(block.commonParams);
27
29
  const [ratios, setRatios] = (0, react_1.useState)({});
28
30
  // an image already loaded when the page hydrates fires no load event of its own
@@ -26,26 +26,26 @@ const StructuredRichText = ({ block }) => {
26
26
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
27
27
  const [ref, setRef] = (0, react_1.useState)(null);
28
28
  (0, useItemGeometry_1.useItemGeometry)(block.id, ref);
29
- const [content, rangeStyles] = (0, react_1.useMemo)(() => richTextConverter.toHtml(block, layouts, { isScaledToViewport: false }), [block, layouts]);
29
+ const [content, rangeStyles, listStyles] = (0, react_1.useMemo)(() => richTextConverter.toHtml(block, layouts, { isScaledToViewport: false }), [block, layouts]);
30
30
  const lang = (0, react_1.useMemo)(() => (0, detectLang_1.detectLang)(block.commonParams.text), [block.commonParams.text]);
31
31
  const isQuote = block.type === sdk_1.StructuredBlockType.Quote;
32
32
  // only a text block of the stack flows in columns: a quote keeps to its box, a date to its line
33
33
  const isText = block.type === sdk_1.StructuredBlockType.RichText;
34
34
  const Wrapper = ((_a = (0, getHeadingTag_1.getHeadingTag)(block)) !== null && _a !== void 0 ? _a : 'div');
35
35
  const layoutValues = [block.layoutParams];
36
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Wrapper, { ref: setRef, lang: lang, className: `structured-text-${block.id}`, children: isQuote ? (0, jsx_runtime_1.jsx)("div", { className: `structured-quote-box-${block.id}`, children: content }) : content }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: id, children: [rangeStyles, `
36
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Wrapper, { ref: setRef, lang: lang, className: `structured-text-${block.id}`, children: isQuote ? (0, jsx_runtime_1.jsx)("div", { className: `structured-quote-box-${block.id}`, children: content }) : content }), listStyles && (0, jsx_runtime_1.jsx)(style_1.default, { id: RichTextConverter_1.LIST_STYLES_ID, children: listStyles }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: id, children: [rangeStyles, `
37
37
  .structured-text-${block.id} {
38
38
  margin: 0;
39
39
  }
40
40
  `, `${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([layoutParams]) => {
41
- var _a, _b;
41
+ var _a;
42
42
  return (`
43
43
  ${(0, textStylesRule_1.textStylesRule)(`.structured-text-${block.id}`, layoutParams)}
44
44
  ${isText ? (0, textStylesRule_1.textColumnsRule)(`.structured-text-${block.id}`, layoutParams) : ''}
45
45
  ${isQuote ? `
46
46
  .structured-quote-box-${block.id} {
47
- padding: ${((_a = layoutParams.boxPadding) !== null && _a !== void 0 ? _a : 0) * 100}vw;
48
- border-radius: ${((_b = layoutParams.boxRadius) !== null && _b !== void 0 ? _b : 0) * 100}vw;
47
+ padding: ${[layoutParams.boxPaddingTop, layoutParams.boxPaddingRight, layoutParams.boxPaddingBottom, layoutParams.boxPaddingLeft].map(side => `${(side !== null && side !== void 0 ? side : 0) * 100}vw`).join(' ')};
48
+ border-radius: ${((_a = layoutParams.boxRadius) !== null && _a !== void 0 ? _a : 0) * 100}vw;
49
49
  background-color: transparent;
50
50
  }
51
51
  ${layoutParams.background ? (0, textStylesRule_1.colorRule)(`.structured-quote-box-${block.id}`, 'background-color', layoutParams.background) : ''}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StructuredTable = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const sdk_1 = require("@cntrl-site/sdk");
9
+ const react_1 = require("react");
10
+ const style_1 = __importDefault(require("styled-jsx/style"));
11
+ const useCntrlContext_1 = require("../../../provider/useCntrlContext");
12
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
13
+ const RichTextConverter_1 = require("../../../utils/RichTextConverter/RichTextConverter");
14
+ const textStylesRule_1 = require("../textStylesRule");
15
+ // the lines between the cells, in pixels of the layout, scaled with it like everything drawn in it
16
+ const BORDER_PX = 1;
17
+ const richTextConverter = new RichTextConverter_1.RichTextConverter();
18
+ /** Every cell as elements, with the styles of its ranges; the list styles once, where any cell has a list. */
19
+ function convertCells(block, layouts) {
20
+ const { header, rows } = block.commonParams;
21
+ const cells = new Map();
22
+ const rangeStyles = [];
23
+ let listStyles;
24
+ for (const cell of [...header, ...rows.flat()]) {
25
+ const source = {
26
+ id: `${block.id}-${cell.id}`,
27
+ commonParams: cell,
28
+ layoutParams: Object.fromEntries(layouts.map(layout => { var _a; return [layout.id, { rangeStyles: (_a = cell.styles[layout.id]) !== null && _a !== void 0 ? _a : [], textAlign: block.layoutParams[layout.id].textAlign }]; }))
29
+ };
30
+ const [content, styles, lists] = richTextConverter.toHtml(source, layouts, { isScaledToViewport: false });
31
+ cells.set(cell.id, content);
32
+ rangeStyles.push(styles);
33
+ listStyles !== null && listStyles !== void 0 ? listStyles : (listStyles = lists);
34
+ }
35
+ return { cells, rangeStyles: rangeStyles.join('\n'), listStyles };
36
+ }
37
+ /**
38
+ * A table of one of three kinds, as served: its cells rich text set, spaced above and below and
39
+ * lined in the styles it comes with, their ranges styled over them, each column its share of the
40
+ * width and padded on either side as its own values say. Cells draw a heading row over a grid; rows
41
+ * draw every row plain, the two fills alternating from the first; lines draw the heading and a line
42
+ * between each pair of rows only.
43
+ */
44
+ const StructuredTable = ({ block }) => {
45
+ const reactId = (0, react_1.useId)();
46
+ const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
47
+ const [ref, setRef] = (0, react_1.useState)(null);
48
+ (0, useItemGeometry_1.useItemGeometry)(block.id, ref);
49
+ const { kind, header, rows } = block.commonParams;
50
+ const { cells: content, rangeStyles, listStyles } = (0, react_1.useMemo)(() => convertCells(block, layouts), [block, layouts]);
51
+ const headingAsRow = kind === 'rows';
52
+ const Heading = headingAsRow ? 'td' : 'th';
53
+ const table = `.structured-table-${block.id}`;
54
+ const cells = `${table} th, ${table} td`;
55
+ const cellContent = (cell) => content.get(cell.id);
56
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("table", { ref: setRef, className: `structured-table-${block.id}`, children: [(0, jsx_runtime_1.jsx)("colgroup", { children: header.map((_, col) => (0, jsx_runtime_1.jsx)("col", {}, col)) }), (0, jsx_runtime_1.jsx)("thead", { className: `structured-table-heading-${block.id}`, children: (0, jsx_runtime_1.jsx)("tr", { children: header.map(cell => (0, jsx_runtime_1.jsx)(Heading, { children: cellContent(cell) }, cell.id)) }) }), (0, jsx_runtime_1.jsx)("tbody", { className: `structured-table-body-${block.id}`, children: rows.map((row, index) => { var _a, _b; return (0, jsx_runtime_1.jsx)("tr", { children: row.map(cell => (0, jsx_runtime_1.jsx)("td", { children: cellContent(cell) }, cell.id)) }, (_b = (_a = row[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : index); }) })] }), listStyles && (0, jsx_runtime_1.jsx)(style_1.default, { id: RichTextConverter_1.LIST_STYLES_ID, children: listStyles }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: `${reactId}-table-${block.id}`, children: [rangeStyles, `
57
+ ${table} {
58
+ width: 100%;
59
+ table-layout: fixed;
60
+ border-collapse: collapse;
61
+ }
62
+ ${cells} {
63
+ box-sizing: border-box;
64
+ vertical-align: top;
65
+ text-align: inherit;
66
+ font-weight: inherit;
67
+ border-style: solid;
68
+ white-space: pre-wrap;
69
+ overflow-wrap: anywhere;
70
+ }
71
+ ${(0, sdk_1.getLayoutStyles)(layouts, [block.layoutParams], ([layoutParams], exemplary) => {
72
+ const vw = (value) => `${value * 100}vw`;
73
+ const border = vw(BORDER_PX / exemplary);
74
+ const fill = (selector, color) => (color ? (0, textStylesRule_1.colorRule)(selector, 'background-color', color) : '');
75
+ return (`
76
+ ${(0, textStylesRule_1.textStylesRule)(table, layoutParams)}
77
+ ${cells} {
78
+ padding-top: ${vw(layoutParams.cellPaddingTop)};
79
+ padding-bottom: ${vw(layoutParams.cellPaddingBottom)};
80
+ border-width: ${kind === 'lines' ? '0' : border};
81
+ }
82
+ ${kind === 'lines' ? `${table} tbody > tr > th, ${table} tbody > tr > td { border-top-width: ${border}; }` : ''}
83
+ ${layoutParams.columns.map((column, index) => `
84
+ ${table} col:nth-child(${index + 1}) {
85
+ width: ${column.width * 100}%;
86
+ }
87
+ ${table} th:nth-child(${index + 1}), ${table} td:nth-child(${index + 1}) {
88
+ padding-left: ${vw(column.paddingLeft)};
89
+ padding-right: ${vw(column.paddingRight)};
90
+ }
91
+ `).join('')}
92
+ ${layoutParams.borderColor ? (0, textStylesRule_1.colorRule)(cells, 'border-color', layoutParams.borderColor) : ''}
93
+ ${headingAsRow
94
+ ? `${fill(`${table} thead tr, ${table} tbody tr:nth-child(even)`, layoutParams.headingBackground)}
95
+ ${fill(`${table} tbody tr:nth-child(odd)`, layoutParams.bodyBackground)}`
96
+ : `${fill(`.structured-table-heading-${block.id}`, layoutParams.headingBackground)}
97
+ ${fill(`.structured-table-body-${block.id}`, layoutParams.bodyBackground)}`}
98
+ `);
99
+ })}
100
+ `] })] }));
101
+ };
102
+ exports.StructuredTable = StructuredTable;
@@ -20,7 +20,6 @@ const StructuredVideo = ({ block }) => {
20
20
  const [ref, setRef] = (0, react_1.useState)(null);
21
21
  const [video, setVideo] = (0, react_1.useState)(null);
22
22
  const [isLoaded, setIsLoaded] = (0, react_1.useState)(false);
23
- const [isPlaying, setIsPlaying] = (0, react_1.useState)(false);
24
23
  const [hasPlayed, setHasPlayed] = (0, react_1.useState)(false);
25
24
  (0, useItemGeometry_1.useItemGeometry)(block.id, ref);
26
25
  const { url, coverUrl } = block.commonParams;
@@ -30,12 +29,12 @@ const StructuredVideo = ({ block }) => {
30
29
  if (!video)
31
30
  return;
32
31
  setHasPlayed(true);
33
- video.play();
32
+ // a play the browser refuses -- an unmuted hover, a pause before it began -- leaves the cover up
33
+ video.play().catch(() => setHasPlayed(false));
34
34
  };
35
- return ((0, jsx_runtime_1.jsxs)("div", { ref: setRef, className: `structured-video-${block.id}${isLoaded ? '' : ` structured-video-loading-${block.id}`}`, children: [layoutParams && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("video", { ref: setVideo, className: `structured-video-el-${block.id}`, src: url, autoPlay: play === 'auto', muted: layoutParams.muted, controls: layoutParams.controls, loop: true, playsInline: true, preload: "auto", onLoadedMetadata: () => setIsLoaded(true), onPlay: () => {
36
- setIsPlaying(true);
37
- setHasPlayed(true);
38
- }, onPause: () => setIsPlaying(false), onMouseEnter: () => {
35
+ return ((0, jsx_runtime_1.jsxs)("div", { ref: setRef, className: `structured-video-${block.id}${isLoaded ? '' : ` structured-video-loading-${block.id}`}`, children: [layoutParams && url && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("video", { ref: setVideo, className: `structured-video-el-${block.id}`, src: url, autoPlay: play === 'auto', muted: layoutParams.muted, controls: layoutParams.controls, loop: true, playsInline: true,
36
+ // a video behind its cover is fetched once it is asked for, not with the page
37
+ preload: play === 'auto' ? 'auto' : 'metadata', onLoadedMetadata: () => setIsLoaded(true), onPlay: () => setHasPlayed(true), onMouseEnter: () => {
39
38
  if (play === 'on-hover')
40
39
  start();
41
40
  }, onMouseLeave: () => {
@@ -44,7 +43,7 @@ const StructuredVideo = ({ block }) => {
44
43
  } }, layoutId), coverUrl && play !== 'auto' && !hasPlayed && ((0, jsx_runtime_1.jsx)("img", { className: `structured-video-cover-${block.id}`, src: coverUrl, alt: "", onMouseEnter: () => {
45
44
  if (play === 'on-hover')
46
45
  start();
47
- }, onClick: start })), play === 'on-click' && !layoutParams.controls && ((0, jsx_runtime_1.jsx)("div", { className: `structured-video-overlay-${block.id}`, onClick: () => (isPlaying ? video === null || video === void 0 ? void 0 : video.pause() : start()) }))] })), (0, jsx_runtime_1.jsx)(style_1.default, { id: `${reactId}-video-${block.id}`, children: `
46
+ }, onClick: start })), play === 'on-click' && !layoutParams.controls && ((0, jsx_runtime_1.jsx)("div", { className: `structured-video-overlay-${block.id}`, onClick: () => (video && !video.paused ? video.pause() : start()) }))] })), (0, jsx_runtime_1.jsx)(style_1.default, { id: `${reactId}-video-${block.id}`, children: `
48
47
  .structured-video-${block.id} {
49
48
  position: relative;
50
49
  width: 100%;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.blocksMap = void 0;
3
+ exports.blocksMap = exports.UnknownBlock = void 0;
4
4
  const sdk_1 = require("@cntrl-site/sdk");
5
5
  const StructuredComponent_1 = require("./StructuredComponent/StructuredComponent");
6
6
  const StructuredRichText_1 = require("./StructuredRichText/StructuredRichText");
@@ -9,9 +9,12 @@ const StructuredHeaderImage_1 = require("./StructuredHeaderImage/StructuredHeade
9
9
  const StructuredVideo_1 = require("./StructuredVideo/StructuredVideo");
10
10
  const StructuredDivider_1 = require("./StructuredDivider/StructuredDivider");
11
11
  const StructuredCode_1 = require("./StructuredCode/StructuredCode");
12
+ const StructuredTable_1 = require("./StructuredTable/StructuredTable");
12
13
  const StructuredVimeoEmbed_1 = require("./StructuredEmbed/StructuredVimeoEmbed");
13
14
  const StructuredYoutubeEmbed_1 = require("./StructuredEmbed/StructuredYoutubeEmbed");
14
- const noop = () => null;
15
+ /** Drawn for a block of a type this build does not know, should one reach it: nothing, rather than a failed page. */
16
+ const UnknownBlock = () => null;
17
+ exports.UnknownBlock = UnknownBlock;
15
18
  exports.blocksMap = {
16
19
  [sdk_1.StructuredBlockType.Component]: StructuredComponent_1.StructuredComponent,
17
20
  [sdk_1.StructuredBlockType.RichText]: StructuredRichText_1.StructuredRichText,
@@ -22,8 +25,7 @@ exports.blocksMap = {
22
25
  [sdk_1.StructuredBlockType.Video]: StructuredVideo_1.StructuredVideo,
23
26
  [sdk_1.StructuredBlockType.Divider]: StructuredDivider_1.StructuredDivider,
24
27
  [sdk_1.StructuredBlockType.Code]: StructuredCode_1.StructuredCode,
28
+ [sdk_1.StructuredBlockType.Table]: StructuredTable_1.StructuredTable,
25
29
  [sdk_1.StructuredBlockType.VimeoEmbed]: StructuredVimeoEmbed_1.StructuredVimeoEmbed,
26
- [sdk_1.StructuredBlockType.YoutubeEmbed]: StructuredYoutubeEmbed_1.StructuredYoutubeEmbed,
27
- // a section's header is drawn by its section, never in the stack
28
- [sdk_1.StructuredBlockType.Header]: noop
30
+ [sdk_1.StructuredBlockType.YoutubeEmbed]: StructuredYoutubeEmbed_1.StructuredYoutubeEmbed
29
31
  };
@@ -6,7 +6,6 @@ const sdk_1 = require("@cntrl-site/sdk");
6
6
  const getFontFamilyValue_1 = require("../../utils/getFontFamilyValue");
7
7
  /** A block's text styles as a CSS rule for `selector`, its lengths in viewport units as the block's own. */
8
8
  function textStylesRule(selector, styles) {
9
- const color = color_1.CntrlColor.parse(styles.color);
10
9
  return `
11
10
  ${selector} {
12
11
  font-family: ${(0, getFontFamilyValue_1.getFontFamilyValue)(styles.typeFace)};
@@ -20,23 +19,22 @@ function textStylesRule(selector, styles) {
20
19
  text-transform: ${styles.textTransform};
21
20
  vertical-align: ${styles.verticalAlign};
22
21
  text-align: ${styles.textAlign};
23
- color: ${color.fmt('oklch')};
24
- }
25
- @supports not (color: oklch(42% 0.3 90 / 1)) {
26
- ${selector} {
27
- color: ${color.fmt('rgba')};
28
- }
29
22
  }
23
+ ${colorRule(selector, 'color', styles.color)}
30
24
  `;
31
25
  }
32
26
  exports.textStylesRule = textStylesRule;
33
- /** The columns a text block flows in, the gap between them in viewport units, and whether its lines hyphenate. */
27
+ /**
28
+ * The columns a text block flows in, the gap between them in viewport units, and whether its lines
29
+ * hyphenate. One column is written out too: the layouts' media queries stack upward, so a smaller
30
+ * layout's columns would otherwise carry into a larger layout set to one.
31
+ */
34
32
  function textColumnsRule(selector, { columns = 1, columnGap = 0, hyphens = sdk_1.Hyphens.None }) {
35
33
  return `
36
34
  ${selector} {
37
35
  hyphens: ${hyphens};
38
36
  -webkit-hyphens: ${hyphens};
39
- ${columns > 1 ? `column-count: ${columns}; column-gap: ${columnGap * 100}vw; column-fill: balance;` : ''}
37
+ ${columns > 1 ? `column-count: ${columns}; column-gap: ${columnGap * 100}vw; column-fill: balance;` : 'column-count: auto; column-gap: normal;'}
40
38
  }
41
39
  `;
42
40
  }