@threlte/theatre 0.0.3-next.0 → 0.1.0-next.2
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 +29 -6
- 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 +8 -8
- 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.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3868395: Updated prettier
|
|
8
|
+
|
|
9
|
+
## 0.1.0-next.1
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 4b67b473: The hook useStudio exposes Theatre.js' studio instance.
|
|
14
|
+
|
|
3
15
|
## 0.0.3-next.0
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
<script>import { useParent, useThrelte } from '@threlte/core';
|
|
1
|
+
<script>import { createRawEventDispatcher, useParent, useThrelte } from '@threlte/core';
|
|
2
2
|
import { TransformControls } from '@threlte/extras';
|
|
3
|
-
import { getContext, onDestroy } from 'svelte';
|
|
3
|
+
import { getContext, onDestroy, onMount } from 'svelte';
|
|
4
4
|
import { DEG2RAD, RAD2DEG } from 'three/src/math/MathUtils';
|
|
5
5
|
import { globalObjects, globalStudio } from '../consts';
|
|
6
|
-
import { createRawEventDispatcher } from './createRawEventDispatcher';
|
|
7
6
|
import { isObject3D, isOrthographicOrPerspectiveCamera, isPrimitive } from './typeGuards';
|
|
8
7
|
import { getAutoPropValue, parseAutoPropKeyByPath, resolve } from './utils';
|
|
9
8
|
export let name;
|
|
@@ -11,6 +10,10 @@ export let transform = false;
|
|
|
11
10
|
export let props = undefined;
|
|
12
11
|
export let controls = undefined;
|
|
13
12
|
export let snap = undefined;
|
|
13
|
+
/**
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
export let detach = false;
|
|
14
17
|
const parent = useParent();
|
|
15
18
|
const { invalidate } = useThrelte();
|
|
16
19
|
/**
|
|
@@ -109,19 +112,29 @@ const parsedProps = Object.entries($$restProps)
|
|
|
109
112
|
throw new Error(`Invalid prop type for auto prop ${key}: ` + typeof value + '. Expected boolean or string.');
|
|
110
113
|
})
|
|
111
114
|
.reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
115
|
+
const dispatch = createRawEventDispatcher();
|
|
112
116
|
const sheet = getContext('theatre-sheet');
|
|
113
117
|
const projectId = sheet.address.projectId;
|
|
114
118
|
const sheetId = sheet.address.sheetId;
|
|
115
119
|
const instanceId = sheet.address.sheetInstanceId;
|
|
116
|
-
const object = globalObjects.get(`${projectId}-${sheetId}-${instanceId}-${name}`) ??
|
|
120
|
+
export const object = globalObjects.get(`${projectId}-${sheetId}-${instanceId}-${name}`) ??
|
|
117
121
|
sheet.object(name, {
|
|
118
122
|
...parsedProps,
|
|
119
123
|
...props,
|
|
120
124
|
...transformProps
|
|
125
|
+
}, {
|
|
126
|
+
reconfigure: true
|
|
121
127
|
});
|
|
122
128
|
globalObjects.set(`${projectId}-${sheetId}-${instanceId}-${name}`, object);
|
|
129
|
+
onDestroy(() => {
|
|
130
|
+
if (detach) {
|
|
131
|
+
sheet.detachObject(name);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
123
134
|
let values = object.value;
|
|
124
|
-
|
|
135
|
+
onMount(() => {
|
|
136
|
+
dispatch('create', object.value);
|
|
137
|
+
});
|
|
125
138
|
let selected = false;
|
|
126
139
|
let isMouseDown = false;
|
|
127
140
|
/**
|
|
@@ -143,7 +156,7 @@ const unsubscribe = object.onValuesChange((newValues) => {
|
|
|
143
156
|
// assign new values to slot prop
|
|
144
157
|
values = newValues;
|
|
145
158
|
// dispatch events to parent component callbacks
|
|
146
|
-
|
|
159
|
+
dispatch('change', newValues);
|
|
147
160
|
// update auto props
|
|
148
161
|
Object.entries(newValues).forEach((prop) => {
|
|
149
162
|
// do not apply values while the transformControls are on
|
|
@@ -254,6 +267,7 @@ $: snapValues = {
|
|
|
254
267
|
rotate: (snap?.rotate ?? 45) * DEG2RAD,
|
|
255
268
|
scale: snap?.scale ?? 0.1
|
|
256
269
|
};
|
|
270
|
+
let space = 'local';
|
|
257
271
|
const onKeyPress = (e) => {
|
|
258
272
|
if (e.key === 't') {
|
|
259
273
|
mode = 'translate';
|
|
@@ -264,6 +278,14 @@ const onKeyPress = (e) => {
|
|
|
264
278
|
if (e.key === 's') {
|
|
265
279
|
mode = 'scale';
|
|
266
280
|
}
|
|
281
|
+
if (e.key === 'g') {
|
|
282
|
+
if (space === 'local') {
|
|
283
|
+
space = 'world';
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
space = 'local';
|
|
287
|
+
}
|
|
288
|
+
}
|
|
267
289
|
};
|
|
268
290
|
const onKeyDown = (e) => {
|
|
269
291
|
if (e.key === 'Shift') {
|
|
@@ -286,6 +308,7 @@ const onKeyUp = (e) => {
|
|
|
286
308
|
translationSnap={snapActive ? snapValues.translate : null}
|
|
287
309
|
rotationSnap={snapActive ? snapValues.rotate : null}
|
|
288
310
|
scaleSnap={snapActive ? snapValues.scale : null}
|
|
311
|
+
{space}
|
|
289
312
|
on:change={onChange}
|
|
290
313
|
on:mouseDown={onMouseDown}
|
|
291
314
|
on:mouseUp={onMouseUp}
|
|
@@ -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,16 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/theatre",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0-next.2",
|
|
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": "6.0.0-next.0",
|
|
13
|
-
"@threlte/extras": "5.0.0-next.0",
|
|
10
|
+
"@theatre/core": "0.6.0",
|
|
11
|
+
"@theatre/studio": "0.6.0",
|
|
14
12
|
"@types/node": "^18.0.3",
|
|
15
13
|
"@types/three": "^0.144.0",
|
|
16
14
|
"@typescript-eslint/eslint-plugin": "^4.31.1",
|
|
@@ -19,18 +17,20 @@
|
|
|
19
17
|
"eslint": "^7.32.0",
|
|
20
18
|
"eslint-config-prettier": "^8.3.0",
|
|
21
19
|
"eslint-plugin-svelte3": "^3.2.1",
|
|
22
|
-
"prettier": "^2.
|
|
20
|
+
"prettier": "^2.8.8",
|
|
23
21
|
"prettier-plugin-svelte": "^2.4.0",
|
|
24
22
|
"svelte": "^3.47.0",
|
|
25
23
|
"svelte-check": "^2.7.0",
|
|
26
24
|
"svelte-preprocess": "^4.10.5",
|
|
27
25
|
"svelte2tsx": "^0.5.9",
|
|
28
|
-
"three": "^0.
|
|
26
|
+
"three": "^0.151.3",
|
|
29
27
|
"ts-node": "^10.8.2",
|
|
30
28
|
"tsafe": "^0.9.0",
|
|
31
29
|
"tslib": "^2.3.1",
|
|
32
30
|
"type-fest": "^2.13.0",
|
|
33
|
-
"typescript": "^4.6.3"
|
|
31
|
+
"typescript": "^4.6.3",
|
|
32
|
+
"@threlte/core": "6.0.0-next.11",
|
|
33
|
+
"@threlte/extras": "5.0.0-next.15"
|
|
34
34
|
},
|
|
35
35
|
"type": "module",
|
|
36
36
|
"exports": {
|
|
@@ -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
|
-
}
|