tempo-sdk 0.0.16 → 0.0.19

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.
Files changed (71) hide show
  1. package/dist/assets/editor.d.ts +79 -0
  2. package/dist/assets/editor.js +571 -0
  3. package/dist/assets/editor.js.map +1 -0
  4. package/dist/assets/index.d.ts +83 -0
  5. package/dist/assets/index.js +26 -0
  6. package/dist/assets/index.js.map +1 -0
  7. package/dist/assets/parser.d.ts +78 -0
  8. package/dist/assets/parser.js +29 -0
  9. package/dist/assets/parser.js.map +1 -0
  10. package/dist/canvas/editor.d.ts +44 -9
  11. package/dist/canvas/editor.js +116 -416
  12. package/dist/canvas/editor.js.map +1 -1
  13. package/dist/canvas/index.d.ts +1 -0
  14. package/dist/canvas/index.js +237 -56
  15. package/dist/canvas/index.js.map +1 -1
  16. package/dist/canvas/parser.d.ts +25 -2
  17. package/dist/canvas/parser.js +3 -3
  18. package/dist/{chunk-77BNMPBS.js → chunk-CB5NJJJT.js} +31 -5
  19. package/dist/chunk-CB5NJJJT.js.map +1 -0
  20. package/dist/chunk-IWULHYPW.js +650 -0
  21. package/dist/chunk-IWULHYPW.js.map +1 -0
  22. package/dist/{chunk-ICP7LCPJ.js → chunk-P277UVZE.js} +279 -40
  23. package/dist/chunk-P277UVZE.js.map +1 -0
  24. package/dist/expo/plugin.cjs +30 -4
  25. package/dist/expo/plugin.cjs.map +1 -1
  26. package/dist/expo/plugin.js +1 -1
  27. package/dist/expo-babel-plugin.cjs +30 -4
  28. package/dist/expo-babel-plugin.cjs.map +1 -1
  29. package/dist/expo-babel-plugin.d.cts +1 -1
  30. package/dist/expo-babel-plugin.d.ts +1 -1
  31. package/dist/expo-babel-plugin.js +1 -1
  32. package/dist/index.js +26 -6
  33. package/dist/index.js.map +1 -1
  34. package/dist/nextjs-loader.cjs +29 -4
  35. package/dist/nextjs-loader.cjs.map +1 -1
  36. package/dist/types-B-dRoF2T.d.ts +102 -0
  37. package/package.json +16 -3
  38. package/dist/annotation-strategy-DCJHc--2.d.cts +0 -13
  39. package/dist/annotation-strategy-DCJHc--2.d.ts +0 -13
  40. package/dist/chunk-2LP5G6CD.js +0 -748
  41. package/dist/chunk-2LP5G6CD.js.map +0 -1
  42. package/dist/chunk-77BNMPBS.js.map +0 -1
  43. package/dist/chunk-B3PHU7XX.js +0 -571
  44. package/dist/chunk-B3PHU7XX.js.map +0 -1
  45. package/dist/chunk-EJBWZCEE.js +0 -434
  46. package/dist/chunk-EJBWZCEE.js.map +0 -1
  47. package/dist/chunk-F64WRL4H.js +0 -884
  48. package/dist/chunk-F64WRL4H.js.map +0 -1
  49. package/dist/chunk-G7M57ARC.js +0 -902
  50. package/dist/chunk-G7M57ARC.js.map +0 -1
  51. package/dist/chunk-GHPL4LGE.js +0 -205
  52. package/dist/chunk-GHPL4LGE.js.map +0 -1
  53. package/dist/chunk-ICP7LCPJ.js.map +0 -1
  54. package/dist/chunk-IG3JZVZI.js +0 -846
  55. package/dist/chunk-IG3JZVZI.js.map +0 -1
  56. package/dist/chunk-MBTLXFNP.js +0 -605
  57. package/dist/chunk-MBTLXFNP.js.map +0 -1
  58. package/dist/chunk-MD3HJ7L3.js +0 -457
  59. package/dist/chunk-MD3HJ7L3.js.map +0 -1
  60. package/dist/chunk-O3HYJ6BU.js +0 -433
  61. package/dist/chunk-O3HYJ6BU.js.map +0 -1
  62. package/dist/chunk-WGGLHHC5.js +0 -337
  63. package/dist/chunk-WGGLHHC5.js.map +0 -1
  64. package/dist/chunk-X3K7Z2BH.js +0 -900
  65. package/dist/chunk-X3K7Z2BH.js.map +0 -1
  66. package/dist/chunk-ZHORRCQG.js +0 -756
  67. package/dist/chunk-ZHORRCQG.js.map +0 -1
  68. package/dist/index.cjs +0 -1170
  69. package/dist/index.cjs.map +0 -1
  70. package/dist/index.d.cts +0 -99
  71. package/dist/page-BokkL6FZ.d.ts +0 -35
@@ -1,6 +1,9 @@
1
1
  // canvas/canvas.tsx
2
2
  import {
3
+ Children,
4
+ cloneElement,
3
5
  createContext,
6
+ isValidElement,
4
7
  useContext,
5
8
  useMemo
6
9
  } from "react";
@@ -48,6 +51,16 @@ function Canvas({
48
51
  );
49
52
  }
50
53
  const identity = useMemo(() => ({ path: canvasPath }), [canvasPath]);
54
+ const keyedChildren = useMemo(
55
+ () => Children.map(children, (child) => {
56
+ if (!isValidElement(child)) return child;
57
+ if (child.key != null) return child;
58
+ const id = child.props.id;
59
+ if (typeof id !== "string" || id.length === 0) return child;
60
+ return cloneElement(child, { key: `storyboard:${id}` });
61
+ }),
62
+ [children]
63
+ );
51
64
  return /* @__PURE__ */ jsx(CanvasIdentityContext.Provider, { value: identity, children: /* @__PURE__ */ jsx(
52
65
  "div",
53
66
  {
@@ -55,7 +68,7 @@ function Canvas({
55
68
  "data-tempo-canvas-path": canvasPath,
56
69
  "data-tempo-canvas-background": backgroundColor,
57
70
  "data-tempo-canvas-viewport": defaultViewport ? JSON.stringify(defaultViewport) : void 0,
58
- children
71
+ children: keyedChildren
59
72
  }
60
73
  ) });
61
74
  }
@@ -121,6 +134,11 @@ function useStoryboardSize(storyboardId) {
121
134
  const host = useRequiredCanvasHost();
122
135
  return host.getStoryboardSize(renderId);
123
136
  }
137
+ function useStoryboardPlacement(storyboardId) {
138
+ const renderId = useCanvasStoryboardRenderId(storyboardId);
139
+ const host = useRequiredCanvasHost();
140
+ return host.getStoryboardPlacement(renderId);
141
+ }
124
142
 
125
143
  // canvas/use-canvas-host-postmessage.ts
126
144
  import { useCallback as useCallback2, useEffect, useMemo as useMemo2, useRef, useState } from "react";
@@ -693,6 +711,7 @@ var CanvasHostProblemTracker = class {
693
711
  this.hostProblemHmrGeneration = 0;
694
712
  this.componentProblems = /* @__PURE__ */ new Map();
695
713
  this.componentProblemHmrGenerations = /* @__PURE__ */ new Map();
714
+ this.canvasProblems = /* @__PURE__ */ new Map();
696
715
  this.watchers = /* @__PURE__ */ new Set();
697
716
  this.hostProblemClearedWatchers = /* @__PURE__ */ new Set();
698
717
  this.hmrGeneration = 0;
@@ -704,7 +723,11 @@ var CanvasHostProblemTracker = class {
704
723
  hostProblem,
705
724
  componentProblems: [...this.componentProblems].map(
706
725
  ([renderId, problem]) => ({ renderId, problem })
707
- )
726
+ ),
727
+ canvasProblems: [...this.canvasProblems].map(([canvasPath, problem]) => ({
728
+ canvasPath,
729
+ problem
730
+ }))
708
731
  };
709
732
  }
710
733
  watch(callback) {
@@ -736,9 +759,24 @@ var CanvasHostProblemTracker = class {
736
759
  }
737
760
  this.publish();
738
761
  }
762
+ // A whole-canvas failure (its module failed to import, so none of its
763
+ // storyboards ever registered). Keyed by canvas path, not renderId — the
764
+ // renderer scopes it to that canvas's storyboards.
765
+ reportCanvasProblem(canvasPath, sourceKind, error, details = {}) {
766
+ this.canvasProblems.set(
767
+ canvasPath,
768
+ createProblem(sourceKind, error, details)
769
+ );
770
+ this.publish();
771
+ }
772
+ clearCanvasProblem(canvasPath) {
773
+ if (!this.canvasProblems.delete(canvasPath)) return;
774
+ this.publish();
775
+ }
739
776
  clearHostProblem(sourceKinds) {
740
777
  if (!this.hostProblem) return;
741
- if (sourceKinds && !sourceKinds.includes(this.hostProblem.sourceKind)) return;
778
+ if (sourceKinds && !sourceKinds.includes(this.hostProblem.sourceKind))
779
+ return;
742
780
  const clearedProblem = this.hostProblem;
743
781
  this.hostProblem = void 0;
744
782
  this.hostProblemHmrGeneration = 0;
@@ -793,6 +831,9 @@ var CanvasHostProblemTracker = class {
793
831
  return {
794
832
  ...currentHostFailure ? { currentHostFailure } : {},
795
833
  currentRenderFailures,
834
+ currentCanvasFailures: [...this.canvasProblems].map(
835
+ ([canvasPath, failure]) => ({ canvasPath, failure })
836
+ ),
796
837
  observedAt: Date.now()
797
838
  };
798
839
  }
@@ -807,7 +848,9 @@ var CanvasHostProblemTracker = class {
807
848
  }
808
849
  }
809
850
  clearRecoveredHostProblemAfterRender(renderId) {
810
- if (!this.hostProblem || !renderRecoveredHostProblemSourceKinds.includes(this.hostProblem.sourceKind)) {
851
+ if (!this.hostProblem || !renderRecoveredHostProblemSourceKinds.includes(
852
+ this.hostProblem.sourceKind
853
+ )) {
811
854
  return false;
812
855
  }
813
856
  if (this.hmrGeneration <= this.hostProblemHmrGeneration) return false;
@@ -828,15 +871,37 @@ function installCanvasHostRuntimeProblemTracking(tracker) {
828
871
  if (typeof window === "undefined") return () => {
829
872
  };
830
873
  const cleanupHostCapture = installHostProblemCapture(tracker);
874
+ const cleanupCanvasImportCapture = installCanvasImportProblemCapture(tracker);
831
875
  const cleanupViteCapture = installViteProblemCapture(tracker);
832
876
  const cleanupInspector = installCurrentProblemInspector(tracker);
833
877
  return () => {
834
878
  cleanupHostCapture();
879
+ cleanupCanvasImportCapture();
835
880
  cleanupViteCapture();
836
881
  cleanupInspector();
837
882
  tracker.dispose();
838
883
  };
839
884
  }
885
+ function installCanvasImportProblemCapture(tracker) {
886
+ const onCanvasImportError = (event) => {
887
+ const detail = event.detail;
888
+ if (typeof detail !== "object" || detail === null) return;
889
+ const canvasPath = typeof detail.canvasPath === "string" ? detail.canvasPath : "";
890
+ if (!canvasPath) return;
891
+ const message = typeof detail.message === "string" && detail.message ? detail.message : "Canvas module failed to load";
892
+ tracker.reportCanvasProblem(canvasPath, "runtime-bootstrap", message, {
893
+ stack: typeof detail.stack === "string" ? detail.stack : void 0,
894
+ filename: canvasPath
895
+ });
896
+ };
897
+ window.addEventListener("tempo:canvas-import-error", onCanvasImportError);
898
+ return () => {
899
+ window.removeEventListener(
900
+ "tempo:canvas-import-error",
901
+ onCanvasImportError
902
+ );
903
+ };
904
+ }
840
905
  var renderRecoveredHostProblemSourceKinds = ["page-error", "unhandled-rejection", "console-vite-error", "vite-hmr-error"];
841
906
  function createProblem(sourceKind, error, details = {}) {
842
907
  return {
@@ -861,7 +926,9 @@ function findRenderIdForProblem(problem) {
861
926
  const renderId = slot.getAttribute("data-render-id");
862
927
  if (!renderId) continue;
863
928
  const sourceFiles = getObservedSourceFiles(slot);
864
- if (sourceFiles.some((sourceFile) => problemTextMentionsSource(haystack, sourceFile))) {
929
+ if (sourceFiles.some(
930
+ (sourceFile) => problemTextMentionsSource(haystack, sourceFile)
931
+ )) {
865
932
  return renderId;
866
933
  }
867
934
  }
@@ -893,11 +960,15 @@ function problemTextMentionsSource(text, sourceFile) {
893
960
  function installHostProblemCapture(tracker) {
894
961
  const onError = (event) => {
895
962
  if (event.target instanceof Element) return;
896
- tracker.reportProblemNearRender("page-error", event.error ?? event.message, {
897
- filename: event.filename || void 0,
898
- line: typeof event.lineno === "number" ? event.lineno : void 0,
899
- column: typeof event.colno === "number" ? event.colno : void 0
900
- });
963
+ tracker.reportProblemNearRender(
964
+ "page-error",
965
+ event.error ?? event.message,
966
+ {
967
+ filename: event.filename || void 0,
968
+ line: typeof event.lineno === "number" ? event.lineno : void 0,
969
+ column: typeof event.colno === "number" ? event.colno : void 0
970
+ }
971
+ );
901
972
  };
902
973
  const onUnhandledRejection = (event) => {
903
974
  tracker.reportProblemNearRender("unhandled-rejection", event.reason);
@@ -974,6 +1045,16 @@ function installViteProblemCapture(tracker) {
974
1045
  }
975
1046
  return latest;
976
1047
  };
1048
+ const deleteViteHmrFailureForPath = (path) => {
1049
+ let removed = false;
1050
+ for (const key of [...viteHmrFailedModules.keys()]) {
1051
+ if (key !== pathlessViteErrorKey && modulePathsMatch(key, path)) {
1052
+ viteHmrFailedModules.delete(key);
1053
+ removed = true;
1054
+ }
1055
+ }
1056
+ return removed;
1057
+ };
977
1058
  const reconcileViteHmrHostProblem = () => {
978
1059
  const latest = latestViteHmrFailure();
979
1060
  if (latest) {
@@ -987,8 +1068,11 @@ function installViteProblemCapture(tracker) {
987
1068
  let viteHmrCycleActive = false;
988
1069
  let cycleFailedPaths = /* @__PURE__ */ new Map();
989
1070
  let lastCycleViteErrorDetail;
1071
+ let hmrCycleSeq = 0;
1072
+ const cleanUpdateCycleByPath = /* @__PURE__ */ new Map();
990
1073
  const onViteBeforeUpdate = () => {
991
1074
  viteHmrCycleActive = true;
1075
+ hmrCycleSeq += 1;
992
1076
  cycleFailedPaths = /* @__PURE__ */ new Map();
993
1077
  lastCycleViteErrorDetail = void 0;
994
1078
  tracker.noteHmrUpdateStarted();
@@ -996,12 +1080,34 @@ function installViteProblemCapture(tracker) {
996
1080
  const onViteAfterUpdate = (payload) => {
997
1081
  const updatedPaths = readUpdatePaths(payload);
998
1082
  let shouldReconcile = false;
1083
+ const failedThisCycle = [...cycleFailedPaths.keys()];
1084
+ for (const updatedPath of updatedPaths) {
1085
+ if (failedThisCycle.some((failed) => modulePathsMatch(failed, updatedPath))) {
1086
+ continue;
1087
+ }
1088
+ cleanUpdateCycleByPath.set(normalizeModulePath(updatedPath), hmrCycleSeq);
1089
+ for (const key of [...viteHmrFailedModules.keys()]) {
1090
+ if (key === pathlessViteErrorKey) continue;
1091
+ if (modulePathsMatch(key, updatedPath)) {
1092
+ viteHmrFailedModules.delete(key);
1093
+ shouldReconcile = true;
1094
+ }
1095
+ }
1096
+ }
999
1097
  if (updatedPaths.length > 0 && !cycleFailedPaths.has(pathlessViteErrorKey)) {
1000
- shouldReconcile = viteHmrFailedModules.delete(pathlessViteErrorKey);
1098
+ if (viteHmrFailedModules.delete(pathlessViteErrorKey)) {
1099
+ shouldReconcile = true;
1100
+ }
1001
1101
  }
1002
1102
  for (const [path, problem] of cycleFailedPaths) {
1003
1103
  viteHmrFailedModules.set(path, problem);
1004
1104
  shouldReconcile = true;
1105
+ void verifyModuleStillExists(path).then((exists) => {
1106
+ if (exists) return;
1107
+ if (deleteViteHmrFailureForPath(path)) {
1108
+ reconcileViteHmrHostProblem();
1109
+ }
1110
+ });
1005
1111
  }
1006
1112
  viteHmrCycleActive = false;
1007
1113
  cycleFailedPaths = /* @__PURE__ */ new Map();
@@ -1050,9 +1156,14 @@ function installViteProblemCapture(tracker) {
1050
1156
  }
1051
1157
  const stopClearedWatch = tracker.watchHostProblemCleared((problem) => {
1052
1158
  if (problem.sourceKind !== "vite-hmr-error") return;
1053
- const key = problem.filename ?? pathlessViteErrorKey;
1054
- if (!viteHmrFailedModules.has(key)) return;
1055
- viteHmrFailedModules.delete(key);
1159
+ const filename = problem.filename;
1160
+ let removed = false;
1161
+ if (filename == null) {
1162
+ removed = viteHmrFailedModules.delete(pathlessViteErrorKey);
1163
+ } else {
1164
+ removed = deleteViteHmrFailureForPath(filename);
1165
+ }
1166
+ if (!removed) return;
1056
1167
  void Promise.resolve().then(reconcileViteHmrHostProblem);
1057
1168
  });
1058
1169
  const originalConsoleError = console.error;
@@ -1077,7 +1188,12 @@ function installViteProblemCapture(tracker) {
1077
1188
  viteHmrFailedModules.set(path, problem);
1078
1189
  reconcileViteHmrHostProblem();
1079
1190
  } else {
1191
+ const observedCycleSeq = hmrCycleSeq;
1080
1192
  void verifyModuleStillExists(path).then((exists) => {
1193
+ const cleanSeq = cleanUpdateCycleByPath.get(
1194
+ normalizeModulePath(path)
1195
+ );
1196
+ if (cleanSeq !== void 0 && cleanSeq > observedCycleSeq) return;
1081
1197
  if (exists) viteHmrFailedModules.set(path, problem);
1082
1198
  else viteHmrFailedModules.delete(path);
1083
1199
  reconcileViteHmrHostProblem();
@@ -1197,10 +1313,23 @@ function readUpdatePaths(payload) {
1197
1313
  }
1198
1314
  return [...paths];
1199
1315
  }
1316
+ function normalizeModulePath(value) {
1317
+ const cutIndex = value.search(/[?#]/);
1318
+ return cutIndex === -1 ? value : value.slice(0, cutIndex);
1319
+ }
1320
+ function modulePathsMatch(a, b) {
1321
+ const left = normalizeModulePath(a);
1322
+ const right = normalizeModulePath(b);
1323
+ if (!left || !right) return false;
1324
+ if (left === right) return true;
1325
+ const [longer, shorter] = left.length >= right.length ? [left, right] : [right, left];
1326
+ return shorter.startsWith("/") && longer.endsWith(shorter);
1327
+ }
1200
1328
  async function verifyModuleStillExists(path) {
1201
1329
  if (typeof fetch !== "function") return true;
1202
1330
  try {
1203
1331
  const response = await fetch(path, { cache: "no-store" });
1332
+ if ("ok" in response && response.ok === false) return false;
1204
1333
  const contentType = response.headers.get("content-type") || "";
1205
1334
  return !contentType.includes("text/html");
1206
1335
  } catch {
@@ -1221,20 +1350,41 @@ function mergeCurrentProblemSnapshots(primary, fallback) {
1221
1350
  seen.add(key);
1222
1351
  currentRenderFailures.push(entry);
1223
1352
  }
1353
+ const currentCanvasFailures = [...primary.currentCanvasFailures ?? []];
1354
+ const seenCanvas = new Set(
1355
+ currentCanvasFailures.map(
1356
+ (entry) => `${entry.canvasPath}:${entry.failure.sourceKind}:${entry.failure.message}`
1357
+ )
1358
+ );
1359
+ for (const entry of fallback.currentCanvasFailures ?? []) {
1360
+ const key = `${entry.canvasPath}:${entry.failure.sourceKind}:${entry.failure.message}`;
1361
+ if (seenCanvas.has(key)) continue;
1362
+ seenCanvas.add(key);
1363
+ currentCanvasFailures.push(entry);
1364
+ }
1224
1365
  return {
1225
1366
  currentHostFailure: primary.currentHostFailure ?? fallback.currentHostFailure,
1226
1367
  currentRenderFailures,
1368
+ currentCanvasFailures,
1227
1369
  observedAt: Math.max(primary.observedAt, fallback.observedAt)
1228
1370
  };
1229
1371
  }
1230
1372
 
1231
1373
  // canvas/use-canvas-host-postmessage.ts
1232
- function postToMessageSource(source, response) {
1374
+ function postToMessageSource(source, response, targetOrigin) {
1375
+ const origin = safePostMessageTargetOrigin(targetOrigin);
1233
1376
  if (source && "postMessage" in source && source !== window) {
1234
- source.postMessage(response, "*");
1377
+ source.postMessage(response, origin);
1235
1378
  } else {
1236
- window.postMessage(response, "*");
1379
+ window.postMessage(response, origin);
1380
+ }
1381
+ }
1382
+ function safePostMessageTargetOrigin(targetOrigin) {
1383
+ if (targetOrigin && targetOrigin !== "null" && targetOrigin !== "file://") {
1384
+ return targetOrigin;
1237
1385
  }
1386
+ const currentOrigin = window.location.origin;
1387
+ return currentOrigin && currentOrigin !== "null" ? currentOrigin : "*";
1238
1388
  }
1239
1389
  function useCanvasHostPostMessage() {
1240
1390
  const [renderEntriesById, setRenderEntriesById] = useState(
@@ -1271,12 +1421,16 @@ function useCanvasHostPostMessage() {
1271
1421
  const publishProblemSnapshot = useCallback2(() => {
1272
1422
  const payload = buildProblemSnapshot();
1273
1423
  for (const watcher of problemWatchersRef.current.values()) {
1274
- postToMessageSource(watcher.source, {
1275
- type: "render-pool:problem-snapshot",
1276
- requestId: watcher.requestId,
1277
- watchId: watcher.watchId,
1278
- payload
1279
- });
1424
+ postToMessageSource(
1425
+ watcher.source,
1426
+ {
1427
+ type: "render-pool:problem-snapshot",
1428
+ requestId: watcher.requestId,
1429
+ watchId: watcher.watchId,
1430
+ payload
1431
+ },
1432
+ watcher.targetOrigin
1433
+ );
1280
1434
  }
1281
1435
  }, [buildProblemSnapshot]);
1282
1436
  const setEntries = useCallback2(
@@ -1445,22 +1599,30 @@ function useCanvasHostPostMessage() {
1445
1599
  if (cancelled) return;
1446
1600
  const onUpdate = (capture) => {
1447
1601
  recordSourceAnnotatedCommit(request.request.renderId);
1448
- postToMessageSource(request.source, {
1449
- type: "render-pool:watch-update",
1450
- requestId: request.requestId,
1451
- watchId: request.watchId,
1452
- command: request.commandType,
1453
- payload: { capture }
1454
- });
1602
+ postToMessageSource(
1603
+ request.source,
1604
+ {
1605
+ type: "render-pool:watch-update",
1606
+ requestId: request.requestId,
1607
+ watchId: request.watchId,
1608
+ command: request.commandType,
1609
+ payload: { capture }
1610
+ },
1611
+ request.targetOrigin
1612
+ );
1455
1613
  };
1456
1614
  const onError = (error) => {
1457
- postToMessageSource(request.source, {
1458
- type: "render-pool:error",
1459
- requestId: request.requestId,
1460
- watchId: request.watchId,
1461
- command: request.commandType,
1462
- error: error.message
1463
- });
1615
+ postToMessageSource(
1616
+ request.source,
1617
+ {
1618
+ type: "render-pool:error",
1619
+ requestId: request.requestId,
1620
+ watchId: request.watchId,
1621
+ command: request.commandType,
1622
+ error: error.message
1623
+ },
1624
+ request.targetOrigin
1625
+ );
1464
1626
  };
1465
1627
  const common = {
1466
1628
  onUpdate,
@@ -1489,13 +1651,17 @@ function useCanvasHostPostMessage() {
1489
1651
  else watch.pause?.();
1490
1652
  }
1491
1653
  })().catch((caught) => {
1492
- postToMessageSource(request.source, {
1493
- type: "render-pool:error",
1494
- requestId: request.requestId,
1495
- watchId: request.watchId,
1496
- command: request.commandType,
1497
- error: caught instanceof Error ? caught.message : String(caught)
1498
- });
1654
+ postToMessageSource(
1655
+ request.source,
1656
+ {
1657
+ type: "render-pool:error",
1658
+ requestId: request.requestId,
1659
+ watchId: request.watchId,
1660
+ command: request.commandType,
1661
+ error: caught instanceof Error ? caught.message : String(caught)
1662
+ },
1663
+ request.targetOrigin
1664
+ );
1499
1665
  });
1500
1666
  }
1501
1667
  return () => {
@@ -1510,19 +1676,27 @@ function useCanvasHostPostMessage() {
1510
1676
  ]);
1511
1677
  useEffect(() => {
1512
1678
  if (typeof window === "undefined") return;
1679
+ const waitForRenderLease = async (request) => {
1680
+ try {
1681
+ await waitForRender(request);
1682
+ } catch (caught) {
1683
+ releaseRenderLease(request.renderId);
1684
+ throw caught;
1685
+ }
1686
+ };
1513
1687
  const withRenderLease = async (request, run) => {
1514
- await waitForRender(request);
1688
+ await waitForRenderLease(request);
1515
1689
  try {
1516
1690
  return await run();
1517
1691
  } finally {
1518
1692
  releaseRenderLease(request.renderId);
1519
1693
  }
1520
1694
  };
1521
- const handleCommand = (message, source) => {
1695
+ const handleCommand = (message, source, targetOrigin) => {
1522
1696
  const command = readCanvasHostCommand(message);
1523
1697
  if (!command) return;
1524
1698
  const payload = command.payload;
1525
- const post = (response) => postToMessageSource(source, response);
1699
+ const post = (response) => postToMessageSource(source, response, targetOrigin);
1526
1700
  const ack = () => post({
1527
1701
  type: "render-pool:ack",
1528
1702
  requestId: command.requestId,
@@ -1546,7 +1720,7 @@ function useCanvasHostPostMessage() {
1546
1720
  try {
1547
1721
  if (command.type === "render-pool:render") {
1548
1722
  const request = readRenderRequest(command.type, payload);
1549
- void waitForRender(request).then(ack).catch(postAsyncError);
1723
+ void waitForRenderLease(request).then(ack).catch(postAsyncError);
1550
1724
  return;
1551
1725
  }
1552
1726
  if (command.type === "render-pool:capture-image") {
@@ -1623,6 +1797,7 @@ function useCanvasHostPostMessage() {
1623
1797
  requestId: command.requestId,
1624
1798
  watchId,
1625
1799
  source,
1800
+ targetOrigin,
1626
1801
  request,
1627
1802
  payload,
1628
1803
  paused: false,
@@ -1716,7 +1891,8 @@ function useCanvasHostPostMessage() {
1716
1891
  problemWatchersRef.current.set(watchId, {
1717
1892
  requestId: command.requestId,
1718
1893
  watchId,
1719
- source
1894
+ source,
1895
+ targetOrigin
1720
1896
  });
1721
1897
  ack();
1722
1898
  post({
@@ -1736,7 +1912,7 @@ function useCanvasHostPostMessage() {
1736
1912
  postAsyncError(caught);
1737
1913
  }
1738
1914
  };
1739
- const onMessage = (event) => handleCommand(event.data, event.source);
1915
+ const onMessage = (event) => handleCommand(event.data, event.source, event.origin);
1740
1916
  const onBridgeCommand = (event) => handleCommand(event instanceof CustomEvent ? event.detail : void 0);
1741
1917
  window.addEventListener("message", onMessage);
1742
1918
  window.addEventListener("__render-pool:command", onBridgeCommand);
@@ -1855,8 +2031,8 @@ function readDirectUrlSize(params) {
1855
2031
  function readDirectUrlRender() {
1856
2032
  if (typeof window === "undefined") return null;
1857
2033
  const params = new URLSearchParams(window.location.search);
1858
- const canvasPath = params.get("pageFile")?.trim() ?? params.get("importPath")?.trim() ?? "";
1859
- const storyboardId = params.get("exportName")?.trim() ?? params.get("importName")?.trim() ?? "";
2034
+ const canvasPath = params.get("canvasPath")?.trim() ?? params.get("pageFile")?.trim() ?? params.get("importPath")?.trim() ?? "";
2035
+ const storyboardId = params.get("storyboardId")?.trim() ?? params.get("exportName")?.trim() ?? params.get("importName")?.trim() ?? "";
1860
2036
  if (!canvasPath || !storyboardId) return null;
1861
2037
  return {
1862
2038
  renderId: getCanvasStoryboardRenderId(canvasPath, storyboardId),
@@ -1897,6 +2073,10 @@ function CanvasHost({
1897
2073
  }
1898
2074
  return renderSizeById.get(normalizedId);
1899
2075
  },
2076
+ getStoryboardPlacement(storyboardId) {
2077
+ const normalizedId = normalizeId(storyboardId, "Storyboard id");
2078
+ return directUrlRender?.renderId === normalizedId ? { left: 0, top: 0 } : void 0;
2079
+ },
1900
2080
  markStoryboardRendered,
1901
2081
  reportStoryboardError,
1902
2082
  clearStoryboardError
@@ -2003,17 +2183,18 @@ function StoryboardSlot({
2003
2183
  const canvas = useCanvasIdentity();
2004
2184
  const status = useStoryboardStatus(id);
2005
2185
  const renderSize = useStoryboardSize(id);
2186
+ const placement = useStoryboardPlacement(id);
2006
2187
  const markRendered = useStoryboardRendered(id);
2007
2188
  const { reportError, clearError } = useStoryboardErrorReporter(id);
2008
2189
  const renderWidth = renderSize?.width;
2009
2190
  const renderHeight = renderSize?.height;
2010
- const intrinsicSize = renderSize?.intrinsicSize;
2191
+ const intrinsicSize = renderSize?.intrinsicSize ?? (kind === "component" && layout.intrinsicSizing === "root-element");
2011
2192
  const resetKey = `${renderId}:${renderSize?.revision ?? 0}`;
2012
2193
  const contentRef = useRef2(null);
2013
2194
  useEffect2(() => {
2014
2195
  if (!contentRef.current || status === "unmounted") return;
2015
2196
  return trackStoryboardPortals(renderId, contentRef.current, status);
2016
- }, [renderId]);
2197
+ }, [renderId, status]);
2017
2198
  useEffect2(() => {
2018
2199
  if (status === "unmounted") return;
2019
2200
  syncStoryboardPortals(renderId, status);
@@ -2034,8 +2215,8 @@ function StoryboardSlot({
2034
2215
  "data-tempo-storyboard-src": src,
2035
2216
  style: {
2036
2217
  position: "absolute",
2037
- left: layout.x,
2038
- top: layout.y,
2218
+ left: placement?.left ?? layout.x,
2219
+ top: placement?.top ?? layout.y,
2039
2220
  width: intrinsicSize ? "max-content" : renderWidth ?? layout.width,
2040
2221
  height: intrinsicSize ? "max-content" : renderHeight ?? layout.height,
2041
2222
  minWidth: intrinsicSize ? renderWidth : void 0,