@kittl/sdk 0.0.3 → 0.0.5

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.
@@ -18,6 +18,9 @@ var isDesignStateUpdatePushMessage = (data) => {
18
18
  var isAppStateUpdatePushMessage = (data) => {
19
19
  return typeof data === "object" && data !== null && "command" in data && data.command === "app-state-update" && "updates" in data && Array.isArray(data.updates);
20
20
  };
21
+ var isContextUpdatePushMessage = (data) => {
22
+ return typeof data === "object" && data !== null && "command" in data && data.command === "context-update" && "subscriptionId" in data && typeof data.subscriptionId === "string" && "context" in data && typeof data.context === "object" && data.context !== null;
23
+ };
21
24
 
22
25
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/shared/createApiProxyCore.js
23
26
  var buildMethodPath = (rootPrefix, pathSegments) => {
@@ -192,6 +195,13 @@ var createSDKCallMessage = {
192
195
  args,
193
196
  messageId,
194
197
  apiType: "upload"
198
+ }),
199
+ data: (dots, args, messageId) => ({
200
+ command: "sdk-call",
201
+ dots,
202
+ args,
203
+ messageId,
204
+ apiType: "data"
195
205
  })
196
206
  };
197
207
  function createApiProxy(apiType) {
@@ -210,6 +220,7 @@ function createApiProxy(apiType) {
210
220
 
211
221
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/apiProxy/aiApiProxy.js
212
222
  var generationHandlers = /* @__PURE__ */ new Map();
223
+ var generationSubscriptions = /* @__PURE__ */ new Map();
213
224
  var dispatchAIGenerationUpdate = (subscriptionId, update) => {
214
225
  const handler = generationHandlers.get(subscriptionId);
215
226
  if (!handler) {
@@ -218,6 +229,20 @@ var dispatchAIGenerationUpdate = (subscriptionId, update) => {
218
229
  void handler(update);
219
230
  };
220
231
  function createAIApiProxy() {
232
+ const unregisterGenerationHandler = (generatorId) => {
233
+ const subscriptionId = generationSubscriptions.get(generatorId);
234
+ if (!subscriptionId) {
235
+ return;
236
+ }
237
+ generationHandlers.delete(subscriptionId);
238
+ generationSubscriptions.delete(generatorId);
239
+ const unregisterMessage = {
240
+ command: "ai-unregister-handler",
241
+ generatorId,
242
+ subscriptionId
243
+ };
244
+ postMessageToParent(unregisterMessage);
245
+ };
221
246
  return {
222
247
  spendCredits: async (options) => {
223
248
  const { onAccept, onDecline, ...serializable } = options;
@@ -247,16 +272,18 @@ function createAIApiProxy() {
247
272
  return sendMessage(message);
248
273
  },
249
274
  registerHandler: async (generatorId, onStatusUpdate) => {
250
- const subscriptionId = generateMessageId();
251
- const unregister = () => {
252
- generationHandlers.delete(subscriptionId);
253
- const unregisterMessage = {
254
- command: "ai-unregister-handler",
255
- subscriptionId
275
+ if (generationSubscriptions.has(generatorId)) {
276
+ return {
277
+ isOk: false,
278
+ error: {
279
+ message: `AI handler for generator "${generatorId}" is already registered`,
280
+ name: "SdkInternalError"
281
+ }
256
282
  };
257
- postMessageToParent(unregisterMessage);
258
- };
283
+ }
284
+ const subscriptionId = generateMessageId();
259
285
  generationHandlers.set(subscriptionId, onStatusUpdate);
286
+ generationSubscriptions.set(generatorId, subscriptionId);
260
287
  const registerMessage = {
261
288
  command: "ai-register-handler",
262
289
  messageId: generateMessageId(),
@@ -267,11 +294,16 @@ function createAIApiProxy() {
267
294
  const response = await sendMessage(registerMessage);
268
295
  if (!response.isOk) {
269
296
  generationHandlers.delete(subscriptionId);
297
+ generationSubscriptions.delete(generatorId);
270
298
  return response;
271
299
  }
272
- return { isOk: true, result: unregister };
300
+ return {
301
+ isOk: true,
302
+ result: () => unregisterGenerationHandler(generatorId)
303
+ };
273
304
  } catch {
274
305
  generationHandlers.delete(subscriptionId);
306
+ generationSubscriptions.delete(generatorId);
275
307
  return {
276
308
  isOk: false,
277
309
  error: {
@@ -280,6 +312,10 @@ function createAIApiProxy() {
280
312
  }
281
313
  };
282
314
  }
315
+ },
316
+ unregisterHandler: async (generatorId) => {
317
+ unregisterGenerationHandler(generatorId);
318
+ return { isOk: true, result: void 0 };
283
319
  }
284
320
  };
285
321
  }
@@ -425,8 +461,7 @@ var createAuthBridgeApi = () => {
425
461
  const message = {
426
462
  command: "auth-refresh",
427
463
  messageId: generateMessageId(),
428
- provider: request.provider,
429
- refresh_token: request.refresh_token
464
+ provider: request.provider
430
465
  };
431
466
  return sendMessage(message);
432
467
  },
@@ -486,6 +521,53 @@ var createBatch = async () => {
486
521
  return buildNode([]);
487
522
  };
488
523
 
524
+ // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/context/contextBridge.js
525
+ var createContextBridgeApi = () => {
526
+ const contextProxy = createApiProxy("context");
527
+ const subscriptionCallbacks = /* @__PURE__ */ new Map();
528
+ const dispatch = (message) => {
529
+ const cb = subscriptionCallbacks.get(message.subscriptionId);
530
+ cb?.(message.context);
531
+ };
532
+ const subscribeImpl = async (callback) => {
533
+ const subscriptionId = generateMessageId();
534
+ const messageId = generateMessageId();
535
+ subscriptionCallbacks.set(subscriptionId, callback);
536
+ let response;
537
+ try {
538
+ response = await sendMessage({
539
+ command: "context-subscribe",
540
+ messageId,
541
+ subscriptionId
542
+ });
543
+ } catch (error) {
544
+ subscriptionCallbacks.delete(subscriptionId);
545
+ throw error;
546
+ }
547
+ if (!response.isOk) {
548
+ subscriptionCallbacks.delete(subscriptionId);
549
+ throw new Error(`context-subscribe failed: ${response.error.message}`);
550
+ }
551
+ return () => {
552
+ subscriptionCallbacks.delete(subscriptionId);
553
+ const message = {
554
+ command: "context-unsubscribe",
555
+ subscriptionId
556
+ };
557
+ postMessageToParent(message);
558
+ };
559
+ };
560
+ const api = new Proxy(contextProxy, {
561
+ get(target, prop, receiver) {
562
+ if (prop === "subscribe") {
563
+ return subscribeImpl;
564
+ }
565
+ return Reflect.get(target, prop, receiver);
566
+ }
567
+ });
568
+ return { api, dispatch };
569
+ };
570
+
489
571
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/designState/index.js
490
572
  var sendUnsubscribe2 = (selectorIds) => {
491
573
  const message = {
@@ -607,6 +689,7 @@ var createStatelessBridgeApi = () => {
607
689
  var statelessApi = createStatelessBridgeApi();
608
690
  var designStateApi = createDesignStateBridgeApi();
609
691
  var appStateApi = createAppStateBridgeApi();
692
+ var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
610
693
  var handleIncomingMessage = (event) => {
611
694
  const parent = window.parent;
612
695
  if (!parent || parent === window) {
@@ -641,10 +724,14 @@ var handleIncomingMessage = (event) => {
641
724
  appStateApi.dispatch(data.updates);
642
725
  return;
643
726
  }
727
+ if (isContextUpdatePushMessage(data)) {
728
+ dispatchContextUpdate(data);
729
+ }
644
730
  };
645
731
  var bridgeHandlers = {
646
732
  ai: createAIApiProxy(),
647
- context: createApiProxy("context"),
733
+ context: contextApi,
734
+ data: createApiProxy("data"),
648
735
  design: createApiProxy("design"),
649
736
  designStore: designStateApi,
650
737
  appStore: appStateApi,
@@ -925,6 +1012,24 @@ var DragAndDropApi = class {
925
1012
  }
926
1013
  };
927
1014
 
1015
+ // src/utils/syncHtmlDataThemeFromHostContext.ts
1016
+ async function syncHtmlDataThemeFromHostContext(kittl2) {
1017
+ if (typeof document === "undefined") {
1018
+ return;
1019
+ }
1020
+ const parent = window.parent;
1021
+ if (!parent || parent === window) {
1022
+ return;
1023
+ }
1024
+ const contextResponse = await kittl2.context.get();
1025
+ if (contextResponse.isOk) {
1026
+ document.documentElement.dataset.theme = contextResponse.result.colorScheme;
1027
+ }
1028
+ await kittl2.context.subscribe((ctx) => {
1029
+ document.documentElement.dataset.theme = ctx.colorScheme;
1030
+ });
1031
+ }
1032
+
928
1033
  // src/index.ts
929
1034
  var kittl = {
930
1035
  onLoadedCallback: null,
@@ -952,8 +1057,10 @@ var initSdk = () => {
952
1057
  handleIncomingMessage(event);
953
1058
  }
954
1059
  );
955
- kittl.onLoadedCallback?.();
956
- sendLoaded();
1060
+ void syncHtmlDataThemeFromHostContext(kittl).then(() => {
1061
+ kittl.onLoadedCallback?.();
1062
+ sendLoaded();
1063
+ });
957
1064
  };
958
1065
  if (typeof document !== "undefined" && typeof window !== "undefined") {
959
1066
  window.kittl = kittl;
package/dist/kittl-sdk.js CHANGED
@@ -19,6 +19,9 @@
19
19
  var isAppStateUpdatePushMessage = (data) => {
20
20
  return typeof data === "object" && data !== null && "command" in data && data.command === "app-state-update" && "updates" in data && Array.isArray(data.updates);
21
21
  };
22
+ var isContextUpdatePushMessage = (data) => {
23
+ return typeof data === "object" && data !== null && "command" in data && data.command === "context-update" && "subscriptionId" in data && typeof data.subscriptionId === "string" && "context" in data && typeof data.context === "object" && data.context !== null;
24
+ };
22
25
 
23
26
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/shared/createApiProxyCore.js
24
27
  var buildMethodPath = (rootPrefix, pathSegments) => {
@@ -193,6 +196,13 @@
193
196
  args,
194
197
  messageId,
195
198
  apiType: "upload"
199
+ }),
200
+ data: (dots, args, messageId) => ({
201
+ command: "sdk-call",
202
+ dots,
203
+ args,
204
+ messageId,
205
+ apiType: "data"
196
206
  })
197
207
  };
198
208
  function createApiProxy(apiType) {
@@ -211,6 +221,7 @@
211
221
 
212
222
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/apiProxy/aiApiProxy.js
213
223
  var generationHandlers = /* @__PURE__ */ new Map();
224
+ var generationSubscriptions = /* @__PURE__ */ new Map();
214
225
  var dispatchAIGenerationUpdate = (subscriptionId, update) => {
215
226
  const handler = generationHandlers.get(subscriptionId);
216
227
  if (!handler) {
@@ -219,6 +230,20 @@
219
230
  void handler(update);
220
231
  };
221
232
  function createAIApiProxy() {
233
+ const unregisterGenerationHandler = (generatorId) => {
234
+ const subscriptionId = generationSubscriptions.get(generatorId);
235
+ if (!subscriptionId) {
236
+ return;
237
+ }
238
+ generationHandlers.delete(subscriptionId);
239
+ generationSubscriptions.delete(generatorId);
240
+ const unregisterMessage = {
241
+ command: "ai-unregister-handler",
242
+ generatorId,
243
+ subscriptionId
244
+ };
245
+ postMessageToParent(unregisterMessage);
246
+ };
222
247
  return {
223
248
  spendCredits: async (options) => {
224
249
  const { onAccept, onDecline, ...serializable } = options;
@@ -248,16 +273,18 @@
248
273
  return sendMessage(message);
249
274
  },
250
275
  registerHandler: async (generatorId, onStatusUpdate) => {
251
- const subscriptionId = generateMessageId();
252
- const unregister = () => {
253
- generationHandlers.delete(subscriptionId);
254
- const unregisterMessage = {
255
- command: "ai-unregister-handler",
256
- subscriptionId
276
+ if (generationSubscriptions.has(generatorId)) {
277
+ return {
278
+ isOk: false,
279
+ error: {
280
+ message: `AI handler for generator "${generatorId}" is already registered`,
281
+ name: "SdkInternalError"
282
+ }
257
283
  };
258
- postMessageToParent(unregisterMessage);
259
- };
284
+ }
285
+ const subscriptionId = generateMessageId();
260
286
  generationHandlers.set(subscriptionId, onStatusUpdate);
287
+ generationSubscriptions.set(generatorId, subscriptionId);
261
288
  const registerMessage = {
262
289
  command: "ai-register-handler",
263
290
  messageId: generateMessageId(),
@@ -268,11 +295,16 @@
268
295
  const response = await sendMessage(registerMessage);
269
296
  if (!response.isOk) {
270
297
  generationHandlers.delete(subscriptionId);
298
+ generationSubscriptions.delete(generatorId);
271
299
  return response;
272
300
  }
273
- return { isOk: true, result: unregister };
301
+ return {
302
+ isOk: true,
303
+ result: () => unregisterGenerationHandler(generatorId)
304
+ };
274
305
  } catch {
275
306
  generationHandlers.delete(subscriptionId);
307
+ generationSubscriptions.delete(generatorId);
276
308
  return {
277
309
  isOk: false,
278
310
  error: {
@@ -281,6 +313,10 @@
281
313
  }
282
314
  };
283
315
  }
316
+ },
317
+ unregisterHandler: async (generatorId) => {
318
+ unregisterGenerationHandler(generatorId);
319
+ return { isOk: true, result: void 0 };
284
320
  }
285
321
  };
286
322
  }
@@ -426,8 +462,7 @@
426
462
  const message = {
427
463
  command: "auth-refresh",
428
464
  messageId: generateMessageId(),
429
- provider: request.provider,
430
- refresh_token: request.refresh_token
465
+ provider: request.provider
431
466
  };
432
467
  return sendMessage(message);
433
468
  },
@@ -487,6 +522,53 @@
487
522
  return buildNode([]);
488
523
  };
489
524
 
525
+ // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/context/contextBridge.js
526
+ var createContextBridgeApi = () => {
527
+ const contextProxy = createApiProxy("context");
528
+ const subscriptionCallbacks = /* @__PURE__ */ new Map();
529
+ const dispatch = (message) => {
530
+ const cb = subscriptionCallbacks.get(message.subscriptionId);
531
+ cb?.(message.context);
532
+ };
533
+ const subscribeImpl = async (callback) => {
534
+ const subscriptionId = generateMessageId();
535
+ const messageId = generateMessageId();
536
+ subscriptionCallbacks.set(subscriptionId, callback);
537
+ let response;
538
+ try {
539
+ response = await sendMessage({
540
+ command: "context-subscribe",
541
+ messageId,
542
+ subscriptionId
543
+ });
544
+ } catch (error) {
545
+ subscriptionCallbacks.delete(subscriptionId);
546
+ throw error;
547
+ }
548
+ if (!response.isOk) {
549
+ subscriptionCallbacks.delete(subscriptionId);
550
+ throw new Error(`context-subscribe failed: ${response.error.message}`);
551
+ }
552
+ return () => {
553
+ subscriptionCallbacks.delete(subscriptionId);
554
+ const message = {
555
+ command: "context-unsubscribe",
556
+ subscriptionId
557
+ };
558
+ postMessageToParent(message);
559
+ };
560
+ };
561
+ const api = new Proxy(contextProxy, {
562
+ get(target, prop, receiver) {
563
+ if (prop === "subscribe") {
564
+ return subscribeImpl;
565
+ }
566
+ return Reflect.get(target, prop, receiver);
567
+ }
568
+ });
569
+ return { api, dispatch };
570
+ };
571
+
490
572
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/designState/index.js
491
573
  var sendUnsubscribe2 = (selectorIds) => {
492
574
  const message = {
@@ -608,6 +690,7 @@
608
690
  var statelessApi = createStatelessBridgeApi();
609
691
  var designStateApi = createDesignStateBridgeApi();
610
692
  var appStateApi = createAppStateBridgeApi();
693
+ var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
611
694
  var handleIncomingMessage = (event) => {
612
695
  const parent = window.parent;
613
696
  if (!parent || parent === window) {
@@ -642,10 +725,14 @@
642
725
  appStateApi.dispatch(data.updates);
643
726
  return;
644
727
  }
728
+ if (isContextUpdatePushMessage(data)) {
729
+ dispatchContextUpdate(data);
730
+ }
645
731
  };
646
732
  var bridgeHandlers = {
647
733
  ai: createAIApiProxy(),
648
- context: createApiProxy("context"),
734
+ context: contextApi,
735
+ data: createApiProxy("data"),
649
736
  design: createApiProxy("design"),
650
737
  designStore: designStateApi,
651
738
  appStore: appStateApi,
@@ -926,6 +1013,24 @@
926
1013
  }
927
1014
  };
928
1015
 
1016
+ // src/utils/syncHtmlDataThemeFromHostContext.ts
1017
+ async function syncHtmlDataThemeFromHostContext(kittl2) {
1018
+ if (typeof document === "undefined") {
1019
+ return;
1020
+ }
1021
+ const parent = window.parent;
1022
+ if (!parent || parent === window) {
1023
+ return;
1024
+ }
1025
+ const contextResponse = await kittl2.context.get();
1026
+ if (contextResponse.isOk) {
1027
+ document.documentElement.dataset.theme = contextResponse.result.colorScheme;
1028
+ }
1029
+ await kittl2.context.subscribe((ctx) => {
1030
+ document.documentElement.dataset.theme = ctx.colorScheme;
1031
+ });
1032
+ }
1033
+
929
1034
  // src/index.ts
930
1035
  var kittl = {
931
1036
  onLoadedCallback: null,
@@ -953,8 +1058,10 @@
953
1058
  handleIncomingMessage(event);
954
1059
  }
955
1060
  );
956
- kittl.onLoadedCallback?.();
957
- sendLoaded();
1061
+ void syncHtmlDataThemeFromHostContext(kittl).then(() => {
1062
+ kittl.onLoadedCallback?.();
1063
+ sendLoaded();
1064
+ });
958
1065
  };
959
1066
  if (typeof document !== "undefined" && typeof window !== "undefined") {
960
1067
  window.kittl = kittl;
package/dist/sdk.d.ts CHANGED
@@ -14,6 +14,16 @@ declare abstract class KittlStateStore<T extends Record<string, unknown>> {
14
14
  abstract internalPatch(args: InternalPatchArgs<T>): void;
15
15
  abstract resetWithState(state: T): void;
16
16
  }
17
+ declare class SdkBadInputError extends Error {
18
+ readonly name: "SdkBadInputError";
19
+ readonly cause?: Error;
20
+ constructor(message: string, cause?: Error);
21
+ }
22
+ declare class SdkInternalError extends Error {
23
+ readonly name: "SdkInternalError";
24
+ readonly cause?: Error;
25
+ constructor(message: string, cause?: Error);
26
+ }
17
27
  declare const BASIC_SHAPE_DEFAULT_VALUES: {
18
28
  defaultIcon: LayerIconType | undefined;
19
29
  shadowOptions?: {
@@ -193,6 +203,9 @@ declare const GUIDE_DEFAULT_VALUES: {
193
203
  version: string;
194
204
  type: ObjectType.Guide;
195
205
  };
206
+ declare const GenerationOperation: {
207
+ readonly INPAINT: "inpaint";
208
+ };
196
209
  declare const GenerationStatus: {
197
210
  readonly CREATED: "CREATED";
198
211
  readonly STARTED: "STARTED";
@@ -552,6 +565,11 @@ export interface AIGenerationOutputSettings {
552
565
  height: number;
553
566
  };
554
567
  }
568
+ export interface AddFontStyleOptions {
569
+ fontFamilyId: string;
570
+ objectIds: string[];
571
+ styles: string[];
572
+ }
555
573
  export interface AppStateAPI {
556
574
  getSelectedObjectsIds(): string[];
557
575
  setSelectedObjectsIds(ids: string[]): void;
@@ -567,6 +585,7 @@ export interface AppStateAPI {
567
585
  setCanvasMode(mode: AppState["canvasMode"], origin?: Origin): void;
568
586
  getActiveTool(): ActiveTool | null;
569
587
  setActiveTool(tool: ActiveTool | null): void;
588
+ getIsDragPanning(): boolean;
570
589
  viewport: ViewportAPI;
571
590
  getHighlightedObjectId(): string | null;
572
591
  setHighlightedObjectId(id: string | null): void;
@@ -576,6 +595,7 @@ export interface AsyncAIAPI {
576
595
  spendCredits: (options: SpendCreditsOptions) => SdkResultAsync<SpendCreditsResult, Error>;
577
596
  startGeneration: (generatorId: string, inputSettings: AIGenerationInputSettings, output: AIGenerationOutputSettings) => SdkResultAsync<StartGenerationResult, Error>;
578
597
  registerHandler: (generatorId: string, onStatusUpdate: OnGenerationStatusUpdate) => SdkResultAsync<() => void, Error>;
598
+ unregisterHandler: (generatorId: string) => SdkResultAsync<void, Error>;
579
599
  }
580
600
  export interface AsyncAppStateAPI extends WithAsync<AppStateAPI> {
581
601
  }
@@ -617,7 +637,10 @@ export interface AsyncAuthAPI {
617
637
  export interface AsyncBatchDesignAPI extends AsyncDesignAPI {
618
638
  commit: () => Promise<void>;
619
639
  }
620
- export interface AsyncContextAPI extends WithAsync<ContextAPI> {
640
+ export interface AsyncContextAPI extends Omit<WithAsync<ContextAPI>, "subscribe"> {
641
+ subscribe(callback: ContextSubscriptionCallback): Promise<() => void>;
642
+ }
643
+ export interface AsyncDataAPI extends WithAsync<DataSDKApi> {
621
644
  }
622
645
  export interface AsyncDesignAPI extends WithAsync<WithOptsRemoved<DesignAPI>> {
623
646
  }
@@ -676,7 +699,6 @@ export interface AuthLogoutRequest {
676
699
  }
677
700
  export interface AuthRefreshRequest {
678
701
  provider: string;
679
- refresh_token: string;
680
702
  }
681
703
  export interface AuthStartRequest {
682
704
  provider: string;
@@ -757,15 +779,27 @@ export interface CanvasAPI {
757
779
  getPreviewImage: (id: string, options?: Partial<GetPreviewImageOptions>) => Promise<string | null>;
758
780
  getExport: (options: GetExportOptions) => Promise<Blob | null>;
759
781
  }
782
+ export interface CatalogItem {
783
+ id: string;
784
+ name: string;
785
+ previewImages: string[];
786
+ }
760
787
  export interface ConfigAPI {
761
788
  setConfig(config: Partial<DesignConfig>, opts?: DesignApiOptions): void;
762
789
  }
763
790
  export interface ContextAPI {
764
791
  get(input?: ContextGetInput): KittlContext;
792
+ subscribe(callback: ContextSubscriptionCallback): () => void;
765
793
  }
766
794
  export interface ContextGetInput {
767
795
  iframe?: Pick<HTMLIFrameElement, "getBoundingClientRect">;
768
796
  }
797
+ export interface CreateFontOptions {
798
+ name: string;
799
+ files: Blob[];
800
+ styles: string[];
801
+ previewImage?: Blob;
802
+ }
769
803
  export interface CreateLoadingCardInput extends CreateElementWithPositionAndSize {
770
804
  imageGenerationId?: string;
771
805
  startedAt?: number;
@@ -773,6 +807,10 @@ export interface CreateLoadingCardInput extends CreateElementWithPositionAndSize
773
807
  generationAverageSpeed?: number;
774
808
  name?: string;
775
809
  }
810
+ export interface DataSDKApi {
811
+ mockups: MockupDataAPI;
812
+ fonts: FontDataAPI;
813
+ }
776
814
  export interface DecorationOptions {
777
815
  type: "horizontalLines" | "colorCut" | "obliqueLines" | "fadingColorCut";
778
816
  color: string | null;
@@ -780,6 +818,10 @@ export interface DecorationOptions {
780
818
  distance: number;
781
819
  cutDistance: number;
782
820
  }
821
+ export interface DeleteFontStyleOptions {
822
+ fontFamilyId: string;
823
+ id: string;
824
+ }
783
825
  export interface DesignAPI {
784
826
  shape: ShapeAPI;
785
827
  board: BoardAPI;
@@ -837,17 +879,42 @@ export interface DragAndDropStartDragImageEventInput {
837
879
  export interface ErrorGenerationResult {
838
880
  type: typeof ResultType.ERROR;
839
881
  message: string;
840
- code?: string;
882
+ subtitle: string;
883
+ status: "warning" | "error";
841
884
  }
842
885
  export interface FontAPI {
843
886
  createFont: (params: {
844
887
  name: string;
845
888
  files: Blob[];
846
889
  styles: string[];
847
- extensionId?: string;
848
890
  previewImage?: Blob;
849
891
  }) => SdkResultAsync<UploadedFontFamily, Error>;
850
892
  }
893
+ export interface FontDataAPI {
894
+ listUserFonts(options?: PaginationOptions): SdkResultAsync<FontListDto>;
895
+ listExtensionFonts(options?: PaginationOptions): SdkResultAsync<FontListDto>;
896
+ get(fontFamilyId: string): SdkResultAsync<FontFamilyDto>;
897
+ find(ids: string[]): SdkResultAsync<FontFamilyDto[]>;
898
+ create(options: CreateFontOptions): SdkResultAsync<FontFamilyDto>;
899
+ update(options: UpdateFontFamilyOptions): SdkResultAsync<FontFamilyDto>;
900
+ delete(ids: string[]): SdkResultAsync<void>;
901
+ destroy(ids: string[]): SdkResultAsync<void>;
902
+ addStyle(options: AddFontStyleOptions): SdkResultAsync<FontFamilyDto>;
903
+ deleteStyle(options: DeleteFontStyleOptions): SdkResultAsync<void>;
904
+ updateStyle(options: UpdateFontStyleOptions): SdkResultAsync<void>;
905
+ }
906
+ export interface FontFamilyDto extends CatalogItem {
907
+ styles: FontStyleDto[];
908
+ extension: {
909
+ id: string;
910
+ name?: string;
911
+ } | null;
912
+ }
913
+ export interface FontStyleDto {
914
+ id: string;
915
+ name: string;
916
+ style: string | null;
917
+ }
851
918
  export interface FontVariation {
852
919
  name: string;
853
920
  min: number;
@@ -876,6 +943,7 @@ export interface GenerationInputData {
876
943
  export interface GenerationMeta {
877
944
  generationEndsAt?: number;
878
945
  pendingGenerationId: string;
946
+ operation?: GenerationOperation;
879
947
  }
880
948
  export interface GenerationStartedResultCommonProps {
881
949
  generationEndsAt?: number;
@@ -897,7 +965,16 @@ export interface GetExportOptions {
897
965
  height: number;
898
966
  };
899
967
  };
968
+ size?: {
969
+ width: number;
970
+ height: number;
971
+ unit: Unit;
972
+ };
973
+ dpi?: number;
974
+ colorModel?: "rgb" | "cmyk";
900
975
  removeArtboardBackground?: boolean;
976
+ optimizedQuality?: boolean;
977
+ renderingIntent?: "download" | "pdf";
901
978
  }
902
979
  export interface GetObjectParams {
903
980
  id: string;
@@ -958,6 +1035,9 @@ export interface IllustrationAPI {
958
1035
  export interface ImageAPI {
959
1036
  addImage(params: AddImageParams, opts?: DesignApiOptions): SdkResultAsync<NormalizedIllustrationImageObject, SdkError>;
960
1037
  updateImage(params: UpdateImageParams, opts?: DesignApiOptions): NormalizedIllustrationImageObject;
1038
+ updateImageSource(params: UpdateImageSourceParams, opts?: DesignApiOptions): SdkResultAsync<NormalizedIllustrationImageObject, SdkError>;
1039
+ resetImageCrop(params: ResetImageCropParams, opts?: DesignApiOptions): SdkResultAsync<NormalizedIllustrationImageObject, SdkError>;
1040
+ resetImageBackgroundRemoval(params: ResetImageBackgroundRemovalParams, opts?: DesignApiOptions): SdkResultAsync<NormalizedIllustrationImageObject, SdkError>;
961
1041
  }
962
1042
  export interface ImageGenerationResult {
963
1043
  type: typeof ResultType.IMAGE;
@@ -977,6 +1057,7 @@ export interface KittlSDK {
977
1057
  onLoadedCallback: (() => void) | null;
978
1058
  onReady: (cb: () => void) => void;
979
1059
  ai: AsyncAIAPI;
1060
+ data: AsyncDataAPI;
980
1061
  design: AsyncDesignAPI;
981
1062
  designStore: AsyncDesignStateAPI;
982
1063
  appStore: AsyncAppStateSubscriptionAPI;
@@ -1005,6 +1086,33 @@ export interface LoadingCardAPI {
1005
1086
  createLoadingCard(input: CreateLoadingCardInput, opts?: DesignApiOptions): NormalizedLoadingCardObject;
1006
1087
  updateLoadingCard(input: UpdateLoadingCardInput, opts?: DesignApiOptions): NormalizedLoadingCardObject;
1007
1088
  }
1089
+ export interface MockupDataAPI {
1090
+ get(id: number): SdkResultAsync<CatalogItem>;
1091
+ getOverview(options?: Pick<PaginationOptions, "sort">): SdkResultAsync<MockupOverviewDto>;
1092
+ getGroup(groupId: string, options?: PaginationOptions): SdkResultAsync<MockupGroupDto>;
1093
+ search(query: string, options?: PaginationOptions): SdkResultAsync<PaginatedResult<CatalogItem>>;
1094
+ getSuggestions(): SdkResultAsync<MockupSuggestions>;
1095
+ }
1096
+ export interface MockupGroupDto {
1097
+ group: {
1098
+ id: string;
1099
+ name: string;
1100
+ };
1101
+ data: PaginatedResult<CatalogItem>;
1102
+ }
1103
+ export interface MockupOverviewDto {
1104
+ overview: MockupOverviewGroupDto[];
1105
+ }
1106
+ export interface MockupOverviewGroupDto {
1107
+ id: string;
1108
+ name: string;
1109
+ mockups: CatalogItem[];
1110
+ total: number;
1111
+ }
1112
+ export interface MockupSuggestions {
1113
+ tags: string[];
1114
+ groups: string[];
1115
+ }
1008
1116
  export interface MockupboardAPI {
1009
1117
  addMockupBoard(params: AddMockupBoardParams, opts?: DesignApiOptions): NormalizedStandardBoard<MockupBoardOptions>;
1010
1118
  addMockupDesignObject(params: AddMockupDesignObjectParams, opts?: DesignApiOptions): NormalizedMockupDesignObject;
@@ -1024,6 +1132,17 @@ export interface ObjectAPI {
1024
1132
  id: string;
1025
1133
  };
1026
1134
  }
1135
+ export interface PaginatedResult<T> {
1136
+ items: T[];
1137
+ total?: number;
1138
+ hasMore: boolean;
1139
+ }
1140
+ export interface PaginationOptions {
1141
+ take?: number;
1142
+ skip?: number;
1143
+ sort?: string;
1144
+ cursor?: string;
1145
+ }
1027
1146
  export interface PhotoFilterOptions {
1028
1147
  [ImageFilterType.Saturation]: {
1029
1148
  saturation: number;
@@ -1093,16 +1212,6 @@ export interface RotateObjectParams {
1093
1212
  y: OriginY;
1094
1213
  };
1095
1214
  }
1096
- export interface SdkBadInputError extends Error {
1097
- name: "SdkBadInputError";
1098
- message: string;
1099
- cause?: Error;
1100
- }
1101
- export interface SdkInternalError extends Error {
1102
- name: "SdkInternalError";
1103
- message: string;
1104
- cause?: Error;
1105
- }
1106
1215
  export interface SetHiddenParams {
1107
1216
  id: string;
1108
1217
  hidden: boolean;
@@ -1183,6 +1292,15 @@ export interface TransformOptions {
1183
1292
  curve?: number;
1184
1293
  isChanging?: boolean;
1185
1294
  }
1295
+ export interface UpdateFontFamilyOptions {
1296
+ id: string;
1297
+ name: string;
1298
+ }
1299
+ export interface UpdateFontStyleOptions {
1300
+ fontFamilyId: string;
1301
+ id: string;
1302
+ style: string;
1303
+ }
1186
1304
  export interface UpdateGuideInput {
1187
1305
  id: string;
1188
1306
  top?: number;
@@ -1202,9 +1320,8 @@ export interface UploadAPI {
1202
1320
  image: UploadImageAPI;
1203
1321
  }
1204
1322
  export interface UploadImageAPI {
1205
- upload: ({ blob, extensionId, }: {
1323
+ upload: ({ blob, }: {
1206
1324
  blob: Blob;
1207
- extensionId?: string;
1208
1325
  }) => SdkResultAsync<UserImageUpload[], Error>;
1209
1326
  uploadTemp: ({ blob, }: {
1210
1327
  blob: Blob;
@@ -1251,7 +1368,7 @@ export interface WithObjectLayout {
1251
1368
  flipX: boolean;
1252
1369
  flipY: boolean;
1253
1370
  }
1254
- export type AIGenerationActionOrigin = "COPILOT" | "RIGHT_PANEL" | "LEFT_PANEL" | "MICRO_APP" | "IMAGE_SETS" | "AI_CHAT" | "SMARTBOARD" | "AI_INPUT_GENERATE_IMAGE" | "AI_INPUT_REMIX_IMAGE" | "AI_INPUT_GENERATE_VIDEO" | "AI_HUB_GENERATE_IMAGE" | "AI_HUB_REMIX_IMAGE" | "AI_HUB_GENERATE_VIDEO" | "VIDEOBOARD";
1371
+ export type AIGenerationActionOrigin = "COPILOT" | "RIGHT_PANEL" | "LEFT_PANEL" | "MICRO_APP" | "IMAGE_SETS" | "AI_CHAT" | "SMARTBOARD" | "AI_INPUT_GENERATE_IMAGE" | "AI_INPUT_REMIX_IMAGE" | "AI_INPUT_GENERATE_VIDEO" | "AI_HUB_GENERATE_IMAGE" | "AI_HUB_REMIX_IMAGE" | "AI_HUB_GENERATE_VIDEO" | "VIDEOBOARD" | "AGENT" | "WORKFLOW";
1255
1372
  export type AIGenerationContentType = "image" | "video";
1256
1373
  export type AIGenerationModelTaskType = "IMAGE_TO_IMAGE" | "IMAGE_INPAINT" | "TEXT_TO_IMAGE" | "IMAGE_TO_VIDEO";
1257
1374
  export type APIOptions<T extends Record<string, unknown>> = {
@@ -1267,6 +1384,8 @@ export type ActiveTool = {
1267
1384
  type: "artboard";
1268
1385
  } | {
1269
1386
  type: "move";
1387
+ } | {
1388
+ type: "hand";
1270
1389
  } | {
1271
1390
  type: "pen";
1272
1391
  } | {
@@ -1349,6 +1468,7 @@ export type AppState = {
1349
1468
  canvasMode: CanvasMode | string;
1350
1469
  activeTool: ActiveTool | null;
1351
1470
  viewport: Viewport;
1471
+ isDragPanning: boolean;
1352
1472
  highlightedObjectId: string | null;
1353
1473
  };
1354
1474
  /**
@@ -1409,6 +1529,7 @@ export type CombinedShapeSerializedObject = Omit<typeof DEFAULT_VALUES, "shapes"
1409
1529
  export type ConnectedArtboardOptions<T extends ArtboardLikeType = ArtboardLikeType> = BaseStandardArtboardOptions<T> & {
1410
1530
  inputBoardIds?: string[];
1411
1531
  };
1532
+ export type ContextSubscriptionCallback = (context: KittlContext) => void;
1412
1533
  export type ConvertShapeToMaskInput = {
1413
1534
  id: NormalizedBasicShapeObject["id"];
1414
1535
  };
@@ -1487,8 +1608,8 @@ export type Expand<T> = T extends infer O ? {
1487
1608
  } : never;
1488
1609
  export type FillMetaTarget = "border" | "fill";
1489
1610
  export type FlattenUnion<T> = UnionToIntersection<T extends unknown ? Partial<T> : never>;
1490
- export type FontVariationAxis = OrAnyString<"wght" | "wdth" | "slnt" | "ital" | "opsz" | "GRAD">;
1491
- export type FontVariationSettings = Partial<Record<FontVariationAxis, number>>;
1611
+ export type FontListDto = PaginatedResult<FontFamilyDto>;
1612
+ export type FontVariationSettings = Record<string, number> & Partial<Record<KnownFontVariationAxis, number>>;
1492
1613
  export type FontWeight = OrAnyString<"Regular" | "Bold" | "Light" | "Medium" | "Black" | "SemiBold" | "Italic" | "ExtraLight" | "Thin" | "ExtraBold" | "LightItalic" | "MediumItalic" | "SemiBoldItalic" | "BlackItalic" | "ExtraBoldItalic" | "ThinItalic" | "ExtraLightItalic" | "BoldItalic">;
1493
1614
  export type FullColor = {
1494
1615
  key: "fill" | (Exclude<string, StringColorKeysType> & {});
@@ -1496,6 +1617,7 @@ export type FullColor = {
1496
1617
  visible: boolean;
1497
1618
  };
1498
1619
  export type FunctionType = (...args: never) => unknown;
1620
+ export type GenerationOperation = (typeof GenerationOperation)[keyof typeof GenerationOperation];
1499
1621
  export type GenerationStatus = (typeof GenerationStatus)[keyof typeof GenerationStatus];
1500
1622
  export type GenerationStatusUpdate = {
1501
1623
  generationId: string;
@@ -1544,6 +1666,7 @@ export type IllustrationProperties = {
1544
1666
  strokeWidth?: IllustrationSerializedObject["strokeWidth"];
1545
1667
  fill?: IllustrationSerializedObject["fill"];
1546
1668
  gradients?: IllustrationSerializedObject["gradients"];
1669
+ generation?: IllustrationSerializedObject["generation"];
1547
1670
  };
1548
1671
  export type IllustrationSerializedObject = typeof ILLUSTRATION_DEFAULT_VALUES;
1549
1672
  export type ImageProperties = {
@@ -1563,6 +1686,7 @@ export type InternalPatchArgs<T> = {
1563
1686
  historyOrigin?: HistoryOrigins;
1564
1687
  transactionMeta?: TransactionMeta;
1565
1688
  };
1689
+ export type KnownFontVariationAxis = "wght" | "wdth" | "slnt" | "ital" | "opsz" | "GRAD";
1566
1690
  export type LayerIconType = "drawIcon";
1567
1691
  export type LayerType = Exclude<SerializableObjectType, ObjectType.Guide> | typeof structuralGroupType | typeof clippingMaskType | typeof backgroundType | typeof pathType;
1568
1692
  export type LayersMovePosition = "before" | "after" | "into";
@@ -1773,6 +1897,12 @@ export type RenameParams = {
1773
1897
  objectId: string;
1774
1898
  newName: string;
1775
1899
  };
1900
+ export type ResetImageBackgroundRemovalParams = {
1901
+ id: IllustrationImageSerializedObject["id"];
1902
+ };
1903
+ export type ResetImageCropParams = {
1904
+ id: IllustrationImageSerializedObject["id"];
1905
+ };
1776
1906
  export type ResultType = (typeof ResultType)[keyof typeof ResultType];
1777
1907
  export type RichTextBasePluginSerializedObject = {
1778
1908
  id: string;
@@ -1987,8 +2117,9 @@ export type TextProperties = {
1987
2117
  fontFamily?: string;
1988
2118
  fontSize?: number;
1989
2119
  fontWeight?: string;
2120
+ fontVariationSettings?: FontVariationSettings;
1990
2121
  fill?: Color;
1991
- textAlign?: "left" | "center" | "right" | "justify";
2122
+ textAlign?: TextAlign;
1992
2123
  lineHeightValue?: LineHeight;
1993
2124
  resizeBehavior?: "none" | "hug" | "hug-height";
1994
2125
  charSpacing?: number;
@@ -1998,7 +2129,7 @@ export type TextProperties = {
1998
2129
  angle?: number;
1999
2130
  scaleX?: number;
2000
2131
  scaleY?: number;
2001
- stroke?: string;
2132
+ stroke?: string | null;
2002
2133
  strokeWidth?: number;
2003
2134
  };
2004
2135
  export type TransactionMeta = {
@@ -2052,6 +2183,12 @@ export type UpdateImageParams = {
2052
2183
  stroke?: IllustrationImageSerializedObject["stroke"];
2053
2184
  strokeWidth?: IllustrationImageSerializedObject["strokeWidth"];
2054
2185
  } & GeneratableObject;
2186
+ export type UpdateImageSourceParams = {
2187
+ id: IllustrationImageSerializedObject["id"];
2188
+ objectName: IllustrationImageSerializedObject["objectName"];
2189
+ keepObjectDimensions?: boolean;
2190
+ flatten?: boolean;
2191
+ };
2055
2192
  export type UpdateMockupBoardParams = {
2056
2193
  mockupBoardId: string;
2057
2194
  size?: Dimensions;
@@ -2100,7 +2237,6 @@ export type UpdateVideoPlaylistItemParams = {
2100
2237
  videoId: string;
2101
2238
  playlistItemId: string;
2102
2239
  playlistItem: Omit<VideoPlaylistItem, "id">;
2103
- allowAspectRatioMismatch?: boolean;
2104
2240
  };
2105
2241
  export type UpdateVideoboardParams = {
2106
2242
  videoBoardId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kittl/sdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "license": "Apache-2.0",
5
5
  "private": false,
6
6
  "type": "module",