@octaviaflow/type 1.0.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/README.md +239 -0
- package/es/index.js +850 -0
- package/index.scss +14 -0
- package/lib/index.js +922 -0
- package/package.json +59 -0
- package/scss/_classes.scss +42 -0
- package/scss/_default-type.scss +50 -0
- package/scss/_font-family.scss +105 -0
- package/scss/_prefix.scss +28 -0
- package/scss/_reset.scss +42 -0
- package/scss/_scale.scss +58 -0
- package/scss/_styles.scss +902 -0
- package/src/__tests__/__snapshots__/fontFamily-test.js.snap +13 -0
- package/src/__tests__/__snapshots__/fontFamily.test.js.snap +13 -0
- package/src/__tests__/__snapshots__/fontWeight-test.js.snap +11 -0
- package/src/__tests__/__snapshots__/fontWeight.test.js.snap +11 -0
- package/src/__tests__/__snapshots__/reset-test.js.snap +11 -0
- package/src/__tests__/__snapshots__/reset.test.js.snap +11 -0
- package/src/__tests__/__snapshots__/scale-test.js.snap +29 -0
- package/src/__tests__/__snapshots__/scale.test.js.snap +29 -0
- package/src/__tests__/__snapshots__/styles-test.js.snap +411 -0
- package/src/__tests__/__snapshots__/styles.test.js.snap +411 -0
- package/src/__tests__/exports-test.js +88 -0
- package/src/__tests__/exports.test.js +88 -0
- package/src/__tests__/fluid-test.js +71 -0
- package/src/__tests__/fluid.test.js +71 -0
- package/src/__tests__/fontFamily-test.js +33 -0
- package/src/__tests__/fontFamily.test.js +33 -0
- package/src/__tests__/fontWeight-test.js +33 -0
- package/src/__tests__/fontWeight.test.js +33 -0
- package/src/__tests__/reset-test.js +23 -0
- package/src/__tests__/reset.test.js +23 -0
- package/src/__tests__/scale-test.js +31 -0
- package/src/__tests__/scale.test.js +31 -0
- package/src/__tests__/styles-test.js +18 -0
- package/src/__tests__/styles.test.js +18 -0
- package/src/__tests__/tokens-test.js +21 -0
- package/src/__tests__/tokens.test.js +21 -0
- package/src/fluid.js +89 -0
- package/src/fontFamily.js +33 -0
- package/src/fontWeight.js +27 -0
- package/src/index.js +31 -0
- package/src/print.js +39 -0
- package/src/reset.js +32 -0
- package/src/scale.js +33 -0
- package/src/styles.js +491 -0
- package/src/tokens.js +132 -0
- package/telemetry.yml +16 -0
- package/umd/index.js +926 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { fluid } from "../fluid";
|
|
11
|
+
import { display04 } from "../styles";
|
|
12
|
+
|
|
13
|
+
describe("fluid", () => {
|
|
14
|
+
it("should return back a token if no breakpoints available", () => {
|
|
15
|
+
const token = {
|
|
16
|
+
fontSize: "1rem",
|
|
17
|
+
};
|
|
18
|
+
expect(fluid(token)).toEqual(token);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should include the default styles for each breakpoint as a media key", () => {
|
|
22
|
+
const token = {
|
|
23
|
+
fontSize: "1rem",
|
|
24
|
+
letterSpacing: 0,
|
|
25
|
+
breakpoints: {
|
|
26
|
+
md: {
|
|
27
|
+
fontSize: "1.5rem",
|
|
28
|
+
letterSpacing: "100%",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
expect(fluid(token)).toEqual(
|
|
33
|
+
expect.objectContaining({
|
|
34
|
+
letterSpacing: token.letterSpacing,
|
|
35
|
+
"@media (min-width: 42rem)": expect.objectContaining({
|
|
36
|
+
letterSpacing: token.breakpoints.md.letterSpacing,
|
|
37
|
+
}),
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should compute the fluid styles for a token", () => {
|
|
43
|
+
expect(fluid(display04)).toMatchInlineSnapshot(`
|
|
44
|
+
{
|
|
45
|
+
"@media (min-width: 42rem)": {
|
|
46
|
+
"fontSize": "calc(4.25rem + 1.5 * ((100vw - 42rem) / 24))",
|
|
47
|
+
"lineHeight": 1.15,
|
|
48
|
+
},
|
|
49
|
+
"@media (min-width: 66rem)": {
|
|
50
|
+
"fontSize": "calc(5.75rem + 1.875 * ((100vw - 66rem) / 16))",
|
|
51
|
+
"letterSpacing": "-0.64px",
|
|
52
|
+
"lineHeight": 1.11,
|
|
53
|
+
},
|
|
54
|
+
"@media (min-width: 82rem)": {
|
|
55
|
+
"fontSize": "calc(7.625rem + 2.125 * ((100vw - 82rem) / 17))",
|
|
56
|
+
"letterSpacing": "-0.64px",
|
|
57
|
+
"lineHeight": 1.07,
|
|
58
|
+
},
|
|
59
|
+
"@media (min-width: 99rem)": {
|
|
60
|
+
"fontSize": "9.75rem",
|
|
61
|
+
"letterSpacing": "-0.96px",
|
|
62
|
+
"lineHeight": 1.05,
|
|
63
|
+
},
|
|
64
|
+
"fontSize": "calc(2.625rem + 1.625 * ((100vw - 20rem) / 22))",
|
|
65
|
+
"fontWeight": 300,
|
|
66
|
+
"letterSpacing": 0,
|
|
67
|
+
"lineHeight": 1.19,
|
|
68
|
+
}
|
|
69
|
+
`);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { fontFamilies, fontFamily } from '../fontFamily';
|
|
11
|
+
import { print } from '../print';
|
|
12
|
+
|
|
13
|
+
describe('fontFamily', () => {
|
|
14
|
+
it('should export the supported font families', () => {
|
|
15
|
+
expect(fontFamilies).toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should support getting the quoted string for a font family', () => {
|
|
19
|
+
expect(fontFamily('mono')).toEqual({
|
|
20
|
+
fontFamily: fontFamilies.mono,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should error out if trying to get a font that does not exist', () => {
|
|
25
|
+
expect(() => {
|
|
26
|
+
fontFamily('<unknown>');
|
|
27
|
+
}).toThrow();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should be printable', () => {
|
|
31
|
+
expect(print(fontFamily('mono'))).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { fontFamilies, fontFamily } from '../fontFamily';
|
|
11
|
+
import { print } from '../print';
|
|
12
|
+
|
|
13
|
+
describe('fontFamily', () => {
|
|
14
|
+
it('should export the supported font families', () => {
|
|
15
|
+
expect(fontFamilies).toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should support getting the quoted string for a font family', () => {
|
|
19
|
+
expect(fontFamily('mono')).toEqual({
|
|
20
|
+
fontFamily: fontFamilies.mono,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should error out if trying to get a font that does not exist', () => {
|
|
25
|
+
expect(() => {
|
|
26
|
+
fontFamily('<unknown>');
|
|
27
|
+
}).toThrow();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should be printable', () => {
|
|
31
|
+
expect(print(fontFamily('mono'))).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { fontWeights, fontWeight } from '../fontWeight';
|
|
11
|
+
import { print } from '../print';
|
|
12
|
+
|
|
13
|
+
describe('fontWeight', () => {
|
|
14
|
+
it('should export the supported font weights', () => {
|
|
15
|
+
expect(fontWeights).toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should support getting the quoted string for a font weight', () => {
|
|
19
|
+
expect(fontWeight('light')).toEqual({
|
|
20
|
+
fontWeight: fontWeights.light,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should error out if trying to get a font weight that does not exist', () => {
|
|
25
|
+
expect(() => {
|
|
26
|
+
fontWeight('<unknown>');
|
|
27
|
+
}).toThrow();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should be printable', () => {
|
|
31
|
+
expect(print(fontWeight('regular'))).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { fontWeights, fontWeight } from '../fontWeight';
|
|
11
|
+
import { print } from '../print';
|
|
12
|
+
|
|
13
|
+
describe('fontWeight', () => {
|
|
14
|
+
it('should export the supported font weights', () => {
|
|
15
|
+
expect(fontWeights).toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should support getting the quoted string for a font weight', () => {
|
|
19
|
+
expect(fontWeight('light')).toEqual({
|
|
20
|
+
fontWeight: fontWeights.light,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should error out if trying to get a font weight that does not exist', () => {
|
|
25
|
+
expect(() => {
|
|
26
|
+
fontWeight('<unknown>');
|
|
27
|
+
}).toThrow();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should be printable', () => {
|
|
31
|
+
expect(print(fontWeight('regular'))).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { reset } from '../reset';
|
|
11
|
+
import { print } from '../print';
|
|
12
|
+
|
|
13
|
+
describe('reset', () => {
|
|
14
|
+
it('should set styles for `html` and `body`', () => {
|
|
15
|
+
expect(reset.html).toBeDefined();
|
|
16
|
+
expect(reset.body).toBeDefined();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should be printable', () => {
|
|
20
|
+
expect(print(reset.html)).toMatchSnapshot();
|
|
21
|
+
expect(print(reset.body)).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { reset } from '../reset';
|
|
11
|
+
import { print } from '../print';
|
|
12
|
+
|
|
13
|
+
describe('reset', () => {
|
|
14
|
+
it('should set styles for `html` and `body`', () => {
|
|
15
|
+
expect(reset.html).toBeDefined();
|
|
16
|
+
expect(reset.body).toBeDefined();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should be printable', () => {
|
|
20
|
+
expect(print(reset.html)).toMatchSnapshot();
|
|
21
|
+
expect(print(reset.body)).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { getTypeSize, scale } from '../scale';
|
|
11
|
+
|
|
12
|
+
describe('scale', () => {
|
|
13
|
+
it('should export the type scale', () => {
|
|
14
|
+
expect(scale).toMatchSnapshot();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('getTypeSize', () => {
|
|
18
|
+
it('should return the base font for steps <= 1', () => {
|
|
19
|
+
expect(getTypeSize(1)).toBe(12);
|
|
20
|
+
expect(getTypeSize(0)).toBe(12);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should support steps greater than 1', () => {
|
|
24
|
+
expect(() => {
|
|
25
|
+
getTypeSize(2);
|
|
26
|
+
getTypeSize(10);
|
|
27
|
+
getTypeSize(20);
|
|
28
|
+
}).not.toThrow();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { getTypeSize, scale } from '../scale';
|
|
11
|
+
|
|
12
|
+
describe('scale', () => {
|
|
13
|
+
it('should export the type scale', () => {
|
|
14
|
+
expect(scale).toMatchSnapshot();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('getTypeSize', () => {
|
|
18
|
+
it('should return the base font for steps <= 1', () => {
|
|
19
|
+
expect(getTypeSize(1)).toBe(12);
|
|
20
|
+
expect(getTypeSize(0)).toBe(12);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should support steps greater than 1', () => {
|
|
24
|
+
expect(() => {
|
|
25
|
+
getTypeSize(2);
|
|
26
|
+
getTypeSize(10);
|
|
27
|
+
getTypeSize(20);
|
|
28
|
+
}).not.toThrow();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as tokens from '../styles';
|
|
11
|
+
import { print } from '../print';
|
|
12
|
+
|
|
13
|
+
describe('styles', () => {
|
|
14
|
+
test.each(Object.keys(tokens))('%s should be printable', (key) => {
|
|
15
|
+
const token = tokens[key];
|
|
16
|
+
expect(print(token)).toMatchSnapshot();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as tokens from '../styles';
|
|
11
|
+
import { print } from '../print';
|
|
12
|
+
|
|
13
|
+
describe('styles', () => {
|
|
14
|
+
test.each(Object.keys(tokens))('%s should be printable', (key) => {
|
|
15
|
+
const token = tokens[key];
|
|
16
|
+
expect(print(token)).toMatchSnapshot();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { unstable_tokens as tokens } from '../tokens';
|
|
11
|
+
import * as styles from '../styles';
|
|
12
|
+
|
|
13
|
+
describe('type tokens', () => {
|
|
14
|
+
test.each(tokens)('%s should be defined in styles', (token) => {
|
|
15
|
+
expect(styles[token]).toBeDefined();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test.each(Object.keys(styles))('%s should be defined in tokens', (token) => {
|
|
19
|
+
expect(tokens.indexOf(token)).not.toBe(-1);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { unstable_tokens as tokens } from '../tokens';
|
|
11
|
+
import * as styles from '../styles';
|
|
12
|
+
|
|
13
|
+
describe('type tokens', () => {
|
|
14
|
+
test.each(tokens)('%s should be defined in styles', (token) => {
|
|
15
|
+
expect(styles[token]).toBeDefined();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test.each(Object.keys(styles))('%s should be defined in tokens', (token) => {
|
|
19
|
+
expect(tokens.indexOf(token)).not.toBe(-1);
|
|
20
|
+
});
|
|
21
|
+
});
|
package/src/fluid.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
import { breakpoint as bp, breakpoints } from '@octaviaflow/layout';
|
|
12
|
+
|
|
13
|
+
const breakpointNames = Object.keys(breakpoints);
|
|
14
|
+
|
|
15
|
+
function next(name) {
|
|
16
|
+
return breakpointNames[breakpointNames.indexOf(name) + 1];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function fluid(selector) {
|
|
20
|
+
const { breakpoints: fluidBreakpoints, ...styles } = selector;
|
|
21
|
+
|
|
22
|
+
if (typeof fluidBreakpoints !== 'object') {
|
|
23
|
+
return styles;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const fluidBreakpointNames = Object.keys(fluidBreakpoints);
|
|
27
|
+
if (fluidBreakpointNames.length === 0) {
|
|
28
|
+
return styles;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
styles.fontSize = fluidTypeSize(styles, 'sm', fluidBreakpoints);
|
|
32
|
+
|
|
33
|
+
fluidBreakpointNames.forEach((name) => {
|
|
34
|
+
styles[bp(name)] = {
|
|
35
|
+
...fluidBreakpoints[name],
|
|
36
|
+
fontSize: fluidTypeSize(styles, name, fluidBreakpoints),
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return styles;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function fluidTypeSize(defaultStyles, fluidBreakpointName, fluidBreakpoints) {
|
|
44
|
+
const breakpoint = breakpoints[fluidBreakpointName];
|
|
45
|
+
const fluidBreakpoint =
|
|
46
|
+
fluidBreakpointName === 'sm'
|
|
47
|
+
? defaultStyles
|
|
48
|
+
: fluidBreakpoints[fluidBreakpointName];
|
|
49
|
+
|
|
50
|
+
let maxFontSize = defaultStyles.fontSize;
|
|
51
|
+
let minFontSize = defaultStyles.fontSize;
|
|
52
|
+
if (fluidBreakpoint.fontSize) {
|
|
53
|
+
minFontSize = fluidBreakpoint.fontSize;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let maxViewportWidth = breakpoint.width;
|
|
57
|
+
let minViewportWidth = breakpoint.width;
|
|
58
|
+
|
|
59
|
+
let nextBreakpointAvailable = next(fluidBreakpointName);
|
|
60
|
+
let nextFluidBreakpointName = null;
|
|
61
|
+
|
|
62
|
+
while (nextBreakpointAvailable) {
|
|
63
|
+
if (fluidBreakpoints[nextBreakpointAvailable]) {
|
|
64
|
+
nextFluidBreakpointName = nextBreakpointAvailable;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
nextBreakpointAvailable = next(nextBreakpointAvailable);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (nextFluidBreakpointName) {
|
|
71
|
+
const nextFluidBreakpoint = breakpoints[nextFluidBreakpointName];
|
|
72
|
+
maxFontSize = fluidBreakpoints[nextFluidBreakpointName].fontSize;
|
|
73
|
+
maxViewportWidth = nextFluidBreakpoint.width;
|
|
74
|
+
|
|
75
|
+
return `calc(${minFontSize} + ${subtract(
|
|
76
|
+
maxFontSize,
|
|
77
|
+
minFontSize
|
|
78
|
+
)} * ((100vw - ${minViewportWidth}) / ${subtract(
|
|
79
|
+
maxViewportWidth,
|
|
80
|
+
minViewportWidth
|
|
81
|
+
)}))`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return minFontSize;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function subtract(a, b) {
|
|
88
|
+
return parseFloat(a) - parseFloat(b);
|
|
89
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
// Font family fallbacks for: IBM Plex Mono, IBM Plex Sans, IBM Plex Sans
|
|
12
|
+
// Condensed, IBM Plex Sans Hebrew, and IBM Plex Serif
|
|
13
|
+
export const fontFamilies = {
|
|
14
|
+
mono: "'IBM Plex Mono', 'Menlo', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Courier, monospace",
|
|
15
|
+
sans: "'IBM Plex Sans', system-ui, -apple-system, BlinkMacSystemFont, '.SFNSText-Regular', sans-serif",
|
|
16
|
+
sansCondensed:
|
|
17
|
+
"'IBM Plex Sans Condensed', 'Helvetica Neue', Arial, sans-serif",
|
|
18
|
+
sansHebrew:
|
|
19
|
+
"'IBM Plex Sans Hebrew', 'Helvetica Hebrew', 'Arial Hebrew', sans-serif",
|
|
20
|
+
serif: "'IBM Plex Serif', 'Georgia', Times, serif",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function fontFamily(name) {
|
|
24
|
+
if (!fontFamilies[name]) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`Unable to find font family: \`${name}\`. Expected one of: ` +
|
|
27
|
+
`[${Object.keys(fontFamilies).join(', ')}]`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
fontFamily: fontFamilies[name],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export const fontWeights = {
|
|
12
|
+
light: 300,
|
|
13
|
+
regular: 400,
|
|
14
|
+
semibold: 600,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function fontWeight(weight) {
|
|
18
|
+
if (!fontWeights[weight]) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`Unable to find font weight: \`${weight}\`. Expected one of: ` +
|
|
21
|
+
`[${Object.keys(fontWeights).join(', ')}]`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
fontWeight: fontWeights[weight],
|
|
26
|
+
};
|
|
27
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
import { fontFamilies, fontFamily } from './fontFamily';
|
|
12
|
+
import { fontWeights, fontWeight } from './fontWeight';
|
|
13
|
+
import { print } from './print';
|
|
14
|
+
import { reset } from './reset';
|
|
15
|
+
import { getTypeSize, scale } from './scale';
|
|
16
|
+
import * as styles from './styles';
|
|
17
|
+
|
|
18
|
+
export { fluid } from './fluid';
|
|
19
|
+
export * from './styles';
|
|
20
|
+
export { unstable_tokens } from './tokens';
|
|
21
|
+
export {
|
|
22
|
+
fontFamilies,
|
|
23
|
+
fontFamily,
|
|
24
|
+
fontWeights,
|
|
25
|
+
fontWeight,
|
|
26
|
+
print,
|
|
27
|
+
reset,
|
|
28
|
+
getTypeSize,
|
|
29
|
+
scale,
|
|
30
|
+
styles,
|
|
31
|
+
};
|
package/src/print.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export function print(block) {
|
|
12
|
+
return Object.keys(block).reduce((acc, key, index) => {
|
|
13
|
+
// Short-circuit on the foreign key 'breakpoints'. This is used in our
|
|
14
|
+
// tokens for fluid type and should not be printed. In the future, we should
|
|
15
|
+
// tie this to media query outputs.
|
|
16
|
+
if (key === 'breakpoints') {
|
|
17
|
+
return acc;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const property = `${paramCase(key)}: ${block[key]};`;
|
|
21
|
+
if (index === 0) {
|
|
22
|
+
return property;
|
|
23
|
+
}
|
|
24
|
+
return acc + '\n' + property;
|
|
25
|
+
}, '');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function paramCase(string) {
|
|
29
|
+
let result = '';
|
|
30
|
+
for (let i = 0; i < string.length; i++) {
|
|
31
|
+
const character = string[i];
|
|
32
|
+
if (character === character.toUpperCase()) {
|
|
33
|
+
result += '-' + character.toLowerCase();
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
result += character;
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
package/src/reset.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
import { baseFontSize, px } from '@octaviaflow/layout';
|
|
12
|
+
import { fontFamilies } from './fontFamily';
|
|
13
|
+
import { fontWeights } from './fontWeight';
|
|
14
|
+
|
|
15
|
+
export const reset = {
|
|
16
|
+
html: {
|
|
17
|
+
fontSize: px(baseFontSize),
|
|
18
|
+
},
|
|
19
|
+
body: {
|
|
20
|
+
fontFamily: fontFamilies.sans,
|
|
21
|
+
fontWeight: fontWeights.regular,
|
|
22
|
+
textRendering: 'optimizeLegibility',
|
|
23
|
+
'-webkit-font-smoothing': 'antialiased',
|
|
24
|
+
'-moz-osx-font-smoothing': 'grayscale',
|
|
25
|
+
},
|
|
26
|
+
strong: {
|
|
27
|
+
fontWeight: fontWeights.semibold,
|
|
28
|
+
},
|
|
29
|
+
code: {
|
|
30
|
+
fontFamily: fontFamilies.mono,
|
|
31
|
+
},
|
|
32
|
+
};
|