@cntrl-site/sdk 1.2.3 → 1.4.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 (61) hide show
  1. package/lib/Client/Client.js +7 -32
  2. package/lib/index.js +19 -16
  3. package/lib/schemas/article/Article.schema.js +9 -0
  4. package/lib/schemas/article/Item.schema.js +137 -0
  5. package/lib/schemas/article/ItemArea.schema.js +17 -0
  6. package/lib/schemas/article/ItemBase.schema.js +20 -0
  7. package/lib/schemas/article/ItemState.schema.js +52 -0
  8. package/lib/schemas/article/RichTextItem.schema.js +60 -0
  9. package/lib/schemas/article/Section.schema.js +20 -0
  10. package/lib/schemas/keyframe/Keyframes.schema.js +114 -0
  11. package/lib/schemas/project/Layout.schema.js +10 -0
  12. package/lib/schemas/project/Project.schema.js +48 -0
  13. package/lib/types/article/Article.js +2 -0
  14. package/lib/types/article/ArticleItemType.js +13 -0
  15. package/lib/types/article/Item.js +3 -0
  16. package/lib/types/article/ItemArea.js +26 -0
  17. package/lib/types/article/ItemState.js +3 -0
  18. package/lib/types/article/RichText.js +27 -0
  19. package/lib/types/article/Section.js +8 -0
  20. package/lib/types/keyframe/Keyframe.js +20 -0
  21. package/lib/types/project/Fonts.js +11 -0
  22. package/lib/types/project/Layout.js +2 -0
  23. package/lib/types/project/Meta.js +2 -0
  24. package/lib/types/project/Page.js +2 -0
  25. package/lib/types/project/Project.js +2 -0
  26. package/lib/utils.js +15 -1
  27. package/package.json +3 -3
  28. package/src/Client/Client.test.ts +1 -5
  29. package/src/Client/Client.ts +18 -51
  30. package/src/Client/__mock__/articleMock.ts +2 -2
  31. package/src/Client/__mock__/keyframesMock.ts +2 -3
  32. package/src/Client/__mock__/projectMock.ts +2 -7
  33. package/src/FontFaceGenerator/FontFaceGenerator.test.ts +2 -4
  34. package/src/FontFaceGenerator/FontFaceGenerator.ts +2 -2
  35. package/src/cli.ts +2 -2
  36. package/src/index.ts +25 -2
  37. package/src/schemas/article/Article.schema.ts +7 -0
  38. package/src/schemas/article/Item.schema.ts +175 -0
  39. package/src/schemas/article/ItemArea.schema.ts +15 -0
  40. package/src/schemas/article/ItemBase.schema.ts +20 -0
  41. package/src/schemas/article/ItemState.schema.ts +62 -0
  42. package/src/schemas/article/RichTextItem.schema.ts +68 -0
  43. package/src/schemas/article/Section.schema.ts +19 -0
  44. package/src/schemas/keyframe/Keyframes.schema.ts +128 -0
  45. package/src/schemas/project/Layout.schema.ts +8 -0
  46. package/src/schemas/project/Project.schema.ts +48 -0
  47. package/src/types/article/Article.ts +6 -0
  48. package/src/types/article/ArticleItemType.ts +9 -0
  49. package/src/types/article/Item.ts +150 -0
  50. package/src/types/article/ItemArea.ts +35 -0
  51. package/src/types/article/ItemState.ts +64 -0
  52. package/src/types/article/RichText.ts +46 -0
  53. package/src/types/article/Section.ts +22 -0
  54. package/src/types/keyframe/Keyframe.ts +102 -0
  55. package/src/types/project/Fonts.ts +25 -0
  56. package/src/types/project/Layout.ts +6 -0
  57. package/src/types/project/Meta.ts +10 -0
  58. package/src/types/project/Page.ts +13 -0
  59. package/src/types/project/Project.ts +19 -0
  60. package/src/utils.ts +16 -2
  61. package/src/Client/__mock__/typePresetsMock.ts +0 -6
@@ -0,0 +1,22 @@
1
+ import { ItemAny } from './Item';
2
+
3
+ export enum SectionHeightMode {
4
+ ControlUnits = 'control-units' ,
5
+ ViewportHeightUnits = 'viewport-height-units'
6
+ }
7
+
8
+ export interface SectionHeight {
9
+ mode: SectionHeightMode;
10
+ units: number;
11
+ vhUnits?: number;
12
+ }
13
+
14
+ export interface Section {
15
+ id: string;
16
+ name?: string;
17
+ height: Record<string, SectionHeight>;
18
+ hidden: Record<string, boolean>;
19
+ items: ItemAny[];
20
+ position: Record<string, number>;
21
+ color: Record<string, string | null>;
22
+ }
@@ -0,0 +1,102 @@
1
+ export type KeyframeAny = Keyframe<KeyframeType>;
2
+
3
+ export interface Keyframe<T extends KeyframeType> {
4
+ id: string;
5
+ type: T;
6
+ layoutId: string;
7
+ itemId: string;
8
+ position: number;
9
+ value: KeyframeValueMap[T];
10
+ }
11
+
12
+ export enum KeyframeType {
13
+ Dimensions = 'dimensions',
14
+ Position = 'position',
15
+ Rotation = 'rotation',
16
+ BorderRadius = 'border-radius',
17
+ BorderWidth = 'border-width',
18
+ Color = 'color',
19
+ BorderColor = 'border-color',
20
+ Opacity = 'opacity',
21
+ Scale = 'scale',
22
+ TextColor = 'text-color',
23
+ LetterSpacing = 'letter-spacing',
24
+ WordSpacing = 'word-spacing',
25
+ Blur = 'blur',
26
+ BackdropBlur = 'backdrop-blur'
27
+ }
28
+
29
+ export interface KeyframeValueMap {
30
+ [KeyframeType.Dimensions]: DimensionsValue;
31
+ [KeyframeType.Position]: PositionValue;
32
+ [KeyframeType.Rotation]: RotationValue;
33
+ [KeyframeType.BorderRadius]: BorderRadiusValue;
34
+ [KeyframeType.BorderWidth]: BorderWidthValue;
35
+ [KeyframeType.Color]: ColorValue;
36
+ [KeyframeType.BorderColor]: BorderColorValue;
37
+ [KeyframeType.Opacity]: OpacityValue;
38
+ [KeyframeType.Scale]: ScaleValue;
39
+ [KeyframeType.Blur]: BlurValue;
40
+ [KeyframeType.BackdropBlur]: BackdropBlurValue;
41
+ [KeyframeType.TextColor]: TextColorValue;
42
+ [KeyframeType.LetterSpacing]: LetterSpacingValue;
43
+ [KeyframeType.WordSpacing]: WordSpacingValue;
44
+ }
45
+
46
+ interface DimensionsValue {
47
+ width: number;
48
+ height: number;
49
+ }
50
+
51
+ interface PositionValue {
52
+ top: number;
53
+ left: number;
54
+ }
55
+
56
+ interface RotationValue {
57
+ angle: number;
58
+ }
59
+
60
+ interface BorderRadiusValue {
61
+ radius: number;
62
+ }
63
+
64
+ interface BorderWidthValue {
65
+ borderWidth: number;
66
+ }
67
+
68
+ interface ColorValue {
69
+ color: string;
70
+ }
71
+
72
+ interface BorderColorValue {
73
+ color: string;
74
+ }
75
+
76
+ interface OpacityValue {
77
+ opacity: number;
78
+ }
79
+
80
+ interface ScaleValue {
81
+ scale: number;
82
+ }
83
+
84
+ interface BlurValue {
85
+ blur: number;
86
+ }
87
+
88
+ interface BackdropBlurValue {
89
+ backdropBlur: number;
90
+ }
91
+
92
+ interface TextColorValue {
93
+ color: string;
94
+ }
95
+
96
+ interface LetterSpacingValue {
97
+ letterSpacing: number;
98
+ }
99
+
100
+ interface WordSpacingValue {
101
+ wordSpacing: number;
102
+ }
@@ -0,0 +1,25 @@
1
+ export enum FontFileTypes {
2
+ OTF = 'otf',
3
+ TTF = 'ttf',
4
+ WOFF = 'woff',
5
+ WOFF2 = 'woff2',
6
+ EOT = 'eot'
7
+ }
8
+
9
+ export interface CustomFontFile {
10
+ type: FontFileTypes;
11
+ url: string;
12
+ }
13
+
14
+ export interface CustomFont {
15
+ name: string;
16
+ style: string;
17
+ weight: number;
18
+ files: CustomFontFile[];
19
+ }
20
+
21
+ export interface Fonts {
22
+ google: string;
23
+ adobe: string;
24
+ custom: CustomFont[];
25
+ }
@@ -0,0 +1,6 @@
1
+ export interface Layout {
2
+ id: string;
3
+ title: string;
4
+ startsWith: number;
5
+ exemplary: number;
6
+ }
@@ -0,0 +1,10 @@
1
+ export interface Meta extends GenericMeta {
2
+ favicon?: string;
3
+ }
4
+
5
+ export interface GenericMeta {
6
+ title?: string;
7
+ description?: string;
8
+ opengraphThumbnail?: string;
9
+ keywords?: string;
10
+ }
@@ -0,0 +1,13 @@
1
+ import { GenericMeta } from './Meta';
2
+
3
+ export interface PageMeta extends GenericMeta {
4
+ enabled?: boolean;
5
+ }
6
+
7
+ export interface Page {
8
+ id: string;
9
+ title: string;
10
+ articleId: string;
11
+ slug: string;
12
+ meta?: PageMeta;
13
+ }
@@ -0,0 +1,19 @@
1
+ import { Layout } from './Layout';
2
+ import { Fonts } from './Fonts';
3
+ import { Meta } from './Meta';
4
+ import { Page } from './Page';
5
+
6
+ export interface AdditionalHTML {
7
+ head: string;
8
+ afterBodyOpen: string;
9
+ beforeBodyClose: string;
10
+ }
11
+
12
+ export interface Project {
13
+ id: string;
14
+ html: AdditionalHTML;
15
+ meta: Meta;
16
+ layouts: Layout[];
17
+ pages: Page[];
18
+ fonts: Fonts;
19
+ }
package/src/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { TLayout } from '@cntrl-site/core';
1
+ import { Layout } from './types/project/Layout';
2
2
 
3
3
  export function getLayoutStyles<V, M> (
4
- layouts: TLayout[],
4
+ layouts: Layout[],
5
5
  layoutValues: Record<string, V>[],
6
6
  mapToStyles: (values: V[], exemplary: number) => M
7
7
  ): string {
@@ -20,3 +20,17 @@ export function getLayoutStyles<V, M> (
20
20
  return mediaQueries;
21
21
  }
22
22
 
23
+ export function getLayoutMediaQuery(layoutId: string, layouts: Layout[]): string {
24
+ const sorted = layouts.slice().sort((a, b) => a.startsWith - b.startsWith);
25
+ const layoutIndex = sorted.findIndex(l => l.id === layoutId);
26
+ if (layoutIndex === -1) {
27
+ throw new Error(`No layout was found by the given id #${layoutId}`);
28
+ }
29
+ const current = sorted[layoutIndex];
30
+ const next = sorted[layoutIndex + 1];
31
+ if (!next) {
32
+ return `@media (min-width: ${current.startsWith}px)`;
33
+ }
34
+ return `@media (min-width: ${current.startsWith}px) and (max-width: ${next.startsWith - 1}px)`;
35
+ }
36
+
@@ -1,6 +0,0 @@
1
- import { TTypePresets } from '@cntrl-site/core';
2
-
3
- export const typePresetsMock: TTypePresets = {
4
- id: 'typePresetsId',
5
- presets: []
6
- };