taffy-wasm 0.9.4 → 0.9.5
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/README.md +16 -29
- package/package.json +1 -1
- package/taffy_wasm.d.ts +11 -11
- package/taffy_wasm.js +20 -20
- package/taffy_wasm_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -44,18 +44,13 @@ async function main() {
|
|
|
44
44
|
containerStyle.display = Display.Flex;
|
|
45
45
|
containerStyle.flexDirection = FlexDirection.Column;
|
|
46
46
|
containerStyle.alignItems = AlignItems.Center;
|
|
47
|
-
containerStyle.size = { width:
|
|
48
|
-
containerStyle.padding = {
|
|
49
|
-
left: { Length: 10 },
|
|
50
|
-
right: { Length: 10 },
|
|
51
|
-
top: { Length: 10 },
|
|
52
|
-
bottom: { Length: 10 },
|
|
53
|
-
};
|
|
47
|
+
containerStyle.size = { width: 300, height: 200 };
|
|
48
|
+
containerStyle.padding = { left: 10, right: 10, top: 10, bottom: 10 };
|
|
54
49
|
|
|
55
50
|
// Create child styles
|
|
56
51
|
const childStyle = new Style();
|
|
57
52
|
childStyle.flexGrow = 1;
|
|
58
|
-
childStyle.size = { width:
|
|
53
|
+
childStyle.size = { width: "100%", height: "auto" };
|
|
59
54
|
|
|
60
55
|
// Create nodes
|
|
61
56
|
const child1 = tree.newLeaf(childStyle);
|
|
@@ -66,10 +61,7 @@ async function main() {
|
|
|
66
61
|
);
|
|
67
62
|
|
|
68
63
|
// Compute layout
|
|
69
|
-
tree.computeLayout(container, {
|
|
70
|
-
width: { Definite: 300 },
|
|
71
|
-
height: { Definite: 200 },
|
|
72
|
-
});
|
|
64
|
+
tree.computeLayout(container, { width: 300, height: 200 });
|
|
73
65
|
|
|
74
66
|
// Read computed layouts
|
|
75
67
|
const containerLayout = tree.getLayout(container);
|
|
@@ -311,10 +303,10 @@ enum BoxSizing {
|
|
|
311
303
|
### Types
|
|
312
304
|
|
|
313
305
|
```typescript
|
|
314
|
-
// Dimension values
|
|
315
|
-
type Dimension =
|
|
316
|
-
type LengthPercentage =
|
|
317
|
-
type LengthPercentageAuto =
|
|
306
|
+
// Dimension values (CSS-like syntax)
|
|
307
|
+
type Dimension = number | `${number}%` | "auto"; // e.g., 100, "50%", "auto"
|
|
308
|
+
type LengthPercentage = number | `${number}%`; // e.g., 10, "25%"
|
|
309
|
+
type LengthPercentageAuto = number | `${number}%` | "auto";
|
|
318
310
|
|
|
319
311
|
// Geometry
|
|
320
312
|
interface Size<T> {
|
|
@@ -333,7 +325,7 @@ interface Point<T> {
|
|
|
333
325
|
}
|
|
334
326
|
|
|
335
327
|
// Available space for layout computation
|
|
336
|
-
type AvailableSpace =
|
|
328
|
+
type AvailableSpace = number | "MinContent" | "MaxContent";
|
|
337
329
|
|
|
338
330
|
// Measure function for custom content measurement
|
|
339
331
|
type MeasureFunction = (
|
|
@@ -354,7 +346,7 @@ const textNode = tree.newLeafWithContext(textStyle, { text: "Hello, World!" });
|
|
|
354
346
|
|
|
355
347
|
tree.computeLayoutWithMeasure(
|
|
356
348
|
rootNode,
|
|
357
|
-
{ width:
|
|
349
|
+
{ width: 800, height: "MaxContent" },
|
|
358
350
|
(known, available, node, context, style) => {
|
|
359
351
|
if (context?.text) {
|
|
360
352
|
// Your text measurement logic here
|
|
@@ -399,7 +391,7 @@ const rowStyle = new Style();
|
|
|
399
391
|
rowStyle.display = Display.Flex;
|
|
400
392
|
rowStyle.flexDirection = FlexDirection.Row;
|
|
401
393
|
rowStyle.justifyContent = JustifyContent.SpaceBetween;
|
|
402
|
-
rowStyle.gap = { width:
|
|
394
|
+
rowStyle.gap = { width: 10, height: 0 };
|
|
403
395
|
```
|
|
404
396
|
|
|
405
397
|
### Absolute Positioning
|
|
@@ -407,13 +399,8 @@ rowStyle.gap = { width: { Length: 10 }, height: { Length: 0 } };
|
|
|
407
399
|
```javascript
|
|
408
400
|
const absoluteStyle = new Style();
|
|
409
401
|
absoluteStyle.position = Position.Absolute;
|
|
410
|
-
absoluteStyle.inset = {
|
|
411
|
-
|
|
412
|
-
top: { Length: 10 },
|
|
413
|
-
right: "Auto",
|
|
414
|
-
bottom: "Auto",
|
|
415
|
-
};
|
|
416
|
-
absoluteStyle.size = { width: { Length: 100 }, height: { Length: 50 } };
|
|
402
|
+
absoluteStyle.inset = { left: 10, top: 10, right: "auto", bottom: "auto" };
|
|
403
|
+
absoluteStyle.size = { width: 100, height: 50 };
|
|
417
404
|
```
|
|
418
405
|
|
|
419
406
|
### Percentage Sizing
|
|
@@ -421,8 +408,8 @@ absoluteStyle.size = { width: { Length: 100 }, height: { Length: 50 } };
|
|
|
421
408
|
```javascript
|
|
422
409
|
const percentStyle = new Style();
|
|
423
410
|
percentStyle.size = {
|
|
424
|
-
width:
|
|
425
|
-
height:
|
|
411
|
+
width: "50%", // 50% of parent
|
|
412
|
+
height: "100%", // 100% of parent
|
|
426
413
|
};
|
|
427
414
|
```
|
|
428
415
|
|
|
@@ -430,7 +417,7 @@ percentStyle.size = {
|
|
|
430
417
|
|
|
431
418
|
```bash
|
|
432
419
|
# Clone the repository
|
|
433
|
-
git clone https://github.com/
|
|
420
|
+
git clone https://github.com/ByteLandTechnology/taffy-js.git
|
|
434
421
|
cd taffy-js
|
|
435
422
|
|
|
436
423
|
# Install dependencies
|
package/package.json
CHANGED
package/taffy_wasm.d.ts
CHANGED
|
@@ -56,8 +56,8 @@ export type AvailableSpace = number | "minContent" | "maxContent";
|
|
|
56
56
|
* const pixelSize: Size<number> = { width: 200, height: 100 };
|
|
57
57
|
*
|
|
58
58
|
* const dimensionSize: Size<Dimension> = {
|
|
59
|
-
* width:
|
|
60
|
-
* height:
|
|
59
|
+
* width: 200,
|
|
60
|
+
* height: "50%"
|
|
61
61
|
* };
|
|
62
62
|
*
|
|
63
63
|
* const availableSize: Size<AvailableSpace> = {
|
|
@@ -981,8 +981,8 @@ export enum Position {
|
|
|
981
981
|
* - `flexGrow`: `0`
|
|
982
982
|
* - `flexShrink`: `1`
|
|
983
983
|
* - All alignment properties: `undefined` (use default behavior)
|
|
984
|
-
* - All dimensions: `"
|
|
985
|
-
* - All spacing: `
|
|
984
|
+
* - All dimensions: `"auto"`
|
|
985
|
+
* - All spacing: `0`
|
|
986
986
|
*
|
|
987
987
|
*/
|
|
988
988
|
export class Style {
|
|
@@ -1023,7 +1023,7 @@ export class Style {
|
|
|
1023
1023
|
*
|
|
1024
1024
|
* The initial size of a flex item before growing/shrinking.
|
|
1025
1025
|
*
|
|
1026
|
-
* @returns - A `Dimension` value (`
|
|
1026
|
+
* @returns - A `Dimension` value (`number`, `\"{number}%\"`, or `\"auto\"`)
|
|
1027
1027
|
*/
|
|
1028
1028
|
flexBasis: Dimension;
|
|
1029
1029
|
/**
|
|
@@ -1342,10 +1342,10 @@ export class TaffyTree {
|
|
|
1342
1342
|
* @example
|
|
1343
1343
|
* ```typescript
|
|
1344
1344
|
* // Fixed size container
|
|
1345
|
-
* { width:
|
|
1345
|
+
* { width: 800, height: 600 }
|
|
1346
1346
|
*
|
|
1347
1347
|
* // Flexible width, fixed height
|
|
1348
|
-
* { width: "MaxContent", height:
|
|
1348
|
+
* { width: "MaxContent", height: 600 }
|
|
1349
1349
|
*
|
|
1350
1350
|
* // Minimum content size
|
|
1351
1351
|
* { width: "MinContent", height: "MinContent" }
|
|
@@ -1355,7 +1355,7 @@ export class TaffyTree {
|
|
|
1355
1355
|
*
|
|
1356
1356
|
* @example
|
|
1357
1357
|
* ```typescript
|
|
1358
|
-
* tree.computeLayout(rootId, { width:
|
|
1358
|
+
* tree.computeLayout(rootId, { width: 800, height: 600 });
|
|
1359
1359
|
* ```
|
|
1360
1360
|
*/
|
|
1361
1361
|
computeLayout(node: bigint, available_space: Size<AvailableSpace>): void;
|
|
@@ -1609,7 +1609,7 @@ export class TaffyTree {
|
|
|
1609
1609
|
* ```typescript
|
|
1610
1610
|
* tree.computeLayoutWithMeasure(
|
|
1611
1611
|
* rootId,
|
|
1612
|
-
* { width:
|
|
1612
|
+
* { width: 800, height: "MaxContent" },
|
|
1613
1613
|
* (known, available, node, context, style) => {
|
|
1614
1614
|
* if (context?.text) {
|
|
1615
1615
|
* const measured = measureText(context.text, available.width);
|
|
@@ -1713,7 +1713,7 @@ export class TaffyTree {
|
|
|
1713
1713
|
*
|
|
1714
1714
|
* @example
|
|
1715
1715
|
* ```typescript
|
|
1716
|
-
* tree.computeLayout(rootId, { width:
|
|
1716
|
+
* tree.computeLayout(rootId, { width: 800, height: 600 });
|
|
1717
1717
|
* const layout: Layout = tree.getLayout(nodeId);
|
|
1718
1718
|
* console.log(`Position: (${layout.x}, ${layout.y}), Size: ${layout.width}x${layout.height}`);
|
|
1719
1719
|
* ```
|
|
@@ -1782,7 +1782,7 @@ export class TaffyTree {
|
|
|
1782
1782
|
* @example
|
|
1783
1783
|
* ```typescript
|
|
1784
1784
|
* const style = new Style();
|
|
1785
|
-
* style.size = { width:
|
|
1785
|
+
* style.size = { width: 100, height: 50 };
|
|
1786
1786
|
* const nodeId: bigint = tree.newLeaf(style);
|
|
1787
1787
|
* ```
|
|
1788
1788
|
*/
|
package/taffy_wasm.js
CHANGED
|
@@ -918,8 +918,8 @@ export const Position = Object.freeze({
|
|
|
918
918
|
* - `flexGrow`: `0`
|
|
919
919
|
* - `flexShrink`: `1`
|
|
920
920
|
* - All alignment properties: `undefined` (use default behavior)
|
|
921
|
-
* - All dimensions: `"
|
|
922
|
-
* - All spacing: `
|
|
921
|
+
* - All dimensions: `"auto"`
|
|
922
|
+
* - All spacing: `0`
|
|
923
923
|
*/
|
|
924
924
|
export class Style {
|
|
925
925
|
static __wrap(ptr) {
|
|
@@ -970,7 +970,7 @@ export class Style {
|
|
|
970
970
|
*
|
|
971
971
|
* The initial size of a flex item before growing/shrinking.
|
|
972
972
|
*
|
|
973
|
-
* @returns - A `Dimension` value (`
|
|
973
|
+
* @returns - A `Dimension` value (`number`, `\"{number}%\"`, or `\"auto\"`)
|
|
974
974
|
* @returns {Dimension}
|
|
975
975
|
*/
|
|
976
976
|
get flexBasis() {
|
|
@@ -984,7 +984,7 @@ export class Style {
|
|
|
984
984
|
*
|
|
985
985
|
* @example
|
|
986
986
|
* ```typescript
|
|
987
|
-
* style.border = { left:
|
|
987
|
+
* style.border = { left: 1, right: 1, top: 1, bottom: 1 };
|
|
988
988
|
* ```
|
|
989
989
|
* @param {Rect<LengthPercentage>} val
|
|
990
990
|
*/
|
|
@@ -998,7 +998,7 @@ export class Style {
|
|
|
998
998
|
*
|
|
999
999
|
* @example
|
|
1000
1000
|
* ```typescript
|
|
1001
|
-
* style.margin = { left:
|
|
1001
|
+
* style.margin = { left: 10, right: 10, top: 5, bottom: 5 };
|
|
1002
1002
|
* ```
|
|
1003
1003
|
* @param {Rect<LengthPercentageAuto>} val
|
|
1004
1004
|
*/
|
|
@@ -1053,7 +1053,7 @@ export class Style {
|
|
|
1053
1053
|
*
|
|
1054
1054
|
* @example
|
|
1055
1055
|
* ```typescript
|
|
1056
|
-
* style.padding = { left:
|
|
1056
|
+
* style.padding = { left: 20, right: 20, top: 10, bottom: 10 };
|
|
1057
1057
|
* ```
|
|
1058
1058
|
* @param {Rect<LengthPercentage>} val
|
|
1059
1059
|
*/
|
|
@@ -1079,7 +1079,7 @@ export class Style {
|
|
|
1079
1079
|
*
|
|
1080
1080
|
* @example
|
|
1081
1081
|
* ```typescript
|
|
1082
|
-
* style.maxSize = { width: "
|
|
1082
|
+
* style.maxSize = { width: "auto", height: 500 };
|
|
1083
1083
|
* ```
|
|
1084
1084
|
* @param {Size<Dimension>} val
|
|
1085
1085
|
*/
|
|
@@ -1093,7 +1093,7 @@ export class Style {
|
|
|
1093
1093
|
*
|
|
1094
1094
|
* @example
|
|
1095
1095
|
* ```typescript
|
|
1096
|
-
* style.minSize = { width:
|
|
1096
|
+
* style.minSize = { width: 100, height: "auto" };
|
|
1097
1097
|
* ```
|
|
1098
1098
|
* @param {Size<Dimension>} val
|
|
1099
1099
|
*/
|
|
@@ -1124,7 +1124,7 @@ export class Style {
|
|
|
1124
1124
|
*
|
|
1125
1125
|
* ```typescript
|
|
1126
1126
|
* style.position = Position.Absolute;
|
|
1127
|
-
* style.inset = { left:
|
|
1127
|
+
* style.inset = { left: 10, top: 10, right: "auto", bottom: "auto" };
|
|
1128
1128
|
* ```
|
|
1129
1129
|
* @param {Position} val
|
|
1130
1130
|
*/
|
|
@@ -1222,7 +1222,7 @@ export class Style {
|
|
|
1222
1222
|
*
|
|
1223
1223
|
* @example
|
|
1224
1224
|
* ```typescript
|
|
1225
|
-
* style.flexBasis =
|
|
1225
|
+
* style.flexBasis = 100;
|
|
1226
1226
|
* ```
|
|
1227
1227
|
* @param {Dimension} val
|
|
1228
1228
|
*/
|
|
@@ -1436,7 +1436,7 @@ export class Style {
|
|
|
1436
1436
|
*
|
|
1437
1437
|
* @example
|
|
1438
1438
|
* ```typescript
|
|
1439
|
-
* style.gap = { width:
|
|
1439
|
+
* style.gap = { width: 10, height: 10 };
|
|
1440
1440
|
* ```
|
|
1441
1441
|
* @param {Size<LengthPercentage>} val
|
|
1442
1442
|
*/
|
|
@@ -1496,7 +1496,7 @@ export class Style {
|
|
|
1496
1496
|
*
|
|
1497
1497
|
* @example
|
|
1498
1498
|
* ```typescript
|
|
1499
|
-
* style.size = { width:
|
|
1499
|
+
* style.size = { width: 200, height: "100%" };
|
|
1500
1500
|
* ```
|
|
1501
1501
|
* @param {Size<Dimension>} val
|
|
1502
1502
|
*/
|
|
@@ -1538,7 +1538,7 @@ export class Style {
|
|
|
1538
1538
|
* @example
|
|
1539
1539
|
* ```typescript
|
|
1540
1540
|
* style.position = Position.Absolute;
|
|
1541
|
-
* style.inset = { left:
|
|
1541
|
+
* style.inset = { left: 0, top: 0, right: "auto", bottom: "auto" };
|
|
1542
1542
|
* ```
|
|
1543
1543
|
* @param {Rect<LengthPercentageAuto>} val
|
|
1544
1544
|
*/
|
|
@@ -1784,10 +1784,10 @@ export class TaffyTree {
|
|
|
1784
1784
|
* @example
|
|
1785
1785
|
* ```typescript
|
|
1786
1786
|
* // Fixed size container
|
|
1787
|
-
* { width:
|
|
1787
|
+
* { width: 800, height: 600 }
|
|
1788
1788
|
*
|
|
1789
1789
|
* // Flexible width, fixed height
|
|
1790
|
-
* { width: "MaxContent", height:
|
|
1790
|
+
* { width: "MaxContent", height: 600 }
|
|
1791
1791
|
*
|
|
1792
1792
|
* // Minimum content size
|
|
1793
1793
|
* { width: "MinContent", height: "MinContent" }
|
|
@@ -1797,7 +1797,7 @@ export class TaffyTree {
|
|
|
1797
1797
|
*
|
|
1798
1798
|
* @example
|
|
1799
1799
|
* ```typescript
|
|
1800
|
-
* tree.computeLayout(rootId, { width:
|
|
1800
|
+
* tree.computeLayout(rootId, { width: 800, height: 600 });
|
|
1801
1801
|
* ```
|
|
1802
1802
|
* @param {bigint} node
|
|
1803
1803
|
* @param {Size<AvailableSpace>} available_space
|
|
@@ -2160,7 +2160,7 @@ export class TaffyTree {
|
|
|
2160
2160
|
* ```typescript
|
|
2161
2161
|
* tree.computeLayoutWithMeasure(
|
|
2162
2162
|
* rootId,
|
|
2163
|
-
* { width:
|
|
2163
|
+
* { width: 800, height: "MaxContent" },
|
|
2164
2164
|
* (known, available, node, context, style) => {
|
|
2165
2165
|
* if (context?.text) {
|
|
2166
2166
|
* const measured = measureText(context.text, available.width);
|
|
@@ -2307,7 +2307,7 @@ export class TaffyTree {
|
|
|
2307
2307
|
*
|
|
2308
2308
|
* @example
|
|
2309
2309
|
* ```typescript
|
|
2310
|
-
* tree.computeLayout(rootId, { width:
|
|
2310
|
+
* tree.computeLayout(rootId, { width: 800, height: 600 });
|
|
2311
2311
|
* const layout: Layout = tree.getLayout(nodeId);
|
|
2312
2312
|
* console.log(`Position: (${layout.x}, ${layout.y}), Size: ${layout.width}x${layout.height}`);
|
|
2313
2313
|
* ```
|
|
@@ -2407,7 +2407,7 @@ export class TaffyTree {
|
|
|
2407
2407
|
* @example
|
|
2408
2408
|
* ```typescript
|
|
2409
2409
|
* const style = new Style();
|
|
2410
|
-
* style.size = { width:
|
|
2410
|
+
* style.size = { width: 100, height: 50 };
|
|
2411
2411
|
* const nodeId: bigint = tree.newLeaf(style);
|
|
2412
2412
|
* ```
|
|
2413
2413
|
* @param {Style} style
|
|
@@ -2681,7 +2681,7 @@ function __wbg_get_imports() {
|
|
|
2681
2681
|
const ret = arg0.length;
|
|
2682
2682
|
return ret;
|
|
2683
2683
|
};
|
|
2684
|
-
imports.wbg.
|
|
2684
|
+
imports.wbg.__wbg_log_274c70cbdd825a00 = function(arg0, arg1) {
|
|
2685
2685
|
console.log(getStringFromWasm0(arg0, arg1));
|
|
2686
2686
|
};
|
|
2687
2687
|
imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
|
package/taffy_wasm_bg.wasm
CHANGED
|
Binary file
|