@cesdk/engine 1.9.0-preview.3 → 1.9.1

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
@@ -21,6 +21,7 @@ export declare interface Asset {
21
21
  uri?: string;
22
22
  filename?: string;
23
23
  vectorPath?: string;
24
+ duration?: string;
24
25
  } & Record<string, unknown>;
25
26
  }
26
27
 
@@ -79,6 +80,8 @@ export declare class AssetAPI {
79
80
  canManageAssets(sourceId: string): boolean;
80
81
 
81
82
 
83
+
84
+
82
85
  /**
83
86
  * Apply an asset result to the active scene.
84
87
  * The default behavior will instantiate a block and configure it according to the asset's properties.
@@ -87,12 +90,25 @@ export declare class AssetAPI {
87
90
  * @param assetResult - A single assetResult of a `findAssets` query.
88
91
  */
89
92
  apply(sourceId: string, assetResult: AssetResult): Promise<void>;
93
+ /**
94
+ * Apply an asset result to the given block.
95
+ * @param sourceId - The ID of the asset source.
96
+ * @param assetResult - A single assetResult of a `findAssets` query.
97
+ * @param block - The block the asset should be applied to.
98
+ */
99
+ applyToBlock(sourceId: string, assetResult: AssetResult, block: DesignBlockId): Promise<void>;
90
100
  /**
91
101
  * The default implementation for applying an asset to the scene.
92
102
  * This implementation is used when no `applyAsset` function is provided to `addSource`.
93
103
  * @param assetResult - A single assetResult of a `findAssets` query.
94
104
  */
95
105
  defaultApplyAsset(assetResult: AssetResult): Promise<void>;
106
+ /**
107
+ * The default implementation for applying an asset to an existing block.
108
+ * @param assetResult - A single assetResult of a `findAssets` query.
109
+ * @param block - The block to apply the asset result to.
110
+ */
111
+ defaultApplyAssetToBlock(assetResult: AssetResult, block: DesignBlockId): Promise<void>;
96
112
 
97
113
  }
98
114
 
@@ -192,6 +208,7 @@ declare interface AssetResult_2 {
192
208
  meta?: {
193
209
  uri?: string;
194
210
  filename?: string;
211
+ duration?: string;
195
212
  } & Record<string, unknown>;
196
213
  /** The locale of the label and tags */
197
214
  locale?: string;
@@ -264,6 +281,11 @@ export declare interface AssetSource {
264
281
  * You can override this with custom behavior.
265
282
  */
266
283
  applyAsset?: (asset: AssetResult) => Promise<void>;
284
+ /**
285
+ * Apply the given asset result to the given block.
286
+ * You can override this with custom behavior.
287
+ */
288
+ applyAssetToBlock?: (asset: AssetResult, block: DesignBlockId) => Promise<void>;
267
289
  /**
268
290
  * Adds the given asset to this source. Throws an error if `canManageAssets`
269
291
  * is `false`.
@@ -284,6 +306,12 @@ export declare interface AssetSource {
284
306
  * @returns true if asset was found and removed, and false otherwise
285
307
  */
286
308
  removeAsset?(assetId: string): Promise<boolean>;
309
+ /**
310
+ * Generates a list of supported mime types for this source.
311
+ *
312
+ * @returns a list of the mime types should be supported by this source
313
+ */
314
+ getSupportedMimeTypes?(): string[] | undefined;
287
315
  }
288
316
 
289
317
  /**
@@ -298,6 +326,12 @@ declare interface AssetSource_2 {
298
326
  * You can override this with custom behavior.
299
327
  */
300
328
  applyAsset?: (asset: AssetResult_2) => Promise<void>;
329
+ /**
330
+ * Apply the given asset result to the given block.
331
+ * You can override this with custom behavior.
332
+ */
333
+ applyAssetToBlock?: (asset: AssetResult_2, block: number) => Promise<void>;
334
+
301
335
  /** Return every available group */
302
336
  getGroups?: () => Promise<string[]>;
303
337
  /**
@@ -318,6 +352,13 @@ declare interface AssetSource_2 {
318
352
  name: string;
319
353
  url?: string;
320
354
  };
355
+
356
+ /**
357
+ * Generates a list of supported mime types for this source.
358
+ *
359
+ * @returns a list of the mime types should be supported by this source
360
+ */
361
+ getSupportedMimeTypes?(): string[] | undefined;
321
362
  }
322
363
 
323
364
  /** @public */
@@ -368,18 +409,28 @@ export declare type BlendMode = 'PassThrough' | 'Normal' | 'Darken' | 'Multiply'
368
409
  export declare class Block extends Entity {
369
410
  #private;
370
411
  effects: ReadWriteChannelSync<number[]>;
412
+ blur: ReadWriteChannelSync<number>;
413
+ isBlurEnabled: ReadWriteChannelSync<boolean>;
371
414
  soloPlaybackEnabled: ReadWriteChannelSync<boolean>;
372
415
  trimOffset: ReadWriteChannelSync<number>;
373
416
  trimLength: ReadWriteChannelSync<number>;
374
417
  playing: ReadWriteChannelSync<boolean>;
375
418
  playbackTime: ReadWriteChannelSync<number>;
376
419
  selection: ReadWriteChannelSync<boolean>;
377
- videoMode: ReadWriteChannelSync<boolean>;
420
+ sceneMode: ReadWriteChannelSync<SceneMode>;
378
421
  duration: ReadWriteChannelSync<number>;
422
+ totalSceneDuration: ReadWriteChannelSync<number>;
379
423
  name: ReadWriteChannelSync<string>;
380
- muted: ReadWriteChannelSync<boolean>;
424
+ audioMuted: ReadWriteChannelSync<boolean>;
425
+ videoMuted: ReadWriteChannelSync<boolean>;
381
426
  avResourceTotalDuration: ReadWriteChannelSync<number>;
382
427
  timeOffset: ReadWriteChannelSync<number>;
428
+ cropTranslationX: ReadWriteChannelSync<number>;
429
+ cropTranslationY: ReadWriteChannelSync<number>;
430
+ cropTranslation: ReadWriteChannelSync<Vec2>;
431
+ width: ReadWriteChannelSync<number>;
432
+ height: ReadWriteChannelSync<number>;
433
+ dimensions: ReadWriteChannelSync<Vec2>;
383
434
 
384
435
 
385
436
  }
@@ -411,7 +462,20 @@ export declare class BlockAPI {
411
462
  * @returns A promise that resolves with an array of the exported image and mask or is rejected with an error.
412
463
  */
413
464
  exportWithColorMask(handle: DesignBlockId, mimeType: MimeType_2 | undefined, maskColorR: number, maskColorG: number, maskColorB: number, options?: ExportOptions): Promise<Blob[]>;
414
-
465
+ /**
466
+ * Exports a design block as a video file of the given mime type.
467
+ * Note: The export will run across multiple iterations of the update loop. In each iteration a frame is scheduled for encoding.
468
+ * @param block - The design block to export.
469
+ * @param timeOffset - The time offset in seconds of the scene's timeline from which the video will start.
470
+ * @param duration - The duration in seconds of the final video.
471
+ * @param mimeType - The mime type of the output video file.
472
+ * @param resolutionWidth - The target video width in pixel.
473
+ * @param resolutionHeight - The target video height in pixel.
474
+ * @param framerate - The target framerate in Hz.
475
+ * @param progressCallback - A callback which reports on the progress of the export. It informs the receiver of the current frame index, which currently gets exported and the total frame count.
476
+ * @returns A promise that resolves with video blob or is rejected with an error.
477
+ */
478
+ exportVideo(handle: DesignBlockId, timeOffset: number, duration: number, mimeType: MimeType_2 | undefined, resolutionWidth: number, resolutionHeight: number, framerate: number, progressCallback: (numberOfRenderedFrames: number, numberOfEncodedFrames: number, totalNumberOfFrames: number) => void): Promise<Blob>;
415
479
  /**
416
480
  * Loads existing blocks from the given string.
417
481
  * The blocks are not attached by default and won't be visible until attached to a page or the scene.
@@ -463,6 +527,12 @@ export declare class BlockAPI {
463
527
  * @returns An array of block ids.
464
528
  */
465
529
  findAllSelected(): DesignBlockId[];
530
+ /**
531
+ * Subscribe to changes in the current set of selected blocks.
532
+ * @param callback - This function is called at the end of the engine update if the selection has changed.
533
+ * @returns A method to unsubscribe.
534
+ */
535
+ onSelectionChanged(callback: () => void): () => void;
466
536
  /**
467
537
  * Confirms that a given set of blocks can be grouped together.
468
538
  * @param ids - A non-empty array of block ids.
@@ -926,6 +996,29 @@ export declare class BlockAPI {
926
996
  * @returns A tuple of channels red, green, blue and alpha in the range of 0 to 1.
927
997
  */
928
998
  getColorRGBA(id: DesignBlockId, property: string): RGBA;
999
+ /**
1000
+ * Set a color property of the given design block to the given value.
1001
+ * @param id - The block whose property should be set.
1002
+ * @param property - The name of the property to set.
1003
+ * @param name - The name of the spot color.
1004
+ * @param tint - The tint factor in the range of 0 to 1.
1005
+ * @returns An empty result on success, an error otherwise.
1006
+ */
1007
+ setColorSpot(id: DesignBlockId, property: string, name: string, tint?: number): void;
1008
+ /**
1009
+ * Get the spot color name of a color property of the given design block.
1010
+ * @param id - The block whose property should be queried.
1011
+ * @param property - The name of the property to query.
1012
+ * @returns A result holding the name of the spot color or an error.
1013
+ */
1014
+ getColorSpotName(id: DesignBlockId, property: string): string;
1015
+ /**
1016
+ * Get the spot color tint factor of a color property of the given design block.
1017
+ * @param id - The block whose property should be queried.
1018
+ * @param property - The name of the property to query.
1019
+ * @returns A result holding the tint factor of the spot color or an error.
1020
+ */
1021
+ getColorSpotTint(id: DesignBlockId, property: string): number;
929
1022
  /**
930
1023
  * Set an enum property of the given design block to the given value.
931
1024
  * @param id - The block whose property should be set.
@@ -1830,17 +1923,28 @@ export declare class BlockAPI {
1830
1923
  /**
1831
1924
  * Generate a thumbnail for the given video fill.
1832
1925
  * @param id - The video fill.
1833
- * @returns A thumbnail encoded as JPEG with a height of 128px.
1926
+ * @param thumbnailHeight - The height of a thumbnail. The width will be calculated from the video aspect ratio.
1927
+ * @returns A thumbnail encoded as JPEG.
1834
1928
  */
1835
- getVideoFillThumbnail(id: DesignBlockId): Promise<Blob>;
1929
+ getVideoFillThumbnail(id: DesignBlockId, thumbnailHeight: number): Promise<Blob>;
1836
1930
  /**
1837
1931
  * Generate a thumbnail atlas for the given video fill.
1838
1932
  * @param id - The video fill.
1839
1933
  * @param numberOfColumns - The number of columns to generate.
1840
1934
  * @param numberOfRows - The number of rows to generate.
1935
+ * @param thumbnailHeight - The height of a thumbnail. The width will be calculated from the video aspect ratio.
1841
1936
  * @returns A thumbnail atlas of the video as JPEG.
1842
1937
  */
1843
- getVideoFillThumbnailAtlas(id: DesignBlockId, numberOfColumns: number, numberOfRows: number): Promise<Blob>;
1938
+ getVideoFillThumbnailAtlas(id: DesignBlockId, numberOfColumns: number, numberOfRows: number, thumbnailHeight: number): Promise<Blob>;
1939
+ /**
1940
+ * Generate a thumbnail atlas for the given page.
1941
+ * @param id - The page.
1942
+ * @param numberOfColumns - The number of columns to generate.
1943
+ * @param numberOfRows - The number of rows to generate.
1944
+ * @param thumbnailHeight - The height of a thumbnail. The width will be calculated from the page aspect ratio.
1945
+ * @returns A thumbnail atlas of the composition as JPEG.
1946
+ */
1947
+ getPageThumbnailAtlas(id: DesignBlockId, numberOfColumns: number, numberOfRows: number, thumbnailHeight: number): Promise<Blob>;
1844
1948
  }
1845
1949
 
1846
1950
  /**
@@ -1989,6 +2093,13 @@ export declare interface Configuration {
1989
2093
  * and always create a webgl1 context.
1990
2094
  */
1991
2095
  forceWebGL1?: boolean;
2096
+ /**
2097
+ * Whether the engine should automatically choose an audio output device or
2098
+ * should not output audio at all.
2099
+ *
2100
+ * If not configured the fallback value is 'auto'.
2101
+ */
2102
+ audioOutput?: 'auto' | 'none';
1992
2103
  }
1993
2104
 
1994
2105
  /**
@@ -2027,16 +2138,15 @@ declare class CreativeEngine {
2027
2138
  /**
2028
2139
  * Initialize a `CreativeEngine` using the given `canvas` element and an optional config.
2029
2140
  * @param config - An optional configuration object.
2030
- * @param canvas - The canvas to use for drawing. Optional, if no canvas is provided,
2031
- * the engine works with an internal offscreen-canvas.
2032
2141
  * @returns An engine instance.
2033
2142
  */
2034
- static init(config?: Partial<Configuration>): Promise<CreativeEngine & {
2035
- readonly element: HTMLCreativeEngineCanvasElement;
2036
- }>;
2037
- static init(config: Partial<Configuration> | undefined, canvas: HTMLCanvasElement | OffscreenCanvas): Promise<CreativeEngine & {
2143
+ static init<C extends Partial<Configuration>>(config?: C): Promise<CreativeEngine & (C extends {
2144
+ readonly canvas: any;
2145
+ } ? {
2038
2146
  readonly element: undefined;
2039
- }>;
2147
+ } : {
2148
+ readonly element: HTMLCreativeEngineCanvasElement;
2149
+ })>;
2040
2150
  }
2041
2151
  export default CreativeEngine;
2042
2152
 
@@ -2069,6 +2179,7 @@ export declare enum DesignBlockType {
2069
2179
  Page = "//ly.img.ubq/page",
2070
2180
  Image = "//ly.img.ubq/image",
2071
2181
  Video = "//ly.img.ubq/video",
2182
+ VideoFill = "//ly.img.ubq/fill/video",
2072
2183
  Audio = "//ly.img.ubq/audio",
2073
2184
  Text = "//ly.img.ubq/text",
2074
2185
  Sticker = "//ly.img.ubq/sticker",
@@ -2129,6 +2240,28 @@ export declare class EditorAPI {
2129
2240
  * @returns The text cursor's y position in screen space.
2130
2241
  */
2131
2242
  getTextCursorPositionInScreenSpaceY(): number;
2243
+ /**
2244
+ * Create a history which consists of an undo/redo stack for editing operations.
2245
+ * There can be multiple. But only one can be active at a time.
2246
+ * @returns The handle of the created history.
2247
+ */
2248
+ createHistory(): HistoryId;
2249
+ /**
2250
+ * Destroy the given history, throws an error if the handle doesn't refer to a history.
2251
+ * @param history - The history to destroy.
2252
+ */
2253
+ destroyHistory(history: HistoryId): void;
2254
+ /**
2255
+ * Mark the given history as active, throws an error if the handle doesn't refer to a history.
2256
+ * All other histories get cleared from the active state. Undo/redo operations only apply to the active history.
2257
+ * @param history - The history to make active.
2258
+ */
2259
+ setActiveHistory(history: HistoryId): void;
2260
+ /**
2261
+ * Get the handle to the currently active history. If there's none it will be created.
2262
+ * @returns History - The handle of the active history.
2263
+ */
2264
+ getActiveHistory(): HistoryId;
2132
2265
  /**
2133
2266
  * Adds a new history state to the stack, if undoable changes were made.
2134
2267
  */
@@ -2153,6 +2286,13 @@ export declare class EditorAPI {
2153
2286
  * @returns True if a redo step is available.
2154
2287
  */
2155
2288
  canRedo(): boolean;
2289
+ /**
2290
+ * Subscribe to changes to the undo/redo history.
2291
+ *
2292
+ * @param callback - This function is called at the end of the engine update, if the undo/redo history has been changed.
2293
+ * @returns A method to unsubscribe
2294
+ */
2295
+ onHistoryUpdated(callback: () => void): () => void;
2156
2296
  /**
2157
2297
  * Subscribe to changes to the editor settings.
2158
2298
  * @param callback - This function is called at the end of the engine update, if the editor settings have changed.
@@ -2274,6 +2414,34 @@ export declare class EditorAPI {
2274
2414
  * @returns `Allow` if the scope is allowed, `Deny` if it is disallowed, and `Defer` if it is deferred to the block-level.
2275
2415
  */
2276
2416
  getGlobalScope(key: string): 'Allow' | 'Deny' | 'Defer';
2417
+ /**
2418
+ * Queries the names of currently set spot colors previously set with `setSpotColorRGB`.
2419
+ * @returns The names of set spot colors.
2420
+ */
2421
+ findAllSpotColors(): string[];
2422
+ /**
2423
+ * Queries the RGB representation set for a spot color.
2424
+ * If the value of the queried spot color has not been set yet, returns the default RGB representation (of magenta).
2425
+ * The alpha value is always 1.0.
2426
+ * @param name - The name of a spot color.
2427
+ * @returns A result holding a float array of the four color components.
2428
+ */
2429
+ getSpotColorRGBA(name: string): RGBA;
2430
+ /**
2431
+ * Sets the RGB representation of a spot color.
2432
+ * Use this function to both create a new spot color or update an existing spot color.
2433
+ * @param name - The name of a spot color.
2434
+ * @param r - The red color component in the range of 0 to 1.
2435
+ * @param g - The green color component in the range of 0 to 1.
2436
+ * @param b - The blue color component in the range of 0 to 1.
2437
+ */
2438
+ setSpotColorRGB(name: string, r: number, g: number, b: number): void;
2439
+ /**
2440
+ * Removes a spot color from the list of set spot colors.
2441
+ * @param name - The name of a spot color.
2442
+ * @returns An empty result on success, an error otherwise.
2443
+ */
2444
+ removeSpotColor(name: string): void;
2277
2445
  }
2278
2446
 
2279
2447
  /**
@@ -2404,7 +2572,7 @@ declare type Extensions = {
2404
2572
  /**
2405
2573
  * @public
2406
2574
  */
2407
- export declare type FillType = 'Solid' | 'Gradient';
2575
+ export declare type FillType = 'Solid' | 'Gradient' | 'Video';
2408
2576
 
2409
2577
  /** @public */
2410
2578
  declare interface FindAssetsQuery {
@@ -2474,6 +2642,12 @@ declare type Handler<T> = (v: T) => void;
2474
2642
  */
2475
2643
  declare type HexColorString = string;
2476
2644
 
2645
+ /**
2646
+ * A numerical identifier for a history stack
2647
+ * @public
2648
+ */
2649
+ export declare type HistoryId = number;
2650
+
2477
2651
  /**
2478
2652
  * A wrapper around a plain canvas
2479
2653
  *
@@ -2775,6 +2949,11 @@ export declare class SceneAPI {
2775
2949
  * @returns A Promise that resolves once the template was applied or rejects if there was an error.
2776
2950
  */
2777
2951
  applyTemplateFromURL(url: string): Promise<void>;
2952
+ /**
2953
+ * Get the current scene mode.
2954
+ * @returns The current mode of the scene.
2955
+ */
2956
+ getMode(): SceneMode;
2778
2957
  /**
2779
2958
  * Sets the zoom level of the active scene.
2780
2959
  * Only has an effect if the zoom level is not handled by the UI.
@@ -2807,6 +2986,12 @@ export declare class SceneAPI {
2807
2986
  * @privateRemarks This will currently fire on _all_ changes to camera properties
2808
2987
  */
2809
2988
  onZoomLevelChanged(callback: () => void): () => void;
2989
+ /**
2990
+ * Subscribe to changes to the active scene rendered by the engine.
2991
+ * @param callback - This function is called at the end of the engine update, if the active scene has changed.
2992
+ * @returns A method to unsubscribe.
2993
+ */
2994
+ onActiveChanged(callback: () => void): () => void;
2810
2995
  /**
2811
2996
  * Converts all values of the current scene into the given design unit.
2812
2997
  * @param designUnit - The new design unit of the scene
@@ -2819,9 +3004,32 @@ export declare class SceneAPI {
2819
3004
  unstable_getDesignUnit(): DesignUnit;
2820
3005
  }
2821
3006
 
2822
- /** @public */
3007
+ /**
3008
+ * The scene layout determines how the layout stack should layout its pages.
3009
+ * @public
3010
+ */
2823
3011
  export declare type SceneLayout = 'Free' | 'VerticalStack' | 'HorizontalStack' | 'DepthStack';
2824
3012
 
3013
+ /**
3014
+ * The mode of the scene defines how the editor and playback should behave.
3015
+ * @public
3016
+ */
3017
+ export declare type SceneMode = 'Design' | 'Video';
3018
+
3019
+ /**
3020
+ * This channel allows to subscribe/update the selected design blocks.
3021
+ * @public
3022
+ */
3023
+ export declare class SelectionChannel implements ReadWriteChannelSync<number[]> {
3024
+ #private;
3025
+ subscribe: Source<number[]>;
3026
+
3027
+ private deselectAll;
3028
+ private selectAll;
3029
+ update: (selectedDesignElements: number[]) => void;
3030
+ value: () => number[];
3031
+ }
3032
+
2825
3033
  /** @public */
2826
3034
  export declare interface Size2 {
2827
3035
  width: number;
@@ -2855,6 +3063,10 @@ export declare interface SpotColor {
2855
3063
  cmykApproximation: CMYKColor;
2856
3064
  }
2857
3065
 
3066
+ declare interface SpotColorLookup {
3067
+ getSpotColorRGBA(name: string): [r: number, g: number, b: number, a: number];
3068
+ }
3069
+
2858
3070
  /** @public */
2859
3071
  export declare type StrokeCornerGeometry = 'Bevel' | 'Miter' | 'Round';
2860
3072