Summary: Fixes https://github.com/facebook/yoga/issues/1417 This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers. This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution. As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS). Pull Request resolved: https://github.com/facebook/yoga/pull/1433 Test Plan: 1. `yarn test` 2. `yarn lint` 3. `yarn tsc` 4. `yarn benchmark` 5. `yarn build` website-next 6. `yarn lint` website-next 7. Locally test website-next 8. Examine package artifact created by GitHub 9. All Automation passes Reviewed By: yungsters Differential Revision: D50453324 Pulled By: NickGerleman fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
125 lines
4.0 KiB
TypeScript
125 lines
4.0 KiB
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import Yoga from 'yoga-layout';
|
|
|
|
test('align_baseline_parent_using_child_in_column_as_reference', () => {
|
|
const config = Yoga.Config.create();
|
|
let root;
|
|
|
|
try {
|
|
root = Yoga.Node.create(config);
|
|
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
|
|
root.setWidth(1000);
|
|
root.setHeight(1000);
|
|
root.setAlignItems(Yoga.ALIGN_BASELINE);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
|
|
root_child0.setWidth(500);
|
|
root_child0.setHeight(600);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
|
|
root_child1.setWidth(500);
|
|
root_child1.setHeight(800);
|
|
root.insertChild(root_child1, 1);
|
|
|
|
const root_child1_child0 = Yoga.Node.create(config);
|
|
root_child1_child0.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
|
|
root_child1_child0.setWidth(500);
|
|
root_child1_child0.setHeight(300);
|
|
root_child1.insertChild(root_child1_child0, 0);
|
|
|
|
const root_child1_child1 = Yoga.Node.create(config);
|
|
root_child1_child1.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
|
|
root_child1_child1.setWidth(500);
|
|
root_child1_child1.setHeight(400);
|
|
root_child1_child1.setIsReferenceBaseline(true);
|
|
root_child1.insertChild(root_child1_child1, 1);
|
|
|
|
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(100);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(500);
|
|
expect(root_child1.getComputedTop()).toBe(0);
|
|
|
|
expect(root_child1_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child1_child0.getComputedTop()).toBe(0);
|
|
|
|
expect(root_child1_child1.getComputedLeft()).toBe(0);
|
|
expect(root_child1_child1.getComputedTop()).toBe(300);
|
|
} finally {
|
|
if (typeof root !== 'undefined') {
|
|
root.freeRecursive();
|
|
}
|
|
|
|
config.free();
|
|
}
|
|
});
|
|
|
|
test('align_baseline_parent_using_child_in_row_as_reference', () => {
|
|
const config = Yoga.Config.create();
|
|
let root;
|
|
|
|
try {
|
|
root = Yoga.Node.create(config);
|
|
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
|
|
root.setWidth(1000);
|
|
root.setHeight(1000);
|
|
root.setAlignItems(Yoga.ALIGN_BASELINE);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
|
|
root_child0.setWidth(500);
|
|
root_child0.setHeight(600);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
|
|
root_child1.setWidth(500);
|
|
root_child1.setHeight(800);
|
|
root.insertChild(root_child1, 1);
|
|
|
|
const root_child1_child0 = Yoga.Node.create(config);
|
|
root_child1_child0.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
|
|
root_child1_child0.setWidth(500);
|
|
root_child1_child0.setHeight(500);
|
|
root_child1.insertChild(root_child1_child0, 0);
|
|
|
|
const root_child1_child1 = Yoga.Node.create(config);
|
|
root_child1_child1.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
|
|
root_child1_child1.setWidth(500);
|
|
root_child1_child1.setHeight(400);
|
|
root_child1_child1.setIsReferenceBaseline(true);
|
|
root_child1.insertChild(root_child1_child1, 1);
|
|
|
|
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(500);
|
|
expect(root_child1.getComputedTop()).toBe(200);
|
|
|
|
expect(root_child1_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child1_child0.getComputedTop()).toBe(0);
|
|
|
|
expect(root_child1_child1.getComputedLeft()).toBe(500);
|
|
expect(root_child1_child1.getComputedTop()).toBe(0);
|
|
} finally {
|
|
if (typeof root !== 'undefined') {
|
|
root.freeRecursive();
|
|
}
|
|
|
|
config.free();
|
|
}
|
|
});
|