lucid-extension-sdk 0.0.33 → 0.0.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "sdk/index.js",
6
6
  "types": "sdk/index.d.ts",
@@ -31,6 +31,7 @@ export declare const enum CommandName {
31
31
  CreateDataSource = "cds",
32
32
  CreateLine = "cl",
33
33
  CreatePage = "cp",
34
+ CreateUserImage = "cui",
34
35
  DataAction = "da",
35
36
  DataItemExists = "die",
36
37
  DeleteItem = "di",
@@ -154,6 +155,10 @@ export declare type CommandArgs = {
154
155
  query: CreatePageQuery;
155
156
  result: CreatePageResult;
156
157
  };
158
+ [CommandName.CreateUserImage]: {
159
+ query: CreateUserImageQuery;
160
+ result: CreateUserImageResult;
161
+ };
157
162
  [CommandName.DataAction]: {
158
163
  query: DataActionQuery;
159
164
  result: DataActionResult;
@@ -531,6 +536,17 @@ export declare type CreateLineQuery = {
531
536
  export declare type CreateLineResult = string;
532
537
  export declare type CreatePageQuery = void;
533
538
  export declare type CreatePageResult = string;
539
+ export declare type CreateUserImageQuery = {
540
+ /** media type */
541
+ 't': string;
542
+ /** base64-encoded image data */
543
+ 'd': string;
544
+ };
545
+ export declare type RawCreateUserImageResult = {
546
+ /** The resulting image URL */
547
+ 'u': string;
548
+ };
549
+ export declare type CreateUserImageResult = Promise<RawCreateUserImageResult>;
534
550
  export declare type DataActionQuery = {
535
551
  /** Flow Name */
536
552
  'fn': string;
@@ -1 +1,2 @@
1
1
  export declare function decodeBase64(base64String: string): Uint8Array;
2
+ export declare function encodeBase64(byteArray: Uint8Array): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeBase64 = void 0;
3
+ exports.encodeBase64 = exports.decodeBase64 = void 0;
4
4
  const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
5
5
  //This gives a ~8x speedup vs. using alphabet.indexOf() in the main decode loop.
6
6
  const charCodeToEncodedInt = [];
@@ -43,3 +43,40 @@ function decodeBase64(base64String) {
43
43
  return output;
44
44
  }
45
45
  exports.decodeBase64 = decodeBase64;
46
+ function encodeBase64(byteArray) {
47
+ // 3 bytes of input become 4 chars of output
48
+ // i.e. every 6 bits of input becomes 1 char of output
49
+ const fullByteChunkCount = Math.floor(byteArray.length / 3);
50
+ const outputLength = Math.ceil(byteArray.length / 3) * 4;
51
+ const output = new Array(outputLength);
52
+ let inputIndex = 0;
53
+ let outputIndex = 0;
54
+ for (let byteChunkIndex = 0; byteChunkIndex < fullByteChunkCount; byteChunkIndex++) {
55
+ const byte1 = byteArray[inputIndex++];
56
+ const byte2 = byteArray[inputIndex++];
57
+ const byte3 = byteArray[inputIndex++];
58
+ const enc1 = byte1 >> 2; // first 6 bits of byte1
59
+ const enc2 = ((byte1 & 3) << 4) | (byte2 >> 4); // last 2 bits of byte1 and first 4 bits of byte2
60
+ const enc3 = ((byte2 & 15) << 2) | (byte3 >> 6); // last 4 bits of byte2 and first 2 bits of byte3
61
+ const enc4 = byte3 & 63; // last 6 bits of byte3
62
+ output[outputIndex++] = alphabet[enc1];
63
+ output[outputIndex++] = alphabet[enc2];
64
+ output[outputIndex++] = alphabet[enc3];
65
+ output[outputIndex++] = alphabet[enc4];
66
+ }
67
+ // handle remainder, i.e. trailing one or two bytes
68
+ if (inputIndex < byteArray.length) {
69
+ const byte1 = byteArray[inputIndex++];
70
+ const hasSecondByte = inputIndex < byteArray.length;
71
+ const byte2 = hasSecondByte ? byteArray[inputIndex++] : 0;
72
+ const enc1 = byte1 >> 2; // first 6 bits of byte1
73
+ const enc2 = ((byte1 & 3) << 4) | (byte2 >> 4); // last 2 bits of byte1 and first 4 bits of byte2
74
+ const enc3 = hasSecondByte ? (byte2 & 15) << 2 : 64; // last 4 bits of byte2
75
+ output[outputIndex++] = alphabet[enc1];
76
+ output[outputIndex++] = alphabet[enc2];
77
+ output[outputIndex++] = alphabet[enc3];
78
+ output[outputIndex++] = '=';
79
+ }
80
+ return output.join('');
81
+ }
82
+ exports.encodeBase64 = encodeBase64;
@@ -65,6 +65,16 @@ export declare class EditorClient {
65
65
  * @param base64 If true, base64 decode the data before downloading it
66
66
  */
67
67
  download(filename: string, data: string, mime: string, base64: boolean): void;
68
+ /**
69
+ * Upload an image and return a URL that can be used for displaying that image on the canvas. Note: the URL is
70
+ * public - anyone with the URL can access the image.
71
+ * @param data The binary image contents, or a base64-encoded string
72
+ * @param mediaType The media type, e.g. 'image/png'
73
+ * @returns A promise that resolves with the URL of the created image.
74
+ *
75
+ * @ignore
76
+ */
77
+ experimentalCreateUserImage(mediaType: string, data: Uint8Array | string): Promise<string>;
68
78
  /**
69
79
  *
70
80
  * @param flowName
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EditorClient = void 0;
4
4
  const commandtypes_1 = require("./commandtypes");
5
5
  const base64_1 = require("./core/base64");
6
+ const checks_1 = require("./core/checks");
6
7
  const blockproxyregistry_1 = require("./document/blockclasses/blockproxyregistry");
7
8
  const blockproxy_1 = require("./document/blockproxy");
8
9
  const documentproxy_1 = require("./document/documentproxy");
@@ -49,6 +50,22 @@ class EditorClient {
49
50
  'b64': base64,
50
51
  });
51
52
  }
53
+ /**
54
+ * Upload an image and return a URL that can be used for displaying that image on the canvas. Note: the URL is
55
+ * public - anyone with the URL can access the image.
56
+ * @param data The binary image contents, or a base64-encoded string
57
+ * @param mediaType The media type, e.g. 'image/png'
58
+ * @returns A promise that resolves with the URL of the created image.
59
+ *
60
+ * @ignore
61
+ */
62
+ async experimentalCreateUserImage(mediaType, data) {
63
+ const result = await this.sendCommand("cui" /* CreateUserImage */, {
64
+ 't': mediaType,
65
+ 'd': (0, checks_1.isString)(data) ? data : (0, base64_1.encodeBase64)(data),
66
+ });
67
+ return result['u'];
68
+ }
52
69
  /**
53
70
  *
54
71
  * @param flowName