@cntrl-site/sdk-nextjs 1.9.116 → 1.9.118

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.
@@ -31,7 +31,7 @@ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
31
31
  const [wrapperRef, setWrapperRef] = (0, react_1.useState)(null);
32
32
  (0, useRegisterResize_1.useRegisterResize)(wrapperRef, onResize);
33
33
  (0, useItemGeometry_1.useItemGeometry)(item.id, wrapperRef);
34
- const { url, hasGLEffect } = item.commonParams;
34
+ const { url, hasGLEffect, altText } = item.commonParams;
35
35
  const fxCanvas = (0, react_1.useRef)(null);
36
36
  const isInitialRef = (0, react_1.useRef)(true);
37
37
  const layoutValues = [item.area, item.layoutParams];
@@ -74,8 +74,8 @@ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
74
74
  onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
75
75
  }, [isInteractive, onVisibilityChange]);
76
76
  return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_p = item.link) === null || _p === void 0 ? void 0 : _p.url, target: (_q = item.link) === null || _q === void 0 ? void 0 : _q.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `image-wrapper-${item.id}`, ref: setWrapperRef, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { willChange: blur !== 0 && blur !== undefined ? 'transform' : 'unset', transition: (_r = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.transition) !== null && _r !== void 0 ? _r : 'none' }), children: hasGLEffect && isFXAllowed
77
- ? ((0, jsx_runtime_1.jsx)("canvas", { style: inlineStyles, ref: fxCanvas, className: `img-canvas image-${item.id}`, width: rectWidth, height: rectHeight }))
78
- : ((0, jsx_runtime_1.jsx)("img", { alt: "", className: `image image-${item.id}`, style: inlineStyles, src: item.commonParams.url })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
77
+ ? ((0, jsx_runtime_1.jsx)("canvas", { style: inlineStyles, ref: fxCanvas, className: `img-canvas image-${item.id}`, width: rectWidth, height: rectHeight, role: "img", "aria-label": altText }))
78
+ : ((0, jsx_runtime_1.jsx)("img", { alt: altText, className: `image image-${item.id}`, style: inlineStyles, src: item.commonParams.url })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
79
79
  .image-wrapper-${item.id} {
80
80
  position: absolute;
81
81
  width: 100%;
@@ -21,8 +21,9 @@ const useCurrentLayout_1 = require("../../../common/useCurrentLayout");
21
21
  const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
22
22
  const RichTextGeometryController_1 = require("../../../ItemGeometry/RichTextGeometryController");
23
23
  const RichTextConverter_1 = require("../../../utils/RichTextConverter/RichTextConverter");
24
+ const getHeadingTag_1 = require("../../../utils/getHeadingTag");
24
25
  const RichTextItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
25
- var _a, _b, _c, _d;
26
+ var _a, _b, _c, _d, _e;
26
27
  const reactId = (0, react_1.useId)();
27
28
  const id = `${reactId}-richtext-${item.id}`;
28
29
  const [ref, setRef] = (0, react_1.useState)(null);
@@ -56,13 +57,15 @@ const RichTextItem = ({ item, sectionId, onResize, interactionCtrl, onVisibility
56
57
  });
57
58
  const isInteractive = colorAlpha !== 0 || hasVisibleRangeColors;
58
59
  const [content, styles] = (0, useRichTextItem_1.useRichTextItem)(item);
60
+ const Wrapper = ((_e = (0, getHeadingTag_1.getHeadingTag)(item)) !== null && _e !== void 0 ? _e : 'div');
59
61
  (0, react_1.useEffect)(() => {
60
62
  onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
61
63
  }, [isInteractive, onVisibilityChange]);
62
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { ref: setRef, className: `rich-text-wrapper-${item.id}${layoutId ? '' : ` ${RichTextConverter_1.RICH_TEXT_LAYOUT_PENDING_CLASS}`}`, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), (textColor ? { color: `${textColor.fmt('rgba')}` } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (letterSpacing !== undefined ? { letterSpacing: `${letterSpacing * exemplary}px` } : {})), (wordSpacing !== undefined ? { wordSpacing: `${wordSpacing * exemplary}px` } : {})), (fontSize !== undefined ? { fontSize: `${Math.round(fontSize * exemplary)}px` } : {})), (lineHeight !== undefined ? { lineHeight: `${lineHeight * exemplary}px` } : {})), { willChange: blur !== 0 && blur !== undefined ? 'transform' : 'unset', transition }), children: content }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: id, children: [styles, `${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
64
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Wrapper, { ref: setRef, className: `rich-text-wrapper-${item.id}${layoutId ? '' : ` ${RichTextConverter_1.RICH_TEXT_LAYOUT_PENDING_CLASS}`}`, style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), (textColor ? { color: `${textColor.fmt('rgba')}` } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (letterSpacing !== undefined ? { letterSpacing: `${letterSpacing * exemplary}px` } : {})), (wordSpacing !== undefined ? { wordSpacing: `${wordSpacing * exemplary}px` } : {})), (fontSize !== undefined ? { fontSize: `${Math.round(fontSize * exemplary)}px` } : {})), (lineHeight !== undefined ? { lineHeight: `${lineHeight * exemplary}px` } : {})), { willChange: blur !== 0 && blur !== undefined ? 'transform' : 'unset', transition }), children: content }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: id, children: [styles, `${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
63
65
  const color = color_1.CntrlColor.parse(layoutParams.color);
64
66
  return (`
65
67
  .rich-text-wrapper-${item.id} {
68
+ margin: 0;
66
69
  font-size: ${layoutParams.fontSize * 100}vw;
67
70
  line-height: ${layoutParams.lineHeight * 100}vw;
68
71
  letter-spacing: ${layoutParams.letterSpacing * 100}vw;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHeadingTag = void 0;
4
+ const HEADING_TAGS = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
5
+ function getHeadingTag(item) {
6
+ const heading = item.commonParams.heading;
7
+ if (typeof heading !== 'string' || !HEADING_TAGS.has(heading))
8
+ return;
9
+ return heading;
10
+ }
11
+ exports.getHeadingTag = getHeadingTag;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.9.116",
3
+ "version": "1.9.118",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -31,9 +31,9 @@
31
31
  "dependencies": {
32
32
  "@antfu/eslint-config": "^3.8.0",
33
33
  "@cntrl-site/color": "^1.0.0",
34
- "@cntrl-site/components": "^1.0.60",
34
+ "@cntrl-site/components": "^1.0.61",
35
35
  "@cntrl-site/effects": "^1.4.2",
36
- "@cntrl-site/sdk": "^1.28.5",
36
+ "@cntrl-site/sdk": "^1.28.7",
37
37
  "@types/vimeo__player": "^2.18.0",
38
38
  "@vimeo/player": "^2.25.0",
39
39
  "html-react-parser": "^3.0.1",
@@ -31,7 +31,7 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
31
31
  const [wrapperRef, setWrapperRef] = useState<HTMLDivElement | null>(null);
32
32
  useRegisterResize(wrapperRef, onResize);
33
33
  useItemGeometry(item.id, wrapperRef);
34
- const { url, hasGLEffect } = item.commonParams;
34
+ const { url, hasGLEffect, altText } = item.commonParams;
35
35
  const fxCanvas = useRef<HTMLCanvasElement | null>(null);
36
36
  const isInitialRef = useRef(true);
37
37
  const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
@@ -106,11 +106,13 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
106
106
  className={`img-canvas image-${item.id}`}
107
107
  width={rectWidth}
108
108
  height={rectHeight}
109
+ role="img"
110
+ aria-label={altText}
109
111
  />
110
112
  )
111
113
  : (
112
114
  <img
113
- alt=""
115
+ alt={altText}
114
116
  className={`image image-${item.id}`}
115
117
  style={inlineStyles}
116
118
  src={item.commonParams.url}
@@ -15,6 +15,7 @@ import { useCurrentLayout } from '../../../common/useCurrentLayout';
15
15
  import { useItemGeometry } from '../../../ItemGeometry/useItemGeometry';
16
16
  import { RichTextGeometryController } from '../../../ItemGeometry/RichTextGeometryController';
17
17
  import { RICH_TEXT_LAYOUT_PENDING_CLASS } from '../../../utils/RichTextConverter/RichTextConverter';
18
+ import { getHeadingTag } from '../../../utils/getHeadingTag';
18
19
 
19
20
  export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
20
21
  const reactId = useId();
@@ -57,13 +58,14 @@ export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, on
57
58
  });
58
59
  const isInteractive = colorAlpha !== 0 || hasVisibleRangeColors;
59
60
  const [content, styles] = useRichTextItem(item);
61
+ const Wrapper = (getHeadingTag(item) ?? 'div') as 'div';
60
62
  useEffect(() => {
61
63
  onVisibilityChange?.(isInteractive);
62
64
  }, [isInteractive, onVisibilityChange]);
63
65
 
64
66
  return (
65
67
  <>
66
- <div
68
+ <Wrapper
67
69
  ref={setRef}
68
70
  className={`rich-text-wrapper-${item.id}${layoutId ? '' : ` ${RICH_TEXT_LAYOUT_PENDING_CLASS}`}`}
69
71
  style={{
@@ -79,13 +81,14 @@ export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, on
79
81
  }}
80
82
  >
81
83
  {content}
82
- </div>
84
+ </Wrapper>
83
85
  <JSXStyle id={id}>
84
86
  {styles}
85
87
  {`${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
86
88
  const color = CntrlColor.parse(layoutParams.color);
87
89
  return (`
88
90
  .rich-text-wrapper-${item.id} {
91
+ margin: 0;
89
92
  font-size: ${layoutParams.fontSize * 100}vw;
90
93
  line-height: ${layoutParams.lineHeight * 100}vw;
91
94
  letter-spacing: ${layoutParams.letterSpacing * 100}vw;
@@ -0,0 +1,11 @@
1
+ import { RichTextItem } from '@cntrl-site/sdk';
2
+
3
+ export type HeadingTag = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
4
+
5
+ const HEADING_TAGS = new Set<string>(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
6
+
7
+ export function getHeadingTag(item: RichTextItem): HeadingTag | undefined {
8
+ const heading = (item.commonParams as { heading?: unknown }).heading;
9
+ if (typeof heading !== 'string' || !HEADING_TAGS.has(heading)) return;
10
+ return heading as HeadingTag;
11
+ }