@threlte/flex 0.0.5 → 0.0.7

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.
@@ -1,19 +1,25 @@
1
- <script>import { HierarchicalObject, T } from '@threlte/core';
1
+ <script>import { HierarchicalObject, T, createRawEventDispatcher } 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 { createNodeContext } from '../nodes/context';
6
+ import { createUseDimensionsContext } from '../hooks/useDimensions';
6
7
  export let order = undefined;
7
8
  let _class = '';
8
9
  export { _class as class };
9
- const { scaleFactor, onEvent, addNode, removeNode, updateNodeProps, mainAxis, crossAxis, depthAxis, classParser } = useFlex();
10
+ const dispatch = createRawEventDispatcher();
11
+ /**
12
+ * Create the context for `useDimensions`
13
+ */
14
+ const dimensionsContext = createUseDimensionsContext();
15
+ const { scaleFactor, onEvent, addNode, removeNode, updateNodeProps, mainAxis, crossAxis, depthAxis, classParser, reflow } = useFlex();
10
16
  export const group = new Group();
11
17
  export const contentGroup = new Group();
12
18
  group.userData.isNode = true;
13
19
  export const { node } = createNodeContext(order);
14
20
  addNode(node, group, $$restProps);
15
- updateNodeProps(node, { ...classParser?.(_class), ...$$restProps }, true);
16
- $: updateNodeProps(node, { ...classParser?.(_class), ...$$restProps });
21
+ updateNodeProps(node, { ...classParser?.(_class, {}), ...$$restProps }, true);
22
+ $: updateNodeProps(node, { ...classParser?.(_class, {}), ...$$restProps });
17
23
  onDestroy(() => {
18
24
  removeNode(node);
19
25
  });
@@ -38,6 +44,12 @@ onEvent('reflow:after', () => {
38
44
  getContentGroup().position[$mainAxis] = computedWidth / 2;
39
45
  getContentGroup().position[$crossAxis] = -computedHeight / 2;
40
46
  getContentGroup().position[$depthAxis] = 0;
47
+ dimensionsContext.width.set(computedWidth);
48
+ dimensionsContext.height.set(computedHeight);
49
+ dispatch('reflow', {
50
+ width: computedWidth,
51
+ height: computedHeight
52
+ });
41
53
  });
42
54
  </script>
43
55
 
@@ -62,6 +74,7 @@ onEvent('reflow:after', () => {
62
74
  }}
63
75
  >
64
76
  <slot
77
+ {reflow}
65
78
  width={computedWidth}
66
79
  height={computedHeight}
67
80
  />
@@ -6,10 +6,16 @@ type BoxProps = NodeProps & {
6
6
  class?: string
7
7
  }
8
8
 
9
- type BoxEvents = {}
9
+ type BoxEvents = {
10
+ reflow: {
11
+ width: number
12
+ height: number
13
+ }
14
+ }
10
15
 
11
16
  type BoxSlots = {
12
17
  default: {
18
+ reflow: () => void
13
19
  width: number
14
20
  height: number
15
21
  }
@@ -15,7 +15,13 @@ const component = forwardEventHandlers();
15
15
  {...$$restProps}
16
16
  bind:this={$component}
17
17
  let:reflow
18
+ let:width
19
+ let:height
18
20
  >
19
- <slot {reflow} />
21
+ <slot
22
+ {reflow}
23
+ {width}
24
+ {height}
25
+ />
20
26
  </InnerFlex>
21
27
  {/if}
@@ -10,6 +10,8 @@ type FlexEvents = ComponentEvents<InnerFlex>
10
10
  type FlexSlots = {
11
11
  default: {
12
12
  reflow: () => void
13
+ width: number
14
+ height: number
13
15
  }
14
16
  }
15
17
 
@@ -8,6 +8,7 @@ import { getRootShift } from '../lib/getRootShift';
8
8
  import { applyNodeProps } from '../lib/props';
9
9
  import { createNodeContext } from '../nodes/context';
10
10
  import { createFlexContext } from './context';
11
+ import { createUseDimensionsContext } from '../hooks/useDimensions';
11
12
  export let yoga;
12
13
  export let width = 1;
13
14
  export let height = 1;
@@ -22,6 +23,10 @@ const rootGroup = new Group();
22
23
  rootGroup.userData.isNode = true;
23
24
  const boundingBox = new Box3();
24
25
  const vec3 = new Vector3();
26
+ /**
27
+ * Create the context for `useDimensions`
28
+ */
29
+ const { width: computedWidth, height: computedHeight } = createUseDimensionsContext();
25
30
  /**
26
31
  * Reflowing inside useFrame automatically batches reflows to 1 per frame.
27
32
  */
@@ -68,9 +73,11 @@ const { start: reflow, stop } = useFrame(() => {
68
73
  maxY = Math.max(maxY, top + height);
69
74
  }
70
75
  flexContext.emit('reflow:after');
76
+ computedWidth.set((maxX - minX) / scaleFactor);
77
+ computedHeight.set((maxY - minY) / scaleFactor);
71
78
  dispatch('reflow', {
72
- width: (maxX - minX) / scaleFactor,
73
- height: (maxY - minY) / scaleFactor
79
+ width: computedWidth.current,
80
+ height: computedHeight.current
74
81
  });
75
82
  stop();
76
83
  }, { autostart: false });
@@ -120,18 +127,25 @@ const flexContext = createFlexContext({
120
127
  const { mainAxis, crossAxis, depthAxis } = flexContext;
121
128
  const { node: rootNode } = createNodeContext();
122
129
  $: rootNode.setWidth(width * scaleFactor), rootNode.setHeight(height * scaleFactor);
123
- $: applyNodeProps(rootNode, { ...classParser?.(_class), ...$$restProps }, scaleFactor), reflow();
124
- $: flexContext.rootWidth.set(width), flexContext.reflow('Updated root width');
125
- $: flexContext.rootHeight.set(height), flexContext.reflow('Updated root height');
126
- $: flexContext.mainAxis.set(plane[0]), flexContext.reflow('Updated main axis');
127
- $: flexContext.crossAxis.set(plane[1]), flexContext.reflow('Updated cross axis');
128
- $: flexContext.depthAxis.set(getDepthAxis(plane)), flexContext.reflow('Updated depth axis');
129
- $: flexContext.scaleFactor.set(scaleFactor), flexContext.reflow('Updated scale factor');
130
+ $: {
131
+ applyNodeProps(rootNode, { ...classParser?.(_class, {}), ...$$restProps }, scaleFactor);
132
+ reflow();
133
+ }
134
+ $: flexContext.rootWidth.set(width), flexContext.reflow();
135
+ $: flexContext.rootHeight.set(height), flexContext.reflow();
136
+ $: flexContext.mainAxis.set(plane[0]), flexContext.reflow();
137
+ $: flexContext.crossAxis.set(plane[1]), flexContext.reflow();
138
+ $: flexContext.depthAxis.set(getDepthAxis(plane)), flexContext.reflow();
139
+ $: flexContext.scaleFactor.set(scaleFactor), flexContext.reflow();
130
140
  onDestroy(() => {
131
141
  rootNode.free();
132
142
  });
133
143
  </script>
134
144
 
135
145
  <T is={rootGroup}>
136
- <slot {reflow} />
146
+ <slot
147
+ {reflow}
148
+ width={$computedWidth}
149
+ height={$computedHeight}
150
+ />
137
151
  </T>
@@ -24,6 +24,8 @@ type InnerFlexEvents = {
24
24
  type InnerFlexSlots = {
25
25
  default: {
26
26
  reflow: () => void
27
+ width: number
28
+ height: number
27
29
  }
28
30
  }
29
31
 
@@ -25,7 +25,7 @@ export type FlexContextData = {
25
25
  rootGroup: Group;
26
26
  rootWidth: CurrentWritable<number>;
27
27
  rootHeight: CurrentWritable<number>;
28
- reflow: (msg?: string) => void;
28
+ reflow: () => void;
29
29
  classParser?: ClassParser;
30
30
  };
31
31
  export type FlexContext = FlexContextData & Emitter<FlexContextEvents> & {
@@ -0,0 +1,50 @@
1
+ import { type CurrentWritable } from '@threlte/core';
2
+ type UseDimensionsContext = {
3
+ width: CurrentWritable<number>;
4
+ height: CurrentWritable<number>;
5
+ };
6
+ export declare const flexContextName = "__threlte-flex-dimensions";
7
+ /**
8
+ * Creates a context for useDimensions.
9
+ */
10
+ export declare const createUseDimensionsContext: () => UseDimensionsContext;
11
+ /**
12
+ * The hook `useDimensions` can be used to retrieve the computed width and
13
+ * height of a `<Flex>` or `<Box>` component as
14
+ * [CurrentWritable](https://threlte.xyz/docs/reference/core/utilities#currentwritable)
15
+ * stores.
16
+ *
17
+ * ## Usage
18
+ *
19
+ * ### In a `<Flex>` component
20
+ *
21
+ * Because there's no viewport to measure, the width and height of a `<Flex>`
22
+ * component need to be set manually. Nevertheless, the dimensions of the
23
+ * contents of the `<Flex>` component will be measured after a layout reflow and
24
+ * can be retrieved using `useDimensions` in a direct child component to
25
+ * `<Flex>`.
26
+ *
27
+ * ### In a `<Box>` component
28
+ *
29
+ * By default `@threlte/flex` controls elements position only. In some cases you
30
+ * may want to control element sizing too. Since `@threlte/flex` has no
31
+ * information about how the inner content size works, you need to set your
32
+ * content size manually. You can do this by using `useDimensions` hook in a
33
+ * direct child component to `<Box>`.
34
+ *
35
+ * @example
36
+ * ```svelte
37
+ * <script>
38
+ * import { useDimensions } from '@threlte/flex'
39
+ *
40
+ * const { width, height } = useDimensions()
41
+ * </script>
42
+ *
43
+ * <T.Mesh scale.x={$width} scale.y={$height}>
44
+ * <T.BoxGeometry />
45
+ * <T.MeshBasicMaterial color="red" />
46
+ * </T.Mesh>
47
+ * ```
48
+ */
49
+ export declare const useDimensions: () => UseDimensionsContext;
50
+ export {};
@@ -0,0 +1,59 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ import { currentWritable } from '@threlte/core';
3
+ export const flexContextName = '__threlte-flex-dimensions';
4
+ /**
5
+ * Creates a context for useDimensions.
6
+ */
7
+ export const createUseDimensionsContext = () => {
8
+ const context = {
9
+ width: currentWritable(0),
10
+ height: currentWritable(0)
11
+ };
12
+ setContext(flexContextName, context);
13
+ return context;
14
+ };
15
+ /**
16
+ * The hook `useDimensions` can be used to retrieve the computed width and
17
+ * height of a `<Flex>` or `<Box>` component as
18
+ * [CurrentWritable](https://threlte.xyz/docs/reference/core/utilities#currentwritable)
19
+ * stores.
20
+ *
21
+ * ## Usage
22
+ *
23
+ * ### In a `<Flex>` component
24
+ *
25
+ * Because there's no viewport to measure, the width and height of a `<Flex>`
26
+ * component need to be set manually. Nevertheless, the dimensions of the
27
+ * contents of the `<Flex>` component will be measured after a layout reflow and
28
+ * can be retrieved using `useDimensions` in a direct child component to
29
+ * `<Flex>`.
30
+ *
31
+ * ### In a `<Box>` component
32
+ *
33
+ * By default `@threlte/flex` controls elements position only. In some cases you
34
+ * may want to control element sizing too. Since `@threlte/flex` has no
35
+ * information about how the inner content size works, you need to set your
36
+ * content size manually. You can do this by using `useDimensions` hook in a
37
+ * direct child component to `<Box>`.
38
+ *
39
+ * @example
40
+ * ```svelte
41
+ * <script>
42
+ * import { useDimensions } from '@threlte/flex'
43
+ *
44
+ * const { width, height } = useDimensions()
45
+ * </script>
46
+ *
47
+ * <T.Mesh scale.x={$width} scale.y={$height}>
48
+ * <T.BoxGeometry />
49
+ * <T.MeshBasicMaterial color="red" />
50
+ * </T.Mesh>
51
+ * ```
52
+ */
53
+ export const useDimensions = () => {
54
+ const context = getContext(flexContextName);
55
+ if (!context) {
56
+ throw new Error('useDimensions must be used within a <Flex> component');
57
+ }
58
+ return context;
59
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The hook useReflow allows you to manually request a [layout
3
+ * reflow](https://threlte.xyz/docs/reference/flex/flex#layout-reflow), for
4
+ * instance when a [`<Text>`](https://threlte.xyz/docs/reference/extras/text)
5
+ * component finished synchronizing or when a model has loaded into view and
6
+ * there’s no easy access to the reflow slot prop of the components `<Flex>` or
7
+ * `<Box>` because of component composition. Calls to`reflow` will be limited to
8
+ * once per frame, so it’s safe to call it from multiple components at a time.
9
+ */
10
+ export declare const useReflow: () => () => void;
@@ -0,0 +1,18 @@
1
+ import { getContext } from 'svelte';
2
+ import { flexContextName } from '../Flex/context';
3
+ /**
4
+ * The hook useReflow allows you to manually request a [layout
5
+ * reflow](https://threlte.xyz/docs/reference/flex/flex#layout-reflow), for
6
+ * instance when a [`<Text>`](https://threlte.xyz/docs/reference/extras/text)
7
+ * component finished synchronizing or when a model has loaded into view and
8
+ * there’s no easy access to the reflow slot prop of the components `<Flex>` or
9
+ * `<Box>` because of component composition. Calls to`reflow` will be limited to
10
+ * once per frame, so it’s safe to call it from multiple components at a time.
11
+ */
12
+ export const useReflow = () => {
13
+ const flexContext = getContext(flexContextName);
14
+ if (!flexContext) {
15
+ throw new Error('useReflow must be used within a <Flex> component');
16
+ }
17
+ return flexContext.reflow;
18
+ };
package/dist/index.d.ts CHANGED
@@ -3,3 +3,5 @@ export { default as Flex } from './Flex/Flex.svelte';
3
3
  export type { NodeProps } from './lib/props';
4
4
  export { createClassParser } from './parsers/createClassParser';
5
5
  export { tailwindParser } from './parsers/tailwindParser';
6
+ export { useReflow } from './hooks/useReflow';
7
+ export { useDimensions } from './hooks/useDimensions';
package/dist/index.js CHANGED
@@ -3,3 +3,6 @@ export { default as Flex } from './Flex/Flex.svelte';
3
3
  // parsers
4
4
  export { createClassParser } from './parsers/createClassParser';
5
5
  export { tailwindParser } from './parsers/tailwindParser';
6
+ // hooks
7
+ export { useReflow } from './hooks/useReflow';
8
+ export { useDimensions } from './hooks/useDimensions';
@@ -1,6 +1,6 @@
1
1
  import type { Align, FlexDirection, Justify, Node, Wrap } from 'yoga-layout';
2
2
  export type FlexPlane = 'xy' | 'yz' | 'xz';
3
- export type ClassParser = (className: string) => NodeProps;
3
+ export type ClassParser = (className: string, props: NodeProps) => NodeProps;
4
4
  export type Axis = 'x' | 'y' | 'z';
5
5
  /**
6
6
  * This map provides the prop setters as well as the types for the props. The
@@ -1,8 +1,8 @@
1
- import type { NodeProps } from '../lib/props';
1
+ import type { ClassParser } from '../lib/props';
2
2
  /**
3
3
  * This function is a type helper for creating a class parser. A class parser is
4
4
  * a function that takes a class name and returns a NodeProps object. This can
5
5
  * be used to create Tailwind-like class names that resolve to yoga-layout
6
6
  * props.
7
7
  */
8
- export declare const createClassParser: (callback: (className: string) => NodeProps) => (className: string) => NodeProps;
8
+ export declare const createClassParser: (callback: ClassParser) => ClassParser;
@@ -1,2 +1 @@
1
- import type { NodeProps } from '../lib/props';
2
- export declare const tailwindParser: (className: string) => NodeProps;
1
+ export declare const tailwindParser: import("../lib/props").ClassParser;
@@ -1,6 +1,5 @@
1
1
  import { createClassParser } from './createClassParser';
2
- export const tailwindParser = createClassParser((string) => {
3
- const styles = {};
2
+ export const tailwindParser = createClassParser((string, props) => {
4
3
  const classes = string.split(' ').map((className) => className.trim());
5
4
  const parseNumericOrAutoOrPercentageValue = (value) => {
6
5
  if (value === 'auto') {
@@ -37,141 +36,141 @@ export const tailwindParser = createClassParser((string) => {
37
36
  // padding
38
37
  if (className.startsWith('p-')) {
39
38
  const [, value] = className.split('-');
40
- styles.padding = parseNumericOrPercentageValue(value);
39
+ props.padding = parseNumericOrPercentageValue(value);
41
40
  }
42
41
  if (className.startsWith('px-')) {
43
42
  const [, value] = className.split('-');
44
- styles.paddingLeft = parseNumericOrPercentageValue(value);
45
- styles.paddingRight = parseNumericOrPercentageValue(value);
43
+ props.paddingLeft = parseNumericOrPercentageValue(value);
44
+ props.paddingRight = parseNumericOrPercentageValue(value);
46
45
  }
47
46
  if (className.startsWith('py-')) {
48
47
  const [, value] = className.split('-');
49
- styles.paddingTop = parseNumericOrPercentageValue(value);
50
- styles.paddingBottom = parseNumericOrPercentageValue(value);
48
+ props.paddingTop = parseNumericOrPercentageValue(value);
49
+ props.paddingBottom = parseNumericOrPercentageValue(value);
51
50
  }
52
51
  if (className.startsWith('pt-')) {
53
52
  const [, value] = className.split('-');
54
- styles.paddingTop = parseNumericOrPercentageValue(value);
53
+ props.paddingTop = parseNumericOrPercentageValue(value);
55
54
  }
56
55
  if (className.startsWith('pr-')) {
57
56
  const [, value] = className.split('-');
58
- styles.paddingRight = parseNumericOrPercentageValue(value);
57
+ props.paddingRight = parseNumericOrPercentageValue(value);
59
58
  }
60
59
  if (className.startsWith('pb-')) {
61
60
  const [, value] = className.split('-');
62
- styles.paddingBottom = parseNumericOrPercentageValue(value);
61
+ props.paddingBottom = parseNumericOrPercentageValue(value);
63
62
  }
64
63
  if (className.startsWith('pl-')) {
65
64
  const [, value] = className.split('-');
66
- styles.paddingLeft = parseNumericOrPercentageValue(value);
65
+ props.paddingLeft = parseNumericOrPercentageValue(value);
67
66
  }
68
67
  // margin
69
68
  if (className.startsWith('m-')) {
70
69
  const [, value] = className.split('-');
71
- styles.margin = parseNumericOrAutoOrPercentageValue(value);
70
+ props.margin = parseNumericOrAutoOrPercentageValue(value);
72
71
  }
73
72
  if (className.startsWith('mx-')) {
74
73
  const [, value] = className.split('-');
75
- styles.marginLeft = parseNumericOrAutoOrPercentageValue(value);
76
- styles.marginRight = parseNumericOrAutoOrPercentageValue(value);
74
+ props.marginLeft = parseNumericOrAutoOrPercentageValue(value);
75
+ props.marginRight = parseNumericOrAutoOrPercentageValue(value);
77
76
  }
78
77
  if (className.startsWith('my-')) {
79
78
  const [, value] = className.split('-');
80
- styles.marginTop = parseNumericOrAutoOrPercentageValue(value);
81
- styles.marginBottom = parseNumericOrAutoOrPercentageValue(value);
79
+ props.marginTop = parseNumericOrAutoOrPercentageValue(value);
80
+ props.marginBottom = parseNumericOrAutoOrPercentageValue(value);
82
81
  }
83
82
  if (className.startsWith('mt-')) {
84
83
  const [, value] = className.split('-');
85
- styles.marginTop = parseNumericOrAutoOrPercentageValue(value);
84
+ props.marginTop = parseNumericOrAutoOrPercentageValue(value);
86
85
  }
87
86
  if (className.startsWith('mr-')) {
88
87
  const [, value] = className.split('-');
89
- styles.marginRight = parseNumericOrAutoOrPercentageValue(value);
88
+ props.marginRight = parseNumericOrAutoOrPercentageValue(value);
90
89
  }
91
90
  if (className.startsWith('mb-')) {
92
91
  const [, value] = className.split('-');
93
- styles.marginBottom = parseNumericOrAutoOrPercentageValue(value);
92
+ props.marginBottom = parseNumericOrAutoOrPercentageValue(value);
94
93
  }
95
94
  if (className.startsWith('ml-')) {
96
95
  const [, value] = className.split('-');
97
- styles.marginLeft = parseNumericOrAutoOrPercentageValue(value);
96
+ props.marginLeft = parseNumericOrAutoOrPercentageValue(value);
98
97
  }
99
98
  // width
100
99
  if (className.startsWith('w-')) {
101
100
  const [, value] = className.split('-');
102
- styles.width = parseNumericOrAutoOrPercentageValue(value);
101
+ props.width = parseNumericOrAutoOrPercentageValue(value);
103
102
  }
104
103
  // height
105
104
  if (className.startsWith('h-')) {
106
105
  const [, value] = className.split('-');
107
- styles.height = parseNumericOrAutoOrPercentageValue(value);
106
+ props.height = parseNumericOrAutoOrPercentageValue(value);
108
107
  }
109
108
  // flex-basis
110
109
  if (className.startsWith('basis-')) {
111
110
  const [, value] = className.split('-');
112
- styles.flexBasis = parseNumericOrAutoOrPercentageValue(value);
111
+ props.flexBasis = parseNumericOrAutoOrPercentageValue(value);
113
112
  }
114
113
  // flex-grow
115
114
  if (className.startsWith('grow-')) {
116
115
  const [, value] = className.split('-');
117
- styles.flexGrow = Number(value);
116
+ props.flexGrow = Number(value);
118
117
  }
119
118
  // flex-shrink
120
119
  if (className.startsWith('shrink-')) {
121
120
  const [, value] = className.split('-');
122
- styles.flexShrink = Number(value);
121
+ props.flexShrink = Number(value);
123
122
  }
124
123
  // flex-direction
125
124
  if (className.startsWith('flex-')) {
126
125
  // first the flex direction
127
126
  switch (className) {
128
127
  case 'flex-row':
129
- styles.flexDirection = 'Row';
128
+ props.flexDirection = 'Row';
130
129
  break;
131
130
  case 'flex-row-reverse':
132
- styles.flexDirection = 'RowReverse';
131
+ props.flexDirection = 'RowReverse';
133
132
  break;
134
133
  case 'flex-col':
135
- styles.flexDirection = 'Column';
134
+ props.flexDirection = 'Column';
136
135
  break;
137
136
  case 'flex-col-reverse':
138
- styles.flexDirection = 'ColumnReverse';
137
+ props.flexDirection = 'ColumnReverse';
139
138
  break;
140
139
  case 'flex-wrap':
141
- styles.flexWrap = 'Wrap';
140
+ props.flexWrap = 'Wrap';
142
141
  break;
143
142
  case 'flex-wrap-reverse':
144
- styles.flexWrap = 'WrapReverse';
143
+ props.flexWrap = 'WrapReverse';
145
144
  break;
146
145
  case 'flex-nowrap':
147
- styles.flexWrap = 'NoWrap';
146
+ props.flexWrap = 'NoWrap';
148
147
  break;
149
148
  default:
150
149
  // flex shorthand
151
150
  const [, value] = className.split('-');
152
- styles.flex = Number(value);
151
+ props.flex = Number(value);
153
152
  }
154
153
  }
155
154
  // justify-content
156
155
  if (className.startsWith('justify-')) {
157
156
  switch (className) {
158
157
  case 'justify-start':
159
- styles.justifyContent = 'FlexStart';
158
+ props.justifyContent = 'FlexStart';
160
159
  break;
161
160
  case 'justify-end':
162
- styles.justifyContent = 'FlexEnd';
161
+ props.justifyContent = 'FlexEnd';
163
162
  break;
164
163
  case 'justify-center':
165
- styles.justifyContent = 'Center';
164
+ props.justifyContent = 'Center';
166
165
  break;
167
166
  case 'justify-between':
168
- styles.justifyContent = 'SpaceBetween';
167
+ props.justifyContent = 'SpaceBetween';
169
168
  break;
170
169
  case 'justify-around':
171
- styles.justifyContent = 'SpaceAround';
170
+ props.justifyContent = 'SpaceAround';
172
171
  break;
173
172
  case 'justify-evenly':
174
- styles.justifyContent = 'SpaceEvenly';
173
+ props.justifyContent = 'SpaceEvenly';
175
174
  break;
176
175
  }
177
176
  }
@@ -179,19 +178,19 @@ export const tailwindParser = createClassParser((string) => {
179
178
  if (className.startsWith('items-')) {
180
179
  switch (className) {
181
180
  case 'items-start':
182
- styles.alignItems = 'FlexStart';
181
+ props.alignItems = 'FlexStart';
183
182
  break;
184
183
  case 'items-end':
185
- styles.alignItems = 'FlexEnd';
184
+ props.alignItems = 'FlexEnd';
186
185
  break;
187
186
  case 'items-center':
188
- styles.alignItems = 'Center';
187
+ props.alignItems = 'Center';
189
188
  break;
190
189
  case 'items-baseline':
191
- styles.alignItems = 'Baseline';
190
+ props.alignItems = 'Baseline';
192
191
  break;
193
192
  case 'items-stretch':
194
- styles.alignItems = 'Stretch';
193
+ props.alignItems = 'Stretch';
195
194
  break;
196
195
  }
197
196
  }
@@ -199,28 +198,28 @@ export const tailwindParser = createClassParser((string) => {
199
198
  if (className.startsWith('content-')) {
200
199
  switch (className) {
201
200
  case 'content-normal':
202
- styles.alignContent = 'Auto';
201
+ props.alignContent = 'Auto';
203
202
  break;
204
203
  case 'content-start':
205
- styles.alignContent = 'FlexStart';
204
+ props.alignContent = 'FlexStart';
206
205
  break;
207
206
  case 'content-end':
208
- styles.alignContent = 'FlexEnd';
207
+ props.alignContent = 'FlexEnd';
209
208
  break;
210
209
  case 'content-center':
211
- styles.alignContent = 'Center';
210
+ props.alignContent = 'Center';
212
211
  break;
213
212
  case 'content-between':
214
- styles.alignContent = 'SpaceBetween';
213
+ props.alignContent = 'SpaceBetween';
215
214
  break;
216
215
  case 'content-around':
217
- styles.alignContent = 'SpaceAround';
216
+ props.alignContent = 'SpaceAround';
218
217
  break;
219
218
  case 'content-stretch':
220
- styles.alignContent = 'Stretch';
219
+ props.alignContent = 'Stretch';
221
220
  break;
222
221
  case 'content-baseline':
223
- styles.alignContent = 'Baseline';
222
+ props.alignContent = 'Baseline';
224
223
  break;
225
224
  }
226
225
  }
@@ -228,73 +227,73 @@ export const tailwindParser = createClassParser((string) => {
228
227
  if (className.startsWith('self-')) {
229
228
  switch (className) {
230
229
  case 'self-auto':
231
- styles.alignSelf = 'Auto';
230
+ props.alignSelf = 'Auto';
232
231
  break;
233
232
  case 'self-start':
234
- styles.alignSelf = 'FlexStart';
233
+ props.alignSelf = 'FlexStart';
235
234
  break;
236
235
  case 'self-end':
237
- styles.alignSelf = 'FlexEnd';
236
+ props.alignSelf = 'FlexEnd';
238
237
  break;
239
238
  case 'self-center':
240
- styles.alignSelf = 'Center';
239
+ props.alignSelf = 'Center';
241
240
  break;
242
241
  case 'self-stretch':
243
- styles.alignSelf = 'Stretch';
242
+ props.alignSelf = 'Stretch';
244
243
  break;
245
244
  case 'self-baseline':
246
- styles.alignSelf = 'Baseline';
245
+ props.alignSelf = 'Baseline';
247
246
  break;
248
247
  }
249
248
  }
250
249
  // Gaps
251
250
  if (className.startsWith('gap-x-')) {
252
251
  const [, value] = className.split('-');
253
- styles.gapColumn = Number(value);
252
+ props.gapColumn = Number(value);
254
253
  }
255
254
  else if (className.startsWith('gap-y-')) {
256
255
  const [, value] = className.split('-');
257
- styles.gapRow = Number(value);
256
+ props.gapRow = Number(value);
258
257
  }
259
258
  else if (className.startsWith('gap-')) {
260
259
  const [, value] = className.split('-');
261
- styles.gap = Number(value);
260
+ props.gap = Number(value);
262
261
  }
263
262
  // Position
264
263
  if (className.startsWith('top-')) {
265
264
  const [, value] = className.split('-');
266
- styles.top = parseNumericOrPercentageValue(value);
265
+ props.top = parseNumericOrPercentageValue(value);
267
266
  }
268
267
  if (className.startsWith('right-')) {
269
268
  const [, value] = className.split('-');
270
- styles.right = parseNumericOrPercentageValue(value);
269
+ props.right = parseNumericOrPercentageValue(value);
271
270
  }
272
271
  if (className.startsWith('bottom-')) {
273
272
  const [, value] = className.split('-');
274
- styles.bottom = parseNumericOrPercentageValue(value);
273
+ props.bottom = parseNumericOrPercentageValue(value);
275
274
  }
276
275
  if (className.startsWith('left-')) {
277
276
  const [, value] = className.split('-');
278
- styles.left = parseNumericOrPercentageValue(value);
277
+ props.left = parseNumericOrPercentageValue(value);
279
278
  }
280
279
  // aspect ratio
281
280
  if (className.startsWith('aspect-')) {
282
281
  switch (className) {
283
282
  case 'aspect-square':
284
- styles.aspectRatio = 1;
283
+ props.aspectRatio = 1;
285
284
  break;
286
285
  case 'aspect-landscape':
287
- styles.aspectRatio = 16 / 9;
286
+ props.aspectRatio = 16 / 9;
288
287
  break;
289
288
  case 'aspect-portrait':
290
- styles.aspectRatio = 9 / 16;
289
+ props.aspectRatio = 9 / 16;
291
290
  break;
292
291
  default:
293
292
  const [, value] = className.split('-');
294
293
  const [width, height] = value.split('/');
295
- styles.aspectRatio = Number(width) / Number(height);
294
+ props.aspectRatio = Number(width) / Number(height);
296
295
  }
297
296
  }
298
297
  });
299
- return styles;
298
+ return props;
300
299
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threlte/flex",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
5
5
  "license": "MIT",
6
6
  "devDependencies": {
@@ -27,8 +27,8 @@
27
27
  "tslib": "^2.4.1",
28
28
  "typescript": "^5.0.0",
29
29
  "vite": "^4.3.6",
30
- "@threlte/core": "6.0.8",
31
- "@threlte/extras": "5.7.0"
30
+ "@threlte/core": "6.0.9",
31
+ "@threlte/extras": "6.0.0"
32
32
  },
33
33
  "dependencies": {
34
34
  "mitt": "^3.0.1",