@threlte/flex 1.0.1 → 2.0.0-next.0
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/dist/Box/Box.svelte +14 -27
- package/dist/Flex/Flex.svelte +4 -6
- package/dist/Flex/InnerFlex.svelte +45 -31
- package/dist/lib/props.js +1 -1
- package/package.json +4 -4
package/dist/Box/Box.svelte
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
<script>import { HierarchicalObject, T
|
|
1
|
+
<script>import { HierarchicalObject, T } from '@threlte/core';
|
|
2
2
|
import { onDestroy } from 'svelte';
|
|
3
3
|
import { Group } from 'three';
|
|
4
4
|
import { useFlex } from '../Flex/context';
|
|
5
5
|
import { createUseDimensionsContext } from '../hooks/useDimensions';
|
|
6
6
|
import { createNodeContext } from '../nodes/context';
|
|
7
|
-
|
|
8
|
-
let _class = '';
|
|
9
|
-
export { _class as class };
|
|
10
|
-
const dispatch = createRawEventDispatcher();
|
|
7
|
+
let { order, class: _class = '', ...props } = $props();
|
|
11
8
|
/**
|
|
12
9
|
* Create the context for `useDimensions`
|
|
13
10
|
*/
|
|
@@ -24,37 +21,27 @@ onDestroy(() => {
|
|
|
24
21
|
parentNodeContext?.removeNode(node);
|
|
25
22
|
});
|
|
26
23
|
// update the order of the node
|
|
27
|
-
|
|
28
|
-
addNode(node, group,
|
|
29
|
-
updateNodeProps(node, { ...classParser?.(_class, {}),
|
|
30
|
-
|
|
24
|
+
$effect.pre(() => parentNodeContext?.updateNodeOrder(node, order));
|
|
25
|
+
addNode(node, group, props);
|
|
26
|
+
updateNodeProps(node, { ...classParser?.(_class, {}), ...props }, true);
|
|
27
|
+
$effect.pre(() => updateNodeProps(node, { ...classParser?.(_class, {}), ...props }));
|
|
31
28
|
onDestroy(() => {
|
|
32
29
|
removeNode(node);
|
|
33
30
|
});
|
|
34
|
-
let computedWidth = 1;
|
|
35
|
-
let computedHeight = 1;
|
|
36
|
-
/**
|
|
37
|
-
* Untrack contentGroup
|
|
38
|
-
*/
|
|
39
|
-
const getContentGroup = () => {
|
|
40
|
-
return contentGroup;
|
|
41
|
-
};
|
|
31
|
+
let computedWidth = $state(1);
|
|
32
|
+
let computedHeight = $state(1);
|
|
42
33
|
// after the parent has been reflowed, we can use the calculated layout to set the properties of the box
|
|
43
34
|
onEvent('reflow:after', () => {
|
|
44
35
|
computedWidth =
|
|
45
|
-
typeof
|
|
46
|
-
? $$restProps.width
|
|
47
|
-
: node.getComputedWidth() / $scaleFactor;
|
|
36
|
+
typeof props.width === 'number' ? props.width : node.getComputedWidth() / $scaleFactor;
|
|
48
37
|
computedHeight =
|
|
49
|
-
typeof
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
getContentGroup().position[$crossAxis] = -computedHeight / 2;
|
|
54
|
-
getContentGroup().position[$depthAxis] = 0;
|
|
38
|
+
typeof props.height === 'number' ? props.height : node.getComputedHeight() / $scaleFactor;
|
|
39
|
+
contentGroup.position[$mainAxis] = computedWidth / 2;
|
|
40
|
+
contentGroup.position[$crossAxis] = -computedHeight / 2;
|
|
41
|
+
contentGroup.position[$depthAxis] = 0;
|
|
55
42
|
dimensionsContext.width.set(computedWidth);
|
|
56
43
|
dimensionsContext.height.set(computedHeight);
|
|
57
|
-
|
|
44
|
+
props.$$events?.reflow?.({
|
|
58
45
|
width: computedWidth,
|
|
59
46
|
height: computedHeight
|
|
60
47
|
});
|
package/dist/Flex/Flex.svelte
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import { loadYoga } from 'yoga-layout';
|
|
1
|
+
<script>import { loadYoga } from 'yoga-layout';
|
|
3
2
|
import InnerFlex from './InnerFlex.svelte';
|
|
4
|
-
let
|
|
3
|
+
let { ...props } = $props();
|
|
4
|
+
let yoga = $state(undefined);
|
|
5
5
|
const initialize = async () => {
|
|
6
6
|
yoga = await loadYoga();
|
|
7
7
|
};
|
|
8
8
|
initialize();
|
|
9
|
-
const component = forwardEventHandlers();
|
|
10
9
|
</script>
|
|
11
10
|
|
|
12
11
|
{#if yoga}
|
|
13
12
|
<InnerFlex
|
|
14
13
|
{yoga}
|
|
15
|
-
{
|
|
16
|
-
bind:this={$component}
|
|
14
|
+
{...props}
|
|
17
15
|
let:reflow
|
|
18
16
|
let:width
|
|
19
17
|
let:height
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<script>import { T,
|
|
1
|
+
<script>import { T, currentWritable, useTask } from '@threlte/core';
|
|
2
2
|
import { onDestroy } from 'svelte';
|
|
3
3
|
import { Box3, Group, Vector3 } from 'three';
|
|
4
4
|
import { Direction } from 'yoga-layout';
|
|
@@ -10,19 +10,10 @@ import { applyNodeProps } from '../lib/props';
|
|
|
10
10
|
import { propsChanged } from '../lib/propsChanged';
|
|
11
11
|
import { createNodeContext } from '../nodes/context';
|
|
12
12
|
import { createFlexContext } from './context';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export let direction = 'LTR';
|
|
18
|
-
export let scaleFactor = 1000;
|
|
19
|
-
export let classParser = undefined;
|
|
20
|
-
let _class = '';
|
|
21
|
-
export { _class as class };
|
|
22
|
-
export let reflowStage = undefined;
|
|
23
|
-
const dispatch = createRawEventDispatcher();
|
|
24
|
-
const rootGroup = new Group();
|
|
25
|
-
rootGroup.userData.isNode = true;
|
|
13
|
+
let { yoga, width = 1, height = 1, plane = 'xy', direction = 'LTR', scaleFactor = 1000, classParser, class: _class = '', reflowStage, ref = $bindable(), ...props } = $props();
|
|
14
|
+
$inspect(yoga);
|
|
15
|
+
ref = new Group();
|
|
16
|
+
ref.userData.isNode = true;
|
|
26
17
|
const boundingBox = new Box3();
|
|
27
18
|
const vec3 = new Vector3();
|
|
28
19
|
/**
|
|
@@ -44,11 +35,11 @@ const { start: reflow, stop } = useTask(Symbol('threlte-flex-reflow'), () => {
|
|
|
44
35
|
}
|
|
45
36
|
else if (node.getChildCount() === 0) {
|
|
46
37
|
// No size specified, calculate size
|
|
47
|
-
if (
|
|
48
|
-
getOrientedBoundingBoxSize(group,
|
|
38
|
+
if (ref) {
|
|
39
|
+
getOrientedBoundingBoxSize(group, ref, boundingBox, vec3);
|
|
49
40
|
}
|
|
50
41
|
else {
|
|
51
|
-
//
|
|
42
|
+
// ref is missing for some reason, let's just use usual bounding box
|
|
52
43
|
boundingBox.setFromObject(group).getSize(vec3);
|
|
53
44
|
}
|
|
54
45
|
node.setWidth(scaledWidth || vec3[$mainAxis] * scaleFactor);
|
|
@@ -77,7 +68,7 @@ const { start: reflow, stop } = useTask(Symbol('threlte-flex-reflow'), () => {
|
|
|
77
68
|
flexContext.emit('reflow:after');
|
|
78
69
|
computedWidth.set((maxX - minX) / scaleFactor);
|
|
79
70
|
computedHeight.set((maxY - minY) / scaleFactor);
|
|
80
|
-
|
|
71
|
+
props.$$events?.reflow?.({
|
|
81
72
|
width: computedWidth.current,
|
|
82
73
|
height: computedHeight.current
|
|
83
74
|
});
|
|
@@ -113,30 +104,53 @@ const flexContext = createFlexContext({
|
|
|
113
104
|
mainAxis: currentWritable(plane[0]),
|
|
114
105
|
crossAxis: currentWritable(plane[1]),
|
|
115
106
|
depthAxis: currentWritable(getDepthAxis(plane)),
|
|
116
|
-
rootGroup:
|
|
107
|
+
rootGroup: ref,
|
|
117
108
|
reflow,
|
|
118
109
|
classParser
|
|
119
110
|
});
|
|
120
111
|
const rootNode = yoga.Node.create();
|
|
121
112
|
createNodeContext(rootNode);
|
|
122
113
|
const { mainAxis, crossAxis, depthAxis } = flexContext;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
114
|
+
$effect.pre(() => {
|
|
115
|
+
rootNode.setWidth(width * scaleFactor), rootNode.setHeight(height * scaleFactor);
|
|
116
|
+
});
|
|
117
|
+
flexContext.updateNodeProps(rootNode, { ...classParser?.(_class, {}), ...props }, true);
|
|
118
|
+
$effect.pre(() => {
|
|
119
|
+
flexContext.updateNodeProps(rootNode, {
|
|
120
|
+
...classParser?.(_class, {}),
|
|
121
|
+
...props
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
$effect.pre(() => {
|
|
125
|
+
flexContext.rootWidth.set(width);
|
|
126
|
+
flexContext.reflow();
|
|
127
|
+
});
|
|
128
|
+
$effect.pre(() => {
|
|
129
|
+
flexContext.rootHeight.set(height);
|
|
130
|
+
flexContext.reflow();
|
|
131
|
+
});
|
|
132
|
+
$effect.pre(() => {
|
|
133
|
+
flexContext.mainAxis.set(plane[0]);
|
|
134
|
+
flexContext.reflow();
|
|
135
|
+
});
|
|
136
|
+
$effect.pre(() => {
|
|
137
|
+
flexContext.crossAxis.set(plane[1]);
|
|
138
|
+
flexContext.reflow();
|
|
139
|
+
});
|
|
140
|
+
$effect.pre(() => {
|
|
141
|
+
flexContext.depthAxis.set(getDepthAxis(plane));
|
|
142
|
+
flexContext.reflow();
|
|
143
|
+
});
|
|
144
|
+
$effect.pre(() => {
|
|
145
|
+
flexContext.scaleFactor.set(scaleFactor);
|
|
146
|
+
flexContext.reflow();
|
|
147
|
+
});
|
|
134
148
|
onDestroy(() => {
|
|
135
149
|
rootNode.free();
|
|
136
150
|
});
|
|
137
151
|
</script>
|
|
138
152
|
|
|
139
|
-
<T is={
|
|
153
|
+
<T is={ref}>
|
|
140
154
|
<slot
|
|
141
155
|
{reflow}
|
|
142
156
|
width={$computedWidth}
|
package/dist/lib/props.js
CHANGED
|
@@ -60,6 +60,6 @@ const applyScaleFactor = (prop, scaleFactor) => {
|
|
|
60
60
|
export const applyNodeProps = (node, props, scaleFactor) => {
|
|
61
61
|
return Object.entries(alignFlexProps(props)).forEach(([key, value]) => {
|
|
62
62
|
const scaledValue = applyScaleFactor(value, scaleFactor);
|
|
63
|
-
propSetter[key](scaledValue, node);
|
|
63
|
+
propSetter[key]?.(scaledValue, node);
|
|
64
64
|
});
|
|
65
65
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/flex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-next.0",
|
|
4
4
|
"author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"devDependencies": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"tslib": "^2.6.2",
|
|
29
29
|
"typescript": "^5.3.3",
|
|
30
30
|
"vite": "^5.0.12",
|
|
31
|
-
"@threlte/core": "
|
|
32
|
-
"@threlte/extras": "
|
|
31
|
+
"@threlte/core": "8.0.0-next.0",
|
|
32
|
+
"@threlte/extras": "9.0.0-next.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"mitt": "^3.0.1",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"svelte": ">=4",
|
|
40
|
-
"three": ">=0.
|
|
40
|
+
"three": ">=0.152"
|
|
41
41
|
},
|
|
42
42
|
"type": "module",
|
|
43
43
|
"exports": {
|