@cntrl-site/sdk-nextjs 0.17.2 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  2. package/.idea/inspectionProfiles/Project_Default.xml +15 -0
  3. package/lib/components/Head.js +1 -1
  4. package/lib/components/Item.js +4 -4
  5. package/lib/components/Page.js +1 -4
  6. package/lib/components/items/ImageItem.js +2 -1
  7. package/lib/components/items/RectangleItem.js +3 -2
  8. package/lib/components/items/RichTextItem.js +3 -2
  9. package/lib/components/items/VideoItem.js +2 -1
  10. package/lib/components/items/useRichTextItem.js +2 -9
  11. package/lib/components/useSectionColor.js +3 -3
  12. package/lib/provider/CntrlSdkContext.js +1 -8
  13. package/lib/utils/Animator/Animator.js +3 -2
  14. package/lib/utils/HoverStyles/HoverStyles.js +4 -4
  15. package/lib/utils/RichTextConverter/RichTextConverter.js +3 -2
  16. package/package.json +3 -2
  17. package/src/common/useKeyframeValue.ts +3 -3
  18. package/src/components/Article.tsx +1 -1
  19. package/src/components/Head.tsx +4 -4
  20. package/src/components/Item.tsx +11 -12
  21. package/src/components/LayoutStyle.tsx +3 -3
  22. package/src/components/Page.tsx +4 -10
  23. package/src/components/Section.tsx +4 -4
  24. package/src/components/items/CustomItem.tsx +1 -1
  25. package/src/components/items/ImageItem.tsx +2 -1
  26. package/src/components/items/RectangleItem.tsx +2 -1
  27. package/src/components/items/RichTextItem.tsx +2 -1
  28. package/src/components/items/VideoItem.tsx +2 -1
  29. package/src/components/items/VimeoEmbed.tsx +1 -2
  30. package/src/components/items/YoutubeEmbed.tsx +1 -2
  31. package/src/components/items/useEmbedVideoItem.ts +2 -2
  32. package/src/components/items/useFileItem.ts +2 -2
  33. package/src/components/items/useRectangleItem.ts +2 -2
  34. package/src/components/items/useRichTextItem.ts +4 -10
  35. package/src/components/items/useRichTextItemValues.ts +2 -2
  36. package/src/components/items/useStickyItemTop.ts +2 -2
  37. package/src/components/useItemAngle.ts +2 -2
  38. package/src/components/useItemDimensions.ts +2 -2
  39. package/src/components/useItemPosition.ts +2 -2
  40. package/src/components/useItemScale.ts +2 -2
  41. package/src/components/useSectionColor.ts +1 -1
  42. package/src/components/useSectionHeightMap.ts +3 -3
  43. package/src/provider/CntrlSdkContext.ts +10 -21
  44. package/src/provider/Keyframes.ts +2 -2
  45. package/src/utils/Animator/Animator.ts +31 -30
  46. package/src/utils/HoverStyles/HoverStyles.ts +5 -4
  47. package/src/utils/RichTextConverter/RichTextConverter.tsx +10 -9
  48. package/lib/utils/generateTypePresetStyles/generateTypePresetStyles.js +0 -27
  49. package/src/utils/generateTypePresetStyles/__mock__/layoutsMock.ts +0 -43
  50. package/src/utils/generateTypePresetStyles/__mock__/presetMock.ts +0 -33
  51. package/src/utils/generateTypePresetStyles/generateTypePresetStyles.test.ts +0 -49
  52. package/src/utils/generateTypePresetStyles/generateTypePresetStyles.ts +0 -25
@@ -1,10 +1,10 @@
1
- import { TImageItem, TVideoItem } from '@cntrl-site/sdk';
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: TImageItem | TVideoItem, sectionId: string) => {
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 { TRectangleItem } from '@cntrl-site/sdk';
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: TRectangleItem, sectionId: string) => {
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 { TRichTextItem, TTypePresetEntry } from '@cntrl-site/sdk';
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: TRichTextItem): [ReactNode[], string, TTypePresetEntry | null] => {
10
- const layoutId = useLayoutContext();
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, preset];
11
+ return [content, styles];
18
12
  };
@@ -1,10 +1,10 @@
1
1
  import { useKeyframeValue } from '../../common/useKeyframeValue';
2
- import { TRichTextItem } from '@cntrl-site/sdk';
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: TRichTextItem, sectionId: string) => {
7
+ export const useRichTextItemValues = (item: RichTextItem, sectionId: string) => {
8
8
  const layoutId = useLayoutContext();
9
9
  const { angle } = useKeyframeValue(
10
10
  item,
@@ -1,8 +1,8 @@
1
- import { TArticleItemAny } from '@cntrl-site/sdk';
1
+ import { ItemAny } from '@cntrl-site/sdk';
2
2
  import { useKeyframeValue } from '../../common/useKeyframeValue';
3
3
  import { useLayoutContext } from '../useLayoutContext';
4
4
 
5
- export function useStickyItemTop(item: TArticleItemAny, sectionHeightMap: Record<string, string>, sectionId: string) {
5
+ export function useStickyItemTop(item: ItemAny, sectionHeightMap: Record<string, string>, sectionId: string) {
6
6
  const layoutId = useLayoutContext();
7
7
  const { top } = useKeyframeValue<{ top: number; left: number }>(
8
8
  item,
@@ -1,7 +1,7 @@
1
- import { TArticleItemAny } from '@cntrl-site/sdk';
1
+ import { ItemAny } from '@cntrl-site/sdk';
2
2
  import { useKeyframeValue } from '../common/useKeyframeValue';
3
3
 
4
- export const useItemAngle = (item: TArticleItemAny, sectionId: string) => {
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 { TArticleItemAny } from '@cntrl-site/sdk';
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: TArticleItemAny, sectionId: string) => {
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, TArticleItemAny } from '@cntrl-site/sdk';
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: TArticleItemAny, sectionId: string) => {
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, TArticleItemAny } from '@cntrl-site/sdk';
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: TArticleItemAny, sectionId: string) => {
5
+ export const useItemScale = (item: ItemAny, sectionId: string) => {
6
6
  const layoutId = useLayoutContext();
7
7
  const { scale } = useKeyframeValue(
8
8
  item,
@@ -1,5 +1,5 @@
1
1
  import { useMemo } from 'react';
2
- import { CntrlColor } from '@cntrl-site/sdk';
2
+ import { CntrlColor } from '@cntrl-site/color';
3
3
  import { useLayoutContext } from './useLayoutContext';
4
4
 
5
5
  type LayoutIdentifier = string;
@@ -1,6 +1,6 @@
1
1
  import { useContext } from 'react';
2
2
  import { CntrlContext } from '../provider/CntrlContext';
3
- import { TLayout, TSectionHeight } from '@cntrl-site/sdk';
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, TSectionHeight>): Record<string, 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: TLayout[]) {
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 { TArticle, TArticleSection, TLayout, TProject, TSectionHeight, TTypePresets } from '@cntrl-site/sdk';
2
+ import { Article, Section, Layout, Project, SectionHeight } from '@cntrl-site/sdk';
3
3
  import { CustomSectionRegistry } from './CustomSectionRegistry';
4
4
 
5
5
  interface SdkContextInitProps {
6
- typePresets: TTypePresets;
7
- project: TProject;
8
- article: TArticle;
6
+ project: Project;
7
+ article: Article;
9
8
  }
10
9
 
11
10
  export class CntrlSdkContext {
12
- private _typePresets?: TTypePresets;
13
- private _layouts: TLayout[] = [];
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: TArticleSection[]): Promise<Record<string, any>> {
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, typePresets, article }: SdkContextInitProps) {
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
- setTypePresets(typePresets: TTypePresets) {
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: TArticleSection[]) {
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(): TLayout[] {
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 { TKeyframeAny } from '@cntrl-site/sdk';
1
+ import { KeyframeAny } from '@cntrl-site/sdk';
2
2
 
3
3
  export class Keyframes {
4
4
  constructor(
5
- private keyframes: TKeyframeAny[] = []
5
+ private keyframes: KeyframeAny[] = []
6
6
  ) {}
7
7
 
8
8
  getItemKeyframes(itemId: string) {
@@ -1,9 +1,10 @@
1
- import { KeyframeType, TKeyframeValueMap, CntrlColor } from '@cntrl-site/sdk';
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: TKeyframeValueMap[T];
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: TKeyframeValueMap[KeyframeType.Dimensions],
35
+ values: KeyframeValueMap[KeyframeType.Dimensions],
35
36
  pos: number
36
- ): TKeyframeValueMap[KeyframeType.Dimensions] {
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: TKeyframeValueMap[KeyframeType.Position],
55
+ values: KeyframeValueMap[KeyframeType.Position],
55
56
  pos: number
56
- ): TKeyframeValueMap[KeyframeType.Position] {
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: TKeyframeValueMap[KeyframeType.Color],
75
+ values: KeyframeValueMap[KeyframeType.Color],
75
76
  pos: number
76
- ): TKeyframeValueMap[KeyframeType.Color] {
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: TKeyframeValueMap[KeyframeType.BorderColor],
93
+ values: KeyframeValueMap[KeyframeType.BorderColor],
93
94
  pos: number
94
- ): TKeyframeValueMap[KeyframeType.BorderColor] {
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: TKeyframeValueMap[KeyframeType.BorderRadius],
111
+ values: KeyframeValueMap[KeyframeType.BorderRadius],
111
112
  pos: number
112
- ): TKeyframeValueMap[KeyframeType.BorderRadius] {
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: TKeyframeValueMap[KeyframeType.BorderWidth],
129
+ values: KeyframeValueMap[KeyframeType.BorderWidth],
129
130
  pos: number
130
- ): TKeyframeValueMap[KeyframeType.BorderWidth] {
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: TKeyframeValueMap[KeyframeType.Rotation],
147
+ values: KeyframeValueMap[KeyframeType.Rotation],
147
148
  pos: number
148
- ): TKeyframeValueMap[KeyframeType.Rotation] {
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: TKeyframeValueMap[KeyframeType.Opacity],
165
+ values: KeyframeValueMap[KeyframeType.Opacity],
165
166
  pos: number
166
- ): TKeyframeValueMap[KeyframeType.Opacity] {
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: TKeyframeValueMap[KeyframeType.Scale],
183
+ values: KeyframeValueMap[KeyframeType.Scale],
183
184
  pos: number
184
- ): TKeyframeValueMap[KeyframeType.Scale] {
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: TKeyframeValueMap[KeyframeType.Blur],
201
+ values: KeyframeValueMap[KeyframeType.Blur],
201
202
  pos: number
202
- ): TKeyframeValueMap[KeyframeType.Blur] {
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: TKeyframeValueMap[KeyframeType.BackdropBlur],
219
+ values: KeyframeValueMap[KeyframeType.BackdropBlur],
219
220
  pos: number
220
- ): TKeyframeValueMap[KeyframeType.BackdropBlur] {
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: TKeyframeValueMap[KeyframeType.TextColor],
237
+ values: KeyframeValueMap[KeyframeType.TextColor],
237
238
  pos: number
238
- ): TKeyframeValueMap[KeyframeType.TextColor] {
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: TKeyframeValueMap[KeyframeType.LetterSpacing],
255
+ values: KeyframeValueMap[KeyframeType.LetterSpacing],
255
256
  pos: number
256
- ): TKeyframeValueMap[KeyframeType.LetterSpacing] {
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: TKeyframeValueMap[KeyframeType.WordSpacing],
280
+ values: KeyframeValueMap[KeyframeType.WordSpacing],
280
281
  pos: number
281
- ): TKeyframeValueMap[KeyframeType.WordSpacing] {
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 { THoverParams, ArticleItemType, CntrlColor, AnchorSide, TItemHoverState } from '@cntrl-site/sdk';
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<TItemHoverState>, 'autoplay'>;
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 THoverParams<string | number>;
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 THoverParams<string | number>;
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
- TLayout,
8
- TRichTextItem,
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: TRichTextItem,
42
- layouts: TLayout[]
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: RichText.Style[], entities: RichText.Entity[]): StyleGroup[] | undefined {
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: RichText.Entity[], styleGroups?: StyleGroup[]): EntitiesGroup[] | undefined {
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) {
@@ -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
- ];
@@ -1,33 +0,0 @@
1
- import { TTypePresets, TypePresetStatus } from '@cntrl-site/sdk';
2
-
3
- export const presetMock: TTypePresets = {
4
- id: 'presetId',
5
- presets: [
6
- {
7
- id: 'heading01',
8
- fontFamily: 'Aeonik',
9
- fontWeight: '400',
10
- fontStyle: '',
11
- name: 'Heading',
12
- fontSize: 24,
13
- lineHeight: 36,
14
- wordSpacing: 1,
15
- letterSpacing: 1,
16
- color: 'rgba(0, 0, 0, 1)',
17
- status: TypePresetStatus.Active
18
- },
19
- {
20
- id: 'heading02',
21
- fontFamily: 'Aeonik',
22
- fontWeight: '400',
23
- fontStyle: 'italic',
24
- name: 'Heading 2',
25
- fontSize: 24,
26
- lineHeight: 36,
27
- wordSpacing: 1,
28
- letterSpacing: 1,
29
- color: 'rgba(0, 0, 0, 1)',
30
- status: TypePresetStatus.Active
31
- }
32
- ]
33
- };
@@ -1,49 +0,0 @@
1
- import { generateTypePresetStyles } from './generateTypePresetStyles';
2
- import { presetMock } from './__mock__/presetMock';
3
- import { layoutsMock } from './__mock__/layoutsMock';
4
-
5
- describe('generateTypePresetStyles', () => {
6
- it('generates blocks of styles', () => {
7
- const styles = generateTypePresetStyles(presetMock, layoutsMock);
8
- const expectedMedia = (id: string) =>
9
- `@media (min-width: 0px) and (max-width: 767px) {
10
- .cntrl-preset-${id} {
11
- font-size: 6.4vw;
12
- line-height: 9.6vw;
13
- letter-spacing: 0.26666666666666666vw;
14
- word-spacing: 0.26666666666666666vw;
15
- color: rgba(0, 0, 0, 1);
16
- }
17
- }
18
- @media (min-width: 768px) and (max-width: 1023px) {
19
- .cntrl-preset-${id} {
20
- font-size: 3.125vw;
21
- line-height: 4.6875vw;
22
- letter-spacing: 0.13020833333333331vw;
23
- word-spacing: 0.13020833333333331vw;
24
- color: rgba(0, 0, 0, 1);
25
- }
26
- }
27
- @media (min-width: 1024px) {
28
- .cntrl-preset-${id} {
29
- font-size: 1.6666666666666667vw;
30
- line-height: 2.5vw;
31
- letter-spacing: 0.06944444444444445vw;
32
- word-spacing: 0.06944444444444445vw;
33
- color: rgba(0, 0, 0, 1);
34
- }
35
- }`;
36
- expect(styles).toBe(
37
- `.cntrl-preset-heading01 {
38
- font-family: Aeonik;
39
- font-weight: 400;
40
- }
41
- ${expectedMedia('heading01')}
42
- .cntrl-preset-heading02 {
43
- font-family: Aeonik;
44
- font-style: italic;
45
- font-weight: 400;
46
- }
47
- ${expectedMedia('heading02')}`);
48
- });
49
- });