@threlte/core
Advanced tools
Comparing version 8.0.0-next.36 to 8.0.0-next.37
import { type Snippet } from 'svelte'; | ||
import type { Renderer } from 'three'; | ||
import type { CreateThrelteContextOptions } from './context/createThrelteContext.svelte'; | ||
declare const Canvas: import("svelte").Component<Omit<CreateThrelteContextOptions<Renderer>, "canvas" | "wrapper"> & { | ||
declare const Canvas: import("svelte").Component<Omit<CreateThrelteContextOptions<Renderer>, "canvas" | "dom"> & { | ||
children?: Snippet; | ||
}, {}, "">; | ||
export default Canvas; |
import type { Snippet } from 'svelte'; | ||
import { type Renderer } from 'three'; | ||
declare const Context: import("svelte").Component<import("../../context/fragments/renderer.svelte").CreateRendererContextOptions<Renderer> & import("../../context/fragments/canvas").CreateCanvasContextOptions & import("../../context/fragments/scheduler.svelte").CreateSchedulerContextOptions & { | ||
declare const Context: import("svelte").Component<import("../../context/fragments/renderer.svelte").CreateRendererContextOptions<Renderer> & import("../../context/fragments/dom").CreateDOMContextOptions & import("../../context/fragments/scheduler.svelte").CreateSchedulerContextOptions & { | ||
children: Snippet; | ||
}, {}, "">; | ||
export default Context; |
import { Scene, type Camera, type ColorSpace, type ShadowMapType, type ToneMapping, type WebGLRenderer } from 'three'; | ||
import type { Scheduler, Stage, Task } from '../../frame-scheduling'; | ||
import type { CurrentReadable, CurrentWritable } from '../../utilities'; | ||
import { type Size } from '../fragments/canvas'; | ||
/** | ||
@@ -12,3 +11,5 @@ * ### `ThrelteContext` | ||
export type ThrelteContext = { | ||
size: CurrentReadable<Size>; | ||
dom: HTMLElement; | ||
canvas: HTMLCanvasElement; | ||
size: CurrentReadable<DOMRect>; | ||
camera: CurrentWritable<Camera>; | ||
@@ -15,0 +16,0 @@ scene: Scene; |
import { useCamera } from '../fragments/camera'; | ||
import { useCanvas } from '../fragments/canvas'; | ||
import { useDOM } from '../fragments/dom'; | ||
import { useRenderer } from '../fragments/renderer.svelte'; | ||
@@ -26,3 +26,3 @@ import { useScene } from '../fragments/scene'; | ||
const sceneCtx = useScene(); | ||
const canvasCtx = useCanvas(); | ||
const domCtx = useDOM(); | ||
const context = { | ||
@@ -44,3 +44,5 @@ advance: schedulerCtx.advance, | ||
shouldRender: schedulerCtx.shouldRender, | ||
size: canvasCtx.size, | ||
dom: domCtx.dom, | ||
canvas: domCtx.canvas, | ||
size: domCtx.size, | ||
toneMapping: rendererCtx.toneMapping, | ||
@@ -47,0 +49,0 @@ get scene() { |
import { type Renderer } from 'three'; | ||
import { type CreateCanvasContextOptions } from './fragments/canvas'; | ||
import { type CreateDOMContextOptions } from './fragments/dom'; | ||
import { type CreateRendererContextOptions } from './fragments/renderer.svelte'; | ||
import { type CreateSchedulerContextOptions } from './fragments/scheduler.svelte'; | ||
export type CreateThrelteContextOptions<T extends Renderer> = CreateRendererContextOptions<T> & CreateCanvasContextOptions & CreateSchedulerContextOptions; | ||
export type CreateThrelteContextOptions<T extends Renderer> = CreateRendererContextOptions<T> & CreateDOMContextOptions & CreateSchedulerContextOptions; | ||
export declare const createThrelteContext: <T extends Renderer>(options: CreateThrelteContextOptions<T>) => void; |
import { createCacheContext } from './fragments/cache'; | ||
import { createCameraContext } from './fragments/camera'; | ||
import { createCanvasContext } from './fragments/canvas'; | ||
import { createDOMContext } from './fragments/dom'; | ||
import { createDisposalContext } from './fragments/disposal'; | ||
@@ -12,3 +12,3 @@ import { createParentContext } from './fragments/parent'; | ||
export const createThrelteContext = (options) => { | ||
createCanvasContext(options); | ||
createDOMContext(options); | ||
createCacheContext(); | ||
@@ -15,0 +15,0 @@ const { scene } = createSceneContext(); |
import { getContext, setContext } from 'svelte'; | ||
import { PerspectiveCamera } from 'three'; | ||
import { currentWritable, watch } from '../../utilities'; | ||
import { useCanvas } from './canvas'; | ||
import { useDOM } from './dom'; | ||
import { useScheduler } from './scheduler.svelte'; | ||
export const createCameraContext = () => { | ||
const { size } = useCanvas(); | ||
const { size } = useDOM(); | ||
const { invalidate } = useScheduler(); | ||
@@ -9,0 +9,0 @@ // Create a default camera to use when no camera is defined by the user |
@@ -6,3 +6,3 @@ import { getContext, onDestroy, setContext } from 'svelte'; | ||
import { useCamera } from './camera'; | ||
import { useCanvas } from './canvas'; | ||
import { useDOM } from './dom'; | ||
import { useDisposal } from './disposal'; | ||
@@ -16,3 +16,3 @@ import { useScene } from './scene'; | ||
const { invalidate, renderStage, autoRender, scheduler, resetFrameInvalidation } = useScheduler(); | ||
const { canvas, size } = useCanvas(); | ||
const { size, canvas } = useDOM(); | ||
const renderer = options.createRenderer | ||
@@ -19,0 +19,0 @@ ? options.createRenderer(canvas) |
@@ -0,1 +1,10 @@ | ||
import { type CurrentWritable } from '../../utilities'; | ||
export type ThrelteUserContext = CurrentWritable<Record<string | symbol, unknown>>; | ||
export declare const createUserContext: () => void; | ||
/** | ||
* ### `useUserContext` | ||
* | ||
* @returns The user context store. The context is to be used with | ||
* `useThrelteUserContext` to set and get the user context. | ||
*/ | ||
export declare const useUserContext: () => ThrelteUserContext; |
@@ -1,2 +0,2 @@ | ||
import { setContext } from 'svelte'; | ||
import { getContext, setContext } from 'svelte'; | ||
import { currentWritable } from '../../utilities'; | ||
@@ -7,1 +7,14 @@ export const createUserContext = () => { | ||
}; | ||
/** | ||
* ### `useUserContext` | ||
* | ||
* @returns The user context store. The context is to be used with | ||
* `useThrelteUserContext` to set and get the user context. | ||
*/ | ||
export const useUserContext = () => { | ||
const context = getContext('threlte-user-context'); | ||
if (!context) { | ||
throw new Error('useUserContext can only be used in a child component to <Canvas>.'); | ||
} | ||
return context; | ||
}; |
import { type Readable } from 'svelte/store'; | ||
import type { CurrentWritable } from '../utilities'; | ||
export type ThrelteUserContext = CurrentWritable<Record<string | symbol, unknown>>; | ||
type UserContextEntry = Record<string, any>; | ||
@@ -5,0 +3,0 @@ type UserContext = Record<string, UserContextEntry>; |
@@ -1,5 +0,5 @@ | ||
import { getContext } from 'svelte'; | ||
import { derived } from 'svelte/store'; | ||
import { useUserContext } from '../context/fragments/user'; | ||
export function useThrelteUserContext(namespace, value, options) { | ||
const userCtxStore = getContext('threlte-user-context'); | ||
const userCtxStore = useUserContext(); | ||
if (!userCtxStore) { | ||
@@ -6,0 +6,0 @@ throw new Error('No user context store found, did you invoke this function outside of your main <Canvas> component?'); |
@@ -17,3 +17,3 @@ export declare const VERSION = 8; | ||
export { createCameraContext, useCamera } from './context/fragments/camera'; | ||
export { createCanvasContext, useCanvas, type Size } from './context/fragments/canvas'; | ||
export { createDOMContext, useDOM } from './context/fragments/dom'; | ||
export { createDisposalContext, useDisposal } from './context/fragments/disposal'; | ||
@@ -25,2 +25,3 @@ export { createParentContext, useParent } from './context/fragments/parent'; | ||
export { createSchedulerContext, useScheduler } from './context/fragments/scheduler.svelte'; | ||
export { createUserContext } from './context/fragments/user'; | ||
export * from './utilities'; |
@@ -18,3 +18,3 @@ export const VERSION = 8; | ||
export { createCameraContext, useCamera } from './context/fragments/camera'; | ||
export { createCanvasContext, useCanvas } from './context/fragments/canvas'; | ||
export { createDOMContext, useDOM } from './context/fragments/dom'; | ||
export { createDisposalContext, useDisposal } from './context/fragments/disposal'; | ||
@@ -26,3 +26,4 @@ export { createParentContext, useParent } from './context/fragments/parent'; | ||
export { createSchedulerContext, useScheduler } from './context/fragments/scheduler.svelte'; | ||
export { createUserContext } from './context/fragments/user'; | ||
// utils | ||
export * from './utilities'; |
{ | ||
"name": "@threlte/core", | ||
"version": "8.0.0-next.36", | ||
"version": "8.0.0-next.37", | ||
"author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
143298
3752