@pilates/core 1.0.0-rc.1
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/LICENSE +21 -0
- package/README.md +97 -0
- package/dist/algorithm/axis.d.ts +41 -0
- package/dist/algorithm/axis.d.ts.map +1 -0
- package/dist/algorithm/axis.js +72 -0
- package/dist/algorithm/axis.js.map +1 -0
- package/dist/algorithm/index.d.ts +12 -0
- package/dist/algorithm/index.d.ts.map +1 -0
- package/dist/algorithm/index.js +26 -0
- package/dist/algorithm/index.js.map +1 -0
- package/dist/algorithm/main-axis.d.ts +59 -0
- package/dist/algorithm/main-axis.d.ts.map +1 -0
- package/dist/algorithm/main-axis.js +704 -0
- package/dist/algorithm/main-axis.js.map +1 -0
- package/dist/algorithm/round.d.ts +20 -0
- package/dist/algorithm/round.d.ts.map +1 -0
- package/dist/algorithm/round.js +45 -0
- package/dist/algorithm/round.js.map +1 -0
- package/dist/edge.d.ts +23 -0
- package/dist/edge.d.ts.map +1 -0
- package/dist/edge.js +22 -0
- package/dist/edge.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +15 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +4 -0
- package/dist/layout.js.map +1 -0
- package/dist/measure/ansi.d.ts +15 -0
- package/dist/measure/ansi.d.ts.map +1 -0
- package/dist/measure/ansi.js +118 -0
- package/dist/measure/ansi.js.map +1 -0
- package/dist/measure/grapheme.d.ts +43 -0
- package/dist/measure/grapheme.d.ts.map +1 -0
- package/dist/measure/grapheme.js +169 -0
- package/dist/measure/grapheme.js.map +1 -0
- package/dist/measure/index.d.ts +4 -0
- package/dist/measure/index.d.ts.map +1 -0
- package/dist/measure/index.js +4 -0
- package/dist/measure/index.js.map +1 -0
- package/dist/measure/range-search.d.ts +7 -0
- package/dist/measure/range-search.d.ts.map +1 -0
- package/dist/measure/range-search.js +22 -0
- package/dist/measure/range-search.js.map +1 -0
- package/dist/measure/tables.d.ts +16 -0
- package/dist/measure/tables.d.ts.map +1 -0
- package/dist/measure/tables.js +262 -0
- package/dist/measure/tables.js.map +1 -0
- package/dist/measure/width.d.ts +37 -0
- package/dist/measure/width.d.ts.map +1 -0
- package/dist/measure/width.js +96 -0
- package/dist/measure/width.js.map +1 -0
- package/dist/measure-func.d.ts +24 -0
- package/dist/measure-func.d.ts.map +1 -0
- package/dist/measure-func.js +18 -0
- package/dist/measure-func.js.map +1 -0
- package/dist/node.d.ts +96 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +332 -0
- package/dist/node.js.map +1 -0
- package/dist/style.d.ts +53 -0
- package/dist/style.d.ts.map +1 -0
- package/dist/style.js +40 -0
- package/dist/style.js.map +1 -0
- package/package.json +46 -0
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Node class — the imperative API for building a layout tree.
|
|
3
|
+
*
|
|
4
|
+
* Style setters mirror Yoga's surface and CSS Flexbox semantics. The actual
|
|
5
|
+
* layout algorithm is filled in across milestones M4-M6; in M3, the API
|
|
6
|
+
* surface and tree mutation are complete but `calculateLayout()` throws so
|
|
7
|
+
* that downstream code can lock in against the API while the algorithm is
|
|
8
|
+
* built.
|
|
9
|
+
*
|
|
10
|
+
* Each Node owns:
|
|
11
|
+
* - `style` — mutable style state, see `style.ts`.
|
|
12
|
+
* - `layout` — last computed layout box (left/top/width/height).
|
|
13
|
+
* - `children` — ordered list of child nodes.
|
|
14
|
+
* - `parent` — back-pointer; `null` for the root.
|
|
15
|
+
* - `measure` — optional measure function for leaf intrinsic sizing.
|
|
16
|
+
* - `dirty` — set on style/tree mutation; consumed by the algorithm.
|
|
17
|
+
*/
|
|
18
|
+
import { Edge } from './edge.js';
|
|
19
|
+
import { type ComputedLayout } from './layout.js';
|
|
20
|
+
import type { MeasureFunc } from './measure-func.js';
|
|
21
|
+
import { type Align, type Display, type FlexDirection, type FlexWrap, type Justify, type Length, type PositionType, type Style } from './style.js';
|
|
22
|
+
export declare class Node {
|
|
23
|
+
/** Public-but-internal: read by the layout algorithm and by `getComputedLayout`. */
|
|
24
|
+
readonly style: Style;
|
|
25
|
+
readonly layout: ComputedLayout;
|
|
26
|
+
private readonly _children;
|
|
27
|
+
private _parent;
|
|
28
|
+
private _measure;
|
|
29
|
+
/** True if style or tree has changed since the last `calculateLayout()`. */
|
|
30
|
+
private _dirty;
|
|
31
|
+
/** Construct via `Node.create()` to mirror Yoga's factory style. */
|
|
32
|
+
static create(): Node;
|
|
33
|
+
insertChild(child: Node, index: number): void;
|
|
34
|
+
removeChild(child: Node): void;
|
|
35
|
+
getChild(index: number): Node | undefined;
|
|
36
|
+
getChildCount(): number;
|
|
37
|
+
/** Snapshot of children — mutating the returned array does not affect the tree. */
|
|
38
|
+
getChildren(): Node[];
|
|
39
|
+
getParent(): Node | null;
|
|
40
|
+
isRoot(): boolean;
|
|
41
|
+
setMeasureFunc(fn: MeasureFunc | null): void;
|
|
42
|
+
getMeasureFunc(): MeasureFunc | null;
|
|
43
|
+
setFlexDirection(value: FlexDirection): void;
|
|
44
|
+
setFlexWrap(value: FlexWrap): void;
|
|
45
|
+
/** CSS `flex` shorthand: grow=value, shrink=1, basis=0 (when value > 0). */
|
|
46
|
+
setFlex(value: number): void;
|
|
47
|
+
setFlexGrow(value: number): void;
|
|
48
|
+
setFlexShrink(value: number): void;
|
|
49
|
+
setFlexBasis(value: Length): void;
|
|
50
|
+
setWidth(value: Length): void;
|
|
51
|
+
setHeight(value: Length): void;
|
|
52
|
+
setMinWidth(value: number): void;
|
|
53
|
+
setMinHeight(value: number): void;
|
|
54
|
+
/** Pass `undefined` to remove an upper bound. */
|
|
55
|
+
setMaxWidth(value: number | undefined): void;
|
|
56
|
+
/** Pass `undefined` to remove an upper bound. */
|
|
57
|
+
setMaxHeight(value: number | undefined): void;
|
|
58
|
+
setPadding(edge: Edge, value: number): void;
|
|
59
|
+
setMargin(edge: Edge, value: number): void;
|
|
60
|
+
setGap(axis: 'row' | 'column', value: number): void;
|
|
61
|
+
setJustifyContent(value: Justify): void;
|
|
62
|
+
setAlignItems(value: Align): void;
|
|
63
|
+
setAlignContent(value: Align): void;
|
|
64
|
+
setAlignSelf(value: Align): void;
|
|
65
|
+
setPositionType(value: PositionType): void;
|
|
66
|
+
/** Pass `undefined` to leave that edge unconstrained. */
|
|
67
|
+
setPosition(edge: Edge, value: number | undefined): void;
|
|
68
|
+
setDisplay(value: Display): void;
|
|
69
|
+
/**
|
|
70
|
+
* Compute layout for this node and its descendants.
|
|
71
|
+
*
|
|
72
|
+
* If `availableWidth` / `availableHeight` are omitted the node's own
|
|
73
|
+
* `width` / `height` style is used. If those are also `'auto'` the
|
|
74
|
+
* algorithm treats the missing axis as 0.
|
|
75
|
+
*
|
|
76
|
+
* Implementation lives in `./algorithm/`. This method delegates so that
|
|
77
|
+
* Node remains a focused state holder.
|
|
78
|
+
*/
|
|
79
|
+
calculateLayout(availableWidth?: number, availableHeight?: number): void;
|
|
80
|
+
/**
|
|
81
|
+
* Returns the most recently computed layout box for this node, in cells,
|
|
82
|
+
* relative to the parent's top-left corner.
|
|
83
|
+
*
|
|
84
|
+
* Before `calculateLayout()` has run, all values are 0.
|
|
85
|
+
*/
|
|
86
|
+
getComputedLayout(): ComputedLayout;
|
|
87
|
+
/**
|
|
88
|
+
* Walk up the tree marking every ancestor dirty too. The algorithm uses
|
|
89
|
+
* this hint to short-circuit work in subtrees that did not change.
|
|
90
|
+
*/
|
|
91
|
+
markDirty(): void;
|
|
92
|
+
isDirty(): boolean;
|
|
93
|
+
/** Internal: called by the algorithm once layout is fresh. */
|
|
94
|
+
clearDirty(): void;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings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CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI;IAIxE;;;;;OAKG;IACH,iBAAiB,IAAI,cAAc;IAMnC;;;OAGG;IACH,SAAS,IAAI,IAAI;IAKjB,OAAO,IAAI,OAAO;IAIlB,8DAA8D;IAC9D,UAAU,IAAI,IAAI;CAGnB"}
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Node class — the imperative API for building a layout tree.
|
|
3
|
+
*
|
|
4
|
+
* Style setters mirror Yoga's surface and CSS Flexbox semantics. The actual
|
|
5
|
+
* layout algorithm is filled in across milestones M4-M6; in M3, the API
|
|
6
|
+
* surface and tree mutation are complete but `calculateLayout()` throws so
|
|
7
|
+
* that downstream code can lock in against the API while the algorithm is
|
|
8
|
+
* built.
|
|
9
|
+
*
|
|
10
|
+
* Each Node owns:
|
|
11
|
+
* - `style` — mutable style state, see `style.ts`.
|
|
12
|
+
* - `layout` — last computed layout box (left/top/width/height).
|
|
13
|
+
* - `children` — ordered list of child nodes.
|
|
14
|
+
* - `parent` — back-pointer; `null` for the root.
|
|
15
|
+
* - `measure` — optional measure function for leaf intrinsic sizing.
|
|
16
|
+
* - `dirty` — set on style/tree mutation; consumed by the algorithm.
|
|
17
|
+
*/
|
|
18
|
+
import { calculateLayout as runCalculateLayout } from './algorithm/index.js';
|
|
19
|
+
import { Edge } from './edge.js';
|
|
20
|
+
import { defaultLayout } from './layout.js';
|
|
21
|
+
import { defaultStyle, } from './style.js';
|
|
22
|
+
const TOP = 0;
|
|
23
|
+
const RIGHT = 1;
|
|
24
|
+
const BOTTOM = 2;
|
|
25
|
+
const LEFT = 3;
|
|
26
|
+
function clampNonNegative(n) {
|
|
27
|
+
return n < 0 ? 0 : n;
|
|
28
|
+
}
|
|
29
|
+
function nonNegativeOrThrow(value, name) {
|
|
30
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
31
|
+
throw new RangeError(`${name} must be a finite non-negative number, got ${value}`);
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
export class Node {
|
|
36
|
+
/** Public-but-internal: read by the layout algorithm and by `getComputedLayout`. */
|
|
37
|
+
style = defaultStyle();
|
|
38
|
+
layout = defaultLayout();
|
|
39
|
+
_children = [];
|
|
40
|
+
_parent = null;
|
|
41
|
+
_measure = null;
|
|
42
|
+
/** True if style or tree has changed since the last `calculateLayout()`. */
|
|
43
|
+
_dirty = true;
|
|
44
|
+
/** Construct via `Node.create()` to mirror Yoga's factory style. */
|
|
45
|
+
static create() {
|
|
46
|
+
return new Node();
|
|
47
|
+
}
|
|
48
|
+
// ─── tree mutation ─────────────────────────────────────────────────────
|
|
49
|
+
insertChild(child, index) {
|
|
50
|
+
if (child === this)
|
|
51
|
+
throw new Error('cannot insert a node into itself');
|
|
52
|
+
if (child._parent !== null) {
|
|
53
|
+
throw new Error('child already has a parent; remove it first');
|
|
54
|
+
}
|
|
55
|
+
if (this._measure !== null) {
|
|
56
|
+
throw new Error('cannot add children to a node with a measure function');
|
|
57
|
+
}
|
|
58
|
+
const i = Math.max(0, Math.min(index, this._children.length));
|
|
59
|
+
this._children.splice(i, 0, child);
|
|
60
|
+
child._parent = this;
|
|
61
|
+
this.markDirty();
|
|
62
|
+
}
|
|
63
|
+
removeChild(child) {
|
|
64
|
+
const idx = this._children.indexOf(child);
|
|
65
|
+
if (idx === -1)
|
|
66
|
+
return;
|
|
67
|
+
this._children.splice(idx, 1);
|
|
68
|
+
child._parent = null;
|
|
69
|
+
this.markDirty();
|
|
70
|
+
}
|
|
71
|
+
getChild(index) {
|
|
72
|
+
return this._children[index];
|
|
73
|
+
}
|
|
74
|
+
getChildCount() {
|
|
75
|
+
return this._children.length;
|
|
76
|
+
}
|
|
77
|
+
/** Snapshot of children — mutating the returned array does not affect the tree. */
|
|
78
|
+
getChildren() {
|
|
79
|
+
return this._children.slice();
|
|
80
|
+
}
|
|
81
|
+
getParent() {
|
|
82
|
+
return this._parent;
|
|
83
|
+
}
|
|
84
|
+
isRoot() {
|
|
85
|
+
return this._parent === null;
|
|
86
|
+
}
|
|
87
|
+
// ─── measure function ──────────────────────────────────────────────────
|
|
88
|
+
setMeasureFunc(fn) {
|
|
89
|
+
if (fn !== null && this._children.length > 0) {
|
|
90
|
+
throw new Error('cannot set a measure function on a node with children');
|
|
91
|
+
}
|
|
92
|
+
this._measure = fn;
|
|
93
|
+
this.markDirty();
|
|
94
|
+
}
|
|
95
|
+
getMeasureFunc() {
|
|
96
|
+
return this._measure;
|
|
97
|
+
}
|
|
98
|
+
// ─── flex direction / wrap / flex shorthand ───────────────────────────
|
|
99
|
+
setFlexDirection(value) {
|
|
100
|
+
this.style.flexDirection = value;
|
|
101
|
+
this.markDirty();
|
|
102
|
+
}
|
|
103
|
+
setFlexWrap(value) {
|
|
104
|
+
this.style.flexWrap = value;
|
|
105
|
+
this.markDirty();
|
|
106
|
+
}
|
|
107
|
+
/** CSS `flex` shorthand: grow=value, shrink=1, basis=0 (when value > 0). */
|
|
108
|
+
setFlex(value) {
|
|
109
|
+
if (!Number.isFinite(value))
|
|
110
|
+
throw new RangeError(`flex must be finite, got ${value}`);
|
|
111
|
+
if (value > 0) {
|
|
112
|
+
this.style.flexGrow = value;
|
|
113
|
+
this.style.flexShrink = 1;
|
|
114
|
+
this.style.flexBasis = 0;
|
|
115
|
+
}
|
|
116
|
+
else if (value < 0) {
|
|
117
|
+
this.style.flexGrow = 0;
|
|
118
|
+
this.style.flexShrink = -value;
|
|
119
|
+
this.style.flexBasis = 'auto';
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
this.style.flexGrow = 0;
|
|
123
|
+
this.style.flexShrink = 0;
|
|
124
|
+
this.style.flexBasis = 'auto';
|
|
125
|
+
}
|
|
126
|
+
this.markDirty();
|
|
127
|
+
}
|
|
128
|
+
setFlexGrow(value) {
|
|
129
|
+
this.style.flexGrow = clampNonNegative(value);
|
|
130
|
+
this.markDirty();
|
|
131
|
+
}
|
|
132
|
+
setFlexShrink(value) {
|
|
133
|
+
this.style.flexShrink = clampNonNegative(value);
|
|
134
|
+
this.markDirty();
|
|
135
|
+
}
|
|
136
|
+
setFlexBasis(value) {
|
|
137
|
+
if (value !== 'auto')
|
|
138
|
+
nonNegativeOrThrow(value, 'flexBasis');
|
|
139
|
+
this.style.flexBasis = value;
|
|
140
|
+
this.markDirty();
|
|
141
|
+
}
|
|
142
|
+
// ─── sizing ────────────────────────────────────────────────────────────
|
|
143
|
+
setWidth(value) {
|
|
144
|
+
if (value !== 'auto')
|
|
145
|
+
nonNegativeOrThrow(value, 'width');
|
|
146
|
+
this.style.width = value;
|
|
147
|
+
this.markDirty();
|
|
148
|
+
}
|
|
149
|
+
setHeight(value) {
|
|
150
|
+
if (value !== 'auto')
|
|
151
|
+
nonNegativeOrThrow(value, 'height');
|
|
152
|
+
this.style.height = value;
|
|
153
|
+
this.markDirty();
|
|
154
|
+
}
|
|
155
|
+
setMinWidth(value) {
|
|
156
|
+
this.style.minWidth = nonNegativeOrThrow(value, 'minWidth');
|
|
157
|
+
this.markDirty();
|
|
158
|
+
}
|
|
159
|
+
setMinHeight(value) {
|
|
160
|
+
this.style.minHeight = nonNegativeOrThrow(value, 'minHeight');
|
|
161
|
+
this.markDirty();
|
|
162
|
+
}
|
|
163
|
+
/** Pass `undefined` to remove an upper bound. */
|
|
164
|
+
setMaxWidth(value) {
|
|
165
|
+
if (value !== undefined)
|
|
166
|
+
nonNegativeOrThrow(value, 'maxWidth');
|
|
167
|
+
this.style.maxWidth = value;
|
|
168
|
+
this.markDirty();
|
|
169
|
+
}
|
|
170
|
+
/** Pass `undefined` to remove an upper bound. */
|
|
171
|
+
setMaxHeight(value) {
|
|
172
|
+
if (value !== undefined)
|
|
173
|
+
nonNegativeOrThrow(value, 'maxHeight');
|
|
174
|
+
this.style.maxHeight = value;
|
|
175
|
+
this.markDirty();
|
|
176
|
+
}
|
|
177
|
+
// ─── padding / margin / gap ────────────────────────────────────────────
|
|
178
|
+
setPadding(edge, value) {
|
|
179
|
+
nonNegativeOrThrow(value, 'padding');
|
|
180
|
+
writeEdge(this.style.padding, edge, value);
|
|
181
|
+
this.markDirty();
|
|
182
|
+
}
|
|
183
|
+
setMargin(edge, value) {
|
|
184
|
+
nonNegativeOrThrow(value, 'margin');
|
|
185
|
+
writeEdge(this.style.margin, edge, value);
|
|
186
|
+
this.markDirty();
|
|
187
|
+
}
|
|
188
|
+
setGap(axis, value) {
|
|
189
|
+
nonNegativeOrThrow(value, 'gap');
|
|
190
|
+
if (axis === 'row')
|
|
191
|
+
this.style.gapRow = value;
|
|
192
|
+
else
|
|
193
|
+
this.style.gapColumn = value;
|
|
194
|
+
this.markDirty();
|
|
195
|
+
}
|
|
196
|
+
// ─── alignment ─────────────────────────────────────────────────────────
|
|
197
|
+
setJustifyContent(value) {
|
|
198
|
+
this.style.justifyContent = value;
|
|
199
|
+
this.markDirty();
|
|
200
|
+
}
|
|
201
|
+
setAlignItems(value) {
|
|
202
|
+
this.style.alignItems = value;
|
|
203
|
+
this.markDirty();
|
|
204
|
+
}
|
|
205
|
+
setAlignContent(value) {
|
|
206
|
+
this.style.alignContent = value;
|
|
207
|
+
this.markDirty();
|
|
208
|
+
}
|
|
209
|
+
setAlignSelf(value) {
|
|
210
|
+
this.style.alignSelf = value;
|
|
211
|
+
this.markDirty();
|
|
212
|
+
}
|
|
213
|
+
// ─── positioning ───────────────────────────────────────────────────────
|
|
214
|
+
setPositionType(value) {
|
|
215
|
+
this.style.positionType = value;
|
|
216
|
+
this.markDirty();
|
|
217
|
+
}
|
|
218
|
+
/** Pass `undefined` to leave that edge unconstrained. */
|
|
219
|
+
setPosition(edge, value) {
|
|
220
|
+
if (value !== undefined && !Number.isFinite(value)) {
|
|
221
|
+
throw new RangeError(`position must be finite or undefined, got ${value}`);
|
|
222
|
+
}
|
|
223
|
+
writePositionEdge(this.style.position, edge, value);
|
|
224
|
+
this.markDirty();
|
|
225
|
+
}
|
|
226
|
+
// ─── display ───────────────────────────────────────────────────────────
|
|
227
|
+
setDisplay(value) {
|
|
228
|
+
this.style.display = value;
|
|
229
|
+
this.markDirty();
|
|
230
|
+
}
|
|
231
|
+
// ─── layout entry points ───────────────────────────────────────────────
|
|
232
|
+
/**
|
|
233
|
+
* Compute layout for this node and its descendants.
|
|
234
|
+
*
|
|
235
|
+
* If `availableWidth` / `availableHeight` are omitted the node's own
|
|
236
|
+
* `width` / `height` style is used. If those are also `'auto'` the
|
|
237
|
+
* algorithm treats the missing axis as 0.
|
|
238
|
+
*
|
|
239
|
+
* Implementation lives in `./algorithm/`. This method delegates so that
|
|
240
|
+
* Node remains a focused state holder.
|
|
241
|
+
*/
|
|
242
|
+
calculateLayout(availableWidth, availableHeight) {
|
|
243
|
+
runCalculateLayout(this, availableWidth, availableHeight);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Returns the most recently computed layout box for this node, in cells,
|
|
247
|
+
* relative to the parent's top-left corner.
|
|
248
|
+
*
|
|
249
|
+
* Before `calculateLayout()` has run, all values are 0.
|
|
250
|
+
*/
|
|
251
|
+
getComputedLayout() {
|
|
252
|
+
return { ...this.layout };
|
|
253
|
+
}
|
|
254
|
+
// ─── dirty tracking ────────────────────────────────────────────────────
|
|
255
|
+
/**
|
|
256
|
+
* Walk up the tree marking every ancestor dirty too. The algorithm uses
|
|
257
|
+
* this hint to short-circuit work in subtrees that did not change.
|
|
258
|
+
*/
|
|
259
|
+
markDirty() {
|
|
260
|
+
this._dirty = true;
|
|
261
|
+
if (this._parent !== null && !this._parent._dirty)
|
|
262
|
+
this._parent.markDirty();
|
|
263
|
+
}
|
|
264
|
+
isDirty() {
|
|
265
|
+
return this._dirty;
|
|
266
|
+
}
|
|
267
|
+
/** Internal: called by the algorithm once layout is fresh. */
|
|
268
|
+
clearDirty() {
|
|
269
|
+
this._dirty = false;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function writeEdge(box, edge, value) {
|
|
273
|
+
switch (edge) {
|
|
274
|
+
case Edge.Top:
|
|
275
|
+
box[TOP] = value;
|
|
276
|
+
return;
|
|
277
|
+
case Edge.Right:
|
|
278
|
+
box[RIGHT] = value;
|
|
279
|
+
return;
|
|
280
|
+
case Edge.Bottom:
|
|
281
|
+
box[BOTTOM] = value;
|
|
282
|
+
return;
|
|
283
|
+
case Edge.Left:
|
|
284
|
+
box[LEFT] = value;
|
|
285
|
+
return;
|
|
286
|
+
case Edge.Horizontal:
|
|
287
|
+
box[LEFT] = value;
|
|
288
|
+
box[RIGHT] = value;
|
|
289
|
+
return;
|
|
290
|
+
case Edge.Vertical:
|
|
291
|
+
box[TOP] = value;
|
|
292
|
+
box[BOTTOM] = value;
|
|
293
|
+
return;
|
|
294
|
+
case Edge.All:
|
|
295
|
+
box[TOP] = value;
|
|
296
|
+
box[RIGHT] = value;
|
|
297
|
+
box[BOTTOM] = value;
|
|
298
|
+
box[LEFT] = value;
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function writePositionEdge(box, edge, value) {
|
|
303
|
+
switch (edge) {
|
|
304
|
+
case Edge.Top:
|
|
305
|
+
box[TOP] = value;
|
|
306
|
+
return;
|
|
307
|
+
case Edge.Right:
|
|
308
|
+
box[RIGHT] = value;
|
|
309
|
+
return;
|
|
310
|
+
case Edge.Bottom:
|
|
311
|
+
box[BOTTOM] = value;
|
|
312
|
+
return;
|
|
313
|
+
case Edge.Left:
|
|
314
|
+
box[LEFT] = value;
|
|
315
|
+
return;
|
|
316
|
+
case Edge.Horizontal:
|
|
317
|
+
box[LEFT] = value;
|
|
318
|
+
box[RIGHT] = value;
|
|
319
|
+
return;
|
|
320
|
+
case Edge.Vertical:
|
|
321
|
+
box[TOP] = value;
|
|
322
|
+
box[BOTTOM] = value;
|
|
323
|
+
return;
|
|
324
|
+
case Edge.All:
|
|
325
|
+
box[TOP] = value;
|
|
326
|
+
box[RIGHT] = value;
|
|
327
|
+
box[BOTTOM] = value;
|
|
328
|
+
box[LEFT] = value;
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,eAAe,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAuB,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,EASL,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,MAAM,IAAI,GAAG,CAAC,CAAC;AAEf,SAAS,gBAAgB,CAAC,CAAS;IACjC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa,EAAE,IAAY;IACrD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,8CAA8C,KAAK,EAAE,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,OAAO,IAAI;IACf,oFAAoF;IAC3E,KAAK,GAAU,YAAY,EAAE,CAAC;IAC9B,MAAM,GAAmB,aAAa,EAAE,CAAC;IAEjC,SAAS,GAAW,EAAE,CAAC;IAChC,OAAO,GAAgB,IAAI,CAAC;IAC5B,QAAQ,GAAuB,IAAI,CAAC;IAC5C,4EAA4E;IACpE,MAAM,GAAG,IAAI,CAAC;IAEtB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,KAAK,CAAC,GAAG,KAAK,CAAC;YACnB,OAAO;QACT,KAAK,IAAI,CAAC,QAAQ;YAChB,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACjB,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;YACpB,OAAO;QACT,KAAK,IAAI,CAAC,GAAG;YACX,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACjB,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;YACnB,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;YACpB,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;YAClB,OAAO;IACX,CAAC;AACH,CAAC"}
|
package/dist/style.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style types and defaults for the layout engine.
|
|
3
|
+
*
|
|
4
|
+
* The shape mirrors a subset of CSS Flexbox plus a few terminal-specific
|
|
5
|
+
* choices (no aspect-ratio, no RTL direction, no baseline alignment in v1).
|
|
6
|
+
*
|
|
7
|
+
* String-literal unions are preferred over numeric enums so that user code
|
|
8
|
+
* reads naturally: `node.setFlexDirection('row')`. Internally we still
|
|
9
|
+
* compare against these strings — the cost is negligible relative to the
|
|
10
|
+
* layout work.
|
|
11
|
+
*/
|
|
12
|
+
export type FlexDirection = 'row' | 'column' | 'row-reverse' | 'column-reverse';
|
|
13
|
+
export type FlexWrap = 'nowrap' | 'wrap' | 'wrap-reverse';
|
|
14
|
+
export type Justify = 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'space-evenly';
|
|
15
|
+
export type Align = 'auto' | 'flex-start' | 'flex-end' | 'center' | 'stretch' | 'space-between' | 'space-around';
|
|
16
|
+
export type PositionType = 'relative' | 'absolute';
|
|
17
|
+
export type Display = 'flex' | 'none';
|
|
18
|
+
/** A length value in terminal cells, or 'auto' to size from content / flex. */
|
|
19
|
+
export type Length = number | 'auto';
|
|
20
|
+
/**
|
|
21
|
+
* Internal style state. Each `Node` owns one of these and mutates it via
|
|
22
|
+
* setters. Defaults match Yoga + CSS Flexbox where applicable.
|
|
23
|
+
*/
|
|
24
|
+
export interface Style {
|
|
25
|
+
flexDirection: FlexDirection;
|
|
26
|
+
flexWrap: FlexWrap;
|
|
27
|
+
flexGrow: number;
|
|
28
|
+
flexShrink: number;
|
|
29
|
+
flexBasis: Length;
|
|
30
|
+
width: Length;
|
|
31
|
+
height: Length;
|
|
32
|
+
minWidth: number;
|
|
33
|
+
minHeight: number;
|
|
34
|
+
/** undefined means "no upper bound". */
|
|
35
|
+
maxWidth: number | undefined;
|
|
36
|
+
maxHeight: number | undefined;
|
|
37
|
+
/** [top, right, bottom, left]. */
|
|
38
|
+
padding: [number, number, number, number];
|
|
39
|
+
/** [top, right, bottom, left]. */
|
|
40
|
+
margin: [number, number, number, number];
|
|
41
|
+
gapRow: number;
|
|
42
|
+
gapColumn: number;
|
|
43
|
+
justifyContent: Justify;
|
|
44
|
+
alignItems: Align;
|
|
45
|
+
alignContent: Align;
|
|
46
|
+
alignSelf: Align;
|
|
47
|
+
positionType: PositionType;
|
|
48
|
+
/** [top, right, bottom, left]; undefined means "edge unconstrained". */
|
|
49
|
+
position: [number | undefined, number | undefined, number | undefined, number | undefined];
|
|
50
|
+
display: Display;
|
|
51
|
+
}
|
|
52
|
+
export declare function defaultStyle(): Style;
|
|
53
|
+
//# sourceMappingURL=style.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,QAAQ,GAAG,aAAa,GAAG,gBAAgB,CAAC;AAEhF,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,cAAc,CAAC;AAE1D,MAAM,MAAM,OAAO,GACf,YAAY,GACZ,UAAU,GACV,QAAQ,GACR,eAA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,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAE3F,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,YAAY,IAAI,KAAK,CAgCpC"}
|
package/dist/style.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style types and defaults for the layout engine.
|
|
3
|
+
*
|
|
4
|
+
* The shape mirrors a subset of CSS Flexbox plus a few terminal-specific
|
|
5
|
+
* choices (no aspect-ratio, no RTL direction, no baseline alignment in v1).
|
|
6
|
+
*
|
|
7
|
+
* String-literal unions are preferred over numeric enums so that user code
|
|
8
|
+
* reads naturally: `node.setFlexDirection('row')`. Internally we still
|
|
9
|
+
* compare against these strings — the cost is negligible relative to the
|
|
10
|
+
* layout work.
|
|
11
|
+
*/
|
|
12
|
+
export function defaultStyle() {
|
|
13
|
+
return {
|
|
14
|
+
flexDirection: 'column',
|
|
15
|
+
flexWrap: 'nowrap',
|
|
16
|
+
flexGrow: 0,
|
|
17
|
+
// Yoga / React Native default rather than CSS spec's 1 — avoids surprise
|
|
18
|
+
// shrinking when a designer just declares a width.
|
|
19
|
+
flexShrink: 0,
|
|
20
|
+
flexBasis: 'auto',
|
|
21
|
+
width: 'auto',
|
|
22
|
+
height: 'auto',
|
|
23
|
+
minWidth: 0,
|
|
24
|
+
minHeight: 0,
|
|
25
|
+
maxWidth: undefined,
|
|
26
|
+
maxHeight: undefined,
|
|
27
|
+
padding: [0, 0, 0, 0],
|
|
28
|
+
margin: [0, 0, 0, 0],
|
|
29
|
+
gapRow: 0,
|
|
30
|
+
gapColumn: 0,
|
|
31
|
+
justifyContent: 'flex-start',
|
|
32
|
+
alignItems: 'stretch',
|
|
33
|
+
alignContent: 'flex-start',
|
|
34
|
+
alignSelf: 'auto',
|
|
35
|
+
positionType: 'relative',
|
|
36
|
+
position: [undefined, undefined, undefined, undefined],
|
|
37
|
+
display: 'flex',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.js","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoEH,MAAM,UAAU,YAAY;IAC1B,OAAO;QACL,aAAa,EAAE,QAAQ;QACvB,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,CAAC;QACX,yEAAyE;QACzE,mDAAmD;QACnD,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,MAAM;QAEjB,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;QACd,QAAQ,EAAE,CAAC;QACX,SAAS,EAAE,CAAC;QACZ,QAAQ,EAAE,SAAS;QACnB,SAAS,EAAE,SAAS;QAEpB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACrB,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACpB,MAAM,EAAE,CAAC;QACT,SAAS,EAAE,CAAC;QAEZ,cAAc,EAAE,YAAY;QAC5B,UAAU,EAAE,SAAS;QACrB,YAAY,EAAE,YAAY;QAC1B,SAAS,EAAE,MAAM;QAEjB,YAAY,EAAE,UAAU;QACxB,QAAQ,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC;QAEtD,OAAO,EAAE,MAAM;KAChB,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pilates/core",
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
|
+
"description": "Headless flex layout engine for terminal UIs. Pure TypeScript, zero dependencies.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/pilates-dev/pilates.git",
|
|
23
|
+
"directory": "packages/core"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/pilates-dev/pilates#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/pilates-dev/pilates/issues"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"terminal",
|
|
31
|
+
"tui",
|
|
32
|
+
"cli",
|
|
33
|
+
"layout",
|
|
34
|
+
"flexbox",
|
|
35
|
+
"yoga",
|
|
36
|
+
"headless"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -b",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
45
|
+
}
|
|
46
|
+
}
|