@cntrl-site/sdk-nextjs 1.9.104 → 1.9.106

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.
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
+ </state>
5
+ </component>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/sdk-nextjs.iml" filepath="$PROJECT_DIR$/.idea/sdk-nextjs.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -20,6 +20,7 @@ const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromIte
20
20
  const useCurrentLayout_1 = require("../../../common/useCurrentLayout");
21
21
  const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
22
22
  const RichTextGeometryController_1 = require("../../../ItemGeometry/RichTextGeometryController");
23
+ const RichTextConverter_1 = require("../../../utils/RichTextConverter/RichTextConverter");
23
24
  const RichTextItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
24
25
  var _a, _b, _c, _d;
25
26
  const reactId = (0, react_1.useId)();
@@ -58,7 +59,7 @@ const RichTextItem = ({ item, sectionId, onResize, interactionCtrl, onVisibility
58
59
  (0, react_1.useEffect)(() => {
59
60
  onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
60
61
  }, [isInteractive, onVisibilityChange]);
61
- 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}`, 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]) => {
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]) => {
62
63
  const color = color_1.CntrlColor.parse(layoutParams.color);
63
64
  return (`
64
65
  .rich-text-wrapper-${item.id} {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RichTextConverter = exports.FontStyles = void 0;
3
+ exports.RichTextConverter = exports.RICH_TEXT_LAYOUT_PENDING_CLASS = exports.FontStyles = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const color_1 = require("@cntrl-site/color");
6
6
  const sdk_1 = require("@cntrl-site/sdk");
@@ -11,6 +11,8 @@ exports.FontStyles = {
11
11
  bold: { 'font-weight': 'bold' },
12
12
  italic: { 'font-style': 'italic' }
13
13
  };
14
+ exports.RICH_TEXT_LAYOUT_PENDING_CLASS = 'rich-text-layout-pending';
15
+ const SCALING_STYLES = new Set(['FONTSIZE', 'LINEHEIGHT', 'LETTERSPACING', 'WORDSPACING']);
14
16
  class RichTextConverter {
15
17
  toHtml(richText, layouts) {
16
18
  var _a, _b, _c;
@@ -37,11 +39,11 @@ class RichTextConverter {
37
39
  const lhForLayout = currentLineHeight[l.id];
38
40
  if (lhForLayout === undefined)
39
41
  return;
40
- const lh = RichTextConverter.fromRangeStylesToInline({
41
- name: 'LINEHEIGHT',
42
- value: lhForLayout
43
- }, l.exemplary);
42
+ const lineHeightStyle = { name: 'LINEHEIGHT', value: lhForLayout };
43
+ const lh = RichTextConverter.fromRangeStylesToInline(lineHeightStyle, l.exemplary, true);
44
+ const lhPending = RichTextConverter.fromRangeStylesToInline(lineHeightStyle, l.exemplary, false);
44
45
  styleRules[l.id].push(`.rt_${richText.id}_br_${blockIndex} {${lh}}`);
46
+ styleRules[l.id].push(`.${exports.RICH_TEXT_LAYOUT_PENDING_CLASS} .rt_${richText.id}_br_${blockIndex} {${lhPending}}`);
45
47
  });
46
48
  continue;
47
49
  }
@@ -113,9 +115,17 @@ class RichTextConverter {
113
115
  }
114
116
  styleRules[item.layout].push(`
115
117
  .${blockClass} .s-${styleGroup.start}-${styleGroup.end} {
116
- ${styleGroup.styles.map(s => RichTextConverter.fromRangeStylesToInline(s, exemplary)).join('\n')}
118
+ ${styleGroup.styles.map(s => RichTextConverter.fromRangeStylesToInline(s, exemplary, true)).join('\n')}
117
119
  }
118
120
  `);
121
+ const lengthStyles = styleGroup.styles.filter(s => SCALING_STYLES.has(s.name));
122
+ if (lengthStyles.length !== 0) {
123
+ styleRules[item.layout].push(`
124
+ .${exports.RICH_TEXT_LAYOUT_PENDING_CLASS} .${blockClass} .s-${styleGroup.start}-${styleGroup.end} {
125
+ ${lengthStyles.map(s => RichTextConverter.fromRangeStylesToInline(s, exemplary, false)).join('\n')}
126
+ }
127
+ `);
128
+ }
119
129
  if (color) {
120
130
  styleRules[item.layout].push(`
121
131
  @supports not (color: oklch(42% 0.3 90 / 1)) {
@@ -220,17 +230,17 @@ class RichTextConverter {
220
230
  }
221
231
  return entitiesGroups;
222
232
  }
223
- static fromRangeStylesToInline(draftStyle, exemplary) {
233
+ static fromRangeStylesToInline(draftStyle, exemplary, isLayoutDefined) {
224
234
  const { value, name } = draftStyle;
225
235
  const map = {
226
236
  COLOR: { color: getResolvedValue(value, name) },
227
237
  TYPEFACE: { 'font-family': `${(0, getFontFamilyValue_1.getFontFamilyValue)(value)}` },
228
238
  FONTSTYLE: value ? Object.assign({}, exports.FontStyles[value]) : {},
229
239
  FONTWEIGHT: { 'font-weight': value },
230
- FONTSIZE: { 'font-size': `${Number.parseFloat(value) * exemplary}px` },
231
- LINEHEIGHT: { 'line-height': `${Number.parseFloat(value) * exemplary}px` },
232
- LETTERSPACING: { 'letter-spacing': `${Number.parseFloat(value) * exemplary}px` },
233
- WORDSPACING: { 'word-spacing': `${Number.parseFloat(value) * exemplary}px` },
240
+ FONTSIZE: { 'font-size': getScaledValue(value, exemplary, isLayoutDefined) },
241
+ LINEHEIGHT: { 'line-height': getScaledValue(value, exemplary, isLayoutDefined) },
242
+ LETTERSPACING: { 'letter-spacing': getScaledValue(value, exemplary, isLayoutDefined) },
243
+ WORDSPACING: { 'word-spacing': getScaledValue(value, exemplary, isLayoutDefined) },
234
244
  TEXTTRANSFORM: value ? { 'text-transform': value } : { 'text-transform': sdk_1.TextTransform.None },
235
245
  VERTICALALIGN: value ? { 'vertical-align': value } : { 'vertical-align': sdk_1.VerticalAlign.Unset },
236
246
  TEXTDECORATION: { 'text-decoration': value },
@@ -255,6 +265,10 @@ function groupBy(items, getKey) {
255
265
  }
256
266
  return groups;
257
267
  }
268
+ function getScaledValue(value, exemplary, isLayoutDefined) {
269
+ const ratio = Number.parseFloat(value);
270
+ return !isLayoutDefined ? `${ratio * 100}vw` : `${ratio * exemplary}px`;
271
+ }
258
272
  function getResolvedValue(value, name) {
259
273
  if (name !== 'COLOR')
260
274
  return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.9.104",
3
+ "version": "1.9.106",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -31,7 +31,7 @@
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.51",
34
+ "@cntrl-site/components": "^1.0.52",
35
35
  "@cntrl-site/effects": "^1.4.2",
36
36
  "@cntrl-site/sdk": "^1.28.4",
37
37
  "@types/vimeo__player": "^2.18.0",
@@ -14,6 +14,7 @@ import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemS
14
14
  import { useCurrentLayout } from '../../../common/useCurrentLayout';
15
15
  import { useItemGeometry } from '../../../ItemGeometry/useItemGeometry';
16
16
  import { RichTextGeometryController } from '../../../ItemGeometry/RichTextGeometryController';
17
+ import { RICH_TEXT_LAYOUT_PENDING_CLASS } from '../../../utils/RichTextConverter/RichTextConverter';
17
18
 
18
19
  export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
19
20
  const reactId = useId();
@@ -64,7 +65,7 @@ export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, on
64
65
  <>
65
66
  <div
66
67
  ref={setRef}
67
- className={`rich-text-wrapper-${item.id}`}
68
+ className={`rich-text-wrapper-${item.id}${layoutId ? '' : ` ${RICH_TEXT_LAYOUT_PENDING_CLASS}`}`}
68
69
  style={{
69
70
  ...(blur !== undefined ? { filter: `blur(${blur as number * 100}vw)` } : {}),
70
71
  ...(textColor ? { color: `${textColor.fmt('rgba')}` } : {}),
@@ -37,6 +37,10 @@ export const FontStyles: Record<string, Record<string, string>> = {
37
37
  italic: { 'font-style': 'italic' }
38
38
  };
39
39
 
40
+ export const RICH_TEXT_LAYOUT_PENDING_CLASS = 'rich-text-layout-pending';
41
+
42
+ const SCALING_STYLES = new Set(['FONTSIZE', 'LINEHEIGHT', 'LETTERSPACING', 'WORDSPACING']);
43
+
40
44
  export class RichTextConverter {
41
45
  toHtml(
42
46
  richText: RichTextItem,
@@ -64,11 +68,11 @@ export class RichTextConverter {
64
68
  layouts.forEach(l => {
65
69
  const lhForLayout = currentLineHeight[l.id];
66
70
  if (lhForLayout === undefined) return;
67
- const lh = RichTextConverter.fromRangeStylesToInline({
68
- name: 'LINEHEIGHT',
69
- value: lhForLayout
70
- }, l.exemplary);
71
+ const lineHeightStyle = { name: 'LINEHEIGHT', value: lhForLayout };
72
+ const lh = RichTextConverter.fromRangeStylesToInline(lineHeightStyle, l.exemplary, true);
73
+ const lhPending = RichTextConverter.fromRangeStylesToInline(lineHeightStyle, l.exemplary, false);
71
74
  styleRules[l.id].push(`.rt_${richText.id}_br_${blockIndex} {${lh}}`);
75
+ styleRules[l.id].push(`.${RICH_TEXT_LAYOUT_PENDING_CLASS} .rt_${richText.id}_br_${blockIndex} {${lhPending}}`);
72
76
  });
73
77
  continue;
74
78
  }
@@ -159,9 +163,17 @@ export class RichTextConverter {
159
163
  }
160
164
  styleRules[item.layout].push(`
161
165
  .${blockClass} .s-${styleGroup.start}-${styleGroup.end} {
162
- ${styleGroup.styles.map(s => RichTextConverter.fromRangeStylesToInline(s, exemplary)).join('\n')}
166
+ ${styleGroup.styles.map(s => RichTextConverter.fromRangeStylesToInline(s, exemplary, true)).join('\n')}
167
+ }
168
+ `);
169
+ const lengthStyles = styleGroup.styles.filter(s => SCALING_STYLES.has(s.name));
170
+ if (lengthStyles.length !== 0) {
171
+ styleRules[item.layout].push(`
172
+ .${RICH_TEXT_LAYOUT_PENDING_CLASS} .${blockClass} .s-${styleGroup.start}-${styleGroup.end} {
173
+ ${lengthStyles.map(s => RichTextConverter.fromRangeStylesToInline(s, exemplary, false)).join('\n')}
163
174
  }
164
175
  `);
176
+ }
165
177
  if (color) {
166
178
  styleRules[item.layout].push(`
167
179
  @supports not (color: oklch(42% 0.3 90 / 1)) {
@@ -275,17 +287,17 @@ export class RichTextConverter {
275
287
  return entitiesGroups;
276
288
  }
277
289
 
278
- private static fromRangeStylesToInline(draftStyle: Style, exemplary: number): string {
290
+ private static fromRangeStylesToInline(draftStyle: Style, exemplary: number, isLayoutDefined: boolean): string {
279
291
  const { value, name } = draftStyle;
280
292
  const map: Record<string, Record<string, string | undefined>> = {
281
293
  COLOR: { color: getResolvedValue(value, name) },
282
294
  TYPEFACE: { 'font-family': `${getFontFamilyValue(value!)}` },
283
295
  FONTSTYLE: value ? { ...FontStyles[value] } : {},
284
296
  FONTWEIGHT: { 'font-weight': value },
285
- FONTSIZE: { 'font-size': `${Number.parseFloat(value!) * exemplary}px` },
286
- LINEHEIGHT: { 'line-height': `${Number.parseFloat(value!) * exemplary}px` },
287
- LETTERSPACING: { 'letter-spacing': `${Number.parseFloat(value!) * exemplary}px` },
288
- WORDSPACING: { 'word-spacing': `${Number.parseFloat(value!) * exemplary}px` },
297
+ FONTSIZE: { 'font-size': getScaledValue(value, exemplary, isLayoutDefined) },
298
+ LINEHEIGHT: { 'line-height': getScaledValue(value, exemplary, isLayoutDefined) },
299
+ LETTERSPACING: { 'letter-spacing': getScaledValue(value, exemplary, isLayoutDefined) },
300
+ WORDSPACING: { 'word-spacing': getScaledValue(value, exemplary, isLayoutDefined) },
289
301
  TEXTTRANSFORM: value ? { 'text-transform': value as TextTransform } : { 'text-transform': TextTransform.None },
290
302
  VERTICALALIGN: value ? { 'vertical-align': value as VerticalAlign } : { 'vertical-align': VerticalAlign.Unset },
291
303
  TEXTDECORATION: { 'text-decoration': value },
@@ -311,6 +323,11 @@ function groupBy<I>(items: I[], getKey: (item: I) => PropertyKey): Record<Proper
311
323
  return groups;
312
324
  }
313
325
 
326
+ function getScaledValue(value: string | undefined, exemplary: number, isLayoutDefined: boolean): string {
327
+ const ratio = Number.parseFloat(value!);
328
+ return !isLayoutDefined ? `${ratio * 100}vw` : `${ratio * exemplary}px`;
329
+ }
330
+
314
331
  function getResolvedValue(value: string | undefined, name: string) {
315
332
  if (name !== 'COLOR') return value;
316
333
  return value ? CntrlColor.parse(value).toCss() : value;