@cesdk/engine 1.32.0 → 1.33.0-rc.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/index.d.ts CHANGED
@@ -286,7 +286,7 @@ export declare type AssetMetaData = {
286
286
  */
287
287
  export declare interface AssetNumberProperty {
288
288
  property: string;
289
- type: 'Integer' | 'Float' | 'Double';
289
+ type: 'Int' | 'Float' | 'Double';
290
290
  value: number;
291
291
  defaultValue: number;
292
292
  min: number;
@@ -2916,47 +2916,12 @@ export declare interface Buffer {
2916
2916
  buffer: Uint8Array;
2917
2917
  }
2918
2918
 
2919
- declare type CameraSettings = {
2920
- /** Horizontal resolution in physical pixels */
2921
- width: number;
2922
- /** Vertical resolution in physical pixels */
2923
- height: number;
2924
- /** Physical pixels per CSS pixel */
2925
- pixelRatio: number;
2926
- };
2927
-
2928
2919
  /**
2929
2920
  * An HTML Canvas or an Offscreen Canvas
2930
2921
  * @public
2931
2922
  */
2932
2923
  export declare type Canvas = HTMLCanvasElement | OffscreenCanvas_2;
2933
2924
 
2934
- /**
2935
- * A Channel represents a reactive data source consisting of three elements:
2936
- *
2937
- * * A `subscribe` method to register a callback for values coming from the
2938
- * data source. Calling this method returns an `unsubscribe` method.
2939
- * * An (optional) `update` method to update the data source
2940
- * * An (optional) synchronous `value` method that can be used to retrieve
2941
- * the current value.
2942
- * @public
2943
- */
2944
- declare interface Channel<Out, In = Out> {
2945
- subscribe: Source_2<Out>;
2946
- update?: (v: In) => void;
2947
- value?: () => Out;
2948
- }
2949
-
2950
- /**
2951
- * A {@link Channel} that is guaranteed to have a `value` method
2952
- * @public
2953
- */
2954
- declare interface ChannelSync<Out, In = Out> extends Channel<Out, In> {
2955
- subscribe: Source_2<Out>;
2956
- update?: (v: In) => void;
2957
- value: () => Out;
2958
- }
2959
-
2960
2925
  /**
2961
2926
  * @public
2962
2927
  */
@@ -3325,7 +3290,7 @@ declare class CreativeEngine {
3325
3290
  event: EventAPI;
3326
3291
  scene: SceneAPI;
3327
3292
  variable: VariableAPI;
3328
-
3293
+ reactor: Reactor;
3329
3294
 
3330
3295
  /**
3331
3296
  * Adds and initializes a plugin to the engine.
@@ -3344,6 +3309,7 @@ declare class CreativeEngine {
3344
3309
  unstable_setVideoExportInactivityTimeout(timeout: number): void;
3345
3310
 
3346
3311
 
3312
+
3347
3313
  /**
3348
3314
  * Install the mousewheel event handler for the CreativeEngine on a different
3349
3315
  * element than the canvas.
@@ -3931,6 +3897,28 @@ export declare class EditorAPI {
3931
3897
  * @throws An error if the resource could not be downloaded or the mimetype could not be determined.
3932
3898
  */
3933
3899
  getMimeType(uri: string): Promise<string>;
3900
+ /**
3901
+ * Returns the URLs and sizes of all resources whose data would be lost if the scene was exported.
3902
+ * This function is useful for determining which resources need to be relocated (e.g., to a CDN) before
3903
+ * exporting a scene since the resources are not included in the exported scene.
3904
+ * @returns The URLs and sizes of transient resources.
3905
+ */
3906
+ findAllTransientResources(): TransientResource[];
3907
+ /**
3908
+ * Provides the data of a resource at the given URL.
3909
+ * @param url - The URL of the resource.
3910
+ * @param chunkSize - The size of the chunks in which the resource data is provided.
3911
+ * @param onData - The callback function that is called with the resource data or an error if an error occurred.
3912
+ * The callback will be called as long as there is data left to provide and the callback returns `true`.
3913
+ */
3914
+ getResourceData(uri: string, chunkSize: number, onData: (result: Uint8Array) => boolean): void;
3915
+ /**
3916
+ * Changes the URL associated with a resource.
3917
+ * This function can be used change the URL of a resource that has been relocated (e.g., to a CDN).
3918
+ * @param currentURL - The current URL of the resource.
3919
+ * @param relocatedURL - The new URL of the resource.
3920
+ */
3921
+ relocateResource(currentUrl: string, relocatedUrl: string): void;
3934
3922
  }
3935
3923
 
3936
3924
  /**
@@ -4154,12 +4142,6 @@ b: number,
4154
4142
  a: number
4155
4143
  ];
4156
4144
 
4157
- /**
4158
- * Will be called by a stream whenever a new value is available.
4159
- * @public
4160
- */
4161
- declare type Handler<T> = (v: T) => void;
4162
-
4163
4145
  /**
4164
4146
  * A hexadecimal color value (RGB or RGBA) that starts with a '#'
4165
4147
  * @example #6686FF or #6686FFFF
@@ -4346,41 +4328,94 @@ declare interface Range_2 {
4346
4328
  export { Range_2 as Range }
4347
4329
 
4348
4330
  /**
4349
- * A Read only {@link Channel}
4350
- * @public
4351
- */
4352
- declare interface ReadOnlyChannel<Out> extends Omit<Channel<Out>, 'update'> {
4353
- subscribe: Source_2<Out>;
4354
- value?: () => Out;
4355
- }
4356
-
4357
- /**
4358
- * A {@link ReadOnlyChannel} that is guaranteed to have a `value`
4359
- * @public
4360
- */
4361
- declare interface ReadOnlyChannelSync<Out> extends Omit<ChannelSync<Out>, 'update'>, ReadOnlyChannel<Out> {
4362
- subscribe: Source_2<Out>;
4363
- value: () => Out;
4364
- }
4365
-
4366
- /**
4367
- * A {@link Channel} that is guaranteed to have an `update` method.
4331
+ * Reactions track read calls and provide a way to react if they change.
4332
+ *
4333
+ * - Read calls are tracked by passing a function to `track`. That function
4334
+ * will be executed, and any read calls made during that execution will be
4335
+ * tracked and associated with this reaction.
4336
+ * - Reactions can be subscribed to by passing a callback to `subscribe`. That
4337
+ * callback will be executed whenever any of the read calls associated with
4338
+ * this reaction change.
4339
+ *
4368
4340
  * @public
4369
4341
  */
4370
- declare interface ReadWriteChannel<Out, In = Out> extends Channel<Out, In> {
4371
- subscribe: Source_2<Out>;
4372
- update: (v: In) => void;
4373
- value?: () => Out;
4342
+ export declare interface Reaction {
4343
+ /**
4344
+ * Execute the callback and track all engine read calls that happen during
4345
+ * the execution. These read calls are associated with this reaction.
4346
+ */
4347
+ track<T>(cb: () => T): T;
4348
+ /**
4349
+ * When the Reactor detects that the engine read calls associated with this
4350
+ * reaction might have changed, it will invoke the subscription handler.
4351
+ * @returns A function that can be called to unsubscribe the handler.
4352
+ */
4353
+ subscribe(cb: () => void): () => void;
4354
+ /**
4355
+ * Unsubscribe all handlers, nullify the reference to the Reactor
4356
+ * and dispose the reaction.
4357
+ */
4358
+ dispose(): void;
4374
4359
  }
4375
4360
 
4376
4361
  /**
4377
- * A {@link ReadWriteChannel} that is guaranteed to have a `value` and an `update` method
4362
+ * The reactor coordinates the update of registered _Reactions_.
4363
+ *
4364
+ * - Reactions are created with `createReaction()`
4365
+ * - `reactor.decorateObject(object)` will register all functions on an object marked with
4366
+ * `@getter` as read calls. If these are called during reaction tracking, their
4367
+ * arguments and return values will be stored so that changes can be detected later.
4368
+ * - `reactor.decorateFunction` does the same, but for individual functions
4369
+ * - `reaction.track(effect)` will run the effect and associate any engine read
4370
+ * calls during the execution with the Reaction.
4371
+ * - `reaction.subscribe(handler)` will invoke the handler whenever the engine read calls
4372
+ * in the reaction might have changed after an update.
4373
+ *
4378
4374
  * @public
4379
4375
  */
4380
- declare interface ReadWriteChannelSync<Out, In = Out> extends ChannelSync<Out, In>, ReadWriteChannel<Out, In> {
4381
- subscribe: Source_2<Out>;
4382
- update: (v: In) => void;
4383
- value: () => Out;
4376
+ export declare interface Reactor {
4377
+ /**
4378
+ * Decorate a single function to be tracked by the reactor.
4379
+ * @param func - The function to decorate.
4380
+ * @param fnName - Name of the function to decorate. Used to generate the
4381
+ * callId, so make sure it's unique with regard to its context.
4382
+ * @returns The decorated function. Calling this function will track the call
4383
+ * in the Reactor and provide caching in reactions.
4384
+ */
4385
+ decorateFunction<A extends any[], R>(func: (...args: A) => R, fnName?: string): (...args: A) => R;
4386
+ /**
4387
+ * Decorate all marked `@getter` and `@setter` functions to be tracked by the reactor
4388
+ *
4389
+ * All functions on the object that are marked with `@getter` will be tracked
4390
+ * during reaction tracking.
4391
+ *
4392
+ * @returns A function that can be called to stop tracking the object.
4393
+ */
4394
+ decorateObject<T extends object>(object: T): () => void;
4395
+ /**
4396
+ * Create and return a new Reaction that is associated with this Reactor.
4397
+ */
4398
+ createReaction(debugName?: string): Reaction;
4399
+ /**
4400
+ * Dispose the reactor and all reactions.
4401
+ * After this call, the reactor is no longer usable.
4402
+ */
4403
+ dispose(): void;
4404
+ /**
4405
+ * A promise that will resolve after the next update of the Reactor.
4406
+ *
4407
+ * This can be used to wait for the next update of the Reactor in an async function.
4408
+ *
4409
+ * ```ts
4410
+ * await reactor.nextReaction;
4411
+ * ```
4412
+ *
4413
+ * This is useful in situations where you want to make sure that the effects of
4414
+ * a reactor update have propagated to any dependent code before continuing.
4415
+ * Particularly, this can be used to ensure that the UI has updated before
4416
+ * continuing with other operations.
4417
+ */
4418
+ nextReaction: Promise<void>;
4384
4419
  }
4385
4420
 
4386
4421
  /**
@@ -4546,20 +4581,21 @@ export declare class SceneAPI {
4546
4581
  */
4547
4582
  getPages(): DesignBlockId[];
4548
4583
  /**
4549
- * Get the current page, i.e., the page nearest to the view port center.
4584
+ * Get the current page, i.e., the page of the first selected element if this page
4585
+ * is at least 25% visible or, otherwise, the page nearest to the viewport center.
4550
4586
  * @returns The current page in the scene or null.
4551
4587
  */
4552
4588
  getCurrentPage(): DesignBlockId | null;
4553
4589
  /**
4554
- * Find all blocks with the given type sorted by the distance to view port center.
4590
+ * Find all blocks with the given type sorted by the distance to viewport center.
4555
4591
  * @param type - The type to search for.
4556
- * @returns A list of block ids sorted by distance to view port center.
4592
+ * @returns A list of block ids sorted by distance to viewport center.
4557
4593
  */
4558
4594
  findNearestToViewPortCenterByType(type: DesignBlockType): DesignBlockId[];
4559
4595
  /**
4560
- * Find all blocks with the given kind sorted by the distance to view port center.
4596
+ * Find all blocks with the given kind sorted by the distance to viewport center.
4561
4597
  * @param kind - The kind to search for.
4562
- * @returns A list of block ids sorted by distance to view port center.
4598
+ * @returns A list of block ids sorted by distance to viewport center.
4563
4599
  */
4564
4600
  findNearestToViewPortCenterByKind(kind: string): DesignBlockId[];
4565
4601
  /**
@@ -4717,7 +4753,7 @@ export declare type SceneMode = 'Design' | 'Video';
4717
4753
  export declare type Scope = 'text/edit' | 'text/character' | 'fill/change' | 'fill/changeType' | 'stroke/change' | 'shape/change' | 'layer/move' | 'layer/resize' | 'layer/rotate' | 'layer/flip' | 'layer/crop' | 'layer/opacity' | 'layer/blendMode' | 'layer/visibility' | 'layer/clipping' | 'appearance/adjustments' | 'appearance/filter' | 'appearance/effect' | 'appearance/blur' | 'appearance/shadow' | 'appearance/animation' | 'lifecycle/destroy' | 'lifecycle/duplicate' | 'editor/add' | 'editor/select';
4718
4754
 
4719
4755
  /** @public */
4720
- export declare type SettingsBool = 'controlGizmo/showCropHandles' | 'controlGizmo/showCropScaleHandles' | 'controlGizmo/showResizeHandles' | 'controlGizmo/showRotateHandles' | 'controlGizmo/showScaleHandles' | 'doubleClickToCropEnabled' | 'features/singlePageModeEnabled' | 'features/pageCarouselEnabled' | 'mouse/enableScroll' | 'mouse/enableZoom' | 'checkScopesInAPIs' | 'page/dimOutOfPageAreas' | 'page/title/appendPageName' | 'page/title/show' | 'page/title/showOnSinglePage' | 'page/title/showPageTitleTemplate' | 'placeholderControls/showButton' | 'placeholderControls/showOverlay' | 'blockAnimations/enabled' | 'showBuildVersion' | 'touch/dragStartCanSelect' | 'touch/singlePointPanning';
4756
+ export declare type SettingsBool = 'controlGizmo/showCropHandles' | 'controlGizmo/showCropScaleHandles' | 'controlGizmo/showMoveHandles' | 'controlGizmo/showResizeHandles' | 'controlGizmo/showRotateHandles' | 'controlGizmo/showScaleHandles' | 'doubleClickToCropEnabled' | 'features/singlePageModeEnabled' | 'features/pageCarouselEnabled' | 'mouse/enableScroll' | 'mouse/enableZoom' | 'checkScopesInAPIs' | 'page/dimOutOfPageAreas' | 'page/title/appendPageName' | 'page/title/show' | 'page/title/showOnSinglePage' | 'page/title/showPageTitleTemplate' | 'placeholderControls/showButton' | 'placeholderControls/showOverlay' | 'blockAnimations/enabled' | 'showBuildVersion' | 'touch/dragStartCanSelect' | 'touch/singlePointPanning';
4721
4757
 
4722
4758
  /** @public
4723
4759
  */
@@ -4798,17 +4834,6 @@ export declare interface Source {
4798
4834
  height: number;
4799
4835
  }
4800
4836
 
4801
- /**
4802
- * A stream source.
4803
- *
4804
- * This is an ordinary function. Pass a handler to have that handler called by
4805
- * the source whenever a new value is available.
4806
- *
4807
- * Returns a function that unsubscribes the handler from the source
4808
- * @public
4809
- */
4810
- declare type Source_2<T> = (handler: Handler<T>) => UnsubscribeFn;
4811
-
4812
4837
  /** @public */
4813
4838
  export declare interface SpotColor {
4814
4839
  name: string;
@@ -4860,6 +4885,12 @@ export declare function supportsWasm(): boolean;
4860
4885
  */
4861
4886
  export declare type TextCase = 'Normal' | 'Uppercase' | 'Lowercase' | 'Titlecase';
4862
4887
 
4888
+ /** @public */
4889
+ export declare interface TransientResource {
4890
+ uri: string;
4891
+ size: number;
4892
+ }
4893
+
4863
4894
  /** @public */
4864
4895
  export declare interface Typeface {
4865
4896
  /** The unique name of this typeface */
@@ -4885,12 +4916,6 @@ export declare type TypefaceDefinition = {
4885
4916
 
4886
4917
  declare type _TypefaceDefinition = TypefaceDefinition;
4887
4918
 
4888
- /**
4889
- * Invoke to unsubscribe from a stream.
4890
- * @public
4891
- */
4892
- declare type UnsubscribeFn = () => void;
4893
-
4894
4919
  /**
4895
4920
  * @public
4896
4921
  */