@opentui/core 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/3d.js CHANGED
@@ -33734,6 +33734,64 @@ function getKeyHandler() {
33734
33734
  return keyHandler;
33735
33735
  }
33736
33736
 
33737
+ // src/lib/yoga.options.ts
33738
+ function parseAlign(value) {
33739
+ switch (value.toLowerCase()) {
33740
+ case "auto":
33741
+ return Align.Auto;
33742
+ case "flex-start":
33743
+ return Align.FlexStart;
33744
+ case "center":
33745
+ return Align.Center;
33746
+ case "flex-end":
33747
+ return Align.FlexEnd;
33748
+ case "stretch":
33749
+ return Align.Stretch;
33750
+ case "baseline":
33751
+ return Align.Baseline;
33752
+ case "space-between":
33753
+ return Align.SpaceBetween;
33754
+ case "space-around":
33755
+ return Align.SpaceAround;
33756
+ case "space-evenly":
33757
+ return Align.SpaceEvenly;
33758
+ default:
33759
+ return Align.Auto;
33760
+ }
33761
+ }
33762
+ function parseFlexDirection(value) {
33763
+ switch (value.toLowerCase()) {
33764
+ case "column":
33765
+ return FlexDirection.Column;
33766
+ case "column-reverse":
33767
+ return FlexDirection.ColumnReverse;
33768
+ case "row":
33769
+ return FlexDirection.Row;
33770
+ case "row-reverse":
33771
+ return FlexDirection.RowReverse;
33772
+ default:
33773
+ return FlexDirection.Column;
33774
+ }
33775
+ }
33776
+ function parseJustify(value) {
33777
+ switch (value.toLowerCase()) {
33778
+ case "flex-start":
33779
+ return Justify.FlexStart;
33780
+ case "center":
33781
+ return Justify.Center;
33782
+ case "flex-end":
33783
+ return Justify.FlexEnd;
33784
+ case "space-between":
33785
+ return Justify.SpaceBetween;
33786
+ case "space-around":
33787
+ return Justify.SpaceAround;
33788
+ case "space-evenly":
33789
+ return Justify.SpaceEvenly;
33790
+ default:
33791
+ return Justify.FlexStart;
33792
+ }
33793
+ }
33794
+
33737
33795
  // src/Renderable.ts
33738
33796
  var renderableNumber = 1;
33739
33797
  function validateOptions(id, options) {
@@ -33748,6 +33806,59 @@ function validateOptions(id, options) {
33748
33806
  }
33749
33807
  }
33750
33808
  }
33809
+ function isValidPercentage(value) {
33810
+ if (typeof value === "string" && value.endsWith("%")) {
33811
+ const numPart = value.slice(0, -1);
33812
+ const num = parseFloat(numPart);
33813
+ return !Number.isNaN(num);
33814
+ }
33815
+ return false;
33816
+ }
33817
+ function isMarginType(value) {
33818
+ if (typeof value === "number" && !Number.isNaN(value)) {
33819
+ return true;
33820
+ }
33821
+ if (value === "auto") {
33822
+ return true;
33823
+ }
33824
+ return isValidPercentage(value);
33825
+ }
33826
+ function isPaddingType(value) {
33827
+ if (typeof value === "number" && !Number.isNaN(value)) {
33828
+ return true;
33829
+ }
33830
+ return isValidPercentage(value);
33831
+ }
33832
+ function isPositionType(value) {
33833
+ if (typeof value === "number" && !Number.isNaN(value)) {
33834
+ return true;
33835
+ }
33836
+ if (value === "auto") {
33837
+ return true;
33838
+ }
33839
+ return isValidPercentage(value);
33840
+ }
33841
+ function isDimensionType(value) {
33842
+ return isPositionType(value);
33843
+ }
33844
+ function isFlexBasisType(value) {
33845
+ if (value === undefined || value === "auto") {
33846
+ return true;
33847
+ }
33848
+ if (typeof value === "number" && !Number.isNaN(value)) {
33849
+ return true;
33850
+ }
33851
+ return false;
33852
+ }
33853
+ function isSizeType(value) {
33854
+ if (value === undefined) {
33855
+ return true;
33856
+ }
33857
+ if (typeof value === "number" && !Number.isNaN(value)) {
33858
+ return true;
33859
+ }
33860
+ return isValidPercentage(value);
33861
+ }
33751
33862
 
33752
33863
  class Renderable extends EventEmitter3 {
33753
33864
  static renderablesByNumber = new Map;
@@ -33869,19 +33980,39 @@ class Renderable extends EventEmitter3 {
33869
33980
  return this._x;
33870
33981
  }
33871
33982
  set x(value) {
33872
- this.setPosition({
33873
- left: value
33874
- });
33983
+ this.left = value;
33984
+ }
33985
+ get top() {
33986
+ return this._position.top;
33875
33987
  }
33876
33988
  set top(value) {
33877
- this.setPosition({
33878
- top: value
33879
- });
33989
+ if (isPositionType(value) || value === undefined) {
33990
+ this.setPosition({ top: value });
33991
+ }
33992
+ }
33993
+ get right() {
33994
+ return this._position.right;
33995
+ }
33996
+ set right(value) {
33997
+ if (isPositionType(value) || value === undefined) {
33998
+ this.setPosition({ right: value });
33999
+ }
34000
+ }
34001
+ get bottom() {
34002
+ return this._position.bottom;
34003
+ }
34004
+ set bottom(value) {
34005
+ if (isPositionType(value) || value === undefined) {
34006
+ this.setPosition({ bottom: value });
34007
+ }
34008
+ }
34009
+ get left() {
34010
+ return this._position.left;
33880
34011
  }
33881
34012
  set left(value) {
33882
- this.setPosition({
33883
- left: value
33884
- });
34013
+ if (isPositionType(value) || value === undefined) {
34014
+ this.setPosition({ left: value });
34015
+ }
33885
34016
  }
33886
34017
  get y() {
33887
34018
  if (this.parent && this._positionType === "relative") {
@@ -33890,25 +34021,27 @@ class Renderable extends EventEmitter3 {
33890
34021
  return this._y;
33891
34022
  }
33892
34023
  set y(value) {
33893
- this.setPosition({
33894
- top: value
33895
- });
34024
+ this.top = value;
33896
34025
  }
33897
34026
  get width() {
33898
34027
  return this._widthValue;
33899
34028
  }
33900
34029
  set width(value) {
33901
- this._width = value;
33902
- this.layoutNode.setWidth(value);
33903
- this.requestLayout();
34030
+ if (isDimensionType(value)) {
34031
+ this._width = value;
34032
+ this.layoutNode.setWidth(value);
34033
+ this.requestLayout();
34034
+ }
33904
34035
  }
33905
34036
  get height() {
33906
34037
  return this._heightValue;
33907
34038
  }
33908
34039
  set height(value) {
33909
- this._height = value;
33910
- this.layoutNode.setHeight(value);
33911
- this.requestLayout();
34040
+ if (isDimensionType(value)) {
34041
+ this._height = value;
34042
+ this.layoutNode.setHeight(value);
34043
+ this.requestLayout();
34044
+ }
33912
34045
  }
33913
34046
  get zIndex() {
33914
34047
  return this._zIndex;
@@ -33930,13 +34063,13 @@ class Renderable extends EventEmitter3 {
33930
34063
  }
33931
34064
  setupYogaProperties(options) {
33932
34065
  const node = this.layoutNode.yogaNode;
33933
- if (options.flexBasis !== undefined) {
34066
+ if (isFlexBasisType(options.flexBasis)) {
33934
34067
  node.setFlexBasis(options.flexBasis);
33935
34068
  }
33936
- if (options.minWidth !== undefined) {
34069
+ if (isSizeType(options.minWidth)) {
33937
34070
  node.setMinWidth(options.minWidth);
33938
34071
  }
33939
- if (options.minHeight !== undefined) {
34072
+ if (isSizeType(options.minHeight)) {
33940
34073
  node.setMinHeight(options.minHeight);
33941
34074
  }
33942
34075
  if (options.flexGrow !== undefined) {
@@ -33951,19 +34084,19 @@ class Renderable extends EventEmitter3 {
33951
34084
  node.setFlexShrink(shrinkValue);
33952
34085
  }
33953
34086
  if (options.flexDirection !== undefined) {
33954
- node.setFlexDirection(options.flexDirection);
34087
+ node.setFlexDirection(parseFlexDirection(options.flexDirection));
33955
34088
  }
33956
34089
  if (options.alignItems !== undefined) {
33957
- node.setAlignItems(options.alignItems);
34090
+ node.setAlignItems(parseAlign(options.alignItems));
33958
34091
  }
33959
34092
  if (options.justifyContent !== undefined) {
33960
- node.setJustifyContent(options.justifyContent);
34093
+ node.setJustifyContent(parseJustify(options.justifyContent));
33961
34094
  }
33962
- if (options.width !== undefined) {
34095
+ if (isDimensionType(options.width)) {
33963
34096
  this._width = options.width;
33964
34097
  this.layoutNode.setWidth(options.width);
33965
34098
  }
33966
- if (options.height !== undefined) {
34099
+ if (isDimensionType(options.height)) {
33967
34100
  this._height = options.height;
33968
34101
  this.layoutNode.setHeight(options.height);
33969
34102
  }
@@ -33971,49 +34104,93 @@ class Renderable extends EventEmitter3 {
33971
34104
  if (this._positionType === "absolute") {
33972
34105
  node.setPositionType(PositionType.Absolute);
33973
34106
  }
33974
- if (options.position) {
33975
- this._position = options.position;
33976
- this.updateYogaPosition(options.position);
34107
+ const hasPositionProps = options.top !== undefined || options.right !== undefined || options.bottom !== undefined || options.left !== undefined;
34108
+ if (hasPositionProps) {
34109
+ this._position = {
34110
+ top: options.top,
34111
+ right: options.right,
34112
+ bottom: options.bottom,
34113
+ left: options.left
34114
+ };
34115
+ this.updateYogaPosition(this._position);
33977
34116
  }
33978
- if (options.maxWidth !== undefined) {
34117
+ if (isSizeType(options.maxWidth)) {
33979
34118
  node.setMaxWidth(options.maxWidth);
33980
34119
  }
33981
- if (options.maxHeight !== undefined) {
34120
+ if (isSizeType(options.maxHeight)) {
33982
34121
  node.setMaxHeight(options.maxHeight);
33983
34122
  }
33984
- this.margin = options.margin;
33985
- this.padding = options.padding;
34123
+ this.setupMarginAndPadding(options);
34124
+ }
34125
+ setupMarginAndPadding(options) {
34126
+ const node = this.layoutNode.yogaNode;
34127
+ if (isMarginType(options.margin)) {
34128
+ node.setMargin(Edge2.Top, options.margin);
34129
+ node.setMargin(Edge2.Right, options.margin);
34130
+ node.setMargin(Edge2.Bottom, options.margin);
34131
+ node.setMargin(Edge2.Left, options.margin);
34132
+ }
34133
+ if (isMarginType(options.marginTop)) {
34134
+ node.setMargin(Edge2.Top, options.marginTop);
34135
+ }
34136
+ if (isMarginType(options.marginRight)) {
34137
+ node.setMargin(Edge2.Right, options.marginRight);
34138
+ }
34139
+ if (isMarginType(options.marginBottom)) {
34140
+ node.setMargin(Edge2.Bottom, options.marginBottom);
34141
+ }
34142
+ if (isMarginType(options.marginLeft)) {
34143
+ node.setMargin(Edge2.Left, options.marginLeft);
34144
+ }
34145
+ if (isPaddingType(options.padding)) {
34146
+ node.setPadding(Edge2.Top, options.padding);
34147
+ node.setPadding(Edge2.Right, options.padding);
34148
+ node.setPadding(Edge2.Bottom, options.padding);
34149
+ node.setPadding(Edge2.Left, options.padding);
34150
+ }
34151
+ if (isPaddingType(options.paddingTop)) {
34152
+ node.setPadding(Edge2.Top, options.paddingTop);
34153
+ }
34154
+ if (isPaddingType(options.paddingRight)) {
34155
+ node.setPadding(Edge2.Right, options.paddingRight);
34156
+ }
34157
+ if (isPaddingType(options.paddingBottom)) {
34158
+ node.setPadding(Edge2.Bottom, options.paddingBottom);
34159
+ }
34160
+ if (isPaddingType(options.paddingLeft)) {
34161
+ node.setPadding(Edge2.Left, options.paddingLeft);
34162
+ }
33986
34163
  }
33987
34164
  setPosition(position) {
33988
- this._position = position;
34165
+ this._position = { ...this._position, ...position };
33989
34166
  this.updateYogaPosition(position);
33990
34167
  }
33991
34168
  updateYogaPosition(position) {
33992
34169
  const node = this.layoutNode.yogaNode;
33993
34170
  const { top, right, bottom, left } = position;
33994
34171
  if (this._positionType === "relative") {
33995
- if (top !== undefined) {
34172
+ if (isPositionType(top)) {
33996
34173
  if (top === "auto") {
33997
34174
  node.setPositionAuto(Edge2.Top);
33998
34175
  } else {
33999
34176
  node.setPosition(Edge2.Top, top);
34000
34177
  }
34001
34178
  }
34002
- if (right !== undefined) {
34179
+ if (isPositionType(right)) {
34003
34180
  if (right === "auto") {
34004
34181
  node.setPositionAuto(Edge2.Right);
34005
34182
  } else {
34006
34183
  node.setPosition(Edge2.Right, right);
34007
34184
  }
34008
34185
  }
34009
- if (bottom !== undefined) {
34186
+ if (isPositionType(bottom)) {
34010
34187
  if (bottom === "auto") {
34011
34188
  node.setPositionAuto(Edge2.Bottom);
34012
34189
  } else {
34013
34190
  node.setPosition(Edge2.Bottom, bottom);
34014
34191
  }
34015
34192
  }
34016
- if (left !== undefined) {
34193
+ if (isPositionType(left)) {
34017
34194
  if (left === "auto") {
34018
34195
  node.setPositionAuto(Edge2.Left);
34019
34196
  } else {
@@ -34041,76 +34218,114 @@ class Renderable extends EventEmitter3 {
34041
34218
  this.requestLayout();
34042
34219
  }
34043
34220
  set flexDirection(direction) {
34044
- this.layoutNode.yogaNode.setFlexDirection(direction);
34221
+ this.layoutNode.yogaNode.setFlexDirection(parseFlexDirection(direction));
34045
34222
  this.requestLayout();
34046
34223
  }
34047
34224
  set alignItems(alignItems) {
34048
- this.layoutNode.yogaNode.setAlignItems(alignItems);
34225
+ this.layoutNode.yogaNode.setAlignItems(parseAlign(alignItems));
34049
34226
  this.requestLayout();
34050
34227
  }
34051
34228
  set justifyContent(justifyContent) {
34052
- this.layoutNode.yogaNode.setJustifyContent(justifyContent);
34229
+ this.layoutNode.yogaNode.setJustifyContent(parseJustify(justifyContent));
34053
34230
  this.requestLayout();
34054
34231
  }
34055
34232
  set flexBasis(basis) {
34056
- this.layoutNode.yogaNode.setFlexBasis(basis);
34057
- this.requestLayout();
34233
+ if (isFlexBasisType(basis)) {
34234
+ this.layoutNode.yogaNode.setFlexBasis(basis);
34235
+ this.requestLayout();
34236
+ }
34058
34237
  }
34059
34238
  set minWidth(minWidth) {
34060
- this.layoutNode.yogaNode.setMinWidth(minWidth);
34061
- this.requestLayout();
34239
+ if (isSizeType(minWidth)) {
34240
+ this.layoutNode.yogaNode.setMinWidth(minWidth);
34241
+ this.requestLayout();
34242
+ }
34062
34243
  }
34063
34244
  set maxWidth(maxWidth) {
34064
- this.layoutNode.yogaNode.setMaxWidth(maxWidth);
34065
- this.requestLayout();
34245
+ if (isSizeType(maxWidth)) {
34246
+ this.layoutNode.yogaNode.setMaxWidth(maxWidth);
34247
+ this.requestLayout();
34248
+ }
34066
34249
  }
34067
34250
  set minHeight(minHeight) {
34068
- this.layoutNode.yogaNode.setMinHeight(minHeight);
34069
- this.requestLayout();
34251
+ if (isSizeType(minHeight)) {
34252
+ this.layoutNode.yogaNode.setMinHeight(minHeight);
34253
+ this.requestLayout();
34254
+ }
34070
34255
  }
34071
34256
  set maxHeight(maxHeight) {
34072
- this.layoutNode.yogaNode.setMaxHeight(maxHeight);
34073
- this.requestLayout();
34257
+ if (isSizeType(maxHeight)) {
34258
+ this.layoutNode.yogaNode.setMaxHeight(maxHeight);
34259
+ this.requestLayout();
34260
+ }
34074
34261
  }
34075
34262
  set margin(margin) {
34076
- const node = this.layoutNode.yogaNode;
34077
- if (typeof margin === "object") {
34078
- const { top, right, bottom, left } = margin;
34079
- if (top !== undefined)
34080
- node.setMargin(Edge2.Top, top);
34081
- if (right !== undefined)
34082
- node.setMargin(Edge2.Right, right);
34083
- if (bottom !== undefined)
34084
- node.setMargin(Edge2.Bottom, bottom);
34085
- if (left !== undefined)
34086
- node.setMargin(Edge2.Left, left);
34087
- } else if (margin !== undefined) {
34263
+ if (isMarginType(margin)) {
34264
+ const node = this.layoutNode.yogaNode;
34088
34265
  node.setMargin(Edge2.Top, margin);
34089
34266
  node.setMargin(Edge2.Right, margin);
34090
34267
  node.setMargin(Edge2.Bottom, margin);
34091
34268
  node.setMargin(Edge2.Left, margin);
34269
+ this.requestLayout();
34270
+ }
34271
+ }
34272
+ set marginTop(margin) {
34273
+ if (isMarginType(margin)) {
34274
+ this.layoutNode.yogaNode.setMargin(Edge2.Top, margin);
34275
+ this.requestLayout();
34276
+ }
34277
+ }
34278
+ set marginRight(margin) {
34279
+ if (isMarginType(margin)) {
34280
+ this.layoutNode.yogaNode.setMargin(Edge2.Right, margin);
34281
+ this.requestLayout();
34282
+ }
34283
+ }
34284
+ set marginBottom(margin) {
34285
+ if (isMarginType(margin)) {
34286
+ this.layoutNode.yogaNode.setMargin(Edge2.Bottom, margin);
34287
+ this.requestLayout();
34288
+ }
34289
+ }
34290
+ set marginLeft(margin) {
34291
+ if (isMarginType(margin)) {
34292
+ this.layoutNode.yogaNode.setMargin(Edge2.Left, margin);
34293
+ this.requestLayout();
34092
34294
  }
34093
- this.requestLayout();
34094
34295
  }
34095
34296
  set padding(padding) {
34096
- const node = this.layoutNode.yogaNode;
34097
- if (typeof padding === "object") {
34098
- const { top, right, bottom, left } = padding;
34099
- if (top !== undefined)
34100
- node.setPadding(Edge2.Top, top);
34101
- if (right !== undefined)
34102
- node.setPadding(Edge2.Right, right);
34103
- if (bottom !== undefined)
34104
- node.setPadding(Edge2.Bottom, bottom);
34105
- if (left !== undefined)
34106
- node.setPadding(Edge2.Left, left);
34107
- } else if (padding !== undefined) {
34297
+ if (isPaddingType(padding)) {
34298
+ const node = this.layoutNode.yogaNode;
34108
34299
  node.setPadding(Edge2.Top, padding);
34109
34300
  node.setPadding(Edge2.Right, padding);
34110
34301
  node.setPadding(Edge2.Bottom, padding);
34111
34302
  node.setPadding(Edge2.Left, padding);
34303
+ this.requestLayout();
34304
+ }
34305
+ }
34306
+ set paddingTop(padding) {
34307
+ if (isPaddingType(padding)) {
34308
+ this.layoutNode.yogaNode.setPadding(Edge2.Top, padding);
34309
+ this.requestLayout();
34310
+ }
34311
+ }
34312
+ set paddingRight(padding) {
34313
+ if (isPaddingType(padding)) {
34314
+ this.layoutNode.yogaNode.setPadding(Edge2.Right, padding);
34315
+ this.requestLayout();
34316
+ }
34317
+ }
34318
+ set paddingBottom(padding) {
34319
+ if (isPaddingType(padding)) {
34320
+ this.layoutNode.yogaNode.setPadding(Edge2.Bottom, padding);
34321
+ this.requestLayout();
34322
+ }
34323
+ }
34324
+ set paddingLeft(padding) {
34325
+ if (isPaddingType(padding)) {
34326
+ this.layoutNode.yogaNode.setPadding(Edge2.Left, padding);
34327
+ this.requestLayout();
34112
34328
  }
34113
- this.requestLayout();
34114
34329
  }
34115
34330
  getLayoutNode() {
34116
34331
  return this.layoutNode;
package/Renderable.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { OptimizedBuffer, type RenderContext, type MouseEvent, type SelectionState } from ".";
2
2
  import { EventEmitter } from "events";
3
- import { FlexDirection, Direction, PositionType, Edge, Align, Justify } from "yoga-layout";
4
3
  import { TrackedNode } from "./lib/TrackedNode";
5
4
  import type { ParsedKey } from "./lib/parse.keypress";
6
5
  import { type KeyHandler } from "./lib/KeyHandler";
6
+ import { type AlignString, type FlexDirectionString, type JustifyString, type PositionTypeString } from "./lib/yoga.options";
7
7
  export declare enum LayoutEvents {
8
8
  LAYOUT_CHANGED = "layout-changed",
9
9
  ADDED = "added",
@@ -14,7 +14,6 @@ export declare enum RenderableEvents {
14
14
  FOCUSED = "focused",
15
15
  BLURRED = "blurred"
16
16
  }
17
- export { Justify, Align, FlexDirection, Direction, PositionType, Edge };
18
17
  export interface Position {
19
18
  top?: number | "auto" | `${number}%`;
20
19
  right?: number | "auto" | `${number}%`;
@@ -24,28 +23,29 @@ export interface Position {
24
23
  export interface LayoutOptions {
25
24
  flexGrow?: number;
26
25
  flexShrink?: number;
27
- flexDirection?: FlexDirection;
28
- alignItems?: Align;
29
- justifyContent?: Justify;
26
+ flexDirection?: FlexDirectionString;
27
+ alignItems?: AlignString;
28
+ justifyContent?: JustifyString;
30
29
  flexBasis?: number | "auto" | undefined;
31
- positionType?: "absolute" | "relative";
32
- position?: Position;
30
+ positionType?: PositionTypeString;
31
+ top?: number | "auto" | `${number}%`;
32
+ right?: number | "auto" | `${number}%`;
33
+ bottom?: number | "auto" | `${number}%`;
34
+ left?: number | "auto" | `${number}%`;
33
35
  minWidth?: number;
34
36
  minHeight?: number;
35
37
  maxWidth?: number;
36
38
  maxHeight?: number;
37
- margin?: {
38
- top?: number;
39
- right?: number;
40
- bottom?: number;
41
- left?: number;
42
- } | number | "auto" | `${number}%`;
43
- padding?: {
44
- top?: number;
45
- right?: number;
46
- bottom?: number;
47
- left?: number;
48
- } | number | `${number}%`;
39
+ margin?: number | "auto" | `${number}%`;
40
+ marginTop?: number | "auto" | `${number}%`;
41
+ marginRight?: number | "auto" | `${number}%`;
42
+ marginBottom?: number | "auto" | `${number}%`;
43
+ marginLeft?: number | "auto" | `${number}%`;
44
+ padding?: number | `${number}%`;
45
+ paddingTop?: number | `${number}%`;
46
+ paddingRight?: number | `${number}%`;
47
+ paddingBottom?: number | `${number}%`;
48
+ paddingLeft?: number | `${number}%`;
49
49
  enableLayout?: boolean;
50
50
  }
51
51
  export interface RenderableOptions extends Partial<LayoutOptions> {
@@ -55,6 +55,12 @@ export interface RenderableOptions extends Partial<LayoutOptions> {
55
55
  visible?: boolean;
56
56
  buffered?: boolean;
57
57
  }
58
+ export declare function isMarginType(value: any): value is number | "auto" | `${number}%`;
59
+ export declare function isPaddingType(value: any): value is number | `${number}%`;
60
+ export declare function isPositionType(value: any): value is number | "auto" | `${number}%`;
61
+ export declare function isDimensionType(value: any): value is number | "auto" | `${number}%`;
62
+ export declare function isFlexBasisType(value: any): value is number | "auto" | undefined;
63
+ export declare function isSizeType(value: any): value is number | `${number}%` | undefined;
58
64
  export declare abstract class Renderable extends EventEmitter {
59
65
  static renderablesByNumber: Map<number, Renderable>;
60
66
  readonly id: string;
@@ -77,7 +83,7 @@ export declare abstract class Renderable extends EventEmitter {
77
83
  protected keyHandler: KeyHandler;
78
84
  protected keypressHandler: ((key: ParsedKey) => void) | null;
79
85
  protected layoutNode: TrackedNode;
80
- protected _positionType: "absolute" | "relative";
86
+ protected _positionType: PositionTypeString;
81
87
  protected _position: Position;
82
88
  private renderableMap;
83
89
  private renderableArray;
@@ -100,8 +106,14 @@ export declare abstract class Renderable extends EventEmitter {
100
106
  needsUpdate(): void;
101
107
  get x(): number;
102
108
  set x(value: number);
103
- set top(value: number);
104
- set left(value: number);
109
+ get top(): number | "auto" | `${number}%` | undefined;
110
+ set top(value: number | "auto" | `${number}%` | undefined);
111
+ get right(): number | "auto" | `${number}%` | undefined;
112
+ set right(value: number | "auto" | `${number}%` | undefined);
113
+ get bottom(): number | "auto" | `${number}%` | undefined;
114
+ set bottom(value: number | "auto" | `${number}%` | undefined);
115
+ get left(): number | "auto" | `${number}%` | undefined;
116
+ set left(value: number | "auto" | `${number}%` | undefined);
105
117
  get y(): number;
106
118
  set y(value: number);
107
119
  get width(): number;
@@ -113,20 +125,29 @@ export declare abstract class Renderable extends EventEmitter {
113
125
  requestZIndexSort(): void;
114
126
  private ensureZIndexSorted;
115
127
  private setupYogaProperties;
128
+ private setupMarginAndPadding;
116
129
  setPosition(position: Position): void;
117
130
  private updateYogaPosition;
118
131
  set flexGrow(grow: number);
119
132
  set flexShrink(shrink: number);
120
- set flexDirection(direction: FlexDirection);
121
- set alignItems(alignItems: Align);
122
- set justifyContent(justifyContent: Justify);
133
+ set flexDirection(direction: FlexDirectionString);
134
+ set alignItems(alignItems: AlignString);
135
+ set justifyContent(justifyContent: JustifyString);
123
136
  set flexBasis(basis: number | "auto" | undefined);
124
137
  set minWidth(minWidth: number | `${number}%` | undefined);
125
138
  set maxWidth(maxWidth: number | `${number}%` | undefined);
126
139
  set minHeight(minHeight: number | `${number}%` | undefined);
127
140
  set maxHeight(maxHeight: number | `${number}%` | undefined);
128
- set margin(margin: LayoutOptions["margin"]);
129
- set padding(padding: LayoutOptions["padding"]);
141
+ set margin(margin: number | "auto" | `${number}%` | undefined);
142
+ set marginTop(margin: number | "auto" | `${number}%` | undefined);
143
+ set marginRight(margin: number | "auto" | `${number}%` | undefined);
144
+ set marginBottom(margin: number | "auto" | `${number}%` | undefined);
145
+ set marginLeft(margin: number | "auto" | `${number}%` | undefined);
146
+ set padding(padding: number | `${number}%` | undefined);
147
+ set paddingTop(padding: number | `${number}%` | undefined);
148
+ set paddingRight(padding: number | `${number}%` | undefined);
149
+ set paddingBottom(padding: number | `${number}%` | undefined);
150
+ set paddingLeft(padding: number | `${number}%` | undefined);
130
151
  getLayoutNode(): TrackedNode;
131
152
  updateFromLayout(): void;
132
153
  protected onLayoutResize(width: number, height: number): void;
package/index.js CHANGED
@@ -1989,6 +1989,64 @@ function getKeyHandler() {
1989
1989
  return keyHandler;
1990
1990
  }
1991
1991
 
1992
+ // src/lib/yoga.options.ts
1993
+ function parseAlign(value) {
1994
+ switch (value.toLowerCase()) {
1995
+ case "auto":
1996
+ return Align.Auto;
1997
+ case "flex-start":
1998
+ return Align.FlexStart;
1999
+ case "center":
2000
+ return Align.Center;
2001
+ case "flex-end":
2002
+ return Align.FlexEnd;
2003
+ case "stretch":
2004
+ return Align.Stretch;
2005
+ case "baseline":
2006
+ return Align.Baseline;
2007
+ case "space-between":
2008
+ return Align.SpaceBetween;
2009
+ case "space-around":
2010
+ return Align.SpaceAround;
2011
+ case "space-evenly":
2012
+ return Align.SpaceEvenly;
2013
+ default:
2014
+ return Align.Auto;
2015
+ }
2016
+ }
2017
+ function parseFlexDirection(value) {
2018
+ switch (value.toLowerCase()) {
2019
+ case "column":
2020
+ return FlexDirection.Column;
2021
+ case "column-reverse":
2022
+ return FlexDirection.ColumnReverse;
2023
+ case "row":
2024
+ return FlexDirection.Row;
2025
+ case "row-reverse":
2026
+ return FlexDirection.RowReverse;
2027
+ default:
2028
+ return FlexDirection.Column;
2029
+ }
2030
+ }
2031
+ function parseJustify(value) {
2032
+ switch (value.toLowerCase()) {
2033
+ case "flex-start":
2034
+ return Justify.FlexStart;
2035
+ case "center":
2036
+ return Justify.Center;
2037
+ case "flex-end":
2038
+ return Justify.FlexEnd;
2039
+ case "space-between":
2040
+ return Justify.SpaceBetween;
2041
+ case "space-around":
2042
+ return Justify.SpaceAround;
2043
+ case "space-evenly":
2044
+ return Justify.SpaceEvenly;
2045
+ default:
2046
+ return Justify.FlexStart;
2047
+ }
2048
+ }
2049
+
1992
2050
  // src/Renderable.ts
1993
2051
  var LayoutEvents;
1994
2052
  ((LayoutEvents2) => {
@@ -2015,6 +2073,59 @@ function validateOptions(id, options) {
2015
2073
  }
2016
2074
  }
2017
2075
  }
2076
+ function isValidPercentage(value) {
2077
+ if (typeof value === "string" && value.endsWith("%")) {
2078
+ const numPart = value.slice(0, -1);
2079
+ const num = parseFloat(numPart);
2080
+ return !Number.isNaN(num);
2081
+ }
2082
+ return false;
2083
+ }
2084
+ function isMarginType(value) {
2085
+ if (typeof value === "number" && !Number.isNaN(value)) {
2086
+ return true;
2087
+ }
2088
+ if (value === "auto") {
2089
+ return true;
2090
+ }
2091
+ return isValidPercentage(value);
2092
+ }
2093
+ function isPaddingType(value) {
2094
+ if (typeof value === "number" && !Number.isNaN(value)) {
2095
+ return true;
2096
+ }
2097
+ return isValidPercentage(value);
2098
+ }
2099
+ function isPositionType(value) {
2100
+ if (typeof value === "number" && !Number.isNaN(value)) {
2101
+ return true;
2102
+ }
2103
+ if (value === "auto") {
2104
+ return true;
2105
+ }
2106
+ return isValidPercentage(value);
2107
+ }
2108
+ function isDimensionType(value) {
2109
+ return isPositionType(value);
2110
+ }
2111
+ function isFlexBasisType(value) {
2112
+ if (value === undefined || value === "auto") {
2113
+ return true;
2114
+ }
2115
+ if (typeof value === "number" && !Number.isNaN(value)) {
2116
+ return true;
2117
+ }
2118
+ return false;
2119
+ }
2120
+ function isSizeType(value) {
2121
+ if (value === undefined) {
2122
+ return true;
2123
+ }
2124
+ if (typeof value === "number" && !Number.isNaN(value)) {
2125
+ return true;
2126
+ }
2127
+ return isValidPercentage(value);
2128
+ }
2018
2129
 
2019
2130
  class Renderable extends EventEmitter3 {
2020
2131
  static renderablesByNumber = new Map;
@@ -2136,19 +2247,39 @@ class Renderable extends EventEmitter3 {
2136
2247
  return this._x;
2137
2248
  }
2138
2249
  set x(value) {
2139
- this.setPosition({
2140
- left: value
2141
- });
2250
+ this.left = value;
2251
+ }
2252
+ get top() {
2253
+ return this._position.top;
2142
2254
  }
2143
2255
  set top(value) {
2144
- this.setPosition({
2145
- top: value
2146
- });
2256
+ if (isPositionType(value) || value === undefined) {
2257
+ this.setPosition({ top: value });
2258
+ }
2259
+ }
2260
+ get right() {
2261
+ return this._position.right;
2262
+ }
2263
+ set right(value) {
2264
+ if (isPositionType(value) || value === undefined) {
2265
+ this.setPosition({ right: value });
2266
+ }
2267
+ }
2268
+ get bottom() {
2269
+ return this._position.bottom;
2270
+ }
2271
+ set bottom(value) {
2272
+ if (isPositionType(value) || value === undefined) {
2273
+ this.setPosition({ bottom: value });
2274
+ }
2275
+ }
2276
+ get left() {
2277
+ return this._position.left;
2147
2278
  }
2148
2279
  set left(value) {
2149
- this.setPosition({
2150
- left: value
2151
- });
2280
+ if (isPositionType(value) || value === undefined) {
2281
+ this.setPosition({ left: value });
2282
+ }
2152
2283
  }
2153
2284
  get y() {
2154
2285
  if (this.parent && this._positionType === "relative") {
@@ -2157,25 +2288,27 @@ class Renderable extends EventEmitter3 {
2157
2288
  return this._y;
2158
2289
  }
2159
2290
  set y(value) {
2160
- this.setPosition({
2161
- top: value
2162
- });
2291
+ this.top = value;
2163
2292
  }
2164
2293
  get width() {
2165
2294
  return this._widthValue;
2166
2295
  }
2167
2296
  set width(value) {
2168
- this._width = value;
2169
- this.layoutNode.setWidth(value);
2170
- this.requestLayout();
2297
+ if (isDimensionType(value)) {
2298
+ this._width = value;
2299
+ this.layoutNode.setWidth(value);
2300
+ this.requestLayout();
2301
+ }
2171
2302
  }
2172
2303
  get height() {
2173
2304
  return this._heightValue;
2174
2305
  }
2175
2306
  set height(value) {
2176
- this._height = value;
2177
- this.layoutNode.setHeight(value);
2178
- this.requestLayout();
2307
+ if (isDimensionType(value)) {
2308
+ this._height = value;
2309
+ this.layoutNode.setHeight(value);
2310
+ this.requestLayout();
2311
+ }
2179
2312
  }
2180
2313
  get zIndex() {
2181
2314
  return this._zIndex;
@@ -2197,13 +2330,13 @@ class Renderable extends EventEmitter3 {
2197
2330
  }
2198
2331
  setupYogaProperties(options) {
2199
2332
  const node = this.layoutNode.yogaNode;
2200
- if (options.flexBasis !== undefined) {
2333
+ if (isFlexBasisType(options.flexBasis)) {
2201
2334
  node.setFlexBasis(options.flexBasis);
2202
2335
  }
2203
- if (options.minWidth !== undefined) {
2336
+ if (isSizeType(options.minWidth)) {
2204
2337
  node.setMinWidth(options.minWidth);
2205
2338
  }
2206
- if (options.minHeight !== undefined) {
2339
+ if (isSizeType(options.minHeight)) {
2207
2340
  node.setMinHeight(options.minHeight);
2208
2341
  }
2209
2342
  if (options.flexGrow !== undefined) {
@@ -2218,19 +2351,19 @@ class Renderable extends EventEmitter3 {
2218
2351
  node.setFlexShrink(shrinkValue);
2219
2352
  }
2220
2353
  if (options.flexDirection !== undefined) {
2221
- node.setFlexDirection(options.flexDirection);
2354
+ node.setFlexDirection(parseFlexDirection(options.flexDirection));
2222
2355
  }
2223
2356
  if (options.alignItems !== undefined) {
2224
- node.setAlignItems(options.alignItems);
2357
+ node.setAlignItems(parseAlign(options.alignItems));
2225
2358
  }
2226
2359
  if (options.justifyContent !== undefined) {
2227
- node.setJustifyContent(options.justifyContent);
2360
+ node.setJustifyContent(parseJustify(options.justifyContent));
2228
2361
  }
2229
- if (options.width !== undefined) {
2362
+ if (isDimensionType(options.width)) {
2230
2363
  this._width = options.width;
2231
2364
  this.layoutNode.setWidth(options.width);
2232
2365
  }
2233
- if (options.height !== undefined) {
2366
+ if (isDimensionType(options.height)) {
2234
2367
  this._height = options.height;
2235
2368
  this.layoutNode.setHeight(options.height);
2236
2369
  }
@@ -2238,49 +2371,93 @@ class Renderable extends EventEmitter3 {
2238
2371
  if (this._positionType === "absolute") {
2239
2372
  node.setPositionType(PositionType.Absolute);
2240
2373
  }
2241
- if (options.position) {
2242
- this._position = options.position;
2243
- this.updateYogaPosition(options.position);
2374
+ const hasPositionProps = options.top !== undefined || options.right !== undefined || options.bottom !== undefined || options.left !== undefined;
2375
+ if (hasPositionProps) {
2376
+ this._position = {
2377
+ top: options.top,
2378
+ right: options.right,
2379
+ bottom: options.bottom,
2380
+ left: options.left
2381
+ };
2382
+ this.updateYogaPosition(this._position);
2244
2383
  }
2245
- if (options.maxWidth !== undefined) {
2384
+ if (isSizeType(options.maxWidth)) {
2246
2385
  node.setMaxWidth(options.maxWidth);
2247
2386
  }
2248
- if (options.maxHeight !== undefined) {
2387
+ if (isSizeType(options.maxHeight)) {
2249
2388
  node.setMaxHeight(options.maxHeight);
2250
2389
  }
2251
- this.margin = options.margin;
2252
- this.padding = options.padding;
2390
+ this.setupMarginAndPadding(options);
2391
+ }
2392
+ setupMarginAndPadding(options) {
2393
+ const node = this.layoutNode.yogaNode;
2394
+ if (isMarginType(options.margin)) {
2395
+ node.setMargin(Edge.Top, options.margin);
2396
+ node.setMargin(Edge.Right, options.margin);
2397
+ node.setMargin(Edge.Bottom, options.margin);
2398
+ node.setMargin(Edge.Left, options.margin);
2399
+ }
2400
+ if (isMarginType(options.marginTop)) {
2401
+ node.setMargin(Edge.Top, options.marginTop);
2402
+ }
2403
+ if (isMarginType(options.marginRight)) {
2404
+ node.setMargin(Edge.Right, options.marginRight);
2405
+ }
2406
+ if (isMarginType(options.marginBottom)) {
2407
+ node.setMargin(Edge.Bottom, options.marginBottom);
2408
+ }
2409
+ if (isMarginType(options.marginLeft)) {
2410
+ node.setMargin(Edge.Left, options.marginLeft);
2411
+ }
2412
+ if (isPaddingType(options.padding)) {
2413
+ node.setPadding(Edge.Top, options.padding);
2414
+ node.setPadding(Edge.Right, options.padding);
2415
+ node.setPadding(Edge.Bottom, options.padding);
2416
+ node.setPadding(Edge.Left, options.padding);
2417
+ }
2418
+ if (isPaddingType(options.paddingTop)) {
2419
+ node.setPadding(Edge.Top, options.paddingTop);
2420
+ }
2421
+ if (isPaddingType(options.paddingRight)) {
2422
+ node.setPadding(Edge.Right, options.paddingRight);
2423
+ }
2424
+ if (isPaddingType(options.paddingBottom)) {
2425
+ node.setPadding(Edge.Bottom, options.paddingBottom);
2426
+ }
2427
+ if (isPaddingType(options.paddingLeft)) {
2428
+ node.setPadding(Edge.Left, options.paddingLeft);
2429
+ }
2253
2430
  }
2254
2431
  setPosition(position) {
2255
- this._position = position;
2432
+ this._position = { ...this._position, ...position };
2256
2433
  this.updateYogaPosition(position);
2257
2434
  }
2258
2435
  updateYogaPosition(position) {
2259
2436
  const node = this.layoutNode.yogaNode;
2260
2437
  const { top, right, bottom, left } = position;
2261
2438
  if (this._positionType === "relative") {
2262
- if (top !== undefined) {
2439
+ if (isPositionType(top)) {
2263
2440
  if (top === "auto") {
2264
2441
  node.setPositionAuto(Edge.Top);
2265
2442
  } else {
2266
2443
  node.setPosition(Edge.Top, top);
2267
2444
  }
2268
2445
  }
2269
- if (right !== undefined) {
2446
+ if (isPositionType(right)) {
2270
2447
  if (right === "auto") {
2271
2448
  node.setPositionAuto(Edge.Right);
2272
2449
  } else {
2273
2450
  node.setPosition(Edge.Right, right);
2274
2451
  }
2275
2452
  }
2276
- if (bottom !== undefined) {
2453
+ if (isPositionType(bottom)) {
2277
2454
  if (bottom === "auto") {
2278
2455
  node.setPositionAuto(Edge.Bottom);
2279
2456
  } else {
2280
2457
  node.setPosition(Edge.Bottom, bottom);
2281
2458
  }
2282
2459
  }
2283
- if (left !== undefined) {
2460
+ if (isPositionType(left)) {
2284
2461
  if (left === "auto") {
2285
2462
  node.setPositionAuto(Edge.Left);
2286
2463
  } else {
@@ -2308,76 +2485,114 @@ class Renderable extends EventEmitter3 {
2308
2485
  this.requestLayout();
2309
2486
  }
2310
2487
  set flexDirection(direction) {
2311
- this.layoutNode.yogaNode.setFlexDirection(direction);
2488
+ this.layoutNode.yogaNode.setFlexDirection(parseFlexDirection(direction));
2312
2489
  this.requestLayout();
2313
2490
  }
2314
2491
  set alignItems(alignItems) {
2315
- this.layoutNode.yogaNode.setAlignItems(alignItems);
2492
+ this.layoutNode.yogaNode.setAlignItems(parseAlign(alignItems));
2316
2493
  this.requestLayout();
2317
2494
  }
2318
2495
  set justifyContent(justifyContent) {
2319
- this.layoutNode.yogaNode.setJustifyContent(justifyContent);
2496
+ this.layoutNode.yogaNode.setJustifyContent(parseJustify(justifyContent));
2320
2497
  this.requestLayout();
2321
2498
  }
2322
2499
  set flexBasis(basis) {
2323
- this.layoutNode.yogaNode.setFlexBasis(basis);
2324
- this.requestLayout();
2500
+ if (isFlexBasisType(basis)) {
2501
+ this.layoutNode.yogaNode.setFlexBasis(basis);
2502
+ this.requestLayout();
2503
+ }
2325
2504
  }
2326
2505
  set minWidth(minWidth) {
2327
- this.layoutNode.yogaNode.setMinWidth(minWidth);
2328
- this.requestLayout();
2506
+ if (isSizeType(minWidth)) {
2507
+ this.layoutNode.yogaNode.setMinWidth(minWidth);
2508
+ this.requestLayout();
2509
+ }
2329
2510
  }
2330
2511
  set maxWidth(maxWidth) {
2331
- this.layoutNode.yogaNode.setMaxWidth(maxWidth);
2332
- this.requestLayout();
2512
+ if (isSizeType(maxWidth)) {
2513
+ this.layoutNode.yogaNode.setMaxWidth(maxWidth);
2514
+ this.requestLayout();
2515
+ }
2333
2516
  }
2334
2517
  set minHeight(minHeight) {
2335
- this.layoutNode.yogaNode.setMinHeight(minHeight);
2336
- this.requestLayout();
2518
+ if (isSizeType(minHeight)) {
2519
+ this.layoutNode.yogaNode.setMinHeight(minHeight);
2520
+ this.requestLayout();
2521
+ }
2337
2522
  }
2338
2523
  set maxHeight(maxHeight) {
2339
- this.layoutNode.yogaNode.setMaxHeight(maxHeight);
2340
- this.requestLayout();
2524
+ if (isSizeType(maxHeight)) {
2525
+ this.layoutNode.yogaNode.setMaxHeight(maxHeight);
2526
+ this.requestLayout();
2527
+ }
2341
2528
  }
2342
2529
  set margin(margin) {
2343
- const node = this.layoutNode.yogaNode;
2344
- if (typeof margin === "object") {
2345
- const { top, right, bottom, left } = margin;
2346
- if (top !== undefined)
2347
- node.setMargin(Edge.Top, top);
2348
- if (right !== undefined)
2349
- node.setMargin(Edge.Right, right);
2350
- if (bottom !== undefined)
2351
- node.setMargin(Edge.Bottom, bottom);
2352
- if (left !== undefined)
2353
- node.setMargin(Edge.Left, left);
2354
- } else if (margin !== undefined) {
2530
+ if (isMarginType(margin)) {
2531
+ const node = this.layoutNode.yogaNode;
2355
2532
  node.setMargin(Edge.Top, margin);
2356
2533
  node.setMargin(Edge.Right, margin);
2357
2534
  node.setMargin(Edge.Bottom, margin);
2358
2535
  node.setMargin(Edge.Left, margin);
2536
+ this.requestLayout();
2537
+ }
2538
+ }
2539
+ set marginTop(margin) {
2540
+ if (isMarginType(margin)) {
2541
+ this.layoutNode.yogaNode.setMargin(Edge.Top, margin);
2542
+ this.requestLayout();
2543
+ }
2544
+ }
2545
+ set marginRight(margin) {
2546
+ if (isMarginType(margin)) {
2547
+ this.layoutNode.yogaNode.setMargin(Edge.Right, margin);
2548
+ this.requestLayout();
2549
+ }
2550
+ }
2551
+ set marginBottom(margin) {
2552
+ if (isMarginType(margin)) {
2553
+ this.layoutNode.yogaNode.setMargin(Edge.Bottom, margin);
2554
+ this.requestLayout();
2555
+ }
2556
+ }
2557
+ set marginLeft(margin) {
2558
+ if (isMarginType(margin)) {
2559
+ this.layoutNode.yogaNode.setMargin(Edge.Left, margin);
2560
+ this.requestLayout();
2359
2561
  }
2360
- this.requestLayout();
2361
2562
  }
2362
2563
  set padding(padding) {
2363
- const node = this.layoutNode.yogaNode;
2364
- if (typeof padding === "object") {
2365
- const { top, right, bottom, left } = padding;
2366
- if (top !== undefined)
2367
- node.setPadding(Edge.Top, top);
2368
- if (right !== undefined)
2369
- node.setPadding(Edge.Right, right);
2370
- if (bottom !== undefined)
2371
- node.setPadding(Edge.Bottom, bottom);
2372
- if (left !== undefined)
2373
- node.setPadding(Edge.Left, left);
2374
- } else if (padding !== undefined) {
2564
+ if (isPaddingType(padding)) {
2565
+ const node = this.layoutNode.yogaNode;
2375
2566
  node.setPadding(Edge.Top, padding);
2376
2567
  node.setPadding(Edge.Right, padding);
2377
2568
  node.setPadding(Edge.Bottom, padding);
2378
2569
  node.setPadding(Edge.Left, padding);
2570
+ this.requestLayout();
2571
+ }
2572
+ }
2573
+ set paddingTop(padding) {
2574
+ if (isPaddingType(padding)) {
2575
+ this.layoutNode.yogaNode.setPadding(Edge.Top, padding);
2576
+ this.requestLayout();
2577
+ }
2578
+ }
2579
+ set paddingRight(padding) {
2580
+ if (isPaddingType(padding)) {
2581
+ this.layoutNode.yogaNode.setPadding(Edge.Right, padding);
2582
+ this.requestLayout();
2583
+ }
2584
+ }
2585
+ set paddingBottom(padding) {
2586
+ if (isPaddingType(padding)) {
2587
+ this.layoutNode.yogaNode.setPadding(Edge.Bottom, padding);
2588
+ this.requestLayout();
2589
+ }
2590
+ }
2591
+ set paddingLeft(padding) {
2592
+ if (isPaddingType(padding)) {
2593
+ this.layoutNode.yogaNode.setPadding(Edge.Left, padding);
2594
+ this.requestLayout();
2379
2595
  }
2380
- this.requestLayout();
2381
2596
  }
2382
2597
  getLayoutNode() {
2383
2598
  return this.layoutNode;
@@ -8816,7 +9031,7 @@ Error details:
8816
9031
  }
8817
9032
  // src/renderables/Box.ts
8818
9033
  class BoxRenderable extends Renderable {
8819
- _bg;
9034
+ _backgroundColor;
8820
9035
  _border;
8821
9036
  _borderStyle;
8822
9037
  _borderColor;
@@ -8828,7 +9043,7 @@ class BoxRenderable extends Renderable {
8828
9043
  _titleAlignment;
8829
9044
  constructor(id, options) {
8830
9045
  super(id, options);
8831
- this._bg = parseColor(options.bg || "transparent");
9046
+ this._backgroundColor = parseColor(options.backgroundColor || "transparent");
8832
9047
  this._border = options.border ?? true;
8833
9048
  this._borderStyle = options.borderStyle || "single";
8834
9049
  this._borderColor = parseColor(options.borderColor || "#FFFFFF");
@@ -8840,14 +9055,14 @@ class BoxRenderable extends Renderable {
8840
9055
  this._titleAlignment = options.titleAlignment || "left";
8841
9056
  this.applyYogaBorders();
8842
9057
  }
8843
- get bg() {
8844
- return this._bg;
9058
+ get backgroundColor() {
9059
+ return this._backgroundColor;
8845
9060
  }
8846
- set bg(value) {
9061
+ set backgroundColor(value) {
8847
9062
  if (value) {
8848
9063
  const newColor = parseColor(value);
8849
- if (this._bg !== newColor) {
8850
- this._bg = newColor;
9064
+ if (this._backgroundColor !== newColor) {
9065
+ this._backgroundColor = newColor;
8851
9066
  this.needsUpdate();
8852
9067
  }
8853
9068
  }
@@ -8924,7 +9139,7 @@ class BoxRenderable extends Renderable {
8924
9139
  customBorderChars: this.customBorderChars,
8925
9140
  border: this._border,
8926
9141
  borderColor: currentBorderColor,
8927
- backgroundColor: this._bg,
9142
+ backgroundColor: this._backgroundColor,
8928
9143
  shouldFill: this.shouldFill,
8929
9144
  title: this._title,
8930
9145
  titleAlignment: this._titleAlignment
@@ -10074,6 +10289,12 @@ export {
10074
10289
  magenta,
10075
10290
  loadTemplate,
10076
10291
  italic,
10292
+ isSizeType,
10293
+ isPositionType,
10294
+ isPaddingType,
10295
+ isMarginType,
10296
+ isFlexBasisType,
10297
+ isDimensionType,
10077
10298
  hsvToRgb,
10078
10299
  hexToRgb,
10079
10300
  green,
@@ -10138,21 +10359,16 @@ export {
10138
10359
  RenderableEvents,
10139
10360
  Renderable,
10140
10361
  RGBA,
10141
- PositionType,
10142
10362
  OptimizedBuffer,
10143
10363
  MouseEvent,
10144
10364
  MouseButton,
10145
10365
  LayoutEvents,
10146
10366
  KeyHandler,
10147
- Justify,
10148
10367
  InputRenderableEvents,
10149
10368
  InputRenderable,
10150
10369
  GroupRenderable,
10151
10370
  FrameBufferRenderable,
10152
- FlexDirection,
10153
- Edge,
10154
10371
  DistortionEffect,
10155
- Direction,
10156
10372
  DebugOverlayCorner,
10157
10373
  CliRenderer,
10158
10374
  CliRenderEvents,
@@ -10162,7 +10378,6 @@ export {
10162
10378
  BorderCharArrays,
10163
10379
  BlurEffect,
10164
10380
  BloomEffect,
10165
- Align,
10166
10381
  ASCIIFontSelectionHelper,
10167
10382
  ASCIIFontRenderable
10168
10383
  };
@@ -0,0 +1,31 @@
1
+ import { BoxSizing, Align, Dimension, Direction, Display, Edge, FlexDirection, Gutter, Justify, LogLevel, MeasureMode, Overflow, PositionType, Unit, Wrap } from "yoga-layout";
2
+ export type AlignString = "auto" | "flex-start" | "center" | "flex-end" | "stretch" | "baseline" | "space-between" | "space-around" | "space-evenly";
3
+ export type BoxSizingString = "border-box" | "content-box";
4
+ export type DimensionString = "width" | "height";
5
+ export type DirectionString = "inherit" | "ltr" | "rtl";
6
+ export type DisplayString = "flex" | "none" | "contents";
7
+ export type EdgeString = "left" | "top" | "right" | "bottom" | "start" | "end" | "horizontal" | "vertical" | "all";
8
+ export type FlexDirectionString = "column" | "column-reverse" | "row" | "row-reverse";
9
+ export type GutterString = "column" | "row" | "all";
10
+ export type JustifyString = "flex-start" | "center" | "flex-end" | "space-between" | "space-around" | "space-evenly";
11
+ export type LogLevelString = "error" | "warn" | "info" | "debug" | "verbose" | "fatal";
12
+ export type MeasureModeString = "undefined" | "exactly" | "at-most";
13
+ export type OverflowString = "visible" | "hidden" | "scroll";
14
+ export type PositionTypeString = "static" | "relative" | "absolute";
15
+ export type UnitString = "undefined" | "point" | "percent" | "auto";
16
+ export type WrapString = "no-wrap" | "wrap" | "wrap-reverse";
17
+ export declare function parseAlign(value: string): Align;
18
+ export declare function parseBoxSizing(value: string): BoxSizing;
19
+ export declare function parseDimension(value: string): Dimension;
20
+ export declare function parseDirection(value: string): Direction;
21
+ export declare function parseDisplay(value: string): Display;
22
+ export declare function parseEdge(value: string): Edge;
23
+ export declare function parseFlexDirection(value: string): FlexDirection;
24
+ export declare function parseGutter(value: string): Gutter;
25
+ export declare function parseJustify(value: string): Justify;
26
+ export declare function parseLogLevel(value: string): LogLevel;
27
+ export declare function parseMeasureMode(value: string): MeasureMode;
28
+ export declare function parseOverflow(value: string): Overflow;
29
+ export declare function parsePositionType(value: string): PositionType;
30
+ export declare function parseUnit(value: string): Unit;
31
+ export declare function parseWrap(value: string): Wrap;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",
7
- "version": "0.1.2",
7
+ "version": "0.1.3",
8
8
  "description": "OpenTUI is a TypeScript library for building terminal user interfaces (TUIs)",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -32,11 +32,11 @@
32
32
  "bun-webgpu": "0.1.3",
33
33
  "planck": "^1.4.2",
34
34
  "three": "0.177.0",
35
- "@opentui/core-darwin-x64": "^0.1.2",
36
- "@opentui/core-darwin-arm64": "^0.1.2",
37
- "@opentui/core-linux-x64": "^0.1.2",
38
- "@opentui/core-linux-arm64": "^0.1.2",
39
- "@opentui/core-win32-x64": "^0.1.2",
40
- "@opentui/core-win32-arm64": "^0.1.2"
35
+ "@opentui/core-darwin-x64": "0.1.3",
36
+ "@opentui/core-darwin-arm64": "0.1.3",
37
+ "@opentui/core-linux-x64": "0.1.3",
38
+ "@opentui/core-linux-arm64": "0.1.3",
39
+ "@opentui/core-win32-x64": "0.1.3",
40
+ "@opentui/core-win32-arm64": "0.1.3"
41
41
  }
42
42
  }
@@ -4,7 +4,7 @@ import { RGBA } from "../types";
4
4
  import { type BorderStyle, type BorderSides, type BorderCharacters, type BorderSidesConfig } from "../lib";
5
5
  import type { ColorInput } from "../types";
6
6
  export interface BoxOptions extends RenderableOptions {
7
- bg?: string | RGBA;
7
+ backgroundColor?: string | RGBA;
8
8
  borderStyle?: BorderStyle;
9
9
  border?: boolean | BorderSides[];
10
10
  borderColor?: string | RGBA;
@@ -15,7 +15,7 @@ export interface BoxOptions extends RenderableOptions {
15
15
  focusedBorderColor?: ColorInput;
16
16
  }
17
17
  export declare class BoxRenderable extends Renderable {
18
- protected _bg: RGBA;
18
+ protected _backgroundColor: RGBA;
19
19
  protected _border: boolean | BorderSides[];
20
20
  protected _borderStyle: BorderStyle;
21
21
  protected _borderColor: RGBA;
@@ -26,8 +26,8 @@ export declare class BoxRenderable extends Renderable {
26
26
  protected _title?: string;
27
27
  protected _titleAlignment: "left" | "center" | "right";
28
28
  constructor(id: string, options: BoxOptions);
29
- get bg(): RGBA;
30
- set bg(value: RGBA | string | undefined);
29
+ get backgroundColor(): RGBA;
30
+ set backgroundColor(value: RGBA | string | undefined);
31
31
  get border(): boolean | BorderSides[];
32
32
  set border(value: boolean | BorderSides[]);
33
33
  get borderStyle(): BorderStyle;