@kittl/sdk 0.0.9 → 1.0.0-alpha.2
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/dist/creativeAgentPanel/sdk.d.ts +8667 -0
- package/dist/{kittl-sdk.esm.js → creativeAgentPanel/sdk.esm.js} +199 -301
- package/dist/{kittl-sdk.js → creativeAgentPanel/sdk.js} +199 -301
- package/dist/dashboardStandalonePage/sdk.d.ts +8656 -0
- package/dist/dashboardStandalonePage/sdk.esm.js +1184 -0
- package/dist/dashboardStandalonePage/sdk.js +1184 -0
- package/dist/editorContentPanel/sdk.d.ts +6318 -103
- package/dist/editorContentPanel/sdk.esm.js +214 -30
- package/dist/editorContentPanel/sdk.js +214 -30
- package/dist/editorScriptRunner/sdk.d.ts +5732 -146
- package/dist/editorScriptRunner/sdk.esm.js +212 -30
- package/dist/editorScriptRunner/sdk.js +212 -30
- package/dist/sharedFileBrowser/sdk.d.ts +188 -2609
- package/dist/sharedFileBrowser/sdk.esm.js +200 -16
- package/dist/sharedFileBrowser/sdk.js +200 -16
- package/package.json +14 -7
- package/dist/sdk.d.ts +0 -2756
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
/*! Kittl SDK - https://kittl.com - see license for terms */
|
|
3
3
|
|
|
4
4
|
var FROM_EXTENSION_COMMANDS = {
|
|
5
|
+
/** Capability-owned AI callback registration. */
|
|
6
|
+
AI_GENERATOR_SUBSCRIBE: "ai-generator-subscribe",
|
|
7
|
+
/** Capability-owned AI callback teardown. */
|
|
8
|
+
AI_GENERATOR_UNSUBSCRIBE: "ai-generator-unsubscribe",
|
|
5
9
|
/** SDK API call */
|
|
6
10
|
SDK_CALL: "sdk-call",
|
|
7
11
|
/** AI handler registration */
|
|
@@ -50,6 +54,8 @@ var FROM_EXTENSION_COMMANDS = {
|
|
|
50
54
|
LOADED: "loaded"
|
|
51
55
|
};
|
|
52
56
|
var TO_EXTENSION_COMMANDS = {
|
|
57
|
+
/** Callback payload for generator or pending-set subscriptions. */
|
|
58
|
+
AI_GENERATOR_UPDATE: "ai-generator-update",
|
|
53
59
|
/** SDK API response */
|
|
54
60
|
SDK_RESPONSE: "sdk-response",
|
|
55
61
|
/** File browser fetch content request */
|
|
@@ -66,6 +72,10 @@ var TO_EXTENSION_COMMANDS = {
|
|
|
66
72
|
APP_STATE_UPDATE: "app-state-update"
|
|
67
73
|
};
|
|
68
74
|
|
|
75
|
+
function isAIGeneratorUpdateMessage(data) {
|
|
76
|
+
return !!data && typeof data === "object" && "command" in data && data.command === "ai-generator-update" && "subscriptionId" in data && typeof data.subscriptionId === "string";
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
var isSDKResponseMessage = (data) => {
|
|
70
80
|
return typeof data === "object" && data !== null && "command" in data && data.command === TO_EXTENSION_COMMANDS.SDK_RESPONSE && "messageId" in data && typeof data.messageId === "string";
|
|
71
81
|
};
|
|
@@ -135,7 +145,10 @@ var APPROVED_EXTENSION_COMMUNICATION_DOMAINS = [
|
|
|
135
145
|
"https://app.stagingdesigner.com",
|
|
136
146
|
"https://*.stagingdesigner.com",
|
|
137
147
|
"http://localhost:3000",
|
|
138
|
-
"https://app.kittl.com"
|
|
148
|
+
"https://app.kittl.com",
|
|
149
|
+
// website, for sandboxed standalone dashboard pages
|
|
150
|
+
"http://localhost:3003",
|
|
151
|
+
"https://www.kittl.com"
|
|
139
152
|
];
|
|
140
153
|
var toOrigin = (value) => {
|
|
141
154
|
if (!value) {
|
|
@@ -190,8 +203,15 @@ var getParentDomain = () => {
|
|
|
190
203
|
};
|
|
191
204
|
|
|
192
205
|
var pendingRequests = /* @__PURE__ */ new Map();
|
|
206
|
+
var sdkVersion;
|
|
207
|
+
function setSDKVersion(version2) {
|
|
208
|
+
sdkVersion = version2;
|
|
209
|
+
}
|
|
193
210
|
var postMessageToParent = (message) => {
|
|
194
|
-
window.parent.postMessage(
|
|
211
|
+
window.parent.postMessage(
|
|
212
|
+
sdkVersion === void 0 ? message : { ...message, sdkVersion },
|
|
213
|
+
getParentDomain()
|
|
214
|
+
);
|
|
195
215
|
};
|
|
196
216
|
var sendMessage = (message) => {
|
|
197
217
|
postMessageToParent(message);
|
|
@@ -214,6 +234,27 @@ var sendLoaded = () => {
|
|
|
214
234
|
};
|
|
215
235
|
|
|
216
236
|
var createSDKCallMessage = {
|
|
237
|
+
aiGenerator: (dots, args, messageId) => ({
|
|
238
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
239
|
+
dots,
|
|
240
|
+
args,
|
|
241
|
+
messageId,
|
|
242
|
+
apiType: "aiGenerator"
|
|
243
|
+
}),
|
|
244
|
+
mockup: (dots, args, messageId) => ({
|
|
245
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
246
|
+
dots,
|
|
247
|
+
args,
|
|
248
|
+
messageId,
|
|
249
|
+
apiType: "mockup"
|
|
250
|
+
}),
|
|
251
|
+
fileBrowser: (dots, args, messageId) => ({
|
|
252
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
253
|
+
dots,
|
|
254
|
+
args,
|
|
255
|
+
messageId,
|
|
256
|
+
apiType: "fileBrowser"
|
|
257
|
+
}),
|
|
217
258
|
ai: (dots, args, messageId) => ({
|
|
218
259
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
219
260
|
dots,
|
|
@@ -249,6 +290,13 @@ var createSDKCallMessage = {
|
|
|
249
290
|
messageId,
|
|
250
291
|
apiType: "font"
|
|
251
292
|
}),
|
|
293
|
+
project: (dots, args, messageId) => ({
|
|
294
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
295
|
+
dots,
|
|
296
|
+
args,
|
|
297
|
+
messageId,
|
|
298
|
+
apiType: "project"
|
|
299
|
+
}),
|
|
252
300
|
state: (dots, args, messageId) => ({
|
|
253
301
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
254
302
|
dots,
|
|
@@ -269,6 +317,34 @@ var createSDKCallMessage = {
|
|
|
269
317
|
args,
|
|
270
318
|
messageId,
|
|
271
319
|
apiType: "data"
|
|
320
|
+
}),
|
|
321
|
+
brandKit: (dots, args, messageId) => ({
|
|
322
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
323
|
+
dots,
|
|
324
|
+
args,
|
|
325
|
+
messageId,
|
|
326
|
+
apiType: "brandKit"
|
|
327
|
+
}),
|
|
328
|
+
openMicroEditor: (dots, args, messageId) => ({
|
|
329
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
330
|
+
dots,
|
|
331
|
+
args,
|
|
332
|
+
messageId,
|
|
333
|
+
apiType: "openMicroEditor"
|
|
334
|
+
}),
|
|
335
|
+
openMainEditor: (dots, args, messageId) => ({
|
|
336
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
337
|
+
dots,
|
|
338
|
+
args,
|
|
339
|
+
messageId,
|
|
340
|
+
apiType: "openMainEditor"
|
|
341
|
+
}),
|
|
342
|
+
agent: (dots, args, messageId) => ({
|
|
343
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
344
|
+
dots,
|
|
345
|
+
args,
|
|
346
|
+
messageId,
|
|
347
|
+
apiType: "agent"
|
|
272
348
|
})
|
|
273
349
|
};
|
|
274
350
|
function createApiProxy(apiType) {
|
|
@@ -285,6 +361,64 @@ function createApiProxy(apiType) {
|
|
|
285
361
|
});
|
|
286
362
|
}
|
|
287
363
|
|
|
364
|
+
function createAIGeneratorBridgeApi() {
|
|
365
|
+
const callbacks = /* @__PURE__ */ new Map();
|
|
366
|
+
const proxy = createApiProxy("aiGenerator");
|
|
367
|
+
async function subscribe(request, callback) {
|
|
368
|
+
const subscriptionId = generateMessageId();
|
|
369
|
+
callbacks.set(subscriptionId, callback);
|
|
370
|
+
let response;
|
|
371
|
+
try {
|
|
372
|
+
response = await sendMessage({
|
|
373
|
+
command: "ai-generator-subscribe",
|
|
374
|
+
...request,
|
|
375
|
+
subscriptionId,
|
|
376
|
+
messageId: generateMessageId()
|
|
377
|
+
});
|
|
378
|
+
} catch (error) {
|
|
379
|
+
callbacks.delete(subscriptionId);
|
|
380
|
+
throw error;
|
|
381
|
+
}
|
|
382
|
+
if (!response.isOk) {
|
|
383
|
+
callbacks.delete(subscriptionId);
|
|
384
|
+
throw new Error(response.error.message);
|
|
385
|
+
}
|
|
386
|
+
return () => {
|
|
387
|
+
callbacks.delete(subscriptionId);
|
|
388
|
+
postMessageToParent({
|
|
389
|
+
command: "ai-generator-unsubscribe",
|
|
390
|
+
subscriptionId
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
const methods = {
|
|
395
|
+
registerGenerator: (id, callback) => subscribe({ method: "registerGenerator", args: [id] }, (update) => {
|
|
396
|
+
if (update) callback(update);
|
|
397
|
+
}),
|
|
398
|
+
subscribeToGenerationUpdates: (ids, callback) => subscribe(
|
|
399
|
+
{ method: "subscribeToGenerationUpdates", args: [ids] },
|
|
400
|
+
(update) => {
|
|
401
|
+
if (update) callback(update);
|
|
402
|
+
}
|
|
403
|
+
),
|
|
404
|
+
subscribeToPendingGenerations: (callback) => subscribe(
|
|
405
|
+
{ method: "subscribeToPendingGenerations", args: [] },
|
|
406
|
+
() => callback()
|
|
407
|
+
),
|
|
408
|
+
/** Callers may reuse richer internal submission objects; never send their local abort callbacks. */
|
|
409
|
+
cancelGenerations: (submission) => proxy.cancelGenerations({
|
|
410
|
+
generationIds: submission.generationIds,
|
|
411
|
+
until: submission.until
|
|
412
|
+
})
|
|
413
|
+
};
|
|
414
|
+
return {
|
|
415
|
+
api: new Proxy(proxy, {
|
|
416
|
+
get: (target, property, receiver) => property in methods ? methods[property] : Reflect.get(target, property, receiver)
|
|
417
|
+
}),
|
|
418
|
+
dispatch: (message) => callbacks.get(message.subscriptionId)?.(message.update)
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
288
422
|
var generationHandlers = /* @__PURE__ */ new Map();
|
|
289
423
|
var generationSubscriptions = /* @__PURE__ */ new Map();
|
|
290
424
|
var dispatchAIGenerationUpdate = (subscriptionId, update) => {
|
|
@@ -652,7 +786,7 @@ var SandboxedAuthClient = class {
|
|
|
652
786
|
}
|
|
653
787
|
};
|
|
654
788
|
|
|
655
|
-
var
|
|
789
|
+
var createBatchFor = async (apiType) => {
|
|
656
790
|
const response = await sendMessage({
|
|
657
791
|
command: FROM_EXTENSION_COMMANDS.BATCH_CREATE,
|
|
658
792
|
messageId: generateMessageId()
|
|
@@ -661,14 +795,17 @@ var createBatch = async () => {
|
|
|
661
795
|
throw response.error;
|
|
662
796
|
}
|
|
663
797
|
const { batchKey } = response.result;
|
|
664
|
-
const sendDesignCall = (dots, args) =>
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
798
|
+
const sendDesignCall = (dots, args) => {
|
|
799
|
+
const message = {
|
|
800
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
801
|
+
dots: apiType === "project" ? ["design", "api", ...dots] : dots,
|
|
802
|
+
args,
|
|
803
|
+
messageId: generateMessageId(),
|
|
804
|
+
apiType,
|
|
805
|
+
batchKey
|
|
806
|
+
};
|
|
807
|
+
return sendMessage(message);
|
|
808
|
+
};
|
|
672
809
|
const commit = async () => {
|
|
673
810
|
const res = await sendMessage({
|
|
674
811
|
command: FROM_EXTENSION_COMMANDS.BATCH_COMMIT,
|
|
@@ -695,6 +832,8 @@ var createBatch = async () => {
|
|
|
695
832
|
};
|
|
696
833
|
return buildNode([]);
|
|
697
834
|
};
|
|
835
|
+
var createBatch = () => createBatchFor("design");
|
|
836
|
+
var createProjectBatch = () => createBatchFor("project");
|
|
698
837
|
|
|
699
838
|
var createContextBridgeApi = () => {
|
|
700
839
|
const contextProxy = createApiProxy("context");
|
|
@@ -862,6 +1001,7 @@ var designStateApi = createDesignStateBridgeApi();
|
|
|
862
1001
|
var appStateApi = createAppStateBridgeApi();
|
|
863
1002
|
var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
|
|
864
1003
|
var authClient = new SandboxedAuthClient();
|
|
1004
|
+
var aiGeneratorBridge = createAIGeneratorBridgeApi();
|
|
865
1005
|
var handleIncomingMessage = (event) => {
|
|
866
1006
|
const parent = window.parent;
|
|
867
1007
|
if (!parent || parent === window) {
|
|
@@ -884,6 +1024,10 @@ var handleIncomingMessage = (event) => {
|
|
|
884
1024
|
statelessApi.dispatch(data.type, data.payload);
|
|
885
1025
|
return;
|
|
886
1026
|
}
|
|
1027
|
+
if (isAIGeneratorUpdateMessage(data)) {
|
|
1028
|
+
aiGeneratorBridge.dispatch(data);
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
887
1031
|
if (isAIGenerationUpdatePushMessage(data)) {
|
|
888
1032
|
dispatchAIGenerationUpdate(data.subscriptionId, data.update);
|
|
889
1033
|
return;
|
|
@@ -908,7 +1052,29 @@ var handleIncomingMessage = (event) => {
|
|
|
908
1052
|
);
|
|
909
1053
|
}
|
|
910
1054
|
};
|
|
1055
|
+
var projectProxy = createApiProxy("project");
|
|
1056
|
+
var projectApi = {
|
|
1057
|
+
design: {
|
|
1058
|
+
state: {
|
|
1059
|
+
getState: projectProxy.design.state.getState,
|
|
1060
|
+
subscribe: designStateApi.subscribe
|
|
1061
|
+
},
|
|
1062
|
+
api: projectProxy.design.api,
|
|
1063
|
+
createBatch: createProjectBatch
|
|
1064
|
+
},
|
|
1065
|
+
app: {
|
|
1066
|
+
state: {
|
|
1067
|
+
getState: projectProxy.app.state.getState,
|
|
1068
|
+
subscribe: appStateApi.subscribe
|
|
1069
|
+
},
|
|
1070
|
+
api: projectProxy.app.api
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
911
1073
|
var bridgeHandlers = {
|
|
1074
|
+
agent: createApiProxy("agent"),
|
|
1075
|
+
aiGenerator: aiGeneratorBridge.api,
|
|
1076
|
+
brandKit: createApiProxy("brandKit"),
|
|
1077
|
+
mockup: createApiProxy("mockup"),
|
|
912
1078
|
ai: createAIApiProxy(),
|
|
913
1079
|
context: contextApi,
|
|
914
1080
|
data: createApiProxy("data"),
|
|
@@ -917,12 +1083,17 @@ var bridgeHandlers = {
|
|
|
917
1083
|
appStore: appStateApi,
|
|
918
1084
|
export: createApiProxy("export"),
|
|
919
1085
|
font: createApiProxy("font"),
|
|
1086
|
+
project: projectApi,
|
|
920
1087
|
state: createApiProxy("state"),
|
|
921
1088
|
upload: createApiProxy("upload"),
|
|
922
|
-
fileBrowser:
|
|
1089
|
+
fileBrowser: { getFiles: createApiProxy("fileBrowser").getFiles },
|
|
1090
|
+
fileBrowserRegistration: createFileBrowserApiProxy(),
|
|
1091
|
+
openMicroEditor: createApiProxy("openMicroEditor"),
|
|
1092
|
+
openMainEditor: createApiProxy("openMainEditor"),
|
|
923
1093
|
auth: authClient,
|
|
924
1094
|
stateless: statelessApi,
|
|
925
|
-
createBatch
|
|
1095
|
+
createBatch,
|
|
1096
|
+
createProjectBatch
|
|
926
1097
|
};
|
|
927
1098
|
|
|
928
1099
|
// src/api/utils.ts
|
|
@@ -933,291 +1104,8 @@ function unwrapResult(result) {
|
|
|
933
1104
|
throw result.error;
|
|
934
1105
|
}
|
|
935
1106
|
|
|
936
|
-
//
|
|
937
|
-
var
|
|
938
|
-
var DragAndDropApi = class {
|
|
939
|
-
/**
|
|
940
|
-
* Creates the drag-and-drop API from bridged SDK dependencies.
|
|
941
|
-
*/
|
|
942
|
-
constructor(dependencies) {
|
|
943
|
-
this.state = dependencies.state;
|
|
944
|
-
this.context = dependencies.context;
|
|
945
|
-
this.design = dependencies.design;
|
|
946
|
-
this.upload = dependencies.upload;
|
|
947
|
-
}
|
|
948
|
-
/**
|
|
949
|
-
* Handles the extension-side `dragstart` event and attaches a one-time
|
|
950
|
-
* `dragend` listener that completes the Kittl drop flow.
|
|
951
|
-
*/
|
|
952
|
-
startDragImageEvent(input) {
|
|
953
|
-
const metrics = this.captureDragMetrics(input);
|
|
954
|
-
this.applyNativeDragSetup(input.event.dataTransfer, input.img, metrics);
|
|
955
|
-
const handleDragEnd = (event) => {
|
|
956
|
-
void this.handleManagedDragEnd(metrics, event);
|
|
957
|
-
};
|
|
958
|
-
input.img.addEventListener("dragend", handleDragEnd, { once: true });
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* Inserts the dropped image at the computed drop position. When
|
|
962
|
-
* `input.persistImage === true`, fetches `src`, uploads it, and replaces
|
|
963
|
-
* the inserted object with the uploaded asset.
|
|
964
|
-
*/
|
|
965
|
-
async dropImage(input) {
|
|
966
|
-
let objectId = null;
|
|
967
|
-
try {
|
|
968
|
-
const offset = unwrapResult(await this.context.get()).dragAndDrop.offset;
|
|
969
|
-
const params = this.buildDropImageParams(input, offset);
|
|
970
|
-
objectId = await this.addDroppedImage(params);
|
|
971
|
-
if (input.persistImage) {
|
|
972
|
-
await this.persistDroppedImage({
|
|
973
|
-
objectId,
|
|
974
|
-
src: input.src
|
|
975
|
-
});
|
|
976
|
-
}
|
|
977
|
-
} catch {
|
|
978
|
-
}
|
|
979
|
-
return objectId;
|
|
980
|
-
}
|
|
981
|
-
/**
|
|
982
|
-
* Adds the dropped image to the design and returns the inserted object id.
|
|
983
|
-
*/
|
|
984
|
-
async addDroppedImage(params) {
|
|
985
|
-
const result = await this.design.image.addImage(params);
|
|
986
|
-
const insertedImage = unwrapResult(result);
|
|
987
|
-
if (!insertedImage?.id) {
|
|
988
|
-
throw new Error("Failed to add dropped image");
|
|
989
|
-
}
|
|
990
|
-
return insertedImage.id;
|
|
991
|
-
}
|
|
992
|
-
/**
|
|
993
|
-
* Fetches `src`, uploads the bytes, and replaces the inserted object with
|
|
994
|
-
* the uploaded Kittl asset when persistence succeeds.
|
|
995
|
-
*/
|
|
996
|
-
async persistDroppedImage(input) {
|
|
997
|
-
const response = await fetch(input.src);
|
|
998
|
-
if (!response.ok) {
|
|
999
|
-
throw new Error(`Failed to fetch dropped image: ${response.status}`);
|
|
1000
|
-
}
|
|
1001
|
-
const blob = await response.blob();
|
|
1002
|
-
const uploadResult = await this.upload.image.upload({ blob });
|
|
1003
|
-
const uploadedFiles = unwrapResult(uploadResult);
|
|
1004
|
-
if (uploadedFiles.length === 0) {
|
|
1005
|
-
throw new Error("Failed to upload dropped image");
|
|
1006
|
-
}
|
|
1007
|
-
await this.replaceWithUploadedImage({
|
|
1008
|
-
objectId: input.objectId,
|
|
1009
|
-
objectName: uploadedFiles[0].objectName
|
|
1010
|
-
});
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Replaces the inserted image with the uploaded asset if the object still
|
|
1014
|
-
* exists.
|
|
1015
|
-
*/
|
|
1016
|
-
async replaceWithUploadedImage(input) {
|
|
1017
|
-
const objectResult = await this.design.object.getObject({
|
|
1018
|
-
id: input.objectId
|
|
1019
|
-
});
|
|
1020
|
-
if (!objectResult.isOk) {
|
|
1021
|
-
return;
|
|
1022
|
-
}
|
|
1023
|
-
await this.design.image.updateImage({
|
|
1024
|
-
id: input.objectId,
|
|
1025
|
-
objectName: input.objectName
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
|
-
/**
|
|
1029
|
-
* Converts iframe drag coordinates into `addImage(...)` params, applying host
|
|
1030
|
-
* offsets, grab offsets, and optional rendered size.
|
|
1031
|
-
*/
|
|
1032
|
-
buildDropImageParams(input, offset) {
|
|
1033
|
-
const grabOffsetX = input.grabOffsetX ?? 0;
|
|
1034
|
-
const grabOffsetY = input.grabOffsetY ?? 0;
|
|
1035
|
-
const baseX = input.x + offset.left;
|
|
1036
|
-
const baseY = input.y + offset.top;
|
|
1037
|
-
const dropX = Math.floor(baseX - grabOffsetX);
|
|
1038
|
-
const dropY = Math.floor(baseY - grabOffsetY);
|
|
1039
|
-
const baseParams = {
|
|
1040
|
-
src: input.src.trim(),
|
|
1041
|
-
position: {
|
|
1042
|
-
relative: {
|
|
1043
|
-
to: "screen",
|
|
1044
|
-
coordinates: {
|
|
1045
|
-
x: dropX,
|
|
1046
|
-
y: dropY
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
};
|
|
1051
|
-
const { imgWidth, imgHeight } = input;
|
|
1052
|
-
if (typeof imgWidth !== "number" || typeof imgHeight !== "number") {
|
|
1053
|
-
return baseParams;
|
|
1054
|
-
}
|
|
1055
|
-
return {
|
|
1056
|
-
...baseParams,
|
|
1057
|
-
size: {
|
|
1058
|
-
width: imgWidth,
|
|
1059
|
-
height: imgHeight,
|
|
1060
|
-
applyViewportScale: true
|
|
1061
|
-
}
|
|
1062
|
-
};
|
|
1063
|
-
}
|
|
1064
|
-
/**
|
|
1065
|
-
* Captures the rendered image size and pointer grab point at drag start so
|
|
1066
|
-
* the native drag preview and drop placement stay aligned.
|
|
1067
|
-
*/
|
|
1068
|
-
captureDragMetrics(input) {
|
|
1069
|
-
const rect = input.img.getBoundingClientRect();
|
|
1070
|
-
const displayWidth = Math.floor(rect.width);
|
|
1071
|
-
const displayHeight = Math.floor(rect.height);
|
|
1072
|
-
const grabOffsetX = this.getGrabOffset(
|
|
1073
|
-
input.event.clientX - rect.left,
|
|
1074
|
-
displayWidth
|
|
1075
|
-
);
|
|
1076
|
-
const grabOffsetY = this.getGrabOffset(
|
|
1077
|
-
input.event.clientY - rect.top,
|
|
1078
|
-
displayHeight
|
|
1079
|
-
);
|
|
1080
|
-
return {
|
|
1081
|
-
displayWidth,
|
|
1082
|
-
displayHeight,
|
|
1083
|
-
grabOffsetX,
|
|
1084
|
-
grabOffsetY,
|
|
1085
|
-
src: input.img.src,
|
|
1086
|
-
persistImage: input.persistImage === true
|
|
1087
|
-
};
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* Clamps a raw pointer offset into the rendered image bounds.
|
|
1091
|
-
*/
|
|
1092
|
-
getGrabOffset(rawOffset, displaySize) {
|
|
1093
|
-
return this.clampFloor(rawOffset, 0, displaySize);
|
|
1094
|
-
}
|
|
1095
|
-
/**
|
|
1096
|
-
* Floors a number and clamps it into the provided inclusive range.
|
|
1097
|
-
*/
|
|
1098
|
-
clampFloor(value, min, max) {
|
|
1099
|
-
return Math.min(Math.max(Math.floor(value), min), max);
|
|
1100
|
-
}
|
|
1101
|
-
/**
|
|
1102
|
-
* Configures the browser drag payload and drag preview image for the current
|
|
1103
|
-
* drag operation.
|
|
1104
|
-
*/
|
|
1105
|
-
applyNativeDragSetup(dataTransfer, img, metrics) {
|
|
1106
|
-
if (!dataTransfer) {
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1109
|
-
const { displayWidth, displayHeight, grabOffsetX, grabOffsetY, src } = metrics;
|
|
1110
|
-
dataTransfer.setData("text/plain", src);
|
|
1111
|
-
dataTransfer.effectAllowed = "copy";
|
|
1112
|
-
const previewCanvas = this.getOrCreateDragPreviewCanvas();
|
|
1113
|
-
if (previewCanvas.canvas && previewCanvas.context) {
|
|
1114
|
-
previewCanvas.canvas.width = displayWidth;
|
|
1115
|
-
previewCanvas.canvas.height = displayHeight;
|
|
1116
|
-
previewCanvas.canvas.style.width = `${displayWidth}px`;
|
|
1117
|
-
previewCanvas.canvas.style.height = `${displayHeight}px`;
|
|
1118
|
-
previewCanvas.context.clearRect(0, 0, displayWidth, displayHeight);
|
|
1119
|
-
previewCanvas.context.drawImage(img, 0, 0, displayWidth, displayHeight);
|
|
1120
|
-
dataTransfer.setDragImage(previewCanvas.canvas, grabOffsetX, grabOffsetY);
|
|
1121
|
-
return;
|
|
1122
|
-
}
|
|
1123
|
-
dataTransfer.setDragImage(img, grabOffsetX, grabOffsetY);
|
|
1124
|
-
}
|
|
1125
|
-
/**
|
|
1126
|
-
* Creates and reuses the hidden canvas used as the native drag preview.
|
|
1127
|
-
* Reuse one canvas as a native drag image so we can control preview size exactly.
|
|
1128
|
-
* Browsers may auto-scale element drag ghosts, which shifts perceived cursor alignment.
|
|
1129
|
-
* Must be in the DOM - Chrome ignores setDragImage on detached elements and falls back
|
|
1130
|
-
* to a scaled ghost. Position it off-screen so it's invisible.
|
|
1131
|
-
*/
|
|
1132
|
-
getOrCreateDragPreviewCanvas() {
|
|
1133
|
-
if (typeof document === "undefined" || !document.body) {
|
|
1134
|
-
return {
|
|
1135
|
-
canvas: null,
|
|
1136
|
-
context: null
|
|
1137
|
-
};
|
|
1138
|
-
}
|
|
1139
|
-
if (!this.dragPreviewCanvas) {
|
|
1140
|
-
this.dragPreviewCanvas = document.createElement("canvas");
|
|
1141
|
-
this.dragPreviewCanvas.style.position = "fixed";
|
|
1142
|
-
this.dragPreviewCanvas.style.left = HIDDEN_DRAG_PREVIEW_OFFSET_PX;
|
|
1143
|
-
this.dragPreviewCanvas.style.top = HIDDEN_DRAG_PREVIEW_OFFSET_PX;
|
|
1144
|
-
this.dragPreviewCanvas.style.pointerEvents = "none";
|
|
1145
|
-
}
|
|
1146
|
-
if (!this.dragPreviewCanvas.isConnected) {
|
|
1147
|
-
document.body.appendChild(this.dragPreviewCanvas);
|
|
1148
|
-
}
|
|
1149
|
-
if (this.dragPreviewCtx === void 0) {
|
|
1150
|
-
this.dragPreviewCtx = this.dragPreviewCanvas.getContext("2d");
|
|
1151
|
-
}
|
|
1152
|
-
return {
|
|
1153
|
-
canvas: this.dragPreviewCanvas,
|
|
1154
|
-
context: this.dragPreviewCtx ?? null
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
|
-
/**
|
|
1158
|
-
* Completes the managed drag on `dragend` by ignoring cancelled/internal
|
|
1159
|
-
* drops, forwarding valid drops to `dropImage(...)`, and selecting the inserted
|
|
1160
|
-
* object when available.
|
|
1161
|
-
*/
|
|
1162
|
-
async handleManagedDragEnd(metrics, event) {
|
|
1163
|
-
const dropInput = {
|
|
1164
|
-
x: event.clientX,
|
|
1165
|
-
y: event.clientY,
|
|
1166
|
-
src: metrics.src,
|
|
1167
|
-
imgWidth: metrics.displayWidth,
|
|
1168
|
-
imgHeight: metrics.displayHeight,
|
|
1169
|
-
grabOffsetX: metrics.grabOffsetX,
|
|
1170
|
-
grabOffsetY: metrics.grabOffsetY,
|
|
1171
|
-
persistImage: metrics.persistImage
|
|
1172
|
-
};
|
|
1173
|
-
try {
|
|
1174
|
-
if (event.clientX === 0 && event.clientY === 0) {
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
|
-
if (this.isInsideIframeViewport(event.clientX, event.clientY)) {
|
|
1178
|
-
return;
|
|
1179
|
-
}
|
|
1180
|
-
const objectId = await this.dropImage(dropInput);
|
|
1181
|
-
if (!objectId) {
|
|
1182
|
-
return;
|
|
1183
|
-
}
|
|
1184
|
-
await this.state.setSelectedObjectsIds([objectId]);
|
|
1185
|
-
} catch {
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
/**
|
|
1189
|
-
* Returns true when the final pointer position is still inside the iframe
|
|
1190
|
-
* viewport.
|
|
1191
|
-
*/
|
|
1192
|
-
isInsideIframeViewport(x, y) {
|
|
1193
|
-
return x >= 0 && y >= 0 && x <= window.innerWidth && y <= window.innerHeight;
|
|
1194
|
-
}
|
|
1195
|
-
};
|
|
1196
|
-
|
|
1197
|
-
// src/createEditorSDKAPIs.ts
|
|
1198
|
-
function createEditorSDKAPIs() {
|
|
1199
|
-
return {
|
|
1200
|
-
ai: bridgeHandlers.ai,
|
|
1201
|
-
data: bridgeHandlers.data,
|
|
1202
|
-
design: bridgeHandlers.design,
|
|
1203
|
-
export: bridgeHandlers.export,
|
|
1204
|
-
designStore: bridgeHandlers.designStore,
|
|
1205
|
-
appStore: bridgeHandlers.appStore,
|
|
1206
|
-
context: bridgeHandlers.context,
|
|
1207
|
-
dragAndDrop: new DragAndDropApi({
|
|
1208
|
-
state: bridgeHandlers.state,
|
|
1209
|
-
context: bridgeHandlers.context,
|
|
1210
|
-
design: bridgeHandlers.design,
|
|
1211
|
-
upload: bridgeHandlers.upload
|
|
1212
|
-
}),
|
|
1213
|
-
state: bridgeHandlers.state,
|
|
1214
|
-
auth: bridgeHandlers.auth,
|
|
1215
|
-
upload: bridgeHandlers.upload,
|
|
1216
|
-
stateless: bridgeHandlers.stateless,
|
|
1217
|
-
font: bridgeHandlers.font,
|
|
1218
|
-
createBatch: bridgeHandlers.createBatch
|
|
1219
|
-
};
|
|
1220
|
-
}
|
|
1107
|
+
// package.json
|
|
1108
|
+
var version = "1.0.0";
|
|
1221
1109
|
|
|
1222
1110
|
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
1223
1111
|
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
@@ -1259,12 +1147,17 @@ function createKittlSDK(apis) {
|
|
|
1259
1147
|
handleIncomingMessage(event);
|
|
1260
1148
|
}
|
|
1261
1149
|
);
|
|
1262
|
-
|
|
1150
|
+
const { context } = apis;
|
|
1151
|
+
const themeSynced = context?.get && context.subscribe ? syncHtmlDataThemeFromHostContext({
|
|
1152
|
+
context
|
|
1153
|
+
}) : Promise.resolve();
|
|
1154
|
+
void themeSynced.catch(() => void 0).then(() => {
|
|
1263
1155
|
kittl2.onLoadedCallback?.();
|
|
1264
1156
|
sendLoaded();
|
|
1265
1157
|
});
|
|
1266
1158
|
};
|
|
1267
1159
|
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
1160
|
+
setSDKVersion(version);
|
|
1268
1161
|
window.kittl = kittl2;
|
|
1269
1162
|
if (document.readyState === "loading") {
|
|
1270
1163
|
document.addEventListener("DOMContentLoaded", initSdk);
|
|
@@ -1275,9 +1168,14 @@ function createKittlSDK(apis) {
|
|
|
1275
1168
|
return kittl2;
|
|
1276
1169
|
}
|
|
1277
1170
|
|
|
1278
|
-
// src/
|
|
1171
|
+
// src/creativeAgentPanel.ts
|
|
1279
1172
|
var kittl = createKittlSDK({
|
|
1280
|
-
|
|
1173
|
+
auth: bridgeHandlers.auth,
|
|
1174
|
+
context: bridgeHandlers.context,
|
|
1175
|
+
agent: bridgeHandlers.agent,
|
|
1176
|
+
upload: bridgeHandlers.upload,
|
|
1177
|
+
brandKit: bridgeHandlers.brandKit,
|
|
1178
|
+
openMicroEditor: bridgeHandlers.openMicroEditor,
|
|
1281
1179
|
fileBrowser: bridgeHandlers.fileBrowser
|
|
1282
1180
|
});
|
|
1283
1181
|
export {
|