@threlte/flex 2.0.5 → 2.1.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/README.md +0 -4
- package/dist/Box/Box.svelte +90 -60
- package/dist/Box/Box.svelte.d.ts +2 -1
- package/dist/Box/types.d.ts +1 -1
- package/dist/Flex/Flex.svelte +14 -8
- package/dist/Flex/Flex.svelte.d.ts +2 -1
- package/dist/Flex/InnerFlex.svelte +179 -130
- package/dist/Flex/InnerFlex.svelte.d.ts +2 -1
- package/dist/Flex/context.d.ts +2 -2
- package/dist/Flex/context.js +4 -1
- package/dist/Flex/types.d.ts +1 -1
- package/dist/hooks/useReflow.js +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -4
- package/dist/lib/alignFlexProps.d.ts +1 -1
- package/dist/lib/getDepthAxis.d.ts +1 -1
- package/dist/lib/getFlex2DSize.d.ts +1 -1
- package/dist/lib/getRootShift.js +1 -1
- package/dist/lib/props.js +13 -5
- package/dist/lib/propsChanged.d.ts +1 -1
- package/dist/nodes/context.js +1 -1
- package/dist/parsers/createClassParser.d.ts +1 -1
- package/dist/parsers/tailwindParser.d.ts +1 -1
- package/dist/parsers/tailwindParser.js +1 -1
- package/package.json +11 -12
package/README.md
CHANGED
|
@@ -50,10 +50,6 @@ Contributions are what make the open source community such an amazing place to l
|
|
|
50
50
|
- **Filing Issues** - if you have feature requestions or you think you spotted a bug, [submit an issue](https://github.com/threlte/threlte/issues/new).
|
|
51
51
|
- **Contributing Code** - if you would like to drop us a PR, read the [contribution guide](https://github.com/threlte/threlte/blob/main/CONTRIBUTING.md) first.
|
|
52
52
|
|
|
53
|
-
## Sponsors
|
|
54
|
-
|
|
55
|
-
[](https://vercel.com/?utm_source=threlte&utm_campaign=oss)
|
|
56
|
-
|
|
57
53
|
---
|
|
58
54
|
|
|
59
55
|
### License
|
package/dist/Box/Box.svelte
CHANGED
|
@@ -1,70 +1,100 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { T } from '@threlte/core'
|
|
3
|
+
import { onDestroy } from 'svelte'
|
|
4
|
+
import { Group, Object3D } from 'three'
|
|
5
|
+
import { useFlex } from '../Flex/context.js'
|
|
6
|
+
import { createUseDimensionsContext } from '../hooks/useDimensions.js'
|
|
7
|
+
import type { NodeProps } from '../lib/props.js'
|
|
8
|
+
import { createNodeContext } from '../nodes/context.js'
|
|
9
|
+
import type { BoxProps } from './types.js'
|
|
10
|
+
|
|
11
|
+
let { order, class: _class = '', onreflow, children, ...props }: BoxProps = $props()
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create the context for `useDimensions`
|
|
15
|
+
*/
|
|
16
|
+
const dimensionsContext = createUseDimensionsContext()
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
scaleFactor,
|
|
20
|
+
onEvent,
|
|
21
|
+
addNode,
|
|
22
|
+
removeNode,
|
|
23
|
+
updateNodeProps,
|
|
24
|
+
mainAxis,
|
|
25
|
+
crossAxis,
|
|
26
|
+
depthAxis,
|
|
27
|
+
classParser,
|
|
28
|
+
reflow
|
|
29
|
+
} = useFlex()
|
|
30
|
+
|
|
31
|
+
const group = new Group()
|
|
32
|
+
group.userData.isNode = true
|
|
33
|
+
const contentGroup = new Group()
|
|
34
|
+
|
|
35
|
+
const { yoga } = useFlex()
|
|
36
|
+
|
|
37
|
+
const node = yoga.Node.create()
|
|
38
|
+
|
|
39
|
+
const parentNodeContext = createNodeContext(node)
|
|
40
|
+
parentNodeContext?.insertNode(node, order)
|
|
41
|
+
onDestroy(() => {
|
|
42
|
+
parentNodeContext?.removeNode(node)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// update the order of the node
|
|
46
|
+
$effect.pre(() => parentNodeContext?.updateNodeOrder(node, order))
|
|
47
|
+
|
|
48
|
+
addNode(node, group, props as NodeProps)
|
|
49
|
+
updateNodeProps(node, { ...classParser?.(_class, {}), ...props } as NodeProps, true)
|
|
50
|
+
|
|
51
|
+
$effect.pre(() => updateNodeProps(node, { ...classParser?.(_class, {}), ...props } as NodeProps))
|
|
52
|
+
|
|
53
|
+
onDestroy(() => {
|
|
54
|
+
removeNode(node)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
let computedWidth = $state(1)
|
|
58
|
+
let computedHeight = $state(1)
|
|
59
|
+
|
|
60
|
+
// after the parent has been reflowed, we can use the calculated layout to set the properties of the box
|
|
61
|
+
onEvent('reflow:after', () => {
|
|
35
62
|
computedWidth =
|
|
36
|
-
|
|
63
|
+
typeof props.width === 'number' ? props.width : node.getComputedWidth() / $scaleFactor
|
|
64
|
+
|
|
37
65
|
computedHeight =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
contentGroup.position[$
|
|
41
|
-
contentGroup.position[$
|
|
42
|
-
|
|
43
|
-
|
|
66
|
+
typeof props.height === 'number' ? props.height : node.getComputedHeight() / $scaleFactor
|
|
67
|
+
|
|
68
|
+
contentGroup.position[$mainAxis] = computedWidth / 2
|
|
69
|
+
contentGroup.position[$crossAxis] = -computedHeight / 2
|
|
70
|
+
contentGroup.position[$depthAxis] = 0
|
|
71
|
+
|
|
72
|
+
dimensionsContext.width.set(computedWidth)
|
|
73
|
+
dimensionsContext.height.set(computedHeight)
|
|
74
|
+
|
|
44
75
|
onreflow?.({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
proxy
|
|
76
|
+
width: computedWidth,
|
|
77
|
+
height: computedHeight
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const proxy = new Object3D()
|
|
82
|
+
proxy.add = (child) => {
|
|
51
83
|
if (child.userData.isNode) {
|
|
52
|
-
|
|
84
|
+
group.add(child)
|
|
85
|
+
} else {
|
|
86
|
+
contentGroup.add(child)
|
|
53
87
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return child;
|
|
58
|
-
};
|
|
59
|
-
proxy.remove = (child) => {
|
|
88
|
+
return child
|
|
89
|
+
}
|
|
90
|
+
proxy.remove = (child) => {
|
|
60
91
|
if (child.userData.isNode) {
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
contentGroup.remove(child);
|
|
92
|
+
group.remove(child)
|
|
93
|
+
} else {
|
|
94
|
+
contentGroup.remove(child)
|
|
65
95
|
}
|
|
66
|
-
return child
|
|
67
|
-
}
|
|
96
|
+
return child
|
|
97
|
+
}
|
|
68
98
|
</script>
|
|
69
99
|
|
|
70
100
|
<T is={group}>
|
package/dist/Box/Box.svelte.d.ts
CHANGED
package/dist/Box/types.d.ts
CHANGED
package/dist/Flex/Flex.svelte
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { loadYoga, type Yoga } from 'yoga-layout/load'
|
|
3
|
+
import InnerFlex from './InnerFlex.svelte'
|
|
4
|
+
import type { FlexProps } from './types.js'
|
|
5
|
+
|
|
6
|
+
let { children: innerChildren, ref = $bindable(), ...props }: FlexProps = $props()
|
|
7
|
+
|
|
8
|
+
let yoga = $state<Yoga>()
|
|
9
|
+
|
|
10
|
+
const initialize = async () => {
|
|
11
|
+
yoga = await loadYoga()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
initialize()
|
|
9
15
|
</script>
|
|
10
16
|
|
|
11
17
|
{#if yoga}
|
|
@@ -1,153 +1,202 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { T, currentWritable, useTask } from '@threlte/core'
|
|
3
|
+
import { onDestroy } from 'svelte'
|
|
4
|
+
import { Box3, Group, Vector3 } from 'three'
|
|
5
|
+
import { Direction } from 'yoga-layout'
|
|
6
|
+
import { createUseDimensionsContext } from '../hooks/useDimensions.js'
|
|
7
|
+
import { getDepthAxis } from '../lib/getDepthAxis.js'
|
|
8
|
+
import { getOrientedBoundingBoxSize } from '../lib/getOrientedBoundingBoxSize.js'
|
|
9
|
+
import { getRootShift } from '../lib/getRootShift.js'
|
|
10
|
+
import { applyNodeProps, type Axis, type NodeProps } from '../lib/props.js'
|
|
11
|
+
import { propsChanged } from '../lib/propsChanged.js'
|
|
12
|
+
import { createNodeContext } from '../nodes/context.js'
|
|
13
|
+
import { createFlexContext } from './context.js'
|
|
14
|
+
import type { InnerFlexProps } from './types.js'
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
yoga,
|
|
18
|
+
width = 1,
|
|
19
|
+
height = 1,
|
|
20
|
+
plane = 'xy',
|
|
21
|
+
direction = 'LTR',
|
|
22
|
+
scaleFactor = 1000,
|
|
23
|
+
classParser,
|
|
24
|
+
class: _class = '',
|
|
25
|
+
reflowStage,
|
|
26
|
+
ref = $bindable(),
|
|
27
|
+
onreflow,
|
|
28
|
+
children,
|
|
29
|
+
...props
|
|
30
|
+
}: InnerFlexProps = $props()
|
|
31
|
+
|
|
32
|
+
ref = new Group()
|
|
33
|
+
ref.userData.isNode = true
|
|
34
|
+
|
|
35
|
+
const boundingBox = new Box3()
|
|
36
|
+
const vec3 = new Vector3()
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create the context for `useDimensions`
|
|
40
|
+
*/
|
|
41
|
+
const { width: computedWidth, height: computedHeight } = createUseDimensionsContext()
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Reflowing inside useTask automatically batches reflows to 1 per frame.
|
|
45
|
+
*/
|
|
46
|
+
const { start: reflow, stop } = useTask(
|
|
47
|
+
Symbol('threlte-flex-reflow'),
|
|
48
|
+
() => {
|
|
49
|
+
flexContext.emit('reflow:before')
|
|
50
|
+
|
|
51
|
+
for (const { node, group, props } of flexContext.nodes.values()) {
|
|
52
|
+
const scaledWidth =
|
|
53
|
+
typeof props.width === 'number' ? props.width * scaleFactor : props.width
|
|
54
|
+
const scaledHeight =
|
|
55
|
+
typeof props.height === 'number' ? props.height * scaleFactor : props.height
|
|
56
|
+
|
|
30
57
|
if (scaledWidth !== undefined && scaledHeight !== undefined) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
node.setHeight(scaledHeight || vec3[$crossAxis] * scaleFactor);
|
|
58
|
+
// Forced size, no need to calculate bounding box
|
|
59
|
+
node.setWidth(scaledWidth)
|
|
60
|
+
node.setHeight(scaledHeight)
|
|
61
|
+
} else if (node.getChildCount() === 0) {
|
|
62
|
+
// No size specified, calculate size
|
|
63
|
+
if (ref) {
|
|
64
|
+
getOrientedBoundingBoxSize(group, ref, boundingBox, vec3)
|
|
65
|
+
} else {
|
|
66
|
+
// ref is missing for some reason, let's just use usual bounding box
|
|
67
|
+
boundingBox.setFromObject(group).getSize(vec3)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
node.setWidth(scaledWidth || vec3[$mainAxis] * scaleFactor)
|
|
71
|
+
node.setHeight(scaledHeight || vec3[$crossAxis] * scaleFactor)
|
|
46
72
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
rootNode.calculateLayout(width * scaleFactor, height * scaleFactor, Direction[direction])
|
|
76
|
+
|
|
77
|
+
const rootWidth = rootNode.getComputedWidth()
|
|
78
|
+
const rootHeight = rootNode.getComputedHeight()
|
|
79
|
+
|
|
80
|
+
let minX = 0
|
|
81
|
+
let maxX = 0
|
|
82
|
+
let minY = 0
|
|
83
|
+
let maxY = 0
|
|
84
|
+
|
|
85
|
+
// Reposition after recalculation
|
|
86
|
+
for (const { node, group } of flexContext.nodes.values()) {
|
|
87
|
+
const { left, top, width, height } = node.getComputedLayout()
|
|
88
|
+
const [mainAxisShift, crossAxisShift] = getRootShift(rootWidth, rootHeight, node)
|
|
89
|
+
|
|
90
|
+
group.position[$mainAxis] = (mainAxisShift + left) / scaleFactor
|
|
91
|
+
group.position[$crossAxis] = -(crossAxisShift + top) / scaleFactor
|
|
92
|
+
group.position[$depthAxis] = 0
|
|
93
|
+
|
|
94
|
+
minX = Math.min(minX, left)
|
|
95
|
+
minY = Math.min(minY, top)
|
|
96
|
+
maxX = Math.max(maxX, left + width)
|
|
97
|
+
maxY = Math.max(maxY, top + height)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
flexContext.emit('reflow:after')
|
|
101
|
+
|
|
102
|
+
computedWidth.set((maxX - minX) / scaleFactor)
|
|
103
|
+
computedHeight.set((maxY - minY) / scaleFactor)
|
|
104
|
+
|
|
105
|
+
onreflow?.({
|
|
71
106
|
width: computedWidth.current,
|
|
72
107
|
height: computedHeight.current
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
stop()
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
stage: reflowStage,
|
|
114
|
+
autoStart: false
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
const flexContext = createFlexContext({
|
|
80
119
|
yoga,
|
|
81
120
|
nodes: new Map(),
|
|
82
121
|
addNode(node, group, props) {
|
|
83
|
-
|
|
84
|
-
|
|
122
|
+
flexContext.nodes.set(node, { node, group, props })
|
|
123
|
+
reflow()
|
|
85
124
|
},
|
|
86
125
|
updateNodeProps(node, props, force = false) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
126
|
+
const nodeData = flexContext.nodes.get(node)
|
|
127
|
+
|
|
128
|
+
// Updating the props can be forced and is done so on the initial call.
|
|
129
|
+
if (force || propsChanged(node, props)) {
|
|
130
|
+
applyNodeProps(node, props, scaleFactor)
|
|
131
|
+
reflow()
|
|
132
|
+
if (nodeData) nodeData.props = props
|
|
133
|
+
}
|
|
95
134
|
},
|
|
96
135
|
removeNode(node) {
|
|
97
|
-
|
|
98
|
-
|
|
136
|
+
flexContext.nodes.delete(node)
|
|
137
|
+
reflow()
|
|
99
138
|
},
|
|
100
139
|
rootWidth: currentWritable(width),
|
|
101
140
|
rootHeight: currentWritable(height),
|
|
102
141
|
scaleFactor: currentWritable(scaleFactor ?? 1000),
|
|
103
|
-
mainAxis: currentWritable(plane[0]),
|
|
104
|
-
crossAxis: currentWritable(plane[1]),
|
|
142
|
+
mainAxis: currentWritable(plane[0] as Axis),
|
|
143
|
+
crossAxis: currentWritable(plane[1] as Axis),
|
|
105
144
|
depthAxis: currentWritable(getDepthAxis(plane)),
|
|
106
145
|
rootGroup: ref,
|
|
107
146
|
reflow,
|
|
108
147
|
classParser
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
const rootNode = yoga.Node.create()
|
|
151
|
+
createNodeContext(rootNode)
|
|
152
|
+
|
|
153
|
+
const { mainAxis, crossAxis, depthAxis } = flexContext
|
|
154
|
+
|
|
155
|
+
$effect.pre(() => {
|
|
156
|
+
rootNode.setWidth(width * scaleFactor)
|
|
157
|
+
rootNode.setHeight(height * scaleFactor)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
flexContext.updateNodeProps(
|
|
161
|
+
rootNode,
|
|
162
|
+
{ ...classParser?.(_class, {}), ...props } as NodeProps,
|
|
163
|
+
true
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
$effect.pre(() => {
|
|
119
167
|
flexContext.updateNodeProps(rootNode, {
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
})
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
168
|
+
...classParser?.(_class, {}),
|
|
169
|
+
...props
|
|
170
|
+
} as NodeProps)
|
|
171
|
+
})
|
|
172
|
+
$effect.pre(() => {
|
|
173
|
+
flexContext.rootWidth.set(width)
|
|
174
|
+
flexContext.reflow()
|
|
175
|
+
})
|
|
176
|
+
$effect.pre(() => {
|
|
177
|
+
flexContext.rootHeight.set(height)
|
|
178
|
+
flexContext.reflow()
|
|
179
|
+
})
|
|
180
|
+
$effect.pre(() => {
|
|
181
|
+
flexContext.mainAxis.set(plane[0] as Axis)
|
|
182
|
+
flexContext.reflow()
|
|
183
|
+
})
|
|
184
|
+
$effect.pre(() => {
|
|
185
|
+
flexContext.crossAxis.set(plane[1] as Axis)
|
|
186
|
+
flexContext.reflow()
|
|
187
|
+
})
|
|
188
|
+
$effect.pre(() => {
|
|
189
|
+
flexContext.depthAxis.set(getDepthAxis(plane))
|
|
190
|
+
flexContext.reflow()
|
|
191
|
+
})
|
|
192
|
+
$effect.pre(() => {
|
|
193
|
+
flexContext.scaleFactor.set(scaleFactor)
|
|
194
|
+
flexContext.reflow()
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
onDestroy(() => {
|
|
198
|
+
rootNode.free()
|
|
199
|
+
})
|
|
151
200
|
</script>
|
|
152
201
|
|
|
153
202
|
<T is={ref}>
|
package/dist/Flex/context.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { CurrentWritable } from '@threlte/core';
|
|
2
|
-
import {
|
|
2
|
+
import type { Emitter } from 'mitt';
|
|
3
3
|
import type { Group } from 'three';
|
|
4
4
|
import type { Node } from 'yoga-layout';
|
|
5
5
|
import type Yoga from 'yoga-layout';
|
|
6
|
-
import type { Axis, ClassParser, NodeProps } from '../lib/props';
|
|
6
|
+
import type { Axis, ClassParser, NodeProps } from '../lib/props.js';
|
|
7
7
|
type FlexContextEvents = {
|
|
8
8
|
'reflow:before': void;
|
|
9
9
|
'reflow:after': void;
|
package/dist/Flex/context.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// We need to cast here because TypeScript with "moduleResolution": "NodeNext"
|
|
2
|
+
// fails to resolve the default export otherwise.
|
|
3
|
+
import mittModule from 'mitt';
|
|
4
|
+
const mitt = mittModule;
|
|
2
5
|
import { getContext, onDestroy, setContext } from 'svelte';
|
|
3
6
|
export const flexContextName = '__threlte-flex';
|
|
4
7
|
export const createFlexContext = (data) => {
|
package/dist/Flex/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Snippet } from 'svelte';
|
|
|
3
3
|
import type { Group } from 'three';
|
|
4
4
|
import type Yoga from 'yoga-layout';
|
|
5
5
|
import type { Direction } from 'yoga-layout';
|
|
6
|
-
import type { ClassParser, FlexPlane, NodeProps } from '../lib/props';
|
|
6
|
+
import type { ClassParser, FlexPlane, NodeProps } from '../lib/props.js';
|
|
7
7
|
export type InnerFlexProps = NodeProps & {
|
|
8
8
|
yoga: typeof Yoga;
|
|
9
9
|
width?: number;
|
package/dist/hooks/useReflow.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getContext } from 'svelte';
|
|
2
|
-
import { flexContextName } from '../Flex/context';
|
|
2
|
+
import { flexContextName } from '../Flex/context.js';
|
|
3
3
|
/**
|
|
4
4
|
* The hook useReflow allows you to manually request a [layout
|
|
5
5
|
* reflow](https://threlte.xyz/docs/reference/flex/flex#layout-reflow), for
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { default as Box } from './Box/Box.svelte';
|
|
2
2
|
export { default as Flex } from './Flex/Flex.svelte';
|
|
3
|
-
export type { NodeProps } from './lib/props';
|
|
4
|
-
export { createClassParser } from './parsers/createClassParser';
|
|
5
|
-
export { tailwindParser } from './parsers/tailwindParser';
|
|
6
|
-
export { useReflow } from './hooks/useReflow';
|
|
7
|
-
export { useDimensions } from './hooks/useDimensions';
|
|
3
|
+
export type { NodeProps } from './lib/props.js';
|
|
4
|
+
export { createClassParser } from './parsers/createClassParser.js';
|
|
5
|
+
export { tailwindParser } from './parsers/tailwindParser.js';
|
|
6
|
+
export { useReflow } from './hooks/useReflow.js';
|
|
7
|
+
export { useDimensions } from './hooks/useDimensions.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { default as Box } from './Box/Box.svelte';
|
|
2
2
|
export { default as Flex } from './Flex/Flex.svelte';
|
|
3
3
|
// parsers
|
|
4
|
-
export { createClassParser } from './parsers/createClassParser';
|
|
5
|
-
export { tailwindParser } from './parsers/tailwindParser';
|
|
4
|
+
export { createClassParser } from './parsers/createClassParser.js';
|
|
5
|
+
export { tailwindParser } from './parsers/tailwindParser.js';
|
|
6
6
|
// hooks
|
|
7
|
-
export { useReflow } from './hooks/useReflow';
|
|
8
|
-
export { useDimensions } from './hooks/useDimensions';
|
|
7
|
+
export { useReflow } from './hooks/useReflow.js';
|
|
8
|
+
export { useDimensions } from './hooks/useDimensions.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { FlexPlane } from './props';
|
|
1
|
+
import type { FlexPlane } from './props.js';
|
|
2
2
|
export declare function getDepthAxis(plane: FlexPlane): "x" | "y" | "z";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { FlexPlane } from './props';
|
|
1
|
+
import type { FlexPlane } from './props.js';
|
|
2
2
|
export declare function getFlex2DSize(sizes: [number, number, number], plane: FlexPlane): number[];
|
package/dist/lib/getRootShift.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isTopLevelChildNode } from './isTopLevelChildNode';
|
|
1
|
+
import { isTopLevelChildNode } from './isTopLevelChildNode.js';
|
|
2
2
|
/** @returns [mainAxisShift, crossAxisShift] */
|
|
3
3
|
export const getRootShift = (rootWidth, rootHeight, node) => {
|
|
4
4
|
if (!isTopLevelChildNode(node)) {
|
package/dist/lib/props.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Yoga from 'yoga-layout';
|
|
2
|
-
import { alignFlexProps } from './alignFlexProps';
|
|
2
|
+
import { alignFlexProps } from './alignFlexProps.js';
|
|
3
3
|
// prettier-ignore
|
|
4
4
|
/**
|
|
5
5
|
* This map provides the prop setters as well as the types for the props. The
|
|
@@ -58,8 +58,16 @@ const applyScaleFactor = (prop, scaleFactor) => {
|
|
|
58
58
|
return prop;
|
|
59
59
|
};
|
|
60
60
|
export const applyNodeProps = (node, props, scaleFactor) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
propSetter
|
|
64
|
-
|
|
61
|
+
const alignedProps = alignFlexProps(props);
|
|
62
|
+
for (const key in alignedProps) {
|
|
63
|
+
// limit to the known keys of propSetter
|
|
64
|
+
if (!(key in propSetter))
|
|
65
|
+
continue;
|
|
66
|
+
const k = key;
|
|
67
|
+
const prop = alignedProps[k];
|
|
68
|
+
if (prop === undefined)
|
|
69
|
+
continue;
|
|
70
|
+
const scaled = applyScaleFactor(prop, scaleFactor);
|
|
71
|
+
propSetter[k](scaled, node);
|
|
72
|
+
}
|
|
65
73
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Node } from 'yoga-layout';
|
|
2
|
-
import type { NodeProps } from './props';
|
|
2
|
+
import type { NodeProps } from './props.js';
|
|
3
3
|
/**
|
|
4
4
|
* Because all NodeProps are primitive types, we can make a simple comparison
|
|
5
5
|
* and only request a reflow when necessary. We do that by checking the length
|
package/dist/nodes/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const tailwindParser: import("../lib/props").ClassParser;
|
|
1
|
+
export declare const tailwindParser: import("../lib/props.js").ClassParser;
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/flex",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Components to easily use the flexbox spec with Threlte",
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@eslint/js": "^9.26.0",
|
|
9
|
-
"@sveltejs/adapter-auto": "^
|
|
10
|
-
"@sveltejs/kit": "^2.
|
|
9
|
+
"@sveltejs/adapter-auto": "^6.1.0",
|
|
10
|
+
"@sveltejs/kit": "^2.37.0",
|
|
11
11
|
"@sveltejs/package": "^2.3.7",
|
|
12
|
-
"@sveltejs/vite-plugin-svelte": "^
|
|
13
|
-
"@types/node": "^20.
|
|
12
|
+
"@sveltejs/vite-plugin-svelte": "^6.1.4",
|
|
13
|
+
"@types/node": "^20.19.4",
|
|
14
14
|
"@types/three": "^0.175.0",
|
|
15
15
|
"@yushijinhun/three-minifier-rollup": "^0.4.0",
|
|
16
16
|
"eslint": "^9.26.0",
|
|
@@ -19,18 +19,17 @@
|
|
|
19
19
|
"prettier": "^3.2.5",
|
|
20
20
|
"prettier-plugin-svelte": "^3.2.2",
|
|
21
21
|
"publint": "^0.2.7",
|
|
22
|
-
"rimraf": "^
|
|
22
|
+
"rimraf": "^6.0.1",
|
|
23
23
|
"svelte": "5.26.2",
|
|
24
|
-
"svelte-check": "^4.1
|
|
25
|
-
"svelte-preprocess": "^5.1.3",
|
|
24
|
+
"svelte-check": "^4.3.1",
|
|
26
25
|
"svelte2tsx": "^0.7.6",
|
|
27
26
|
"three": "^0.175.0",
|
|
28
27
|
"tslib": "^2.6.2",
|
|
29
|
-
"typescript": "
|
|
28
|
+
"typescript": "5.9.2",
|
|
30
29
|
"typescript-eslint": "^8.32.0",
|
|
31
|
-
"vite": "^
|
|
32
|
-
"@threlte/core": "8.
|
|
33
|
-
"@threlte/extras": "9.
|
|
30
|
+
"vite": "^7.1.4",
|
|
31
|
+
"@threlte/core": "8.3.0",
|
|
32
|
+
"@threlte/extras": "9.7.0"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
35
|
"mitt": "^3.0.1",
|