@unseenco/theatre-core 0.2.3 → 0.3.0
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/README.md +2 -18
- package/dist/index.d.ts +54 -1
- package/dist/index.js +191 -326
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +188 -323
- package/dist/index.mjs.map +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -7,30 +7,14 @@ Theatre.js can be used both programmatically _and_ visually.
|
|
|
7
7
|
You can use Theatre.js to:
|
|
8
8
|
|
|
9
9
|
* Animate 3D objects made with THREE.js or other 3D libraries
|
|
10
|
-
|
|
11
|
-

|
|
12
|
-
|
|
13
|
-
<sub>Art by [drei.lu](https://sketchfab.com/models/91964c1ce1a34c3985b6257441efa500)</sub>
|
|
14
|
-
|
|
15
10
|
* Animate HTML/SVG via React or other libraries
|
|
16
|
-
|
|
17
|
-

|
|
18
|
-
|
|
19
11
|
* Design micro-interactions
|
|
20
|
-
|
|
21
|
-

|
|
22
|
-
|
|
23
12
|
* Choreograph generative interactive art
|
|
24
|
-
|
|
25
|
-

|
|
26
|
-
|
|
27
13
|
* Or animate any other JS variable
|
|
28
14
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
## Documentation and Tutorials
|
|
15
|
+
## Documentation
|
|
32
16
|
|
|
33
|
-
|
|
17
|
+
Guides and API reference live in the monorepo `docs/` workspace. Run `yarn docs:dev` from the repo root, or see the deployed site from [craftedbygc/theatre](https://github.com/craftedbygc/theatre).
|
|
34
18
|
|
|
35
19
|
## Community
|
|
36
20
|
|
package/dist/index.d.ts
CHANGED
|
@@ -312,6 +312,14 @@ type ShorthandCompoundPropsToLonghandCompoundProps<P extends UnknownShorthandCom
|
|
|
312
312
|
*
|
|
313
313
|
*/
|
|
314
314
|
declare function compoundFromSanitizedProps<Props extends UnknownValidCompoundProps>(sanitizedProps: Props, opts?: CommonOpts): PropTypeConfig_Compound<Props>;
|
|
315
|
+
/**
|
|
316
|
+
* Shorthand compound prop type: plain object literals are sanitized into longhand prop configs.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts
|
|
320
|
+
* sheet.object('obj', types.compound({x: 0, y: 0}))
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
315
323
|
declare const compound: <Props extends UnknownShorthandCompoundProps>(props: Props, opts?: CommonOpts) => PropTypeConfig_Compound<ShorthandCompoundPropsToLonghandCompoundProps<Props>>;
|
|
316
324
|
/**
|
|
317
325
|
* A file prop type
|
|
@@ -412,6 +420,12 @@ declare const number: (defaultValue: number, opts?: {
|
|
|
412
420
|
precision?: number;
|
|
413
421
|
label?: string;
|
|
414
422
|
}) => PropTypeConfig_Number;
|
|
423
|
+
/**
|
|
424
|
+
* RGBA color prop type factory.
|
|
425
|
+
*
|
|
426
|
+
* @param defaultValue - Initial color; defaults to opaque black
|
|
427
|
+
* @param opts - Optional `{ label }` for the Studio
|
|
428
|
+
*/
|
|
415
429
|
declare const rgba: (defaultValue?: Rgba, opts?: CommonOpts) => PropTypeConfig_Rgba;
|
|
416
430
|
/**
|
|
417
431
|
* A boolean prop type
|
|
@@ -521,6 +535,7 @@ opts?: {
|
|
|
521
535
|
* ```
|
|
522
536
|
*/
|
|
523
537
|
type Interpolator<T> = (left: T, right: T, progression: number) => T;
|
|
538
|
+
/** Base shape shared by all Theatre prop type configurations. */
|
|
524
539
|
interface IBasePropType<LiteralIdentifier extends string, ValueType, DeserializeType = ValueType> {
|
|
525
540
|
/**
|
|
526
541
|
* Each prop config has a string literal identifying it. For example,
|
|
@@ -531,6 +546,7 @@ interface IBasePropType<LiteralIdentifier extends string, ValueType, Deserialize
|
|
|
531
546
|
* the `valueType` is only used by typescript. It won't be present in runtime.
|
|
532
547
|
*/
|
|
533
548
|
valueType: ValueType;
|
|
549
|
+
/** Internal marker distinguishing Theatre prop configs from plain values. */
|
|
534
550
|
[propTypeSymbol]: 'TheatrePropType';
|
|
535
551
|
/**
|
|
536
552
|
* Each prop type may be given a custom label instead of the name of the sub-prop
|
|
@@ -545,6 +561,7 @@ interface IBasePropType<LiteralIdentifier extends string, ValueType, Deserialize
|
|
|
545
561
|
* ```
|
|
546
562
|
*/
|
|
547
563
|
label: string | undefined;
|
|
564
|
+
/** Default value used when the prop has no override or keyframes. */
|
|
548
565
|
default: ValueType;
|
|
549
566
|
/**
|
|
550
567
|
* Each prop config has a `deserializeAndSanitize()` function that deserializes and sanitizes
|
|
@@ -574,8 +591,11 @@ interface IBasePropType<LiteralIdentifier extends string, ValueType, Deserialize
|
|
|
574
591
|
interface ISimplePropType<LiteralIdentifier extends string, ValueType> extends IBasePropType<LiteralIdentifier, ValueType, ValueType> {
|
|
575
592
|
interpolate: Interpolator<ValueType>;
|
|
576
593
|
}
|
|
594
|
+
/** Number prop type configuration. */
|
|
577
595
|
interface PropTypeConfig_Number extends ISimplePropType<'number', number> {
|
|
596
|
+
/** Optional min/max shown in the Studio number editor (not a runtime clamp). */
|
|
578
597
|
range?: [min: number, max: number];
|
|
598
|
+
/** Custom nudging behavior when dragging the number in the Studio. */
|
|
579
599
|
nudgeFn: NumberNudgeFn;
|
|
580
600
|
/**
|
|
581
601
|
* See {@link defaultNumberNudgeFn} to see how `nudgeMultiplier` is treated.
|
|
@@ -587,12 +607,14 @@ interface PropTypeConfig_Number extends ISimplePropType<'number', number> {
|
|
|
587
607
|
*/
|
|
588
608
|
precision?: number;
|
|
589
609
|
}
|
|
610
|
+
/** Function that computes a new number when the user nudges a number prop in the Studio. */
|
|
590
611
|
type NumberNudgeFn = (p: {
|
|
591
612
|
deltaX: number;
|
|
592
613
|
deltaFraction: number;
|
|
593
614
|
magnitude: number;
|
|
594
615
|
config: PropTypeConfig_Number;
|
|
595
616
|
}) => number;
|
|
617
|
+
/** Boolean prop type configuration. */
|
|
596
618
|
interface PropTypeConfig_Boolean extends ISimplePropType<'boolean', boolean> {
|
|
597
619
|
}
|
|
598
620
|
type CommonOpts = {
|
|
@@ -610,14 +632,20 @@ type CommonOpts = {
|
|
|
610
632
|
*/
|
|
611
633
|
label?: string;
|
|
612
634
|
};
|
|
635
|
+
/** String prop type configuration. */
|
|
613
636
|
interface PropTypeConfig_String extends ISimplePropType<'string', string> {
|
|
614
637
|
}
|
|
638
|
+
/** String-literal prop type configuration (menu or switch UI in the Studio). */
|
|
615
639
|
interface PropTypeConfig_StringLiteral<T extends string> extends ISimplePropType<'stringLiteral', T> {
|
|
640
|
+
/** Map of allowed values to human-readable labels in the Studio. */
|
|
616
641
|
valuesAndLabels: Record<T, string>;
|
|
642
|
+
/** Whether the Studio renders a dropdown menu or a switch control. */
|
|
617
643
|
as: 'menu' | 'switch';
|
|
618
644
|
}
|
|
645
|
+
/** RGBA color prop type configuration. */
|
|
619
646
|
interface PropTypeConfig_Rgba extends ISimplePropType<'rgba', Rgba> {
|
|
620
647
|
}
|
|
648
|
+
/** Image (texture) prop type configuration. */
|
|
621
649
|
interface PropTypeConfig_Image extends ISimplePropType<'image', Asset> {
|
|
622
650
|
/**
|
|
623
651
|
* When `false`, Studio edits are session-only and not written to persisted
|
|
@@ -625,22 +653,30 @@ interface PropTypeConfig_Image extends ISimplePropType<'image', Asset> {
|
|
|
625
653
|
*/
|
|
626
654
|
persist: boolean;
|
|
627
655
|
}
|
|
656
|
+
/** File asset prop type configuration. */
|
|
628
657
|
interface PropTypeConfig_File extends ISimplePropType<'file', File> {
|
|
629
658
|
}
|
|
630
659
|
type DeepPartialCompound<Props extends UnknownValidCompoundProps> = {
|
|
631
660
|
[K in keyof Props]?: DeepPartial<Props[K]>;
|
|
632
661
|
};
|
|
633
662
|
type DeepPartial<Conf extends PropTypeConfig> = Conf extends PropTypeConfig_AllSimples ? Conf['valueType'] : Conf extends PropTypeConfig_Compound<infer T> ? DeepPartialCompound<T> : never;
|
|
663
|
+
/** Compound (nested object) prop type configuration. */
|
|
634
664
|
interface PropTypeConfig_Compound<Props extends UnknownValidCompoundProps> extends IBasePropType<'compound', {
|
|
635
665
|
[K in keyof Props]: Props[K]['valueType'];
|
|
636
666
|
}, DeepPartialCompound<Props>> {
|
|
667
|
+
/** Child prop configurations keyed by sub-prop name. */
|
|
637
668
|
props: Record<keyof Props, PropTypeConfig>;
|
|
638
669
|
}
|
|
670
|
+
/** Enum (discriminated) prop type configuration with named cases. */
|
|
639
671
|
interface PropTypeConfig_Enum extends IBasePropType<'enum', {}> {
|
|
672
|
+
/** Prop configs for each enum case name. */
|
|
640
673
|
cases: Record<string, PropTypeConfig>;
|
|
674
|
+
/** Case name used when no value is set. */
|
|
641
675
|
defaultCase: string;
|
|
642
676
|
}
|
|
677
|
+
/** Union of all simple (non-compound, non-enum) prop type configurations. */
|
|
643
678
|
type PropTypeConfig_AllSimples = PropTypeConfig_Number | PropTypeConfig_Boolean | PropTypeConfig_String | PropTypeConfig_StringLiteral<$IntentionalAny> | PropTypeConfig_Rgba | PropTypeConfig_Image | PropTypeConfig_File;
|
|
679
|
+
/** Any Theatre prop type configuration (simple, compound, or enum). */
|
|
644
680
|
type PropTypeConfig = PropTypeConfig_AllSimples | PropTypeConfig_Compound<$IntentionalAny> | PropTypeConfig_Enum;
|
|
645
681
|
|
|
646
682
|
type index_d_UnknownShorthandCompoundProps = UnknownShorthandCompoundProps;
|
|
@@ -700,6 +736,7 @@ type TransientPropPath = string | readonly (string | number)[];
|
|
|
700
736
|
/** Same path format as {@link TransientPropPath}. */
|
|
701
737
|
type StaticPropPath = TransientPropPath;
|
|
702
738
|
|
|
739
|
+
/** Public API for a custom requestAnimationFrame driver that advances Theatre's core ticker. */
|
|
703
740
|
interface IRafDriver {
|
|
704
741
|
/**
|
|
705
742
|
* All raf derivers have have `driver.type === 'Theatre_RafDriver_PublicAPI'`
|
|
@@ -822,6 +859,7 @@ type SheetObjectValuesChangeMeta = {
|
|
|
822
859
|
*/
|
|
823
860
|
variant: SequenceVariantId;
|
|
824
861
|
};
|
|
862
|
+
/** Public API for a Theatre.js sheet object (animated props and Studio integration). */
|
|
825
863
|
interface ISheetObject<Props extends UnknownShorthandCompoundProps = UnknownShorthandCompoundProps> {
|
|
826
864
|
/**
|
|
827
865
|
* All Objects will have `object.type === 'Theatre_SheetObject_PublicAPI'`
|
|
@@ -988,7 +1026,9 @@ interface IAttachAudioArgs {
|
|
|
988
1026
|
*/
|
|
989
1027
|
destinationNode?: AudioNode;
|
|
990
1028
|
}
|
|
1029
|
+
/** Public API for a sheet's animation sequence (playback, playhead, and audio). */
|
|
991
1030
|
interface ISequence {
|
|
1031
|
+
/** Discriminator for Theatre.js public sequence instances. */
|
|
992
1032
|
readonly type: 'Theatre_Sequence_PublicAPI';
|
|
993
1033
|
/**
|
|
994
1034
|
* Starts playback of a sequence.
|
|
@@ -1195,6 +1235,7 @@ interface ISequence {
|
|
|
1195
1235
|
|
|
1196
1236
|
type SheetObjectAction = (object: ISheetObject) => void;
|
|
1197
1237
|
type SheetObjectActionsConfig = Record<string, SheetObjectAction>;
|
|
1238
|
+
/** Options for {@link ISheet.object} beyond prop definitions (visibility, showPropsOf, etc.). */
|
|
1198
1239
|
type ISheetObjectOptions = {
|
|
1199
1240
|
reconfigure?: boolean;
|
|
1200
1241
|
/**
|
|
@@ -1232,6 +1273,7 @@ type ISheetObjectOptions = {
|
|
|
1232
1273
|
__actions__THIS_API_IS_UNSTABLE_AND_WILL_CHANGE_IN_THE_NEXT_VERSION?: SheetObjectActionsConfig;
|
|
1233
1274
|
};
|
|
1234
1275
|
type ISheetPropsOptions = Omit<ISheetObjectOptions, 'visible' | 'showPropsOf'>;
|
|
1276
|
+
/** Public API for a Theatre.js sheet (objects, sequence, and runtime lifecycle). */
|
|
1235
1277
|
interface ISheet {
|
|
1236
1278
|
/**
|
|
1237
1279
|
* All sheets have `sheet.type === 'Theatre_Sheet_PublicAPI'`
|
|
@@ -1430,6 +1472,7 @@ type ISheetOptions = {
|
|
|
1430
1472
|
*/
|
|
1431
1473
|
visible?: boolean;
|
|
1432
1474
|
};
|
|
1475
|
+
/** Options passed to {@link getProject} when creating or attaching to a project. */
|
|
1433
1476
|
type IProjectConfig = {
|
|
1434
1477
|
/**
|
|
1435
1478
|
* The state of the project, as [exported](https://www.theatrejs.com/docs/latest/manual/projects#state) by the studio.
|
|
@@ -1450,6 +1493,7 @@ type IProjectConfig = {
|
|
|
1450
1493
|
* A Theatre.js project
|
|
1451
1494
|
*/
|
|
1452
1495
|
interface IProject {
|
|
1496
|
+
/** Discriminator for Theatre.js public project instances. */
|
|
1453
1497
|
readonly type: 'Theatre_Project_PublicAPI';
|
|
1454
1498
|
/**
|
|
1455
1499
|
* If `@unseenco/theatre-studio` is used, this promise would resolve when studio has loaded
|
|
@@ -1478,6 +1522,14 @@ interface IProject {
|
|
|
1478
1522
|
* **Docs: https://www.theatrejs.com/docs/latest/manual/sheets**
|
|
1479
1523
|
*/
|
|
1480
1524
|
sheet(sheetId: string, instanceIdOrOpts?: string | ISheetOptions): ISheet;
|
|
1525
|
+
/**
|
|
1526
|
+
* Creates a Sheet under the project (overload with explicit `instanceId`).
|
|
1527
|
+
*
|
|
1528
|
+
* @param sheetId - Sheets are identified by their `sheetId`, which must be a string longer than 3 characters
|
|
1529
|
+
* @param instanceId - Instance id when creating multiple instances of the same sheet
|
|
1530
|
+
* @param opts - Optionally provide `{ visible: false }` to hide the sheet from the Studio outline panel
|
|
1531
|
+
* @returns The newly created Sheet
|
|
1532
|
+
*/
|
|
1481
1533
|
sheet(sheetId: string, instanceId: string, opts?: ISheetOptions): ISheet;
|
|
1482
1534
|
/**
|
|
1483
1535
|
* Returns all currently loaded sheet instances under this project.
|
|
@@ -1553,6 +1605,7 @@ type Notifiers = {
|
|
|
1553
1605
|
*/
|
|
1554
1606
|
error: Notify;
|
|
1555
1607
|
};
|
|
1608
|
+
/** User-facing notification helpers (success, warning, info, error) used by Theatre.js runtimes. */
|
|
1556
1609
|
declare const notify: Notifiers;
|
|
1557
1610
|
|
|
1558
1611
|
/**
|
|
@@ -1676,7 +1729,7 @@ declare function val<T>(pointer: PointerType<T>): T;
|
|
|
1676
1729
|
* This type represents the object returned by `studio.createContnentOfSaveFile()`. It's
|
|
1677
1730
|
* meant for advanced users who want to interact with the state of projects. In the vast
|
|
1678
1731
|
* majority of cases, you __should not__ use this type. Either an API for your use-case
|
|
1679
|
-
* already exists, or you should open an issue on GitHub: https://github.com/
|
|
1732
|
+
* already exists, or you should open an issue on GitHub: https://github.com/craftedbygc/theatre/issues
|
|
1680
1733
|
*
|
|
1681
1734
|
*/
|
|
1682
1735
|
type __UNSTABLE_Project_OnDiskState = OnDiskState;
|