tempo-sdk 0.0.51 → 0.0.57
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/assets/editor.d.ts +1 -1
- package/dist/assets/editor.js +1 -1
- package/dist/assets/index.d.ts +3 -3
- package/dist/assets/index.js +4 -2
- package/dist/assets/index.js.map +1 -1
- package/dist/assets/parser.d.ts +10 -4
- package/dist/assets/parser.js +1 -1
- package/dist/canvas/editor.d.ts +11 -16
- package/dist/canvas/editor.js +79 -49
- package/dist/canvas/editor.js.map +1 -1
- package/dist/canvas/index.d.ts +15 -11
- package/dist/canvas/index.js +130 -47
- package/dist/canvas/index.js.map +1 -1
- package/dist/canvas/interact-projection.js +4 -3
- package/dist/canvas/parser.d.ts +10 -5
- package/dist/canvas/parser.js +3 -1
- package/dist/canvas/svelte.d.ts +9 -7
- package/dist/canvas/svelte.js +20 -5
- package/dist/canvas/svelte.js.map +1 -1
- package/dist/chunk-2IQD2KPS.js +219 -0
- package/dist/chunk-2IQD2KPS.js.map +1 -0
- package/dist/chunk-5BHIHP25.js +410 -0
- package/dist/chunk-5BHIHP25.js.map +1 -0
- package/dist/chunk-EMYYTS6D.js +1585 -0
- package/dist/chunk-EMYYTS6D.js.map +1 -0
- package/dist/{chunk-DX6XAXCK.js → chunk-N2TYN3RB.js} +189 -420
- package/dist/chunk-N2TYN3RB.js.map +1 -0
- package/dist/{chunk-LFYKJJC5.js → chunk-QXL6GL2P.js} +18 -3
- package/dist/chunk-QXL6GL2P.js.map +1 -0
- package/dist/{chunk-QP2NTODB.js → chunk-RHHVVWAC.js} +115 -25
- package/dist/chunk-RHHVVWAC.js.map +1 -0
- package/dist/chunk-TL4MGN7E.js +2570 -0
- package/dist/chunk-TL4MGN7E.js.map +1 -0
- package/dist/{chunk-PULSTDX2.js → chunk-U3SLJNRS.js} +284 -46
- package/dist/chunk-U3SLJNRS.js.map +1 -0
- package/dist/{chunk-ZZYNOX24.js → chunk-U64AHDHZ.js} +1708 -2461
- package/dist/chunk-U64AHDHZ.js.map +1 -0
- package/dist/{chunk-O65OD3NA.js → chunk-XLEKCOB7.js} +6 -5
- package/dist/chunk-XLEKCOB7.js.map +1 -0
- package/dist/expo/plugin.cjs +1256 -16
- package/dist/expo/plugin.cjs.map +1 -1
- package/dist/expo/plugin.d.cts +0 -1
- package/dist/expo/plugin.d.ts +0 -1
- package/dist/expo/plugin.js +1 -1
- package/dist/expo-babel-plugin.cjs +1258 -16
- package/dist/expo-babel-plugin.cjs.map +1 -1
- package/dist/expo-babel-plugin.d.cts +8 -5
- package/dist/expo-babel-plugin.d.ts +8 -5
- package/dist/expo-babel-plugin.js +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +464 -154
- package/dist/index.js.map +1 -1
- package/dist/nextjs/plugin.cjs +151 -0
- package/dist/nextjs/plugin.cjs.map +1 -1
- package/dist/nextjs/plugin.d.cts +1 -1
- package/dist/nextjs/plugin.d.ts +1 -1
- package/dist/nextjs/plugin.js +1 -1
- package/dist/nextjs-loader.cjs +1432 -35
- package/dist/nextjs-loader.cjs.map +1 -1
- package/dist/nextjs.cjs +17 -2
- package/dist/nextjs.cjs.map +1 -1
- package/dist/nextjs.d.cts +14 -3
- package/dist/nextjs.d.ts +14 -3
- package/dist/nextjs.js +1 -1
- package/dist/{page-xi1aI5a7.d.ts → page-DwLnOM5d.d.ts} +12 -6
- package/dist/{storyboard-CBHki7Aw.d.ts → storyboard-BtQuVGpl.d.ts} +35 -17
- package/dist/svelte.d.ts +3 -2
- package/dist/svelte.js +103 -29
- package/dist/svelte.js.map +1 -1
- package/dist/{types-C7cvcY6T.d.ts → types-C8OIU-kc.d.ts} +1 -1
- package/dist/v1-client-compat-qxaXEDm_.d.ts +23 -0
- package/package.json +5 -2
- package/dist/chunk-57KAYXHF.js +0 -19
- package/dist/chunk-57KAYXHF.js.map +0 -1
- package/dist/chunk-CB5NJJJT.js +0 -345
- package/dist/chunk-CB5NJJJT.js.map +0 -1
- package/dist/chunk-DX6XAXCK.js.map +0 -1
- package/dist/chunk-F3KJDCMU.js +0 -19
- package/dist/chunk-F3KJDCMU.js.map +0 -1
- package/dist/chunk-LFYKJJC5.js.map +0 -1
- package/dist/chunk-O65OD3NA.js.map +0 -1
- package/dist/chunk-PULSTDX2.js.map +0 -1
- package/dist/chunk-QP2NTODB.js.map +0 -1
- package/dist/chunk-ZZYNOX24.js.map +0 -1
package/dist/assets/editor.d.ts
CHANGED
package/dist/assets/editor.js
CHANGED
package/dist/assets/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
1
2
|
import { ComponentType, ComponentProps, ReactNode } from 'react';
|
|
2
|
-
import
|
|
3
|
-
import { S as StaticValue } from '../types-C7cvcY6T.js';
|
|
3
|
+
import { S as StaticValue } from '../types-C8OIU-kc.js';
|
|
4
4
|
|
|
5
5
|
/** Browser-safe control definitions shared by authoring, parsing and the editor. */
|
|
6
6
|
type AssetOption = string | number | boolean;
|
|
@@ -67,7 +67,7 @@ type AssetControls<P> = {
|
|
|
67
67
|
declare function AssetLivePreview({ component, sessionId, }: {
|
|
68
68
|
component: ComponentType<any>;
|
|
69
69
|
sessionId: string;
|
|
70
|
-
}):
|
|
70
|
+
}): react.JSX.Element;
|
|
71
71
|
|
|
72
72
|
declare function getComponentControlsSnapshot(component: unknown): StaticValue;
|
|
73
73
|
declare function getAssetConfigSnapshot(component: unknown): StaticValue;
|
package/dist/assets/index.js
CHANGED
package/dist/assets/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../assets/prop-overrides.ts","../../assets/live-preview.tsx","../../assets/snapshot.ts","../../assets/preview-snapshot.ts","../../assets/index.ts"],"sourcesContent":["/** Internal, JSON-safe omission marker. Never emitted as a component prop. */\nexport const OMIT_ASSET_PROP = { __tempo_omit_prop__: true } as const;\n\nexport function applyPropOverrides<T>(\n props: Readonly<Record<string, T>>,\n edits?: Readonly<Record<string, T>>,\n): Record<string, T> {\n const result = { ...props };\n for (const [name, value] of Object.entries(edits ?? {})) {\n if (\n value &&\n typeof value === \"object\" &&\n Object.keys(value).length === 1 &&\n (value as Record<string, unknown>).__tempo_omit_prop__ === true\n ) {\n delete result[name];\n } else\n Object.defineProperty(result, name, {\n value,\n enumerable: true,\n configurable: true,\n writable: true,\n });\n }\n return result;\n}\n","import { applyPropOverrides } from \"./prop-overrides\";\nimport {\n Component,\n createElement,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n type ComponentType,\n type ReactNode,\n} from \"react\";\nimport {\n getAssetConfig,\n type AssetDefinitionVariant,\n} from \"./index\";\nimport { getAssetConfigSnapshot } from \"./snapshot\";\nimport { captureAssetPreview } from \"./preview-snapshot\";\n\nexport const ASSET_PREVIEW_MESSAGE = \"tempo:asset-live-preview\";\n\nexport type AssetLivePreviewUpdate = {\n variant: string | null;\n edits: Record<string, unknown>;\n};\n\nclass PreviewBoundary extends Component<\n {\n children: ReactNode;\n update: AssetLivePreviewUpdate;\n },\n { error: string | null; update: AssetLivePreviewUpdate | null }\n> {\n state = {\n error: null as string | null,\n update: null as AssetLivePreviewUpdate | null,\n };\n static getDerivedStateFromProps(\n props: { update: AssetLivePreviewUpdate },\n state: { update: AssetLivePreviewUpdate | null },\n ) {\n return props.update !== state.update\n ? { update: props.update, error: null }\n : null;\n }\n static getDerivedStateFromError(error: Error) {\n return { error: error.message };\n }\n render() {\n return this.state.error ? (\n <p role=\"alert\" style={{ padding: 12, fontSize: 12 }}>\n {this.state.error}\n </p>\n ) : (\n this.props.children\n );\n }\n}\n\n/** One mounted component, driven by its editor. No file writes or captures on\n * variant/prop changes. Imports and source updates remain owned by Vite. */\nexport function AssetLivePreview({\n component,\n sessionId,\n}: {\n component: ComponentType<any>;\n sessionId: string;\n}) {\n const [update, setUpdate] = useState<AssetLivePreviewUpdate>({\n variant: null,\n edits: {},\n });\n const peer = useRef<{ origin: string } | null>(null);\n const viewport = useRef<HTMLDivElement>(null);\n const contentRoot = useRef<HTMLDivElement>(null);\n const [fit, setFit] = useState({ width: 0, height: 0, scale: 1 });\n const boundary = useRef<PreviewBoundary>(null);\n const [captureRequest, setCaptureRequest] = useState<string | null>(null);\n const lastMetadata = useRef(\"\");\n useLayoutEffect(() => {\n const frame = viewport.current!;\n const content = contentRoot.current!;\n const measure = () => {\n // Measure layout dimensions, not the transformed preview. The same\n // 16px inset and no-upscaling rule apply to its cached screenshot.\n const width = content.offsetWidth;\n const height = content.offsetHeight;\n const scale = Math.min(\n 1,\n Math.max(0, frame.clientWidth - 32) / (width || 1),\n Math.max(0, frame.clientHeight - 32) / (height || 1),\n );\n setFit((previous) =>\n previous.width === width &&\n previous.height === height &&\n previous.scale === scale\n ? previous\n : { width, height, scale },\n );\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(frame);\n observer.observe(content);\n return () => observer.disconnect();\n }, []);\n const publish = () => {\n if (!peer.current) return;\n const metadata = getAssetConfigSnapshot(component);\n const serialized = JSON.stringify(metadata);\n if (lastMetadata.current === serialized) return;\n lastMetadata.current = serialized;\n window.parent.postMessage(\n {\n type: ASSET_PREVIEW_MESSAGE,\n sessionId,\n kind: \"metadata\",\n metadata,\n captureVersion: 1,\n },\n peer.current.origin,\n );\n };\n const publishRef = useRef(publish);\n publishRef.current = publish;\n useEffect(() => {\n const receive = (event: MessageEvent) => {\n if (\n event.source !== window.parent ||\n event.data?.type !== ASSET_PREVIEW_MESSAGE ||\n event.data.sessionId !== sessionId\n )\n return;\n if (event.data.kind === \"connect\") {\n peer.current = { origin: event.origin === \"null\" ? \"*\" : event.origin };\n lastMetadata.current = \"\";\n publishRef.current();\n } else if (\n (event.data.kind === \"update\" || event.data.kind === \"capture\") &&\n peer.current\n ) {\n const next = event.data.update;\n if (\n next &&\n (next.variant === null || typeof next.variant === \"string\") &&\n next.edits &&\n typeof next.edits === \"object\" &&\n !Array.isArray(next.edits)\n ) {\n setUpdate(next);\n if (\n event.data.kind === \"capture\" &&\n typeof event.data.requestId === \"string\"\n )\n setCaptureRequest(event.data.requestId);\n }\n }\n };\n window.addEventListener(\"message\", receive);\n // The parent may have received iframe.load before this lazy storyboard mounted.\n window.parent.postMessage(\n { type: ASSET_PREVIEW_MESSAGE, sessionId, kind: \"ready\" },\n \"*\",\n );\n return () => window.removeEventListener(\"message\", receive);\n }, [sessionId]);\n useLayoutEffect(() => {\n if (!captureRequest || !peer.current) return;\n // Capture after React has committed the EXACT props from the request, even\n // when Insert follows the last keystroke before its update message arrived.\n const frame = requestAnimationFrame(() => {\n let snapshot = null;\n try {\n if (contentRoot.current && !boundary.current?.state.error)\n snapshot = captureAssetPreview(contentRoot.current);\n } catch {\n // Snapshotting is an optimization; an unusual DOM must not block Add.\n }\n window.parent.postMessage(\n {\n type: ASSET_PREVIEW_MESSAGE,\n sessionId,\n kind: \"captured\",\n requestId: captureRequest,\n snapshot,\n },\n peer.current!.origin,\n );\n setCaptureRequest(null);\n });\n return () => cancelAnimationFrame(frame);\n }, [captureRequest, update, sessionId]);\n // A hot update can change metadata without changing the component identity.\n useEffect(publish);\n const config = getAssetConfig(component);\n const variant = (\n update.variant &&\n Object.prototype.hasOwnProperty.call(config?.variants ?? {}, update.variant)\n ? config?.variants?.[update.variant]\n : undefined\n ) as AssetDefinitionVariant<Record<string, unknown>> | undefined;\n const render =\n variant && \"render\" in variant ? variant.render : undefined;\n const content =\n update.variant === null\n ? null\n : render\n ? createElement(render)\n : createElement(\n component,\n applyPropOverrides(variant?.props ?? {}, update.edits),\n );\n return (\n <div\n ref={viewport}\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n overflow: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 16,\n boxSizing: \"border-box\",\n }}\n >\n <div\n style={{\n position: \"relative\",\n flexShrink: 0,\n width: fit.width * fit.scale,\n height: fit.height * fit.scale,\n }}\n >\n <div\n ref={contentRoot}\n style={{\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"max-content\",\n height: \"max-content\",\n transform: `scale(${fit.scale})`,\n transformOrigin: \"top left\",\n }}\n >\n <PreviewBoundary ref={boundary} update={update}>\n {content}\n </PreviewBoundary>\n </div>\n </div>\n </div>\n );\n}\n","import { getAssetConfig, getComponentControls } from \"./index\";\nimport { UNRESOLVED_VALUE, type StaticValue } from \"./types\";\n\n/** Browser-side metadata transport. Unsupported values stay visible; JSON must\n * never silently drop a function, JSX child, cyclic object, or undefined prop. */\nfunction snapshot(value: unknown): StaticValue {\n function copy(value: unknown, seen: Set<object>, depth: number): StaticValue {\n if (\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"boolean\"\n )\n return value;\n if (typeof value === \"number\")\n return Number.isFinite(value) ? value : UNRESOLVED_VALUE;\n if (!value || typeof value !== \"object\" || depth > 16 || seen.has(value))\n return UNRESOLVED_VALUE;\n if (\n !Array.isArray(value) &&\n Object.getPrototypeOf(value) !== Object.prototype &&\n Object.getPrototypeOf(value) !== null\n )\n return UNRESOLVED_VALUE;\n if (\"$$typeof\" in value) return UNRESOLVED_VALUE;\n const next = new Set(seen).add(value);\n if (Array.isArray(value))\n return value.map((item) => copy(item, next, depth + 1));\n return Object.fromEntries(\n Object.entries(value).map(([key, child]) => [\n key,\n copy(child, next, depth + 1),\n ]),\n );\n }\n return copy(value, new Set(), 0);\n}\n\nexport function getComponentControlsSnapshot(component: unknown): StaticValue {\n return snapshot(getComponentControls(component));\n}\nexport function getAssetConfigSnapshot(component: unknown): StaticValue {\n return snapshot({\n asset: getAssetConfig(component),\n ...getComponentControls(component),\n });\n}\n","import { capture } from \"../../../modules/iframe-projection/html/capture\";\nimport { captureHead } from \"../../../modules/iframe-projection/html/watch-head\";\n\n/** Rendered markup, not React state or executable code. Source identities are\n * rebound by the editor only after it knows where the insertion will land. */\nexport type AssetPreviewSnapshot = {\n html: string;\n width: number;\n height: number;\n};\n\n/** One cold read on insert/drag, never a second continuous projection watch. */\nexport function captureAssetPreview(\n root: HTMLElement,\n): AssetPreviewSnapshot | null {\n if (\n !root.firstElementChild ||\n root.querySelector(\"[data-tempo-projection-pending]\")\n )\n return null;\n // The preview may be scaled down to fit its window. Insertion keeps the\n // component's natural layout size and captures only its inner markup.\n const width = root.offsetWidth;\n const height = root.offsetHeight;\n if (width <= 0 || height <= 0) return null;\n const captured = capture(root);\n const doc = root.ownerDocument.implementation.createHTMLDocument(\"\");\n for (const [name, value] of Object.entries(\n captured.dom.documentElementAttributes ?? {},\n ))\n doc.documentElement.setAttribute(name, value);\n for (const [name, value] of Object.entries(captured.dom.bodyAttributes ?? {}))\n doc.body.setAttribute(name, value);\n doc.head.innerHTML = captureHead(root.ownerDocument);\n const base = doc.createElement(\"base\");\n base.href = root.ownerDocument.baseURI;\n doc.head.prepend(base);\n doc.body.innerHTML = captured.dom.html;\n return {\n html: `<!DOCTYPE html>${doc.documentElement.outerHTML}`,\n width,\n height,\n };\n}\n","/**\n * tempo-sdk/assets — runtime authoring surface for asset declarations.\n *\n * `defineAsset(Component, { ... })` marks a component (or canvas component)\n * as a design asset: library membership, usage instructions, and named prop\n * variants. `defineControls` independently describes prop editors. Tempo\n * discovers assets statically and reads explicit controls from the running\n * component. Source analysis supplies prop types and portable JSX for insertion.\n *\n * This subpath must stay browser-safe (no node imports): user component\n * files import it from app code, unlike the root entry's Vite plugin.\n * See specs/asset-libraries.md §2.\n */\nimport type { ComponentProps, ComponentType, ReactNode } from \"react\";\nimport type { AssetComponentProps, AssetControls } from \"./controls\";\nexport { AssetLivePreview } from \"./live-preview\";\nexport type {\n AssetControlDefinition,\n AssetControls,\n AssetPropControl,\n} from \"./controls\";\n\n/** Property key `defineAsset` attaches its config under. Non-enumerable so it\n * never leaks into spreads or serialization of the component value. */\nexport const TEMPO_ASSET_CONFIG_PROPERTY = \"__tempoAssetConfig\";\n\nexport type AssetVariant<P> = {\n /** Must satisfy the component's prop types. Kept required for source\n * compatibility with the original public asset-reader contract. */\n props: P;\n};\n\nexport type AssetRenderVariant = {\n props?: never;\n render: () => ReactNode;\n};\n\nexport type AssetDefinitionVariant<P> =\n | (AssetVariant<P> & { render?: never })\n | AssetRenderVariant;\n\nexport type AssetVariants<P> = Record<string, AssetVariant<P>>;\n\nexport type AssetConfigBase = {\n /** What this asset is and when to reach for it — and when not (e.g. \"form\n * submits, CTAs — not navigation (use Link)\"). Shown on the asset detail\n * page and returned by the asset MCP tools. */\n usageInstructions?: string;\n /** Library names this asset belongs to. Arbitrary non-empty strings; a\n * library exists iff some asset names it. Unset/empty = library-less\n * (still an asset, still shown in the Assets tab). */\n libraries?: string[];\n};\n\n/**\n * `variants` is required exactly when the component has required props. This\n * preserves the public reader guarantees from the first published asset API.\n * `defineAsset` also accepts metadata-only and render-only declarations through\n * its additive authoring input below.\n */\nexport type AssetConfig<C extends ComponentType<any>> = AssetConfigBase &\n ({} extends ComponentProps<C>\n ? { variants?: AssetVariants<ComponentProps<C>> }\n : { variants: AssetVariants<ComponentProps<C>> });\n\nexport type AssetDefinitionConfig<C extends ComponentType<any>> =\n AssetConfigBase & {\n variants?: Record<string, AssetDefinitionVariant<ComponentProps<C>>>;\n };\n\n/**\n * Declare a component or canvas as a design asset.\n *\n * Two supported shapes, both top-level statements. Prefer a declaration in a\n * canvas that curates the component — the\n * declaring canvas becomes the component's linked canvas:\n *\n * import { Button } from \"@/components/Button\";\n *\n * defineAsset(Button, {\n * usageInstructions: \"form submits, CTAs — not navigation (use Link)\",\n * variants: { Primary: { props: { label: \"Buy now\" } } },\n * });\n *\n * A legacy shape is the same statement in the file that defines the\n * component, placed after its definition — keeps working:\n *\n * export const Button = ({ label }: ButtonProps) => <button>{label}</button>;\n *\n * defineAsset(Button, {\n * libraries: [\"core\"],\n * variants: { Primary: { props: { label: \"Buy now\" } } },\n * });\n *\n * Returns void deliberately: `export default defineAsset(App, {...})` would\n * turn the export into a call expression and break React Fast Refresh's\n * component-only export analysis, so the wrapper form is a type error.\n */\nexport function defineAsset<C extends ComponentType<any>>(\n component: C,\n config: AssetDefinitionConfig<C>,\n): void {\n try {\n // Re-runs on every hot update, re-attaching the current config —\n // configurable so the redefinition is legal.\n Object.defineProperty(component, TEMPO_ASSET_CONFIG_PROPERTY, {\n value: config,\n enumerable: false,\n configurable: true,\n writable: false,\n });\n } catch {\n // Frozen or exotic component values must never crash the user's app.\n }\n}\n\n/** Loosely-typed read shape: callers of getAssetConfig don't know the\n * component's prop types. */\nexport type ReadAssetConfig = AssetConfigBase & {\n variants?: AssetVariants<Record<string, unknown>>;\n};\n\n/** Read a config previously attached by `defineAsset`, if any. */\nexport function getAssetConfig(\n component: unknown,\n): ReadAssetConfig | undefined {\n if (\n (typeof component !== \"function\" && typeof component !== \"object\") ||\n component === null\n ) {\n return undefined;\n }\n const config = (component as Record<string, unknown>)[\n TEMPO_ASSET_CONFIG_PROPERTY\n ];\n return config === undefined\n ? (config as undefined)\n : (config as ReadAssetConfig);\n}\n\nexport {\n getAssetConfigSnapshot,\n getComponentControlsSnapshot,\n} from \"./snapshot\";\n\nexport type ComponentControls<P> = AssetControls<P>;\nexport type ComponentControlsTarget = {\n filePath: string;\n name: string;\n exportName?: string;\n};\nexport const TEMPO_CONTROLS_CONFIG_PROPERTY = \"__tempoControlsConfig\";\n\ntype ControlsRegistration = {\n controls: Record<string, import(\"./controls\").AssetControlDefinition>;\n};\n\n/** Describe real prop editors once, independently of assets and libraries.\n * New components keep this call in their own file. Existing components may use\n * tempo/controls.ts to avoid editing app source. Both work across every canvas.\n * Legacy canvas declarations remain supported.\n * The returned cleanup is used by Tempo's development transform during HMR.\n */\nexport function defineControls<\n C extends ComponentType<any>,\n const Controls extends AssetControls<ComponentProps<NoInfer<C>>>,\n>(\n component: C,\n controls: Controls &\n Record<\n Exclude<\n keyof Controls,\n keyof AssetComponentProps<ComponentProps<NoInfer<C>>>\n >,\n never\n >,\n): () => void {\n const registration = { controls } as ControlsRegistration;\n let registrations: Set<ControlsRegistration>;\n try {\n const previous = (component as unknown as Record<string, unknown>)[\n TEMPO_CONTROLS_CONFIG_PROPERTY\n ] as Set<ControlsRegistration> | undefined;\n registrations = previous ?? new Set();\n registrations.add(registration);\n Object.defineProperty(component, TEMPO_CONTROLS_CONFIG_PROPERTY, {\n value: registrations,\n enumerable: false,\n configurable: true,\n });\n } catch {\n /* Frozen components still render; use a local wrapper to attach controls. */\n return () => {};\n }\n return () => registrations.delete(registration);\n}\n\nexport function getComponentControls(component: unknown): {\n controls?: Record<string, import(\"./controls\").AssetControlDefinition>;\n error?: string;\n} {\n if (\n !component ||\n (typeof component !== \"function\" && typeof component !== \"object\")\n )\n return {};\n const registrations = (component as Record<string, unknown>)[\n TEMPO_CONTROLS_CONFIG_PROPERTY\n ] as Set<ControlsRegistration> | undefined;\n if (!registrations?.size) return {};\n if (registrations.size > 1)\n return {\n error:\n \"Multiple defineControls declarations for this component. Keep one declaration in the component file or tempo/controls.ts; remove the duplicate.\",\n };\n return registrations.values().next().value ?? {};\n}\n"],"mappings":";;;;;;;;;AAGO,SAAS,mBACd,OACA,OACmB;AACnB,QAAM,SAAS,EAAE,GAAG,MAAM;AAC1B,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,SAAS,CAAC,CAAC,GAAG;AACvD,QACE,SACA,OAAO,UAAU,YACjB,OAAO,KAAK,KAAK,EAAE,WAAW,KAC7B,MAAkC,wBAAwB,MAC3D;AACA,aAAO,OAAO,IAAI;AAAA,IACpB;AACE,aAAO,eAAe,QAAQ,MAAM;AAAA,QAClC;AAAA,QACA,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,UAAU;AAAA,MACZ,CAAC;AAAA,EACL;AACA,SAAO;AACT;;;ACxBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;;;ACLP,SAAS,SAAS,OAA6B;AAC7C,WAAS,KAAKA,QAAgB,MAAmB,OAA4B;AAC3E,QACEA,WAAU,QACV,OAAOA,WAAU,YACjB,OAAOA,WAAU;AAEjB,aAAOA;AACT,QAAI,OAAOA,WAAU;AACnB,aAA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ACM;AACN,MAAI;AAGF,WAAO,eAAe,WAAW,6BAA6B;AAAA,MAC5D,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,cAAc;AAAA,MACd,UAAU;AAAA,IACZ,CAAC;AAAA,EACH,QAAQ;AAAA,EAER;AACF;AASO,SAAS,eACd,WAC6B;AAC7B,MACG,OAAO,cAAc,cAAc,OAAO,cAAc,YACzD,cAAc,MACd;AACA,WAAO;AAAA,EACT;AACA,QAAM,SAAU,UACd,2BACF;AACA,SAAO,WAAW,SACb,SACA;AACP;AAaO,IAAM,iCAAiC;AAYvC,SAAS,eAId,WACA,UAQY;AACZ,QAAM,eAAe,EAAE,SAAS;AAChC,MAAI;AACJ,MAAI;AACF,UAAM,WAAY,UAChB,8BACF;AACA,oBAAgB,YAAY,oBAAI,IAAI;AACpC,kBAAc,IAAI,YAAY;AAC9B,WAAO,eAAe,WAAW,gCAAgC;AAAA,MAC/D,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,cAAc;AAAA,IAChB,CAAC;AAAA,EACH,QAAQ;AAEN,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AACA,SAAO,MAAM,cAAc,OAAO,YAAY;AAChD;AAEO,SAAS,qBAAqB,WAGnC;AACA,MACE,CAAC,aACA,OAAO,cAAc,cAAc,OAAO,cAAc;AAEzD,WAAO,CAAC;AACV,QAAM,gBAAiB,UACrB,8BACF;AACA,MAAI,CAAC,eAAe,KAAM,QAAO,CAAC;AAClC,MAAI,cAAc,OAAO;AACvB,WAAO;AAAA,MACL,OACE;AAAA,IACJ;AACF,SAAO,cAAc,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC;AACjD;","names":["value","content","snapshot"]}
|
|
1
|
+
{"version":3,"sources":["../../assets/prop-overrides.ts","../../assets/live-preview.tsx","../../assets/snapshot.ts","../../assets/preview-snapshot.ts","../../assets/index.ts"],"sourcesContent":["/** Internal, JSON-safe omission marker. Never emitted as a component prop. */\nexport const OMIT_ASSET_PROP = { __tempo_omit_prop__: true } as const;\n\nexport function applyPropOverrides<T>(\n props: Readonly<Record<string, T>>,\n edits?: Readonly<Record<string, T>>,\n): Record<string, T> {\n const result = { ...props };\n for (const [name, value] of Object.entries(edits ?? {})) {\n if (\n value &&\n typeof value === \"object\" &&\n Object.keys(value).length === 1 &&\n (value as Record<string, unknown>).__tempo_omit_prop__ === true\n ) {\n delete result[name];\n } else\n Object.defineProperty(result, name, {\n value,\n enumerable: true,\n configurable: true,\n writable: true,\n });\n }\n return result;\n}\n","import { applyPropOverrides } from \"./prop-overrides\";\nimport {\n Component,\n createElement,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n type ComponentType,\n type ReactNode,\n} from \"react\";\nimport {\n getAssetConfig,\n type AssetDefinitionVariant,\n} from \"./index\";\nimport { getAssetConfigSnapshot } from \"./snapshot\";\nimport { captureAssetPreview } from \"./preview-snapshot\";\n\nexport const ASSET_PREVIEW_MESSAGE = \"tempo:asset-live-preview\";\n\nexport type AssetLivePreviewUpdate = {\n variant: string | null;\n edits: Record<string, unknown>;\n};\n\nclass PreviewBoundary extends Component<\n {\n children: ReactNode;\n update: AssetLivePreviewUpdate;\n },\n { error: string | null; update: AssetLivePreviewUpdate | null }\n> {\n state = {\n error: null as string | null,\n update: null as AssetLivePreviewUpdate | null,\n };\n static getDerivedStateFromProps(\n props: { update: AssetLivePreviewUpdate },\n state: { update: AssetLivePreviewUpdate | null },\n ) {\n return props.update !== state.update\n ? { update: props.update, error: null }\n : null;\n }\n static getDerivedStateFromError(error: Error) {\n return { error: error.message };\n }\n render() {\n return this.state.error ? (\n <p role=\"alert\" style={{ padding: 12, fontSize: 12 }}>\n {this.state.error}\n </p>\n ) : (\n this.props.children\n );\n }\n}\n\n/** One mounted component, driven by its editor. No file writes or captures on\n * variant/prop changes. Imports and source updates remain owned by Vite. */\nexport function AssetLivePreview({\n component,\n sessionId,\n}: {\n component: ComponentType<any>;\n sessionId: string;\n}) {\n const [update, setUpdate] = useState<AssetLivePreviewUpdate>({\n variant: null,\n edits: {},\n });\n const peer = useRef<{ origin: string } | null>(null);\n const viewport = useRef<HTMLDivElement>(null);\n const contentRoot = useRef<HTMLDivElement>(null);\n const [fit, setFit] = useState({ width: 0, height: 0, scale: 1 });\n const boundary = useRef<PreviewBoundary>(null);\n const [captureRequest, setCaptureRequest] = useState<string | null>(null);\n const lastMetadata = useRef(\"\");\n useLayoutEffect(() => {\n const frame = viewport.current!;\n const content = contentRoot.current!;\n const measure = () => {\n // Measure layout dimensions, not the transformed preview. The same\n // 16px inset and no-upscaling rule apply to its cached screenshot.\n const width = content.offsetWidth;\n const height = content.offsetHeight;\n const scale = Math.min(\n 1,\n Math.max(0, frame.clientWidth - 32) / (width || 1),\n Math.max(0, frame.clientHeight - 32) / (height || 1),\n );\n setFit((previous) =>\n previous.width === width &&\n previous.height === height &&\n previous.scale === scale\n ? previous\n : { width, height, scale },\n );\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(frame);\n observer.observe(content);\n return () => observer.disconnect();\n }, []);\n const publish = () => {\n if (!peer.current) return;\n const metadata = getAssetConfigSnapshot(component);\n const serialized = JSON.stringify(metadata);\n if (lastMetadata.current === serialized) return;\n lastMetadata.current = serialized;\n window.parent.postMessage(\n {\n type: ASSET_PREVIEW_MESSAGE,\n sessionId,\n kind: \"metadata\",\n metadata,\n captureVersion: 1,\n },\n peer.current.origin,\n );\n };\n const publishRef = useRef(publish);\n publishRef.current = publish;\n useEffect(() => {\n const receive = (event: MessageEvent) => {\n if (\n event.source !== window.parent ||\n event.data?.type !== ASSET_PREVIEW_MESSAGE ||\n event.data.sessionId !== sessionId\n )\n return;\n if (event.data.kind === \"connect\") {\n peer.current = { origin: event.origin === \"null\" ? \"*\" : event.origin };\n lastMetadata.current = \"\";\n publishRef.current();\n } else if (\n (event.data.kind === \"update\" || event.data.kind === \"capture\") &&\n peer.current\n ) {\n const next = event.data.update;\n if (\n next &&\n (next.variant === null || typeof next.variant === \"string\") &&\n next.edits &&\n typeof next.edits === \"object\" &&\n !Array.isArray(next.edits)\n ) {\n setUpdate(next);\n if (\n event.data.kind === \"capture\" &&\n typeof event.data.requestId === \"string\"\n )\n setCaptureRequest(event.data.requestId);\n }\n }\n };\n window.addEventListener(\"message\", receive);\n // The parent may have received iframe.load before this lazy storyboard mounted.\n window.parent.postMessage(\n { type: ASSET_PREVIEW_MESSAGE, sessionId, kind: \"ready\" },\n \"*\",\n );\n return () => window.removeEventListener(\"message\", receive);\n }, [sessionId]);\n useLayoutEffect(() => {\n if (!captureRequest || !peer.current) return;\n // Capture after React has committed the EXACT props from the request, even\n // when Insert follows the last keystroke before its update message arrived.\n const frame = requestAnimationFrame(() => {\n let snapshot = null;\n try {\n if (contentRoot.current && !boundary.current?.state.error)\n snapshot = captureAssetPreview(contentRoot.current);\n } catch {\n // Snapshotting is an optimization; an unusual DOM must not block Add.\n }\n window.parent.postMessage(\n {\n type: ASSET_PREVIEW_MESSAGE,\n sessionId,\n kind: \"captured\",\n requestId: captureRequest,\n snapshot,\n },\n peer.current!.origin,\n );\n setCaptureRequest(null);\n });\n return () => cancelAnimationFrame(frame);\n }, [captureRequest, update, sessionId]);\n // A hot update can change metadata without changing the component identity.\n useEffect(publish);\n const config = getAssetConfig(component);\n const variant = (\n update.variant &&\n Object.prototype.hasOwnProperty.call(config?.variants ?? {}, update.variant)\n ? config?.variants?.[update.variant]\n : undefined\n ) as AssetDefinitionVariant<Record<string, unknown>> | undefined;\n const render =\n variant && \"render\" in variant ? variant.render : undefined;\n const content =\n update.variant === null\n ? null\n : render\n ? createElement(render)\n : createElement(\n component,\n applyPropOverrides(variant?.props ?? {}, update.edits),\n );\n return (\n <div\n ref={viewport}\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n overflow: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 16,\n boxSizing: \"border-box\",\n }}\n >\n <div\n style={{\n position: \"relative\",\n flexShrink: 0,\n width: fit.width * fit.scale,\n height: fit.height * fit.scale,\n }}\n >\n <div\n ref={contentRoot}\n style={{\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"max-content\",\n height: \"max-content\",\n transform: `scale(${fit.scale})`,\n transformOrigin: \"top left\",\n }}\n >\n <PreviewBoundary ref={boundary} update={update}>\n {content}\n </PreviewBoundary>\n </div>\n </div>\n </div>\n );\n}\n","import { getAssetConfig, getComponentControls } from \"./index\";\nimport { UNRESOLVED_VALUE, type StaticValue } from \"./types\";\n\n/** Browser-side metadata transport. Unsupported values stay visible; JSON must\n * never silently drop a function, JSX child, cyclic object, or undefined prop. */\nfunction snapshot(value: unknown): StaticValue {\n function copy(value: unknown, seen: Set<object>, depth: number): StaticValue {\n if (\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"boolean\"\n )\n return value;\n if (typeof value === \"number\")\n return Number.isFinite(value) ? value : UNRESOLVED_VALUE;\n if (!value || typeof value !== \"object\" || depth > 16 || seen.has(value))\n return UNRESOLVED_VALUE;\n if (\n !Array.isArray(value) &&\n Object.getPrototypeOf(value) !== Object.prototype &&\n Object.getPrototypeOf(value) !== null\n )\n return UNRESOLVED_VALUE;\n if (\"$$typeof\" in value) return UNRESOLVED_VALUE;\n const next = new Set(seen).add(value);\n if (Array.isArray(value))\n return value.map((item) => copy(item, next, depth + 1));\n return Object.fromEntries(\n Object.entries(value).map(([key, child]) => [\n key,\n copy(child, next, depth + 1),\n ]),\n );\n }\n return copy(value, new Set(), 0);\n}\n\nexport function getComponentControlsSnapshot(component: unknown): StaticValue {\n return snapshot(getComponentControls(component));\n}\nexport function getAssetConfigSnapshot(component: unknown): StaticValue {\n return snapshot({\n asset: getAssetConfig(component),\n ...getComponentControls(component),\n });\n}\n","import { capture } from \"../../../modules/iframe-projection/html/capture\";\nimport { captureHead } from \"../../../modules/iframe-projection/html/watch-head\";\n\n/** Rendered markup, not React state or executable code. Source identities are\n * rebound by the editor only after it knows where the insertion will land. */\nexport type AssetPreviewSnapshot = {\n html: string;\n width: number;\n height: number;\n};\n\n/** One cold read on insert/drag, never a second continuous projection watch. */\nexport function captureAssetPreview(\n root: HTMLElement,\n): AssetPreviewSnapshot | null {\n if (\n !root.firstElementChild ||\n root.querySelector(\"[data-tempo-projection-pending]\")\n )\n return null;\n // The preview may be scaled down to fit its window. Insertion keeps the\n // component's natural layout size and captures only its inner markup.\n const width = root.offsetWidth;\n const height = root.offsetHeight;\n if (width <= 0 || height <= 0) return null;\n const captured = capture(root);\n const doc = root.ownerDocument.implementation.createHTMLDocument(\"\");\n for (const [name, value] of Object.entries(\n captured.dom.documentElementAttributes ?? {},\n ))\n doc.documentElement.setAttribute(name, value);\n for (const [name, value] of Object.entries(captured.dom.bodyAttributes ?? {}))\n doc.body.setAttribute(name, value);\n doc.head.innerHTML = captureHead(root.ownerDocument);\n const base = doc.createElement(\"base\");\n base.href = root.ownerDocument.baseURI;\n doc.head.prepend(base);\n doc.body.innerHTML = captured.dom.html;\n return {\n html: `<!DOCTYPE html>${doc.documentElement.outerHTML}`,\n width,\n height,\n };\n}\n","/**\n * tempo-sdk/assets — runtime authoring surface for asset declarations.\n *\n * `defineAsset(Component, { ... })` marks a component (or canvas component)\n * as a design asset: library membership, usage instructions, and named prop\n * variants. `defineControls` independently describes prop editors. Tempo\n * discovers assets statically and reads explicit controls from the running\n * component. Source analysis supplies prop types and portable JSX for insertion.\n *\n * This subpath must stay browser-safe (no node imports): user component\n * files import it from app code, unlike the root entry's Vite plugin.\n * See specs/asset-libraries.md §2.\n */\nimport type { ComponentProps, ComponentType, ReactNode } from \"react\";\nimport type { AssetComponentProps, AssetControls } from \"./controls\";\nexport { AssetLivePreview } from \"./live-preview\";\nexport type {\n AssetControlDefinition,\n AssetControls,\n AssetPropControl,\n} from \"./controls\";\n\n/** Property key `defineAsset` attaches its config under. Non-enumerable so it\n * never leaks into spreads or serialization of the component value. */\nexport const TEMPO_ASSET_CONFIG_PROPERTY = \"__tempoAssetConfig\";\n\nexport type AssetVariant<P> = {\n /** Must satisfy the component's prop types. Kept required for source\n * compatibility with the original public asset-reader contract. */\n props: P;\n};\n\nexport type AssetRenderVariant = {\n props?: never;\n render: () => ReactNode;\n};\n\nexport type AssetDefinitionVariant<P> =\n | (AssetVariant<P> & { render?: never })\n | AssetRenderVariant;\n\nexport type AssetVariants<P> = Record<string, AssetVariant<P>>;\n\nexport type AssetConfigBase = {\n /** What this asset is and when to reach for it — and when not (e.g. \"form\n * submits, CTAs — not navigation (use Link)\"). Shown on the asset detail\n * page and returned by the asset MCP tools. */\n usageInstructions?: string;\n /** Library names this asset belongs to. Arbitrary non-empty strings; a\n * library exists iff some asset names it. Unset/empty = library-less\n * (still an asset, still shown in the Assets tab). */\n libraries?: string[];\n};\n\n/**\n * `variants` is required exactly when the component has required props. This\n * preserves the public reader guarantees from the first published asset API.\n * `defineAsset` also accepts metadata-only and render-only declarations through\n * its additive authoring input below.\n */\nexport type AssetConfig<C extends ComponentType<any>> = AssetConfigBase &\n ({} extends ComponentProps<C>\n ? { variants?: AssetVariants<ComponentProps<C>> }\n : { variants: AssetVariants<ComponentProps<C>> });\n\nexport type AssetDefinitionConfig<C extends ComponentType<any>> =\n AssetConfigBase & {\n variants?: Record<string, AssetDefinitionVariant<ComponentProps<C>>>;\n };\n\n/**\n * Declare a component or canvas as a design asset.\n *\n * Two supported shapes, both top-level statements. Prefer a declaration in a\n * canvas that curates the component — the\n * declaring canvas becomes the component's linked canvas:\n *\n * import { Button } from \"@/components/Button\";\n *\n * defineAsset(Button, {\n * usageInstructions: \"form submits, CTAs — not navigation (use Link)\",\n * variants: { Primary: { props: { label: \"Buy now\" } } },\n * });\n *\n * A legacy shape is the same statement in the file that defines the\n * component, placed after its definition — keeps working:\n *\n * export const Button = ({ label }: ButtonProps) => <button>{label}</button>;\n *\n * defineAsset(Button, {\n * libraries: [\"core\"],\n * variants: { Primary: { props: { label: \"Buy now\" } } },\n * });\n *\n * Returns void deliberately: `export default defineAsset(App, {...})` would\n * turn the export into a call expression and break React Fast Refresh's\n * component-only export analysis, so the wrapper form is a type error.\n */\nexport function defineAsset<C extends ComponentType<any>>(\n component: C,\n config: AssetDefinitionConfig<C>,\n): void {\n try {\n // Re-runs on every hot update, re-attaching the current config —\n // configurable so the redefinition is legal.\n Object.defineProperty(component, TEMPO_ASSET_CONFIG_PROPERTY, {\n value: config,\n enumerable: false,\n configurable: true,\n writable: false,\n });\n } catch {\n // Frozen or exotic component values must never crash the user's app.\n }\n}\n\n/** Loosely-typed read shape: callers of getAssetConfig don't know the\n * component's prop types. */\nexport type ReadAssetConfig = AssetConfigBase & {\n variants?: AssetVariants<Record<string, unknown>>;\n};\n\n/** Read a config previously attached by `defineAsset`, if any. */\nexport function getAssetConfig(\n component: unknown,\n): ReadAssetConfig | undefined {\n if (\n (typeof component !== \"function\" && typeof component !== \"object\") ||\n component === null\n ) {\n return undefined;\n }\n const config = (component as Record<string, unknown>)[\n TEMPO_ASSET_CONFIG_PROPERTY\n ];\n return config === undefined\n ? (config as undefined)\n : (config as ReadAssetConfig);\n}\n\nexport {\n getAssetConfigSnapshot,\n getComponentControlsSnapshot,\n} from \"./snapshot\";\n\nexport type ComponentControls<P> = AssetControls<P>;\nexport type ComponentControlsTarget = {\n filePath: string;\n name: string;\n exportName?: string;\n};\nexport const TEMPO_CONTROLS_CONFIG_PROPERTY = \"__tempoControlsConfig\";\n\ntype ControlsRegistration = {\n controls: Record<string, import(\"./controls\").AssetControlDefinition>;\n};\n\n/** Describe real prop editors once, independently of assets and libraries.\n * New components keep this call in their own file. Existing components may use\n * tempo/controls.ts to avoid editing app source. Both work across every canvas.\n * Legacy canvas declarations remain supported.\n * The returned cleanup is used by Tempo's development transform during HMR.\n */\nexport function defineControls<\n C extends ComponentType<any>,\n const Controls extends AssetControls<ComponentProps<NoInfer<C>>>,\n>(\n component: C,\n controls: Controls &\n Record<\n Exclude<\n keyof Controls,\n keyof AssetComponentProps<ComponentProps<NoInfer<C>>>\n >,\n never\n >,\n): () => void {\n const registration = { controls } as ControlsRegistration;\n let registrations: Set<ControlsRegistration>;\n try {\n const previous = (component as unknown as Record<string, unknown>)[\n TEMPO_CONTROLS_CONFIG_PROPERTY\n ] as Set<ControlsRegistration> | undefined;\n registrations = previous ?? new Set();\n registrations.add(registration);\n Object.defineProperty(component, TEMPO_CONTROLS_CONFIG_PROPERTY, {\n value: registrations,\n enumerable: false,\n configurable: true,\n });\n } catch {\n /* Frozen components still render; use a local wrapper to attach controls. */\n return () => {};\n }\n return () => registrations.delete(registration);\n}\n\nexport function getComponentControls(component: unknown): {\n controls?: Record<string, import(\"./controls\").AssetControlDefinition>;\n error?: string;\n} {\n if (\n !component ||\n (typeof component !== \"function\" && typeof component !== \"object\")\n )\n return {};\n const registrations = (component as Record<string, unknown>)[\n TEMPO_CONTROLS_CONFIG_PROPERTY\n ] as Set<ControlsRegistration> | undefined;\n if (!registrations?.size) return {};\n if (registrations.size > 1)\n return {\n error:\n \"Multiple defineControls declarations for this component. Keep one declaration in the component file or tempo/controls.ts; remove the duplicate.\",\n };\n return registrations.values().next().value ?? {};\n}\n"],"mappings":";;;;;;;;;;;AAGO,SAAS,mBACd,OACA,OACmB;AACnB,QAAM,SAAS,EAAE,GAAG,MAAM;AAC1B,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,SAAS,CAAC,CAAC,GAAG;AACvD,QACE,SACA,OAAO,UAAU,YACjB,OAAO,KAAK,KAAK,EAAE,WAAW,KAC7B,MAAkC,wBAAwB,MAC3D;AACA,aAAO,OAAO,IAAI;AAAA,IACpB;AACE,aAAO,eAAe,QAAQ,MAAM;AAAA,QAClC;AAAA,QACA,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,UAAU;AAAA,MACZ,CAAC;AAAA,EACL;AACA,SAAO;AACT;;;ACxBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;;;ACLP,SAAS,SAAS,OAA6B;AAC7C,WAAS,KAAKA,QAAgB,MAAmB,OAA4B;AAC3E,QACEA,WAAU,QACV,OAAO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F;AAAA;AAAA,EACF;AAEJ;;;AGpOO,IAAM,8BAA8B;AA0EpC,SAAS,YACd,WACA,QACM;AACN,MAAI;AAGF,WAAO,eAAe,WAAW,6BAA6B;AAAA,MAC5D,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,cAAc;AAAA,MACd,UAAU;AAAA,IACZ,CAAC;AAAA,EACH,QAAQ;AAAA,EAER;AACF;AASO,SAAS,eACd,WAC6B;AAC7B,MACG,OAAO,cAAc,cAAc,OAAO,cAAc,YACzD,cAAc,MACd;AACA,WAAO;AAAA,EACT;AACA,QAAM,SAAU,UACd,2BACF;AACA,SAAO,WAAW,SACb,SACA;AACP;AAaO,IAAM,iCAAiC;AAYvC,SAAS,eAId,WACA,UAQY;AACZ,QAAM,eAAe,EAAE,SAAS;AAChC,MAAI;AACJ,MAAI;AACF,UAAM,WAAY,UAChB,8BACF;AACA,oBAAgB,YAAY,oBAAI,IAAI;AACpC,kBAAc,IAAI,YAAY;AAC9B,WAAO,eAAe,WAAW,gCAAgC;AAAA,MAC/D,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,cAAc;AAAA,IAChB,CAAC;AAAA,EACH,QAAQ;AAEN,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AACA,SAAO,MAAM,cAAc,OAAO,YAAY;AAChD;AAEO,SAAS,qBAAqB,WAGnC;AACA,MACE,CAAC,aACA,OAAO,cAAc,cAAc,OAAO,cAAc;AAEzD,WAAO,CAAC;AACV,QAAM,gBAAiB,UACrB,8BACF;AACA,MAAI,CAAC,eAAe,KAAM,QAAO,CAAC;AAClC,MAAI,cAAc,OAAO;AACvB,WAAO;AAAA,MACL,OACE;AAAA,IACJ;AACF,SAAO,cAAc,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC;AACjD;","names":["value","content","snapshot"]}
|
package/dist/assets/parser.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { P as ParsedAssetReference, a as AssetSourceSpan, b as AssetExportKind, c as
|
|
2
|
-
export { A as AssetEditFailureCode, e as AssetParseErrorCode, f as AssetSpans, g as ParsedAssetDeclaration, h as ParsedAssetVariant, S as StaticValue, U as UNRESOLVED_VALUE, i as UnresolvedValue, j as isUnresolvedValue } from '../types-
|
|
1
|
+
import { P as ParsedAssetReference, a as AssetSourceSpan, b as AssetExportKind, c as AssetParseError, d as ParsedAssetFile } from '../types-C8OIU-kc.js';
|
|
2
|
+
export { A as AssetEditFailureCode, e as AssetParseErrorCode, f as AssetSpans, g as ParsedAssetDeclaration, h as ParsedAssetVariant, S as StaticValue, U as UNRESOLVED_VALUE, i as UnresolvedValue, j as isUnresolvedValue } from '../types-C8OIU-kc.js';
|
|
3
3
|
|
|
4
4
|
/** The one module specifier `defineAsset` may be imported from. */
|
|
5
5
|
declare const ASSET_SDK_IMPORT_SOURCE = "tempo-sdk/assets";
|
|
6
|
-
declare function parseAssetFile(filePath: string, source: string
|
|
6
|
+
declare function parseAssetFile(filePath: string, source: string, parsed?: {
|
|
7
|
+
program: any | null;
|
|
8
|
+
errors: AssetParseError[];
|
|
9
|
+
}): ParsedAssetFile;
|
|
7
10
|
/**
|
|
8
11
|
* Editor-support: parse and return the raw oxc program. A file with syntax
|
|
9
12
|
* errors returns `program: null` plus structural `unparseable_source` errors
|
|
@@ -50,7 +53,10 @@ type AssetImportInfo = {
|
|
|
50
53
|
};
|
|
51
54
|
declare function readAssetImports(program: any): AssetImportInfo;
|
|
52
55
|
/** Discover control owners without evaluating their config or requiring an asset. */
|
|
53
|
-
declare function parseControlsFile(filePath: string, source: string
|
|
56
|
+
declare function parseControlsFile(filePath: string, source: string, parsed?: {
|
|
57
|
+
program: any | null;
|
|
58
|
+
errors: AssetParseError[];
|
|
59
|
+
}): {
|
|
54
60
|
bindingName: string;
|
|
55
61
|
reference?: ParsedAssetReference;
|
|
56
62
|
exportKind: AssetExportKind;
|
package/dist/assets/parser.js
CHANGED
package/dist/canvas/editor.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ParsedCanvasFile, CanvasSourceSpan } from './parser.js';
|
|
2
|
+
import { V as V1LayoutCompat } from '../v1-client-compat-qxaXEDm_.js';
|
|
3
|
+
import 'oxc-parser';
|
|
2
4
|
|
|
3
5
|
type CanvasSourceEdit = {
|
|
4
6
|
start: number;
|
|
@@ -13,27 +15,20 @@ type CanvasEditResult = {
|
|
|
13
15
|
type CanvasEditorLayout = {
|
|
14
16
|
x: number;
|
|
15
17
|
y: number;
|
|
16
|
-
width
|
|
17
|
-
height
|
|
18
|
+
width?: number;
|
|
19
|
+
height?: number;
|
|
18
20
|
zIndex?: number;
|
|
19
|
-
intrinsicSizing?: "root-element";
|
|
20
21
|
};
|
|
21
22
|
type AddCanvasStoryboardInput = {
|
|
22
23
|
kind: "component";
|
|
24
|
+
/** The component's authored framework, as the declaration and the
|
|
25
|
+
* parser spell it: a Svelte component is written as
|
|
26
|
+
* `<SvelteStoryboard>` from "tempo-sdk/canvas/svelte". */
|
|
27
|
+
uiFramework?: "svelte";
|
|
23
28
|
id: string;
|
|
24
|
-
layout
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
props?: string;
|
|
28
|
-
componentImport?: {
|
|
29
|
-
localName: string;
|
|
30
|
-
source: string;
|
|
31
|
-
importedName?: string;
|
|
32
|
-
};
|
|
33
|
-
} | {
|
|
34
|
-
kind: "svelte-component";
|
|
35
|
-
id: string;
|
|
36
|
-
layout: CanvasEditorLayout;
|
|
29
|
+
/** Migration passes a legacy responsive layout in its V1-readable
|
|
30
|
+
* spelling (see v1-file-compat.ts). */
|
|
31
|
+
layout: CanvasEditorLayout & V1LayoutCompat;
|
|
37
32
|
name?: string;
|
|
38
33
|
componentExpression?: string;
|
|
39
34
|
props?: string;
|
package/dist/canvas/editor.js
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parseCanvasFile
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-RHHVVWAC.js";
|
|
4
4
|
|
|
5
5
|
// canvas/editor.ts
|
|
6
6
|
import { parseSync } from "oxc-parser";
|
|
7
|
+
|
|
8
|
+
// canvas/v1-file-compat.ts
|
|
9
|
+
function v1ReadableLayout(layout, hint) {
|
|
10
|
+
const fixed = layout.width !== void 0 && layout.height !== void 0;
|
|
11
|
+
if (fixed || !hint) return layout;
|
|
12
|
+
return {
|
|
13
|
+
...layout,
|
|
14
|
+
width: hint.width,
|
|
15
|
+
height: hint.height,
|
|
16
|
+
intrinsicSizing: "root-element"
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function v1LayoutHint(layoutSource) {
|
|
20
|
+
const width = readNumberProperty(layoutSource, "width");
|
|
21
|
+
const height = readNumberProperty(layoutSource, "height");
|
|
22
|
+
return width === void 0 || height === void 0 ? void 0 : { width, height };
|
|
23
|
+
}
|
|
24
|
+
function readNumberProperty(source, key) {
|
|
25
|
+
const match = source.match(
|
|
26
|
+
new RegExp(`(?:^|[{,\\s])${key}\\s*:\\s*(-?[0-9]*\\.?[0-9]+)`)
|
|
27
|
+
);
|
|
28
|
+
return match ? Number(match[1]) : void 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// canvas/editor.ts
|
|
7
32
|
function applyCanvasSourceEdits(source, edits) {
|
|
8
33
|
const sorted = [...edits].sort((left, right) => right.start - left.start);
|
|
9
34
|
let previousStart = source.length + 1;
|
|
@@ -127,42 +152,50 @@ function updateStoryboardLayout(options) {
|
|
|
127
152
|
`Storyboard "${options.storyboardId}" has no editable layout`
|
|
128
153
|
);
|
|
129
154
|
}
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
155
|
+
const span = storyboard.legacyV1?.layoutPropertySpan ?? storyboard.layoutAttributeSpan;
|
|
156
|
+
if (!span || spans.layoutClose === void 0) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`Storyboard "${options.storyboardId}" has no editable layout`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
for (const key of ["x", "y", "width", "height", "zIndex"]) {
|
|
162
|
+
if (parsed.errors.some(
|
|
163
|
+
(error) => error.span && error.span.start >= span.start && error.span.end <= span.end && error.message.includes(`layout.${key} must be a number literal`)
|
|
164
|
+
)) {
|
|
135
165
|
throw new Error(
|
|
136
166
|
`Storyboard "${options.storyboardId}" layout.${key} is not editable`
|
|
137
167
|
);
|
|
138
168
|
}
|
|
139
|
-
edits.push({
|
|
140
|
-
start: span.start,
|
|
141
|
-
end: span.end,
|
|
142
|
-
value: String(roundLayoutNumber(options.layout[key]))
|
|
143
|
-
});
|
|
144
169
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
);
|
|
170
|
+
const layout = { ...storyboard.layout, ...options.layout };
|
|
171
|
+
if (storyboard.kind === "component" && storyboard.layout.width === void 0 && storyboard.layout.height === void 0) {
|
|
172
|
+
delete layout.width;
|
|
173
|
+
delete layout.height;
|
|
150
174
|
}
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
edits.push(
|
|
154
|
-
spans.intrinsicSizing ? {
|
|
155
|
-
start: spans.intrinsicSizing.start,
|
|
156
|
-
end: spans.intrinsicSizing.end,
|
|
157
|
-
value
|
|
158
|
-
} : insertLayoutProperty(
|
|
159
|
-
options.source,
|
|
160
|
-
spans,
|
|
161
|
-
`intrinsicSizing: ${value}`
|
|
162
|
-
)
|
|
163
|
-
);
|
|
175
|
+
if (layout.width === void 0 !== (layout.height === void 0)) {
|
|
176
|
+
throw new Error("layout.width and layout.height must be set together");
|
|
164
177
|
}
|
|
165
|
-
|
|
178
|
+
if (storyboard.kind !== "component" && layout.width === void 0) {
|
|
179
|
+
throw new Error("Route and HTML layouts require width and height");
|
|
180
|
+
}
|
|
181
|
+
for (const key of ["x", "y"]) {
|
|
182
|
+
if (options.layout[key] !== void 0 && !spans[key]) {
|
|
183
|
+
throw new Error(
|
|
184
|
+
`Storyboard "${options.storyboardId}" layout.${key} is not editable`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const written = v1ReadableLayout(
|
|
189
|
+
layout,
|
|
190
|
+
v1LayoutHint(options.source.slice(span.start, span.end))
|
|
191
|
+
);
|
|
192
|
+
return applyResult(options.source, parsed, [
|
|
193
|
+
{
|
|
194
|
+
start: span.start,
|
|
195
|
+
end: span.end,
|
|
196
|
+
value: storyboard.legacyV1 ? `layout: { ${formatLayout(written)} }` : `layout={{ ${formatLayout(written)} }}`
|
|
197
|
+
}
|
|
198
|
+
]);
|
|
166
199
|
}
|
|
167
200
|
function updateStoryboardComponent(options) {
|
|
168
201
|
const parsed = parseCanvasFile(options.filePath, options.source);
|
|
@@ -220,9 +253,9 @@ function updateStoryboardProps(options) {
|
|
|
220
253
|
function updateStoryboardVrt(options) {
|
|
221
254
|
const parsed = parseCanvasFile(options.filePath, options.source);
|
|
222
255
|
const storyboard = findStoryboard(parsed, options.storyboardId);
|
|
223
|
-
if (storyboard.kind
|
|
256
|
+
if (storyboard.kind === "route") {
|
|
224
257
|
throw new Error(
|
|
225
|
-
`Storyboard "${options.storyboardId}" is
|
|
258
|
+
`Storyboard "${options.storyboardId}" is a route storyboard; VRT supports component and local HTML storyboards`
|
|
226
259
|
);
|
|
227
260
|
}
|
|
228
261
|
if (typeof options.tracked === "object") {
|
|
@@ -392,7 +425,7 @@ function addCanvasStoryboard(options) {
|
|
|
392
425
|
throw new Error(`Storyboard id "${options.storyboard.id}" already exists`);
|
|
393
426
|
}
|
|
394
427
|
const imports = [];
|
|
395
|
-
const sdkComponent = sdkComponentForStoryboard(options.storyboard
|
|
428
|
+
const sdkComponent = sdkComponentForStoryboard(options.storyboard);
|
|
396
429
|
const sdkTag = resolveSdkTag(parsed, sdkComponent);
|
|
397
430
|
let storyboardTag = sdkTag.tag;
|
|
398
431
|
if (sdkTag.importLine) {
|
|
@@ -400,7 +433,7 @@ function addCanvasStoryboard(options) {
|
|
|
400
433
|
storyboardTag = sdkTag.tag;
|
|
401
434
|
}
|
|
402
435
|
let componentExpression;
|
|
403
|
-
if (options.storyboard.kind === "component"
|
|
436
|
+
if (options.storyboard.kind === "component") {
|
|
404
437
|
componentExpression = options.storyboard.componentExpression ?? options.storyboard.componentImport?.localName;
|
|
405
438
|
if (!componentExpression) {
|
|
406
439
|
throw new Error(
|
|
@@ -553,12 +586,6 @@ function upsertJsxExpressionAttribute(options) {
|
|
|
553
586
|
value: ` ${options.name}={${options.value}}`
|
|
554
587
|
};
|
|
555
588
|
}
|
|
556
|
-
function insertLayoutProperty(source, spans, propertySource) {
|
|
557
|
-
if (typeof spans.layoutClose !== "number") {
|
|
558
|
-
throw new Error("Layout object close span not found");
|
|
559
|
-
}
|
|
560
|
-
return insertObjectProperty(source, spans.layoutClose, propertySource);
|
|
561
|
-
}
|
|
562
589
|
function insertObjectProperty(source, objectClose, propertySource) {
|
|
563
590
|
const offset = trimWhitespaceBeforeOffset(source, objectClose);
|
|
564
591
|
const previous = previousMeaningfulCharacter(source, offset);
|
|
@@ -635,6 +662,9 @@ function storyboardElementProps(storyboard, componentExpression) {
|
|
|
635
662
|
if (storyboard.kind === "legacy-v1") {
|
|
636
663
|
return [idProp, `storyboard={${storyboard.storyboardExpression}}`];
|
|
637
664
|
}
|
|
665
|
+
if ((storyboard.kind === "route" || storyboard.kind === "html") && (storyboard.layout.width === void 0 || storyboard.layout.height === void 0)) {
|
|
666
|
+
throw new Error("Route and HTML layouts require width and height");
|
|
667
|
+
}
|
|
638
668
|
return [
|
|
639
669
|
idProp,
|
|
640
670
|
...storyboard.name && storyboard.name.trim() !== "" ? [formatJsxStringAttribute("name", storyboard.name)] : [],
|
|
@@ -648,7 +678,7 @@ function formatJsxStringAttribute(name, value) {
|
|
|
648
678
|
return plainSafe ? `${name}=${encoded}` : `${name}={${encoded}}`;
|
|
649
679
|
}
|
|
650
680
|
function storyboardKindProps(storyboard, componentExpression) {
|
|
651
|
-
if (storyboard.kind === "component"
|
|
681
|
+
if (storyboard.kind === "component") {
|
|
652
682
|
return [
|
|
653
683
|
`component={${componentExpression}}`,
|
|
654
684
|
...storyboard.props && storyboard.props.trim() !== "" ? [`props={${storyboard.props.trim()}}`] : []
|
|
@@ -666,17 +696,17 @@ function formatLayout(layout) {
|
|
|
666
696
|
return [
|
|
667
697
|
`x: ${roundLayoutNumber(layout.x)}`,
|
|
668
698
|
`y: ${roundLayoutNumber(layout.y)}`,
|
|
669
|
-
`width: ${roundLayoutNumber(layout.width)}
|
|
670
|
-
`height: ${roundLayoutNumber(layout.height)}
|
|
699
|
+
...layout.width === void 0 ? [] : [`width: ${roundLayoutNumber(layout.width)}`],
|
|
700
|
+
...layout.height === void 0 ? [] : [`height: ${roundLayoutNumber(layout.height)}`],
|
|
671
701
|
...layout.zIndex === void 0 ? [] : [`zIndex: ${roundLayoutNumber(layout.zIndex)}`],
|
|
672
|
-
...layout.intrinsicSizing ? [`intrinsicSizing: ${JSON.stringify(layout.intrinsicSizing)}`]
|
|
702
|
+
...layout.intrinsicSizing === void 0 ? [] : [`intrinsicSizing: ${JSON.stringify(layout.intrinsicSizing)}`]
|
|
673
703
|
].join(", ");
|
|
674
704
|
}
|
|
675
|
-
function sdkComponentForStoryboard(
|
|
676
|
-
if (kind === "route") return "RouteStoryboard";
|
|
677
|
-
if (kind === "html") return "HtmlStoryboard";
|
|
678
|
-
if (kind === "legacy-v1") return "LegacyStoryboardV1";
|
|
679
|
-
if (
|
|
705
|
+
function sdkComponentForStoryboard(storyboard) {
|
|
706
|
+
if (storyboard.kind === "route") return "RouteStoryboard";
|
|
707
|
+
if (storyboard.kind === "html") return "HtmlStoryboard";
|
|
708
|
+
if (storyboard.kind === "legacy-v1") return "LegacyStoryboardV1";
|
|
709
|
+
if (storyboard.uiFramework === "svelte") return "SvelteStoryboard";
|
|
680
710
|
return "Storyboard";
|
|
681
711
|
}
|
|
682
712
|
function resolveSdkTag(parsed, component) {
|