Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c20ab0e

Browse files
committed
separate out transformations as hooks and export from library
1 parent 9989643 commit c20ab0e

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

‎src/Transform2d.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ export function apply2dTransforms({
7373
}
7474
}
7575

76-
const Transform2d = ({
77-
children,
76+
export function use2dTransformations({
7877
parentMatrixWorld,
7978
translate,
8079
scale,
8180
rotate,
8281
multiplicationOrder = 'POST',
83-
}: Transform2dProps)=> {
82+
}: Omit<Transform2dProps,'children'>) {
8483
const safeParentMatrixWorld = useFactoryRef<mat2d>(
8584
() => parentMatrixWorld || mat2d.create(),
8685
);
@@ -101,6 +100,28 @@ const Transform2d = ({
101100
rotate,
102101
});
103102

103+
return {
104+
matrix,
105+
matrixWorld,
106+
};
107+
}
108+
109+
const Transform2d = ({
110+
children,
111+
parentMatrixWorld,
112+
translate,
113+
scale,
114+
rotate,
115+
multiplicationOrder = 'POST',
116+
}: Transform2dProps) => {
117+
const { matrixWorld } = use2dTransformations({
118+
parentMatrixWorld,
119+
translate,
120+
scale,
121+
rotate,
122+
multiplicationOrder,
123+
});
124+
104125
const render = useRender<mat2d>({
105126
cssMatrixPrefix: 'matrix',
106127
matrixWorld,

‎src/Transform3d.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ export function apply3dTransforms({
8080
}
8181
}
8282

83-
const Transform3d = ({
84-
children,
83+
export function use3dTransformations({
8584
parentMatrixWorld,
8685
translate,
8786
scale,
8887
rotate,
8988
rotateAxis,
9089
multiplicationOrder = 'POST',
91-
}: Transform3dProps)=> {
90+
}: Omit<Transform3dProps,'children'>) {
9291
const safeParentMatrixWorld = useFactoryRef<mat4>(
9392
() => parentMatrixWorld || mat4.create(),
9493
);
@@ -112,6 +111,30 @@ const Transform3d = ({
112111
rotateAxis,
113112
});
114113

114+
return {
115+
matrix,
116+
matrixWorld,
117+
};
118+
}
119+
120+
const Transform3d = ({
121+
children,
122+
parentMatrixWorld,
123+
translate,
124+
scale,
125+
rotate,
126+
rotateAxis,
127+
multiplicationOrder = 'POST',
128+
}: Transform3dProps) => {
129+
const { matrixWorld } = use3dTransformations({
130+
parentMatrixWorld,
131+
translate,
132+
scale,
133+
rotate,
134+
rotateAxis,
135+
multiplicationOrder,
136+
});
137+
115138
const render = useRender<mat4>({
116139
cssMatrixPrefix: 'matrix3d',
117140
matrixWorld,

‎src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './propTypes';
22
export { useFactoryRef } from './useFactoryRef';
3-
export { default as Transform2d } from './Transform2d';
4-
export { default as Transform3d } from './Transform3d';
3+
export { default as Transform2d,use2dTransformations } from './Transform2d';
4+
export { default as Transform3d,use3dTransformations } from './Transform3d';
55
export type { Transform2dProps } from './Transform2d';
66
export type { Transform3dProps } from './Transform3d';
7+
export type { GLMatrixType, Vec2Object, Vec3Object } from './types';

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /