In-place JS environment
Summary: This change restructures the package to try to remove the JS build step from the inner loop. Instead, we have a single `src` directory that we babel transform when using, then apply the same transform inline during prepublish. At the end, we will be publishing a source directory with Babel transformed TS, JS, and TS declarations. We do a little spring cleaning when doing this. Fixing up some of the folder/file conventions, and removing the non-export-map fallbacks. We cannot remove the need for a native build. Reviewed By: yungsters Differential Revision: D45682153 fbshipit-source-id: ea2dd75c2dd6e3529b1ef6cf6ac6a64a270049a4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0a6a581936
commit
aa812d0e48
68
javascript/src/Config.cpp
Normal file
68
javascript/src/Config.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include "./Config.h"
|
||||
|
||||
/* static */ Config* Config::create(void) {
|
||||
return new Config();
|
||||
}
|
||||
|
||||
/* static */ void Config::destroy(Config* node) {
|
||||
delete node;
|
||||
}
|
||||
|
||||
Config::Config(void) : m_config(YGConfigNew()) {}
|
||||
|
||||
Config::~Config(void) {
|
||||
YGConfigFree(m_config);
|
||||
}
|
||||
|
||||
void Config::setExperimentalFeatureEnabled(int feature, bool enabled) {
|
||||
YGConfigSetExperimentalFeatureEnabled(
|
||||
m_config, static_cast<YGExperimentalFeature>(feature), enabled);
|
||||
}
|
||||
|
||||
void Config::setPointScaleFactor(float pixelsInPoint) {
|
||||
YGConfigSetPointScaleFactor(m_config, pixelsInPoint);
|
||||
}
|
||||
|
||||
void Config::setUseLegacyStretchBehaviour(bool useLegacyStretchBehaviour) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated"
|
||||
YGConfigSetUseLegacyStretchBehaviour(m_config, useLegacyStretchBehaviour);
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
void Config::setErrata(int errata) {
|
||||
YGConfigSetErrata(m_config, static_cast<YGErrata>(errata));
|
||||
}
|
||||
|
||||
void Config::setUseWebDefaults(bool useWebDefaults) {
|
||||
YGConfigSetUseWebDefaults(m_config, useWebDefaults);
|
||||
}
|
||||
|
||||
bool Config::isExperimentalFeatureEnabled(int feature) const {
|
||||
return YGConfigIsExperimentalFeatureEnabled(
|
||||
m_config, static_cast<YGExperimentalFeature>(feature));
|
||||
}
|
||||
|
||||
bool Config::useLegacyStretchBehaviour() const {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated"
|
||||
return YGConfigGetUseLegacyStretchBehaviour(m_config);
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
int Config::getErrata() const {
|
||||
return static_cast<int>(YGConfigGetErrata(m_config));
|
||||
}
|
||||
|
||||
bool Config::useWebDefaults() const {
|
||||
return YGConfigGetUseWebDefaults(m_config);
|
||||
}
|
47
javascript/src/Config.h
Normal file
47
javascript/src/Config.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
class Config {
|
||||
|
||||
friend class Node;
|
||||
|
||||
public:
|
||||
static Config* create(void);
|
||||
|
||||
static void destroy(Config* config);
|
||||
|
||||
private:
|
||||
Config(void);
|
||||
|
||||
public:
|
||||
~Config(void);
|
||||
|
||||
public: // Prevent accidental copy
|
||||
Config(Config const&) = delete;
|
||||
|
||||
Config const& operator=(Config const&) = delete;
|
||||
|
||||
public: // Setters
|
||||
void setExperimentalFeatureEnabled(int feature, bool enabled);
|
||||
void setPointScaleFactor(float pixelsInPoint);
|
||||
void setUseLegacyStretchBehaviour(bool useLegacyStretchBehaviour);
|
||||
void setErrata(int errata);
|
||||
void setUseWebDefaults(bool useWebDefaults);
|
||||
|
||||
public: // Getters
|
||||
bool isExperimentalFeatureEnabled(int feature) const;
|
||||
bool useLegacyStretchBehaviour() const;
|
||||
int getErrata() const;
|
||||
bool useWebDefaults() const;
|
||||
|
||||
private:
|
||||
YGConfigRef m_config;
|
||||
};
|
19
javascript/src/Layout.h
Normal file
19
javascript/src/Layout.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
struct Layout {
|
||||
double left;
|
||||
double right;
|
||||
|
||||
double top;
|
||||
double bottom;
|
||||
|
||||
double width;
|
||||
double height;
|
||||
};
|
470
javascript/src/Node.cpp
Normal file
470
javascript/src/Node.cpp
Normal file
@@ -0,0 +1,470 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include "./Node.h"
|
||||
#include "./Layout.h"
|
||||
#include "./Size.h"
|
||||
#include "./Config.h"
|
||||
|
||||
static YGSize globalMeasureFunc(
|
||||
YGNodeRef nodeRef,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
Node const& node = *reinterpret_cast<Node const*>(YGNodeGetContext(nodeRef));
|
||||
|
||||
Size size = node.callMeasureFunc(width, widthMode, height, heightMode);
|
||||
YGSize ygSize = {
|
||||
static_cast<float>(size.width), static_cast<float>(size.height)};
|
||||
|
||||
return ygSize;
|
||||
}
|
||||
|
||||
static void globalDirtiedFunc(YGNodeRef nodeRef) {
|
||||
Node const& node = *reinterpret_cast<Node const*>(YGNodeGetContext(nodeRef));
|
||||
|
||||
node.callDirtiedFunc();
|
||||
}
|
||||
|
||||
/* static */ Node* Node::createDefault(void) {
|
||||
return new Node(nullptr);
|
||||
}
|
||||
|
||||
/* static */ Node* Node::createWithConfig(Config* config) {
|
||||
return new Node(config);
|
||||
}
|
||||
|
||||
/* static */ void Node::destroy(Node* node) {
|
||||
delete node;
|
||||
}
|
||||
|
||||
/* static */ Node* Node::fromYGNode(YGNodeRef nodeRef) {
|
||||
return reinterpret_cast<Node*>(YGNodeGetContext(nodeRef));
|
||||
}
|
||||
|
||||
Node::Node(Config* config)
|
||||
: m_node(
|
||||
config != nullptr ? YGNodeNewWithConfig(config->m_config)
|
||||
: YGNodeNew()),
|
||||
m_measureFunc(nullptr),
|
||||
m_dirtiedFunc(nullptr) {
|
||||
YGNodeSetContext(m_node, reinterpret_cast<void*>(this));
|
||||
}
|
||||
|
||||
Node::~Node(void) {
|
||||
YGNodeFree(m_node);
|
||||
}
|
||||
|
||||
void Node::reset(void) {
|
||||
m_measureFunc.reset(nullptr);
|
||||
m_dirtiedFunc.reset(nullptr);
|
||||
|
||||
YGNodeReset(m_node);
|
||||
}
|
||||
|
||||
void Node::copyStyle(Node const& other) {
|
||||
YGNodeCopyStyle(m_node, other.m_node);
|
||||
}
|
||||
|
||||
void Node::setPositionType(int positionType) {
|
||||
YGNodeStyleSetPositionType(m_node, static_cast<YGPositionType>(positionType));
|
||||
}
|
||||
|
||||
void Node::setPosition(int edge, double position) {
|
||||
YGNodeStyleSetPosition(m_node, static_cast<YGEdge>(edge), position);
|
||||
}
|
||||
|
||||
void Node::setPositionPercent(int edge, double position) {
|
||||
YGNodeStyleSetPositionPercent(m_node, static_cast<YGEdge>(edge), position);
|
||||
}
|
||||
|
||||
void Node::setAlignContent(int alignContent) {
|
||||
YGNodeStyleSetAlignContent(m_node, static_cast<YGAlign>(alignContent));
|
||||
}
|
||||
|
||||
void Node::setAlignItems(int alignItems) {
|
||||
YGNodeStyleSetAlignItems(m_node, static_cast<YGAlign>(alignItems));
|
||||
}
|
||||
|
||||
void Node::setAlignSelf(int alignSelf) {
|
||||
YGNodeStyleSetAlignSelf(m_node, static_cast<YGAlign>(alignSelf));
|
||||
}
|
||||
|
||||
void Node::setFlexDirection(int flexDirection) {
|
||||
YGNodeStyleSetFlexDirection(
|
||||
m_node, static_cast<YGFlexDirection>(flexDirection));
|
||||
}
|
||||
|
||||
void Node::setFlexWrap(int flexWrap) {
|
||||
YGNodeStyleSetFlexWrap(m_node, static_cast<YGWrap>(flexWrap));
|
||||
}
|
||||
|
||||
void Node::setJustifyContent(int justifyContent) {
|
||||
YGNodeStyleSetJustifyContent(m_node, static_cast<YGJustify>(justifyContent));
|
||||
}
|
||||
|
||||
void Node::setMargin(int edge, double margin) {
|
||||
YGNodeStyleSetMargin(m_node, static_cast<YGEdge>(edge), margin);
|
||||
}
|
||||
|
||||
void Node::setMarginPercent(int edge, double margin) {
|
||||
YGNodeStyleSetMarginPercent(m_node, static_cast<YGEdge>(edge), margin);
|
||||
}
|
||||
|
||||
void Node::setMarginAuto(int edge) {
|
||||
YGNodeStyleSetMarginAuto(m_node, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
void Node::setOverflow(int overflow) {
|
||||
YGNodeStyleSetOverflow(m_node, static_cast<YGOverflow>(overflow));
|
||||
}
|
||||
|
||||
void Node::setDisplay(int display) {
|
||||
YGNodeStyleSetDisplay(m_node, static_cast<YGDisplay>(display));
|
||||
}
|
||||
|
||||
void Node::setFlex(double flex) {
|
||||
YGNodeStyleSetFlex(m_node, flex);
|
||||
}
|
||||
|
||||
void Node::setFlexBasis(double flexBasis) {
|
||||
YGNodeStyleSetFlexBasis(m_node, flexBasis);
|
||||
}
|
||||
|
||||
void Node::setFlexBasisPercent(double flexBasis) {
|
||||
YGNodeStyleSetFlexBasisPercent(m_node, flexBasis);
|
||||
}
|
||||
|
||||
void Node::setFlexBasisAuto() {
|
||||
YGNodeStyleSetFlexBasisAuto(m_node);
|
||||
}
|
||||
|
||||
void Node::setFlexGrow(double flexGrow) {
|
||||
YGNodeStyleSetFlexGrow(m_node, flexGrow);
|
||||
}
|
||||
|
||||
void Node::setFlexShrink(double flexShrink) {
|
||||
YGNodeStyleSetFlexShrink(m_node, flexShrink);
|
||||
}
|
||||
|
||||
void Node::setWidth(double width) {
|
||||
YGNodeStyleSetWidth(m_node, width);
|
||||
}
|
||||
|
||||
void Node::setWidthPercent(double width) {
|
||||
YGNodeStyleSetWidthPercent(m_node, width);
|
||||
}
|
||||
|
||||
void Node::setWidthAuto() {
|
||||
YGNodeStyleSetWidthAuto(m_node);
|
||||
}
|
||||
|
||||
void Node::setHeight(double height) {
|
||||
YGNodeStyleSetHeight(m_node, height);
|
||||
}
|
||||
|
||||
void Node::setHeightPercent(double height) {
|
||||
YGNodeStyleSetHeightPercent(m_node, height);
|
||||
}
|
||||
|
||||
void Node::setHeightAuto() {
|
||||
YGNodeStyleSetHeightAuto(m_node);
|
||||
}
|
||||
|
||||
void Node::setMinWidth(double minWidth) {
|
||||
YGNodeStyleSetMinWidth(m_node, minWidth);
|
||||
}
|
||||
|
||||
void Node::setMinWidthPercent(double minWidth) {
|
||||
YGNodeStyleSetMinWidthPercent(m_node, minWidth);
|
||||
}
|
||||
|
||||
void Node::setMinHeight(double minHeight) {
|
||||
YGNodeStyleSetMinHeight(m_node, minHeight);
|
||||
}
|
||||
|
||||
void Node::setMinHeightPercent(double minHeight) {
|
||||
YGNodeStyleSetMinHeightPercent(m_node, minHeight);
|
||||
}
|
||||
|
||||
void Node::setMaxWidth(double maxWidth) {
|
||||
YGNodeStyleSetMaxWidth(m_node, maxWidth);
|
||||
}
|
||||
|
||||
void Node::setMaxWidthPercent(double maxWidth) {
|
||||
YGNodeStyleSetMaxWidthPercent(m_node, maxWidth);
|
||||
}
|
||||
|
||||
void Node::setMaxHeight(double maxHeight) {
|
||||
YGNodeStyleSetMaxHeight(m_node, maxHeight);
|
||||
}
|
||||
|
||||
void Node::setMaxHeightPercent(double maxHeight) {
|
||||
YGNodeStyleSetMaxHeightPercent(m_node, maxHeight);
|
||||
}
|
||||
|
||||
void Node::setAspectRatio(double aspectRatio) {
|
||||
YGNodeStyleSetAspectRatio(m_node, aspectRatio);
|
||||
}
|
||||
|
||||
void Node::setBorder(int edge, double border) {
|
||||
YGNodeStyleSetBorder(m_node, static_cast<YGEdge>(edge), border);
|
||||
}
|
||||
|
||||
void Node::setPadding(int edge, double padding) {
|
||||
YGNodeStyleSetPadding(m_node, static_cast<YGEdge>(edge), padding);
|
||||
}
|
||||
|
||||
void Node::setPaddingPercent(int edge, double padding) {
|
||||
YGNodeStyleSetPaddingPercent(m_node, static_cast<YGEdge>(edge), padding);
|
||||
}
|
||||
|
||||
void Node::setIsReferenceBaseline(bool isReferenceBaseline) {
|
||||
YGNodeSetIsReferenceBaseline(m_node, isReferenceBaseline);
|
||||
}
|
||||
|
||||
void Node::setGap(int gutter, double gapLength) {
|
||||
YGNodeStyleSetGap(m_node, static_cast<YGGutter>(gutter), gapLength);
|
||||
}
|
||||
|
||||
int Node::getPositionType(void) const {
|
||||
return YGNodeStyleGetPositionType(m_node);
|
||||
}
|
||||
|
||||
Value Node::getPosition(int edge) const {
|
||||
return Value::fromYGValue(
|
||||
YGNodeStyleGetPosition(m_node, static_cast<YGEdge>(edge)));
|
||||
}
|
||||
|
||||
int Node::getAlignContent(void) const {
|
||||
return YGNodeStyleGetAlignContent(m_node);
|
||||
}
|
||||
|
||||
int Node::getAlignItems(void) const {
|
||||
return YGNodeStyleGetAlignItems(m_node);
|
||||
}
|
||||
|
||||
int Node::getAlignSelf(void) const {
|
||||
return YGNodeStyleGetAlignSelf(m_node);
|
||||
}
|
||||
|
||||
int Node::getFlexDirection(void) const {
|
||||
return YGNodeStyleGetFlexDirection(m_node);
|
||||
}
|
||||
|
||||
int Node::getFlexWrap(void) const {
|
||||
return YGNodeStyleGetFlexWrap(m_node);
|
||||
}
|
||||
|
||||
int Node::getJustifyContent(void) const {
|
||||
return YGNodeStyleGetJustifyContent(m_node);
|
||||
}
|
||||
|
||||
Value Node::getMargin(int edge) const {
|
||||
return Value::fromYGValue(
|
||||
YGNodeStyleGetMargin(m_node, static_cast<YGEdge>(edge)));
|
||||
}
|
||||
|
||||
int Node::getOverflow(void) const {
|
||||
return YGNodeStyleGetOverflow(m_node);
|
||||
}
|
||||
|
||||
int Node::getDisplay(void) const {
|
||||
return YGNodeStyleGetDisplay(m_node);
|
||||
}
|
||||
|
||||
Value Node::getFlexBasis(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetFlexBasis(m_node));
|
||||
}
|
||||
|
||||
double Node::getFlexGrow(void) const {
|
||||
return YGNodeStyleGetFlexGrow(m_node);
|
||||
}
|
||||
|
||||
double Node::getFlexShrink(void) const {
|
||||
return YGNodeStyleGetFlexShrink(m_node);
|
||||
}
|
||||
|
||||
Value Node::getWidth(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetWidth(m_node));
|
||||
}
|
||||
|
||||
Value Node::getHeight(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetHeight(m_node));
|
||||
}
|
||||
|
||||
Value Node::getMinWidth(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetMinWidth(m_node));
|
||||
}
|
||||
|
||||
Value Node::getMinHeight(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetMinHeight(m_node));
|
||||
}
|
||||
|
||||
Value Node::getMaxWidth(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetMaxWidth(m_node));
|
||||
}
|
||||
|
||||
Value Node::getMaxHeight(void) const {
|
||||
return Value::fromYGValue(YGNodeStyleGetMaxHeight(m_node));
|
||||
}
|
||||
|
||||
double Node::getAspectRatio(void) const {
|
||||
return YGNodeStyleGetAspectRatio(m_node);
|
||||
}
|
||||
|
||||
double Node::getBorder(int edge) const {
|
||||
return YGNodeStyleGetBorder(m_node, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
Value Node::getPadding(int edge) const {
|
||||
return Value::fromYGValue(
|
||||
YGNodeStyleGetPadding(m_node, static_cast<YGEdge>(edge)));
|
||||
}
|
||||
|
||||
float Node::getGap(int gutter) {
|
||||
return YGNodeStyleGetGap(m_node, static_cast<YGGutter>(gutter));
|
||||
}
|
||||
|
||||
bool Node::isReferenceBaseline() {
|
||||
return YGNodeIsReferenceBaseline(m_node);
|
||||
}
|
||||
|
||||
void Node::insertChild(Node* child, unsigned index) {
|
||||
YGNodeInsertChild(m_node, child->m_node, index);
|
||||
}
|
||||
|
||||
void Node::removeChild(Node* child) {
|
||||
YGNodeRemoveChild(m_node, child->m_node);
|
||||
}
|
||||
|
||||
unsigned Node::getChildCount(void) const {
|
||||
return YGNodeGetChildCount(m_node);
|
||||
}
|
||||
|
||||
Node* Node::getParent(void) {
|
||||
auto nodePtr = YGNodeGetParent(m_node);
|
||||
|
||||
if (nodePtr == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return Node::fromYGNode(nodePtr);
|
||||
}
|
||||
|
||||
Node* Node::getChild(unsigned index) {
|
||||
auto nodePtr = YGNodeGetChild(m_node, index);
|
||||
|
||||
if (nodePtr == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return Node::fromYGNode(nodePtr);
|
||||
}
|
||||
|
||||
void Node::setMeasureFunc(MeasureCallback* measureFunc) {
|
||||
m_measureFunc.reset(measureFunc);
|
||||
|
||||
YGNodeSetMeasureFunc(m_node, &globalMeasureFunc);
|
||||
}
|
||||
|
||||
void Node::unsetMeasureFunc(void) {
|
||||
m_measureFunc.reset(nullptr);
|
||||
|
||||
YGNodeSetMeasureFunc(m_node, nullptr);
|
||||
}
|
||||
|
||||
Size Node::callMeasureFunc(
|
||||
double width,
|
||||
int widthMode,
|
||||
double height,
|
||||
int heightMode) const {
|
||||
return m_measureFunc->measure(width, widthMode, height, heightMode);
|
||||
}
|
||||
|
||||
void Node::setDirtiedFunc(DirtiedCallback* dirtiedFunc) {
|
||||
m_dirtiedFunc.reset(dirtiedFunc);
|
||||
|
||||
YGNodeSetDirtiedFunc(m_node, &globalDirtiedFunc);
|
||||
}
|
||||
|
||||
void Node::unsetDirtiedFunc(void) {
|
||||
m_dirtiedFunc.reset(nullptr);
|
||||
|
||||
YGNodeSetDirtiedFunc(m_node, nullptr);
|
||||
}
|
||||
|
||||
void Node::callDirtiedFunc(void) const {
|
||||
m_dirtiedFunc->dirtied();
|
||||
}
|
||||
|
||||
void Node::markDirty(void) {
|
||||
YGNodeMarkDirty(m_node);
|
||||
}
|
||||
|
||||
bool Node::isDirty(void) const {
|
||||
return YGNodeIsDirty(m_node);
|
||||
}
|
||||
|
||||
void Node::calculateLayout(double width, double height, int direction) {
|
||||
YGNodeCalculateLayout(
|
||||
m_node, width, height, static_cast<YGDirection>(direction));
|
||||
}
|
||||
|
||||
double Node::getComputedLeft(void) const {
|
||||
return YGNodeLayoutGetLeft(m_node);
|
||||
}
|
||||
|
||||
double Node::getComputedRight(void) const {
|
||||
return YGNodeLayoutGetRight(m_node);
|
||||
}
|
||||
|
||||
double Node::getComputedTop(void) const {
|
||||
return YGNodeLayoutGetTop(m_node);
|
||||
}
|
||||
|
||||
double Node::getComputedBottom(void) const {
|
||||
return YGNodeLayoutGetBottom(m_node);
|
||||
}
|
||||
|
||||
double Node::getComputedWidth(void) const {
|
||||
return YGNodeLayoutGetWidth(m_node);
|
||||
}
|
||||
|
||||
double Node::getComputedHeight(void) const {
|
||||
return YGNodeLayoutGetHeight(m_node);
|
||||
}
|
||||
|
||||
Layout Node::getComputedLayout(void) const {
|
||||
Layout layout;
|
||||
|
||||
layout.left = YGNodeLayoutGetLeft(m_node);
|
||||
layout.right = YGNodeLayoutGetRight(m_node);
|
||||
|
||||
layout.top = YGNodeLayoutGetTop(m_node);
|
||||
layout.bottom = YGNodeLayoutGetBottom(m_node);
|
||||
|
||||
layout.width = YGNodeLayoutGetWidth(m_node);
|
||||
layout.height = YGNodeLayoutGetHeight(m_node);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
double Node::getComputedMargin(int edge) const {
|
||||
return YGNodeLayoutGetMargin(m_node, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
double Node::getComputedBorder(int edge) const {
|
||||
return YGNodeLayoutGetBorder(m_node, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
double Node::getComputedPadding(int edge) const {
|
||||
return YGNodeLayoutGetPadding(m_node, static_cast<YGEdge>(edge));
|
||||
}
|
228
javascript/src/Node.h
Normal file
228
javascript/src/Node.h
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <emscripten/bind.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include "./Layout.h"
|
||||
#include "./Size.h"
|
||||
#include "./Value.h"
|
||||
#include "./Config.h"
|
||||
|
||||
class MeasureCallback {
|
||||
public:
|
||||
virtual ~MeasureCallback() {}
|
||||
virtual Size measure(
|
||||
float width,
|
||||
int widthMode,
|
||||
float height,
|
||||
int heightMode) = 0;
|
||||
};
|
||||
|
||||
class MeasureCallbackWrapper : public emscripten::wrapper<MeasureCallback> {
|
||||
public:
|
||||
EMSCRIPTEN_WRAPPER(MeasureCallbackWrapper);
|
||||
Size measure(float width, int widthMode, float height, int heightMode) {
|
||||
return call<Size>("measure", width, widthMode, height, heightMode);
|
||||
}
|
||||
};
|
||||
|
||||
class DirtiedCallback {
|
||||
public:
|
||||
virtual ~DirtiedCallback() {}
|
||||
virtual void dirtied() = 0;
|
||||
};
|
||||
|
||||
class DirtiedCallbackWrapper : public emscripten::wrapper<DirtiedCallback> {
|
||||
public:
|
||||
EMSCRIPTEN_WRAPPER(DirtiedCallbackWrapper);
|
||||
void dirtied() { return call<void>("dirtied"); }
|
||||
};
|
||||
|
||||
class Node {
|
||||
|
||||
public:
|
||||
static Node* createDefault(void);
|
||||
static Node* createWithConfig(Config* config);
|
||||
|
||||
static void destroy(Node* node);
|
||||
|
||||
public:
|
||||
static Node* fromYGNode(YGNodeRef nodeRef);
|
||||
|
||||
private:
|
||||
Node(Config* config);
|
||||
|
||||
public:
|
||||
~Node(void);
|
||||
|
||||
public: // Prevent accidental copy
|
||||
Node(Node const&) = delete;
|
||||
|
||||
Node const& operator=(Node const&) = delete;
|
||||
|
||||
public:
|
||||
void reset(void);
|
||||
|
||||
public: // Style setters
|
||||
void copyStyle(Node const& other);
|
||||
|
||||
void setPositionType(int positionType);
|
||||
void setPosition(int edge, double position);
|
||||
void setPositionPercent(int edge, double position);
|
||||
|
||||
void setAlignContent(int alignContent);
|
||||
void setAlignItems(int alignItems);
|
||||
void setAlignSelf(int alignSelf);
|
||||
void setFlexDirection(int flexDirection);
|
||||
void setFlexWrap(int flexWrap);
|
||||
void setJustifyContent(int justifyContent);
|
||||
|
||||
void setMargin(int edge, double margin);
|
||||
void setMarginPercent(int edge, double margin);
|
||||
void setMarginAuto(int edge);
|
||||
|
||||
void setOverflow(int overflow);
|
||||
void setDisplay(int display);
|
||||
|
||||
void setFlex(double flex);
|
||||
void setFlexBasis(double flexBasis);
|
||||
void setFlexBasisPercent(double flexBasis);
|
||||
void setFlexBasisAuto();
|
||||
void setFlexGrow(double flexGrow);
|
||||
void setFlexShrink(double flexShrink);
|
||||
|
||||
void setWidth(double width);
|
||||
void setWidthPercent(double width);
|
||||
void setWidthAuto();
|
||||
void setHeight(double height);
|
||||
void setHeightPercent(double height);
|
||||
void setHeightAuto();
|
||||
|
||||
void setMinWidth(double minWidth);
|
||||
void setMinWidthPercent(double minWidth);
|
||||
void setMinHeight(double minHeight);
|
||||
void setMinHeightPercent(double minHeight);
|
||||
|
||||
void setMaxWidth(double maxWidth);
|
||||
void setMaxWidthPercent(double maxWidth);
|
||||
void setMaxHeight(double maxHeight);
|
||||
void setMaxHeightPercent(double maxHeight);
|
||||
|
||||
void setAspectRatio(double aspectRatio);
|
||||
|
||||
void setBorder(int edge, double border);
|
||||
|
||||
void setPadding(int edge, double padding);
|
||||
void setPaddingPercent(int edge, double padding);
|
||||
|
||||
void setGap(int gutter, double gapLength);
|
||||
|
||||
public: // Style getters
|
||||
int getPositionType(void) const;
|
||||
Value getPosition(int edge) const;
|
||||
|
||||
int getAlignContent(void) const;
|
||||
int getAlignItems(void) const;
|
||||
int getAlignSelf(void) const;
|
||||
int getFlexDirection(void) const;
|
||||
int getFlexWrap(void) const;
|
||||
int getJustifyContent(void) const;
|
||||
|
||||
Value getMargin(int edge) const;
|
||||
|
||||
int getOverflow(void) const;
|
||||
int getDisplay(void) const;
|
||||
|
||||
Value getFlexBasis(void) const;
|
||||
double getFlexGrow(void) const;
|
||||
double getFlexShrink(void) const;
|
||||
|
||||
Value getWidth(void) const;
|
||||
Value getHeight(void) const;
|
||||
|
||||
Value getMinWidth(void) const;
|
||||
Value getMinHeight(void) const;
|
||||
|
||||
Value getMaxWidth(void) const;
|
||||
Value getMaxHeight(void) const;
|
||||
|
||||
double getAspectRatio(void) const;
|
||||
|
||||
double getBorder(int edge) const;
|
||||
|
||||
Value getPadding(int edge) const;
|
||||
|
||||
float getGap(int gutter);
|
||||
|
||||
public: // Tree hierarchy mutators
|
||||
void insertChild(Node* child, unsigned index);
|
||||
void removeChild(Node* child);
|
||||
|
||||
public: // Tree hierarchy inspectors
|
||||
unsigned getChildCount(void) const;
|
||||
|
||||
// The following functions cannot be const because they could discard const
|
||||
// qualifiers (ex: constNode->getChild(0)->getParent() wouldn't be const)
|
||||
|
||||
Node* getParent(void);
|
||||
Node* getChild(unsigned index);
|
||||
|
||||
public: // Measure func mutators
|
||||
void setMeasureFunc(MeasureCallback* measureFunc);
|
||||
void unsetMeasureFunc(void);
|
||||
|
||||
public: // Measure func inspectors
|
||||
Size callMeasureFunc(
|
||||
double width,
|
||||
int widthMode,
|
||||
double height,
|
||||
int heightMode) const;
|
||||
|
||||
public: // Dirtied func mutators
|
||||
void setDirtiedFunc(DirtiedCallback* dirtiedFunc);
|
||||
void unsetDirtiedFunc(void);
|
||||
|
||||
public: // Dirtied func inspectors
|
||||
void callDirtiedFunc(void) const;
|
||||
|
||||
public: // Dirtiness accessors
|
||||
void markDirty(void);
|
||||
bool isDirty(void) const;
|
||||
|
||||
public: // Layout mutators
|
||||
void calculateLayout(double width, double height, int direction);
|
||||
|
||||
public: // Layout inspectors
|
||||
double getComputedLeft(void) const;
|
||||
double getComputedRight(void) const;
|
||||
|
||||
double getComputedTop(void) const;
|
||||
double getComputedBottom(void) const;
|
||||
|
||||
double getComputedWidth(void) const;
|
||||
double getComputedHeight(void) const;
|
||||
|
||||
Layout getComputedLayout(void) const;
|
||||
|
||||
double getComputedMargin(int edge) const;
|
||||
double getComputedBorder(int edge) const;
|
||||
double getComputedPadding(int edge) const;
|
||||
|
||||
public:
|
||||
void setIsReferenceBaseline(bool isReferenceBaseline);
|
||||
bool isReferenceBaseline();
|
||||
|
||||
YGNodeRef m_node;
|
||||
|
||||
std::unique_ptr<MeasureCallback> m_measureFunc;
|
||||
std::unique_ptr<DirtiedCallback> m_dirtiedFunc;
|
||||
};
|
17
javascript/src/Size.h
Normal file
17
javascript/src/Size.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
struct Size {
|
||||
double width;
|
||||
double height;
|
||||
|
||||
Size(void) : width(0.0), height(0.0) {}
|
||||
|
||||
Size(double width, double height) : width(width), height(height) {}
|
||||
};
|
23
javascript/src/Value.h
Normal file
23
javascript/src/Value.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
struct Value {
|
||||
static Value fromYGValue(YGValue const& ygValue) {
|
||||
return Value(static_cast<int>(ygValue.unit), ygValue.value);
|
||||
}
|
||||
|
||||
int unit;
|
||||
double value;
|
||||
|
||||
Value(void) : unit(YGUnitUndefined), value(0.0) {}
|
||||
|
||||
Value(int unit, double value) : unit(unit), value(value) {}
|
||||
};
|
194
javascript/src/embind.cpp
Normal file
194
javascript/src/embind.cpp
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "./Node.h"
|
||||
#include "./Layout.h"
|
||||
#include "./Size.h"
|
||||
#include "./Value.h"
|
||||
#include "./Config.h"
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
#include <emscripten/bind.h>
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
EMSCRIPTEN_BINDINGS(YOGA_LAYOUT) {
|
||||
class_<MeasureCallback>("MeasureCallback")
|
||||
.function("measure", &MeasureCallback::measure, pure_virtual())
|
||||
.allow_subclass<MeasureCallbackWrapper>("MeasureCallbackWrapper");
|
||||
class_<DirtiedCallback>("DirtiedCallback")
|
||||
.function("dirtied", &DirtiedCallback::dirtied, pure_virtual())
|
||||
.allow_subclass<DirtiedCallbackWrapper>("DirtiedCallbackWrapper");
|
||||
|
||||
class_<Config>("Config")
|
||||
.constructor<>(&Config::create, allow_raw_pointers())
|
||||
.class_function<>("create", &Config::create, allow_raw_pointers())
|
||||
.class_function<>("destroy", &Config::destroy, allow_raw_pointers())
|
||||
.function(
|
||||
"setExperimentalFeatureEnabled",
|
||||
&Config::setExperimentalFeatureEnabled)
|
||||
.function("setPointScaleFactor", &Config::setPointScaleFactor)
|
||||
.function(
|
||||
"setUseLegacyStretchBehaviour", &Config::setUseLegacyStretchBehaviour)
|
||||
.function("setErrata", &Config::setErrata)
|
||||
.function("setUseWebDefaults", &Config::setUseWebDefaults)
|
||||
.function(
|
||||
"isExperimentalFeatureEnabled", &Config::isExperimentalFeatureEnabled)
|
||||
.function("useLegacyStretchBehaviour", &Config::useLegacyStretchBehaviour)
|
||||
.function("getErrata", &Config::getErrata)
|
||||
.function("useWebDefaults", &Config::useWebDefaults);
|
||||
|
||||
value_object<Layout>("Layout")
|
||||
.field("left", &Layout::left)
|
||||
.field("right", &Layout::right)
|
||||
.field("top", &Layout::top)
|
||||
.field("bottom", &Layout::bottom)
|
||||
.field("width", &Layout::width)
|
||||
.field("height", &Layout::height);
|
||||
|
||||
value_object<Size>("Size")
|
||||
.field("width", &Size::width)
|
||||
.field("height", &Size::height);
|
||||
|
||||
value_object<Value>("Value")
|
||||
.field("value", &Value::value)
|
||||
.field("unit", &Value::unit);
|
||||
|
||||
class_<Node>("Node")
|
||||
.constructor<>(&Node::createDefault, allow_raw_pointers())
|
||||
|
||||
.class_function<>(
|
||||
"createDefault", &Node::createDefault, allow_raw_pointers())
|
||||
.class_function<>(
|
||||
"createWithConfig", &Node::createWithConfig, allow_raw_pointers())
|
||||
.class_function<>("destroy", &Node::destroy, allow_raw_pointers())
|
||||
.function("reset", &Node::reset)
|
||||
|
||||
.function("copyStyle", &Node::copyStyle)
|
||||
|
||||
.function("setPositionType", &Node::setPositionType)
|
||||
.function("setPosition", &Node::setPosition)
|
||||
.function("setPositionPercent", &Node::setPositionPercent)
|
||||
|
||||
.function("setAlignContent", &Node::setAlignContent)
|
||||
.function("setAlignItems", &Node::setAlignItems)
|
||||
.function("setAlignSelf", &Node::setAlignSelf)
|
||||
.function("setFlexDirection", &Node::setFlexDirection)
|
||||
.function("setFlexWrap", &Node::setFlexWrap)
|
||||
.function("setJustifyContent", &Node::setJustifyContent)
|
||||
|
||||
.function("setMargin", &Node::setMargin)
|
||||
.function("setMarginPercent", &Node::setMarginPercent)
|
||||
.function("setMarginAuto", &Node::setMarginAuto)
|
||||
|
||||
.function("setOverflow", &Node::setOverflow)
|
||||
.function("setDisplay", &Node::setDisplay)
|
||||
|
||||
.function("setFlex", &Node::setFlex)
|
||||
.function("setFlexBasis", &Node::setFlexBasis)
|
||||
.function("setFlexBasisPercent", &Node::setFlexBasisPercent)
|
||||
.function("setFlexBasisAuto", &Node::setFlexBasisAuto)
|
||||
.function("setFlexGrow", &Node::setFlexGrow)
|
||||
.function("setFlexShrink", &Node::setFlexShrink)
|
||||
|
||||
.function("setWidth", &Node::setWidth)
|
||||
.function("setWidthPercent", &Node::setWidthPercent)
|
||||
.function("setWidthAuto", &Node::setWidthAuto)
|
||||
.function("setHeight", &Node::setHeight)
|
||||
.function("setHeightPercent", &Node::setHeightPercent)
|
||||
.function("setHeightAuto", &Node::setHeightAuto)
|
||||
|
||||
.function("setMinWidth", &Node::setMinWidth)
|
||||
.function("setMinWidthPercent", &Node::setMinWidthPercent)
|
||||
.function("setMinHeight", &Node::setMinHeight)
|
||||
.function("setMinHeightPercent", &Node::setMinHeightPercent)
|
||||
|
||||
.function("setMaxWidth", &Node::setMaxWidth)
|
||||
.function("setMaxWidthPercent", &Node::setMaxWidthPercent)
|
||||
.function("setMaxHeight", &Node::setMaxHeight)
|
||||
.function("setMaxHeightPercent", &Node::setMaxHeightPercent)
|
||||
|
||||
.function("setAspectRatio", &Node::setAspectRatio)
|
||||
|
||||
.function("setBorder", &Node::setBorder)
|
||||
|
||||
.function("setPadding", &Node::setPadding)
|
||||
.function("setPaddingPercent", &Node::setPaddingPercent)
|
||||
.function("setGap", &Node::setGap)
|
||||
|
||||
.function("getPositionType", &Node::getPositionType)
|
||||
.function("getPosition", &Node::getPosition)
|
||||
|
||||
.function("getAlignContent", &Node::getAlignContent)
|
||||
.function("getAlignItems", &Node::getAlignItems)
|
||||
.function("getAlignSelf", &Node::getAlignSelf)
|
||||
.function("getFlexDirection", &Node::getFlexDirection)
|
||||
.function("getFlexWrap", &Node::getFlexWrap)
|
||||
.function("getJustifyContent", &Node::getJustifyContent)
|
||||
|
||||
.function("getMargin", &Node::getMargin)
|
||||
|
||||
.function("getFlexBasis", &Node::getFlexBasis)
|
||||
.function("getFlexGrow", &Node::getFlexGrow)
|
||||
.function("getFlexShrink", &Node::getFlexShrink)
|
||||
|
||||
.function("getWidth", &Node::getWidth)
|
||||
.function("getHeight", &Node::getHeight)
|
||||
|
||||
.function("getMinWidth", &Node::getMinWidth)
|
||||
.function("getMinHeight", &Node::getMinHeight)
|
||||
|
||||
.function("getMaxWidth", &Node::getMaxWidth)
|
||||
.function("getMaxHeight", &Node::getMaxHeight)
|
||||
|
||||
.function("getAspectRatio", &Node::getAspectRatio)
|
||||
|
||||
.function("getBorder", &Node::getBorder)
|
||||
|
||||
.function("getOverflow", &Node::getOverflow)
|
||||
.function("getDisplay", &Node::getDisplay)
|
||||
|
||||
.function("getPadding", &Node::getPadding)
|
||||
.function("getGap", &Node::getGap)
|
||||
|
||||
.function("insertChild", &Node::insertChild, allow_raw_pointers())
|
||||
.function("removeChild", &Node::removeChild, allow_raw_pointers())
|
||||
|
||||
.function("getChildCount", &Node::getChildCount)
|
||||
|
||||
.function("getParent", &Node::getParent, allow_raw_pointers())
|
||||
.function("getChild", &Node::getChild, allow_raw_pointers())
|
||||
|
||||
.function("isReferenceBaseline", &Node::isReferenceBaseline)
|
||||
.function("setIsReferenceBaseline", &Node::setIsReferenceBaseline)
|
||||
|
||||
.function("setMeasureFunc", &Node::setMeasureFunc, allow_raw_pointers())
|
||||
.function("unsetMeasureFunc", &Node::unsetMeasureFunc)
|
||||
|
||||
.function("setDirtiedFunc", &Node::setDirtiedFunc, allow_raw_pointers())
|
||||
.function("unsetDirtiedFunc", &Node::unsetDirtiedFunc)
|
||||
|
||||
.function("markDirty", &Node::markDirty)
|
||||
.function("isDirty", &Node::isDirty)
|
||||
|
||||
.function("calculateLayout", &Node::calculateLayout)
|
||||
|
||||
.function("getComputedLeft", &Node::getComputedLeft)
|
||||
.function("getComputedRight", &Node::getComputedRight)
|
||||
|
||||
.function("getComputedTop", &Node::getComputedTop)
|
||||
.function("getComputedBottom", &Node::getComputedBottom)
|
||||
|
||||
.function("getComputedWidth", &Node::getComputedWidth)
|
||||
.function("getComputedHeight", &Node::getComputedHeight)
|
||||
|
||||
.function("getComputedLayout", &Node::getComputedLayout)
|
||||
|
||||
.function("getComputedMargin", &Node::getComputedMargin)
|
||||
.function("getComputedBorder", &Node::getComputedBorder)
|
||||
.function("getComputedPadding", &Node::getComputedPadding);
|
||||
}
|
15
javascript/src/entrypoint/_entryAsync.js
Normal file
15
javascript/src/entrypoint/_entryAsync.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
const wrapAsm = require('../wrapAsm');
|
||||
|
||||
module.exports = loadAsm => ({
|
||||
loadYoga: () => loadAsm().then(wrapAsm),
|
||||
...require('../generated/YGEnums'),
|
||||
});
|
11
javascript/src/entrypoint/_entrySync.js
Normal file
11
javascript/src/entrypoint/_entrySync.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
const wrapAsm = require('../wrapAsm');
|
||||
module.exports = asm => wrapAsm(asm());
|
11
javascript/src/entrypoint/asmjs-async.js
Normal file
11
javascript/src/entrypoint/asmjs-async.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
const asm = require('../build/asmjs-async');
|
||||
module.exports = require('./_entryAsync')(asm);
|
11
javascript/src/entrypoint/asmjs-sync.js
Normal file
11
javascript/src/entrypoint/asmjs-sync.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
const asm = require('../build/asmjs-sync');
|
||||
module.exports = require('./_entrySync')(asm);
|
11
javascript/src/entrypoint/wasm-async.js
Normal file
11
javascript/src/entrypoint/wasm-async.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
const asm = require('../build/wasm-async');
|
||||
module.exports = require('./_entryAsync')(asm);
|
11
javascript/src/entrypoint/wasm-sync.js
Normal file
11
javascript/src/entrypoint/wasm-sync.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
const asm = require('../build/wasm-sync');
|
||||
module.exports = require('./_entrySync')(asm);
|
347
javascript/src/generated/YGEnums.d.ts
vendored
Normal file
347
javascript/src/generated/YGEnums.d.ts
vendored
Normal file
@@ -0,0 +1,347 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// @generated by enums.py
|
||||
|
||||
type ALIGN_AUTO = 0 & ['ALIGN']
|
||||
export declare const ALIGN_AUTO: ALIGN_AUTO;
|
||||
|
||||
type ALIGN_FLEX_START = 1 & ['ALIGN']
|
||||
export declare const ALIGN_FLEX_START: ALIGN_FLEX_START;
|
||||
|
||||
type ALIGN_CENTER = 2 & ['ALIGN']
|
||||
export declare const ALIGN_CENTER: ALIGN_CENTER;
|
||||
|
||||
type ALIGN_FLEX_END = 3 & ['ALIGN']
|
||||
export declare const ALIGN_FLEX_END: ALIGN_FLEX_END;
|
||||
|
||||
type ALIGN_STRETCH = 4 & ['ALIGN']
|
||||
export declare const ALIGN_STRETCH: ALIGN_STRETCH;
|
||||
|
||||
type ALIGN_BASELINE = 5 & ['ALIGN']
|
||||
export declare const ALIGN_BASELINE: ALIGN_BASELINE;
|
||||
|
||||
type ALIGN_SPACE_BETWEEN = 6 & ['ALIGN']
|
||||
export declare const ALIGN_SPACE_BETWEEN: ALIGN_SPACE_BETWEEN;
|
||||
|
||||
type ALIGN_SPACE_AROUND = 7 & ['ALIGN']
|
||||
export declare const ALIGN_SPACE_AROUND: ALIGN_SPACE_AROUND;
|
||||
|
||||
|
||||
type DIMENSION_WIDTH = 0 & ['DIMENSION']
|
||||
export declare const DIMENSION_WIDTH: DIMENSION_WIDTH;
|
||||
|
||||
type DIMENSION_HEIGHT = 1 & ['DIMENSION']
|
||||
export declare const DIMENSION_HEIGHT: DIMENSION_HEIGHT;
|
||||
|
||||
|
||||
type DIRECTION_INHERIT = 0 & ['DIRECTION']
|
||||
export declare const DIRECTION_INHERIT: DIRECTION_INHERIT;
|
||||
|
||||
type DIRECTION_LTR = 1 & ['DIRECTION']
|
||||
export declare const DIRECTION_LTR: DIRECTION_LTR;
|
||||
|
||||
type DIRECTION_RTL = 2 & ['DIRECTION']
|
||||
export declare const DIRECTION_RTL: DIRECTION_RTL;
|
||||
|
||||
|
||||
type DISPLAY_FLEX = 0 & ['DISPLAY']
|
||||
export declare const DISPLAY_FLEX: DISPLAY_FLEX;
|
||||
|
||||
type DISPLAY_NONE = 1 & ['DISPLAY']
|
||||
export declare const DISPLAY_NONE: DISPLAY_NONE;
|
||||
|
||||
|
||||
type EDGE_LEFT = 0 & ['EDGE']
|
||||
export declare const EDGE_LEFT: EDGE_LEFT;
|
||||
|
||||
type EDGE_TOP = 1 & ['EDGE']
|
||||
export declare const EDGE_TOP: EDGE_TOP;
|
||||
|
||||
type EDGE_RIGHT = 2 & ['EDGE']
|
||||
export declare const EDGE_RIGHT: EDGE_RIGHT;
|
||||
|
||||
type EDGE_BOTTOM = 3 & ['EDGE']
|
||||
export declare const EDGE_BOTTOM: EDGE_BOTTOM;
|
||||
|
||||
type EDGE_START = 4 & ['EDGE']
|
||||
export declare const EDGE_START: EDGE_START;
|
||||
|
||||
type EDGE_END = 5 & ['EDGE']
|
||||
export declare const EDGE_END: EDGE_END;
|
||||
|
||||
type EDGE_HORIZONTAL = 6 & ['EDGE']
|
||||
export declare const EDGE_HORIZONTAL: EDGE_HORIZONTAL;
|
||||
|
||||
type EDGE_VERTICAL = 7 & ['EDGE']
|
||||
export declare const EDGE_VERTICAL: EDGE_VERTICAL;
|
||||
|
||||
type EDGE_ALL = 8 & ['EDGE']
|
||||
export declare const EDGE_ALL: EDGE_ALL;
|
||||
|
||||
|
||||
type ERRATA_NONE = 0 & ['ERRATA']
|
||||
export declare const ERRATA_NONE: ERRATA_NONE;
|
||||
|
||||
type ERRATA_STRETCH_FLEX_BASIS = 1 & ['ERRATA']
|
||||
export declare const ERRATA_STRETCH_FLEX_BASIS: ERRATA_STRETCH_FLEX_BASIS;
|
||||
|
||||
type ERRATA_ALL = 2147483647 & ['ERRATA']
|
||||
export declare const ERRATA_ALL: ERRATA_ALL;
|
||||
|
||||
type ERRATA_CLASSIC = 2147483646 & ['ERRATA']
|
||||
export declare const ERRATA_CLASSIC: ERRATA_CLASSIC;
|
||||
|
||||
|
||||
type EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS = 0 & ['EXPERIMENTAL_FEATURE']
|
||||
export declare const EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS: EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS;
|
||||
|
||||
type EXPERIMENTAL_FEATURE_ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE = 1 & ['EXPERIMENTAL_FEATURE']
|
||||
export declare const EXPERIMENTAL_FEATURE_ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE: EXPERIMENTAL_FEATURE_ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE;
|
||||
|
||||
type EXPERIMENTAL_FEATURE_FIX_ABSOLUTE_TRAILING_COLUMN_MARGIN = 2 & ['EXPERIMENTAL_FEATURE']
|
||||
export declare const EXPERIMENTAL_FEATURE_FIX_ABSOLUTE_TRAILING_COLUMN_MARGIN: EXPERIMENTAL_FEATURE_FIX_ABSOLUTE_TRAILING_COLUMN_MARGIN;
|
||||
|
||||
|
||||
type FLEX_DIRECTION_COLUMN = 0 & ['FLEX_DIRECTION']
|
||||
export declare const FLEX_DIRECTION_COLUMN: FLEX_DIRECTION_COLUMN;
|
||||
|
||||
type FLEX_DIRECTION_COLUMN_REVERSE = 1 & ['FLEX_DIRECTION']
|
||||
export declare const FLEX_DIRECTION_COLUMN_REVERSE: FLEX_DIRECTION_COLUMN_REVERSE;
|
||||
|
||||
type FLEX_DIRECTION_ROW = 2 & ['FLEX_DIRECTION']
|
||||
export declare const FLEX_DIRECTION_ROW: FLEX_DIRECTION_ROW;
|
||||
|
||||
type FLEX_DIRECTION_ROW_REVERSE = 3 & ['FLEX_DIRECTION']
|
||||
export declare const FLEX_DIRECTION_ROW_REVERSE: FLEX_DIRECTION_ROW_REVERSE;
|
||||
|
||||
|
||||
type GUTTER_COLUMN = 0 & ['GUTTER']
|
||||
export declare const GUTTER_COLUMN: GUTTER_COLUMN;
|
||||
|
||||
type GUTTER_ROW = 1 & ['GUTTER']
|
||||
export declare const GUTTER_ROW: GUTTER_ROW;
|
||||
|
||||
type GUTTER_ALL = 2 & ['GUTTER']
|
||||
export declare const GUTTER_ALL: GUTTER_ALL;
|
||||
|
||||
|
||||
type JUSTIFY_FLEX_START = 0 & ['JUSTIFY']
|
||||
export declare const JUSTIFY_FLEX_START: JUSTIFY_FLEX_START;
|
||||
|
||||
type JUSTIFY_CENTER = 1 & ['JUSTIFY']
|
||||
export declare const JUSTIFY_CENTER: JUSTIFY_CENTER;
|
||||
|
||||
type JUSTIFY_FLEX_END = 2 & ['JUSTIFY']
|
||||
export declare const JUSTIFY_FLEX_END: JUSTIFY_FLEX_END;
|
||||
|
||||
type JUSTIFY_SPACE_BETWEEN = 3 & ['JUSTIFY']
|
||||
export declare const JUSTIFY_SPACE_BETWEEN: JUSTIFY_SPACE_BETWEEN;
|
||||
|
||||
type JUSTIFY_SPACE_AROUND = 4 & ['JUSTIFY']
|
||||
export declare const JUSTIFY_SPACE_AROUND: JUSTIFY_SPACE_AROUND;
|
||||
|
||||
type JUSTIFY_SPACE_EVENLY = 5 & ['JUSTIFY']
|
||||
export declare const JUSTIFY_SPACE_EVENLY: JUSTIFY_SPACE_EVENLY;
|
||||
|
||||
|
||||
type LOG_LEVEL_ERROR = 0 & ['LOG_LEVEL']
|
||||
export declare const LOG_LEVEL_ERROR: LOG_LEVEL_ERROR;
|
||||
|
||||
type LOG_LEVEL_WARN = 1 & ['LOG_LEVEL']
|
||||
export declare const LOG_LEVEL_WARN: LOG_LEVEL_WARN;
|
||||
|
||||
type LOG_LEVEL_INFO = 2 & ['LOG_LEVEL']
|
||||
export declare const LOG_LEVEL_INFO: LOG_LEVEL_INFO;
|
||||
|
||||
type LOG_LEVEL_DEBUG = 3 & ['LOG_LEVEL']
|
||||
export declare const LOG_LEVEL_DEBUG: LOG_LEVEL_DEBUG;
|
||||
|
||||
type LOG_LEVEL_VERBOSE = 4 & ['LOG_LEVEL']
|
||||
export declare const LOG_LEVEL_VERBOSE: LOG_LEVEL_VERBOSE;
|
||||
|
||||
type LOG_LEVEL_FATAL = 5 & ['LOG_LEVEL']
|
||||
export declare const LOG_LEVEL_FATAL: LOG_LEVEL_FATAL;
|
||||
|
||||
|
||||
type MEASURE_MODE_UNDEFINED = 0 & ['MEASURE_MODE']
|
||||
export declare const MEASURE_MODE_UNDEFINED: MEASURE_MODE_UNDEFINED;
|
||||
|
||||
type MEASURE_MODE_EXACTLY = 1 & ['MEASURE_MODE']
|
||||
export declare const MEASURE_MODE_EXACTLY: MEASURE_MODE_EXACTLY;
|
||||
|
||||
type MEASURE_MODE_AT_MOST = 2 & ['MEASURE_MODE']
|
||||
export declare const MEASURE_MODE_AT_MOST: MEASURE_MODE_AT_MOST;
|
||||
|
||||
|
||||
type NODE_TYPE_DEFAULT = 0 & ['NODE_TYPE']
|
||||
export declare const NODE_TYPE_DEFAULT: NODE_TYPE_DEFAULT;
|
||||
|
||||
type NODE_TYPE_TEXT = 1 & ['NODE_TYPE']
|
||||
export declare const NODE_TYPE_TEXT: NODE_TYPE_TEXT;
|
||||
|
||||
|
||||
type OVERFLOW_VISIBLE = 0 & ['OVERFLOW']
|
||||
export declare const OVERFLOW_VISIBLE: OVERFLOW_VISIBLE;
|
||||
|
||||
type OVERFLOW_HIDDEN = 1 & ['OVERFLOW']
|
||||
export declare const OVERFLOW_HIDDEN: OVERFLOW_HIDDEN;
|
||||
|
||||
type OVERFLOW_SCROLL = 2 & ['OVERFLOW']
|
||||
export declare const OVERFLOW_SCROLL: OVERFLOW_SCROLL;
|
||||
|
||||
|
||||
type POSITION_TYPE_STATIC = 0 & ['POSITION_TYPE']
|
||||
export declare const POSITION_TYPE_STATIC: POSITION_TYPE_STATIC;
|
||||
|
||||
type POSITION_TYPE_RELATIVE = 1 & ['POSITION_TYPE']
|
||||
export declare const POSITION_TYPE_RELATIVE: POSITION_TYPE_RELATIVE;
|
||||
|
||||
type POSITION_TYPE_ABSOLUTE = 2 & ['POSITION_TYPE']
|
||||
export declare const POSITION_TYPE_ABSOLUTE: POSITION_TYPE_ABSOLUTE;
|
||||
|
||||
|
||||
type PRINT_OPTIONS_LAYOUT = 1 & ['PRINT_OPTIONS']
|
||||
export declare const PRINT_OPTIONS_LAYOUT: PRINT_OPTIONS_LAYOUT;
|
||||
|
||||
type PRINT_OPTIONS_STYLE = 2 & ['PRINT_OPTIONS']
|
||||
export declare const PRINT_OPTIONS_STYLE: PRINT_OPTIONS_STYLE;
|
||||
|
||||
type PRINT_OPTIONS_CHILDREN = 4 & ['PRINT_OPTIONS']
|
||||
export declare const PRINT_OPTIONS_CHILDREN: PRINT_OPTIONS_CHILDREN;
|
||||
|
||||
|
||||
type UNIT_UNDEFINED = 0 & ['UNIT']
|
||||
export declare const UNIT_UNDEFINED: UNIT_UNDEFINED;
|
||||
|
||||
type UNIT_POINT = 1 & ['UNIT']
|
||||
export declare const UNIT_POINT: UNIT_POINT;
|
||||
|
||||
type UNIT_PERCENT = 2 & ['UNIT']
|
||||
export declare const UNIT_PERCENT: UNIT_PERCENT;
|
||||
|
||||
type UNIT_AUTO = 3 & ['UNIT']
|
||||
export declare const UNIT_AUTO: UNIT_AUTO;
|
||||
|
||||
|
||||
type WRAP_NO_WRAP = 0 & ['WRAP']
|
||||
export declare const WRAP_NO_WRAP: WRAP_NO_WRAP;
|
||||
|
||||
type WRAP_WRAP = 1 & ['WRAP']
|
||||
export declare const WRAP_WRAP: WRAP_WRAP;
|
||||
|
||||
type WRAP_WRAP_REVERSE = 2 & ['WRAP']
|
||||
export declare const WRAP_WRAP_REVERSE: WRAP_WRAP_REVERSE;
|
||||
|
||||
|
||||
export type Align =
|
||||
| typeof ALIGN_AUTO
|
||||
| typeof ALIGN_FLEX_START
|
||||
| typeof ALIGN_CENTER
|
||||
| typeof ALIGN_FLEX_END
|
||||
| typeof ALIGN_STRETCH
|
||||
| typeof ALIGN_BASELINE
|
||||
| typeof ALIGN_SPACE_BETWEEN
|
||||
| typeof ALIGN_SPACE_AROUND;
|
||||
|
||||
export type Dimension =
|
||||
| typeof DIMENSION_WIDTH
|
||||
| typeof DIMENSION_HEIGHT;
|
||||
|
||||
export type Direction =
|
||||
| typeof DIRECTION_INHERIT
|
||||
| typeof DIRECTION_LTR
|
||||
| typeof DIRECTION_RTL;
|
||||
|
||||
export type Display =
|
||||
| typeof DISPLAY_FLEX
|
||||
| typeof DISPLAY_NONE;
|
||||
|
||||
export type Edge =
|
||||
| typeof EDGE_LEFT
|
||||
| typeof EDGE_TOP
|
||||
| typeof EDGE_RIGHT
|
||||
| typeof EDGE_BOTTOM
|
||||
| typeof EDGE_START
|
||||
| typeof EDGE_END
|
||||
| typeof EDGE_HORIZONTAL
|
||||
| typeof EDGE_VERTICAL
|
||||
| typeof EDGE_ALL;
|
||||
|
||||
export type Errata =
|
||||
| typeof ERRATA_NONE
|
||||
| typeof ERRATA_STRETCH_FLEX_BASIS
|
||||
| typeof ERRATA_ALL
|
||||
| typeof ERRATA_CLASSIC;
|
||||
|
||||
export type ExperimentalFeature =
|
||||
| typeof EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS
|
||||
| typeof EXPERIMENTAL_FEATURE_ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE
|
||||
| typeof EXPERIMENTAL_FEATURE_FIX_ABSOLUTE_TRAILING_COLUMN_MARGIN;
|
||||
|
||||
export type FlexDirection =
|
||||
| typeof FLEX_DIRECTION_COLUMN
|
||||
| typeof FLEX_DIRECTION_COLUMN_REVERSE
|
||||
| typeof FLEX_DIRECTION_ROW
|
||||
| typeof FLEX_DIRECTION_ROW_REVERSE;
|
||||
|
||||
export type Gutter =
|
||||
| typeof GUTTER_COLUMN
|
||||
| typeof GUTTER_ROW
|
||||
| typeof GUTTER_ALL;
|
||||
|
||||
export type Justify =
|
||||
| typeof JUSTIFY_FLEX_START
|
||||
| typeof JUSTIFY_CENTER
|
||||
| typeof JUSTIFY_FLEX_END
|
||||
| typeof JUSTIFY_SPACE_BETWEEN
|
||||
| typeof JUSTIFY_SPACE_AROUND
|
||||
| typeof JUSTIFY_SPACE_EVENLY;
|
||||
|
||||
export type LogLevel =
|
||||
| typeof LOG_LEVEL_ERROR
|
||||
| typeof LOG_LEVEL_WARN
|
||||
| typeof LOG_LEVEL_INFO
|
||||
| typeof LOG_LEVEL_DEBUG
|
||||
| typeof LOG_LEVEL_VERBOSE
|
||||
| typeof LOG_LEVEL_FATAL;
|
||||
|
||||
export type MeasureMode =
|
||||
| typeof MEASURE_MODE_UNDEFINED
|
||||
| typeof MEASURE_MODE_EXACTLY
|
||||
| typeof MEASURE_MODE_AT_MOST;
|
||||
|
||||
export type NodeType =
|
||||
| typeof NODE_TYPE_DEFAULT
|
||||
| typeof NODE_TYPE_TEXT;
|
||||
|
||||
export type Overflow =
|
||||
| typeof OVERFLOW_VISIBLE
|
||||
| typeof OVERFLOW_HIDDEN
|
||||
| typeof OVERFLOW_SCROLL;
|
||||
|
||||
export type PositionType =
|
||||
| typeof POSITION_TYPE_STATIC
|
||||
| typeof POSITION_TYPE_RELATIVE
|
||||
| typeof POSITION_TYPE_ABSOLUTE;
|
||||
|
||||
export type PrintOptions =
|
||||
| typeof PRINT_OPTIONS_LAYOUT
|
||||
| typeof PRINT_OPTIONS_STYLE
|
||||
| typeof PRINT_OPTIONS_CHILDREN;
|
||||
|
||||
export type Unit =
|
||||
| typeof UNIT_UNDEFINED
|
||||
| typeof UNIT_POINT
|
||||
| typeof UNIT_PERCENT
|
||||
| typeof UNIT_AUTO;
|
||||
|
||||
export type Wrap =
|
||||
| typeof WRAP_NO_WRAP
|
||||
| typeof WRAP_WRAP
|
||||
| typeof WRAP_WRAP_REVERSE;
|
||||
|
97
javascript/src/generated/YGEnums.js
Normal file
97
javascript/src/generated/YGEnums.js
Normal file
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// @generated by enums.py
|
||||
|
||||
exports.ALIGN_AUTO = 0;
|
||||
exports.ALIGN_FLEX_START = 1;
|
||||
exports.ALIGN_CENTER = 2;
|
||||
exports.ALIGN_FLEX_END = 3;
|
||||
exports.ALIGN_STRETCH = 4;
|
||||
exports.ALIGN_BASELINE = 5;
|
||||
exports.ALIGN_SPACE_BETWEEN = 6;
|
||||
exports.ALIGN_SPACE_AROUND = 7;
|
||||
|
||||
exports.DIMENSION_WIDTH = 0;
|
||||
exports.DIMENSION_HEIGHT = 1;
|
||||
|
||||
exports.DIRECTION_INHERIT = 0;
|
||||
exports.DIRECTION_LTR = 1;
|
||||
exports.DIRECTION_RTL = 2;
|
||||
|
||||
exports.DISPLAY_FLEX = 0;
|
||||
exports.DISPLAY_NONE = 1;
|
||||
|
||||
exports.EDGE_LEFT = 0;
|
||||
exports.EDGE_TOP = 1;
|
||||
exports.EDGE_RIGHT = 2;
|
||||
exports.EDGE_BOTTOM = 3;
|
||||
exports.EDGE_START = 4;
|
||||
exports.EDGE_END = 5;
|
||||
exports.EDGE_HORIZONTAL = 6;
|
||||
exports.EDGE_VERTICAL = 7;
|
||||
exports.EDGE_ALL = 8;
|
||||
|
||||
exports.ERRATA_NONE = 0;
|
||||
exports.ERRATA_STRETCH_FLEX_BASIS = 1;
|
||||
exports.ERRATA_ALL = 2147483647;
|
||||
exports.ERRATA_CLASSIC = 2147483646;
|
||||
|
||||
exports.EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS = 0;
|
||||
exports.EXPERIMENTAL_FEATURE_ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE = 1;
|
||||
exports.EXPERIMENTAL_FEATURE_FIX_ABSOLUTE_TRAILING_COLUMN_MARGIN = 2;
|
||||
|
||||
exports.FLEX_DIRECTION_COLUMN = 0;
|
||||
exports.FLEX_DIRECTION_COLUMN_REVERSE = 1;
|
||||
exports.FLEX_DIRECTION_ROW = 2;
|
||||
exports.FLEX_DIRECTION_ROW_REVERSE = 3;
|
||||
|
||||
exports.GUTTER_COLUMN = 0;
|
||||
exports.GUTTER_ROW = 1;
|
||||
exports.GUTTER_ALL = 2;
|
||||
|
||||
exports.JUSTIFY_FLEX_START = 0;
|
||||
exports.JUSTIFY_CENTER = 1;
|
||||
exports.JUSTIFY_FLEX_END = 2;
|
||||
exports.JUSTIFY_SPACE_BETWEEN = 3;
|
||||
exports.JUSTIFY_SPACE_AROUND = 4;
|
||||
exports.JUSTIFY_SPACE_EVENLY = 5;
|
||||
|
||||
exports.LOG_LEVEL_ERROR = 0;
|
||||
exports.LOG_LEVEL_WARN = 1;
|
||||
exports.LOG_LEVEL_INFO = 2;
|
||||
exports.LOG_LEVEL_DEBUG = 3;
|
||||
exports.LOG_LEVEL_VERBOSE = 4;
|
||||
exports.LOG_LEVEL_FATAL = 5;
|
||||
|
||||
exports.MEASURE_MODE_UNDEFINED = 0;
|
||||
exports.MEASURE_MODE_EXACTLY = 1;
|
||||
exports.MEASURE_MODE_AT_MOST = 2;
|
||||
|
||||
exports.NODE_TYPE_DEFAULT = 0;
|
||||
exports.NODE_TYPE_TEXT = 1;
|
||||
|
||||
exports.OVERFLOW_VISIBLE = 0;
|
||||
exports.OVERFLOW_HIDDEN = 1;
|
||||
exports.OVERFLOW_SCROLL = 2;
|
||||
|
||||
exports.POSITION_TYPE_STATIC = 0;
|
||||
exports.POSITION_TYPE_RELATIVE = 1;
|
||||
exports.POSITION_TYPE_ABSOLUTE = 2;
|
||||
|
||||
exports.PRINT_OPTIONS_LAYOUT = 1;
|
||||
exports.PRINT_OPTIONS_STYLE = 2;
|
||||
exports.PRINT_OPTIONS_CHILDREN = 4;
|
||||
|
||||
exports.UNIT_UNDEFINED = 0;
|
||||
exports.UNIT_POINT = 1;
|
||||
exports.UNIT_PERCENT = 2;
|
||||
exports.UNIT_AUTO = 3;
|
||||
|
||||
exports.WRAP_NO_WRAP = 0;
|
||||
exports.WRAP_WRAP = 1;
|
||||
exports.WRAP_WRAP_REVERSE = 2;
|
15
javascript/src/index.d.ts
vendored
Normal file
15
javascript/src/index.d.ts
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type {Yoga} from './wrapAsm';
|
||||
|
||||
export * from './generated/YGEnums';
|
||||
export * from './wrapAsm';
|
||||
|
||||
export function loadYoga(): Promise<Yoga>;
|
11
javascript/src/index.js
Normal file
11
javascript/src/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
// Fallback for when the export map is not followed
|
||||
module.exports = require('./entrypoint/asmjs-async');
|
16
javascript/src/sync.d.ts
vendored
Normal file
16
javascript/src/sync.d.ts
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type {Yoga} from './wrapAsm';
|
||||
|
||||
export * from './generated/YGEnums';
|
||||
export * from './wrapAsm';
|
||||
|
||||
declare const yoga: Yoga;
|
||||
export default yoga;
|
11
javascript/src/sync.js
Normal file
11
javascript/src/sync.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
// Fallback for when the export map is not followed
|
||||
module.exports = require('./entrypoint/asmjs-sync');
|
191
javascript/src/wrapAsm.d.ts
vendored
Normal file
191
javascript/src/wrapAsm.d.ts
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type {
|
||||
Align,
|
||||
Direction,
|
||||
Display,
|
||||
Edge,
|
||||
Errata,
|
||||
ExperimentalFeature,
|
||||
FlexDirection,
|
||||
Gutter,
|
||||
Justify,
|
||||
MeasureMode,
|
||||
Overflow,
|
||||
PositionType,
|
||||
Unit,
|
||||
Wrap,
|
||||
} from './generated/YGEnums';
|
||||
|
||||
import type * as YGEnums from './generated/YGEnums';
|
||||
|
||||
type Layout = {
|
||||
left: number;
|
||||
right: number;
|
||||
top: number;
|
||||
bottom: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
type Size = {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
type Value = {
|
||||
unit: Unit;
|
||||
value: number;
|
||||
};
|
||||
|
||||
export type Config = {
|
||||
free(): void;
|
||||
isExperimentalFeatureEnabled(feature: ExperimentalFeature): boolean;
|
||||
setExperimentalFeatureEnabled(
|
||||
feature: ExperimentalFeature,
|
||||
enabled: boolean,
|
||||
): void;
|
||||
setPointScaleFactor(factor: number): void;
|
||||
/**
|
||||
* @deprecated Please use "getErrata()"
|
||||
*/
|
||||
useLegacyStretchBehaviour(): boolean;
|
||||
/**
|
||||
* @deprecated "setUseLegacyStretchBehaviour" will be removed in the next
|
||||
* release. Usage should be replaced with "setErrata(ERRATA_ALL)" to opt out
|
||||
* of all future breaking conformance fixes, or
|
||||
* "setErrata(ERRATA_STRETCH_FLEX_BASIS)" to opt out of the specific
|
||||
* conformance fix previously disabled by "UseLegacyStretchBehaviour".
|
||||
*/
|
||||
setUseLegacyStretchBehaviour(useLegacyStretchBehaviour: boolean): void;
|
||||
getErrata(): Errata;
|
||||
setErrata(errata: Errata): void;
|
||||
useWebDefaults(): boolean;
|
||||
setUseWebDefaults(useWebDefaults: boolean): void;
|
||||
};
|
||||
|
||||
export type DirtiedFunction = (node: Node) => void;
|
||||
|
||||
export type MeasureFunction = (
|
||||
width: number,
|
||||
widthMode: MeasureMode,
|
||||
height: number,
|
||||
heightMode: MeasureMode,
|
||||
) => Size;
|
||||
|
||||
export type Node = {
|
||||
calculateLayout(width?: number, height?: number, direction?: Direction): void;
|
||||
copyStyle(node: Node): void;
|
||||
free(): void;
|
||||
freeRecursive(): void;
|
||||
getAlignContent(): Align;
|
||||
getAlignItems(): Align;
|
||||
getAlignSelf(): Align;
|
||||
getAspectRatio(): number;
|
||||
getBorder(edge: Edge): number;
|
||||
getChild(index: number): Node;
|
||||
getChildCount(): number;
|
||||
getComputedBorder(edge: Edge): number;
|
||||
getComputedBottom(): number;
|
||||
getComputedHeight(): number;
|
||||
getComputedLayout(): Layout;
|
||||
getComputedLeft(): number;
|
||||
getComputedMargin(edge: Edge): number;
|
||||
getComputedPadding(edge: Edge): number;
|
||||
getComputedRight(): number;
|
||||
getComputedTop(): number;
|
||||
getComputedWidth(): number;
|
||||
getDisplay(): Display;
|
||||
getFlexBasis(): Value;
|
||||
getFlexDirection(): FlexDirection;
|
||||
getFlexGrow(): number;
|
||||
getFlexShrink(): number;
|
||||
getFlexWrap(): Wrap;
|
||||
getHeight(): Value;
|
||||
getJustifyContent(): Justify;
|
||||
getGap(gutter: Gutter): Value;
|
||||
getMargin(edge: Edge): Value;
|
||||
getMaxHeight(): Value;
|
||||
getMaxWidth(): Value;
|
||||
getMinHeight(): Value;
|
||||
getMinWidth(): Value;
|
||||
getOverflow(): Overflow;
|
||||
getPadding(edge: Edge): Value;
|
||||
getParent(): Node | null;
|
||||
getPosition(edge: Edge): Value;
|
||||
getPositionType(): PositionType;
|
||||
getWidth(): Value;
|
||||
insertChild(child: Node, index: number): void;
|
||||
isDirty(): boolean;
|
||||
isReferenceBaseline(): boolean;
|
||||
markDirty(): void;
|
||||
removeChild(child: Node): void;
|
||||
reset(): void;
|
||||
setAlignContent(alignContent: Align): void;
|
||||
setAlignItems(alignItems: Align): void;
|
||||
setAlignSelf(alignSelf: Align): void;
|
||||
setAspectRatio(aspectRatio: number): void;
|
||||
setBorder(edge: Edge, borderWidth: number): void;
|
||||
setDisplay(display: Display): void;
|
||||
setFlex(flex: number): void;
|
||||
setFlexBasis(flexBasis: number | 'auto' | `${number}%`): void;
|
||||
setFlexBasisPercent(flexBasis: number): void;
|
||||
setFlexBasisAuto(): void;
|
||||
setFlexDirection(flexDirection: FlexDirection): void;
|
||||
setFlexGrow(flexGrow: number): void;
|
||||
setFlexShrink(flexShrink: number): void;
|
||||
setFlexWrap(flexWrap: Wrap): void;
|
||||
setHeight(height: number | 'auto' | `${number}%`): void;
|
||||
setIsReferenceBaseline(isReferenceBaseline: boolean): void;
|
||||
setHeightAuto(): void;
|
||||
setHeightPercent(height: number): void;
|
||||
setJustifyContent(justifyContent: Justify): void;
|
||||
setGap(gutter: Gutter, gapLength: number): Value;
|
||||
setMargin(edge: Edge, margin: number | 'auto' | `${number}%`): void;
|
||||
setMarginAuto(edge: Edge): void;
|
||||
setMarginPercent(edge: Edge, margin: number): void;
|
||||
setMaxHeight(maxHeight: number | `${number}%`): void;
|
||||
setMaxHeightPercent(maxHeight: number): void;
|
||||
setMaxWidth(maxWidth: number | `${number}%`): void;
|
||||
setMaxWidthPercent(maxWidth: number): void;
|
||||
setDirtiedFunc(dirtiedFunc: DirtiedFunction | null): void;
|
||||
setMeasureFunc(measureFunc: MeasureFunction | null): void;
|
||||
setMinHeight(minHeight: number | `${number}%`): void;
|
||||
setMinHeightPercent(minHeight: number): void;
|
||||
setMinWidth(minWidth: number | `${number}%`): void;
|
||||
setMinWidthPercent(minWidth: number): void;
|
||||
setOverflow(overflow: Overflow): void;
|
||||
setPadding(edge: Edge, padding: number | `${number}%`): void;
|
||||
setPaddingPercent(edge: Edge, padding: number): void;
|
||||
setPosition(edge: Edge, position: number | `${number}%`): void;
|
||||
setPositionPercent(edge: Edge, position: number): void;
|
||||
setPositionType(positionType: PositionType): void;
|
||||
setWidth(width: number | 'auto' | `${number}%`): void;
|
||||
setWidthAuto(): void;
|
||||
setWidthPercent(width: number): void;
|
||||
unsetDirtiedFunc(): void;
|
||||
unsetMeasureFunc(): void;
|
||||
};
|
||||
|
||||
export type Yoga = {
|
||||
Config: {
|
||||
create(): Config;
|
||||
destroy(config: Config): void;
|
||||
};
|
||||
Node: {
|
||||
create(config?: Config): Node;
|
||||
createDefault(): Node;
|
||||
createWithConfig(config: Config): Node;
|
||||
destroy(node: Node): void;
|
||||
};
|
||||
} & typeof YGEnums;
|
||||
|
||||
declare const wrapAsm: () => Yoga;
|
||||
export default wrapAsm;
|
151
javascript/src/wrapAsm.js
Normal file
151
javascript/src/wrapAsm.js
Normal file
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
const CONSTANTS = require('./generated/YGEnums');
|
||||
|
||||
module.exports = lib => {
|
||||
function patch(prototype, name, fn) {
|
||||
const original = prototype[name];
|
||||
|
||||
prototype[name] = function (...args) {
|
||||
return fn.call(this, original, ...args);
|
||||
};
|
||||
}
|
||||
|
||||
for (const fnName of [
|
||||
'setPosition',
|
||||
'setMargin',
|
||||
'setFlexBasis',
|
||||
'setWidth',
|
||||
'setHeight',
|
||||
'setMinWidth',
|
||||
'setMinHeight',
|
||||
'setMaxWidth',
|
||||
'setMaxHeight',
|
||||
'setPadding',
|
||||
]) {
|
||||
const 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, fnName, function (original, ...args) {
|
||||
// We patch all these functions to add support for the following calls:
|
||||
// .setWidth(100) / .setWidth("100%") / .setWidth(.getWidth()) / .setWidth("auto")
|
||||
|
||||
const value = args.pop();
|
||||
let unit, asNumber;
|
||||
|
||||
if (value === 'auto') {
|
||||
unit = CONSTANTS.UNIT_AUTO;
|
||||
asNumber = undefined;
|
||||
} else if (typeof value === 'object') {
|
||||
unit = value.unit;
|
||||
asNumber = value.valueOf();
|
||||
} else {
|
||||
unit =
|
||||
typeof value === 'string' && value.endsWith('%')
|
||||
? CONSTANTS.UNIT_PERCENT
|
||||
: CONSTANTS.UNIT_POINT;
|
||||
asNumber = parseFloat(value);
|
||||
if (!Number.isNaN(value) && Number.isNaN(asNumber)) {
|
||||
throw new Error(`Invalid value ${value} for ${fnName}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!methods[unit])
|
||||
throw new Error(
|
||||
`Failed to execute "${fnName}": Unsupported unit '${value}'`,
|
||||
);
|
||||
|
||||
if (asNumber !== undefined) {
|
||||
return methods[unit].call(this, ...args, asNumber);
|
||||
} else {
|
||||
return methods[unit].call(this, ...args);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function wrapMeasureFunction(measureFunction) {
|
||||
return lib.MeasureCallback.implement({
|
||||
measure: (...args) => {
|
||||
const {width, height} = measureFunction(...args);
|
||||
return {
|
||||
width: width ?? NaN,
|
||||
height: height ?? NaN,
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
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))
|
||||
if (measureFunc) {
|
||||
return original.call(this, wrapMeasureFunction(measureFunc));
|
||||
} else {
|
||||
return this.unsetMeasureFunc();
|
||||
}
|
||||
});
|
||||
|
||||
function wrapDirtiedFunc(dirtiedFunction) {
|
||||
return lib.DirtiedCallback.implement({dirtied: dirtiedFunction});
|
||||
}
|
||||
|
||||
patch(lib.Node.prototype, 'setDirtiedFunc', function (original, dirtiedFunc) {
|
||||
original.call(this, wrapDirtiedFunc(dirtiedFunc));
|
||||
});
|
||||
|
||||
patch(lib.Config.prototype, 'free', function () {
|
||||
// Since we handle the memory allocation ourselves (via lib.Config.create),
|
||||
// we also need to handle the deallocation
|
||||
lib.Config.destroy(this);
|
||||
});
|
||||
|
||||
patch(lib.Node, 'create', (_, 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,
|
||||
'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,
|
||||
...CONSTANTS,
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user