@threlte/theatre 0.0.2 → 0.1.0-next.1
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/CHANGELOG.md +12 -0
- package/dist/components/Editable/Editable.svelte +33 -17
- package/dist/components/Editable/types.d.ts +3 -0
- package/dist/components/Project/Project.svelte +1 -1
- package/dist/components/Project/Project.svelte.d.ts +2 -0
- package/dist/components/Sheet/Sheet.svelte +1 -7
- package/dist/components/Sheet/Sheet.svelte.d.ts +4 -0
- package/dist/components/Studio/InnerStudio.svelte +34 -9
- package/dist/components/Studio/InnerStudio.svelte.d.ts +8 -2
- package/dist/components/Studio/Studio.svelte +12 -4
- package/dist/components/Studio/Studio.svelte.d.ts +3 -0
- package/dist/components/Studio/useStudio.d.ts +5 -0
- package/dist/components/Studio/useStudio.js +8 -0
- package/dist/components/consts.d.ts +1 -1
- package/dist/components/consts.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/package.json +6 -5
- package/dist/components/Editable/createRawEventDispatcher.d.ts +0 -7
- package/dist/components/Editable/createRawEventDispatcher.js +0 -19
package/dist/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @threlte/extras
|
|
2
2
|
|
|
3
|
+
## 0.1.0-next.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4b67b473: The hook useStudio exposes Theatre.js' studio instance.
|
|
8
|
+
|
|
9
|
+
## 0.0.3-next.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- d41cb6cf: Adapted theatre package to new TransformControls syntax
|
|
14
|
+
|
|
3
15
|
## 0.0.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import {
|
|
1
|
+
<script>import { createRawEventDispatcher, useParent, useThrelte } from '@threlte/core';
|
|
2
|
+
import { TransformControls } from '@threlte/extras';
|
|
3
|
+
import { getContext, onDestroy, onMount } from 'svelte';
|
|
3
4
|
import { DEG2RAD, RAD2DEG } from 'three/src/math/MathUtils';
|
|
4
5
|
import { globalObjects, globalStudio } from '../consts';
|
|
5
|
-
import { createRawEventDispatcher } from './createRawEventDispatcher';
|
|
6
6
|
import { isObject3D, isOrthographicOrPerspectiveCamera, isPrimitive } from './typeGuards';
|
|
7
7
|
import { getAutoPropValue, parseAutoPropKeyByPath, resolve } from './utils';
|
|
8
8
|
export let name;
|
|
@@ -10,6 +10,10 @@ export let transform = false;
|
|
|
10
10
|
export let props = undefined;
|
|
11
11
|
export let controls = undefined;
|
|
12
12
|
export let snap = undefined;
|
|
13
|
+
/**
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
export let detach = false;
|
|
13
17
|
const parent = useParent();
|
|
14
18
|
const { invalidate } = useThrelte();
|
|
15
19
|
/**
|
|
@@ -108,19 +112,29 @@ const parsedProps = Object.entries($$restProps)
|
|
|
108
112
|
throw new Error(`Invalid prop type for auto prop ${key}: ` + typeof value + '. Expected boolean or string.');
|
|
109
113
|
})
|
|
110
114
|
.reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
115
|
+
const dispatch = createRawEventDispatcher();
|
|
111
116
|
const sheet = getContext('theatre-sheet');
|
|
112
117
|
const projectId = sheet.address.projectId;
|
|
113
118
|
const sheetId = sheet.address.sheetId;
|
|
114
119
|
const instanceId = sheet.address.sheetInstanceId;
|
|
115
|
-
const object = globalObjects.get(`${projectId}-${sheetId}-${instanceId}-${name}`) ??
|
|
120
|
+
export const object = globalObjects.get(`${projectId}-${sheetId}-${instanceId}-${name}`) ??
|
|
116
121
|
sheet.object(name, {
|
|
117
122
|
...parsedProps,
|
|
118
123
|
...props,
|
|
119
124
|
...transformProps
|
|
125
|
+
}, {
|
|
126
|
+
reconfigure: true
|
|
120
127
|
});
|
|
121
128
|
globalObjects.set(`${projectId}-${sheetId}-${instanceId}-${name}`, object);
|
|
129
|
+
onDestroy(() => {
|
|
130
|
+
if (detach) {
|
|
131
|
+
sheet.detachObject(name);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
122
134
|
let values = object.value;
|
|
123
|
-
|
|
135
|
+
onMount(() => {
|
|
136
|
+
dispatch('create', object.value);
|
|
137
|
+
});
|
|
124
138
|
let selected = false;
|
|
125
139
|
let isMouseDown = false;
|
|
126
140
|
/**
|
|
@@ -142,7 +156,7 @@ const unsubscribe = object.onValuesChange((newValues) => {
|
|
|
142
156
|
// assign new values to slot prop
|
|
143
157
|
values = newValues;
|
|
144
158
|
// dispatch events to parent component callbacks
|
|
145
|
-
|
|
159
|
+
dispatch('change', newValues);
|
|
146
160
|
// update auto props
|
|
147
161
|
Object.entries(newValues).forEach((prop) => {
|
|
148
162
|
// do not apply values while the transformControls are on
|
|
@@ -253,6 +267,7 @@ $: snapValues = {
|
|
|
253
267
|
rotate: (snap?.rotate ?? 45) * DEG2RAD,
|
|
254
268
|
scale: snap?.scale ?? 0.1
|
|
255
269
|
};
|
|
270
|
+
let space = 'local';
|
|
256
271
|
const onKeyPress = (e) => {
|
|
257
272
|
if (e.key === 't') {
|
|
258
273
|
mode = 'translate';
|
|
@@ -263,6 +278,14 @@ const onKeyPress = (e) => {
|
|
|
263
278
|
if (e.key === 's') {
|
|
264
279
|
mode = 'scale';
|
|
265
280
|
}
|
|
281
|
+
if (e.key === 'g') {
|
|
282
|
+
if (space === 'local') {
|
|
283
|
+
space = 'world';
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
space = 'local';
|
|
287
|
+
}
|
|
288
|
+
}
|
|
266
289
|
};
|
|
267
290
|
const onKeyDown = (e) => {
|
|
268
291
|
if (e.key === 'Shift') {
|
|
@@ -276,27 +299,20 @@ const onKeyUp = (e) => {
|
|
|
276
299
|
};
|
|
277
300
|
</script>
|
|
278
301
|
|
|
279
|
-
<svelte:window
|
|
280
|
-
on:keypress={onKeyPress}
|
|
281
|
-
on:keydown={onKeyDown}
|
|
282
|
-
on:keyup={onKeyUp}
|
|
283
|
-
/>
|
|
302
|
+
<svelte:window on:keypress={onKeyPress} on:keydown={onKeyDown} on:keyup={onKeyUp} />
|
|
284
303
|
|
|
285
304
|
{#if selected && isObject3D($parent) && transform && controls}
|
|
286
305
|
<TransformControls
|
|
287
306
|
{mode}
|
|
307
|
+
object={$parent}
|
|
288
308
|
translationSnap={snapActive ? snapValues.translate : null}
|
|
289
309
|
rotationSnap={snapActive ? snapValues.rotate : null}
|
|
290
310
|
scaleSnap={snapActive ? snapValues.scale : null}
|
|
311
|
+
{space}
|
|
291
312
|
on:change={onChange}
|
|
292
313
|
on:mouseDown={onMouseDown}
|
|
293
314
|
on:mouseUp={onMouseUp}
|
|
294
315
|
/>
|
|
295
316
|
{/if}
|
|
296
317
|
|
|
297
|
-
<slot
|
|
298
|
-
{values}
|
|
299
|
-
{read}
|
|
300
|
-
{sheet}
|
|
301
|
-
{object}
|
|
302
|
-
/>
|
|
318
|
+
<slot {values} {read} {sheet} {object} />
|
|
@@ -13,6 +13,8 @@ export declare type Props<T extends UnknownShorthandCompoundProps> = {
|
|
|
13
13
|
scale?: number;
|
|
14
14
|
};
|
|
15
15
|
read?: () => void;
|
|
16
|
+
object?: ISheetObject<T>;
|
|
17
|
+
detach?: boolean;
|
|
16
18
|
} & Record<string, AutoProp | any>;
|
|
17
19
|
export declare type Slots<T extends UnknownShorthandCompoundProps> = {
|
|
18
20
|
default: {
|
|
@@ -24,5 +26,6 @@ export declare type Slots<T extends UnknownShorthandCompoundProps> = {
|
|
|
24
26
|
};
|
|
25
27
|
export declare type Events<T extends UnknownShorthandCompoundProps> = {
|
|
26
28
|
change: ISheetObject<T>['value'];
|
|
29
|
+
create: ISheetObject<T>['value'];
|
|
27
30
|
};
|
|
28
31
|
export declare type PropTransform = 'none' | 'euler';
|
|
@@ -3,7 +3,7 @@ import { getProject } from '../theatre';
|
|
|
3
3
|
import { setContext } from 'svelte';
|
|
4
4
|
export let name = 'default';
|
|
5
5
|
export let config = undefined;
|
|
6
|
-
const project = globalProjects.get(name) ?? getProject(name, config);
|
|
6
|
+
export const project = globalProjects.get(name) ?? getProject(name, config);
|
|
7
7
|
globalProjects.set(name, project);
|
|
8
8
|
let isReady = false;
|
|
9
9
|
const init = async () => {
|
|
@@ -4,6 +4,7 @@ declare const __propDef: {
|
|
|
4
4
|
props: {
|
|
5
5
|
name?: string | undefined;
|
|
6
6
|
config?: IProjectConfig | undefined;
|
|
7
|
+
project?: import("@theatre/core").IProject | undefined;
|
|
7
8
|
};
|
|
8
9
|
events: {
|
|
9
10
|
[evt: string]: CustomEvent<any>;
|
|
@@ -18,5 +19,6 @@ export declare type ProjectProps = typeof __propDef.props;
|
|
|
18
19
|
export declare type ProjectEvents = typeof __propDef.events;
|
|
19
20
|
export declare type ProjectSlots = typeof __propDef.slots;
|
|
20
21
|
export default class Project extends SvelteComponentTyped<ProjectProps, ProjectEvents, ProjectSlots> {
|
|
22
|
+
get project(): import("@theatre/core").IProject;
|
|
21
23
|
}
|
|
22
24
|
export {};
|
|
@@ -11,6 +11,7 @@ declare const __propDef: {
|
|
|
11
11
|
range?: [from: number, to: number] | undefined;
|
|
12
12
|
rate?: number | undefined;
|
|
13
13
|
direction?: ("reverse" | "alternate" | "normal" | "alternateReverse") | undefined;
|
|
14
|
+
rafDriver?: import("@theatre/core").IRafDriver | undefined;
|
|
14
15
|
} & {
|
|
15
16
|
delay?: number | undefined;
|
|
16
17
|
}) | undefined;
|
|
@@ -26,6 +27,7 @@ declare const __propDef: {
|
|
|
26
27
|
range?: [from: number, to: number] | undefined;
|
|
27
28
|
rate?: number | undefined;
|
|
28
29
|
direction?: ("reverse" | "alternate" | "normal" | "alternateReverse") | undefined;
|
|
30
|
+
rafDriver?: import("@theatre/core").IRafDriver | undefined;
|
|
29
31
|
} | undefined) => Promise<boolean>) | undefined;
|
|
30
32
|
pause?: (() => void) | undefined;
|
|
31
33
|
position?: number | undefined;
|
|
@@ -43,6 +45,7 @@ declare const __propDef: {
|
|
|
43
45
|
range?: [from: number, to: number] | undefined;
|
|
44
46
|
rate?: number | undefined;
|
|
45
47
|
direction?: ("reverse" | "alternate" | "normal" | "alternateReverse") | undefined;
|
|
48
|
+
rafDriver?: import("@theatre/core").IRafDriver | undefined;
|
|
46
49
|
} | undefined) => Promise<boolean>;
|
|
47
50
|
pause: () => void;
|
|
48
51
|
};
|
|
@@ -59,6 +62,7 @@ export default class Sheet extends SvelteComponentTyped<SheetProps, SheetEvents,
|
|
|
59
62
|
range?: [from: number, to: number] | undefined;
|
|
60
63
|
rate?: number | undefined;
|
|
61
64
|
direction?: ("reverse" | "alternate" | "normal" | "alternateReverse") | undefined;
|
|
65
|
+
rafDriver?: import("@theatre/core").IRafDriver | undefined;
|
|
62
66
|
} | undefined) => Promise<boolean>;
|
|
63
67
|
get pause(): () => void;
|
|
64
68
|
}
|
|
@@ -1,16 +1,41 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import {
|
|
1
|
+
<script>import { watch } from '@threlte/core';
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
import { writable } from 'svelte/store';
|
|
4
|
+
import { globalStudio } from '../consts';
|
|
5
|
+
import { useStudio } from './useStudio';
|
|
6
|
+
export let studio = undefined;
|
|
7
|
+
export let hide;
|
|
8
|
+
const hideStore = writable(hide);
|
|
9
|
+
$: hideStore.set(hide);
|
|
10
|
+
const studioCtx = useStudio();
|
|
11
|
+
let initialized = false;
|
|
3
12
|
onMount(async () => {
|
|
4
13
|
if ($globalStudio) {
|
|
5
|
-
|
|
14
|
+
studioCtx.studio.set($globalStudio);
|
|
15
|
+
initialized = true;
|
|
6
16
|
return;
|
|
7
17
|
}
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
globalStudio.set(
|
|
18
|
+
const pkg = await import('@theatre/studio');
|
|
19
|
+
const Studio = pkg.default;
|
|
20
|
+
Studio.initialize();
|
|
21
|
+
globalStudio.set(Studio);
|
|
22
|
+
studioCtx.studio.set(Studio);
|
|
23
|
+
studio = Studio;
|
|
24
|
+
initialized = true;
|
|
12
25
|
});
|
|
13
|
-
|
|
14
|
-
|
|
26
|
+
watch([globalStudio, hideStore], ([studio, hide]) => {
|
|
27
|
+
if (hide) {
|
|
28
|
+
studio?.ui.hide();
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
studio?.ui.restore();
|
|
32
|
+
}
|
|
33
|
+
return () => {
|
|
34
|
+
studio?.ui.hide();
|
|
35
|
+
};
|
|
15
36
|
});
|
|
16
37
|
</script>
|
|
38
|
+
|
|
39
|
+
{#if initialized}
|
|
40
|
+
<slot />
|
|
41
|
+
{/if}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { IStudio } from '@theatre/studio';
|
|
2
3
|
declare const __propDef: {
|
|
3
|
-
props: {
|
|
4
|
+
props: {
|
|
5
|
+
studio?: IStudio | undefined;
|
|
6
|
+
hide: boolean;
|
|
7
|
+
};
|
|
4
8
|
events: {
|
|
5
9
|
[evt: string]: CustomEvent<any>;
|
|
6
10
|
};
|
|
7
|
-
slots: {
|
|
11
|
+
slots: {
|
|
12
|
+
default: {};
|
|
13
|
+
};
|
|
8
14
|
};
|
|
9
15
|
export declare type InnerStudioProps = typeof __propDef.props;
|
|
10
16
|
export declare type InnerStudioEvents = typeof __propDef.events;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
<script>import
|
|
1
|
+
<script>import { currentWritable } from '@threlte/core';
|
|
2
|
+
import { setContext } from 'svelte';
|
|
3
|
+
import InnerStudio from './InnerStudio.svelte';
|
|
2
4
|
export let enabled = true;
|
|
5
|
+
export let hide = false;
|
|
3
6
|
const browser = typeof window !== 'undefined';
|
|
7
|
+
export let studio = undefined;
|
|
8
|
+
const studioCtx = currentWritable(undefined);
|
|
9
|
+
setContext('theatre-studio', studioCtx);
|
|
4
10
|
</script>
|
|
5
11
|
|
|
6
12
|
{#if browser && enabled}
|
|
7
|
-
<InnerStudio
|
|
13
|
+
<InnerStudio bind:studio {hide}>
|
|
14
|
+
<slot />
|
|
15
|
+
</InnerStudio>
|
|
16
|
+
{:else}
|
|
17
|
+
<slot />
|
|
8
18
|
{/if}
|
|
9
|
-
|
|
10
|
-
<slot />
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { IStudio } from '@theatre/studio';
|
|
2
3
|
declare const __propDef: {
|
|
3
4
|
props: {
|
|
4
5
|
enabled?: boolean | undefined;
|
|
6
|
+
hide?: boolean | undefined;
|
|
7
|
+
studio?: IStudio | undefined;
|
|
5
8
|
};
|
|
6
9
|
events: {
|
|
7
10
|
[evt: string]: CustomEvent<any>;
|
|
@@ -3,4 +3,4 @@ import type { IStudio } from '@theatre/studio';
|
|
|
3
3
|
export declare const globalProjects: Map<string, IProject>;
|
|
4
4
|
export declare const globalSheets: Map<string, ISheet>;
|
|
5
5
|
export declare const globalObjects: Map<string, ISheetObject<import("@theatre/core").UnknownShorthandCompoundProps>>;
|
|
6
|
-
export declare const globalStudio: import("
|
|
6
|
+
export declare const globalStudio: import("@threlte/core").CurrentWritable<IStudio | undefined>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { currentWritable } from '@threlte/core';
|
|
2
2
|
export const globalProjects = new Map();
|
|
3
3
|
export const globalSheets = new Map();
|
|
4
4
|
export const globalObjects = new Map();
|
|
5
|
-
export const globalStudio =
|
|
5
|
+
export const globalStudio = currentWritable(undefined);
|
package/dist/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { default as Project } from './components/Project/Project.svelte';
|
|
|
3
3
|
export { default as Sheet } from './components/Sheet/Sheet.svelte';
|
|
4
4
|
export { default as Editable } from './components/Editable/Editable.svelte';
|
|
5
5
|
export { default as Theatre } from './components/Theatre/Theatre.svelte';
|
|
6
|
+
export { useStudio } from './components/Studio/useStudio';
|
package/dist/index.js
CHANGED
|
@@ -4,3 +4,5 @@ export { default as Project } from './components/Project/Project.svelte';
|
|
|
4
4
|
export { default as Sheet } from './components/Sheet/Sheet.svelte';
|
|
5
5
|
export { default as Editable } from './components/Editable/Editable.svelte';
|
|
6
6
|
export { default as Theatre } from './components/Theatre/Theatre.svelte';
|
|
7
|
+
// hooks
|
|
8
|
+
export { useStudio } from './components/Studio/useStudio';
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/theatre",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.1.0-next.1",
|
|
4
4
|
"author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@sveltejs/adapter-auto": "1.0.0-next.61",
|
|
8
8
|
"@sveltejs/adapter-static": "1.0.0-next.35",
|
|
9
9
|
"@sveltejs/kit": "1.0.0-next.377",
|
|
10
|
-
"@theatre/core": "0.
|
|
11
|
-
"@theatre/studio": "0.
|
|
12
|
-
"@threlte/core": "
|
|
10
|
+
"@theatre/core": "0.6.0",
|
|
11
|
+
"@theatre/studio": "0.6.0",
|
|
12
|
+
"@threlte/core": "6.0.0-next.2",
|
|
13
|
+
"@threlte/extras": "5.0.0-next.5",
|
|
13
14
|
"@types/node": "^18.0.3",
|
|
14
15
|
"@types/three": "^0.144.0",
|
|
15
16
|
"@typescript-eslint/eslint-plugin": "^4.31.1",
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
"svelte-check": "^2.7.0",
|
|
25
26
|
"svelte-preprocess": "^4.10.5",
|
|
26
27
|
"svelte2tsx": "^0.5.9",
|
|
27
|
-
"three": "^0.
|
|
28
|
+
"three": "^0.151.3",
|
|
28
29
|
"ts-node": "^10.8.2",
|
|
29
30
|
"tsafe": "^0.9.0",
|
|
30
31
|
"tslib": "^2.3.1",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This event dispatcher creates Raw Events unline sveltes own event dispatcher
|
|
3
|
-
* which nests the data in a detail object. This is not nesessary for our use
|
|
4
|
-
* case and makes it harder to work with the data.
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export declare function createRawEventDispatcher<EventMap extends Record<string, unknown> = any>(): <EventKey extends Extract<keyof EventMap, string>>(type: EventKey, value?: EventMap[EventKey]) => void;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { get_current_component } from 'svelte/internal';
|
|
2
|
-
/**
|
|
3
|
-
* This event dispatcher creates Raw Events unline sveltes own event dispatcher
|
|
4
|
-
* which nests the data in a detail object. This is not nesessary for our use
|
|
5
|
-
* case and makes it harder to work with the data.
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export function createRawEventDispatcher() {
|
|
9
|
-
const component = get_current_component();
|
|
10
|
-
const dispatchRawEvent = (type, value) => {
|
|
11
|
-
const callbacks = component.$$.callbacks[type];
|
|
12
|
-
if (callbacks) {
|
|
13
|
-
callbacks.forEach((fn) => {
|
|
14
|
-
fn(value);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
return dispatchRawEvent;
|
|
19
|
-
}
|