update JavaScript bindings

Summary:
- adds flow types
- transpiles bundle using babel
- cleans and formats code

Reviewed By: emilsjolander

Differential Revision: D6748362

fbshipit-source-id: fcb5fdde73df6e0062eff1e5038bb5fe0532f997
This commit is contained in:
Daniel Büchele
2018-01-18 07:55:50 -08:00
committed by Facebook Github Bot
parent 9ecdff14fa
commit a40ba9d350
9 changed files with 1218 additions and 1030 deletions

View File

@@ -1,5 +1,7 @@
{ {
"presets": ["stage-3", "es2015"],
"plugins": [ "plugins": [
"transform-flow-strip-types",
[ [
"replace-require", "replace-require",
{ {
@@ -8,4 +10,4 @@
} }
] ]
] ]
} }

11
javascript/.flowconfig Normal file
View File

@@ -0,0 +1,11 @@
[ignore]
[include]
[libs]
[lints]
[options]
[strict]

View File

@@ -1,65 +1,48 @@
{ {
"name": "yoga-layout", "name": "yoga-layout",
"version": "1.8.0", "version": "1.8.0",
"description": "Yoga is a cross-platform layout engine enabling maximum collaboration within your team by implementing an API many designers are familiar with, and opening it up to developers across different platforms.", "description": "Yoga is a cross-platform layout engine enabling maximum collaboration within your team by implementing an API many designers are familiar with, and opening it up to developers across different platforms.",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git@github.com:facebook/yoga.git" "url": "git@github.com:facebook/yoga.git"
}, },
"main": "./dist/entry-node",
"main": "./sources/entry-node", "browser": "./dist/entry-browser",
"browser": "./sources/entry-browser", "config": {
"platform": "all"
"config": { },
"platform": "all" "scripts": {
}, "which": "which",
"autogypi": "autogypi",
"scripts": { "node-gyp": "node-gyp",
"emcc-path": "emcc-path",
"which": "which", "is-monolithic": "test \"$(basename \"$(pwd)\")\" = javascript",
"autogypi": "autogypi", "copy-sources": "! npm -s -- run is-monolithic || (rsync -r --checksum --delete ../yoga/ sources/yoga/)",
"node-gyp": "node-gyp", "build:node": "npm -- run copy-sources && npm -- run node-gyp configure build && flow-copy-source sources dist",
"emcc-path": "emcc-path", "build:browser": "npm -- run copy-sources && npm -- run node-gyp configure build --asmjs=1 && babel sources --out-dir dist && flow-copy-source sources dist",
"build:all": "npm -- run build:node && npm -- run build:browser",
"is-monolithic": "test \"$(basename \"$(pwd)\")\" = javascript", "build": "cross-env \"npm --if-present -- run build:$npm_package_config_platform\"",
"copy-sources": "! npm -s -- run is-monolithic || (rsync -r --checksum --delete ../yoga/ sources/yoga/)", "test:node": "TEST_ENTRY=node time mocha --compilers js:babel-core/register --expose-gc -r tests/tools.js tests/Facebook.Yoga/**/*.js",
"test:browser": "TEST_ENTRY=browser time mocha --compilers js:babel-core/register --expose-gc -r tests/tools.js tests/Facebook.Yoga/**/*.js",
"build:node": "npm -- run copy-sources && npm -- run node-gyp configure build", "test": "npm -- run test:node && npm -- run test:browser",
"build:browser": "npm -- run copy-sources && npm -- run node-gyp configure build --asmjs=1", "bench": "node tests/run-bench $(find tests/Benchmarks -name '*.js')",
"postbuild:browser": "babel build/Release/nbind.js --out-file build/Release/nbind.js", "install": "npm -- run autogypi && npm -- run build:node"
"build:standalone": "webpack", },
"build:all": "npm -- run build:node && npm -- run build:browser && npm -- run build:standalone", "dependencies": {
"build": "cross-env \"npm --if-present -- run build:$npm_package_config_platform\"", "autogypi": "^0.2.2",
"nbind": "^0.3.8",
"test:node": "TEST_ENTRY=node time mocha --expose-gc -r tests/tools.js tests/Facebook.Yoga/**/*.js", "node-gyp": "^3.4.0"
"test:browser": "TEST_ENTRY=browser time mocha --expose-gc -r tests/tools.js tests/Facebook.Yoga/**/*.js", },
"test:all": "npm -- run test:node && npm -- run test:browser", "devDependencies": {
"test": "npm -- run test:all", "babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"bench": "node tests/run-bench $(find tests/Benchmarks -name '*.js')", "babel-plugin-replace-require": "^0.0.4",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"install": "npm -- run autogypi && npm -- run build:node", "babel-preset-es2015": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"prepare": "npm -- run build:browser" "cross-env": "^4.0.0",
"flow-copy-source": "^1.2.1",
}, "mocha": "^3.2.0"
}
"dependencies": {
"autogypi": "^0.2.2",
"nbind": "^0.3.8",
"node-gyp": "^3.4.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-plugin-replace-require": "^0.0.4",
"cross-env": "^4.0.0",
"mocha": "^3.2.0",
"webpack": "^2.2.0-rc.2"
}
} }

View File

@@ -5,10 +5,12 @@
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @format
*/ */
module.exports = { const CONSTANTS = {
ALIGN_COUNT: 8, ALIGN_COUNT: 8,
ALIGN_AUTO: 0, ALIGN_AUTO: 0,
ALIGN_FLEX_START: 1, ALIGN_FLEX_START: 1,
@@ -101,5 +103,73 @@ module.exports = {
WRAP_NO_WRAP: 0, WRAP_NO_WRAP: 0,
WRAP_WRAP: 1, WRAP_WRAP: 1,
WRAP_WRAP_REVERSE: 2, WRAP_WRAP_REVERSE: 2,
}; };
export type Yoga$JustifyContent =
| typeof CONSTANTS.JUSTIFY_CENTER
| typeof CONSTANTS.JUSTIFY_FLEX_END
| typeof CONSTANTS.JUSTIFY_FLEX_START
| typeof CONSTANTS.JUSTIFY_SPACE_AROUND
| typeof CONSTANTS.JUSTIFY_SPACE_BETWEEN
| typeof CONSTANTS.JUSTIFY_SPACE_EVENLY;
export type Yoga$Align =
| typeof CONSTANTS.ALIGN_AUTO
| typeof CONSTANTS.ALIGN_BASELINE
| typeof CONSTANTS.ALIGN_CENTER
| typeof CONSTANTS.ALIGN_FLEX_END
| typeof CONSTANTS.ALIGN_FLEX_START
| typeof CONSTANTS.ALIGN_SPACE_AROUND
| typeof CONSTANTS.ALIGN_SPACE_BETWEEN
| typeof CONSTANTS.ALIGN_STRETCH;
export type Yoga$FlexDirection =
| typeof CONSTANTS.FLEX_DIRECTION_COLUMN
| typeof CONSTANTS.FLEX_DIRECTION_COLUMN_REVERSE
| typeof CONSTANTS.FLEX_DIRECTION_COUNT
| typeof CONSTANTS.FLEX_DIRECTION_ROW
| typeof CONSTANTS.FLEX_DIRECTION_ROW_REVERSE;
export type Yoga$Direction =
| typeof CONSTANTS.DIRECTION_INHERIT
| typeof CONSTANTS.DIRECTION_LTR
| typeof CONSTANTS.DIRECTION_RTL;
export type Yoga$FlexWrap =
| typeof CONSTANTS.WRAP_NO_WRAP
| typeof CONSTANTS.WRAP_WRAP
| typeof CONSTANTS.WRAP_WRAP_REVERSE;
export type Yoga$Edge =
| typeof CONSTANTS.EDGE_LEFT
| typeof CONSTANTS.EDGE_TOP
| typeof CONSTANTS.EDGE_RIGHT
| typeof CONSTANTS.EDGE_BOTTOM
| typeof CONSTANTS.EDGE_START
| typeof CONSTANTS.EDGE_END
| typeof CONSTANTS.EDGE_HORIZONTAL
| typeof CONSTANTS.EDGE_VERTICAL
| typeof CONSTANTS.EDGE_ALL;
export type Yoga$Display =
| typeof CONSTANTS.DISPLAY_FLEX
| typeof CONSTANTS.DISPLAY_NONE;
export type Yoga$Unit =
| typeof CONSTANTS.UNIT_AUTO
| typeof CONSTANTS.UNIT_PERCENT
| typeof CONSTANTS.UNIT_POINT
| typeof CONSTANTS.UNIT_UNDEFINED;
export type Yoga$Overflow =
| typeof CONSTANTS.OVERFLOW_HIDDEN
| typeof CONSTANTS.OVERFLOW_SCROLL
| typeof CONSTANTS.OVERFLOW_VISIBLE;
export type Yoga$PositionType =
| typeof CONSTANTS.POSITION_TYPE_ABSOLUTE
| typeof CONSTANTS.POSITION_TYPE_RELATIVE;
export type Yoga$ExperimentalFeature = typeof CONSTANTS.EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS;
export default CONSTANTS;

View File

@@ -5,28 +5,51 @@
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @format
*/ */
var nbind = require('../build/Release/nbind.js'); import Yoga from './entry-common';
var ran = false; const nbind = require('../build/Release/nbind.js');
var ret = null;
nbind({}, function (err, result) { let ran = false;
let ret = null;
if (ran) nbind({}, function(err, result) {
return; if (ran) {
return;
}
ran = true; ran = true;
if (err) if (err) {
throw err; throw err;
}
ret = result;
ret = result;
}); });
if (!ran) if (!ran) {
throw new Error('Failed to load the yoga module - it needed to be loaded synchronously, but didn\'t'); throw new Error(
"Failed to load the yoga module - it needed to be loaded synchronously, but didn't",
);
}
module.exports = require('./entry-common')(ret.bind, ret.lib); // $FlowFixMe ret will not be null here
module.exports = Yoga(ret.bind, ret.lib);
export type {
Yoga$JustifyContent,
Yoga$Align,
Yoga$FlexDirection,
Yoga$Direction,
Yoga$FlexWrap,
Yoga$Edge,
Yoga$Display,
Yoga$Unit,
Yoga$Overflow,
Yoga$PositionType,
Yoga$ExperimentalFeature,
} from './YGEnums.js';

View File

@@ -5,245 +5,352 @@
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @format
*/ */
function patch(prototype, name, fn) { import CONSTANTS from './YGEnums';
import type {
Yoga$Edge,
Yoga$FlexWrap,
Yoga$Align,
Yoga$FlexDirection,
Yoga$Direction,
Yoga$PositionType,
Yoga$Overflow,
Yoga$JustifyContent,
Yoga$Display,
Yoga$ExperimentalFeature,
} from './YGEnums';
let original = prototype[name]; class Layout {
left: number;
right: number;
top: number;
bottom: number;
width: number;
height: number;
prototype[name] = function (... args) { constructor(left, right, top, bottom, width, height) {
return fn.call(this, original, ... args); this.left = left;
}; this.right = right;
this.top = top;
this.bottom = bottom;
this.width = width;
this.height = height;
}
fromJS(expose) {
expose(
this.left,
this.right,
this.top,
this.bottom,
this.width,
this.height,
);
}
toString() {
return `<Layout#${this.left}:${this.right};${this.top}:${this.bottom};${
this.width
}:${this.height}>`;
}
} }
module.exports = function (bind, lib) { class Size {
static fromJS({width, height}) {
return new Size(width, height);
}
let constants = Object.assign({ width: number;
height: number;
UNDEFINED: NaN constructor(width, height) {
this.width = width;
this.height = height;
}
}, require('./YGEnums')); fromJS(expose) {
expose(this.width, this.height);
}
class Layout { toString() {
return `<Size#${this.width}x${this.height}>`;
}
}
constructor(left, right, top, bottom, width, height) { class Value {
unit: number;
value: number;
this.left = left; constructor(unit, value) {
this.right = right; this.unit = unit;
this.value = value;
}
this.top = top; fromJS(expose) {
this.bottom = bottom; expose(this.unit, this.value);
}
this.width = width;
this.height = height;
}
fromJS(expose) {
expose(this.left, this.right, this.top, this.bottom, this.width, this.height);
}
toString() {
return `<Layout#${this.left}:${this.right};${this.top}:${this.bottom};${this.width}:${this.height}>`;
}
toString() {
switch (this.unit) {
case CONSTANTS.UNIT_POINT:
return String(this.value);
case CONSTANTS.UNIT_PERCENT:
return `${this.value}%`;
case CONSTANTS.UNIT_AUTO:
return 'auto';
default: {
return `${this.value}?`;
}
} }
}
class Size {
valueOf() {
static fromJS({ width, height }) { return this.value;
}
return new Size(width, height); }
} declare class Yoga$Config {
isExperimentalFeatureEnabled(feature: Yoga$ExperimentalFeature): boolean;
constructor(width, height) { setExperimentalFeatureEnabled(
feature: Yoga$ExperimentalFeature,
this.width = width; enabled: boolean,
this.height = height; ): void;
setPointScaleFactor(factor: number): void;
} }
declare class Yoga$Node {
fromJS(expose) { calculateLayout(
width?: number,
expose(this.width, this.height); height?: number,
direction?: Yoga$Direction,
} ): void;
copyStyle(node: Yoga$Node): void;
toString() { free(): void;
freeRecursive(): void;
return `<Size#${this.width}x${this.height}>`; getAlignContent(): Yoga$Align;
getAlignItems(): Yoga$Align;
} getAlignSelf(): Yoga$Align;
getAspectRatio(): number;
} getBorder(edge: Yoga$Edge): number;
getChild(index: number): Yoga$Node;
class Value { getChildCount(): number;
getComputedBorder(edge: Yoga$Edge): number;
constructor(unit, value) { getComputedBottom(): number;
getComputedHeight(): number;
this.unit = unit; getComputedLayout(): Layout;
this.value = value; getComputedLeft(): number;
getComputedMargin(edge: Yoga$Edge): number;
} getComputedPadding(edge: Yoga$Edge): number;
getComputedRight(): number;
fromJS(expose) { getComputedTop(): number;
getComputedWidth(): number;
expose(this.unit, this.value); getDisplay(): Yoga$Display;
getFlexBasis(): number;
} getFlexDirection(): Yoga$FlexDirection;
getFlexGrow(): number;
toString() { getFlexShrink(): number;
getFlexWrap(): Yoga$FlexWrap;
switch (this.unit) { getHeight(): Value;
getJustifyContent(): Yoga$JustifyContent;
case constants.UNIT_POINT: getMargin(edge: Yoga$Edge): Value;
return `${this.value}`; getMaxHeight(): Value;
getMaxWidth(): Value;
case constants.UNIT_PERCENT: getMinHeight(): Value;
return `${this.value}%`; getMinWidth(): Value;
getOverflow(): Yoga$Overflow;
case constants.UNIT_AUTO: getPadding(edge: Yoga$Edge): Value;
return `auto`; getParent(): ?Yoga$Node;
getPosition(edge: Yoga$Edge): Value;
default: { getPositionType(): Yoga$PositionType;
return `${this.value}?`; getWidth(): Value;
} insertChild(child: Yoga$Node, index: number): void;
isDirty(): boolean;
} markDirty(): void;
removeChild(child: Yoga$Node): void;
} reset(): void;
setAlignContent(alignContent: Yoga$Align): void;
valueOf() { setAlignItems(alignItems: Yoga$Align): void;
setAlignSelf(alignSelf: Yoga$Align): void;
return this.value; setAspectRatio(aspectRatio: number): void;
setBorder(edge: Yoga$Edge, borderWidth: number): void;
} setDisplay(display: Yoga$Display): void;
setFlex(flex: number): void;
} setFlexBasis(flexBasis: number | string): void;
setFlexBasisPercent(flexBasis: number): void;
for (let fnName of [ `setPosition`, `setMargin`, `setFlexBasis`, `setWidth`, `setHeight`, `setMinWidth`, `setMinHeight`, `setMaxWidth`, `setMaxHeight`, `setPadding` ]) { setFlexDirection(flexDirection: Yoga$FlexDirection): void;
setFlexGrow(flexGrow: number): void;
let methods = { [constants.UNIT_POINT]: lib.Node.prototype[fnName], [constants.UNIT_PERCENT]: lib.Node.prototype[`${fnName}Percent`], [constants.UNIT_AUTO]: lib.Node.prototype[`${fnName}Auto`] }; setFlexShrink(flexShrink: number): void;
setFlexWrap(flexWrap: Yoga$FlexWrap): void;
patch(lib.Node.prototype, fnName, function (original, ... args) { setHeight(height: number | string): void;
setHeightAuto(): void;
// We patch all these functions to add support for the following calls: setHeightPercent(height: number): void;
// .setWidth(100) / .setWidth("100%") / .setWidth(.getWidth()) / .setWidth("auto") setJustifyContent(justifyContent: Yoga$JustifyContent): void;
setMargin(edge: Yoga$Edge, margin: number): void;
let value = args.pop(); setMarginAuto(edge: Yoga$Edge): void;
let unit, asNumber; setMarginPercent(edge: Yoga$Edge, margin: number): void;
setMaxHeight(maxHeight: number | string): void;
if (value === `auto`) { setMaxHeightPercent(maxHeight: number): void;
setMaxWidth(maxWidth: number | string): void;
unit = constants.UNIT_AUTO; setMaxWidthPercent(maxWidth: number): void;
asNumber = undefined; setMeasureFunc(measureFunc: ?Function): void;
setMinHeight(minHeight: number | string): void;
} else if (value instanceof Value) { setMinHeightPercent(minHeight: number): void;
setMinWidth(minWidth: number | string): void;
unit = value.unit; setMinWidthPercent(minWidth: number): void;
asNumber = value.valueOf(); setOverflow(overflow: Yoga$Overflow): void;
setPadding(edge: Yoga$Edge, padding: number | string): void;
} else { setPaddingPercent(edge: Yoga$Edge, padding: number): void;
setPosition(edge: Yoga$Edge, position: number | string): void;
unit = typeof value === `string` && value.endsWith(`%`) ? constants.UNIT_PERCENT : constants.UNIT_POINT; setPositionPercent(edge: Yoga$Edge, position: number): void;
asNumber = parseFloat(value); setPositionType(positionType: Yoga$PositionType): void;
setWidth(width: number | string): void;
} setWidthAuto(): void;
setWidthPercent(width: number): void;
if (!methods[unit]) unsetMeasureFun(): void;
throw new Error(`Failed to execute "${fnName}": Unsupported unit '${value}'`); }
if (asNumber !== undefined) { type Yoga = {
return methods[unit].call(this, ... args, asNumber); Config: {
} else { create(): Yoga$Config,
return methods[unit].call(this, ... args); destroy(config: Yoga$Config): any,
} },
Node: {
}); create(): Yoga$Node,
createDefault(): Yoga$Node,
} createWithConfig(config: Yoga$Config): Yoga$Node,
destroy(node: Yoga$Node): any,
patch(lib.Config.prototype, `free`, function () { },
Layout: Layout,
// Since we handle the memory allocation ourselves (via lib.Config.create), we also need to handle the deallocation Size: Size,
Value: Value,
lib.Config.destroy(this); getInstanceCount(): number,
...typeof CONSTANTS,
}); };
patch(lib.Node, `create`, function (_, config) { export default (bind: any, lib: any): Yoga => {
function patch(prototype, name, fn) {
// We decide the constructor we want to call depending on the parameters let original = prototype[name];
return config ? lib.Node.createWithConfig(config) : lib.Node.createDefault(); prototype[name] = function(...args) {
return fn.call(this, original, ...args);
}); };
}
patch(lib.Node.prototype, `free`, function () {
for (let fnName of [
// Since we handle the memory allocation ourselves (via lib.Node.create), we also need to handle the deallocation 'setPosition',
'setMargin',
lib.Node.destroy(this); 'setFlexBasis',
'setWidth',
}); 'setHeight',
'setMinWidth',
patch(lib.Node.prototype, `freeRecursive`, function () { 'setMinHeight',
'setMaxWidth',
for (let t = 0, T = this.getChildCount(); t < T; ++t) 'setMaxHeight',
this.getChild(0).freeRecursive(); 'setPadding',
]) {
this.free(); let methods = {
[CONSTANTS.UNIT_POINT]: lib.Node.prototype[fnName],
}); [CONSTANTS.UNIT_PERCENT]: lib.Node.prototype[`${fnName}Percent`],
[CONSTANTS.UNIT_AUTO]: lib.Node.prototype[`${fnName}Auto`],
patch(lib.Node.prototype, `setMeasureFunc`, function (original, measureFunc) { };
// This patch is just a convenience patch, since it helps write more idiomatic source code (such as .setMeasureFunc(null)) patch(lib.Node.prototype, fnName, function(original, ...args) {
// We also automatically convert the return value of the measureFunc to a Size object, so that we can return anything that has .width and .height properties // We patch all these functions to add support for the following calls:
// .setWidth(100) / .setWidth("100%") / .setWidth(.getWidth()) / .setWidth("auto")
if (measureFunc) {
return original.call(this, (... args) => Size.fromJS(measureFunc(... args))); let value = args.pop();
} else { let unit, asNumber;
return this.unsetMeasureFunc();
} if (value === 'auto') {
unit = CONSTANTS.UNIT_AUTO;
}); asNumber = undefined;
} else if (value instanceof Value) {
patch(lib.Node.prototype, `calculateLayout`, function (original, width = constants.UNDEFINED, height = constants.UNDEFINED, direction = constants.DIRECTION_LTR) { unit = value.unit;
asNumber = value.valueOf();
// Just a small patch to add support for the function default parameters } else {
unit =
return original.call(this, width, height, direction); typeof value === 'string' && value.endsWith('%')
? CONSTANTS.UNIT_PERCENT
}); : CONSTANTS.UNIT_POINT;
asNumber = parseFloat(value);
function getInstanceCount(... args) { }
return lib.getInstanceCount(... args); if (!methods[unit])
throw new Error(
} `Failed to execute "${fnName}": Unsupported unit '${value}'`,
);
bind(`Layout`, Layout);
bind(`Size`, Size); if (asNumber !== undefined) {
bind(`Value`, Value); return methods[unit].call(this, ...args, asNumber);
} else {
return Object.assign({ return methods[unit].call(this, ...args);
}
Config: lib.Config, });
Node: lib.Node, }
Layout, patch(lib.Config.prototype, 'free', function() {
Size, // Since we handle the memory allocation ourselves (via lib.Config.create),
Value, // we also need to handle the deallocation
lib.Config.destroy(this);
getInstanceCount });
}, constants); patch(lib.Node, 'create', function(_, config) {
// We decide the constructor we want to call depending on the parameters
return config
? lib.Node.createWithConfig(config)
: lib.Node.createDefault();
});
patch(lib.Node.prototype, 'free', function() {
// Since we handle the memory allocation ourselves (via lib.Node.create),
// we also need to handle the deallocation
lib.Node.destroy(this);
});
patch(lib.Node.prototype, 'freeRecursive', function() {
for (let t = 0, T = this.getChildCount(); t < T; ++t) {
this.getChild(0).freeRecursive();
}
this.free();
});
patch(lib.Node.prototype, 'setMeasureFunc', function(original, measureFunc) {
// This patch is just a convenience patch, since it helps write more
// idiomatic source code (such as .setMeasureFunc(null))
// We also automatically convert the return value of the measureFunc
// to a Size object, so that we can return anything that has .width and
// .height properties
if (measureFunc) {
return original.call(this, (...args) =>
Size.fromJS(measureFunc(...args)),
);
} else {
return this.unsetMeasureFunc();
}
});
patch(lib.Node.prototype, 'calculateLayout', function(
original,
width = NaN,
height = NaN,
direction = CONSTANTS.DIRECTION_LTR,
) {
// Just a small patch to add support for the function default parameters
return original.call(this, width, height, direction);
});
return {
Config: lib.Config,
Node: lib.Node,
Layout: bind('Layout', Layout),
Size: bind('Size', Size),
Value: bind('Value', Value),
getInstanceCount(...args) {
return lib.getInstanceCount(...args);
},
...CONSTANTS,
};
}; };

View File

@@ -5,9 +5,25 @@
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @format
*/ */
var nbind = require('nbind'); import Yoga from './entry-common';
var ret = nbind.init(__dirname + '/../'); const nbind = require('nbind');
const {bind, lib} = nbind.init(__dirname + '/../');
module.exports = require('./entry-common')(ret.bind, ret.lib); module.exports = Yoga(bind, lib);
export type {
Yoga$JustifyContent,
Yoga$Align,
Yoga$FlexDirection,
Yoga$Direction,
Yoga$FlexWrap,
Yoga$Edge,
Yoga$Display,
Yoga$Unit,
Yoga$Overflow,
Yoga$PositionType,
Yoga$ExperimentalFeature,
} from './YGEnums.js';

View File

@@ -1,43 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
module.exports = {
entry: "./sources/entry-browser",
output: {
path: require("path").resolve(__dirname, "dist"),
filename: "Yoga.bundle.js",
libraryTarget: "umd",
library: "Yoga"
},
node: {
fs: "empty",
module: "empty"
},
performance: {
hints: false
},
plugins: [
new (require("webpack").BannerPlugin)(require("fs").readFileSync(__dirname + "/../LICENSE", "utf8"))
]
};

File diff suppressed because it is too large Load Diff