@contrail/extensions-sdk 1.0.28 → 1.0.30

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.
@@ -8,7 +8,8 @@ export declare enum BoardCommand {
8
8
  RECOLOR_IMAGES = "board:recolor_images",
9
9
  ADD_CONTENT_TO_ENTITY_FROM_ELEMENTS = "board:add_content_to_entity_from_elements",
10
10
  ADD_FRAMES_FROM_TEMPLATE = "board:add_frames_from_template",
11
- ADD_ITEMS_TO_CLIPBOARD = "board:add_items_to_clipboard"
11
+ ADD_ITEMS_TO_CLIPBOARD = "board:add_items_to_clipboard",
12
+ COMPOSE_CONTENT = "board:compose_content"
12
13
  }
13
14
  /** Payload for bulk-add items to clipboard (Board and Showcase). */
14
15
  export interface ClipboardItemsPayload {
@@ -17,6 +18,70 @@ export interface ClipboardItemsPayload {
17
18
  projectItemId?: string | null;
18
19
  }>;
19
20
  }
21
+ /** One image in a composition, placed in fractions of the output box. */
22
+ export interface ComposeContentLayer {
23
+ /**
24
+ * The content to draw. The host resolves it to an image, so no URL is needed - and none can
25
+ * expire between planning the layout and composing it.
26
+ *
27
+ * Supply this or {@link fileId}, not both.
28
+ */
29
+ contentId?: string;
30
+ /**
31
+ * A file to draw, for images that exist as files without a content wrapper - the output of a
32
+ * background-removal operation, for instance, which returns a file id.
33
+ *
34
+ * Supply this or {@link contentId}, not both.
35
+ */
36
+ fileId?: string;
37
+ /**
38
+ * Top-left corner as a fraction of the composition box, so `{x: 0.5, y: 0}` is the top middle.
39
+ *
40
+ * Fractions rather than pixels: the layout is then independent of whatever size the extension
41
+ * previewed it at, and the same plan can be reused at any output resolution.
42
+ */
43
+ position: {
44
+ x: number;
45
+ y: number;
46
+ };
47
+ /** Size as a fraction of the composition box. `{width: 1, height: 1}` fills it. */
48
+ size: {
49
+ width: number;
50
+ height: number;
51
+ };
52
+ /** Degrees clockwise about the layer's centre. */
53
+ rotation?: number;
54
+ /** 0-1. Defaults to fully opaque. */
55
+ opacity?: number;
56
+ }
57
+ export interface ComposeContentRequest {
58
+ /** Drawn back to front: the first layer is behind, the last on top. */
59
+ layers: Array<ComposeContentLayer>;
60
+ /**
61
+ * What the new content is filed against, e.g. `item:<id>`.
62
+ *
63
+ * Required: content cannot be created free-floating - the platform derives its access policies
64
+ * from the holder.
65
+ */
66
+ contentHolderReference: string;
67
+ /** Output size in pixels. The host derives one from the source images when omitted. */
68
+ outputSize?: {
69
+ width: number;
70
+ height: number;
71
+ };
72
+ /** Defaults to transparent, which is usually what a composed pack shot wants. */
73
+ backgroundColor?: string;
74
+ fileName?: string;
75
+ }
76
+ export interface ComposeContentResult {
77
+ contentId: string;
78
+ primaryFileId?: string;
79
+ primaryFileUrl?: string;
80
+ size: {
81
+ width: number;
82
+ height: number;
83
+ };
84
+ }
20
85
  export interface BoardDocumentElement extends DocumentElement {
21
86
  [key: string]: any;
22
87
  }
@@ -59,6 +124,28 @@ export declare class BoardsApp {
59
124
  static getElements(criteria: object): Promise<Array<DocumentElement>>;
60
125
  /** Creates new content from a set of elements and assigns to an entity (item, etc) as a viewable */
61
126
  static createNewContentAndAssignToEntity(assignmentOptions: any, entity: any, elements: Array<DocumentElement>): Promise<Array<DocumentElement>>;
127
+ /**
128
+ * Composes several contents into one new image, and returns it as a new content.
129
+ *
130
+ * The extension supplies a layout - which content goes where, at what size - and the board
131
+ * rasterises it with the same renderer its own image export uses. Nothing is added to the
132
+ * board: the elements exist only for the duration of the render.
133
+ *
134
+ * This is the way to build a composed image from an extension. Reading the source images into
135
+ * a canvas the extension owns would taint it and make the export throw, because the image
136
+ * files are cross-origin.
137
+ *
138
+ * ```ts
139
+ * const composed = await BoardsApp.composeContent({
140
+ * layers: [
141
+ * { contentId: 'c1', position: { x: 0, y: 0 }, size: { width: 0.6, height: 0.6 } },
142
+ * { contentId: 'c2', position: { x: 0.4, y: 0.4 }, size: { width: 0.6, height: 0.6 } },
143
+ * ],
144
+ * contentHolderReference: `item:${setItem.id}`,
145
+ * });
146
+ * ```
147
+ */
148
+ static composeContent(request: ComposeContentRequest): Promise<ComposeContentResult>;
62
149
  static recolorImages(imageElements: Array<DocumentElement>, hexCode: string, hexMap?: {}): Promise<Array<DocumentElement>>;
63
150
  /** Request the host to bulk-add items to the user's clipboard. */
64
151
  static addItemsToClipboard(clipboardItems: Array<{
@@ -22,6 +22,7 @@ var BoardCommand;
22
22
  BoardCommand["ADD_CONTENT_TO_ENTITY_FROM_ELEMENTS"] = "board:add_content_to_entity_from_elements";
23
23
  BoardCommand["ADD_FRAMES_FROM_TEMPLATE"] = "board:add_frames_from_template";
24
24
  BoardCommand["ADD_ITEMS_TO_CLIPBOARD"] = "board:add_items_to_clipboard";
25
+ BoardCommand["COMPOSE_CONTENT"] = "board:compose_content";
25
26
  })(BoardCommand = exports.BoardCommand || (exports.BoardCommand = {}));
26
27
  class BoardsApp {
27
28
  static getCurrentBoard() {
@@ -92,6 +93,48 @@ class BoardsApp {
92
93
  return this.validateAndReturnResults(results);
93
94
  });
94
95
  }
96
+ /**
97
+ * Composes several contents into one new image, and returns it as a new content.
98
+ *
99
+ * The extension supplies a layout - which content goes where, at what size - and the board
100
+ * rasterises it with the same renderer its own image export uses. Nothing is added to the
101
+ * board: the elements exist only for the duration of the render.
102
+ *
103
+ * This is the way to build a composed image from an extension. Reading the source images into
104
+ * a canvas the extension owns would taint it and make the export throw, because the image
105
+ * files are cross-origin.
106
+ *
107
+ * ```ts
108
+ * const composed = await BoardsApp.composeContent({
109
+ * layers: [
110
+ * { contentId: 'c1', position: { x: 0, y: 0 }, size: { width: 0.6, height: 0.6 } },
111
+ * { contentId: 'c2', position: { x: 0.4, y: 0.4 }, size: { width: 0.6, height: 0.6 } },
112
+ * ],
113
+ * contentHolderReference: `item:${setItem.id}`,
114
+ * });
115
+ * ```
116
+ */
117
+ static composeContent(request) {
118
+ var _a;
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ BoardsApp.validateBoardContext();
121
+ if (!((_a = request === null || request === void 0 ? void 0 : request.layers) === null || _a === void 0 ? void 0 : _a.length)) {
122
+ throw new Error('composeContent requires at least one layer.');
123
+ }
124
+ if (!(request === null || request === void 0 ? void 0 : request.contentHolderReference)) {
125
+ throw new Error('composeContent requires a contentHolderReference, e.g. `item:<id>`.');
126
+ }
127
+ const unsourced = request.layers.findIndex((layer) => !(layer === null || layer === void 0 ? void 0 : layer.contentId) && !(layer === null || layer === void 0 ? void 0 : layer.fileId));
128
+ if (unsourced >= 0) {
129
+ throw new Error(`composeContent layer ${unsourced} needs either a contentId or a fileId.`);
130
+ }
131
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToHost({
132
+ command: BoardCommand.COMPOSE_CONTENT,
133
+ data: request,
134
+ });
135
+ return this.validateAndReturnResults(results);
136
+ });
137
+ }
95
138
  static recolorImages(imageElements, hexCode, hexMap = {}) {
96
139
  return __awaiter(this, void 0, void 0, function* () {
97
140
  BoardsApp.validateBoardContext();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/extensions-sdk",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "description": "Client library for interfacing with VibeIQ's services and apps from an extension.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",