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