Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: update Yoga to 3.0 #2711

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/honest-boxes-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-pdf/layout": major
---

Update Yoga to 3.0
2 changes: 1 addition & 1 deletion packages/layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"cross-fetch": "^3.1.5",
"emoji-regex": "^10.3.0",
"queue": "^6.0.1",
"yoga-layout": "^2.0.1"
"yoga-layout": "^3.0.0"
},
"files": [
"lib"
Expand Down
4 changes: 2 additions & 2 deletions packages/layout/src/steps/resolveYoga.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { loadYoga } from '../yoga/index';

const resolveYoga = async (root) => {
const yoga = await loadYoga();
const resolveYoga = (root) => {
const yoga = loadYoga();

return Object.assign({}, root, { yoga });
};
Expand Down
9 changes: 4 additions & 5 deletions packages/layout/src/yoga/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-disable import/prefer-default-export */

import * as Yoga from 'yoga-layout';
import Yoga from 'yoga-layout';

export const loadYoga = async () => {
const instance = await Yoga.loadYoga();
const config = instance.Config.create();
export const loadYoga = () => {
const config = Yoga.Config.create();

config.setPointScaleFactor(0);

const node = { create: () => instance.Node.createWithConfig(config) };
const node = { create: () => Yoga.Node.createWithConfig(config) };

return { node };
};
10 changes: 5 additions & 5 deletions packages/layout/tests/steps/resolvePagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const calcLayout = (node) => resolvePagination(resolveDimensions(node));

describe('pagination step', () => {
test('should stretch absolute block to full page size', async () => {
const yoga = await loadYoga();
const yoga = loadYoga();

const root = {
type: 'DOCUMENT',
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('pagination step', () => {
});

test('should force new height for split nodes', async () => {
const yoga = await loadYoga();
const yoga = loadYoga();

const root = {
type: 'DOCUMENT',
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('pagination step', () => {
});

test('should force new height for split nodes with fixed height', async () => {
const yoga = await loadYoga();
const yoga = loadYoga();

const root = {
type: 'DOCUMENT',
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('pagination step', () => {
});

test('should not wrap page with false wrap prop', async () => {
const yoga = await loadYoga();
const yoga = loadYoga();

const root = {
type: 'DOCUMENT',
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('pagination step', () => {
});

test('should break on a container whose children can not fit on a page', async () => {
const yoga = await loadYoga();
const yoga = loadYoga();

const root = {
type: 'DOCUMENT',
Expand Down
10 changes: 5 additions & 5 deletions packages/layout/tests/steps/resolveTextLayout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { loadYoga } from '../../src/yoga';
import resolveTextLayout from '../../src/steps/resolveTextLayout';
import resolveDimensions from '../../src/steps/resolveDimensions';

const getRoot = async (text = 'hello world', styles = {}) => ({
const getRoot = (text = 'hello world', styles = {}) => ({
type: 'DOCUMENT',
yoga: await loadYoga(),
yoga: loadYoga(),
children: [
{
type: 'PAGE',
Expand Down Expand Up @@ -38,14 +38,14 @@ describe('text layout step', () => {
const getText = (root) => root.children[0].children[0];

test('should calculate lines for text while resolve dimensions', async () => {
const root = await getRoot('text text text');
const root = getRoot('text text text');
const dimensions = resolveDimensions(root);

expect(getText(dimensions).lines).toBeDefined();
});

test('should calculate lines for text width defined height', async () => {
const root = await getRoot('text text text', { height: 50 });
const root = getRoot('text text text', { height: 50 });
const dimensions = resolveDimensions(root);

expect(getText(dimensions).lines).not.toBeDefined();
Expand All @@ -56,7 +56,7 @@ describe('text layout step', () => {
});

test('should calculate lines for empty text', async () => {
const root = await getRoot('');
const root = getRoot('');
const dimensions = resolveDimensions(root);

expect(getText(dimensions).lines).toBeDefined();
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10027,7 +10027,7 @@ yocto-queue@^1.0.0:
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251"
integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==

yoga-layout@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/yoga-layout/-/yoga-layout-2.0.1.tgz#4bc686abe2464f977866650ddccc1dbcf9f0d03c"
integrity sha512-tT/oChyDXelLo2A+UVnlW9GU7CsvFMaEnd9kVFsaiCQonFAXd3xrHhkLYu+suwwosrAEQ746xBU+HvYtm1Zs2Q==
yoga-layout@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/yoga-layout/-/yoga-layout-3.0.3.tgz#0231bfbffe0b3aeb09fed53e02599d5c954d1946"
integrity sha512-7Y9/DP9BaEDKwrL2+rQPq5HFYSOdwED0hPceuXd1NIdnxQf6hnrYGMZBnUqG1CLXXL6njh/dEjsli574OmAcVw==