@cntrl-site/sdk 0.0.7 → 0.1.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/{client → Client}/Client.js +0 -0
- package/lib/FontFaceGenerator/FontFaceGenerator.js +26 -0
- package/lib/index.js +4 -2
- package/package.json +5 -2
- package/src/{client → Client}/Client.ts +0 -0
- package/src/FontFaceGenerator/FontFaceGenerator.test.ts +53 -0
- package/src/FontFaceGenerator/FontFaceGenerator.ts +26 -0
- package/src/index.ts +2 -1
- package/src/utils.ts +1 -0
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FontFaceGenerator = void 0;
|
|
4
|
+
const FILE_TYPES_MAP = {
|
|
5
|
+
ttf: 'truetype'
|
|
6
|
+
};
|
|
7
|
+
class FontFaceGenerator {
|
|
8
|
+
constructor(fonts) {
|
|
9
|
+
this.fonts = fonts;
|
|
10
|
+
}
|
|
11
|
+
generate() {
|
|
12
|
+
return this.fonts.map(font => {
|
|
13
|
+
const eotFile = font.files.find(file => file.type === 'eot');
|
|
14
|
+
const otherFiles = font.files
|
|
15
|
+
.filter(file => file.type !== 'eot')
|
|
16
|
+
.map(file => `url('${file.url}') format('${FILE_TYPES_MAP[file.type] || file.type}')`);
|
|
17
|
+
return `
|
|
18
|
+
@font-face {
|
|
19
|
+
font-family: ${font.name};
|
|
20
|
+
font-weight: ${font.weight};
|
|
21
|
+
${eotFile ? `src: url('${eotFile.url}');\n ` : ''}src: ${otherFiles.join(', ')};
|
|
22
|
+
}`;
|
|
23
|
+
}).join('\n');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.FontFaceGenerator = FontFaceGenerator;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLayoutStyles = exports.CntrlClient = void 0;
|
|
4
|
-
var Client_1 = require("./
|
|
3
|
+
exports.getLayoutStyles = exports.FontFaceGenerator = exports.CntrlClient = void 0;
|
|
4
|
+
var Client_1 = require("./Client/Client");
|
|
5
5
|
Object.defineProperty(exports, "CntrlClient", { enumerable: true, get: function () { return Client_1.Client; } });
|
|
6
|
+
var FontFaceGenerator_1 = require("./FontFaceGenerator/FontFaceGenerator");
|
|
7
|
+
Object.defineProperty(exports, "FontFaceGenerator", { enumerable: true, get: function () { return FontFaceGenerator_1.FontFaceGenerator; } });
|
|
6
8
|
var utils_1 = require("./utils");
|
|
7
9
|
Object.defineProperty(exports, "getLayoutStyles", { enumerable: true, get: function () { return utils_1.getLayoutStyles; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Generic SDK for use in public websites.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -24,13 +24,16 @@
|
|
|
24
24
|
"lib": "lib"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@cntrl-site/core": "^1.0.
|
|
27
|
+
"@cntrl-site/core": "^1.0.12",
|
|
28
28
|
"@types/isomorphic-fetch": "^0.0.36",
|
|
29
29
|
"isomorphic-fetch": "^3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@tsconfig/node16": "^1.0.3",
|
|
33
33
|
"@tsconfig/recommended": "^1.0.1",
|
|
34
|
+
"@types/jest": "^29.0.0",
|
|
35
|
+
"jest": "^28.1.3",
|
|
36
|
+
"ts-jest": "^28.0.8",
|
|
34
37
|
"typescript": "^4.7.4"
|
|
35
38
|
}
|
|
36
39
|
}
|
|
File without changes
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { FontFaceGenerator } from './FontFaceGenerator';
|
|
2
|
+
import { FontFileTypes, TCustomFont } from '@cntrl-site/core';
|
|
3
|
+
|
|
4
|
+
describe('FontFaceGenerator', () => {
|
|
5
|
+
it('generates font face with eot', () => {
|
|
6
|
+
const fonts: TCustomFont[] = [
|
|
7
|
+
{
|
|
8
|
+
name: 'Aeonik',
|
|
9
|
+
weight: 400,
|
|
10
|
+
style: 'normal',
|
|
11
|
+
files: [
|
|
12
|
+
{
|
|
13
|
+
type: FontFileTypes.EOT,
|
|
14
|
+
url: 'link/to/font.eot'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
type: FontFileTypes.WOFF,
|
|
18
|
+
url: 'link/to/font.woff'
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'Anek Odia',
|
|
24
|
+
weight: 700,
|
|
25
|
+
style: 'italic',
|
|
26
|
+
files: [
|
|
27
|
+
{
|
|
28
|
+
type: FontFileTypes.WOFF,
|
|
29
|
+
url: 'link/to/font.woff'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: FontFileTypes.TTF,
|
|
33
|
+
url: 'link/to/font.ttf'
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
const generator = new FontFaceGenerator(fonts);
|
|
39
|
+
expect(generator.generate()).toEqual(`
|
|
40
|
+
@font-face {
|
|
41
|
+
font-family: Aeonik;
|
|
42
|
+
font-weight: 400;
|
|
43
|
+
src: url('link/to/font.eot');
|
|
44
|
+
src: url('link/to/font.woff') format('woff');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@font-face {
|
|
48
|
+
font-family: Anek Odia;
|
|
49
|
+
font-weight: 700;
|
|
50
|
+
src: url('link/to/font.woff') format('woff'), url('link/to/font.ttf') format('truetype');
|
|
51
|
+
}`)
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TCustomFont } from '@cntrl-site/core';
|
|
2
|
+
|
|
3
|
+
const FILE_TYPES_MAP: Record<string, string> = {
|
|
4
|
+
ttf: 'truetype'
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export class FontFaceGenerator {
|
|
8
|
+
constructor(
|
|
9
|
+
private fonts: TCustomFont[]
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
generate(): string {
|
|
13
|
+
return this.fonts.map(font => {
|
|
14
|
+
const eotFile = font.files.find(file => file.type === 'eot');
|
|
15
|
+
const otherFiles = font.files
|
|
16
|
+
.filter(file => file.type !== 'eot')
|
|
17
|
+
.map(file => `url('${file.url}') format('${FILE_TYPES_MAP[file.type] || file.type}')`);
|
|
18
|
+
return `
|
|
19
|
+
@font-face {
|
|
20
|
+
font-family: ${font.name};
|
|
21
|
+
font-weight: ${font.weight};
|
|
22
|
+
${eotFile ? `src: url('${eotFile.url}');\n ` : ''}src: ${otherFiles.join(', ')};
|
|
23
|
+
}`;
|
|
24
|
+
}).join('\n');
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/index.ts
CHANGED
package/src/utils.ts
CHANGED