@cntrl-site/sdk-nextjs 0.17.1 → 0.18.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 (54) hide show
  1. package/lib/common/useRegisterResize.js +1 -1
  2. package/lib/components/Head.js +1 -1
  3. package/lib/components/Item.js +8 -8
  4. package/lib/components/Page.js +1 -4
  5. package/lib/components/items/ImageItem.js +2 -1
  6. package/lib/components/items/RectangleItem.js +3 -2
  7. package/lib/components/items/RichTextItem.js +3 -2
  8. package/lib/components/items/VideoItem.js +2 -1
  9. package/lib/components/items/useRichTextItem.js +2 -9
  10. package/lib/components/items/useStickyItemTop.js +1 -5
  11. package/lib/components/useSectionColor.js +3 -3
  12. package/lib/provider/CntrlSdkContext.js +1 -8
  13. package/lib/utils/Animator/Animator.js +3 -2
  14. package/lib/utils/HoverStyles/HoverStyles.js +4 -4
  15. package/lib/utils/RichTextConverter/RichTextConverter.js +3 -2
  16. package/package.json +3 -2
  17. package/src/common/useKeyframeValue.ts +3 -3
  18. package/src/common/useRegisterResize.ts +1 -1
  19. package/src/components/Article.tsx +1 -1
  20. package/src/components/Head.tsx +4 -4
  21. package/src/components/Item.tsx +15 -16
  22. package/src/components/LayoutStyle.tsx +3 -3
  23. package/src/components/Page.tsx +4 -10
  24. package/src/components/Section.tsx +4 -4
  25. package/src/components/items/CustomItem.tsx +1 -1
  26. package/src/components/items/ImageItem.tsx +2 -1
  27. package/src/components/items/RectangleItem.tsx +2 -1
  28. package/src/components/items/RichTextItem.tsx +2 -1
  29. package/src/components/items/VideoItem.tsx +2 -1
  30. package/src/components/items/VimeoEmbed.tsx +1 -2
  31. package/src/components/items/YoutubeEmbed.tsx +1 -2
  32. package/src/components/items/useEmbedVideoItem.ts +2 -2
  33. package/src/components/items/useFileItem.ts +2 -2
  34. package/src/components/items/useRectangleItem.ts +2 -2
  35. package/src/components/items/useRichTextItem.ts +4 -10
  36. package/src/components/items/useRichTextItemValues.ts +2 -2
  37. package/src/components/items/useStickyItemTop.ts +3 -6
  38. package/src/components/useItemAngle.ts +2 -2
  39. package/src/components/useItemDimensions.ts +2 -2
  40. package/src/components/useItemPosition.ts +2 -2
  41. package/src/components/useItemScale.ts +2 -2
  42. package/src/components/useSectionColor.ts +1 -1
  43. package/src/components/useSectionHeightMap.ts +3 -3
  44. package/src/provider/CntrlSdkContext.ts +10 -21
  45. package/src/provider/Keyframes.ts +2 -2
  46. package/src/utils/Animator/Animator.ts +31 -30
  47. package/src/utils/HoverStyles/HoverStyles.ts +5 -4
  48. package/src/utils/RichTextConverter/RichTextConverter.tsx +10 -9
  49. package/cntrl-site-sdk-nextjs-0.17.1.tgz +0 -0
  50. package/lib/utils/generateTypePresetStyles/generateTypePresetStyles.js +0 -27
  51. package/src/utils/generateTypePresetStyles/__mock__/layoutsMock.ts +0 -43
  52. package/src/utils/generateTypePresetStyles/__mock__/presetMock.ts +0 -33
  53. package/src/utils/generateTypePresetStyles/generateTypePresetStyles.test.ts +0 -49
  54. package/src/utils/generateTypePresetStyles/generateTypePresetStyles.ts +0 -25
@@ -12,7 +12,7 @@ const useRegisterResize = (ref, onResize) => {
12
12
  return;
13
13
  const observer = new resize_observer_polyfill_1.default((entries) => {
14
14
  const [entry] = entries;
15
- onResize(entry.target.getBoundingClientRect().height / window.innerWidth);
15
+ onResize(entry.target.clientHeight / window.innerWidth);
16
16
  });
17
17
  observer.observe(ref);
18
18
  return () => {
@@ -15,7 +15,7 @@ const CNTRLHead = ({ meta, project }) => {
15
15
  const customFonts = project.fonts.custom;
16
16
  const htmlHead = (0, html_react_parser_1.default)(project.html.head);
17
17
  const ffGenerator = new sdk_1.FontFaceGenerator(customFonts);
18
- const links = Object.values(parsedFonts).map((value, i) => {
18
+ const links = Object.values(parsedFonts).map((value) => {
19
19
  var _a, _b;
20
20
  if (!value)
21
21
  return;
@@ -71,8 +71,6 @@ const Item = ({ item, sectionId, articleHeight }) => {
71
71
  const ItemComponent = itemsMap[item.type] || noop;
72
72
  const sectionTop = rectObserver ? rectObserver.getSectionTop(sectionId) : 0;
73
73
  const handleItemResize = (height) => {
74
- var _a, _b;
75
- const itemSectionTop = (_b = (_a = itemWrapperRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop) !== null && _b !== void 0 ? _b : 0;
76
74
  if (!layout)
77
75
  return;
78
76
  const sticky = item.sticky[layout];
@@ -80,7 +78,7 @@ const Item = ({ item, sectionId, articleHeight }) => {
80
78
  setWrapperHeight(undefined);
81
79
  return;
82
80
  }
83
- const itemArticleOffset = (sectionTop + itemSectionTop) / window.innerWidth;
81
+ const itemArticleOffset = sectionTop / window.innerWidth + stickyTop;
84
82
  const maxStickyTo = articleHeight - itemArticleOffset - height;
85
83
  const end = sticky.to
86
84
  ? Math.min(maxStickyTo, sticky.to)
@@ -93,17 +91,19 @@ const Item = ({ item, sectionId, articleHeight }) => {
93
91
  isInitialRef.current = false;
94
92
  }, []);
95
93
  const isRichText = isItemType(item, sdk_1.ArticleItemType.RichText);
94
+ if (!layout)
95
+ return null;
96
96
  const styles = {
97
- top: stickyTop,
97
+ top: `${(0, getAnchoredItemTop_1.getAnchoredItemTop)(stickyTop, sectionHeight[layout], item.area[layout].anchorSide)}`,
98
98
  height: isRichText && itemHeight ? `${itemHeight * 100}vw` : 'unset'
99
99
  };
100
100
  return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: `item-wrapper-${item.id}`, ref: itemWrapperRef, style: isInitialRef.current ? {} : Object.assign({ top, left }, (wrapperHeight !== undefined ? { height: `${wrapperHeight * 100}vw` } : {})) }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ suppressHydrationWarning: true, className: `item-${item.id}`, style: isInitialRef.current ? {} : styles }, { children: (0, jsx_runtime_1.jsx)(RichTextWrapper, Object.assign({ isRichText: isRichText }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ className: `item-${item.id}-inner`, style: {
101
- width: `${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual
101
+ width: `${sizingAxis.x === 'manual'
102
102
  ? isRichText
103
103
  ? `${width * exemplary}px`
104
104
  : `${width * 100}vw`
105
105
  : 'max-content'}`,
106
- height: `${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${height * 100}vw` : 'unset'}`,
106
+ height: `${sizingAxis.y === 'manual' ? `${height * 100}vw` : 'unset'}`,
107
107
  transform: `scale(${scale})`,
108
108
  transformOrigin: ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]
109
109
  } }, { children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize }) })) })) })), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
@@ -120,8 +120,8 @@ const Item = ({ item, sectionId, articleHeight }) => {
120
120
  }
121
121
  .item-${item.id}-inner {
122
122
  transition: ${(0, HoverStyles_1.getTransitions)(['width', 'height', 'scale'], hoverParams)};
123
- width: ${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual ? `${area.width * 100}vw` : 'max-content'};
124
- height: ${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${area.height * 100}vw` : 'unset'};
123
+ width: ${sizingAxis.x === 'manual' ? `${area.width * 100}vw` : 'max-content'};
124
+ height: ${sizingAxis.y === 'manual' ? `${area.height * 100}vw` : 'unset'};
125
125
  transform: scale(${scale});
126
126
  transform-origin: ${ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]};
127
127
  --webkit-backface-visibility: hidden;
@@ -10,14 +10,11 @@ const html_react_parser_1 = __importDefault(require("html-react-parser"));
10
10
  const Article_1 = require("./Article");
11
11
  const KeyframesContext_1 = require("../provider/KeyframesContext");
12
12
  const Head_1 = require("./Head");
13
- const useCntrlContext_1 = require("../provider/useCntrlContext");
14
- const generateTypePresetStyles_1 = require("../utils/generateTypePresetStyles/generateTypePresetStyles");
15
13
  const Keyframes_1 = require("../provider/Keyframes");
16
14
  const Page = ({ article, project, meta, keyframes, sectionData }) => {
17
15
  const afterBodyOpen = (0, html_react_parser_1.default)(project.html.afterBodyOpen);
18
16
  const beforeBodyClose = (0, html_react_parser_1.default)(project.html.beforeBodyClose);
19
17
  const keyframesRepo = (0, react_1.useMemo)(() => new Keyframes_1.Keyframes(keyframes), [keyframes]);
20
- const { typePresets, layouts } = (0, useCntrlContext_1.useCntrlContext)();
21
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Head_1.CNTRLHead, { project: project, meta: meta }), afterBodyOpen, (0, jsx_runtime_1.jsx)(KeyframesContext_1.KeyframesContext.Provider, Object.assign({ value: keyframesRepo }, { children: (0, jsx_runtime_1.jsx)(Article_1.Article, { article: article, sectionData: sectionData }) })), beforeBodyClose, typePresets && typePresets.presets.length > 0 && ((0, jsx_runtime_1.jsx)("style", { children: (0, generateTypePresetStyles_1.generateTypePresetStyles)(typePresets, layouts) }))] }));
18
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Head_1.CNTRLHead, { project: project, meta: meta }), afterBodyOpen, (0, jsx_runtime_1.jsx)(KeyframesContext_1.KeyframesContext.Provider, Object.assign({ value: keyframesRepo }, { children: (0, jsx_runtime_1.jsx)(Article_1.Article, { article: article, sectionData: sectionData }) })), beforeBodyClose] }));
22
19
  };
23
20
  exports.Page = Page;
@@ -7,6 +7,7 @@ exports.ImageItem = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const react_1 = require("react");
9
9
  const style_1 = __importDefault(require("styled-jsx/style"));
10
+ const color_1 = require("@cntrl-site/color");
10
11
  const sdk_1 = require("@cntrl-site/sdk");
11
12
  const LinkWrapper_1 = require("../LinkWrapper");
12
13
  const useFileItem_1 = require("./useFileItem");
@@ -20,7 +21,7 @@ const ImageItem = ({ item, sectionId, onResize }) => {
20
21
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
21
22
  const { radius, strokeWidth, opacity, strokeColor, blur } = (0, useFileItem_1.useFileItem)(item, sectionId);
22
23
  const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
23
- const borderColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(strokeColor), [strokeColor]);
24
+ const borderColor = (0, react_1.useMemo)(() => color_1.CntrlColor.parse(strokeColor), [strokeColor]);
24
25
  const [ref, setRef] = (0, react_1.useState)(null);
25
26
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
26
27
  return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, Object.assign({ url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url }, { children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: `image-wrapper-${item.id}`, ref: setRef, style: {
@@ -7,6 +7,7 @@ exports.RectangleItem = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const react_1 = require("react");
9
9
  const style_1 = __importDefault(require("styled-jsx/style"));
10
+ const color_1 = require("@cntrl-site/color");
10
11
  const sdk_1 = require("@cntrl-site/sdk");
11
12
  const LinkWrapper_1 = require("../LinkWrapper");
12
13
  const useRectangleItem_1 = require("./useRectangleItem");
@@ -20,8 +21,8 @@ const RectangleItem = ({ item, sectionId, onResize }) => {
20
21
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
21
22
  const { fillColor, radius, strokeWidth, strokeColor, blur, backdropBlur } = (0, useRectangleItem_1.useRectangleItem)(item, sectionId);
22
23
  const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
23
- const backgroundColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(fillColor), [fillColor]);
24
- const borderColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(strokeColor), [strokeColor]);
24
+ const backgroundColor = (0, react_1.useMemo)(() => color_1.CntrlColor.parse(fillColor), [fillColor]);
25
+ const borderColor = (0, react_1.useMemo)(() => color_1.CntrlColor.parse(strokeColor), [strokeColor]);
25
26
  const [ref, setRef] = (0, react_1.useState)(null);
26
27
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
27
28
  const backdropFilterValue = backdropBlur !== 0 ? `blur(${backdropBlur * 100}vw)` : 'unset';
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RichTextItem = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const react_1 = require("react");
9
+ const color_1 = require("@cntrl-site/color");
9
10
  const sdk_1 = require("@cntrl-site/sdk");
10
11
  const style_1 = __importDefault(require("styled-jsx/style"));
11
12
  const useRichTextItem_1 = require("./useRichTextItem");
@@ -20,7 +21,7 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
20
21
  const [ref, setRef] = (0, react_1.useState)(null);
21
22
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
22
23
  const { angle, blur, wordSpacing, letterSpacing, color } = (0, useRichTextItemValues_1.useRichTextItemValues)(item, sectionId);
23
- const textColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(color), [color]);
24
+ const textColor = (0, react_1.useMemo)(() => color_1.CntrlColor.parse(color), [color]);
24
25
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
25
26
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ ref: setRef, className: `rich-text-wrapper-${item.id}`, style: {
26
27
  transform: `rotate(${angle}deg)`,
@@ -38,7 +39,7 @@ const RichTextItem = ({ item, sectionId, onResize }) => {
38
39
  }
39
40
  `);
40
41
  })}`, `${(0, sdk_1.getLayoutStyles)(layouts, [item.layoutParams], ([layoutParams], exemplary) => {
41
- const color = sdk_1.CntrlColor.parse(layoutParams.color);
42
+ const color = color_1.CntrlColor.parse(layoutParams.color);
42
43
  return (`
43
44
  .rich-text-wrapper-${item.id} {
44
45
  font-size: ${Math.round(layoutParams.fontSize * exemplary)}px;
@@ -7,6 +7,7 @@ exports.VideoItem = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const react_1 = require("react");
9
9
  const style_1 = __importDefault(require("styled-jsx/style"));
10
+ const color_1 = require("@cntrl-site/color");
10
11
  const sdk_1 = require("@cntrl-site/sdk");
11
12
  const LinkWrapper_1 = require("../LinkWrapper");
12
13
  const useFileItem_1 = require("./useFileItem");
@@ -20,7 +21,7 @@ const VideoItem = ({ item, sectionId, onResize }) => {
20
21
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
21
22
  const { radius, strokeWidth, strokeColor, opacity, blur } = (0, useFileItem_1.useFileItem)(item, sectionId);
22
23
  const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
23
- const borderColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(strokeColor), [strokeColor]);
24
+ const borderColor = (0, react_1.useMemo)(() => color_1.CntrlColor.parse(strokeColor), [strokeColor]);
24
25
  const [ref, setRef] = (0, react_1.useState)(null);
25
26
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
26
27
  return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, Object.assign({ url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: `video-wrapper-${item.id}`, ref: setRef, style: {
@@ -3,17 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useRichTextItem = void 0;
4
4
  const RichTextConverter_1 = require("../../utils/RichTextConverter/RichTextConverter");
5
5
  const useCntrlContext_1 = require("../../provider/useCntrlContext");
6
- const useLayoutContext_1 = require("../useLayoutContext");
7
6
  const richTextConverter = new RichTextConverter_1.RichTextConverter();
8
7
  const useRichTextItem = (item) => {
9
- var _a;
10
- const layoutId = (0, useLayoutContext_1.useLayoutContext)();
11
- const { layouts, typePresets } = (0, useCntrlContext_1.useCntrlContext)();
12
- const presetId = layoutId ? item.layoutParams[layoutId].preset : null;
13
- const preset = presetId
14
- ? (_a = typePresets === null || typePresets === void 0 ? void 0 : typePresets.presets.find(p => p.id === presetId)) !== null && _a !== void 0 ? _a : null
15
- : null;
8
+ const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
16
9
  const [content, styles] = richTextConverter.toHtml(item, layouts);
17
- return [content, styles, preset];
10
+ return [content, styles];
18
11
  };
19
12
  exports.useRichTextItem = useRichTextItem;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useStickyItemTop = void 0;
4
- const sdk_1 = require("@cntrl-site/sdk");
5
4
  const useKeyframeValue_1 = require("../../common/useKeyframeValue");
6
- const getAnchoredItemTop_1 = require("../../utils/getAnchoredItemTop");
7
5
  const useLayoutContext_1 = require("../useLayoutContext");
8
6
  function useStickyItemTop(item, sectionHeightMap, sectionId) {
9
7
  const layoutId = (0, useLayoutContext_1.useLayoutContext)();
@@ -13,8 +11,6 @@ function useStickyItemTop(item, sectionHeightMap, sectionId) {
13
11
  return item.area[layoutId];
14
12
  }, (animator, scroll, value) => animator.getPositions(value, scroll), sectionId, [layoutId]);
15
13
  const sticky = layoutId ? item.sticky[layoutId] : undefined;
16
- const sectionHeight = layoutId ? sectionHeightMap[layoutId] : '0vh';
17
- const anchorSide = layoutId ? item.area[layoutId].anchorSide : sdk_1.AnchorSide.Top;
18
- return sticky ? `${(0, getAnchoredItemTop_1.getAnchoredItemTop)(top - sticky.from, sectionHeight, anchorSide)}` : 0;
14
+ return sticky ? top - sticky.from : 0;
19
15
  }
20
16
  exports.useStickyItemTop = useStickyItemTop;
@@ -2,16 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useSectionColor = void 0;
4
4
  const react_1 = require("react");
5
- const sdk_1 = require("@cntrl-site/sdk");
5
+ const color_1 = require("@cntrl-site/color");
6
6
  const useLayoutContext_1 = require("./useLayoutContext");
7
7
  const DEFAULT_COLOR = 'rgba(0, 0, 0, 0)';
8
8
  const useSectionColor = (colorData) => {
9
9
  const layoutId = (0, useLayoutContext_1.useLayoutContext)();
10
10
  return (0, react_1.useMemo)(() => {
11
11
  if (!layoutId)
12
- return sdk_1.CntrlColor.parse(DEFAULT_COLOR);
12
+ return color_1.CntrlColor.parse(DEFAULT_COLOR);
13
13
  const layoutColor = colorData[layoutId];
14
- return sdk_1.CntrlColor.parse(!layoutColor
14
+ return color_1.CntrlColor.parse(!layoutColor
15
15
  ? DEFAULT_COLOR
16
16
  : layoutColor);
17
17
  }, [layoutId]);
@@ -31,14 +31,10 @@ class CntrlSdkContext {
31
31
  return Object.fromEntries(yield Promise.all(resolvers.map(({ name, resolver }) => __awaiter(this, void 0, void 0, function* () { return [name, yield resolver()]; }))));
32
32
  });
33
33
  }
34
- init({ project, typePresets, article }) {
35
- this.setTypePresets(typePresets);
34
+ init({ project, article }) {
36
35
  this.setLayouts(project.layouts);
37
36
  this.setSectionsHeight(article.sections);
38
37
  }
39
- setTypePresets(typePresets) {
40
- this._typePresets = typePresets;
41
- }
42
38
  setLayouts(layouts) {
43
39
  this._layouts = layouts;
44
40
  }
@@ -54,9 +50,6 @@ class CntrlSdkContext {
54
50
  get layouts() {
55
51
  return this._layouts;
56
52
  }
57
- get typePresets() {
58
- return this._typePresets;
59
- }
60
53
  }
61
54
  exports.CntrlSdkContext = CntrlSdkContext;
62
55
  function isDefined(value) {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Animator = void 0;
4
4
  const sdk_1 = require("@cntrl-site/sdk");
5
+ const color_1 = require("@cntrl-site/color");
5
6
  const binSearchInsertAt_1 = require("../binSearchInsertAt");
6
7
  const compare = (lhs, rhs) => lhs.position - rhs.position;
7
8
  const insertBin = (0, binSearchInsertAt_1.createInsert)(binSearchInsertAt_1.binSearchInsertAt, compare);
@@ -242,8 +243,8 @@ class Animator {
242
243
  }
243
244
  getRangeColor(start, end, position) {
244
245
  const rangeAmount = rangeMap(position, start.position, end.position, 0, 1, true);
245
- const startColor = sdk_1.CntrlColor.parse(start.value.color);
246
- const endColor = sdk_1.CntrlColor.parse(end.value.color);
246
+ const startColor = color_1.CntrlColor.parse(start.value.color);
247
+ const endColor = color_1.CntrlColor.parse(end.value.color);
247
248
  const mixedColor = startColor.mix(endColor, rangeAmount);
248
249
  return mixedColor.fmt('oklch');
249
250
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getHoverStyles = exports.getTransitions = void 0;
4
- const sdk_1 = require("@cntrl-site/sdk");
4
+ const color_1 = require("@cntrl-site/color");
5
5
  const getItemTopStyle_1 = require("../getItemTopStyle");
6
6
  const hoverTransformationMap = {
7
7
  'width': (width) => `width: ${width * 100}vw !important;`,
@@ -13,11 +13,11 @@ const hoverTransformationMap = {
13
13
  'opacity': (opacity) => `opacity: ${opacity} !important;`,
14
14
  'radius': (radius) => `border-radius: ${radius * 100}vw !important;`,
15
15
  'strokeWidth': (strokeWidth) => `border-width: ${strokeWidth * 100}vw !important;`,
16
- 'strokeColor': (strokeColor) => `border-color: ${sdk_1.CntrlColor.parse(strokeColor).toCss()} !important;`,
17
- 'fillColor': (fillColor) => `background-color: ${sdk_1.CntrlColor.parse(fillColor).toCss()} !important;`,
16
+ 'strokeColor': (strokeColor) => `border-color: ${color_1.CntrlColor.parse(strokeColor).toCss()} !important;`,
17
+ 'fillColor': (fillColor) => `background-color: ${color_1.CntrlColor.parse(fillColor).toCss()} !important;`,
18
18
  'blur': (blur) => `filter: blur(${blur * 100}vw) !important;`,
19
19
  'backdropBlur': (backdropBlur) => `backdrop-filter: blur(${backdropBlur * 100}vw) !important;`,
20
- 'color': (color) => `color: ${sdk_1.CntrlColor.parse(color).toCss()} !important;`,
20
+ 'color': (color) => `color: ${color_1.CntrlColor.parse(color).toCss()} !important;`,
21
21
  'letterSpacing': (letterSpacing) => `letter-spacing: ${letterSpacing * 100}vw !important;`,
22
22
  'wordSpacing': (wordSpacing) => `word-spacing: ${wordSpacing * 100}vw !important;`
23
23
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RichTextConverter = exports.FontStyles = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const color_1 = require("@cntrl-site/color");
5
6
  const sdk_1 = require("@cntrl-site/sdk");
6
7
  const LinkWrapper_1 = require("../../components/LinkWrapper");
7
8
  const getFontFamilyValue_1 = require("../getFontFamilyValue");
@@ -119,7 +120,7 @@ class RichTextConverter {
119
120
  styleRules[item.layout].push(`
120
121
  @supports not (color: oklch(42% 0.3 90 / 1)) {
121
122
  .${blockClass} .s-${styleGroup.start}-${styleGroup.end} {
122
- color: ${sdk_1.CntrlColor.parse(getResolvedValue(color.value, 'COLOR')).fmt('rgba')};
123
+ color: ${color_1.CntrlColor.parse(getResolvedValue(color.value, 'COLOR')).fmt('rgba')};
123
124
  }
124
125
  }
125
126
  `);
@@ -250,7 +251,7 @@ function groupBy(items, getKey) {
250
251
  function getResolvedValue(value, name) {
251
252
  if (name !== 'COLOR')
252
253
  return value;
253
- return value ? sdk_1.CntrlColor.parse(value).toCss() : value;
254
+ return value ? color_1.CntrlColor.parse(value).toCss() : value;
254
255
  }
255
256
  function sliceSymbols(text, start, end = NaN) {
256
257
  let startOffset = NaN;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.17.1",
3
+ "version": "0.18.0",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.ts",
@@ -21,7 +21,8 @@
21
21
  },
22
22
  "homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
23
23
  "dependencies": {
24
- "@cntrl-site/sdk": "^1.2.3",
24
+ "@cntrl-site/color": "^1.0.0",
25
+ "@cntrl-site/sdk": "^1.3.0",
25
26
  "@types/vimeo__player": "^2.18.0",
26
27
  "@vimeo/player": "^2.20.1",
27
28
  "html-react-parser": "^3.0.1",
@@ -1,4 +1,4 @@
1
- import { KeyframeType, TArticleItemAny } from '@cntrl-site/sdk';
1
+ import { KeyframeType, ItemAny } from '@cntrl-site/sdk';
2
2
  import isEqual from 'lodash.isequal';
3
3
  import { DependencyList, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import { ArticleRectContext } from '../provider/ArticleRectContext';
@@ -7,11 +7,11 @@ import { AnimationData, Animator } from '../utils/Animator/Animator';
7
7
  import { useLayoutContext } from '../components/useLayoutContext';
8
8
 
9
9
  export type AnimatorGetter<T> = (animator: Animator, scroll: number, value: T) => T;
10
- type ItemParamGetter<T> = (item: TArticleItemAny, layoutId: string | undefined) => T;
10
+ type ItemParamGetter<T> = (item: ItemAny, layoutId: string | undefined) => T;
11
11
  const emptyDeps: DependencyList = [];
12
12
 
13
13
  export const useKeyframeValue = <T>(
14
- item: TArticleItemAny,
14
+ item: ItemAny,
15
15
  itemParamsGetter: ItemParamGetter<T>,
16
16
  animatorGetter: AnimatorGetter<T>,
17
17
  sectionId: string,
@@ -6,7 +6,7 @@ export const useRegisterResize = (ref: HTMLElement | null, onResize?: (height: n
6
6
  if (!ref || !onResize) return;
7
7
  const observer = new ResizeObserver((entries) => {
8
8
  const [entry] = entries;
9
- onResize(entry.target.getBoundingClientRect().height / window.innerWidth);
9
+ onResize(entry.target.clientHeight / window.innerWidth);
10
10
  });
11
11
  observer.observe(ref);
12
12
  return () => {
@@ -1,6 +1,6 @@
1
1
  import { FC, useEffect, useId, useRef, useState } from 'react';
2
2
  import JSXStyle from 'styled-jsx/style';
3
- import { TArticle } from '@cntrl-site/sdk';
3
+ import { Article as TArticle } from '@cntrl-site/sdk';
4
4
  import { Section } from './Section';
5
5
  import { Item } from './Item';
6
6
  import { useArticleRectObserver } from '../utils/ArticleRectManager/useArticleRectObserver';
@@ -1,11 +1,11 @@
1
1
  import React, { FC } from 'react';
2
2
  import HTMLReactParser, { domToReact } from 'html-react-parser';
3
3
  import Head from 'next/head';
4
- import { FontFaceGenerator, TMeta, TProject } from '@cntrl-site/sdk';
4
+ import { FontFaceGenerator, Meta, Project } from '@cntrl-site/sdk';
5
5
 
6
6
  interface Props {
7
- project: TProject;
8
- meta: TMeta;
7
+ project: Project;
8
+ meta: Meta;
9
9
  }
10
10
 
11
11
  export const CNTRLHead: FC<Props> = ({ meta, project }) => {
@@ -18,7 +18,7 @@ export const CNTRLHead: FC<Props> = ({ meta, project }) => {
18
18
  const customFonts = project.fonts.custom;
19
19
  const htmlHead = HTMLReactParser(project.html.head);
20
20
  const ffGenerator = new FontFaceGenerator(customFonts);
21
- const links = Object.values(parsedFonts as ReturnType<typeof domToReact>).map((value, i) => {
21
+ const links = Object.values(parsedFonts as ReturnType<typeof domToReact>).map((value) => {
22
22
  if (!value) return;
23
23
  const rel = value?.rel || value.props?.rel;
24
24
  const href = value?.href || value.props?.href;
@@ -1,12 +1,10 @@
1
1
  import { ComponentType, FC, PropsWithChildren, useContext, useEffect, useId, useRef, useState } from 'react';
2
2
  import JSXStyle from 'styled-jsx/style';
3
3
  import {
4
- ArticleItemSizingType as SizingType,
5
4
  ArticleItemType,
6
5
  getLayoutStyles,
7
- TArticleItem,
8
- TStickyParams,
9
- TArticleItemAny,
6
+ Item as TItem,
7
+ ItemAny,
10
8
  } from '@cntrl-site/sdk';
11
9
  import { RectangleItem } from './items/RectangleItem';
12
10
  import { ImageItem } from './items/ImageItem';
@@ -29,13 +27,13 @@ import { useLayoutContext } from './useLayoutContext';
29
27
  import { ArticleRectContext } from "../provider/ArticleRectContext";
30
28
  import { useExemplary } from "../common/useExemplary";
31
29
 
32
- export interface ItemProps<I extends TArticleItemAny> {
30
+ export interface ItemProps<I extends ItemAny> {
33
31
  item: I;
34
32
  sectionId: string;
35
33
  onResize?: (height: number) => void;
36
34
  }
37
35
 
38
- export interface ItemWrapperProps extends ItemProps<TArticleItemAny> {
36
+ export interface ItemWrapperProps extends ItemProps<ItemAny> {
39
37
  articleHeight: number;
40
38
  }
41
39
 
@@ -94,14 +92,13 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
94
92
  const sectionTop = rectObserver ? rectObserver.getSectionTop(sectionId) : 0;
95
93
 
96
94
  const handleItemResize = (height: number) => {
97
- const itemSectionTop = itemWrapperRef.current?.offsetTop ?? 0;
98
95
  if (!layout) return;
99
96
  const sticky = item.sticky[layout];
100
97
  if (!sticky) {
101
98
  setWrapperHeight(undefined);
102
99
  return;
103
100
  }
104
- const itemArticleOffset = (sectionTop + itemSectionTop) / window.innerWidth;
101
+ const itemArticleOffset = sectionTop / window.innerWidth + stickyTop;
105
102
  const maxStickyTo = articleHeight - itemArticleOffset - height;
106
103
  const end = sticky.to
107
104
  ? Math.min(maxStickyTo, sticky.to)
@@ -117,8 +114,10 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
117
114
 
118
115
  const isRichText = isItemType(item, ArticleItemType.RichText);
119
116
 
117
+ if (!layout) return null;
118
+
120
119
  const styles = {
121
- top: stickyTop,
120
+ top: `${getAnchoredItemTop(stickyTop, sectionHeight[layout], item.area[layout].anchorSide)}`,
122
121
  height: isRichText && itemHeight ? `${itemHeight * 100}vw` : 'unset'
123
122
  };
124
123
 
@@ -137,12 +136,12 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
137
136
  <div
138
137
  className={`item-${item.id}-inner`}
139
138
  style={{
140
- width: `${sizingAxis.x === SizingType.Manual
139
+ width: `${sizingAxis.x === 'manual'
141
140
  ? isRichText
142
141
  ? `${width * exemplary}px`
143
142
  : `${width * 100}vw`
144
143
  : 'max-content'}`,
145
- height: `${sizingAxis.y === SizingType.Manual ? `${height * 100}vw` : 'unset'}`,
144
+ height: `${sizingAxis.y === 'manual' ? `${height * 100}vw` : 'unset'}`,
146
145
  transform: `scale(${scale})`,
147
146
  transformOrigin: ScaleAnchorMap[scaleAnchor]
148
147
  }}
@@ -165,8 +164,8 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
165
164
  }
166
165
  .item-${item.id}-inner {
167
166
  transition: ${getTransitions(['width', 'height', 'scale'], hoverParams)};
168
- width: ${sizingAxis.x === SizingType.Manual ? `${area.width * 100}vw` : 'max-content'};
169
- height: ${sizingAxis.y === SizingType.Manual ? `${area.height * 100}vw` : 'unset'};
167
+ width: ${sizingAxis.x === 'manual' ? `${area.width * 100}vw` : 'max-content'};
168
+ height: ${sizingAxis.y === 'manual' ? `${area.height * 100}vw` : 'unset'};
170
169
  transform: scale(${scale});
171
170
  transform-origin: ${ScaleAnchorMap[scaleAnchor]};
172
171
  --webkit-backface-visibility: hidden;
@@ -203,10 +202,10 @@ function parseSizing(sizing: string = 'manual'): Axis {
203
202
  }
204
203
 
205
204
  interface Axis {
206
- x: SizingType;
207
- y: SizingType;
205
+ x: 'manual' | 'auto';
206
+ y: 'manual' | 'auto';
208
207
  }
209
208
 
210
- export function isItemType<T extends ArticleItemType>(item: TArticleItemAny, itemType: T): item is TArticleItem<T> {
209
+ export function isItemType<T extends ArticleItemType>(item: ItemAny, itemType: T): item is TItem<T> {
211
210
  return item.type === itemType;
212
211
  }
@@ -1,12 +1,12 @@
1
1
  import React, { FC } from 'react';
2
- import { getLayoutMediaQuery, TLayout } from '@cntrl-site/sdk';
2
+ import { getLayoutMediaQuery, Layout } from '@cntrl-site/sdk';
3
3
  import JSXStyle from 'styled-jsx/style';
4
4
 
5
5
  export interface LayoutStyleProps {
6
6
  id: string;
7
- layouts: TLayout[];
7
+ layouts: Layout[];
8
8
  layoutId: string;
9
- children?: (layout: TLayout) => string;
9
+ children?: (layout: Layout) => string;
10
10
  }
11
11
 
12
12
  export const LayoutStyle: FC<LayoutStyleProps> = ({ id, layouts, layoutId, children }) => {
@@ -1,18 +1,16 @@
1
1
  import React, { FC, useMemo } from 'react';
2
2
  import HTMLReactParser from 'html-react-parser';
3
- import { TArticle, TProject, TMeta, TKeyframeAny } from '@cntrl-site/sdk';
3
+ import { Article as TArticle, Project, Meta, KeyframeAny } from '@cntrl-site/sdk';
4
4
  import { Article } from './Article';
5
5
  import { KeyframesContext } from '../provider/KeyframesContext';
6
6
  import { CNTRLHead } from './Head';
7
- import { useCntrlContext } from '../provider/useCntrlContext';
8
- import { generateTypePresetStyles } from '../utils/generateTypePresetStyles/generateTypePresetStyles';
9
7
  import { Keyframes } from '../provider/Keyframes';
10
8
 
11
9
  export interface PageProps {
12
10
  article: TArticle;
13
- project: TProject;
14
- meta: TMeta;
15
- keyframes: TKeyframeAny[];
11
+ project: Project;
12
+ meta: Meta;
13
+ keyframes: KeyframeAny[];
16
14
  sectionData: Record<SectionName, any>;
17
15
  }
18
16
 
@@ -20,7 +18,6 @@ export const Page: FC<PageProps> = ({ article, project, meta, keyframes, section
20
18
  const afterBodyOpen = HTMLReactParser(project.html.afterBodyOpen);
21
19
  const beforeBodyClose = HTMLReactParser(project.html.beforeBodyClose);
22
20
  const keyframesRepo = useMemo(() => new Keyframes(keyframes), [keyframes]);
23
- const { typePresets, layouts } = useCntrlContext();
24
21
  return (
25
22
  <>
26
23
  <CNTRLHead project={project} meta={meta} />
@@ -29,9 +26,6 @@ export const Page: FC<PageProps> = ({ article, project, meta, keyframes, section
29
26
  <Article article={article} sectionData={sectionData} />
30
27
  </KeyframesContext.Provider>
31
28
  {beforeBodyClose}
32
- {typePresets && typePresets.presets.length > 0 && (
33
- <style>{generateTypePresetStyles(typePresets, layouts)}</style>
34
- )}
35
29
  </>
36
30
  );
37
31
  };
@@ -3,8 +3,8 @@ import JSXStyle from 'styled-jsx/style';
3
3
  import {
4
4
  getLayoutMediaQuery,
5
5
  getLayoutStyles,
6
- TArticleSection,
7
- TSectionHeight,
6
+ Section as TSection,
7
+ SectionHeight,
8
8
  SectionHeightMode
9
9
  } from '@cntrl-site/sdk';
10
10
  import { useCntrlContext } from '../provider/useCntrlContext';
@@ -14,7 +14,7 @@ import { useSectionRegistry } from '../utils/ArticleRectManager/useSectionRegist
14
14
  type SectionChild = ReactElement<any, any>;
15
15
 
16
16
  interface Props {
17
- section: TArticleSection;
17
+ section: TSection;
18
18
  children: SectionChild[];
19
19
  data?: any;
20
20
  }
@@ -75,7 +75,7 @@ export const Section: FC<Props> = ({ section, data, children }) => {
75
75
  );
76
76
  };
77
77
 
78
- export function getSectionHeight(heightData: TSectionHeight): string {
78
+ export function getSectionHeight(heightData: SectionHeight): string {
79
79
  const { units, vhUnits, mode } = heightData;
80
80
  if (mode === SectionHeightMode.ViewportHeightUnits) return `${vhUnits}vh`;
81
81
  if (mode === SectionHeightMode.ControlUnits) return `${units * 100}vw`;
@@ -1,4 +1,4 @@
1
- import { ArticleItemType, getLayoutStyles, TCustomItem } from '@cntrl-site/sdk';
1
+ import { ArticleItemType, getLayoutStyles, CustomItem as TCustomItem } from '@cntrl-site/sdk';
2
2
  import { FC, useState } from 'react';
3
3
  import { useCntrlContext } from '../../provider/useCntrlContext';
4
4
  import { ItemProps } from '../Item';
@@ -1,6 +1,7 @@
1
1
  import { FC, useId, useMemo, useState } from 'react';
2
2
  import JSXStyle from 'styled-jsx/style';
3
- import { ArticleItemType, CntrlColor, getLayoutStyles, TImageItem } from '@cntrl-site/sdk';
3
+ import { CntrlColor } from '@cntrl-site/color';
4
+ import { ArticleItemType, getLayoutStyles, ImageItem as TImageItem } from '@cntrl-site/sdk';
4
5
  import { ItemProps } from '../Item';
5
6
  import { LinkWrapper } from '../LinkWrapper';
6
7
  import { useFileItem } from './useFileItem';
@@ -1,6 +1,7 @@
1
1
  import { FC, useId, useMemo, useState } from 'react';
2
2
  import JSXStyle from 'styled-jsx/style';
3
- import { TRectangleItem, CntrlColor, getLayoutStyles, ArticleItemType } from '@cntrl-site/sdk';
3
+ import { CntrlColor } from '@cntrl-site/color';
4
+ import { RectangleItem as TRectangleItem, getLayoutStyles, ArticleItemType } from '@cntrl-site/sdk';
4
5
  import { ItemProps } from '../Item';
5
6
  import { LinkWrapper } from '../LinkWrapper';
6
7
  import { useRectangleItem } from './useRectangleItem';