Skip to content

Commit

Permalink
Move Yoga hack to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jan 18, 2024
1 parent 6d72e26 commit 75410c3
Show file tree
Hide file tree
Showing 36 changed files with 42 additions and 180 deletions.
6 changes: 1 addition & 5 deletions packages/layout/src/image/measureImage.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import getRatio from './getRatio';
import getMargin from '../node/getMargin';
import getPadding from '../node/getPadding';
import isHeightAuto from '../page/isHeightAuto';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

const SAFETY_HEIGHT = 10;

/**
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/node/getBorderWidth.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import yogaModule from 'yoga-layout/sync';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

const getComputedBorder = (yogaNode, edge) =>
yogaNode ? yogaNode.getComputedBorder(edge) : 0;
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/node/getMargin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import yogaModule from 'yoga-layout/sync';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

const getComputedMargin = (node, edge) => {
const { yogaNode } = node;
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/node/getPadding.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import yogaModule from 'yoga-layout/sync';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

const getComputedPadding = (node, edge) => {
const { yogaNode } = node;
Expand Down
7 changes: 1 addition & 6 deletions packages/layout/src/node/setAlign.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import yogaModule from 'yoga-layout/sync';

import { upperFirst } from '@react-pdf/fns';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

const ALIGN = {
'flex-start': Yoga.ALIGN_FLEX_START,
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/node/setBorderWidth.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setYogaValue from './setYogaValue';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

/**
* Set border top attribute to node's Yoga instance
*
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/node/setDisplay.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import yogaModule from 'yoga-layout/sync';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

/**
* Set display attribute to node's Yoga instance
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/node/setFlexDirection.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import yogaModule from 'yoga-layout/sync';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

const FLEX_DIRECTIONS = {
row: Yoga.FLEX_DIRECTION_ROW,
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/node/setFlexWrap.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import yogaModule from 'yoga-layout/sync';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

const FLEX_WRAP = {
wrap: Yoga.WRAP_WRAP,
Expand Down
7 changes: 1 addition & 6 deletions packages/layout/src/node/setGap.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import yogaModule from 'yoga-layout/sync';

import { isNil, matchPercent } from '@react-pdf/fns';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

const checkPercents = (attr, value) => {
const percent = matchPercent(value);
Expand Down
7 changes: 1 addition & 6 deletions packages/layout/src/node/setJustifyContent.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import yogaModule from 'yoga-layout/sync';

import { isNil } from '@react-pdf/fns';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

const JUSTIFY_CONTENT = {
center: Yoga.JUSTIFY_CENTER,
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/node/setMargin.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setYogaValue from './setYogaValue';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

/**
* Set margin top attribute to node's Yoga instance
*
Expand Down
7 changes: 1 addition & 6 deletions packages/layout/src/node/setOverflow.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import yogaModule from 'yoga-layout/sync';

import { isNil } from '@react-pdf/fns';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

const OVERFLOW = {
hidden: Yoga.OVERFLOW_HIDDEN,
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/node/setPadding.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setYogaValue from './setYogaValue';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

/**
* Set padding top attribute to node's Yoga instance
*
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/node/setPosition.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setYogaValue from './setYogaValue';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

/**
* Set position top attribute to node's Yoga instance
*
Expand Down
7 changes: 1 addition & 6 deletions packages/layout/src/node/setPositionType.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import yogaModule from 'yoga-layout/sync';

import { isNil } from '@react-pdf/fns';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

/**
* Set position type attribute to node's Yoga instance
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/steps/resolveDimensions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import yogaModule from 'yoga-layout/sync';
import * as P from '@react-pdf/primitives';
import { isNil, compose } from '@react-pdf/fns';
import Yoga from '../../yoga';

import getMargin from '../node/getMargin';
import getPadding from '../node/getPadding';
Expand Down Expand Up @@ -58,10 +58,6 @@ import measureText from '../text/measureText';
import measureImage from '../image/measureImage';
import measureCanvas from '../canvas/measureCanvas';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

const YOGA_CONFIG = Yoga.Config.create();

YOGA_CONFIG.setPointScaleFactor(0);
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/svg/measureSvg.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import yogaModule from 'yoga-layout/sync';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;
import Yoga from '../../yoga';

const getAspectRatio = viewbox => {
if (!viewbox) return null;
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/src/text/measureText.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/* eslint-disable no-param-reassign */

import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import layoutText from './layoutText';
import linesWidth from './linesWidth';
import linesHeight from './linesHeight';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

const ALIGNMENT_FACTORS = { center: 0.5, right: 1 };

/**
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/tests/node/getBorderWidth.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import getBorderWidth from '../../src/node/getBorderWidth';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

const getComputedBorder = value => {
if (value === Yoga.EDGE_TOP) return 1;
if (value === Yoga.EDGE_RIGHT) return 2;
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/tests/node/getMargin.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import getMargin from '../../src/node/getMargin';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

const getComputedMargin = value => {
if (value === Yoga.EDGE_TOP) return 1;
if (value === Yoga.EDGE_RIGHT) return 2;
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/tests/node/getPadding.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import getPadding from '../../src/node/getPadding';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

const getComputedPadding = value => {
if (value === Yoga.EDGE_TOP) return 1;
if (value === Yoga.EDGE_RIGHT) return 2;
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/tests/node/setAlignContent.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { jest } from '@jest/globals';
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setAlignContent from '../../src/node/setAlignContent';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

describe('node setAlignContent', () => {
const mock = jest.fn();
const node = { yogaNode: { setAlignContent: mock } };
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/tests/node/setAlignItems.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { jest } from '@jest/globals';
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setAlignItems from '../../src/node/setAlignItems';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

describe('node setAlignItems', () => {
const mock = jest.fn();
const node = { yogaNode: { setAlignItems: mock } };
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/tests/node/setAlignSelf.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { jest } from '@jest/globals';
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setAlignSelf from '../../src/node/setAlignSelf';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

describe('node setAlignSelf', () => {
const mock = jest.fn();
const node = { yogaNode: { setAlignSelf: mock } };
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/tests/node/setBorderWidth.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jest } from '@jest/globals';
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setBorder, {
setBorderTop,
Expand All @@ -8,10 +8,6 @@ import setBorder, {
setBorderLeft,
} from '../../src/node/setBorderWidth';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

describe('node setBorderWidth', () => {
const mock = jest.fn();
const node = { yogaNode: { setBorder: mock } };
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/tests/node/setDisplay.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { jest } from '@jest/globals';
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setDisplay from '../../src/node/setDisplay';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

describe('node setDisplay', () => {
const mock = jest.fn();
const node = { yogaNode: { setDisplay: mock } };
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/tests/node/setFlexDirection.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { jest } from '@jest/globals';
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setFlexDirection from '../../src/node/setFlexDirection';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

describe('node setFlexDirection', () => {
const mock = jest.fn();
const node = { yogaNode: { setFlexDirection: mock } };
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/tests/node/setFlexWrap.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { jest } from '@jest/globals';
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setFlexWrap from '../../src/node/setFlexWrap';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

describe('node setFlexWrap', () => {
const mock = jest.fn();
const node = { yogaNode: { setFlexWrap: mock } };
Expand Down
6 changes: 1 addition & 5 deletions packages/layout/tests/node/setJustifyContent.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { jest } from '@jest/globals';
import yogaModule from 'yoga-layout/sync';
import Yoga from '../../yoga';

import setJustifyContent from '../../src/node/setJustifyContent';

// yoga-layout sets default export using non-standard __esModule property, so we need to
// make an additional check in case it's used in a bundler that does not support it.
const Yoga = 'default' in yogaModule ? yogaModule.default : yogaModule;

describe('node setJustifyContent', () => {
const mock = jest.fn();
const node = { yogaNode: { setJustifyContent: mock } };
Expand Down
Loading

0 comments on commit 75410c3

Please sign in to comment.