@kittl/sdk 0.0.2 → 0.0.4
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/kittl-sdk.esm.js +274 -4
- package/dist/kittl-sdk.js +274 -4
- package/dist/sdk.d.ts +238 -12
- package/package.json +5 -2
package/dist/kittl-sdk.esm.js
CHANGED
|
@@ -12,6 +12,15 @@ var isStatelessPushMessage = (data) => {
|
|
|
12
12
|
var isAIGenerationUpdatePushMessage = (data) => {
|
|
13
13
|
return typeof data === "object" && data !== null && "command" in data && data.command === "ai-generation-update" && "subscriptionId" in data && typeof data.subscriptionId === "string" && "update" in data && typeof data.update === "object" && data.update !== null;
|
|
14
14
|
};
|
|
15
|
+
var isDesignStateUpdatePushMessage = (data) => {
|
|
16
|
+
return typeof data === "object" && data !== null && "command" in data && data.command === "design-state-update" && "updates" in data && Array.isArray(data.updates);
|
|
17
|
+
};
|
|
18
|
+
var isAppStateUpdatePushMessage = (data) => {
|
|
19
|
+
return typeof data === "object" && data !== null && "command" in data && data.command === "app-state-update" && "updates" in data && Array.isArray(data.updates);
|
|
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
|
+
};
|
|
15
24
|
|
|
16
25
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/shared/createApiProxyCore.js
|
|
17
26
|
var buildMethodPath = (rootPrefix, pathSegments) => {
|
|
@@ -278,6 +287,71 @@ function createAIApiProxy() {
|
|
|
278
287
|
};
|
|
279
288
|
}
|
|
280
289
|
|
|
290
|
+
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/appState/index.js
|
|
291
|
+
var sendUnsubscribe = (selectorIds) => {
|
|
292
|
+
const message = {
|
|
293
|
+
command: "app-state-unsubscribe",
|
|
294
|
+
selectorIds
|
|
295
|
+
};
|
|
296
|
+
postMessageToParent(message);
|
|
297
|
+
};
|
|
298
|
+
var createAppStateBridgeApi = () => {
|
|
299
|
+
const localSubscriptions = /* @__PURE__ */ new Map();
|
|
300
|
+
async function subscribe(paths, callback) {
|
|
301
|
+
if (paths.length === 0) {
|
|
302
|
+
return () => {
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const values = new Array(paths.length).fill(void 0);
|
|
306
|
+
const selectorIds = [];
|
|
307
|
+
const pathArrays = [];
|
|
308
|
+
for (const dotPath of paths) {
|
|
309
|
+
const segments = dotPath.split(".");
|
|
310
|
+
if (segments.some((s) => s === "")) {
|
|
311
|
+
throw new Error(
|
|
312
|
+
`Invalid app state path: '${dotPath}'. Path must be a non-empty dot-separated string.`
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
selectorIds.push(generateMessageId());
|
|
316
|
+
pathArrays.push(segments);
|
|
317
|
+
}
|
|
318
|
+
const messageId = generateMessageId();
|
|
319
|
+
const subscribeMessage = {
|
|
320
|
+
command: "app-state-subscribe",
|
|
321
|
+
messageId,
|
|
322
|
+
selectorIds,
|
|
323
|
+
paths: pathArrays
|
|
324
|
+
};
|
|
325
|
+
const response = await sendMessage(subscribeMessage);
|
|
326
|
+
if (!response.isOk) {
|
|
327
|
+
throw new Error(`app-state-subscribe failed: ${response.error.message}`);
|
|
328
|
+
}
|
|
329
|
+
for (let i = 0; i < selectorIds.length; i++) {
|
|
330
|
+
localSubscriptions.set(selectorIds[i], {
|
|
331
|
+
callback: (value) => {
|
|
332
|
+
values[i] = value;
|
|
333
|
+
callback(...values);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
return () => {
|
|
338
|
+
for (const selectorId of selectorIds) {
|
|
339
|
+
localSubscriptions.delete(selectorId);
|
|
340
|
+
}
|
|
341
|
+
sendUnsubscribe(selectorIds);
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
const dispatch = (updates) => {
|
|
345
|
+
for (const { selectorId, value } of updates) {
|
|
346
|
+
const entry = localSubscriptions.get(selectorId);
|
|
347
|
+
if (entry) {
|
|
348
|
+
entry.callback(value);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
return { subscribe, dispatch };
|
|
353
|
+
};
|
|
354
|
+
|
|
281
355
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/authBridge/index.js
|
|
282
356
|
var hashPKCECode = async (input) => {
|
|
283
357
|
const textAsBuffer = new TextEncoder().encode(input);
|
|
@@ -370,6 +444,165 @@ var createAuthBridgeApi = () => {
|
|
|
370
444
|
};
|
|
371
445
|
};
|
|
372
446
|
|
|
447
|
+
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/batch/index.js
|
|
448
|
+
var createBatch = async () => {
|
|
449
|
+
const response = await sendMessage({
|
|
450
|
+
command: "batch-create",
|
|
451
|
+
messageId: generateMessageId()
|
|
452
|
+
});
|
|
453
|
+
if (!response.isOk) {
|
|
454
|
+
throw response.error;
|
|
455
|
+
}
|
|
456
|
+
const { batchKey } = response.result;
|
|
457
|
+
const sendDesignCall = (dots, args) => sendMessage({
|
|
458
|
+
command: "sdk-call",
|
|
459
|
+
dots,
|
|
460
|
+
args,
|
|
461
|
+
messageId: generateMessageId(),
|
|
462
|
+
apiType: "design",
|
|
463
|
+
batchKey
|
|
464
|
+
});
|
|
465
|
+
const commit = async () => {
|
|
466
|
+
const res = await sendMessage({
|
|
467
|
+
command: "batch-commit",
|
|
468
|
+
messageId: generateMessageId(),
|
|
469
|
+
batchKey
|
|
470
|
+
});
|
|
471
|
+
if (!res.isOk) {
|
|
472
|
+
throw res.error;
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
const buildNode = (pathSegments) => {
|
|
476
|
+
const target = () => {
|
|
477
|
+
};
|
|
478
|
+
return new Proxy(target, {
|
|
479
|
+
get: (_t, prop) => {
|
|
480
|
+
if (typeof prop === "symbol" || prop === "then") return void 0;
|
|
481
|
+
if (prop === "commit") return commit;
|
|
482
|
+
return buildNode([...pathSegments, prop]);
|
|
483
|
+
},
|
|
484
|
+
apply: (_t, _this, args) => {
|
|
485
|
+
return sendDesignCall(pathSegments, args);
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
};
|
|
489
|
+
return buildNode([]);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/context/contextBridge.js
|
|
493
|
+
var createContextBridgeApi = () => {
|
|
494
|
+
const contextProxy = createApiProxy("context");
|
|
495
|
+
const subscriptionCallbacks = /* @__PURE__ */ new Map();
|
|
496
|
+
const dispatch = (message) => {
|
|
497
|
+
const cb = subscriptionCallbacks.get(message.subscriptionId);
|
|
498
|
+
cb?.(message.context);
|
|
499
|
+
};
|
|
500
|
+
const subscribeImpl = async (callback) => {
|
|
501
|
+
const subscriptionId = generateMessageId();
|
|
502
|
+
const messageId = generateMessageId();
|
|
503
|
+
subscriptionCallbacks.set(subscriptionId, callback);
|
|
504
|
+
let response;
|
|
505
|
+
try {
|
|
506
|
+
response = await sendMessage({
|
|
507
|
+
command: "context-subscribe",
|
|
508
|
+
messageId,
|
|
509
|
+
subscriptionId
|
|
510
|
+
});
|
|
511
|
+
} catch (error) {
|
|
512
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
513
|
+
throw error;
|
|
514
|
+
}
|
|
515
|
+
if (!response.isOk) {
|
|
516
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
517
|
+
throw new Error(`context-subscribe failed: ${response.error.message}`);
|
|
518
|
+
}
|
|
519
|
+
return () => {
|
|
520
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
521
|
+
const message = {
|
|
522
|
+
command: "context-unsubscribe",
|
|
523
|
+
subscriptionId
|
|
524
|
+
};
|
|
525
|
+
postMessageToParent(message);
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
const api = new Proxy(contextProxy, {
|
|
529
|
+
get(target, prop, receiver) {
|
|
530
|
+
if (prop === "subscribe") {
|
|
531
|
+
return subscribeImpl;
|
|
532
|
+
}
|
|
533
|
+
return Reflect.get(target, prop, receiver);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
return { api, dispatch };
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/designState/index.js
|
|
540
|
+
var sendUnsubscribe2 = (selectorIds) => {
|
|
541
|
+
const message = {
|
|
542
|
+
command: "design-state-unsubscribe",
|
|
543
|
+
selectorIds
|
|
544
|
+
};
|
|
545
|
+
postMessageToParent(message);
|
|
546
|
+
};
|
|
547
|
+
var createDesignStateBridgeApi = () => {
|
|
548
|
+
const localSubscriptions = /* @__PURE__ */ new Map();
|
|
549
|
+
async function subscribe(paths, callback) {
|
|
550
|
+
if (paths.length === 0) {
|
|
551
|
+
return () => {
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
const values = new Array(paths.length).fill(void 0);
|
|
555
|
+
const selectorIds = [];
|
|
556
|
+
const pathArrays = [];
|
|
557
|
+
for (const dotPath of paths) {
|
|
558
|
+
const segments = dotPath.split(".");
|
|
559
|
+
if (segments.some((s) => s === "")) {
|
|
560
|
+
throw new Error(
|
|
561
|
+
`Invalid design state path: '${dotPath}'. Path must be a non-empty dot-separated string.`
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
selectorIds.push(generateMessageId());
|
|
565
|
+
pathArrays.push(segments);
|
|
566
|
+
}
|
|
567
|
+
const messageId = generateMessageId();
|
|
568
|
+
const subscribeMessage = {
|
|
569
|
+
command: "design-state-subscribe",
|
|
570
|
+
messageId,
|
|
571
|
+
selectorIds,
|
|
572
|
+
paths: pathArrays
|
|
573
|
+
};
|
|
574
|
+
const response = await sendMessage(subscribeMessage);
|
|
575
|
+
if (!response.isOk) {
|
|
576
|
+
throw new Error(
|
|
577
|
+
`design-state-subscribe failed: ${response.error.message}`
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
for (let i = 0; i < selectorIds.length; i++) {
|
|
581
|
+
localSubscriptions.set(selectorIds[i], {
|
|
582
|
+
callback: (value) => {
|
|
583
|
+
values[i] = value;
|
|
584
|
+
callback(...values);
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
return () => {
|
|
589
|
+
for (const selectorId of selectorIds) {
|
|
590
|
+
localSubscriptions.delete(selectorId);
|
|
591
|
+
}
|
|
592
|
+
sendUnsubscribe2(selectorIds);
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
const dispatch = (updates) => {
|
|
596
|
+
for (const { selectorId, value } of updates) {
|
|
597
|
+
const entry = localSubscriptions.get(selectorId);
|
|
598
|
+
if (entry) {
|
|
599
|
+
entry.callback(value);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
return { subscribe, dispatch };
|
|
604
|
+
};
|
|
605
|
+
|
|
373
606
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/stateless/index.js
|
|
374
607
|
var createStatelessBridgeApi = () => {
|
|
375
608
|
const subscribers = /* @__PURE__ */ new Map();
|
|
@@ -422,6 +655,9 @@ var createStatelessBridgeApi = () => {
|
|
|
422
655
|
|
|
423
656
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers.js
|
|
424
657
|
var statelessApi = createStatelessBridgeApi();
|
|
658
|
+
var designStateApi = createDesignStateBridgeApi();
|
|
659
|
+
var appStateApi = createAppStateBridgeApi();
|
|
660
|
+
var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
|
|
425
661
|
var handleIncomingMessage = (event) => {
|
|
426
662
|
const parent = window.parent;
|
|
427
663
|
if (!parent || parent === window) {
|
|
@@ -448,16 +684,30 @@ var handleIncomingMessage = (event) => {
|
|
|
448
684
|
dispatchAIGenerationUpdate(data.subscriptionId, data.update);
|
|
449
685
|
return;
|
|
450
686
|
}
|
|
687
|
+
if (isDesignStateUpdatePushMessage(data)) {
|
|
688
|
+
designStateApi.dispatch(data.updates);
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
if (isAppStateUpdatePushMessage(data)) {
|
|
692
|
+
appStateApi.dispatch(data.updates);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
if (isContextUpdatePushMessage(data)) {
|
|
696
|
+
dispatchContextUpdate(data);
|
|
697
|
+
}
|
|
451
698
|
};
|
|
452
699
|
var bridgeHandlers = {
|
|
453
700
|
ai: createAIApiProxy(),
|
|
454
|
-
context:
|
|
701
|
+
context: contextApi,
|
|
455
702
|
design: createApiProxy("design"),
|
|
703
|
+
designStore: designStateApi,
|
|
704
|
+
appStore: appStateApi,
|
|
456
705
|
font: createApiProxy("font"),
|
|
457
706
|
state: createApiProxy("state"),
|
|
458
707
|
upload: createApiProxy("upload"),
|
|
459
708
|
auth: createAuthBridgeApi(),
|
|
460
|
-
stateless: statelessApi
|
|
709
|
+
stateless: statelessApi,
|
|
710
|
+
createBatch
|
|
461
711
|
};
|
|
462
712
|
|
|
463
713
|
// src/api/utils.ts
|
|
@@ -729,6 +979,24 @@ var DragAndDropApi = class {
|
|
|
729
979
|
}
|
|
730
980
|
};
|
|
731
981
|
|
|
982
|
+
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
983
|
+
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
984
|
+
if (typeof document === "undefined") {
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
const parent = window.parent;
|
|
988
|
+
if (!parent || parent === window) {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
const contextResponse = await kittl2.context.get();
|
|
992
|
+
if (contextResponse.isOk) {
|
|
993
|
+
document.documentElement.dataset.theme = contextResponse.result.colorScheme;
|
|
994
|
+
}
|
|
995
|
+
await kittl2.context.subscribe((ctx) => {
|
|
996
|
+
document.documentElement.dataset.theme = ctx.colorScheme;
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
|
|
732
1000
|
// src/index.ts
|
|
733
1001
|
var kittl = {
|
|
734
1002
|
onLoadedCallback: null,
|
|
@@ -756,8 +1024,10 @@ var initSdk = () => {
|
|
|
756
1024
|
handleIncomingMessage(event);
|
|
757
1025
|
}
|
|
758
1026
|
);
|
|
759
|
-
kittl.
|
|
760
|
-
|
|
1027
|
+
void syncHtmlDataThemeFromHostContext(kittl).then(() => {
|
|
1028
|
+
kittl.onLoadedCallback?.();
|
|
1029
|
+
sendLoaded();
|
|
1030
|
+
});
|
|
761
1031
|
};
|
|
762
1032
|
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
763
1033
|
window.kittl = kittl;
|
package/dist/kittl-sdk.js
CHANGED
|
@@ -13,6 +13,15 @@
|
|
|
13
13
|
var isAIGenerationUpdatePushMessage = (data) => {
|
|
14
14
|
return typeof data === "object" && data !== null && "command" in data && data.command === "ai-generation-update" && "subscriptionId" in data && typeof data.subscriptionId === "string" && "update" in data && typeof data.update === "object" && data.update !== null;
|
|
15
15
|
};
|
|
16
|
+
var isDesignStateUpdatePushMessage = (data) => {
|
|
17
|
+
return typeof data === "object" && data !== null && "command" in data && data.command === "design-state-update" && "updates" in data && Array.isArray(data.updates);
|
|
18
|
+
};
|
|
19
|
+
var isAppStateUpdatePushMessage = (data) => {
|
|
20
|
+
return typeof data === "object" && data !== null && "command" in data && data.command === "app-state-update" && "updates" in data && Array.isArray(data.updates);
|
|
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
|
+
};
|
|
16
25
|
|
|
17
26
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/shared/createApiProxyCore.js
|
|
18
27
|
var buildMethodPath = (rootPrefix, pathSegments) => {
|
|
@@ -279,6 +288,71 @@
|
|
|
279
288
|
};
|
|
280
289
|
}
|
|
281
290
|
|
|
291
|
+
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/appState/index.js
|
|
292
|
+
var sendUnsubscribe = (selectorIds) => {
|
|
293
|
+
const message = {
|
|
294
|
+
command: "app-state-unsubscribe",
|
|
295
|
+
selectorIds
|
|
296
|
+
};
|
|
297
|
+
postMessageToParent(message);
|
|
298
|
+
};
|
|
299
|
+
var createAppStateBridgeApi = () => {
|
|
300
|
+
const localSubscriptions = /* @__PURE__ */ new Map();
|
|
301
|
+
async function subscribe(paths, callback) {
|
|
302
|
+
if (paths.length === 0) {
|
|
303
|
+
return () => {
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
const values = new Array(paths.length).fill(void 0);
|
|
307
|
+
const selectorIds = [];
|
|
308
|
+
const pathArrays = [];
|
|
309
|
+
for (const dotPath of paths) {
|
|
310
|
+
const segments = dotPath.split(".");
|
|
311
|
+
if (segments.some((s) => s === "")) {
|
|
312
|
+
throw new Error(
|
|
313
|
+
`Invalid app state path: '${dotPath}'. Path must be a non-empty dot-separated string.`
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
selectorIds.push(generateMessageId());
|
|
317
|
+
pathArrays.push(segments);
|
|
318
|
+
}
|
|
319
|
+
const messageId = generateMessageId();
|
|
320
|
+
const subscribeMessage = {
|
|
321
|
+
command: "app-state-subscribe",
|
|
322
|
+
messageId,
|
|
323
|
+
selectorIds,
|
|
324
|
+
paths: pathArrays
|
|
325
|
+
};
|
|
326
|
+
const response = await sendMessage(subscribeMessage);
|
|
327
|
+
if (!response.isOk) {
|
|
328
|
+
throw new Error(`app-state-subscribe failed: ${response.error.message}`);
|
|
329
|
+
}
|
|
330
|
+
for (let i = 0; i < selectorIds.length; i++) {
|
|
331
|
+
localSubscriptions.set(selectorIds[i], {
|
|
332
|
+
callback: (value) => {
|
|
333
|
+
values[i] = value;
|
|
334
|
+
callback(...values);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
return () => {
|
|
339
|
+
for (const selectorId of selectorIds) {
|
|
340
|
+
localSubscriptions.delete(selectorId);
|
|
341
|
+
}
|
|
342
|
+
sendUnsubscribe(selectorIds);
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
const dispatch = (updates) => {
|
|
346
|
+
for (const { selectorId, value } of updates) {
|
|
347
|
+
const entry = localSubscriptions.get(selectorId);
|
|
348
|
+
if (entry) {
|
|
349
|
+
entry.callback(value);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
return { subscribe, dispatch };
|
|
354
|
+
};
|
|
355
|
+
|
|
282
356
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/authBridge/index.js
|
|
283
357
|
var hashPKCECode = async (input) => {
|
|
284
358
|
const textAsBuffer = new TextEncoder().encode(input);
|
|
@@ -371,6 +445,165 @@
|
|
|
371
445
|
};
|
|
372
446
|
};
|
|
373
447
|
|
|
448
|
+
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/batch/index.js
|
|
449
|
+
var createBatch = async () => {
|
|
450
|
+
const response = await sendMessage({
|
|
451
|
+
command: "batch-create",
|
|
452
|
+
messageId: generateMessageId()
|
|
453
|
+
});
|
|
454
|
+
if (!response.isOk) {
|
|
455
|
+
throw response.error;
|
|
456
|
+
}
|
|
457
|
+
const { batchKey } = response.result;
|
|
458
|
+
const sendDesignCall = (dots, args) => sendMessage({
|
|
459
|
+
command: "sdk-call",
|
|
460
|
+
dots,
|
|
461
|
+
args,
|
|
462
|
+
messageId: generateMessageId(),
|
|
463
|
+
apiType: "design",
|
|
464
|
+
batchKey
|
|
465
|
+
});
|
|
466
|
+
const commit = async () => {
|
|
467
|
+
const res = await sendMessage({
|
|
468
|
+
command: "batch-commit",
|
|
469
|
+
messageId: generateMessageId(),
|
|
470
|
+
batchKey
|
|
471
|
+
});
|
|
472
|
+
if (!res.isOk) {
|
|
473
|
+
throw res.error;
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
const buildNode = (pathSegments) => {
|
|
477
|
+
const target = () => {
|
|
478
|
+
};
|
|
479
|
+
return new Proxy(target, {
|
|
480
|
+
get: (_t, prop) => {
|
|
481
|
+
if (typeof prop === "symbol" || prop === "then") return void 0;
|
|
482
|
+
if (prop === "commit") return commit;
|
|
483
|
+
return buildNode([...pathSegments, prop]);
|
|
484
|
+
},
|
|
485
|
+
apply: (_t, _this, args) => {
|
|
486
|
+
return sendDesignCall(pathSegments, args);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
};
|
|
490
|
+
return buildNode([]);
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/context/contextBridge.js
|
|
494
|
+
var createContextBridgeApi = () => {
|
|
495
|
+
const contextProxy = createApiProxy("context");
|
|
496
|
+
const subscriptionCallbacks = /* @__PURE__ */ new Map();
|
|
497
|
+
const dispatch = (message) => {
|
|
498
|
+
const cb = subscriptionCallbacks.get(message.subscriptionId);
|
|
499
|
+
cb?.(message.context);
|
|
500
|
+
};
|
|
501
|
+
const subscribeImpl = async (callback) => {
|
|
502
|
+
const subscriptionId = generateMessageId();
|
|
503
|
+
const messageId = generateMessageId();
|
|
504
|
+
subscriptionCallbacks.set(subscriptionId, callback);
|
|
505
|
+
let response;
|
|
506
|
+
try {
|
|
507
|
+
response = await sendMessage({
|
|
508
|
+
command: "context-subscribe",
|
|
509
|
+
messageId,
|
|
510
|
+
subscriptionId
|
|
511
|
+
});
|
|
512
|
+
} catch (error) {
|
|
513
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
514
|
+
throw error;
|
|
515
|
+
}
|
|
516
|
+
if (!response.isOk) {
|
|
517
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
518
|
+
throw new Error(`context-subscribe failed: ${response.error.message}`);
|
|
519
|
+
}
|
|
520
|
+
return () => {
|
|
521
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
522
|
+
const message = {
|
|
523
|
+
command: "context-unsubscribe",
|
|
524
|
+
subscriptionId
|
|
525
|
+
};
|
|
526
|
+
postMessageToParent(message);
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
const api = new Proxy(contextProxy, {
|
|
530
|
+
get(target, prop, receiver) {
|
|
531
|
+
if (prop === "subscribe") {
|
|
532
|
+
return subscribeImpl;
|
|
533
|
+
}
|
|
534
|
+
return Reflect.get(target, prop, receiver);
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
return { api, dispatch };
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/designState/index.js
|
|
541
|
+
var sendUnsubscribe2 = (selectorIds) => {
|
|
542
|
+
const message = {
|
|
543
|
+
command: "design-state-unsubscribe",
|
|
544
|
+
selectorIds
|
|
545
|
+
};
|
|
546
|
+
postMessageToParent(message);
|
|
547
|
+
};
|
|
548
|
+
var createDesignStateBridgeApi = () => {
|
|
549
|
+
const localSubscriptions = /* @__PURE__ */ new Map();
|
|
550
|
+
async function subscribe(paths, callback) {
|
|
551
|
+
if (paths.length === 0) {
|
|
552
|
+
return () => {
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
const values = new Array(paths.length).fill(void 0);
|
|
556
|
+
const selectorIds = [];
|
|
557
|
+
const pathArrays = [];
|
|
558
|
+
for (const dotPath of paths) {
|
|
559
|
+
const segments = dotPath.split(".");
|
|
560
|
+
if (segments.some((s) => s === "")) {
|
|
561
|
+
throw new Error(
|
|
562
|
+
`Invalid design state path: '${dotPath}'. Path must be a non-empty dot-separated string.`
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
selectorIds.push(generateMessageId());
|
|
566
|
+
pathArrays.push(segments);
|
|
567
|
+
}
|
|
568
|
+
const messageId = generateMessageId();
|
|
569
|
+
const subscribeMessage = {
|
|
570
|
+
command: "design-state-subscribe",
|
|
571
|
+
messageId,
|
|
572
|
+
selectorIds,
|
|
573
|
+
paths: pathArrays
|
|
574
|
+
};
|
|
575
|
+
const response = await sendMessage(subscribeMessage);
|
|
576
|
+
if (!response.isOk) {
|
|
577
|
+
throw new Error(
|
|
578
|
+
`design-state-subscribe failed: ${response.error.message}`
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
for (let i = 0; i < selectorIds.length; i++) {
|
|
582
|
+
localSubscriptions.set(selectorIds[i], {
|
|
583
|
+
callback: (value) => {
|
|
584
|
+
values[i] = value;
|
|
585
|
+
callback(...values);
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
return () => {
|
|
590
|
+
for (const selectorId of selectorIds) {
|
|
591
|
+
localSubscriptions.delete(selectorId);
|
|
592
|
+
}
|
|
593
|
+
sendUnsubscribe2(selectorIds);
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
const dispatch = (updates) => {
|
|
597
|
+
for (const { selectorId, value } of updates) {
|
|
598
|
+
const entry = localSubscriptions.get(selectorId);
|
|
599
|
+
if (entry) {
|
|
600
|
+
entry.callback(value);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
return { subscribe, dispatch };
|
|
605
|
+
};
|
|
606
|
+
|
|
374
607
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/stateless/index.js
|
|
375
608
|
var createStatelessBridgeApi = () => {
|
|
376
609
|
const subscribers = /* @__PURE__ */ new Map();
|
|
@@ -423,6 +656,9 @@
|
|
|
423
656
|
|
|
424
657
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers.js
|
|
425
658
|
var statelessApi = createStatelessBridgeApi();
|
|
659
|
+
var designStateApi = createDesignStateBridgeApi();
|
|
660
|
+
var appStateApi = createAppStateBridgeApi();
|
|
661
|
+
var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
|
|
426
662
|
var handleIncomingMessage = (event) => {
|
|
427
663
|
const parent = window.parent;
|
|
428
664
|
if (!parent || parent === window) {
|
|
@@ -449,16 +685,30 @@
|
|
|
449
685
|
dispatchAIGenerationUpdate(data.subscriptionId, data.update);
|
|
450
686
|
return;
|
|
451
687
|
}
|
|
688
|
+
if (isDesignStateUpdatePushMessage(data)) {
|
|
689
|
+
designStateApi.dispatch(data.updates);
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (isAppStateUpdatePushMessage(data)) {
|
|
693
|
+
appStateApi.dispatch(data.updates);
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
if (isContextUpdatePushMessage(data)) {
|
|
697
|
+
dispatchContextUpdate(data);
|
|
698
|
+
}
|
|
452
699
|
};
|
|
453
700
|
var bridgeHandlers = {
|
|
454
701
|
ai: createAIApiProxy(),
|
|
455
|
-
context:
|
|
702
|
+
context: contextApi,
|
|
456
703
|
design: createApiProxy("design"),
|
|
704
|
+
designStore: designStateApi,
|
|
705
|
+
appStore: appStateApi,
|
|
457
706
|
font: createApiProxy("font"),
|
|
458
707
|
state: createApiProxy("state"),
|
|
459
708
|
upload: createApiProxy("upload"),
|
|
460
709
|
auth: createAuthBridgeApi(),
|
|
461
|
-
stateless: statelessApi
|
|
710
|
+
stateless: statelessApi,
|
|
711
|
+
createBatch
|
|
462
712
|
};
|
|
463
713
|
|
|
464
714
|
// src/api/utils.ts
|
|
@@ -730,6 +980,24 @@
|
|
|
730
980
|
}
|
|
731
981
|
};
|
|
732
982
|
|
|
983
|
+
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
984
|
+
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
985
|
+
if (typeof document === "undefined") {
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
const parent = window.parent;
|
|
989
|
+
if (!parent || parent === window) {
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
const contextResponse = await kittl2.context.get();
|
|
993
|
+
if (contextResponse.isOk) {
|
|
994
|
+
document.documentElement.dataset.theme = contextResponse.result.colorScheme;
|
|
995
|
+
}
|
|
996
|
+
await kittl2.context.subscribe((ctx) => {
|
|
997
|
+
document.documentElement.dataset.theme = ctx.colorScheme;
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
|
|
733
1001
|
// src/index.ts
|
|
734
1002
|
var kittl = {
|
|
735
1003
|
onLoadedCallback: null,
|
|
@@ -757,8 +1025,10 @@
|
|
|
757
1025
|
handleIncomingMessage(event);
|
|
758
1026
|
}
|
|
759
1027
|
);
|
|
760
|
-
kittl.
|
|
761
|
-
|
|
1028
|
+
void syncHtmlDataThemeFromHostContext(kittl).then(() => {
|
|
1029
|
+
kittl.onLoadedCallback?.();
|
|
1030
|
+
sendLoaded();
|
|
1031
|
+
});
|
|
762
1032
|
};
|
|
763
1033
|
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
764
1034
|
window.kittl = kittl;
|
package/dist/sdk.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ declare const BASIC_SHAPE_DEFAULT_VALUES: {
|
|
|
51
51
|
locked?: boolean | undefined;
|
|
52
52
|
hidden?: boolean | undefined;
|
|
53
53
|
opacity?: number | undefined;
|
|
54
|
-
stroke?: string;
|
|
54
|
+
stroke?: string | null;
|
|
55
55
|
strokeWidth?: number;
|
|
56
56
|
fill?: ColorInfo[] | undefined;
|
|
57
57
|
scalingCorners?: boolean | undefined;
|
|
@@ -68,7 +68,7 @@ declare const BasicShapeType: {
|
|
|
68
68
|
};
|
|
69
69
|
declare const DEFAULT_VALUES$1: {
|
|
70
70
|
globalCompositeOperation: BlendMode;
|
|
71
|
-
stroke?: string;
|
|
71
|
+
stroke?: string | null;
|
|
72
72
|
strokeWidth?: number;
|
|
73
73
|
shadowOptions?: {
|
|
74
74
|
color?: string | undefined | null;
|
|
@@ -123,7 +123,7 @@ declare const DEFAULT_VALUES$2: {
|
|
|
123
123
|
offset?: number;
|
|
124
124
|
angle?: number;
|
|
125
125
|
};
|
|
126
|
-
stroke?: string;
|
|
126
|
+
stroke?: string | null;
|
|
127
127
|
strokeWidth?: number;
|
|
128
128
|
opacity?: number | undefined;
|
|
129
129
|
width: number;
|
|
@@ -166,7 +166,7 @@ declare const DEFAULT_VALUES: {
|
|
|
166
166
|
presets?: LinkedPreset[] | undefined;
|
|
167
167
|
opacity?: number | undefined;
|
|
168
168
|
hiddenColors?: Record<string, NonNullable<Color>> | undefined;
|
|
169
|
-
stroke?: string;
|
|
169
|
+
stroke?: string | null;
|
|
170
170
|
strokeWidth?: number;
|
|
171
171
|
fill?: ColorInfo[] | undefined;
|
|
172
172
|
locked?: boolean | undefined;
|
|
@@ -226,7 +226,7 @@ declare const ILLUSTRATION_DEFAULT_VALUES: {
|
|
|
226
226
|
gradients?: StateGradientInfo | undefined;
|
|
227
227
|
presets?: LinkedPreset[] | undefined;
|
|
228
228
|
opacity?: number | undefined;
|
|
229
|
-
stroke?: string;
|
|
229
|
+
stroke?: string | null;
|
|
230
230
|
strokeWidth?: number;
|
|
231
231
|
fill?: ColorInfo[] | undefined;
|
|
232
232
|
inLoadingStage?: boolean | undefined;
|
|
@@ -332,10 +332,9 @@ declare const PATH_TEXT_DEFAULT_VALUES: {
|
|
|
332
332
|
type: ObjectType.PathText;
|
|
333
333
|
};
|
|
334
334
|
declare const RICH_TEXT_DEFAULT_VALUES: {
|
|
335
|
-
activeTransformPlugin?: object | undefined;
|
|
336
335
|
presets?: LinkedPreset[] | undefined;
|
|
337
336
|
opacity?: number | undefined;
|
|
338
|
-
stroke?: string;
|
|
337
|
+
stroke?: string | null;
|
|
339
338
|
strokeWidth?: number;
|
|
340
339
|
fill?: Color | undefined;
|
|
341
340
|
locked?: boolean | undefined;
|
|
@@ -514,7 +513,8 @@ declare enum Origin {
|
|
|
514
513
|
CANVAS = 2,
|
|
515
514
|
UI = 4,
|
|
516
515
|
VOLATILE = 8,
|
|
517
|
-
EVENTS_SYNC = 16
|
|
516
|
+
EVENTS_SYNC = 16,
|
|
517
|
+
API = 32
|
|
518
518
|
}
|
|
519
519
|
declare enum TextAlignment {
|
|
520
520
|
right = "right",
|
|
@@ -542,6 +542,7 @@ export interface AIGenerationInputSettings {
|
|
|
542
542
|
id: string;
|
|
543
543
|
};
|
|
544
544
|
additionalParams?: Record<string, unknown>;
|
|
545
|
+
actionOrigin?: AIGenerationActionOrigin;
|
|
545
546
|
type: AIGenerationContentType;
|
|
546
547
|
}
|
|
547
548
|
export interface AIGenerationOutputSettings {
|
|
@@ -566,6 +567,7 @@ export interface AppStateAPI {
|
|
|
566
567
|
setCanvasMode(mode: AppState["canvasMode"], origin?: Origin): void;
|
|
567
568
|
getActiveTool(): ActiveTool | null;
|
|
568
569
|
setActiveTool(tool: ActiveTool | null): void;
|
|
570
|
+
getIsDragPanning(): boolean;
|
|
569
571
|
viewport: ViewportAPI;
|
|
570
572
|
getHighlightedObjectId(): string | null;
|
|
571
573
|
setHighlightedObjectId(id: string | null): void;
|
|
@@ -578,6 +580,34 @@ export interface AsyncAIAPI {
|
|
|
578
580
|
}
|
|
579
581
|
export interface AsyncAppStateAPI extends WithAsync<AppStateAPI> {
|
|
580
582
|
}
|
|
583
|
+
export interface AsyncAppStateSubscriptionAPI {
|
|
584
|
+
/**
|
|
585
|
+
* Subscribe to one or more paths in the app state.
|
|
586
|
+
* Each path is a dot-separated string like `'selectedObjectsIds'`.
|
|
587
|
+
* The callback receives the current value at each path as positional
|
|
588
|
+
* arguments whenever any subscribed value changes.
|
|
589
|
+
* Returns a single unsubscribe function that tears down all subscriptions.
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* // Single path
|
|
593
|
+
* const unsub = await kittl.appStore.subscribe(
|
|
594
|
+
* ['selectedObjectsIds'],
|
|
595
|
+
* (ids) => console.log('selection changed:', ids)
|
|
596
|
+
* );
|
|
597
|
+
*
|
|
598
|
+
* // Multiple paths
|
|
599
|
+
* const unsub = await kittl.appStore.subscribe(
|
|
600
|
+
* ['selectedObjectsIds', 'activeTool'],
|
|
601
|
+
* (ids, tool) => console.log('changed:', ids, tool)
|
|
602
|
+
* );
|
|
603
|
+
* unsub();
|
|
604
|
+
*/
|
|
605
|
+
subscribe<T extends readonly AppStateSelectorPath[]>(paths: [
|
|
606
|
+
...T
|
|
607
|
+
], callback: (...values: {
|
|
608
|
+
[K in keyof T]: T[K] extends string ? DeepValue<AppState, T[K]> | undefined : unknown;
|
|
609
|
+
}) => void): Promise<() => void>;
|
|
610
|
+
}
|
|
581
611
|
export interface AsyncAuthAPI {
|
|
582
612
|
startAuth: (request: AuthStartRequest) => Promise<SdkResult<AuthStartResult>>;
|
|
583
613
|
exchangeCode: (request: AuthExchangeRequest) => Promise<SdkResult<AuthTokenResponse>>;
|
|
@@ -585,10 +615,42 @@ export interface AsyncAuthAPI {
|
|
|
585
615
|
refreshToken: (request: AuthRefreshRequest) => Promise<SdkResult<AuthTokenResponse>>;
|
|
586
616
|
logout: (request: AuthLogoutRequest) => Promise<SdkResult<void>>;
|
|
587
617
|
}
|
|
588
|
-
export interface
|
|
618
|
+
export interface AsyncBatchDesignAPI extends AsyncDesignAPI {
|
|
619
|
+
commit: () => Promise<void>;
|
|
620
|
+
}
|
|
621
|
+
export interface AsyncContextAPI extends Omit<WithAsync<ContextAPI>, "subscribe"> {
|
|
622
|
+
subscribe(callback: ContextSubscriptionCallback): Promise<() => void>;
|
|
589
623
|
}
|
|
590
624
|
export interface AsyncDesignAPI extends WithAsync<WithOptsRemoved<DesignAPI>> {
|
|
591
625
|
}
|
|
626
|
+
export interface AsyncDesignStateAPI {
|
|
627
|
+
/**
|
|
628
|
+
* Subscribe to one or more paths in the design state.
|
|
629
|
+
* Each path is a dot-separated string like `'objects.id1.width'`.
|
|
630
|
+
* The callback receives the current value at each path as positional
|
|
631
|
+
* arguments whenever any subscribed value changes.
|
|
632
|
+
* Returns a single unsubscribe function that tears down all subscriptions.
|
|
633
|
+
*
|
|
634
|
+
* @example
|
|
635
|
+
* // Single path
|
|
636
|
+
* const unsub = await kittl.designStore.subscribe(
|
|
637
|
+
* ['objects.id1.width'],
|
|
638
|
+
* (width) => console.log('width changed:', width)
|
|
639
|
+
* );
|
|
640
|
+
*
|
|
641
|
+
* // Multiple paths
|
|
642
|
+
* const unsub = await kittl.designStore.subscribe(
|
|
643
|
+
* ['objects.id1.width', 'objects.id1.height'],
|
|
644
|
+
* (width, height) => console.log('changed:', width, height)
|
|
645
|
+
* );
|
|
646
|
+
* unsub();
|
|
647
|
+
*/
|
|
648
|
+
subscribe<T extends readonly DesignStateSelectorPath[]>(paths: [
|
|
649
|
+
...T
|
|
650
|
+
], callback: (...values: {
|
|
651
|
+
[K in keyof T]: T[K] extends string ? DeepValue<SelectorState, T[K]> | undefined : unknown;
|
|
652
|
+
}) => void): Promise<() => void>;
|
|
653
|
+
}
|
|
592
654
|
export interface AsyncFontAPI extends WithAsync<FontAPI> {
|
|
593
655
|
}
|
|
594
656
|
export interface AsyncStatelessAPI {
|
|
@@ -702,6 +764,7 @@ export interface ConfigAPI {
|
|
|
702
764
|
}
|
|
703
765
|
export interface ContextAPI {
|
|
704
766
|
get(input?: ContextGetInput): KittlContext;
|
|
767
|
+
subscribe(callback: ContextSubscriptionCallback): () => void;
|
|
705
768
|
}
|
|
706
769
|
export interface ContextGetInput {
|
|
707
770
|
iframe?: Pick<HTMLIFrameElement, "getBoundingClientRect">;
|
|
@@ -837,6 +900,7 @@ export interface GetExportOptions {
|
|
|
837
900
|
height: number;
|
|
838
901
|
};
|
|
839
902
|
};
|
|
903
|
+
removeArtboardBackground?: boolean;
|
|
840
904
|
}
|
|
841
905
|
export interface GetObjectParams {
|
|
842
906
|
id: string;
|
|
@@ -906,6 +970,7 @@ export interface ImageGenerationStartedResult extends GenerationStartedResultCom
|
|
|
906
970
|
type: typeof ResultType.IMAGE;
|
|
907
971
|
}
|
|
908
972
|
export interface KittlContext {
|
|
973
|
+
colorScheme: EditorColorScheme;
|
|
909
974
|
dragAndDrop: {
|
|
910
975
|
offset: DragAndDropOffset;
|
|
911
976
|
};
|
|
@@ -916,6 +981,8 @@ export interface KittlSDK {
|
|
|
916
981
|
onReady: (cb: () => void) => void;
|
|
917
982
|
ai: AsyncAIAPI;
|
|
918
983
|
design: AsyncDesignAPI;
|
|
984
|
+
designStore: AsyncDesignStateAPI;
|
|
985
|
+
appStore: AsyncAppStateSubscriptionAPI;
|
|
919
986
|
context: AsyncContextAPI;
|
|
920
987
|
dragAndDrop: PublicDragAndDropAPI;
|
|
921
988
|
state: AsyncAppStateAPI;
|
|
@@ -923,6 +990,7 @@ export interface KittlSDK {
|
|
|
923
990
|
upload: AsyncUploadAPI;
|
|
924
991
|
stateless: AsyncStatelessAPI;
|
|
925
992
|
font: AsyncFontAPI;
|
|
993
|
+
createBatch: () => Promise<AsyncBatchDesignAPI>;
|
|
926
994
|
}
|
|
927
995
|
export interface LayersAPI {
|
|
928
996
|
moveTo(input: MoveToParams, opts?: DesignApiOptions): void;
|
|
@@ -1002,6 +1070,24 @@ export interface RemoveObjectParams {
|
|
|
1002
1070
|
export interface RemoveObjectResult {
|
|
1003
1071
|
removedObject: NormalizedObject;
|
|
1004
1072
|
}
|
|
1073
|
+
export interface RichTextCompressedStylesV1 {
|
|
1074
|
+
version: "v1";
|
|
1075
|
+
[lineIndex: LineIndex]: {
|
|
1076
|
+
charsAt: CharacterIndex[];
|
|
1077
|
+
styles: Partial<RichTextSerializedCharacterStyle>;
|
|
1078
|
+
}[];
|
|
1079
|
+
}
|
|
1080
|
+
export interface RichTextCompressedStylesV2 {
|
|
1081
|
+
version: "v2";
|
|
1082
|
+
customStyles: Record<string, Partial<RichTextSerializedCharacterStyle>>;
|
|
1083
|
+
[lineIndex: LineIndex]: {
|
|
1084
|
+
charsAt: [
|
|
1085
|
+
CharacterIndex,
|
|
1086
|
+
SequenceLength
|
|
1087
|
+
][];
|
|
1088
|
+
styleId: string;
|
|
1089
|
+
}[];
|
|
1090
|
+
}
|
|
1005
1091
|
export interface RotateObjectParams {
|
|
1006
1092
|
id: string;
|
|
1007
1093
|
angle: number;
|
|
@@ -1168,6 +1254,7 @@ export interface WithObjectLayout {
|
|
|
1168
1254
|
flipX: boolean;
|
|
1169
1255
|
flipY: boolean;
|
|
1170
1256
|
}
|
|
1257
|
+
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";
|
|
1171
1258
|
export type AIGenerationContentType = "image" | "video";
|
|
1172
1259
|
export type AIGenerationModelTaskType = "IMAGE_TO_IMAGE" | "IMAGE_INPAINT" | "TEXT_TO_IMAGE" | "IMAGE_TO_VIDEO";
|
|
1173
1260
|
export type APIOptions<T extends Record<string, unknown>> = {
|
|
@@ -1183,6 +1270,8 @@ export type ActiveTool = {
|
|
|
1183
1270
|
type: "artboard";
|
|
1184
1271
|
} | {
|
|
1185
1272
|
type: "move";
|
|
1273
|
+
} | {
|
|
1274
|
+
type: "hand";
|
|
1186
1275
|
} | {
|
|
1187
1276
|
type: "pen";
|
|
1188
1277
|
} | {
|
|
@@ -1265,8 +1354,23 @@ export type AppState = {
|
|
|
1265
1354
|
canvasMode: CanvasMode | string;
|
|
1266
1355
|
activeTool: ActiveTool | null;
|
|
1267
1356
|
viewport: Viewport;
|
|
1357
|
+
isDragPanning: boolean;
|
|
1268
1358
|
highlightedObjectId: string | null;
|
|
1269
1359
|
};
|
|
1360
|
+
/**
|
|
1361
|
+
* A dot-separated string path into the app state.
|
|
1362
|
+
* The first segment must be a valid top-level key of AppState.
|
|
1363
|
+
*
|
|
1364
|
+
* @example
|
|
1365
|
+
* 'selectedObjectsIds'
|
|
1366
|
+
* 'viewport.coords.tl.x'
|
|
1367
|
+
* 'activeTool.type'
|
|
1368
|
+
*/
|
|
1369
|
+
export type AppStateSelectorPath = AppStateTopLevelKey | `${AppStateTopLevelKey}.${string}`;
|
|
1370
|
+
/**
|
|
1371
|
+
* Top-level keys of AppState that extensions can subscribe to.
|
|
1372
|
+
*/
|
|
1373
|
+
export type AppStateTopLevelKey = keyof AppState;
|
|
1270
1374
|
export type ArtboardLikeType = ObjectType.Artboard | ObjectType.MockupBoard | ObjectType.Smartboard | ObjectType.Videoboard;
|
|
1271
1375
|
export type ArtboardOptions = StandardArtboardOptions | SmartboardOptions | MockupBoardOptions | VideoboardOptions;
|
|
1272
1376
|
export type AvailableShadowOptions = Partial<Pick<ShadowOptions, "blur">> & Omit<ShadowOptions, "blur">;
|
|
@@ -1298,6 +1402,7 @@ export type BasicShapeType = (typeof BasicShapeType)[keyof typeof BasicShapeType
|
|
|
1298
1402
|
export type BridgedSdkResult<T> = T extends SdkResult<infer _R, infer _E> ? T : SdkResult<T, Error>;
|
|
1299
1403
|
export type Builtin = Date | Function | Uint8Array | RegExp | Map<unknown, unknown> | Set<unknown>;
|
|
1300
1404
|
export type CanvasMode = "erase" | "crop" | "reframe" | "inpaint" | null;
|
|
1405
|
+
export type CharacterIndex = number;
|
|
1301
1406
|
export type CloneArtboardParams = {
|
|
1302
1407
|
boardId: string;
|
|
1303
1408
|
position: CreateElementWithPositionAndSize["position"];
|
|
@@ -1310,6 +1415,7 @@ export type CombinedShapeSerializedObject = Omit<typeof DEFAULT_VALUES, "shapes"
|
|
|
1310
1415
|
export type ConnectedArtboardOptions<T extends ArtboardLikeType = ArtboardLikeType> = BaseStandardArtboardOptions<T> & {
|
|
1311
1416
|
inputBoardIds?: string[];
|
|
1312
1417
|
};
|
|
1418
|
+
export type ContextSubscriptionCallback = (context: KittlContext) => void;
|
|
1313
1419
|
export type ConvertShapeToMaskInput = {
|
|
1314
1420
|
id: NormalizedBasicShapeObject["id"];
|
|
1315
1421
|
};
|
|
@@ -1344,8 +1450,34 @@ export type CreateShapeInput = CreateElementWithPositionAndSize & {
|
|
|
1344
1450
|
export type DeepPartial<T> = {
|
|
1345
1451
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
1346
1452
|
};
|
|
1453
|
+
/**
|
|
1454
|
+
* Resolves a dot-separated string path against a type `T`.
|
|
1455
|
+
*
|
|
1456
|
+
* For `Record<string, V>` intermediaries (e.g. `objects`), any string
|
|
1457
|
+
* key is accepted and the type continues into `V`.
|
|
1458
|
+
*
|
|
1459
|
+
* @example
|
|
1460
|
+
* DeepValue<SelectorState, 'objects.id1.width'> // number | undefined
|
|
1461
|
+
* DeepValue<SelectorState, 'config'> // DesignConfig
|
|
1462
|
+
* DeepValue<AppState, 'viewport.coords.tl.x'> // number
|
|
1463
|
+
*/
|
|
1464
|
+
export type DeepValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? DeepValue<NonNullable<T[K]>, Rest> : T extends Record<string, infer V> ? DeepValue<NonNullable<V>, Rest> : undefined : P extends keyof T ? T[P] : T extends Record<string, infer V> ? V : undefined;
|
|
1347
1465
|
export type DesignApiOptions = APIOptions<NormalizedDesignState>;
|
|
1348
1466
|
export type DesignObjectId = string;
|
|
1467
|
+
/**
|
|
1468
|
+
* A dot-separated string path into the design state.
|
|
1469
|
+
* The first segment must be a valid top-level key of NormalizedDesignState.
|
|
1470
|
+
*
|
|
1471
|
+
* @example
|
|
1472
|
+
* 'objects.id1.width'
|
|
1473
|
+
* 'config.title'
|
|
1474
|
+
* 'boards.board1.backgroundColor'
|
|
1475
|
+
*/
|
|
1476
|
+
export type DesignStateSelectorPath = DesignStateTopLevelKey | `${DesignStateTopLevelKey}.${string}`;
|
|
1477
|
+
/**
|
|
1478
|
+
* Top-level keys of NormalizedDesignState that extensions can subscribe to.
|
|
1479
|
+
*/
|
|
1480
|
+
export type DesignStateTopLevelKey = keyof NormalizedDesignState;
|
|
1349
1481
|
export type DesignStructureObject = {
|
|
1350
1482
|
id?: StructureObjectId | null;
|
|
1351
1483
|
meta?: StructureObjectMeta;
|
|
@@ -1355,11 +1487,16 @@ export type Dimensions = {
|
|
|
1355
1487
|
width: number;
|
|
1356
1488
|
height: number;
|
|
1357
1489
|
};
|
|
1490
|
+
export type EditorColorScheme = "light" | "dark";
|
|
1358
1491
|
export type ElementLocation = "origin" | "center";
|
|
1359
1492
|
export type Expand<T> = T extends infer O ? {
|
|
1360
1493
|
[K in keyof O]: O[K];
|
|
1361
1494
|
} : never;
|
|
1362
1495
|
export type FillMetaTarget = "border" | "fill";
|
|
1496
|
+
export type FlattenUnion<T> = UnionToIntersection<T extends unknown ? Partial<T> : never>;
|
|
1497
|
+
export type FontVariationAxis = OrAnyString<"wght" | "wdth" | "slnt" | "ital" | "opsz" | "GRAD">;
|
|
1498
|
+
export type FontVariationSettings = Partial<Record<FontVariationAxis, number>>;
|
|
1499
|
+
export type FontWeight = OrAnyString<"Regular" | "Bold" | "Light" | "Medium" | "Black" | "SemiBold" | "Italic" | "ExtraLight" | "Thin" | "ExtraBold" | "LightItalic" | "MediumItalic" | "SemiBoldItalic" | "BlackItalic" | "ExtraBoldItalic" | "ThinItalic" | "ExtraLightItalic" | "BoldItalic">;
|
|
1363
1500
|
export type FullColor = {
|
|
1364
1501
|
key: "fill" | (Exclude<string, StringColorKeysType> & {});
|
|
1365
1502
|
value: Color;
|
|
@@ -1392,6 +1529,8 @@ export type GuideSerializedObject = typeof GUIDE_DEFAULT_VALUES & OrientationDir
|
|
|
1392
1529
|
export type ID = string;
|
|
1393
1530
|
export type IllustrationImageSerializedObject = typeof DEFAULT_VALUES$1 & {
|
|
1394
1531
|
backgroundRemoved?: boolean | undefined;
|
|
1532
|
+
objectNameWithBackground?: string;
|
|
1533
|
+
backgroundRestorePathBoundary?: number | undefined;
|
|
1395
1534
|
realWidth?: number | undefined;
|
|
1396
1535
|
realHeight?: number | undefined;
|
|
1397
1536
|
erasePaths?: {
|
|
@@ -1429,6 +1568,7 @@ export type InternalPatchArgs<T> = {
|
|
|
1429
1568
|
patch: PatchTree<T> | PatchTree<T>[];
|
|
1430
1569
|
origin: Origin;
|
|
1431
1570
|
historyOrigin?: HistoryOrigins;
|
|
1571
|
+
transactionMeta?: TransactionMeta;
|
|
1432
1572
|
};
|
|
1433
1573
|
export type LayerIconType = "drawIcon";
|
|
1434
1574
|
export type LayerType = Exclude<SerializableObjectType, ObjectType.Guide> | typeof structuralGroupType | typeof clippingMaskType | typeof backgroundType | typeof pathType;
|
|
@@ -1437,6 +1577,12 @@ export type LeftTopPosition = {
|
|
|
1437
1577
|
left: number;
|
|
1438
1578
|
top: number;
|
|
1439
1579
|
};
|
|
1580
|
+
export type LineHeight = {
|
|
1581
|
+
value: number;
|
|
1582
|
+
unit: LineHeightUnit;
|
|
1583
|
+
};
|
|
1584
|
+
export type LineHeightUnit = "px" | "%";
|
|
1585
|
+
export type LineIndex = number;
|
|
1440
1586
|
export type LinkedPreset = {
|
|
1441
1587
|
id: string;
|
|
1442
1588
|
libraryId: string;
|
|
@@ -1531,6 +1677,7 @@ export type NullablePathTextShadowOptions = PathTextShadowOptions | {
|
|
|
1531
1677
|
type: null;
|
|
1532
1678
|
};
|
|
1533
1679
|
export type OnGenerationStatusUpdate = (update: GenerationStatusUpdate) => void | Promise<void>;
|
|
1680
|
+
export type OrAnyString<T extends string> = T | (string & {});
|
|
1534
1681
|
export type OrientationConditional = {
|
|
1535
1682
|
orientation: Orientation.HORIZONTAL;
|
|
1536
1683
|
top: number;
|
|
@@ -1639,21 +1786,78 @@ export type RichTextBasePluginSerializedObject = {
|
|
|
1639
1786
|
name: string;
|
|
1640
1787
|
version: string;
|
|
1641
1788
|
};
|
|
1789
|
+
export type RichTextCompressedColor = string | GradientObject | null;
|
|
1790
|
+
export type RichTextCompressedStyles = RichTextCompressedStylesV1 | RichTextCompressedStylesV2;
|
|
1642
1791
|
export type RichTextDecorationPluginSerializedObject = RichTextBasePluginSerializedObject & {
|
|
1643
1792
|
fillStyle: string;
|
|
1644
1793
|
[key: string]: string | number;
|
|
1645
1794
|
};
|
|
1795
|
+
export type RichTextHyperlinkSerializedObject = {
|
|
1796
|
+
id: string;
|
|
1797
|
+
url: string;
|
|
1798
|
+
};
|
|
1646
1799
|
export type RichTextRenderPluginSerializedObject = RichTextBasePluginSerializedObject & {
|
|
1647
1800
|
color: string;
|
|
1648
1801
|
angle: number;
|
|
1649
1802
|
offset: number;
|
|
1650
1803
|
[key: string]: string | number;
|
|
1651
1804
|
};
|
|
1805
|
+
export type RichTextResizeBehavior = "hug" | "none" | "hug-height";
|
|
1806
|
+
export type RichTextSerializedCharacterStyle = Partial<{
|
|
1807
|
+
fontFamily: string;
|
|
1808
|
+
fontWeight: FontWeight;
|
|
1809
|
+
fontSize: number;
|
|
1810
|
+
fill: RichTextCompressedColor;
|
|
1811
|
+
underline: boolean;
|
|
1812
|
+
linethrough: boolean;
|
|
1813
|
+
charSpacing: number;
|
|
1814
|
+
textCase: TextCase;
|
|
1815
|
+
lineHeightValue: LineHeight;
|
|
1816
|
+
hyperlinkId: string | null;
|
|
1817
|
+
preLinkFill: RichTextCompressedColor;
|
|
1818
|
+
fontVariationSettings: FontVariationSettings;
|
|
1819
|
+
fontFeatureSettings: Record<string, boolean | number>;
|
|
1820
|
+
}>;
|
|
1652
1821
|
export type RichTextSerializedObject = typeof RICH_TEXT_DEFAULT_VALUES & {
|
|
1653
1822
|
text: string;
|
|
1823
|
+
fontFamily: string;
|
|
1824
|
+
styles?: RichTextCompressedStyles;
|
|
1654
1825
|
activeRenderPlugins?: RichTextRenderPluginSerializedObject[];
|
|
1655
1826
|
activeDecorationPlugins?: RichTextDecorationPluginSerializedObject[];
|
|
1656
|
-
|
|
1827
|
+
activeTransformPlugin?: RichTextSerializedTransformPluginObject;
|
|
1828
|
+
fontSize?: number;
|
|
1829
|
+
fontWeight?: FontWeight;
|
|
1830
|
+
textAlign?: TextAlign;
|
|
1831
|
+
charSpacing?: number;
|
|
1832
|
+
underline?: boolean;
|
|
1833
|
+
linethrough?: boolean;
|
|
1834
|
+
fontVariationSettings?: FontVariationSettings;
|
|
1835
|
+
textCase?: TextCase;
|
|
1836
|
+
lineHeightValue?: LineHeight;
|
|
1837
|
+
untransformedWidth?: number;
|
|
1838
|
+
widthBeforeTransform?: number;
|
|
1839
|
+
resizeBehavior?: RichTextResizeBehavior;
|
|
1840
|
+
hyperlinkId?: string;
|
|
1841
|
+
preLinkFill?: string | GradientObject | null;
|
|
1842
|
+
fontFeatureSettings?: Record<string, boolean | number>;
|
|
1843
|
+
links?: RichTextHyperlinkSerializedObject[];
|
|
1844
|
+
volatileData?: {
|
|
1845
|
+
top: number;
|
|
1846
|
+
left: number;
|
|
1847
|
+
width: number;
|
|
1848
|
+
height: number;
|
|
1849
|
+
activeTransformPlugin: RichTextSerializedTransformPluginObject;
|
|
1850
|
+
key: string;
|
|
1851
|
+
};
|
|
1852
|
+
};
|
|
1853
|
+
export type RichTextSerializedTransformPluginObject = RichTextBasePluginSerializedObject & {
|
|
1854
|
+
type?: string;
|
|
1855
|
+
points: {
|
|
1856
|
+
x: number;
|
|
1857
|
+
y: number;
|
|
1858
|
+
}[];
|
|
1859
|
+
curveHeight?: number;
|
|
1860
|
+
directionInverted?: boolean;
|
|
1657
1861
|
};
|
|
1658
1862
|
export type ScreenCoordinates = {
|
|
1659
1863
|
x: number;
|
|
@@ -1679,9 +1883,18 @@ export type SdkResultAsync<T, E = SdkError> = Promise<{
|
|
|
1679
1883
|
error: E;
|
|
1680
1884
|
}>;
|
|
1681
1885
|
export type Selector<T, U = unknown> = (state: T) => U;
|
|
1886
|
+
/**
|
|
1887
|
+
* The design state shape exposed to string path selectors.
|
|
1888
|
+
* `objects` values are flattened so that variant-specific properties
|
|
1889
|
+
* (e.g. `width`, `fill`) are accessible without manual narrowing.
|
|
1890
|
+
*/
|
|
1891
|
+
export type SelectorState = Omit<NormalizedDesignState, "objects"> & {
|
|
1892
|
+
objects: Record<string, FlattenUnion<NormalizedObject>>;
|
|
1893
|
+
};
|
|
1682
1894
|
export type SendToParams = {
|
|
1683
1895
|
boardOrObjectIds: string[];
|
|
1684
1896
|
};
|
|
1897
|
+
export type SequenceLength = number;
|
|
1685
1898
|
export type SerialisedPhotoFilter = ({
|
|
1686
1899
|
type: ImageFilterType;
|
|
1687
1900
|
} & PhotoFilterOptions[ImageFilterType]) | {
|
|
@@ -1775,13 +1988,15 @@ export type TempUserImageUpload = {
|
|
|
1775
1988
|
objectId: string;
|
|
1776
1989
|
mimeType: string;
|
|
1777
1990
|
};
|
|
1991
|
+
export type TextAlign = "left" | "center" | "right" | "justify" | "justify-left" | "justify-center" | "justify-right" | "justify-legacy";
|
|
1992
|
+
export type TextCase = "none" | "uppercase";
|
|
1778
1993
|
export type TextProperties = {
|
|
1779
1994
|
fontFamily?: string;
|
|
1780
1995
|
fontSize?: number;
|
|
1781
|
-
fontWeight?: string
|
|
1996
|
+
fontWeight?: string;
|
|
1782
1997
|
fill?: Color;
|
|
1783
1998
|
textAlign?: "left" | "center" | "right" | "justify";
|
|
1784
|
-
|
|
1999
|
+
lineHeightValue?: LineHeight;
|
|
1785
2000
|
resizeBehavior?: "none" | "hug" | "hug-height";
|
|
1786
2001
|
charSpacing?: number;
|
|
1787
2002
|
underline?: boolean;
|
|
@@ -1793,6 +2008,16 @@ export type TextProperties = {
|
|
|
1793
2008
|
stroke?: string;
|
|
1794
2009
|
strokeWidth?: number;
|
|
1795
2010
|
};
|
|
2011
|
+
export type TransactionMeta = {
|
|
2012
|
+
isLocal: boolean;
|
|
2013
|
+
isUndoRedo: boolean;
|
|
2014
|
+
};
|
|
2015
|
+
/**
|
|
2016
|
+
* Collapses a union type into a single object type where:
|
|
2017
|
+
* - Properties shared by all members keep their original type.
|
|
2018
|
+
* - Properties that exist only on some members become optional.
|
|
2019
|
+
*/
|
|
2020
|
+
export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
1796
2021
|
export type UpdateArtboardBackgroundParams = {
|
|
1797
2022
|
id: string;
|
|
1798
2023
|
objectName: string;
|
|
@@ -1882,6 +2107,7 @@ export type UpdateVideoPlaylistItemParams = {
|
|
|
1882
2107
|
videoId: string;
|
|
1883
2108
|
playlistItemId: string;
|
|
1884
2109
|
playlistItem: Omit<VideoPlaylistItem, "id">;
|
|
2110
|
+
allowAspectRatioMismatch?: boolean;
|
|
1885
2111
|
};
|
|
1886
2112
|
export type UpdateVideoboardParams = {
|
|
1887
2113
|
videoBoardId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kittl/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -22,5 +22,8 @@
|
|
|
22
22
|
"dist",
|
|
23
23
|
"README.md",
|
|
24
24
|
"LICENSE"
|
|
25
|
-
]
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"deploy": "bash ../../scripts/npm-publish.sh"
|
|
28
|
+
}
|
|
26
29
|
}
|