@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.
- package/lib/common/useRegisterResize.js +1 -1
- package/lib/components/Head.js +1 -1
- package/lib/components/Item.js +8 -8
- package/lib/components/Page.js +1 -4
- package/lib/components/items/ImageItem.js +2 -1
- package/lib/components/items/RectangleItem.js +3 -2
- package/lib/components/items/RichTextItem.js +3 -2
- package/lib/components/items/VideoItem.js +2 -1
- package/lib/components/items/useRichTextItem.js +2 -9
- package/lib/components/items/useStickyItemTop.js +1 -5
- package/lib/components/useSectionColor.js +3 -3
- package/lib/provider/CntrlSdkContext.js +1 -8
- package/lib/utils/Animator/Animator.js +3 -2
- package/lib/utils/HoverStyles/HoverStyles.js +4 -4
- package/lib/utils/RichTextConverter/RichTextConverter.js +3 -2
- package/package.json +3 -2
- package/src/common/useKeyframeValue.ts +3 -3
- package/src/common/useRegisterResize.ts +1 -1
- package/src/components/Article.tsx +1 -1
- package/src/components/Head.tsx +4 -4
- package/src/components/Item.tsx +15 -16
- package/src/components/LayoutStyle.tsx +3 -3
- package/src/components/Page.tsx +4 -10
- package/src/components/Section.tsx +4 -4
- package/src/components/items/CustomItem.tsx +1 -1
- package/src/components/items/ImageItem.tsx +2 -1
- package/src/components/items/RectangleItem.tsx +2 -1
- package/src/components/items/RichTextItem.tsx +2 -1
- package/src/components/items/VideoItem.tsx +2 -1
- package/src/components/items/VimeoEmbed.tsx +1 -2
- package/src/components/items/YoutubeEmbed.tsx +1 -2
- package/src/components/items/useEmbedVideoItem.ts +2 -2
- package/src/components/items/useFileItem.ts +2 -2
- package/src/components/items/useRectangleItem.ts +2 -2
- package/src/components/items/useRichTextItem.ts +4 -10
- package/src/components/items/useRichTextItemValues.ts +2 -2
- package/src/components/items/useStickyItemTop.ts +3 -6
- package/src/components/useItemAngle.ts +2 -2
- package/src/components/useItemDimensions.ts +2 -2
- package/src/components/useItemPosition.ts +2 -2
- package/src/components/useItemScale.ts +2 -2
- package/src/components/useSectionColor.ts +1 -1
- package/src/components/useSectionHeightMap.ts +3 -3
- package/src/provider/CntrlSdkContext.ts +10 -21
- package/src/provider/Keyframes.ts +2 -2
- package/src/utils/Animator/Animator.ts +31 -30
- package/src/utils/HoverStyles/HoverStyles.ts +5 -4
- package/src/utils/RichTextConverter/RichTextConverter.tsx +10 -9
- package/cntrl-site-sdk-nextjs-0.17.1.tgz +0 -0
- package/lib/utils/generateTypePresetStyles/generateTypePresetStyles.js +0 -27
- package/src/utils/generateTypePresetStyles/__mock__/layoutsMock.ts +0 -43
- package/src/utils/generateTypePresetStyles/__mock__/presetMock.ts +0 -33
- package/src/utils/generateTypePresetStyles/generateTypePresetStyles.test.ts +0 -49
- package/src/utils/generateTypePresetStyles/generateTypePresetStyles.ts +0 -25
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FC, useId, useMemo, useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { CntrlColor } from '@cntrl-site/color';
|
|
3
|
+
import { ArticleItemType, getLayoutStyles, RichTextItem as TRichTextItem } from '@cntrl-site/sdk';
|
|
3
4
|
import JSXStyle from 'styled-jsx/style';
|
|
4
5
|
import { ItemProps } from '../Item';
|
|
5
6
|
import { useRichTextItem } from './useRichTextItem';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FC, useId, useMemo, useState } from 'react';
|
|
2
2
|
import JSXStyle from 'styled-jsx/style';
|
|
3
|
-
import {
|
|
3
|
+
import { CntrlColor } from '@cntrl-site/color';
|
|
4
|
+
import { ArticleItemType, getLayoutStyles, VideoItem as TVideoItem } from '@cntrl-site/sdk';
|
|
4
5
|
import { ItemProps } from '../Item';
|
|
5
6
|
import { LinkWrapper } from '../LinkWrapper';
|
|
6
7
|
import { useFileItem } from './useFileItem';
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { FC, useId, useMemo, useState } from 'react';
|
|
2
2
|
import Player from '@vimeo/player';
|
|
3
3
|
import JSXStyle from 'styled-jsx/style';
|
|
4
|
-
import { TVimeoEmbedItem } from '@cntrl-site/core';
|
|
5
4
|
import { ItemProps } from '../Item';
|
|
6
5
|
import { LinkWrapper } from '../LinkWrapper';
|
|
7
6
|
import { useEmbedVideoItem } from './useEmbedVideoItem';
|
|
8
7
|
import { useItemAngle } from '../useItemAngle';
|
|
9
|
-
import { ArticleItemType, getLayoutStyles } from '@cntrl-site/sdk';
|
|
8
|
+
import { ArticleItemType, getLayoutStyles, VimeoEmbedItem as TVimeoEmbedItem } from '@cntrl-site/sdk';
|
|
10
9
|
import { useCntrlContext } from '../../provider/useCntrlContext';
|
|
11
10
|
import { getHoverStyles, getTransitions } from '../../utils/HoverStyles/HoverStyles';
|
|
12
11
|
import { useRegisterResize } from "../../common/useRegisterResize";
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { FC, useEffect, useId, useState } from 'react';
|
|
2
2
|
import JSXStyle from 'styled-jsx/style';
|
|
3
|
-
import { TYoutubeEmbedItem } from '@cntrl-site/core';
|
|
4
3
|
import { ItemProps } from '../Item';
|
|
5
4
|
import { LinkWrapper } from '../LinkWrapper';
|
|
6
5
|
import { getYoutubeId } from '../../utils/getValidYoutubeUrl';
|
|
7
6
|
import { useEmbedVideoItem } from './useEmbedVideoItem';
|
|
8
7
|
import { useItemAngle } from '../useItemAngle';
|
|
9
|
-
import { ArticleItemType, getLayoutStyles } from '@cntrl-site/sdk';
|
|
8
|
+
import { ArticleItemType, getLayoutStyles, YoutubeEmbedItem as TYoutubeEmbedItem } from '@cntrl-site/sdk';
|
|
10
9
|
import { getHoverStyles, getTransitions } from '../../utils/HoverStyles/HoverStyles';
|
|
11
10
|
import { useCntrlContext } from '../../provider/useCntrlContext';
|
|
12
11
|
import { useYouTubeIframeApi } from '../../utils/Youtube/useYouTubeIframeApi';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VimeoEmbedItem, YoutubeEmbedItem } from '@cntrl-site/sdk';
|
|
2
2
|
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
3
3
|
import { useLayoutContext } from '../useLayoutContext';
|
|
4
4
|
|
|
5
|
-
export const useEmbedVideoItem = (item:
|
|
5
|
+
export const useEmbedVideoItem = (item: VimeoEmbedItem | YoutubeEmbedItem, sectionId: string) => {
|
|
6
6
|
const layoutId = useLayoutContext();
|
|
7
7
|
const radius = useKeyframeValue(
|
|
8
8
|
item,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ImageItem, VideoItem } from '@cntrl-site/sdk';
|
|
2
2
|
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
3
3
|
import { useLayoutContext } from '../useLayoutContext';
|
|
4
4
|
|
|
5
5
|
const defaultColor = 'rgba(0, 0, 0, 1)';
|
|
6
6
|
|
|
7
|
-
export const useFileItem = (item:
|
|
7
|
+
export const useFileItem = (item: ImageItem | VideoItem, sectionId: string) => {
|
|
8
8
|
const layoutId = useLayoutContext();
|
|
9
9
|
const radius = useKeyframeValue(
|
|
10
10
|
item,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RectangleItem } from '@cntrl-site/sdk';
|
|
2
2
|
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
3
3
|
import { useLayoutContext } from '../useLayoutContext';
|
|
4
4
|
|
|
5
5
|
const defaultColor = 'rgba(0, 0, 0, 1)';
|
|
6
6
|
|
|
7
|
-
export const useRectangleItem = (item:
|
|
7
|
+
export const useRectangleItem = (item: RectangleItem, sectionId: string) => {
|
|
8
8
|
const layoutId = useLayoutContext();
|
|
9
9
|
const radius = useKeyframeValue(
|
|
10
10
|
item,
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RichTextItem } from '@cntrl-site/sdk';
|
|
2
2
|
import { RichTextConverter } from '../../utils/RichTextConverter/RichTextConverter';
|
|
3
3
|
import { useCntrlContext } from '../../provider/useCntrlContext';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
|
-
import { useLayoutContext } from '../useLayoutContext';
|
|
6
5
|
|
|
7
6
|
const richTextConverter = new RichTextConverter();
|
|
8
7
|
|
|
9
|
-
export const useRichTextItem = (item:
|
|
10
|
-
const
|
|
11
|
-
const { layouts, typePresets } = useCntrlContext();
|
|
12
|
-
const presetId = layoutId ? item.layoutParams[layoutId].preset : null;
|
|
13
|
-
const preset = presetId
|
|
14
|
-
? typePresets?.presets.find(p => p.id === presetId) ?? null
|
|
15
|
-
: null;
|
|
8
|
+
export const useRichTextItem = (item: RichTextItem): [ReactNode[], string] => {
|
|
9
|
+
const { layouts } = useCntrlContext();
|
|
16
10
|
const [content, styles] = richTextConverter.toHtml(item, layouts);
|
|
17
|
-
return [content, styles
|
|
11
|
+
return [content, styles];
|
|
18
12
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
2
|
-
import {
|
|
2
|
+
import { RichTextItem } from '@cntrl-site/sdk';
|
|
3
3
|
import { useLayoutContext } from '../useLayoutContext';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_COLOR = 'rgba(0, 0, 0, 1)';
|
|
6
6
|
|
|
7
|
-
export const useRichTextItemValues = (item:
|
|
7
|
+
export const useRichTextItemValues = (item: RichTextItem, sectionId: string) => {
|
|
8
8
|
const layoutId = useLayoutContext();
|
|
9
9
|
const { angle } = useKeyframeValue(
|
|
10
10
|
item,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ItemAny } from '@cntrl-site/sdk';
|
|
2
2
|
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
3
|
-
import { getAnchoredItemTop } from '../../utils/getAnchoredItemTop';
|
|
4
3
|
import { useLayoutContext } from '../useLayoutContext';
|
|
5
4
|
|
|
6
|
-
export function useStickyItemTop(item:
|
|
5
|
+
export function useStickyItemTop(item: ItemAny, sectionHeightMap: Record<string, string>, sectionId: string) {
|
|
7
6
|
const layoutId = useLayoutContext();
|
|
8
7
|
const { top } = useKeyframeValue<{ top: number; left: number }>(
|
|
9
8
|
item,
|
|
@@ -16,7 +15,5 @@ export function useStickyItemTop(item: TArticleItemAny, sectionHeightMap: Record
|
|
|
16
15
|
[layoutId]
|
|
17
16
|
);
|
|
18
17
|
const sticky = layoutId ? item.sticky[layoutId] : undefined;
|
|
19
|
-
|
|
20
|
-
const anchorSide = layoutId ? item.area[layoutId].anchorSide : AnchorSide.Top;
|
|
21
|
-
return sticky ? `${getAnchoredItemTop(top - sticky.from, sectionHeight, anchorSide)}` : 0
|
|
18
|
+
return sticky ? top - sticky.from : 0
|
|
22
19
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ItemAny } from '@cntrl-site/sdk';
|
|
2
2
|
import { useKeyframeValue } from '../common/useKeyframeValue';
|
|
3
3
|
|
|
4
|
-
export const useItemAngle = (item:
|
|
4
|
+
export const useItemAngle = (item: ItemAny, sectionId: string) => {
|
|
5
5
|
const { angle } = useKeyframeValue(
|
|
6
6
|
item,
|
|
7
7
|
(item, layoutId) => ({ angle: layoutId ? item.area[layoutId].angle : 0 }),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ItemAny } from '@cntrl-site/sdk';
|
|
2
2
|
import { useKeyframeValue } from '../common/useKeyframeValue';
|
|
3
3
|
import { useLayoutContext } from './useLayoutContext';
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@ const defaultArea = {
|
|
|
11
11
|
zIndex: 0
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export const useItemDimensions = (item:
|
|
14
|
+
export const useItemDimensions = (item: ItemAny, sectionId: string) => {
|
|
15
15
|
const layoutId = useLayoutContext();
|
|
16
16
|
const { width, height } = useKeyframeValue<{ width: number; height: number }>(
|
|
17
17
|
item,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AnchorSide,
|
|
1
|
+
import { AnchorSide, ItemAny } from '@cntrl-site/sdk';
|
|
2
2
|
import { useKeyframeValue } from '../common/useKeyframeValue';
|
|
3
3
|
import { getItemTopStyle } from '../utils/getItemTopStyle';
|
|
4
4
|
import { useLayoutContext } from './useLayoutContext';
|
|
5
5
|
|
|
6
|
-
export const useItemPosition = (item:
|
|
6
|
+
export const useItemPosition = (item: ItemAny, sectionId: string) => {
|
|
7
7
|
const layoutId = useLayoutContext();
|
|
8
8
|
const { top, left } = useKeyframeValue<{ top: number; left: number }>(
|
|
9
9
|
item,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ScaleAnchor,
|
|
1
|
+
import { ScaleAnchor, ItemAny } from '@cntrl-site/sdk';
|
|
2
2
|
import { useKeyframeValue } from '../common/useKeyframeValue';
|
|
3
3
|
import { useLayoutContext } from './useLayoutContext';
|
|
4
4
|
|
|
5
|
-
export const useItemScale = (item:
|
|
5
|
+
export const useItemScale = (item: ItemAny, sectionId: string) => {
|
|
6
6
|
const layoutId = useLayoutContext();
|
|
7
7
|
const { scale } = useKeyframeValue(
|
|
8
8
|
item,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import { CntrlContext } from '../provider/CntrlContext';
|
|
3
|
-
import {
|
|
3
|
+
import { Layout, SectionHeight } from '@cntrl-site/sdk';
|
|
4
4
|
import { getSectionHeight } from './Section';
|
|
5
5
|
|
|
6
6
|
export const useSectionHeightData = (sectionId: string): Record<string, string> => {
|
|
@@ -10,10 +10,10 @@ export const useSectionHeightData = (sectionId: string): Record<string, string>
|
|
|
10
10
|
return sectionHeightData ? getSectionHeightMap(sectionHeightData) : getDefaultHeightData(layouts);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export function getSectionHeightMap(sectionHeight: Record<string,
|
|
13
|
+
export function getSectionHeightMap(sectionHeight: Record<string, SectionHeight>): Record<string, string> {
|
|
14
14
|
return Object.fromEntries(Object.entries(sectionHeight).map(([sectionId, heightData]) => [sectionId, getSectionHeight(heightData)]));
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function getDefaultHeightData(layouts:
|
|
17
|
+
function getDefaultHeightData(layouts: Layout[]) {
|
|
18
18
|
return layouts.reduce((acc, layout) => ({...acc, [layout.id]: '0'}), {});
|
|
19
19
|
}
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import { CustomItemRegistry } from './CustomItemRegistry';
|
|
2
|
-
import {
|
|
2
|
+
import { Article, Section, Layout, Project, SectionHeight } from '@cntrl-site/sdk';
|
|
3
3
|
import { CustomSectionRegistry } from './CustomSectionRegistry';
|
|
4
4
|
|
|
5
5
|
interface SdkContextInitProps {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
article: TArticle;
|
|
6
|
+
project: Project;
|
|
7
|
+
article: Article;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export class CntrlSdkContext {
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private sectionHeightMap: Map<string, Record<string, TSectionHeight>> = new Map();
|
|
11
|
+
private _layouts: Layout[] = [];
|
|
12
|
+
private sectionHeightMap: Map<string, Record<string, SectionHeight>> = new Map();
|
|
15
13
|
constructor(
|
|
16
14
|
public readonly customItems: CustomItemRegistry,
|
|
17
15
|
public readonly customSections: CustomSectionRegistry
|
|
18
16
|
) {}
|
|
19
17
|
|
|
20
|
-
async resolveSectionData(sections:
|
|
18
|
+
async resolveSectionData(sections: Section[]): Promise<Record<string, any>> {
|
|
21
19
|
const resolvers = sections.map(section => {
|
|
22
20
|
const resolver = section.name ? this.customSections.getResolver(section.name) : undefined;
|
|
23
21
|
if (!resolver) return;
|
|
@@ -31,21 +29,16 @@ export class CntrlSdkContext {
|
|
|
31
29
|
);
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
init({ project,
|
|
35
|
-
this.setTypePresets(typePresets);
|
|
32
|
+
init({ project, article }: SdkContextInitProps) {
|
|
36
33
|
this.setLayouts(project.layouts);
|
|
37
34
|
this.setSectionsHeight(article.sections);
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
this._typePresets = typePresets;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
setLayouts(layouts: TLayout[]) {
|
|
37
|
+
setLayouts(layouts: Layout[]) {
|
|
45
38
|
this._layouts = layouts;
|
|
46
39
|
}
|
|
47
40
|
|
|
48
|
-
setSectionsHeight(sections:
|
|
41
|
+
setSectionsHeight(sections: Section[]) {
|
|
49
42
|
for (const section of sections) {
|
|
50
43
|
this.sectionHeightMap.set(section.id, section.height)
|
|
51
44
|
}
|
|
@@ -56,13 +49,9 @@ export class CntrlSdkContext {
|
|
|
56
49
|
return sectionHeightData;
|
|
57
50
|
}
|
|
58
51
|
|
|
59
|
-
get layouts():
|
|
52
|
+
get layouts(): Layout[] {
|
|
60
53
|
return this._layouts;
|
|
61
54
|
}
|
|
62
|
-
|
|
63
|
-
get typePresets(): TTypePresets | undefined {
|
|
64
|
-
return this._typePresets;
|
|
65
|
-
}
|
|
66
55
|
}
|
|
67
56
|
|
|
68
57
|
function isDefined<T>(value: T): value is Exclude<T, undefined> {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KeyframeAny } from '@cntrl-site/sdk';
|
|
2
2
|
|
|
3
3
|
export class Keyframes {
|
|
4
4
|
constructor(
|
|
5
|
-
private keyframes:
|
|
5
|
+
private keyframes: KeyframeAny[] = []
|
|
6
6
|
) {}
|
|
7
7
|
|
|
8
8
|
getItemKeyframes(itemId: string) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { KeyframeType,
|
|
1
|
+
import { KeyframeType, KeyframeValueMap } from '@cntrl-site/sdk';
|
|
2
|
+
import { CntrlColor } from '@cntrl-site/color';
|
|
2
3
|
import { binSearchInsertAt, createInsert } from '../binSearchInsertAt';
|
|
3
4
|
|
|
4
5
|
export interface AnimationData<T extends KeyframeType> {
|
|
5
6
|
position: number;
|
|
6
|
-
value:
|
|
7
|
+
value: KeyframeValueMap[T];
|
|
7
8
|
type: T;
|
|
8
9
|
}
|
|
9
10
|
|
|
@@ -31,9 +32,9 @@ export class Animator {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
getDimensions(
|
|
34
|
-
values:
|
|
35
|
+
values: KeyframeValueMap[KeyframeType.Dimensions],
|
|
35
36
|
pos: number
|
|
36
|
-
):
|
|
37
|
+
): KeyframeValueMap[KeyframeType.Dimensions] {
|
|
37
38
|
const keyframes = this.keyframesMap[KeyframeType.Dimensions];
|
|
38
39
|
if (!keyframes || !keyframes.length) return values;
|
|
39
40
|
if (keyframes.length === 1) {
|
|
@@ -51,9 +52,9 @@ export class Animator {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
getPositions(
|
|
54
|
-
values:
|
|
55
|
+
values: KeyframeValueMap[KeyframeType.Position],
|
|
55
56
|
pos: number
|
|
56
|
-
):
|
|
57
|
+
): KeyframeValueMap[KeyframeType.Position] {
|
|
57
58
|
const keyframes = this.keyframesMap[KeyframeType.Position];
|
|
58
59
|
if (!keyframes || !keyframes.length) return values;
|
|
59
60
|
if (keyframes.length === 1) {
|
|
@@ -71,9 +72,9 @@ export class Animator {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
getColor(
|
|
74
|
-
values:
|
|
75
|
+
values: KeyframeValueMap[KeyframeType.Color],
|
|
75
76
|
pos: number
|
|
76
|
-
):
|
|
77
|
+
): KeyframeValueMap[KeyframeType.Color] {
|
|
77
78
|
const keyframes = this.keyframesMap[KeyframeType.Color];
|
|
78
79
|
if (!keyframes || !keyframes.length) return values;
|
|
79
80
|
if (keyframes.length === 1) {
|
|
@@ -89,9 +90,9 @@ export class Animator {
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
getBorderColor(
|
|
92
|
-
values:
|
|
93
|
+
values: KeyframeValueMap[KeyframeType.BorderColor],
|
|
93
94
|
pos: number
|
|
94
|
-
):
|
|
95
|
+
): KeyframeValueMap[KeyframeType.BorderColor] {
|
|
95
96
|
const keyframes = this.keyframesMap[KeyframeType.BorderColor];
|
|
96
97
|
if (!keyframes || !keyframes.length) return values;
|
|
97
98
|
if (keyframes.length === 1) {
|
|
@@ -107,9 +108,9 @@ export class Animator {
|
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
getRadius(
|
|
110
|
-
values:
|
|
111
|
+
values: KeyframeValueMap[KeyframeType.BorderRadius],
|
|
111
112
|
pos: number
|
|
112
|
-
):
|
|
113
|
+
): KeyframeValueMap[KeyframeType.BorderRadius] {
|
|
113
114
|
const keyframes = this.keyframesMap[KeyframeType.BorderRadius];
|
|
114
115
|
if (!keyframes || !keyframes.length) return values;
|
|
115
116
|
if (keyframes.length === 1) {
|
|
@@ -125,9 +126,9 @@ export class Animator {
|
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
getBorderWidth(
|
|
128
|
-
values:
|
|
129
|
+
values: KeyframeValueMap[KeyframeType.BorderWidth],
|
|
129
130
|
pos: number
|
|
130
|
-
):
|
|
131
|
+
): KeyframeValueMap[KeyframeType.BorderWidth] {
|
|
131
132
|
const keyframes = this.keyframesMap[KeyframeType.BorderWidth];
|
|
132
133
|
if (!keyframes || !keyframes.length) return values;
|
|
133
134
|
if (keyframes.length === 1) {
|
|
@@ -143,9 +144,9 @@ export class Animator {
|
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
getRotation(
|
|
146
|
-
values:
|
|
147
|
+
values: KeyframeValueMap[KeyframeType.Rotation],
|
|
147
148
|
pos: number
|
|
148
|
-
):
|
|
149
|
+
): KeyframeValueMap[KeyframeType.Rotation] {
|
|
149
150
|
const keyframes = this.keyframesMap[KeyframeType.Rotation];
|
|
150
151
|
if (!keyframes || !keyframes.length) return values;
|
|
151
152
|
if (keyframes.length === 1) {
|
|
@@ -161,9 +162,9 @@ export class Animator {
|
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
getOpacity(
|
|
164
|
-
values:
|
|
165
|
+
values: KeyframeValueMap[KeyframeType.Opacity],
|
|
165
166
|
pos: number
|
|
166
|
-
):
|
|
167
|
+
): KeyframeValueMap[KeyframeType.Opacity] {
|
|
167
168
|
const keyframes = this.keyframesMap[KeyframeType.Opacity];
|
|
168
169
|
if (!keyframes || !keyframes.length) return values;
|
|
169
170
|
if (keyframes.length === 1) {
|
|
@@ -179,9 +180,9 @@ export class Animator {
|
|
|
179
180
|
}
|
|
180
181
|
|
|
181
182
|
getScale(
|
|
182
|
-
values:
|
|
183
|
+
values: KeyframeValueMap[KeyframeType.Scale],
|
|
183
184
|
pos: number
|
|
184
|
-
):
|
|
185
|
+
): KeyframeValueMap[KeyframeType.Scale] {
|
|
185
186
|
const keyframes = this.keyframesMap[KeyframeType.Scale];
|
|
186
187
|
if (!keyframes || !keyframes.length) return values;
|
|
187
188
|
if (keyframes.length === 1) {
|
|
@@ -197,9 +198,9 @@ export class Animator {
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
getBlur(
|
|
200
|
-
values:
|
|
201
|
+
values: KeyframeValueMap[KeyframeType.Blur],
|
|
201
202
|
pos: number
|
|
202
|
-
):
|
|
203
|
+
): KeyframeValueMap[KeyframeType.Blur] {
|
|
203
204
|
const keyframes = this.keyframesMap[KeyframeType.Blur];
|
|
204
205
|
if (!keyframes || !keyframes.length) return values;
|
|
205
206
|
if (keyframes.length === 1) {
|
|
@@ -215,9 +216,9 @@ export class Animator {
|
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
getBackdropBlur(
|
|
218
|
-
values:
|
|
219
|
+
values: KeyframeValueMap[KeyframeType.BackdropBlur],
|
|
219
220
|
pos: number
|
|
220
|
-
):
|
|
221
|
+
): KeyframeValueMap[KeyframeType.BackdropBlur] {
|
|
221
222
|
const keyframes = this.keyframesMap[KeyframeType.BackdropBlur];
|
|
222
223
|
if (!keyframes || !keyframes.length) return values;
|
|
223
224
|
if (keyframes.length === 1) {
|
|
@@ -233,9 +234,9 @@ export class Animator {
|
|
|
233
234
|
}
|
|
234
235
|
|
|
235
236
|
getTextColor(
|
|
236
|
-
values:
|
|
237
|
+
values: KeyframeValueMap[KeyframeType.TextColor],
|
|
237
238
|
pos: number
|
|
238
|
-
):
|
|
239
|
+
): KeyframeValueMap[KeyframeType.TextColor] {
|
|
239
240
|
const keyframes = this.keyframesMap[KeyframeType.TextColor];
|
|
240
241
|
if (!keyframes || !keyframes.length) return values;
|
|
241
242
|
if (keyframes.length === 1) {
|
|
@@ -251,9 +252,9 @@ export class Animator {
|
|
|
251
252
|
}
|
|
252
253
|
|
|
253
254
|
getLetterSpacing(
|
|
254
|
-
values:
|
|
255
|
+
values: KeyframeValueMap[KeyframeType.LetterSpacing],
|
|
255
256
|
pos: number
|
|
256
|
-
):
|
|
257
|
+
): KeyframeValueMap[KeyframeType.LetterSpacing] {
|
|
257
258
|
const keyframes = this.keyframesMap[KeyframeType.LetterSpacing];
|
|
258
259
|
if (!keyframes || !keyframes.length) return values;
|
|
259
260
|
if (keyframes.length === 1) {
|
|
@@ -276,9 +277,9 @@ export class Animator {
|
|
|
276
277
|
}
|
|
277
278
|
|
|
278
279
|
getWordSpacing(
|
|
279
|
-
values:
|
|
280
|
+
values: KeyframeValueMap[KeyframeType.WordSpacing],
|
|
280
281
|
pos: number
|
|
281
|
-
):
|
|
282
|
+
): KeyframeValueMap[KeyframeType.WordSpacing] {
|
|
282
283
|
const keyframes = this.keyframesMap[KeyframeType.WordSpacing];
|
|
283
284
|
if (!keyframes || !keyframes.length) return values;
|
|
284
285
|
if (keyframes.length === 1) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HoverParams, ArticleItemType, AnchorSide, ItemHoverState } from '@cntrl-site/sdk';
|
|
2
|
+
import { CntrlColor } from '@cntrl-site/color';
|
|
2
3
|
import { getItemTopStyle } from '../getItemTopStyle';
|
|
3
4
|
|
|
4
5
|
type UnionToIntersection<U> = (U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
|
|
5
6
|
type HoverParamsGetter = (value: any, anchorSide?: AnchorSide) => string;
|
|
6
|
-
type ItemHoverParams = Omit<UnionToIntersection<
|
|
7
|
+
type ItemHoverParams = Omit<UnionToIntersection<ItemHoverState>, 'autoplay'>;
|
|
7
8
|
|
|
8
9
|
const hoverTransformationMap: Record<keyof ItemHoverParams, HoverParamsGetter> = {
|
|
9
10
|
'width': (width: number) => `width: ${width * 100}vw !important;`,
|
|
@@ -50,7 +51,7 @@ export function getTransitions<T extends ArticleItemType>(
|
|
|
50
51
|
if (!hover) return 'unset';
|
|
51
52
|
const transitionValues = values.reduce<string[]>((acc, valueName) => {
|
|
52
53
|
if (valueName in hover && hover[valueName] !== undefined) {
|
|
53
|
-
const hoverProperties = hover[valueName] as
|
|
54
|
+
const hoverProperties = hover[valueName] as HoverParams<string | number>;
|
|
54
55
|
return [
|
|
55
56
|
...acc,
|
|
56
57
|
`${CSSPropertyNameMap[valueName]} ${hoverProperties!.duration}ms ${hoverProperties!.timing} ${hoverProperties!.delay}ms`
|
|
@@ -70,7 +71,7 @@ export function getHoverStyles<T extends ArticleItemType>(
|
|
|
70
71
|
if (!hover) return '';
|
|
71
72
|
const hoverValues = values.reduce<string[]>((acc, valueName) => {
|
|
72
73
|
if (valueName in hover && hover[valueName] !== undefined) {
|
|
73
|
-
const hoverProperties = hover[valueName] as
|
|
74
|
+
const hoverProperties = hover[valueName] as HoverParams<string | number>;
|
|
74
75
|
return [
|
|
75
76
|
...acc,
|
|
76
77
|
hoverTransformationMap[valueName](hoverProperties.value, anchorSide)
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { CntrlColor } from '@cntrl-site/color';
|
|
2
3
|
import {
|
|
3
|
-
CntrlColor,
|
|
4
4
|
getLayoutMediaQuery,
|
|
5
|
-
RichText,
|
|
6
5
|
TextTransform,
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
Layout,
|
|
7
|
+
RichTextItem,
|
|
9
8
|
VerticalAlign,
|
|
10
|
-
TextAlign
|
|
9
|
+
TextAlign,
|
|
10
|
+
RichTextStyle,
|
|
11
|
+
RichTextEntity
|
|
11
12
|
} from '@cntrl-site/sdk';
|
|
12
13
|
import { LinkWrapper } from '../../components/LinkWrapper';
|
|
13
14
|
import { getFontFamilyValue } from '../getFontFamilyValue';
|
|
@@ -38,8 +39,8 @@ export const FontStyles: Record<string, Record<string, string>> = {
|
|
|
38
39
|
|
|
39
40
|
export class RichTextConverter {
|
|
40
41
|
toHtml(
|
|
41
|
-
richText:
|
|
42
|
-
layouts:
|
|
42
|
+
richText: RichTextItem,
|
|
43
|
+
layouts: Layout[]
|
|
43
44
|
): [ReactNode[], string] {
|
|
44
45
|
const { text, blocks = [] } = richText.commonParams;
|
|
45
46
|
const root: ReactElement[] = [];
|
|
@@ -175,7 +176,7 @@ export class RichTextConverter {
|
|
|
175
176
|
return ranges.map(r => `${r.start},${r.end}`).join(' ');
|
|
176
177
|
}
|
|
177
178
|
|
|
178
|
-
private normalizeStyles(styles:
|
|
179
|
+
private normalizeStyles(styles: RichTextStyle[], entities: RichTextEntity[]): StyleGroup[] | undefined {
|
|
179
180
|
const styleGroups: StyleGroup[] = [];
|
|
180
181
|
const dividers = [...styles, ...entities].reduce((ds, s) => {
|
|
181
182
|
ds.add(s.start);
|
|
@@ -199,7 +200,7 @@ export class RichTextConverter {
|
|
|
199
200
|
return styleGroups;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
|
-
private groupEntities(entities:
|
|
203
|
+
private groupEntities(entities: RichTextEntity[], styleGroups?: StyleGroup[]): EntitiesGroup[] | undefined {
|
|
203
204
|
const entitiesGroups: EntitiesGroup[] = [];
|
|
204
205
|
if (!entities.length && !styleGroups) return;
|
|
205
206
|
if (!styleGroups || styleGroups.length === 0) {
|
|
Binary file
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateTypePresetStyles = void 0;
|
|
4
|
-
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
-
const reEmptyLines = /^\s*\n/gm;
|
|
6
|
-
function generateTypePresetStyles(preset, layouts) {
|
|
7
|
-
const sorted = layouts.slice().sort((a, b) => a.startsWith - b.startsWith);
|
|
8
|
-
const stylesStr = (`
|
|
9
|
-
${preset.presets.map(p => (`
|
|
10
|
-
.cntrl-preset-${p.id} {
|
|
11
|
-
font-family: ${p.fontFamily};
|
|
12
|
-
${p.fontStyle.length > 0 ? `font-style: ${p.fontStyle};` : ''}
|
|
13
|
-
font-weight: ${p.fontWeight};
|
|
14
|
-
}
|
|
15
|
-
${sorted.map(l => (`
|
|
16
|
-
${(0, sdk_1.getLayoutMediaQuery)(l.id, sorted)} {
|
|
17
|
-
.cntrl-preset-${p.id} {
|
|
18
|
-
font-size: ${p.fontSize / l.exemplary * 100}vw;
|
|
19
|
-
line-height: ${p.lineHeight / l.exemplary * 100}vw;
|
|
20
|
-
letter-spacing: ${p.letterSpacing / l.exemplary * 100}vw;
|
|
21
|
-
word-spacing: ${p.wordSpacing / l.exemplary * 100}vw;
|
|
22
|
-
color: ${sdk_1.CntrlColor.parse(p.color).toCss()};
|
|
23
|
-
}
|
|
24
|
-
}`)).join('\n')}`)).join('\n')}`);
|
|
25
|
-
return stylesStr.replace(reEmptyLines, '');
|
|
26
|
-
}
|
|
27
|
-
exports.generateTypePresetStyles = generateTypePresetStyles;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { TLayout } from '@cntrl-site/sdk';
|
|
2
|
-
|
|
3
|
-
const sampleGrid = {
|
|
4
|
-
columnsAmount: 0,
|
|
5
|
-
beatHeight: 0,
|
|
6
|
-
beatMultiplier: 1,
|
|
7
|
-
maxWidth: 0,
|
|
8
|
-
columnWidth: 0.01,
|
|
9
|
-
gutterWidth: 0.001
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const layoutsMock: TLayout[] = [
|
|
13
|
-
{
|
|
14
|
-
id: 'tablet',
|
|
15
|
-
exemplary: 768,
|
|
16
|
-
startsWith: 768,
|
|
17
|
-
title: 'Tablet',
|
|
18
|
-
icon: 'any',
|
|
19
|
-
grid: sampleGrid,
|
|
20
|
-
disabled: false,
|
|
21
|
-
locked: false
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
id: 'desktop',
|
|
25
|
-
exemplary: 1440,
|
|
26
|
-
startsWith: 1024,
|
|
27
|
-
title: 'Desktop',
|
|
28
|
-
icon: 'any',
|
|
29
|
-
grid: sampleGrid,
|
|
30
|
-
disabled: false,
|
|
31
|
-
locked: false
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
id: 'mobile',
|
|
35
|
-
exemplary: 375,
|
|
36
|
-
startsWith: 0,
|
|
37
|
-
title: 'Mobile',
|
|
38
|
-
icon: 'any',
|
|
39
|
-
grid: sampleGrid,
|
|
40
|
-
disabled: false,
|
|
41
|
-
locked: false
|
|
42
|
-
}
|
|
43
|
-
];
|