tempo-sdk 0.0.16 → 0.0.18

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 (59) hide show
  1. package/dist/canvas/editor.d.ts +44 -9
  2. package/dist/canvas/editor.js +116 -416
  3. package/dist/canvas/editor.js.map +1 -1
  4. package/dist/canvas/index.d.ts +1 -0
  5. package/dist/canvas/index.js +152 -44
  6. package/dist/canvas/index.js.map +1 -1
  7. package/dist/canvas/parser.d.ts +1 -2
  8. package/dist/canvas/parser.js +1 -3
  9. package/dist/{chunk-ICP7LCPJ.js → chunk-6Q4I3RFN.js} +37 -9
  10. package/dist/chunk-6Q4I3RFN.js.map +1 -0
  11. package/dist/{chunk-77BNMPBS.js → chunk-CB5NJJJT.js} +31 -5
  12. package/dist/chunk-CB5NJJJT.js.map +1 -0
  13. package/dist/expo/plugin.cjs +30 -4
  14. package/dist/expo/plugin.cjs.map +1 -1
  15. package/dist/expo/plugin.js +1 -1
  16. package/dist/expo-babel-plugin.cjs +30 -4
  17. package/dist/expo-babel-plugin.cjs.map +1 -1
  18. package/dist/expo-babel-plugin.d.cts +1 -1
  19. package/dist/expo-babel-plugin.d.ts +1 -1
  20. package/dist/expo-babel-plugin.js +1 -1
  21. package/dist/index.js +26 -6
  22. package/dist/index.js.map +1 -1
  23. package/dist/nextjs-loader.cjs +29 -4
  24. package/dist/nextjs-loader.cjs.map +1 -1
  25. package/package.json +4 -3
  26. package/dist/annotation-strategy-DCJHc--2.d.cts +0 -13
  27. package/dist/annotation-strategy-DCJHc--2.d.ts +0 -13
  28. package/dist/chunk-2LP5G6CD.js +0 -748
  29. package/dist/chunk-2LP5G6CD.js.map +0 -1
  30. package/dist/chunk-77BNMPBS.js.map +0 -1
  31. package/dist/chunk-B3PHU7XX.js +0 -571
  32. package/dist/chunk-B3PHU7XX.js.map +0 -1
  33. package/dist/chunk-EJBWZCEE.js +0 -434
  34. package/dist/chunk-EJBWZCEE.js.map +0 -1
  35. package/dist/chunk-F64WRL4H.js +0 -884
  36. package/dist/chunk-F64WRL4H.js.map +0 -1
  37. package/dist/chunk-G7M57ARC.js +0 -902
  38. package/dist/chunk-G7M57ARC.js.map +0 -1
  39. package/dist/chunk-GHPL4LGE.js +0 -205
  40. package/dist/chunk-GHPL4LGE.js.map +0 -1
  41. package/dist/chunk-ICP7LCPJ.js.map +0 -1
  42. package/dist/chunk-IG3JZVZI.js +0 -846
  43. package/dist/chunk-IG3JZVZI.js.map +0 -1
  44. package/dist/chunk-MBTLXFNP.js +0 -605
  45. package/dist/chunk-MBTLXFNP.js.map +0 -1
  46. package/dist/chunk-MD3HJ7L3.js +0 -457
  47. package/dist/chunk-MD3HJ7L3.js.map +0 -1
  48. package/dist/chunk-O3HYJ6BU.js +0 -433
  49. package/dist/chunk-O3HYJ6BU.js.map +0 -1
  50. package/dist/chunk-WGGLHHC5.js +0 -337
  51. package/dist/chunk-WGGLHHC5.js.map +0 -1
  52. package/dist/chunk-X3K7Z2BH.js +0 -900
  53. package/dist/chunk-X3K7Z2BH.js.map +0 -1
  54. package/dist/chunk-ZHORRCQG.js +0 -756
  55. package/dist/chunk-ZHORRCQG.js.map +0 -1
  56. package/dist/index.cjs +0 -1170
  57. package/dist/index.cjs.map +0 -1
  58. package/dist/index.d.cts +0 -99
  59. 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,6 +759,17 @@ 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(canvasPath, createProblem(sourceKind, error, details));
767
+ this.publish();
768
+ }
769
+ clearCanvasProblem(canvasPath) {
770
+ if (!this.canvasProblems.delete(canvasPath)) return;
771
+ this.publish();
772
+ }
739
773
  clearHostProblem(sourceKinds) {
740
774
  if (!this.hostProblem) return;
741
775
  if (sourceKinds && !sourceKinds.includes(this.hostProblem.sourceKind)) return;
@@ -793,6 +827,9 @@ var CanvasHostProblemTracker = class {
793
827
  return {
794
828
  ...currentHostFailure ? { currentHostFailure } : {},
795
829
  currentRenderFailures,
830
+ currentCanvasFailures: [...this.canvasProblems].map(
831
+ ([canvasPath, failure]) => ({ canvasPath, failure })
832
+ ),
796
833
  observedAt: Date.now()
797
834
  };
798
835
  }
@@ -828,15 +865,34 @@ function installCanvasHostRuntimeProblemTracking(tracker) {
828
865
  if (typeof window === "undefined") return () => {
829
866
  };
830
867
  const cleanupHostCapture = installHostProblemCapture(tracker);
868
+ const cleanupCanvasImportCapture = installCanvasImportProblemCapture(tracker);
831
869
  const cleanupViteCapture = installViteProblemCapture(tracker);
832
870
  const cleanupInspector = installCurrentProblemInspector(tracker);
833
871
  return () => {
834
872
  cleanupHostCapture();
873
+ cleanupCanvasImportCapture();
835
874
  cleanupViteCapture();
836
875
  cleanupInspector();
837
876
  tracker.dispose();
838
877
  };
839
878
  }
879
+ function installCanvasImportProblemCapture(tracker) {
880
+ const onCanvasImportError = (event) => {
881
+ const detail = event.detail;
882
+ if (typeof detail !== "object" || detail === null) return;
883
+ const canvasPath = typeof detail.canvasPath === "string" ? detail.canvasPath : "";
884
+ if (!canvasPath) return;
885
+ const message = typeof detail.message === "string" && detail.message ? detail.message : "Canvas module failed to load";
886
+ tracker.reportCanvasProblem(canvasPath, "runtime-bootstrap", message, {
887
+ stack: typeof detail.stack === "string" ? detail.stack : void 0,
888
+ filename: canvasPath
889
+ });
890
+ };
891
+ window.addEventListener("tempo:canvas-import-error", onCanvasImportError);
892
+ return () => {
893
+ window.removeEventListener("tempo:canvas-import-error", onCanvasImportError);
894
+ };
895
+ }
840
896
  var renderRecoveredHostProblemSourceKinds = ["page-error", "unhandled-rejection", "console-vite-error", "vite-hmr-error"];
841
897
  function createProblem(sourceKind, error, details = {}) {
842
898
  return {
@@ -1221,20 +1277,41 @@ function mergeCurrentProblemSnapshots(primary, fallback) {
1221
1277
  seen.add(key);
1222
1278
  currentRenderFailures.push(entry);
1223
1279
  }
1280
+ const currentCanvasFailures = [...primary.currentCanvasFailures ?? []];
1281
+ const seenCanvas = new Set(
1282
+ currentCanvasFailures.map(
1283
+ (entry) => `${entry.canvasPath}:${entry.failure.sourceKind}:${entry.failure.message}`
1284
+ )
1285
+ );
1286
+ for (const entry of fallback.currentCanvasFailures ?? []) {
1287
+ const key = `${entry.canvasPath}:${entry.failure.sourceKind}:${entry.failure.message}`;
1288
+ if (seenCanvas.has(key)) continue;
1289
+ seenCanvas.add(key);
1290
+ currentCanvasFailures.push(entry);
1291
+ }
1224
1292
  return {
1225
1293
  currentHostFailure: primary.currentHostFailure ?? fallback.currentHostFailure,
1226
1294
  currentRenderFailures,
1295
+ currentCanvasFailures,
1227
1296
  observedAt: Math.max(primary.observedAt, fallback.observedAt)
1228
1297
  };
1229
1298
  }
1230
1299
 
1231
1300
  // canvas/use-canvas-host-postmessage.ts
1232
- function postToMessageSource(source, response) {
1301
+ function postToMessageSource(source, response, targetOrigin) {
1302
+ const origin = safePostMessageTargetOrigin(targetOrigin);
1233
1303
  if (source && "postMessage" in source && source !== window) {
1234
- source.postMessage(response, "*");
1304
+ source.postMessage(response, origin);
1235
1305
  } else {
1236
- window.postMessage(response, "*");
1306
+ window.postMessage(response, origin);
1307
+ }
1308
+ }
1309
+ function safePostMessageTargetOrigin(targetOrigin) {
1310
+ if (targetOrigin && targetOrigin !== "null" && targetOrigin !== "file://") {
1311
+ return targetOrigin;
1237
1312
  }
1313
+ const currentOrigin = window.location.origin;
1314
+ return currentOrigin && currentOrigin !== "null" ? currentOrigin : "*";
1238
1315
  }
1239
1316
  function useCanvasHostPostMessage() {
1240
1317
  const [renderEntriesById, setRenderEntriesById] = useState(
@@ -1271,12 +1348,16 @@ function useCanvasHostPostMessage() {
1271
1348
  const publishProblemSnapshot = useCallback2(() => {
1272
1349
  const payload = buildProblemSnapshot();
1273
1350
  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
- });
1351
+ postToMessageSource(
1352
+ watcher.source,
1353
+ {
1354
+ type: "render-pool:problem-snapshot",
1355
+ requestId: watcher.requestId,
1356
+ watchId: watcher.watchId,
1357
+ payload
1358
+ },
1359
+ watcher.targetOrigin
1360
+ );
1280
1361
  }
1281
1362
  }, [buildProblemSnapshot]);
1282
1363
  const setEntries = useCallback2(
@@ -1445,22 +1526,30 @@ function useCanvasHostPostMessage() {
1445
1526
  if (cancelled) return;
1446
1527
  const onUpdate = (capture) => {
1447
1528
  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
- });
1529
+ postToMessageSource(
1530
+ request.source,
1531
+ {
1532
+ type: "render-pool:watch-update",
1533
+ requestId: request.requestId,
1534
+ watchId: request.watchId,
1535
+ command: request.commandType,
1536
+ payload: { capture }
1537
+ },
1538
+ request.targetOrigin
1539
+ );
1455
1540
  };
1456
1541
  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
- });
1542
+ postToMessageSource(
1543
+ request.source,
1544
+ {
1545
+ type: "render-pool:error",
1546
+ requestId: request.requestId,
1547
+ watchId: request.watchId,
1548
+ command: request.commandType,
1549
+ error: error.message
1550
+ },
1551
+ request.targetOrigin
1552
+ );
1464
1553
  };
1465
1554
  const common = {
1466
1555
  onUpdate,
@@ -1489,13 +1578,17 @@ function useCanvasHostPostMessage() {
1489
1578
  else watch.pause?.();
1490
1579
  }
1491
1580
  })().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
- });
1581
+ postToMessageSource(
1582
+ request.source,
1583
+ {
1584
+ type: "render-pool:error",
1585
+ requestId: request.requestId,
1586
+ watchId: request.watchId,
1587
+ command: request.commandType,
1588
+ error: caught instanceof Error ? caught.message : String(caught)
1589
+ },
1590
+ request.targetOrigin
1591
+ );
1499
1592
  });
1500
1593
  }
1501
1594
  return () => {
@@ -1510,19 +1603,27 @@ function useCanvasHostPostMessage() {
1510
1603
  ]);
1511
1604
  useEffect(() => {
1512
1605
  if (typeof window === "undefined") return;
1606
+ const waitForRenderLease = async (request) => {
1607
+ try {
1608
+ await waitForRender(request);
1609
+ } catch (caught) {
1610
+ releaseRenderLease(request.renderId);
1611
+ throw caught;
1612
+ }
1613
+ };
1513
1614
  const withRenderLease = async (request, run) => {
1514
- await waitForRender(request);
1615
+ await waitForRenderLease(request);
1515
1616
  try {
1516
1617
  return await run();
1517
1618
  } finally {
1518
1619
  releaseRenderLease(request.renderId);
1519
1620
  }
1520
1621
  };
1521
- const handleCommand = (message, source) => {
1622
+ const handleCommand = (message, source, targetOrigin) => {
1522
1623
  const command = readCanvasHostCommand(message);
1523
1624
  if (!command) return;
1524
1625
  const payload = command.payload;
1525
- const post = (response) => postToMessageSource(source, response);
1626
+ const post = (response) => postToMessageSource(source, response, targetOrigin);
1526
1627
  const ack = () => post({
1527
1628
  type: "render-pool:ack",
1528
1629
  requestId: command.requestId,
@@ -1546,7 +1647,7 @@ function useCanvasHostPostMessage() {
1546
1647
  try {
1547
1648
  if (command.type === "render-pool:render") {
1548
1649
  const request = readRenderRequest(command.type, payload);
1549
- void waitForRender(request).then(ack).catch(postAsyncError);
1650
+ void waitForRenderLease(request).then(ack).catch(postAsyncError);
1550
1651
  return;
1551
1652
  }
1552
1653
  if (command.type === "render-pool:capture-image") {
@@ -1623,6 +1724,7 @@ function useCanvasHostPostMessage() {
1623
1724
  requestId: command.requestId,
1624
1725
  watchId,
1625
1726
  source,
1727
+ targetOrigin,
1626
1728
  request,
1627
1729
  payload,
1628
1730
  paused: false,
@@ -1716,7 +1818,8 @@ function useCanvasHostPostMessage() {
1716
1818
  problemWatchersRef.current.set(watchId, {
1717
1819
  requestId: command.requestId,
1718
1820
  watchId,
1719
- source
1821
+ source,
1822
+ targetOrigin
1720
1823
  });
1721
1824
  ack();
1722
1825
  post({
@@ -1736,7 +1839,7 @@ function useCanvasHostPostMessage() {
1736
1839
  postAsyncError(caught);
1737
1840
  }
1738
1841
  };
1739
- const onMessage = (event) => handleCommand(event.data, event.source);
1842
+ const onMessage = (event) => handleCommand(event.data, event.source, event.origin);
1740
1843
  const onBridgeCommand = (event) => handleCommand(event instanceof CustomEvent ? event.detail : void 0);
1741
1844
  window.addEventListener("message", onMessage);
1742
1845
  window.addEventListener("__render-pool:command", onBridgeCommand);
@@ -1855,8 +1958,8 @@ function readDirectUrlSize(params) {
1855
1958
  function readDirectUrlRender() {
1856
1959
  if (typeof window === "undefined") return null;
1857
1960
  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() ?? "";
1961
+ const canvasPath = params.get("canvasPath")?.trim() ?? params.get("pageFile")?.trim() ?? params.get("importPath")?.trim() ?? "";
1962
+ const storyboardId = params.get("storyboardId")?.trim() ?? params.get("exportName")?.trim() ?? params.get("importName")?.trim() ?? "";
1860
1963
  if (!canvasPath || !storyboardId) return null;
1861
1964
  return {
1862
1965
  renderId: getCanvasStoryboardRenderId(canvasPath, storyboardId),
@@ -1897,6 +2000,10 @@ function CanvasHost({
1897
2000
  }
1898
2001
  return renderSizeById.get(normalizedId);
1899
2002
  },
2003
+ getStoryboardPlacement(storyboardId) {
2004
+ const normalizedId = normalizeId(storyboardId, "Storyboard id");
2005
+ return directUrlRender?.renderId === normalizedId ? { left: 0, top: 0 } : void 0;
2006
+ },
1900
2007
  markStoryboardRendered,
1901
2008
  reportStoryboardError,
1902
2009
  clearStoryboardError
@@ -2003,17 +2110,18 @@ function StoryboardSlot({
2003
2110
  const canvas = useCanvasIdentity();
2004
2111
  const status = useStoryboardStatus(id);
2005
2112
  const renderSize = useStoryboardSize(id);
2113
+ const placement = useStoryboardPlacement(id);
2006
2114
  const markRendered = useStoryboardRendered(id);
2007
2115
  const { reportError, clearError } = useStoryboardErrorReporter(id);
2008
2116
  const renderWidth = renderSize?.width;
2009
2117
  const renderHeight = renderSize?.height;
2010
- const intrinsicSize = renderSize?.intrinsicSize;
2118
+ const intrinsicSize = renderSize?.intrinsicSize ?? (kind === "component" && layout.intrinsicSizing === "root-element");
2011
2119
  const resetKey = `${renderId}:${renderSize?.revision ?? 0}`;
2012
2120
  const contentRef = useRef2(null);
2013
2121
  useEffect2(() => {
2014
2122
  if (!contentRef.current || status === "unmounted") return;
2015
2123
  return trackStoryboardPortals(renderId, contentRef.current, status);
2016
- }, [renderId]);
2124
+ }, [renderId, status]);
2017
2125
  useEffect2(() => {
2018
2126
  if (status === "unmounted") return;
2019
2127
  syncStoryboardPortals(renderId, status);
@@ -2034,8 +2142,8 @@ function StoryboardSlot({
2034
2142
  "data-tempo-storyboard-src": src,
2035
2143
  style: {
2036
2144
  position: "absolute",
2037
- left: layout.x,
2038
- top: layout.y,
2145
+ left: placement?.left ?? layout.x,
2146
+ top: placement?.top ?? layout.y,
2039
2147
  width: intrinsicSize ? "max-content" : renderWidth ?? layout.width,
2040
2148
  height: intrinsicSize ? "max-content" : renderHeight ?? layout.height,
2041
2149
  minWidth: intrinsicSize ? renderWidth : void 0,