@gxpl/sdk 0.0.13 → 0.0.14

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/sdk/Client/Client.d.ts +3 -7
  2. package/lib/sdk/Client/Client.js +9 -38
  3. package/lib/sdk/schemas/project/Project.schema.d.ts +28 -57
  4. package/lib/sdk/schemas/project/Project.schema.js +7 -10
  5. package/lib/sdk/transitions/transitionMachine.d.ts +616 -0
  6. package/lib/sdk/transitions/transitionMachine.js +258 -0
  7. package/lib/sdk/transitions/utils/findRelation.d.ts +2 -0
  8. package/lib/sdk/transitions/utils/findRelation.js +10 -0
  9. package/lib/sdk/transitions/utils/getAvailableTransitions.d.ts +7 -0
  10. package/lib/sdk/transitions/utils/getAvailableTransitions.js +12 -0
  11. package/lib/sdk/transitions/utils/getAxis.d.ts +2 -0
  12. package/lib/sdk/transitions/utils/getAxis.js +6 -0
  13. package/lib/sdk/transitions/utils/getDeltaAndProgress.d.ts +11 -0
  14. package/lib/sdk/transitions/utils/getDeltaAndProgress.js +13 -0
  15. package/lib/sdk/transitions/utils/getScenesOnEnd.d.ts +21 -0
  16. package/lib/sdk/transitions/utils/getScenesOnEnd.js +30 -0
  17. package/lib/sdk/transitions/utils/getScenesOnInit.d.ts +6 -0
  18. package/lib/sdk/transitions/utils/getScenesOnInit.js +20 -0
  19. package/lib/sdk/transitions/utils/getScenesOnInstantTransition.d.ts +2 -0
  20. package/lib/sdk/transitions/utils/getScenesOnInstantTransition.js +38 -0
  21. package/lib/sdk/transitions/utils/getScenesOnProgressUpdate.d.ts +26 -0
  22. package/lib/sdk/transitions/utils/getScenesOnProgressUpdate.js +15 -0
  23. package/lib/sdk/transitions/utils/getScenesOnStart.d.ts +21 -0
  24. package/lib/sdk/transitions/utils/getScenesOnStart.js +52 -0
  25. package/lib/sdk/transitions/utils/isActiveSwipeTransition.d.ts +2 -0
  26. package/lib/sdk/transitions/utils/isActiveSwipeTransition.js +12 -0
  27. package/lib/sdk/transitions/utils/isOverThreshold.d.ts +1 -0
  28. package/lib/sdk/transitions/utils/isOverThreshold.js +6 -0
  29. package/lib/sdk/transitions/utils/isTransitionSuccess.d.ts +2 -0
  30. package/lib/sdk/transitions/utils/isTransitionSuccess.js +15 -0
  31. package/lib/sdk/transitions/utils/normalizeOpacity.d.ts +1 -0
  32. package/lib/sdk/transitions/utils/normalizeOpacity.js +8 -0
  33. package/lib/sdk/transitions/utils/types.d.ts +49 -0
  34. package/lib/sdk/transitions/utils/types.js +2 -0
  35. package/lib/sdk/types/project/Page.d.ts +0 -7
  36. package/lib/sdk/types/project/Project.d.ts +2 -0
  37. package/lib/sdk/types/project/Relation.d.ts +8 -0
  38. package/lib/sdk/types/project/Relation.js +2 -0
  39. package/lib/sdk-nextjs/components/Article.d.ts +9 -2
  40. package/lib/sdk-nextjs/components/Article.js +8 -5
  41. package/lib/sdk-nextjs/components/ArticleWrapper.d.ts +12 -1
  42. package/lib/sdk-nextjs/components/ArticleWrapper.js +155 -2
  43. package/lib/sdk-nextjs/components/Head.d.ts +0 -2
  44. package/lib/sdk-nextjs/components/Head.js +2 -1
  45. package/lib/sdk-nextjs/components/Page.d.ts +4 -7
  46. package/lib/sdk-nextjs/components/Page.js +13 -7
  47. package/lib/sdk-nextjs/components/Scenes/Scenes.d.ts +11 -0
  48. package/lib/sdk-nextjs/components/Scenes/Scenes.js +16 -0
  49. package/lib/sdk-nextjs/components/items/RectangleItem/RectangleItem.js +3 -3
  50. package/lib/sdk-nextjs/provider/CntrlSdkContext.d.ts +2 -2
  51. package/lib/sdk-nextjs/provider/CntrlSdkContext.js +4 -2
  52. package/lib/sdk-nextjs/provider/TransitionMachineContext.d.ts +2186 -0
  53. package/lib/sdk-nextjs/provider/TransitionMachineContext.js +6 -0
  54. package/package.json +3 -1
@@ -0,0 +1,49 @@
1
+ export type Relation = {
2
+ type: 'slide' | 'fade';
3
+ from: string;
4
+ to: string;
5
+ direction: Direction;
6
+ };
7
+ export type Direction = 'north' | 'east' | 'south' | 'west';
8
+ export type Transition = PreparingTransition | ActiveTransition | InstantTransition | SettlingTransition;
9
+ export type PreparingTransition = {
10
+ stage: 'preparing';
11
+ startX: number;
12
+ startY: number;
13
+ };
14
+ export type ActiveTransition = {
15
+ stage: 'active';
16
+ direction: Direction;
17
+ type: 'slide' | 'fade';
18
+ from: string;
19
+ to: string;
20
+ startX: number;
21
+ startY: number;
22
+ currentX: number;
23
+ currentY: number;
24
+ };
25
+ export type SettlingTransition = {
26
+ stage: 'settling';
27
+ type: 'slide' | 'fade';
28
+ success: boolean;
29
+ from: string;
30
+ to: string;
31
+ };
32
+ export type InstantTransition = {
33
+ stage: 'active';
34
+ type: 'slide' | 'fade';
35
+ from: string;
36
+ to: string;
37
+ direction?: Direction;
38
+ };
39
+ export type TransitionScene = {
40
+ id: string;
41
+ styles: TransitionSceneStyle;
42
+ };
43
+ export type TransitionSceneStyle = {
44
+ startX: number;
45
+ startY: number;
46
+ x: number;
47
+ y: number;
48
+ opacity: number;
49
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +1,4 @@
1
- import { GenericMeta } from './Meta';
2
- export interface PageMeta extends GenericMeta {
3
- enabled?: boolean;
4
- }
5
1
  export interface Page {
6
2
  id: string;
7
- title: string;
8
3
  articleId: string;
9
- slug: string;
10
- meta?: PageMeta;
11
4
  }
@@ -1,3 +1,4 @@
1
+ import { Relation } from './Relation';
1
2
  import { Fonts } from './Fonts';
2
3
  import { Meta } from './Meta';
3
4
  import { Page } from './Page';
@@ -13,4 +14,5 @@ export interface Project {
13
14
  exemplary: number;
14
15
  pages: Page[];
15
16
  fonts: Fonts;
17
+ relations: Relation[];
16
18
  }
@@ -0,0 +1,8 @@
1
+ export interface Relation {
2
+ from: ArticleId;
3
+ to: ArticleId;
4
+ type: 'slide' | 'fade';
5
+ direction: 'north' | 'east' | 'south' | 'west';
6
+ }
7
+ type ArticleId = string;
8
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +1,16 @@
1
1
  import { FC } from 'react';
2
2
  import { Article as TArticle } from '../../sdk/types/article/Article';
3
+ import { KeyframeAny } from '../../sdk/types/keyframe/Keyframe';
3
4
  interface Props {
4
5
  article: TArticle;
5
- sectionData: Record<SectionName, any>;
6
+ keyframes: KeyframeAny[];
7
+ styles: {
8
+ x: number;
9
+ y: number;
10
+ opacity: number;
11
+ startX: number;
12
+ startY: number;
13
+ } | undefined;
6
14
  }
7
15
  export declare const Article: FC<Props>;
8
- type SectionName = string;
9
16
  export {};
@@ -15,11 +15,14 @@ const ArticleWrapper_1 = require("./ArticleWrapper");
15
15
  const InteractionsContext_1 = require("../provider/InteractionsContext");
16
16
  const WebGLContextManagerContext_1 = require("../provider/WebGLContextManagerContext");
17
17
  const effects_1 = require("@cntrl-site/effects");
18
- const Article = ({ article, sectionData }) => {
18
+ const KeyframesContext_1 = require("../provider/KeyframesContext");
19
+ const Keyframes_1 = require("../provider/Keyframes");
20
+ const Article = ({ article, styles, keyframes }) => {
19
21
  const articleRef = (0, react_1.useRef)(null);
20
22
  const articleRectObserver = (0, useArticleRectObserver_1.useArticleRectObserver)(articleRef.current);
21
23
  const id = (0, react_1.useId)();
22
24
  const [articleHeight, setArticleHeight] = (0, react_1.useState)(1);
25
+ const keyframesRepo = (0, react_1.useMemo)(() => new Keyframes_1.Keyframes(keyframes), [keyframes]);
23
26
  (0, react_1.useEffect)(() => {
24
27
  if (!articleRectObserver)
25
28
  return;
@@ -28,10 +31,10 @@ const Article = ({ article, sectionData }) => {
28
31
  });
29
32
  }, [articleRectObserver]);
30
33
  const webglContextManager = (0, react_1.useMemo)(() => new effects_1.WebGLContextManager(), []);
31
- return ((0, jsx_runtime_1.jsx)(ArticleRectContext_1.ArticleRectContext.Provider, { value: articleRectObserver, children: (0, jsx_runtime_1.jsxs)(InteractionsContext_1.InteractionsProvider, { article: article, children: [(0, jsx_runtime_1.jsx)(ArticleWrapper_1.ArticleWrapper, { children: (0, jsx_runtime_1.jsx)("div", { className: "article", ref: articleRef, children: (0, jsx_runtime_1.jsx)(WebGLContextManagerContext_1.WebglContextManagerContext.Provider, { value: webglContextManager, children: article.sections.map((section, i) => {
32
- const data = section.name ? sectionData[section.name] : {};
33
- return ((0, jsx_runtime_1.jsx)(Section_1.Section, { section: section, data: data, children: article.sections[i].items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: section.id, articleHeight: articleHeight }, item.id))) }, section.id));
34
- }) }) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
34
+ return ((0, jsx_runtime_1.jsx)(ArticleRectContext_1.ArticleRectContext.Provider, { value: articleRectObserver, children: (0, jsx_runtime_1.jsxs)(InteractionsContext_1.InteractionsProvider, { article: article, children: [(0, jsx_runtime_1.jsx)(KeyframesContext_1.KeyframesContext.Provider, { value: keyframesRepo, children: (0, jsx_runtime_1.jsx)(ArticleWrapper_1.ArticleWrapper, { id: article.id, styles: styles, children: (0, jsx_runtime_1.jsx)("div", { className: "article", ref: articleRef, children: (0, jsx_runtime_1.jsx)(WebGLContextManagerContext_1.WebglContextManagerContext.Provider, { value: webglContextManager, children: article.sections.map((section, i) => {
35
+ const data = {};
36
+ return ((0, jsx_runtime_1.jsx)(Section_1.Section, { section: section, data: data, children: article.sections[i].items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: section.id, articleHeight: articleHeight }, item.id))) }, section.id));
37
+ }) }) }) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
35
38
  .article {
36
39
  position: relative;
37
40
  overflow: clip;
@@ -1,2 +1,13 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
- export declare const ArticleWrapper: FC<PropsWithChildren<{}>>;
2
+ interface Props {
3
+ id: string;
4
+ styles: {
5
+ x: number;
6
+ y: number;
7
+ opacity: number;
8
+ startX: number;
9
+ startY: number;
10
+ } | undefined;
11
+ }
12
+ export declare const ArticleWrapper: FC<PropsWithChildren<Props>>;
13
+ export {};
@@ -2,10 +2,163 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ArticleWrapper = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
5
6
  const useLayoutDeviation_1 = require("../common/useLayoutDeviation");
6
- const ArticleWrapper = ({ children }) => {
7
+ const TransitionMachineContext_1 = require("../provider/TransitionMachineContext");
8
+ const ArticleWrapper = ({ children, id, styles: sceneStyles }) => {
9
+ var _a;
7
10
  const { layoutDeviation } = (0, useLayoutDeviation_1.useLayoutDeviation)();
8
11
  const layoutDeviationStyle = { '--layout-deviation': layoutDeviation };
9
- return ((0, jsx_runtime_1.jsx)("div", { className: "article-wrapper", style: Object.assign({}, layoutDeviationStyle), children: children }));
12
+ const sceneRef = (0, react_1.useRef)(null);
13
+ const actorRef = TransitionMachineContext_1.TransitionMachineContext.useActorRef();
14
+ const { isControlledTransitioning, isSettling, isInstantTransitioning } = TransitionMachineContext_1.TransitionMachineContext.useSelector((state) => ({
15
+ isControlledTransitioning: state.matches('transitioning'),
16
+ isSettling: state.matches('settling'),
17
+ isInstantTransitioning: state.matches('instant_transitioning'),
18
+ }));
19
+ const type = TransitionMachineContext_1.TransitionMachineContext.useSelector((state) => {
20
+ const { transition } = state.context;
21
+ if (!transition || !('type' in transition))
22
+ return undefined;
23
+ return transition.type;
24
+ });
25
+ const isTransitioningRef = (0, react_1.useRef)(false);
26
+ const isTransitioning = isControlledTransitioning || isInstantTransitioning;
27
+ const handleTouchStart = (0, react_1.useCallback)((e) => {
28
+ const { context } = actorRef.getSnapshot();
29
+ const { transitionReady } = context;
30
+ if (isTransitionDisabled(transitionReady))
31
+ return;
32
+ const touch = e.touches[0];
33
+ actorRef.send({
34
+ type: 'SWIPE_PREPARE',
35
+ touchData: {
36
+ startX: touch.clientX,
37
+ startY: touch.clientY,
38
+ }
39
+ });
40
+ }, [actorRef]);
41
+ const handleTouchMove = (0, react_1.useCallback)((e) => {
42
+ const touch = e.touches[0];
43
+ const { context } = actorRef.getSnapshot();
44
+ const { transition, transitionReady } = context;
45
+ const el = sceneRef.current;
46
+ if (!el || !transition || !('startX' in transition) || !('startY' in transition))
47
+ return;
48
+ const deltaX = touch.clientX - transition.startX;
49
+ const deltaY = touch.clientY - transition.startY;
50
+ const direction = getDirectionFromDelta(deltaX, deltaY);
51
+ const isTransitionAllowed = canTransition(direction, el);
52
+ if ((!transitionReady[direction] && transition.stage === 'preparing') || !isTransitionAllowed) {
53
+ actorRef.send({ type: 'SWIPE_CANCEL' });
54
+ return;
55
+ }
56
+ if (transition.stage === 'preparing') {
57
+ actorRef.send({
58
+ type: 'SWIPE_START',
59
+ direction,
60
+ touchData: {
61
+ x: touch.clientX,
62
+ y: touch.clientY,
63
+ }
64
+ });
65
+ }
66
+ else if (transition.stage === 'active') {
67
+ actorRef.send({
68
+ type: 'SWIPE_PROGRESS_UPDATE',
69
+ touchData: {
70
+ x: touch.clientX,
71
+ y: touch.clientY,
72
+ }
73
+ });
74
+ }
75
+ }, [actorRef]);
76
+ const handleTouchEnd = (0, react_1.useCallback)(() => {
77
+ const { context } = actorRef.getSnapshot();
78
+ const { transition } = context;
79
+ if (!transition || transition.stage !== 'active') {
80
+ actorRef.send({ type: 'SWIPE_CANCEL' });
81
+ return;
82
+ }
83
+ actorRef.send({
84
+ type: 'SWIPE_END',
85
+ });
86
+ }, [actorRef]);
87
+ (0, react_1.useEffect)(() => {
88
+ const el = sceneRef.current;
89
+ if (!el)
90
+ return;
91
+ el.addEventListener('touchstart', handleTouchStart, { passive: true });
92
+ el.addEventListener('touchmove', handleTouchMove, { passive: true });
93
+ el.addEventListener('touchend', handleTouchEnd);
94
+ return () => {
95
+ el.removeEventListener('touchstart', handleTouchStart);
96
+ el.removeEventListener('touchmove', handleTouchMove);
97
+ el.removeEventListener('touchend', handleTouchEnd);
98
+ };
99
+ }, [handleTouchStart, handleTouchMove, handleTouchEnd]);
100
+ (0, react_1.useEffect)(() => {
101
+ const el = sceneRef.current;
102
+ if (!isSettling || !el)
103
+ return;
104
+ const handleTransitionEnd = (e) => {
105
+ const { context } = actorRef.getSnapshot();
106
+ const { transition } = context;
107
+ if (!transition || transition.stage !== 'settling') {
108
+ throw new Error('Transition not found');
109
+ }
110
+ const { type } = transition;
111
+ const propType = type === 'slide' ? 'transform' : 'opacity';
112
+ if (e.propertyName !== propType)
113
+ return;
114
+ actorRef.send({
115
+ type: 'SETTLE_END',
116
+ });
117
+ };
118
+ el.addEventListener('transitionend', handleTransitionEnd);
119
+ return () => {
120
+ el.removeEventListener('transitionend', handleTransitionEnd);
121
+ };
122
+ }, [actorRef, isSettling]);
123
+ (0, react_1.useEffect)(() => {
124
+ const scene = sceneRef.current;
125
+ if (!isTransitioning || isTransitioningRef.current || !scene)
126
+ return;
127
+ isTransitioningRef.current = true;
128
+ const { context } = actorRef.getSnapshot();
129
+ const { transition } = context;
130
+ if (!transition || transition.stage !== 'active')
131
+ return;
132
+ const { to, direction } = transition;
133
+ if (direction === 'north' && to === id) {
134
+ scene.scrollTo({ top: scene.scrollHeight });
135
+ }
136
+ }, [isTransitioning, actorRef, id]);
137
+ const isFixed = isControlledTransitioning || isSettling || isInstantTransitioning;
138
+ const transitionStyle = type === 'slide' ? 'transform' : 'opacity';
139
+ return ((0, jsx_runtime_1.jsx)("div", { ref: sceneRef, className: "article-wrapper", style: Object.assign(Object.assign({}, layoutDeviationStyle), { width: '100vw', height: '100%', position: isFixed ? 'fixed' : 'absolute', transform: `translate3d(${sceneStyles === null || sceneStyles === void 0 ? void 0 : sceneStyles.x}px, ${sceneStyles === null || sceneStyles === void 0 ? void 0 : sceneStyles.y}px, 0)`, transition: isSettling || isInstantTransitioning ? `${transitionStyle} 0.25s ease-out` : 'none', overflowY: isFixed ? 'hidden' : 'auto', opacity: (_a = sceneStyles === null || sceneStyles === void 0 ? void 0 : sceneStyles.opacity) !== null && _a !== void 0 ? _a : 1 }), children: children }));
10
140
  };
11
141
  exports.ArticleWrapper = ArticleWrapper;
142
+ function isTransitionDisabled(transitionReady) {
143
+ return !transitionReady.north && !transitionReady.east && !transitionReady.south && !transitionReady.west;
144
+ }
145
+ function getDirectionFromDelta(deltaX, deltaY) {
146
+ if (Math.abs(deltaX) > Math.abs(deltaY)) {
147
+ return deltaX > 0 ? 'west' : 'east';
148
+ }
149
+ return deltaY > 0 ? 'north' : 'south';
150
+ }
151
+ function canTransition(direction, el) {
152
+ switch (direction) {
153
+ case 'north':
154
+ return el.scrollTop === 0;
155
+ case 'south': {
156
+ const isAllowed = el.scrollTop + el.clientHeight >= el.scrollHeight;
157
+ return isAllowed;
158
+ }
159
+ case 'west':
160
+ return el.scrollLeft === 0;
161
+ case 'east':
162
+ return el.scrollLeft + el.clientWidth === el.scrollWidth;
163
+ }
164
+ }
@@ -1,9 +1,7 @@
1
1
  import { FC } from 'react';
2
- import { Meta } from '../../sdk/types/project/Meta';
3
2
  import { Project } from '../../sdk/types/project/Project';
4
3
  interface Props {
5
4
  project: Project;
6
- meta: Meta;
7
5
  }
8
6
  export declare const CNTRLHead: FC<Props>;
9
7
  export {};
@@ -8,7 +8,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const html_react_parser_1 = __importDefault(require("html-react-parser"));
9
9
  const head_1 = __importDefault(require("next/head"));
10
10
  const FontFaceGenerator_1 = require("../../sdk/FontFaceGenerator/FontFaceGenerator");
11
- const CNTRLHead = ({ meta, project }) => {
11
+ const CNTRLHead = ({ project }) => {
12
12
  const googleFonts = (0, html_react_parser_1.default)(project.fonts.google);
13
13
  const adobeFonts = (0, html_react_parser_1.default)(project.fonts.adobe);
14
14
  const parsedFonts = Object.assign(Object.assign({}, (typeof googleFonts === 'object' ? googleFonts : {})), (typeof adobeFonts === 'object' ? adobeFonts : {}));
@@ -25,6 +25,7 @@ const CNTRLHead = ({ meta, project }) => {
25
25
  return;
26
26
  return ((0, jsx_runtime_1.jsx)("link", { rel: rel, href: href }, `link-${rel}-${href}`));
27
27
  });
28
+ const { meta } = project;
28
29
  return ((0, jsx_runtime_1.jsxs)(head_1.default, { children: [(0, jsx_runtime_1.jsx)("title", { children: meta.title }), (0, jsx_runtime_1.jsx)("meta", { name: "description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { name: "keywords", content: meta.keywords }), (0, jsx_runtime_1.jsx)("meta", { name: "og:title", content: meta.title }), (0, jsx_runtime_1.jsx)("meta", { name: "og:image", content: meta.opengraphThumbnail }), (0, jsx_runtime_1.jsx)("meta", { name: "og:description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:title", content: meta.title }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:image", content: meta.opengraphThumbnail }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { property: "twitter:card", content: "summary_large_image" }), (0, jsx_runtime_1.jsx)("meta", { name: "generator", content: "https://cntrl.site" }), (0, jsx_runtime_1.jsx)("link", { rel: "icon", href: meta.favicon }), customFonts.length > 0 && ((0, jsx_runtime_1.jsx)("style", { dangerouslySetInnerHTML: {
29
30
  __html: ffGenerator.generate()
30
31
  } })), links, htmlHead] }));
@@ -1,15 +1,12 @@
1
1
  import { FC } from 'react';
2
2
  import { Project } from '../../sdk/types/project/Project';
3
3
  import { Article as TArticle } from '../../sdk/types/article/Article';
4
- import { Meta } from '../../sdk/types/project/Meta';
5
4
  import { KeyframeAny } from '../../sdk/types/keyframe/Keyframe';
6
5
  export interface PageProps {
7
- article: TArticle;
8
6
  project: Project;
9
- meta: Meta;
10
- keyframes: KeyframeAny[];
11
- sectionData: Record<SectionName, any>;
7
+ articlesData: Record<string, {
8
+ article: TArticle;
9
+ keyframes: KeyframeAny[];
10
+ }>;
12
11
  }
13
12
  export declare const Page: FC<PageProps>;
14
- type SectionName = string;
15
- export {};
@@ -5,16 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Page = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
- const react_1 = require("react");
9
8
  const html_react_parser_1 = __importDefault(require("html-react-parser"));
10
- const Article_1 = require("./Article");
11
- const KeyframesContext_1 = require("../provider/KeyframesContext");
12
9
  const Head_1 = require("./Head");
13
- const Keyframes_1 = require("../provider/Keyframes");
14
- const Page = ({ article, project, meta, keyframes, sectionData }) => {
10
+ const TransitionMachineContext_1 = require("../provider/TransitionMachineContext");
11
+ const Scenes_1 = require("./Scenes/Scenes");
12
+ const Page = ({ project, articlesData }) => {
15
13
  const afterBodyOpen = (0, html_react_parser_1.default)(project.html.afterBodyOpen);
16
14
  const beforeBodyClose = (0, html_react_parser_1.default)(project.html.beforeBodyClose);
17
- 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] }));
15
+ const startScene = Object.keys(articlesData)[0];
16
+ const scenes = Object.values(articlesData).map(({ article }) => ({ id: article.id }));
17
+ const { relations } = project;
18
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Head_1.CNTRLHead, { project: project }), afterBodyOpen, (0, jsx_runtime_1.jsx)(TransitionMachineContext_1.TransitionMachineContext.Provider, { options: {
19
+ input: {
20
+ startScene,
21
+ relations,
22
+ scenes,
23
+ }
24
+ }, children: (0, jsx_runtime_1.jsx)(Scenes_1.Scenes, { articlesData: articlesData }) }), beforeBodyClose] }));
19
25
  };
20
26
  exports.Page = Page;
@@ -0,0 +1,11 @@
1
+ import { FC } from 'react';
2
+ import { Article as TArticle } from '../../../sdk/types/article/Article';
3
+ import { KeyframeAny } from '../../../sdk/types/keyframe/Keyframe';
4
+ interface Props {
5
+ articlesData: Record<string, {
6
+ article: TArticle;
7
+ keyframes: KeyframeAny[];
8
+ }>;
9
+ }
10
+ export declare const Scenes: FC<Props>;
11
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Scenes = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const TransitionMachineContext_1 = require("../../provider/TransitionMachineContext");
6
+ const Article_1 = require("../Article");
7
+ const Scenes = ({ articlesData }) => {
8
+ const scenes = TransitionMachineContext_1.TransitionMachineContext.useSelector(({ context }) => context.scenes);
9
+ return ((0, jsx_runtime_1.jsx)("div", { children: scenes.map((scene) => {
10
+ const { article, keyframes } = articlesData[scene.id];
11
+ if (!article || !keyframes)
12
+ return null;
13
+ return ((0, jsx_runtime_1.jsx)(Article_1.Article, { article: article, keyframes: keyframes, styles: scene.styles }, article.id));
14
+ }) }));
15
+ };
16
+ exports.Scenes = Scenes;
@@ -55,7 +55,7 @@ const RectangleItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilit
55
55
  const background = value
56
56
  ? (_b = (0, getFill_1.getFill)(value)) !== null && _b !== void 0 ? _b : 'transparent'
57
57
  : 'transparent';
58
- return ((0, jsx_runtime_1.jsx)(Fill, { fill: value, itemId: item.id, background: background, solidTransition: solidTransition, radius: radius, strokeWidth: strokeWidth }, `fill-${i}-${fill.id}`));
58
+ return ((0, jsx_runtime_1.jsx)(Fill, { fill: value, itemId: item.id, background: background, solidTransition: solidTransition, radius: radius, strokeWidth: strokeWidth, fillId: fill.id }, `fill-${i}-${fill.id}`));
59
59
  }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
60
60
  .rectangle-${item.id} {
61
61
  position: absolute;
@@ -82,7 +82,7 @@ const RectangleItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilit
82
82
  ` })] }) }));
83
83
  };
84
84
  exports.RectangleItem = RectangleItem;
85
- function Fill({ fill, itemId, background, solidTransition, radius, strokeWidth, key }) {
85
+ function Fill({ fillId, fill, itemId, background, solidTransition, radius, strokeWidth, }) {
86
86
  const isRotatedImage = fill.type === 'image' && fill.rotation && fill.rotation !== 0;
87
87
  return ((0, jsx_runtime_1.jsx)("div", { className: fill.type === 'image' ? `image-fill-${itemId}` : `fill-${itemId}`, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (fill.type === 'solid' ? { background, transition: solidTransition } : {})), (fill.type === 'image'
88
88
  ? {
@@ -92,6 +92,6 @@ function Fill({ fill, itemId, background, solidTransition, radius, strokeWidth,
92
92
  backgroundRepeat: fill.behavior === 'repeat' ? 'repeat' : 'no-repeat',
93
93
  opacity: fill.opacity
94
94
  }
95
- : { background })), { position: 'absolute', mixBlendMode: fill.blendMode, top: 0, left: 0, borderRadius: `calc(${radius * 100}vw - ${strokeWidth * 100}vw)`, width: '100%', height: '100%', pointerEvents: 'none' }), (isRotatedImage ? { overflow: 'hidden' } : {})) }, key));
95
+ : { background })), { position: 'absolute', mixBlendMode: fill.blendMode, top: 0, left: 0, borderRadius: `calc(${radius * 100}vw - ${strokeWidth * 100}vw)`, width: '100%', height: '100%', pointerEvents: 'none' }), (isRotatedImage ? { overflow: 'hidden' } : {})) }, fillId));
96
96
  }
97
97
  ;
@@ -6,7 +6,7 @@ import { CustomSectionRegistry } from './CustomSectionRegistry';
6
6
  import { Component as TComponent } from '@cntrl-site/components';
7
7
  interface SdkContextInitProps {
8
8
  project: Project;
9
- article: Article;
9
+ articles: Article[];
10
10
  }
11
11
  export declare class CntrlSdkContext {
12
12
  readonly customItems: CustomItemRegistry;
@@ -17,7 +17,7 @@ export declare class CntrlSdkContext {
17
17
  private components;
18
18
  constructor(customItems: CustomItemRegistry, customSections: CustomSectionRegistry);
19
19
  resolveSectionData(sections: Section[]): Promise<Record<string, any>>;
20
- init({ project, article }: SdkContextInitProps): void;
20
+ init({ project, articles }: SdkContextInitProps): void;
21
21
  private setExemplary;
22
22
  private setComponents;
23
23
  private setFonts;
@@ -34,11 +34,13 @@ class CntrlSdkContext {
34
34
  return Object.fromEntries(yield Promise.all(resolvers.map((_a) => __awaiter(this, [_a], void 0, function* ({ name, resolver }) { return [name, yield resolver()]; }))));
35
35
  });
36
36
  }
37
- init({ project, article }) {
37
+ init({ project, articles }) {
38
38
  this.setComponents(components_1.components);
39
39
  this.setExemplary(project.exemplary);
40
40
  this.setFonts(project.fonts);
41
- this.setSectionsHeight(article.sections);
41
+ for (const article of articles) {
42
+ this.setSectionsHeight(article.sections);
43
+ }
42
44
  }
43
45
  setExemplary(exemplary) {
44
46
  this._exemplary = exemplary;