tempo-sdk 0.0.57 → 0.0.66

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 (108) hide show
  1. package/astro/client.d.ts +4 -0
  2. package/dist/assets/editor.js +1 -1
  3. package/dist/assets/index.d.ts +10 -63
  4. package/dist/assets/index.js +12 -32
  5. package/dist/assets/index.js.map +1 -1
  6. package/dist/assets/parser.js +1 -1
  7. package/dist/astro/asset-preview-client.d.ts +4 -0
  8. package/dist/astro/asset-preview-client.js +93 -0
  9. package/dist/astro/asset-preview-client.js.map +1 -0
  10. package/dist/astro/controls.d.ts +7 -0
  11. package/dist/astro/controls.js +7 -0
  12. package/dist/astro/controls.js.map +1 -0
  13. package/dist/astro/document-client.d.ts +10 -0
  14. package/dist/astro/document-client.js +78 -0
  15. package/dist/astro/document-client.js.map +1 -0
  16. package/dist/astro/runtime.d.ts +15 -0
  17. package/dist/astro/runtime.js +86 -0
  18. package/dist/astro/runtime.js.map +1 -0
  19. package/dist/astro.d.ts +21 -0
  20. package/dist/astro.js +749 -0
  21. package/dist/astro.js.map +1 -0
  22. package/dist/canvas/astro-contract.d.ts +21 -0
  23. package/dist/canvas/astro-contract.js +9 -0
  24. package/dist/canvas/astro-contract.js.map +1 -0
  25. package/dist/canvas/astro.d.ts +18 -0
  26. package/dist/canvas/astro.js +42 -0
  27. package/dist/canvas/astro.js.map +1 -0
  28. package/dist/canvas/editor.d.ts +1 -1
  29. package/dist/canvas/editor.js +3 -2
  30. package/dist/canvas/editor.js.map +1 -1
  31. package/dist/canvas/index.d.ts +4 -2
  32. package/dist/canvas/index.js +138 -34
  33. package/dist/canvas/index.js.map +1 -1
  34. package/dist/canvas/interact-projection.js +4 -4
  35. package/dist/canvas/parser.d.ts +3 -1
  36. package/dist/canvas/parser.js +1 -1
  37. package/dist/canvas/svelte.d.ts +1 -1
  38. package/dist/canvas/svelte.js +3 -3
  39. package/dist/{chunk-5BHIHP25.js → chunk-2JRAG36X.js} +37 -11
  40. package/dist/chunk-2JRAG36X.js.map +1 -0
  41. package/dist/{chunk-N2TYN3RB.js → chunk-6AAE4LYV.js} +123 -123
  42. package/dist/chunk-6AAE4LYV.js.map +1 -0
  43. package/dist/{chunk-U3SLJNRS.js → chunk-6IR5JY6W.js} +106 -7
  44. package/dist/chunk-6IR5JY6W.js.map +1 -0
  45. package/dist/{chunk-QXL6GL2P.js → chunk-6W6UKDSY.js} +46 -5
  46. package/dist/chunk-6W6UKDSY.js.map +1 -0
  47. package/dist/chunk-77DZCV5Z.js +38 -0
  48. package/dist/chunk-77DZCV5Z.js.map +1 -0
  49. package/dist/chunk-DELFOKU3.js +2495 -0
  50. package/dist/chunk-DELFOKU3.js.map +1 -0
  51. package/dist/{chunk-U64AHDHZ.js → chunk-EYKOOLPL.js} +380 -34
  52. package/dist/chunk-EYKOOLPL.js.map +1 -0
  53. package/dist/chunk-F23JGM4U.js +107 -0
  54. package/dist/chunk-F23JGM4U.js.map +1 -0
  55. package/dist/chunk-FE6TYCLF.js +1514 -0
  56. package/dist/chunk-FE6TYCLF.js.map +1 -0
  57. package/dist/chunk-H6OZIX2U.js +133 -0
  58. package/dist/chunk-H6OZIX2U.js.map +1 -0
  59. package/dist/chunk-JVVHU3A7.js +1077 -0
  60. package/dist/chunk-JVVHU3A7.js.map +1 -0
  61. package/dist/{chunk-2IQD2KPS.js → chunk-KOSJXE4G.js} +3 -102
  62. package/dist/chunk-KOSJXE4G.js.map +1 -0
  63. package/dist/{chunk-TL4MGN7E.js → chunk-NSKYOKG5.js} +254 -10
  64. package/dist/chunk-NSKYOKG5.js.map +1 -0
  65. package/dist/chunk-OX2YKYSL.js +13 -0
  66. package/dist/chunk-OX2YKYSL.js.map +1 -0
  67. package/dist/{chunk-RHHVVWAC.js → chunk-PXDTH36X.js} +14 -12
  68. package/dist/chunk-PXDTH36X.js.map +1 -0
  69. package/dist/{chunk-XLEKCOB7.js → chunk-PYAJHLXO.js} +56 -1
  70. package/dist/chunk-PYAJHLXO.js.map +1 -0
  71. package/dist/{chunk-EMYYTS6D.js → chunk-Q2A46HHW.js} +19 -14
  72. package/dist/chunk-Q2A46HHW.js.map +1 -0
  73. package/dist/controls-reader-SNMI2UY7.js +191 -0
  74. package/dist/controls-reader-SNMI2UY7.js.map +1 -0
  75. package/dist/controls-uCaQ3CNX.d.ts +61 -0
  76. package/dist/expo/plugin.cjs +18 -13
  77. package/dist/expo/plugin.cjs.map +1 -1
  78. package/dist/expo/plugin.js +1 -1
  79. package/dist/expo-babel-plugin.cjs +18 -13
  80. package/dist/expo-babel-plugin.cjs.map +1 -1
  81. package/dist/expo-babel-plugin.js +1 -1
  82. package/dist/index.d.ts +4 -0
  83. package/dist/index.js +10 -2294
  84. package/dist/index.js.map +1 -1
  85. package/dist/nextjs/plugin.cjs +45 -4
  86. package/dist/nextjs/plugin.cjs.map +1 -1
  87. package/dist/nextjs/plugin.js +1 -1
  88. package/dist/nextjs-loader.cjs +63 -17
  89. package/dist/nextjs-loader.cjs.map +1 -1
  90. package/dist/nextjs.cjs +45 -4
  91. package/dist/nextjs.cjs.map +1 -1
  92. package/dist/nextjs.d.cts +4 -4
  93. package/dist/nextjs.d.ts +4 -4
  94. package/dist/nextjs.js +1 -1
  95. package/dist/{storyboard-BtQuVGpl.d.ts → storyboard-4YdTYq_e.d.ts} +3 -1
  96. package/dist/svelte.js +7 -1075
  97. package/dist/svelte.js.map +1 -1
  98. package/package.json +45 -4
  99. package/dist/chunk-2IQD2KPS.js.map +0 -1
  100. package/dist/chunk-5BHIHP25.js.map +0 -1
  101. package/dist/chunk-EMYYTS6D.js.map +0 -1
  102. package/dist/chunk-N2TYN3RB.js.map +0 -1
  103. package/dist/chunk-QXL6GL2P.js.map +0 -1
  104. package/dist/chunk-RHHVVWAC.js.map +0 -1
  105. package/dist/chunk-TL4MGN7E.js.map +0 -1
  106. package/dist/chunk-U3SLJNRS.js.map +0 -1
  107. package/dist/chunk-U64AHDHZ.js.map +0 -1
  108. package/dist/chunk-XLEKCOB7.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import {
2
- VITE_ERROR_FEED_KEY
3
- } from "../chunk-K3EYTZLL.js";
2
+ installTempoInteractProjectionSource
3
+ } from "../chunk-EYKOOLPL.js";
4
+ import "../chunk-2JRAG36X.js";
4
5
  import {
5
6
  AdmissionBudgetError,
6
7
  Canvas,
@@ -22,21 +23,24 @@ import {
22
23
  useRequiredCanvasHost,
23
24
  v1DirectUrlSize,
24
25
  v1RenderRequestSize
25
- } from "../chunk-U3SLJNRS.js";
26
+ } from "../chunk-6IR5JY6W.js";
27
+ import "../chunk-NSKYOKG5.js";
28
+ import "../chunk-6AAE4LYV.js";
26
29
  import {
27
- installTempoInteractProjectionSource
28
- } from "../chunk-U64AHDHZ.js";
30
+ VITE_ERROR_FEED_KEY
31
+ } from "../chunk-K3EYTZLL.js";
29
32
  import {
30
33
  TEMPO_INTERACT_FRAME_NAME,
31
34
  isTempoInteractFrameName
32
35
  } from "../chunk-65B52AR7.js";
33
- import "../chunk-TL4MGN7E.js";
34
- import "../chunk-5BHIHP25.js";
35
- import "../chunk-N2TYN3RB.js";
36
36
 
37
37
  // canvas/canvas-host.tsx
38
38
  import {
39
39
  useEffect as useEffect3,
40
+ useCallback as useCallback3,
41
+ useLayoutEffect as useLayoutEffect3,
42
+ useRef as useRef3,
43
+ useState as useState3,
40
44
  useMemo as useMemo3,
41
45
  useSyncExternalStore
42
46
  } from "react";
@@ -221,8 +225,12 @@ function CanvasImportBoundary({
221
225
  () => registerCanvasProblemScope(canvasPath),
222
226
  [canvasPath, registerCanvasProblemScope]
223
227
  );
228
+ const canvasElement = useMemo(
229
+ () => /* @__PURE__ */ jsx(LazyCanvas, { replacement }),
230
+ [LazyCanvas, replacement]
231
+ );
224
232
  return /* @__PURE__ */ jsx(CanvasImportErrorBoundary, { reportError, children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(CanvasPendingMarker, {}), children: /* @__PURE__ */ jsxs(CanvasContext, { path: canvasPath, children: [
225
- /* @__PURE__ */ jsx(LazyCanvas, { replacement }),
233
+ canvasElement,
226
234
  /* @__PURE__ */ jsx(CanvasCommitSignal, { onCommit: markCommitted })
227
235
  ] }) }) }, retryRevision);
228
236
  }
@@ -534,6 +542,7 @@ function readRenderRequest(commandType, payload) {
534
542
  importPath: importPath ?? target.canvasPath ?? target.renderId,
535
543
  importName: importName ?? target.storyboardId ?? target.renderId,
536
544
  ...props ? { props } : {},
545
+ ...payload.userInitiated === true ? { userInitiated: true } : {},
537
546
  ...readOptionalSize(payload),
538
547
  ...isV1CanvasClient() ? v1RenderRequestSize(payload) : {}
539
548
  };
@@ -560,21 +569,27 @@ function acquireRender(entries, request) {
560
569
  const changed = !renderRequestMatchesEntry(current, request);
561
570
  next.set(request.renderId, {
562
571
  ...request,
572
+ lastUsedAt: request.userInitiated ? Date.now() : current?.lastUsedAt,
563
573
  status: "active",
564
574
  activeCount: (current?.activeCount ?? 0) + 1,
565
575
  revision: changed ? (current?.revision ?? 0) + 1 : current?.revision ?? 1
566
576
  });
567
577
  return next;
568
578
  }
569
- function releaseRender(entries, renderId, maxCached, now = Date.now()) {
570
- const current = entries.get(renderId);
571
- if (!current) return entries;
579
+ function releaseRender(entries, renderId, maxCached, now = Date.now(), cacheWhenIdle) {
580
+ const previous = entries.get(renderId);
581
+ if (!previous) return entries;
582
+ const current = cacheWhenIdle === true ? { ...previous, lastUsedAt: now } : previous;
572
583
  const next = new Map(entries);
573
584
  const activeCount = Math.max(0, current.activeCount - 1);
574
585
  if (activeCount > 0) {
575
586
  next.set(renderId, { ...current, activeCount, status: "active" });
576
587
  return next;
577
588
  }
589
+ if (cacheWhenIdle === false && current.lastUsedAt === void 0) {
590
+ next.delete(renderId);
591
+ return next;
592
+ }
578
593
  next.set(renderId, {
579
594
  ...current,
580
595
  activeCount: 0,
@@ -584,7 +599,9 @@ function releaseRender(entries, renderId, maxCached, now = Date.now()) {
584
599
  return evictCachedRenders(next, maxCached);
585
600
  }
586
601
  function evictCachedRenders(entries, maxCached) {
587
- const cached = [...entries.values()].filter((entry) => entry.status === "cached").sort((a, b) => (a.lastInactiveAt ?? 0) - (b.lastInactiveAt ?? 0));
602
+ const cached = [...entries.values()].filter((entry) => entry.status === "cached").sort(
603
+ (a, b) => (a.lastUsedAt ?? 0) - (b.lastUsedAt ?? 0) || (a.lastInactiveAt ?? 0) - (b.lastInactiveAt ?? 0)
604
+ );
588
605
  const evicted = cached.slice(0, Math.max(0, cached.length - maxCached));
589
606
  if (evicted.length === 0) return entries;
590
607
  const next = new Map(entries);
@@ -598,6 +615,8 @@ function buildRenderStatePayload(entries, maxCached, canvasPaths = []) {
598
615
  ({
599
616
  activeCount: _activeCount,
600
617
  lastInactiveAt: _lastInactiveAt,
618
+ lastUsedAt: _lastUsedAt,
619
+ userInitiated: _userInitiated,
601
620
  revision: _revision,
602
621
  ...entry
603
622
  }) => entry
@@ -1590,7 +1609,7 @@ function setRuntimeWatchPaused(watch, paused, resumeOptions) {
1590
1609
  }
1591
1610
  }
1592
1611
  }
1593
- function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId = null) {
1612
+ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId = null, registerCanvas) {
1594
1613
  const [renderEntriesById, setRenderEntriesById] = useState2(() => /* @__PURE__ */ new Map());
1595
1614
  const [watchRequestsById, setWatchRequestsById] = useState2(
1596
1615
  () => /* @__PURE__ */ new Map()
@@ -1606,6 +1625,8 @@ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId
1606
1625
  registeredCanvasPathsRef.current = registeredCanvasPaths;
1607
1626
  const urlPinnedRenderIdRef = useRef2(null);
1608
1627
  urlPinnedRenderIdRef.current = urlPinnedRenderId;
1628
+ const registerCanvasRef = useRef2(registerCanvas);
1629
+ registerCanvasRef.current = registerCanvas;
1609
1630
  const maxCachedRef = useRef2(DEFAULT_MAX_CACHED_RENDERS);
1610
1631
  const legacyHealthRef = useRef2(createLegacyHostHealth());
1611
1632
  const renderedRenderIdsRef = useRef2(/* @__PURE__ */ new Set());
@@ -1683,9 +1704,15 @@ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId
1683
1704
  [setEntries]
1684
1705
  );
1685
1706
  const releaseRenderLease = useCallback2(
1686
- (renderId) => {
1707
+ (renderId, cacheWhenIdle) => {
1687
1708
  setEntries(
1688
- (entries) => releaseRender(entries, renderId, maxCachedRef.current)
1709
+ (entries) => releaseRender(
1710
+ entries,
1711
+ renderId,
1712
+ maxCachedRef.current,
1713
+ Date.now(),
1714
+ cacheWhenIdle
1715
+ )
1689
1716
  );
1690
1717
  },
1691
1718
  [setEntries]
@@ -1741,11 +1768,14 @@ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId
1741
1768
  [stopRuntimeWatch]
1742
1769
  );
1743
1770
  const buildState = useCallback2(
1744
- () => buildRenderStatePayload(
1745
- renderEntriesRef.current,
1746
- maxCachedRef.current,
1747
- registeredCanvasPathsRef.current
1748
- ),
1771
+ () => ({
1772
+ ...registerCanvasRef.current ? { incrementalCanvasRegistration: true } : {},
1773
+ ...buildRenderStatePayload(
1774
+ renderEntriesRef.current,
1775
+ maxCachedRef.current,
1776
+ registeredCanvasPathsRef.current
1777
+ )
1778
+ }),
1749
1779
  []
1750
1780
  );
1751
1781
  const markStoryboardRendered = useCallback2((storyboardId) => {
@@ -2136,6 +2166,12 @@ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId
2136
2166
  ack();
2137
2167
  return;
2138
2168
  }
2169
+ if (command.type === "render-pool:register-canvas") {
2170
+ if (!registerCanvasRef.current || typeof payload.canvasPath !== "string" || !payload.canvasPath.trim() || typeof payload.moduleUrl !== "string")
2171
+ throw new Error("Invalid canvas registration command");
2172
+ void registerCanvasRef.current(payload.canvasPath, payload.moduleUrl).then(ack).catch(postAsyncError);
2173
+ return;
2174
+ }
2139
2175
  if (command.type === "render-pool:list") {
2140
2176
  post({
2141
2177
  type: "render-pool:state",
@@ -2182,7 +2218,10 @@ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId
2182
2218
  }
2183
2219
  if (command.type === "render-pool:unrender") {
2184
2220
  const target = requireRenderTarget(command.type, payload);
2185
- releaseRenderLease(target.renderId);
2221
+ releaseRenderLease(
2222
+ target.renderId,
2223
+ typeof payload.cacheWhenIdle === "boolean" ? payload.cacheWhenIdle : void 0
2224
+ );
2186
2225
  ack();
2187
2226
  return;
2188
2227
  }
@@ -2337,7 +2376,8 @@ function readDirectUrlDimension(value) {
2337
2376
  return unit && unit !== "px" ? `${numberValue}${unit}` : numberValue;
2338
2377
  }
2339
2378
  function readDirectUrlSize(params) {
2340
- if (isV1CanvasClient()) return v1DirectUrlSize(params, readDirectUrlDimension);
2379
+ if (isV1CanvasClient())
2380
+ return v1DirectUrlSize(params, readDirectUrlDimension);
2341
2381
  const width = params.get("width")?.trim();
2342
2382
  const height = params.get("height")?.trim();
2343
2383
  if (!width || !height) return { revision: 1 };
@@ -2369,6 +2409,7 @@ function readDirectUrlSearch() {
2369
2409
  function CanvasHost({
2370
2410
  children,
2371
2411
  canvasModules,
2412
+ incremental = false,
2372
2413
  activeStoryboardIds,
2373
2414
  isStoryboardActive
2374
2415
  }) {
@@ -2377,19 +2418,77 @@ function CanvasHost({
2377
2418
  "CanvasHost cannot receive both children and canvasModules."
2378
2419
  );
2379
2420
  }
2380
- const registeredCanvasPaths = useMemo3(
2381
- () => [
2382
- ...new Set(
2383
- canvasModules?.map(({ canvasPath }) => canvasPath.trim()) ?? []
2384
- )
2385
- ].filter(Boolean),
2386
- [canvasModules]
2421
+ const [admitted, setAdmitted] = useState3([]);
2422
+ const pendingAdmissions = useRef3(
2423
+ /* @__PURE__ */ new Map()
2424
+ );
2425
+ const admittedRef = useRef3(admitted);
2426
+ const modules = useMemo3(() => {
2427
+ const all = new Map(
2428
+ canvasModules?.map((module) => [module.canvasPath, module])
2429
+ );
2430
+ for (const module of admitted)
2431
+ if (!all.has(module.canvasPath)) all.set(module.canvasPath, module);
2432
+ return [...all.values()];
2433
+ }, [canvasModules, admitted]);
2434
+ const registerCanvas = useCallback3((canvasPath, rawUrl) => {
2435
+ const url = new URL(rawUrl, window.location.href);
2436
+ if (url.origin !== window.location.origin || !url.pathname.startsWith("/@fs/")) {
2437
+ return Promise.reject(
2438
+ new Error("Canvas registration requires a same-origin Vite module URL")
2439
+ );
2440
+ }
2441
+ if (admittedRef.current.some((module) => module.canvasPath === canvasPath))
2442
+ return Promise.resolve();
2443
+ return new Promise((resolve, reject) => {
2444
+ const pending = pendingAdmissions.current.get(canvasPath) ?? [];
2445
+ pending.push({ resolve, reject });
2446
+ pendingAdmissions.current.set(canvasPath, pending);
2447
+ setAdmitted(
2448
+ (current) => current.some((module) => module.canvasPath === canvasPath) ? current : [
2449
+ ...current,
2450
+ { canvasPath, load: () => import(
2451
+ /* @vite-ignore */
2452
+ url.href
2453
+ ) }
2454
+ ]
2455
+ );
2456
+ });
2457
+ }, []);
2458
+ useLayoutEffect3(() => {
2459
+ admittedRef.current = admitted;
2460
+ for (const module of admitted) {
2461
+ const pending = pendingAdmissions.current.get(module.canvasPath);
2462
+ pendingAdmissions.current.delete(module.canvasPath);
2463
+ pending?.forEach(({ resolve }) => resolve());
2464
+ }
2465
+ }, [admitted]);
2466
+ useEffect3(
2467
+ () => () => {
2468
+ for (const pending of pendingAdmissions.current.values())
2469
+ pending.forEach(
2470
+ ({ reject }) => reject(new Error("Canvas host disposed during registration"))
2471
+ );
2472
+ pendingAdmissions.current.clear();
2473
+ },
2474
+ []
2387
2475
  );
2388
2476
  const directUrlSearch = useSyncExternalStore(
2389
2477
  subscribeDirectUrlSearch,
2390
2478
  readDirectUrlSearch,
2391
2479
  () => ""
2392
2480
  );
2481
+ const demandRegistration = incremental && new URLSearchParams(directUrlSearch).get("canvasRegistration") === "incremental";
2482
+ const registeredCanvasPaths = useMemo3(
2483
+ () => [
2484
+ ...new Set(
2485
+ (demandRegistration ? admitted : modules).map(
2486
+ ({ canvasPath }) => canvasPath.trim()
2487
+ )
2488
+ )
2489
+ ].filter(Boolean),
2490
+ [modules, admitted, demandRegistration]
2491
+ );
2393
2492
  const directUrlRender = useMemo3(() => {
2394
2493
  return readDirectUrlRender();
2395
2494
  }, [directUrlSearch]);
@@ -2405,7 +2504,8 @@ function CanvasHost({
2405
2504
  registerCanvasProblemScope
2406
2505
  } = useCanvasHostPostMessage(
2407
2506
  registeredCanvasPaths,
2408
- directUrlRender?.renderId ?? null
2507
+ directUrlRender?.renderId ?? null,
2508
+ incremental ? registerCanvas : void 0
2409
2509
  );
2410
2510
  useEffect3(() => {
2411
2511
  if (typeof document === "undefined") return;
@@ -2420,10 +2520,14 @@ function CanvasHost({
2420
2520
  [directUrlSearch]
2421
2521
  );
2422
2522
  const mountedCanvasModules = useMemo3(
2423
- () => directUrlIdle ? [] : directUrlRender ? canvasModules?.filter(
2523
+ () => directUrlIdle ? [] : directUrlRender ? modules.filter(
2424
2524
  ({ canvasPath }) => canvasPath.trim() === directUrlRender.canvasPath
2425
- ) : canvasModules,
2426
- [canvasModules, directUrlIdle, directUrlRender]
2525
+ ) : demandRegistration ? modules.filter(
2526
+ (module) => admitted.some(
2527
+ (entry) => entry.canvasPath === module.canvasPath
2528
+ )
2529
+ ) : modules,
2530
+ [modules, admitted, demandRegistration, directUrlIdle, directUrlRender]
2427
2531
  );
2428
2532
  const runtime = useMemo3(
2429
2533
  () => ({