@gxpl/sdk 0.0.17 → 0.0.19
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.
- package/lib/sdk/schemas/article/ItemBase.schema.d.ts +44 -4
- package/lib/sdk/schemas/article/ItemBase.schema.js +8 -1
- package/lib/sdk/schemas/article/RichTextItem.schema.d.ts +27 -2
- package/lib/sdk/schemas/project/Project.schema.d.ts +4 -4
- package/lib/sdk/types/article/Item.d.ts +0 -4
- package/lib/sdk-nextjs/common/useKeyframeValue.js +6 -4
- package/lib/sdk-nextjs/components/Article.js +2 -2
- package/lib/sdk-nextjs/components/{ArticleWrapper.d.ts → Scene.d.ts} +1 -1
- package/lib/sdk-nextjs/components/{ArticleWrapper.js → Scene.js} +7 -6
- package/lib/sdk-nextjs/components/Section/Section.js +18 -18
- package/lib/sdk-nextjs/utils/ArticleRectManager/ArticleRectObserver.d.ts +3 -0
- package/lib/sdk-nextjs/utils/ArticleRectManager/ArticleRectObserver.js +34 -5
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { AreaAnchor, DimensionMode } from '../../types/article/ItemArea';
|
|
3
|
-
export declare const Link: z.ZodObject<{
|
|
3
|
+
export declare const Link: z.ZodUnion<[z.ZodObject<{
|
|
4
4
|
url: z.ZodString;
|
|
5
5
|
target: z.ZodString;
|
|
6
6
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -9,7 +9,22 @@ export declare const Link: z.ZodObject<{
|
|
|
9
9
|
}, {
|
|
10
10
|
url: string;
|
|
11
11
|
target: string;
|
|
12
|
-
}
|
|
12
|
+
}>, z.ZodObject<{
|
|
13
|
+
value: z.ZodString;
|
|
14
|
+
animation: z.ZodEnum<["fade", "slide", "reveal"]>;
|
|
15
|
+
duration: z.ZodNumber;
|
|
16
|
+
direction: z.ZodEnum<["north", "west", "south", "east"]>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
value: string;
|
|
19
|
+
duration: number;
|
|
20
|
+
animation: "slide" | "fade" | "reveal";
|
|
21
|
+
direction: "north" | "east" | "south" | "west";
|
|
22
|
+
}, {
|
|
23
|
+
value: string;
|
|
24
|
+
duration: number;
|
|
25
|
+
animation: "slide" | "fade" | "reveal";
|
|
26
|
+
direction: "north" | "east" | "south" | "west";
|
|
27
|
+
}>]>;
|
|
13
28
|
export declare const CompoundSettingsSchema: z.ZodObject<{
|
|
14
29
|
positionAnchor: z.ZodNativeEnum<typeof AreaAnchor>;
|
|
15
30
|
widthMode: z.ZodNativeEnum<typeof DimensionMode>;
|
|
@@ -60,7 +75,7 @@ export declare const ItemBaseSchema: z.ZodObject<{
|
|
|
60
75
|
anchorSide?: import("../../types/article/ItemArea").AnchorSide | undefined;
|
|
61
76
|
}>;
|
|
62
77
|
hidden: z.ZodBoolean;
|
|
63
|
-
link: z.ZodOptional<z.ZodObject<{
|
|
78
|
+
link: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
64
79
|
url: z.ZodString;
|
|
65
80
|
target: z.ZodString;
|
|
66
81
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -69,7 +84,22 @@ export declare const ItemBaseSchema: z.ZodObject<{
|
|
|
69
84
|
}, {
|
|
70
85
|
url: string;
|
|
71
86
|
target: string;
|
|
72
|
-
}
|
|
87
|
+
}>, z.ZodObject<{
|
|
88
|
+
value: z.ZodString;
|
|
89
|
+
animation: z.ZodEnum<["fade", "slide", "reveal"]>;
|
|
90
|
+
duration: z.ZodNumber;
|
|
91
|
+
direction: z.ZodEnum<["north", "west", "south", "east"]>;
|
|
92
|
+
}, "strip", z.ZodTypeAny, {
|
|
93
|
+
value: string;
|
|
94
|
+
duration: number;
|
|
95
|
+
animation: "slide" | "fade" | "reveal";
|
|
96
|
+
direction: "north" | "east" | "south" | "west";
|
|
97
|
+
}, {
|
|
98
|
+
value: string;
|
|
99
|
+
duration: number;
|
|
100
|
+
animation: "slide" | "fade" | "reveal";
|
|
101
|
+
direction: "north" | "east" | "south" | "west";
|
|
102
|
+
}>]>>;
|
|
73
103
|
compoundSettings: z.ZodOptional<z.ZodObject<{
|
|
74
104
|
positionAnchor: z.ZodNativeEnum<typeof AreaAnchor>;
|
|
75
105
|
widthMode: z.ZodNativeEnum<typeof DimensionMode>;
|
|
@@ -101,6 +131,11 @@ export declare const ItemBaseSchema: z.ZodObject<{
|
|
|
101
131
|
link?: {
|
|
102
132
|
url: string;
|
|
103
133
|
target: string;
|
|
134
|
+
} | {
|
|
135
|
+
value: string;
|
|
136
|
+
duration: number;
|
|
137
|
+
animation: "slide" | "fade" | "reveal";
|
|
138
|
+
direction: "north" | "east" | "south" | "west";
|
|
104
139
|
} | undefined;
|
|
105
140
|
compoundSettings?: {
|
|
106
141
|
positionAnchor: AreaAnchor;
|
|
@@ -125,6 +160,11 @@ export declare const ItemBaseSchema: z.ZodObject<{
|
|
|
125
160
|
link?: {
|
|
126
161
|
url: string;
|
|
127
162
|
target: string;
|
|
163
|
+
} | {
|
|
164
|
+
value: string;
|
|
165
|
+
duration: number;
|
|
166
|
+
animation: "slide" | "fade" | "reveal";
|
|
167
|
+
direction: "north" | "east" | "south" | "west";
|
|
128
168
|
} | undefined;
|
|
129
169
|
compoundSettings?: {
|
|
130
170
|
positionAnchor: AreaAnchor;
|
|
@@ -4,10 +4,17 @@ exports.ItemBaseSchema = exports.CompoundSettingsSchema = exports.Link = void 0;
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const ItemArea_schema_1 = require("./ItemArea.schema");
|
|
6
6
|
const ItemArea_1 = require("../../types/article/ItemArea");
|
|
7
|
-
|
|
7
|
+
const UrlLinkSchema = zod_1.z.object({
|
|
8
8
|
url: zod_1.z.string().min(1),
|
|
9
9
|
target: zod_1.z.string().min(1)
|
|
10
10
|
});
|
|
11
|
+
const ClickLinkSchema = zod_1.z.object({
|
|
12
|
+
value: zod_1.z.string().min(1),
|
|
13
|
+
animation: zod_1.z.enum(['fade', 'slide', 'reveal']),
|
|
14
|
+
duration: zod_1.z.number(),
|
|
15
|
+
direction: zod_1.z.enum(['north', 'west', 'south', 'east'])
|
|
16
|
+
});
|
|
17
|
+
exports.Link = zod_1.z.union([UrlLinkSchema, ClickLinkSchema]);
|
|
11
18
|
exports.CompoundSettingsSchema = zod_1.z.object({
|
|
12
19
|
positionAnchor: zod_1.z.nativeEnum(ItemArea_1.AreaAnchor),
|
|
13
20
|
widthMode: zod_1.z.nativeEnum(ItemArea_1.DimensionMode),
|
|
@@ -71,7 +71,7 @@ export declare const RichTextItemSchema: z.ZodObject<{
|
|
|
71
71
|
anchorSide?: import("../../..").AnchorSide | undefined;
|
|
72
72
|
}>;
|
|
73
73
|
hidden: z.ZodBoolean;
|
|
74
|
-
link: z.ZodOptional<z.ZodObject<{
|
|
74
|
+
link: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
75
75
|
url: z.ZodString;
|
|
76
76
|
target: z.ZodString;
|
|
77
77
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -80,7 +80,22 @@ export declare const RichTextItemSchema: z.ZodObject<{
|
|
|
80
80
|
}, {
|
|
81
81
|
url: string;
|
|
82
82
|
target: string;
|
|
83
|
-
}
|
|
83
|
+
}>, z.ZodObject<{
|
|
84
|
+
value: z.ZodString;
|
|
85
|
+
animation: z.ZodEnum<["fade", "slide", "reveal"]>;
|
|
86
|
+
duration: z.ZodNumber;
|
|
87
|
+
direction: z.ZodEnum<["north", "west", "south", "east"]>;
|
|
88
|
+
}, "strip", z.ZodTypeAny, {
|
|
89
|
+
value: string;
|
|
90
|
+
duration: number;
|
|
91
|
+
animation: "slide" | "fade" | "reveal";
|
|
92
|
+
direction: "north" | "east" | "south" | "west";
|
|
93
|
+
}, {
|
|
94
|
+
value: string;
|
|
95
|
+
duration: number;
|
|
96
|
+
animation: "slide" | "fade" | "reveal";
|
|
97
|
+
direction: "north" | "east" | "south" | "west";
|
|
98
|
+
}>]>>;
|
|
84
99
|
compoundSettings: z.ZodOptional<z.ZodObject<{
|
|
85
100
|
positionAnchor: z.ZodNativeEnum<typeof import("../../..").AreaAnchor>;
|
|
86
101
|
widthMode: z.ZodNativeEnum<typeof import("../../..").DimensionMode>;
|
|
@@ -1168,6 +1183,11 @@ export declare const RichTextItemSchema: z.ZodObject<{
|
|
|
1168
1183
|
link?: {
|
|
1169
1184
|
url: string;
|
|
1170
1185
|
target: string;
|
|
1186
|
+
} | {
|
|
1187
|
+
value: string;
|
|
1188
|
+
duration: number;
|
|
1189
|
+
animation: "slide" | "fade" | "reveal";
|
|
1190
|
+
direction: "north" | "east" | "south" | "west";
|
|
1171
1191
|
} | undefined;
|
|
1172
1192
|
compoundSettings?: {
|
|
1173
1193
|
positionAnchor: import("../../..").AreaAnchor;
|
|
@@ -1355,6 +1375,11 @@ export declare const RichTextItemSchema: z.ZodObject<{
|
|
|
1355
1375
|
link?: {
|
|
1356
1376
|
url: string;
|
|
1357
1377
|
target: string;
|
|
1378
|
+
} | {
|
|
1379
|
+
value: string;
|
|
1380
|
+
duration: number;
|
|
1381
|
+
animation: "slide" | "fade" | "reveal";
|
|
1382
|
+
direction: "north" | "east" | "south" | "west";
|
|
1358
1383
|
} | undefined;
|
|
1359
1384
|
compoundSettings?: {
|
|
1360
1385
|
positionAnchor: import("../../..").AreaAnchor;
|
|
@@ -111,14 +111,14 @@ export declare const ProjectSchema: z.ZodObject<{
|
|
|
111
111
|
direction: z.ZodEnum<["north", "east", "south", "west"]>;
|
|
112
112
|
}, "strip", z.ZodTypeAny, {
|
|
113
113
|
type: "slide" | "fade";
|
|
114
|
+
direction: "north" | "east" | "south" | "west";
|
|
114
115
|
from: string;
|
|
115
116
|
to: string;
|
|
116
|
-
direction: "north" | "east" | "south" | "west";
|
|
117
117
|
}, {
|
|
118
118
|
type: "slide" | "fade";
|
|
119
|
+
direction: "north" | "east" | "south" | "west";
|
|
119
120
|
from: string;
|
|
120
121
|
to: string;
|
|
121
|
-
direction: "north" | "east" | "south" | "west";
|
|
122
122
|
}>, "many">;
|
|
123
123
|
}, "strip", z.ZodTypeAny, {
|
|
124
124
|
html: {
|
|
@@ -154,9 +154,9 @@ export declare const ProjectSchema: z.ZodObject<{
|
|
|
154
154
|
};
|
|
155
155
|
relations: {
|
|
156
156
|
type: "slide" | "fade";
|
|
157
|
+
direction: "north" | "east" | "south" | "west";
|
|
157
158
|
from: string;
|
|
158
159
|
to: string;
|
|
159
|
-
direction: "north" | "east" | "south" | "west";
|
|
160
160
|
}[];
|
|
161
161
|
}, {
|
|
162
162
|
html: {
|
|
@@ -192,8 +192,8 @@ export declare const ProjectSchema: z.ZodObject<{
|
|
|
192
192
|
};
|
|
193
193
|
relations: {
|
|
194
194
|
type: "slide" | "fade";
|
|
195
|
+
direction: "north" | "east" | "south" | "west";
|
|
195
196
|
from: string;
|
|
196
197
|
to: string;
|
|
197
|
-
direction: "north" | "east" | "south" | "west";
|
|
198
198
|
}[];
|
|
199
199
|
}>;
|
|
@@ -49,8 +49,10 @@ function useKeyframeValue(item, type, itemParamsGetter, animatorGetter, sectionI
|
|
|
49
49
|
(0, react_1.useEffect)(() => {
|
|
50
50
|
if (!articleRectObserver || !animator)
|
|
51
51
|
return;
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
return articleRectObserver.on('init', () => {
|
|
53
|
+
const scroll = articleRectObserver.getSectionScroll(sectionId);
|
|
54
|
+
handleKeyframeValue(scroll);
|
|
55
|
+
});
|
|
54
56
|
}, [articleRectObserver, handleKeyframeValue, animator]);
|
|
55
57
|
(0, react_1.useEffect)(() => {
|
|
56
58
|
if (!articleRectObserver || !animator)
|
|
@@ -59,7 +61,7 @@ function useKeyframeValue(item, type, itemParamsGetter, animatorGetter, sectionI
|
|
|
59
61
|
const scroll = articleRectObserver.getSectionScroll(sectionId);
|
|
60
62
|
handleKeyframeValue(scroll);
|
|
61
63
|
});
|
|
62
|
-
}, [
|
|
64
|
+
}, [articleRectObserver, handleKeyframeValue, animator]);
|
|
63
65
|
(0, react_1.useEffect)(() => {
|
|
64
66
|
if (!articleRectObserver || !animator)
|
|
65
67
|
return;
|
|
@@ -67,6 +69,6 @@ function useKeyframeValue(item, type, itemParamsGetter, animatorGetter, sectionI
|
|
|
67
69
|
const scroll = articleRectObserver.getSectionScroll(sectionId);
|
|
68
70
|
handleKeyframeValue(scroll);
|
|
69
71
|
});
|
|
70
|
-
}, [
|
|
72
|
+
}, [articleRectObserver, handleKeyframeValue, animator]);
|
|
71
73
|
return keyframes.length ? adjustedValue : paramValue;
|
|
72
74
|
}
|
|
@@ -11,7 +11,7 @@ const Section_1 = require("./Section/Section");
|
|
|
11
11
|
const Item_1 = require("./items/Item");
|
|
12
12
|
const useArticleRectObserver_1 = require("../utils/ArticleRectManager/useArticleRectObserver");
|
|
13
13
|
const ArticleRectContext_1 = require("../provider/ArticleRectContext");
|
|
14
|
-
const
|
|
14
|
+
const Scene_1 = require("./Scene");
|
|
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");
|
|
@@ -31,7 +31,7 @@ const Article = ({ article, styles, keyframes }) => {
|
|
|
31
31
|
});
|
|
32
32
|
}, [articleRectObserver]);
|
|
33
33
|
const webglContextManager = (0, react_1.useMemo)(() => new effects_1.WebGLContextManager(), []);
|
|
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)(
|
|
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)(Scene_1.Scene, { 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
35
|
const data = {};
|
|
36
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
37
|
}) }) }) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Scene = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const useLayoutDeviation_1 = require("../common/useLayoutDeviation");
|
|
7
7
|
const TransitionMachineContext_1 = require("../provider/TransitionMachineContext");
|
|
8
|
-
const
|
|
8
|
+
const Scene = ({ children, id, styles: sceneStyles }) => {
|
|
9
9
|
var _a;
|
|
10
10
|
const { layoutDeviation } = (0, useLayoutDeviation_1.useLayoutDeviation)();
|
|
11
11
|
const layoutDeviationStyle = { '--layout-deviation': layoutDeviation };
|
|
12
12
|
const sceneRef = (0, react_1.useRef)(null);
|
|
13
13
|
const actorRef = TransitionMachineContext_1.TransitionMachineContext.useActorRef();
|
|
14
|
-
const { isControlledTransitioning, isSettling, isInstantTransitioning } = TransitionMachineContext_1.TransitionMachineContext.useSelector((state) => ({
|
|
14
|
+
const { isControlledTransitioning, isSettling, isInstantTransitioning, stateValue } = TransitionMachineContext_1.TransitionMachineContext.useSelector((state) => ({
|
|
15
15
|
isControlledTransitioning: state.matches('transitioning'),
|
|
16
16
|
isSettling: state.matches('settling'),
|
|
17
17
|
isInstantTransitioning: state.matches('instant_transitioning'),
|
|
18
|
+
stateValue: state.value
|
|
18
19
|
}));
|
|
19
20
|
const type = TransitionMachineContext_1.TransitionMachineContext.useSelector((state) => {
|
|
20
21
|
const { transition } = state.context;
|
|
@@ -136,9 +137,9 @@ const ArticleWrapper = ({ children, id, styles: sceneStyles }) => {
|
|
|
136
137
|
}, [isTransitioning, actorRef, id]);
|
|
137
138
|
const isFixed = isControlledTransitioning || isSettling || isInstantTransitioning;
|
|
138
139
|
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' : '
|
|
140
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (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' : 'scroll', opacity: (_a = sceneStyles === null || sceneStyles === void 0 ? void 0 : sceneStyles.opacity) !== null && _a !== void 0 ? _a : 1 }), children: children }) }));
|
|
140
141
|
};
|
|
141
|
-
exports.
|
|
142
|
+
exports.Scene = Scene;
|
|
142
143
|
function isTransitionDisabled(transitionReady) {
|
|
143
144
|
return !transitionReady.north && !transitionReady.east && !transitionReady.south && !transitionReady.west;
|
|
144
145
|
}
|
|
@@ -153,7 +154,7 @@ function canTransition(direction, el) {
|
|
|
153
154
|
case 'north':
|
|
154
155
|
return el.scrollTop === 0;
|
|
155
156
|
case 'south': {
|
|
156
|
-
const isAllowed = el.scrollTop + el.clientHeight >= el.scrollHeight;
|
|
157
|
+
const isAllowed = el.scrollTop + el.clientHeight + 1 >= el.scrollHeight;
|
|
157
158
|
return isAllowed;
|
|
158
159
|
}
|
|
159
160
|
case 'west':
|
|
@@ -35,24 +35,24 @@ const Section = ({ section, data, children }) => {
|
|
|
35
35
|
transform: media.position === 'fixed' ? 'translateY(-100vh)' : 'unset',
|
|
36
36
|
height: media.position === 'fixed' ? `calc(${getSectionHeight(height)} + 200vh)` : getSectionHeight(height)
|
|
37
37
|
}, children: [media.type === 'video' && ((0, jsx_runtime_1.jsx)(SectionVideo_1.SectionVideo, { container: sectionRef.current, sectionId: section.id, media: media })), media.type === 'image' && ((0, jsx_runtime_1.jsx)(SectionImage_1.SectionImage, { media: media, sectionId: section.id }))] }, `section-background-wrapper-${section.id}`) })), children] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
38
|
+
.section-${section.id} {
|
|
39
|
+
height: ${getSectionHeight(height)};
|
|
40
|
+
position: relative;
|
|
41
|
+
display: ${hidden ? 'none' : 'block'};
|
|
42
|
+
background-color: ${color_1.CntrlColor.parse(color !== null && color !== void 0 ? color : DEFAULT_COLOR).fmt('rgba')};
|
|
43
|
+
}
|
|
44
|
+
.section-background-overlay-${section.id} {
|
|
45
|
+
height: ${getSectionHeight(height)};
|
|
46
|
+
width: 100%;
|
|
47
|
+
position: relative;
|
|
48
|
+
overflow: clip;
|
|
49
|
+
}
|
|
50
|
+
.section-background-wrapper-${section.id} {
|
|
51
|
+
transform: ${(media === null || media === void 0 ? void 0 : media.position) === 'fixed' ? 'translateY(-100vh)' : 'unset'};
|
|
52
|
+
position: relative;
|
|
53
|
+
height: ${(media === null || media === void 0 ? void 0 : media.position) === 'fixed' ? `calc(${getSectionHeight(height)} + 200vh)` : getSectionHeight(height)};
|
|
54
|
+
width: 100%;
|
|
55
|
+
}
|
|
56
56
|
` })] }));
|
|
57
57
|
};
|
|
58
58
|
exports.Section = Section;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from '../EventEmitter';
|
|
2
2
|
interface EventMap {
|
|
3
|
+
'init': undefined;
|
|
3
4
|
'scroll': undefined;
|
|
4
5
|
'resize': DOMRect;
|
|
5
6
|
}
|
|
@@ -11,6 +12,8 @@ export declare class ArticleRectObserver extends EventEmitter<EventMap> {
|
|
|
11
12
|
private animationFrame;
|
|
12
13
|
private parent;
|
|
13
14
|
private sectionsScrollMap;
|
|
15
|
+
private previousParentWidth;
|
|
16
|
+
private isInitialized;
|
|
14
17
|
constructor();
|
|
15
18
|
get scroll(): number;
|
|
16
19
|
getSectionScroll(sectionId: string): number;
|
|
@@ -9,12 +9,14 @@ const resize_observer_polyfill_1 = __importDefault(require("resize-observer-poly
|
|
|
9
9
|
class ArticleRectObserver extends EventEmitter_1.EventEmitter {
|
|
10
10
|
constructor() {
|
|
11
11
|
super();
|
|
12
|
-
this.articleWidth =
|
|
12
|
+
this.articleWidth = 1;
|
|
13
13
|
this.registry = new Map();
|
|
14
14
|
this.scrollPos = window.scrollY;
|
|
15
15
|
this.animationFrame = NaN;
|
|
16
16
|
this.parent = undefined;
|
|
17
17
|
this.sectionsScrollMap = new Map();
|
|
18
|
+
this.previousParentWidth = null;
|
|
19
|
+
this.isInitialized = false;
|
|
18
20
|
this.handleScroll = (scroll) => {
|
|
19
21
|
this.setScroll(scroll / this.articleWidth);
|
|
20
22
|
};
|
|
@@ -41,8 +43,17 @@ class ArticleRectObserver extends EventEmitter_1.EventEmitter {
|
|
|
41
43
|
}
|
|
42
44
|
init(parent) {
|
|
43
45
|
this.parent = parent;
|
|
46
|
+
const scrollableParent = parent.parentElement;
|
|
47
|
+
const parentBoundary = parent.getBoundingClientRect();
|
|
48
|
+
if (!scrollableParent) {
|
|
49
|
+
throw new Error('Scrollable parent not found');
|
|
50
|
+
}
|
|
51
|
+
const articleWidth = parentBoundary.width;
|
|
52
|
+
this.articleWidth = articleWidth;
|
|
53
|
+
this.previousParentWidth = articleWidth;
|
|
54
|
+
this.setScroll(scrollableParent.scrollTop / articleWidth);
|
|
44
55
|
const onScroll = () => {
|
|
45
|
-
this.handleScroll(
|
|
56
|
+
this.handleScroll(scrollableParent.scrollTop);
|
|
46
57
|
if (!isNaN(this.animationFrame))
|
|
47
58
|
return;
|
|
48
59
|
this.animationFrame = window.requestAnimationFrame(() => {
|
|
@@ -50,10 +61,21 @@ class ArticleRectObserver extends EventEmitter_1.EventEmitter {
|
|
|
50
61
|
this.emit('scroll', undefined);
|
|
51
62
|
});
|
|
52
63
|
};
|
|
53
|
-
|
|
64
|
+
scrollableParent.addEventListener('scroll', onScroll);
|
|
65
|
+
for (const sectionId of this.registry.keys()) {
|
|
66
|
+
const el = this.registry.get(sectionId);
|
|
67
|
+
if (!el)
|
|
68
|
+
continue;
|
|
69
|
+
const rect = el.getBoundingClientRect();
|
|
70
|
+
this.sectionsScrollMap.set(sectionId, rect.top - parentBoundary.top);
|
|
71
|
+
}
|
|
72
|
+
this.isInitialized = true;
|
|
73
|
+
this.emit('init', undefined);
|
|
54
74
|
return () => {
|
|
55
75
|
this.parent = undefined;
|
|
56
|
-
|
|
76
|
+
this.isInitialized = false;
|
|
77
|
+
this.previousParentWidth = null;
|
|
78
|
+
scrollableParent.removeEventListener('scroll', onScroll);
|
|
57
79
|
if (!isNaN(this.animationFrame)) {
|
|
58
80
|
window.cancelAnimationFrame(this.animationFrame);
|
|
59
81
|
this.animationFrame = NaN;
|
|
@@ -72,7 +94,14 @@ class ArticleRectObserver extends EventEmitter_1.EventEmitter {
|
|
|
72
94
|
if (!this.parent)
|
|
73
95
|
return;
|
|
74
96
|
const parentBoundary = this.parent.getBoundingClientRect();
|
|
75
|
-
|
|
97
|
+
const newWidth = parentBoundary.width;
|
|
98
|
+
if (!this.isInitialized || this.previousParentWidth === newWidth) {
|
|
99
|
+
this.articleWidth = newWidth;
|
|
100
|
+
this.previousParentWidth = newWidth;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
this.articleWidth = newWidth;
|
|
104
|
+
this.previousParentWidth = newWidth;
|
|
76
105
|
this.setScroll(window.scrollY / this.articleWidth);
|
|
77
106
|
this.emit('resize', parentBoundary);
|
|
78
107
|
for (const sectionId of this.registry.keys()) {
|