tempo-sdk 0.0.57 → 0.0.60

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 (38) hide show
  1. package/dist/canvas/editor.js +1 -1
  2. package/dist/canvas/index.d.ts +4 -2
  3. package/dist/canvas/index.js +100 -20
  4. package/dist/canvas/index.js.map +1 -1
  5. package/dist/canvas/interact-projection.js +1 -1
  6. package/dist/canvas/parser.js +1 -1
  7. package/dist/canvas/svelte.d.ts +1 -1
  8. package/dist/canvas/svelte.js +1 -1
  9. package/dist/{chunk-U3SLJNRS.js → chunk-7DT5DDSH.js} +1 -1
  10. package/dist/chunk-7DT5DDSH.js.map +1 -0
  11. package/dist/{chunk-QXL6GL2P.js → chunk-FQSZRVSL.js} +3 -3
  12. package/dist/{chunk-QXL6GL2P.js.map → chunk-FQSZRVSL.js.map} +1 -1
  13. package/dist/{chunk-U64AHDHZ.js → chunk-MXKZZOLM.js} +14 -4
  14. package/dist/chunk-MXKZZOLM.js.map +1 -0
  15. package/dist/{chunk-EMYYTS6D.js → chunk-OTVBSF7U.js} +3 -3
  16. package/dist/{chunk-EMYYTS6D.js.map → chunk-OTVBSF7U.js.map} +1 -1
  17. package/dist/{chunk-RHHVVWAC.js → chunk-VMTQDG4U.js} +3 -3
  18. package/dist/{chunk-RHHVVWAC.js.map → chunk-VMTQDG4U.js.map} +1 -1
  19. package/dist/expo/plugin.cjs +2 -2
  20. package/dist/expo/plugin.cjs.map +1 -1
  21. package/dist/expo/plugin.js +1 -1
  22. package/dist/expo-babel-plugin.cjs +2 -2
  23. package/dist/expo-babel-plugin.cjs.map +1 -1
  24. package/dist/expo-babel-plugin.js +1 -1
  25. package/dist/index.js +211 -40
  26. package/dist/index.js.map +1 -1
  27. package/dist/nextjs/plugin.cjs +2 -2
  28. package/dist/nextjs/plugin.cjs.map +1 -1
  29. package/dist/nextjs/plugin.js +1 -1
  30. package/dist/nextjs-loader.cjs +4 -4
  31. package/dist/nextjs-loader.cjs.map +1 -1
  32. package/dist/nextjs.cjs +2 -2
  33. package/dist/nextjs.cjs.map +1 -1
  34. package/dist/nextjs.js +1 -1
  35. package/dist/{storyboard-BtQuVGpl.d.ts → storyboard-DjOF61B_.d.ts} +2 -0
  36. package/package.json +2 -2
  37. package/dist/chunk-U3SLJNRS.js.map +0 -1
  38. package/dist/chunk-U64AHDHZ.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseCanvasFile
3
- } from "../chunk-RHHVVWAC.js";
3
+ } from "../chunk-VMTQDG4U.js";
4
4
 
5
5
  // canvas/editor.ts
6
6
  import { parseSync } from "oxc-parser";
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, ComponentType } from 'react';
3
- export { H as HtmlStoryboard, L as LegacyStoryboardV1, R as RouteStoryboard, S as Storyboard, a as StoryboardLayout, b as StoryboardSlot, c as StoryboardVrtConfig, d as StoryboardVrtIgnoreRegion } from '../storyboard-BtQuVGpl.js';
3
+ export { H as HtmlStoryboard, L as LegacyStoryboardV1, R as RouteStoryboard, S as Storyboard, a as StoryboardLayout, b as StoryboardSlot, c as StoryboardVrtConfig, d as StoryboardVrtIgnoreRegion } from '../storyboard-DjOF61B_.js';
4
4
  import '../page-DwLnOM5d.js';
5
5
  import '../v1-client-compat-qxaXEDm_.js';
6
6
 
@@ -49,9 +49,11 @@ type CanvasHostModule = {
49
49
  declare class CanvasHostContractError extends Error {
50
50
  name: string;
51
51
  }
52
- declare function CanvasHost({ children, canvasModules, activeStoryboardIds, isStoryboardActive, }: {
52
+ declare function CanvasHost({ children, canvasModules, incremental, activeStoryboardIds, isStoryboardActive, }: {
53
53
  children?: ReactNode;
54
54
  canvasModules?: readonly CanvasHostModule[];
55
+ /** Generated Vite hosts admit requested canvases without replacing the document. */
56
+ incremental?: boolean;
55
57
  activeStoryboardIds?: ReadonlySet<string> | readonly string[];
56
58
  isStoryboardActive?: (storyboardId: string) => boolean;
57
59
  }): react.JSX.Element;
@@ -22,10 +22,10 @@ import {
22
22
  useRequiredCanvasHost,
23
23
  v1DirectUrlSize,
24
24
  v1RenderRequestSize
25
- } from "../chunk-U3SLJNRS.js";
25
+ } from "../chunk-7DT5DDSH.js";
26
26
  import {
27
27
  installTempoInteractProjectionSource
28
- } from "../chunk-U64AHDHZ.js";
28
+ } from "../chunk-MXKZZOLM.js";
29
29
  import {
30
30
  TEMPO_INTERACT_FRAME_NAME,
31
31
  isTempoInteractFrameName
@@ -37,6 +37,10 @@ import "../chunk-N2TYN3RB.js";
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";
@@ -1590,7 +1594,7 @@ function setRuntimeWatchPaused(watch, paused, resumeOptions) {
1590
1594
  }
1591
1595
  }
1592
1596
  }
1593
- function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId = null) {
1597
+ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId = null, registerCanvas) {
1594
1598
  const [renderEntriesById, setRenderEntriesById] = useState2(() => /* @__PURE__ */ new Map());
1595
1599
  const [watchRequestsById, setWatchRequestsById] = useState2(
1596
1600
  () => /* @__PURE__ */ new Map()
@@ -1606,6 +1610,8 @@ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId
1606
1610
  registeredCanvasPathsRef.current = registeredCanvasPaths;
1607
1611
  const urlPinnedRenderIdRef = useRef2(null);
1608
1612
  urlPinnedRenderIdRef.current = urlPinnedRenderId;
1613
+ const registerCanvasRef = useRef2(registerCanvas);
1614
+ registerCanvasRef.current = registerCanvas;
1609
1615
  const maxCachedRef = useRef2(DEFAULT_MAX_CACHED_RENDERS);
1610
1616
  const legacyHealthRef = useRef2(createLegacyHostHealth());
1611
1617
  const renderedRenderIdsRef = useRef2(/* @__PURE__ */ new Set());
@@ -1741,11 +1747,14 @@ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId
1741
1747
  [stopRuntimeWatch]
1742
1748
  );
1743
1749
  const buildState = useCallback2(
1744
- () => buildRenderStatePayload(
1745
- renderEntriesRef.current,
1746
- maxCachedRef.current,
1747
- registeredCanvasPathsRef.current
1748
- ),
1750
+ () => ({
1751
+ ...registerCanvasRef.current ? { incrementalCanvasRegistration: true } : {},
1752
+ ...buildRenderStatePayload(
1753
+ renderEntriesRef.current,
1754
+ maxCachedRef.current,
1755
+ registeredCanvasPathsRef.current
1756
+ )
1757
+ }),
1749
1758
  []
1750
1759
  );
1751
1760
  const markStoryboardRendered = useCallback2((storyboardId) => {
@@ -2136,6 +2145,12 @@ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId
2136
2145
  ack();
2137
2146
  return;
2138
2147
  }
2148
+ if (command.type === "render-pool:register-canvas") {
2149
+ if (!registerCanvasRef.current || typeof payload.canvasPath !== "string" || !payload.canvasPath.trim() || typeof payload.moduleUrl !== "string")
2150
+ throw new Error("Invalid canvas registration command");
2151
+ void registerCanvasRef.current(payload.canvasPath, payload.moduleUrl).then(ack).catch(postAsyncError);
2152
+ return;
2153
+ }
2139
2154
  if (command.type === "render-pool:list") {
2140
2155
  post({
2141
2156
  type: "render-pool:state",
@@ -2337,7 +2352,8 @@ function readDirectUrlDimension(value) {
2337
2352
  return unit && unit !== "px" ? `${numberValue}${unit}` : numberValue;
2338
2353
  }
2339
2354
  function readDirectUrlSize(params) {
2340
- if (isV1CanvasClient()) return v1DirectUrlSize(params, readDirectUrlDimension);
2355
+ if (isV1CanvasClient())
2356
+ return v1DirectUrlSize(params, readDirectUrlDimension);
2341
2357
  const width = params.get("width")?.trim();
2342
2358
  const height = params.get("height")?.trim();
2343
2359
  if (!width || !height) return { revision: 1 };
@@ -2369,6 +2385,7 @@ function readDirectUrlSearch() {
2369
2385
  function CanvasHost({
2370
2386
  children,
2371
2387
  canvasModules,
2388
+ incremental = false,
2372
2389
  activeStoryboardIds,
2373
2390
  isStoryboardActive
2374
2391
  }) {
@@ -2377,19 +2394,77 @@ function CanvasHost({
2377
2394
  "CanvasHost cannot receive both children and canvasModules."
2378
2395
  );
2379
2396
  }
2380
- const registeredCanvasPaths = useMemo3(
2381
- () => [
2382
- ...new Set(
2383
- canvasModules?.map(({ canvasPath }) => canvasPath.trim()) ?? []
2384
- )
2385
- ].filter(Boolean),
2386
- [canvasModules]
2397
+ const [admitted, setAdmitted] = useState3([]);
2398
+ const pendingAdmissions = useRef3(
2399
+ /* @__PURE__ */ new Map()
2400
+ );
2401
+ const admittedRef = useRef3(admitted);
2402
+ const modules = useMemo3(() => {
2403
+ const all = new Map(
2404
+ canvasModules?.map((module) => [module.canvasPath, module])
2405
+ );
2406
+ for (const module of admitted)
2407
+ if (!all.has(module.canvasPath)) all.set(module.canvasPath, module);
2408
+ return [...all.values()];
2409
+ }, [canvasModules, admitted]);
2410
+ const registerCanvas = useCallback3((canvasPath, rawUrl) => {
2411
+ const url = new URL(rawUrl, window.location.href);
2412
+ if (url.origin !== window.location.origin || !url.pathname.startsWith("/@fs/")) {
2413
+ return Promise.reject(
2414
+ new Error("Canvas registration requires a same-origin Vite module URL")
2415
+ );
2416
+ }
2417
+ if (admittedRef.current.some((module) => module.canvasPath === canvasPath))
2418
+ return Promise.resolve();
2419
+ return new Promise((resolve, reject) => {
2420
+ const pending = pendingAdmissions.current.get(canvasPath) ?? [];
2421
+ pending.push({ resolve, reject });
2422
+ pendingAdmissions.current.set(canvasPath, pending);
2423
+ setAdmitted(
2424
+ (current) => current.some((module) => module.canvasPath === canvasPath) ? current : [
2425
+ ...current,
2426
+ { canvasPath, load: () => import(
2427
+ /* @vite-ignore */
2428
+ url.href
2429
+ ) }
2430
+ ]
2431
+ );
2432
+ });
2433
+ }, []);
2434
+ useLayoutEffect3(() => {
2435
+ admittedRef.current = admitted;
2436
+ for (const module of admitted) {
2437
+ const pending = pendingAdmissions.current.get(module.canvasPath);
2438
+ pendingAdmissions.current.delete(module.canvasPath);
2439
+ pending?.forEach(({ resolve }) => resolve());
2440
+ }
2441
+ }, [admitted]);
2442
+ useEffect3(
2443
+ () => () => {
2444
+ for (const pending of pendingAdmissions.current.values())
2445
+ pending.forEach(
2446
+ ({ reject }) => reject(new Error("Canvas host disposed during registration"))
2447
+ );
2448
+ pendingAdmissions.current.clear();
2449
+ },
2450
+ []
2387
2451
  );
2388
2452
  const directUrlSearch = useSyncExternalStore(
2389
2453
  subscribeDirectUrlSearch,
2390
2454
  readDirectUrlSearch,
2391
2455
  () => ""
2392
2456
  );
2457
+ const demandRegistration = incremental && new URLSearchParams(directUrlSearch).get("canvasRegistration") === "incremental";
2458
+ const registeredCanvasPaths = useMemo3(
2459
+ () => [
2460
+ ...new Set(
2461
+ (demandRegistration ? admitted : modules).map(
2462
+ ({ canvasPath }) => canvasPath.trim()
2463
+ )
2464
+ )
2465
+ ].filter(Boolean),
2466
+ [modules, admitted, demandRegistration]
2467
+ );
2393
2468
  const directUrlRender = useMemo3(() => {
2394
2469
  return readDirectUrlRender();
2395
2470
  }, [directUrlSearch]);
@@ -2405,7 +2480,8 @@ function CanvasHost({
2405
2480
  registerCanvasProblemScope
2406
2481
  } = useCanvasHostPostMessage(
2407
2482
  registeredCanvasPaths,
2408
- directUrlRender?.renderId ?? null
2483
+ directUrlRender?.renderId ?? null,
2484
+ incremental ? registerCanvas : void 0
2409
2485
  );
2410
2486
  useEffect3(() => {
2411
2487
  if (typeof document === "undefined") return;
@@ -2420,10 +2496,14 @@ function CanvasHost({
2420
2496
  [directUrlSearch]
2421
2497
  );
2422
2498
  const mountedCanvasModules = useMemo3(
2423
- () => directUrlIdle ? [] : directUrlRender ? canvasModules?.filter(
2499
+ () => directUrlIdle ? [] : directUrlRender ? modules.filter(
2424
2500
  ({ canvasPath }) => canvasPath.trim() === directUrlRender.canvasPath
2425
- ) : canvasModules,
2426
- [canvasModules, directUrlIdle, directUrlRender]
2501
+ ) : demandRegistration ? modules.filter(
2502
+ (module) => admitted.some(
2503
+ (entry) => entry.canvasPath === module.canvasPath
2504
+ )
2505
+ ) : modules,
2506
+ [modules, admitted, demandRegistration, directUrlIdle, directUrlRender]
2427
2507
  );
2428
2508
  const runtime = useMemo3(
2429
2509
  () => ({