@tomorrowevening/theatre-core 1.0.4 → 1.0.5
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/CoreBundle.d.ts +19 -0
- package/dist/CoreBundle.d.ts.map +1 -0
- package/dist/CoreBundle.js +27 -0
- package/dist/_coreLogger.d.ts +7 -0
- package/dist/_coreLogger.d.ts.map +1 -0
- package/dist/_coreLogger.js +32 -0
- package/dist/coreExports.d.ts +77 -0
- package/dist/coreExports.d.ts.map +1 -0
- package/dist/coreExports.js +163 -0
- package/dist/coreTicker.d.ts +16 -0
- package/dist/coreTicker.d.ts.map +1 -0
- package/dist/coreTicker.js +61 -0
- package/dist/index.d.ts +10 -12
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +80 -7767
- package/dist/index.js.map +2 -2
- package/dist/privateAPIs.d.ts +27 -0
- package/dist/privateAPIs.d.ts.map +1 -0
- package/dist/privateAPIs.js +10 -0
- package/dist/projects/Project.d.ts +67 -0
- package/dist/projects/Project.d.ts.map +1 -0
- package/dist/projects/Project.js +153 -0
- package/dist/projects/TheatreProject.d.ts +64 -0
- package/dist/projects/TheatreProject.d.ts.map +1 -0
- package/dist/projects/TheatreProject.js +42 -0
- package/dist/projects/initialiseProjectState.d.ts +10 -0
- package/dist/projects/initialiseProjectState.d.ts.map +1 -0
- package/dist/projects/initialiseProjectState.js +96 -0
- package/dist/projects/projectsSingleton.d.ts +19 -0
- package/dist/projects/projectsSingleton.d.ts.map +1 -0
- package/dist/projects/projectsSingleton.js +19 -0
- package/dist/projects/store/storeTypes.d.ts +48 -0
- package/dist/projects/store/storeTypes.d.ts.map +1 -0
- package/dist/projects/store/storeTypes.js +1 -0
- package/dist/projects/store/types/SheetState_Historic.d.ts +94 -0
- package/dist/projects/store/types/SheetState_Historic.d.ts.map +1 -0
- package/dist/projects/store/types/SheetState_Historic.js +1 -0
- package/dist/propTypes/index.d.ts +343 -0
- package/dist/propTypes/index.d.ts.map +1 -0
- package/dist/propTypes/index.js +536 -0
- package/dist/propTypes/internals.d.ts +34 -0
- package/dist/propTypes/internals.d.ts.map +1 -0
- package/dist/propTypes/internals.js +63 -0
- package/dist/rafDrivers.d.ts +123 -0
- package/dist/rafDrivers.d.ts.map +1 -0
- package/dist/rafDrivers.js +120 -0
- package/dist/sequences/Sequence.d.ts +87 -0
- package/dist/sequences/Sequence.d.ts.map +1 -0
- package/dist/sequences/Sequence.js +368 -0
- package/dist/sequences/Sequence.test.d.ts +2 -0
- package/dist/sequences/Sequence.test.d.ts.map +1 -0
- package/dist/sequences/Sequence.test.js +56 -0
- package/dist/sequences/TheatreSequence.d.ts +309 -0
- package/dist/sequences/TheatreSequence.d.ts.map +1 -0
- package/dist/sequences/TheatreSequence.js +189 -0
- package/dist/sequences/interpolationTripleAtPosition.d.ts +14 -0
- package/dist/sequences/interpolationTripleAtPosition.d.ts.map +1 -0
- package/dist/sequences/interpolationTripleAtPosition.js +168 -0
- package/dist/sequences/playbackControllers/AudioPlaybackController.d.ts +24 -0
- package/dist/sequences/playbackControllers/AudioPlaybackController.d.ts.map +1 -0
- package/dist/sequences/playbackControllers/AudioPlaybackController.js +189 -0
- package/dist/sequences/playbackControllers/DefaultPlaybackController.d.ts +42 -0
- package/dist/sequences/playbackControllers/DefaultPlaybackController.d.ts.map +1 -0
- package/dist/sequences/playbackControllers/DefaultPlaybackController.js +177 -0
- package/dist/sheetObjects/SheetObject.d.ts +50 -0
- package/dist/sheetObjects/SheetObject.d.ts.map +1 -0
- package/dist/sheetObjects/SheetObject.js +212 -0
- package/dist/sheetObjects/SheetObject.test.d.ts +2 -0
- package/dist/sheetObjects/SheetObject.test.d.ts.map +1 -0
- package/dist/sheetObjects/SheetObject.test.js +268 -0
- package/dist/sheetObjects/SheetObjectTemplate.d.ts +92 -0
- package/dist/sheetObjects/SheetObjectTemplate.d.ts.map +1 -0
- package/dist/sheetObjects/SheetObjectTemplate.js +196 -0
- package/dist/sheetObjects/SheetObjectTemplate.test.d.ts +2 -0
- package/dist/sheetObjects/SheetObjectTemplate.test.d.ts.map +1 -0
- package/dist/sheetObjects/SheetObjectTemplate.test.js +92 -0
- package/dist/sheetObjects/TheatreSheetObject.d.ts +102 -0
- package/dist/sheetObjects/TheatreSheetObject.d.ts.map +1 -0
- package/dist/sheetObjects/TheatreSheetObject.js +80 -0
- package/dist/sheetObjects/getOrderingOfPropTypeConfig.d.ts +8 -0
- package/dist/sheetObjects/getOrderingOfPropTypeConfig.d.ts.map +1 -0
- package/dist/sheetObjects/getOrderingOfPropTypeConfig.js +49 -0
- package/dist/sheetObjects/getPropDefaultsOfSheetObject.d.ts +7 -0
- package/dist/sheetObjects/getPropDefaultsOfSheetObject.d.ts.map +1 -0
- package/dist/sheetObjects/getPropDefaultsOfSheetObject.js +35 -0
- package/dist/sheets/Sheet.d.ts +42 -0
- package/dist/sheets/Sheet.d.ts.map +1 -0
- package/dist/sheets/Sheet.js +68 -0
- package/dist/sheets/SheetTemplate.d.ts +24 -0
- package/dist/sheets/SheetTemplate.d.ts.map +1 -0
- package/dist/sheets/SheetTemplate.js +32 -0
- package/dist/sheets/TheatreSheet.d.ts +105 -0
- package/dist/sheets/TheatreSheet.d.ts.map +1 -0
- package/dist/sheets/TheatreSheet.js +106 -0
- package/package.json +2 -2
- package/dist/index.mjs +0 -7766
- package/dist/index.mjs.map +0 -7
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Studio } from '@tomorrowevening/theatre-studio/Studio';
|
|
2
|
+
import projectsSingleton from './projects/projectsSingleton';
|
|
3
|
+
import { privateAPI } from './privateAPIs';
|
|
4
|
+
import * as coreExports from './coreExports';
|
|
5
|
+
import { getCoreRafDriver } from './coreTicker';
|
|
6
|
+
export type CoreBits = {
|
|
7
|
+
projectsP: typeof projectsSingleton.atom.pointer.projects;
|
|
8
|
+
privateAPI: typeof privateAPI;
|
|
9
|
+
coreExports: typeof coreExports;
|
|
10
|
+
getCoreRafDriver: typeof getCoreRafDriver;
|
|
11
|
+
};
|
|
12
|
+
export default class CoreBundle {
|
|
13
|
+
private _studio;
|
|
14
|
+
constructor();
|
|
15
|
+
get type(): 'Theatre_CoreBundle';
|
|
16
|
+
get version(): string | undefined;
|
|
17
|
+
getBitsForStudio(studio: Studio, callback: (bits: CoreBits) => void): void;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=CoreBundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoreBundle.d.ts","sourceRoot":"","sources":["../../../../core/src/CoreBundle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,wCAAwC,CAAA;AAClE,OAAO,iBAAiB,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,WAAW,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAA;AAE7C,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,EAAE,OAAO,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAA;IACzD,UAAU,EAAE,OAAO,UAAU,CAAA;IAC7B,WAAW,EAAE,OAAO,WAAW,CAAA;IAC/B,gBAAgB,EAAE,OAAO,gBAAgB,CAAA;CAC1C,CAAA;AAED,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,OAAO,CAAgC;;IAG/C,IAAI,IAAI,IAAI,oBAAoB,CAE/B;IAED,IAAI,OAAO,uBAEV;IAED,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI;CAcpE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import projectsSingleton from './projects/projectsSingleton';
|
|
2
|
+
import { privateAPI } from './privateAPIs';
|
|
3
|
+
import * as coreExports from './coreExports';
|
|
4
|
+
import { getCoreRafDriver } from './coreTicker';
|
|
5
|
+
export default class CoreBundle {
|
|
6
|
+
_studio = undefined;
|
|
7
|
+
constructor() { }
|
|
8
|
+
get type() {
|
|
9
|
+
return 'Theatre_CoreBundle';
|
|
10
|
+
}
|
|
11
|
+
get version() {
|
|
12
|
+
return process.env.THEATRE_VERSION;
|
|
13
|
+
}
|
|
14
|
+
getBitsForStudio(studio, callback) {
|
|
15
|
+
if (this._studio) {
|
|
16
|
+
throw new Error(`@tomorrowevening/theatre-core is already attached to @tomorrowevening/theatre-studio`);
|
|
17
|
+
}
|
|
18
|
+
this._studio = studio;
|
|
19
|
+
const bits = {
|
|
20
|
+
projectsP: projectsSingleton.atom.pointer.projects,
|
|
21
|
+
privateAPI: privateAPI,
|
|
22
|
+
coreExports,
|
|
23
|
+
getCoreRafDriver,
|
|
24
|
+
};
|
|
25
|
+
callback(bits);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ITheatreLoggerConfig, ITheatreLoggingConfig } from '@tomorrowevening/theatre-shared/logger';
|
|
2
|
+
export type CoreLoggingConfig = Partial<{
|
|
3
|
+
logger: ITheatreLoggerConfig;
|
|
4
|
+
logging: ITheatreLoggingConfig;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function _coreLogger(config?: CoreLoggingConfig): import("@tomorrowevening/theatre-shared/logger").ILogger;
|
|
7
|
+
//# sourceMappingURL=_coreLogger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_coreLogger.d.ts","sourceRoot":"","sources":["../../../../core/src/_coreLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,wCAAwC,CAAA;AAI/C,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC;IACtC,MAAM,EAAE,oBAAoB,CAAA;IAC5B,OAAO,EAAE,qBAAqB,CAAA;CAC/B,CAAC,CAAA;AAIF,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,iBAAiB,4DA4BrD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TheatreLoggerLevel } from '@tomorrowevening/theatre-shared/logger';
|
|
2
|
+
import { createTheatreInternalLogger } from '@tomorrowevening/theatre-shared/logger';
|
|
3
|
+
function noop() { }
|
|
4
|
+
export function _coreLogger(config) {
|
|
5
|
+
const internalMin = config?.logging?.internal
|
|
6
|
+
? config.logging.min ?? TheatreLoggerLevel.WARN
|
|
7
|
+
: Infinity; // if not internal, then don't show any logs
|
|
8
|
+
const shouldDebugLogger = internalMin <= TheatreLoggerLevel.DEBUG;
|
|
9
|
+
const shouldShowLoggerErrors = internalMin <= TheatreLoggerLevel.ERROR;
|
|
10
|
+
const internal = createTheatreInternalLogger(undefined, {
|
|
11
|
+
_debug: shouldDebugLogger
|
|
12
|
+
? console.debug.bind(console, '_coreLogger(TheatreInternalLogger) debug')
|
|
13
|
+
: noop,
|
|
14
|
+
_error: shouldShowLoggerErrors
|
|
15
|
+
? console.error.bind(console, '_coreLogger(TheatreInternalLogger) error')
|
|
16
|
+
: noop,
|
|
17
|
+
});
|
|
18
|
+
if (config) {
|
|
19
|
+
const { logger, logging } = config;
|
|
20
|
+
if (logger)
|
|
21
|
+
internal.configureLogger(logger);
|
|
22
|
+
if (logging)
|
|
23
|
+
internal.configureLogging(logging);
|
|
24
|
+
else {
|
|
25
|
+
// default to showing Theatre.js dev logs in non-production environments
|
|
26
|
+
internal.configureLogging({
|
|
27
|
+
dev: process.env.NODE_ENV !== 'production',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return internal.getLogger().named('Theatre');
|
|
32
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { IProject, IProjectConfig } from './projects/TheatreProject';
|
|
2
|
+
import * as types from './propTypes';
|
|
3
|
+
import type { PointerType, Prism } from '@tomorrowevening/theatre-dataverse';
|
|
4
|
+
import type { $IntentionalAny, VoidFn } from '@tomorrowevening/theatre-shared/utils/types';
|
|
5
|
+
import type { IRafDriver } from './rafDrivers';
|
|
6
|
+
export { notify } from '@tomorrowevening/theatre-shared/notify';
|
|
7
|
+
export { types };
|
|
8
|
+
export { createRafDriver } from './rafDrivers';
|
|
9
|
+
export type { IRafDriver } from './rafDrivers';
|
|
10
|
+
/**
|
|
11
|
+
* Returns a project of the given id, or creates one if it doesn't already exist.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* If \@tomorrowevening/theatre-studio is also loaded, then the state of the project will be managed by the studio.
|
|
15
|
+
*
|
|
16
|
+
* [Learn more about exporting](https://www.theatrejs.com/docs/latest/manual/projects#state)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* Usage:
|
|
20
|
+
* ```ts
|
|
21
|
+
* import {getProject} from '@tomorrowevening/theatre-core'
|
|
22
|
+
* const config = {} // the config can be empty when starting a new project
|
|
23
|
+
* const project = getProject("a-unique-id", config)
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* Usage with an explicit state:
|
|
28
|
+
* ```ts
|
|
29
|
+
* import {getProject} from '@tomorrowevening/theatre-core'
|
|
30
|
+
* import state from './saved-state.json'
|
|
31
|
+
* const config = {state} // here the config contains our saved state
|
|
32
|
+
* const project = getProject("a-unique-id", config)
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function getProject(id: string, config?: IProjectConfig): IProject;
|
|
36
|
+
/**
|
|
37
|
+
* Calls `callback` every time the pointed value of `pointer` changes.
|
|
38
|
+
*
|
|
39
|
+
* @param pointer - A Pointer (like `object.props.x`)
|
|
40
|
+
* @param callback - The callback is called every time the value of pointer changes
|
|
41
|
+
* @param rafDriver - (optional) The `rafDriver` to use. Learn how to use `rafDriver`s [from the docs](https://www.theatrejs.com/docs/latest/manual/advanced#rafdrivers).
|
|
42
|
+
* @returns An unsubscribe function
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* Usage:
|
|
46
|
+
* ```ts
|
|
47
|
+
* import {getProject, onChange} from '@tomorrowevening/theatre-core'
|
|
48
|
+
*
|
|
49
|
+
* const obj = getProject("A project").sheet("Scene").object("Box", {position: {x: 0}})
|
|
50
|
+
*
|
|
51
|
+
* const usubscribe = onChange(obj.props.position.x, (x) => {
|
|
52
|
+
* console.log('position.x changed to:', x)
|
|
53
|
+
* })
|
|
54
|
+
*
|
|
55
|
+
* setTimeout(usubscribe, 10000) // stop listening to changes after 10 seconds
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function onChange<P extends PointerType<$IntentionalAny> | Prism<$IntentionalAny>>(pointer: P, callback: (value: P extends PointerType<infer T> ? T : P extends Prism<infer T> ? T : unknown) => void, rafDriver?: IRafDriver): VoidFn;
|
|
59
|
+
/**
|
|
60
|
+
* Takes a Pointer and returns the value it points to.
|
|
61
|
+
*
|
|
62
|
+
* @param pointer - A pointer (like `object.props.x`)
|
|
63
|
+
* @returns The value the pointer points to
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
*
|
|
67
|
+
* Usage
|
|
68
|
+
* ```ts
|
|
69
|
+
* import {val, getProject} from '@tomorrowevening/theatre-core'
|
|
70
|
+
*
|
|
71
|
+
* const obj = getProject("A project").sheet("Scene").object("Box", {position: {x: 0}})
|
|
72
|
+
*
|
|
73
|
+
* console.log(val(obj.props.position.x)) // logs the value of obj.props.x
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function val<T>(pointer: PointerType<T>): T;
|
|
77
|
+
//# sourceMappingURL=coreExports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coreExports.d.ts","sourceRoot":"","sources":["../../../../core/src/coreExports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,QAAQ,EAAE,cAAc,EAAC,MAAM,2BAA2B,CAAA;AAGvE,OAAO,KAAK,KAAK,MAAM,aAAa,CAAA;AAKpC,OAAO,KAAK,EAAC,WAAW,EAAE,KAAK,EAAC,MAAM,oCAAoC,CAAA;AAG1E,OAAO,KAAK,EAAC,eAAe,EAAE,MAAM,EAAC,MAAM,6CAA6C,CAAA;AAIxF,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AAE5C,OAAO,EAAC,MAAM,EAAC,MAAM,wCAAwC,CAAA;AAC7D,OAAO,EAAC,KAAK,EAAC,CAAA;AACd,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAA;AAC5C,YAAY,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,GAAE,cAAmB,GAAG,QAAQ,CAsC5E;AAgDD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,QAAQ,CACtB,CAAC,SAAS,WAAW,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC,EAE/D,OAAO,EAAE,CAAC,EACV,QAAQ,EAAE,CACR,KAAK,EAAE,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GACjC,CAAC,GACD,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GACxB,CAAC,GACD,OAAO,KACR,IAAI,EACT,SAAS,CAAC,EAAE,UAAU,GACrB,MAAM,CAaR;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAMjD"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import projectsSingleton from './projects/projectsSingleton';
|
|
2
|
+
import TheatreProject from './projects/TheatreProject';
|
|
3
|
+
import globals from '@tomorrowevening/theatre-shared/globals';
|
|
4
|
+
import * as types from './propTypes';
|
|
5
|
+
import { InvalidArgumentError } from '@tomorrowevening/theatre-shared/utils/errors';
|
|
6
|
+
import { validateName } from '@tomorrowevening/theatre-shared/utils/sanitizers';
|
|
7
|
+
import userReadableTypeOfValue from '@tomorrowevening/theatre-shared/utils/userReadableTypeOfValue';
|
|
8
|
+
import deepEqual from 'fast-deep-equal';
|
|
9
|
+
import { isPointer } from '@tomorrowevening/theatre-dataverse';
|
|
10
|
+
import { isPrism, pointerToPrism } from '@tomorrowevening/theatre-dataverse';
|
|
11
|
+
import { _coreLogger } from './_coreLogger';
|
|
12
|
+
import { getCoreTicker } from './coreTicker';
|
|
13
|
+
import { privateAPI } from './privateAPIs';
|
|
14
|
+
export { notify } from '@tomorrowevening/theatre-shared/notify';
|
|
15
|
+
export { types };
|
|
16
|
+
export { createRafDriver } from './rafDrivers';
|
|
17
|
+
/**
|
|
18
|
+
* Returns a project of the given id, or creates one if it doesn't already exist.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* If \@tomorrowevening/theatre-studio is also loaded, then the state of the project will be managed by the studio.
|
|
22
|
+
*
|
|
23
|
+
* [Learn more about exporting](https://www.theatrejs.com/docs/latest/manual/projects#state)
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* Usage:
|
|
27
|
+
* ```ts
|
|
28
|
+
* import {getProject} from '@tomorrowevening/theatre-core'
|
|
29
|
+
* const config = {} // the config can be empty when starting a new project
|
|
30
|
+
* const project = getProject("a-unique-id", config)
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* Usage with an explicit state:
|
|
35
|
+
* ```ts
|
|
36
|
+
* import {getProject} from '@tomorrowevening/theatre-core'
|
|
37
|
+
* import state from './saved-state.json'
|
|
38
|
+
* const config = {state} // here the config contains our saved state
|
|
39
|
+
* const project = getProject("a-unique-id", config)
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function getProject(id, config = {}) {
|
|
43
|
+
const existingProject = projectsSingleton.get(id);
|
|
44
|
+
if (existingProject) {
|
|
45
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
46
|
+
if (!deepEqual(config, existingProject.config)) {
|
|
47
|
+
throw new Error(`You seem to have called Theatre.getProject("${id}", config) twice, with different config objects. ` +
|
|
48
|
+
`This is disallowed because changing the config of a project on the fly can lead to hard-to-debug issues.\n\n` +
|
|
49
|
+
`You can fix this by either calling Theatre.getProject() once per projectId,` +
|
|
50
|
+
` or calling it multiple times but with the exact same config.`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return existingProject.publicApi;
|
|
54
|
+
}
|
|
55
|
+
const rootLogger = _coreLogger();
|
|
56
|
+
const plogger = rootLogger.named('Project', id);
|
|
57
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
58
|
+
validateName(id, 'projectName in Theatre.getProject(projectName)', true);
|
|
59
|
+
validateProjectIdOrThrow(id);
|
|
60
|
+
plogger._debug('validated projectName', { projectName: id });
|
|
61
|
+
}
|
|
62
|
+
if (config.state) {
|
|
63
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
64
|
+
shallowValidateOnDiskState(id, config.state);
|
|
65
|
+
plogger._debug('shallow validated config.state on disk');
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
deepValidateOnDiskState(id, config.state);
|
|
69
|
+
plogger._debug('deep validated config.state on disk');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
plogger._debug('no config.state');
|
|
74
|
+
}
|
|
75
|
+
return new TheatreProject(id, config);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Lightweight validator that only makes sure the state's definitionVersion is correct.
|
|
79
|
+
* Does not do a thorough validation of the state.
|
|
80
|
+
*/
|
|
81
|
+
const shallowValidateOnDiskState = (projectId, s) => {
|
|
82
|
+
if (Array.isArray(s) ||
|
|
83
|
+
s == null ||
|
|
84
|
+
s.definitionVersion !== globals.currentProjectStateDefinitionVersion) {
|
|
85
|
+
throw new InvalidArgumentError(`Error validating conf.state in Theatre.getProject(${JSON.stringify(projectId)}, conf). The state seems to be formatted in a way that is unreadable to Theatre.js. Read more at https://www.theatrejs.com/docs/latest/manual/projects#state`);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const deepValidateOnDiskState = (projectId, s) => {
|
|
89
|
+
shallowValidateOnDiskState(projectId, s);
|
|
90
|
+
// @TODO do a deep validation here
|
|
91
|
+
};
|
|
92
|
+
const validateProjectIdOrThrow = (value) => {
|
|
93
|
+
if (typeof value !== 'string') {
|
|
94
|
+
throw new InvalidArgumentError(`Argument 'projectId' in \`Theatre.getProject(projectId, ...)\` must be a string. Instead, it was ${userReadableTypeOfValue(value)}.`);
|
|
95
|
+
}
|
|
96
|
+
const idTrimmed = value.trim();
|
|
97
|
+
if (idTrimmed.length !== value.length) {
|
|
98
|
+
throw new InvalidArgumentError(`Argument 'projectId' in \`Theatre.getProject("${value}", ...)\` should not have surrounding whitespace.`);
|
|
99
|
+
}
|
|
100
|
+
if (idTrimmed.length < 3) {
|
|
101
|
+
throw new InvalidArgumentError(`Argument 'projectId' in \`Theatre.getProject("${value}", ...)\` should be at least 3 characters long.`);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Calls `callback` every time the pointed value of `pointer` changes.
|
|
106
|
+
*
|
|
107
|
+
* @param pointer - A Pointer (like `object.props.x`)
|
|
108
|
+
* @param callback - The callback is called every time the value of pointer changes
|
|
109
|
+
* @param rafDriver - (optional) The `rafDriver` to use. Learn how to use `rafDriver`s [from the docs](https://www.theatrejs.com/docs/latest/manual/advanced#rafdrivers).
|
|
110
|
+
* @returns An unsubscribe function
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* Usage:
|
|
114
|
+
* ```ts
|
|
115
|
+
* import {getProject, onChange} from '@tomorrowevening/theatre-core'
|
|
116
|
+
*
|
|
117
|
+
* const obj = getProject("A project").sheet("Scene").object("Box", {position: {x: 0}})
|
|
118
|
+
*
|
|
119
|
+
* const usubscribe = onChange(obj.props.position.x, (x) => {
|
|
120
|
+
* console.log('position.x changed to:', x)
|
|
121
|
+
* })
|
|
122
|
+
*
|
|
123
|
+
* setTimeout(usubscribe, 10000) // stop listening to changes after 10 seconds
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export function onChange(pointer, callback, rafDriver) {
|
|
127
|
+
const ticker = rafDriver ? privateAPI(rafDriver).ticker : getCoreTicker();
|
|
128
|
+
if (isPointer(pointer)) {
|
|
129
|
+
const pr = pointerToPrism(pointer);
|
|
130
|
+
return pr.onChange(ticker, callback, true);
|
|
131
|
+
}
|
|
132
|
+
else if (isPrism(pointer)) {
|
|
133
|
+
return pointer.onChange(ticker, callback, true);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
throw new Error(`Called onChange(p) where p is neither a pointer nor a prism.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Takes a Pointer and returns the value it points to.
|
|
141
|
+
*
|
|
142
|
+
* @param pointer - A pointer (like `object.props.x`)
|
|
143
|
+
* @returns The value the pointer points to
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
*
|
|
147
|
+
* Usage
|
|
148
|
+
* ```ts
|
|
149
|
+
* import {val, getProject} from '@tomorrowevening/theatre-core'
|
|
150
|
+
*
|
|
151
|
+
* const obj = getProject("A project").sheet("Scene").object("Box", {position: {x: 0}})
|
|
152
|
+
*
|
|
153
|
+
* console.log(val(obj.props.position.x)) // logs the value of obj.props.x
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export function val(pointer) {
|
|
157
|
+
if (isPointer(pointer)) {
|
|
158
|
+
return pointerToPrism(pointer).getValue();
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
throw new Error(`Called val(p) where p is not a pointer.`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Ticker } from '@tomorrowevening/theatre-dataverse';
|
|
2
|
+
import type { IRafDriver, RafDriverPrivateAPI } from './rafDrivers';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the rafDriver that is used by the core internally. Creates a new one if it's not set yet.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getCoreRafDriver(): RafDriverPrivateAPI;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @returns The ticker that is used by the core internally.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getCoreTicker(): Ticker;
|
|
12
|
+
/**
|
|
13
|
+
* Sets the rafDriver that is used by the core internally.
|
|
14
|
+
*/
|
|
15
|
+
export declare function setCoreRafDriver(driver: IRafDriver): void;
|
|
16
|
+
//# sourceMappingURL=coreTicker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coreTicker.d.ts","sourceRoot":"","sources":["../../../../core/src/coreTicker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,oCAAoC,CAAA;AAE9D,OAAO,KAAK,EAAC,UAAU,EAAE,mBAAmB,EAAC,MAAM,cAAc,CAAA;AAuCjE;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,mBAAmB,CAKtD;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,QAMlD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { privateAPI } from './privateAPIs';
|
|
2
|
+
import { createRafDriver } from './rafDrivers';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a rafDrive that uses `window.requestAnimationFrame` in browsers,
|
|
5
|
+
* or a single `setTimeout` in SSR.
|
|
6
|
+
*/
|
|
7
|
+
function createBasicRafDriver() {
|
|
8
|
+
let rafId = null;
|
|
9
|
+
const start = () => {
|
|
10
|
+
if (typeof window !== 'undefined') {
|
|
11
|
+
const onAnimationFrame = (t) => {
|
|
12
|
+
driver.tick(t);
|
|
13
|
+
rafId = window.requestAnimationFrame(onAnimationFrame);
|
|
14
|
+
};
|
|
15
|
+
rafId = window.requestAnimationFrame(onAnimationFrame);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
driver.tick(0);
|
|
19
|
+
setTimeout(() => driver.tick(1), 0);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const stop = () => {
|
|
23
|
+
if (typeof window !== 'undefined') {
|
|
24
|
+
if (rafId !== null) {
|
|
25
|
+
window.cancelAnimationFrame(rafId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// nothing to do in SSR
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const driver = createRafDriver({ name: 'DefaultCoreRafDriver', start, stop });
|
|
33
|
+
return driver;
|
|
34
|
+
}
|
|
35
|
+
let coreRafDriver;
|
|
36
|
+
/**
|
|
37
|
+
* Returns the rafDriver that is used by the core internally. Creates a new one if it's not set yet.
|
|
38
|
+
*/
|
|
39
|
+
export function getCoreRafDriver() {
|
|
40
|
+
if (!coreRafDriver) {
|
|
41
|
+
setCoreRafDriver(createBasicRafDriver());
|
|
42
|
+
}
|
|
43
|
+
return coreRafDriver;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @returns The ticker that is used by the core internally.
|
|
48
|
+
*/
|
|
49
|
+
export function getCoreTicker() {
|
|
50
|
+
return getCoreRafDriver().ticker;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Sets the rafDriver that is used by the core internally.
|
|
54
|
+
*/
|
|
55
|
+
export function setCoreRafDriver(driver) {
|
|
56
|
+
if (coreRafDriver) {
|
|
57
|
+
throw new Error(`\`setCoreRafDriver()\` is already called.`);
|
|
58
|
+
}
|
|
59
|
+
const driverPrivateApi = privateAPI(driver);
|
|
60
|
+
coreRafDriver = driverPrivateApi;
|
|
61
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
export * from './coreExports';
|
|
2
|
-
export { IProject, IProjectConfig } from './projects/TheatreProject';
|
|
3
|
-
export { ISequence } from './sequences/TheatreSequence';
|
|
4
|
-
export { ISheetObject } from './sheetObjects/TheatreSheetObject';
|
|
5
|
-
export { ISheet } from './sheets/TheatreSheet';
|
|
6
|
-
export { UnknownShorthandCompoundProps } from './propTypes/index';
|
|
7
|
-
import { OnDiskState } from './projects/store/storeTypes';
|
|
8
|
-
|
|
9
1
|
/**
|
|
10
2
|
* The library providing the runtime functionality of Theatre.js.
|
|
11
3
|
*
|
|
12
4
|
* @packageDocumentation
|
|
13
5
|
*/
|
|
14
|
-
|
|
6
|
+
export { notify, types, createRafDriver, getProject, onChange, val, } from './coreExports';
|
|
7
|
+
export type { IRafDriver } from './coreExports';
|
|
8
|
+
export type { IProject, IProjectConfig } from './projects/TheatreProject';
|
|
9
|
+
export type { ISequence } from './sequences/TheatreSequence';
|
|
10
|
+
export type { ISheetObject } from './sheetObjects/TheatreSheetObject';
|
|
11
|
+
export type { ISheet } from './sheets/TheatreSheet';
|
|
12
|
+
export type { UnknownShorthandCompoundProps } from './propTypes';
|
|
13
|
+
import type { OnDiskState } from './projects/store/storeTypes';
|
|
15
14
|
/**
|
|
16
15
|
* NOTE: **INTERNAL and UNSTABLE** - This _WILL_ break between minor versions.
|
|
17
16
|
*
|
|
@@ -21,6 +20,5 @@ import { OnDiskState } from './projects/store/storeTypes';
|
|
|
21
20
|
* already exists, or you should open an issue on GitHub: https://github.com/theatre-js/theatre/issues
|
|
22
21
|
*
|
|
23
22
|
*/
|
|
24
|
-
type __UNSTABLE_Project_OnDiskState = OnDiskState;
|
|
25
|
-
|
|
26
|
-
export { __UNSTABLE_Project_OnDiskState };
|
|
23
|
+
export type __UNSTABLE_Project_OnDiskState = OnDiskState;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../core/src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,eAAe,EACf,UAAU,EACV,QAAQ,EACR,GAAG,GACJ,MAAM,eAAe,CAAA;AACtB,YAAY,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AAC7C,YAAY,EAAC,QAAQ,EAAE,cAAc,EAAC,MAAM,2BAA2B,CAAA;AACvE,YAAY,EAAC,SAAS,EAAC,MAAM,6BAA6B,CAAA;AAC1D,YAAY,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAA;AACnE,YAAY,EAAC,MAAM,EAAC,MAAM,uBAAuB,CAAA;AACjD,YAAY,EAAC,6BAA6B,EAAC,MAAM,aAAa,CAAA;AAI9D,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAA;AAE5D;;;;;;;;GAQG;AACH,MAAM,MAAM,8BAA8B,GAAG,WAAW,CAAA"}
|