@cntrl-site/sdk-nextjs 1.9.14 → 1.9.16

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 (59) hide show
  1. package/lib/ItemGeometry/GenericGeometryController.js +43 -0
  2. package/lib/ItemGeometry/ItemGeometryContext.js +6 -0
  3. package/lib/ItemGeometry/ItemGeometryController.js +2 -0
  4. package/lib/ItemGeometry/ItemGeometryService.js +34 -0
  5. package/lib/ItemGeometry/RichTextGeometryController.js +135 -0
  6. package/lib/ItemGeometry/useItemGeometry.js +25 -0
  7. package/lib/components/Page.js +4 -1
  8. package/lib/components/items/CodeEmbedItem/CodeEmbedItem.js +2 -0
  9. package/lib/components/items/ComponentItem/ComponentItem.js +2 -0
  10. package/lib/components/items/CompoundItem/CompoundItem.js +17 -0
  11. package/lib/components/items/CustomItem/CustomItem.js +2 -0
  12. package/lib/components/items/EmbedVideoItem/VimeoEmbed.js +2 -0
  13. package/lib/components/items/EmbedVideoItem/YoutubeEmbed.js +2 -0
  14. package/lib/components/items/FileItem/ImageItem.js +2 -0
  15. package/lib/components/items/FileItem/VideoItem.js +2 -0
  16. package/lib/components/items/GroupItem/GroupItem.js +17 -0
  17. package/lib/components/items/Item.js +8 -0
  18. package/lib/components/items/RectangleItem/RectangleItem.js +2 -0
  19. package/lib/components/items/RichTextItem/RichTextItem.js +5 -1
  20. package/lib/components/items/useRichTextItemValues.js +2 -1
  21. package/lib/interactions/InteractionsRegistry.js +113 -12
  22. package/lib/interactions/ItemInteractionCtrl.js +1 -1
  23. package/lib/interactions/getTransition.js +1 -1
  24. package/lib/provider/InteractionsContext.js +4 -2
  25. package/lib/utils/CSSNumeric.js +19 -0
  26. package/lib/utils/RichTextConverter/RichTextConverter.js +4 -4
  27. package/lib/utils/domDfs.js +15 -0
  28. package/package.json +2 -2
  29. package/src/ItemGeometry/GenericGeometryController.ts +59 -0
  30. package/src/ItemGeometry/ItemGeometryContext.ts +4 -0
  31. package/src/ItemGeometry/ItemGeometryController.ts +22 -0
  32. package/src/ItemGeometry/ItemGeometryService.ts +34 -0
  33. package/src/ItemGeometry/RichTextGeometryController.ts +166 -0
  34. package/src/ItemGeometry/useItemGeometry.ts +25 -0
  35. package/src/components/Page.tsx +8 -3
  36. package/src/components/items/CodeEmbedItem/CodeEmbedItem.tsx +2 -0
  37. package/src/components/items/ComponentItem/ComponentItem.tsx +2 -0
  38. package/src/components/items/CompoundItem/CompoundItem.tsx +18 -1
  39. package/src/components/items/CustomItem/CustomItem.tsx +2 -0
  40. package/src/components/items/EmbedVideoItem/VimeoEmbed.tsx +2 -0
  41. package/src/components/items/EmbedVideoItem/YoutubeEmbed.tsx +2 -0
  42. package/src/components/items/FileItem/ImageItem.tsx +2 -0
  43. package/src/components/items/FileItem/VideoItem.tsx +2 -0
  44. package/src/components/items/GroupItem/GroupItem.tsx +18 -1
  45. package/src/components/items/Item.tsx +11 -3
  46. package/src/components/items/RectangleItem/RectangleItem.tsx +3 -1
  47. package/src/components/items/RichTextItem/RichTextItem.tsx +6 -1
  48. package/src/components/items/useRichTextItemValues.ts +2 -1
  49. package/src/interactions/InteractionsRegistry.ts +120 -15
  50. package/src/interactions/ItemInteractionCtrl.ts +2 -2
  51. package/src/interactions/getTransition.ts +1 -1
  52. package/src/interactions/types.ts +2 -2
  53. package/src/provider/InteractionsContext.tsx +4 -2
  54. package/src/utils/CSSNumeric.ts +19 -0
  55. package/src/utils/RichTextConverter/RichTextConverter.tsx +20 -4
  56. package/src/utils/domDfs.ts +11 -0
  57. package/cntrl-site-sdk-nextjs-1.9.14-2.tgz +0 -0
  58. /package/lib/{interactions → ItemGeometry}/CSSPropertyNameMap.js +0 -0
  59. /package/src/{interactions → ItemGeometry}/CSSPropertyNameMap.ts +0 -0
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GenericGeometryController = void 0;
4
+ const sdk_1 = require("@cntrl-site/sdk");
5
+ class GenericGeometryController {
6
+ constructor(container) {
7
+ this.container = container;
8
+ this.scale = 1;
9
+ this.offsetParent = null;
10
+ this.angle = 0;
11
+ }
12
+ setRegistry(registry) {
13
+ this.registry = registry;
14
+ }
15
+ setParentId(parentId) {
16
+ this.parentId = parentId;
17
+ }
18
+ getParentId() {
19
+ return this.parentId;
20
+ }
21
+ getBoundary() {
22
+ const rect = this.container.getBoundingClientRect();
23
+ return sdk_1.Rect.fromObject(rect);
24
+ }
25
+ getContentBoundary() {
26
+ return this.getBoundary();
27
+ }
28
+ setScale(scale) {
29
+ this.scale = scale;
30
+ }
31
+ setAngle(angle) {
32
+ this.angle = angle;
33
+ }
34
+ setOptions(options) {
35
+ }
36
+ getAngle() {
37
+ return 0;
38
+ }
39
+ getScale() {
40
+ return 1;
41
+ }
42
+ }
43
+ exports.GenericGeometryController = GenericGeometryController;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ItemGeometryContext = void 0;
4
+ const react_1 = require("react");
5
+ const ItemGeometryService_1 = require("./ItemGeometryService");
6
+ exports.ItemGeometryContext = (0, react_1.createContext)(new ItemGeometryService_1.ItemGeometryService());
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ItemGeometryService = void 0;
4
+ const sdk_1 = require("@cntrl-site/sdk");
5
+ class ItemGeometryService {
6
+ constructor() {
7
+ this.registry = new Map();
8
+ }
9
+ register(itemId, controller) {
10
+ this.registry.set(itemId, controller);
11
+ controller.setRegistry(this);
12
+ return () => {
13
+ this.registry.delete(itemId);
14
+ };
15
+ }
16
+ getItemBoundary(itemId) {
17
+ const controller = this.registry.get(itemId);
18
+ if (!controller) {
19
+ return new sdk_1.Rect(0, 0, 0, 0);
20
+ }
21
+ return controller.getContentBoundary();
22
+ }
23
+ getControllerById(itemId) {
24
+ const controller = this.registry.get(itemId);
25
+ if (!controller) {
26
+ throw new ReferenceError(`There is no registred contoller for item w/ id ${itemId}`);
27
+ }
28
+ return controller;
29
+ }
30
+ hasItem(itemId) {
31
+ return this.registry.has(itemId);
32
+ }
33
+ }
34
+ exports.ItemGeometryService = ItemGeometryService;
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RichTextGeometryController = exports.SizingType = void 0;
4
+ const sdk_1 = require("@cntrl-site/sdk");
5
+ const domDfs_1 = require("../utils/domDfs");
6
+ const CSSNumeric_1 = require("../utils/CSSNumeric");
7
+ var SizingType;
8
+ (function (SizingType) {
9
+ SizingType["Auto"] = "auto";
10
+ SizingType["Manual"] = "manual";
11
+ })(SizingType || (exports.SizingType = SizingType = {}));
12
+ class RichTextGeometryController {
13
+ static parseCssValue(value) {
14
+ const parsedLs = Number.parseInt(value);
15
+ return Number.isNaN(parsedLs) ? 0 : parsedLs;
16
+ }
17
+ constructor(container) {
18
+ this.container = container;
19
+ this.scale = 1;
20
+ this.angle = 0;
21
+ }
22
+ setRegistry(registry) {
23
+ this.registry = registry;
24
+ }
25
+ getBoundary(isRotatedBoundary) {
26
+ const rect = this.container.getBoundingClientRect();
27
+ if (isRotatedBoundary) {
28
+ return sdk_1.Rect.fromObject(rect);
29
+ }
30
+ const angle = this.getAngle();
31
+ if (angle === 0)
32
+ return sdk_1.Rect.fromObject(rect);
33
+ const styles = getComputedStyle(this.container);
34
+ const ratio = Number.parseInt(styles.width) / Number.parseInt(styles.height);
35
+ return sdk_1.Rect.getOriginRectFromBoundary(rect, angle, ratio);
36
+ }
37
+ getContentGuides() {
38
+ const boundary = this.getBoundary();
39
+ const contentXs = new Set();
40
+ const { xSizing } = this.options;
41
+ const contentYs = new Set();
42
+ (0, domDfs_1.domDfs)(Array.from(this.container.children), (el) => {
43
+ var _a, _b;
44
+ if (el.children.length !== 0)
45
+ return;
46
+ const rects = el.getClientRects();
47
+ const styles = window.getComputedStyle(el);
48
+ const ls = RichTextGeometryController.parseCssValue(styles.letterSpacing);
49
+ const metrics = (0, sdk_1.measureFont)(this.getFontStr(styles), (_b = (_a = el.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '');
50
+ const { capHeight, baseline, fontBoxHeight, xHeight, leftMargin, rightMargin } = metrics;
51
+ for (let i = 0; i <= rects.length - 1; i += 1) {
52
+ const rect = rects[i];
53
+ const halfLead = (rect.height - fontBoxHeight) / 2;
54
+ contentXs.add(rect.left + leftMargin - boundary.left);
55
+ contentXs.add(rect.right - rightMargin - ls - boundary.left);
56
+ contentYs.add(rect.top + halfLead + baseline - boundary.top); // baseline
57
+ if (i === 0) {
58
+ contentYs.add(rect.top + halfLead + baseline - capHeight - boundary.top); // cap height
59
+ }
60
+ if (rects.length === 1) {
61
+ contentYs.add(rect.top + halfLead + baseline - xHeight - boundary.top); // x-height
62
+ }
63
+ }
64
+ });
65
+ const left = xSizing === SizingType.Auto ? Math.min(...contentXs.values()) : 0;
66
+ const right = xSizing === SizingType.Auto ? Math.max(...contentXs.values()) : boundary.width;
67
+ const center = left + (right - left) / 2;
68
+ return [
69
+ boundary,
70
+ [left, center, right],
71
+ [...Array.from(contentYs.values(), y => y)]
72
+ ];
73
+ }
74
+ setParentId(parentId) {
75
+ this.parentId = parentId;
76
+ }
77
+ getParentId() {
78
+ return this.parentId;
79
+ }
80
+ setScale(scale) {
81
+ this.scale = scale;
82
+ }
83
+ setAngle(angle) {
84
+ this.angle = angle;
85
+ }
86
+ getContentBoundary() {
87
+ if (this.getAngle() !== 0) {
88
+ return this.getBoundary(true);
89
+ }
90
+ const [boundary, xs, ys] = this.getContentGuides();
91
+ const left = Math.min(...xs);
92
+ const right = Math.max(...xs);
93
+ const top = Math.min(...ys);
94
+ const bottom = Math.max(...ys);
95
+ const content = new sdk_1.Rect(boundary.left + left, boundary.top + top, right - left, bottom - top);
96
+ return content;
97
+ }
98
+ getFontStr(styles) {
99
+ const fontSize = (0, CSSNumeric_1.parseCSSNumber)(styles.fontSize);
100
+ const lineHeight = (0, CSSNumeric_1.parseCSSNumber)(styles.lineHeight);
101
+ const scaledFontSize = (0, CSSNumeric_1.formatCSSNumber)({
102
+ value: fontSize.value * this.getScale(),
103
+ unit: fontSize.unit
104
+ });
105
+ const scaledLineHeight = (0, CSSNumeric_1.formatCSSNumber)({
106
+ value: lineHeight.value * this.getScale(),
107
+ unit: lineHeight.unit
108
+ });
109
+ return `${scaledFontSize} / ${scaledLineHeight} ${styles.fontFamily}`;
110
+ }
111
+ setOptions(options) {
112
+ if (!options)
113
+ return;
114
+ this.options = options;
115
+ }
116
+ getAngle() {
117
+ return this.angle + this.getParentAngle();
118
+ }
119
+ getScale() {
120
+ return this.scale * this.getParentScale();
121
+ }
122
+ getParentAngle() {
123
+ if (!this.registry || !this.parentId)
124
+ return 0;
125
+ const parentController = this.registry.getControllerById(this.parentId);
126
+ return parentController.getAngle();
127
+ }
128
+ getParentScale() {
129
+ if (!this.registry || !this.parentId)
130
+ return 1;
131
+ const parentController = this.registry.getControllerById(this.parentId);
132
+ return parentController.getScale();
133
+ }
134
+ }
135
+ exports.RichTextGeometryController = RichTextGeometryController;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useItemGeometry = void 0;
4
+ const react_1 = require("react");
5
+ const GenericGeometryController_1 = require("./GenericGeometryController");
6
+ const ItemGeometryContext_1 = require("./ItemGeometryContext");
7
+ function useItemGeometry(itemId, element,
8
+ // @ts-ignore
9
+ controllerCtor = GenericGeometryController_1.GenericGeometryController, options) {
10
+ const itemGeometryService = (0, react_1.useContext)(ItemGeometryContext_1.ItemGeometryContext);
11
+ const controller = (0, react_1.useMemo)(() => {
12
+ if (!element)
13
+ return undefined;
14
+ return new controllerCtor(element);
15
+ }, [element, controllerCtor]);
16
+ (0, react_1.useEffect)(() => {
17
+ if (!controller)
18
+ return;
19
+ controller.setOptions(options);
20
+ return itemGeometryService.register(itemId, controller);
21
+ }, [itemGeometryService, itemId, controller]);
22
+ // @ts-ignore
23
+ return controller;
24
+ }
25
+ exports.useItemGeometry = useItemGeometry;
@@ -11,10 +11,13 @@ const Article_1 = require("./Article");
11
11
  const KeyframesContext_1 = require("../provider/KeyframesContext");
12
12
  const Head_1 = require("./Head");
13
13
  const Keyframes_1 = require("../provider/Keyframes");
14
+ const ItemGeometryContext_1 = require("../ItemGeometry/ItemGeometryContext");
15
+ const ItemGeometryService_1 = require("../ItemGeometry/ItemGeometryService");
14
16
  const Page = ({ article, project, meta, keyframes, sectionData }) => {
15
17
  const afterBodyOpen = (0, html_react_parser_1.default)(project.html.afterBodyOpen);
16
18
  const beforeBodyClose = (0, html_react_parser_1.default)(project.html.beforeBodyClose);
17
19
  const keyframesRepo = (0, react_1.useMemo)(() => new Keyframes_1.Keyframes(keyframes), [keyframes]);
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, { value: keyframesRepo, children: (0, jsx_runtime_1.jsx)(Article_1.Article, { article: article, sectionData: sectionData }) }), beforeBodyClose] }));
20
+ const itemGeometryService = (0, react_1.useMemo)(() => new ItemGeometryService_1.ItemGeometryService(), []);
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)(ItemGeometryContext_1.ItemGeometryContext.Provider, { value: itemGeometryService, children: (0, jsx_runtime_1.jsx)(KeyframesContext_1.KeyframesContext.Provider, { value: keyframesRepo, children: (0, jsx_runtime_1.jsx)(Article_1.Article, { article: article, sectionData: sectionData }) }) }), beforeBodyClose] }));
19
22
  };
20
23
  exports.Page = Page;
@@ -13,6 +13,7 @@ const useRegisterResize_1 = require("../../../common/useRegisterResize");
13
13
  const useItemAngle_1 = require("../useItemAngle");
14
14
  const LinkWrapper_1 = require("../LinkWrapper");
15
15
  const useCodeEmbedItem_1 = require("./useCodeEmbedItem");
16
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
16
17
  const stylesMap = {
17
18
  [sdk_1.AreaAnchor.TopLeft]: {},
18
19
  [sdk_1.AreaAnchor.TopCenter]: { justifyContent: 'center' },
@@ -36,6 +37,7 @@ const CodeEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilit
36
37
  const html = decodeBase64(item.commonParams.html);
37
38
  const [ref, setRef] = (0, react_1.useState)(null);
38
39
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
40
+ (0, useItemGeometry_1.useItemGeometry)(item.id, ref);
39
41
  const pos = stylesMap[anchor];
40
42
  const layoutValues = [item.area, item.layoutParams];
41
43
  const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'opacity']);
@@ -14,6 +14,7 @@ const useItemAngle_1 = require("../useItemAngle");
14
14
  const useRegisterResize_1 = require("../../../common/useRegisterResize");
15
15
  const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromItemStateAndParams");
16
16
  const useLayoutContext_1 = require("../../useLayoutContext");
17
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
17
18
  const ComponentItem = ({ item, sectionId, onResize, interactionCtrl }) => {
18
19
  var _a, _b, _c, _d;
19
20
  const sdk = (0, useCntrlContext_1.useCntrlContext)();
@@ -25,6 +26,7 @@ const ComponentItem = ({ item, sectionId, onResize, interactionCtrl }) => {
25
26
  const [ref, setRef] = (0, react_1.useState)(null);
26
27
  const { opacity: itemOpacity, blur: itemBlur } = (0, useComponentItem_1.useComponentItem)(item, sectionId);
27
28
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
29
+ (0, useItemGeometry_1.useItemGeometry)(item.id, ref);
28
30
  const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['opacity', 'angle', 'blur']);
29
31
  const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _a === void 0 ? void 0 : _a.angle, itemAngle);
30
32
  const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_b = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _b === void 0 ? void 0 : _b.opacity, itemOpacity);
@@ -15,16 +15,21 @@ const style_1 = __importDefault(require("styled-jsx/style"));
15
15
  const sdk_1 = require("@cntrl-site/sdk");
16
16
  const CompoundChild_1 = require("./CompoundChild");
17
17
  const useCompoundItem_1 = require("./useCompoundItem");
18
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
19
+ const ItemGeometryContext_1 = require("../../../ItemGeometry/ItemGeometryContext");
18
20
  const CompoundItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
19
21
  var _a, _b, _c, _d, _e;
20
22
  const id = (0, react_1.useId)();
21
23
  const { items } = item;
24
+ const itemIds = items ? items.map(item => item.id) : [];
22
25
  const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
23
26
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
24
27
  const { opacity: itemOpacity } = (0, useCompoundItem_1.useCompoundItem)(item, sectionId);
25
28
  const layoutValues = [item.area, item.layoutParams];
26
29
  const [ref, setRef] = (0, react_1.useState)(null);
27
30
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
31
+ (0, useItemGeometry_1.useItemGeometry)(item.id, ref);
32
+ const itemGeometryService = (0, react_1.useContext)(ItemGeometryContext_1.ItemGeometryContext);
28
33
  const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['opacity', 'angle']);
29
34
  const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _a === void 0 ? void 0 : _a.angle, itemAngle);
30
35
  const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_b = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _b === void 0 ? void 0 : _b.opacity, itemOpacity);
@@ -32,6 +37,18 @@ const CompoundItem = ({ item, sectionId, onResize, interactionCtrl, onVisibility
32
37
  (0, react_1.useEffect)(() => {
33
38
  onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
34
39
  }, [isInteractive, onVisibilityChange]);
40
+ (0, react_1.useEffect)(() => {
41
+ // because on first render controllers not yet initialized
42
+ setTimeout(() => {
43
+ for (const id of itemIds) {
44
+ const hasItem = itemGeometryService.hasItem(id);
45
+ if (hasItem) {
46
+ const cntrl = itemGeometryService.getControllerById(id);
47
+ cntrl.setParentId(item.id);
48
+ }
49
+ }
50
+ }, 0);
51
+ }, [itemIds, item.id]);
35
52
  return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_c = item.link) === null || _c === void 0 ? void 0 : _c.url, target: (_d = item.link) === null || _d === void 0 ? void 0 : _d.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `compound-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), { transition: (_e = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _e !== void 0 ? _e : 'none' }), children: items && items.map(item => ((0, jsx_runtime_1.jsx)(CompoundChild_1.CompoundChild, { item: item, sectionId: sectionId, isParentVisible: isInteractive }, item.id))) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
36
53
  .compound-${item.id} {
37
54
  overflow: ${item.commonParams.overflow};
@@ -11,6 +11,7 @@ const useCntrlContext_1 = require("../../../provider/useCntrlContext");
11
11
  const style_1 = __importDefault(require("styled-jsx/style"));
12
12
  const useRegisterResize_1 = require("../../../common/useRegisterResize");
13
13
  const useItemAngle_1 = require("../useItemAngle");
14
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
14
15
  const CustomItem = ({ item, onResize, sectionId, interactionCtrl }) => {
15
16
  var _a, _b, _c;
16
17
  const sdk = (0, useCntrlContext_1.useCntrlContext)();
@@ -20,6 +21,7 @@ const CustomItem = ({ item, onResize, sectionId, interactionCtrl }) => {
20
21
  const layoutValues = [item.area];
21
22
  const [ref, setRef] = (0, react_1.useState)(null);
22
23
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
24
+ (0, useItemGeometry_1.useItemGeometry)(item.id, ref);
23
25
  const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle']);
24
26
  const angle = (_b = (_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _a === void 0 ? void 0 : _a.angle) !== null && _b !== void 0 ? _b : itemAngle;
25
27
  if (!component)
@@ -25,6 +25,7 @@ const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromIte
25
25
  const useEmbedVideoItem_1 = require("./useEmbedVideoItem");
26
26
  const LinkWrapper_1 = require("../LinkWrapper");
27
27
  const useLayoutContext_1 = require("../../useLayoutContext");
28
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
28
29
  const VimeoEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
29
30
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
30
31
  const id = (0, react_1.useId)();
@@ -47,6 +48,7 @@ const VimeoEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibili
47
48
  const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_c = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _c === void 0 ? void 0 : _c.opacity, itemOpacity);
48
49
  const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_d = frameStateParams === null || frameStateParams === void 0 ? void 0 : frameStateParams.styles) === null || _d === void 0 ? void 0 : _d.radius, itemRadius);
49
50
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
51
+ (0, useItemGeometry_1.useItemGeometry)(item.id, ref);
50
52
  const validUrl = (0, react_1.useMemo)(() => {
51
53
  if (!layoutParams)
52
54
  return url;
@@ -17,6 +17,7 @@ const useYouTubeIframeApi_1 = require("../../../utils/Youtube/useYouTubeIframeAp
17
17
  const useRegisterResize_1 = require("../../../common/useRegisterResize");
18
18
  const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromItemStateAndParams");
19
19
  const useLayoutContext_1 = require("../../useLayoutContext");
20
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
20
21
  const YoutubeEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
21
22
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
22
23
  const id = (0, react_1.useId)();
@@ -43,6 +44,7 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibi
43
44
  onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
44
45
  }, [isInteractive, onVisibilityChange]);
45
46
  (0, useRegisterResize_1.useRegisterResize)(div, onResize);
47
+ (0, useItemGeometry_1.useItemGeometry)(item.id, div);
46
48
  (0, react_1.useEffect)(() => {
47
49
  const newUrl = new URL(url);
48
50
  const videoId = (0, getValidYoutubeUrl_1.getYoutubeId)(newUrl);
@@ -19,6 +19,7 @@ const useLayoutContext_1 = require("../../useLayoutContext");
19
19
  const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromItemStateAndParams");
20
20
  const useItemFXData_1 = require("../../../common/useItemFXData");
21
21
  const getFill_1 = require("../../../utils/getFill");
22
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
22
23
  const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
23
24
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
24
25
  const id = (0, react_1.useId)();
@@ -28,6 +29,7 @@ const ImageItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
28
29
  const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
29
30
  const [wrapperRef, setWrapperRef] = (0, react_1.useState)(null);
30
31
  (0, useRegisterResize_1.useRegisterResize)(wrapperRef, onResize);
32
+ (0, useItemGeometry_1.useItemGeometry)(item.id, wrapperRef);
31
33
  const { url, hasGLEffect } = item.commonParams;
32
34
  const fxCanvas = (0, react_1.useRef)(null);
33
35
  const isInitialRef = (0, react_1.useRef)(true);
@@ -20,6 +20,7 @@ const useVideoFx_1 = require("../../../utils/effects/useVideoFx");
20
20
  const useElementRect_1 = require("../../../utils/useElementRect");
21
21
  const useItemFXData_1 = require("../../../common/useItemFXData");
22
22
  const getFill_1 = require("../../../utils/getFill");
23
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
23
24
  const VideoItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
24
25
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
25
26
  const id = (0, react_1.useId)();
@@ -68,6 +69,7 @@ const VideoItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
68
69
  controls: controlsValues
69
70
  }, width, height);
70
71
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
72
+ (0, useItemGeometry_1.useItemGeometry)(item.id, ref);
71
73
  const inlineStyles = Object.assign(Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? {
72
74
  borderWidth: `${strokeWidth * 100}vw`,
73
75
  borderColor: stroke,
@@ -16,16 +16,21 @@ const useItemAngle_1 = require("../useItemAngle");
16
16
  const useGroupItem_1 = require("./useGroupItem");
17
17
  const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromItemStateAndParams");
18
18
  const CompoundChild_1 = require("../CompoundItem/CompoundChild");
19
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
20
+ const ItemGeometryContext_1 = require("../../../ItemGeometry/ItemGeometryContext");
19
21
  const GroupItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange, isInCompound }) => {
20
22
  var _a, _b, _c, _d, _e, _f;
21
23
  const id = (0, react_1.useId)();
22
24
  const { items } = item;
25
+ const itemIds = items ? items.map(item => item.id) : [];
23
26
  const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
24
27
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
25
28
  const { opacity: itemOpacity, blur: itemBlur } = (0, useGroupItem_1.useGroupItem)(item, sectionId);
26
29
  const layoutValues = [item.area, item.layoutParams];
27
30
  const [ref, setRef] = (0, react_1.useState)(null);
28
31
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
32
+ (0, useItemGeometry_1.useItemGeometry)(item.id, ref);
33
+ const itemGeometryService = (0, react_1.useContext)(ItemGeometryContext_1.ItemGeometryContext);
29
34
  const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['opacity', 'angle', 'blur']);
30
35
  const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _a === void 0 ? void 0 : _a.angle, itemAngle);
31
36
  const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_b = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) === null || _b === void 0 ? void 0 : _b.opacity, itemOpacity);
@@ -34,6 +39,18 @@ const GroupItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
34
39
  (0, react_1.useEffect)(() => {
35
40
  onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
36
41
  }, [isInteractive, onVisibilityChange]);
42
+ (0, react_1.useEffect)(() => {
43
+ // because on first render controllers not yet initialized
44
+ setTimeout(() => {
45
+ for (const id of itemIds) {
46
+ const hasItem = itemGeometryService.hasItem(id);
47
+ if (hasItem) {
48
+ const cntrl = itemGeometryService.getControllerById(id);
49
+ cntrl.setParentId(item.id);
50
+ }
51
+ }
52
+ }, 0);
53
+ }, [itemIds, item.id]);
37
54
  return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_d = item.link) === null || _d === void 0 ? void 0 : _d.url, target: (_e = item.link) === null || _e === void 0 ? void 0 : _e.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `group-${item.id}`, ref: setRef, 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)` } : {})), { transition: (_f = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _f !== void 0 ? _f : 'none', willChange: blur !== 0 && blur !== undefined ? 'transform' : 'unset' }), children: items && items.map(item => isInCompound ? ((0, jsx_runtime_1.jsx)(CompoundChild_1.CompoundChild, { item: item, sectionId: sectionId, isParentVisible: isInteractive }, item.id)) : ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: sectionId, isParentVisible: isInteractive, isInGroup: true }, item.id))) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
38
55
  .group-${item.id} {
39
56
  position: absolute;
@@ -28,6 +28,7 @@ const useSizing_1 = require("./useSizing");
28
28
  const useItemPointerEvents_1 = require("./useItemPointerEvents");
29
29
  const useItemArea_1 = require("./useItemArea");
30
30
  const useDraggable_1 = require("./useDraggable");
31
+ const ItemGeometryContext_1 = require("../../ItemGeometry/ItemGeometryContext");
31
32
  const stickyFix = `
32
33
  -webkit-transform: translate3d(0, 0, 0);
33
34
  transform: translate3d(0, 0, 0);
@@ -54,6 +55,13 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
54
55
  const [isDraggingActive, setIsDraggingActive] = (0, react_1.useState)(false);
55
56
  const wrapperStateProps = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['top', 'left']);
56
57
  const innerStateProps = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['width', 'height', 'scale']);
58
+ const geometryService = (0, react_1.useContext)(ItemGeometryContext_1.ItemGeometryContext);
59
+ const triggerZone = geometryService.getItemBoundary(item.id);
60
+ const hasItem = geometryService.hasItem(item.id);
61
+ const geometryController = (0, react_1.useMemo)(() => hasItem ? geometryService.getControllerById(item.id) : undefined, [hasItem]);
62
+ if (geometryController) {
63
+ geometryController.setScale(itemScale);
64
+ }
57
65
  const { width, height, top, left } = (0, useItemArea_1.useItemArea)(item, sectionId, {
58
66
  top: (_b = wrapperStateProps === null || wrapperStateProps === void 0 ? void 0 : wrapperStateProps.styles) === null || _b === void 0 ? void 0 : _b.top,
59
67
  left: (_c = wrapperStateProps === null || wrapperStateProps === void 0 ? void 0 : wrapperStateProps.styles) === null || _c === void 0 ? void 0 : _c.left,
@@ -17,6 +17,7 @@ const useRegisterResize_1 = require("../../../common/useRegisterResize");
17
17
  const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromItemStateAndParams");
18
18
  const getFill_1 = require("../../../utils/getFill");
19
19
  const areFillsVisible_1 = require("../../../utils/areFillsVisible/areFillsVisible");
20
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
20
21
  const RectangleItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
21
22
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
22
23
  const id = (0, react_1.useId)();
@@ -31,6 +32,7 @@ const RectangleItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilit
31
32
  const layoutValues = [item.area, item.layoutParams];
32
33
  const [ref, setRef] = (0, react_1.useState)(null);
33
34
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
35
+ (0, useItemGeometry_1.useItemGeometry)(item.id, ref);
34
36
  const backdropBlur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.backdropBlur, itemBackdropBlur);
35
37
  const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.radius, itemRadius);
36
38
  const strokeWidth = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)(styles === null || styles === void 0 ? void 0 : styles.strokeWidth, itemStrokeWidth);
@@ -18,17 +18,21 @@ const useExemplary_1 = require("../../../common/useExemplary");
18
18
  const useItemAngle_1 = require("../useItemAngle");
19
19
  const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromItemStateAndParams");
20
20
  const useCurrentLayout_1 = require("../../../common/useCurrentLayout");
21
+ const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
22
+ const RichTextGeometryController_1 = require("../../../ItemGeometry/RichTextGeometryController");
21
23
  const RichTextItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
22
24
  var _a, _b, _c, _d;
23
25
  const id = (0, react_1.useId)();
24
26
  const [ref, setRef] = (0, react_1.useState)(null);
25
27
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
26
28
  const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
27
- const { blur: itemBlur, wordSpacing: itemWordSpacing, letterSpacing: itemLetterSpacing, color: itemColor, fontSize, lineHeight } = (0, useRichTextItemValues_1.useRichTextItemValues)(item, sectionId);
29
+ const { blur: itemBlur, wordSpacing: itemWordSpacing, letterSpacing: itemLetterSpacing, color: itemColor, fontSize, lineHeight, xSizing } = (0, useRichTextItemValues_1.useRichTextItemValues)(item, sectionId);
28
30
  const layoutValues = [item.area, item.layoutParams];
29
31
  const exemplary = (0, useExemplary_1.useExemplary)();
30
32
  const { layoutId } = (0, useCurrentLayout_1.useCurrentLayout)();
31
33
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
34
+ const geometry = (0, useItemGeometry_1.useItemGeometry)(item.id, ref, RichTextGeometryController_1.RichTextGeometryController, { xSizing });
35
+ geometry === null || geometry === void 0 ? void 0 : geometry.setAngle(itemAngle);
32
36
  const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'letterSpacing', 'wordSpacing', 'color']);
33
37
  const stateStyles = (_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) !== null && _a !== void 0 ? _a : {};
34
38
  const transition = (_b = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _b !== void 0 ? _b : 'none';
@@ -33,6 +33,7 @@ const useRichTextItemValues = (item, sectionId) => {
33
33
  }, (animator, scroll, value) => value ? animator.getTextColor({ color: value }, scroll).color : undefined, sectionId, [layoutId]);
34
34
  const fontSize = layoutId ? item.layoutParams[layoutId].fontSize : undefined;
35
35
  const lineHeight = layoutId ? item.layoutParams[layoutId].lineHeight : undefined;
36
- return { blur, letterSpacing, wordSpacing, color, fontSize, lineHeight };
36
+ const xSizing = layoutId ? item.layoutParams[layoutId].sizing : undefined;
37
+ return { blur, letterSpacing, wordSpacing, color, fontSize, lineHeight, xSizing };
37
38
  };
38
39
  exports.useRichTextItemValues = useRichTextItemValues;